Class: Lab42::Curry::ArgCompiler::Phase2
- Inherits:
-
Object
- Object
- Lab42::Curry::ArgCompiler::Phase2
- Defined in:
- lib/lab42/curry/arg_compiler/phase2.rb
Instance Attribute Summary collapse
-
#compiler ⇒ Object
readonly
Returns the value of attribute compiler.
-
#rt_args ⇒ Object
readonly
Returns the value of attribute rt_args.
-
#rt_blk ⇒ Object
readonly
Returns the value of attribute rt_blk.
-
#rt_kwds ⇒ Object
readonly
Returns the value of attribute rt_kwds.
Instance Method Summary collapse
-
#compile ⇒ Object
TODO: Easy, peasy sequential refactor.
Instance Attribute Details
#compiler ⇒ Object (readonly)
Returns the value of attribute compiler.
8 9 10 |
# File 'lib/lab42/curry/arg_compiler/phase2.rb', line 8 def compiler @compiler end |
#rt_args ⇒ Object (readonly)
Returns the value of attribute rt_args.
8 9 10 |
# File 'lib/lab42/curry/arg_compiler/phase2.rb', line 8 def rt_args @rt_args end |
#rt_blk ⇒ Object (readonly)
Returns the value of attribute rt_blk.
8 9 10 |
# File 'lib/lab42/curry/arg_compiler/phase2.rb', line 8 def rt_blk @rt_blk end |
#rt_kwds ⇒ Object (readonly)
Returns the value of attribute rt_kwds.
8 9 10 |
# File 'lib/lab42/curry/arg_compiler/phase2.rb', line 8 def rt_kwds @rt_kwds end |
Instance Method Details
#compile ⇒ Object
TODO: Easy, peasy sequential refactor
11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 |
# File 'lib/lab42/curry/arg_compiler/phase2.rb', line 11 def compile if rt_blk && compiler.ct_blk && !compiler.allows_override? raise Lab42::Curry::DuplicateBlock, "block has already been curried" end @blk = rt_blk || compiler.ct_blk @kwds = compiler.final_kwds.merge(rt_kwds){ |k, old, new| raise Lab42::Curry::DuplicateKeywordArgument, "keyword argument :#{k} is already defined with value #{old.inspect} cannot override with #{new.inspect}" unless compiler.allows_override? new } @args = compiler.positionals.export_args @first_free = 0 rt_args.each_with_index do |rt_arg, idx| computed = compiler.positionals.computed(idx) if computed end translated = compiler.positionals.translation(idx) if translated @args[translated] = rt_arg else # @args[idx + some_dynamic_offset] = rt_arg ??? _occupy_first_free rt_arg end end compiler.positionals.computations do |idx, computed_arg| @args[idx] = _compute(computed_arg) end @kwds.each do |kwd, val| case val when ComputedArg @kwds[kwd] = _compute(val) end end # TODO: Raise ArgumentError if holes are left in @args, but for that reason we must make compiler.final_args compact # and indicate wholes with RuntimeArg, not sure this is done same for holes in @kwds [@args, @kwds, @blk] end |