From e0f0ae7f244485af73e29f7c91a30334c062d48d Mon Sep 17 00:00:00 2001 From: Luna Date: Thu, 23 Jul 2020 16:42:59 -0300 Subject: [PATCH] toSlice -> items --- src/analysis.zig | 18 +++++++++--------- src/ast_printer.zig | 22 +++++++++++----------- src/codegen/llvm.zig | 20 ++++++++++---------- src/comp_ctx.zig | 6 +++--- 4 files changed, 33 insertions(+), 33 deletions(-) diff --git a/src/analysis.zig b/src/analysis.zig index 078d116..5545f1c 100644 --- a/src/analysis.zig +++ b/src/analysis.zig @@ -257,7 +257,7 @@ pub const Analyzer = struct { var symbol = try ctx.fetchGlobalSymbol(func_name, .Function); var func_sym = symbol.Function; - for (call.arguments.toSlice()) |arg_expr, idx| { + for (call.arguments.items) |arg_expr, idx| { var param_type = func_sym.parameter_list.at(idx); var arg_type = try self.resolveExprType(ctx, &arg_expr); @@ -411,7 +411,7 @@ pub const Analyzer = struct { try ctx.bumpScope("if_then"); - for (ifstmt.then_branch.toSlice()) |then_stmt| { + for (ifstmt.then_branch.items) |then_stmt| { try self.stmtPass(ctx, then_stmt); } @@ -421,7 +421,7 @@ pub const Analyzer = struct { try ctx.bumpScope("if_else"); defer ctx.dumpScope(); - for (else_branch.toSlice()) |else_stmt| { + for (else_branch.items) |else_stmt| { try self.stmtPass(ctx, else_stmt); } } @@ -437,7 +437,7 @@ pub const Analyzer = struct { try ctx.bumpScope("loop"); - for (loop.then_branch.toSlice()) |then_stmt| { + for (loop.then_branch.items) |then_stmt| { try self.stmtPass(ctx, then_stmt); } @@ -476,7 +476,7 @@ pub const Analyzer = struct { }); var parameters = comp.TypeList.init(self.allocator); - for (decl.params.toSlice()) |param| { + for (decl.params.items) |param| { var param_type = self.resolveGlobalType(ctx, param.typ.lexeme); if (param_type == null) continue; try parameters.append(param_type.?); @@ -507,7 +507,7 @@ pub const Analyzer = struct { std.debug.assert(ctx.current_scope == null); ctx.setScope(scope); - for (decl.body.toSlice()) |stmt| { + for (decl.body.items) |stmt| { try self.stmtPass(ctx, stmt); } @@ -522,7 +522,7 @@ pub const Analyzer = struct { var types = comp.TypeList.init(self.allocator); - for (struc.fields.toSlice()) |field| { + for (struc.fields.items) |field| { self.setErrToken(field.name); var field_type = self.resolveGlobalType(ctx, field.typ.lexeme); if (field_type == null) continue; @@ -547,7 +547,7 @@ pub const Analyzer = struct { }, .ConstDecl => |constlist| { - for (constlist.toSlice()) |constdecl| { + for (constlist.items) |constdecl| { self.setErrToken(constdecl.name); self.setErrContext("const {}", .{constdecl.name.lexeme}); @@ -566,7 +566,7 @@ pub const Analyzer = struct { pub fn pass(self: *@This(), root: *ast.Node) !comp.CompilationContext { var ctx = comp.CompilationContext.init(self.allocator); - var slice = root.Root.toSlice(); + var slice = root.Root.items; for (slice) |_, idx| { try self.nodePass(&ctx, &slice[idx]); } diff --git a/src/ast_printer.zig b/src/ast_printer.zig index 1f248ee..fd628ca 100644 --- a/src/ast_printer.zig +++ b/src/ast_printer.zig @@ -22,7 +22,7 @@ fn print(ident: usize, comptime fmt: []const u8, args: anytype) void { fn printBlock(ident: usize, block: anytype, endNewline: bool) void { std.debug.warn("(\n", .{}); - for (block.toSlice()) |stmt| { + for (block.items) |stmt| { printIdent(ident); printStmt(ident, &stmt); std.debug.warn("\n", .{}); @@ -53,7 +53,7 @@ pub fn printNode(node: *const Node, ident: usize) void { warn("(fn {} {} (", .{ name, ret_type }); } - for (decl.params.toSlice()) |param| { + for (decl.params.items) |param| { warn(" ({} {})", .{ param.name.lexeme, param.typ.lexeme }); } warn(") ", .{}); @@ -65,7 +65,7 @@ pub fn printNode(node: *const Node, ident: usize) void { .ConstDecl => |consts| { print(ident, "(const (\n", .{}); - for (consts.toSlice()) |const_decl| { + for (consts.items) |const_decl| { print(ident + 1, "({} ", .{ const_decl.name.lexeme, }); @@ -80,7 +80,7 @@ pub fn printNode(node: *const Node, ident: usize) void { .Enum => |decl| { print(ident, "(enum {} (\n", .{decl.name.lexeme}); - for (decl.fields.toSlice()) |field| { + for (decl.fields.items) |field| { print(ident + 1, "{}\n", .{ field.lexeme, }); @@ -90,14 +90,14 @@ pub fn printNode(node: *const Node, ident: usize) void { }, .Root => { - for (node.Root.toSlice()) |child| { + for (node.Root.items) |child| { printNode(&child, ident + 1); } }, .Struct => |struc| { print(ident, "(struct {} (\n", .{struc.name.lexeme}); - for (struc.fields.toSlice()) |field| { + for (struc.fields.items) |field| { print(ident + 1, "({} {})\n", .{ field.name.lexeme, field.typ.lexeme }); } print(ident, "))\n", .{}); @@ -203,7 +203,7 @@ pub fn printExpr(expr: *const Expr) void { .Float => |val| std.debug.warn("{}", .{val}), .String => |val| std.debug.warn("'{}'", .{val}), .Array => |exprs| { - parenthetize("array", exprs.toSlice()); + parenthetize("array", exprs.items); }, else => |typ| std.debug.warn("UnknownLiteral-{}", .{typ}), } @@ -222,7 +222,7 @@ pub fn printExpr(expr: *const Expr) void { std.debug.warn("(", .{}); printExpr(call.callee); - for (call.arguments.toSlice()) |arg| { + for (call.arguments.items) |arg| { std.debug.warn(" ", .{}); printExpr(&arg); } @@ -233,7 +233,7 @@ pub fn printExpr(expr: *const Expr) void { .Struct => |val| { std.debug.warn("({} (", .{val.name.lexeme}); - for (val.inits.toSlice()) |init| { + for (val.inits.items) |init| { std.debug.warn(" ({} ", .{init.field.lexeme}); printExpr(init.expr); std.debug.warn(")", .{}); @@ -350,7 +350,7 @@ pub fn printScope(scope: *Scope, ident: usize) void { print(ident + 1, "sym: {}, typ: {}\n", .{ kv.key, prettyType(kv.value) }); } - for (scope.children.toSlice()) |child| { + for (scope.children.items) |child| { printScope(child, ident + 1); } } @@ -366,7 +366,7 @@ pub fn printContext(ctx: CompilationContext) void { prettyType(fn_sym.return_type), }); - for (fn_sym.decl.params.toSlice()) |param| { + for (fn_sym.decl.params.items) |param| { var param_kv = fn_sym.parameters.get(param.name.lexeme).?; std.debug.warn("\tparameter {} typ {}\n", .{ param_kv.key, diff --git a/src/codegen/llvm.zig b/src/codegen/llvm.zig index ccde966..32e4bc7 100644 --- a/src/codegen/llvm.zig +++ b/src/codegen/llvm.zig @@ -185,12 +185,12 @@ pub const Codegen = struct { var args = LLVMValueList.init(self.allocator); errdefer args.deinit(); - for (call.arguments.toSlice()) |arg_expr| { + for (call.arguments.items) |arg_expr| { var arg_val = try self.emitExpr(builder, &arg_expr); try args.append(arg_val); } - var args_slice = args.toSlice(); + var args_slice = args.items; return llvm.LLVMBuildCall( builder, @@ -294,7 +294,7 @@ pub const Codegen = struct { self.ctx.setScope(self.ctx.current_scope.?.nextChild()); - var then_branch = ifstmt.then_branch.toSlice(); + var then_branch = ifstmt.then_branch.items; for (then_branch) |_, idx| { // keep emitting until branch has ret var then_stmt = &then_branch[idx]; @@ -326,7 +326,7 @@ pub const Codegen = struct { if (ifstmt.else_branch) |else_block| { self.ctx.setScope(self.ctx.current_scope.?.nextChild()); - var else_slice = else_block.toSlice(); + var else_slice = else_block.items; for (else_slice) |_, idx| { // keep emitting until branch has ret var else_stmt = &else_slice[idx]; @@ -418,7 +418,7 @@ pub const Codegen = struct { var param_types = llvm.LLVMTypeList.init(self.allocator); errdefer param_types.deinit(); - for (decl.params.toSlice()) |param| { + for (decl.params.items) |param| { try param_types.append(try self.typeToLLVM(fn_sym.parameters.get( param.name.lexeme, ).?.value.typ)); @@ -426,7 +426,7 @@ pub const Codegen = struct { var llvm_ret_type = llvm.LLVMFunctionType( try self.typeToLLVM(fn_sym.return_type), - param_types.toSlice().ptr, + param_types.items.ptr, @intCast(c_uint, param_types.len), 0, ); @@ -444,7 +444,7 @@ pub const Codegen = struct { // to have the ability to mutate parameters, we must allocate them on // the stack - var params_slice = decl.params.toSlice(); + var params_slice = decl.params.items; for (params_slice) |param_node, idx| { var param = fn_sym.parameters.get(param_node.name.lexeme).?.value; @@ -467,7 +467,7 @@ pub const Codegen = struct { // TODO check if stmt is return and if we already // returned before - var body_slice = decl.body.toSlice(); + var body_slice = decl.body.items; for (body_slice) |_, idx| { try self.emitStmt(builder, &body_slice[idx]); } @@ -480,7 +480,7 @@ pub const Codegen = struct { .Enum => {}, .ConstDecl => |constdecls| { - for (constdecls.toSlice()) |constdecl| { + for (constdecls.items) |constdecl| { const name = constdecl.name.lexeme; var const_type = self.ctx.symbol_table.get(name).?.value; @@ -515,7 +515,7 @@ pub const Codegen = struct { var mod = llvm.LLVMModuleCreateWithName("awoo").?; defer llvm.LLVMDisposeModule(mod); - var root_slice = root.Root.toSlice(); + var root_slice = root.Root.items; for (root_slice) |_, idx| { try self.genNode(mod, &root_slice[idx]); } diff --git a/src/comp_ctx.zig b/src/comp_ctx.zig index 44f377b..05a8896 100644 --- a/src/comp_ctx.zig +++ b/src/comp_ctx.zig @@ -271,7 +271,7 @@ pub const CompilationContext = struct { pub fn insertStruct(self: *@This(), struc: ast.Struct, field_types: TypeList) !void { var type_map = UnderlyingTypeMap.init(self.allocator); - for (struc.fields.toSlice()) |field, idx| { + for (struc.fields.items) |field, idx| { _ = try type_map.put(field.name.lexeme, field_types.at(idx)); } @@ -289,7 +289,7 @@ pub const CompilationContext = struct { ) !void { var param_map = ParameterMap.init(self.allocator); - for (decl.params.toSlice()) |param, idx| { + for (decl.params.items) |param, idx| { var param_sym = try self.allocator.create(Parameter); param_sym.* = Parameter{ @@ -326,7 +326,7 @@ pub const CompilationContext = struct { errdefer ident_map.deinit(); // TODO change this when enums get support for custom values - for (enu.fields.toSlice()) |token, idx| { + for (enu.fields.items) |token, idx| { _ = try ident_map.put(token.lexeme, @intCast(u32, idx)); }