assert(!"bad store op");
}
}
+
+void codegen_if(Parser* p, Item* item)
+{
+ load_var(p, item);
+ printf(" if (_T%d) {\n", item->reg);
+}
+
+void codegen_else(Parser* p, Item* item)
+{
+ (void)p, (void)item;
+ printf(" } else {\n");
+}
+
+void codegen_endif(Parser* p, long elsifs, Item* item)
+{
+ (void)p, (void)item;
+ printf(" ");
+ for (long i = 0; i < elsifs; i ++)
+ {
+ printf("}");
+ }
+ printf("}\n");
+}
{
(void)p, (void)a, (void)b;
}
+
+void codegen_if(Parser* p, Item* item)
+{
+ (void)p, (void)item;
+}
+
+void codegen_else(Parser* p, Item* item)
+{
+ (void)p, (void)item;
+}
+
+void codegen_endif(Parser* p, long elsifs, Item* item)
+{
+ (void)p, (void)elsifs, (void)item;
+}
// assert(!"bad store op");
}
}
+
+void codegen_if(Parser* p, Item* item)
+{
+ (void)p, (void)item;
+}
+
+void codegen_else(Parser* p, Item* item)
+{
+ (void)p, (void)item;
+}
+
+void codegen_endif(Parser* p, long elsifs, Item* item)
+{
+ (void)p, (void)elsifs, (void)item;
+}
void codegen_unop(Parser* p, int op, Item* a);
void codegen_binop(Parser* p, int op, Item* a, Item* b);
void codegen_store(Parser* p, Item* a, Item* b);
+void codegen_if(Parser* p, Item* item);
+void codegen_else(Parser* p, Item* item);
+void codegen_endif(Parser* p, long elsifs, Item* item);
+
expect(p, IF);
expression(p, item);
check_bool(p, item);
- // CFJump(item)
+ codegen_if(p, item);
expect(p, THEN);
statement_seq(p, &(Item){0});
- // L = 0
+ int elsifs = 0;
while (accept(p, ELSIF))
{
- // FJump(L)
- // FixLink(item->imm.i)
+ elsifs++;
+ codegen_else(p, item);
expression(p, item);
check_bool(p, item);
- // CFJump(item)
+ codegen_if(p, item);
expect(p, THEN);
statement_seq(p, &(Item){0});
}
if (accept(p, ELSE))
{
- // FJump(L)
- // FixLink(item->imm.i)
+ codegen_else(p, item);
statement_seq(p, &(Item){0});
}
- else
- {
- // FixLink(item->imm.i)
- }
+ codegen_endif(p, elsifs, item);
expect(p, END);
}
else
# # Complex arithmetic
# c = b + b * b + b;
#
+
+
+ # If statements
+ if 1 == 1 then
+ c = 1;
+ end
+
+ if 1 == 1 then
+ c = 1;
+ else
+ c = 1;
+ end
+
+ if 1 == 1 then
+ c = 1;
+ elsif 2 == 2 then
+ c = 1;
+ end
+
if 1 == 1 then
c = 1;
elsif 2 == 2 then
c = 2;
+ elsif 2 == 2 then
+ c = 2;
else
c = 3;
end