You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
When trying to write the Dodge the Creeps (Godot 2d demo) with GDLisp, the GDLisp compiler outputs the script error :
GDLisp v1.0.0
Running under Godot
3.5.3.stable.official.6c814135b
Compiling .\main.lisp ...
SCRIPT ERROR: Parse Error: The identifier "direction" isn't declared in the current scope.
at: GDScript::reload (C:/Users/yzxl/AppData/Local/Temp/__gdlisp_fileDt1rg.gd:38)
The same parsed error can be caused by the simple statement :
(let ((x 0))
(set x (+ x 1)))
The statement will be transformed by the GDLisp compiler, and output some GDScript statements as below:
functest():
varx=x+1returnx
After a several attempts, I think that the redundant assignment elimination leads to the variable beyond its scope.
See the src\optimize\gdscript\redundant_assignment_elimination.rs. :)
// ...pubfn run_on_stmts(&self,stmts:&[Stmt]) -> Result<Vec<Stmt>,GDError>{// Look for something to eliminate. If we find it, do the// elimination and call the function again. If not, we're done.for(index, stmt1)in stmts.iter().enumerate(){ifletSome(AssignmentStmt{ assign_type,var_name: name,expr: expr1 }) = self.match_first_assign(stmt1){if !constant::expr_has_side_effects(expr1){// Found a match. Keep going.for jndex in index+1..stmts.len(){let stmt2 = &stmts[jndex];ifletSome(expr2) = self.match_second_assign(name, stmt2){// Redundant assignment; culllet new_stmt = self.rebuild_assignment(assign_type.ensure_eq(), name, expr2);letmut new_stmts = stmts.to_vec();
new_stmts.splice(index..=jndex,vec!(new_stmt).into_iter());returnself.run_on_stmts(&new_stmts);}elseif constant::stmt_has_side_effects(stmt2){// If it's stateful, then we can't do anythingbreak;}}}}}//...
When the first assignment type is VarDecl and the second assignment type is AssignType::Assignment(op::AssignOp::Eq), the expression of the second statement will be moved as the new VarDecl statement expression. The expression may contains any number of references of the variable (with the same name).
When inserting some stateful statements, or replacing the second assignment with other compound assignments, the script error will disappear. For example,
(let ((x 0))
(print"hello world")
(set x (+ x 1)))
Of course, they not trigger the redundant assignment elimination. :)
Environment Info.
Windows
Godot 3.5.3.stable.official.6c814135b
GDLisp v1.0.0
The text was updated successfully, but these errors were encountered:
When trying to write the Dodge the Creeps (Godot 2d demo) with GDLisp, the GDLisp compiler outputs the script error :
The same parsed error can be caused by the simple statement :
The statement will be transformed by the GDLisp compiler, and output some GDScript statements as below:
After a several attempts, I think that the redundant assignment elimination leads to the variable beyond its scope.
See the
src\optimize\gdscript\redundant_assignment_elimination.rs
. :)When the first assignment type is
VarDecl
and the second assignment type isAssignType::Assignment(op::AssignOp::Eq)
, the expression of the second statement will be moved as the newVarDecl
statement expression. The expression may contains any number of references of the variable (with the same name).When inserting some stateful statements, or replacing the second assignment with other compound assignments, the script error will disappear. For example,
Of course, they not trigger the redundant assignment elimination. :)
The text was updated successfully, but these errors were encountered: