Skip to content

Commit aa760c0

Browse files
committed
Update
1 parent 3465b2d commit aa760c0

8 files changed

Lines changed: 102 additions & 45 deletions

File tree

src/builtins.pr

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -182,7 +182,7 @@ scope::create_variable(
182182
)
183183

184184
// This one gets set by toolchain
185-
export var File_: typechecking::TypeId
185+
//export var File_: typechecking::TypeId
186186

187187
export var Type_: typechecking::TypeId
188188
export def type_t -> typechecking::TypeId {

src/compiler.pr

Lines changed: 21 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1085,7 +1085,9 @@ def make_return_type(rtpe: &typechecking::Type) -> typechecking::TypeId {
10851085
return type_registry_return_types(rtpe.id).id
10861086
}
10871087

1088-
assert typechecking::is_tuple(rtpe)
1088+
if not typechecking::is_tuple(rtpe) {
1089+
return 0
1090+
}
10891091
let length = vector::length(rtpe.return_t)
10901092
let fields = vector::make(typechecking::StructMember)
10911093

@@ -4130,6 +4132,10 @@ type Member = struct {
41304132

41314133
// This list needs to be reversed to find the actual indices
41324134
def resolve_member(vec: &Vector(Member), tpe: &typechecking::Type, name: Str) -> bool {
4135+
if not tpe { return false }
4136+
if tpe.kind == typechecking::TypeKind::REFERENCE {
4137+
tpe = tpe.tpe.resolve()
4138+
}
41334139
let fields = tpe.fields
41344140
if not fields { return false }
41354141
for var i in 0..fields.length() {
@@ -6336,8 +6342,12 @@ def walk_Assert(node: &parser::Node, state: &State) {
63366342
import_structures(scope::get(state.scope, parser::make_identifier("fprintf")).get_type(), state.module)
63376343

63386344
let std_module = toolchain::find_module("std")
6345+
if not std_module { return }
63396346
let stderr_fun = scope::get(std_module.scope, parser::make_identifier("stderr"))
63406347
let print_stacktrace_fun = scope::get(std_module.scope, parser::make_identifier("print_stacktrace"))
6348+
predeclare_function(stderr_fun.fdef, state.module)
6349+
predeclare_function(print_stacktrace_fun.fdef, state.module)
6350+
63416351
//let fun = predeclare_function(stderr_fun, std_module)
63426352
//state.module.result.functions[stderr_fun.type_name] = fun
63436353

@@ -6396,7 +6406,9 @@ def walk_Assert(node: &parser::Node, state: &State) {
63966406
fmt = "%s:%d:%s: Unreachable!\n"
63976407
}
63986408

6399-
let stderr = make_local_value(builtins::File_, null, state)
6409+
let file = stderr_fun.fdef.to_type().resolve().return_t(0)
6410+
import_structures(file, state.module)
6411+
let stderr = make_local_value(file, null, state)
64006412
let mcall = make_insn_dbg(InsnKind::CALL, loc)
64016413
mcall.value.call = [
64026414
name = [
@@ -6421,7 +6433,7 @@ def walk_Assert(node: &parser::Node, state: &State) {
64216433
args(4) = charp(function_name, state)
64226434

64236435
let proto = allocate_ref(typechecking::NamedParameter, 3)
6424-
proto(0) = [ tpe = builtins::File_ ] !typechecking::NamedParameter
6436+
proto(0) = [ tpe = file ] !typechecking::NamedParameter
64256437
proto(1) = [ tpe = typechecking::pointer(builtins::char_) ] !typechecking::NamedParameter
64266438
proto(2) = [ varargs = true ] !typechecking::NamedParameter
64276439

@@ -7159,6 +7171,7 @@ export def predeclare_function(function: &Function, scpe: &scope::Scope, overwri
71597171
function.args = vector::make(typechecking::NamedParameter)
71607172
for var i in 0..vector::length(fdef.parameter_t) {
71617173
let np = fdef.parameter_t(i)
7174+
if np.kw == parser::VarDecl::TYPE { continue }
71627175
let restpe = np.tpe.resolve(scpe)
71637176
if restpe {
71647177
let resnp = [
@@ -9273,12 +9286,12 @@ def generate_reflection_data_2(tpe: &typechecking::Type, data: &ByteStream, stri
92739286
case typechecking::TypeKind::INTERFACE
92749287
for var member in tpe.members {
92759288
for var np in member.parameter_t {
9276-
assert np.tpe.tpe
9277-
data.write(np.tpe.tpe !uint64)
9289+
assert np.tpe
9290+
data.write(np.tpe !uint64)
92789291
}
92799292
for var t in member.return_t {
9280-
assert t.tpe.tpe
9281-
data.write(t.tpe.tpe !uint64)
9293+
assert t
9294+
data.write(t !uint64)
92829295
}
92839296
}
92849297
case typechecking::TypeKind::POINTER, typechecking::TypeKind::REFERENCE,
@@ -9521,7 +9534,7 @@ def generate_vtable_function(function: &Function, fdef: typechecking::FunctionDe
95219534
}
95229535
}
95239536

9524-
if kind != 0 and implementor.kind != typechecking::TypeKind::STRUCT { continue }
9537+
if kind != 0 and implementor.kind != typechecking::TypeKind::REFERENCE { continue }
95259538

95269539
if not consteval::is_static {
95279540
import_structure(implementor, state.module)

src/consteval.pr

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -814,6 +814,8 @@ export def compile_function(value: &scope::Value, context: &scope::Scope, argume
814814
var node = value.node
815815
var module = value.module
816816

817+
if not node { return value }
818+
817819
/*var is_repurposed = false // When There's no node and we find a new function we don't need to typecheck anymore
818820
if not node {
819821
if not arguments { return value }
@@ -863,7 +865,7 @@ export def compile_function(value: &scope::Value, context: &scope::Scope, argume
863865
let prev_context = state.context
864866
state.context = node.scope
865867
//node.tpe = value.tpe = typechecking::lookup_parameters(node, state)
866-
print(node.tpe.type_name, "\n")
868+
//print(node.tpe.type_name, "\n")
867869
typechecking::walk_Def(node, state)
868870
state.context = prev_context
869871
}
@@ -1229,9 +1231,7 @@ export def consteval(module: &toolchain::Module) {
12291231
module.state = state
12301232
consteval(state)
12311233

1232-
if module.module == "std" {
1233-
toolchain::load_file_type()
1234-
} else if module.module == "reflection" {
1234+
if module.module == "reflection" {
12351235
builtins::TypeT_ = module.scope.get_type_id(parser::make_identifier("Type"))
12361236
}
12371237
}

src/eval.pr

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1125,7 +1125,7 @@ def eval_Inttoptr(insn: &compiler::Insn, state: &State) {
11251125

11261126
def eval_insn(insn: &compiler::Insn, state: &State) {
11271127
if toolchain::trace_consteval {
1128-
codegen::emit(std::stdout(), insn)
1128+
//codegen::emit(std::stdout(), insn)
11291129
}
11301130
switch insn.kind !int {
11311131
case compiler::InsnKind::INSERTVALUE

src/scope.pr

Lines changed: 40 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -978,7 +978,7 @@ export def generate_function(scope: &Scope, node: &parser::Node, parameter_t: &V
978978
// Switch to strong reference
979979
// TODO this removes the reference's canonical name but this is needed to only create one function
980980
// We should really get rid of the string name creating a hash
981-
ftpe = reference(ftpe.tpe).resolve()
981+
//ftpe = reference(ftpe.tpe).resolve()
982982

983983
//let equals = get(toolchain::runtime_.scope, parser::make_identifier("equals"))
984984
//consteval::compile_function(equals, scope)
@@ -1975,7 +1975,11 @@ export def create_impl(
19751975
// is a forward declared type, it will be resolved later
19761976
// and the equality check looks at the patterns
19771977

1978-
if left.resolve(scope, error_on_fail = false) {
1978+
// TODO Should impls be unique? The problem with looking up types here is
1979+
// that they might recursively resolve other stuff and fail because of
1980+
// types that aren't resolvable yet
1981+
1982+
/*if left.resolve(scope, error_on_fail = false) {
19791983
right.resolve(scope, error_on_fail = false)
19801984
}
19811985

@@ -1987,7 +1991,7 @@ export def create_impl(
19871991
errors::errorn(node, "Duplicate impl for `", typechecking::generic_to_string(left), "`")
19881992
return
19891993
}
1990-
}
1994+
}*/
19911995

19921996
scope.impls.push(impl)
19931997
}
@@ -2087,6 +2091,39 @@ export def trigger_impl(scope: &Scope, tpe: &typechecking::Type) {
20872091
parameter_t.push(param)
20882092
}
20892093

2094+
var struct_tpe = tpe
2095+
if tpe and tpe.kind == typechecking::TypeKind::REFERENCE {
2096+
struct_tpe = tpe.tpe.resolve()
2097+
}
2098+
if struct_tpe and struct_tpe.kind == typechecking::TypeKind::STRUCT or
2099+
struct_tpe.kind == typechecking::TypeKind::UNION {
2100+
// Check for fields
2101+
2102+
let fields = typechecking::flatten_fields(null, struct_tpe)
2103+
2104+
var found = false
2105+
if typechecking::is_getter(member) {
2106+
for var field in fields {
2107+
if field.name == member.name and equals(member.return_t(0), field.tpe) {
2108+
found = true
2109+
break
2110+
}
2111+
}
2112+
} else if typechecking::is_setter(member) {
2113+
let name = member.name.slice(6, member.name.length() - 2)
2114+
for var field in fields {
2115+
if field.name == name and equals(member.parameter_t(0).tpe, field.tpe) {
2116+
found = true
2117+
break
2118+
}
2119+
}
2120+
}
2121+
2122+
if found {
2123+
continue
2124+
}
2125+
}
2126+
20902127
let name_node = parser::make_identifier(member.name)
20912128
let fun = get_function(impl.module.scope, name_node, parameter_t, dry_run = true)
20922129
var res = fun != null

src/serialize.pr

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1470,9 +1470,6 @@ export def dependency_pass(module: &toolchain::Module) {
14701470
if module.is_dirty and module.stage !int < toolchain::Stage::TYPECHECKING !int {
14711471
toolchain::reset_and_consteval(module)
14721472
}
1473-
if module.module == "std" {
1474-
toolchain::load_file_type()
1475-
}
14761473

14771474
toolchain::progress_update(module, toolchain::ProgressUpdate::END)
14781475
}

src/toolchain.pr

Lines changed: 0 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -706,15 +706,6 @@ export def create_types_main {
706706
types.imported.add(main_def.name)
707707
}
708708

709-
export def load_file_type {
710-
if no_stdlib or builtins::File_ != null { return }
711-
var std_module = find_module("std")
712-
if not std_module {
713-
std_module = create_module_if_absent(find_module_file("/std", null), "std")
714-
}
715-
builtins::File_ = scope::get_type_id(std_module.scope, parser::make_identifier("File"))
716-
}
717-
718709
export def reset_types {
719710
types.scope = scope::enter_scope(null !&scope::Scope, types, true)
720711
types.code = compiler::make_block()

0 commit comments

Comments
 (0)