This commit is contained in:
David Gonzalez Martin 2025-04-20 21:20:12 -06:00
parent b8873564af
commit cd2608f0c2
2 changed files with 110 additions and 4 deletions

View File

@ -5472,7 +5472,10 @@ pub const Module = struct {
pub fn check_types(module: *Module, expected_type: *Type, source_type: *Type) void { pub fn check_types(module: *Module, expected_type: *Type, source_type: *Type) void {
if (expected_type != source_type) { if (expected_type != source_type) {
const dst_p_src_i = expected_type.bb == .pointer and source_type.bb == .integer; const dst_p_src_i = expected_type.bb == .pointer and source_type.bb == .integer;
const result = dst_p_src_i; const dst_alias_src_not = expected_type.bb == .alias and expected_type.bb.alias.type == source_type;
const src_alias_dst_not = source_type.bb == .alias and source_type.bb.alias.type == expected_type;
const both_alias_to_same_type = expected_type.bb == .alias and source_type.bb == .alias and expected_type.bb.alias.type == source_type.bb.alias.type;
const result = dst_p_src_i or dst_alias_src_not or src_alias_dst_not or both_alias_to_same_type;
if (!result) { if (!result) {
module.report_error(); module.report_error();
} }

View File

@ -1,9 +1,45 @@
mode_t = typealias u64; mode_t = typealias u64;
int = typealias s32;
usize = typealias u64;
File = typealias s32;
[extern] memcmp = fn [cc(c)] (a: &u8, b: &u8, byte_count: u64) s32; OAccessMode = enum u2
{
read_only = 0,
write_only = 1,
read_write = 2,
}
O = bits u32
{
access_mode: OAccessMode,
_: u4,
creat: u1,
excl: u1,
noctty: u1,
trunc: u1,
append: u1,
nonblock: u1,
dsync: u1,
async: u1,
direct: u1,
_: u1,
directory: u1,
nofollow: u1,
noatime: u1,
cloexec: u1,
sync: u1,
path: u1,
tmpfile: u1,
_: u9,
}
[extern] memcmp = fn [cc(c)] (a: &u8, b: &u8, byte_count: usize) int;
[extern] memcpy = fn [cc(c)] (destination: &u8, source: &u8, byte_count: u64) &u8; [extern] memcpy = fn [cc(c)] (destination: &u8, source: &u8, byte_count: u64) &u8;
[extern] exit = fn [cc(c)] (exit_code: s32) noreturn; [extern] exit = fn [cc(c)] (exit_code: int) noreturn;
[extern] mkdir = fn [cc(c)] (path: &u8, mode: mode_t) s32;
[extern] mkdir = fn [cc(c)] (path: &u8, mode: mode_t) int;
[extern] open = fn [cc(c)] (path: &u8, o: O, ...) int;
assert = fn (ok: u1) void assert = fn (ok: u1) void
{ {
@ -177,6 +213,55 @@ os_make_directory = fn (path: &u8) void
>result = mkdir(path, 0o755); >result = mkdir(path, 0o755);
} }
OpenFlags = bits
{
truncate: u1,
execute: u1,
write: u1,
read: u1,
create: u1,
directory: u1,
}
OpenPermissions = bits
{
read: u1,
write: u1,
execute: u1,
}
os_file_open = fn (path: &u8, flags: OpenFlags, permissions: OpenPermissions) File
{
>access_mode: OAccessMode = undefined;
if (flags.read and flags.write)
{
access_mode = .read_write;
}
else if (flags.read)
{
access_mode = .read_only;
}
else if (flags.write)
{
access_mode = .write_only;
}
else
{
unreachable;
}
>o: O = {
.access_mode = access_mode,
.trunc = flags.truncate,
.creat = flags.create,
.directory = flags.directory,
};
>mode: mode_t = #select(permissions.execute, 0o755, 0o644);
>fd = open(path, o, mode);
return fd;
}
Arena = struct Arena = struct
{ {
reserved_size: u64, reserved_size: u64,
@ -288,6 +373,11 @@ arena_join_string = fn (arena: &Arena, pieces: [][]u8) []u8
return pointer[..size]; return pointer[..size];
} }
file_read = fn (arena: &Arena, path: []u8) []u8
{
>fd = os_file_open(path.pointer, { .read = 1 }, { .read = 1 });
}
GlobalState = struct GlobalState = struct
{ {
arena: &Arena, arena: &Arena,
@ -371,6 +461,19 @@ compile_file = fn (arena: &Arena, compile: CompileFile) void
"_", "_",
#select(compile.has_debug_info, "di", "nodi"), #select(compile.has_debug_info, "di", "nodi"),
][..]); ][..]);
os_make_directory(base_cache_dir.pointer);
if (is_compiler)
{
>compiler_dir = arena_join_string(arena, [ base_cache_dir, "/compiler" ][..]);
os_make_directory(compiler_dir.pointer);
}
os_make_directory(outputh_path_dir.pointer);
>outputh_path_base = arena_join_string(arena, [ outputh_path_dir, "/", base_name ][..]);
>output_object_path = arena_join_string(arena, [ outputh_path_base, ".o" ][..]);
>output_executable_path = outputh_path_base;
} }
[export] main = fn [cc(c)] (argument_count: u32, argv: &&u8) s32 [export] main = fn [cc(c)] (argument_count: u32, argv: &&u8) s32