Dream of my own C compiler
This commit is contained in:
32
packages/cjit/test/root.zig
Normal file
32
packages/cjit/test/root.zig
Normal file
@@ -0,0 +1,32 @@
|
||||
const std = @import("std");
|
||||
const cjit = @import("cjit");
|
||||
|
||||
fn add(a: i32, b: i32) callconv(cjit.call) i32 {
|
||||
return a + b;
|
||||
}
|
||||
|
||||
test {
|
||||
var rt: cjit.Runtime = .init(std.testing.allocator);
|
||||
defer rt.deinit();
|
||||
|
||||
try rt.compile(
|
||||
\\int add(int a, int b);
|
||||
\\
|
||||
\\int add_one(int x)
|
||||
\\{
|
||||
\\ return add(x, 1);
|
||||
\\}
|
||||
);
|
||||
|
||||
try rt.setSymbol(fn (i32, i32) callconv(cjit.call) i32, "add", &add);
|
||||
try rt.link();
|
||||
|
||||
const add_one = rt.getSymbol(fn (i32) callconv(cjit.call) i32, "add_one").?;
|
||||
|
||||
try std.testing.expectEqual(-9, add_one(-10));
|
||||
try std.testing.expectEqual(11, add_one(10));
|
||||
|
||||
const add_ptr = rt.getSymbol(fn (i32, i32) callconv(cjit.call) i32, "add").?;
|
||||
|
||||
try std.testing.expectEqual(add_ptr, &add);
|
||||
}
|
||||
Reference in New Issue
Block a user