Replace System Objects with Builtins and Syscalls #33
|
@ -164,12 +164,18 @@ pub const RuntimeEnv = struct {
|
|||
try self.compile_expression(chunk, grouped_expression.*);
|
||||
},
|
||||
|
||||
.import => {
|
||||
try chunk.opcodes.push_one(.{.push_builtin = .import});
|
||||
},
|
||||
.builtin => |builtin| {
|
||||
coral.debug.assert(builtin.len != 0);
|
||||
|
||||
.print => {
|
||||
try chunk.opcodes.push_one(.{.push_builtin = .print});
|
||||
const decoded_builtin = @as(?Builtin, switch (builtin[0]) {
|
||||
'i' => if (coral.io.ends_with(builtin, "mport")) .import else null,
|
||||
'p' => if (coral.io.ends_with(builtin, "rint")) .print else null,
|
||||
else => null,
|
||||
});
|
||||
|
||||
try chunk.opcodes.push_one(.{.push_builtin = decoded_builtin orelse {
|
||||
return chunk.env.raise(error.BadSyntax, "unknown builtin");
|
||||
}});
|
||||
},
|
||||
|
||||
.local_get => |local_get| {
|
||||
|
|
|
@ -13,8 +13,7 @@ pub const Expression = union (enum) {
|
|||
nil_literal,
|
||||
true_literal,
|
||||
false_literal,
|
||||
import,
|
||||
print,
|
||||
builtin: []const coral.io.Byte,
|
||||
number_literal: []const coral.io.Byte,
|
||||
string_literal: []const coral.io.Byte,
|
||||
symbol_literal: []const coral.io.Byte,
|
||||
|
@ -354,25 +353,8 @@ fn parse_factor(self: *Self) ParseError!Expression {
|
|||
|
||||
.builtin => |builtin| {
|
||||
self.tokenizer.skip_newlines();
|
||||
coral.debug.assert(builtin.len != 0);
|
||||
|
||||
switch (builtin[0]) {
|
||||
'i' => {
|
||||
if (coral.io.ends_with(builtin, "mport")) {
|
||||
break: parse .import;
|
||||
}
|
||||
},
|
||||
|
||||
'p' => {
|
||||
if (coral.io.ends_with(builtin, "rint")) {
|
||||
break: parse .print;
|
||||
}
|
||||
},
|
||||
|
||||
else => {},
|
||||
}
|
||||
|
||||
return self.report("unknown builtin");
|
||||
break: parse .{.builtin = builtin};
|
||||
},
|
||||
|
||||
.symbol_brace_left => {
|
||||
|
|
Loading…
Reference in New Issue