Skip to content

Commit

Permalink
Add to-def and make to-cmd not lazy
Browse files Browse the repository at this point in the history
  • Loading branch information
booniepepper committed Jul 7, 2023
1 parent a374718 commit 7e34fcd
Showing 1 changed file with 8 additions and 1 deletion.
9 changes: 8 additions & 1 deletion src/builtins.zig
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,8 @@ pub fn defineAll(machine: *DtMachine) !void {
try machine.define("to-int", "coerce value to integer", .{ .builtin = toInt });
try machine.define("to-float", "coerce value to floating-point number", .{ .builtin = toFloat });
try machine.define("to-string", "coerce value to string", .{ .builtin = toString });
try machine.define("to-cmd", "coerce value to a deferred command", .{ .builtin = toCommand });
try machine.define("to-cmd", "coerce value to a command", .{ .builtin = toCommand });
try machine.define("to-def", "coerce value to a deferred command", .{ .builtin = toDef });
try machine.define("to-quote", "coerce value to quote", .{ .builtin = toQuote });
try machine.define("to-error", "coerce value to an error", .{ .builtin = toError });
}
Expand Down Expand Up @@ -1138,6 +1139,12 @@ pub fn toString(dt: *DtMachine) !void {
}

pub fn toCommand(dt: *DtMachine) !void {
const val = try dt.pop();
const cmd = val.intoString(dt) catch |e| return dt.rewind(val, e);
try dt.push(.{ .command = cmd });
}

pub fn toDef(dt: *DtMachine) !void {
const val = try dt.pop();
const cmd = val.intoString(dt) catch |e| return dt.rewind(val, e);
try dt.push(.{ .deferred_command = cmd });
Expand Down

0 comments on commit 7e34fcd

Please sign in to comment.