Add indexing strings

This commit is contained in:
zongor 2026-07-03 12:35:22 -07:00
parent fad545d52c
commit 9f6d2b7b2d
4 changed files with 27 additions and 3 deletions

View File

@ -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);
}

1
emit.h
View File

@ -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);

View File

@ -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,
};
}

View File

@ -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;