This commit is contained in:
gingerBill
2021-12-28 14:05:18 +00:00
9 changed files with 54 additions and 10 deletions
+1
View File
@@ -711,6 +711,7 @@ Union_Type :: struct {
poly_params: ^Field_List,
align: ^Expr,
is_maybe: bool,
is_no_nil: bool,
where_token: tokenizer.Token,
where_clauses: []^Expr,
variants: []^Expr,
+8
View File
@@ -888,6 +888,7 @@ parse_for_stmt :: proc(p: ^Parser) -> ^ast.Stmt {
error(p, body.pos, "the body of a 'do' must be on the same line as the 'for' token")
}
} else {
allow_token(p, .Semicolon)
body = parse_body(p)
}
@@ -2600,6 +2601,7 @@ parse_operand :: proc(p: ^Parser, lhs: bool) -> ^ast.Expr {
poly_params: ^ast.Field_List
align: ^ast.Expr
is_maybe: bool
is_no_nil: bool
if allow_token(p, .Open_Paren) {
param_count: int
@@ -2626,6 +2628,11 @@ parse_operand :: proc(p: ^Parser, lhs: bool) -> ^ast.Expr {
error(p, tag.pos, "duplicate union tag '#%s'", tag.text)
}
is_maybe = true
case "no_nil":
if is_no_nil {
error(p, tag.pos, "duplicate union tag '#%s'", tag.text)
}
is_no_nil = true
case:
error(p, tag.pos, "invalid union tag '#%s", tag.text)
}
@@ -2669,6 +2676,7 @@ parse_operand :: proc(p: ^Parser, lhs: bool) -> ^ast.Expr {
ut.where_token = where_token
ut.where_clauses = where_clauses
ut.is_maybe = is_maybe
ut.is_no_nil = is_no_nil
return ut
+3 -2
View File
@@ -185,7 +185,7 @@ concatenate :: proc(a: []$T/[]$E, allocator := context.allocator) -> (res: T) {
return
}
// copies slice into a new dynamic array
// copies a slice into a new slice
clone :: proc(a: $T/[]$E, allocator := context.allocator) -> []E {
d := make([]E, len(a), allocator)
copy(d[:], a)
@@ -194,11 +194,12 @@ clone :: proc(a: $T/[]$E, allocator := context.allocator) -> []E {
// copies slice into a new dynamic array
to_dynamic :: proc(a: $T/[]$E, allocator := context.allocator) -> [dynamic]E {
clone_to_dynamic :: proc(a: $T/[]$E, allocator := context.allocator) -> [dynamic]E {
d := make([dynamic]E, len(a), allocator)
copy(d[:], a)
return d
}
to_dynamic :: clone_to_dynamic
// Converts slice into a dynamic array without cloning or allocating memory
into_dynamic :: proc(a: $T/[]$E) -> [dynamic]E {