Add indexing strings
This commit is contained in:
parent
fad545d52c
commit
9f6d2b7b2d
15
compiler.c
15
compiler.c
|
|
@ -611,10 +611,20 @@ variable(void)
|
||||||
emitter->emit_nat(arena, code, "2", 1);
|
emitter->emit_nat(arena, code, "2", 1);
|
||||||
emitter->emit_add(arena, code, 2);
|
emitter->emit_add(arena, code, 2);
|
||||||
expression();
|
expression();
|
||||||
emitter->emit_add(arena, code, 2);
|
emitter->emit_add(arena, code, 2);
|
||||||
emitter->emit_deref(arena, code, 1);
|
|
||||||
while (!match(TOKEN_RBRACKET)) {
|
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;
|
parser->current_type = SYMBOL_BYTE;
|
||||||
} else if (match(TOKEN_DOT)) {
|
} else if (match(TOKEN_DOT)) {
|
||||||
if (sleq("length", parser->current.start, parser->current.length)) {
|
if (sleq("length", parser->current.start, parser->current.length)) {
|
||||||
|
|
@ -958,7 +968,6 @@ void
|
||||||
write(void)
|
write(void)
|
||||||
{
|
{
|
||||||
consume(TOKEN_EQ);
|
consume(TOKEN_EQ);
|
||||||
advance();
|
|
||||||
variable();
|
variable();
|
||||||
emitter->emit_write(arena, code);
|
emitter->emit_write(arena, code);
|
||||||
}
|
}
|
||||||
|
|
|
||||||
1
emit.h
1
emit.h
|
|
@ -110,6 +110,7 @@ struct emitter_s {
|
||||||
StrArgEmit emit_inline_str;
|
StrArgEmit emit_inline_str;
|
||||||
U32ArgEmit emit_ref_store;
|
U32ArgEmit emit_ref_store;
|
||||||
U32ArgEmit emit_stack_swap;
|
U32ArgEmit emit_stack_swap;
|
||||||
|
U32ArgEmit emit_stack_rot;
|
||||||
};
|
};
|
||||||
|
|
||||||
Emitter rer_emitter(void);
|
Emitter rer_emitter(void);
|
||||||
|
|
|
||||||
|
|
@ -1464,6 +1464,15 @@ uxn_emit_stack_swap(Arena *a, List *out, u32 size)
|
||||||
StrBuf_append(a, out, "SWP ");
|
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
|
Emitter
|
||||||
uxn_emitter()
|
uxn_emitter()
|
||||||
{
|
{
|
||||||
|
|
@ -1560,5 +1569,6 @@ uxn_emitter()
|
||||||
uxn_emit_inline_str,
|
uxn_emit_inline_str,
|
||||||
uxn_emit_ref_store,
|
uxn_emit_ref_store,
|
||||||
uxn_emit_stack_swap,
|
uxn_emit_stack_swap,
|
||||||
|
uxn_emit_stack_rot,
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -1,3 +1,4 @@
|
||||||
|
str hello = "hello World!\n";
|
||||||
str msg = " damage inflicted!\n";
|
str msg = " damage inflicted!\n";
|
||||||
|
|
||||||
if (msg[1] == 'd') {
|
if (msg[1] == 'd') {
|
||||||
|
|
@ -6,4 +7,7 @@ if (msg[1] == 'd') {
|
||||||
|
|
||||||
print(msg.length as str);
|
print(msg.length as str);
|
||||||
print(msg);
|
print(msg);
|
||||||
|
|
||||||
|
hello[0] = hello[0] - ' ';
|
||||||
|
print(hello);
|
||||||
halt;
|
halt;
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue