From 97371d13be6c3a1b5a6262e266fd5d3189727846 Mon Sep 17 00:00:00 2001 From: Alpha Chen Date: Wed, 17 Aug 2022 20:37:01 -0700 Subject: [PATCH] 11.3.1 --- ruby/Rakefile | 7 ++++++- ruby/lib/lox/resolver.rb | 33 +++++++++++++++++++++++++++++++++ 2 files changed, 39 insertions(+), 1 deletion(-) create mode 100644 ruby/lib/lox/resolver.rb diff --git a/ruby/Rakefile b/ruby/Rakefile index bf533d4..ca9dddc 100644 --- a/ruby/Rakefile +++ b/ruby/Rakefile @@ -7,7 +7,12 @@ namespace :test do desc "Run tests on source changes" task :watch do loop do - sh "fd .*.rb | entr -d rake test:isolated" + sh <<~SH + while true + do + fd .*.rb | entr -d rake test:isolated + done + SH end end end diff --git a/ruby/lib/lox/resolver.rb b/ruby/lib/lox/resolver.rb new file mode 100644 index 0000000..1321adf --- /dev/null +++ b/ruby/lib/lox/resolver.rb @@ -0,0 +1,33 @@ +module Lox + class Resolver + + def initialize(interpreter) + @interpreter = interpreter + + @scopes = [] + end + + def resolve(values) + values.each do + value.accept(self) + end + end + + def visit_block(stmt) + with_scope do + resolve(stmt.stmts) + end + nil + end + + private + + def with_block + @scopes.push({}) + yield + @scopes.pop + end + + + end +end