Skip to content

Commit c39ba20

Browse files
committed
Fix varargs and some other stuff
1 parent 93fbf94 commit c39ba20

File tree

5 files changed

+37
-24
lines changed

5 files changed

+37
-24
lines changed

src/compiler.pr

Lines changed: 7 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -329,6 +329,7 @@ export type InsnCall = struct {
329329
}
330330

331331
export def call(state: &State, name: Str, tpe: typechecking::TypeId, args: &[Value], loc: &Value = null) -> Value {
332+
assert name
332333
let name_v = [ kind = ValueKind::GLOBAL, name = name ] !Value
333334
return call(state, name_v, tpe, args, parser::InlineSpecifier::NONE, null, loc)
334335
}
@@ -8759,9 +8760,8 @@ def create_destructor(tpe: &typechecking::Type, value: Value, state: &State) {
87598760
let destructor = typechecking::get_builtin_destructor(field.tpe)
87608761

87618762
if destructor {
8762-
let dtortpe = destructor.get_type().resolve()
87638763
let field_value = state.gep(ptpe, structure_type.id, obj, [make_int_value(0), make_int_value(i)])
8764-
state.call(dtortpe.type_name, 0, [field_value])
8764+
state.call(destructor.fdef.name, 0, [field_value])
87658765
}
87668766
}
87678767
}
@@ -8834,7 +8834,7 @@ def create_destructor(tpe: &typechecking::Type, value: Value, state: &State) {
88348834
}
88358835

