More treewalker stuff
This commit is contained in:
parent
cdfa8d3f90
commit
cfc288e279
@ -4,7 +4,7 @@ const types = @import("types.zig");
|
|||||||
|
|
||||||
pub fn interpret(root: parser.ChunkNode, allocator: std.mem.Allocator) !void
|
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);
|
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);
|
var results = std.ArrayList(types.Value).init(allocator);
|
||||||
for(node.exps.items) |exp|
|
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();
|
return results.toOwnedSlice();
|
||||||
}
|
}
|
||||||
@ -99,13 +99,44 @@ fn walkExp(node: parser.ExpNode, environment: *types.Table, allocator: std.mem.A
|
|||||||
return error.UseVarargsOutsideVariadicFunction;
|
return error.UseVarargsOutsideVariadicFunction;
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
.Suffixexp => |suffixExp|
|
||||||
|
{
|
||||||
|
return walkSuffixexp(suffixExp.*, environment, allocator);
|
||||||
|
},
|
||||||
else =>
|
else =>
|
||||||
{
|
{
|
||||||
std.debug.print("{}\n", .{node});
|
std.debug.print("{}\n", .{node});
|
||||||
return error.NotImplemented;
|
return error.NotImplemented;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
_ = environment;
|
|
||||||
_ = allocator;
|
|
||||||
return error.NotImplemented;
|
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;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
@ -7,7 +7,7 @@ pub const Numeral = union(enum)
|
|||||||
};
|
};
|
||||||
pub const Table = struct
|
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
|
pub fn insert(self: *const Table, key: Value, value: Value) !bool
|
||||||
{
|
{
|
||||||
@ -25,7 +25,7 @@ pub const Value = union(enum)
|
|||||||
Nil,
|
Nil,
|
||||||
Bool: bool,
|
Bool: bool,
|
||||||
Numeral: Numeral,
|
Numeral: Numeral,
|
||||||
String: []u8,
|
String: []const u8,
|
||||||
Table: *Table,
|
Table: *Table,
|
||||||
};
|
};
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user