// FUNCTIONS
-args_get :: (argv: ^^u8, argv_buf: ^u8) -> Errno #foreign "wasi_unstable" "args_get"---
-args_sizes_get :: (argc: ^Size, argv_buf_size: ^Size) -> Errno #foreign "wasi_unstable" "args_sizes_get" ---
-
-environ_get :: (environ: ^^u8, environ_buf: ^u8) -> Errno #foreign "wasi_unstable" "environ_get" ---
-environ_sizes_get :: (environc: ^Size, environ_buf_size: ^Size) -> Errno #foreign "wasi_unstable" "environ_sizes_get" ---
-
-clock_res_get :: (id: ClockID, resolution: ^Timestamp) -> Errno #foreign "wasi_unstable" "clock_res_get" ---
-clock_time_get :: (id: ClockID, precision: Timestamp, time: ^Timestamp) -> Errno #foreign "wasi_unstable" "clock_time_get" ---
-
-fd_advise :: (fd: FileDescriptor, offset: Filesize, len: Filesize, advice: Advice) -> Errno #foreign "wasi_unstable" "fd_advise" ---
-fd_allocate :: (fd: FileDescriptor, offset: Filesize, len: Filesize) -> Errno #foreign "wasi_unstable" "fd_allocate" ---
-fd_close :: (fd: FileDescriptor) -> Errno #foreign "wasi_unstable" "fd_close" ---
-fd_datasync :: (fd: FileDescriptor) -> Errno #foreign "wasi_unstable" "fd_datasync" ---
-fd_fdstat_get :: (fd: FileDescriptor, stat: ^FDStat) -> Errno #foreign "wasi_unstable" "fd_fdstat_get" ---
-fd_fdstat_set_flags :: (fd: FileDescriptor, flags: FDFlags) -> Errno #foreign "wasi_unstable" "fd_fdstat_set_flags" ---
-fd_fdstat_set_rights :: (fd: FileDescriptor, rights_base: Rights, rights_inheriting: Rights) -> Errno #foreign "wasi_unstable" "fd_fdstat_set_rights" ---
-fd_filestat_get :: (fd: FileDescriptor, buf: ^FileStat) -> Errno #foreign "wasi_unstable" "fd_filestat_get" ---
-fd_filestat_set_size :: (fd: FileDescriptor, size: Filesize) -> Errno #foreign "wasi_unstable" "fd_filestat_set_size" ---
-fd_filestat_set_times :: (fd: FileDescriptor, atim: Timestamp, mtim: Timestamp, fst_flags: FSTFlags) -> Errno #foreign "wasi_unstable" "fd_filestat_set_times" ---
-fd_pread :: (fd: FileDescriptor, iovs: IOVecArray, offset: Filesize, nread: ^Size) -> Errno #foreign "wasi_unstable" "fd_pread" ---
-fd_prestat_get :: (fd: FileDescriptor, buf: ^PrestatTagged) -> Errno #foreign "wasi_unstable" "fd_prestat_get" ---
-fd_prestat_dir_name :: (fd: FileDescriptor, path: str) -> Errno #foreign "wasi_unstable" "fd_prestat_dir_name" ---
-fd_pwrite :: (fd: FileDescriptor, iovs: IOVecArray, offset: Filesize, nwritten: ^Size) -> Errno #foreign "wasi_unstable" "fd_pwrite" ---
-fd_read :: (fd: FileDescriptor, iovs: IOVecArray, nread: ^Size) -> Errno #foreign "wasi_unstable" "fd_read" ---
-fd_readdir :: (fd: FileDescriptor, buf: ^u8, buf_len: Size, cookie: DirCookie, bufused: ^Size) -> Errno #foreign "wasi_unstable" "fd_readdir" ---
-fd_renumber :: (fd: FileDescriptor, to: FileDescriptor) -> Errno #foreign "wasi_unstable" "fd_renumber" ---
-fd_seek :: (fd: FileDescriptor, offset: FileDelta, whence: Whence, newoffset: ^Filesize) -> Errno #foreign "wasi_unstable" "fd_seek" ---
-fd_sync :: (fd: FileDescriptor) -> Errno #foreign "wasi_unstable" "fd_sync" ---
-fd_tell :: (fd: FileDescriptor, offset: ^Filesize) -> Errno #foreign "wasi_unstable" "fd_tell" ---
-fd_write :: (fd: FileDescriptor, iovs: IOVecArray, nwritten: ^Size) -> Errno #foreign "wasi_unstable" "fd_write" ---
-
-path_create_directory :: (fd: FileDescriptor, path: str) -> Errno #foreign "wasi_unstable" "path_create_directory" ---
-path_filestat_get :: (fd: FileDescriptor, flags: LookupFlags, path: str, buf: ^FileStat) -> Errno #foreign "wasi_unstable" "path_filestat_get" ---
-path_filestat_set_times :: (fd: FileDescriptor, flags: LookupFlags, path: str, atim: Timestamp, mtim: Timestamp, fst_flags: FSTFlags) -> Errno #foreign "wasi_unstable" "path_filestat_set_times" ---
-
-path_link :: (fd: FileDescriptor, old_flags: LookupFlags, old_path: str, new_fd: FileDescriptor, new_path: str) -> Errno #foreign "wasi_unstable" "path_link" ---
+args_get :: (argv: ^^u8, argv_buf: ^u8) -> Errno #foreign "wasi_snapshot_preview1" "args_get"---
+args_sizes_get :: (argc: ^Size, argv_buf_size: ^Size) -> Errno #foreign "wasi_snapshot_preview1" "args_sizes_get" ---
+
+environ_get :: (environ: ^^u8, environ_buf: ^u8) -> Errno #foreign "wasi_snapshot_preview1" "environ_get" ---
+environ_sizes_get :: (environc: ^Size, environ_buf_size: ^Size) -> Errno #foreign "wasi_snapshot_preview1" "environ_sizes_get" ---
+
+clock_res_get :: (id: ClockID, resolution: ^Timestamp) -> Errno #foreign "wasi_snapshot_preview1" "clock_res_get" ---
+clock_time_get :: (id: ClockID, precision: Timestamp, time: ^Timestamp) -> Errno #foreign "wasi_snapshot_preview1" "clock_time_get" ---
+
+fd_advise :: (fd: FileDescriptor, offset: Filesize, len: Filesize, advice: Advice) -> Errno #foreign "wasi_snapshot_preview1" "fd_advise" ---
+fd_allocate :: (fd: FileDescriptor, offset: Filesize, len: Filesize) -> Errno #foreign "wasi_snapshot_preview1" "fd_allocate" ---
+fd_close :: (fd: FileDescriptor) -> Errno #foreign "wasi_snapshot_preview1" "fd_close" ---
+fd_datasync :: (fd: FileDescriptor) -> Errno #foreign "wasi_snapshot_preview1" "fd_datasync" ---
+fd_fdstat_get :: (fd: FileDescriptor, stat: ^FDStat) -> Errno #foreign "wasi_snapshot_preview1" "fd_fdstat_get" ---
+fd_fdstat_set_flags :: (fd: FileDescriptor, flags: FDFlags) -> Errno #foreign "wasi_snapshot_preview1" "fd_fdstat_set_flags" ---
+fd_fdstat_set_rights :: (fd: FileDescriptor, rights_base: Rights, rights_inheriting: Rights) -> Errno #foreign "wasi_snapshot_preview1" "fd_fdstat_set_rights" ---
+fd_filestat_get :: (fd: FileDescriptor, buf: ^FileStat) -> Errno #foreign "wasi_snapshot_preview1" "fd_filestat_get" ---
+fd_filestat_set_size :: (fd: FileDescriptor, size: Filesize) -> Errno #foreign "wasi_snapshot_preview1" "fd_filestat_set_size" ---
+fd_filestat_set_times :: (fd: FileDescriptor, atim: Timestamp, mtim: Timestamp, fst_flags: FSTFlags) -> Errno #foreign "wasi_snapshot_preview1" "fd_filestat_set_times" ---
+fd_pread :: (fd: FileDescriptor, iovs: IOVecArray, offset: Filesize, nread: ^Size) -> Errno #foreign "wasi_snapshot_preview1" "fd_pread" ---
+fd_prestat_get :: (fd: FileDescriptor, buf: ^PrestatTagged) -> Errno #foreign "wasi_snapshot_preview1" "fd_prestat_get" ---
+fd_prestat_dir_name :: (fd: FileDescriptor, path: str) -> Errno #foreign "wasi_snapshot_preview1" "fd_prestat_dir_name" ---
+fd_pwrite :: (fd: FileDescriptor, iovs: IOVecArray, offset: Filesize, nwritten: ^Size) -> Errno #foreign "wasi_snapshot_preview1" "fd_pwrite" ---
+fd_read :: (fd: FileDescriptor, iovs: IOVecArray, nread: ^Size) -> Errno #foreign "wasi_snapshot_preview1" "fd_read" ---
+fd_readdir :: (fd: FileDescriptor, buf: ^u8, buf_len: Size, cookie: DirCookie, bufused: ^Size) -> Errno #foreign "wasi_snapshot_preview1" "fd_readdir" ---
+fd_renumber :: (fd: FileDescriptor, to: FileDescriptor) -> Errno #foreign "wasi_snapshot_preview1" "fd_renumber" ---
+fd_seek :: (fd: FileDescriptor, offset: FileDelta, whence: Whence, newoffset: ^Filesize) -> Errno #foreign "wasi_snapshot_preview1" "fd_seek" ---
+fd_sync :: (fd: FileDescriptor) -> Errno #foreign "wasi_snapshot_preview1" "fd_sync" ---
+fd_tell :: (fd: FileDescriptor, offset: ^Filesize) -> Errno #foreign "wasi_snapshot_preview1" "fd_tell" ---
+fd_write :: (fd: FileDescriptor, iovs: IOVecArray, nwritten: ^Size) -> Errno #foreign "wasi_snapshot_preview1" "fd_write" ---
+
+path_create_directory :: (fd: FileDescriptor, path: str) -> Errno #foreign "wasi_snapshot_preview1" "path_create_directory" ---
+path_filestat_get :: (fd: FileDescriptor, flags: LookupFlags, path: str, buf: ^FileStat) -> Errno #foreign "wasi_snapshot_preview1" "path_filestat_get" ---
+path_filestat_set_times :: (fd: FileDescriptor, flags: LookupFlags, path: str, atim: Timestamp, mtim: Timestamp, fst_flags: FSTFlags) -> Errno #foreign "wasi_snapshot_preview1" "path_filestat_set_times" ---
+
+path_link :: (fd: FileDescriptor, old_flags: LookupFlags, old_path: str, new_fd: FileDescriptor, new_path: str) -> Errno #foreign "wasi_snapshot_preview1" "path_link" ---
path_open :: (fd: FileDescriptor
, dirflags: LookupFlags
, path: str
, fdflags: FDFlags
, opened_fd: ^FileDescriptor
) -> Errno
- #foreign "wasi_unstable" "path_open" ---
+ #foreign "wasi_snapshot_preview1" "path_open" ---
-path_readlink :: (fd: FileDescriptor, path: str, buf: ^u8, buf_len: Size, bufused: ^Size) -> Errno #foreign "wasi_unstable" "path_readlink" ---
-path_remove_directory :: (fd: FileDescriptor, path: str) -> Errno #foreign "wasi_unstable" "path_remove_directory" ---
-path_rename :: (fd: FileDescriptor, old_path: str, new_fd: FileDescriptor, new_path: str) -> Errno #foreign "wasi_unstable" "path_rename" ---
-path_symlink :: (old_path: ^u8, old_path_len: Size, fd: FileDescriptor, new_path: str) -> Errno #foreign "wasi_unstable" "path_symlink" ---
-path_unlink_file :: (fd: FileDescriptor, path: str) -> Errno #foreign "wasi_unstable" "path_unlink_file" ---
+path_readlink :: (fd: FileDescriptor, path: str, buf: ^u8, buf_len: Size, bufused: ^Size) -> Errno #foreign "wasi_snapshot_preview1" "path_readlink" ---
+path_remove_directory :: (fd: FileDescriptor, path: str) -> Errno #foreign "wasi_snapshot_preview1" "path_remove_directory" ---
+path_rename :: (fd: FileDescriptor, old_path: str, new_fd: FileDescriptor, new_path: str) -> Errno #foreign "wasi_snapshot_preview1" "path_rename" ---
+path_symlink :: (old_path: ^u8, old_path_len: Size, fd: FileDescriptor, new_path: str) -> Errno #foreign "wasi_snapshot_preview1" "path_symlink" ---
+path_unlink_file :: (fd: FileDescriptor, path: str) -> Errno #foreign "wasi_snapshot_preview1" "path_unlink_file" ---
-poll_oneoff :: (in: ^Subscription, out: ^Event, nsubscriptions: Size, nevents: ^Size) -> Errno #foreign "wasi_unstable" "poll_oneoff" ---
+poll_oneoff :: (in: ^Subscription, out: ^Event, nsubscriptions: Size, nevents: ^Size) -> Errno #foreign "wasi_snapshot_preview1" "poll_oneoff" ---
-proc_exit :: (rval: ExitCode) -> void #foreign "wasi_unstable" "proc_exit" ---
-proc_raise :: (sig: Signal) -> Errno #foreign "wasi_unstable" "proc_raise" ---
+proc_exit :: (rval: ExitCode) -> void #foreign "wasi_snapshot_preview1" "proc_exit" ---
+proc_raise :: (sig: Signal) -> Errno #foreign "wasi_snapshot_preview1" "proc_raise" ---
-sched_yield :: () -> Errno #foreign "wasi_unstable" "sched_yield" ---
+sched_yield :: () -> Errno #foreign "wasi_snapshot_preview1" "sched_yield" ---
-random_get :: (buf: ^u8, buf_len: Size) -> Errno #foreign "wasi_unstable" "random_get" ---
+random_get :: (buf: ^u8, buf_len: Size) -> Errno #foreign "wasi_snapshot_preview1" "random_get" ---
-sock_recv :: (fd: FileDescriptor, ri_data: IOVecArray, ri_flags: RIFlags, ro_datalen: ^Size, ro_flags: ^ROFlags) -> Errno #foreign "wasi_unstable" "sock_recv" ---
-sock_send :: (fd: FileDescriptor, si_data: IOVecArray, si_flags: SIFlags, so_datalen: ^Size) -> Errno #foreign "wasi_unstable" "sock_send" ---
-sock_shutdown :: (fd: FileDescriptor, how: SDFlags) -> Errno #foreign "wasi_unstable" "sock_shutdown" ---
+sock_recv :: (fd: FileDescriptor, ri_data: IOVecArray, ri_flags: RIFlags, ro_datalen: ^Size, ro_flags: ^ROFlags) -> Errno #foreign "wasi_snapshot_preview1" "sock_recv" ---
+sock_send :: (fd: FileDescriptor, si_data: IOVecArray, si_flags: SIFlags, so_datalen: ^Size) -> Errno #foreign "wasi_snapshot_preview1" "sock_send" ---
+sock_shutdown :: (fd: FileDescriptor, how: SDFlags) -> Errno #foreign "wasi_snapshot_preview1" "sock_shutdown" ---
{ Type_Kind_Basic, 0, (AstType *) &basic_type_v128, { Basic_Kind_V128, Basic_Flag_SIMD, 16, 16, "v128" } },
};
-b32 types_are_surface_compatible(Type* t1, Type* t2) {
- // NOTE: If they are pointing to the same thing,
- // it is safe to assume they are the same type
- if (t1 == t2) return 1;
- if (t1 == NULL || t2 == NULL) return 0;
-
- switch (t1->kind) {
- case Type_Kind_Basic:
- if (t2->kind == Type_Kind_Basic) {
- // HACK: Not sure if this is right way to check this?
- if (t1 == t2) return 1;
-
- if ((t1->Basic.flags & Basic_Flag_Integer) && (t2->Basic.flags & Basic_Flag_Integer)) {
- return t1->Basic.size == t2->Basic.size;
- }
-
- if (t1->Basic.kind == Basic_Kind_Rawptr && type_is_pointer(t2)) {
- return 1;
- }
- }
- break;
-
- case Type_Kind_Pointer:
- if (t2->kind != Type_Kind_Pointer) return 0;
-
- if (t1->Pointer.elem->kind == Type_Kind_Basic && t2->Pointer.elem->kind == Type_Kind_Basic)
- return types_are_compatible(t1->Pointer.elem, t2->Pointer.elem);
-
- return 1;
-
- case Type_Kind_Array: {
- if (t2->kind != Type_Kind_Array) return 0;
-
- if (t1->Array.count != 0)
- if (t1->Array.count != t2->Array.count) return 0;
-
- return types_are_compatible(t1->Array.elem, t2->Array.elem);
- }
-
- case Type_Kind_Struct: {
- if (t2->kind != Type_Kind_Struct) return 0;
- if (t1->Struct.mem_count != t2->Struct.mem_count) return 0;
- if (t1->Struct.name && t2->Struct.name)
- if (strcmp(t1->Struct.name, t2->Struct.name) == 0) return 1;
-
- b32 works = 1;
- bh_table_each_start(StructMember, t1->Struct.members);
- if (!bh_table_has(StructMember, t2->Struct.members, (char *) key)) return 0;
- StructMember other = bh_table_get(StructMember, t2->Struct.members, (char *) key);
- if (other.offset != value.offset) return 0;
-
- if (!types_are_compatible(value.type, other.type)) {
- works = 0;
- break;
- }
- bh_table_each_end;
-
- return works;
- }
-
- case Type_Kind_Enum: {
- if (t2->kind != Type_Kind_Enum) return 0;
- return t1 == t2;
- }
-
- case Type_Kind_Slice: {
- if (t2->kind != Type_Kind_Slice) return 0;
- return types_are_compatible(t1->Slice.ptr_to_data->Pointer.elem, t2->Slice.ptr_to_data->Pointer.elem);
- }
-
- case Type_Kind_VarArgs: {
- if (t2->kind != Type_Kind_VarArgs) return 0;
- return types_are_compatible(t1->VarArgs.ptr_to_data->Pointer.elem, t2->VarArgs.ptr_to_data->Pointer.elem);
- }
-
- case Type_Kind_DynArray: {
- if (t2->kind != Type_Kind_DynArray) return 0;
- return types_are_compatible(t1->DynArray.ptr_to_data->Pointer.elem, t2->DynArray.ptr_to_data->Pointer.elem);
- }
-
- default:
- assert(("Invalid type", 0));
- break;
- }
-
- return 0;
-}
-
-b32 types_are_compatible(Type* t1, Type* t2) {
+b32 types_are_compatible_(Type* t1, Type* t2, b32 recurse_pointers) {
// NOTE: If they are pointing to the same thing,
// it is safe to assume they are the same type
if (t1 == t2) return 1;
case Type_Kind_Pointer: {
if (t2->kind == Type_Kind_Pointer) {
+ if (!recurse_pointers) return 1;
+
if (types_are_compatible(t1->Pointer.elem, t2->Pointer.elem)) return 1;
if (t1->Pointer.elem->kind == Type_Kind_Struct && t2->Pointer.elem->kind == Type_Kind_Struct) {
case Type_Kind_Struct: {
if (t2->kind != Type_Kind_Struct) return 0;
+ if (t1->Struct.unique_id != t2->Struct.unique_id) return 0;
if (t1->Struct.mem_count != t2->Struct.mem_count) return 0;
b32 works = 1;
StructMember other = bh_table_get(StructMember, t2->Struct.members, (char *) key);
if (other.offset != value.offset) return 0;
- if (!types_are_surface_compatible(value.type, other.type)) {
+ // NOTE: Don't recurse down pointers; This could be a problem, but it is a quick
+ // fix for the problem that occurs when using a linked-list style data structure.
+ if (!types_are_compatible_(value.type, other.type, 0)) {
works = 0;
break;
}
}
case Type_Kind_Enum: {
+ // NOTE: The check above for t1 == t2 would already catch this.
return 0;
- // if (t2->kind != Type_Kind_Enum) return 0;
- // return t1 == t2;
}
case Type_Kind_Function: {
return 0;
}
+b32 types_are_compatible(Type* t1, Type* t2) {
+ return types_are_compatible_(t1, t2, 1);
+}
+
u32 type_size_of(Type* type) {
if (type == NULL) return 0;