Skip to content

Commit

Permalink
Merge pull request #533 from nevalang/new_sugar2
Browse files Browse the repository at this point in the history
One-liners connections sugar. It's not finished, it has this issue #544
  • Loading branch information
emil14 committed Apr 7, 2024
2 parents 19d63a3 + 8878477 commit 255128a
Show file tree
Hide file tree
Showing 88 changed files with 2,849 additions and 2,004 deletions.
37 changes: 32 additions & 5 deletions .vscode/launch.json
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,16 @@
"mode": "auto",
"program": "${workspaceFolder}/cmd/neva",
"cwd": "${workspaceFolder}/examples",
"args": ["run", "3_interfaces"]
"args": ["run", "3_interfaces/verbose"]
},
{
"name": "Neva CLI 31",
"type": "go",
"request": "launch",
"mode": "auto",
"program": "${workspaceFolder}/cmd/neva",
"cwd": "${workspaceFolder}/examples",
"args": ["run", "3_interfaces/with_imports"]
},
{
"name": "Neva CLI 40",
Expand Down Expand Up @@ -223,10 +232,28 @@
"mode": "auto",
"program": "${workspaceFolder}/cmd/neva",
"cwd": "${workspaceFolder}/examples",
"args": ["run", "11_99_bottles"]
"args": ["run", "11_99_bottles/verbose"]
},
{
"name": "Neva CLI 111",
"type": "go",
"request": "launch",
"mode": "auto",
"program": "${workspaceFolder}/cmd/neva",
"cwd": "${workspaceFolder}/examples",
"args": ["run", "11_99_bottles/with_chain"]
},
{
"name": "TMP",
"type": "go",
"request": "launch",
"mode": "auto",
"program": "${workspaceFolder}/cmd/neva",
"cwd": "${workspaceFolder}/e2e/tmp",
"args": ["run", "-debug", "main"]
},
{
"name": "Neva CLI 113",
"name": "Neva CLI 130",
"type": "go",
"request": "launch",
"mode": "auto",
Expand All @@ -235,7 +262,7 @@
"args": ["run", "13_fizzbuzz"]
},
{
"name": "Neva CLI 114",
"name": "Neva CLI 140",
"type": "go",
"request": "launch",
"mode": "auto",
Expand All @@ -244,7 +271,7 @@
"args": ["run", "14_list_index"]
},
{
"name": "Neva CLI 115",
"name": "Neva CLI 150",
"type": "go",
"request": "launch",
"mode": "auto",
Expand Down
6 changes: 3 additions & 3 deletions e2e/comments/main/main.neva
Original file line number Diff line number Diff line change
Expand Up @@ -3,15 +3,15 @@ component Main(start) (stop) {
// comment inside component 1
nodes {
// comment inside nodes 1
Printer<any>
Println<any>
// comment inside nodes 2
}
// comment inside component 2
net {
// comment inside network 1
:start -> printer:data
:start -> println:data
// comment inside network 2
printer:sig -> :stop
println:sig -> :stop
// comment inside network
}
// comment inside component 3
Expand Down
6 changes: 3 additions & 3 deletions e2e/conn_with_only_port_addr/main/main.neva
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,9 @@

const array list<int> = [1,2,3]
component Main(start any) (stop any) {
nodes { printer Printer<any>}
nodes { println Println<any>}
net {
:start -> ($array -> printer:data)
printer:sig
:start -> ($array -> println:data)
println:sig
}
}
2 changes: 1 addition & 1 deletion e2e/incompat_comp_type_arg/main/main.neva
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
component Main(start) (stop) {
nodes { Decrementor<any> }
nodes { Decr<any> }
net {
:start -> (42 -> decrementor:data)
decrementor:res -> :stop
Expand Down
6 changes: 3 additions & 3 deletions e2e/list_with_neg_nums/main/main.neva
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
const l list<int> = [-215]

component Main(start) (stop) {
nodes { Printer<any> }
nodes { Println<any> }
net {
:start -> ($l -> printer:data)
printer:sig -> :stop
:start -> ($l -> println:data)
println:sig -> :stop
}
}
14 changes: 7 additions & 7 deletions e2e/order_dependend_with_arr_inport/main/main.neva
Original file line number Diff line number Diff line change
@@ -1,15 +1,15 @@
component Main(start) (stop) {
nodes {
Printer<int>
sub PortBridge<int> { handler Subtractor<int> }
Println<int>
sub PortReducer<int> { reducer Sub<int> }
}
net {
:start -> (
1 -> sub:ports[0],
2 -> sub:ports[1],
3 -> sub:ports[2]
1 -> sub:port[0],
2 -> sub:port[1],
3 -> sub:port[2]
)
sub:res -> printer:data
printer:sig -> :stop
sub:res -> println:data
println:sig -> :stop
}
}
6 changes: 3 additions & 3 deletions e2e/print_float/main/main.neva
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
const x float = 42

component Main(start) (stop) {
nodes { Printer<float> }
nodes { Println<float> }
net {
:start -> ($x -> printer:data)
printer:sig -> :stop
:start -> ($x -> println:data)
println:sig -> :stop
}
}
6 changes: 3 additions & 3 deletions e2e/struct_selector_on_port_addr/main/main.neva
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
component Main(start) (stop) {
nodes {
Foo
Printer<int>
Println<int>
}
net {
:start -> foo:sig
foo:msg.a -> printer:data
printer:sig -> :stop
foo:msg.a -> println:data
println:sig -> :stop
}
}

Expand Down
10 changes: 5 additions & 5 deletions examples/10_regex_submatch/main.neva
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
import { regexp }

component Main(start) (stop) {
nodes { Printer<any>, regexp.Submatcher }
nodes { Println<any>, regexp.Submatch }
net {
:start -> (
'a(x*)b(y|z)c' -> submatcher:regexp,
'-axxxbyc-' -> submatcher:data
'a(x*)b(y|z)c' -> submatch:regexp,
'-axxxbyc-' -> submatch:data
)
submatcher:res -> printer:data
printer:sig -> :stop
submatch:res -> println:data
println:sig -> :stop
}
}
83 changes: 0 additions & 83 deletions examples/11_99_bottles/main.neva

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -9,14 +9,14 @@ import (
)

func Test(t *testing.T) {
err := os.Chdir("../")
err := os.Chdir("../..")
require.NoError(t, err)

wd, err := os.Getwd()
require.NoError(t, err)
defer os.Chdir(wd)

cmd := exec.Command("neva", "run", "11_99_bottles")
cmd := exec.Command("neva", "run", "11_99_bottles/verbose")

out, err := cmd.CombinedOutput()
require.NoError(t, err)
Expand Down
83 changes: 83 additions & 0 deletions examples/11_99_bottles/verbose/main.neva
Original file line number Diff line number Diff line change
@@ -0,0 +1,83 @@
// https://www.99-bottles-of-beer.net

component Main(start) (stop) {
nodes { Match<int>, next PrintNext2Lines }
net {
:start -> (99 -> next:n)

next:n -> match:data
-1 -> match:case[0]

match:case[0] -> :stop
match:else -> next:n
}
}

component PrintNext2Lines(n int) (n int) {
nodes {
decr Decr<int>
first PrintFirstLine
second PrintSecondLine
}
net {
:n -> first:n
first:n -> decr:n
decr:n -> second:n
second:n -> :n
}
}

// === First Line ===

const {
firstLine1 string = '$0 bottles of beer on the wall, $0 bottles of beer.\n'
firstLine2 string = '1 bottle of beer on the wall, 1 bottle of beer.'
firstLine3 string = 'No more bottles of beer on the wall, no more bottles of beer.'
}

component PrintFirstLine(n int) (n int) {
nodes { Match<int>, Println<string>, Printf<int>, Lock<int> }
net {
:n -> [match:data, lock:data]
0 -> match:case[0]
1 -> match:case[1]

match:case[0] -> ($firstLine3 -> println:data)
match:case[1] -> ($firstLine2 -> println:data)
match:else -> printf:args[0]
$firstLine1 -> printf:tpl

println:sig -> lock:sig
printf:args[0] -> lock:sig

lock:data -> :n
}
}

// === Second Line ===

const {
secondLine1 string = 'Take one down and pass it around, $0 bottles of beer on the wall.\n\n'
secondLine2 string = 'Take one down and pass it around, 1 bottle of beer on the wall.\n'
secondLine3 string = 'Take one down and pass it around, no more bottles of beer on the wall.\n'
secondLine4 string = 'Go to the store and buy some more, 99 bottles of beer on the wall.'
}

component PrintSecondLine(n int) (n int) {
nodes { Match<int>, Lock<int>, Printf<int>, Println<string> }
net {
:n -> [match:data, lock:data]
-1 -> match:case[0]
0 -> match:case[1]
1 -> match:case[2]

match:case[0] -> ($secondLine4 -> println:data)
match:case[1] -> ($secondLine3 -> println:data)
match:case[2] -> ($secondLine2 -> println:data)
match:else -> printf:args[0]
$secondLine1 -> printf:tpl

[println:sig, printf:args[0]] -> lock:sig
lock:data -> :n
}
}
Loading

0 comments on commit 255128a

Please sign in to comment.