Skip to content

Commit a6d6141

Browse files
committed
Fix some stuff
1 parent 86d3126 commit a6d6141

3 files changed

Lines changed: 32 additions & 9 deletions

File tree

src/consteval.pr

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -577,6 +577,14 @@ export def walk_TypeDecl(node: &parser::Node, state: &typechecking::State) {
577577
typechecking::register(tpe, enum_tpe)
578578
} else {
579579
left.svalue = scope::create_type(state.scope, name, share, typechecking::make_type_ref(tpe), scope::Phase::DEFINED, typedef)
580+
// Register stub type that can be replaced later on demand
581+
let stub = [
582+
kind = typechecking::TypeKind::STUB,
583+
id = tpe,
584+
defmodule = state.module,
585+
type_name = parser::identifier_to_str(name)
586+
] !&typechecking::Type
587+
register(tpe, stub)
580588
}
581589
value.tpe = tpe
582590
} else {

src/toolchain.pr

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -859,6 +859,7 @@ export def compile_main_file(filename: String) {
859859
let filename = keys(i)
860860
let module = modules(filename)
861861
if module.module == "builtin" or not (module.is_dirty or no_incremental) { continue }
862+
if no_stdlib and (module.module == "runtime" or module.module == "optional") { continue }
862863
codegen::gen(module)
863864
}
864865

@@ -894,6 +895,7 @@ export def compile_main_file(filename: String) {
894895
let filename = keys(i)
895896
let module = modules(filename)
896897
if module.module == "builtin" or not (module.is_dirty or no_incremental) { continue }
898+
if no_stdlib and (module.module == "runtime" or module.module == "optional") { continue }
897899

898900
var combine = false
899901
if module.module != "type" and module.is_dirty and not no_incremental {
@@ -965,6 +967,7 @@ export def compile_main_file(filename: String) {
965967
let filename = keys2(i)
966968
let module = modules(filename)
967969
if module.module == "builtin" { continue }
970+
if no_stdlib and (module.module == "runtime" or module.module == "optional") { continue }
968971
link_command += outfolder + "/" + module.file + ".o "
969972
}
970973

src/typechecking.pr

Lines changed: 21 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -44,8 +44,8 @@ export type TypeKind = enum {
4444
TYPE_CONSTRUCTOR
4545
// For patterns that are type instances
4646
TYPE_INSTANCE
47-
// Forward declaration
48-
// STUB
47+
// Type placeholder for types that haven't been compiled yet
48+
STUB
4949
// Placeholder for arguments with polymorphic type parameter in function definition
5050
TYPE_DEF
5151
// Reference to a type
@@ -335,6 +335,13 @@ export def kind(typeref: &TypeRef) -> TypeKind {
335335
export def resolve(typeref: &TypeRef, scpe: &Scope, error_on_fail: bool = true) -> TypeId {
336336
if not typeref { return 0 }
337337
if typeref.tpe {
338+
let actual = typeref.tpe.resolve()
339+
if actual and actual.kind == TypeKind::STUB {
340+
// Lookup stub types on demand
341+
let id = scope::get_type_id(actual.defmodule.scope, parser::identifier_from_str(actual.type_name), error_on_fail)
342+
assert id == typeref.tpe
343+
return id
344+
}
338345
return typeref.tpe
339346
}
340347
if typeref.name {
@@ -570,7 +577,7 @@ export def equals(this: &Pattern, other: &Pattern, env: &EqEnv = null) -> bool {
570577
}
571578
}
572579
return true
573-
case TypeKind::TUPLE, TypeKind::TUNION
580+
case TypeKind::TUPLE, TypeKind::TUNION, TypeKind::TYPE_INSTANCE
574581
if this.return_t.length() != other.return_t.length() {
575582
return false
576583
}
@@ -2532,9 +2539,9 @@ export def convert_type_score(a: &TypeRef, b: &Type, scpe: &scope::Scope, impl:
25322539
if not a or not b { return 0 }
25332540
if a.pattern {
25342541
return convert_type_score(a.pattern, b, scpe, impl)
2535-
} /*else if a.name {
2542+
} else if a.name {
25362543
if scope::get_type(scpe, parser::identifier_from_str(a.name)) { return 1 }
2537-
}*/ else {
2544+
} else {
25382545
return convert_type_score(a.resolve(scpe), b, scpe, impl)
25392546
}
25402547
}
@@ -2977,12 +2984,17 @@ export def is_polymorph(tpe: &TypeRef) -> bool {
29772984
} else {
29782985
return is_polymorph(pattern.tpe)
29792986
}
2980-
} else if pattern.kind == TypeKind::TUPLE or pattern.kind == TypeKind::TUNION {
2987+
} else if pattern.kind == TypeKind::TUPLE or
2988+
pattern.kind == TypeKind::TUNION or
2989+
pattern.kind == TypeKind::TYPE_INSTANCE {
2990+
29812991
for var tpe in pattern.return_t {
29822992
if is_polymorph(tpe) { return true }
29832993
}
29842994
return false
29852995
}
2996+
} else if tpe.name {
2997+
return true
29862998
}
29872999
return false
29883000
}
@@ -5696,7 +5708,7 @@ export def walk_TypeDecl(node: &parser::Node, state: &State) {
56965708
type_value.defmodule = state.module
56975709

56985710
type_value.name = parser::identifier_to_str(name)
5699-
print("Registered type ", type_value.name, " with id ", tpe, "\n")
5711+
//print("Registered type ", type_value.name, " with id ", tpe, "\n")
57005712
if value.kind != parser::NodeKind::TYPE_CONSTRUCTOR {
57015713
type_value.type_name = append_module(type_value.name, node.loc.module)
57025714
}
@@ -7499,14 +7511,14 @@ export def typecheck(state: &State) {
74997511
//lookup_stub_types(state)
75007512

75017513
// Typcheck Type decls
7502-
for var i in 0..vector::length(node.body) {
7514+
/*for var i in 0..vector::length(node.body) {
75037515
let n = node.body(i)
75047516
switch n.kind !int {
75057517
case parser::NodeKind::TYPE_DECL
75067518
n.parent = node
75077519
walk_TypeDecl(n, state)
75087520
}
7509-
}
7521+
}*/
75107522

75117523
typecheck(node, state)
75127524

0 commit comments

Comments
 (0)