lib/loxxy/back_end/resolver.rb in loxxy-0.1.12 vs lib/loxxy/back_end/resolver.rb in loxxy-0.1.13
- old
+ new
@@ -56,12 +56,15 @@
# A class declaration adds a new variable to current scope
def before_class_stmt(aClassStmt)
declare(aClassStmt.name)
end
- def after_class_stmt(aClassStmt, _visitor)
+ def after_class_stmt(aClassStmt, aVisitor)
define(aClassStmt.name)
+ aClassStmt.body.each do |fun_stmt|
+ resolve_function(fun_stmt, :method, aVisitor)
+ end
end
def before_for_stmt(aForStmt)
before_block_stmt(aForStmt)
end
@@ -107,10 +110,15 @@
# Assignment expressions require their variables resolved
def after_assign_expr(anAssignExpr, aVisitor)
resolve_local(anAssignExpr, aVisitor)
end
+ def after_set_expr(aSetExpr, aVisitor)
+ # Evaluate object part
+ aSetExpr.object.accept(aVisitor)
+ end
+
# Variable expressions require their variables resolved
def before_variable_expr(aVarExpr)
var_name = aVarExpr.name
if !scopes.empty? && (scopes.last[var_name] == false)
raise StandardError, "Can't read variable #{var_name} in its own initializer"
@@ -123,9 +131,14 @@
def after_call_expr(aCallExpr, aVisitor)
# Evaluate callee part
aCallExpr.callee.accept(aVisitor)
aCallExpr.arguments.reverse_each { |arg| arg.accept(aVisitor) }
+ end
+
+ def after_get_expr(aGetExpr, aVisitor)
+ # Evaluate object part
+ aGetExpr.object.accept(aVisitor)
end
# function declaration creates a new scope for its body & binds its parameters for that scope
def before_fun_stmt(aFunStmt, aVisitor)
declare(aFunStmt.name)