toSlice -> items

This commit is contained in:
Luna 2020-07-23 16:42:59 -03:00
parent 03561ebe6a
commit e0f0ae7f24
4 changed files with 33 additions and 33 deletions

View file

@ -257,7 +257,7 @@ pub const Analyzer = struct {
var symbol = try ctx.fetchGlobalSymbol(func_name, .Function); var symbol = try ctx.fetchGlobalSymbol(func_name, .Function);
var func_sym = symbol.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 param_type = func_sym.parameter_list.at(idx);
var arg_type = try self.resolveExprType(ctx, &arg_expr); var arg_type = try self.resolveExprType(ctx, &arg_expr);
@ -411,7 +411,7 @@ pub const Analyzer = struct {
try ctx.bumpScope("if_then"); 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); try self.stmtPass(ctx, then_stmt);
} }
@ -421,7 +421,7 @@ pub const Analyzer = struct {
try ctx.bumpScope("if_else"); try ctx.bumpScope("if_else");
defer ctx.dumpScope(); defer ctx.dumpScope();
for (else_branch.toSlice()) |else_stmt| { for (else_branch.items) |else_stmt| {
try self.stmtPass(ctx, else_stmt); try self.stmtPass(ctx, else_stmt);
} }
} }
@ -437,7 +437,7 @@ pub const Analyzer = struct {
try ctx.bumpScope("loop"); try ctx.bumpScope("loop");
for (loop.then_branch.toSlice()) |then_stmt| { for (loop.then_branch.items) |then_stmt| {
try self.stmtPass(ctx, then_stmt); try self.stmtPass(ctx, then_stmt);
} }
@ -476,7 +476,7 @@ pub const Analyzer = struct {
}); });
var parameters = comp.TypeList.init(self.allocator); 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); var param_type = self.resolveGlobalType(ctx, param.typ.lexeme);
if (param_type == null) continue; if (param_type == null) continue;
try parameters.append(param_type.?); try parameters.append(param_type.?);
@ -507,7 +507,7 @@ pub const Analyzer = struct {
std.debug.assert(ctx.current_scope == null); std.debug.assert(ctx.current_scope == null);
ctx.setScope(scope); ctx.setScope(scope);
for (decl.body.toSlice()) |stmt| { for (decl.body.items) |stmt| {
try self.stmtPass(ctx, stmt); try self.stmtPass(ctx, stmt);
} }
@ -522,7 +522,7 @@ pub const Analyzer = struct {
var types = comp.TypeList.init(self.allocator); var types = comp.TypeList.init(self.allocator);
for (struc.fields.toSlice()) |field| { for (struc.fields.items) |field| {
self.setErrToken(field.name); self.setErrToken(field.name);
var field_type = self.resolveGlobalType(ctx, field.typ.lexeme); var field_type = self.resolveGlobalType(ctx, field.typ.lexeme);
if (field_type == null) continue; if (field_type == null) continue;
@ -547,7 +547,7 @@ pub const Analyzer = struct {
}, },
.ConstDecl => |constlist| { .ConstDecl => |constlist| {
for (constlist.toSlice()) |constdecl| { for (constlist.items) |constdecl| {
self.setErrToken(constdecl.name); self.setErrToken(constdecl.name);
self.setErrContext("const {}", .{constdecl.name.lexeme}); self.setErrContext("const {}", .{constdecl.name.lexeme});
@ -566,7 +566,7 @@ pub const Analyzer = struct {
pub fn pass(self: *@This(), root: *ast.Node) !comp.CompilationContext { pub fn pass(self: *@This(), root: *ast.Node) !comp.CompilationContext {
var ctx = comp.CompilationContext.init(self.allocator); var ctx = comp.CompilationContext.init(self.allocator);
var slice = root.Root.toSlice(); var slice = root.Root.items;
for (slice) |_, idx| { for (slice) |_, idx| {
try self.nodePass(&ctx, &slice[idx]); try self.nodePass(&ctx, &slice[idx]);
} }

View file

@ -22,7 +22,7 @@ fn print(ident: usize, comptime fmt: []const u8, args: anytype) void {
fn printBlock(ident: usize, block: anytype, endNewline: bool) void { fn printBlock(ident: usize, block: anytype, endNewline: bool) void {
std.debug.warn("(\n", .{}); std.debug.warn("(\n", .{});
for (block.toSlice()) |stmt| { for (block.items) |stmt| {
printIdent(ident); printIdent(ident);
printStmt(ident, &stmt); printStmt(ident, &stmt);
std.debug.warn("\n", .{}); std.debug.warn("\n", .{});
@ -53,7 +53,7 @@ pub fn printNode(node: *const Node, ident: usize) void {
warn("(fn {} {} (", .{ name, ret_type }); warn("(fn {} {} (", .{ name, ret_type });
} }
for (decl.params.toSlice()) |param| { for (decl.params.items) |param| {
warn(" ({} {})", .{ param.name.lexeme, param.typ.lexeme }); warn(" ({} {})", .{ param.name.lexeme, param.typ.lexeme });
} }
warn(") ", .{}); warn(") ", .{});
@ -65,7 +65,7 @@ pub fn printNode(node: *const Node, ident: usize) void {
.ConstDecl => |consts| { .ConstDecl => |consts| {
print(ident, "(const (\n", .{}); print(ident, "(const (\n", .{});
for (consts.toSlice()) |const_decl| { for (consts.items) |const_decl| {
print(ident + 1, "({} ", .{ print(ident + 1, "({} ", .{
const_decl.name.lexeme, const_decl.name.lexeme,
}); });
@ -80,7 +80,7 @@ pub fn printNode(node: *const Node, ident: usize) void {
.Enum => |decl| { .Enum => |decl| {
print(ident, "(enum {} (\n", .{decl.name.lexeme}); print(ident, "(enum {} (\n", .{decl.name.lexeme});
for (decl.fields.toSlice()) |field| { for (decl.fields.items) |field| {
print(ident + 1, "{}\n", .{ print(ident + 1, "{}\n", .{
field.lexeme, field.lexeme,
}); });
@ -90,14 +90,14 @@ pub fn printNode(node: *const Node, ident: usize) void {
}, },
.Root => { .Root => {
for (node.Root.toSlice()) |child| { for (node.Root.items) |child| {
printNode(&child, ident + 1); printNode(&child, ident + 1);
} }
}, },
.Struct => |struc| { .Struct => |struc| {
print(ident, "(struct {} (\n", .{struc.name.lexeme}); 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 + 1, "({} {})\n", .{ field.name.lexeme, field.typ.lexeme });
} }
print(ident, "))\n", .{}); print(ident, "))\n", .{});
@ -203,7 +203,7 @@ pub fn printExpr(expr: *const Expr) void {
.Float => |val| std.debug.warn("{}", .{val}), .Float => |val| std.debug.warn("{}", .{val}),
.String => |val| std.debug.warn("'{}'", .{val}), .String => |val| std.debug.warn("'{}'", .{val}),
.Array => |exprs| { .Array => |exprs| {
parenthetize("array", exprs.toSlice()); parenthetize("array", exprs.items);
}, },
else => |typ| std.debug.warn("UnknownLiteral-{}", .{typ}), else => |typ| std.debug.warn("UnknownLiteral-{}", .{typ}),
} }
@ -222,7 +222,7 @@ pub fn printExpr(expr: *const Expr) void {
std.debug.warn("(", .{}); std.debug.warn("(", .{});
printExpr(call.callee); printExpr(call.callee);
for (call.arguments.toSlice()) |arg| { for (call.arguments.items) |arg| {
std.debug.warn(" ", .{}); std.debug.warn(" ", .{});
printExpr(&arg); printExpr(&arg);
} }
@ -233,7 +233,7 @@ pub fn printExpr(expr: *const Expr) void {
.Struct => |val| { .Struct => |val| {
std.debug.warn("({} (", .{val.name.lexeme}); std.debug.warn("({} (", .{val.name.lexeme});
for (val.inits.toSlice()) |init| { for (val.inits.items) |init| {
std.debug.warn(" ({} ", .{init.field.lexeme}); std.debug.warn(" ({} ", .{init.field.lexeme});
printExpr(init.expr); printExpr(init.expr);
std.debug.warn(")", .{}); 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) }); 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); printScope(child, ident + 1);
} }
} }
@ -366,7 +366,7 @@ pub fn printContext(ctx: CompilationContext) void {
prettyType(fn_sym.return_type), 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).?; var param_kv = fn_sym.parameters.get(param.name.lexeme).?;
std.debug.warn("\tparameter {} typ {}\n", .{ std.debug.warn("\tparameter {} typ {}\n", .{
param_kv.key, param_kv.key,

View file

@ -185,12 +185,12 @@ pub const Codegen = struct {
var args = LLVMValueList.init(self.allocator); var args = LLVMValueList.init(self.allocator);
errdefer args.deinit(); errdefer args.deinit();
for (call.arguments.toSlice()) |arg_expr| { for (call.arguments.items) |arg_expr| {
var arg_val = try self.emitExpr(builder, &arg_expr); var arg_val = try self.emitExpr(builder, &arg_expr);
try args.append(arg_val); try args.append(arg_val);
} }
var args_slice = args.toSlice(); var args_slice = args.items;
return llvm.LLVMBuildCall( return llvm.LLVMBuildCall(
builder, builder,
@ -294,7 +294,7 @@ pub const Codegen = struct {
self.ctx.setScope(self.ctx.current_scope.?.nextChild()); 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| { for (then_branch) |_, idx| {
// keep emitting until branch has ret // keep emitting until branch has ret
var then_stmt = &then_branch[idx]; var then_stmt = &then_branch[idx];
@ -326,7 +326,7 @@ pub const Codegen = struct {
if (ifstmt.else_branch) |else_block| { if (ifstmt.else_branch) |else_block| {
self.ctx.setScope(self.ctx.current_scope.?.nextChild()); self.ctx.setScope(self.ctx.current_scope.?.nextChild());
var else_slice = else_block.toSlice(); var else_slice = else_block.items;
for (else_slice) |_, idx| { for (else_slice) |_, idx| {
// keep emitting until branch has ret // keep emitting until branch has ret
var else_stmt = &else_slice[idx]; var else_stmt = &else_slice[idx];
@ -418,7 +418,7 @@ pub const Codegen = struct {
var param_types = llvm.LLVMTypeList.init(self.allocator); var param_types = llvm.LLVMTypeList.init(self.allocator);
errdefer param_types.deinit(); 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( try param_types.append(try self.typeToLLVM(fn_sym.parameters.get(
param.name.lexeme, param.name.lexeme,
).?.value.typ)); ).?.value.typ));
@ -426,7 +426,7 @@ pub const Codegen = struct {
var llvm_ret_type = llvm.LLVMFunctionType( var llvm_ret_type = llvm.LLVMFunctionType(
try self.typeToLLVM(fn_sym.return_type), try self.typeToLLVM(fn_sym.return_type),
param_types.toSlice().ptr, param_types.items.ptr,
@intCast(c_uint, param_types.len), @intCast(c_uint, param_types.len),
0, 0,
); );
@ -444,7 +444,7 @@ pub const Codegen = struct {
// to have the ability to mutate parameters, we must allocate them on // to have the ability to mutate parameters, we must allocate them on
// the stack // the stack
var params_slice = decl.params.toSlice(); var params_slice = decl.params.items;
for (params_slice) |param_node, idx| { 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).?.value;
@ -467,7 +467,7 @@ pub const Codegen = struct {
// TODO check if stmt is return and if we already // TODO check if stmt is return and if we already
// returned before // returned before
var body_slice = decl.body.toSlice(); var body_slice = decl.body.items;
for (body_slice) |_, idx| { for (body_slice) |_, idx| {
try self.emitStmt(builder, &body_slice[idx]); try self.emitStmt(builder, &body_slice[idx]);
} }
@ -480,7 +480,7 @@ pub const Codegen = struct {
.Enum => {}, .Enum => {},
.ConstDecl => |constdecls| { .ConstDecl => |constdecls| {
for (constdecls.toSlice()) |constdecl| { for (constdecls.items) |constdecl| {
const name = constdecl.name.lexeme; const name = constdecl.name.lexeme;
var const_type = self.ctx.symbol_table.get(name).?.value; var const_type = self.ctx.symbol_table.get(name).?.value;
@ -515,7 +515,7 @@ pub const Codegen = struct {
var mod = llvm.LLVMModuleCreateWithName("awoo").?; var mod = llvm.LLVMModuleCreateWithName("awoo").?;
defer llvm.LLVMDisposeModule(mod); defer llvm.LLVMDisposeModule(mod);
var root_slice = root.Root.toSlice(); var root_slice = root.Root.items;
for (root_slice) |_, idx| { for (root_slice) |_, idx| {
try self.genNode(mod, &root_slice[idx]); try self.genNode(mod, &root_slice[idx]);
} }

View file

@ -271,7 +271,7 @@ pub const CompilationContext = struct {
pub fn insertStruct(self: *@This(), struc: ast.Struct, field_types: TypeList) !void { pub fn insertStruct(self: *@This(), struc: ast.Struct, field_types: TypeList) !void {
var type_map = UnderlyingTypeMap.init(self.allocator); 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)); _ = try type_map.put(field.name.lexeme, field_types.at(idx));
} }
@ -289,7 +289,7 @@ pub const CompilationContext = struct {
) !void { ) !void {
var param_map = ParameterMap.init(self.allocator); 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); var param_sym = try self.allocator.create(Parameter);
param_sym.* = Parameter{ param_sym.* = Parameter{
@ -326,7 +326,7 @@ pub const CompilationContext = struct {
errdefer ident_map.deinit(); errdefer ident_map.deinit();
// TODO change this when enums get support for custom values // 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)); _ = try ident_map.put(token.lexeme, @intCast(u32, idx));
} }