stlib arraylist
This commit is contained in:
@@ -215,6 +215,7 @@ Ct_Value_Kind :: enum u8 {
|
||||
Pointer,
|
||||
Slice,
|
||||
Function,
|
||||
Type,
|
||||
None,
|
||||
Optional_Some,
|
||||
Fallible,
|
||||
@@ -333,6 +334,9 @@ ct_state_make :: proc(
|
||||
if value.kind == .Integer {
|
||||
id := ct_add_value(&state, Ct_Value{kind=.Integer, type=value.type, integer=value.value})
|
||||
ct_bind_value(&state, value.name, value.type, id, false)
|
||||
} else if value.kind == .Type {
|
||||
id := ct_add_value(&state, Ct_Value{kind=.Type, type=types.INVALID, index=u64(value.type)})
|
||||
ct_bind_value(&state, value.name, types.INVALID, id, false)
|
||||
}
|
||||
}
|
||||
return state
|
||||
@@ -532,6 +536,9 @@ ct_coerce_value :: proc(state: ^Ct_State, id: Ct_Value_Id, expected: types.Type,
|
||||
return id, true
|
||||
}
|
||||
value := state.values[id]
|
||||
if value.kind == .Type && is_type_metatype_syntax(state.checker, expected) {
|
||||
return id, true
|
||||
}
|
||||
if types.equal(value.type, expected) {
|
||||
return id, true
|
||||
}
|
||||
@@ -914,7 +921,7 @@ ct_eval_expr :: proc(
|
||||
id := ct_add_value(state, Ct_Value{kind=.Integer, type=value.type, integer=value.value})
|
||||
return id, ct_flow(.Normal), true
|
||||
}
|
||||
return INVALID_CT_VALUE, ct_flow(.Normal), ct_failf(state, .Not_Comptime, expr.span, "type parameter '%s' is not a runtime value", symbol_text(checker, expr.name))
|
||||
return ct_add_value(state, Ct_Value{kind=.Type, type=types.INVALID, index=u64(value.type)}), ct_flow(.Normal), true
|
||||
}
|
||||
} else if find_import(checker, state.file, expr.qualifier) == ast.INVALID_IMPORT {
|
||||
if index, ok := ct_find_binding_index(state, expr.qualifier); ok {
|
||||
@@ -971,6 +978,12 @@ ct_eval_expr :: proc(
|
||||
return ct_eval_array_expr(state, expr, expected, depth+1)
|
||||
case .Struct_Literal:
|
||||
return ct_eval_struct_expr(state, expr, expected, depth+1)
|
||||
case .Type:
|
||||
resolved := type_from_syntax(checker, expr.type, state.pkg, state.file)
|
||||
return ct_add_value(state, Ct_Value{kind=.Type, type=types.INVALID, index=u64(resolved)}), ct_flow(.Normal), types.is_valid(resolved)
|
||||
case .Anonymous_Struct_Type:
|
||||
resolved := resolve_generated_struct_type(checker, expr_id, state.pkg, state.file)
|
||||
return ct_add_value(state, Ct_Value{kind=.Type, type=types.INVALID, index=u64(resolved)}), ct_flow(.Normal), types.is_valid(resolved)
|
||||
case .Enum_Literal:
|
||||
return ct_eval_enum_literal(state, expr, expected, depth+1)
|
||||
case .None:
|
||||
@@ -1150,7 +1163,7 @@ ct_eval_expr :: proc(
|
||||
return value, ct_flow(.Normal), true
|
||||
case .Slice:
|
||||
return ct_eval_slice_expr(state, expr, depth+1)
|
||||
case .Type, .Undefined, .Keyed:
|
||||
case .Undefined, .Keyed:
|
||||
return INVALID_CT_VALUE, ct_flow(.Normal), ct_fail(state, .Not_Comptime, expr.span, "expression cannot be evaluated at comptime")
|
||||
}
|
||||
return INVALID_CT_VALUE, ct_flow(.Normal), ct_fail(state, .Not_Comptime, expr.span, "expression cannot be evaluated at comptime")
|
||||
@@ -1216,7 +1229,10 @@ ct_eval_struct_expr :: proc(state: ^Ct_State, expr: ast.Expr, expected: types.Ty
|
||||
checker := state.checker
|
||||
store := &checker.module.types
|
||||
struct_type := types.INVALID
|
||||
if symbol.is_valid(expr.name) {
|
||||
if expr.left != ast.INVALID_EXPR {
|
||||
struct_type, _ = resolve_type_argument(checker, expr.left, state.pkg, state.file)
|
||||
struct_type = types.resolve_alias(struct_type, store)
|
||||
} else if symbol.is_valid(expr.name) {
|
||||
target_pkg, available := expr_package(checker, expr, state.pkg, state.file, false)
|
||||
struct_type = types.find_named(store, u32(target_pkg), u32(expr.name), file=u32(expr_lookup_file(expr, state.file))) if available else types.INVALID
|
||||
struct_type = types.resolve_alias(struct_type, store)
|
||||
|
||||
Reference in New Issue
Block a user