aboutsummaryrefslogtreecommitdiff
path: root/src/parse.zig
diff options
context:
space:
mode:
authorMathias Magnusson <mathias@magnusson.space>2025-05-31 02:12:02 +0200
committerMathias Magnusson <mathias@magnusson.space>2025-05-31 02:12:02 +0200
commitee78756a504dc61f50422298cc1123c5ac6b3b69 (patch)
treefe99400865ef7fe652cee6678f27d7e8093b3e23 /src/parse.zig
parent1ba97916933d858434294b3fde9631873bbf16c8 (diff)
downloadhuginn-ee78756a504dc61f50422298cc1123c5ac6b3b69.tar.gz
actually codegen the provided code
... well, since all we can do is to add integer literals, we produce code for the calculations and then perform the exit syscall with the result
Diffstat (limited to 'src/parse.zig')
-rw-r--r--src/parse.zig9
1 files changed, 9 insertions, 0 deletions
diff --git a/src/parse.zig b/src/parse.zig
index 2149cd7..e0c1fd0 100644
--- a/src/parse.zig
+++ b/src/parse.zig
@@ -26,6 +26,15 @@ pub const Expr = struct {
};
};
};
+
+ pub fn getInt(self: *const @This(), file_source: []const u8) u64 {
+ var value: u64 = 0;
+ for (file_source[self.loc.start..self.loc.end]) |c| {
+ std.debug.assert('0' <= c and c <= '9');
+ value = value * 10 + c - '0';
+ }
+ return value;
+ }
};
pub fn expression(allocator: Allocator, lexer: *Peekable(Lexer)) error{OutOfMemory}!*Expr {