wip
This commit is contained in:
parent
71707473bd
commit
fba9b0f327
@ -5998,6 +5998,20 @@ pub const Module = struct {
|
|||||||
},
|
},
|
||||||
},
|
},
|
||||||
.variable_reference => unreachable,
|
.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(),
|
else => @trap(),
|
||||||
},
|
},
|
||||||
.kind = source.kind,
|
.kind = source.kind,
|
||||||
@ -7198,10 +7212,8 @@ pub const Module = struct {
|
|||||||
|
|
||||||
const slice_length = if (has_start) {
|
const slice_length = if (has_start) {
|
||||||
@trap();
|
@trap();
|
||||||
} else if (slice_expression.end) |end| {
|
} else if (slice_expression.end) |end| end.llvm.?
|
||||||
_ = end;
|
else llvm_integer_index_type.get_constant(array.element_count, 0).to_value();
|
||||||
@trap();
|
|
||||||
} else llvm_integer_index_type.get_constant(array.element_count, 0).to_value();
|
|
||||||
|
|
||||||
return .{ slice_pointer, slice_length };
|
return .{ slice_pointer, slice_length };
|
||||||
},
|
},
|
||||||
@ -8466,10 +8478,8 @@ pub const Module = struct {
|
|||||||
const start = for_loop.right_values[0];
|
const start = for_loop.right_values[0];
|
||||||
const end = for_loop.right_values[1];
|
const end = for_loop.right_values[1];
|
||||||
const local_type = switch (start.bb) {
|
const local_type = switch (start.bb) {
|
||||||
.constant_integer => |_| switch (end.bb) {
|
.constant_integer => |start_constant_integer| switch (end.bb) {
|
||||||
.constant_integer => |_| {
|
.constant_integer => |end_constant_integer| module.integer_type(64, !(!start_constant_integer.signed and !end_constant_integer.signed)),
|
||||||
@trap();
|
|
||||||
},
|
|
||||||
else => blk: {
|
else => blk: {
|
||||||
module.analyze_value_type(end, .{});
|
module.analyze_value_type(end, .{});
|
||||||
start.type = end.type;
|
start.type = end.type;
|
||||||
@ -8579,7 +8589,21 @@ pub const Module = struct {
|
|||||||
uint64.resolve(module);
|
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());
|
_ = 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) {
|
.aggregate_initialization => |aggregate_initialization| switch (aggregate_initialization.is_constant) {
|
||||||
true => {
|
true => {
|
||||||
@ -9121,8 +9145,24 @@ pub const Module = struct {
|
|||||||
|
|
||||||
break :blk result_type;
|
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;
|
return result_type;
|
||||||
}
|
}
|
||||||
|
@ -586,9 +586,35 @@ CompileOptions = struct
|
|||||||
silent: u1,
|
silent: u1,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Type = struct
|
||||||
|
{
|
||||||
|
foo: u32,
|
||||||
|
}
|
||||||
|
|
||||||
compile = fn (arena: &Arena, options: CompileOptions) void
|
compile = fn (arena: &Arena, options: CompileOptions) void
|
||||||
{
|
{
|
||||||
>signs: [2]u1 = [0, 1];
|
>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
|
compile_file = fn (arena: &Arena, compile_options: CompileFile) void
|
||||||
|
Loading…
x
Reference in New Issue
Block a user