Class: Lab42::Curry::ArgCompiler::Positionals
- Inherits:
-
Object
- Object
- Lab42::Curry::ArgCompiler::Positionals
- Defined in:
- lib/lab42/curry/arg_compiler/positionals.rb
Instance Attribute Summary collapse
-
#ct_pos ⇒ Object
readonly
Returns the value of attribute ct_pos.
-
#rt_pos ⇒ Object
readonly
Returns the value of attribute rt_pos.
Instance Method Summary collapse
- #computations ⇒ Object
- #computed(idx) ⇒ Object
- #export_args ⇒ Object
- #set_computation(comp_arg) ⇒ Object
-
#set_runtime_arg(rt_arg) ⇒ Object
An rt_arg placeholder.
-
#set_value!(value, ct_pos = nil) ⇒ Object
A curried value or computation, occurs from ‘ct_args` or literal values in which case `ct_pos` is `nil`.
- #translation(idx) ⇒ Object
Instance Attribute Details
#ct_pos ⇒ Object (readonly)
Returns the value of attribute ct_pos.
15 16 17 |
# File 'lib/lab42/curry/arg_compiler/positionals.rb', line 15 def ct_pos @ct_pos end |
#rt_pos ⇒ Object (readonly)
Returns the value of attribute rt_pos.
15 16 17 |
# File 'lib/lab42/curry/arg_compiler/positionals.rb', line 15 def rt_pos @rt_pos end |
Instance Method Details
#computations ⇒ Object
17 18 19 |
# File 'lib/lab42/curry/arg_compiler/positionals.rb', line 17 def computations @computations.each { |idx, comp| yield idx, comp } end |
#computed(idx) ⇒ Object
21 22 23 |
# File 'lib/lab42/curry/arg_compiler/positionals.rb', line 21 def computed idx @computations[idx] end |
#export_args ⇒ Object
25 26 27 28 29 30 31 32 33 34 35 |
# File 'lib/lab42/curry/arg_compiler/positionals.rb', line 25 def export_args (0...(@args.keys.max&.succ||0)) .inject [] do |result, idx| if @args.has_key?(idx) result << @args[idx] else result << RuntimeArg end result end end |
#set_computation(comp_arg) ⇒ Object
37 38 39 40 |
# File 'lib/lab42/curry/arg_compiler/positionals.rb', line 37 def set_computation comp_arg @args[comp_arg.position || ct_pos] = comp_arg.class @computations[comp_arg.position || rt_pos] = comp_arg end |
#set_runtime_arg(rt_arg) ⇒ Object
An rt_arg placeholder
43 44 45 46 47 |
# File 'lib/lab42/curry/arg_compiler/positionals.rb', line 43 def set_runtime_arg rt_arg @args[ct_pos] = rt_arg.class @translations[rt_arg.position || rt_pos] = ct_pos _update_positions end |
#set_value!(value, ct_pos = nil) ⇒ Object
A curried value or computation, occurs from ‘ct_args` or literal values in which case `ct_pos` is `nil`
50 51 52 53 54 55 56 57 58 59 60 61 |
# File 'lib/lab42/curry/arg_compiler/positionals.rb', line 50 def set_value! value, ct_pos=nil ct_pos ||= @ct_pos raise Lab42::Curry::DuplicatePositionSpecification, "There is already a curried value #{@args[ct_pos].inspect} at index #{ct_pos}" if _occupied?(ct_pos) @args[ct_pos] = value (@ct_pos..ct_pos.pred).each(&method(:_occupy)) # TODO: Need to check if we have to fill the holes with RuntimeArg # and allow @ct_pos to point to present RuntimeArg values? _update_positions end |
#translation(idx) ⇒ Object
63 64 65 |
# File 'lib/lab42/curry/arg_compiler/positionals.rb', line 63 def translation idx @translations[idx] end |