Skip to content

Commit

Permalink
Change type to call function in reflection
Browse files Browse the repository at this point in the history
  • Loading branch information
Victorious3 committed Oct 12, 2024
1 parent 348db0d commit be3954c
Showing 1 changed file with 17 additions and 17 deletions.
34 changes: 17 additions & 17 deletions src/compiler.pr
Original file line number Diff line number Diff line change
Expand Up @@ -3363,7 +3363,7 @@ def walk_Identifier(node: &parser::Node, state: &State) -> Value {
if not val { return NO_VALUE }

if val.tpe and val.tpe.kind == typechecking::TypeKind::TYPE {
val = change_value_to_type(node.tpe.tpe.tpe, state)
return change_value_to_type(node.tpe.tpe.tpe, state)
}
if not val { return NO_VALUE }

Expand Down Expand Up @@ -4724,16 +4724,12 @@ def walk_IfExpr(node: &parser::Node, state: &State) -> Value {

def walk_Type(node: &parser::Node, state: &State) -> Value {
let expr = node.value.t_parr.tpe
node.svalue = change_value_to_type(node.tpe.tpe.tpe, state)
if not node.svalue { return NO_VALUE }
return @node.svalue.value
return change_value_to_type(node.tpe.tpe.tpe, state)
}

def walk_TypeOfT(node: &parser::Node, state: &State) -> Value {
let expr = node.value.expr
node.svalue = change_value_to_type(expr.tpe, state)
if not node.svalue { return NO_VALUE }
return @node.svalue.value
return change_value_to_type(expr.tpe, state)
}

export def walk_expression(node: &parser::Node, state: &State) -> Value {
Expand Down Expand Up @@ -8768,8 +8764,8 @@ def do_create_type(tpe: &typechecking::Type, svalue: &scope::Value, module: &too

value.values = allocate_ref(Value, 3)
value.values(0) = [ kind = ValueKind::INT, tpe = builtins::int64_, i = md5::high(md5::md5(name_str)) ] !Value
value.values(1) = [ kind = ValueKind::NULL, tpe = unbox((builtins::Type_).field_types(1).tpe) ] !Value
value.values(2) = [ kind = ValueKind::NULL, tpe = unbox((builtins::Type_).field_types(2).tpe) ] !Value
value.values(1) = [ kind = ValueKind::ZEROINITIALIZER, tpe = unbox((builtins::Type_).field_types(1).tpe) ] !Value
value.values(2) = [ kind = ValueKind::ZEROINITIALIZER, tpe = unbox((builtins::Type_).field_types(2).tpe) ] !Value

if is_ref(tpe) and typechecking::has_destructor(tpe) {
let fp = unbox((builtins::Type_).field_types(15).tpe)
Expand Down Expand Up @@ -8887,23 +8883,27 @@ export def create_type(tpe: &typechecking::Type, module: &toolchain::Module, cac
return value
}

def change_value_to_type(tpe: &typechecking::Type, state: &State) -> &scope::Value {
def change_value_to_type(tpe: &typechecking::Type, state: &State) -> Value {
let type_tpe = copy(builtins::Type_)
type_tpe._tpe = tpe
import_structures(builtins::Type_, state.module)

add_type_meta(tpe, state)

let value_tpe = create_type(tpe, state.module)
if not value_tpe { return null }
if not value_tpe { return NO_VALUE }

value_tpe.value_tpe = tpe
let value = [
tpe = typechecking::pointer(type_tpe),
value = value_tpe
] !&scope::Value
let reflection = toolchain::find_module("reflection")
let type_t = reflection.scope.get_type(parser::make_identifier("Type"))
let fun = reflection.scope.get(parser::make_identifier("type_id"))
if consteval::is_static {
consteval::compile_function(fun, state.scope)
}
predeclare_function(fun.tpe, state.module)
state.module.imported.add(fun.tpe.type_name)

return value
let hash = md5::high(md5::md5(debug::type_to_str(tpe, full_name = true)))
return state.call(fun.tpe.type_name, type_t, [[ tpe = builtins::uint64_, kind = ValueKind::INT, i = hash ] !Value])
}

def make_global_data(name: Str, value: &ByteStream, state: &State) {
Expand Down

0 comments on commit be3954c

Please sign in to comment.