Implement Control Flow Statements in Kym #37

Merged
kayomn merged 8 commits from kym-control-flow into main 2023-08-26 00:01:25 +02:00
1 changed files with 4 additions and 4 deletions
Showing only changes of commit 77af4d067b - Show all commits

View File

@ -136,9 +136,9 @@ pub const RuntimeEnv = struct {
.subtraction => .sub, .subtraction => .sub,
.multiplication => .mul, .multiplication => .mul,
.divsion => .div, .divsion => .div,
.greater_equals_comparison => .eql, .greater_equals_comparison => .cge,
.greater_than_comparison => .cgt, .greater_than_comparison => .cgt,
.equals_comparison => .cge, .equals_comparison => .eql,
.less_than_comparison => .clt, .less_than_comparison => .clt,
.less_equals_comparison => .cle, .less_equals_comparison => .cle,
}); });
@ -297,13 +297,13 @@ pub const RuntimeEnv = struct {
try self.compile_expression(chunk, @"if".condition_expression); try self.compile_expression(chunk, @"if".condition_expression);
try chunk.opcodes.push_one(.{.jf = 0}); try chunk.opcodes.push_one(.{.jf = 0});
const then_origin_index = @as(u32, @intCast(chunk.opcodes.values.len - 1)); const origin_index = @as(u32, @intCast(chunk.opcodes.values.len - 1));
for (@"if".block_statements.values) |block_statement| { for (@"if".block_statements.values) |block_statement| {
try self.compile_statement(chunk, block_statement); try self.compile_statement(chunk, block_statement);
} }
chunk.opcodes.values[then_origin_index].jf = @intCast(chunk.opcodes.values.len - 1); chunk.opcodes.values[origin_index].jf = @intCast(chunk.opcodes.values.len - 1);
if (@"if".else_statement) |else_statement| { if (@"if".else_statement) |else_statement| {
try self.compile_statement(chunk, else_statement.*); try self.compile_statement(chunk, else_statement.*);