const std = @import("std"); const ast = @import("ast.zig"); const comp = @import("comp_ctx.zig"); pub const TypeSolver = struct { allocator: *std.mem.Allocator, pub fn init(allocator: *std.mem.Allocator) TypeSolver { return TypeSolver{ .allocator = allocator }; } pub fn nodePass( self: *@This(), ctx: *comp.CompilationContext, node: *ast.Node, ) void { switch (node.*) { .Root => unreachable, .FnDecl => |decl| { var ret_type = ctx.solveType(decl.return_type.lexeme); // TODO maybe solve when custom? std.debug.warn("fn {} type: {}\n", decl.func_name.lexeme, ret_type); // ctx.insertFn(decl.name.lexeme, ret_type); }, // TODO infer type of expr in const //.ConstDecl => {}, //.Struct => {}, //.Enum => {}, else => unreachable, } } pub fn pass(self: *@This(), root: *ast.Node) comp.CompilationContext { var ctx = comp.CompilationContext.init(self.allocator); var slice = root.Root.toSlice(); for (slice) |_, idx| { self.nodePass(&ctx, &slice[idx]); } return ctx; } };