diff --git a/.gitea/workflows/ci.yml b/.gitea/workflows/main.yml similarity index 55% rename from .gitea/workflows/ci.yml rename to .gitea/workflows/main.yml index 5df8b3d..97de1a7 100644 --- a/.gitea/workflows/ci.yml +++ b/.gitea/workflows/main.yml @@ -1,17 +1,15 @@ name: CI on: - pull_request: push: tags: - "**" branches: - main - schedule: - - cron: "0 0 * * *" env: BB_CI: 1 + BUILD_DEBUG: 1 jobs: ci: @@ -19,7 +17,7 @@ jobs: fail-fast: false matrix: os: [ ubuntu-latest ] - BIRTH_CMAKE_BUILD_TYPE: [ Debug, Release ] + BIRTH_CMAKE_BUILD_TYPE: [ Debug, Release-assertions, Release ] runs-on: ${{ matrix.os }} steps: - uses: actions/checkout@v4 @@ -32,11 +30,7 @@ jobs: CLANGXX_PATH: clang++-19 run: | set -eux - ./generate.sh - ./build.sh - ./build/bb test - mkdir -p $HOME/bloat-buster-artifacts/$(git rev-parse --abbrev-ref HEAD)/$(git rev-parse HEAD)/$CMAKE_BUILD_TYPE - mv ./self-hosted-bb-cache $HOME/bloat-buster-artifacts/$(git rev-parse --abbrev-ref HEAD)/$(git rev-parse HEAD)/$CMAKE_BUILD_TYPE/cache + ci/reproduce.sh release: needs: ci strategy: @@ -52,8 +46,7 @@ jobs: BB_CI: 1 run: | set -eux - mkdir -p $HOME/bloat-buster-artifacts/releases/$(git rev-parse --abbrev-ref HEAD)/$(git rev-parse HEAD) - cp $HOME/bloat-buster-artifacts/$(git rev-parse --abbrev-ref HEAD)/$(git rev-parse HEAD)/Release/cache/debug_none_di/compiler/aggressively_optimize_for_speed_nodi/compiler $HOME/bloat-buster-artifacts/releases/$(git rev-parse --abbrev-ref HEAD)/$(git rev-parse HEAD) + ci/install.sh - name: Release (locally) if: ${{ (github.ref == 'refs/heads/main') }} shell: bash @@ -61,8 +54,7 @@ jobs: BB_CI: 1 run: | set -eux - cp $HOME/bloat-buster-artifacts/releases/$(git rev-parse --abbrev-ref HEAD)/$(git rev-parse HEAD)/compiler $HOME/bloat-buster-artifacts/releases/main/ - + ci/release.sh - name: Release (web) uses: akkuman/gitea-release-action@v1 if: ${{ (github.ref == 'refs/heads/main') }} @@ -70,4 +62,6 @@ jobs: NODE_OPTIONS: '--experimental-fetch' # if nodejs < 18 with: files: |- - /home/act_runner/bloat-buster-artifacts/releases/main/compiler + /home/act_runner/bloat-buster-artifacts/releases/main/compiler_generic_debug + /home/act_runner/bloat-buster-artifacts/releases/main/compiler_generic + /home/act_runner/bloat-buster-artifacts/releases/main/compiler_native diff --git a/.gitea/workflows/pr.yml b/.gitea/workflows/pr.yml new file mode 100644 index 0000000..b973236 --- /dev/null +++ b/.gitea/workflows/pr.yml @@ -0,0 +1,30 @@ +name: CI + +on: + pull_request: + +env: + BB_CI: 1 + +jobs: + ci: + strategy: + fail-fast: false + matrix: + os: [ ubuntu-latest ] + BIRTH_CMAKE_BUILD_TYPE: [ Release-assertions, Release ] + runs-on: ${{ matrix.os }} + steps: + - uses: actions/checkout@v4 + - name: Build and test (Packaged LLVM) + shell: bash + env: + BB_CI: 1 + CMAKE_BUILD_TYPE: ${{matrix.BIRTH_CMAKE_BUILD_TYPE}} + CLANG_PATH: clang-19 + CLANGXX_PATH: clang++-19 + run: | + set -eux + ./generate.sh + ./build.sh + ./build/bb test diff --git a/ci/install.sh b/ci/install.sh new file mode 100755 index 0000000..16cd308 --- /dev/null +++ b/ci/install.sh @@ -0,0 +1,7 @@ +set -eux +mkdir -p $HOME/bloat-buster-artifacts/releases/$(git rev-parse --abbrev-ref HEAD)/$(git rev-parse HEAD) +if [[ -n "${BUILD_DEBUG:-}" ]]; then + cp $HOME/bloat-buster-artifacts/$(git rev-parse --abbrev-ref HEAD)/$(git rev-parse HEAD)/Debug/cache/generic/debug_none_di/compiler/aggressively_optimize_for_speed_nodi/compiler $HOME/bloat-buster-artifacts/releases/$(git rev-parse --abbrev-ref HEAD)/$(git rev-parse HEAD)/compiler_generic_debug +fi +cp $HOME/bloat-buster-artifacts/$(git rev-parse --abbrev-ref HEAD)/$(git rev-parse HEAD)/Release/cache/generic/debug_none_di/compiler/aggressively_optimize_for_speed_nodi/compiler $HOME/bloat-buster-artifacts/releases/$(git rev-parse --abbrev-ref HEAD)/$(git rev-parse HEAD)/compiler_generic +cp $HOME/bloat-buster-artifacts/$(git rev-parse --abbrev-ref HEAD)/$(git rev-parse HEAD)/Release/cache/native/debug_none_di/compiler/aggressively_optimize_for_speed_nodi/compiler $HOME/bloat-buster-artifacts/releases/$(git rev-parse --abbrev-ref HEAD)/$(git rev-parse HEAD)/compiler_native diff --git a/ci/release.sh b/ci/release.sh new file mode 100755 index 0000000..8e5ef24 --- /dev/null +++ b/ci/release.sh @@ -0,0 +1,6 @@ +set -eux +if [[ -n "${BUILD_DEBUG:-}" ]]; then + cp $HOME/bloat-buster-artifacts/releases/$(git rev-parse --abbrev-ref HEAD)/$(git rev-parse HEAD)/compiler_generic_debug $HOME/bloat-buster-artifacts/releases/main/ +fi +cp $HOME/bloat-buster-artifacts/releases/$(git rev-parse --abbrev-ref HEAD)/$(git rev-parse HEAD)/compiler_generic $HOME/bloat-buster-artifacts/releases/main/ +cp $HOME/bloat-buster-artifacts/releases/$(git rev-parse --abbrev-ref HEAD)/$(git rev-parse HEAD)/compiler_native $HOME/bloat-buster-artifacts/releases/main/ diff --git a/ci/release_locally.sh b/ci/release_locally.sh new file mode 100755 index 0000000..db6a3d8 --- /dev/null +++ b/ci/release_locally.sh @@ -0,0 +1,10 @@ +#!/usr/bin/env bash +set -eux +if [[ -n "${BUILD_DEBUG:-}" ]]; then + export BUILD_DEBUG + CMAKE_BUILD_TYPE=Debug ./reproduce.sh +fi +CMAKE_BUILD_TYPE=Release ./reproduce.sh +CMAKE_BUILD_TYPE=Release-assertions ./reproduce.sh +./install.sh +./release.sh diff --git a/ci/reproduce.sh b/ci/reproduce.sh new file mode 100755 index 0000000..7cd3b47 --- /dev/null +++ b/ci/reproduce.sh @@ -0,0 +1,8 @@ +set -eux +rm -rf bb-cache self-hosted-bb-cache || true +./generate.sh +./build.sh +./build/bb test +mkdir -p $HOME/bloat-buster-artifacts/$(git rev-parse --abbrev-ref HEAD)/$(git rev-parse HEAD)/$CMAKE_BUILD_TYPE +mv ./self-hosted-bb-cache $HOME/bloat-buster-artifacts/$(git rev-parse --abbrev-ref HEAD)/$(git rev-parse HEAD)/$CMAKE_BUILD_TYPE/cache + diff --git a/generate.sh b/generate.sh index 0fc07f6..94c34f3 100755 --- a/generate.sh +++ b/generate.sh @@ -1,10 +1,13 @@ #!/usr/bin/env bash -set -eu +set -eux if [[ -z "${BB_CI:-}" ]]; then + BB_CI=0 +fi + +if [[ -z "${CMAKE_BUILD_TYPE:-}" ]]; then CMAKE_BUILD_TYPE=Debug LLVM_CMAKE_BUILD_TYPE=Release - BB_CI=0 else LLVM_CMAKE_BUILD_TYPE=$CMAKE_BUILD_TYPE fi @@ -36,12 +39,12 @@ esac rm -rf $BUILD_DIR mkdir $BUILD_DIR cd $BUILD_DIR -LLVM_PREFIX_PATH=$HOME/dev/llvm/install/llvm_20.1.3_$BIRTH_ARCH-$BIRTH_OS-$LLVM_CMAKE_BUILD_TYPE +LLVM_PREFIX_PATH=$HOME/dev/llvm/install/llvm_20.1.7_$BIRTH_ARCH-$BIRTH_OS-$LLVM_CMAKE_BUILD_TYPE if [[ -z "${CLANG_PATH:-}" ]]; then CLANG_PATH=clang CLANGXX_PATH=clang++ fi -cmake .. -G Ninja -DCMAKE_C_COMPILER=$CLANG_PATH -DCMAKE_CXX_COMPILER=$CLANGXX_PATH -DCMAKE_LINKER_TYPE=$LINKER_TYPE -DCMAKE_EXPORT_COMPILE_COMMANDS=ON -DCMAKE_PREFIX_PATH=$LLVM_PREFIX_PATH -DCMAKE_COLOR_DIAGNOSTICS=ON -DBB_CI=$BB_CI +cmake .. -G Ninja -DCMAKE_C_COMPILER=$CLANG_PATH -DCMAKE_CXX_COMPILER=$CLANGXX_PATH -DCMAKE_LINKER_TYPE=$LINKER_TYPE -DCMAKE_EXPORT_COMPILE_COMMANDS=ON -DCMAKE_BUILD_TYPE=${CMAKE_BUILD_TYPE%%-*} -DCMAKE_PREFIX_PATH=$LLVM_PREFIX_PATH -DCMAKE_COLOR_DIAGNOSTICS=ON -DBB_CI=$BB_CI cd .. diff --git a/src/compiler.bbb b/src/compiler.bbb index 620797f..a28c1e1 100644 --- a/src/compiler.bbb +++ b/src/compiler.bbb @@ -1,6 +1,6 @@ report_error = fn () noreturn { - #trap(); + @trap(); } mode_t = typealias u64; @@ -145,7 +145,7 @@ next_power_of_two = fn (n: u64) u64 return n; } -string_no_match = #integer_max(u64); +string_no_match = @integer_max(u64); c_string_length = fn (c_string: &u8) u64 { @@ -156,7 +156,7 @@ c_string_length = fn (c_string: &u8) u64 it = it + 1; } - return #int_from_pointer(it) - #int_from_pointer(c_string); + return @int_from_pointer(it) - @int_from_pointer(c_string); } c_string_to_slice = fn (c_string: &u8) []u8 @@ -167,7 +167,7 @@ c_string_to_slice = fn (c_string: &u8) []u8 string_equal = fn(a: []u8, b: []u8) u1 { - >result: #ReturnType = 0; + >result: @ReturnType = 0; if (a.length == b.length) { @@ -281,7 +281,7 @@ os_linux_protection_flags = fn(map_flags: OS_ProtectionFlags) OS_Linux_PROT os_linux_map_flags = fn(map_flags: OS_MapFlags) OS_Linux_MAP { return { - .type = #select(map_flags.private, .private, .shared), + .type = @select(map_flags.private, .private, .shared), .anonymous = map_flags.anonymous, .no_reserve = map_flags.no_reserve, .populate = map_flags.populate, @@ -294,7 +294,7 @@ os_reserve = fn (base: u64, size: u64, protection: OS_ProtectionFlags, map: OS_M >protection_flags = os_linux_protection_flags(protection); >map_flags = os_linux_map_flags(map); >address = mmap(base, size, protection_flags, map_flags, -1, 0); - if (#int_from_pointer(address) == #integer_max(u64)) + if (@int_from_pointer(address) == @integer_max(u64)) { unreachable; } @@ -362,7 +362,7 @@ os_file_open = fn (path: &u8, flags: OpenFlags, permissions: OpenPermissions) Fi zero, }; - >mode: mode_t = #select(permissions.execute, 0o755, 0o644); + >mode: mode_t = @select(permissions.execute, 0o755, 0o644); >fd = open(path, o, mode); return fd; } @@ -383,14 +383,14 @@ os_file_get_size = fn (fd: File) u64 >stat: Stat = undefined; >result = fstat(fd, &stat); assert(result == 0); - return #extend(stat.size); + return @extend(stat.size); } os_file_read_partially = fn (fd: File, pointer: &u8, length: u64) u64 { >result = read(fd, pointer, length); assert(result > 0); - return #extend(result); + return @extend(result); } os_file_read = fn (fd: File, buffer: []u8, byte_count: u64) void @@ -410,7 +410,7 @@ os_file_write_partially = fn (fd: File, pointer: &u8, length: u64) u64 { >result = write(fd, pointer, length); assert(result > 0); - return #extend(result); + return @extend(result); } os_file_write = fn (fd: File, buffer: []u8) void @@ -448,7 +448,7 @@ Arena = struct reserved: [32]u8, } -minimum_position: u64 = #byte_size(Arena); +minimum_position: u64 = @byte_size(Arena); ArenaInitialization = struct { @@ -472,8 +472,8 @@ arena_initialize = fn (initialization: ArenaInitialization) &Arena .populate = 0, }; - >arena: &Arena = #pointer_cast(os_reserve(0, initialization.reserved_size, protection_flags, map_flags)); - os_commit(#int_from_pointer(arena), initialization.initial_size, { + >arena: &Arena = @pointer_cast(os_reserve(0, initialization.reserved_size, protection_flags, map_flags)); + os_commit(@int_from_pointer(arena), initialization.initial_size, { .read = 1, .write = 1, zero, @@ -504,14 +504,14 @@ arena_allocate_bytes = fn (arena: &Arena, size: u64, alignment: u64) &u8 >aligned_offset = align_forward(arena.position, alignment); >aligned_size_after = aligned_offset + size; - >arena_byte_pointer: &u8 = #pointer_cast(arena); + >arena_byte_pointer: &u8 = @pointer_cast(arena); if (aligned_size_after > arena.os_position) { >target_committed_size = align_forward(aligned_size_after, arena.granularity); >size_to_commit = target_committed_size - arena.os_position; >commit_pointer = arena_byte_pointer + arena.os_position; - os_commit(#int_from_pointer(commit_pointer), size_to_commit, { + os_commit(@int_from_pointer(commit_pointer), size_to_commit, { .read = 1, .write = 1, zero, @@ -528,12 +528,12 @@ arena_allocate_bytes = fn (arena: &Arena, size: u64, alignment: u64) &u8 arena_allocate = macro [T] (arena: &Arena, count: u64) &T { - return #pointer_cast(arena_allocate_bytes(arena, #byte_size(T) * count, #align_of(T))); + return @pointer_cast(arena_allocate_bytes(arena, @byte_size(T) * count, @align_of(T))); } arena_allocate_slice = macro [T] (arena: &Arena, count: u64) []T { - >pointer: &T = #pointer_cast(arena_allocate_bytes(arena, #byte_size(T) * count, #align_of(T))); + >pointer: &T = @pointer_cast(arena_allocate_bytes(arena, @byte_size(T) * count, @align_of(T))); return pointer[..count]; } @@ -571,7 +571,7 @@ arena_join_string = fn (arena: &Arena, pieces: [][]u8) []u8 exit_status = fn (s: u32) u8 { - return #truncate((s & 0xff00) >> 8); + return @truncate((s & 0xff00) >> 8); } term_sig = fn (s: u32) u32 @@ -581,7 +581,7 @@ term_sig = fn (s: u32) u32 stop_sig = fn (s: u32) u32 { - return #extend(exit_status(s)); + return @extend(exit_status(s)); } if_exited = fn (s: u32) u1 @@ -591,7 +591,7 @@ if_exited = fn (s: u32) u1 if_stopped = fn (s: u32) u1 { - >v: u16 = #truncate(((s & 0xffff) * 0x10001) >> 8); + >v: u16 = @truncate(((s & 0xffff) * 0x10001) >> 8); return v > 0x7f00; } @@ -655,7 +655,7 @@ os_execute = fn (arena: &Arena, arguments: []&u8, environment: &&u8, options: Ex { if (pipe(&pipes[i]) == -1) { - #trap(); + @trap(); } } } @@ -666,13 +666,13 @@ os_execute = fn (arena: &Arena, arguments: []&u8, environment: &&u8, options: Ex { -1 => { - #trap(); + @trap(); }, 0 => { for (i: 0..2) { - >fd: s32 = #truncate(i + 1); + >fd: s32 = @truncate(i + 1); switch (options.policies[i]) { @@ -698,7 +698,7 @@ os_execute = fn (arena: &Arena, arguments: []&u8, environment: &&u8, options: Ex unreachable; } - #trap(); + @trap(); }, else => { @@ -718,8 +718,8 @@ os_execute = fn (arena: &Arena, arguments: []&u8, environment: &&u8, options: Ex if (is_pipe0 or is_pipe1) { >element_count: u64 = 0; - element_count += #extend(is_pipe0); - element_count += #extend(is_pipe1); + element_count += @extend(is_pipe0); + element_count += @extend(is_pipe1); allocation = arena_allocate_slice[u8](arena, allocation_size * element_count); } @@ -732,7 +732,7 @@ os_execute = fn (arena: &Arena, arguments: []&u8, environment: &&u8, options: Ex >buffer = allocation[offset..offset + allocation_size]; >byte_count = read(pipes[i][0], buffer.pointer, buffer.length); assert(byte_count >= 0); - result.streams[i] = buffer[..#extend(byte_count)]; + result.streams[i] = buffer[..@extend(byte_count)]; close(pipes[i][0]); offset += allocation_size; @@ -747,7 +747,7 @@ os_execute = fn (arena: &Arena, arguments: []&u8, environment: &&u8, options: Ex if (if_exited(status)) { result.termination_kind = .exit; - result.termination_code = #extend(exit_status(status)); + result.termination_code = @extend(exit_status(status)); } else if (if_signaled(status)) { @@ -771,11 +771,11 @@ os_execute = fn (arena: &Arena, arguments: []&u8, environment: &&u8, options: Ex } else if (waitpid_result == -1) { - #trap(); + @trap(); } else { - #trap(); + @trap(); } }, } @@ -1012,6 +1012,7 @@ CompileFile = struct relative_file_path: []u8, build_mode: BuildMode, has_debug_info: u1, + host_cpu_model: u1, silent: u1, } @@ -1031,11 +1032,16 @@ Target = struct { cpu: CPUArchitecture, os: OperatingSystem, + host_cpu_model: u1, } -target_get_native = fn () Target +target_get_native = fn (host_cpu_model: u1) Target { - return { .cpu = .x86_64, .os = .linux }; + return { + .cpu = .x86_64, + .os = .linux, + .host_cpu_model = host_cpu_model, + }; } target_compare = fn (a: Target, b: Target) u1 @@ -1344,7 +1350,7 @@ abi_set_padding_type = fn (abi_information: &AbiInformation, type: &Type) void abi_get_padding_type = fn (abi_information: &AbiInformation) &Type { - return #select(abi_can_have_padding_type(abi_information), abi_information.padding.type, zero); + return @select(abi_can_have_padding_type(abi_information), abi_information.padding.type, zero); } abi_set_direct_offset = fn (abi_information: &AbiInformation, offset: u32) void @@ -1586,7 +1592,7 @@ receives_type = fn (value: &Value) u1 }, else => { - #trap(); + @trap(); }, } } @@ -1618,7 +1624,7 @@ type_is_signed = fn (type: &Type) u1 }, else => { - #trap(); + @trap(); }, } } @@ -1670,7 +1676,7 @@ is_illegal_vector_type = fn (type: &Type) u1 { .vector => { - #trap(); + @trap(); } else => { return 0; }, } @@ -1708,13 +1714,13 @@ is_arbitrary_bit_integer = fn (type: &Type) u1 integer_max_value = fn (bit_count: u64, signed: u1) u64 { - >value: u64 = #select(bit_count == 64, ~0, (1 << (bit_count - #extend(signed))) - 1); + >value: u64 = @select(bit_count == 64, ~0, (1 << (bit_count - @extend(signed))) - 1); return value; } align_bit_count = fn (bit_count: u64) u64 { - >aligned_bit_count = #max(next_power_of_two(bit_count), 8); + >aligned_bit_count = @max(next_power_of_two(bit_count), 8); assert(aligned_bit_count % 8 == 0); return aligned_bit_count; } @@ -1785,7 +1791,7 @@ get_byte_size = fn (type: &Type) u64 }, else => { - #trap(); + @trap(); }, } } @@ -1796,7 +1802,7 @@ get_byte_alignment = fn (type: &Type) u32 { .integer => { - >aligned_byte_count: u32 = #truncate(aligned_byte_count_from_bit_count(type.content.integer.bit_count)); + >aligned_byte_count: u32 = @truncate(aligned_byte_count_from_bit_count(type.content.integer.bit_count)); assert(aligned_byte_count == 1 or aligned_byte_count == 2 or aligned_byte_count == 4 or aligned_byte_count == 8 or aligned_byte_count == 16); return aligned_byte_count; }, @@ -1836,7 +1842,7 @@ get_byte_alignment = fn (type: &Type) u32 }, else => { - #trap(); + @trap(); }, } } @@ -1889,7 +1895,7 @@ get_bit_size = fn (type: &Type) u64 }, else => { - #trap(); + @trap(); }, } } @@ -1898,7 +1904,7 @@ get_byte_allocation_size = fn (type: &Type) u64 { >size = get_byte_size(type); >alignment = get_byte_alignment(type); - >result = align_forward(size, #extend(alignment)); + >result = align_forward(size, @extend(alignment)); return result; } @@ -1949,7 +1955,7 @@ is_promotable_integer_type_for_abi = fn (type: &Type) u1 }, else => { - #trap(); + @trap(); } } } @@ -2386,7 +2392,7 @@ value_is_constant = fn (value: &Value) u1 }, else => { - #trap(); + @trap(); } } } @@ -2789,11 +2795,11 @@ llvm_create_global_variable = fn (module: &LLVMModule, type: &LLVMType, is_const assert(name.pointer[name.length] == 0); >global = LLVMAddGlobal(module, type, name.pointer); - LLVMSetGlobalConstant(global, #extend(is_constant)); + LLVMSetGlobalConstant(global, @extend(is_constant)); LLVMSetLinkage(global, linkage); LLVMSetInitializer(global, initial_value); LLVMSetThreadLocalMode(global, thread_local_mode); - LLVMSetExternallyInitialized(global, #extend(externally_initialized)); + LLVMSetExternallyInitialized(global, @extend(externally_initialized)); LLVMSetUnnamedAddress(global, unnamed_address); LLVMSetAlignment(global, alignment); @@ -3136,25 +3142,25 @@ Statement = struct scope_to_for = fn (scope: &Scope) &StatementFor { assert(scope.kind == .for_each); - return #field_parent_pointer(scope, "scope"); + return @field_parent_pointer(scope, "scope"); } scope_to_block = fn (scope: &Scope) &Block { assert(scope.kind == .local); - return #field_parent_pointer(scope, "scope"); + return @field_parent_pointer(scope, "scope"); } scope_to_function = fn (scope: &Scope) &ValueFunction { assert(scope.kind == .function); - return #field_parent_pointer(scope, "scope"); + return @field_parent_pointer(scope, "scope"); } scope_to_module = fn (scope: &Scope) &Module { assert(scope.kind == .global); - return #field_parent_pointer(scope, "scope"); + return @field_parent_pointer(scope, "scope"); } new_local = fn (module: &Module, scope: &Scope) &Local @@ -3249,7 +3255,7 @@ integer_type = fn (module: &Module, integer: TypeInteger) &Type { assert(integer.bit_count != 0); assert(integer.bit_count <= 64); - >index = #select(integer.bit_count == 128, i128_offset + #extend(integer.signed), integer.bit_count - 1 + 64 * #extend(integer.signed)); + >index = @select(integer.bit_count == 128, i128_offset + @extend(integer.signed), integer.bit_count - 1 + 64 * @extend(integer.signed)); >result = module.scope.types.first + index; assert(result.id == .integer); assert(result.content.integer.bit_count == integer.bit_count); @@ -3363,7 +3369,7 @@ format_integer_decimal = fn (buffer: []u8, v: u64) u64 while (value != 0) { - >digit_value: u8 = #truncate(value % 10); + >digit_value: u8 = @truncate(value % 10); >ascii_character = digit_value + '0'; value /= 10; reverse_buffer[reverse_index] = ascii_character; @@ -3518,15 +3524,15 @@ is_identifier = fn (ch: u8) u1 get_line = fn (module: &Module) u32 { >line = module.line_offset + 1; - assert(line <= #integer_max(u32)); - return #truncate(line); + assert(line <= @integer_max(u32)); + return @truncate(line); } get_column = fn (module: &Module) u32 { >column = module.offset - module.line_character_offset + 1; - assert(column <= #integer_max(u32)); - return #truncate(column); + assert(column <= @integer_max(u32)); + return @truncate(column); } Checkpoint = struct @@ -3560,8 +3566,8 @@ skip_space = fn (module: &Module) void while (module.offset < module.content.length and? is_space(module.content[module.offset])) { - module.line_offset += #extend(module.content[module.offset] == '\n'); - module.line_character_offset = #select(module.content[module.offset] == '\n', module.offset, module.line_character_offset); + module.line_offset += @extend(module.content[module.offset] == '\n'); + module.line_character_offset = @select(module.content[module.offset] == '\n', module.offset, module.line_character_offset); module.offset += 1; } @@ -3601,7 +3607,7 @@ consume_character_if_match = fn (module: &Module, expected_character: u8) u1 { >ch = module.content[module.offset]; is_ch = expected_character == ch; - module.offset += #extend(is_ch); + module.offset += @extend(is_ch); } return is_ch; @@ -3674,7 +3680,7 @@ parse_string_literal = fn (module: &Module) []u8 break; } - escape_character_count += #extend(ch == '\\'); + escape_character_count += @extend(ch == '\\'); module.offset += 1; } @@ -3757,7 +3763,7 @@ FunctionTypeAttribute = enum accumulate_decimal = fn(accumulator: u64, ch: u8) u64 { assert(is_decimal(ch)); - return (accumulator * 10) + #extend(ch - '0'); + return (accumulator * 10) + @extend(ch - '0'); } parse_decimal = fn (module: &Module) u64 @@ -3796,7 +3802,7 @@ accumulate_octal = fn (accumulator: u64, ch: u8) u64 { assert(is_octal(ch)); - return (accumulator * 8) + #extend(ch - '0'); + return (accumulator * 8) + @extend(ch - '0'); } parse_octal = fn (module: &Module) u64 @@ -3823,7 +3829,7 @@ parse_octal = fn (module: &Module) u64 accumulate_binary = fn (accumulator: u64, ch: u8) u64 { assert(is_binary(ch)); - return (accumulator * 2) + #extend(ch - '0'); + return (accumulator * 2) + @extend(ch - '0'); } parse_binary = fn (module: &Module) u64 @@ -3960,14 +3966,14 @@ get_anonymous_struct_pair = fn (module: &Module, low: &Type, high: &Type) &Type } >high_alignment = get_byte_alignment(high); - >alignment = #max(get_byte_alignment(low), high_alignment); - >high_offset = align_forward(get_byte_size(low), #extend(alignment)); - >byte_size = align_forward(high_offset + get_byte_size(high), #extend(alignment)); + >alignment = @max(get_byte_alignment(low), high_alignment); + >high_offset = align_forward(get_byte_size(low), @extend(alignment)); + >byte_size = align_forward(high_offset + get_byte_size(high), @extend(alignment)); assert(low.scope != zero); assert(high.scope != zero); - >scope = #select(low.scope.kind == .global, high.scope, low.scope); + >scope = @select(low.scope.kind == .global, high.scope, low.scope); >fields = arena_allocate_slice[Field](module.arena, 2); @@ -4018,12 +4024,12 @@ get_by_value_argument_pair = fn (module: &Module, low: &Type, high: &Type) &Type { >low_size = get_byte_allocation_size(low); >high_alignment = get_byte_alignment(high); - >high_start = align_forward(low_size, #extend(high_alignment)); + >high_start = align_forward(low_size, @extend(high_alignment)); assert(high_start != 0 and high_start <= 8); if (high_start != 8) { - #trap(); + @trap(); } >result = get_anonymous_struct_pair(module, low, high); @@ -4242,7 +4248,7 @@ get_enum_array_type = fn (module: &Module, enum_type: &Type, element_type: &Type assert(enum_type.scope != zero); assert(element_type.scope != zero); - >scope = #select(element_type.scope.kind == .global, enum_type.scope, element_type.scope); + >scope = @select(element_type.scope.kind == .global, enum_type.scope, element_type.scope); >enum_array_type = new_type(module, { .content = { @@ -4351,7 +4357,7 @@ resolve_alias = fn (module: &Module, type: &Type) &Type }, else => { - #trap(); + @trap(); }, } @@ -4454,7 +4460,7 @@ parse_function_header = fn (module: &Module, scope: &Scope, mandate_argument_nam while (module.offset < module.content.length) { >function_identifier = parse_identifier(module); - >function_keyword_s2e = #string_to_enum(FunctionKeyword, function_identifier); + >function_keyword_s2e = @string_to_enum(FunctionKeyword, function_identifier); if (!function_keyword_s2e.is_valid) { @@ -4471,7 +4477,7 @@ parse_function_header = fn (module: &Module, scope: &Scope, mandate_argument_nam expect_character(module, left_parenthesis); skip_space(module); >calling_convention_string = parse_identifier(module); - >calling_convention_s2e = #string_to_enum(CallingConvention, calling_convention_string); + >calling_convention_s2e = @string_to_enum(CallingConvention, calling_convention_string); if (!calling_convention_s2e.is_valid) { @@ -4564,7 +4570,7 @@ parse_function_header = fn (module: &Module, scope: &Scope, mandate_argument_nam if (semantic_argument_count != 0) { argument_types = arena_allocate_slice[&Type](module.arena, semantic_argument_count); - memcpy(#pointer_cast(argument_types.pointer), #pointer_cast(&semantic_argument_type_buffer), semantic_argument_count * #byte_size(&Type)); + memcpy(@pointer_cast(argument_types.pointer), @pointer_cast(&semantic_argument_type_buffer), semantic_argument_count * @byte_size(&Type)); } >function_type = get_function_type(module, { @@ -4608,7 +4614,7 @@ parse_type = fn (module: &Module, scope: &Scope) &Type { >identifier = parse_identifier(module); - >type_keyword_s2e = #string_to_enum(TypeKeyword, identifier); + >type_keyword_s2e = @string_to_enum(TypeKeyword, identifier); if (type_keyword_s2e.is_valid) { @@ -4829,12 +4835,12 @@ parse_type = fn (module: &Module, scope: &Scope) &Type } } } - else if (start_character == '#') + else if (start_character == '@') { module.offset += 1; >identifier = parse_identifier(module); - >intrinsic_s2e = #string_to_enum(TypeIntrinsic, identifier); + >intrinsic_s2e = @string_to_enum(TypeIntrinsic, identifier); if (!intrinsic_s2e.is_valid) { report_error(); @@ -4877,7 +4883,7 @@ accumulate_hexadecimal = fn (accumulator: u64, ch: u8) u64 unreachable; } - return (accumulator * 16) + #extend(value); + return (accumulator * 16) + @extend(value); } parse_hexadecimal = fn (module: &Module) u64 @@ -4953,7 +4959,7 @@ tokenize = fn (module: &Module) Token zero, }; }, - '#' => + '@' => { module.offset += 1; @@ -4961,7 +4967,7 @@ tokenize = fn (module: &Module) Token { >identifier = parse_identifier(module); - >value_intrinsic_s2e = #string_to_enum(ValueIntrinsic, identifier); + >value_intrinsic_s2e = @string_to_enum(ValueIntrinsic, identifier); if (value_intrinsic_s2e.is_valid) { >value_intrinsic = value_intrinsic_s2e.enum_value; @@ -4988,7 +4994,7 @@ tokenize = fn (module: &Module) Token >id: TokenId = undefined; switch (next_ch) { - '<' => { id = #select(module.content[start_index + 2] == '=', .assign_shift_left, .shift_left); }, + '<' => { id = @select(module.content[start_index + 2] == '=', .assign_shift_left, .shift_left); }, '=' => { id = .compare_less_equal; }, else => { id = .compare_less; }, } @@ -5015,7 +5021,7 @@ tokenize = fn (module: &Module) Token >id: TokenId = undefined; switch (next_ch) { - '>' => { id = #select(module.content[start_index + 2] == '=', .assign_shift_right, .shift_right); }, + '>' => { id = @select(module.content[start_index + 2] == '=', .assign_shift_right, .shift_right); }, '=' => { id = .compare_greater_equal; }, else => { id = .compare_greater; }, } @@ -5040,8 +5046,8 @@ tokenize = fn (module: &Module) Token { >next_ch = module.content[start_index + 1]; >is_compare_equal = next_ch == '='; - >id: TokenId = #select(is_compare_equal, .compare_equal, .assign); - module.offset += #extend(is_compare_equal) + 1; + >id: TokenId = @select(is_compare_equal, .compare_equal, .assign); + module.offset += @extend(is_compare_equal) + 1; token = { .id = id, zero, @@ -5118,7 +5124,7 @@ tokenize = fn (module: &Module) Token token = { .content = { .integer = { - .value = #extend(ch), + .value = @extend(ch), .kind = .character_literal, }, }, @@ -5142,7 +5148,7 @@ tokenize = fn (module: &Module) Token } >inferred_decimal = token_integer_kind == .decimal and next_ch != 'd'; - module.offset += 2 * #extend(token_integer_kind != .decimal or !inferred_decimal); + module.offset += 2 * @extend(token_integer_kind != .decimal or !inferred_decimal); } >value: u64 = undefined; @@ -5215,14 +5221,14 @@ tokenize = fn (module: &Module) Token token.id = id; - module.offset += #extend(next_ch == '=') + 1; + module.offset += @extend(next_ch == '=') + 1; }, else => { if (is_identifier_start(start_character)) { >identifier = parse_identifier(module); - >value_keyword_s2e = #string_to_enum(ValueKeyword, identifier); + >value_keyword_s2e = @string_to_enum(ValueKeyword, identifier); if (value_keyword_s2e.is_valid) { >value_keyword = value_keyword_s2e.enum_value; @@ -5236,10 +5242,10 @@ tokenize = fn (module: &Module) Token else { >advance = identifier.pointer[identifier.length] == '?'; - identifier.length += #extend(advance); - module.offset += #extend(advance); + identifier.length += @extend(advance); + module.offset += @extend(advance); - >operator_keyword_s2e = #string_to_enum(OperatorKeyword, identifier); + >operator_keyword_s2e = @string_to_enum(OperatorKeyword, identifier); if (operator_keyword_s2e.is_valid) { @@ -5254,8 +5260,8 @@ tokenize = fn (module: &Module) Token } else { - identifier.length -= #extend(advance); - module.offset -= #extend(advance); + identifier.length -= @extend(advance); + module.offset -= @extend(advance); token = { .content = { @@ -5282,13 +5288,13 @@ parse_precedence = fn (module: &Module, scope: &Scope, builder: ValueBuilder) &V scope_to_macro_declaration = fn (scope: &Scope) &MacroDeclaration { assert(scope.kind == .macro_declaration); - return #field_parent_pointer(scope, "scope"); + return @field_parent_pointer(scope, "scope"); } scope_to_macro_instantiation = fn (scope: &Scope) &MacroInstantiation { assert(scope.kind == .macro_instantiation); - return #field_parent_pointer(scope, "scope"); + return @field_parent_pointer(scope, "scope"); } reference_identifier = fn (module: &Module, current_scope: &Scope, identifier: []u8, kind: ValueKind) &Value @@ -5401,7 +5407,7 @@ reference_identifier = fn (module: &Module, current_scope: &Scope, identifier: [ { if (string_equal(identifier, constant_argument.name)) { - #trap(); + @trap(); } } @@ -5520,7 +5526,7 @@ parse_aggregate_initialization = fn (module: &Module, scope: &Scope, builder: Va } >elements = arena_allocate_slice[AggregateInitializationElement](module.arena, field_count); - memcpy(#pointer_cast(elements.pointer), #pointer_cast(&element_buffer), field_count * #byte_size(AggregateInitializationElement)); + memcpy(@pointer_cast(elements.pointer), @pointer_cast(&element_buffer), field_count * @byte_size(AggregateInitializationElement)); >result = new_value(module); result.& = { @@ -5580,7 +5586,7 @@ parse_left = fn (module: &Module, scope: &Scope, builder: ValueBuilder) &Value >unary_builder = builder; unary_builder.precedence = .prefix; unary_builder.token = zero; - unary_builder.kind = #select(token.id == .ampersand, .left, builder.kind); + unary_builder.kind = @select(token.id == .ampersand, .left, builder.kind); >unary_value = parse_precedence(module, scope, unary_builder); @@ -5807,7 +5813,7 @@ parse_left = fn (module: &Module, scope: &Scope, builder: ValueBuilder) &Value // TODO .va_copy => { - #trap(); + @trap(); }, .max, .min => { @@ -5941,7 +5947,7 @@ parse_left = fn (module: &Module, scope: &Scope, builder: ValueBuilder) &Value } >values = arena_allocate_slice[&Value](module.arena, element_count); - memcpy(#pointer_cast(values.pointer), #pointer_cast(&value_buffer), element_count * #byte_size(&Value)); + memcpy(@pointer_cast(values.pointer), @pointer_cast(&value_buffer), element_count * @byte_size(&Value)); result = new_value(module); @@ -6146,7 +6152,7 @@ parse_call_arguments = fn (module: &Module, scope: &Scope) []&Value if (argument_count != 0) { arguments = arena_allocate_slice[&Value](module.arena, argument_count); - memcpy(#pointer_cast(arguments.pointer), #pointer_cast(&argument_buffer), argument_count * #byte_size(&Value)); + memcpy(@pointer_cast(arguments.pointer), @pointer_cast(&argument_buffer), argument_count * @byte_size(&Value)); } return arguments; @@ -6219,7 +6225,7 @@ parse_right = fn (module: &Module, scope: &Scope, builder: ValueBuilder) &Value else => { unreachable; }, } - >right_precedence: Precedence = #enum_from_int(#int_from_enum(precedence) + 1); + >right_precedence: Precedence = @enum_from_int(@int_from_enum(precedence) + 1); >right_builder = builder; right_builder.precedence = right_precedence; right_builder.token = zero; @@ -6360,7 +6366,7 @@ parse_right = fn (module: &Module, scope: &Scope, builder: ValueBuilder) &Value { .value => { - #trap(); + @trap(); }, .type => { @@ -6520,7 +6526,7 @@ parse_right_with_left = fn (module: &Module, scope: &Scope, builder: ValueBuilde >token_precedence = get_token_precedence(token); if (token_precedence == .assignment) { - token_precedence = #select(builder.allow_assignment_operators, token_precedence, .none); + token_precedence = @select(builder.allow_assignment_operators, token_precedence, .none); } if (precedence > token_precedence) @@ -6635,7 +6641,7 @@ parse_statement = fn (module: &Module, scope: &Scope) &Statement }; statement.id = .local; }, - '#' => + '@' => { statement.content = { .expression = parse_value(module, scope, zero), @@ -6660,7 +6666,7 @@ parse_statement = fn (module: &Module, scope: &Scope) &Statement skip_space(module); - >statement_start_keyword_s2e = #string_to_enum(StatementStartKeyword, statement_start_identifier); + >statement_start_keyword_s2e = @string_to_enum(StatementStartKeyword, statement_start_identifier); if (statement_start_keyword_s2e.is_valid) { >statement_start_keyword = statement_start_keyword_s2e.enum_value; @@ -6669,7 +6675,7 @@ parse_statement = fn (module: &Module, scope: &Scope) &Statement { ._ => { - #trap(); + @trap(); }, .return => { @@ -6761,7 +6767,7 @@ parse_statement = fn (module: &Module, scope: &Scope) &Statement skip_space(module); >is_left = module.content[module.offset] == '&'; - module.offset += #extend(is_left); + module.offset += @extend(is_left); >for_local_line = get_line(module); >for_local_column = get_column(module); @@ -6781,14 +6787,14 @@ parse_statement = fn (module: &Module, scope: &Scope) &Statement zero, }; - >kind: ValueKind = #select(is_left, .left, .right); + >kind: ValueKind = @select(is_left, .left, .right); left_value_buffer[left_value_count] = kind; left_value_count += 1; } else { - #trap(); + @trap(); } skip_space(module); @@ -6847,10 +6853,10 @@ parse_statement = fn (module: &Module, scope: &Scope) &Statement } >left_values = arena_allocate_slice[ValueKind](module.arena, left_value_count); - memcpy(#pointer_cast(left_values.pointer), #pointer_cast(&left_value_buffer), left_value_count * #byte_size(ValueKind)); + memcpy(@pointer_cast(left_values.pointer), @pointer_cast(&left_value_buffer), left_value_count * @byte_size(ValueKind)); >right_values = arena_allocate_slice[&Value](module.arena, right_value_count); - memcpy(#pointer_cast(right_values.pointer), #pointer_cast(&right_value_buffer), right_value_count * #byte_size(&Value)); + memcpy(@pointer_cast(right_values.pointer), @pointer_cast(&right_value_buffer), right_value_count * @byte_size(&Value)); statement.content.for.kinds = left_values; statement.content.for.iteratables = right_values; @@ -6997,7 +7003,7 @@ parse_statement = fn (module: &Module, scope: &Scope) &Statement } clause_values = arena_allocate_slice[StatementSwitchDiscriminant](module.arena, case_count); - memcpy(#pointer_cast(clause_values.pointer), #pointer_cast(&case_buffer), case_count * #byte_size(StatementSwitchDiscriminant)); + memcpy(@pointer_cast(clause_values.pointer), @pointer_cast(&case_buffer), case_count * @byte_size(StatementSwitchDiscriminant)); } skip_space(module); @@ -7022,7 +7028,7 @@ parse_statement = fn (module: &Module, scope: &Scope) &Statement } >clauses = arena_allocate_slice[StatementSwitchClause](module.arena, clause_count); - memcpy(#pointer_cast(clauses.pointer), #pointer_cast(&clause_buffer), clause_count * #byte_size(StatementSwitchClause)); + memcpy(@pointer_cast(clauses.pointer), @pointer_cast(&clause_buffer), clause_count * @byte_size(StatementSwitchClause)); require_semicolon = 0; @@ -7166,7 +7172,7 @@ parse_block = fn (module: &Module, parent_scope: &Scope) &Block enum_bit_count = fn (highest_value: u64) u64 { - >needed_bit_count: u64 = #select(highest_value == 0, 1, 64 - #leading_zeroes(highest_value)); + >needed_bit_count: u64 = @select(highest_value == 0, 1, 64 - @leading_zeroes(highest_value)); return needed_bit_count; } @@ -7194,7 +7200,7 @@ parse = fn (module: &Module) void while (module.offset < module.content.length) { >global_attribute_keyword_string = parse_identifier(module); - >global_attribute_keyword_s2e = #string_to_enum(GlobalAttributeKeyword, global_attribute_keyword_string); + >global_attribute_keyword_s2e = @string_to_enum(GlobalAttributeKeyword, global_attribute_keyword_string); if (!global_attribute_keyword_s2e.is_valid) { report_error(); @@ -7311,7 +7317,7 @@ parse = fn (module: &Module) void >global_keyword_string = parse_identifier(module); skip_space(module); - >global_keyword_s2e = #string_to_enum(GlobalKeyword, global_keyword_string); + >global_keyword_s2e = @string_to_enum(GlobalKeyword, global_keyword_string); is_global_keyword = global_keyword_s2e.is_valid; @@ -7382,10 +7388,10 @@ parse = fn (module: &Module) void consume_character_if_match(module, ';'); >fields = arena_allocate_slice[Field](module.arena, field_count); - memcpy(#pointer_cast(fields.pointer), #pointer_cast(&field_buffer), field_count * #byte_size(Field)); + memcpy(@pointer_cast(fields.pointer), @pointer_cast(&field_buffer), field_count * @byte_size(Field)); - >needed_bit_count = #max(next_power_of_two(field_bit_offset), 8); - if (needed_bit_count > #integer_max(u32)) + >needed_bit_count = @max(next_power_of_two(field_bit_offset), 8); + if (needed_bit_count > @integer_max(u32)) { report_error(); } @@ -7511,7 +7517,7 @@ parse = fn (module: &Module) void for (i: 0..field_count) { >value = int_value_buffer[i]; - highest_value = #max(highest_value, value); + highest_value = @max(highest_value, value); fields[i] = { .name = name_buffer[i], .value = value, @@ -7592,7 +7598,7 @@ parse = fn (module: &Module) void .column = global_column, }, .initial_value = zero, - .linkage = #select(is_export or is_extern, .external, .internal), + .linkage = @select(is_export or is_extern, .external, .internal), zero, }; } @@ -7619,7 +7625,7 @@ parse = fn (module: &Module) void .line = line, .column = 0, }, - .index = #truncate(i + 1), + .index = @truncate(i + 1), }; } @@ -7682,7 +7688,7 @@ parse = fn (module: &Module) void if (has_value) { - #trap(); + @trap(); } else { @@ -7721,7 +7727,7 @@ parse = fn (module: &Module) void expect_character(module, left_parenthesis); macro_declaration.constant_arguments = arena_allocate_slice[ConstantArgument](module.arena, constant_argument_count); - memcpy(#pointer_cast(macro_declaration.constant_arguments.pointer), #pointer_cast(&constant_argument_buffer), constant_argument_count * #byte_size(ConstantArgument)); + memcpy(@pointer_cast(macro_declaration.constant_arguments.pointer), @pointer_cast(&constant_argument_buffer), constant_argument_count * @byte_size(ConstantArgument)); if (module.first_macro_declaration) { @@ -7774,7 +7780,7 @@ parse = fn (module: &Module) void .column = argument_column, zero, }, - .index = #truncate(argument_index + 1), + .index = @truncate(argument_index + 1), }; argument_count += 1; @@ -7789,7 +7795,7 @@ parse = fn (module: &Module) void macro_declaration.return_type = return_type; >arguments = arena_allocate_slice[Argument](module.arena, argument_count); - memcpy(#pointer_cast(arguments.pointer), #pointer_cast(&argument_buffer), argument_count * #byte_size(Argument)); + memcpy(@pointer_cast(arguments.pointer), @pointer_cast(&argument_buffer), argument_count * @byte_size(Argument)); macro_declaration.arguments = arguments; skip_space(module); @@ -7860,7 +7866,7 @@ parse = fn (module: &Module) void >field_byte_size = get_byte_size(field_type); >field_byte_alignment = get_byte_alignment(field_type); // Align struct size by field alignment - >field_byte_offset = align_forward(byte_size, #extend(field_byte_alignment)); + >field_byte_offset = align_forward(byte_size, @extend(field_byte_alignment)); field_buffer[field_index] = { .name = field_name, @@ -7870,7 +7876,7 @@ parse = fn (module: &Module) void }; byte_size = field_byte_offset + field_byte_size; - byte_alignment = #max(byte_alignment, field_byte_alignment); + byte_alignment = @max(byte_alignment, field_byte_alignment); skip_space(module); @@ -7879,14 +7885,14 @@ parse = fn (module: &Module) void field_count += 1; } - byte_size = align_forward(byte_size, #extend(byte_alignment)); - assert(byte_size % #extend(byte_alignment) == 0); + byte_size = align_forward(byte_size, @extend(byte_alignment)); + assert(byte_size % @extend(byte_alignment) == 0); skip_space(module); consume_character_if_match(module, ';'); >fields = arena_allocate_slice[Field](module.arena, field_count); - memcpy(#pointer_cast(fields.pointer), #pointer_cast(&field_buffer), field_count * #byte_size(Field)); + memcpy(@pointer_cast(fields.pointer), @pointer_cast(&field_buffer), field_count * @byte_size(Field)); struct_type.content = { .struct = { @@ -7991,9 +7997,9 @@ parse = fn (module: &Module) void .line = field_line, }; - biggest_field = #select(field_size > byte_size, field_index, biggest_field); - alignment = #max(alignment, field_alignment); - byte_size = #max(byte_size, field_size); + biggest_field = @select(field_size > byte_size, field_index, biggest_field); + alignment = @max(alignment, field_alignment); + byte_size = @max(byte_size, field_size); skip_space(module); @@ -8004,7 +8010,7 @@ parse = fn (module: &Module) void consume_character_if_match(module, ';'); >fields = arena_allocate_slice[UnionField](module.arena, field_count); - memcpy(#pointer_cast(fields.pointer), #pointer_cast(&field_buffer), field_count * #byte_size(UnionField)); + memcpy(@pointer_cast(fields.pointer), @pointer_cast(&field_buffer), field_count * @byte_size(UnionField)); >biggest_size = get_byte_size(fields[biggest_field].type); assert(biggest_size == byte_size); @@ -8071,8 +8077,8 @@ resolve_type_in_place_abi = fn (module: &Module, type: &Type) void .integer => { >bit_count = type.content.integer.bit_count; - assert(bit_count <= #integer_max(u32)); - result = LLVMIntTypeInContext(module.llvm.context, #truncate(bit_count)); + assert(bit_count <= @integer_max(u32)); + result = LLVMIntTypeInContext(module.llvm.context, @truncate(bit_count)); }, .pointer, .opaque, @@ -8109,7 +8115,7 @@ resolve_type_in_place_abi = fn (module: &Module, type: &Type) void } >is_packed: u1 = 0; - result = LLVMStructTypeInContext(module.llvm.context, &llvm_type_buffer[0], #truncate(fields.length), #extend(is_packed)); + result = LLVMStructTypeInContext(module.llvm.context, &llvm_type_buffer[0], @truncate(fields.length), @extend(is_packed)); >llvm_size = LLVMStoreSizeOfType(module.llvm.target_data_layout, result); >size = get_byte_size(type); assert(llvm_size == size); @@ -8160,7 +8166,7 @@ resolve_type_in_place_abi = fn (module: &Module, type: &Type) void }, else => { - #trap(); + @trap(); }, } @@ -8194,7 +8200,7 @@ resolve_type_in_place_memory = fn (module: &Module, type: &Type) void { >byte_size = get_byte_size(type); >bit_count = byte_size * 8; - result = LLVMIntTypeInContext(module.llvm.context, #truncate(bit_count)); + result = LLVMIntTypeInContext(module.llvm.context, @truncate(bit_count)); }, .enum => { @@ -8226,7 +8232,7 @@ resolve_type_in_place_memory = fn (module: &Module, type: &Type) void }, else => { - #trap(); + @trap(); }, } @@ -8276,7 +8282,7 @@ resolve_type_in_place_debug = fn (module: &Module, type: &Type) void } else { - dwarf_encoding = #select(type.content.integer.signed, .signed, .unsigned); + dwarf_encoding = @select(type.content.integer.signed, .signed, .unsigned); } >flags: LLVMDIFlags = zero; @@ -8316,7 +8322,7 @@ resolve_type_in_place_debug = fn (module: &Module, type: &Type) void for (i: 0..fields.length) { >field = &fields[i]; - >enum_field = LLVMDIBuilderCreateEnumerator(module.llvm.di_builder, field.name.pointer, field.name.length, field.value, #extend(!type_is_signed(backing_type))); + >enum_field = LLVMDIBuilderCreateEnumerator(module.llvm.di_builder, field.name.pointer, field.name.length, field.value, @extend(!type_is_signed(backing_type))); field_buffer[i] = enum_field; } @@ -8355,7 +8361,7 @@ resolve_type_in_place_debug = fn (module: &Module, type: &Type) void >runtime_language: u32 = 0; >vtable_holder: &LLVMMetadata = zero; - >struct_type = LLVMDIBuilderCreateStructType(module.llvm.di_builder, module.scope.llvm, name.pointer, name.length, module.llvm.file, type.content.struct.line, byte_size * 8, alignment * 8, flags, derived_from, &llvm_type_buffer[0], #truncate(fields.length), runtime_language, vtable_holder, name.pointer, name.length); + >struct_type = LLVMDIBuilderCreateStructType(module.llvm.di_builder, module.scope.llvm, name.pointer, name.length, module.llvm.file, type.content.struct.line, byte_size * 8, alignment * 8, flags, derived_from, &llvm_type_buffer[0], @truncate(fields.length), runtime_language, vtable_holder, name.pointer, name.length); LLVMMetadataReplaceAllUsesWith(forward_declaration, struct_type); result = struct_type; }, @@ -8382,7 +8388,7 @@ resolve_type_in_place_debug = fn (module: &Module, type: &Type) void >derived_from: &LLVMMetadata = zero; >runtime_language: u32 = 0; >vtable_holder: &LLVMMetadata = zero; - >struct_type = LLVMDIBuilderCreateStructType(module.llvm.di_builder, module.scope.llvm, type.name.pointer, type.name.length, module.llvm.file, type.content.bits.line, size, alignment, flags, zero, &llvm_type_buffer[0], #truncate(fields.length), runtime_language, vtable_holder, type.name.pointer, type.name.length); + >struct_type = LLVMDIBuilderCreateStructType(module.llvm.di_builder, module.scope.llvm, type.name.pointer, type.name.length, module.llvm.file, type.content.bits.line, size, alignment, flags, zero, &llvm_type_buffer[0], @truncate(fields.length), runtime_language, vtable_holder, type.name.pointer, type.name.length); result = struct_type; }, .union => @@ -8414,7 +8420,7 @@ resolve_type_in_place_debug = fn (module: &Module, type: &Type) void >runtime_language: u32 = 0; - >union_type = LLVMDIBuilderCreateUnionType(module.llvm.di_builder, module.scope.llvm, type.name.pointer, type.name.length, module.llvm.file, type.content.union.line, byte_size * 8, alignment * 8, flags, &llvm_type_buffer[0], #truncate(fields.length), runtime_language, type.name.pointer, type.name.length); + >union_type = LLVMDIBuilderCreateUnionType(module.llvm.di_builder, module.scope.llvm, type.name.pointer, type.name.length, module.llvm.file, type.content.union.line, byte_size * 8, alignment * 8, flags, &llvm_type_buffer[0], @truncate(fields.length), runtime_language, type.name.pointer, type.name.length); LLVMMetadataReplaceAllUsesWith(forward_declaration, union_type); result = union_type; @@ -8445,7 +8451,7 @@ resolve_type_in_place_debug = fn (module: &Module, type: &Type) void }, else => { - #trap(); + @trap(); }, } @@ -8529,7 +8535,7 @@ abi_system_v_classify_post_merge = fn (aggregate_size: u64, classes: [2]AbiSyste if (result[1] == .x87_up) { - #trap(); + @trap(); } if (aggregate_size > 16 and (result[0] != .sse or result[1] != .sse_up)) @@ -8557,8 +8563,8 @@ abi_system_v_classify_type = fn (type: &Type, options: AbiSystemVClassifyArgumen >result: [2]AbiSystemVClass = zero; >is_memory = options.base_offset >= 8; - >current_index: u64 = #extend(is_memory); - >not_current_index: u64 = #extend(!is_memory); + >current_index: u64 = @extend(is_memory); + >not_current_index: u64 = @extend(!is_memory); assert(current_index != not_current_index); result[current_index] = .memory; @@ -8581,7 +8587,7 @@ abi_system_v_classify_type = fn (type: &Type, options: AbiSystemVClassifyArgumen } else if (bit_count == 128) { - #trap(); + @trap(); } else { @@ -8612,7 +8618,7 @@ abi_system_v_classify_type = fn (type: &Type, options: AbiSystemVClassifyArgumen >offset = options.base_offset + field.offset; >member_type = field.type; >member_size = get_byte_size(member_type); - >member_alignment: u64 = #extend(get_byte_alignment(member_type)); + >member_alignment: u64 = @extend(get_byte_alignment(member_type)); >native_vector_size: u64 = 16; @@ -8647,7 +8653,7 @@ abi_system_v_classify_type = fn (type: &Type, options: AbiSystemVClassifyArgumen }, .union => { - #trap(); + @trap(); } else => { unreachable; }, } @@ -8660,7 +8666,7 @@ abi_system_v_classify_type = fn (type: &Type, options: AbiSystemVClassifyArgumen if (byte_size <= 64) { - if (options.base_offset % #extend(get_byte_alignment(type)) == 0) + if (options.base_offset % @extend(get_byte_alignment(type)) == 0) { >element_type = type.content.array.element_type; >element_size = get_byte_size(element_type); @@ -8712,7 +8718,7 @@ abi_system_v_classify_type = fn (type: &Type, options: AbiSystemVClassifyArgumen }, else => { - #trap(); + @trap(); }, } @@ -8743,7 +8749,7 @@ contains_no_user_data = fn (type: &Type, start: u64, end: u64) u1 break; } - >field_start = #select(field_offset < start, start - field_offset, 0); + >field_start = @select(field_offset < start, start - field_offset, 0); if (!contains_no_user_data(field.type, field_start, end - field_offset)) { @@ -8768,7 +8774,7 @@ contains_no_user_data = fn (type: &Type, start: u64, end: u64) u1 }, .enum_array => { - #trap(); + @trap(); }, else => { unreachable; }, } @@ -8787,7 +8793,7 @@ contains_no_user_data = fn (type: &Type, start: u64, end: u64) u1 break; } - >element_start = #select(offset < start, start - offset, 0); + >element_start = @select(offset < start, start - offset, 0); if (!contains_no_user_data(element_type, element_start, end - offset)) { @@ -8864,7 +8870,7 @@ abi_system_v_get_integer_type_at_offset = fn (module: &Module, type: &Type, offs } else { - #trap(); + @trap(); } }, .struct => @@ -8895,12 +8901,12 @@ abi_system_v_get_integer_type_at_offset = fn (module: &Module, type: &Type, offs .bits => { >backing_type = type.content.bits.backing_type; - return abi_system_v_get_integer_type_at_offset(module, backing_type, offset, #select(source_type == type, backing_type, source_type), source_offset); + return abi_system_v_get_integer_type_at_offset(module, backing_type, offset, @select(source_type == type, backing_type, source_type), source_offset); }, .enum => { >backing_type = type.content.enum.backing_type; - return abi_system_v_get_integer_type_at_offset(module, backing_type, offset, #select(source_type == type, backing_type, source_type), source_offset); + return abi_system_v_get_integer_type_at_offset(module, backing_type, offset, @select(source_type == type, backing_type, source_type), source_offset); }, .array => { @@ -8909,13 +8915,13 @@ abi_system_v_get_integer_type_at_offset = fn (module: &Module, type: &Type, offs >element_offset = (offset / element_size) * element_size; return abi_system_v_get_integer_type_at_offset(module, element_type, offset - element_offset, source_type, source_offset); }, - else => { #trap(); }, + else => { @trap(); }, } >source_size = get_byte_size(source_type); assert(source_size != source_offset); >byte_count = source_size - source_offset; - >bit_count = #select(byte_count > 8, 64, byte_count * 8); + >bit_count = @select(byte_count > 8, 64, byte_count * 8); >result = integer_type(module, { .bit_count = bit_count, .signed = 0 }); return result; } @@ -8991,7 +8997,7 @@ abi_system_v_get_extend = fn (options: AbiSystemVExtendOptions) AbiInformation zero, }; - abi_set_coerce_to_type(&result, #select(options.type != zero, options.type, options.semantic_type)); + abi_set_coerce_to_type(&result, @select(options.type != zero, options.type, options.semantic_type)); abi_set_padding_type(&result, zero); abi_set_direct_offset(&result, 0); abi_set_direct_alignment(&result, 0); @@ -9058,7 +9064,7 @@ abi_system_v_get_indirect_result = fn (module: &Module, type: &Type, free_gpr: u } else { - >alignment = #max(get_byte_alignment(type), 8); + >alignment = @max(get_byte_alignment(type), 8); >size = get_byte_size(type); if (free_gpr == 0 and alignment != 8 and size <= 8) @@ -9112,7 +9118,7 @@ abi_system_v_get_indirect_return_result = fn (type: &Type) AbiInformation } else { - #trap(); + @trap(); } } @@ -9159,7 +9165,7 @@ abi_system_v_classify_return_type = fn (module: &Module, semantic_return_type: & }, else => { - #trap(); + @trap(); }, } @@ -9175,12 +9181,12 @@ abi_system_v_classify_return_type = fn (module: &Module, semantic_return_type: & if (classes[0] == .none) { - #trap(); + @trap(); } }, else => { - #trap(); + @trap(); }, } @@ -9273,7 +9279,7 @@ abi_system_v_classify_argument_type = fn (module: &Module, semantic_argument_typ if (classes[0] == .none) { - #trap(); + @trap(); } }, else => { unreachable; }, @@ -9309,7 +9315,7 @@ abi_system_v_classify_argument = fn (module: &Module, available_registers: &AbiR if (options.register_call) { - #trap(); + @trap(); } >result = abi_system_v_classify_argument_type(module, semantic_argument_type, { @@ -9337,14 +9343,14 @@ abi_system_v_classify_argument = fn (module: &Module, available_registers: &AbiR if (abi_get_padding_type(&argument_abi)) { - #trap(); + @trap(); } argument_abi.abi_start = options.abi_start; >count: u16 = 0; - >abi_start: u64 = #extend(argument_abi.abi_start); + >abi_start: u64 = @extend(argument_abi.abi_start); switch (argument_abi.flags.kind) { @@ -9369,7 +9375,7 @@ abi_system_v_classify_argument = fn (module: &Module, available_registers: &AbiR abi_argument_type_buffer[abi_start + i] = field_type; } - count = #truncate(coerce_to_type.content.struct.fields.length); + count = @truncate(coerce_to_type.content.struct.fields.length); } else { @@ -9437,7 +9443,7 @@ add_value_attribute = fn (module: &Module, value: &LLVMValue, index: u32, add_ca if (attributes.alignment) { - add_enum_attribute(module, .align, #extend(attributes.alignment), add_callback, value, index); + add_enum_attribute(module, .align, @extend(attributes.alignment), add_callback, value, index); } if (attributes.sign_extend) @@ -9520,7 +9526,7 @@ emit_attributes = fn (module: &Module, value: &LLVMValue, add_callback: &LLVMAtt >abi_type = options.abi_argument_types[abi_index]; resolve_type_in_place(module, abi_type); - add_value_attribute(module, value, #extend(abi_index + 1), add_callback, semantic_return_type.llvm.memory, abi_type.llvm.abi, { + add_value_attribute(module, value, @extend(abi_index + 1), add_callback, semantic_return_type.llvm.memory, abi_type.llvm.abi, { .alignment = get_byte_alignment(semantic_return_type), .sign_extend = 0, .zero_extend = 0, @@ -9544,8 +9550,8 @@ emit_attributes = fn (module: &Module, value: &LLVMValue, add_callback: &LLVMAtt >abi_type = options.abi_argument_types[abi_index]; resolve_type_in_place(module, abi_type); - add_value_attribute(module, value, #extend(abi_index + 1), add_callback, abi.semantic_type.llvm.memory, abi_type.llvm.abi, { - .alignment = #select(abi.flags.kind == .indirect, 8, 0), + add_value_attribute(module, value, @extend(abi_index + 1), add_callback, abi.semantic_type.llvm.memory, abi_type.llvm.abi, { + .alignment = @select(abi.flags.kind == .indirect, 8, 0), .sign_extend = abi.flags.kind == .extend and abi.flags.sign_extension, .zero_extend = abi.flags.kind == .extend and !abi.flags.sign_extension, .no_alias = 0, @@ -9684,7 +9690,7 @@ create_store = fn (module: &Module, options: StoreOptions) void if (resolved_type.llvm.abi != memory_type) { - source_value = LLVMBuildIntCast2(module.llvm.builder, source_value, memory_type, #extend(type_is_signed(resolved_type)), ""); + source_value = LLVMBuildIntCast2(module.llvm.builder, source_value, memory_type, @extend(type_is_signed(resolved_type)), ""); } >alignment = options.alignment; @@ -9708,7 +9714,7 @@ memory_to_abi = fn (module: &Module, value: &LLVMValue, type: &Type) &LLVMValue >result = value; if (type.llvm.memory != type.llvm.abi) { - result = LLVMBuildIntCast2(module.llvm.builder, result, type.llvm.abi, #extend(type_is_signed(type)), ""); + result = LLVMBuildIntCast2(module.llvm.builder, result, type.llvm.abi, @extend(type_is_signed(type)), ""); } return result; } @@ -9756,8 +9762,8 @@ GEPOptions = struct create_gep = fn (module: &Module, options: GEPOptions) &LLVMValue { assert(options.indices.length == 1 or options.indices.length == 2); - >gep_function = #select(options.not_inbounds, &LLVMBuildGEP2, &LLVMBuildInBoundsGEP2); - >gep = gep_function(module.llvm.builder, options.type, options.pointer, options.indices.pointer, #truncate(options.indices.length), ""); + >gep_function = @select(options.not_inbounds, &LLVMBuildGEP2, &LLVMBuildInBoundsGEP2); + >gep = gep_function(module.llvm.builder, options.type, options.pointer, options.indices.pointer, @truncate(options.indices.length), ""); return gep; } @@ -9943,10 +9949,10 @@ get_enum_name_array_global = fn (module: &Module, enum_type: &Type) &Global >is_constant: u1 = 1; >null_terminate: u1 = 1; - >initial_value = LLVMConstStringInContext2(module.llvm.context, field.name.pointer, field.name.length, #extend(!null_terminate)); + >initial_value = LLVMConstStringInContext2(module.llvm.context, field.name.pointer, field.name.length, @extend(!null_terminate)); >alignment: u32 = 1; - >name_global = llvm_create_global_variable(module.llvm.module, LLVMArrayType2(u8_type.llvm.abi, field.name.length + #extend(null_terminate)), is_constant, .internal, initial_value, arena_join_string(module.arena, [ "string.", enum_type.name, ".", field.name ][..]), .none, 0, alignment, .global); + >name_global = llvm_create_global_variable(module.llvm.module, LLVMArrayType2(u8_type.llvm.abi, field.name.length + @extend(null_terminate)), is_constant, .internal, initial_value, arena_join_string(module.arena, [ "string.", enum_type.name, ".", field.name ][..]), .none, 0, alignment, .global); >constants: [_]&LLVMValue = [ name_global, @@ -10078,7 +10084,7 @@ resolve_type = fn (module: &Module, type: &Type) &Type }, else => { - #trap(); + @trap(); }, } @@ -10188,7 +10194,7 @@ clone_value = fn (module: &Module, scope: &Scope, old_value: &Value) &Value }, else => { - #trap(); + @trap(); }, } } @@ -10291,7 +10297,7 @@ clone_statement = fn (module: &Module, scope: &Scope, old_statement: &Statement) }, else => { - #trap(); + @trap(); }, } @@ -10338,7 +10344,7 @@ get_build_mode_enum = fn (module: &Module) &Type if (!result) { - >enum_names = #enum_names(BuildMode); + >enum_names = @enum_names(BuildMode); >enum_fields = arena_allocate_slice[EnumField](module.arena, enum_names.length); >field_value: u64 = 0; @@ -10380,7 +10386,7 @@ analyze_type = fn (module: &Module, value: &Value, expected_type: &Type, analysi if (expected_type != zero and? expected_type.id == .unresolved) { - #trap(); + @trap(); } >value_type: &Type = zero; @@ -10422,7 +10428,7 @@ analyze_type = fn (module: &Module, value: &Value, expected_type: &Type, analysi report_error(); } - #trap(); + @trap(); } else { @@ -10529,7 +10535,7 @@ analyze_type = fn (module: &Module, value: &Value, expected_type: &Type, analysi if (expected_type) { - #trap(); + @trap(); } else { @@ -10720,7 +10726,7 @@ analyze_type = fn (module: &Module, value: &Value, expected_type: &Type, analysi >enum_fields = enum_type.content.enum.fields; - >switch_instruction = LLVMBuildSwitch(module.llvm.builder, llvm_argument, else_block, #truncate(enum_fields.length)); + >switch_instruction = LLVMBuildSwitch(module.llvm.builder, llvm_argument, else_block, @truncate(enum_fields.length)); >backing_type = enum_type.llvm.abi; assert(backing_type != zero); @@ -10887,7 +10893,7 @@ analyze_type = fn (module: &Module, value: &Value, expected_type: &Type, analysi else => { // TODO - #trap(); + @trap(); }, } }, @@ -10973,7 +10979,7 @@ analyze_type = fn (module: &Module, value: &Value, expected_type: &Type, analysi switch (unary_type_id) { - .align_of => { value = #extend(get_byte_alignment(unary_type)); }, + .align_of => { value = @extend(get_byte_alignment(unary_type)); }, .byte_size => { value = get_byte_size(unary_type); }, .integer_max => { @@ -11192,7 +11198,7 @@ analyze_type = fn (module: &Module, value: &Value, expected_type: &Type, analysi } >pointer_element_type = array_like_type.content.pointer.element_type; - >indexing_type = #select(pointer_element_type.id == .enum_array, pointer_element_type.content.enum_array.enum_type, uint64(module)); + >indexing_type = @select(pointer_element_type.id == .enum_array, pointer_element_type.content.enum_array.enum_type, uint64(module)); analyze_type(module, value.content.array_expression.index, zero, { .indexing_type = indexing_type, .must_be_constant = analysis.must_be_constant }); @@ -11279,7 +11285,7 @@ analyze_type = fn (module: &Module, value: &Value, expected_type: &Type, analysi } >aggregate_element_type = aggregate_type.content.pointer.element_type; - >real_aggregate_type = #select(aggregate_element_type.id == .pointer, aggregate_element_type.content.pointer.element_type, aggregate_element_type); + >real_aggregate_type = @select(aggregate_element_type.id == .pointer, aggregate_element_type.content.pointer.element_type, aggregate_element_type); >resolved_aggregate_type = resolve_alias(module, real_aggregate_type); switch (resolved_aggregate_type.id) @@ -11307,7 +11313,7 @@ analyze_type = fn (module: &Module, value: &Value, expected_type: &Type, analysi >field_type = result_field.type; - value_type = #select(value.kind == .left, get_pointer_type(module, field_type), field_type); + value_type = @select(value.kind == .left, get_pointer_type(module, field_type), field_type); }, .union => { @@ -11770,7 +11776,7 @@ analyze_type = fn (module: &Module, value: &Value, expected_type: &Type, analysi report_error(); } - >declaration_index: u64 = #extend(result_field - fields.pointer); + >declaration_index: u64 = @extend(result_field - fields.pointer); >mask = 1 << declaration_index; >current_mask = field_mask; if (current_mask & mask) @@ -11861,7 +11867,7 @@ analyze_type = fn (module: &Module, value: &Value, expected_type: &Type, analysi >enum_alignment = get_byte_alignment(enum_type); >enum_size = get_byte_size(enum_type); - >byte_size = align_forward(enum_size + 1, #extend(enum_alignment)); + >byte_size = align_forward(enum_size + 1, @extend(enum_alignment)); >struct_fields = arena_allocate_slice[Field](module.arena, 2); @@ -12219,7 +12225,7 @@ analyze_type = fn (module: &Module, value: &Value, expected_type: &Type, analysi >is_definition: u1 = 1; >flags: LLVMDIFlags = zero; >is_optimized = build_mode_is_optimized(module.build_mode); - subprogram = LLVMDIBuilderCreateFunction(module.llvm.di_builder, module.scope.llvm, declaration.name.pointer, declaration.name.length, declaration.name.pointer, declaration.name.length, module.llvm.file, macro_instantiation.scope.line, subroutine_type, #extend(is_local_to_unit), #extend(is_definition), macro_instantiation.scope.line, flags, #extend(is_optimized)); + subprogram = LLVMDIBuilderCreateFunction(module.llvm.di_builder, module.scope.llvm, declaration.name.pointer, declaration.name.length, declaration.name.pointer, declaration.name.length, module.llvm.file, macro_instantiation.scope.line, subroutine_type, @extend(is_local_to_unit), @extend(is_definition), macro_instantiation.scope.line, flags, @extend(is_optimized)); } macro_instantiation.scope.llvm = subprogram; @@ -12258,7 +12264,7 @@ analyze_type = fn (module: &Module, value: &Value, expected_type: &Type, analysi { .value => { - #trap(); + @trap(); }, .type => { @@ -12331,7 +12337,7 @@ analyze_type = fn (module: &Module, value: &Value, expected_type: &Type, analysi LLVMSetCurrentDebugLocation2(module.llvm.builder, zero); >flags: LLVMDIFlags = zero; - >subroutine_type = LLVMDIBuilderCreateSubroutineType(module.llvm.di_builder, module.llvm.file, &type_buffer[0], #truncate(type_count), flags); + >subroutine_type = LLVMDIBuilderCreateSubroutineType(module.llvm.di_builder, module.llvm.file, &type_buffer[0], @truncate(type_count), flags); assert(macro_instantiation.scope.llvm != zero); llvm_subprogram_replace_type(subprogram, subroutine_type); } @@ -12400,7 +12406,7 @@ analyze_type = fn (module: &Module, value: &Value, expected_type: &Type, analysi } } }, - else => { #trap(); }, + else => { @trap(); }, } if (!field_type) @@ -12423,7 +12429,7 @@ analyze_type = fn (module: &Module, value: &Value, expected_type: &Type, analysi }, else => { - #trap(); + @trap(); }, } @@ -12451,7 +12457,7 @@ emit_intrinsic_call = fn (module: &Module, index: LLVMIntrinsicIndex, argument_t >intrinsic_id = module.llvm.intrinsic_table[index]; >intrinsic_function = LLVMGetIntrinsicDeclaration(module.llvm.module, intrinsic_id, argument_types.pointer, argument_types.length); >intrinsic_function_type = LLVMIntrinsicGetType(module.llvm.context, intrinsic_id, argument_types.pointer, argument_types.length); - >call = LLVMBuildCall2(module.llvm.builder, intrinsic_function_type, intrinsic_function, argument_values.pointer, #truncate(argument_values.length), ""); + >call = LLVMBuildCall2(module.llvm.builder, intrinsic_function_type, intrinsic_function, argument_values.pointer, @truncate(argument_values.length), ""); return call; } @@ -12465,7 +12471,7 @@ emit_binary = fn (module: &Module, left: &LLVMValue, left_type: &Type, right: &L >left_signed = type_is_signed(left_type); >right_signed = type_is_signed(left_type); assert(left_signed == right_signed); - >signed = #select(is_boolean, left_signed, resolved_value_type.content.integer.signed); + >signed = @select(is_boolean, left_signed, resolved_value_type.content.integer.signed); switch (id) { @@ -12483,11 +12489,11 @@ emit_binary = fn (module: &Module, left: &LLVMValue, left_type: &Type, right: &L { .max => { - intrinsic_index = #select(signed, ."llvm.smax", ."llvm.umax"); + intrinsic_index = @select(signed, ."llvm.smax", ."llvm.umax"); }, .min => { - intrinsic_index = #select(signed, ."llvm.smin", ."llvm.umin"); + intrinsic_index = @select(signed, ."llvm.smin", ."llvm.umin"); }, else => { unreachable; }, } @@ -12549,10 +12555,10 @@ emit_binary = fn (module: &Module, left: &LLVMValue, left_type: &Type, right: &L { .compare_equal => { predicate = .eq; }, .compare_not_equal => { predicate = .ne; }, - .compare_less => { predicate = #select(signed, .slt, .ult); }, - .compare_less_equal => { predicate = #select(signed, .sle, .ule); }, - .compare_greater => { predicate = #select(signed, .sgt, .ugt); }, - .compare_greater_equal => { predicate = #select(signed, .sge, .uge); }, + .compare_less => { predicate = @select(signed, .slt, .ult); }, + .compare_less_equal => { predicate = @select(signed, .sle, .ule); }, + .compare_greater => { predicate = @select(signed, .sgt, .ugt); }, + .compare_greater_equal => { predicate = @select(signed, .sge, .uge); }, } return LLVMBuildICmp(module.llvm.builder, predicate, left, right, ""); @@ -12652,7 +12658,7 @@ reanalyze_type_as_left_value = fn (module: &Module, value: &Value) void assert(value.kind == .right); invalidate_analysis(module, value); value.kind = .left; - >expected_type = #select(value.id == .aggregate_initialization, get_pointer_type(module, original_type), zero); + >expected_type = @select(value.id == .aggregate_initialization, get_pointer_type(module, original_type), zero); analyze_type(module, value, expected_type, zero); } @@ -12691,7 +12697,7 @@ enter_struct_pointer_for_coerced_access = fn (module: &Module, source_value: &LL >gep = LLVMBuildStructGEP2(module.llvm.builder, source_type.llvm.abi, source_value, 0, "coerce.dive"); if (first_field_type.id == .struct) { - #trap(); + @trap(); } else { @@ -12704,6 +12710,16 @@ enter_struct_pointer_for_coerced_access = fn (module: &Module, source_value: &LL } } +coerce_integer_or_pointer_to_integer_or_pointer = fn (module: &Module, source: &LLVMValue, source_type: &Type, destination_type: &Type) &LLVMValue +{ + if (source_type != destination_type) + { + @trap(); + } + + return source; +} + create_coerced_store = fn (module: &Module, source_value: &LLVMValue, source_type: &Type, destination_value: &LLVMValue, destination_type: &Type, destination_size: u64, destination_volatile: u1) void { >source_size = get_byte_size(source_type); @@ -12723,9 +12739,9 @@ create_coerced_store = fn (module: &Module, source_value: &LLVMValue, source_typ { >destination_alignment = get_byte_alignment(destination_type); - if (source_type.id == .integer and destination_type.id == .pointer and source_size == align_forward(destination_size, #extend(destination_alignment))) + if (source_type.id == .integer and destination_type.id == .pointer and source_size == align_forward(destination_size, @extend(destination_alignment))) { - #trap(); + @trap(); } else if (source_type.id == .struct) { @@ -12735,8 +12751,8 @@ create_coerced_store = fn (module: &Module, source_value: &LLVMValue, source_typ { >field = &fields[i]; - >gep = LLVMBuildStructGEP2(module.llvm.builder, source_type.llvm.abi, destination_value, #truncate(i), ""); - >field_value = LLVMBuildExtractValue(module.llvm.builder, source_value, #truncate(i), ""); + >gep = LLVMBuildStructGEP2(module.llvm.builder, source_type.llvm.abi, destination_value, @truncate(i), ""); + >field_value = LLVMBuildExtractValue(module.llvm.builder, source_value, @truncate(i), ""); create_store(module, { .source = field_value, @@ -12758,14 +12774,21 @@ create_coerced_store = fn (module: &Module, source_value: &LLVMValue, source_typ } else if (type_is_integer_backing(source_type)) { - #trap(); + >int_type = integer_type(module, { .bit_count = destination_size * 8, .signed = 0 }); + >value = coerce_integer_or_pointer_to_integer_or_pointer(module, source_value, source_type, int_type); + create_store(module, { + .source = value, + .destination = destination_value, + .type = int_type, + zero, + }); } else { // Coercion through memory >original_destination_alignment = get_byte_alignment(destination_type); - >source_alloca_alignment = #max(original_destination_alignment, get_byte_alignment(source_type)); + >source_alloca_alignment = @max(original_destination_alignment, get_byte_alignment(source_type)); >source_alloca = create_alloca(module, { .type = source_type, .name = "coerce", @@ -12786,18 +12809,13 @@ create_coerced_store = fn (module: &Module, source_value: &LLVMValue, source_typ } } -coerce_integer_or_pointer_to_integer_or_pointer = fn (module: &Module, source: &LLVMValue, source_type: &Type, destination_type: &Type) &LLVMValue -{ - #trap(); -} - create_coerced_load = fn (module: &Module, source: &LLVMValue, source_type: &Type, destination_type: &Type) &LLVMValue { >result: &LLVMValue = zero; if (type_is_abi_equal(module, source_type, destination_type)) { - #trap(); + @trap(); } else { @@ -12840,14 +12858,14 @@ create_coerced_load = fn (module: &Module, source: &LLVMValue, source_type: &Typ >scalable_vector_type: u1 = 0; if (scalable_vector_type) { - #trap(); + @trap(); } else { // Coercion through memory >original_destination_alignment = get_byte_alignment(destination_type); >source_alignment = get_byte_alignment(source_type); - >destination_alignment = #max(original_destination_alignment, source_alignment); + >destination_alignment = @max(original_destination_alignment, source_alignment); >destination_alloca = create_alloca(module, { .type = destination_type, .name = "coerce", @@ -12934,7 +12952,7 @@ emit_call = fn (module: &Module, value: &Value, left_llvm: &LLVMValue, left_type >uses_in_alloca: u1 = 0; if (uses_in_alloca) { - #trap(); + @trap(); } >llvm_indirect_return_value: &LLVMValue = zero; @@ -12964,7 +12982,7 @@ emit_call = fn (module: &Module, value: &Value, left_llvm: &LLVMValue, left_type } else { - #trap(); + @trap(); } assert(pointer != zero); @@ -12981,11 +12999,11 @@ emit_call = fn (module: &Module, value: &Value, left_llvm: &LLVMValue, left_type } else if (return_abi.flags.kind == .in_alloca) { - #trap(); + @trap(); } else { - #trap(); + @trap(); } }, else => {}, @@ -13025,9 +13043,9 @@ emit_call = fn (module: &Module, value: &Value, left_llvm: &LLVMValue, left_type if (is_named_argument) { // TODO: better slice single statement - >llvm_abi_argument_types = llvm_abi_argument_type_buffer_slice[#extend(argument_abi.abi_start)..#extend(argument_abi.abi_start + argument_abi.abi_count)]; - >destination_abi_argument_types = abi_argument_type_buffer_slice[#extend(argument_abi.abi_start)..#extend(argument_abi.abi_start + argument_abi.abi_count)]; - >source_abi_argument_types = raw_function_type.content.function.abi.abi_argument_types[#extend(argument_abi.abi_start)..#extend(argument_abi.abi_start + argument_abi.abi_count)]; + >llvm_abi_argument_types = llvm_abi_argument_type_buffer_slice[@extend(argument_abi.abi_start)..@extend(argument_abi.abi_start + argument_abi.abi_count)]; + >destination_abi_argument_types = abi_argument_type_buffer_slice[@extend(argument_abi.abi_start)..@extend(argument_abi.abi_start + argument_abi.abi_count)]; + >source_abi_argument_types = raw_function_type.content.function.abi.abi_argument_types[@extend(argument_abi.abi_start)..@extend(argument_abi.abi_start + argument_abi.abi_count)]; for (i: 0..argument_abi.abi_count) { @@ -13040,7 +13058,7 @@ emit_call = fn (module: &Module, value: &Value, left_llvm: &LLVMValue, left_type if (argument_abi.padding.type != zero) { - #trap(); + @trap(); } assert(abi_argument_count == argument_abi.abi_start); @@ -13064,13 +13082,13 @@ emit_call = fn (module: &Module, value: &Value, left_llvm: &LLVMValue, left_type switch (evaluation_kind) { .scalar => { v = semantic_call_argument_value; }, - .aggregate => { #trap(); }, - .complex => { #trap(); }, + .aggregate => { @trap(); }, + .complex => { @trap(); }, } if (!type_is_abi_equal(module, coerce_to_type, v.type)) { - #trap(); + @trap(); } llvm_abi_argument_value_buffer[abi_argument_count] = v.llvm; @@ -13080,13 +13098,13 @@ emit_call = fn (module: &Module, value: &Value, left_llvm: &LLVMValue, left_type { if (coerce_to_type.id == .struct and argument_abi.flags.kind == .direct and !argument_abi.flags.can_be_flattened) { - #trap(); + @trap(); } // TODO: fix this hack and collapse it into the generic path if (coerce_to_type == uint8(module) and semantic_argument_type == uint1(module)) { - #trap(); + @trap(); } else { @@ -13095,9 +13113,9 @@ emit_call = fn (module: &Module, value: &Value, left_llvm: &LLVMValue, left_type switch (evaluation_kind) { - .scalar => { #trap(); }, + .scalar => { @trap(); }, .aggregate => { src = semantic_call_argument_value; }, - .complex => { #trap(); }, + .complex => { @trap(); }, } assert(src != zero); @@ -13112,7 +13130,7 @@ emit_call = fn (module: &Module, value: &Value, left_llvm: &LLVMValue, left_type >source_type_is_scalable: u1 = 0; if (source_type_is_scalable) { - #trap(); + @trap(); } else { @@ -13131,7 +13149,7 @@ emit_call = fn (module: &Module, value: &Value, left_llvm: &LLVMValue, left_type }, else => { - #trap(); + @trap(); } } } @@ -13171,11 +13189,11 @@ emit_call = fn (module: &Module, value: &Value, left_llvm: &LLVMValue, left_type for (i: 0..coerce_fields.length) { >field = &coerce_fields[i]; - >gep = LLVMBuildStructGEP2(module.llvm.builder, coerce_to_type.llvm.memory, source, #truncate(i), ""); + >gep = LLVMBuildStructGEP2(module.llvm.builder, coerce_to_type.llvm.memory, source, @truncate(i), ""); >maybe_undef: u1 = 0; if (maybe_undef) { - #trap(); + @trap(); } >load = create_load(module, { @@ -13195,7 +13213,7 @@ emit_call = fn (module: &Module, value: &Value, left_llvm: &LLVMValue, left_type { for (i: 0..coerce_fields.length) { - llvm_abi_argument_value_buffer[abi_argument_count] = LLVMBuildExtractValue(module.llvm.builder, source, #truncate(i), ""); + llvm_abi_argument_value_buffer[abi_argument_count] = LLVMBuildExtractValue(module.llvm.builder, source, @truncate(i), ""); abi_argument_count += 1; } } @@ -13219,13 +13237,13 @@ emit_call = fn (module: &Module, value: &Value, left_llvm: &LLVMValue, left_type for (i: 0..coerce_fields.length) { - >gep = LLVMBuildStructGEP2(module.llvm.builder, coerce_to_type.llvm.abi, global, #truncate(i), ""); + >gep = LLVMBuildStructGEP2(module.llvm.builder, coerce_to_type.llvm.abi, global, @truncate(i), ""); >field = &coerce_fields[i]; >maybe_undef: u1 = 0; if (maybe_undef) { - #trap(); + @trap(); } >load = create_load(module, { @@ -13241,7 +13259,7 @@ emit_call = fn (module: &Module, value: &Value, left_llvm: &LLVMValue, left_type } else { - #trap(); + @trap(); } } .zero => @@ -13256,7 +13274,7 @@ emit_call = fn (module: &Module, value: &Value, left_llvm: &LLVMValue, left_type }, else => { - #trap(); + @trap(); }, } } @@ -13306,7 +13324,7 @@ emit_call = fn (module: &Module, value: &Value, left_llvm: &LLVMValue, left_type } else { - #trap(); + @trap(); } assert(pointer_type != zero); @@ -13328,13 +13346,13 @@ emit_call = fn (module: &Module, value: &Value, left_llvm: &LLVMValue, left_type >is_cmse_ns_call: u1 = 0; if (is_cmse_ns_call) { - #trap(); + @trap(); } >maybe_undef: u1 = 0; if (maybe_undef) { - #trap(); + @trap(); } v = load; @@ -13359,7 +13377,7 @@ emit_call = fn (module: &Module, value: &Value, left_llvm: &LLVMValue, left_type if (evaluation_kind == .aggregate) { >same_address_space: u1 = 1; - >abi_start: u64 = #extend(argument_abi.abi_start); + >abi_start: u64 = @extend(argument_abi.abi_start); assert(abi_start >= raw_function_type.content.function.abi.abi_argument_types.length or same_address_space); // TODO: handmade code, may contain bugs @@ -13370,7 +13388,7 @@ emit_call = fn (module: &Module, value: &Value, left_llvm: &LLVMValue, left_type if (abi_argument_type == semantic_argument_type) { - #trap(); + @trap(); } else if (abi_argument_type.id == .pointer and abi_argument_type.content.pointer.element_type == semantic_argument_type) { @@ -13428,17 +13446,17 @@ emit_call = fn (module: &Module, value: &Value, left_llvm: &LLVMValue, left_type } else { - #trap(); + @trap(); } } if (!do_continue) { - #trap(); + @trap(); } }, .ignore => { unreachable; }, - else => { #trap(); }, // TODO + else => { @trap(); }, // TODO } assert(abi_argument_count == argument_abi.abi_start + argument_abi.abi_count); @@ -13448,16 +13466,16 @@ emit_call = fn (module: &Module, value: &Value, left_llvm: &LLVMValue, left_type if (raw_function_type.content.function.base.is_variable_argument) { - assert(declaration_abi_argument_types.length <= #extend(abi_argument_count)); + assert(declaration_abi_argument_types.length <= @extend(abi_argument_count)); } else { - assert(declaration_abi_argument_types.length == #extend(abi_argument_count)); + assert(declaration_abi_argument_types.length == @extend(abi_argument_count)); } assert(raw_function_type.llvm.abi != zero); - >llvm_call = LLVMBuildCall2(module.llvm.builder, raw_function_type.llvm.abi, llvm_callable, &llvm_abi_argument_value_buffer[0], #extend(abi_argument_count), ""); + >llvm_call = LLVMBuildCall2(module.llvm.builder, raw_function_type.llvm.abi, llvm_callable, &llvm_abi_argument_value_buffer[0], @extend(abi_argument_count), ""); >llvm_calling_convention: LLVMCallingConvention = undefined; switch (raw_function_type.content.function.base.calling_convention) { @@ -13471,7 +13489,7 @@ emit_call = fn (module: &Module, value: &Value, left_llvm: &LLVMValue, left_type emit_attributes(module, llvm_call, &LLVMAddCallSiteAttribute, { .return_abi = return_abi, .argument_abis = argument_abis, - .abi_argument_types = abi_argument_type_buffer[..#extend(abi_argument_count)], + .abi_argument_types = abi_argument_type_buffer[..@extend(abi_argument_count)], .abi_return_type = raw_function_type.content.function.abi.abi_return_type, .attributes = zero, }); @@ -13505,7 +13523,7 @@ emit_call = fn (module: &Module, value: &Value, left_llvm: &LLVMValue, left_type >fixed_vector_type: u1 = 0; if (fixed_vector_type) { - #trap(); + @trap(); } >coerce_alloca: &LLVMValue = zero; @@ -13529,7 +13547,7 @@ emit_call = fn (module: &Module, value: &Value, left_llvm: &LLVMValue, left_type if (return_abi.attributes.direct.offset != 0) { - #trap(); + @trap(); } >destination_type = return_abi.semantic_type; @@ -13537,7 +13555,7 @@ emit_call = fn (module: &Module, value: &Value, left_llvm: &LLVMValue, left_type >source_value = llvm_call; >source_type = raw_function_type.content.function.abi.abi_return_type; >destination_size = get_byte_size(destination_type); - >left_destination_size = destination_size - #extend(return_abi.attributes.direct.offset); + >left_destination_size = destination_size - @extend(return_abi.attributes.direct.offset); >is_destination_volatile: u1 = 0; switch (return_abi.semantic_type.id) @@ -13551,7 +13569,7 @@ emit_call = fn (module: &Module, value: &Value, left_llvm: &LLVMValue, left_type } else { - #trap(); + @trap(); } }, .array => @@ -13592,7 +13610,7 @@ emit_call = fn (module: &Module, value: &Value, left_llvm: &LLVMValue, left_type zero, }); }, - .left => { #trap(); }, + .left => { @trap(); }, } } }, @@ -13643,7 +13661,7 @@ emit_field_access = fn (module: &Module, value: &Value, left_llvm: &LLVMValue, l assert(aggregate_type.id == .pointer); >aggregate_element_type = aggregate_type.content.pointer.element_type; - >real_aggregate_type = #select(aggregate_element_type.id == .pointer, aggregate_element_type.content.pointer.element_type, aggregate_element_type); + >real_aggregate_type = @select(aggregate_element_type.id == .pointer, aggregate_element_type.content.pointer.element_type, aggregate_element_type); >resolved_aggregate_type = resolve_alias(module, real_aggregate_type); resolve_type_in_place(module, resolved_aggregate_type); @@ -13686,7 +13704,7 @@ emit_field_access = fn (module: &Module, value: &Value, left_llvm: &LLVMValue, l } assert(result_field != zero); - >field_index: u32 = #truncate(result_field - fields.pointer); + >field_index: u32 = @truncate(result_field - fields.pointer); field_access = { .type = resolved_aggregate_type.content.struct.fields[field_index].type, @@ -13782,7 +13800,7 @@ emit_field_access = fn (module: &Module, value: &Value, left_llvm: &LLVMValue, l if (left_llvm) { - #trap(); + @trap(); } return trunc; @@ -13954,7 +13972,7 @@ emit_slice_expresion = fn (module: &Module, value: &Value) [2]&LLVMValue >slice_length: &LLVMValue = zero; if (has_start) { - #trap(); + @trap(); } else if (end != zero) { @@ -13996,7 +14014,7 @@ emit_va_arg_from_memory = fn (module: &Module, va_list_pointer: &LLVMValue, va_l if (get_byte_alignment(argument_type) > 8) { - #trap(); + @trap(); } >argument_type_size = get_byte_size(argument_type); @@ -14089,7 +14107,7 @@ emit_va_arg = fn (module: &Module, value: &Value, left_llvm: &LLVMValue, left_ty } else { - #trap(); + @trap(); } >raw_in_regs = 48 - needed_registers.gpr * 8; @@ -14100,11 +14118,11 @@ emit_va_arg = fn (module: &Module, value: &Value, left_llvm: &LLVMValue, left_ty >in_regs: &LLVMValue = zero; if (needed_registers.gpr != 0) { - in_regs = LLVMConstInt(u32_llvm, #extend(raw_in_regs), 0); + in_regs = LLVMConstInt(u32_llvm, @extend(raw_in_regs), 0); } else { - #trap(); + @trap(); } if (needed_registers.gpr != 0) @@ -14113,7 +14131,7 @@ emit_va_arg = fn (module: &Module, value: &Value, left_llvm: &LLVMValue, left_ty } else { - #trap(); + @trap(); } assert(in_regs != zero); @@ -14121,25 +14139,25 @@ emit_va_arg = fn (module: &Module, value: &Value, left_llvm: &LLVMValue, left_ty >fp_offset_pointer: &LLVMValue = zero; if (needed_registers.sse != 0) { - #trap(); + @trap(); } >fp_offset: &LLVMValue = zero; if (needed_registers.sse != 0) { - #trap(); + @trap(); } >raw_fits_in_fp = 176 - needed_registers.sse * 16; >fits_in_fp: &LLVMValue = zero; if (needed_registers.sse != 0) { - #trap(); + @trap(); } if (needed_registers.sse != 0 and needed_registers.gpr != 0) { - #trap(); + @trap(); } >in_reg_block = LLVMAppendBasicBlockInContext(module.llvm.context, llvm_function, "va_arg.in_reg"); @@ -14162,7 +14180,7 @@ emit_va_arg = fn (module: &Module, value: &Value, left_llvm: &LLVMValue, left_ty if (needed_registers.gpr != 0 and needed_registers.sse != 0) { - #trap(); + @trap(); } else if (needed_registers.gpr != 0) { @@ -14178,11 +14196,11 @@ emit_va_arg = fn (module: &Module, value: &Value, left_llvm: &LLVMValue, left_ty } else if (needed_registers.sse == 1) { - #trap(); + @trap(); } else if (needed_registers.sse == 2) { - #trap(); + @trap(); } else { @@ -14192,7 +14210,7 @@ emit_va_arg = fn (module: &Module, value: &Value, left_llvm: &LLVMValue, left_ty if (needed_registers.gpr != 0) { >raw_offset = needed_registers.gpr * 8; - >new_offset = LLVMBuildAdd(module.llvm.builder, gpr_offset, LLVMConstInt(u32_llvm, #extend(raw_offset), 0), ""); + >new_offset = LLVMBuildAdd(module.llvm.builder, gpr_offset, LLVMConstInt(u32_llvm, @extend(raw_offset), 0), ""); create_store(module, { .source = new_offset, .destination = gpr_offset_pointer, @@ -14203,7 +14221,7 @@ emit_va_arg = fn (module: &Module, value: &Value, left_llvm: &LLVMValue, left_ty if (needed_registers.sse != 0) { - #trap(); + @trap(); } LLVMBuildBr(module.llvm.builder, end_block); @@ -14253,10 +14271,10 @@ emit_va_arg = fn (module: &Module, value: &Value, left_llvm: &LLVMValue, left_ty } else { - #trap(); + @trap(); } }, - .complex => { #trap(); }, + .complex => { @trap(); }, } } @@ -14288,12 +14306,12 @@ emit_string_literal = fn (module: &Module, value: &Value) [2]&LLVMValue >pointer = value.content.string_literal.pointer; >length = value.content.string_literal.length; - >constant_string = LLVMConstStringInContext2(module.llvm.context, pointer, length, #extend(!null_terminate)); + >constant_string = LLVMConstStringInContext2(module.llvm.context, pointer, length, @extend(!null_terminate)); >u8_type = uint8(module); resolve_type_in_place(module, u8_type); - >string_type = LLVMArrayType2(u8_type.llvm.abi, length + #extend(null_terminate)); + >string_type = LLVMArrayType2(u8_type.llvm.abi, length + @extend(null_terminate)); >is_constant: u1 = 1; >thread_local_mode: LLVMThreadLocalMode = .none; >externally_initialized: u1 = 0; @@ -14377,7 +14395,7 @@ emit_argument = fn (module: &Module, argument: &Argument) void assert(scope != zero); >always_preserve: u1 = 1; >flags: LLVMDIFlags = zero; - >argument_variable = LLVMDIBuilderCreateParameterVariable(module.llvm.di_builder, scope, argument.variable.name.pointer, argument.variable.name.length, argument.index, module.llvm.file, argument.variable.line, debug_type, #extend(always_preserve), flags); + >argument_variable = LLVMDIBuilderCreateParameterVariable(module.llvm.di_builder, scope, argument.variable.name.pointer, argument.variable.name.length, argument.index, module.llvm.file, argument.variable.line, debug_type, @extend(always_preserve), flags); end_debug_local(module, &argument.variable, argument_variable); } @@ -14470,11 +14488,11 @@ emit_macro_instantiation = fn (module: &Module, value: &Value) void }, .aggregate => { - #trap(); + @trap(); }, .complex => { - #trap(); + @trap(); }, } } @@ -14538,7 +14556,7 @@ emit_value = fn (module: &Module, value: &Value, type_kind: TypeKind, expect_con .constant_integer => { >llvm_integer_type = get_llvm_type(resolved_value_type, type_kind); - llvm_value = LLVMConstInt(llvm_integer_type, value.content.constant_integer.value, #extend(value.content.constant_integer.signed)); + llvm_value = LLVMConstInt(llvm_integer_type, value.content.constant_integer.value, @extend(value.content.constant_integer.signed)); }, .binary => { @@ -14610,10 +14628,10 @@ emit_value = fn (module: &Module, value: &Value, type_kind: TypeKind, expect_con { right_condition = right_llvm; }, - else => { #trap(); }, + else => { @trap(); }, } }, - else => { #trap(); }, + else => { @trap(); }, } assert(right_condition != zero); @@ -14743,7 +14761,7 @@ emit_value = fn (module: &Module, value: &Value, type_kind: TypeKind, expect_con }, .left => { - #trap(); + @trap(); } } }, @@ -14828,7 +14846,7 @@ emit_value = fn (module: &Module, value: &Value, type_kind: TypeKind, expect_con { llvm_value = llvm_unary_value; }, - else => { #trap(); }, + else => { @trap(); }, } }, .variable => @@ -14858,7 +14876,7 @@ emit_value = fn (module: &Module, value: &Value, type_kind: TypeKind, expect_con report_error(); } - >global: &Global = #field_parent_pointer(variable, "variable"); + >global: &Global = @field_parent_pointer(variable, "variable"); llvm_value = global.initial_value.llvm; } else @@ -14877,12 +14895,12 @@ emit_value = fn (module: &Module, value: &Value, type_kind: TypeKind, expect_con zero, }); }, - .complex => { #trap(); }, + .complex => { @trap(); }, } } else { - #trap(); + @trap(); } } }, @@ -14902,7 +14920,7 @@ emit_value = fn (module: &Module, value: &Value, type_kind: TypeKind, expect_con .align_of => { assert(resolved_value_type.id == .integer); - llvm_value = LLVMConstInt(llvm_result_type, #extend(get_byte_alignment(unary_type)), 0); + llvm_value = LLVMConstInt(llvm_result_type, @extend(get_byte_alignment(unary_type)), 0); }, .byte_size => { @@ -14915,7 +14933,7 @@ emit_value = fn (module: &Module, value: &Value, type_kind: TypeKind, expect_con assert(unary_type.id == .integer); >signed = unary_type.content.integer.signed; >max_value = integer_max_value(unary_type.content.integer.bit_count, signed); - llvm_value = LLVMConstInt(llvm_result_type, max_value, #extend(signed)); + llvm_value = LLVMConstInt(llvm_result_type, max_value, @extend(signed)); }, .enum_values => { @@ -14977,7 +14995,7 @@ emit_value = fn (module: &Module, value: &Value, type_kind: TypeKind, expect_con { .right => { - #trap(); + @trap(); }, .left => { @@ -15157,7 +15175,7 @@ emit_value = fn (module: &Module, value: &Value, type_kind: TypeKind, expect_con }, else => { - #trap(); + @trap(); }, } }, @@ -15184,7 +15202,7 @@ emit_value = fn (module: &Module, value: &Value, type_kind: TypeKind, expect_con } >llvm_type = get_llvm_type(resolved_value_type, type_kind); - llvm_value = LLVMConstInt(llvm_type, result_field.value, #extend(type_is_signed(resolved_value_type))); + llvm_value = LLVMConstInt(llvm_type, result_field.value, @extend(type_is_signed(resolved_value_type))); }, .trap => { @@ -15282,7 +15300,7 @@ emit_value = fn (module: &Module, value: &Value, type_kind: TypeKind, expect_con assert(constant_count == fields.length); - llvm_value = LLVMConstNamedStruct(get_llvm_type(resolved_value_type, type_kind), &constant_buffer[0], #truncate(constant_count)); + llvm_value = LLVMConstNamedStruct(get_llvm_type(resolved_value_type, type_kind), &constant_buffer[0], @truncate(constant_count)); } else { @@ -15292,7 +15310,7 @@ emit_value = fn (module: &Module, value: &Value, type_kind: TypeKind, expect_con }, .union => { - #trap(); + @trap(); }, .bits => { @@ -15434,10 +15452,10 @@ emit_value = fn (module: &Module, value: &Value, type_kind: TypeKind, expect_con >bit_count = condition_type.content.integer.bit_count; if (bit_count != 1) { - #trap(); + @trap(); } }, - else => { #trap(); }, + else => { @trap(); }, } emit_value(module, true_value, type_kind, must_be_constant); @@ -15571,15 +15589,15 @@ emit_value = fn (module: &Module, value: &Value, type_kind: TypeKind, expect_con }, .build_mode => { - llvm_value = LLVMConstInt(get_llvm_type(resolved_value_type.content.enum.backing_type, type_kind), #extend(#int_from_enum(module.build_mode)), 0); + llvm_value = LLVMConstInt(get_llvm_type(resolved_value_type.content.enum.backing_type, type_kind), @extend(@int_from_enum(module.build_mode)), 0); }, .has_debug_info => { - llvm_value = LLVMConstInt(get_llvm_type(resolved_value_type, type_kind), #extend(module.has_debug_info), 0); + llvm_value = LLVMConstInt(get_llvm_type(resolved_value_type, type_kind), @extend(module.has_debug_info), 0); }, else => { - #trap(); + @trap(); }, } @@ -15692,7 +15710,7 @@ emit_assignment = fn (module: &Module, left_llvm: &LLVMValue, left_type: &Type, for (i: 0..string_literal.length) { - >member_pointer = LLVMBuildStructGEP2(module.llvm.builder, slice_type.llvm.abi, left_llvm, #truncate(i), ""); + >member_pointer = LLVMBuildStructGEP2(module.llvm.builder, slice_type.llvm.abi, left_llvm, @truncate(i), ""); >slice_member_type = slice_type.content.struct.fields[i].type; create_store(module, { .source = string_literal[i], @@ -15788,11 +15806,11 @@ emit_assignment = fn (module: &Module, left_llvm: &LLVMValue, left_type: &Type, } field_mask |= 1 << declaration_index; - max_field_index = #max(max_field_index, declaration_index); + max_field_index = @max(max_field_index, declaration_index); >field = &fields[declaration_index]; - >destination_pointer = LLVMBuildStructGEP2(module.llvm.builder, resolved_value_type.llvm.memory, left_llvm, #truncate(declaration_index), ""); + >destination_pointer = LLVMBuildStructGEP2(module.llvm.builder, resolved_value_type.llvm.memory, left_llvm, @truncate(declaration_index), ""); emit_assignment(module, destination_pointer, get_pointer_type(module, field.type), value); } @@ -15841,7 +15859,7 @@ emit_assignment = fn (module: &Module, left_llvm: &LLVMValue, left_type: &Type, }, else => { - #trap(); + @trap(); }, } } @@ -15891,7 +15909,7 @@ emit_assignment = fn (module: &Module, left_llvm: &LLVMValue, left_type: &Type, { .left => { - #trap(); + @trap(); }, .right => { @@ -15986,13 +16004,13 @@ emit_assignment = fn (module: &Module, left_llvm: &LLVMValue, left_type: &Type, }, else => { - #trap(); + @trap(); }, } }, .complex => { - #trap(); + @trap(); }, } } @@ -16100,7 +16118,7 @@ analyze_statement = fn (module: &Module, scope: &Scope, statement: &Statement) v assert(!local.variable.storage); analyze_type(module, local.initial_value, expected_type, zero); - local.variable.type = #select(expected_type != zero, expected_type, local.initial_value.type); + local.variable.type = @select(expected_type != zero, expected_type, local.initial_value.type); assert(local.variable.type != zero); emit_local(module, local); @@ -16206,14 +16224,14 @@ analyze_statement = fn (module: &Module, scope: &Scope, statement: &Statement) v LLVMBuildBr(module.llvm.builder, entry_block); - if (!LLVMGetFirstUse(#pointer_cast(body_block))) + if (!LLVMGetFirstUse(@pointer_cast(body_block))) { - #trap(); + @trap(); } - if (!LLVMGetFirstUse(#pointer_cast(exit_block))) + if (!LLVMGetFirstUse(@pointer_cast(exit_block))) { - #trap(); + @trap(); } LLVMPositionBuilderAtEnd(module.llvm.builder, exit_block); @@ -16314,7 +16332,7 @@ analyze_statement = fn (module: &Module, scope: &Scope, statement: &Statement) v for (i: 0..clauses.length) { >clause = &clauses[i]; - clause.basic_block = LLVMAppendBasicBlockInContext(module.llvm.context, llvm_function, #select(clause.values.length == 0, "switch.else_case_block", "switch.case_block")); + clause.basic_block = LLVMAppendBasicBlockInContext(module.llvm.context, llvm_function, @select(clause.values.length == 0, "switch.else_case_block", "switch.case_block")); discriminant_case_count += clause.values.length; if (clause.values.length == 0) @@ -16381,7 +16399,7 @@ analyze_statement = fn (module: &Module, scope: &Scope, statement: &Statement) v else_block = LLVMAppendBasicBlockInContext(module.llvm.context, llvm_function, "switch.else_case_block"); } - >switch_instruction = LLVMBuildSwitch(module.llvm.builder, discriminant.llvm, else_block, #truncate(discriminant_case_count)); + >switch_instruction = LLVMBuildSwitch(module.llvm.builder, discriminant.llvm, else_block, @truncate(discriminant_case_count)); >all_blocks_terminated: u1 = 1; for (&clause: clauses) @@ -16764,7 +16782,7 @@ analyze_statement = fn (module: &Module, scope: &Scope, statement: &Statement) v } else { - #trap(); + @trap(); } }, .left => @@ -16932,7 +16950,7 @@ analyze_statement = fn (module: &Module, scope: &Scope, statement: &Statement) v else { // TODO: case for reverse range - #trap(); + @trap(); } }, } @@ -16965,7 +16983,7 @@ analyze_statement = fn (module: &Module, scope: &Scope, statement: &Statement) v }, else => { - #trap(); + @trap(); }, } } @@ -17021,7 +17039,7 @@ generate_object = fn (module: &LLVMModule, target_machine: &LLVMTargetMachine, o >code_generation_options: LLVMCodeGenerationOptions = { .output_file_path = options.path, .file_type = .object, - .optimize_when_possible = #extend(options.optimization_level > .O0), + .optimize_when_possible = @extend(options.optimization_level > .O0), .verify_module = 1, zero, }; @@ -17114,7 +17132,7 @@ link = fn (module: &Module) void >result = lld_elf_link(linker_arguments.pointer, linker_arguments.length, 1, 0); if (!result.success) { - #trap(); + @trap(); } } @@ -17128,7 +17146,7 @@ emit_debug_argument = fn (module: &Module, argument: &Argument, basic_block: &LL >flags: LLVMDIFlags = zero; >scope = argument.variable.scope.llvm; - >parameter_variable = LLVMDIBuilderCreateParameterVariable(module.llvm.di_builder, scope, argument.variable.name.pointer, argument.variable.name.length, argument.index, module.llvm.file, argument.variable.line, argument.variable.type.llvm.debug, #extend(always_preserve), flags); + >parameter_variable = LLVMDIBuilderCreateParameterVariable(module.llvm.di_builder, scope, argument.variable.name.pointer, argument.variable.name.length, argument.index, module.llvm.file, argument.variable.line, argument.variable.type.llvm.debug, @extend(always_preserve), flags); >inlined_at = module.llvm.inlined_at; >debug_location = LLVMDIBuilderCreateDebugLocation(module.llvm.context, argument.variable.line, argument.variable.column, scope, inlined_at); @@ -17172,22 +17190,31 @@ emit = fn (module: &Module) void >sysroot = ""; >sdk = ""; - module.scope.llvm = LLVMDIBuilderCreateCompileUnit(di_builder, language, di_file, producer_name.pointer, producer_name.length, #extend(is_optimized), flags.pointer, flags.length, runtime_version, split_name.pointer, split_name.length, emission_kind, 0, 0, #extend(is_optimized), sysroot.pointer, sysroot.length, sdk.pointer, sdk.length); + module.scope.llvm = LLVMDIBuilderCreateCompileUnit(di_builder, language, di_file, producer_name.pointer, producer_name.length, @extend(is_optimized), flags.pointer, flags.length, runtime_version, split_name.pointer, split_name.length, emission_kind, 0, 0, @extend(is_optimized), sysroot.pointer, sysroot.length, sdk.pointer, sdk.length); } >target_triple: &u8 = zero; >cpu_model: &u8 = zero; >cpu_features: &u8 = zero; - if (target_compare(module.target, target_get_native())) + if (target_compare(module.target, target_get_native(module.target.host_cpu_model))) { target_triple = host_target_triple; - cpu_model = host_cpu_model; - cpu_features = host_cpu_features; + + if (module.target.host_cpu_model) + { + cpu_model = host_cpu_model; + cpu_features = host_cpu_features; + } + else + { + cpu_model = "generic"; + cpu_features = ""; + } } else { - #trap(); + @trap(); } >target_machine_options = LLVMCreateTargetMachineOptions(); @@ -17236,8 +17263,8 @@ emit = fn (module: &Module) void for (i: 0..module.llvm.intrinsic_table.length) { - >e: LLVMIntrinsicIndex = #enum_from_int(i); - >name = #enum_name(e); + >e: LLVMIntrinsicIndex = @enum_from_int(i); + >name = @enum_name(e); >intrinsic_id = LLVMLookupIntrinsicID(name.pointer, name.length); assert(intrinsic_id != 0); module.llvm.intrinsic_table[i] = intrinsic_id; @@ -17245,8 +17272,8 @@ emit = fn (module: &Module) void for (i: 0..module.llvm.attribute_table.length) { - >e: LLVMAttributeIndex = #enum_from_int(i); - >name = #enum_name(e); + >e: LLVMAttributeIndex = @enum_from_int(i); + >name = @enum_name(e); >attribute_id = LLVMGetEnumAttributeKindForName(name.pointer, name.length); assert(attribute_id != 0); module.llvm.attribute_table[i] = attribute_id; @@ -17298,8 +17325,8 @@ emit = fn (module: &Module) void function_type.abi.available_registers = { .system_v = { - .gpr = #select(register_call, 11, 6), - .sse = #select(register_call, 16, 8), + .gpr = @select(register_call, 11, 6), + .sse = @select(register_call, 16, 8), }, }; @@ -17368,24 +17395,24 @@ emit = fn (module: &Module) void } - >abi_argument_types = arena_allocate_slice[&Type](module.arena, #extend(abi_argument_type_count)); - memcpy(#pointer_cast(abi_argument_types.pointer), #pointer_cast(&abi_argument_type_buffer), #extend(#byte_size(&Type) * abi_argument_type_count)); + >abi_argument_types = arena_allocate_slice[&Type](module.arena, @extend(abi_argument_type_count)); + memcpy(@pointer_cast(abi_argument_types.pointer), @pointer_cast(&abi_argument_type_buffer), @extend(@byte_size(&Type) * abi_argument_type_count)); function_type.abi.abi_argument_types = abi_argument_types; }, .win64 => { -#trap(); +@trap(); }, } - >llvm_function_type = LLVMFunctionType(function_type.abi.abi_return_type.llvm.abi, &llvm_abi_argument_type_buffer[0], #truncate(function_type.abi.abi_argument_types.length), #extend(function_type.base.is_variable_argument)); + >llvm_function_type = LLVMFunctionType(function_type.abi.abi_return_type.llvm.abi, &llvm_abi_argument_type_buffer[0], @truncate(function_type.abi.abi_argument_types.length), @extend(function_type.base.is_variable_argument)); >subroutine_type: &LLVMMetadata = zero; if (module.has_debug_info) { >debug_argument_type_buffer: [64]&LLVMMetadata = undefined; - >debug_argument_types = debug_argument_type_buffer[..function_type.abi.argument_abis.length + 1 + #extend(function_type.base.is_variable_argument)]; + >debug_argument_types = debug_argument_type_buffer[..function_type.abi.argument_abis.length + 1 + @extend(function_type.base.is_variable_argument)]; debug_argument_types[0] = function_type.abi.return_abi.semantic_type.llvm.debug; assert(debug_argument_types[0] != zero); @@ -17409,7 +17436,7 @@ emit = fn (module: &Module) void } >flags: LLVMDIFlags = zero; - subroutine_type = LLVMDIBuilderCreateSubroutineType(module.llvm.di_builder, module.llvm.file, debug_argument_types.pointer, #truncate(debug_argument_types.length), flags); + subroutine_type = LLVMDIBuilderCreateSubroutineType(module.llvm.di_builder, module.llvm.file, debug_argument_types.pointer, @truncate(debug_argument_types.length), flags); } assert(global.variable.storage.type.id == .pointer); @@ -17464,7 +17491,7 @@ emit = fn (module: &Module) void >scope_line = line + 1; >flags: LLVMDIFlags = zero; >is_optimized = build_mode_is_optimized(module.build_mode); - subprogram = LLVMDIBuilderCreateFunction(module.llvm.di_builder, module.scope.llvm, name.pointer, name.length, linkage_name.pointer, linkage_name.length, module.llvm.file, line, subroutine_type, #extend(is_local_to_unit), #extend(is_definition), scope_line, flags, #extend(is_optimized)); + subprogram = LLVMDIBuilderCreateFunction(module.llvm.di_builder, module.scope.llvm, name.pointer, name.length, linkage_name.pointer, linkage_name.length, module.llvm.file, line, subroutine_type, @extend(is_local_to_unit), @extend(is_definition), scope_line, flags, @extend(is_optimized)); LLVMSetSubprogram(llvm_function, subprogram); } @@ -17529,7 +17556,7 @@ emit = fn (module: &Module) void >name = global.variable.name; >linkage_name = name; >local_to_unit = global.linkage == .internal; - >global_debug = LLVMDIBuilderCreateGlobalVariableExpression(module.llvm.di_builder, module.scope.llvm, name.pointer, name.length, linkage_name.pointer, linkage_name.length, module.llvm.file, global.variable.line, global_type.llvm.debug, #extend(local_to_unit), null_expression(module), zero, alignment * 8); + >global_debug = LLVMDIBuilderCreateGlobalVariableExpression(module.llvm.di_builder, module.scope.llvm, name.pointer, name.length, linkage_name.pointer, linkage_name.length, module.llvm.file, global.variable.line, global_type.llvm.debug, @extend(local_to_unit), null_expression(module), zero, alignment * 8); LLVMGlobalSetMetadata(llvm_global, 0, global_debug); } }, @@ -17594,19 +17621,19 @@ emit = fn (module: &Module) void >indirect_argument_index = function_type.abi.return_abi.flags.sret_after_this; if (function_type.abi.return_abi.flags.sret_after_this) { -#trap(); +@trap(); } global.variable.storage.content.function.llvm.return_alloca = llvm_abi_arguments[indirect_argument_index]; if (!function_type.abi.return_abi.flags.indirect_by_value) { -#trap(); +@trap(); } }, .in_alloca => { -#trap(); +@trap(); }, else => { @@ -17628,8 +17655,8 @@ emit = fn (module: &Module) void >argument = &arguments[i]; >argument_abi = &argument_abis[i]; // TODO: double slice - >argument_abi_arguments = llvm_abi_arguments[#extend(argument_abi.abi_start)..]; - argument_abi_arguments = argument_abi_arguments[..#extend(argument_abi.abi_count)]; + >argument_abi_arguments = llvm_abi_arguments[@extend(argument_abi.abi_start)..]; + argument_abi_arguments = argument_abi_arguments[..@extend(argument_abi.abi_count)]; >semantic_argument_storage: &LLVMValue = zero; @@ -17648,12 +17675,12 @@ emit = fn (module: &Module) void if (coerce_to_type.llvm.abi != LLVMTypeOf(v)) { -#trap(); +@trap(); } if (is_promoted) { -#trap(); +@trap(); } // TODO: this we can get rid of because we handle all of this inside `create_alloca`, load, stores, etc @@ -17685,7 +17712,7 @@ emit = fn (module: &Module) void } else { -#trap(); +@trap(); } create_store(module, { @@ -17720,7 +17747,7 @@ emit = fn (module: &Module) void >is_fixed_vector_type: u1 = 0; if (is_fixed_vector_type) { -#trap(); +@trap(); } if (coerce_to_type.id == .struct and coerce_to_type.content.struct.fields.length > 1 and argument_abi.flags.kind == .direct and !argument_abi.flags.can_be_flattened) @@ -17728,7 +17755,7 @@ emit = fn (module: &Module) void >contains_homogeneous_scalable_vector_types: u1 = 0; if (contains_homogeneous_scalable_vector_types) { -#trap(); +@trap(); } } @@ -17743,7 +17770,7 @@ emit = fn (module: &Module) void if (argument_abi.attributes.direct.offset > 0) { -#trap(); +@trap(); } else { @@ -17759,7 +17786,7 @@ emit = fn (module: &Module) void if (is_scalable) { -#trap(); +@trap(); } else { @@ -17783,14 +17810,14 @@ emit = fn (module: &Module) void } >fields = coerce_to_type.content.struct.fields; - assert(fields.length == #extend(argument_abi.abi_count)); + assert(fields.length == @extend(argument_abi.abi_count)); resolve_type_in_place(module, coerce_to_type); for (i: 0..fields.length) { >field = &fields[i]; - >gep = LLVMBuildStructGEP2(module.llvm.builder, coerce_to_type.llvm.abi, address, #truncate(i), ""); + >gep = LLVMBuildStructGEP2(module.llvm.builder, coerce_to_type.llvm.abi, address, @truncate(i), ""); create_store(module, { .source = argument_abi_arguments[i], .destination = gep, @@ -17813,7 +17840,7 @@ emit = fn (module: &Module) void { assert(argument_abi.abi_count == 1); >abi_argument_type = function_type.abi.abi_argument_types[argument_abi.abi_start]; - >destination_size: u64 = get_byte_size(pointer_type) - #extend(argument_abi.attributes.direct.offset); + >destination_size: u64 = get_byte_size(pointer_type) - @extend(argument_abi.attributes.direct.offset); >is_volatile: u1 = 0; create_coerced_store(module, argument_abi_arguments[0], abi_argument_type, pointer, pointer_type, destination_size, is_volatile); } @@ -17832,13 +17859,13 @@ emit = fn (module: &Module) void { if (argument_abi.flags.indirect_realign or argument_abi.flags.kind == .indirect_aliased) { -#trap(); +@trap(); } >use_indirect_debug_address = !argument_abi.flags.indirect_by_value; if (use_indirect_debug_address) { -#trap(); +@trap(); } >llvm_argument = argument_abi_arguments[0]; @@ -17846,7 +17873,7 @@ emit = fn (module: &Module) void }, .scalar => { -#trap(); +@trap(); }, } }, @@ -17881,9 +17908,9 @@ emit = fn (module: &Module) void if (current_basic_block) { assert(!LLVMGetBasicBlockTerminator(current_basic_block)); - if (!LLVMGetFirstInstruction(current_basic_block) or !LLVMGetFirstUse(#pointer_cast(current_basic_block))) + if (!LLVMGetFirstInstruction(current_basic_block) or !LLVMGetFirstUse(@pointer_cast(current_basic_block))) { - LLVMReplaceAllUsesWith(#pointer_cast(return_block), #pointer_cast(current_basic_block)); + LLVMReplaceAllUsesWith(@pointer_cast(return_block), @pointer_cast(current_basic_block)); LLVMDeleteBasicBlock(return_block); } else @@ -17895,7 +17922,7 @@ emit = fn (module: &Module) void { >has_single_jump_to_return_block: u1 = 0; - >first_use = LLVMGetFirstUse(#pointer_cast(return_block)); + >first_use = LLVMGetFirstUse(@pointer_cast(return_block)); >user: &LLVMValue = zero; if (first_use) @@ -17916,7 +17943,7 @@ emit = fn (module: &Module) void >new_return_block = LLVMGetInstructionParent(user); // Remove unconditional branch instruction to the return block LLVMInstructionEraseFromParent(user); - assert(!LLVMGetFirstUse(#pointer_cast(return_block))); + assert(!LLVMGetFirstUse(@pointer_cast(return_block))); assert(!LLVMGetBasicBlockTerminator(return_block)); assert(LLVMGetBasicBlockParent(return_block) != zero); LLVMPositionBuilderAtEnd(module.llvm.builder, new_return_block); @@ -17983,7 +18010,7 @@ emit = fn (module: &Module) void } else { -#trap(); +@trap(); } assert(source != zero); @@ -17999,9 +18026,9 @@ emit = fn (module: &Module) void >evaluation_kind = get_evaluation_kind(function_type.abi.return_abi.semantic_type); switch (evaluation_kind) { - .scalar => { #trap(); }, + .scalar => { @trap(); }, .aggregate => {}, - .complex => { #trap(); }, + .complex => { @trap(); }, } }, } @@ -18104,10 +18131,10 @@ compile = fn (arena: &Arena, options: CompileOptions) void 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); + >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]); @@ -18137,7 +18164,7 @@ compile = fn (arena: &Arena, options: CompileOptions) void for (sign: signs) { - >name = #select(sign, "s128", "u128"); + >name = @select(sign, "s128", "u128"); type_it.& = { .content = { .integer = { @@ -18269,34 +18296,49 @@ compile_file = fn (arena: &Arena, compile_options: CompileFile, envp: &&u8) []u8 separator_index = 0; } - >base_start = separator_index + #extend(separator_index != 0 or relative_file_path[separator_index] == '/'); + >base_start = separator_index + @extend(separator_index != 0 or relative_file_path[separator_index] == '/'); >base_name = relative_file_path[base_start..extension_start]; >is_compiler = string_equal(relative_file_path, "src/compiler.bbb"); + + os_make_directory(base_cache_dir.pointer); + >base_dir = arena_join_string(arena, [ base_cache_dir, "/", - #enum_name(#build_mode), - "_", - #select(#has_debug_info(), "di", "nodi"), - ][..]); - >outputh_path_dir = arena_join_string(arena, [ - base_dir, - #select(is_compiler, "/compiler/", "/"), - #enum_name(compile_options.build_mode), - "_", - #select(compile_options.has_debug_info, "di", "nodi"), + @select(compile_options.host_cpu_model, "native", "generic"), + ][..]); + + os_make_directory(base_dir.pointer); + + base_dir = arena_join_string(arena, [ + base_dir, + "/", + @enum_name(@build_mode), + "_", + @select(@has_debug_info(), "di", "nodi"), ][..]); - os_make_directory(base_cache_dir.pointer); os_make_directory(base_dir.pointer); if (is_compiler) { - >compiler_dir = arena_join_string(arena, [ base_dir, "/compiler" ][..]); - os_make_directory(compiler_dir.pointer); + base_dir = arena_join_string(arena, [ + base_dir, + "/compiler", + ][..]); + + os_make_directory(base_dir.pointer); } + >outputh_path_dir = arena_join_string(arena, [ + base_dir, + "/", + @enum_name(compile_options.build_mode), + "_", + @select(compile_options.has_debug_info, "di", "nodi"), + ][..]); + os_make_directory(outputh_path_dir.pointer); >outputh_path_base = arena_join_string(arena, [ outputh_path_dir, "/", base_name ][..]); @@ -18437,7 +18479,7 @@ compile_file = fn (arena: &Arena, compile_options: CompileFile, envp: &&u8) []u8 library_names = library_buffer[..library_count]; library_paths = { .pointer = &llvm_bindings_library, .length = 1 }; } - else if (string_equal(base_name, "c_abi")) + else if (string_equal(base_name, "tests")) { library_paths = { .pointer = &c_abi_library, .length = 1 }; } @@ -18456,7 +18498,7 @@ compile_file = fn (arena: &Arena, compile_options: CompileFile, envp: &&u8) []u8 .content = file_content, .path = file_path, .has_debug_info = compile_options.has_debug_info, - .target = target_get_native(), + .target = target_get_native(compile_options.host_cpu_model), .silent = compile_options.silent, }; @@ -18467,125 +18509,7 @@ compile_file = fn (arena: &Arena, compile_options: CompileFile, envp: &&u8) []u8 names: [_][]u8 = [ - "minimal", - "comments", - "constant_add", - "constant_and", - "constant_div", - "constant_mul", - "constant_rem", - "constant_or", - "constant_sub", - "constant_xor", - "constant_shift_left", - "constant_shift_right", - "minimal_stack", - "minimal_stack_arithmetic", - "minimal_stack_arithmetic2", - "minimal_stack_arithmetic3", - "stack_negation", - "stack_add", - "stack_sub", - "extend", - "integer_max", - "integer_hex", - "basic_pointer", - "basic_call", - "basic_branch", - "basic_array", - "basic_enum", - "basic_slice", - "basic_string", - "basic_varargs", - "basic_while", - "pointer", - "pointer_cast", - "u1_return", - "local_type_inference", - "global", - "function_pointer", - "extern", - "byte_size", - "argv", - "assignment_operators", - "not_pointer", - "bits", - "bits_no_backing_type", - "bits_return_u1", - "bits_zero", - "comparison", - "global_struct", - "if_no_else", - "if_no_else_void", - "indirect", - "indirect_struct", - "indirect_varargs", - "ret_c_bool", - "return_type_builtin", - "return_u64_u64", - "select", - "slice", - "small_struct_ints", - "struct_assignment", - "struct", - "struct_u64_u64", - "struct_varargs", - "struct_zero", - "unreachable", - "varargs", - "c_abi0", - "c_abi1", - "c_med_struct_ints", - "c_ret_struct_array", - "c_split_struct_ints", - "c_string_to_slice", - "c_struct_with_array", - "c_function_pointer", - "basic_bool_call", - "abi_enum_bool", - "return_small_struct", - "c_abi", - "string_to_enum", - "empty_if", - "else_if", - "else_if_complicated", - "basic_shortcircuiting_if", - "shortcircuiting_if", - "field_access_left_assign", - "for_each", - "pointer_decay", - "enum_name", - "slice_of_slices", - "type_alias", - "integer_formats", - "for_each_int", - "bool_array", - "basic_union", - "break_continue", - "constant_global_reference", - "concat_logical_or", - "strict_array_type", - "pointer_struct_initialization", - "slice_array_literal", - "slice_only_start", - "basic_macro", - "generic_macro", - "generic_pointer_macro", - "noreturn_macro", - "generic_pointer_array", - "self_referential_struct", - "forward_declared_type", - "enum_array", - "opaque", - "basic_struct_passing", - "enum_arbitrary_abi", - "enum_debug_info", - "return_array", - "bool_pair", - "min_max", - "field_parent_pointer", - "leading_trailing_zeroes", - "pointer_sub", + "tests", ]; [export] main = fn [cc(c)] (argument_count: u32, argv: &&u8, envp: &&u8) s32 @@ -18593,7 +18517,7 @@ names: [_][]u8 = global_state_initialize(); >arena = global_state.arena; - >arguments = argv[..#extend(argument_count)]; + >arguments = argv[..@extend(argument_count)]; if (arguments.length < 2) { return 1; @@ -18601,13 +18525,14 @@ names: [_][]u8 = >command_string = c_string_to_slice(arguments[1]); - >command_string_to_enum = #string_to_enum(CompilerCommand, command_string); + >command_string_to_enum = @string_to_enum(CompilerCommand, command_string); if (!command_string_to_enum.is_valid) { return 1; } >debug_info_array: [_]u1 = [1, 0]; + >is_host_cpu_model_array: [_]u1 = [1, 0]; >command = command_string_to_enum.enum_value; @@ -18622,10 +18547,11 @@ names: [_][]u8 = >build_mode: BuildMode = .debug_none; >has_debug_info: u1 = 1; + >is_host_cpu_model: u1 = 1; if (argument_count >= 4) { - >build_mode_string_to_enum = #string_to_enum(BuildMode, c_string_to_slice(arguments[3])); + >build_mode_string_to_enum = @string_to_enum(BuildMode, c_string_to_slice(arguments[3])); if (!build_mode_string_to_enum.is_valid) { return 1; @@ -18650,6 +18576,23 @@ names: [_][]u8 = } } + if (argument_count >= 6) + { + >is_host_cpu_model_string = c_string_to_slice(arguments[5]); + if (string_equal(is_host_cpu_model_string, "true")) + { + is_host_cpu_model = 1; + } + else if (string_equal(is_host_cpu_model_string, "false")) + { + is_host_cpu_model = 0; + } + else + { + return 1; + } + } + >relative_file_path_pointer = arguments[2]; if (!relative_file_path_pointer) { @@ -18661,6 +18604,7 @@ names: [_][]u8 = compile_file(arena, { .relative_file_path = relative_file_path, .build_mode = build_mode, + .host_cpu_model = is_host_cpu_model, .has_debug_info = has_debug_info, .silent = 0, }, envp); @@ -18674,22 +18618,67 @@ names: [_][]u8 = for (name: names) { - for (build_mode: #enum_values(BuildMode)) + for (is_host_cpu_model: is_host_cpu_model_array) + { + for (build_mode: @enum_values(BuildMode)) + { + for (has_debug_info: debug_info_array) + { + >position = arena.position; + + >relative_file_path = arena_join_string(arena, [ "tests/", name, ".bbb" ][..]); + >executable_path = compile_file(arena, { + .relative_file_path = relative_file_path, + .build_mode = build_mode, + .has_debug_info = has_debug_info, + .host_cpu_model = is_host_cpu_model, + .silent = 1, + }, envp); + + >arguments: [_]&u8 = [ + executable_path.pointer, + zero, + ]; + >args = arguments[..arguments.length - 1]; + >execution = os_execute(arena, args, envp, zero); + + >success = execution.termination_kind == .exit and execution.termination_code == 0; + + if (!success) + { + @trap(); + } + + arena.position = position; + } + } + } + } + }, + .reproduce => + { + for (is_host_cpu_model: is_host_cpu_model_array) + { + for (build_mode: @enum_values(BuildMode)) { for (has_debug_info: debug_info_array) { >position = arena.position; - >relative_file_path = arena_join_string(arena, [ "tests/", name, ".bbb" ][..]); + // Produce the compiler + >relative_file_path = "src/compiler.bbb"; >executable_path = compile_file(arena, { - .relative_file_path = relative_file_path, - .build_mode = build_mode, - .has_debug_info = has_debug_info, - .silent = 1, - }, envp); + .relative_file_path = relative_file_path, + .host_cpu_model = is_host_cpu_model, + .build_mode = build_mode, + .has_debug_info = has_debug_info, + .silent = 1, + }, envp); + // Test the compiler >arguments: [_]&u8 = [ executable_path.pointer, + "test", zero, ]; >args = arguments[..arguments.length - 1]; @@ -18699,7 +18688,7 @@ names: [_][]u8 = if (!success) { - #trap(); + @trap(); } arena.position = position; @@ -18707,43 +18696,6 @@ names: [_][]u8 = } } }, - .reproduce => - { - for (build_mode: #enum_values(BuildMode)) - { - for (has_debug_info: debug_info_array) - { - >position = arena.position; - - // Produce the compiler - >relative_file_path = "src/compiler.bbb"; - >executable_path = compile_file(arena, { - .relative_file_path = relative_file_path, - .build_mode = build_mode, - .has_debug_info = has_debug_info, - .silent = 1, - }, envp); - - // Test the compiler - >arguments: [_]&u8 = [ - executable_path.pointer, - "test", - zero, - ]; - >args = arguments[..arguments.length - 1]; - >execution = os_execute(arena, args, envp, zero); - - >success = execution.termination_kind == .exit and execution.termination_code == 0; - - if (!success) - { - #trap(); - } - - arena.position = position; - } - } - }, } return 0; diff --git a/src/compiler.cpp b/src/compiler.cpp index 876235a..729b640 100644 --- a/src/compiler.cpp +++ b/src/compiler.cpp @@ -163,22 +163,39 @@ fn String compile_file(Arena* arena, Compile options) auto is_compiler = relative_file_path.equal(string_literal("src/compiler.bbb")); - String output_path_dir_parts[] = { + make_directory(base_cache_dir); + + String cpu_dir_parts[] = { string_literal(base_cache_dir), - is_compiler ? string_literal("/compiler/") : string_literal("/"), + string_literal("/"), + options.host_cpu_model ? string_literal("native") : string_literal("generic"), + }; + + auto cpu_dir = arena_join_string(arena, array_to_slice(cpu_dir_parts)); + + make_directory(cstr(cpu_dir)); + + auto base_dir = cpu_dir; + + if (is_compiler) + { + String compiler_dir_parts[] = { + base_dir, + string_literal("/compiler"), + }; + base_dir = arena_join_string(arena, array_to_slice(compiler_dir_parts)); + make_directory(cstr(base_dir)); + } + + String output_path_dir_parts[] = { + base_dir, + string_literal("/"), build_mode_to_string(options.build_mode), string_literal("_"), options.has_debug_info ? string_literal("di") : string_literal("nodi"), }; auto output_path_dir = arena_join_string(arena, array_to_slice(output_path_dir_parts)); - make_directory(base_cache_dir); - - if (is_compiler) - { - make_directory(base_cache_dir "/compiler"); - } - make_directory(cstr(output_path_dir)); String output_path_base_parts[] = { @@ -322,7 +339,7 @@ fn String compile_file(Arena* arena, Compile options) library_names = { library_buffer, library_count }; library_paths = { &llvm_bindings_library, 1 }; } - else if (base_name.equal(string_literal("c_abi"))) + else if (base_name.equal(string_literal("tests"))) { library_paths = { &c_abi_library, 1 }; } @@ -341,6 +358,7 @@ fn String compile_file(Arena* arena, Compile options) .target = { .cpu = CPUArchitecture::x86_64, .os = OperatingSystem::linux_, + .host_cpu_model = options.host_cpu_model, }, .build_mode = options.build_mode, .has_debug_info = options.has_debug_info, @@ -352,129 +370,7 @@ fn String compile_file(Arena* arena, Compile options) global_variable String names[] = { - string_literal("minimal"), - string_literal("comments"), - string_literal("constant_add"), - string_literal("constant_and"), - string_literal("constant_div"), - string_literal("constant_mul"), - string_literal("constant_rem"), - string_literal("constant_or"), - string_literal("constant_sub"), - string_literal("constant_xor"), - string_literal("constant_shift_left"), - string_literal("constant_shift_right"), - string_literal("minimal_stack"), - string_literal("minimal_stack_arithmetic"), - string_literal("minimal_stack_arithmetic2"), - string_literal("minimal_stack_arithmetic3"), - string_literal("stack_negation"), - string_literal("stack_add"), - string_literal("stack_sub"), - string_literal("extend"), - string_literal("integer_max"), - string_literal("integer_hex"), - string_literal("basic_pointer"), - string_literal("basic_call"), - string_literal("basic_branch"), - string_literal("basic_array"), - string_literal("basic_enum"), - string_literal("basic_slice"), - string_literal("basic_string"), - string_literal("basic_varargs"), - string_literal("basic_while"), - string_literal("pointer"), - string_literal("pointer_cast"), - string_literal("u1_return"), - string_literal("local_type_inference"), - string_literal("global"), - string_literal("function_pointer"), - string_literal("extern"), - string_literal("byte_size"), - string_literal("argv"), - string_literal("assignment_operators"), - string_literal("not_pointer"), - string_literal("bits"), - string_literal("bits_no_backing_type"), - string_literal("bits_return_u1"), - string_literal("bits_zero"), - string_literal("comparison"), - string_literal("global_struct"), - string_literal("if_no_else"), - string_literal("if_no_else_void"), - string_literal("indirect"), - string_literal("indirect_struct"), - string_literal("indirect_varargs"), - string_literal("ret_c_bool"), - string_literal("return_type_builtin"), - string_literal("return_u64_u64"), - string_literal("select"), - string_literal("slice"), - string_literal("small_struct_ints"), - string_literal("struct_assignment"), - string_literal("struct"), - string_literal("struct_u64_u64"), - string_literal("struct_varargs"), - string_literal("struct_zero"), - string_literal("unreachable"), - string_literal("varargs"), - string_literal("c_abi0"), - string_literal("c_abi1"), - string_literal("c_med_struct_ints"), - string_literal("c_ret_struct_array"), - string_literal("c_split_struct_ints"), - string_literal("c_string_to_slice"), - string_literal("c_struct_with_array"), - string_literal("c_function_pointer"), - string_literal("basic_bool_call"), - string_literal("abi_enum_bool"), - string_literal("return_small_struct"), - string_literal("c_abi"), - string_literal("string_to_enum"), - string_literal("empty_if"), - string_literal("else_if"), - string_literal("else_if_complicated"), - string_literal("basic_shortcircuiting_if"), - string_literal("shortcircuiting_if"), - string_literal("field_access_left_assign"), - string_literal("for_each"), - string_literal("pointer_decay"), - string_literal("enum_name"), - string_literal("slice_of_slices"), - string_literal("type_alias"), - string_literal("integer_formats"), - string_literal("for_each_int"), - string_literal("bool_array"), - string_literal("basic_union"), - string_literal("break_continue"), - string_literal("constant_global_reference"), - string_literal("concat_logical_or"), - string_literal("strict_array_type"), - string_literal("pointer_struct_initialization"), - string_literal("slice_array_literal"), - string_literal("slice_only_start"), - - string_literal("basic_macro"), - string_literal("generic_macro"), - - string_literal("generic_pointer_macro"), - string_literal("noreturn_macro"), - string_literal("generic_pointer_array"), - - string_literal("self_referential_struct"), - string_literal("forward_declared_type"), - - string_literal("enum_array"), - string_literal("opaque"), - string_literal("basic_struct_passing"), - string_literal("enum_arbitrary_abi"), - string_literal("enum_debug_info"), - string_literal("return_array"), - string_literal("bool_pair"), - string_literal("min_max"), - string_literal("field_parent_pointer"), - string_literal("leading_trailing_zeroes"), - string_literal("pointer_sub"), + string_literal("tests"), }; void entry_point(Slice arguments, Slice envp) @@ -517,6 +413,7 @@ void entry_point(Slice arguments, Slice envp) auto build_mode = BuildMode::debug_none; auto has_debug_info = true; + auto is_host_cpu_model = true; if (arguments.length >= 4) { @@ -565,12 +462,30 @@ void entry_point(Slice arguments, Slice envp) } } + if (arguments.length >= 6) + { + auto is_host_cpu_model_string = c_string_to_slice(arguments[5]); + if (is_host_cpu_model_string.equal(string_literal("true"))) + { + is_host_cpu_model = true; + } + else if (is_host_cpu_model_string.equal(string_literal("false"))) + { + is_host_cpu_model = false; + } + else + { + bb_fail_with_message(string_literal("Wrong value for is_host_cpu_model\n")); + } + } + auto relative_file_path = c_string_to_slice(arguments[2]); compile_file(arena, { .relative_file_path = relative_file_path, .build_mode = build_mode, .has_debug_info = has_debug_info, + .host_cpu_model = is_host_cpu_model, .silent = false, }); } break; @@ -596,11 +511,11 @@ void entry_point(Slice arguments, Slice envp) auto relative_file_path = arena_join_string(arena, array_to_slice(relative_file_path_parts)); auto executable_path = compile_file(arena, { - .relative_file_path = relative_file_path, - .build_mode = build_mode, - .has_debug_info = has_debug_info, - .silent = true, - }); + .relative_file_path = relative_file_path, + .build_mode = build_mode, + .has_debug_info = has_debug_info, + .silent = true, + }); char* const arguments[] = { @@ -630,6 +545,7 @@ void entry_point(Slice arguments, Slice envp) .relative_file_path = string_literal("src/compiler.bbb"), .build_mode = compiler_build_mode, .has_debug_info = compiler_has_debug_info, + .host_cpu_model = true, .silent = true, }); diff --git a/src/compiler.hpp b/src/compiler.hpp index 56962e0..50836dd 100644 --- a/src/compiler.hpp +++ b/src/compiler.hpp @@ -247,6 +247,7 @@ struct Target { CPUArchitecture cpu; OperatingSystem os; + bool host_cpu_model; }; fn Target target_get_native() @@ -270,6 +271,7 @@ struct Compile String relative_file_path; BuildMode build_mode; bool has_debug_info; + bool host_cpu_model; bool silent; }; diff --git a/src/emitter.cpp b/src/emitter.cpp index 48c1448..42dd043 100644 --- a/src/emitter.cpp +++ b/src/emitter.cpp @@ -416,15 +416,23 @@ fn void llvm_initialize(Module* module) module->scope.llvm = di_compile_unit; } - char* target_triple = {}; - char* cpu_model = {}; - char* cpu_features = {}; + const char* target_triple = {}; + const char* cpu_model = {}; + const char* cpu_features = {}; if (target_compare(module->target, target_get_native())) { target_triple = llvm_global.host_triple; - cpu_model = llvm_global.host_cpu_model; - cpu_features = llvm_global.host_cpu_features; + if (module->target.host_cpu_model) + { + cpu_model = llvm_global.host_cpu_model; + cpu_features = llvm_global.host_cpu_features; + } + else + { + cpu_model = "generic"; + cpu_features = ""; + } } else { diff --git a/src/parser.cpp b/src/parser.cpp index e750513..ceb7a7a 100644 --- a/src/parser.cpp +++ b/src/parser.cpp @@ -999,7 +999,7 @@ fn Type* parse_type(Module* module, Scope* scope) } } } - else if (start_character == '#') + else if (start_character == '@') { module->offset += 1; auto identifier = parse_identifier(module); @@ -1167,7 +1167,7 @@ fn Token tokenize(Module* module) .id = id, }; } break; - case '#': + case '@': { module->offset += 1; if (is_identifier_start(module->content[module->offset])) @@ -2631,7 +2631,7 @@ fn Statement* parse_statement(Module* module, Scope* scope) statement->local = local; statement->id = StatementId::local; } break; - case '#': + case '@': { statement->expression = parse_value(module, scope, {}); statement->id = StatementId::expression; diff --git a/tests/abi_enum_bool.bbb b/tests/abi_enum_bool.bbb deleted file mode 100644 index 56999dc..0000000 --- a/tests/abi_enum_bool.bbb +++ /dev/null @@ -1,36 +0,0 @@ -Foo = enum { - a, - b, - c, - d, - e, - f, - g, -} - -S = struct -{ - enum: Foo, - some_boolean: u1, -} - -require = fn (ok: u1) void -{ - if (!ok) - { - #trap(); - } -} - -[export] main = fn [cc(c)] () s32 -{ - >s: S = { - .enum = .f, - .some_boolean = 1, - }; - - require(s.enum == .f); - require(s.some_boolean); - - return 0; -} diff --git a/tests/argv.bbb b/tests/argv.bbb deleted file mode 100644 index 690c97a..0000000 --- a/tests/argv.bbb +++ /dev/null @@ -1,13 +0,0 @@ -[export] main = fn [cc(c)] (argument_count: u32, argument_pointer: &&u8) s32 -{ - if (argument_count != 1) - { - return 1; - } - >arg = argument_pointer[0]; - if (arg != argument_pointer[0]) - { - return 1; - } - return 0; -} diff --git a/tests/assignment_operators.bbb b/tests/assignment_operators.bbb deleted file mode 100644 index b72d2dd..0000000 --- a/tests/assignment_operators.bbb +++ /dev/null @@ -1,35 +0,0 @@ -unsigned = fn(n: s32) s32 -{ - >result: u32 = #extend(n); - result >>= 1; - result <<= 1; - result ^= 1; - result |= 1; - result &= 1; - result += 1; - result -= 1; - result /= 1; - result %= 1; - result *= 0; - - return #extend(result); -} - -[export] main = fn [cc(c)] () s32 -{ - >result: s32 = 0; - >pointer = &result; - pointer -= 1; - pointer += 1; - result >>= 1; - result <<= 1; - result ^= 1; - result |= 1; - result &= 1; - result += 1; - result -= 1; - result /= 1; - result %= 1; - result *= 0; - return unsigned(result); -} diff --git a/tests/basic_array.bbb b/tests/basic_array.bbb deleted file mode 100644 index a496845..0000000 --- a/tests/basic_array.bbb +++ /dev/null @@ -1,5 +0,0 @@ -[export] main = fn [cc(c)] () s32 -{ - >array: [_]s32 = [3, 2, 1, 0]; - return array[3]; -} diff --git a/tests/basic_bool_call.bbb b/tests/basic_bool_call.bbb deleted file mode 100644 index 7b9b28d..0000000 --- a/tests/basic_bool_call.bbb +++ /dev/null @@ -1,16 +0,0 @@ -require = fn (ok: u1) void -{ - if (!ok) #trap(); -} - -bb_bool = fn (x: u8) void -{ - require(#truncate(x)); -} - -[export] main = fn [cc(c)] () s32 -{ - bb_bool(1); - return 0; -} - diff --git a/tests/basic_branch.bbb b/tests/basic_branch.bbb deleted file mode 100644 index 788d962..0000000 --- a/tests/basic_branch.bbb +++ /dev/null @@ -1,12 +0,0 @@ -[export] main = fn [cc(c)] () s32 -{ - >result: s32 = 1; - if (result != 1) - { - return 1; - } - else - { - return 0; - } -} diff --git a/tests/basic_call.bbb b/tests/basic_call.bbb deleted file mode 100644 index 0e60991..0000000 --- a/tests/basic_call.bbb +++ /dev/null @@ -1,9 +0,0 @@ -foo = fn() s32 -{ - return 0; -} - -[export] main = fn[cc(c)] () s32 -{ - return foo(); -} diff --git a/tests/basic_enum.bbb b/tests/basic_enum.bbb deleted file mode 100644 index a83edab..0000000 --- a/tests/basic_enum.bbb +++ /dev/null @@ -1,18 +0,0 @@ -E = enum -{ - zero = 0, - one = 1, - two = 2, - three = 3, -} - -[export] main = fn [cc(c)] () s32 -{ - >a: E = .three; - >b: E = .two; - >c: E = .one; - >a_int: s32 = #extend(#int_from_enum(a)); - >b_int: s32 = #extend(#int_from_enum(b)); - >c_int: s32 = #extend(#int_from_enum(c)); - return a_int - (b_int + c_int); -} diff --git a/tests/basic_macro.bbb b/tests/basic_macro.bbb deleted file mode 100644 index 4ddfb9a..0000000 --- a/tests/basic_macro.bbb +++ /dev/null @@ -1,11 +0,0 @@ -sub = macro (a: s32, b: s32) s32 -{ - return a - b; -} - -[export] main = fn [cc(c)] () s32 -{ - >a = sub(1, 1); - >b = sub(2, 2); - return a + b; -} diff --git a/tests/basic_pointer.bbb b/tests/basic_pointer.bbb deleted file mode 100644 index 5b6591c..0000000 --- a/tests/basic_pointer.bbb +++ /dev/null @@ -1,6 +0,0 @@ -[export] main = fn [cc(c)] () s32 -{ - >a: s32 = 0; - >pointer = &a; - return pointer.&; -} diff --git a/tests/basic_shortcircuiting_if.bbb b/tests/basic_shortcircuiting_if.bbb deleted file mode 100644 index c938530..0000000 --- a/tests/basic_shortcircuiting_if.bbb +++ /dev/null @@ -1,12 +0,0 @@ -[export] main = fn [cc(c)] (argument_count: u32) s32 -{ - >a: s32 = 0; - if (argument_count != 3 and? argument_count != 2) - { - return 0; - } - else - { - return 1; - } -} diff --git a/tests/basic_slice.bbb b/tests/basic_slice.bbb deleted file mode 100644 index 8de1662..0000000 --- a/tests/basic_slice.bbb +++ /dev/null @@ -1,22 +0,0 @@ -require = fn (ok: u1) void -{ - if (!ok) - { - #trap(); - } -} - -slice_receiver = fn (slice: []u8) void -{ - require(slice.length == 3); - require(slice[0] == 0); - require(slice[1] == 1); - require(slice[2] == 2); -} - -[export] main = fn [cc(c)] () s32 -{ - >a: [_]u8 = [0, 1, 2]; - slice_receiver(a[..]); - return 0; -} diff --git a/tests/basic_string.bbb b/tests/basic_string.bbb deleted file mode 100644 index 1d40df7..0000000 --- a/tests/basic_string.bbb +++ /dev/null @@ -1,16 +0,0 @@ -require = fn (ok: u1) void -{ - if (!ok) - { - #trap(); - } -} - -[export] main = fn [cc(c)] () s32 -{ - >string = "abc"; - require(string[0] == 'a'); - require(string[1] == 'b'); - require(string[2] == 'c'); - return 0; -} diff --git a/tests/basic_struct_passing.bbb b/tests/basic_struct_passing.bbb deleted file mode 100644 index 37bc6d1..0000000 --- a/tests/basic_struct_passing.bbb +++ /dev/null @@ -1,140 +0,0 @@ -CallingConvention = enum -{ - c, -} - -InlineBehavior = enum -{ - default = 0, - always_inline = 1, - no_inline = 2, - inline_hint = 3, -} - -FunctionAttributes = struct -{ - inline_behavior: InlineBehavior, - naked: u1, -} - -Type = struct; - -TypeId = enum -{ - void, - noreturn, - forward_declaration, - integer, - function, - pointer, - array, - enum, - struct, - bits, - alias, - union, - unresolved, - vector, - floating_point, - enum_array, - opaque, -} - -TypeInteger = struct -{ - bit_count: u32, - signed: u1, -} - -TypePointer = struct -{ - element_type: &Type, - next: &Type, -} - -AbiRegisterCountSystemV = struct -{ - gpr: u32, - sse: u32, -}; - -AbiRegisterCount = union -{ - system_v: AbiRegisterCountSystemV, -}; - -AbiInformation = struct -{ - foo: u32, -} - -TypeFunction = struct -{ - semantic_return_type: &Type, - semantic_argument_types: []&Type, - calling_convention: CallingConvention, - is_variable_arguments: u1, - - abi_argument_types: []&Type, - abi_return_type: &Type, - available_registers: AbiRegisterCount, - argument_abis: []AbiInformation, - return_abi: AbiInformation, -} - -TypeContent = union -{ - integer: TypeInteger, - function: TypeFunction, - pointer: TypePointer, -} - -Type = struct -{ - content: TypeContent, - id: TypeId, - name: []u8, - next: &Type, -} - -give_me_string = fn () []u8 -{ - return "foooo"; -} - -get_type = fn (src: &Type, type: Type) &Type -{ - src.& = type; - return src; -} - -require = fn (ok: u1) void -{ - if (!ok) #trap(); -} - -[export] main = fn [cc(c)] () s32 -{ - >buffer: Type = undefined; - >pointer = &buffer; - require(pointer == &buffer); - require(pointer != zero); - >result = get_type(pointer, { - .content = { - .pointer = { - .element_type = pointer, - zero, - }, - }, - .id = .pointer, - .name = give_me_string(), - zero, - }); - - require(pointer != zero); - require(pointer == &buffer); - require(buffer.content.pointer.element_type == pointer); - require(buffer.id == .pointer); - - return 0; -} diff --git a/tests/basic_switch.bbb b/tests/basic_switch.bbb deleted file mode 100644 index 075439e..0000000 --- a/tests/basic_switch.bbb +++ /dev/null @@ -1,26 +0,0 @@ -E = enum -{ - a, - b, - c, -} - -[export] main = fn [cc(c)] () s32 -{ - >some_enum: E = .a; - switch (some_enum) - { - .a => - { - return 0; - }, - .b => - { - return 1; - }, - .c => - { - return 1; - }, - } -} diff --git a/tests/basic_union.bbb b/tests/basic_union.bbb deleted file mode 100644 index ff33f7c..0000000 --- a/tests/basic_union.bbb +++ /dev/null @@ -1,15 +0,0 @@ -U = union -{ - s: s32, - u: u32, -} - -[export] main = fn [cc(c)] () s32 -{ - >my_union: U = { - .s = -1, - }; - if (my_union.s != -1) #trap(); - if (my_union.u != 0xffffffff) #trap(); - return 0; -} diff --git a/tests/basic_varargs.bbb b/tests/basic_varargs.bbb deleted file mode 100644 index b51087c..0000000 --- a/tests/basic_varargs.bbb +++ /dev/null @@ -1,29 +0,0 @@ -va_arg_fn = fn [cc(c)] (first_arg: u32, ...) void -{ - if (first_arg != 123456789) - { - #trap(); - } - - >va = #va_start(); - - >a = #va_arg(&va, u32); - if (a != 987654321) - { - #trap(); - } - - >first_arg_b = #va_arg(&va, u32); - if (first_arg_b != 123456789) - { - #trap(); - } -} - -[export] main = fn [cc(c)] () s32 -{ - >first_arg: u32 = 123456789; - >a: u32 = 987654321; - va_arg_fn(first_arg, a, first_arg); - return 0; -} diff --git a/tests/basic_while.bbb b/tests/basic_while.bbb deleted file mode 100644 index 70d877e..0000000 --- a/tests/basic_while.bbb +++ /dev/null @@ -1,38 +0,0 @@ -c_string_length = fn (c_string: &u8) u64 -{ - >it = c_string; - - while (it.&) - { - it = it + 1; - } - - return #int_from_pointer(it) - #int_from_pointer(c_string); -} - -[export] main = fn (argument_count: u32, argument_pointer: &&u8) s32 -{ - if (argument_count == 0) - { - return 1; - } - - >first_arg = argument_pointer[0]; - if (!first_arg) - { - return 1; - } - - >arg_length = c_string_length(first_arg); - if (arg_length == 0) - { - return 1; - } - - if (first_arg[arg_length] != 0) - { - return 1; - } - - return 0; -} diff --git a/tests/bits.bbb b/tests/bits.bbb deleted file mode 100644 index 5048119..0000000 --- a/tests/bits.bbb +++ /dev/null @@ -1,18 +0,0 @@ -BitField = bits u8 -{ - a: u2, - b: u2, - c: u2, - d: u2, -}; - -[export] main = fn [cc(c)] () s32 -{ - >b: BitField = { - .a = 3, - .b = 2, - .c = 2, - .d = 3, - }; - return #extend((b.a - b.d) + (b.b - b.c)); -} diff --git a/tests/bits_no_backing_type.bbb b/tests/bits_no_backing_type.bbb deleted file mode 100644 index 7dea283..0000000 --- a/tests/bits_no_backing_type.bbb +++ /dev/null @@ -1,13 +0,0 @@ -A = bits { - a: u1, - b: u1, -} - -[export] main = fn [cc(c)] () s32 -{ - >a: A = { - .a = 1, - .b = 1, - }; - return #extend(a.a - a.b); -} diff --git a/tests/bits_return_u1.bbb b/tests/bits_return_u1.bbb deleted file mode 100644 index af251ce..0000000 --- a/tests/bits_return_u1.bbb +++ /dev/null @@ -1,17 +0,0 @@ -S = bits u32 -{ - a: u1, - b: u1, - c: u1, -} - -foo = fn () u1 -{ - >a: S = { .a = 1, .b = 1, .c = 0 }; - return a.c; -} - -[export] main = fn [cc(c)] () s32 -{ - return #extend(foo() == 1); -} diff --git a/tests/bits_zero.bbb b/tests/bits_zero.bbb deleted file mode 100644 index d6169b4..0000000 --- a/tests/bits_zero.bbb +++ /dev/null @@ -1,35 +0,0 @@ -require = fn (ok: u1) void -{ - if (!ok) - { - #trap(); - } -} - -S = bits -{ - a: u1, - b: u1, - c: u1, -} - -[export] main = fn () s32 -{ - >a: S = zero; - - require(a.a == 0); - require(a.b == 0); - require(a.c == 0); - - >b: S = { - .a = 1, - .b = 1, - zero, - }; - - require(b.a == 1); - require(b.b == 1); - require(b.c == 0); - - return 0; -} diff --git a/tests/bool_array.bbb b/tests/bool_array.bbb deleted file mode 100644 index 3b02e41..0000000 --- a/tests/bool_array.bbb +++ /dev/null @@ -1,12 +0,0 @@ -[export] main = fn [cc(c)] () s32 -{ - >signs: [2]u1 = [0, 0]; - >accumulator: s32 = 0; - - for (s: signs) - { - accumulator += #extend(s); - } - - return accumulator; -} diff --git a/tests/bool_pair.bbb b/tests/bool_pair.bbb deleted file mode 100644 index 13eed46..0000000 --- a/tests/bool_pair.bbb +++ /dev/null @@ -1,18 +0,0 @@ -BoolPair = struct -{ - a: u1, - b: u1, -} - -bool_pair = fn () BoolPair -{ - return { .a = 0, .b = 1 }; -} - -[export] main = fn [cc(c)] () s32 -{ - >result = bool_pair(); - if (result.a) #trap(); - if (!result.b) #trap(); - return 0; -} diff --git a/tests/break_continue.bbb b/tests/break_continue.bbb deleted file mode 100644 index 07bf915..0000000 --- a/tests/break_continue.bbb +++ /dev/null @@ -1,31 +0,0 @@ -[export] main = fn [cc(c)] () s32 -{ - >a: s32 = 0; - - while (a < 10) - { - if (a == 3) - { - break; - } - - a += 1; - continue; - } - - >b: s32 = 2; - for (i: 0..10) - { - if (b == 2) - { - b += 1; - continue; - } - else - { - break; - } - } - - return a - b; -} diff --git a/tests/byte_size.bbb b/tests/byte_size.bbb deleted file mode 100644 index a07d92f..0000000 --- a/tests/byte_size.bbb +++ /dev/null @@ -1,6 +0,0 @@ -[export] main = fn [cc(c)] () s32 -{ - >a: s32 = #byte_size(s32); - >b: s32 = #byte_size(s32); - return a - b; -} diff --git a/tests/c_abi.bbb b/tests/c_abi.bbb deleted file mode 100644 index 261128c..0000000 --- a/tests/c_abi.bbb +++ /dev/null @@ -1,539 +0,0 @@ -Struct_u64_u64 = struct -{ - a: u64, - b: u64, -} - -BigStruct = struct -{ - a: u64, - b: u64, - c: u64, - d: u64, - e: u8, -} - -SmallPackedStruct = bits u8 -{ - a: u2, - b: u2, - c: u2, - d: u2, -} - -SmallStructInts = struct -{ - a: u8, - b: u8, - c: u8, - d: u8, -} - -SplitStructInt = struct -{ - a: u64, - b: u8, - c: u32, -} - -MedStructInts = struct -{ - x: s32, - y: s32, - z: s32, -} - -Rect = struct -{ - left: u32, - right: u32, - top: u32, - bottom: u32, -} - -StructWithArray = struct -{ - a: s32, - padding: [4]u8, - b: s64, -} - -ByRef = struct -{ - val: s32, - arr: [15]s32, -} - -ByValOrigin = struct -{ - x: u64, - y: u64, - z: u64, -} - -ByValSize = struct -{ - width: u64, - height: u64, - depth: u64, -} - -ByVal = struct -{ - origin: ByValOrigin, - size: ByValSize, -} - -[extern] run_c_tests = fn [cc(c)] () void; - -[extern] c_u8 = fn [cc(c)] (x: u8) void; -[extern] c_u16 = fn [cc(c)] (x: u16) void; -[extern] c_u32 = fn [cc(c)] (x: u32) void; -[extern] c_u64 = fn [cc(c)] (x: u64) void; - -[extern] c_s8 = fn [cc(c)] (x: s8) void; -[extern] c_s16 = fn [cc(c)] (x: s16) void; -[extern] c_s32 = fn [cc(c)] (x: s32) void; -[extern] c_s64 = fn [cc(c)] (x: s64) void; - -[extern] c_bool = fn [cc(c)] (x: u8) void; - -[extern] c_five_integers = fn [cc(c)] (a: s32, b: s32, c: s32, d: s32, e: s32) void; -[extern] c_ret_struct_u64_u64 = fn [cc(c)] () Struct_u64_u64; - -[extern] c_struct_u64_u64_0 = fn [cc(c)] (a: Struct_u64_u64) void; -[extern] c_struct_u64_u64_1 = fn [cc(c)] (a: u64, b: Struct_u64_u64) void; -[extern] c_struct_u64_u64_2 = fn [cc(c)] (a: u64, b: u64, c: Struct_u64_u64) void; -[extern] c_struct_u64_u64_3 = fn [cc(c)] (a: u64, b: u64, c: u64, d: Struct_u64_u64) void; -[extern] c_struct_u64_u64_4 = fn [cc(c)] (a: u64, b: u64, c: u64, d: u64, e: Struct_u64_u64) void; -[extern] c_struct_u64_u64_5 = fn [cc(c)] (a: u64, b: u64, c: u64, d: u64, e: u64, f: Struct_u64_u64) void; -[extern] c_struct_u64_u64_6 = fn [cc(c)] (a: u64, b: u64, c: u64, d: u64, e: u64, f: u64, g: Struct_u64_u64) void; -[extern] c_struct_u64_u64_7 = fn [cc(c)] (a: u64, b: u64, c: u64, d: u64, e: u64, f: u64, g: u64, h: Struct_u64_u64) void; -[extern] c_struct_u64_u64_8 = fn [cc(c)] (a: u64, b: u64, c: u64, d: u64, e: u64, f: u64, g: u64, h: u64, i: Struct_u64_u64) void; - -[extern] c_big_struct = fn [cc(c)] (x: BigStruct) void; -[extern] c_small_struct_ints = fn [cc(c)] (x: SmallStructInts) void; -[extern] c_ret_small_struct_ints = fn [cc(c)] () SmallStructInts; -[extern] c_med_struct_ints = fn [cc(c)] (x: MedStructInts) void; -[extern] c_ret_med_struct_ints = fn [cc(c)] () MedStructInts; -[extern] c_small_packed_struct = fn [cc(c)] (x: SmallPackedStruct) void; -[extern] c_ret_small_packed_struct = fn [cc(c)] () SmallPackedStruct; -[extern] c_split_struct_ints = fn [cc(c)] (x: SplitStructInt) void; -[extern] c_big_struct_both = fn [cc(c)] (x: BigStruct) BigStruct; -[extern] c_multiple_struct_ints = fn [cc(c)] (a: Rect, b: Rect) void; - -[extern] c_ret_bool = fn [cc(c)] () u8; - -[extern] c_ret_u8 = fn [cc(c)] () u8; -[extern] c_ret_u16 = fn [cc(c)] () u16; -[extern] c_ret_u32 = fn [cc(c)] () u32; -[extern] c_ret_u64 = fn [cc(c)] () u64; - -[extern] c_ret_s8 = fn [cc(c)] () s8; -[extern] c_ret_s16 = fn [cc(c)] () s16; -[extern] c_ret_s32 = fn [cc(c)] () s32; -[extern] c_ret_s64 = fn [cc(c)] () s64; - -[extern] c_struct_with_array = fn [cc(c)] (x: StructWithArray) void; -[extern] c_ret_struct_with_array = fn [cc(c)] () StructWithArray; - -[extern] c_modify_by_ref_param = fn [cc(c)] (x: ByRef) ByRef; -[extern] c_func_ptr_byval = fn [cc(c)] (a: u64, b: u64, c: ByVal, d: u64, e: u64, f: u64) void; - -require = fn (ok: u1) void -{ - if (!ok) - { - #trap(); - } -} - -[export] main = fn [cc(c)] () s32 -{ - run_c_tests(); - c_u8(0xff); - c_u16(0xfffe); - c_u32(0xfffffffd); - c_u64(0xfffffffffffffffc); - - //if (has_i128) { - // c_struct_u128({ .value = 0xfffffffffffffffc, }); - //} - - c_s8(-1); - c_s16(-2); - c_s32(-3); - c_s64(-4); - - //if (has_i128) { - // c_struct_i128({ .value = -6, }); - //} - - c_bool(1); - - c_five_integers(12, 34, 56, 78, 90); - - >s = c_ret_struct_u64_u64(); - require(s.a == 21); - require(s.b == 22); - c_struct_u64_u64_0({ .a = 23, .b = 24, }); - c_struct_u64_u64_1(0, { .a = 25, .b = 26, }); - c_struct_u64_u64_2(0, 1, { .a = 27, .b = 28, }); - c_struct_u64_u64_3(0, 1, 2, { .a = 29, .b = 30, }); - c_struct_u64_u64_4(0, 1, 2, 3, { .a = 31, .b = 32, }); - c_struct_u64_u64_5(0, 1, 2, 3, 4, { .a = 33, .b = 34, }); - c_struct_u64_u64_6(0, 1, 2, 3, 4, 5, { .a = 35, .b = 36, }); - c_struct_u64_u64_7(0, 1, 2, 3, 4, 5, 6, { .a = 37, .b = 38, }); - c_struct_u64_u64_8(0, 1, 2, 3, 4, 5, 6, 7, { .a = 39, .b = 40, }); - - >big_struct: BigStruct = { - .a = 1, - .b = 2, - .c = 3, - .d = 4, - .e = 5, - }; - c_big_struct(big_struct); - - >small: SmallStructInts = { - .a = 1, - .b = 2, - .c = 3, - .d = 4, - }; - c_small_struct_ints(small); - >small2 = c_ret_small_struct_ints(); - require(small2.a == 1); - require(small2.b == 2); - require(small2.c == 3); - require(small2.d == 4); - - >med: MedStructInts = { - .x = 1, - .y = 2, - .z = 3, - }; - c_med_struct_ints(med); - >med2 = c_ret_med_struct_ints(); - require(med2.x == 1); - require(med2.y == 2); - require(med2.z == 3); - - >p: SmallPackedStruct = { .a = 0, .b = 1, .c = 2, .d = 3, }; - c_small_packed_struct(p); - >p2 = c_ret_small_packed_struct(); - require(p2.a == 0); - require(p2.b == 1); - require(p2.c == 2); - require(p2.d == 3); - - >split: SplitStructInt = { - .a = 1234, - .b = 100, - .c = 1337, - }; - c_split_struct_ints(split); - - > big: BigStruct = { - .a = 1, - .b = 2, - .c = 3, - .d = 4, - .e = 5, - }; - >big2 = c_big_struct_both(big); - require(big2.a == 10); - require(big2.b == 11); - require(big2.c == 12); - require(big2.d == 13); - require(big2.e == 14); - - >r1: Rect = { - .left = 1, - .right = 21, - .top = 16, - .bottom = 4, - }; - >r2: Rect = { - .left = 178, - .right = 189, - .top = 21, - .bottom = 15, - }; - c_multiple_struct_ints(r1, r2); - - require(c_ret_bool() == 1); - - require(c_ret_u8() == 0xff); - require(c_ret_u16() == 0xffff); - require(c_ret_u32() == 0xffffffff); - require(c_ret_u64() == 0xffffffffffffffff); - - require(c_ret_s8() == -1); - require(c_ret_s16() == -1); - require(c_ret_s32() == -1); - require(c_ret_s64() == -1); - - c_struct_with_array({ .a = 1, .padding = [0, 0, 0, 0], .b = 2, }); - - >x = c_ret_struct_with_array(); - require(x.a == 4); - require(x.b == 155); - - >res = c_modify_by_ref_param({ .val = 1, .arr = [ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 ] }); - require(res.val == 42); - - >function_pointer = &c_func_ptr_byval; - function_pointer(1, 2, { .origin = { .x = 9, .y = 10, .z = 11, }, .size = { .width = 12, .height = 13, .depth = 14, }, }, 3, 4, 5); - return 0; -} - -[export] bb_u8 = fn [cc(c)] (x: u8) void -{ - require(x == 0xff); -} - -[export] bb_u16 = fn [cc(c)] (x: u16) void -{ - require(x == 0xfffe); -} - -[export] bb_u32 = fn [cc(c)] (x: u32) void -{ - require(x == 0xfffffffd); -} - -[export] bb_u64 = fn [cc(c)] (x: u64) void -{ - require(x == 0xfffffffffffffffc); -} - -[export] bb_s8 = fn [cc(c)] (x: s8) void -{ - require(x == -1); -} - -[export] bb_s16 = fn [cc(c)] (x: s16) void -{ - require(x == -2); -} - -[export] bb_s32 = fn [cc(c)] (x: s32) void -{ - require(x == -3); -} - -[export] bb_s64 = fn [cc(c)] (x: s64) void -{ - require(x == -4); -} - -[export] bb_ptr = fn [cc(c)] (x: &u8) void -{ - require(#int_from_pointer(x) == 0xdeadbeef); -} - -[export] bb_five_integers = fn [cc(c)] (a: s32, b: s32, c: s32, d: s32, e: s32) void -{ - require(a == 12); - require(b == 34); - require(c == 56); - require(d == 78); - require(e == 90); -} - -[export] bb_bool = fn [cc(c)] (x: u8) void -{ - require(#truncate(x)); -} - -[export] bb_ret_struct_u64_u64 = fn [cc(c)] () Struct_u64_u64 -{ - return { .a = 1, .b = 2, }; -} - -[export] bb_struct_u64_u64_0 = fn [cc(c)] (s: Struct_u64_u64) void -{ - require(s.a == 3); - require(s.b == 4); -} - -[export] bb_struct_u64_u64_1 = fn [cc(c)] (_: u64, s: Struct_u64_u64) void -{ - require(s.a == 5); - require(s.b == 6); -} - -[export] bb_struct_u64_u64_2 = fn [cc(c)] (_: u64, _: u64, s: Struct_u64_u64) void -{ - require(s.a == 7); - require(s.b == 8); -} - -[export] bb_struct_u64_u64_3 = fn [cc(c)] (_: u64, _: u64, _: u64, s: Struct_u64_u64) void -{ - require(s.a == 9); - require(s.b == 10); -} - -[export] bb_struct_u64_u64_4 = fn [cc(c)] (_: u64, _: u64, _: u64, _: u64, s: Struct_u64_u64) void -{ - require(s.a == 11); - require(s.b == 12); -} - -[export] bb_struct_u64_u64_5 = fn [cc(c)] (_: u64, _: u64, _: u64, _: u64, _: u64, s: Struct_u64_u64) void -{ - require(s.a == 13); - require(s.b == 14); -} - -[export] bb_struct_u64_u64_6 = fn [cc(c)] (_: u64, _: u64, _: u64, _: u64, _: u64, _: u64, s: Struct_u64_u64) void -{ - require(s.a == 15); - require(s.b == 16); -} - -[export] bb_struct_u64_u64_7 = fn [cc(c)] (_: u64, _: u64, _: u64, _: u64, _: u64, _: u64, _: u64, s: Struct_u64_u64) void -{ - require(s.a == 17); - require(s.b == 18); -} - -[export] bb_struct_u64_u64_8 = fn [cc(c)] (_: u64, _: u64, _: u64, _: u64, _: u64, _: u64, _: u64, _: u64, s: Struct_u64_u64) void -{ - require(s.a == 19); - require(s.b == 20); -} - -[export] bb_big_struct = fn [cc(c)] (x: BigStruct) void -{ - require(x.a == 1); - require(x.b == 2); - require(x.c == 3); - require(x.d == 4); - require(x.e == 5); -} - -[export] bb_small_packed_struct = fn [cc(c)] (x: SmallPackedStruct) void -{ - require(x.a == 0); - require(x.b == 1); - require(x.c == 2); - require(x.d == 3); -} - -[export] bb_split_struct_ints = fn [cc(c)] (x: SplitStructInt) void -{ - require(x.a == 1234); - require(x.b == 100); - require(x.c == 1337); -} - -[export] bb_big_struct_both = fn [cc(c)] (x: BigStruct) BigStruct -{ - require(x.a == 30); - require(x.b == 31); - require(x.c == 32); - require(x.d == 33); - require(x.e == 34); - >s: BigStruct = { - .a = 20, - .b = 21, - .c = 22, - .d = 23, - .e = 24, - }; - return s; -} - -[export] bb_ret_bool = fn [cc(c)] () u8 -{ - return 1; -} - -[export] bb_ret_u8 = fn [cc(c)] () u8 -{ - return 0xff; -} - -[export] bb_ret_u16 = fn [cc(c)] () u16 -{ - return 0xffff; -} - -[export] bb_ret_u32 = fn [cc(c)] () u32 -{ - return 0xffffffff; -} - -[export] bb_ret_u64 = fn [cc(c)] () u64 -{ - return 0xffffffffffffffff; -} - -[export] bb_ret_s8 = fn [cc(c)] () s8 -{ - return -1; -} - -[export] bb_ret_s16 = fn [cc(c)] () s16 -{ - return -1; -} - -[export] bb_ret_s32 = fn [cc(c)] () s32 -{ - return -1; -} - -[export] bb_ret_s64 = fn [cc(c)] () s64 -{ - return -1; -} - -[export] bb_ret_small_struct_ints = fn [cc(c)] () SmallStructInts -{ - return { - .a = 1, - .b = 2, - .c = 3, - .d = 4, - }; -} - -[export] bb_ret_med_struct_ints = fn [cc(c)] () MedStructInts -{ - return { - .x = 1, - .y = 2, - .z = 3, - }; -} - -[export] bb_multiple_struct_ints = fn [cc(c)] (x: Rect, y: Rect) void -{ - require(x.left == 1); - require(x.right == 21); - require(x.top == 16); - require(x.bottom == 4); - require(y.left == 178); - require(y.right == 189); - require(y.top == 21); - require(y.bottom == 15); -} - -[export] bb_small_struct_ints = fn [cc(c)] (x: SmallStructInts) void -{ - require(x.a == 1); - require(x.b == 2); - require(x.c == 3); - require(x.d == 4); -} - -[export] bb_med_struct_ints = fn [cc(c)] (s: MedStructInts) void -{ - require(s.x == 1); - require(s.y == 2); - require(s.z == 3); -} diff --git a/tests/c_abi0.bbb b/tests/c_abi0.bbb deleted file mode 100644 index 6c5162d..0000000 --- a/tests/c_abi0.bbb +++ /dev/null @@ -1,20 +0,0 @@ -require = fn (ok: u1) void -{ - if (!ok) - { - #trap(); - } -} - -c_u8 = fn [cc(c)] (x: u8) void -{ - require(x == 0xff); -} - -[export] main = fn [cc(c)] () s32 -{ - >v: u8 = 0xff; - c_u8(v); - return 0; -} - diff --git a/tests/c_abi1.bbb b/tests/c_abi1.bbb deleted file mode 100644 index 6f41eee..0000000 --- a/tests/c_abi1.bbb +++ /dev/null @@ -1,18 +0,0 @@ -require = fn(ok: u1) void -{ - if (!ok) - { - #trap(); - } -} - -c_u16 = fn [cc(c)] (v: u16) void -{ - require(v == 0xfffe); -} - -[export] main = fn [cc(c)] () s32 -{ - c_u16(0xfffe); - return 0; -} diff --git a/tests/c_function_pointer.bbb b/tests/c_function_pointer.bbb deleted file mode 100644 index 6e6911b..0000000 --- a/tests/c_function_pointer.bbb +++ /dev/null @@ -1,7 +0,0 @@ -[extern] exit = fn [cc(c)] (exit_code: s32) noreturn; - -[export] main = fn [cc(c)] () s32 -{ - >c_function_pointer = &exit; - c_function_pointer(0); -} diff --git a/tests/c_med_struct_ints.bbb b/tests/c_med_struct_ints.bbb deleted file mode 100644 index 01e366b..0000000 --- a/tests/c_med_struct_ints.bbb +++ /dev/null @@ -1,51 +0,0 @@ -require = fn (ok: u1) void -{ - if (!ok) - { - #trap(); - } -} -MedStructInts = struct -{ - x: s32, - y: s32, - z: s32, -} - -bb_ret_med_struct_ints = fn [cc(c)] () MedStructInts -{ - return { - .x = 1, - .y = 2, - .z = 3, - }; -} - -c_med_struct_ints = fn [cc(c)] (s: MedStructInts) void -{ - require(s.x == 1); - require(s.y == 2); - require(s.z == 3); - - >s2 = bb_ret_med_struct_ints(); - - require(s2.x == 1); - require(s2.y == 2); - require(s2.z == 3); -} - -[export] main = fn [cc(c)] () s32 -{ - >med: MedStructInts = { - .x = 1, - .y = 2, - .z = 3, - }; - c_med_struct_ints(med); - >med2 = bb_ret_med_struct_ints(); - require(med2.x == 1); - require(med2.y == 2); - require(med2.z == 3); - - return 0; -} diff --git a/tests/c_ret_struct_array.bbb b/tests/c_ret_struct_array.bbb deleted file mode 100644 index 2707d0d..0000000 --- a/tests/c_ret_struct_array.bbb +++ /dev/null @@ -1,27 +0,0 @@ -StructWithArray = struct -{ - a: u32, - padding: [4]u8, - c: u64, -}; - -c_ret_struct_with_array = fn [cc(c)] () StructWithArray -{ - return { .a = 4, .padding = [ 0, 0, 0, 0 ], .c = 155 }; -} - -require = fn(ok: u1) void -{ - if (!ok) - { - #trap(); - } -} - -[export] main = fn [cc(c)] () s32 -{ - >s = c_ret_struct_with_array(); - require(s.a == 4); - require(s.c == 155); - return 0; -} diff --git a/tests/c_split_struct_ints.bbb b/tests/c_split_struct_ints.bbb deleted file mode 100644 index 69a62d5..0000000 --- a/tests/c_split_struct_ints.bbb +++ /dev/null @@ -1,36 +0,0 @@ -SplitStructInt = struct -{ - a: u64, - b: u8, - c: u32, -} - -require = fn (ok: u1) void -{ - if (!ok) - { - #trap(); - } -} - -bb_split_struct_ints = fn [cc(c)] (x: SplitStructInt) void -{ - require(x.a == 1234); - require(x.b == 100); - require(x.c == 1337); -} - -[export] main = fn [cc(c)] () s32 -{ - >split: SplitStructInt = { - .a = 1234, - .b = 100, - .c = 1337, - }; - - bb_split_struct_ints(split); - >a: s32 = #truncate(split.a); - >b: s32 = #extend(split.b); - >c: s32 = #extend(split.c); - return a + b + 3 - c; -} diff --git a/tests/c_string_to_slice.bbb b/tests/c_string_to_slice.bbb deleted file mode 100644 index e9d78d2..0000000 --- a/tests/c_string_to_slice.bbb +++ /dev/null @@ -1,33 +0,0 @@ -require = fn (ok: u1) void -{ - if (!ok) - { - #trap(); - } -} - -c_string_length = fn (c_string: &u8) u64 -{ - >it = c_string; - - while (it.&) - { - it = it + 1; - } - - return #int_from_pointer(it) - #int_from_pointer(c_string); -} - -c_string_slice_build = fn (c_string: &u8, length: u64) []u8 -{ - return c_string[0..length]; -} - -[export] main = fn [cc(c)] (argument_count: u32, argument_pointer: &&u8) s32 -{ - >length = c_string_length(argument_pointer[0]); - >string = c_string_slice_build(argument_pointer[0], length); - require(string.pointer == argument_pointer[0]); - require(string.length == length); - return 0; -} diff --git a/tests/c_struct_with_array.bbb b/tests/c_struct_with_array.bbb deleted file mode 100644 index acf4dac..0000000 --- a/tests/c_struct_with_array.bbb +++ /dev/null @@ -1,26 +0,0 @@ -require = fn(ok: u1) void -{ - if (!ok) - { - #trap(); - } -} - -StructWithArray = struct -{ - a: u32, - padding: [4]u8, - b: u64, -} - -c_struct_with_array = fn [cc(c)] (x: StructWithArray) void -{ - require(x.a == 1); - require(x.b == 2); -} - -[export] main = fn [cc(c)] () s32 -{ - c_struct_with_array({ .a = 1, .padding = [0, 0, 0, 0], .b = 2 }); - return 0; -} diff --git a/tests/comments.bbb b/tests/comments.bbb deleted file mode 100644 index e69fc6e..0000000 --- a/tests/comments.bbb +++ /dev/null @@ -1,7 +0,0 @@ -[export] main = fn [cc(c)] () s32 // This is a comment -// This is a comment -{ // This is a comment - // This is a comment - return 0; // This is a comment -}// This is a comment -// This is a comment diff --git a/tests/comparison.bbb b/tests/comparison.bbb deleted file mode 100644 index 4d558c3..0000000 --- a/tests/comparison.bbb +++ /dev/null @@ -1,14 +0,0 @@ -trivial_comparison = fn (a: u32, b: u32) u1 -{ - return a + 1 == b + 1; -} - -[export] main = fn [cc(c)] (argument_count: u32) s32 -{ - >result = trivial_comparison(argument_count, argument_count); - if (!result) - { - #trap(); - } - return 0; -} diff --git a/tests/concat_logical_or.bbb b/tests/concat_logical_or.bbb deleted file mode 100644 index 5b14498..0000000 --- a/tests/concat_logical_or.bbb +++ /dev/null @@ -1,9 +0,0 @@ -is_space = fn (ch: u8) u1 -{ - return ch == ' ' or ch == '\n' or ch == '\t' or ch == '\r'; -} - -[export] main = fn [cc(c)] () s32 -{ - return #extend(is_space('f')); -} diff --git a/tests/constant_add.bbb b/tests/constant_add.bbb deleted file mode 100644 index 5366bca..0000000 --- a/tests/constant_add.bbb +++ /dev/null @@ -1,4 +0,0 @@ -[export] main = fn [cc(c)] () s32 -{ - return -1 + 1; -} diff --git a/tests/constant_and.bbb b/tests/constant_and.bbb deleted file mode 100644 index bc8c00e..0000000 --- a/tests/constant_and.bbb +++ /dev/null @@ -1,4 +0,0 @@ -[export] main = fn [cc(c)] () s32 -{ - return 1 & 2; -} diff --git a/tests/constant_div.bbb b/tests/constant_div.bbb deleted file mode 100644 index 513116f..0000000 --- a/tests/constant_div.bbb +++ /dev/null @@ -1,4 +0,0 @@ -[export] main = fn [cc(c)] () s32 -{ - return 0 / 5; -} diff --git a/tests/constant_global_reference.bbb b/tests/constant_global_reference.bbb deleted file mode 100644 index d0059f6..0000000 --- a/tests/constant_global_reference.bbb +++ /dev/null @@ -1,7 +0,0 @@ -i2315_abc: s32 = 5; -asjdkj = i2315_abc - i2315_abc; - -[export] main = fn [cc(c)] () s32 -{ - return asjdkj; -} diff --git a/tests/constant_mul.bbb b/tests/constant_mul.bbb deleted file mode 100644 index db66565..0000000 --- a/tests/constant_mul.bbb +++ /dev/null @@ -1,4 +0,0 @@ -[export] main = fn [cc(c)] () s32 -{ - return 1 * 0; -} diff --git a/tests/constant_or.bbb b/tests/constant_or.bbb deleted file mode 100644 index 4392873..0000000 --- a/tests/constant_or.bbb +++ /dev/null @@ -1,4 +0,0 @@ -[export] main = fn [cc(c)] () s32 -{ - return 0 | 0; -} diff --git a/tests/constant_rem.bbb b/tests/constant_rem.bbb deleted file mode 100644 index f30b973..0000000 --- a/tests/constant_rem.bbb +++ /dev/null @@ -1,4 +0,0 @@ -[export] main = fn [cc(c)] () s32 -{ - return 5 % 5; -} diff --git a/tests/constant_shift_left.bbb b/tests/constant_shift_left.bbb deleted file mode 100644 index 8a3c197..0000000 --- a/tests/constant_shift_left.bbb +++ /dev/null @@ -1,4 +0,0 @@ -[export] main = fn [cc(c)] () s32 -{ - return 0 << 1; -} diff --git a/tests/constant_shift_right.bbb b/tests/constant_shift_right.bbb deleted file mode 100644 index af22c4b..0000000 --- a/tests/constant_shift_right.bbb +++ /dev/null @@ -1,4 +0,0 @@ -[export] main = fn [cc(c)] () s32 -{ - return 0 >> 1; -} diff --git a/tests/constant_sub.bbb b/tests/constant_sub.bbb deleted file mode 100644 index 458bba9..0000000 --- a/tests/constant_sub.bbb +++ /dev/null @@ -1,5 +0,0 @@ -[export] main = fn [cc(c)] () s32 -{ - return 1 - 1; -} - diff --git a/tests/constant_xor.bbb b/tests/constant_xor.bbb deleted file mode 100644 index 78dbee3..0000000 --- a/tests/constant_xor.bbb +++ /dev/null @@ -1,4 +0,0 @@ -[export] main = fn [cc(c)] () s32 -{ - return 0 ^ 0; -} diff --git a/tests/else_if.bbb b/tests/else_if.bbb deleted file mode 100644 index d56ed61..0000000 --- a/tests/else_if.bbb +++ /dev/null @@ -1,16 +0,0 @@ -[export] main = fn [cc(c)] () s32 -{ - >result: s32 = 0; - if (result == 1) - { - return 1; - } - else if (result == 0) - { - return 0; - } - else - { - return 5; - } -} diff --git a/tests/else_if_complicated.bbb b/tests/else_if_complicated.bbb deleted file mode 100644 index 91585c1..0000000 --- a/tests/else_if_complicated.bbb +++ /dev/null @@ -1,37 +0,0 @@ -Foo = enum -{ - a,b,c, -} - -[export] main = fn [cc(c)] (argument_count: u32) s32 -{ - >result: s32 = 0; - >foo: Foo = .b; - switch (foo) - { - .b => - { - if (argument_count != 0) - { - >a: s32 = 1; - if (result == 1) - { - } - else if (result == 0) - { - return 0; - } - else - { - return 5; - } - return a; - } - }, - else => - { - } - } - - return 0; -} diff --git a/tests/empty_if.bbb b/tests/empty_if.bbb deleted file mode 100644 index 68bb130..0000000 --- a/tests/empty_if.bbb +++ /dev/null @@ -1,12 +0,0 @@ -[export] main = fn [cc(c)] (argument_count: u32) s32 -{ - >result: s32 = 0; - if (argument_count != 1) - { - result = 1; - } - else - { - } - return result; -} diff --git a/tests/enum_arbitrary_abi.bbb b/tests/enum_arbitrary_abi.bbb deleted file mode 100644 index e98d1b7..0000000 --- a/tests/enum_arbitrary_abi.bbb +++ /dev/null @@ -1,22 +0,0 @@ -SomeEnum = enum -{ - a, - b, - c, - d, -} - -foo = fn (arg: SomeEnum) SomeEnum -{ - return arg; -} - -[export] main = fn [cc(c)] () s32 -{ - >some_e: SomeEnum = .c; - >a = foo(some_e); - >b = foo(.d); - if (a != .c) #trap(); - if (b != .d) #trap(); - return 0; -} diff --git a/tests/enum_array.bbb b/tests/enum_array.bbb deleted file mode 100644 index 42a99c8..0000000 --- a/tests/enum_array.bbb +++ /dev/null @@ -1,22 +0,0 @@ -require = fn (ok: u1) void -{ - if (!ok) #trap(); -} - -E = enum -{ - a, - b, - c, - d, -} - -[export] main = fn [cc(c)] () s32 -{ - >some_enum_array: enum_array[E](u32) = [ .a = 4, .b = 3, .c = 2, .d = 1 ]; - require(some_enum_array[.a] == 4); - require(some_enum_array[.b] == 3); - require(some_enum_array[.c] == 2); - require(some_enum_array[.d] == 1); - return 0; -} diff --git a/tests/enum_debug_info.bbb b/tests/enum_debug_info.bbb deleted file mode 100644 index 9fb82ec..0000000 --- a/tests/enum_debug_info.bbb +++ /dev/null @@ -1,38 +0,0 @@ -TypeId = enum -{ - void, - noreturn, - forward_declaration, - integer, - function, - pointer, - array, - enum, - struct, - bits, - alias, - union, - unresolved, - vector, - floating_point, - enum_array, - opaque, -} - -Type = struct -{ - arr: [5]u32, - id: TypeId, - a: [2]u64, - b: u64, -} - -[export] main = fn [cc(c)] () s32 -{ - >t: Type = { - .id = .integer, - zero, - }; - t.arr[0] = 1; - return 0; -} diff --git a/tests/enum_name.bbb b/tests/enum_name.bbb deleted file mode 100644 index 2a03c95..0000000 --- a/tests/enum_name.bbb +++ /dev/null @@ -1,24 +0,0 @@ -E = enum -{ - my_expected_result, - a, - b, -} - -[extern] memcmp = fn [cc(c)] (a: &u8, b: &u8, byte_count: u64) s32; -string_equal = fn (slice_a: []u8, slice_b: []u8) u1 -{ - >result = slice_a.length == slice_b.length; - if (result) - { - result = memcmp(slice_a.pointer, slice_b.pointer, slice_a.length) == 0; - } - - return result; -} - -[export] main = fn [cc(c)] () s32 -{ - >some_enum: E = .my_expected_result; - return #extend(!string_equal(#enum_name(some_enum), "my_expected_result")); -} diff --git a/tests/extend.bbb b/tests/extend.bbb deleted file mode 100644 index 7518732..0000000 --- a/tests/extend.bbb +++ /dev/null @@ -1,5 +0,0 @@ -[export] main = fn [cc(c)] () s32 -{ - >result: s8 = 0; - return #extend(result); -} diff --git a/tests/extern.bbb b/tests/extern.bbb deleted file mode 100644 index 7bcbe8a..0000000 --- a/tests/extern.bbb +++ /dev/null @@ -1,5 +0,0 @@ -[extern] exit = fn [cc(c)] (exit_code: s32) noreturn; -[export] main = fn [cc(c)] () s32 -{ - exit(0); -} diff --git a/tests/field_access_left_assign.bbb b/tests/field_access_left_assign.bbb deleted file mode 100644 index 9f0383e..0000000 --- a/tests/field_access_left_assign.bbb +++ /dev/null @@ -1,24 +0,0 @@ -S = struct -{ - a: u32, - b: u32, -} - -require = fn (ok: u1) void -{ - if (!ok) #trap(); -} - -[export] main = fn [cc(c)] () s32 -{ - >s: S = { - .a = 2, - .b = 3, - }; - - s.a = s.b + 1; - s.b = s.a + 2; - require(s.a == 4); - require(s.b == 6); - return 0; -} diff --git a/tests/field_parent_pointer.bbb b/tests/field_parent_pointer.bbb deleted file mode 100644 index 4e10524..0000000 --- a/tests/field_parent_pointer.bbb +++ /dev/null @@ -1,43 +0,0 @@ -S = struct -{ - a: u8, - b: u32, - c: u8, -} - -assert = fn (ok: u1) void -{ - if (!ok) #trap(); -} - -[export] main = fn [cc(c)] () s32 -{ - >s: S = { - .a = 241, - .b = 12356, - .c = 128, - }; - - >p_a = &s.a; - >p_a_struct: &S = #field_parent_pointer(p_a, "a"); - assert(p_a_struct == &s); - assert(p_a_struct.a == s.a); - assert(p_a_struct.b == s.b); - assert(p_a_struct.c == s.c); - - >p_b = &s.b; - >p_b_struct: &S = #field_parent_pointer(p_b, "b"); - assert(p_b_struct == &s); - assert(p_b_struct.a == s.a); - assert(p_b_struct.b == s.b); - assert(p_b_struct.c == s.c); - - >p_c = &s.c; - >p_c_struct: &S = #field_parent_pointer(p_c, "c"); - assert(p_c_struct == &s); - assert(p_c_struct.a == s.a); - assert(p_c_struct.b == s.b); - assert(p_c_struct.c == s.c); - - return 0; -} diff --git a/tests/for_each.bbb b/tests/for_each.bbb deleted file mode 100644 index c4ed0cd..0000000 --- a/tests/for_each.bbb +++ /dev/null @@ -1,32 +0,0 @@ -require = fn (ok: u1) void -{ - if (!ok) #trap(); -} - -[export] main = fn [cc(c)] () s32 -{ - >array: [_]u32 = [5, 3, 2]; - >counter: u32 = 0; - for (e : array) - { - counter += e; - } - - require(counter == 10); - - for (&e : array) - { - e.& += 1; - } - - >new_counter: u32 = 0; - - for (e : array) - { - new_counter += e; - } - - require(new_counter == counter + array.length); - - return 0; -} diff --git a/tests/for_each_int.bbb b/tests/for_each_int.bbb deleted file mode 100644 index c827a5f..0000000 --- a/tests/for_each_int.bbb +++ /dev/null @@ -1,10 +0,0 @@ -[export] main = fn [cc(c)] () s32 -{ - >top: s32 = 64; - >accumulator: s32 = 0; - for (i: 0..top) - { - accumulator += 1; - } - return accumulator - top; -} diff --git a/tests/forward_declared_type.bbb b/tests/forward_declared_type.bbb deleted file mode 100644 index 967e39e..0000000 --- a/tests/forward_declared_type.bbb +++ /dev/null @@ -1,17 +0,0 @@ -T = struct; -Foo = struct -{ - t: &T, -} - -T = struct -{ - f: Foo, -} - -[export] main = fn [cc(c)] () s32 -{ - >t: T = zero; - t.f.t = &t; - return 0; -} diff --git a/tests/function_pointer.bbb b/tests/function_pointer.bbb deleted file mode 100644 index 8f46be7..0000000 --- a/tests/function_pointer.bbb +++ /dev/null @@ -1,10 +0,0 @@ -foo = fn [cc(c)] () s32 -{ - return 123; -} - -[export] main = fn [cc(c)] () s32 -{ - >fn_ptr = &foo; - return fn_ptr() - 123; -} diff --git a/tests/generic_macro.bbb b/tests/generic_macro.bbb deleted file mode 100644 index 432dbe5..0000000 --- a/tests/generic_macro.bbb +++ /dev/null @@ -1,11 +0,0 @@ -sub = macro [T] (a: T, b: T) T -{ - return a - b; -} - -[export] main = fn [cc(c)] () s32 -{ - >a = sub[s32](1, 1); - >b = sub[u8](2, 2); - return a + #extend(b); -} diff --git a/tests/generic_pointer_array.bbb b/tests/generic_pointer_array.bbb deleted file mode 100644 index 31b9765..0000000 --- a/tests/generic_pointer_array.bbb +++ /dev/null @@ -1,15 +0,0 @@ -foo = macro[T](addr: &u64, count: u64) []T -{ - >pointer: &T = #pointer_cast(addr); - return pointer[..count]; -} - -[export] main = fn [cc(c)] () s32 -{ - >address_raw: u64 = 0xaaaaaaaaaaaaaaaa; - >some_var: &u64 = #pointer_from_int(address_raw); - >result: []&u8 = foo[&u8](some_var, 1); - if (#int_from_pointer(result.pointer) != address_raw) #trap(); - if (result.length != 1) #trap(); - return 0; -} diff --git a/tests/generic_pointer_macro.bbb b/tests/generic_pointer_macro.bbb deleted file mode 100644 index b78d463..0000000 --- a/tests/generic_pointer_macro.bbb +++ /dev/null @@ -1,25 +0,0 @@ -foo = macro [T] (ptr: &u32) &T -{ - return #pointer_cast(ptr); -} - -A = struct -{ - a: u32, -} - -B = struct -{ - b: u32, -} - -[export] main = fn [cc(c)] () s32 -{ - >var: u32 = 0; - >a = foo[A](&var); - >b = foo[B](&var); - a.a = 1; - if (b.b != 1) #trap(); - if (var != 1) #trap(); - return 0; -} diff --git a/tests/global.bbb b/tests/global.bbb deleted file mode 100644 index 1859a25..0000000 --- a/tests/global.bbb +++ /dev/null @@ -1,5 +0,0 @@ -result: s32 = 0; - -[export] main = fn [cc(c)] () s32 { - return result; -} diff --git a/tests/global_struct.bbb b/tests/global_struct.bbb deleted file mode 100644 index adb0454..0000000 --- a/tests/global_struct.bbb +++ /dev/null @@ -1,28 +0,0 @@ -S = struct -{ - a: u32, - b: u32, - c: u32, -} - -s: S = { - .a = 1, - .b = 2, - .c = 3, -}; - -require = fn (ok: u1) void -{ - if (!ok) - { - #trap(); - } -} - -[export] main = fn () s32 -{ - require(s.a == 1); - require(s.b == 2); - require(s.c == 3); - return 0; -} diff --git a/tests/if_no_else.bbb b/tests/if_no_else.bbb deleted file mode 100644 index 8e5d125..0000000 --- a/tests/if_no_else.bbb +++ /dev/null @@ -1,9 +0,0 @@ -[export] main = fn [cc(c)] () s32 -{ - >a: s32 = 5; - if (a == 2) - { - return 1; - } - return 0; -} diff --git a/tests/if_no_else_void.bbb b/tests/if_no_else_void.bbb deleted file mode 100644 index 3875fda..0000000 --- a/tests/if_no_else_void.bbb +++ /dev/null @@ -1,14 +0,0 @@ -require = fn [cc(c)] (ok: u1) void -{ - if (!ok) - { - #trap(); - } -} - -[export] main = fn [cc(c)] () s32 -{ - >result: s32 = 0; - require(result == 0); - return result; -} diff --git a/tests/indirect.bbb b/tests/indirect.bbb deleted file mode 100644 index ff02f67..0000000 --- a/tests/indirect.bbb +++ /dev/null @@ -1,45 +0,0 @@ -require = fn (ok: u1) void -{ - if (!ok) - { - #trap(); - } -} - -S = struct -{ - a: u32, - b: u32, - c: u32, - d: u32, - e: u32, - f: u32, -} - -ret = fn [cc(c)] () S -{ - return { .a = 56, .b = 57, .c = 58, .d = 59, .e = 60, .f = 61 }; -} - -arg = fn [cc(c)] (s: S) void -{ - require(s.a == 56); - require(s.b == 57); - require(s.c == 58); - require(s.d == 59); - require(s.e == 60); - require(s.f == 61); -} - -[export] main = fn [cc(c)] () s32 -{ - >s = ret(); - require(s.a == 56); - require(s.b == 57); - require(s.c == 58); - require(s.d == 59); - require(s.e == 60); - require(s.f == 61); - arg(s); - return 0; -} diff --git a/tests/indirect_struct.bbb b/tests/indirect_struct.bbb deleted file mode 100644 index 8fcc69d..0000000 --- a/tests/indirect_struct.bbb +++ /dev/null @@ -1,46 +0,0 @@ -Struct_u64_u64 = struct -{ - a: u64, - b: u64, -} - -require = fn (ok: u1) void -{ - if (!ok) - { - #trap(); - } -} - -c_struct_u64_u64_5 = fn [cc(c)] (a: u64, b: u64, c: u64, d: u64, e: u64, s: Struct_u64_u64) void -{ - require(s.a == 33); - require(s.b == 34); -} - -c_struct_u64_u64_6 = fn [cc(c)] (a: u64, b: u64, c: u64, d: u64, e: u64, f: u64, s: Struct_u64_u64) void -{ - require(s.a == 35); - require(s.b == 36); -} - -c_struct_u64_u64_7 = fn [cc(c)] (a: u64, b: u64, c: u64, d: u64, e: u64, f: u64, g: u64, s: Struct_u64_u64) void -{ - require(s.a == 37); - require(s.b == 38); -} - -c_struct_u64_u64_8 = fn [cc(c)] (a: u64, b: u64, c: u64, d: u64, e: u64, f: u64, g: u64, h: u64, s: Struct_u64_u64) void -{ - require(s.a == 39); - require(s.b == 40); -} - -[export] main = fn [cc(c)] () s32 -{ - c_struct_u64_u64_5(0, 0, 0, 0, 0, { .a = 33, .b = 34, }); - c_struct_u64_u64_6(0, 0, 0, 0, 0, 0, { .a = 35, .b = 36, }); - c_struct_u64_u64_7(0, 0, 0, 0, 0, 0, 0, { .a = 37, .b = 38, }); - c_struct_u64_u64_8(0, 0, 0, 0, 0, 0, 0, 0, { .a = 39, .b = 40, }); - return 0; -} diff --git a/tests/indirect_varargs.bbb b/tests/indirect_varargs.bbb deleted file mode 100644 index cf78be9..0000000 --- a/tests/indirect_varargs.bbb +++ /dev/null @@ -1,62 +0,0 @@ -S = struct -{ - a: u64, - b: u64, - c: u64, - d: u64, - e: u64 - f: u64, - g: u64, - h: u64, - i: u64, - j: u64 -} - -require = fn (ok: u1) void -{ - if (!ok) - { - #trap(); - } -} - -va_arg_fn = fn [cc(c)] (first_arg: u32, ...) void -{ - if (first_arg != 123456789) - { - #trap(); - } - - >va = #va_start(); - - >s = #va_arg(&va, S); - require(s.a == 9); - require(s.b == 8); - require(s.c == 7); - require(s.d == 6); - require(s.e == 5); - require(s.f == 4); - require(s.g == 3); - require(s.h == 2); - require(s.i == 1); - require(s.j == 0); -} - -[export] main = fn [cc(c)] () s32 -{ - >first_arg: u32 = 123456789; - >s : S = { - .a = 9, - .b = 8, - .c = 7, - .d = 6, - .e = 5, - .f = 4, - .g = 3, - .h = 2, - .i = 1, - .j = 0, - }; - va_arg_fn(first_arg, s); - return 0; -} diff --git a/tests/integer_formats.bbb b/tests/integer_formats.bbb deleted file mode 100644 index 88c6bc1..0000000 --- a/tests/integer_formats.bbb +++ /dev/null @@ -1,7 +0,0 @@ -[export] main = fn [cc(c)] () s32 -{ - >a: s32 = 0o10; - >b: s32 = 0b1000; - >c: s32 = 0d0; - return a - b + c; -} diff --git a/tests/integer_hex.bbb b/tests/integer_hex.bbb deleted file mode 100644 index 8725225..0000000 --- a/tests/integer_hex.bbb +++ /dev/null @@ -1,5 +0,0 @@ -[export] main = fn [cc(c)] () s32 -{ - >result: s32 = 0x0; - return result; -} diff --git a/tests/integer_max.bbb b/tests/integer_max.bbb deleted file mode 100644 index 585cf43..0000000 --- a/tests/integer_max.bbb +++ /dev/null @@ -1,5 +0,0 @@ -[export] main = fn [cc(c)] () s32 -{ - >a = #integer_max(u64); - return #truncate(a + 1); -} diff --git a/tests/leading_trailing_zeroes.bbb b/tests/leading_trailing_zeroes.bbb deleted file mode 100644 index bac6816..0000000 --- a/tests/leading_trailing_zeroes.bbb +++ /dev/null @@ -1,10 +0,0 @@ -[export] main = fn [cc(c)] () s32 -{ - >a: u32 = 0b111; - if (#leading_zeroes(a) != 29) #trap(); - if (#trailing_zeroes(a) != 0) #trap(); - >b: u8 = 0b11010; - if (#leading_zeroes(b) != 3) #trap(); - if (#trailing_zeroes(b) != 1) #trap(); - return 0; -} diff --git a/tests/local_type_inference.bbb b/tests/local_type_inference.bbb deleted file mode 100644 index 68db5e2..0000000 --- a/tests/local_type_inference.bbb +++ /dev/null @@ -1,10 +0,0 @@ -foo = fn() s32 -{ - return 0; -} -[export] main = fn [cc(c)] () s32 -{ - >a: s32 = 0; - >result = foo() + a; - return result; -} diff --git a/tests/min_max.bbb b/tests/min_max.bbb deleted file mode 100644 index 14b3c12..0000000 --- a/tests/min_max.bbb +++ /dev/null @@ -1,10 +0,0 @@ -[export] main = fn [cc(c)] () s32 -{ - >a: u32 = 1; - >b: u32 = 2; - >min = #min(a, b); - >max = #max(a, b); - if (min != a) #trap(); - if (max != b) #trap(); - return 0; -} diff --git a/tests/minimal.bbb b/tests/minimal.bbb deleted file mode 100644 index 774af15..0000000 --- a/tests/minimal.bbb +++ /dev/null @@ -1,5 +0,0 @@ -[export] main = fn [cc(c)] () s32 -{ - return 0; -} - diff --git a/tests/minimal_stack.bbb b/tests/minimal_stack.bbb deleted file mode 100644 index 0525a16..0000000 --- a/tests/minimal_stack.bbb +++ /dev/null @@ -1,5 +0,0 @@ -[export] main = fn [cc(c)] () s32 -{ - >result: s32 = 0; - return result; -} diff --git a/tests/minimal_stack_arithmetic.bbb b/tests/minimal_stack_arithmetic.bbb deleted file mode 100644 index 14df665..0000000 --- a/tests/minimal_stack_arithmetic.bbb +++ /dev/null @@ -1,5 +0,0 @@ -[export] main = fn [cc(c)] () s32 -{ - >a: s32 = 1; - return a - 1; -} diff --git a/tests/minimal_stack_arithmetic2.bbb b/tests/minimal_stack_arithmetic2.bbb deleted file mode 100644 index 4c321bc..0000000 --- a/tests/minimal_stack_arithmetic2.bbb +++ /dev/null @@ -1,6 +0,0 @@ -[export] main = fn [cc(c)] () s32 -{ - >a: s32 = 1; - >b = a - 1; - return b; -} diff --git a/tests/minimal_stack_arithmetic3.bbb b/tests/minimal_stack_arithmetic3.bbb deleted file mode 100644 index c34d0f5..0000000 --- a/tests/minimal_stack_arithmetic3.bbb +++ /dev/null @@ -1,6 +0,0 @@ -[export] main = fn [cc(c)] () s32 -{ - >a: s32 = 1; - >b = 1 - a; - return b; -} diff --git a/tests/noreturn_macro.bbb b/tests/noreturn_macro.bbb deleted file mode 100644 index 0197244..0000000 --- a/tests/noreturn_macro.bbb +++ /dev/null @@ -1,27 +0,0 @@ -assert = macro (ok: u1) void -{ - if (!ok) - { - unreachable; - } -} - -align_forward = fn (value: u64, alignment: u64) u64 -{ - assert(alignment != 0); - >mask = alignment - 1; - >result = (value + mask) & ~mask; - return result; -} - -[export] main = fn [cc(c)] () s32 -{ - >result = align_forward(1, 64); - - if (result != 64) - { - #trap(); - } - - return 0; -} diff --git a/tests/not_pointer.bbb b/tests/not_pointer.bbb deleted file mode 100644 index 10d4d16..0000000 --- a/tests/not_pointer.bbb +++ /dev/null @@ -1,7 +0,0 @@ -[export] main = fn [cc(c)] () s32 -{ - >a: s32 = 0; - >ptr = &a; - >b = !ptr; - return #extend(b); -} diff --git a/tests/opaque.bbb b/tests/opaque.bbb deleted file mode 100644 index 23f8a8f..0000000 --- a/tests/opaque.bbb +++ /dev/null @@ -1,16 +0,0 @@ -OpaqueType = opaque; - -[extern] memcpy = fn [cc(c)] (destination: &s32, source: &s32, size: u64) &OpaqueType; - -[export] main = fn [cc(c)] () s32 -{ - >destination: s32 = 1; - >source: s32 = 0; - >opaque_pointer = memcpy(&destination, &source, #byte_size(s32)); - >pointer: &s32 = #pointer_cast(opaque_pointer); - if (pointer != &destination) - { - #trap(); - } - return destination; -} diff --git a/tests/pointer.bbb b/tests/pointer.bbb deleted file mode 100644 index 35e938e..0000000 --- a/tests/pointer.bbb +++ /dev/null @@ -1,11 +0,0 @@ -modify = fn (v: &s32) void -{ - v.& = 1; -} - -[export] main = fn [cc(c)] () s32 -{ - >value: s32 = 0; - modify(&value); - return #extend(value == 0); -} diff --git a/tests/pointer_cast.bbb b/tests/pointer_cast.bbb deleted file mode 100644 index 1146bea..0000000 --- a/tests/pointer_cast.bbb +++ /dev/null @@ -1,7 +0,0 @@ -[export] main = fn [cc(c)] () s32 -{ - >result: u32 = 0; - >pointer = &result; - >signed_ptr: &s32 = #pointer_cast(pointer); - return signed_ptr.&; -} diff --git a/tests/pointer_decay.bbb b/tests/pointer_decay.bbb deleted file mode 100644 index ee60d48..0000000 --- a/tests/pointer_decay.bbb +++ /dev/null @@ -1,8 +0,0 @@ -[export] main = fn [cc(c)] () s32 -{ - >array: [_]s32 = [1, 3, 5]; - >pointer: &s32 = &array[0]; - >index: u64 = 0; - pointer[index] = 0; - return pointer[index]; -} diff --git a/tests/pointer_struct_initialization.bbb b/tests/pointer_struct_initialization.bbb deleted file mode 100644 index eda2b5b..0000000 --- a/tests/pointer_struct_initialization.bbb +++ /dev/null @@ -1,32 +0,0 @@ -require = fn (ok: u1) void -{ - if (!ok) #trap(); -} - -S = struct -{ - a: u16, - b: u8, - c: u8, - d: u32, -} - -[export] main = fn [cc(c)] () s32 -{ - >s: S = zero; - - >p_s = &s; - p_s.& = { - .a = 1, - .b = 2, - .c = 3, - .d = 4, - }; - - require(s.a == 1); - require(s.b == 2); - require(s.c == 3); - require(s.d == 4); - - return 0; -} diff --git a/tests/pointer_sub.bbb b/tests/pointer_sub.bbb deleted file mode 100644 index d6a04c4..0000000 --- a/tests/pointer_sub.bbb +++ /dev/null @@ -1,9 +0,0 @@ -[export] main = fn [cc(c)] () s32 -{ - >a: [_]s32 = [ 3, 1 ]; - >p0 = &a[0]; - >p1 = p0 + 1; - >sub: u32 = #truncate(p1 - p0); - if (sub != 1) #trap(); - return 0; -} diff --git a/tests/ret_c_bool.bbb b/tests/ret_c_bool.bbb deleted file mode 100644 index ddc73d7..0000000 --- a/tests/ret_c_bool.bbb +++ /dev/null @@ -1,9 +0,0 @@ -ret_c_bool = fn [cc(c)] () u8 -{ - return 0; -} - -[export] main = fn [cc(c)] () s32 -{ - return #extend(ret_c_bool()); -} diff --git a/tests/return_array.bbb b/tests/return_array.bbb deleted file mode 100644 index a9674db..0000000 --- a/tests/return_array.bbb +++ /dev/null @@ -1,22 +0,0 @@ -SomeEnum = enum -{ - a, - b, - c, - d, - e, - f, -} - -foo = fn () [2]SomeEnum -{ - return [ .f, .e ]; -} - -[export] main = fn [cc(c)] () s32 -{ - >result = foo(); - if (result[0] != .f) #trap(); - if (result[1] != .e) #trap(); - return 0; -} diff --git a/tests/return_small_struct.bbb b/tests/return_small_struct.bbb deleted file mode 100644 index 26f9e5c..0000000 --- a/tests/return_small_struct.bbb +++ /dev/null @@ -1,20 +0,0 @@ -S = struct -{ - a: u1, - b: u1, -} - -foo = fn [cc(c)] () S -{ - return { .a = 1, .b = 0 }; -} - -[export] main = fn [cc(c)] () s32 -{ - >s = foo(); - - if (s.a != 1) #trap(); - if (s.b != 0) #trap(); - - return 0; -} diff --git a/tests/return_type_builtin.bbb b/tests/return_type_builtin.bbb deleted file mode 100644 index cdfcabb..0000000 --- a/tests/return_type_builtin.bbb +++ /dev/null @@ -1,5 +0,0 @@ -[export] main = fn () s32 -{ - >result: #ReturnType = 0; - return result; -} diff --git a/tests/return_u64_u64.bbb b/tests/return_u64_u64.bbb deleted file mode 100644 index 10b07aa..0000000 --- a/tests/return_u64_u64.bbb +++ /dev/null @@ -1,16 +0,0 @@ -Struct_u64_u64 = struct -{ - a: u64, - b: u64, -} - -return_struct_u64_u64 = fn [cc(c)] () Struct_u64_u64 -{ - return { .a = 1, .b = 2 }; -} - -[export] main = fn [cc(c)] () s32 -{ - >r = return_struct_u64_u64(); - return #truncate(r.a + r.b - 3); -} diff --git a/tests/select.bbb b/tests/select.bbb deleted file mode 100644 index 75a609b..0000000 --- a/tests/select.bbb +++ /dev/null @@ -1,7 +0,0 @@ -[export] main = fn [cc(c)] () s32 -{ - >boolean: u1 = 1; - >true_value: s32 = 0; - >false_value: s32 = 1; - return #select(boolean, true_value, false_value); -} diff --git a/tests/self_referential_struct.bbb b/tests/self_referential_struct.bbb deleted file mode 100644 index f2f5463..0000000 --- a/tests/self_referential_struct.bbb +++ /dev/null @@ -1,11 +0,0 @@ -S = struct -{ - self: &S, -} - -[export] main = fn [cc(c)] () s32 -{ - >s: S = zero; - s.self = &s; - return 0; -} diff --git a/tests/shortcircuiting_if.bbb b/tests/shortcircuiting_if.bbb deleted file mode 100644 index 8a8b1c7..0000000 --- a/tests/shortcircuiting_if.bbb +++ /dev/null @@ -1,16 +0,0 @@ -[export] main = fn [cc(c)] (argument_count: u32) s32 -{ - >a: s32 = 0; - if (argument_count != 0 and? argument_count != 2 and? argument_count != 3 or? argument_count != 1) - { - return 0; - } - else if (argument_count == 5 or? a == 0) - { - return 45; - } - else - { - return 1; - } -} diff --git a/tests/slice.bbb b/tests/slice.bbb deleted file mode 100644 index 67ced61..0000000 --- a/tests/slice.bbb +++ /dev/null @@ -1,34 +0,0 @@ -c_string_length = fn (c_string: &u8) u64 -{ - >it = c_string; - - while (it.&) - { - it = it + 1; - } - - return #int_from_pointer(it) - #int_from_pointer(c_string); -} - -[export] main = fn (argument_count: u32, argument_pointer: &&u8) s32 -{ - if (argument_count == 0) - { - return 1; - } - >arg_ptr = argument_pointer[0]; - >a1 = arg_ptr[0..c_string_length(arg_ptr)]; - >a2 = a1[1..]; - - if (a1.pointer != a2.pointer - 1) - { - return 1; - } - - if (a1.length != a2.length + 1) - { - return 1; - } - - return 0; -} diff --git a/tests/slice_array_literal.bbb b/tests/slice_array_literal.bbb deleted file mode 100644 index 1f51463..0000000 --- a/tests/slice_array_literal.bbb +++ /dev/null @@ -1,13 +0,0 @@ -foo = fn (slices: [][]u8) void -{ - if (slices.length != 3) - { - #trap(); - } -} -[export] main = fn [cc(c)] () s32 -{ - >some_bool: u1 = 0; - foo([ "abc", #select(some_bool, "bcd", "cbd"), "sas", ][..]); - return 0; -} diff --git a/tests/slice_of_slices.bbb b/tests/slice_of_slices.bbb deleted file mode 100644 index 70faf0d..0000000 --- a/tests/slice_of_slices.bbb +++ /dev/null @@ -1,31 +0,0 @@ -[extern] memcmp = fn [cc(c)] (a: &u8, b: &u8, byte_count: u64) s32; - -join = fn (slice: []u8, parts: [][]u8) void -{ - >destination_i: u64 = 0; - - for (part: parts) - { - >source_i: u64 = 0; - - while (source_i < part.length) - { - slice[destination_i] = part[source_i]; - destination_i += 1; - source_i += 1; - } - } -} - -[export] main = fn [cc(c)] () s32 -{ - >a = "a"; - >b = "b"; - >ab = "ab"; - >buffer: [2]u8 = undefined; - >buffer_slice = buffer[..]; - join(buffer_slice, [ a, b ][..]); - - >result = memcmp(buffer_slice.pointer, ab.pointer, ab.length); - return result; -} diff --git a/tests/slice_only_start.bbb b/tests/slice_only_start.bbb deleted file mode 100644 index 2a6afca..0000000 --- a/tests/slice_only_start.bbb +++ /dev/null @@ -1,11 +0,0 @@ -[export] main = fn [cc(c)] () s32 -{ - >s = "abcde"; - >index: u64 = 3; - >s_sub = s[index..]; - if (s_sub[0] != 'd') - { - #trap(); - } - return 0; -} diff --git a/tests/small_struct_ints.bbb b/tests/small_struct_ints.bbb deleted file mode 100644 index 2e0e25a..0000000 --- a/tests/small_struct_ints.bbb +++ /dev/null @@ -1,47 +0,0 @@ -SmallStructInts = struct -{ - a: u8, - b: u8, - c: u8, - d: u8, -} - -bb_ret_small_struct_ints = fn [cc(c)] () SmallStructInts -{ - return { - .a = 1, - .b = 2, - .c = 3, - .d = 4, - }; -} - -require = fn(ok: u1) void -{ - if (!ok) - { - #trap(); - } -} - -c_small_struct_ints = fn [cc(c)] (x: SmallStructInts) void -{ - require(x.a == 1); - require(x.b == 2); - require(x.c == 3); - require(x.d == 4); - - >y = bb_ret_small_struct_ints(); - - require(y.a == 1); - require(y.b == 2); - require(y.c == 3); - require(y.d == 4); -} - -[export] main = fn [cc(c)] () s32 -{ - >s: SmallStructInts = { .a = 1, .b = 2, .c = 3, .d = 4 }; - c_small_struct_ints(s); - return 0; -} diff --git a/tests/stack_add.bbb b/tests/stack_add.bbb deleted file mode 100644 index 3d7ba44..0000000 --- a/tests/stack_add.bbb +++ /dev/null @@ -1,6 +0,0 @@ -[export] main = fn [cc(c)] () s32 -{ - >a: s32 = -1; - >b: s32 = 1; - return a + b; -} diff --git a/tests/stack_negation.bbb b/tests/stack_negation.bbb deleted file mode 100644 index efb49a4..0000000 --- a/tests/stack_negation.bbb +++ /dev/null @@ -1,5 +0,0 @@ -[export] main = fn [cc(c)] () s32 -{ - >v: s32 = 0; - return -v; -} diff --git a/tests/stack_sub.bbb b/tests/stack_sub.bbb deleted file mode 100644 index 04ad5cc..0000000 --- a/tests/stack_sub.bbb +++ /dev/null @@ -1,6 +0,0 @@ -[export] main = fn [cc(c)] () s32 -{ - >a: s32 = 1; - >b: s32 = 1; - return a - b; -} diff --git a/tests/strict_array_type.bbb b/tests/strict_array_type.bbb deleted file mode 100644 index 66ec212..0000000 --- a/tests/strict_array_type.bbb +++ /dev/null @@ -1,5 +0,0 @@ -[export] main = fn [cc(c)] () s32 -{ - >arr: [3]s32 = [3, 1, 0]; - return arr[2]; -} diff --git a/tests/string_to_enum.bbb b/tests/string_to_enum.bbb deleted file mode 100644 index 558384f..0000000 --- a/tests/string_to_enum.bbb +++ /dev/null @@ -1,20 +0,0 @@ -E = enum -{ - asd, - dsa, - gsa, -} - -[export] main = fn [cc(c)] () s32 -{ - >e = "dsa"; - >s2e = #string_to_enum(E, e); - >result: s32 = 1; - - if (s2e.is_valid) - { - result = #extend(s2e.enum_value != .dsa); - } - - return result; -} diff --git a/tests/struct.bbb b/tests/struct.bbb deleted file mode 100644 index 43bf668..0000000 --- a/tests/struct.bbb +++ /dev/null @@ -1,20 +0,0 @@ -Foo = struct { - x: s32, - y: s32, - z: s32, -}; - -foo = fn(arg: Foo) s32 { - return arg.z; -} - -[export] main = fn [cc(c)] () s32 -{ - >a: Foo = { - .x = 2, - .y = 1, - .z = 0, - }; - - return foo(a); -} diff --git a/tests/struct_assignment.bbb b/tests/struct_assignment.bbb deleted file mode 100644 index 7d168ef..0000000 --- a/tests/struct_assignment.bbb +++ /dev/null @@ -1,46 +0,0 @@ -S1 = struct -{ - a: u8, - b: u8, - c: u8, -} - -S2 = struct -{ - a: u8, - b: u8, - c: u8, -} - -require = fn (ok: u1) void -{ - if (!ok) - { - #trap(); - } -} - -[export] main = fn [cc(c)] () s32 -{ - >s1: S1 = { - .a = 255, - .b = 254, - .c = 253, - }; - - >s2 :S2 = { - .a = s1.a, - .b = s1.b, - .c = s1.c, - }; - - require(s1.a == 255); - require(s1.b == 254); - require(s1.c == 253); - - require(s2.a == 255); - require(s2.b == 254); - require(s2.c == 253); - - return 0; -} diff --git a/tests/struct_u64_u64.bbb b/tests/struct_u64_u64.bbb deleted file mode 100644 index e6f5c1f..0000000 --- a/tests/struct_u64_u64.bbb +++ /dev/null @@ -1,25 +0,0 @@ -require = fn (ok: u1) void -{ - if (!ok) - { - #trap(); - } -} - -Struct_u64_u64 = struct -{ - a: u64, - b: u64, -}; - -bb_struct_u64_u64_0 = fn [cc(c)] (s: Struct_u64_u64) void -{ - require(s.a == 3); - require(s.b == 4); -} - -[export] main = fn [cc(c)] () s32 -{ - bb_struct_u64_u64_0({ .a = 3, .b = 4 }); - return 0; -} diff --git a/tests/struct_varargs.bbb b/tests/struct_varargs.bbb deleted file mode 100644 index cc3478f..0000000 --- a/tests/struct_varargs.bbb +++ /dev/null @@ -1,47 +0,0 @@ -S = struct -{ - a: u32, - b: u32, - c: u64, - d: u64, - e: u64 -} - -require = fn (ok: u1) void -{ - if (!ok) - { - #trap(); - } -} - -va_arg_fn = fn [cc(c)] (first_arg: u32, ...) void -{ - if (first_arg != 123456789) - { - #trap(); - } - - >va = #va_start(); - - >s = #va_arg(&va, S); - require(s.a == 5); - require(s.b == 4); - require(s.c == 3); - require(s.d == 2); - require(s.e == 1); -} - -[export] main = fn [cc(c)] () s32 -{ - >first_arg: u32 = 123456789; - >s : S = { - .a = 5, - .b = 4, - .c = 3, - .d = 2, - .e = 1, - }; - va_arg_fn(first_arg, s); - return 0; -} diff --git a/tests/struct_zero.bbb b/tests/struct_zero.bbb deleted file mode 100644 index 32f5b90..0000000 --- a/tests/struct_zero.bbb +++ /dev/null @@ -1,35 +0,0 @@ -require = fn (ok: u1) void -{ - if (!ok) - { - #trap(); - } -} - -S = struct -{ - a: u8, - b: u8, - c: u8, -} - -[export] main = fn () s32 -{ - >a: S = zero; - - require(a.a == 0); - require(a.b == 0); - require(a.c == 0); - - >b: S = { - .a = 1, - .b = 1, - zero, - }; - - require(b.a == 1); - require(b.b == 1); - require(b.c == 0); - - return 0; -} diff --git a/tests/switch_else.bbb b/tests/switch_else.bbb deleted file mode 100644 index a6550bb..0000000 --- a/tests/switch_else.bbb +++ /dev/null @@ -1,22 +0,0 @@ -E = enum -{ - a, - b, - c, -} - -[export] main = fn [cc(c)] () s32 -{ - >some_enum: E = .a; - switch (some_enum) - { - .a => - { - return 0; - }, - else => - { - return 1; - }, - } -} diff --git a/tests/switch_else_empty.bbb b/tests/switch_else_empty.bbb deleted file mode 100644 index af7db27..0000000 --- a/tests/switch_else_empty.bbb +++ /dev/null @@ -1,23 +0,0 @@ -E = enum -{ - a, - b, - c, -} - -[export] main = fn [cc(c)] () s32 -{ - >some_enum: E = .b; - switch (some_enum) - { - .a => - { - return 1; - }, - else => - { - }, - } - - return 0; -} diff --git a/tests/tests.bbb b/tests/tests.bbb new file mode 100644 index 0000000..152b426 --- /dev/null +++ b/tests/tests.bbb @@ -0,0 +1,2328 @@ +require = fn (ok: u1) void +{ + if (!ok) + { + @trap(); + } +} + +return_constant = fn () s32 // This is a comment +// This is a comment +{ // This is a comment + // This is a comment + return 0; // This is a comment +}// This is a comment +// This is a comment + +constant_add = fn () s32 +{ + return -1 + 1; +} + +constant_and = fn () s32 +{ + return 1 & 2; +} + +constant_div = fn () s32 +{ + return 0 / 5; +} + +constant_mul = fn () s32 +{ + return 1 * 0; +} + +constant_rem = fn () s32 +{ + return 5 % 5; +} + +constant_or = fn () s32 +{ + return 0 | 0; +} + +constant_sub = fn () s32 +{ + return 1 - 1; +} + +constant_xor = fn () s32 +{ + return 0 ^ 0; +} + +constant_shift_left = fn () s32 +{ + return 0 << 1; +} + +constant_shift_right = fn () s32 +{ + return 0 >> 1; +} + +minimal_stack = fn () s32 +{ + >a: s32 = 0; + return a; +} + +minimal_stack_arithmetic0 = fn () s32 +{ + >a: s32 = 1; + return a - 1; +} + +minimal_stack_arithmetic1 = fn () s32 +{ + >a: s32 = 1; + >b = a - 1; + return b; +} + +minimal_stack_arithmetic2 = fn () s32 +{ + >a: s32 = 1; + >b = 1 - a; + return b; +} + +stack_negation = fn () s32 +{ + >v: s32 = 0; + return -v; +} + +stack_add = fn () s32 +{ + >a: s32 = -1; + >b: s32 = 1; + return a + b; +} + +stack_sub = fn () s32 +{ + >a: s32 = 1; + >b: s32 = 1; + return a - b; +} + +extend = fn () s32 +{ + >a: s8 = 0; + return @extend(a); +} + +integer_max = fn () s32 +{ + >a = @integer_max(u64); + return @truncate(a + 1); +} + +integer_hex = fn () s32 +{ + >result: s32 = 0x0; + return result; +} + +basic_pointer = fn () s32 +{ + >a: s32 = 0; + >pointer = &a; + return pointer.&; +} + +basic_call_foo = fn () s32 +{ + return 0; +} + +basic_call = fn () s32 +{ + return basic_call_foo(); +} + +basic_branch = fn () s32 +{ + >result: s32 = 1; + if (result != 1) + { + return 1; + } + else + { + return 0; + } +} + +basic_array = fn () s32 +{ + >array: [_]s32 = [3, 2, 1, 0]; + return array[3]; +} + +BasicEnum = enum +{ + zero = 0, + one = 1, + two = 2, + three = 3, +} + +basic_enum = fn () s32 +{ + >a: BasicEnum = .three; + >b: BasicEnum = .two; + >c: BasicEnum = .one; + >a_int: s32 = @extend(@int_from_enum(a)); + >b_int: s32 = @extend(@int_from_enum(b)); + >c_int: s32 = @extend(@int_from_enum(c)); + + return a_int - (b_int + c_int); +} + +basic_slice_receiver = fn (slice: []u8) void +{ + require(slice.length == 3); + require(slice[0] == 0); + require(slice[1] == 1); + require(slice[2] == 2); +} + +basic_slice = fn () void +{ + >a: [_]u8 = [0, 1, 2]; + basic_slice_receiver(a[..]); +} + +basic_string = fn () void +{ + >string = "abc"; + require(string[0] == 'a'); + require(string[1] == 'b'); + require(string[2] == 'c'); +} + +basic_varargs_function = fn [cc(c)] (first_arg: u32, ...) void +{ + require(first_arg == 123456789); + + >va = @va_start(); + + >a = @va_arg(&va, u32); + + require(a == 987654321); + + >first_arg_b = @va_arg(&va, u32); + require(first_arg == first_arg_b); +} + +basic_varargs = fn () void +{ + >first_arg: u32 = 123456789; + >a: u32 = 987654321; + basic_varargs_function(first_arg, a, first_arg); +} + +c_string_length = fn (c_string: &u8) u64 +{ + >it = c_string; + + while (it.&) + { + it = it + 1; + } + + return @int_from_pointer(it) - @int_from_pointer(c_string); +} + +basic_while = fn (argc: s32, argv: &&u8) void +{ + require(argc != 0); + + >first_arg = argv[0]; + require(first_arg != zero); + + >arg_length = c_string_length(first_arg); + require(arg_length != 0); + + require(first_arg[arg_length] == 0); +} + +pointer_function = fn (v: &s32) void +{ + v.& = 1; +} + +pointer = fn () s32 +{ + >value: s32 = 0; + pointer_function(&value); + return @extend(value == 0); +} + +pointer_cast = fn () s32 +{ + >result: u32 = 0; + >p = &result; + >signed_pointer: &s32 = @pointer_cast(p); + return signed_pointer.&; +} + +u1_return_foo = fn () u1 +{ + >result: u1 = 0; + return result; +} + +u1_return = fn () s32 +{ + >result = u1_return_foo(); + return @extend(result); +} + +local_type_inference_foo = fn () s32 +{ + return 0; +} + +local_type_inference = fn () s32 +{ + >a: s32 = 0; + >result = local_type_inference_foo() + a; + return result; +} + +basic_global_foo: s32 = 0; + +basic_global = fn () s32 +{ + return basic_global_foo; +} + +basic_function_pointer_callback = fn () s32 +{ + return 123; +} + +basic_function_pointer = fn () s32 +{ + >function_pointer = &basic_function_pointer_callback; + return function_pointer() - 123; +} + +[extern] strlen = fn [cc(c)] (string: &u8) s64; + +basic_extern = fn () void +{ + >length = strlen("abc"); + require(length == 3); +} + +basic_byte_size = fn () void +{ + >sizeofu8: u8 = @byte_size(u8); + require(sizeofu8 == 1); + >sizeofu16: u8 = @byte_size(u16); + require(sizeofu16 == 2); + >sizeofs32: s32 = @byte_size(s32); + require(sizeofs32 == 4); + >sizeofs64: s32 = @byte_size(s64); + require(sizeofs64 == 8); +} + +unsigned_assignment_operators = fn(n: s32) s32 +{ + >result: u32 = @extend(n); + result >>= 1; + result <<= 1; + result ^= 1; + result |= 1; + result &= 1; + result += 1; + result -= 1; + result /= 1; + result %= 1; + result *= 0; + + return @extend(result); +} + +assignment_operators = fn () s32 +{ + >result: s32 = 0; + >pointer = &result; + pointer -= 1; + pointer += 1; + result >>= 1; + result <<= 1; + result ^= 1; + result |= 1; + result &= 1; + result += 1; + result -= 1; + result /= 1; + result %= 1; + result *= 0; + return unsigned_assignment_operators(result); +} + +not_pointer = fn () s32 +{ + >a: s32 = 0; + >ptr = &a; + >b = !ptr; + return @extend(b); +} + +BasicBitField = bits u8 +{ + a: u2, + b: u2, + c: u2, + d: u2, +} + +basic_bits = fn () void +{ + >bf: BasicBitField = { + .a = 3, + .b = 2, + .c = 2, + .d = 3, + }; + + require(bf.a == 3); + require(bf.b == 2); + require(bf.c == 2); + require(bf.d == 3); +} + +BitsNoBackingType = bits +{ + a: u1, + b: u1, +} + +bits_no_backing_type = fn () void +{ + >bf: BitsNoBackingType = { + .a = 1, + .b = 1, + }; + + require(bf.a == 1); + require(bf.b == 1); +} + +BitsU1 = bits u32 +{ + a: u1, + b: u1, + c: u1, +} + +bits_return_u1_function = fn () u1 +{ + >b1: BitsU1 = { + .a = 1, + .b = 1, + .c = 0, + }; + + return b1.c; +} + +bits_return_u1 = fn () void +{ + >b1 = bits_return_u1_function(); + require(b1 == 0); +} + +BitsZero = bits +{ + a: u1, + b: u1, + c: u1, +} + +bits_zero = fn () void +{ + >a_bz: BitsZero = zero; + + require(a_bz.a == 0); + require(a_bz.b == 0); + require(a_bz.c == 0); + + >b_bz: BitsZero = { + .a = 1, + .b = 1, + zero, + }; + + require(b_bz.a == 1); + require(b_bz.b == 1); + require(b_bz.c == 0); +} + +basic_comparison_trivial = fn (a: s32, b: s32) u1 +{ + return a + 1 == b + 1; +} + +basic_comparison = fn (argument_count: s32) void +{ + require(basic_comparison_trivial(argument_count, argument_count)); +} + +BasicGlobalStruct = struct +{ + a: u32, + b: u32, + c: u32, +} + +basic_global_struct_variable: BasicGlobalStruct = { + .a = 1, + .b = 2, + .c = 3, +}; + +basic_global_struct = fn () void +{ + require(basic_global_struct_variable.a == 1); + require(basic_global_struct_variable.b == 2); + require(basic_global_struct_variable.c == 3); +} + +if_no_else = fn () s32 +{ + >a: s32 = 5; + if (a == 2) + { + return 1; + } + + return 0; +} + +if_no_else_void = fn () void +{ + >result: s32 = 0; + if (result != 0) + { + @trap(); + } +} + +Indirect = struct +{ + a: u32, + b: u32, + c: u32, + d: u32, + e: u32, + f: u32, +} + +indirect_ret = fn [cc(c)] () Indirect +{ + return { .a = 56, .b = 57, .c = 58, .d = 59, .e = 60, .f = 61 }; +} + +indirect_arg = fn [cc(c)] (s: Indirect) void +{ + require(s.a == 56); + require(s.b == 57); + require(s.c == 58); + require(s.d == 59); + require(s.e == 60); + require(s.f == 61); +} + +basic_indirect = fn () void +{ + >s = indirect_ret(); + require(s.a == 56); + require(s.b == 57); + require(s.c == 58); + require(s.d == 59); + require(s.e == 60); + require(s.f == 61); + indirect_arg(s); +} + +IndirectVarArgs = struct +{ + a: u64, + b: u64, + c: u64, + d: u64, + e: u64 + f: u64, + g: u64, + h: u64, + i: u64, + j: u64 +} + +indirect_varargs_function = fn [cc(c)] (first_arg: u32, ...) void +{ + if (first_arg != 123456789) + { + @trap(); + } + + >va = @va_start(); + + >s = @va_arg(&va, IndirectVarArgs); + require(s.a == 9); + require(s.b == 8); + require(s.c == 7); + require(s.d == 6); + require(s.e == 5); + require(s.f == 4); + require(s.g == 3); + require(s.h == 2); + require(s.i == 1); + require(s.j == 0); +} + +indirect_varargs = fn () void +{ + >first_arg: u32 = 123456789; + >s: IndirectVarArgs = { + .a = 9, + .b = 8, + .c = 7, + .d = 6, + .e = 5, + .f = 4, + .g = 3, + .h = 2, + .i = 1, + .j = 0, + }; + indirect_varargs_function(first_arg, s); +} + +return_type_builtin = fn () s32 +{ + >result: @ReturnType = 0; + return result; +} + +Struct_u64_u64 = struct +{ + a: u64, + b: u64, +} + +return_struct_u64_u64_function = fn [cc(c)] () Struct_u64_u64 +{ + return { .a = 1, .b = 2 }; +} + +return_struct_u64_u64 = fn [cc(c)] () s32 +{ + >r = return_struct_u64_u64_function(); + return @truncate(r.a + r.b - 3); +} + +select = fn () s32 +{ + >boolean: u1 = 1; + >left: s32 = 0; + >right: s32 = 1; + return @select(boolean, left, right); +} + +slice2 = fn (argc: s32, argv: &&u8) void +{ + require(argc != 0); + >arg_ptr = argv[0]; + >a1 = arg_ptr[0..c_string_length(arg_ptr)]; + >a2 = a1[1..]; + + require(a1.pointer == a2.pointer - 1); + require(a1.length == a2.length + 1); +} + +SA1 = struct +{ + a: u8, + b: u8, + c: u8, +} + +SA2 = struct +{ + a: u8, + b: u8, + c: u8, +} + +struct_assignment = fn () void +{ + >s1: SA1 = { + .a = 255, + .b = 254, + .c = 253, + }; + >s2: SA2 = { + .a = s1.a, + .b = s1.b, + .c = s1.c, + }; + + require(s1.a == 255); + require(s1.b == 254); + require(s1.c == 253); + + require(s2.a == 255); + require(s2.b == 254); + require(s2.c == 253); +} + +BasicStruct = struct +{ + x: s32, + y: s32, + z: s32, +} + +basic_struct_fn = fn (s: BasicStruct) s32 +{ + return s.z; +} + +basic_struct = fn () s32 +{ + >a: BasicStruct = { + .x = 2, + .y = 1, + .z = 0, + }; + + return basic_struct_fn(a); +} + +struct_zero = fn () void +{ + >a: SA1 = zero; + + require(a.a == 0); + require(a.b == 0); + require(a.c == 0); + + >b: SA1 = { + .a = 1, + .b = 1, + zero, + }; + + require(b.a == 1); + require(b.b == 1); + require(b.c == 0); +} + +basic_unreachable = fn () s32 +{ + >result: s32 = 0; + + if (result != 0) + { + unreachable; + } + + return result; +} + +S = struct +{ + a: u32, + b: u32, + c: u64, + d: u64, + e: u64 +} + +va_arg_function = fn [cc(c)] (first_arg: u32, ...) void +{ + >va = @va_start(); + + >a = @va_arg(&va, u32); + >b = @va_arg(&va, S); + >c = @va_arg(&va, s64); + >d = @va_arg(&va, s32); + + require(first_arg == 123456789); + require(a == 123); + require(c == -1); + require(d == -2); + require(b.a == 1); + require(b.b == 2); + require(b.c == 3); + require(b.d == 4); + require(b.e == 5); + + @va_end(&va); +} + +S2 = struct +{ + a: u64, + b: u64, +} + +va_arg_function2 = fn [cc(c)] (...) void +{ + >va = @va_start(); + >s2 = @va_arg(&va, S2); + require(s2.a == 8); + require(s2.b == 9); + @va_end(&va); +} + +va_args = fn [cc(c)] () void +{ + >first_arg: u32 = 123456789; + >a: u32 = 123; + >b: S = { .a = 1, .b = 2, .c = 3, .d = 4, .e = 5 }; + >c: s64 = -1; + >d: s32 = -2; + va_arg_function(first_arg, a, b, c, d); + >s2: S2 = { .a = 8, .b = 9 }; + va_arg_function2(s2); +} + +EnumBoolEnum = enum { + a, + b, + c, + d, + e, + f, + g, +} + +EnumBoolStruct = struct +{ + enum: EnumBoolEnum, + bool: u1, +} + +enum_bool_struct = fn () void +{ + >s: EnumBoolStruct = { + .enum = .f, + .bool = 1, + }; + + require(s.enum == .f); + require(s.bool); +} + +BigStruct = struct +{ + a: u64, + b: u64, + c: u64, + d: u64, + e: u8, +} + +SmallPackedStruct = bits u8 +{ + a: u2, + b: u2, + c: u2, + d: u2, +} + +SmallStructInts = struct +{ + a: u8, + b: u8, + c: u8, + d: u8, +} + +SplitStructInt = struct +{ + a: u64, + b: u8, + c: u32, +} + +MedStructInts = struct +{ + x: s32, + y: s32, + z: s32, +} + +Rect = struct +{ + left: u32, + right: u32, + top: u32, + bottom: u32, +} + +StructWithArray = struct +{ + a: s32, + padding: [4]u8, + b: s64, +} + +ByRef = struct +{ + val: s32, + arr: [15]s32, +} + +ByValOrigin = struct +{ + x: u64, + y: u64, + z: u64, +} + +ByValSize = struct +{ + width: u64, + height: u64, + depth: u64, +} + +ByVal = struct +{ + origin: ByValOrigin, + size: ByValSize, +} + +[extern] run_c_tests = fn [cc(c)] () void; + +[extern] c_u8 = fn [cc(c)] (x: u8) void; +[extern] c_u16 = fn [cc(c)] (x: u16) void; +[extern] c_u32 = fn [cc(c)] (x: u32) void; +[extern] c_u64 = fn [cc(c)] (x: u64) void; + +[extern] c_s8 = fn [cc(c)] (x: s8) void; +[extern] c_s16 = fn [cc(c)] (x: s16) void; +[extern] c_s32 = fn [cc(c)] (x: s32) void; +[extern] c_s64 = fn [cc(c)] (x: s64) void; + +[extern] c_bool = fn [cc(c)] (x: u8) void; + +[extern] c_five_integers = fn [cc(c)] (a: s32, b: s32, c: s32, d: s32, e: s32) void; +[extern] c_ret_struct_u64_u64 = fn [cc(c)] () Struct_u64_u64; + +[extern] c_struct_u64_u64_0 = fn [cc(c)] (a: Struct_u64_u64) void; +[extern] c_struct_u64_u64_1 = fn [cc(c)] (a: u64, b: Struct_u64_u64) void; +[extern] c_struct_u64_u64_2 = fn [cc(c)] (a: u64, b: u64, c: Struct_u64_u64) void; +[extern] c_struct_u64_u64_3 = fn [cc(c)] (a: u64, b: u64, c: u64, d: Struct_u64_u64) void; +[extern] c_struct_u64_u64_4 = fn [cc(c)] (a: u64, b: u64, c: u64, d: u64, e: Struct_u64_u64) void; +[extern] c_struct_u64_u64_5 = fn [cc(c)] (a: u64, b: u64, c: u64, d: u64, e: u64, f: Struct_u64_u64) void; +[extern] c_struct_u64_u64_6 = fn [cc(c)] (a: u64, b: u64, c: u64, d: u64, e: u64, f: u64, g: Struct_u64_u64) void; +[extern] c_struct_u64_u64_7 = fn [cc(c)] (a: u64, b: u64, c: u64, d: u64, e: u64, f: u64, g: u64, h: Struct_u64_u64) void; +[extern] c_struct_u64_u64_8 = fn [cc(c)] (a: u64, b: u64, c: u64, d: u64, e: u64, f: u64, g: u64, h: u64, i: Struct_u64_u64) void; + +[extern] c_big_struct = fn [cc(c)] (x: BigStruct) void; +[extern] c_small_struct_ints = fn [cc(c)] (x: SmallStructInts) void; +[extern] c_ret_small_struct_ints = fn [cc(c)] () SmallStructInts; +[extern] c_med_struct_ints = fn [cc(c)] (x: MedStructInts) void; +[extern] c_ret_med_struct_ints = fn [cc(c)] () MedStructInts; +[extern] c_small_packed_struct = fn [cc(c)] (x: SmallPackedStruct) void; +[extern] c_ret_small_packed_struct = fn [cc(c)] () SmallPackedStruct; +[extern] c_split_struct_ints = fn [cc(c)] (x: SplitStructInt) void; +[extern] c_big_struct_both = fn [cc(c)] (x: BigStruct) BigStruct; +[extern] c_multiple_struct_ints = fn [cc(c)] (a: Rect, b: Rect) void; + +[extern] c_ret_bool = fn [cc(c)] () u8; + +[extern] c_ret_u8 = fn [cc(c)] () u8; +[extern] c_ret_u16 = fn [cc(c)] () u16; +[extern] c_ret_u32 = fn [cc(c)] () u32; +[extern] c_ret_u64 = fn [cc(c)] () u64; + +[extern] c_ret_s8 = fn [cc(c)] () s8; +[extern] c_ret_s16 = fn [cc(c)] () s16; +[extern] c_ret_s32 = fn [cc(c)] () s32; +[extern] c_ret_s64 = fn [cc(c)] () s64; + +[extern] c_struct_with_array = fn [cc(c)] (x: StructWithArray) void; +[extern] c_ret_struct_with_array = fn [cc(c)] () StructWithArray; + +[extern] c_modify_by_ref_param = fn [cc(c)] (x: ByRef) ByRef; +[extern] c_func_ptr_byval = fn [cc(c)] (a: u64, b: u64, c: ByVal, d: u64, e: u64, f: u64) void; + +[export] bb_u8 = fn [cc(c)] (x: u8) void +{ + require(x == 0xff); +} + +[export] bb_u16 = fn [cc(c)] (x: u16) void +{ + require(x == 0xfffe); +} + +[export] bb_u32 = fn [cc(c)] (x: u32) void +{ + require(x == 0xfffffffd); +} + +[export] bb_u64 = fn [cc(c)] (x: u64) void +{ + require(x == 0xfffffffffffffffc); +} + +[export] bb_s8 = fn [cc(c)] (x: s8) void +{ + require(x == -1); +} + +[export] bb_s16 = fn [cc(c)] (x: s16) void +{ + require(x == -2); +} + +[export] bb_s32 = fn [cc(c)] (x: s32) void +{ + require(x == -3); +} + +[export] bb_s64 = fn [cc(c)] (x: s64) void +{ + require(x == -4); +} + +[export] bb_ptr = fn [cc(c)] (x: &u8) void +{ + require(@int_from_pointer(x) == 0xdeadbeef); +} + +[export] bb_five_integers = fn [cc(c)] (a: s32, b: s32, c: s32, d: s32, e: s32) void +{ + require(a == 12); + require(b == 34); + require(c == 56); + require(d == 78); + require(e == 90); +} + +[export] bb_bool = fn [cc(c)] (x: u8) void +{ + require(@truncate(x)); +} + +[export] bb_ret_struct_u64_u64 = fn [cc(c)] () Struct_u64_u64 +{ + return { .a = 1, .b = 2, }; +} + +[export] bb_struct_u64_u64_0 = fn [cc(c)] (s: Struct_u64_u64) void +{ + require(s.a == 3); + require(s.b == 4); +} + +[export] bb_struct_u64_u64_1 = fn [cc(c)] (_: u64, s: Struct_u64_u64) void +{ + require(s.a == 5); + require(s.b == 6); +} + +[export] bb_struct_u64_u64_2 = fn [cc(c)] (_: u64, _: u64, s: Struct_u64_u64) void +{ + require(s.a == 7); + require(s.b == 8); +} + +[export] bb_struct_u64_u64_3 = fn [cc(c)] (_: u64, _: u64, _: u64, s: Struct_u64_u64) void +{ + require(s.a == 9); + require(s.b == 10); +} + +[export] bb_struct_u64_u64_4 = fn [cc(c)] (_: u64, _: u64, _: u64, _: u64, s: Struct_u64_u64) void +{ + require(s.a == 11); + require(s.b == 12); +} + +[export] bb_struct_u64_u64_5 = fn [cc(c)] (_: u64, _: u64, _: u64, _: u64, _: u64, s: Struct_u64_u64) void +{ + require(s.a == 13); + require(s.b == 14); +} + +[export] bb_struct_u64_u64_6 = fn [cc(c)] (_: u64, _: u64, _: u64, _: u64, _: u64, _: u64, s: Struct_u64_u64) void +{ + require(s.a == 15); + require(s.b == 16); +} + +[export] bb_struct_u64_u64_7 = fn [cc(c)] (_: u64, _: u64, _: u64, _: u64, _: u64, _: u64, _: u64, s: Struct_u64_u64) void +{ + require(s.a == 17); + require(s.b == 18); +} + +[export] bb_struct_u64_u64_8 = fn [cc(c)] (_: u64, _: u64, _: u64, _: u64, _: u64, _: u64, _: u64, _: u64, s: Struct_u64_u64) void +{ + require(s.a == 19); + require(s.b == 20); +} + +[export] bb_big_struct = fn [cc(c)] (x: BigStruct) void +{ + require(x.a == 1); + require(x.b == 2); + require(x.c == 3); + require(x.d == 4); + require(x.e == 5); +} + +[export] bb_small_packed_struct = fn [cc(c)] (x: SmallPackedStruct) void +{ + require(x.a == 0); + require(x.b == 1); + require(x.c == 2); + require(x.d == 3); +} + +[export] bb_split_struct_ints = fn [cc(c)] (x: SplitStructInt) void +{ + require(x.a == 1234); + require(x.b == 100); + require(x.c == 1337); +} + +[export] bb_big_struct_both = fn [cc(c)] (x: BigStruct) BigStruct +{ + require(x.a == 30); + require(x.b == 31); + require(x.c == 32); + require(x.d == 33); + require(x.e == 34); + >s: BigStruct = { + .a = 20, + .b = 21, + .c = 22, + .d = 23, + .e = 24, + }; + return s; +} + +[export] bb_ret_bool = fn [cc(c)] () u8 +{ + return 1; +} + +[export] bb_ret_u8 = fn [cc(c)] () u8 +{ + return 0xff; +} + +[export] bb_ret_u16 = fn [cc(c)] () u16 +{ + return 0xffff; +} + +[export] bb_ret_u32 = fn [cc(c)] () u32 +{ + return 0xffffffff; +} + +[export] bb_ret_u64 = fn [cc(c)] () u64 +{ + return 0xffffffffffffffff; +} + +[export] bb_ret_s8 = fn [cc(c)] () s8 +{ + return -1; +} + +[export] bb_ret_s16 = fn [cc(c)] () s16 +{ + return -1; +} + +[export] bb_ret_s32 = fn [cc(c)] () s32 +{ + return -1; +} + +[export] bb_ret_s64 = fn [cc(c)] () s64 +{ + return -1; +} + +[export] bb_ret_small_struct_ints = fn [cc(c)] () SmallStructInts +{ + return { + .a = 1, + .b = 2, + .c = 3, + .d = 4, + }; +} + +[export] bb_ret_med_struct_ints = fn [cc(c)] () MedStructInts +{ + return { + .x = 1, + .y = 2, + .z = 3, + }; +} + +[export] bb_multiple_struct_ints = fn [cc(c)] (x: Rect, y: Rect) void +{ + require(x.left == 1); + require(x.right == 21); + require(x.top == 16); + require(x.bottom == 4); + require(y.left == 178); + require(y.right == 189); + require(y.top == 21); + require(y.bottom == 15); +} + +[export] bb_small_struct_ints = fn [cc(c)] (x: SmallStructInts) void +{ + require(x.a == 1); + require(x.b == 2); + require(x.c == 3); + require(x.d == 4); +} + +[export] bb_med_struct_ints = fn [cc(c)] (s: MedStructInts) void +{ + require(s.x == 1); + require(s.y == 2); + require(s.z == 3); +} + +c_abi_tests = fn () void +{ + run_c_tests(); + c_u8(0xff); + c_u16(0xfffe); + c_u32(0xfffffffd); + c_u64(0xfffffffffffffffc); + + //if (has_i128) { + // c_struct_u128({ .value = 0xfffffffffffffffc, }); + //} + + c_s8(-1); + c_s16(-2); + c_s32(-3); + c_s64(-4); + + //if (has_i128) { + // c_struct_i128({ .value = -6, }); + //} + + c_bool(1); + + c_five_integers(12, 34, 56, 78, 90); + + >s = c_ret_struct_u64_u64(); + require(s.a == 21); + require(s.b == 22); + c_struct_u64_u64_0({ .a = 23, .b = 24, }); + c_struct_u64_u64_1(0, { .a = 25, .b = 26, }); + c_struct_u64_u64_2(0, 1, { .a = 27, .b = 28, }); + c_struct_u64_u64_3(0, 1, 2, { .a = 29, .b = 30, }); + c_struct_u64_u64_4(0, 1, 2, 3, { .a = 31, .b = 32, }); + c_struct_u64_u64_5(0, 1, 2, 3, 4, { .a = 33, .b = 34, }); + c_struct_u64_u64_6(0, 1, 2, 3, 4, 5, { .a = 35, .b = 36, }); + c_struct_u64_u64_7(0, 1, 2, 3, 4, 5, 6, { .a = 37, .b = 38, }); + c_struct_u64_u64_8(0, 1, 2, 3, 4, 5, 6, 7, { .a = 39, .b = 40, }); + + >big_struct: BigStruct = { + .a = 1, + .b = 2, + .c = 3, + .d = 4, + .e = 5, + }; + c_big_struct(big_struct); + + >small: SmallStructInts = { + .a = 1, + .b = 2, + .c = 3, + .d = 4, + }; + c_small_struct_ints(small); + >small2 = c_ret_small_struct_ints(); + require(small2.a == 1); + require(small2.b == 2); + require(small2.c == 3); + require(small2.d == 4); + + >med: MedStructInts = { + .x = 1, + .y = 2, + .z = 3, + }; + c_med_struct_ints(med); + >med2 = c_ret_med_struct_ints(); + require(med2.x == 1); + require(med2.y == 2); + require(med2.z == 3); + + >p: SmallPackedStruct = { .a = 0, .b = 1, .c = 2, .d = 3, }; + c_small_packed_struct(p); + >p2 = c_ret_small_packed_struct(); + require(p2.a == 0); + require(p2.b == 1); + require(p2.c == 2); + require(p2.d == 3); + + >split: SplitStructInt = { + .a = 1234, + .b = 100, + .c = 1337, + }; + c_split_struct_ints(split); + + > big: BigStruct = { + .a = 1, + .b = 2, + .c = 3, + .d = 4, + .e = 5, + }; + >big2 = c_big_struct_both(big); + require(big2.a == 10); + require(big2.b == 11); + require(big2.c == 12); + require(big2.d == 13); + require(big2.e == 14); + + >r1: Rect = { + .left = 1, + .right = 21, + .top = 16, + .bottom = 4, + }; + >r2: Rect = { + .left = 178, + .right = 189, + .top = 21, + .bottom = 15, + }; + c_multiple_struct_ints(r1, r2); + + require(c_ret_bool() == 1); + + require(c_ret_u8() == 0xff); + require(c_ret_u16() == 0xffff); + require(c_ret_u32() == 0xffffffff); + require(c_ret_u64() == 0xffffffffffffffff); + + require(c_ret_s8() == -1); + require(c_ret_s16() == -1); + require(c_ret_s32() == -1); + require(c_ret_s64() == -1); + + c_struct_with_array({ .a = 1, .padding = [0, 0, 0, 0], .b = 2, }); + + >x = c_ret_struct_with_array(); + require(x.a == 4); + require(x.b == 155); + + >res = c_modify_by_ref_param({ .val = 1, .arr = [ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 ] }); + require(res.val == 42); + + >function_pointer = &c_func_ptr_byval; + function_pointer(1, 2, { .origin = { .x = 9, .y = 10, .z = 11, }, .size = { .width = 12, .height = 13, .depth = 14, }, }, 3, 4, 5); +} + +S2Enum = enum +{ + asd, + dsa, + gsa, +} + +string_to_enum = fn () s32 +{ + >e = "dsa"; + >s2e = @string_to_enum(S2Enum, e); + >result: s32 = 1; + + if (s2e.is_valid) + { + result = @extend(s2e.enum_value != .dsa); + } + + return result; +} + +empty_if = fn (argument_count: s32) s32 +{ + >result: s32 = 0; + + if (argument_count != 1) + { + result = 1; + } + else + { + } + + return result; +} + +else_if = fn () s32 +{ + >result: s32 = 0; + if (result == 1) + { + return 1; + } + else if (result == 0) + { + return 0; + } + else + { + return 5; + } +} + +ElseIfEnum = enum +{ + a, + b, + c, +} + +else_if_complicated = fn (argument_count: s32) s32 +{ + >result: s32 = 0; + >foo: ElseIfEnum = .b; + switch (foo) + { + .b => + { + if (argument_count != 0) + { + >a: s32 = 1; + if (result == 1) + { + } + else if (result == 0) + { + return 0; + } + else + { + return 5; + } + return a; + } + }, + else => + { + } + } + + return 0; +} + +basic_shortcircuiting_if = fn (argument_count: s32) s32 +{ + >a: s32 = 0; + if (argument_count != 3 and? argument_count != 2) + { + return 0; + } + else + { + return 1; + } +} + +shortcircuiting_if = fn (argument_count: s32) s32 +{ + >a: s32 = 0; + if (argument_count != 0 and? argument_count != 2 and? argument_count != 3 or? argument_count != 1) + { + return 0; + } + else if (argument_count == 5 or? a == 0) + { + return 45; + } + else + { + return 1; + } +} + +FieldAccessLeftAssign = struct +{ + a: u32, + b: u32, +} + +field_access_left_assign = fn () void +{ + >s: FieldAccessLeftAssign = { + .a = 2, + .b = 3, + }; + + s.a = s.b + 1; + s.b = s.a + 2; + + require(s.a == 4); + require(s.b == 6); +} + +for_each = fn () void +{ + >array: [_]u32 = [5, 3, 2]; + >counter: u32 = 0; + for (e : array) + { + counter += e; + } + + require(counter == 10); + + for (&e : array) + { + e.& += 1; + } + + >new_counter: u32 = 0; + + for (e : array) + { + new_counter += e; + } + + require(new_counter == counter + array.length); +} + +pointer_decay = fn () s32 +{ + >array: [_]s32 = [1, 3, 5]; + >pointer: &s32 = &array[0]; + >index: u64 = 0; + pointer[index] = 0; + return pointer[index]; +} + +NameEnum = enum +{ + my_expected_result, + a, + b, +} + +[extern] memcmp = fn [cc(c)] (a: &u8, b: &u8, byte_count: u64) s32; + +string_equal = fn (slice_a: []u8, slice_b: []u8) u1 +{ + >result = slice_a.length == slice_b.length; + if (result) + { + result = memcmp(slice_a.pointer, slice_b.pointer, slice_a.length) == 0; + } + + return result; +} + +enum_name = fn () s32 +{ + >some_enum: NameEnum = .my_expected_result; + return @extend(!string_equal(@enum_name(some_enum), "my_expected_result")); +} + +join = fn (slice: []u8, parts: [][]u8) void +{ + >destination_i: u64 = 0; + + for (part: parts) + { + >source_i: u64 = 0; + + while (source_i < part.length) + { + slice[destination_i] = part[source_i]; + destination_i += 1; + source_i += 1; + } + } +} + +slice_of_slices = fn () s32 +{ + >a = "a"; + >b = "b"; + >ab = "ab"; + >buffer: [2]u8 = undefined; + >buffer_slice = buffer[..]; + join(buffer_slice, [ a, b ][..]); + + >result = memcmp(buffer_slice.pointer, ab.pointer, ab.length); + return result; +} + +int = typealias s32; + +type_alias = fn [cc(c)] () int +{ + return 0; +} + +integer_formats = fn () s32 +{ + >a: s32 = 0o10; + >b: s32 = 0b1000; + >c: s32 = 0d0; + return a - b + c; +} + +for_each_int = fn () s32 +{ + >top: s32 = 64; + >accumulator: s32 = 0; + for (i: 0..top) + { + accumulator += 1; + } + return accumulator - top; +} + +bool_array = fn () s32 +{ + >signs: [2]u1 = [0, 0]; + >accumulator: s32 = 0; + + for (s: signs) + { + accumulator += @extend(s); + } + + return accumulator; +} + +BasicUnion = union +{ + s: s32, + u: u32, +} + +basic_union = fn [cc(c)] () void +{ + >my_union: BasicUnion = { + .s = -1, + }; + require(my_union.s == -1); + require(my_union.u == 0xffffffff); +} + +break_continue = fn () s32 +{ + >a: s32 = 0; + + while (a < 10) + { + if (a == 3) + { + break; + } + + a += 1; + continue; + } + + >b: s32 = 2; + for (i: 0..10) + { + if (b == 2) + { + b += 1; + continue; + } + else + { + break; + } + } + + return a - b; +} + +i2315_abc: s32 = 5; +asjdkj = i2315_abc - i2315_abc; + +constant_global_reference = fn () s32 +{ + return asjdkj; +} + +is_space = fn (ch: u8) u1 +{ + return ch == ' ' or ch == '\n' or ch == '\t' or ch == '\r'; +} + +concat_logical_or = fn () s32 +{ + return @extend(is_space('f')); +} + +strict_array_type = fn () s32 +{ + >arr: [3]s32 = [3, 1, 0]; + return arr[2]; +} + +PointerStructInitialization = struct +{ + a: u16, + b: u8, + c: u8, + d: u32, +} + +pointer_struct_initialization = fn () void +{ + >s: PointerStructInitialization = zero; + + >p_s = &s; + p_s.& = { + .a = 1, + .b = 2, + .c = 3, + .d = 4, + }; + + require(s.a == 1); + require(s.b == 2); + require(s.c == 3); + require(s.d == 4); +} + +slice_array_literal_receiver = fn (slices: [][]u8) void +{ + require(slices.length == 3); +} + +slice_array_literal = fn () void +{ + >some_bool: u1 = 0; + slice_array_literal_receiver([ "abc", @select(some_bool, "bcd", "cbd"), "sas", ][..]); +} + +slice_only_start = fn () void +{ + >s = "abcde"; + >index: u64 = 3; + >s_sub = s[index..]; + require(s_sub[0] == 'd'); +} + +sub = macro (a: s32, b: s32) s32 +{ + return a - b; +} + +basic_macro = fn () s32 +{ + >a = sub(1, 1); + >b = sub(2, 2); + return a + b; +} + +sub_generic = macro [T] (a: T, b: T) T +{ + return a - b; +} + +generic_macro = fn () s32 +{ + >a = sub_generic[s32](1, 1); + >b = sub_generic[u8](2, 2); + return a + @extend(b); +} + +pointer_macro = macro [T] (ptr: &u32) &T +{ + return @pointer_cast(ptr); +} + +A = struct +{ + a: u32, +} + +B = struct +{ + b: u32, +} + +generic_pointer_macro = fn () void +{ + >var: u32 = 0; + >a = pointer_macro[A](&var); + >b = pointer_macro[B](&var); + a.a = 1; + require(b.b == 1); + require(var == 1); +} + +assert = macro (ok: u1) void +{ + if (!ok) + { + unreachable; + } +} + +align_forward = fn (value: u64, alignment: u64) u64 +{ + assert(alignment != 0); + >mask = alignment - 1; + >result = (value + mask) & ~mask; + return result; +} + +noreturn_macro = fn () void +{ + >result = align_forward(1, 64); + + if (result != 64) + { + @trap(); + } +} + +generic_pointer_array_macro = macro[T](addr: &u64, count: u64) []T +{ + >pointer: &T = @pointer_cast(addr); + return pointer[..count]; +} + +generic_pointer_array = fn () void +{ + >address_raw: u64 = 0xaaaaaaaaaaaaaaaa; + >some_var: &u64 = @pointer_from_int(address_raw); + >result: []&u8 = generic_pointer_array_macro[&u8](some_var, 1); + require(@int_from_pointer(result.pointer) == address_raw); + require(result.length == 1); +} + +SelfReferentialStruct = struct +{ + self: &SelfReferentialStruct, +} + +self_referential_struct = fn () void +{ + >s: SelfReferentialStruct = zero; + s.self = &s; + require(s.self == &s); +} + +ForwardDeclaredType = struct; +ForwardDeclaredTypeWrapper = struct +{ + forward: &ForwardDeclaredType, +} + +ForwardDeclaredType = struct +{ + f: ForwardDeclaredTypeWrapper, +} + +forward_declared_type = fn () void +{ + >f: ForwardDeclaredType = zero; + f.f.forward = &f; +} + +EnumArrayEnum = enum +{ + a, + b, + c, + d, +} + +enum_array = fn () void +{ + >some_enum_array: enum_array[EnumArrayEnum](u32) = [ .a = 4, .b = 3, .c = 2, .d = 1 ]; + require(some_enum_array[.a] == 4); + require(some_enum_array[.b] == 3); + require(some_enum_array[.c] == 2); + require(some_enum_array[.d] == 1); +} + +OpaqueType = opaque; + +[extern] memcpy = fn [cc(c)] (destination: &s32, source: &s32, size: u64) &OpaqueType; + +basic_opaque = fn () s32 +{ + >destination: s32 = 1; + >source: s32 = 0; + >opaque_pointer = memcpy(&destination, &source, @byte_size(s32)); + >pointer: &s32 = @pointer_cast(opaque_pointer); + if (pointer != &destination) + { + @trap(); + } + return destination; +} + +EnumArbitraryAbi = enum +{ + a, + b, + c, + d, +} + +enum_arbitrary_abi_function = fn (arg: EnumArbitraryAbi) EnumArbitraryAbi +{ + return arg; +} + +enum_arbitrary_abi = fn () void +{ + >some_e: EnumArbitraryAbi = .c; + >a = enum_arbitrary_abi_function(some_e); + >b = enum_arbitrary_abi_function(.d); + require(a == .c); + require(b == .d); +} + +TypeId = enum +{ + void, + noreturn, + forward_declaration, + integer, + function, + pointer, + array, + enum, + struct, + bits, + alias, + union, + unresolved, + vector, + floating_point, + enum_array, + opaque, +} + +Type = struct +{ + arr: [5]u32, + id: TypeId, + a: [2]u64, + b: u64, +} + +enum_debug_info = fn () void +{ + >t: Type = { + .id = .integer, + zero, + }; + t.arr[0] = 1; + t.arr[0] = 2; + t.arr[0] = 3; +} + +ReturnArrayEnum = enum +{ + a, + b, + c, + d, + e, + f, +} + +return_array_function = fn () [2]ReturnArrayEnum +{ + return [ .f, .e ]; +} + +return_array = fn () void +{ + >result = return_array_function(); + require(result[0] == .f); + require(result[1] == .e); +} + +BoolPair = struct +{ + a: u1, + b: u1, +} + +bool_pair_function = fn () BoolPair +{ + return { .a = 0, .b = 1 }; +} + +bool_pair = fn () void +{ + >result = bool_pair_function(); + require(!result.a); + require(result.b); +} + +min_max = fn () void +{ + >a: u32 = 1; + >b: u32 = 2; + >min = @min(a, b); + >max = @max(a, b); + require(min == a); + require(max == b); +} + +FieldParentPointerStruct = struct +{ + a: u8, + b: u32, + c: u8, +} + +field_parent_pointer = fn () void +{ + >s: FieldParentPointerStruct = { + .a = 241, + .b = 12356, + .c = 128, + }; + + >p_a = &s.a; + >p_a_struct: &FieldParentPointerStruct = @field_parent_pointer(p_a, "a"); + require(p_a_struct == &s); + require(p_a_struct.a == s.a); + require(p_a_struct.b == s.b); + require(p_a_struct.c == s.c); + + >p_b = &s.b; + >p_b_struct: &FieldParentPointerStruct = @field_parent_pointer(p_b, "b"); + require(p_b_struct == &s); + require(p_b_struct.a == s.a); + require(p_b_struct.b == s.b); + require(p_b_struct.c == s.c); + + >p_c = &s.c; + >p_c_struct: &FieldParentPointerStruct = @field_parent_pointer(p_c, "c"); + require(p_c_struct == &s); + require(p_c_struct.a == s.a); + require(p_c_struct.b == s.b); + require(p_c_struct.c == s.c); +} + +leading_trailing_zeroes = fn () void +{ + >a: u32 = 0b111; + require(@leading_zeroes(a) == 29); + require(@trailing_zeroes(a) == 0); + >b: u8 = 0b11010; + require(@leading_zeroes(b) == 3); + require(@trailing_zeroes(b) == 1); +} + +pointer_sub = fn () void +{ + >a: [_]s32 = [ 3, 1 ]; + >p0 = &a[0]; + >p1 = p0 + 1; + >sub: u32 = @truncate(p1 - p0); + require(sub == 1); +} + +[export] main = fn [cc(c)] (argc: s32, argv: &&u8, envp: &&u8) s32 +{ + >rc = return_constant(); + require(rc == 0); + + >const_add = constant_add(); + require(const_add == 0); + + >const_and = constant_and(); + require(const_and == 0); + + >const_div = constant_div(); + require(const_div == 0); + + >const_mul = constant_mul(); + require(const_mul == 0); + + >const_rem = constant_rem(); + require(const_rem == 0); + + >const_or = constant_or(); + require(const_or == 0); + + >const_sub = constant_sub(); + require(const_sub == 0); + + >const_xor = constant_xor(); + require(const_xor == 0); + + >const_shift_left = constant_shift_left(); + require(const_shift_left == 0); + + >const_shift_right = constant_shift_right(); + require(const_shift_right == 0); + + >min_stack = minimal_stack(); + require(min_stack == 0); + + >min_stack_arithmetic0 = minimal_stack_arithmetic0(); + require(min_stack_arithmetic0 == 0); + + >min_stack_arithmetic1 = minimal_stack_arithmetic1(); + require(min_stack_arithmetic1 == 0); + + >min_stack_arithmetic2 = minimal_stack_arithmetic2(); + require(min_stack_arithmetic2 == 0); + + >st_neg = stack_negation(); + require(st_neg == 0); + + >st_add = stack_add(); + require(st_add == 0); + + >st_sub = stack_sub(); + require(st_sub == 0); + + >ext = extend(); + require(ext == 0); + + >int_max = integer_max(); + require(int_max == 0); + + >int_hex = integer_hex(); + require(int_hex == 0); + + >b_pointer = basic_pointer(); + require(b_pointer == 0); + + >b_call = basic_call(); + require(b_call == 0); + + >b_branch = basic_branch(); + require(b_branch == 0); + + >b_array = basic_array(); + require(b_array == 0); + + >b_enum = basic_enum(); + require(b_enum == 0); + + basic_slice(); + + basic_string(); + + basic_varargs(); + + basic_while(argc, argv); + + >p = pointer(); + require(p == 0); + + >pc = pointer_cast(); + require(pc == 0); + + >u1_ret = u1_return(); + require(u1_ret == 0); + + >lti = local_type_inference(); + require(lti == 0); + + >bg = basic_global(); + require(bg == 0); + + >bfp = basic_function_pointer(); + require(bfp == 0); + + basic_extern(); + + basic_byte_size(); + + >assignment_ops = assignment_operators(); + require(assignment_ops == 0); + + >np = not_pointer(); + require(np == 0); + + basic_bits(); + + bits_no_backing_type(); + + bits_return_u1(); + + bits_zero(); + + basic_comparison(argc); + + basic_global_struct(); + + >if_ne = if_no_else(); + require(if_ne == 0); + + if_no_else_void(); + + basic_indirect(); + + indirect_varargs(); + + >rtb = return_type_builtin(); + require(rtb == 0); + + >rs6464 = return_struct_u64_u64(); + require(rs6464 == 0); + + >sel = select(); + require(sel == 0); + + slice2(argc, argv); + + struct_assignment(); + + >bs = basic_struct(); + require(bs == 0); + + struct_zero(); + + >bu = basic_unreachable(); + require(bu == 0); + + va_args(); + + enum_bool_struct(); + + c_abi_tests(); + + >s2e = string_to_enum(); + require(s2e == 0); + + >ei = empty_if(argc); + require(ei == 0); + + >eif = else_if(); + require(eif == 0); + + >ei_complicated = else_if_complicated(argc); + require(ei_complicated == 0); + + >basic_sif = basic_shortcircuiting_if(argc); + require(basic_sif == 0); + + >sif = shortcircuiting_if(argc); + require(sif == 0); + + field_access_left_assign(); + + for_each(); + + >pdecay = pointer_decay(); + require(pdecay == 0); + + >en = enum_name(); + require(en == 0); + + >sos = slice_of_slices(); + require(sos == 0); + + require(type_alias() == 0); + + >if = integer_formats(); + require(if == 0); + + >fei = for_each_int(); + require(fei == 0); + + >ba = bool_array(); + require(ba == 0); + + basic_union(); + + >bc = break_continue(); + require(bc == 0); + + >cgr = constant_global_reference(); + require(cgr == 0); + + >cc_logical_or = concat_logical_or(); + require(cc_logical_or == 0); + + >sat = strict_array_type(); + require(sat == 0); + + pointer_struct_initialization(); + + slice_array_literal(); + + slice_only_start(); + + >bm = basic_macro(); + require(bm == 0); + + >gm = generic_macro(); + require(gm == 0); + + generic_pointer_macro(); + + noreturn_macro(); + + generic_pointer_array(); + + self_referential_struct(); + + forward_declared_type(); + + enum_array(); + + >opq = basic_opaque(); + require(opq == 0); + + enum_arbitrary_abi(); + + enum_debug_info(); + + return_array(); + + bool_pair(); + + min_max(); + + field_parent_pointer(); + + leading_trailing_zeroes(); + + pointer_sub(); + + return 0; +} diff --git a/tests/type_alias.bbb b/tests/type_alias.bbb deleted file mode 100644 index 4ca70d3..0000000 --- a/tests/type_alias.bbb +++ /dev/null @@ -1,6 +0,0 @@ -int = typealias s32; - -[export] main = fn [cc(c)] () int -{ - return 0; -} diff --git a/tests/u1_return.bbb b/tests/u1_return.bbb deleted file mode 100644 index b7dee5c..0000000 --- a/tests/u1_return.bbb +++ /dev/null @@ -1,11 +0,0 @@ -foo = fn [cc(c)] () u1 -{ - >result: u1 = 0; - return result; -} - -[export] main = fn [cc(c)] () s32 -{ - >result = foo(); - return #extend(result); -} diff --git a/tests/unreachable.bbb b/tests/unreachable.bbb deleted file mode 100644 index d2c2e16..0000000 --- a/tests/unreachable.bbb +++ /dev/null @@ -1,9 +0,0 @@ -[export] main = fn [cc(c)] () s32 -{ - >result: s32 = 0; - if (result != 0) - { - unreachable; - } - return result; -} diff --git a/tests/varargs.bbb b/tests/varargs.bbb deleted file mode 100644 index 192af57..0000000 --- a/tests/varargs.bbb +++ /dev/null @@ -1,66 +0,0 @@ -S = struct -{ - a: u32, - b: u32, - c: u64, - d: u64, - e: u64 -} - -require = fn (ok: u1) void -{ - if (!ok) - { - #trap(); - } -} - -va_arg_function = fn [cc(c)] (first_arg: u32, ...) void -{ - >va = #va_start(); - - >a = #va_arg(&va, u32); - >b = #va_arg(&va, S); - >c = #va_arg(&va, s64); - >d = #va_arg(&va, s32); - - require(first_arg == 123456789); - require(a == 123); - require(c == -1); - require(d == -2); - require(b.a == 1); - require(b.b == 2); - require(b.c == 3); - require(b.d == 4); - require(b.e == 5); - - #va_end(&va); -} - -S2 = struct -{ - a: u64, - b: u64, -} - -va_arg_function2 = fn [cc(c)] (...) void -{ - >va = #va_start(); - >s2 = #va_arg(&va, S2); - require(s2.a == 8); - require(s2.b == 9); - #va_end(&va); -} - -[export] main = fn [cc(c)] () s32 -{ - >first_arg: u32 = 123456789; - >a: u32 = 123; - >b: S = { .a = 1, .b = 2, .c = 3, .d = 4, .e = 5 }; - >c: s64 = -1; - >d: s32 = -2; - va_arg_function(first_arg, a, b, c, d); - >s2: S2 = { .a = 8, .b = 9 }; - va_arg_function2(s2); - return 0; -}