From fba9b0f327f1e5bff78689b9f6e72aef45932f3c Mon Sep 17 00:00:00 2001 From: David Gonzalez Martin Date: Sat, 26 Apr 2025 19:32:35 -0600 Subject: [PATCH] wip --- src/bootstrap.zig | 60 +++++++++++++++++++++++++++++++++++++++-------- src/compiler.bbb | 26 ++++++++++++++++++++ 2 files changed, 76 insertions(+), 10 deletions(-) diff --git a/src/bootstrap.zig b/src/bootstrap.zig index a93b87f..2e5ac13 100644 --- a/src/bootstrap.zig +++ b/src/bootstrap.zig @@ -5998,6 +5998,20 @@ pub const Module = struct { }, }, .variable_reference => unreachable, + .call => |call| b: { + const callable = module.clone_value(scope, call.callable); + const arguments = module.arena.allocate(*Value, call.arguments.len); + for (arguments, call.arguments) |*new_argument, old_argument| { + new_argument.* = module.clone_value(scope, old_argument); + } + break :b .{ + .call = .{ + .callable = callable, + .arguments = arguments, + .function_type = call.function_type, + }, + }; + }, else => @trap(), }, .kind = source.kind, @@ -7198,10 +7212,8 @@ pub const Module = struct { const slice_length = if (has_start) { @trap(); - } else if (slice_expression.end) |end| { - _ = end; - @trap(); - } else llvm_integer_index_type.get_constant(array.element_count, 0).to_value(); + } else if (slice_expression.end) |end| end.llvm.? + else llvm_integer_index_type.get_constant(array.element_count, 0).to_value(); return .{ slice_pointer, slice_length }; }, @@ -8466,10 +8478,8 @@ pub const Module = struct { const start = for_loop.right_values[0]; const end = for_loop.right_values[1]; const local_type = switch (start.bb) { - .constant_integer => |_| switch (end.bb) { - .constant_integer => |_| { - @trap(); - }, + .constant_integer => |start_constant_integer| switch (end.bb) { + .constant_integer => |end_constant_integer| module.integer_type(64, !(!start_constant_integer.signed and !end_constant_integer.signed)), else => blk: { module.analyze_value_type(end, .{}); start.type = end.type; @@ -8579,7 +8589,21 @@ pub const Module = struct { uint64.resolve(module); _ = module.llvm.builder.create_memcpy(left_llvm, pointer_type.bb.pointer.alignment.?, global_variable.to_value(), alignment, uint64.llvm.abi.?.to_integer().get_constant(array_initialization.values.len * pointer_type.bb.pointer.type.bb.array.element_type.get_byte_size(), @intFromBool(false)).to_value()); }, - false => @trap(), + false => { + assert(value_type.bb == .array); + const uint64 = module.integer_type(64, false); + uint64.resolve(module); + const u64_zero = uint64.llvm.abi.?.to_integer().get_constant(0, 0).to_value(); + const pointer_to_element_type = module.get_pointer_type(.{ .type = value_type.bb.array.element_type }); + for (array_initialization.values, 0..) |v, i| { + const alloca_gep = module.llvm.builder.create_gep(.{ + .type = value_type.llvm.memory.?, + .aggregate = left_llvm, + .indices = &.{ u64_zero, uint64.llvm.abi.?.to_integer().get_constant(i, 0).to_value() }, + }); + module.emit_assignment(alloca_gep, pointer_to_element_type, v); + } + }, }, .aggregate_initialization => |aggregate_initialization| switch (aggregate_initialization.is_constant) { true => { @@ -9121,8 +9145,24 @@ pub const Module = struct { break :blk result_type; }, - else => ty, + .pointer => |*pointer| blk: { + pointer.type = module.resolve_type(pointer.type); + break :blk ty; + }, + .structure => |structure| blk: { + for (structure.fields) |*field| { + field.type = module.resolve_type(field.type); + } + break :blk ty; + }, + .integer => ty, + .array => |*array| blk: { + array.element_type = module.resolve_type(array.element_type); + break :blk ty; + }, + else => @trap(), }; + assert(result_type.bb != .unresolved); return result_type; } diff --git a/src/compiler.bbb b/src/compiler.bbb index a6df1b1..cb123b2 100644 --- a/src/compiler.bbb +++ b/src/compiler.bbb @@ -586,9 +586,35 @@ CompileOptions = struct silent: u1, } +Type = struct +{ + foo: u32, +} + compile = fn (arena: &Arena, options: CompileOptions) void { >signs: [2]u1 = [0, 1]; + + >type_allocation = arena_allocate[Type](arena, + 64 * 2 // Basic integer types + + 2 // u128, s128 + + 2 // void, noreturn + ); + + for (sign: signs) + { + for (b: 0..64) + { + >bit_count = b + 1; + >first_digit: u8 = #truncate(#select(bit_count < 10, bit_count % 10 + '0', bit_count / 10 + '0')); + >second_digit: u8 = #truncate(#select(bit_count > 9, bit_count % 10 + '0', 0)); + >name_buffer: [3]u8 = [ #select(sign, 's', 'u'), first_digit, second_digit ]; + >name_length: u64 = 2 + #extend(bit_count > 9); + + >name = arena_duplicate_string(arena, name_buffer[..name_length]); + + } + } } compile_file = fn (arena: &Arena, compile_options: CompileFile) void