Class: TempExpander
- Inherits:
-
SexpProcessor
- Object
- SexpProcessor
- TempExpander
- Defined in:
- lib/bud/rewrite.rb
Overview
Look for temp declarations and remove the “temp” keyword, yielding code that we can safely eval. We also record the set of “temp” collections we’ve seen, and provide a helper method that returns the AST of a state block that contains declarations for all those temp tables.
Constant Summary collapse
- KEYWORD =
:temp
Instance Attribute Summary collapse
-
#did_work ⇒ Object
Returns the value of attribute did_work.
-
#tmp_tables ⇒ Object
readonly
:nodoc: all.
Instance Method Summary collapse
-
#initialize ⇒ TempExpander
constructor
A new instance of TempExpander.
- #process_defn(exp) ⇒ Object
Constructor Details
#initialize ⇒ TempExpander
Returns a new instance of TempExpander.
301 302 303 304 305 306 307 |
# File 'lib/bud/rewrite.rb', line 301 def initialize super() self.require_empty = false self.expected = Sexp @tmp_tables = [] @did_work = false end |
Instance Attribute Details
#did_work ⇒ Object
Returns the value of attribute did_work.
297 298 299 |
# File 'lib/bud/rewrite.rb', line 297 def did_work @did_work end |
#tmp_tables ⇒ Object (readonly)
:nodoc: all
296 297 298 |
# File 'lib/bud/rewrite.rb', line 296 def tmp_tables @tmp_tables end |
Instance Method Details
#process_defn(exp) ⇒ Object
309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 |
# File 'lib/bud/rewrite.rb', line 309 def process_defn(exp) tag, name, args, scope = exp if name.to_s =~ /^__bloom__.+/ block = scope[1] block.each_with_index do |n,i| if i == 0 raise Bud::CompileError if n != :block next end # temp declarations are misparsed if the RHS contains certain constructs # (e.g., group, "do |f| ... end" rather than "{|f| ... }"). Rewrite to # correct the misparsing. if n.sexp_type == :iter iter_body = n.sexp_body new_n = fix_temp_decl(iter_body) unless new_n.nil? block[i] = n = new_n @did_work = true end end _, recv, meth, meth_args = n if meth == KEYWORD and recv.nil? block[i] = rewrite_me(n) @did_work = true end end end s(tag, name, args, scope) end |