2018-10-27 02:59:58 +08:00
|
|
|
const std = @import("std");
|
2019-02-09 07:18:47 +08:00
|
|
|
const expect = std.testing.expect;
|
2019-03-01 04:40:57 +08:00
|
|
|
const expectEqualSlices = std.testing.expectEqualSlices;
|
stage1: rework tokenizer to match stage2
* Extracts AstGen logic from ir.cpp into astgen.cpp. Reduces the
largest file of stage1 from 33,551 lines to 25,510.
* tokenizer: rework it completely to match the stage2 tokenizer logic.
They can now be maintained together; when one is changed, the other
can be changed in the same way.
- Each token now takes up 13 bytes instead of 64 bytes. The tokenizer
does not parse char literals, string literals, integer literals,
etc into meaningful data. Instead, that happens during parsing or
astgen.
- no longer store line offsets. Error messages scan source
files to find the line/column as needed (same as stage2).
- main loop: instead of checking the loop, handle a null byte
explicitly in the switch statements. This is a nice improvement
that we may want to backport to stage2.
- delete some dead tokens, artifacts of past syntax that no longer
exists.
* Parser: fix a TODO by parsing builtin functions as tokens rather than
`@` as a separate token. This is how stage2 does it.
* Remove some debugging infrastructure. These will need to be redone,
if at all, as the code migrates to match stage2.
- remove the ast_render code.
- remove the IR debugging stuff
- remove teh token printing code
2021-05-28 07:32:35 +08:00
|
|
|
const expectEqualStrings = std.testing.expectEqualStrings;
|
2018-10-27 02:59:58 +08:00
|
|
|
const mem = std.mem;
|
2017-05-02 01:12:38 +08:00
|
|
|
const builtin = @import("builtin");
|
2017-01-05 16:57:48 +08:00
|
|
|
|
2017-05-30 02:25:00 +08:00
|
|
|
// can't really run this test but we can make sure it has no compile error
|
|
|
|
// and generates code
|
2018-06-05 10:11:14 +08:00
|
|
|
const vram = @intToPtr([*]volatile u8, 0x20000000)[0..0x8000];
|
2018-01-25 17:10:11 +08:00
|
|
|
export fn writeToVRam() void {
|
2017-05-30 02:25:00 +08:00
|
|
|
vram[0] = 'X';
|
|
|
|
}
|
2017-08-30 12:17:11 +08:00
|
|
|
|
2018-11-13 21:08:37 +08:00
|
|
|
const PackedStruct = packed struct {
|
2018-05-01 08:35:54 +08:00
|
|
|
a: u8,
|
|
|
|
b: u8,
|
|
|
|
};
|
2018-11-13 21:08:37 +08:00
|
|
|
const PackedUnion = packed union {
|
2018-05-01 08:35:54 +08:00
|
|
|
a: u8,
|
|
|
|
b: u32,
|
|
|
|
};
|
2018-01-29 23:57:09 +08:00
|
|
|
|
|
|
|
test "packed struct, enum, union parameters in extern function" {
|
2018-11-13 21:08:37 +08:00
|
|
|
testPackedStuff(&(PackedStruct{
|
2018-05-01 08:35:54 +08:00
|
|
|
.a = 1,
|
|
|
|
.b = 2,
|
2021-06-14 03:27:27 +08:00
|
|
|
}), &(PackedUnion{ .a = 1 }));
|
2018-01-29 23:57:09 +08:00
|
|
|
}
|
2018-03-07 06:19:45 +08:00
|
|
|
|
2021-06-20 09:10:22 +08:00
|
|
|
export fn testPackedStuff(a: *const PackedStruct, b: *const PackedUnion) void {
|
|
|
|
if (false) {
|
|
|
|
a;
|
|
|
|
b;
|
|
|
|
}
|
|
|
|
}
|
2022-03-02 14:46:57 +08:00
|
|
|
|
|
|
|
test "exporting enum type and value" {
|
|
|
|
const S = struct {
|
|
|
|
const E = enum(c_int) { one, two };
|
|
|
|
const e: E = .two;
|
|
|
|
comptime {
|
|
|
|
@export(e, .{ .name = "e" });
|
|
|
|
}
|
|
|
|
};
|
|
|
|
try expect(S.e == .two);
|
|
|
|
}
|
2022-04-25 11:07:39 +08:00
|
|
|
|
|
|
|
test "exporting with internal linkage" {
|
|
|
|
const S = struct {
|
|
|
|
fn foo() callconv(.C) void {}
|
|
|
|
comptime {
|
|
|
|
@export(foo, .{ .name = "exporting_with_internal_linkage_foo", .linkage = .Internal });
|
|
|
|
}
|
|
|
|
};
|
|
|
|
S.foo();
|
|
|
|
}
|