|
|
|
@ -8,6 +8,7 @@ module Lox
|
|
|
|
|
|
|
|
|
|
@scopes = []
|
|
|
|
|
@current_func = :NONE
|
|
|
|
|
@current_class = :NONE
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
def resolve(*resolvees)
|
|
|
|
@ -25,6 +26,7 @@ module Lox
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
def visit_class(stmt)
|
|
|
|
|
with_current_class(:CLASS) do
|
|
|
|
|
declare(stmt.name)
|
|
|
|
|
|
|
|
|
|
with_scope do
|
|
|
|
@ -36,6 +38,7 @@ module Lox
|
|
|
|
|
|
|
|
|
|
define(stmt.name)
|
|
|
|
|
end
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
nil
|
|
|
|
|
end
|
|
|
|
@ -104,6 +107,8 @@ module Lox
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
def visit_this(expr)
|
|
|
|
|
raise ResolverError.new(expr.keyword, "Can't use 'this' outside of a class.") if @current_class == :NONE
|
|
|
|
|
|
|
|
|
|
resolve_local(expr, expr.keyword)
|
|
|
|
|
nil
|
|
|
|
|
end
|
|
|
|
@ -163,5 +168,14 @@ module Lox
|
|
|
|
|
@current_func = enclosing_func
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
def with_current_class(type)
|
|
|
|
|
enclosing_class = @current_class
|
|
|
|
|
@current_class = type
|
|
|
|
|
|
|
|
|
|
yield
|
|
|
|
|
|
|
|
|
|
@current_class = enclosing_class
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
end
|
|
|
|
|
end
|
|
|
|
|