embed FnDecl inside FunctionSymbol for correct param order

This commit is contained in:
Luna 2019-09-25 10:53:10 -03:00
parent e2cca03d52
commit 6b3d54aed7
2 changed files with 4 additions and 2 deletions

View file

@ -368,8 +368,8 @@ pub fn printContext(ctx: CompilationContext) void {
prettyType(fn_sym.return_type), prettyType(fn_sym.return_type),
); );
var param_it = fn_sym.parameters.iterator(); for (fn_sym.decl.params.toSlice()) |param| {
while (param_it.next()) |param_kv| { var param_kv = fn_sym.parameters.get(param.name.lexeme).?;
std.debug.warn( std.debug.warn(
"\tparameter {} typ {}\n", "\tparameter {} typ {}\n",
param_kv.key, param_kv.key,

View file

@ -33,6 +33,7 @@ pub const SymbolUnderlyingType = union(SymbolUnderlyingTypeEnum) {
// - a return type // - a return type
// - TODO parameters // - TODO parameters
pub const FunctionSymbol = struct { pub const FunctionSymbol = struct {
decl: ast.FnDecl,
return_type: SymbolUnderlyingType, return_type: SymbolUnderlyingType,
/// Parameters for a function are also a table instead of an ArrayList /// Parameters for a function are also a table instead of an ArrayList
@ -153,6 +154,7 @@ pub const CompilationContext = struct {
_ = try self.symbol_table.put(decl.func_name.lexeme, SymbolData{ _ = try self.symbol_table.put(decl.func_name.lexeme, SymbolData{
.Function = FunctionSymbol{ .Function = FunctionSymbol{
.decl = decl,
.return_type = ret_type, .return_type = ret_type,
.parameters = type_map, .parameters = type_map,
.symbols = symbols, .symbols = symbols,