diff --git a/compiler.c b/compiler.c index f5a181d..e8d0090 100644 --- a/compiler.c +++ b/compiler.c @@ -611,10 +611,20 @@ variable(void) emitter->emit_nat(arena, code, "2", 1); emitter->emit_add(arena, code, 2); expression(); - emitter->emit_add(arena, code, 2); - emitter->emit_deref(arena, code, 1); + emitter->emit_add(arena, code, 2); while (!match(TOKEN_RBRACKET)) { } + + if (match(TOKEN_EQ)) { + expression(); + + emitter->emit_stack_rot(arena, code, 1); + emitter->emit_stack_rot(arena, code, 1); + emitter->emit_ref_store(arena, code, 1); + } else { + emitter->emit_deref(arena, code, 1); + } + parser->current_type = SYMBOL_BYTE; } else if (match(TOKEN_DOT)) { if (sleq("length", parser->current.start, parser->current.length)) { @@ -958,7 +968,6 @@ void write(void) { consume(TOKEN_EQ); - advance(); variable(); emitter->emit_write(arena, code); } diff --git a/emit.h b/emit.h index e421e29..8104d7a 100644 --- a/emit.h +++ b/emit.h @@ -110,6 +110,7 @@ struct emitter_s { StrArgEmit emit_inline_str; U32ArgEmit emit_ref_store; U32ArgEmit emit_stack_swap; + U32ArgEmit emit_stack_rot; }; Emitter rer_emitter(void); diff --git a/emit/uxn/emit.c b/emit/uxn/emit.c index 28e7d08..8a7ccfc 100644 --- a/emit/uxn/emit.c +++ b/emit/uxn/emit.c @@ -1464,6 +1464,15 @@ uxn_emit_stack_swap(Arena *a, List *out, u32 size) StrBuf_append(a, out, "SWP "); } +void +uxn_emit_stack_rot(Arena *a, List *out, u32 size) +{ + if (size > 1) + StrBuf_append(a, out, "ROT2 "); + else + StrBuf_append(a, out, "ROT "); +} + Emitter uxn_emitter() { @@ -1560,5 +1569,6 @@ uxn_emitter() uxn_emit_inline_str, uxn_emit_ref_store, uxn_emit_stack_swap, + uxn_emit_stack_rot, }; } diff --git a/test/string.ul b/test/string.ul index 6536f77..62e7af2 100755 --- a/test/string.ul +++ b/test/string.ul @@ -1,3 +1,4 @@ +str hello = "hello World!\n"; str msg = " damage inflicted!\n"; if (msg[1] == 'd') { @@ -6,4 +7,7 @@ if (msg[1] == 'd') { print(msg.length as str); print(msg); + +hello[0] = hello[0] - ' '; +print(hello); halt;