hashmap changes

This commit is contained in:
Luna 2020-07-23 16:56:37 -03:00
parent 56be677c7a
commit 0265eddb2e
3 changed files with 27 additions and 26 deletions

View File

@ -80,14 +80,14 @@ pub const Analyzer = struct {
return null;
}
return switch (sym.?.value.*) {
return switch (sym.?.*) {
.Struct => SymbolUnderlyingType{ .Struct = val },
.Enum => SymbolUnderlyingType{ .Enum = val },
else => blk: {
self.doError("expected struct or enum for '{}', got {}", .{
val,
@tagName(@as(comp.SymbolType, sym.?.value.*)),
@tagName(@as(comp.SymbolType, sym.?.*)),
});
break :blk null;
},
@ -314,7 +314,7 @@ pub const Analyzer = struct {
.Enum => |enum_identifier| {
// fetch an enum off symbol table, then we use the
// identifier map to ensure get.name exists in the enum
var map = ctx.symbol_table.get(enum_identifier).?.value.Enum;
var map = ctx.symbol_table.get(enum_identifier).?.Enum;
const name = get.name.lexeme;
var kv = map.get(name);
@ -355,8 +355,8 @@ pub const Analyzer = struct {
}
var value_type = try self.resolveExprType(ctx, assign.value);
try self.expectSymUnTypeEqual(var_type.?.value, value_type);
return var_type.?.value;
try self.expectSymUnTypeEqual(var_type.?, value_type);
return var_type.?;
},
.Set => @panic("TODO analysis of Set exprs"),
@ -496,8 +496,8 @@ pub const Analyzer = struct {
if (ret_type != null)
self.doError("Return type was not fully resolved", .{});
if (parameters.len != decl.params.len)
self.doError("Fully analyzed {} parameters, wanted {}", .{ parameters.len, decl.params.len });
if (parameters.items.len != decl.params.items.len)
self.doError("Fully analyzed {} parameters, wanted {}", .{ parameters.items.len, decl.params.items.len });
return CompileError.TypeError;
}
@ -534,7 +534,7 @@ pub const Analyzer = struct {
// we don't return type errors from the main loop so we can
// keep going and find more type errors
if (types.len == struc.fields.len)
if (types.items.len == struc.fields.items.len)
try ctx.insertStruct(struc, types);
},

View File

@ -46,7 +46,7 @@ pub const Codegen = struct {
},
.Struct, .Enum => |lex| blk: {
var sym_data = self.ctx.symbol_table.get(lex).?.value;
var sym_data = self.ctx.symbol_table.get(lex).?;
break :blk switch (sym_data.*) {
.Struct => unreachable,
.Enum => llvm.LLVMInt32Type(),
@ -76,7 +76,7 @@ pub const Codegen = struct {
get.name.lexeme,
});
}
return llvm.LLVMConstInt(llvm.LLVMInt32Type(), val.?.value, 1);
return llvm.LLVMConstInt(llvm.LLVMInt32Type(), val.?, 1);
},
.Struct => @panic("TODO handle struct"),
@ -194,7 +194,7 @@ pub const Codegen = struct {
return llvm.LLVMBuildCall(
builder,
llvm_func.?.value,
llvm_func.?,
args_slice.ptr,
@intCast(c_uint, args_slice.len),
"call",
@ -203,10 +203,10 @@ pub const Codegen = struct {
.Assign => |assign| {
const name = assign.name.lexeme;
var meta = self.ctx.current_scope.?.meta_map.get(name).?.value;
var meta = self.ctx.current_scope.?.meta_map.get(name).?;
var assign_expr = try self.emitExpr(builder, assign.value);
var llvm_alloca: llvm.LLVMValueRef = switch (meta.using) {
.Function => meta.from_function.?.parameters.get(name).?.value.llvm_alloca.?,
.Function => meta.from_function.?.parameters.get(name).?.llvm_alloca.?,
.Scope => meta.llvm_alloca.?,
};
@ -224,7 +224,7 @@ pub const Codegen = struct {
// we have metadata, which means we can check if the variable
// is coming from the scope or from the function
var metadata = kv_opt.?.value;
var metadata = kv_opt.?;
std.debug.warn("!! LOAD FROM VAR META {}\n", .{@ptrToInt(metadata)});
var buf = try self.allocator.alloc(u8, 512);
@ -237,13 +237,13 @@ pub const Codegen = struct {
return switch (metadata.using) {
.Function => blk: {
var param = metadata.from_function.?.parameters.get(vari.lexeme).?.value;
var param = metadata.from_function.?.parameters.get(vari.lexeme).?;
break :blk llvm.LLVMBuildLoad(builder, param.llvm_alloca.?, load_cstr.ptr);
},
.Scope => blk: {
var llvm_alloca = metadata.llvm_alloca.?;
//var var_typ = metadata.from_scope.?.env.get(vari.lexeme).?.value;
//var var_typ = metadata.from_scope.?.env.get(vari.lexeme).?;
break :blk llvm.LLVMBuildLoad(builder, llvm_alloca, load_cstr.ptr);
},
};
@ -361,7 +361,7 @@ pub const Codegen = struct {
// analyze pass and the current scope contains the variable's
// type(hopefully), so we resolve it
const name = vardecl.name.lexeme;
var var_metadata = self.ctx.current_scope.?.meta_map.get(name).?.value;
var var_metadata = self.ctx.current_scope.?.meta_map.get(name).?;
var name_cstr = try std.cstr.addNullByte(self.allocator, name);
errdefer self.allocator.free(name_cstr);
@ -392,7 +392,7 @@ pub const Codegen = struct {
}
fn getFnSymbol(self: *@This(), name: []const u8) *comp.FunctionSymbol {
var fn_sym_search = self.ctx.symbol_table.get(name).?.value;
var fn_sym_search = self.ctx.symbol_table.get(name).?;
std.debug.assert(@as(comp.SymbolType, fn_sym_search.*) == .Function);
return &fn_sym_search.Function;
}
@ -421,7 +421,7 @@ pub const Codegen = struct {
for (decl.params.items) |param| {
try param_types.append(try self.typeToLLVM(fn_sym.parameters.get(
param.name.lexeme,
).?.value.typ));
).?.typ));
}
var llvm_ret_type = llvm.LLVMFunctionType(
@ -446,7 +446,7 @@ pub const Codegen = struct {
// the stack
var params_slice = decl.params.items;
for (params_slice) |param_node, idx| {
var param = fn_sym.parameters.get(param_node.name.lexeme).?.value;
var param = fn_sym.parameters.get(param_node.name.lexeme).?;
const param_name_cstr = try std.cstr.addNullByte(self.allocator, param_node.name.lexeme);
errdefer self.allocator.free(param_name_cstr);
@ -483,7 +483,7 @@ pub const Codegen = struct {
for (constdecls.items) |constdecl| {
const name = constdecl.name.lexeme;
var const_type = self.ctx.symbol_table.get(name).?.value;
var const_type = self.ctx.symbol_table.get(name).?;
var const_llvm_type = try self.typeToLLVM(const_type.Const);
const const_name = try std.cstr.addNullByte(self.allocator, name);

View File

@ -76,7 +76,8 @@ pub const Scope = struct {
}
pub fn deinit(self: *const @This()) void {
self.env.deinit();
// XXX: fix this someday
// self.env.deinit();
}
};
@ -318,7 +319,7 @@ pub const CompilationContext = struct {
_ = try self.symbol_table.put(lex, symbol);
var kv = self.symbol_table.get(lex);
self.cur_function = &kv.?.value.Function;
self.cur_function = &kv.?.Function;
}
pub fn insertEnum(self: *@This(), enu: ast.Enum) !void {
@ -352,7 +353,7 @@ pub const CompilationContext = struct {
return CompilationError.TypeError;
}
var value = sym_kv.?.value;
var value = sym_kv.?;
var sym_typ = @as(SymbolType, value.*);
if (sym_typ != typ) {
@ -378,7 +379,7 @@ pub const CompilationContext = struct {
return try VariableMetadata.withScope(
self.allocator,
scope,
kv.value,
kv,
);
} else {
return null;
@ -408,7 +409,7 @@ pub const CompilationContext = struct {
return try VariableMetadata.withParam(
self.allocator,
cur_function,
kv.value.typ,
kv.typ,
);
} else {
return null;