Compare commits
2 Commits
fad545d52c
...
9280f52f65
| Author | SHA1 | Date |
|---|---|---|
|
|
9280f52f65 | |
|
|
9f6d2b7b2d |
15
compiler.c
15
compiler.c
|
|
@ -612,9 +612,19 @@ variable(void)
|
|||
emitter->emit_add(arena, code, 2);
|
||||
expression();
|
||||
emitter->emit_add(arena, code, 2);
|
||||
emitter->emit_deref(arena, code, 1);
|
||||
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);
|
||||
}
|
||||
|
|
@ -1104,7 +1113,7 @@ compile(Arena *a, List *c, List* m, Emitter *e, char *source)
|
|||
build_symbol_table(source);
|
||||
parser->pass++;
|
||||
parser->depth = 0;
|
||||
parser->scope_idx = 1;
|
||||
parser->scope_idx = 0;
|
||||
emit_program(source);
|
||||
|
||||
return true;
|
||||
|
|
|
|||
1
emit.h
1
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);
|
||||
|
|
|
|||
|
|
@ -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,
|
||||
};
|
||||
}
|
||||
|
|
|
|||
|
|
@ -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;
|
||||
|
|
|
|||
Loading…
Reference in New Issue