implementing global variables (ch21)

This commit is contained in:
2024-08-26 22:54:25 +02:00
parent 062d2e44de
commit 5fb7d361cf
10 changed files with 219 additions and 20 deletions

View File

@ -70,7 +70,7 @@ pub const Value = struct {
}
pub fn as_string(self: Value) *Obj.String {
const obj: *Obj.String = self.as_obj();
const obj: *Obj.String = self.as_obj().as_string();
return obj;
}
@ -126,6 +126,18 @@ pub const Value = struct {
ValueType.Obj => self.as_obj().print(),
}
}
pub fn type_print(self: Value) void {
switch (self.value_type) {
ValueType.Nil => debug.print("(nil)", .{}),
ValueType.Bool => debug.print("(bool)", .{}),
ValueType.Number => debug.print("(number)", .{}),
ValueType.Obj => debug.print("(obj)", .{}),
}
debug.print(" ", .{});
self.print();
}
};
pub const ValueArray = struct {