align with new @hide syntax
This commit is contained in:
+2
-1
@@ -9,7 +9,8 @@
|
||||
import "@std/debug"
|
||||
import "@source/lexer"
|
||||
|
||||
hide(file) TokenId :: alias lexer.TokenId
|
||||
@hide:file
|
||||
TokenId :: alias lexer.TokenId
|
||||
|
||||
NodeId :: distinct u32
|
||||
ExtraId :: distinct u32
|
||||
|
||||
@@ -6,11 +6,20 @@ import "@source/lexer"
|
||||
import "@source/parser"
|
||||
import "@source/ast"
|
||||
|
||||
hide(file) TokenId :: alias lexer.TokenId
|
||||
hide(file) Token :: alias lexer.Token
|
||||
hide(file) Node :: alias ast.Node
|
||||
hide(file) NodeId :: alias ast.NodeId
|
||||
hide(file) ParseState :: alias parser.State
|
||||
@hide:file
|
||||
TokenId :: alias lexer.TokenId
|
||||
|
||||
@hide:file
|
||||
Token :: alias lexer.Token
|
||||
|
||||
@hide:file
|
||||
Node :: alias ast.Node
|
||||
|
||||
@hide:file
|
||||
NodeId :: alias ast.NodeId
|
||||
|
||||
@hide:file
|
||||
ParseState :: alias parser.State
|
||||
|
||||
Renderer :: struct { tokens std.ArrayList(Token) }
|
||||
|
||||
@@ -38,7 +47,8 @@ render proc(
|
||||
}
|
||||
}
|
||||
|
||||
hide render_decl proc(
|
||||
@hide:file
|
||||
render_decl proc(
|
||||
renderer @mut Renderer,
|
||||
node_id NodeId,
|
||||
parse_state @ParseState,
|
||||
@@ -68,7 +78,8 @@ hide render_decl proc(
|
||||
) try arraylist.append(&renderer.tokens, tokens[eof_idx])
|
||||
}
|
||||
|
||||
hide render_expr proc(renderer @mut Renderer,
|
||||
@hide:file
|
||||
render_expr proc(renderer @mut Renderer,
|
||||
node_id NodeId,
|
||||
parse_state @ParseState,
|
||||
tokens []Token,
|
||||
@@ -87,7 +98,8 @@ hide render_expr proc(renderer @mut Renderer,
|
||||
}
|
||||
}
|
||||
|
||||
hide render_type proc(
|
||||
@hide:file
|
||||
render_type proc(
|
||||
renderer @mut Renderer,
|
||||
node_id NodeId,
|
||||
parse_state @ParseState,
|
||||
@@ -104,7 +116,8 @@ hide render_type proc(
|
||||
}
|
||||
}
|
||||
|
||||
hide render_lit proc(
|
||||
@hide:file
|
||||
render_lit proc(
|
||||
renderer @mut Renderer,
|
||||
node_id NodeId,
|
||||
parse_state @ParseState,
|
||||
|
||||
+10
-5
@@ -278,30 +278,35 @@ scan_string proc(start usize, program []u8) ScanStrResult ! ScanError {
|
||||
}
|
||||
}
|
||||
|
||||
hide is_whitespace proc(char u8) bool {
|
||||
@hide
|
||||
is_whitespace proc(char u8) bool {
|
||||
return char == ' ' or char == '\t' or char == '\n' or char == '\r'
|
||||
}
|
||||
|
||||
hide is_alpha proc(char u8) bool {
|
||||
@hide
|
||||
is_alpha proc(char u8) bool {
|
||||
return match char {
|
||||
'a'..='z', 'A'..='Z': true
|
||||
else: false
|
||||
}
|
||||
}
|
||||
|
||||
hide is_digit proc(char u8) bool {
|
||||
@hide
|
||||
is_digit proc(char u8) bool {
|
||||
return match char {
|
||||
'0'..='9': true
|
||||
else: false
|
||||
}
|
||||
}
|
||||
|
||||
hide add_token proc(tokens @mut std.ArrayList(Token), token Token) void ! mem.AllocError {
|
||||
@hide
|
||||
add_token proc(tokens @mut std.ArrayList(Token), token Token) void ! mem.AllocError {
|
||||
_ = token_id(tokens.items.len)
|
||||
try arraylist.append(tokens, token)
|
||||
}
|
||||
|
||||
hide token_id proc(idx uint) TokenId {
|
||||
@hide
|
||||
token_id proc(idx uint) TokenId {
|
||||
debug.assert(u64(idx) < u64(maxval!(TokenId)))
|
||||
return TokenId(idx)
|
||||
}
|
||||
|
||||
+2
-4
@@ -6,6 +6,7 @@ test import "@std/enums/enummap"
|
||||
test import "@std/arraylist"
|
||||
test import "@std/hashmap"
|
||||
test import "@std/strmap"
|
||||
test import "@std/meta"
|
||||
|
||||
import "@source/strpool"
|
||||
import "@source/lexer"
|
||||
@@ -17,7 +18,6 @@ test import "@source/strpool"
|
||||
test import "@source/lexer"
|
||||
test import "@source/parser"
|
||||
|
||||
|
||||
program ::
|
||||
`# literals
|
||||
`x int :: 123.9
|
||||
@@ -81,8 +81,6 @@ main proc() void! {
|
||||
try ast_renderer.render(&renderer, root, &parse_state, scan_state.tokens.items)
|
||||
|
||||
debug.print("AST Render::[[\n", {})
|
||||
for renderer.tokens.items |tok| {
|
||||
debug.print("{}\n", {tok.kind})
|
||||
}
|
||||
for (renderer.tokens.items) |tok| debug.print("{}\n", {tok.kind})
|
||||
debug.print("]]\n", {})
|
||||
}
|
||||
|
||||
+31
-15
@@ -31,16 +31,32 @@ error_msg_map std.EnumMap(ErrorCode, ErrorDetails) :: enummap.init({
|
||||
},
|
||||
})
|
||||
|
||||
hide(file) Token :: alias lexer.Token
|
||||
hide(file) TokenId :: alias lexer.TokenId
|
||||
hide(file) TokenKind :: alias lexer.TokenKind
|
||||
hide(file) Node :: alias ast.Node
|
||||
hide(file) NodeId :: alias ast.NodeId
|
||||
hide(file) ExtraId :: alias ast.ExtraId
|
||||
hide(file) NodeData :: alias ast.NodeData
|
||||
@hide:file
|
||||
Token :: alias lexer.Token
|
||||
|
||||
hide(file) NO_ID_NODE :: alias ast.NO_ID_NODE
|
||||
hide(file) NO_ID_EXTRA :: alias ast.NO_ID_EXTRA
|
||||
@hide:file
|
||||
TokenId :: alias lexer.TokenId
|
||||
|
||||
@hide:file
|
||||
TokenKind :: alias lexer.TokenKind
|
||||
|
||||
@hide:file
|
||||
Node :: alias ast.Node
|
||||
|
||||
@hide:file
|
||||
NodeId :: alias ast.NodeId
|
||||
|
||||
@hide:file
|
||||
ExtraId :: alias ast.ExtraId
|
||||
|
||||
@hide:file
|
||||
NodeData :: alias ast.NodeData
|
||||
|
||||
@hide:file
|
||||
NO_ID_NODE :: alias ast.NO_ID_NODE
|
||||
|
||||
@hide:file
|
||||
NO_ID_EXTRA :: alias ast.NO_ID_EXTRA
|
||||
|
||||
State :: struct {
|
||||
nodes std.ArrayList(Node)
|
||||
@@ -135,34 +151,34 @@ parse_primary proc(state @mut State) NodeId ! mem.AllocError {
|
||||
}
|
||||
}
|
||||
|
||||
hide expect proc(state @mut State, token_kind TokenKind) void ! ErrorCode {
|
||||
expect proc(state @mut State, token_kind TokenKind) void ! ErrorCode {
|
||||
if (state.tokens[state.next_token].kind != token_kind) return .unexpected_token
|
||||
}
|
||||
|
||||
hide expect_either proc(state @mut State, token_kinds []TokenKind) void ! ErrorCode {
|
||||
expect_either proc(state @mut State, token_kinds []TokenKind) void ! ErrorCode {
|
||||
for (token_kinds) |kind| if (state.tokens[state.next_token].kind == kind) return
|
||||
return .unexpected_token
|
||||
}
|
||||
|
||||
hide consume proc(state @mut State, token_kind TokenKind) TokenId ! ErrorCode {
|
||||
consume proc(state @mut State, token_kind TokenKind) TokenId ! ErrorCode {
|
||||
try expect(state, token_kind)
|
||||
state.next_token += 1
|
||||
return state.next_token - 1
|
||||
}
|
||||
|
||||
hide consume_either proc(state @mut State, token_kinds []TokenKind) TokenId ! ErrorCode {
|
||||
consume_either proc(state @mut State, token_kinds []TokenKind) TokenId ! ErrorCode {
|
||||
try expect_either(state, token_kinds)
|
||||
state.next_token += 1
|
||||
return state.next_token - 1
|
||||
}
|
||||
|
||||
hide add_node proc(nodes @mut std.ArrayList(Node), node Node) NodeId ! mem.AllocError {
|
||||
add_node proc(nodes @mut std.ArrayList(Node), node Node) NodeId ! mem.AllocError {
|
||||
id :: ast.node_id(nodes.items.len)
|
||||
try arraylist.append(nodes, node)
|
||||
return id
|
||||
}
|
||||
|
||||
hide add_extra proc(extra @mut std.ArrayList(u32), data u32) ExtraId ! mem.AllocError {
|
||||
add_extra proc(extra @mut std.ArrayList(u32), data u32) ExtraId ! mem.AllocError {
|
||||
id :: ast.extra_id(extra.items.len)
|
||||
try arraylist.append(extra, data)
|
||||
return id
|
||||
|
||||
@@ -23,7 +23,7 @@ deinit proc($T type, list @mut ArrayList(T)) void {
|
||||
list.capacity = 0
|
||||
}
|
||||
|
||||
hide reserve proc($T type, list @mut ArrayList(T), min_capacity usize) void ! mem.AllocError {
|
||||
reserve proc($T type, list @mut ArrayList(T), min_capacity usize) void ! mem.AllocError {
|
||||
if min_capacity <= list.capacity {
|
||||
return
|
||||
}
|
||||
|
||||
+2
-1
@@ -14,7 +14,8 @@ print proc($format []u8, $Args type, args Args) void {
|
||||
io.print(writer, format, Args, args) catch |_| {}
|
||||
}
|
||||
|
||||
hide write proc(_ ?@mut anyopaque, handle io.Handle, bytes []u8) usize ! io.WriteError {
|
||||
@hide
|
||||
write proc(_ ?@mut anyopaque, handle io.Handle, bytes []u8) usize ! io.WriteError {
|
||||
request := bytes.len
|
||||
maximum :: usize(maxval!(c_long))
|
||||
if request > maximum {
|
||||
|
||||
@@ -132,7 +132,8 @@ put proc(
|
||||
}
|
||||
}
|
||||
|
||||
hide normalize proc(hash usize) usize {
|
||||
@hide
|
||||
normalize proc(hash usize) usize {
|
||||
# mapping both 0 and 1 to 1 is safe because equality resolves
|
||||
# collisions (since hash and key must both be equal).
|
||||
if (hash == 0) return 1
|
||||
@@ -141,7 +142,8 @@ hide normalize proc(hash usize) usize {
|
||||
|
||||
#! FNV-1a hash implementation.
|
||||
#! note: vulnerable to collision attacks.
|
||||
hide str_hash proc(key []u8) usize {
|
||||
@hide
|
||||
str_hash proc(key []u8) usize {
|
||||
hash u32 := 2166136261 # offset basis
|
||||
prime u32 := 16777619
|
||||
|
||||
@@ -153,4 +155,5 @@ hide str_hash proc(key []u8) usize {
|
||||
return usize(hash)
|
||||
}
|
||||
|
||||
hide str_eql proc(a, b []u8) bool { return mem.eql(a, b) }
|
||||
@hide
|
||||
str_eql proc(a, b []u8) bool { return mem.eql(a, b) }
|
||||
|
||||
+9
-9
@@ -44,7 +44,7 @@ writer proc(file File) Writer {
|
||||
}
|
||||
}
|
||||
|
||||
hide system_read proc(_ ?@mut anyopaque, handle Handle, buffer []mut u8) usize ! ReadError {
|
||||
@hide system_read proc(_ ?@mut anyopaque, handle Handle, buffer []mut u8) usize ! ReadError {
|
||||
request := buffer.len
|
||||
maximum usize :: usize(maxval!(c_long))
|
||||
if (request > maximum) request = maximum
|
||||
@@ -60,7 +60,7 @@ hide system_read proc(_ ?@mut anyopaque, handle Handle, buffer []mut u8) usize !
|
||||
}
|
||||
}
|
||||
|
||||
hide system_write proc(_ ?@mut anyopaque, handle Handle, bytes []u8) usize ! WriteError {
|
||||
@hide system_write proc(_ ?@mut anyopaque, handle Handle, bytes []u8) usize ! WriteError {
|
||||
request := bytes.len
|
||||
maximum usize :: usize(maxval!(c_long))
|
||||
if (request > maximum) request = maximum
|
||||
@@ -76,7 +76,7 @@ hide system_write proc(_ ?@mut anyopaque, handle Handle, bytes []u8) usize ! Wri
|
||||
}
|
||||
}
|
||||
|
||||
hide system_open proc(_ ?@mut anyopaque, path [;0]u8, mode FileMode) Handle ! OpenError {
|
||||
@hide system_open proc(_ ?@mut anyopaque, path [;0]u8, mode FileMode) Handle ! OpenError {
|
||||
flags := c.O_RDONLY
|
||||
match mode {
|
||||
.read_only: flags = c.O_RDONLY
|
||||
@@ -90,23 +90,23 @@ hide system_open proc(_ ?@mut anyopaque, path [;0]u8, mode FileMode) Handle ! Op
|
||||
}
|
||||
}
|
||||
|
||||
hide system_close proc(_ ?@mut anyopaque, handle Handle) void ! CloseError {
|
||||
@hide system_close proc(_ ?@mut anyopaque, handle Handle) void ! CloseError {
|
||||
if (c.close(handle.file_desc) != 0) return .close_failed
|
||||
}
|
||||
|
||||
hide system_stdin proc(_ ?@mut anyopaque) Handle {
|
||||
@hide system_stdin proc(_ ?@mut anyopaque) Handle {
|
||||
return Handle{ file_desc = c_int(Stream.stdin) }
|
||||
}
|
||||
|
||||
hide system_stdout proc(_ ?@mut anyopaque) Handle {
|
||||
@hide system_stdout proc(_ ?@mut anyopaque) Handle {
|
||||
return Handle{ file_desc = c_int(Stream.stdout) }
|
||||
}
|
||||
|
||||
hide system_stderr proc(_ ?@mut anyopaque) Handle {
|
||||
@hide system_stderr proc(_ ?@mut anyopaque) Handle {
|
||||
return Handle{ file_desc = c_int(Stream.stderr) }
|
||||
}
|
||||
|
||||
hide system_vtable IoVTable :: IoVTable {
|
||||
@hide system_vtable IoVTable :: IoVTable {
|
||||
read = system_read,
|
||||
write = system_write,
|
||||
open = system_open,
|
||||
@@ -116,7 +116,7 @@ hide system_vtable IoVTable :: IoVTable {
|
||||
stderr = system_stderr,
|
||||
}
|
||||
|
||||
hide system proc() Io {
|
||||
@hide system proc() Io {
|
||||
return Io {
|
||||
context = null,
|
||||
vtable = &system_vtable,
|
||||
|
||||
+26
-13
@@ -119,7 +119,8 @@ print proc(output Writer, $format []u8, $Args type, args Args) void ! WriteError
|
||||
}
|
||||
}
|
||||
|
||||
hide write_integer_signed proc(output Writer, value i64, base u64, uppercase bool) void ! WriteError {
|
||||
@hide:file
|
||||
write_integer_signed proc(output Writer, value i64, base u64, uppercase bool) void ! WriteError {
|
||||
buffer [65]mut u8 := undefined
|
||||
end := buffer.len
|
||||
current := value
|
||||
@@ -150,7 +151,8 @@ hide write_integer_signed proc(output Writer, value i64, base u64, uppercase boo
|
||||
try write_all(output, buffer[end..])
|
||||
}
|
||||
|
||||
hide write_integer_unsigned proc(output Writer, value u64, base u64, uppercase bool) void ! WriteError {
|
||||
@hide:file
|
||||
write_integer_unsigned proc(output Writer, value u64, base u64, uppercase bool) void ! WriteError {
|
||||
buffer [65]mut u8 := undefined
|
||||
end := buffer.len
|
||||
current := value
|
||||
@@ -173,7 +175,8 @@ hide write_integer_unsigned proc(output Writer, value u64, base u64, uppercase b
|
||||
try write_all(output, buffer[end..])
|
||||
}
|
||||
|
||||
hide FormatTokenKind :: enum {
|
||||
@hide:file
|
||||
FormatTokenKind :: enum {
|
||||
unused
|
||||
literal
|
||||
default
|
||||
@@ -187,14 +190,16 @@ hide FormatTokenKind :: enum {
|
||||
scientific
|
||||
}
|
||||
|
||||
hide FormatToken :: struct {
|
||||
@hide:file
|
||||
FormatToken :: struct {
|
||||
kind FormatTokenKind
|
||||
start usize
|
||||
end usize
|
||||
field []u8
|
||||
}
|
||||
|
||||
hide parse_format proc($N usize, $format []u8, $Args type) [N]mut FormatToken {
|
||||
@hide:file
|
||||
parse_format proc($N usize, $format []u8, $Args type) [N]mut FormatToken {
|
||||
tokens [N]mut FormatToken := undefined
|
||||
for (usize(0))..format.len |index| {
|
||||
tokens[index] = FormatToken{ kind = .unused, start = 0, end = 0, field = "" }
|
||||
@@ -321,18 +326,21 @@ hide parse_format proc($N usize, $format []u8, $Args type) [N]mut FormatToken {
|
||||
return tokens
|
||||
}
|
||||
|
||||
hide format_field_name proc($T type, index usize) []u8 {
|
||||
@hide:file
|
||||
format_field_name proc($T type, index usize) []u8 {
|
||||
match typeinfo!(T) {
|
||||
.record |r|: return r.fields[index].name
|
||||
else: compile_error!("io.print arguments must be a tuple")
|
||||
}
|
||||
}
|
||||
|
||||
hide distinct_value proc($Backing, $Distinct type, value Distinct) Backing {
|
||||
@hide:file
|
||||
distinct_value proc($Backing, $Distinct type, value Distinct) Backing {
|
||||
return ptrcast!(Backing, &value)^
|
||||
}
|
||||
|
||||
hide scalar_or_distinct_type proc($T type) bool {
|
||||
@hide:file
|
||||
scalar_or_distinct_type proc($T type) bool {
|
||||
match typeinfo!(T) {
|
||||
.bool: return true
|
||||
.integer: return true
|
||||
@@ -342,7 +350,8 @@ hide scalar_or_distinct_type proc($T type) bool {
|
||||
}
|
||||
}
|
||||
|
||||
hide write_integer proc(output Writer, $T type, value T, base u64, uppercase bool) void ! WriteError {
|
||||
@hide:file
|
||||
write_integer proc(output Writer, $T type, value T, base u64, uppercase bool) void ! WriteError {
|
||||
match typeinfo!(T) {
|
||||
.integer: if minval!(T) < 0 {
|
||||
try write_integer_signed(output, i64(value), base, uppercase)
|
||||
@@ -359,7 +368,8 @@ hide write_integer proc(output Writer, $T type, value T, base u64, uppercase boo
|
||||
}
|
||||
|
||||
# note: libc keeps float formatting small; replace it with a native shortest-roundtrip writer if locale independence matters.
|
||||
hide write_float proc(output Writer, $T type, value T, scientific bool) void ! WriteError {
|
||||
@hide:file
|
||||
write_float proc(output Writer, $T type, value T, scientific bool) void ! WriteError {
|
||||
match typeinfo!(T) {
|
||||
.float: {
|
||||
buffer [64]mut u8 := undefined
|
||||
@@ -384,7 +394,8 @@ hide write_float proc(output Writer, $T type, value T, scientific bool) void ! W
|
||||
}
|
||||
}
|
||||
|
||||
hide write_decimal proc(output Writer, $T type, value T) void ! WriteError {
|
||||
@hide:file
|
||||
write_decimal proc(output Writer, $T type, value T) void ! WriteError {
|
||||
match typeinfo!(T) {
|
||||
.integer: try write_integer(output, value, 10, false)
|
||||
.float: try write_float(output, value, false)
|
||||
@@ -397,7 +408,8 @@ hide write_decimal proc(output Writer, $T type, value T) void ! WriteError {
|
||||
}
|
||||
}
|
||||
|
||||
hide write_character proc(output Writer, $T type, value T) void ! WriteError {
|
||||
@hide:file
|
||||
write_character proc(output Writer, $T type, value T) void ! WriteError {
|
||||
match typeinfo!(T) {
|
||||
.integer: {
|
||||
if minval!(T) < 0 or maxval!(T) > 255 {
|
||||
@@ -415,7 +427,8 @@ hide write_character proc(output Writer, $T type, value T) void ! WriteError {
|
||||
}
|
||||
}
|
||||
|
||||
hide write_default proc(output Writer, $T type, value T) void ! WriteError {
|
||||
@hide:file
|
||||
write_default proc(output Writer, $T type, value T) void ! WriteError {
|
||||
match typeinfo!(T) {
|
||||
.bool: if value {
|
||||
try write_all(output, "true")
|
||||
|
||||
+14
-7
@@ -116,11 +116,14 @@ empty proc($T type) []mut T {
|
||||
return empty_slice(T, 0)
|
||||
}
|
||||
|
||||
hide empty_storage [1]mut u64 := [0]
|
||||
@hide
|
||||
empty_storage [1]mut u64 := [0]
|
||||
|
||||
hide malloc_alignment usize :: 16 # note: aarch64-macos libc malloc alignment assumption.
|
||||
@hide
|
||||
malloc_alignment usize :: 16 # note: aarch64-macos libc malloc alignment assumption.
|
||||
|
||||
hide power_of_two proc(value usize) bool {
|
||||
@hide:file
|
||||
power_of_two proc(value usize) bool {
|
||||
if (value == 0) return false
|
||||
current := value
|
||||
while current > 1 {
|
||||
@@ -131,7 +134,8 @@ hide power_of_two proc(value usize) bool {
|
||||
return true
|
||||
}
|
||||
|
||||
hide c_alloc proc(_ ?@mut anyopaque, size usize, alignment usize) ?*mut u8 {
|
||||
@hide:file
|
||||
c_alloc proc(_ ?@mut anyopaque, size usize, alignment usize) ?*mut u8 {
|
||||
if (power_of_two(alignment) == false) return null
|
||||
if (alignment <= malloc_alignment) return ptrcast!(u8, c.malloc(c_ulong(size)))
|
||||
|
||||
@@ -142,7 +146,8 @@ hide c_alloc proc(_ ?@mut anyopaque, size usize, alignment usize) ?*mut u8 {
|
||||
return ptrcast!(u8, memory[0])
|
||||
}
|
||||
|
||||
hide c_realloc proc(
|
||||
@hide:file
|
||||
c_realloc proc(
|
||||
_ ?@mut anyopaque,
|
||||
memory ?*mut u8,
|
||||
old_size usize,
|
||||
@@ -174,11 +179,13 @@ hide c_realloc proc(
|
||||
return c_alloc(null, new_size, alignment)
|
||||
}
|
||||
|
||||
hide c_free proc(_ ?@mut anyopaque, memory ?*mut u8, _ usize, _ usize) void {
|
||||
@hide:file
|
||||
c_free proc(_ ?@mut anyopaque, memory ?*mut u8, _ usize, _ usize) void {
|
||||
c.free(memory)
|
||||
}
|
||||
|
||||
hide c_vtable AllocatorVTable :: AllocatorVTable {
|
||||
@hide:file
|
||||
c_vtable AllocatorVTable :: AllocatorVTable {
|
||||
alloc = c_alloc,
|
||||
realloc = c_realloc,
|
||||
free = c_free,
|
||||
|
||||
+23
-25
@@ -1,4 +1,4 @@
|
||||
testing :: import "@std/testing"
|
||||
import "@std/testing"
|
||||
|
||||
TestTokenKind :: enum(u8) {
|
||||
ident = 3
|
||||
@@ -12,20 +12,21 @@ TestInner :: distinct u16
|
||||
TestOuter :: distinct TestInner
|
||||
TestOuterAlias :: alias TestOuter
|
||||
|
||||
|
||||
hide array_info_matches proc($Array, $Child type, $len usize) bool {
|
||||
match typeinfo!(Array) {
|
||||
.array |info|: return info.child == Child and info.len == len
|
||||
else: return false
|
||||
}
|
||||
}
|
||||
hide distinct_info_matches proc($Distinct, $Backing type) bool {
|
||||
match typeinfo!(Distinct) {
|
||||
.distinct |backing|: return backing == Backing
|
||||
else: return false
|
||||
@hide
|
||||
array_info_matches proc($Array, $Child type, $len usize) bool {
|
||||
return match typeinfo!(Array) {
|
||||
.array |info|: info.child == Child and info.len == len
|
||||
else: false
|
||||
}
|
||||
}
|
||||
|
||||
@hide
|
||||
distinct_info_matches proc($Distinct, $Backing type) bool {
|
||||
return match typeinfo!(Distinct) {
|
||||
.distinct |backing|: backing == Backing
|
||||
else: false
|
||||
}
|
||||
}
|
||||
|
||||
array_reflection_exposes_child_and_logical_length test {
|
||||
try testing.expect($(array_info_matches([4]i32, i32, 4)))
|
||||
@@ -34,34 +35,31 @@ array_reflection_exposes_child_and_logical_length test {
|
||||
try testing.expect($(array_info_matches([2]mut i64, i64, 2)))
|
||||
try testing.expect($(array_info_matches([2;0]u8, u8, 2)))
|
||||
}
|
||||
|
||||
distinct_reflection_exposes_immediate_backing test {
|
||||
try testing.expect($(distinct_info_matches(TestInner, u16)))
|
||||
try testing.expect($(distinct_info_matches(TestOuter, TestInner)))
|
||||
try testing.expect($(distinct_info_matches(TestOuterAlias, TestInner)))
|
||||
}
|
||||
|
||||
|
||||
enum_field_struct_defaults test {
|
||||
names TestNames := {
|
||||
ident = "identifier",
|
||||
int = "integer",
|
||||
}
|
||||
if field!(names, "ident") |value| {
|
||||
|
||||
if (field!(names, "ident")) |value|
|
||||
try testing.expect(value.len == 10)
|
||||
} else {
|
||||
else
|
||||
try testing.expect(false)
|
||||
}
|
||||
if field!(names, "int") |value| {
|
||||
|
||||
if (field!(names, "int")) |value|
|
||||
try testing.expect(value.len == 7)
|
||||
} else {
|
||||
else
|
||||
try testing.expect(false)
|
||||
}
|
||||
if field!(names, "eof") |_| {
|
||||
try testing.expect(false)
|
||||
}
|
||||
|
||||
if (field!(names, "eof")) |_| try testing.expect(false)
|
||||
|
||||
empty TestNames := {}
|
||||
if field!(empty, "ident") |_| {
|
||||
try testing.expect(false)
|
||||
}
|
||||
if (field!(empty, "ident")) |_| try testing.expect(false)
|
||||
}
|
||||
|
||||
@@ -10,7 +10,8 @@ StringMap proc($V type) type {
|
||||
}
|
||||
}
|
||||
|
||||
hide Pair proc($V type) type {
|
||||
@hide:file
|
||||
Pair proc($V type) type {
|
||||
return struct { []u8, V }
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user