Skip to content

Commit

Permalink
Support soa in generics
Browse files Browse the repository at this point in the history
  • Loading branch information
DanielGavin committed Jul 25, 2024
1 parent 5f37d25 commit 18afea3
Show file tree
Hide file tree
Showing 4 changed files with 87 additions and 2 deletions.
20 changes: 20 additions & 0 deletions src/common/ast.odin
Original file line number Diff line number Diff line change
Expand Up @@ -207,6 +207,26 @@ unwrap_pointer_expr :: proc(expr: ^ast.Expr) -> (^ast.Expr, int, bool) {
return expr, n, true
}

array_is_soa :: proc(array: ast.Array_Type) -> bool {
if array.tag != nil {
if basic, ok := array.tag.derived.(^ast.Basic_Directive);
ok && basic.name == "soa" {
return true
}
}
return false
}

dynamic_array_is_soa :: proc(array: ast.Dynamic_Array_Type) -> bool {
if array.tag != nil {
if basic, ok := array.tag.derived.(^ast.Basic_Directive);
ok && basic.name == "soa" {
return true
}
}
return false
}

expr_contains_poly :: proc(expr: ^ast.Expr) -> bool {
if expr == nil {
return false
Expand Down
26 changes: 24 additions & 2 deletions src/server/analysis.odin
Original file line number Diff line number Diff line change
Expand Up @@ -489,7 +489,13 @@ is_symbol_same_typed :: proc(
return false
}

return is_symbol_same_typed(ast_context, a_symbol, b_symbol)
a_is_soa := .Soa in a_symbol.flags
b_is_soa := .Soa in a_symbol.flags

return(
is_symbol_same_typed(ast_context, a_symbol, b_symbol) &&
a_is_soa == b_is_soa \
)
case SymbolFixedArrayValue:
b_value := b.value.(SymbolFixedArrayValue)

Expand Down Expand Up @@ -561,7 +567,13 @@ is_symbol_same_typed :: proc(
return false
}

return is_symbol_same_typed(ast_context, a_symbol, b_symbol)
a_is_soa := .Soa in a_symbol.flags
b_is_soa := .Soa in a_symbol.flags

return(
is_symbol_same_typed(ast_context, a_symbol, b_symbol) &&
a_is_soa == b_is_soa \
)
case SymbolMapValue:
b_value := b.value.(SymbolMapValue)

Expand Down Expand Up @@ -2826,6 +2838,10 @@ make_symbol_array_from_ast :: proc(
}
}

if common.array_is_soa(v) {
symbol.flags |= {.Soa}
}

return symbol
}

Expand All @@ -2845,6 +2861,12 @@ make_symbol_dynamic_array_from_ast :: proc(
expr = v.elem,
}


if common.dynamic_array_is_soa(v) {
symbol.flags |= {.Soa}
}


return symbol
}

Expand Down
42 changes: 42 additions & 0 deletions src/server/generics.odin
Original file line number Diff line number Diff line change
Expand Up @@ -150,6 +150,27 @@ resolve_poly :: proc(
}
case ^ast.Dynamic_Array_Type:
if call_array, ok := call_node.derived.(^ast.Dynamic_Array_Type); ok {

a_soa := common.dynamic_array_is_soa(p^)
b_soa := common.dynamic_array_is_soa(call_array^)

if (a_soa || b_soa) && a_soa != b_soa {
return false
}

//It's not enough for them to both arrays, they also have to share soa attributes
if p.tag != nil && call_array.tag != nil {
a, ok1 := p.tag.derived.(^ast.Basic_Directive)
b, ok2 := call_array.tag.derived.(^ast.Basic_Directive)

if ok1 &&
ok2 &&
(a.name == "soa" || b.name == "soa") &&
a.name != b.name {
return false
}
}

if poly_type, ok := p.elem.derived.(^ast.Poly_Type); ok {
if ident, ok := unwrap_ident(poly_type.type); ok {
save_poly_map(ident, call_array.elem, poly_map)
Expand All @@ -170,6 +191,27 @@ resolve_poly :: proc(
case ^ast.Array_Type:
if call_array, ok := call_node.derived.(^ast.Array_Type); ok {
found := false

a_soa := common.array_is_soa(p^)
b_soa := common.array_is_soa(call_array^)

if (a_soa || b_soa) && a_soa != b_soa {
return false
}

//It's not enough for them to both arrays, they also have to share soa attributes
if p.tag != nil && call_array.tag != nil {
a, ok1 := p.tag.derived.(^ast.Basic_Directive)
b, ok2 := call_array.tag.derived.(^ast.Basic_Directive)

if ok1 &&
ok2 &&
(a.name == "soa" || b.name == "soa") &&
a.name != b.name {
return false
}
}

if poly_type, ok := p.elem.derived.(^ast.Poly_Type); ok {
if ident, ok := unwrap_ident(poly_type.type); ok {
save_poly_map(ident, call_array.elem, poly_map)
Expand Down
1 change: 1 addition & 0 deletions src/server/symbol.odin
Original file line number Diff line number Diff line change
Expand Up @@ -146,6 +146,7 @@ SymbolFlag :: enum {
Local,
ObjC,
ObjCIsClassMethod, // should be set true only when ObjC is enabled
Soa,
}

SymbolFlags :: bit_set[SymbolFlag]
Expand Down

0 comments on commit 18afea3

Please sign in to comment.