More treewalker stuff

This commit is contained in:
0x4261756D 2023-11-17 01:37:29 +01:00
parent cdfa8d3f90
commit cfc288e279
2 changed files with 37 additions and 6 deletions

View File

@ -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;
}
}
}

View File

@ -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,
};