Skip to content

Commit

Permalink
Proposal to resolve #127
Browse files Browse the repository at this point in the history
  • Loading branch information
phorward committed Feb 29, 2024
1 parent c4e9f06 commit 127a9cf
Show file tree
Hide file tree
Showing 3 changed files with 38 additions and 15 deletions.
29 changes: 22 additions & 7 deletions src/compiler/ast.rs
Original file line number Diff line number Diff line change
Expand Up @@ -406,7 +406,26 @@ fn traverse_node_static(scope: &Scope, assign: Option<String>, node: &Dict) -> I
let emit = node["emit"].borrow();
let emit = emit.object::<Str>().unwrap().as_str();

if emit.starts_with("value_") {
// Special case: Put a generic with an assignment name into its own parselet
if emit == "value_generic" && assign.is_some() {
// Handle anything else as an implicit parselet in its own scope
let implicit_parselet = ImlParselet::new(ImlParseletInstance::new(
None,
None,
traverse_node_offset(node),
assign,
5,
false,
));

implicit_parselet.borrow().model.borrow_mut().body = traverse_node_rvalue(
&scope.shadow(ScopeLevel::Parselet(implicit_parselet.clone())),
node,
Rvalue::CallOrLoad,
);

ImlValue::from(implicit_parselet)
} else if emit.starts_with("value_") {
traverse_node_value(scope, node, assign).try_resolve(scope)
} else {
// Handle anything else as an implicit parselet in its own scope
Expand All @@ -420,15 +439,11 @@ fn traverse_node_static(scope: &Scope, assign: Option<String>, node: &Dict) -> I
));

implicit_parselet.borrow().model.borrow_mut().body = {
let ret = traverse_node_rvalue(
match traverse_node_rvalue(
&scope.shadow(ScopeLevel::Parselet(implicit_parselet.clone())),
node,
Rvalue::Load,
);

//println!("ret = {:?}", ret);

match ret {
) {
ImlOp::Nop => return value!(void).into(),
// Defined value call without parameters, or load becomes just the value
ImlOp::Load { target: value, .. } => return value,
Expand Down
2 changes: 1 addition & 1 deletion src/compiler/iml/imlvalue.rs
Original file line number Diff line number Diff line change
Expand Up @@ -306,7 +306,7 @@ impl ImlValue {
true
}
}
Self::Instance { target, .. } => target.is_callable(without_arguments),
Self::Instance { target, .. } => true,
_ => false,
}
}
Expand Down
22 changes: 15 additions & 7 deletions tests/parselet_generic_selfref.tok
Original file line number Diff line number Diff line change
@@ -1,10 +1,18 @@
Y: X<Y>

X: @<X> {
'x' X
Assignment : @<Expression, Assignment: Assignment, ext: void> {
Ident _ '=' _ Expect<Assignment> ast("assign" + ext)
Expression ast("value")
}

HoldAssignment : Assignment<Int, HoldAssignment> # endless recursion!
# HoldAssignment : Assignment<Int, HoldAssignment> Empty # works!

# ast_print(Assignment<Int>)
ast_print(HoldAssignment)

#---
#a=b=c=42
#---
#ERR:SKIP
#ERR:not yet implemented: Recursive resolve() impossible by design, see bug #127
#ERR:SKIP
#assign [start 1:1, end 1:9]
# assign [start 1:3, end 1:9]
# assign [start 1:5, end 1:9]
# value [start 1:7, end 1:9] => 42

0 comments on commit 127a9cf

Please sign in to comment.