Skip to content

Commit

Permalink
Make structs work in default arguments
Browse files Browse the repository at this point in the history
  • Loading branch information
Victorious3 committed Jan 10, 2024
1 parent 260014a commit 82a0702
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 1 deletion.
6 changes: 5 additions & 1 deletion src/compiler.pr
Original file line number Diff line number Diff line change
Expand Up @@ -4528,7 +4528,11 @@ export def walk_expression(node: &parser::Node, state: &State) -> Value {
var expr = NO_VALUE
if not node { return NO_VALUE }
let scpe = state.scope
state.scope = node.scope

if node.scope {
state.scope = node.scope
}

switch node.kind !int {
case parser::NodeKind::NULL:
expr = walk_Null(node, state)
Expand Down
7 changes: 7 additions & 0 deletions src/consteval.pr
Original file line number Diff line number Diff line change
Expand Up @@ -201,6 +201,11 @@ def walk_From(node: &parser::Node, state: &typechecking::State) {
export def evaluate_parameter(node: &parser::Node, param: &parser::Node, tpe: &typechecking::Type, state: &typechecking::State) -> &compiler::Value {
var value: &compiler::Value = null
if param.value.param.value {
// Set up temporary scope
let prev_scope = compiler_state.module.scope
let temp_scope = scope::enter_scope(state.module.scope)

compiler_state.scope = temp_scope
let previous_block = compiler_state.current_block
let function = set_current_function()
typechecking::walk(node, param.value.param.value, state)
Expand All @@ -209,6 +214,8 @@ export def evaluate_parameter(node: &parser::Node, param: &parser::Node, tpe: &t
let gvalue = compiler::make_global_value(result.tpe, "default_param", null, compiler_state)
let estate = eval::eval(compiler_state)
result = eval::get_value(result, estate)

compiler_state.scope = prev_scope

if result.kind != compiler::ValueKind::NULL {
eval::set_value(gvalue, result, estate)
Expand Down
3 changes: 3 additions & 0 deletions src/typechecking.pr
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,9 @@ export type StructuralTypeMember = struct {
return_t: &Vector(&Type)
}

// TODO Really, types should not be copied. There should only be one instance for every given type.
// This would make comparing them so much easier but changing that at this point might be too much work.
// It would also make the whole TypeMeta thing useless in the process.
export type Type = struct {
kind: TypeKind
// Source line
Expand Down

0 comments on commit 82a0702

Please sign in to comment.