Skip to content

Commit dc72aba

Browse files
committed
Replace function types with FunctionDef
1 parent 64158b2 commit dc72aba

File tree

10 files changed

+364
-341
lines changed

10 files changed

+364
-341
lines changed

src/compiler.pr

Lines changed: 147 additions & 153 deletions
Large diffs are not rendered by default.

src/consteval.pr

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -391,11 +391,11 @@ export def walk_Def(node: &parser::Node, state: &typechecking::State) {
391391
}
392392
}
393393

394-
var tpe = typechecking::function(parser::identifier_to_str(name), parameter_t, return_t, state.module, extern, test = test).resolve()
394+
var fdef = typechecking::function_def(parser::identifier_to_str(name), parameter_t, return_t, state.module, extern, test = test) !&FunctionDef
395395
//tpe.node = node
396396
let current_function = errors::current_function
397397
let current_signature = errors::current_signature
398-
errors::current_function = tpe.type_name
398+
errors::current_function = fdef.name
399399
errors::current_signature = node.signature_hash
400400

401401
if body {
@@ -410,9 +410,9 @@ export def walk_Def(node: &parser::Node, state: &typechecking::State) {
410410
node.svalue = scope::create_function(state.scope, name, function.value)
411411
} else {
412412
if body {
413-
node.svalue = scope::create_function(state.scope, name, share, tpe.id, scope::Phase::DEFINED, node, local_type_defs, impl = impl)
413+
node.svalue = scope::create_function(state.scope, name, share, @fdef, scope::Phase::DEFINED, node, local_type_defs, impl = impl)
414414
} else {
415-
node.svalue = scope::create_function(state.scope, name, share, tpe.id, scope::Phase::DECLARED, node, local_type_defs)
415+
node.svalue = scope::create_function(state.scope, name, share, @fdef, scope::Phase::DECLARED, node, local_type_defs)
416416
}
417417
}
418418
if node.svalue {
@@ -424,7 +424,7 @@ export def walk_Def(node: &parser::Node, state: &typechecking::State) {
424424

425425
if not function {
426426
function = [
427-
tpe = tpe.id,
427+
fdef = @fdef,
428428
module = state.module,
429429
locals = map::make(typechecking::TypeId),
430430
unmangled = parser::identifier_to_str(name),
@@ -476,7 +476,7 @@ export def walk_Def(node: &parser::Node, state: &typechecking::State) {
476476

477477
errors::current_function = current_function
478478
errors::current_signature = current_signature
479-
node.tpe = tpe.id
479+
node.fdef = fdef
480480
}
481481

482482
export def walk_TypeDecl(node: &parser::Node, state: &typechecking::State) {
@@ -573,8 +573,8 @@ export def walk_TypeDecl(node: &parser::Node, state: &typechecking::State) {
573573
return_t.push(builtins::string_)
574574

575575
let ident = parser::make_identifier("to_string")
576-
let ftpe = typechecking::function("to_string", parameter_t, return_t)
577-
let v = scope::create_function(state.scope, ident, parser::ShareMarker::EXPORT, ftpe, local_type_defs = make_local_type_defs())
576+
let fdef = typechecking::function_def("to_string", parameter_t, return_t)
577+
let v = scope::create_function(state.scope, ident, parser::ShareMarker::EXPORT, fdef, local_type_defs = make_local_type_defs())
578578
v.identifier = ident
579579
left.svalue = scope::create_type(state.scope, name, share, tpe, scope::Phase::DEFINED, null)
580580
typechecking::register(tpe, enum_tpe)
@@ -831,7 +831,7 @@ export def compile_function(value: &scope::Value, context: &scope::Scope, argume
831831
var function = node.value.def_.function
832832
if function.is_typechecked and not is_repurposed { return value }
833833

834-
let is_polymorph = typechecking::is_polymorph(function.tpe.resolve().parameter_t)
834+
let is_polymorph = typechecking::is_polymorph(function.fdef.sig.parameter_t)
835835
if not is_polymorph {
836836
compiler::predeclare_function(function, overwrite = true)
837837
const_module.result.functions(function.name) = function
@@ -868,10 +868,10 @@ export def compile_function(value: &scope::Value, context: &scope::Scope, argume
868868

869869
//print("Creating function ", function.tpe.type_name, "\n")
870870

871-
// This is a big ugly but what can we do
871+
// This is a bit ugly but what can we do
872872
let debug = toolchain::debug_sym
873873
toolchain::debug_sym = false
874-
compiler::create_function(node, node.tpe, node.value.def_.body, node.inner_scope, null, compiler_state, params = node.value.def_.params)
874+
compiler::create_function(node, function.fdef, node.value.def_.body, node.inner_scope, null, compiler_state, params = node.value.def_.params)
875875
toolchain::debug_sym = debug
876876

877877
if function.defer_functions {

src/parser.pr

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -456,9 +456,9 @@ export type Node = struct {
456456
loc: SourceLoc
457457

458458
tpe: typechecking::TypeId
459-
// This is for passing on a function from typechecking to the compiler
460-
// TODO There might be better ways of doing this
461-
function: typechecking::TypeId
459+
fdef: &typechecking::FunctionDef
460+
call_type: typechecking::TypeId
461+
462462
svalue: &scope::Value
463463
scope: &scope::Scope
464464
// For things like if statements or functions
@@ -611,7 +611,8 @@ export def construct(copy: *Node, node: *Node) {
611611
copy.kind = node.kind
612612
copy.loc = node.loc
613613
copy.tpe = node.tpe
614-
copy.function = node.function
614+
copy.fdef = node.fdef
615+
copy.call_type = node.call_type
615616
copy.svalue = node.svalue
616617
copy.scope = node.scope
617618
copy.inner_scope = node.inner_scope

src/repl.pr

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -400,7 +400,7 @@ def execute(source: Str) {
400400
] !parser::NodeFuncCall
401401
let svalue = scope::get(old_node.scope, print_ident)
402402
print_ident.svalue = svalue
403-
node.function = svalue.tpe
403+
node.fdef = svalue.fdef !&FunctionDef
404404
}
405405
}
406406
}
@@ -411,7 +411,8 @@ def execute(source: Str) {
411411

412412
// Compile delayed functions
413413
for var n in consteval::const_module.delayed_compile {
414-
compiler::create_function(n, n.tpe, n.value.def_.body, n.inner_scope, null, consteval::const_module.compiler_state)
414+
if not n.fdef { continue }
415+
compiler::create_function(n, @n.fdef, n.value.def_.body, n.inner_scope, null, consteval::const_module.compiler_state)
415416
}
416417
consteval::const_module.delayed_compile = vector::make(type &parser::Node)
417418

0 commit comments

Comments
 (0)