From b4e55040b971a21f0d24de978c6bfa7c5d038725 Mon Sep 17 00:00:00 2001 From: Emil Valeev Date: Tue, 30 Apr 2024 21:19:45 +0500 Subject: [PATCH 1/6] refactor(std) --- e2e/add_nums_from_stdin_naive/main/main.neva | 12 ++-- .../main.neva | 6 +- .../main/main.neva | 12 ++-- .../main/main.neva | 6 +- .../main/main.neva | 6 +- e2e/add_nums_verbose/main/main.neva | 2 +- e2e/add_nums_with_bridge/main/main.neva | 2 +- e2e/echo_verbose/main/main.neva | 4 +- e2e/multiply_numbers/main/main.neva | 2 +- .../main/main.neva | 2 +- examples/add_numbers/main.neva | 2 +- examples/add_numbers_from_stdin/main.neva | 6 +- examples/echo/main.neva | 4 +- examples/list_index/main.neva | 9 ++- examples/split_join_string/main.neva | 2 +- examples/stream_to_list/main.neva | 10 +++ internal/runtime/funcs/field.go | 6 +- internal/runtime/funcs/int_add.go | 1 - .../funcs/{list_iter.go => list_to_stream.go} | 4 +- internal/runtime/funcs/port_streamer.go | 4 +- internal/runtime/funcs/range.go | 4 +- internal/runtime/funcs/registry.go | 63 +++++++++++-------- internal/runtime/funcs/stream_to_list.go | 50 +++++++++++++++ std/builtin/collections.neva | 29 ++++----- std/builtin/core.neva | 2 +- std/builtin/sequences.neva | 23 ------- std/builtin/streams.neva | 30 +++++++++ std/io/io.neva | 2 + std/strconv/strconv.neva | 2 + std/strings/strings.neva | 7 +++ std/x/x.neva | 10 --- 31 files changed, 199 insertions(+), 125 deletions(-) create mode 100644 examples/stream_to_list/main.neva rename internal/runtime/funcs/{list_iter.go => list_to_stream.go} (92%) create mode 100644 internal/runtime/funcs/stream_to_list.go delete mode 100644 std/builtin/sequences.neva create mode 100644 std/builtin/streams.neva create mode 100644 std/io/io.neva create mode 100644 std/strconv/strconv.neva create mode 100644 std/strings/strings.neva delete mode 100644 std/x/x.neva diff --git a/e2e/add_nums_from_stdin_naive/main/main.neva b/e2e/add_nums_from_stdin_naive/main/main.neva index 6791dc36..4388b019 100644 --- a/e2e/add_nums_from_stdin_naive/main/main.neva +++ b/e2e/add_nums_from_stdin_naive/main/main.neva @@ -1,12 +1,12 @@ -import { x } +import { io, strconv } component Main(start any) (stop any) { nodes { - scanner1 x.Scanln - scanner2 x.Scanln - parser1 x.ParseNum - parser2 x.ParseNum - adder Reduce { Add } + scanner1 io.Scanln + scanner2 io.Scanln + parser1 strconv.ParseNum + parser2 strconv.ParseNum + adder ReducePort { Add } println Println } net { diff --git a/e2e/add_nums_from_stdin_with_default_any/main.neva b/e2e/add_nums_from_stdin_with_default_any/main.neva index ed6f2de9..8054dd60 100644 --- a/e2e/add_nums_from_stdin_with_default_any/main.neva +++ b/e2e/add_nums_from_stdin_with_default_any/main.neva @@ -1,4 +1,4 @@ -import { x } +import { io, strconv } component { Main(start) (stop) { @@ -14,7 +14,7 @@ component { nodes { reader1 IntReader reader2 IntReader - adder Reduce { Add } + adder ReducePort { Add } } net { :sig -> reader1:sig @@ -26,7 +26,7 @@ component { } IntReader(sig any) (num int, err error) { - nodes { x.Scanln, x.ParseNum } + nodes { io.Scanln, strconv.ParseNum } net { :sig -> scanln:sig scanln:data -> parseNum:data diff --git a/e2e/add_nums_from_stdin_with_err_handling/main/main.neva b/e2e/add_nums_from_stdin_with_err_handling/main/main.neva index 962006c3..91061f78 100644 --- a/e2e/add_nums_from_stdin_with_err_handling/main/main.neva +++ b/e2e/add_nums_from_stdin_with_err_handling/main/main.neva @@ -1,12 +1,12 @@ -import { x } +import { io, strconv } component Main(start any) (stop any) { nodes { - scanner1 x.Scanln - scanner2 x.Scanln - parser1 x.ParseNum - parser2 x.ParseNum - adder Reduce { Add } + scanner1 io.Scanln + scanner2 io.Scanln + parser1 strconv.ParseNum + parser2 strconv.ParseNum + adder ReducePort { Add } println Println } net { diff --git a/e2e/add_nums_from_stdin_with_multuple_senders/main/main.neva b/e2e/add_nums_from_stdin_with_multuple_senders/main/main.neva index d0bcbc09..a7f8c540 100644 --- a/e2e/add_nums_from_stdin_with_multuple_senders/main/main.neva +++ b/e2e/add_nums_from_stdin_with_multuple_senders/main/main.neva @@ -1,4 +1,4 @@ -import { x } +import { io, strconv } component { Main(start) (stop) { @@ -14,7 +14,7 @@ component { nodes { reader1 IntReader reader2 IntReader - adder Reduce { Add } + adder ReducePort { Add } } net { :sig -> reader1:sig @@ -26,7 +26,7 @@ component { } IntReader(sig any) (num int, err error) { - nodes { x.Scanln, x.ParseNum } + nodes { io.Scanln, strconv.ParseNum } net { :sig -> scanln:sig scanln:data -> parseNum:data diff --git a/e2e/add_nums_from_stdin_with_sub_components/main/main.neva b/e2e/add_nums_from_stdin_with_sub_components/main/main.neva index a11528f6..a3003244 100644 --- a/e2e/add_nums_from_stdin_with_sub_components/main/main.neva +++ b/e2e/add_nums_from_stdin_with_sub_components/main/main.neva @@ -1,4 +1,4 @@ -import { x } +import { io, strconv } component { Main(start any) (stop any) { @@ -15,7 +15,7 @@ component { nodes { reader1 IntReader reader2 IntReader - adder Reduce { Add } + adder ReducePort { Add } } net { :sig -> reader1:sig @@ -28,7 +28,7 @@ component { } IntReader(sig any) (num int, err error) { - nodes { x.Scanln, x.ParseNum } + nodes { io.Scanln, strconv.ParseNum } net { :sig -> scanln:sig scanln:data -> parseNum:data diff --git a/e2e/add_nums_verbose/main/main.neva b/e2e/add_nums_verbose/main/main.neva index 2970a85a..c54f2414 100644 --- a/e2e/add_nums_verbose/main/main.neva +++ b/e2e/add_nums_verbose/main/main.neva @@ -1,7 +1,7 @@ component Main(start any) (stop any) { nodes { adder Add - sequencer PortSequencer + sequencer StreamPort println Println } net { diff --git a/e2e/add_nums_with_bridge/main/main.neva b/e2e/add_nums_with_bridge/main/main.neva index dc22e2d6..6c570fac 100644 --- a/e2e/add_nums_with_bridge/main/main.neva +++ b/e2e/add_nums_with_bridge/main/main.neva @@ -1,6 +1,6 @@ component Main(start any) (stop any) { nodes { - adder Reduce { Add } + adder ReducePort { Add } println Println } net { diff --git a/e2e/echo_verbose/main/main.neva b/e2e/echo_verbose/main/main.neva index 72b9fff3..fe9ff909 100644 --- a/e2e/echo_verbose/main/main.neva +++ b/e2e/echo_verbose/main/main.neva @@ -1,8 +1,8 @@ -import { x } +import { io } component Main(start any) (stop any) { nodes { - scanner x.Scanln + scanner io.Scanln println Println } net { diff --git a/e2e/multiply_numbers/main/main.neva b/e2e/multiply_numbers/main/main.neva index 62dc8396..23919bbc 100644 --- a/e2e/multiply_numbers/main/main.neva +++ b/e2e/multiply_numbers/main/main.neva @@ -1,7 +1,7 @@ component Main(start) (stop) { nodes { Println - mul Reduce { Mul } + mul ReducePort { Mul } } net { :start -> [ diff --git a/e2e/order_dependend_with_arr_inport/main/main.neva b/e2e/order_dependend_with_arr_inport/main/main.neva index 5499d241..c1a4359b 100644 --- a/e2e/order_dependend_with_arr_inport/main/main.neva +++ b/e2e/order_dependend_with_arr_inport/main/main.neva @@ -1,7 +1,7 @@ component Main(start) (stop) { nodes { Println - sub Reduce { Sub } + sub ReducePort { Sub } } net { :start -> [ diff --git a/examples/add_numbers/main.neva b/examples/add_numbers/main.neva index 19c695d7..9e1f8af2 100644 --- a/examples/add_numbers/main.neva +++ b/examples/add_numbers/main.neva @@ -1,6 +1,6 @@ component Main(start) (stop) { nodes { - add Reduce { Add } + add ReducePort { Add } Println } net { diff --git a/examples/add_numbers_from_stdin/main.neva b/examples/add_numbers_from_stdin/main.neva index 3533455c..dab64e5b 100644 --- a/examples/add_numbers_from_stdin/main.neva +++ b/examples/add_numbers_from_stdin/main.neva @@ -1,4 +1,4 @@ -import { x } +import { io, strconv } component { Main(start) (stop) { @@ -13,7 +13,7 @@ component { nodes { readFirstInt ReadIntFromStdin readSecondInt ReadIntFromStdin - add Reduce { Add } + add ReducePort { Add } } net { :sig -> readFirstInt @@ -25,7 +25,7 @@ component { } ReadIntFromStdin(sig) (num int, err error) { - nodes { x.Scanln, x.ParseNum } + nodes { io.Scanln, strconv.ParseNum } net { :sig -> scanln -> parseNum parseNum:res -> :num diff --git a/examples/echo/main.neva b/examples/echo/main.neva index 102fd7a4..19614929 100644 --- a/examples/echo/main.neva +++ b/examples/echo/main.neva @@ -1,7 +1,7 @@ -import { x } +import { io } component Main(start) (stop) { - nodes { x.Scanln, Println } + nodes { io.Scanln, Println } net { :start -> scanln -> println -> :stop } diff --git a/examples/list_index/main.neva b/examples/list_index/main.neva index 501fa12c..5dc289a6 100644 --- a/examples/list_index/main.neva +++ b/examples/list_index/main.neva @@ -1,12 +1,11 @@ -const l list = [1, 1, 5, 112, 69, 420] -const i int = 4 +const lst list = [1, 1, 5, 112, 69, 420] component Main(start) (stop) { - nodes { Index, Println } + nodes { Index>, Println } net { :start -> [ - ($l -> index:data), - ($i -> index:idx) + ($lst -> index:data), + (4 -> index:idx) ] [index:res, index:err] -> println -> :stop } diff --git a/examples/split_join_string/main.neva b/examples/split_join_string/main.neva index ef0e8c80..7838cdd9 100644 --- a/examples/split_join_string/main.neva +++ b/examples/split_join_string/main.neva @@ -1,5 +1,5 @@ component Main(start) (stop) { - nodes { Println, Split, Join } + nodes { Println, strings.Split, strings.Join } net { :start -> [ ('neva' -> split:data), diff --git a/examples/stream_to_list/main.neva b/examples/stream_to_list/main.neva new file mode 100644 index 00000000..7b8f4390 --- /dev/null +++ b/examples/stream_to_list/main.neva @@ -0,0 +1,10 @@ +component Main(start) (stop) { + nodes { Range, List } + net { + :start -> [ + (1 -> range:from), + (11 -> range:to) + ] + range -> list -> println -> :stop + } +} diff --git a/internal/runtime/funcs/field.go b/internal/runtime/funcs/field.go index 523e77dd..9955d2f3 100644 --- a/internal/runtime/funcs/field.go +++ b/internal/runtime/funcs/field.go @@ -7,9 +7,9 @@ import ( "github.com/nevalang/neva/internal/runtime" ) -type field struct{} +type readStructField struct{} -func (s field) Create(io runtime.FuncIO, fieldPathMsg runtime.Msg) (func(ctx context.Context), error) { +func (s readStructField) Create(io runtime.FuncIO, fieldPathMsg runtime.Msg) (func(ctx context.Context), error) { fieldPath := fieldPathMsg.List() if len(fieldPath) == 0 { return nil, errors.New("field path cannot be empty") @@ -49,7 +49,7 @@ func (s field) Create(io runtime.FuncIO, fieldPathMsg runtime.Msg) (func(ctx con }, nil } -func (field) mapLookup(m runtime.Msg, path []string) runtime.Msg { +func (readStructField) mapLookup(m runtime.Msg, path []string) runtime.Msg { for len(path) > 0 { m = m.Map()[path[0]] path = path[1:] diff --git a/internal/runtime/funcs/int_add.go b/internal/runtime/funcs/int_add.go index f1d82e4b..fedd0118 100644 --- a/internal/runtime/funcs/int_add.go +++ b/internal/runtime/funcs/int_add.go @@ -45,7 +45,6 @@ func (intAdd) Create( continue } } - } }, nil } diff --git a/internal/runtime/funcs/list_iter.go b/internal/runtime/funcs/list_to_stream.go similarity index 92% rename from internal/runtime/funcs/list_iter.go rename to internal/runtime/funcs/list_to_stream.go index 372be673..771526cd 100644 --- a/internal/runtime/funcs/list_iter.go +++ b/internal/runtime/funcs/list_to_stream.go @@ -6,9 +6,9 @@ import ( "github.com/nevalang/neva/internal/runtime" ) -type list_iter struct{} +type listToStream struct{} -func (c list_iter) Create( +func (c listToStream) Create( io runtime.FuncIO, _ runtime.Msg, ) (func(ctx context.Context), error) { diff --git a/internal/runtime/funcs/port_streamer.go b/internal/runtime/funcs/port_streamer.go index e12c4f62..df9d94ea 100644 --- a/internal/runtime/funcs/port_streamer.go +++ b/internal/runtime/funcs/port_streamer.go @@ -7,9 +7,9 @@ import ( "github.com/nevalang/neva/internal/runtime" ) -type portStreamer struct{} +type arrayPortToStream struct{} -func (portStreamer) Create( +func (arrayPortToStream) Create( io runtime.FuncIO, _ runtime.Msg, ) (func(context.Context), error) { diff --git a/internal/runtime/funcs/range.go b/internal/runtime/funcs/range.go index d266e4e6..e69e035e 100644 --- a/internal/runtime/funcs/range.go +++ b/internal/runtime/funcs/range.go @@ -6,9 +6,9 @@ import ( "github.com/nevalang/neva/internal/runtime" ) -type ranger struct{} +type streamIntRange struct{} -func (ranger) Create( +func (streamIntRange) Create( io runtime.FuncIO, _ runtime.Msg, ) (func(ctx context.Context), error) { diff --git a/internal/runtime/funcs/registry.go b/internal/runtime/funcs/registry.go index de3a6635..18866866 100644 --- a/internal/runtime/funcs/registry.go +++ b/internal/runtime/funcs/registry.go @@ -9,44 +9,57 @@ import ( func CreatorRegistry() map[string]runtime.FuncCreator { return map[string]runtime.FuncCreator{ // core - "new": new{}, - "del": del{}, - "lock": lock{}, - "range": ranger{}, - "port_sequencer": portStreamer{}, - // structures - "field": field{}, - "struct_builder": structBuilder{}, - // logic + "new": new{}, + "del": del{}, + "lock": lock{}, "match": match{}, "unwrap": unwrap{}, + + // streamers + "array_port_to_stream": arrayPortToStream{}, + "list_to_stream": listToStream{}, + "stream_int_range": streamIntRange{}, + + // builders + "struct_builder": structBuilder{}, + "stream_to_list": streamToList{}, + + // structures + "field": readStructField{}, + // math "int_add": intAdd{}, "int_sub": intSub{}, "int_mul": intMul{}, "int_decr": intDecr{}, "int_mod": intMod{}, - // io - "scanln": scanln{}, - "println": println{}, - "printf": printf{}, - // strings + + // strconv "parse_int": parseInt{}, + // regexp "regexp_submatch": regexpSubmatch{}, - //list - "index": index{}, - "list_len": listlen{}, - "list_iter": list_iter{}, - "list_push": listPush{}, - "int_sort": listSortInt{}, - "float_sort": listSortFloat{}, - "string_sort": listSortString{}, - "join": stringJoin{}, + + // list + "index": index{}, + "list_len": listlen{}, + "list_push": listPush{}, + "int_sort": listSortInt{}, + "float_sort": listSortFloat{}, + // time "time_sleep": timeSleep{}, - //string - "split": stringSplit{}, + + // strings + "join": stringJoin{}, + "split": stringSplit{}, + "string_sort": listSortString{}, + + // io + "scanln": scanln{}, + "println": println{}, + "printf": printf{}, + // io/file "read_all": readAll{}, "write_all": writeAll{}, diff --git a/internal/runtime/funcs/stream_to_list.go b/internal/runtime/funcs/stream_to_list.go new file mode 100644 index 00000000..c0cbc9c2 --- /dev/null +++ b/internal/runtime/funcs/stream_to_list.go @@ -0,0 +1,50 @@ +package funcs + +import ( + "context" + + "github.com/nevalang/neva/internal/runtime" +) + +type streamToList struct{} + +func (s streamToList) Create( + io runtime.FuncIO, + _ runtime.Msg, +) (func(ctx context.Context), error) { + seqIn, err := io.In.Port("seq") + if err != nil { + return nil, err + } + + resOut, err := io.Out.Port("res") + if err != nil { + return nil, err + } + + return func(ctx context.Context) { + acc := []runtime.Msg{} + + for { + var item map[string]runtime.Msg + select { + case <-ctx.Done(): + return + case msg := <-seqIn: + item = msg.Map() + } + + acc = append(acc, item["data"]) + + if item["last"].Bool() { + select { + case <-ctx.Done(): + return + case resOut <- runtime.NewListMsg(acc...): + acc = []runtime.Msg{} // reset + continue + } + } + } + }, nil +} diff --git a/std/builtin/collections.neva b/std/builtin/collections.neva index dc3f67fb..2282296c 100644 --- a/std/builtin/collections.neva +++ b/std/builtin/collections.neva @@ -1,37 +1,32 @@ component { - // Len returns the length of the given sequence: list, map, or string. - // For lists it returns number of elements, + // Len returns the length of the given sequence: list, map, or string: + // for lists it returns number of elements, // for maps it returns number of keys, - // and for strings it returns number of utf-8 characters. + // for for strings it returns number of utf-8 characters. #extern(list list_len, map map_len) pub Len | map | string>(data T) (res int) + // List receives stream and sends list with all elements from the stream. + #extern(stream_to_list) + pub List(seq stream) (res list) + // Index returns the element at the given index in the ordered collection. // If the index is out of bounds, it returns an error. // The index is zero-based. #extern(index) - pub Index(data list, idx int) (res T, err error) + pub Index | string>(data T, idx int) (res T, err error) - // Push appends new element to a list. - // It allocates a copy so old list is not modified. + // Push creates new list with appended element. #extern(list_push) pub Push (lst list, data T) (res list) - // Sort returns sorted version of the given list. + // Sort creates sorted version of the given list. #extern(int int_sort, float float_sort, string string_sort) pub Sort(data list) (res T) - // Join returns - #extern(join) - pub Join(data list) (res string) - - // Split - #extern(split) - pub Split(data string, delim string) (res list) - #extern(slice) pub Slice>(data T, from int, to int) (res T, err error) - #extern(list_iter) - pub Iter (data list) (seq stream) + #extern(list_to_stream) + pub Iter(data list) (seq stream) } diff --git a/std/builtin/core.neva b/std/builtin/core.neva index bf1da65b..376cac70 100644 --- a/std/builtin/core.neva +++ b/std/builtin/core.neva @@ -21,6 +21,6 @@ component { #extern(unwrap) pub Unwrap(data maybe) (some T, none struct{}) - #extern(range) + #extern(stream_int_range) pub Range(from int, to int) (data stream) } \ No newline at end of file diff --git a/std/builtin/sequences.neva b/std/builtin/sequences.neva deleted file mode 100644 index 6ec1fcd3..00000000 --- a/std/builtin/sequences.neva +++ /dev/null @@ -1,23 +0,0 @@ -// PortSequencer iterates over all array-inport's slots in order -// and produces stream of messages. -#extern(port_sequencer) -pub component PortSequencer([port] T) (seq stream) - -// ISeqReducer reduce stream of messages to one single message. -// It's expected to send result message after every processed stream. -pub interface ISeqReducer(seq stream) (res T) - -// Reduce reduces messages from multiple connections to a single message. -// It iterates over all array-inport's slots in order and streams every message -// to reducer. When all messages are processed the result is emited to outport. -pub component Reduce([port] T) (res T) { - nodes { - reducer ISeqReducer - sequencer PortSequencer - } - net { - :port => sequencer:port - sequencer:seq -> reducer:seq - reducer:res -> :res - } -} diff --git a/std/builtin/streams.neva b/std/builtin/streams.neva new file mode 100644 index 00000000..ad0b7235 --- /dev/null +++ b/std/builtin/streams.neva @@ -0,0 +1,30 @@ +// StreamPort iterates over all array-inport's slots in order +// and produces stream of messages. +#extern(array_port_to_stream) +pub component StreamPort([port] T) (seq stream) + +// IPortReducer reduce stream of messages to one single message. +// It's expected to send result message after every processed stream. +pub interface IPortReducer(seq stream) (res T) + +// ReducePort reduces messages from multiple connections to a single message. +// It iterates over all array-inport's slots in order and streams every message +// to reducer. When all messages are processed the result is emited to outport. +pub component ReducePort([port] T) (res T) { + nodes { reducer IPortReducer, streamer StreamPort } + net { :port => streamer -> reducer -> :res } +} + +// IMapper maps input message to output message. +pub interface IMapper(data T) (res Y) + +// Map component maps input stream of messages to output stream of messages. +pub component Map(data stream) (res stream) { + nodes { mapper IMapper, builder Struct } + net { + :data.data -> mapper -> builder:data + :data.idx -> builder:idx + :data.last -> builder:last + builder -> :res + } +} \ No newline at end of file diff --git a/std/io/io.neva b/std/io/io.neva new file mode 100644 index 00000000..47aba899 --- /dev/null +++ b/std/io/io.neva @@ -0,0 +1,2 @@ +#extern(scanln) +pub component Scanln(sig any) (data string) \ No newline at end of file diff --git a/std/strconv/strconv.neva b/std/strconv/strconv.neva new file mode 100644 index 00000000..f111f2b5 --- /dev/null +++ b/std/strconv/strconv.neva @@ -0,0 +1,2 @@ +#extern(int parse_int, float parse_float) +pub component ParseNum(data string) (res T, err error) \ No newline at end of file diff --git a/std/strings/strings.neva b/std/strings/strings.neva new file mode 100644 index 00000000..b4d0afdc --- /dev/null +++ b/std/strings/strings.neva @@ -0,0 +1,7 @@ +component { + #extern(join) + pub Join(data list) (res string) + + #extern(split) + pub Split(data string, delim string) (res list) +} \ No newline at end of file diff --git a/std/x/x.neva b/std/x/x.neva deleted file mode 100644 index 7e6bceba..00000000 --- a/std/x/x.neva +++ /dev/null @@ -1,10 +0,0 @@ -// this is a package where we temporary keep everything that is not builtin -// we will organize it later into separate packages - -component { - #extern(int parse_int, float parse_float) - pub ParseNum(data string) (res T, err error) - - #extern(scanln) - pub Scanln(sig any) (data string) -} From 758e6f20c0c960c2a5dfef0f1b943c3d95575e51 Mon Sep 17 00:00:00 2001 From: Emil Valeev Date: Tue, 30 Apr 2024 23:00:21 +0500 Subject: [PATCH 2/6] feat(src:location:stringer): omit ".neva" if no file found --- .vscode/launch.json | 2 +- .../stream_to_list/main}/main.neva | 1 + e2e/stream_to_list/neva.yml | 1 + internal/compiler/parser/listener_helpers.go | 6 +++++- internal/compiler/sourcecode/scope.go | 11 +++++++++-- std/builtin/streams.neva | 5 ++++- 6 files changed, 21 insertions(+), 5 deletions(-) rename {examples/stream_to_list => e2e/stream_to_list/main}/main.neva (89%) create mode 100644 e2e/stream_to_list/neva.yml diff --git a/.vscode/launch.json b/.vscode/launch.json index 9fa2d6bb..4ad23b6b 100644 --- a/.vscode/launch.json +++ b/.vscode/launch.json @@ -17,7 +17,7 @@ "mode": "auto", "program": "${workspaceFolder}/cmd/neva", "cwd": "${workspaceFolder}", - "args": ["run", "e2e/add_nums_verbose/main"] + "args": ["run", "e2e/stream_to_list/main"] }, { "name": "LSP", diff --git a/examples/stream_to_list/main.neva b/e2e/stream_to_list/main/main.neva similarity index 89% rename from examples/stream_to_list/main.neva rename to e2e/stream_to_list/main/main.neva index 7b8f4390..e352921d 100644 --- a/examples/stream_to_list/main.neva +++ b/e2e/stream_to_list/main/main.neva @@ -1,3 +1,4 @@ +// TODO move to examples component Main(start) (stop) { nodes { Range, List } net { diff --git a/e2e/stream_to_list/neva.yml b/e2e/stream_to_list/neva.yml new file mode 100644 index 00000000..56866f0d --- /dev/null +++ b/e2e/stream_to_list/neva.yml @@ -0,0 +1 @@ +neva: 0.10.0 \ No newline at end of file diff --git a/internal/compiler/parser/listener_helpers.go b/internal/compiler/parser/listener_helpers.go index 746d0c40..aca88d46 100644 --- a/internal/compiler/parser/listener_helpers.go +++ b/internal/compiler/parser/listener_helpers.go @@ -581,7 +581,11 @@ func parsePortAddr( } -func parseSinglePortAddr(fallbackNode string, expr generated.ISinglePortAddrContext, meta core.Meta) (src.PortAddr, *compiler.Error) { +func parseSinglePortAddr( + fallbackNode string, + expr generated.ISinglePortAddrContext, + meta core.Meta, +) (src.PortAddr, *compiler.Error) { nodeName := fallbackNode if n := expr.PortAddrNode(); n != nil { nodeName = n.GetText() diff --git a/internal/compiler/sourcecode/scope.go b/internal/compiler/sourcecode/scope.go index e246196b..fada6d21 100644 --- a/internal/compiler/sourcecode/scope.go +++ b/internal/compiler/sourcecode/scope.go @@ -3,6 +3,7 @@ package sourcecode import ( "errors" "fmt" + "path" "github.com/nevalang/neva/internal/compiler/sourcecode/core" ts "github.com/nevalang/neva/internal/compiler/sourcecode/typesystem" @@ -36,10 +37,16 @@ type Location struct { } func (l Location) String() string { + var s string if l.ModRef.Path == "@" { - return fmt.Sprintf("%v/%v.neva", l.PkgName, l.FileName) + s = l.PkgName + } else { + s = path.Join(l.ModRef.String(), l.PkgName) + } + if l.FileName != "" { + s = path.Join(s, l.FileName+".neva") } - return fmt.Sprintf("%v/%v/%v.neva", l.ModRef, l.PkgName, l.FileName) + return s } func (s Scope) IsTopType(expr ts.Expr) bool { diff --git a/std/builtin/streams.neva b/std/builtin/streams.neva index ad0b7235..69171ae9 100644 --- a/std/builtin/streams.neva +++ b/std/builtin/streams.neva @@ -12,7 +12,10 @@ pub interface IPortReducer(seq stream) (res T) // to reducer. When all messages are processed the result is emited to outport. pub component ReducePort([port] T) (res T) { nodes { reducer IPortReducer, streamer StreamPort } - net { :port => streamer -> reducer -> :res } + net { + :port => streamer:data + streamer -> reducer -> :res + } } // IMapper maps input message to output message. From 6beddab454ef9137b8e302d5d0f87cba8be80f13 Mon Sep 17 00:00:00 2001 From: Emil Valeev Date: Tue, 30 Apr 2024 23:09:19 +0500 Subject: [PATCH 3/6] wip(e2e): add missing Println node --- e2e/stream_to_list/main/main.neva | 2 +- std/builtin/types.neva | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/e2e/stream_to_list/main/main.neva b/e2e/stream_to_list/main/main.neva index e352921d..7a17bb4f 100644 --- a/e2e/stream_to_list/main/main.neva +++ b/e2e/stream_to_list/main/main.neva @@ -1,6 +1,6 @@ // TODO move to examples component Main(start) (stop) { - nodes { Range, List } + nodes { Range, List, Println } net { :start -> [ (1 -> range:from), diff --git a/std/builtin/types.neva b/std/builtin/types.neva index 9dfe50c7..f92882d3 100644 --- a/std/builtin/types.neva +++ b/std/builtin/types.neva @@ -4,7 +4,7 @@ type { pub int pub float pub string - pub map + pub map // TODO rename to dict pub list pub maybe From 645dfcfd0d2d1452f9720be04d5c704995c51a8f Mon Sep 17 00:00:00 2001 From: Emil Valeev Date: Wed, 1 May 2024 01:18:38 +0500 Subject: [PATCH 4/6] wip(std): comment out map because it can't be parsed yet --- internal/compiler/analyzer/component_net.go | 2 +- std/builtin/streams.neva | 20 ++++++++++---------- 2 files changed, 11 insertions(+), 11 deletions(-) diff --git a/internal/compiler/analyzer/component_net.go b/internal/compiler/analyzer/component_net.go index c3d06d8d..ffa609ab 100644 --- a/internal/compiler/analyzer/component_net.go +++ b/internal/compiler/analyzer/component_net.go @@ -118,7 +118,7 @@ func (a Analyzer) analyzeConnection( if err != nil { return src.Connection{}, compiler.Error{ Location: &scope.Location, - Meta: &conn.Normal.SenderSide.Meta, + Meta: &conn.Meta, }.Wrap(err) } if !isArray { diff --git a/std/builtin/streams.neva b/std/builtin/streams.neva index 69171ae9..75c88eea 100644 --- a/std/builtin/streams.neva +++ b/std/builtin/streams.neva @@ -13,7 +13,7 @@ pub interface IPortReducer(seq stream) (res T) pub component ReducePort([port] T) (res T) { nodes { reducer IPortReducer, streamer StreamPort } net { - :port => streamer:data + :port => streamer:port streamer -> reducer -> :res } } @@ -22,12 +22,12 @@ pub component ReducePort([port] T) (res T) { pub interface IMapper(data T) (res Y) // Map component maps input stream of messages to output stream of messages. -pub component Map(data stream) (res stream) { - nodes { mapper IMapper, builder Struct } - net { - :data.data -> mapper -> builder:data - :data.idx -> builder:idx - :data.last -> builder:last - builder -> :res - } -} \ No newline at end of file +// pub component Map(data stream) (res stream) { +// nodes { mapper IMapper, builder Struct> } +// net { +// :data.data -> mapper -> builder:data +// :data.idx -> builder:idx +// :data.last -> builder:last +// builder -> :res +// } +// } \ No newline at end of file From 83aa86a8a52f47cdb0d2c2f6924f35b7f70bcbb2 Mon Sep 17 00:00:00 2001 From: Emil Valeev Date: Fri, 3 May 2024 20:28:06 +0500 Subject: [PATCH 5/6] wip(parser): fixing --- .vscode/launch.json | 2 +- examples/split_join_string/main.neva | 2 ++ internal/compiler/parser/parser.go | 10 +++------- 3 files changed, 6 insertions(+), 8 deletions(-) diff --git a/.vscode/launch.json b/.vscode/launch.json index 4ad23b6b..e84d470c 100644 --- a/.vscode/launch.json +++ b/.vscode/launch.json @@ -17,7 +17,7 @@ "mode": "auto", "program": "${workspaceFolder}/cmd/neva", "cwd": "${workspaceFolder}", - "args": ["run", "e2e/stream_to_list/main"] + "args": ["run", "examples/hello_world"] }, { "name": "LSP", diff --git a/examples/split_join_string/main.neva b/examples/split_join_string/main.neva index 7838cdd9..d75efee0 100644 --- a/examples/split_join_string/main.neva +++ b/examples/split_join_string/main.neva @@ -1,3 +1,5 @@ +import { strings } + component Main(start) (stop) { nodes { Println, strings.Split, strings.Join } net { diff --git a/internal/compiler/parser/parser.go b/internal/compiler/parser/parser.go index 533d2cc0..3017e4f8 100644 --- a/internal/compiler/parser/parser.go +++ b/internal/compiler/parser/parser.go @@ -12,7 +12,6 @@ import ( "github.com/nevalang/neva/internal/compiler" generated "github.com/nevalang/neva/internal/compiler/parser/generated" src "github.com/nevalang/neva/internal/compiler/sourcecode" - "github.com/nevalang/neva/internal/compiler/sourcecode/core" ) type treeShapeListener struct { @@ -139,16 +138,13 @@ func (p Parser) parseFile( if len(lexerErrors.Errors) > 0 { return src.File{}, &compiler.Error{ - Err: errors.Join(lexerErrors.Errors...), - Location: &src.Location{}, - Meta: &core.Meta{}, + Err: lexerErrors.Errors[0], } } + if len(parserErrors.Errors) > 0 { return src.File{}, &compiler.Error{ - Err: errors.Join(parserErrors.Errors...), - Location: &src.Location{}, - Meta: &core.Meta{}, + Err: parserErrors.Errors[0], } } From 45347e423dc50a766e39140e04287fe2bc2ed66a Mon Sep 17 00:00:00 2001 From: Emil Valeev Date: Fri, 3 May 2024 20:36:50 +0500 Subject: [PATCH 6/6] fix(examples,e2e): import do not support ',' --- e2e/add_nums_from_stdin_naive/main/main.neva | 5 ++++- e2e/add_nums_from_stdin_with_default_any/main.neva | 5 ++++- e2e/add_nums_from_stdin_with_err_handling/main/main.neva | 5 ++++- e2e/add_nums_from_stdin_with_multuple_senders/main/main.neva | 5 ++++- e2e/add_nums_from_stdin_with_sub_components/main/main.neva | 5 ++++- examples/add_numbers_from_stdin/main.neva | 5 ++++- 6 files changed, 24 insertions(+), 6 deletions(-) diff --git a/e2e/add_nums_from_stdin_naive/main/main.neva b/e2e/add_nums_from_stdin_naive/main/main.neva index 4388b019..cf754b3f 100644 --- a/e2e/add_nums_from_stdin_naive/main/main.neva +++ b/e2e/add_nums_from_stdin_naive/main/main.neva @@ -1,4 +1,7 @@ -import { io, strconv } +import { + io + strconv +} component Main(start any) (stop any) { nodes { diff --git a/e2e/add_nums_from_stdin_with_default_any/main.neva b/e2e/add_nums_from_stdin_with_default_any/main.neva index 8054dd60..084035b4 100644 --- a/e2e/add_nums_from_stdin_with_default_any/main.neva +++ b/e2e/add_nums_from_stdin_with_default_any/main.neva @@ -1,4 +1,7 @@ -import { io, strconv } +import { + io + strconv +} component { Main(start) (stop) { diff --git a/e2e/add_nums_from_stdin_with_err_handling/main/main.neva b/e2e/add_nums_from_stdin_with_err_handling/main/main.neva index 91061f78..bfb4b32c 100644 --- a/e2e/add_nums_from_stdin_with_err_handling/main/main.neva +++ b/e2e/add_nums_from_stdin_with_err_handling/main/main.neva @@ -1,4 +1,7 @@ -import { io, strconv } +import { + io + strconv +} component Main(start any) (stop any) { nodes { diff --git a/e2e/add_nums_from_stdin_with_multuple_senders/main/main.neva b/e2e/add_nums_from_stdin_with_multuple_senders/main/main.neva index a7f8c540..3b3208e8 100644 --- a/e2e/add_nums_from_stdin_with_multuple_senders/main/main.neva +++ b/e2e/add_nums_from_stdin_with_multuple_senders/main/main.neva @@ -1,4 +1,7 @@ -import { io, strconv } +import { + io + strconv +} component { Main(start) (stop) { diff --git a/e2e/add_nums_from_stdin_with_sub_components/main/main.neva b/e2e/add_nums_from_stdin_with_sub_components/main/main.neva index a3003244..c2924149 100644 --- a/e2e/add_nums_from_stdin_with_sub_components/main/main.neva +++ b/e2e/add_nums_from_stdin_with_sub_components/main/main.neva @@ -1,4 +1,7 @@ -import { io, strconv } +import { + io + strconv +} component { Main(start any) (stop any) { diff --git a/examples/add_numbers_from_stdin/main.neva b/examples/add_numbers_from_stdin/main.neva index dab64e5b..e280011a 100644 --- a/examples/add_numbers_from_stdin/main.neva +++ b/examples/add_numbers_from_stdin/main.neva @@ -1,4 +1,7 @@ -import { io, strconv } +import { + io + strconv +} component { Main(start) (stop) {