88368836
def do_create_type(tpe: &typechecking::Type, svalue: &scope::Value, module: &toolchain::Module) -> &Value {
8837-
if toolchain::no_stdlib { return NO_VALUE }
8837+
//if toolchain::no_stdlib { return NO_VALUE }
88388838

88398839
//let generic = typechecking::get_generic(tpe)
88408840
//if generic and generic.tc_incomplete { return null }
@@ -8854,11 +8854,9 @@ def do_create_type(tpe: &typechecking::Type, svalue: &scope::Value, module: &too
88548854
toolchain::types.result.globals(global2.name) = global2
88558855
toolchain::types.imported.add(global2.name)
88568856

8857-
let name_str = debug::type_to_str(tpe, full_name = true)
8858-
88598857
let type_ = builtins::type_t().resolve()
88608858
value.values = allocate_ref(Value, 3)
8861-
value.values(0) = [ kind = ValueKind::INT, tpe = builtins::int64_, i = md5::high(md5::md5(name_str)) ] !Value
8859+
value.values(0) = [ kind = ValueKind::INT, tpe = builtins::int64_, i = tpe.id ] !Value
88628860
value.values(1) = [ kind = ValueKind::ZEROINITIALIZER, tpe = type_.field_types(1).tpe ] !Value
88638861
value.values(2) = [ kind = ValueKind::ZEROINITIALIZER, tpe = type_.field_types(2).tpe ] !Value
88648862

@@ -8992,9 +8990,7 @@ export def create_type(tpe: &typechecking::Type, module: &toolchain::Module, res
89928990

89938991
let state = toolchain::types_state
89948992
let assembly_name = scope::assembly_name(svalue, state)
8995-
if not state.consteval and
8996-
not map::contains(module.result.globals, assembly_name) {
8997-
8993+
if not map::contains(module.result.globals, assembly_name) {
89988994
let global = [
89998995
external = true,
90008996
name = assembly_name,
@@ -9042,9 +9038,8 @@ def change_value_to_type(tpe: &typechecking::Type, loc: &Value, state: &State) -
90429038

90439039
let fun = declare_reflection_type_id_fun(state)
90449040
if not fun { return NO_VALUE }
9045-
let hash = md5::high(md5::md5(debug::type_to_str(tpe, full_name = true)))
90469041
let tmp = state.alloca(builtins::type_t(), loc)
9047-
let res = state.call(fun.fdef.name, builtins::TypeT_, [[ tpe = builtins::uint64_, kind = ValueKind::INT, i = hash ] !Value], loc)
9042+
let res = state.call(fun.fdef.name, builtins::TypeT_, [[ tpe = builtins::uint64_, kind = ValueKind::INT, i = tpe.id ] !Value], loc)
90489043
state.store(tmp, res, loc)
90499044
create_temporary(tmp, res, loc, state)
90509045
return res
@@ -9468,7 +9463,7 @@ def generate_vtable_function(function: &Function, fdef: typechecking::FunctionDe
94689463
let type_entry = typechecking::type_registry(keys(i))
94699464
if is_ref(type_entry.tpe) and typechecking::implements(type_entry, intf, state.scope) {
94709465
// FIXME This whole branch isn't working yet because interfaces don't work right now
9471-
let hash = md5::high(md5::md5(debug::type_to_str(type_entry, full_name = true)))
9466+
let hash = type_entry.id
94729467
if hashes.contains(hash) { continue }
94739468
hashes.add(hash)
94749469

src/runtime.pr

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -219,6 +219,8 @@ export def reference(tpe: *Type) -> *Type {
219219
return ret
220220
}*/
221221

222+
// FIXME Commend this in
223+
/*
222224
import cstd
223225
import optional
224226

@@ -246,4 +248,4 @@ export def destruct(this: *Generator(type T)) {
246248

247249
export def next(generator: &Generator(type T)) -> optional::Optional(T) {
248250
return generator.implementation(generator)
249-
}
251+
}*/

src/scope.pr

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -137,6 +137,7 @@ export type Value = struct {
137137
}
138138

139139
export def get_type(value: &Value) -> typechecking::TypeId {
140+
assert value.module
140141
return value.tpe.resolve(value.module.scope)
141142
}
142143

@@ -396,7 +397,8 @@ export def enter_scope(parents: &Vector(weak &Scope), module: &toolchain::Module
396397
parents = parents,
397398
fields = map::make(type &Value),
398399
implicits = vector::make(type &Value),
399-
underscore_count = 0
400+
underscore_count = 0,
401+
is_global = is_global
400402
] !&Scope
401403
let function_parent = get_function_parent(s)
402404
if function_parent {
@@ -1047,7 +1049,7 @@ export def generate_function(scope: &Scope, node: &parser::Node, parameter_t: &V
10471049
] !typechecking::NamedParameterPre)
10481050

10491051
let name_node = parser::make_identifier("__destruct__")
1050-
let fdef = typechecking::function_def("__destruct__", args, vector::make(type &typechecking::TypeRef))
1052+
let fdef = typechecking::function_def("__destruct__", args, vector::make(type &typechecking::TypeRef), context = scope.module)
10511053
let fun = has_function(builtins::builtins, fdef)
10521054
if fun { return fun }
10531055

@@ -1075,7 +1077,7 @@ export def generate_function(scope: &Scope, node: &parser::Node, parameter_t: &V
10751077
] !typechecking::NamedParameterPre)
10761078

10771079
let name_node = parser::make_identifier("__construct__")
1078-
let fdef = typechecking::function_def("__construct__", args, vector::make(type &typechecking::TypeRef))
1080+
let fdef = typechecking::function_def("__construct__", args, vector::make(type &typechecking::TypeRef), context = scope.module)
10791081
let fun = has_function(builtins::builtins, fdef)
10801082
if fun { return fun }
10811083

src/toolchain.pr

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -653,8 +653,9 @@ def create_types_module {
653653
filename = null,
654654
modulename = "type",
655655
node = null,
656-
scpe = scope::enter_scope(null !&scope::Scope, types, true)
656+
scpe = scope::enter_scope(null !&scope::Scope, null, true)
657657
)
658+
types.scope.module = types
658659
types.is_dirty = true
659660
modules("type") = types
660661

src/typechecking.pr

Lines changed: 20 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -319,7 +319,14 @@ def resolve_generic(generic: &Pattern, scpe: &Scope, error_on_fail: bool = true)
319319
case TypeKind::FUNCTION, TypeKind::CLOSURE
320320
var params: &Vector(NamedParameter) = vector::make(NamedParameter)
321321
for var param in generic.parameter_t {
322-
vector::push(params, [tpe = resolve(param.tpe, scpe, error_on_fail)] !NamedParameter)
322+
vector::push(params, [
323+
name = param.name,
324+
tpe = resolve(param.tpe, scpe, error_on_fail),
325+
value = param.value,
326+
kw = param.kw,
327+
varargs = param.varargs,
328+
node = param.node
329+
] !NamedParameter)
323330
}
324331
var return_ids: &Vector(TypeId) = vector::make(TypeId)
325332
for var ret in generic.return_t {
@@ -1283,11 +1290,12 @@ export def function_def(
12831290
] !FunctionDef
12841291
}
12851292
export def to_type(fdef: FunctionDef, scpe: &scope::Scope) -> TypeId {
1286-
return function(fdef.parameter_t, fdef.return_t).resolve(scpe)
1293+
let generic = [ kind = TypeKind::FUNCTION, parameter_t = fdef.parameter_t, return_t = fdef.return_t ] !&Pattern
1294+
return generic.resolve_generic(scpe)
12871295
}
12881296
export def to_type(fdef: FunctionDef) -> TypeId {
12891297
assert fdef.context != null
1290-
return function(fdef.parameter_t, fdef.return_t).resolve(fdef.context.scope)
1298+
return to_type(fdef, fdef.context.scope)
12911299
}
12921300

12931301
export type Signature = struct {
@@ -3426,7 +3434,7 @@ def do_type_lookup(node: &parser::Node, state: &State, is_type: bool = false) ->
34263434
scope::create_type(state.scope, node, parser::ShareMarker::NONE, make_type_ref(name))
34273435
return make_type_ref([ kind = TypeKind::TYPE_DEF, name = name ] !&Pattern)
34283436
} else /*if not lookup_default*/ {
3429-
let value = scope::get(state.scope, node)
3437+
let value = scope::get(state.scope, node, force_compile = not consteval::is_static)
34303438
if not value {
34313439
//errors::errorn(node, "Unknown identifier `", name, "`")
34323440
scope::create_dependency(state.current_value(), scope::make_ident(name))
@@ -5697,7 +5705,7 @@ def check_for_apply_and_update(node: &parser::Node, left: &parser::Node, argumen
56975705
let right = arguments(0).node
56985706

56995707
if not left or not right { return false }
5700-
let tpe = (@left).tpe
5708+
let tpe = left.tpe
57015709
if not tpe { return false }
57025710
if is_function(tpe) { return false }
57035711

@@ -5791,9 +5799,14 @@ export def walk_Call(node: &parser::Node, dry_run: bool, state: &State) -> bool
57915799
walk(node, left, state)
57925800
} else {
57935801
let value = get_value(left, state, force_compile = not consteval::is_static, dry_run = true)
5794-
if value and value.kind == scope::ValueKind::FUNCTION and not is_polymorph(value.fdef.parameter_t){
5802+
if value {
57955803
left.svalue = value
5796-
left.tpe = value.fdef.to_type()
5804+
if value.kind == scope::ValueKind::FUNCTION and not is_polymorph(value.fdef.parameter_t) {
5805+
// TODO is this really correct?
5806+
left.tpe = value.fdef.to_type()
5807+
} else {
5808+
left.tpe = value.get_type()
5809+
}
57975810
}
57985811
}
57995812
}

0 commit comments

Comments
 (0)