class List
Public Class Methods
new(val, scope=nil)
click to toggle source
# File lib/sdx/vm/datatypes.rb, line 498 def initialize(val, scope=nil) @internal = val @scope = scope @pos = 0 @fields = { "__as_str" => (NativeFnInternal.new (Proc.new do as_string end)), "__as_code_str" => (NativeFnInternal.new (Proc.new do as_code_string end)), "__reset" => (NativeFnInternal.new (Proc.new do reset end)), "__iter" => (NativeFnInternal.new (Proc.new do iter end)), "__add" => (NativeFnInternal.new (Proc.new do |other| add other[0] end)), "__mul" => (NativeFnInternal.new (Proc.new do |other| mul other[0] end)), "__arity" => (Int.new 1), "__call" => (NativeFnInternal.new (Proc.new do |args, scope| @internal[args[0].value.internal] end)), "__eq" => (NativeFnInternal.new (lambda do |other| Bool.new @internal == other[0].internal end)), "__neq" => (NativeFnInternal.new (lambda do |other| Bool.new @internal != other[0].internal end)) } end
Public Instance Methods
add(other)
click to toggle source
# File lib/sdx/vm/datatypes.rb, line 568 def add(other) return List.new [*@internal, (Variable.new other, (get_type other), @scope || @internal[0].scope)] end
as_code_string()
click to toggle source
# File lib/sdx/vm/datatypes.rb, line 544 def as_code_string s = "" @internal.each do |item| s += (codify item) + ", " end s = "[" + s[0..-3] s += "]" Str.new s end
as_string()
click to toggle source
# File lib/sdx/vm/datatypes.rb, line 534 def as_string s = "" @internal.each do |item| s += (stringify item) + ", " end s = "[" + s[0..-3] s += "]" Str.new s end
iter()
click to toggle source
# File lib/sdx/vm/datatypes.rb, line 558 def iter val = @internal[@pos] @pos += 1 if val return val else return Variable.new Nil.new, :nil, @internal[0].scope end end
mul(other)
click to toggle source
# File lib/sdx/vm/datatypes.rb, line 572 def mul(other) case other when Int else error "Cannot use List * on #{other.class}" return nil end return List.new @internal * other.internal end
reset()
click to toggle source
# File lib/sdx/vm/datatypes.rb, line 554 def reset @pos = 0 end