From 5346b91cc2412076f46c2e9a7887a667e0472ff9 Mon Sep 17 00:00:00 2001 From: overflowerror Date: Sun, 5 May 2024 22:14:12 +0200 Subject: [PATCH] feat: Add rmap - reverse map builtin --- compiler/src/ast.c | 3 +- compiler/src/ast.h | 3 +- compiler/src/codegen_stat.c | 20 +++++++++--- compiler/src/lexer.l | 2 ++ compiler/src/parser.y | 7 ++++- compiler/test/cases/023a-rmap-array-print.in | 6 ++++ compiler/test/cases/023a-rmap-array-print.out | 14 +++++++++ .../test/cases/023b-rmap-array-index-print.in | 5 +++ .../cases/023b-rmap-array-index-print.out | 6 ++++ .../test/cases/023c-rmap-array-modify-ref.in | 7 +++++ .../test/cases/023c-rmap-array-modify-ref.out | 6 ++++ compiler/test/cases/023d-rmap-str-print.in | 9 ++++++ compiler/test/cases/023d-rmap-str-print.out | 31 +++++++++++++++++++ .../test/cases/023e-rmap-extract-value.in | 11 +++++++ .../test/cases/023e-rmap-extract-value.out | 10 ++++++ 15 files changed, 133 insertions(+), 7 deletions(-) create mode 100644 compiler/test/cases/023a-rmap-array-print.in create mode 100644 compiler/test/cases/023a-rmap-array-print.out create mode 100644 compiler/test/cases/023b-rmap-array-index-print.in create mode 100644 compiler/test/cases/023b-rmap-array-index-print.out create mode 100644 compiler/test/cases/023c-rmap-array-modify-ref.in create mode 100644 compiler/test/cases/023c-rmap-array-modify-ref.out create mode 100644 compiler/test/cases/023d-rmap-str-print.in create mode 100644 compiler/test/cases/023d-rmap-str-print.out create mode 100644 compiler/test/cases/023e-rmap-extract-value.in create mode 100644 compiler/test/cases/023e-rmap-extract-value.out diff --git a/compiler/src/ast.c b/compiler/src/ast.c index 08a27bd..70189c5 100644 --- a/compiler/src/ast.c +++ b/compiler/src/ast.c @@ -79,7 +79,7 @@ struct statement* while_statement_new(struct expression* condition, struct block return stat; } -struct statement* map_statement_new(char* index_id, char* ref_id, char* list_id, struct block* block) { +struct statement* map_statement_new(char* index_id, char* ref_id, char* list_id, struct block* block, bool reverse) { _new(stat, statement); stat->kind = MAP_STATEMENT; stat->map_loop = (struct map_statement) { @@ -87,6 +87,7 @@ struct statement* map_statement_new(char* index_id, char* ref_id, char* list_id, .ref_id = ref_id, .list_id = list_id, .block = block, + .reverse = reverse, }; return stat; } diff --git a/compiler/src/ast.h b/compiler/src/ast.h index 5ef6cb0..5ce7a90 100644 --- a/compiler/src/ast.h +++ b/compiler/src/ast.h @@ -123,6 +123,7 @@ struct map_statement { char* ref_id; char* list_id; struct block* block; + bool reverse; }; struct expr_statement { @@ -153,7 +154,7 @@ struct statement* assignment_statement_new(struct expression*, struct expression struct statement* expr_statement_new(struct expression*); struct statement* if_statement_new(struct expression*, struct block*, struct block*); struct statement* while_statement_new(struct expression*, struct block*); -struct statement* map_statement_new(char*, char*, char*, struct block*); +struct statement* map_statement_new(char*, char*, char*, struct block*, bool); struct expression* literal_expression_char_new(char); struct expression* literal_expression_str_new(char*); diff --git a/compiler/src/codegen_stat.c b/compiler/src/codegen_stat.c index 284ef60..9a6c05c 100644 --- a/compiler/src/codegen_stat.c +++ b/compiler/src/codegen_stat.c @@ -164,10 +164,22 @@ static void codegen_map_statement(FILE* out, scope_t* scope, struct map_statemen region_t* value = scope_add_ref(local_scope, list, 0, 1); scope_existing(local_scope, value, statement.ref_id); - for (size_t i = 0; i < list->size; i++) { - codegen_block(out, local_scope, statement.block); - value->start++; - move_to(index); inc(); + if (statement.reverse) { + move_to(index); add(list->size - 1); + value->start += list->size - 1; + for (long long i = list->size - 1; i >= 0; i--) { + codegen_block(out, local_scope, statement.block); + value->start--; + move_to(index); + dec(); + } + } else { + for (size_t i = 0; i < list->size; i++) { + codegen_block(out, local_scope, statement.block); + value->start++; + move_to(index); + inc(); + } } scope_free(local_scope); diff --git a/compiler/src/lexer.l b/compiler/src/lexer.l index 1ba8b03..8a6daad 100644 --- a/compiler/src/lexer.l +++ b/compiler/src/lexer.l @@ -10,6 +10,7 @@ if "if" else "else" while "while" map "map" +rmap "rmap" in "in" char "'"([^\\]|[\\]n|[\\]t|[\\]{2})"'" @@ -82,6 +83,7 @@ strbuf_t strbuf = NULL; {else} { return ELSE; } {while} { return WHILE; } {map} { return MAP; } +{rmap} { return RMAP; } {in} { return IN; } "=" { return ASSIGNMENT; } diff --git a/compiler/src/parser.y b/compiler/src/parser.y index 969d806..a32d608 100644 --- a/compiler/src/parser.y +++ b/compiler/src/parser.y @@ -73,6 +73,7 @@ extern struct block* program; %token ELSE %token WHILE %token MAP +%token RMAP %token IN %start file @@ -145,7 +146,11 @@ while: WHILE expr block map: MAP OPENING_BRACKETS ID COMMA ID IN ID CLOSING_BRACKETS block { - $$ = map_statement_new($3, $5, $7, $9); + $$ = map_statement_new($3, $5, $7, $9, false); + } + | RMAP OPENING_BRACKETS ID COMMA ID IN ID CLOSING_BRACKETS block + { + $$ = map_statement_new($3, $5, $7, $9, true); } ; diff --git a/compiler/test/cases/023a-rmap-array-print.in b/compiler/test/cases/023a-rmap-array-print.in new file mode 100644 index 0000000..2e4764e --- /dev/null +++ b/compiler/test/cases/023a-rmap-array-print.in @@ -0,0 +1,6 @@ +var list = []{'f', 'o', 'o', 'b', 'a', 'r'}; + +rmap(_, value in list) { + print(value); + print('\n'); +} \ No newline at end of file diff --git a/compiler/test/cases/023a-rmap-array-print.out b/compiler/test/cases/023a-rmap-array-print.out new file mode 100644 index 0000000..2ab5066 --- /dev/null +++ b/compiler/test/cases/023a-rmap-array-print.out @@ -0,0 +1,14 @@ +>>>>>>[-]++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++>[-]<[-<<<<<<+>>>>>>>+<]>[-<+>]<[-]+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++>[-]<[-<<<<<+>>>>>>+<]>[-<+>]<[-]+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++>[-]<[-<<<<+>>>>>+<]>[-<+>]<[-]++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++>[-]<[-<<<+>>>>+<]>[-<+>]<[-]+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++>[-]<[-<<+>>>+<]>[-<+>]<[-]++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++>[-]<[-<+>>+<]>[-<+>] +<[-]+++++<. +>>[-]++++++++++. +<-<<. +>>>[-]++++++++++. +<-<<<. +>>>>[-]++++++++++. +<-<<<<. +>>>>>[-]++++++++++. +<-<<<<<. +>>>>>>[-]++++++++++. +<-<<<<<<. +>>>>>>>[-]++++++++++. +<- diff --git a/compiler/test/cases/023b-rmap-array-index-print.in b/compiler/test/cases/023b-rmap-array-index-print.in new file mode 100644 index 0000000..c75b503 --- /dev/null +++ b/compiler/test/cases/023b-rmap-array-index-print.in @@ -0,0 +1,5 @@ +var list = []{0, 0, 0, 0}; + +rmap(index, _ in list) { + print(to_str(index), '\n'); +} \ No newline at end of file diff --git a/compiler/test/cases/023b-rmap-array-index-print.out b/compiler/test/cases/023b-rmap-array-index-print.out new file mode 100644 index 0000000..1b010f6 --- /dev/null +++ b/compiler/test/cases/023b-rmap-array-index-print.out @@ -0,0 +1,6 @@ +>>>>[-]>[-]<[-<<<<+>>>>>+<]>[-<+>]<[-]>[-]<[-<<<+>>>>+<]>[-<+>]<[-]>[-]<[-<<+>>>+<]>[-<+>]<[-]>[-]<[-<+>>+<]>[-<+>] +<[-]+++>[-]>[-]>[-]>[-]>[-]++++++++++>[-]>[-]<<<<<<<[->>>>>>+<<+<+<[-]<[-]>>>>-[-<<<<+>+>>>]<<<[>>>>[-]<<<<[-]]<[->>>>+<<<<]>>>>>[>+<<<<[-]>>++++++++++>[-]]<<<<<<]>>>>[-<<<<+>>>>]>[-]++++++++++>>[-<[-]+<<<<+>>[-]>>>>[-]<<<-[-<+>>>>+<<<]>>>[<<[-]>>[-]]<<<<[->+<]>>[<++++++++++<<<<+>[-]>>>>[-]]>]<<<<<<++++++++++++++++++++++++++++++++++++++++++++++++>++++++++++++++++++++++++++++++++++++++++++++++++>++++++++++++++++++++++++++++++++++++++++++++++++>[-]++++++++++<<<.>.>.>. +<<<<->[-]>[-]>[-]>[-]>[-]++++++++++>[-]>[-]<<<<<<<[->>>>>>+<<+<+<[-]<[-]>>>>-[-<<<<+>+>>>]<<<[>>>>[-]<<<<[-]]<[->>>>+<<<<]>>>>>[>+<<<<[-]>>++++++++++>[-]]<<<<<<]>>>>[-<<<<+>>>>]>[-]++++++++++>>[-<[-]+<<<<+>>[-]>>>>[-]<<<-[-<+>>>>+<<<]>>>[<<[-]>>[-]]<<<<[->+<]>>[<++++++++++<<<<+>[-]>>>>[-]]>]<<<<<<++++++++++++++++++++++++++++++++++++++++++++++++>++++++++++++++++++++++++++++++++++++++++++++++++>++++++++++++++++++++++++++++++++++++++++++++++++>[-]++++++++++<<<.>.>.>. +<<<<->[-]>[-]>[-]>[-]>[-]++++++++++>[-]>[-]<<<<<<<[->>>>>>+<<+<+<[-]<[-]>>>>-[-<<<<+>+>>>]<<<[>>>>[-]<<<<[-]]<[->>>>+<<<<]>>>>>[>+<<<<[-]>>++++++++++>[-]]<<<<<<]>>>>[-<<<<+>>>>]>[-]++++++++++>>[-<[-]+<<<<+>>[-]>>>>[-]<<<-[-<+>>>>+<<<]>>>[<<[-]>>[-]]<<<<[->+<]>>[<++++++++++<<<<+>[-]>>>>[-]]>]<<<<<<++++++++++++++++++++++++++++++++++++++++++++++++>++++++++++++++++++++++++++++++++++++++++++++++++>++++++++++++++++++++++++++++++++++++++++++++++++>[-]++++++++++<<<.>.>.>. +<<<<->[-]>[-]>[-]>[-]>[-]++++++++++>[-]>[-]<<<<<<<[->>>>>>+<<+<+<[-]<[-]>>>>-[-<<<<+>+>>>]<<<[>>>>[-]<<<<[-]]<[->>>>+<<<<]>>>>>[>+<<<<[-]>>++++++++++>[-]]<<<<<<]>>>>[-<<<<+>>>>]>[-]++++++++++>>[-<[-]+<<<<+>>[-]>>>>[-]<<<-[-<+>>>>+<<<]>>>[<<[-]>>[-]]<<<<[->+<]>>[<++++++++++<<<<+>[-]>>>>[-]]>]<<<<<<++++++++++++++++++++++++++++++++++++++++++++++++>++++++++++++++++++++++++++++++++++++++++++++++++>++++++++++++++++++++++++++++++++++++++++++++++++>[-]++++++++++<<<.>.>.>. +<<<<- diff --git a/compiler/test/cases/023c-rmap-array-modify-ref.in b/compiler/test/cases/023c-rmap-array-modify-ref.in new file mode 100644 index 0000000..706e6f3 --- /dev/null +++ b/compiler/test/cases/023c-rmap-array-modify-ref.in @@ -0,0 +1,7 @@ +var list = []{'e', 'n', 'n'}; + +rmap(_, value in list) { + value = (value + 1); +} + +print(list, '\n'); \ No newline at end of file diff --git a/compiler/test/cases/023c-rmap-array-modify-ref.out b/compiler/test/cases/023c-rmap-array-modify-ref.out new file mode 100644 index 0000000..54ee896 --- /dev/null +++ b/compiler/test/cases/023c-rmap-array-modify-ref.out @@ -0,0 +1,6 @@ +>>>[-]+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++>[-]<[-<<<+>>>>+<]>[-<+>]<[-]++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++>[-]<[-<<+>>>+<]>[-<+>]<[-]++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++>[-]<[-<+>>+<]>[-<+>] +<[-]++>[-]+>[-]>[-]<<<<[->>>+>+<<<<]>>>>[-<<<<+>>>>]<[-<+>]<<<[-]>>>[-]<[-<<+>>>+<]>[-<+>] +<<->[-]+>[-]>[-]<<<<<[->>>>+>+<<<<<]>>>>>[-<<<<<+>>>>>]<[-<+>]<<<<[-]>>>>[-]<[-<<<+>>>>+<]>[-<+>] +<<->[-]+>[-]>[-]<<<<<<[->>>>>+>+<<<<<<]>>>>>>[-<<<<<<+>>>>>>]<[-<+>]<<<<<[-]>>>>>[-]<[-<<<<+>>>>>+<]>[-<+>] +<<- +[-]++++++++++<<<.>.>.>. diff --git a/compiler/test/cases/023d-rmap-str-print.in b/compiler/test/cases/023d-rmap-str-print.in new file mode 100644 index 0000000..0b4f994 --- /dev/null +++ b/compiler/test/cases/023d-rmap-str-print.in @@ -0,0 +1,9 @@ +var s = "hello, world!\n"; + +rmap(_, c in s) { + if ((c >= 'a') && (c <= 'z')) { + c = ((c - 'a') + 'A'); + } +} + +print(s); \ No newline at end of file diff --git a/compiler/test/cases/023d-rmap-str-print.out b/compiler/test/cases/023d-rmap-str-print.out new file mode 100644 index 0000000..7d421fe --- /dev/null +++ b/compiler/test/cases/023d-rmap-str-print.out @@ -0,0 +1,31 @@ +[-]++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++>[-]+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++>[-]++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++>[-]++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++>[-]+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++>[-]++++++++++++++++++++++++++++++++++++++++++++>[-]++++++++++++++++++++++++++++++++>[-]+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++>[-]+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++>[-]++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++>[-]++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++>[-]++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++>[-]+++++++++++++++++++++++++++++++++>[-]++++++++++ +>[-]+++++++++++++>[-]+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++>[-]>[-]<<<<[->>>+>+<<<<]>>>>[-<<<<+>>>>][-]+<<[->>>>[-]+<[-]<<[>>+>[-]<<<-]>>[<<+>>-]<<->>>[<<[-]<<[-]>>>>-]<<<<][-]++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++>[-]>>[-]<<<<<[->>>+>>+<<<<<]>>>>>[-<<<<<+>>>>>][-]+<<[->>>>[-]+<[-]<<<<[>>>>+>[-]<<<<<-]>>>>[<<<<+>>>>-]<<<<->>>>>[<<[-]<<[-]>>>>-]<<<<]<[-]>>[>[<<<+>>>[-]]<[-]]<<[>[-]+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++>[-]>[-]<<<<<[->>>>+>+<<<<<]>>>>>[-<<<<<+>>>>>]<<[->-<][-]+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++[->+<]<<<[-]>>>[-]>[-<<<<+>>>+>]<[->+<] +<[-]] +<->[-]+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++>[-]>[-]<<<<<[->>>>+>+<<<<<]>>>>>[-<<<<<+>>>>>][-]+<<[->>>>[-]+<[-]<<[>>+>[-]<<<-]>>[<<+>>-]<<->>>[<<[-]<<[-]>>>>-]<<<<][-]++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++>[-]>>[-]<<<<<<[->>>>+>>+<<<<<<]>>>>>>[-<<<<<<+>>>>>>][-]+<<[->>>>[-]+<[-]<<<<[>>>>+>[-]<<<<<-]>>>>[<<<<+>>>>-]<<<<->>>>>[<<[-]<<[-]>>>>-]<<<<]<[-]>>[>[<<<+>>>[-]]<[-]]<<[>[-]+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++>[-]>[-]<<<<<<[->>>>>+>+<<<<<<]>>>>>>[-<<<<<<+>>>>>>]<<[->-<][-]+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++[->+<]<<<<[-]>>>>[-]>[-<<<<<+>>>>+>]<[->+<] +<[-]] +<->[-]+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++>[-]>[-]<<<<<<[->>>>>+>+<<<<<<]>>>>>>[-<<<<<<+>>>>>>][-]+<<[->>>>[-]+<[-]<<[>>+>[-]<<<-]>>[<<+>>-]<<->>>[<<[-]<<[-]>>>>-]<<<<][-]++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++>[-]>>[-]<<<<<<<[->>>>>+>>+<<<<<<<]>>>>>>>[-<<<<<<<+>>>>>>>][-]+<<[->>>>[-]+<[-]<<<<[>>>>+>[-]<<<<<-]>>>>[<<<<+>>>>-]<<<<->>>>>[<<[-]<<[-]>>>>-]<<<<]<[-]>>[>[<<<+>>>[-]]<[-]]<<[>[-]+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++>[-]>[-]<<<<<<<[->>>>>>+>+<<<<<<<]>>>>>>>[-<<<<<<<+>>>>>>>]<<[->-<][-]+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++[->+<]<<<<<[-]>>>>>[-]>[-<<<<<<+>>>>>+>]<[->+<] +<[-]] +<->[-]+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++>[-]>[-]<<<<<<<[->>>>>>+>+<<<<<<<]>>>>>>>[-<<<<<<<+>>>>>>>][-]+<<[->>>>[-]+<[-]<<[>>+>[-]<<<-]>>[<<+>>-]<<->>>[<<[-]<<[-]>>>>-]<<<<][-]++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++>[-]>>[-]<<<<<<<<[->>>>>>+>>+<<<<<<<<]>>>>>>>>[-<<<<<<<<+>>>>>>>>][-]+<<[->>>>[-]+<[-]<<<<[>>>>+>[-]<<<<<-]>>>>[<<<<+>>>>-]<<<<->>>>>[<<[-]<<[-]>>>>-]<<<<]<[-]>>[>[<<<+>>>[-]]<[-]]<<[>[-]+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++>[-]>[-]<<<<<<<<[->>>>>>>+>+<<<<<<<<]>>>>>>>>[-<<<<<<<<+>>>>>>>>]<<[->-<][-]+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++[->+<]<<<<<<[-]>>>>>>[-]>[-<<<<<<<+>>>>>>+>]<[->+<] +<[-]] +<->[-]+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++>[-]>[-]<<<<<<<<[->>>>>>>+>+<<<<<<<<]>>>>>>>>[-<<<<<<<<+>>>>>>>>][-]+<<[->>>>[-]+<[-]<<[>>+>[-]<<<-]>>[<<+>>-]<<->>>[<<[-]<<[-]>>>>-]<<<<][-]++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++>[-]>>[-]<<<<<<<<<[->>>>>>>+>>+<<<<<<<<<]>>>>>>>>>[-<<<<<<<<<+>>>>>>>>>][-]+<<[->>>>[-]+<[-]<<<<[>>>>+>[-]<<<<<-]>>>>[<<<<+>>>>-]<<<<->>>>>[<<[-]<<[-]>>>>-]<<<<]<[-]>>[>[<<<+>>>[-]]<[-]]<<[>[-]+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++>[-]>[-]<<<<<<<<<[->>>>>>>>+>+<<<<<<<<<]>>>>>>>>>[-<<<<<<<<<+>>>>>>>>>]<<[->-<][-]+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++[->+<]<<<<<<<[-]>>>>>>>[-]>[-<<<<<<<<+>>>>>>>+>]<[->+<] +<[-]] +<->[-]+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++>[-]>[-]<<<<<<<<<[->>>>>>>>+>+<<<<<<<<<]>>>>>>>>>[-<<<<<<<<<+>>>>>>>>>][-]+<<[->>>>[-]+<[-]<<[>>+>[-]<<<-]>>[<<+>>-]<<->>>[<<[-]<<[-]>>>>-]<<<<][-]++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++>[-]>>[-]<<<<<<<<<<[->>>>>>>>+>>+<<<<<<<<<<]>>>>>>>>>>[-<<<<<<<<<<+>>>>>>>>>>][-]+<<[->>>>[-]+<[-]<<<<[>>>>+>[-]<<<<<-]>>>>[<<<<+>>>>-]<<<<->>>>>[<<[-]<<[-]>>>>-]<<<<]<[-]>>[>[<<<+>>>[-]]<[-]]<<[>[-]+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++>[-]>[-]<<<<<<<<<<[->>>>>>>>>+>+<<<<<<<<<<]>>>>>>>>>>[-<<<<<<<<<<+>>>>>>>>>>]<<[->-<][-]+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++[->+<]<<<<<<<<[-]>>>>>>>>[-]>[-<<<<<<<<<+>>>>>>>>+>]<[->+<] +<[-]] +<->[-]+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++>[-]>[-]<<<<<<<<<<[->>>>>>>>>+>+<<<<<<<<<<]>>>>>>>>>>[-<<<<<<<<<<+>>>>>>>>>>][-]+<<[->>>>[-]+<[-]<<[>>+>[-]<<<-]>>[<<+>>-]<<->>>[<<[-]<<[-]>>>>-]<<<<][-]++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++>[-]>>[-]<<<<<<<<<<<[->>>>>>>>>+>>+<<<<<<<<<<<]>>>>>>>>>>>[-<<<<<<<<<<<+>>>>>>>>>>>][-]+<<[->>>>[-]+<[-]<<<<[>>>>+>[-]<<<<<-]>>>>[<<<<+>>>>-]<<<<->>>>>[<<[-]<<[-]>>>>-]<<<<]<[-]>>[>[<<<+>>>[-]]<[-]]<<[>[-]+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++>[-]>[-]<<<<<<<<<<<[->>>>>>>>>>+>+<<<<<<<<<<<]>>>>>>>>>>>[-<<<<<<<<<<<+>>>>>>>>>>>]<<[->-<][-]+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++[->+<]<<<<<<<<<[-]>>>>>>>>>[-]>[-<<<<<<<<<<+>>>>>>>>>+>]<[->+<] +<[-]] +<->[-]+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++>[-]>[-]<<<<<<<<<<<[->>>>>>>>>>+>+<<<<<<<<<<<]>>>>>>>>>>>[-<<<<<<<<<<<+>>>>>>>>>>>][-]+<<[->>>>[-]+<[-]<<[>>+>[-]<<<-]>>[<<+>>-]<<->>>[<<[-]<<[-]>>>>-]<<<<][-]++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++>[-]>>[-]<<<<<<<<<<<<[->>>>>>>>>>+>>+<<<<<<<<<<<<]>>>>>>>>>>>>[-<<<<<<<<<<<<+>>>>>>>>>>>>][-]+<<[->>>>[-]+<[-]<<<<[>>>>+>[-]<<<<<-]>>>>[<<<<+>>>>-]<<<<->>>>>[<<[-]<<[-]>>>>-]<<<<]<[-]>>[>[<<<+>>>[-]]<[-]]<<[>[-]+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++>[-]>[-]<<<<<<<<<<<<[->>>>>>>>>>>+>+<<<<<<<<<<<<]>>>>>>>>>>>>[-<<<<<<<<<<<<+>>>>>>>>>>>>]<<[->-<][-]+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++[->+<]<<<<<<<<<<[-]>>>>>>>>>>[-]>[-<<<<<<<<<<<+>>>>>>>>>>+>]<[->+<] +<[-]] +<->[-]+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++>[-]>[-]<<<<<<<<<<<<[->>>>>>>>>>>+>+<<<<<<<<<<<<]>>>>>>>>>>>>[-<<<<<<<<<<<<+>>>>>>>>>>>>][-]+<<[->>>>[-]+<[-]<<[>>+>[-]<<<-]>>[<<+>>-]<<->>>[<<[-]<<[-]>>>>-]<<<<][-]++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++>[-]>>[-]<<<<<<<<<<<<<[->>>>>>>>>>>+>>+<<<<<<<<<<<<<]>>>>>>>>>>>>>[-<<<<<<<<<<<<<+>>>>>>>>>>>>>][-]+<<[->>>>[-]+<[-]<<<<[>>>>+>[-]<<<<<-]>>>>[<<<<+>>>>-]<<<<->>>>>[<<[-]<<[-]>>>>-]<<<<]<[-]>>[>[<<<+>>>[-]]<[-]]<<[>[-]+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++>[-]>[-]<<<<<<<<<<<<<[->>>>>>>>>>>>+>+<<<<<<<<<<<<<]>>>>>>>>>>>>>[-<<<<<<<<<<<<<+>>>>>>>>>>>>>]<<[->-<][-]+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++[->+<]<<<<<<<<<<<[-]>>>>>>>>>>>[-]>[-<<<<<<<<<<<<+>>>>>>>>>>>+>]<[->+<] +<[-]] +<->[-]+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++>[-]>[-]<<<<<<<<<<<<<[->>>>>>>>>>>>+>+<<<<<<<<<<<<<]>>>>>>>>>>>>>[-<<<<<<<<<<<<<+>>>>>>>>>>>>>][-]+<<[->>>>[-]+<[-]<<[>>+>[-]<<<-]>>[<<+>>-]<<->>>[<<[-]<<[-]>>>>-]<<<<][-]++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++>[-]>>[-]<<<<<<<<<<<<<<[->>>>>>>>>>>>+>>+<<<<<<<<<<<<<<]>>>>>>>>>>>>>>[-<<<<<<<<<<<<<<+>>>>>>>>>>>>>>][-]+<<[->>>>[-]+<[-]<<<<[>>>>+>[-]<<<<<-]>>>>[<<<<+>>>>-]<<<<->>>>>[<<[-]<<[-]>>>>-]<<<<]<[-]>>[>[<<<+>>>[-]]<[-]]<<[>[-]+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++>[-]>[-]<<<<<<<<<<<<<<[->>>>>>>>>>>>>+>+<<<<<<<<<<<<<<]>>>>>>>>>>>>>>[-<<<<<<<<<<<<<<+>>>>>>>>>>>>>>]<<[->-<][-]+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++[->+<]<<<<<<<<<<<<[-]>>>>>>>>>>>>[-]>[-<<<<<<<<<<<<<+>>>>>>>>>>>>+>]<[->+<] +<[-]] +<->[-]+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++>[-]>[-]<<<<<<<<<<<<<<[->>>>>>>>>>>>>+>+<<<<<<<<<<<<<<]>>>>>>>>>>>>>>[-<<<<<<<<<<<<<<+>>>>>>>>>>>>>>][-]+<<[->>>>[-]+<[-]<<[>>+>[-]<<<-]>>[<<+>>-]<<->>>[<<[-]<<[-]>>>>-]<<<<][-]++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++>[-]>>[-]<<<<<<<<<<<<<<<[->>>>>>>>>>>>>+>>+<<<<<<<<<<<<<<<]>>>>>>>>>>>>>>>[-<<<<<<<<<<<<<<<+>>>>>>>>>>>>>>>][-]+<<[->>>>[-]+<[-]<<<<[>>>>+>[-]<<<<<-]>>>>[<<<<+>>>>-]<<<<->>>>>[<<[-]<<[-]>>>>-]<<<<]<[-]>>[>[<<<+>>>[-]]<[-]]<<[>[-]+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++>[-]>[-]<<<<<<<<<<<<<<<[->>>>>>>>>>>>>>+>+<<<<<<<<<<<<<<<]>>>>>>>>>>>>>>>[-<<<<<<<<<<<<<<<+>>>>>>>>>>>>>>>]<<[->-<][-]+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++[->+<]<<<<<<<<<<<<<[-]>>>>>>>>>>>>>[-]>[-<<<<<<<<<<<<<<+>>>>>>>>>>>>>+>]<[->+<] +<[-]] +<->[-]+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++>[-]>[-]<<<<<<<<<<<<<<<[->>>>>>>>>>>>>>+>+<<<<<<<<<<<<<<<]>>>>>>>>>>>>>>>[-<<<<<<<<<<<<<<<+>>>>>>>>>>>>>>>][-]+<<[->>>>[-]+<[-]<<[>>+>[-]<<<-]>>[<<+>>-]<<->>>[<<[-]<<[-]>>>>-]<<<<][-]++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++>[-]>>[-]<<<<<<<<<<<<<<<<[->>>>>>>>>>>>>>+>>+<<<<<<<<<<<<<<<<]>>>>>>>>>>>>>>>>[-<<<<<<<<<<<<<<<<+>>>>>>>>>>>>>>>>][-]+<<[->>>>[-]+<[-]<<<<[>>>>+>[-]<<<<<-]>>>>[<<<<+>>>>-]<<<<->>>>>[<<[-]<<[-]>>>>-]<<<<]<[-]>>[>[<<<+>>>[-]]<[-]]<<[>[-]+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++>[-]>[-]<<<<<<<<<<<<<<<<[->>>>>>>>>>>>>>>+>+<<<<<<<<<<<<<<<<]>>>>>>>>>>>>>>>>[-<<<<<<<<<<<<<<<<+>>>>>>>>>>>>>>>>]<<[->-<][-]+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++[->+<]<<<<<<<<<<<<<<[-]>>>>>>>>>>>>>>[-]>[-<<<<<<<<<<<<<<<+>>>>>>>>>>>>>>+>]<[->+<] +<[-]] +<->[-]+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++>[-]>[-]<<<<<<<<<<<<<<<<[->>>>>>>>>>>>>>>+>+<<<<<<<<<<<<<<<<]>>>>>>>>>>>>>>>>[-<<<<<<<<<<<<<<<<+>>>>>>>>>>>>>>>>][-]+<<[->>>>[-]+<[-]<<[>>+>[-]<<<-]>>[<<+>>-]<<->>>[<<[-]<<[-]>>>>-]<<<<][-]++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++>[-]>>[-]<<<<<<<<<<<<<<<<<[->>>>>>>>>>>>>>>+>>+<<<<<<<<<<<<<<<<<]>>>>>>>>>>>>>>>>>[-<<<<<<<<<<<<<<<<<+>>>>>>>>>>>>>>>>>][-]+<<[->>>>[-]+<[-]<<<<[>>>>+>[-]<<<<<-]>>>>[<<<<+>>>>-]<<<<->>>>>[<<[-]<<[-]>>>>-]<<<<]<[-]>>[>[<<<+>>>[-]]<[-]]<<[>[-]+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++>[-]>[-]<<<<<<<<<<<<<<<<<[->>>>>>>>>>>>>>>>+>+<<<<<<<<<<<<<<<<<]>>>>>>>>>>>>>>>>>[-<<<<<<<<<<<<<<<<<+>>>>>>>>>>>>>>>>>]<<[->-<][-]+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++[->+<]<<<<<<<<<<<<<<<[-]>>>>>>>>>>>>>>>[-]>[-<<<<<<<<<<<<<<<<+>>>>>>>>>>>>>>>+>]<[->+<] +<[-]] +<->[-]+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++>[-]>[-]<<<<<<<<<<<<<<<<<[->>>>>>>>>>>>>>>>+>+<<<<<<<<<<<<<<<<<]>>>>>>>>>>>>>>>>>[-<<<<<<<<<<<<<<<<<+>>>>>>>>>>>>>>>>>][-]+<<[->>>>[-]+<[-]<<[>>+>[-]<<<-]>>[<<+>>-]<<->>>[<<[-]<<[-]>>>>-]<<<<][-]++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++>[-]>>[-]<<<<<<<<<<<<<<<<<<[->>>>>>>>>>>>>>>>+>>+<<<<<<<<<<<<<<<<<<]>>>>>>>>>>>>>>>>>>[-<<<<<<<<<<<<<<<<<<+>>>>>>>>>>>>>>>>>>][-]+<<[->>>>[-]+<[-]<<<<[>>>>+>[-]<<<<<-]>>>>[<<<<+>>>>-]<<<<->>>>>[<<[-]<<[-]>>>>-]<<<<]<[-]>>[>[<<<+>>>[-]]<[-]]<<[>[-]+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++>[-]>[-]<<<<<<<<<<<<<<<<<<[->>>>>>>>>>>>>>>>>+>+<<<<<<<<<<<<<<<<<<]>>>>>>>>>>>>>>>>>>[-<<<<<<<<<<<<<<<<<<+>>>>>>>>>>>>>>>>>>]<<[->-<][-]+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++[->+<]<<<<<<<<<<<<<<<<[-]>>>>>>>>>>>>>>>>[-]>[-<<<<<<<<<<<<<<<<<+>>>>>>>>>>>>>>>>+>]<[->+<] +<[-]] +<- +<<<<<<<<<<<<<<.>.>.>.>.>.>.>.>.>.>.>.>.>. diff --git a/compiler/test/cases/023e-rmap-extract-value.in b/compiler/test/cases/023e-rmap-extract-value.in new file mode 100644 index 0000000..e66d512 --- /dev/null +++ b/compiler/test/cases/023e-rmap-extract-value.in @@ -0,0 +1,11 @@ +var a = []{'a', 'b', 'c'}; + +var extract = 0; + +rmap(i, v in a) { + if (i == 1) { + extract = v; + } +} + +print(extract, '\n'); \ No newline at end of file diff --git a/compiler/test/cases/023e-rmap-extract-value.out b/compiler/test/cases/023e-rmap-extract-value.out new file mode 100644 index 0000000..1558b6f --- /dev/null +++ b/compiler/test/cases/023e-rmap-extract-value.out @@ -0,0 +1,10 @@ +>>>[-]+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++>[-]<[-<<<+>>>>+<]>[-<+>]<[-]++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++>[-]<[-<<+>>>+<]>[-<+>]<[-]+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++>[-]<[-<+>>+<]>[-<+>] +<[-] +>[-]++>[-]+>[-]>[-]<<<[->>+>+<<<]>>>[-<<<+>>>]<<[->-<]+>[<->[-]]<[<<[-]>>>[-]<<<<[->+>>>+<<<<]>>>>[-<<<<+>>>>] +<[-]] +<->[-]+>[-]>[-]<<<[->>+>+<<<]>>>[-<<<+>>>]<<[->-<]+>[<->[-]]<[<<[-]>>>[-]<<<<<[->>+>>>+<<<<<]>>>>>[-<<<<<+>>>>>] +<[-]] +<->[-]+>[-]>[-]<<<[->>+>+<<<]>>>[-<<<+>>>]<<[->-<]+>[<->[-]]<[<<[-]>>>[-]<<<<<<[->>>+>>>+<<<<<<]>>>>>>[-<<<<<<+>>>>>>] +<[-]] +<- +[-]++++++++++<.>.