Skip to content
Snippets Groups Projects
Commit fb2decbe authored by gyuri's avatar gyuri
Browse files

Add stub sizeof implementation

Will be useful when types are properly implemented
parent 79d245ad
No related branches found
No related tags found
No related merge requests found
...@@ -245,7 +245,8 @@ static val cg_gen_expr(struct state *s, const struct ast_node *n) { ...@@ -245,7 +245,8 @@ static val cg_gen_expr(struct state *s, const struct ast_node *n) {
// TODO; // TODO;
break; break;
case AST_SIZEOF_EXPR: case AST_SIZEOF_EXPR:
// TODO fprintf(s->f, "mov rax, %lld\n", 8LL); // TODO: types
return val_push_new(s, "rax");
break; break;
case AST_ALIGNOF_EXPR: case AST_ALIGNOF_EXPR:
// TODO // TODO
......
...@@ -15,32 +15,32 @@ int main() { ...@@ -15,32 +15,32 @@ int main() {
if (c == '[') { if (c == '[') {
// push onto stack // push onto stack
*(stack + sp) = pc; *(stack + sp) = pc;
sp = sp + 8; sp = sp + sizeof(int);
} }
if (c == ']') { if (c == ']') {
// pop from stack // pop from stack
sp = sp - 8; sp = sp - sizeof(int);
int jmp_pc; int jmp_pc;
jmp_pc = *(stack + sp); jmp_pc = *(stack + sp);
*(jumps + pc) = jmp_pc; *(jumps + pc) = jmp_pc;
*(jumps + jmp_pc) = pc; *(jumps + jmp_pc) = pc;
} }
pc = pc + 8; pc = pc + sizeof(int);
} }
*(program + pc + 8) = 0; *(program + pc + sizeof(int)) = 0;
int i = 0; int i = 0;
while (i < 65536) { while (i < 65536) {
*(stack + i) = 0; *(stack + i) = 0;
i = i + 8; i = i + sizeof(int);
} }
int ptr = 0; int ptr = 0;
pc = 0; pc = 0;
while (c = *(program + pc)) { while (c = *(program + pc)) {
if (c == '>') { ptr = ptr + 8; } if (c == '>') { ptr = ptr + sizeof(int); }
if (c == '<') { ptr = ptr - 8; } if (c == '<') { ptr = ptr - sizeof(int); }
if (c == '+') { ++*(stack + ptr); } if (c == '+') { ++*(stack + ptr); }
if (c == '-') { --*(stack + ptr); } if (c == '-') { --*(stack + ptr); }
if (c == '.') { printf("%c", *(stack + ptr)); } if (c == '.') { printf("%c", *(stack + ptr)); }
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment