From cfc288e279631c18f6e22ef517068c52f2dc8621 Mon Sep 17 00:00:00 2001 From: 0x4261756D <38735823+0x4261756D@users.noreply.github.com> Date: Fri, 17 Nov 2023 01:37:29 +0100 Subject: [PATCH] More treewalker stuff --- src/treewalker.zig | 39 +++++++++++++++++++++++++++++++++++---- src/types.zig | 4 ++-- 2 files changed, 37 insertions(+), 6 deletions(-) diff --git a/src/treewalker.zig b/src/treewalker.zig index 6312081..08d97a9 100644 --- a/src/treewalker.zig +++ b/src/treewalker.zig @@ -4,7 +4,7 @@ const types = @import("types.zig"); pub fn interpret(root: parser.ChunkNode, allocator: std.mem.Allocator) !void { - var _ENV = types.Table { .items = std.AutoArrayHashMap(types.Value, types.Value).init(allocator) }; + var _ENV = types.Table { .items = std.HashMap(types.Value, types.Value, std.hash_map.AutoContext(types.Value), std.hash_map.default_max_load_percentage).init(allocator) }; try walkChunk(root, &_ENV, allocator); } @@ -74,7 +74,7 @@ fn walkExplist(node: parser.ExplistNode, environment: *types.Table, allocator: s var results = std.ArrayList(types.Value).init(allocator); for(node.exps.items) |exp| { - try results.append(try walkExp(exp, environment, allocator)); + try results.append(try walkExp(exp, environment, allocator, false)); } return results.toOwnedSlice(); } @@ -99,13 +99,44 @@ fn walkExp(node: parser.ExpNode, environment: *types.Table, allocator: std.mem.A return error.UseVarargsOutsideVariadicFunction; } }, + .Suffixexp => |suffixExp| + { + return walkSuffixexp(suffixExp.*, environment, allocator); + }, else => { std.debug.print("{}\n", .{node}); return error.NotImplemented; } } - _ = environment; - _ = allocator; return error.NotImplemented; } + +fn walkSuffixexp(node: parser.SuffixexpNode, environment: *types.Table, allocator: std.mem.Allocator) !types.Value +{ + _ = allocator; + switch(node) + { + .Normal => |normal| + { + switch(normal.firstPart) + { + .Name => |name| + { + std.debug.print("name: {s}\n", .{name}); + std.debug.print("val: {!}\n", .{environment.get(types.Value { .String = name })}); + }, + else => + { + std.debug.print("{}\n", .{normal.firstPart}); + } + } + return error.NotImplemented; + }, + else => + { + std.debug.print("{}\n", .{node}); + return error.NotImplemented; + } + } +} diff --git a/src/types.zig b/src/types.zig index 2f26155..8ee2a85 100644 --- a/src/types.zig +++ b/src/types.zig @@ -7,7 +7,7 @@ pub const Numeral = union(enum) }; pub const Table = struct { - items: std.AutoArrayHashMap(Value, Value), + items: std.HashMap(Value, Value, std.hash_map.AutoContext(Value), std.hash_map.default_max_load_percentage), pub fn insert(self: *const Table, key: Value, value: Value) !bool { @@ -25,7 +25,7 @@ pub const Value = union(enum) Nil, Bool: bool, Numeral: Numeral, - String: []u8, + String: []const u8, Table: *Table, };