|
1 | 1 | const std = @import("std");
|
2 | 2 | const heap = std.heap;
|
| 3 | +const builtin = @import("builtin"); |
3 | 4 | const token = @import("lexer").token;
|
4 | 5 | const codegen = @import("codegen");
|
5 | 6 | const lexer = @import("lexer");
|
6 | 7 | const parser = @import("parser");
|
7 | 8 | const utils = @import("utils");
|
8 | 9 | const cli = @import("cli");
|
9 | 10 |
|
| 11 | +var debug_allocator: heap.DebugAllocator(.{}) = .init; |
| 12 | + |
10 | 13 | fn print_error_and_exit(err: anyerror) noreturn {
|
11 | 14 | const stderr = std.io.getStdErr().writer();
|
12 | 15 |
|
@@ -38,9 +41,17 @@ fn print_error_and_exit(err: anyerror) noreturn {
|
38 | 41 | }
|
39 | 42 |
|
40 | 43 | pub fn main() void {
|
41 |
| - var gpa = heap.DebugAllocator(.{ .thread_safe = true, .safety = true }){}; |
42 |
| - defer _ = gpa.deinit(); |
43 |
| - var arena = heap.ArenaAllocator.init(gpa.allocator()); |
| 44 | + const gpa, const is_debug = blk: { |
| 45 | + if (builtin.target.os.tag == .wasi) break :blk .{ heap.wasm_allocator, false }; |
| 46 | + break :blk switch (builtin.mode) { |
| 47 | + .Debug, .ReleaseSafe => .{ debug_allocator.allocator(), true }, |
| 48 | + .ReleaseFast, .ReleaseSmall => .{ heap.smp_allocator, false }, |
| 49 | + }; |
| 50 | + }; |
| 51 | + defer if (is_debug) { |
| 52 | + _ = debug_allocator.deinit(); |
| 53 | + }; |
| 54 | + var arena = heap.ArenaAllocator.init(gpa); |
44 | 55 | defer arena.deinit();
|
45 | 56 | const global_allocator = arena.allocator();
|
46 | 57 |
|
|
0 commit comments