Class: List
Instance Attribute Summary
Attributes inherited from DataType
Instance Method Summary collapse
- #add(other) ⇒ Object
- #as_code_string ⇒ Object
- #as_string ⇒ Object
-
#initialize(val, scope = nil) ⇒ List
constructor
A new instance of List.
- #iter ⇒ Object
- #mul(other) ⇒ Object
- #reset ⇒ Object
Constructor Details
#initialize(val, scope = nil) ⇒ List
Returns a new instance of List.
342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 |
# File 'lib/sdx/vm/datatypes.rb', line 342 def initialize(val, scope=nil) @internal = val @scope = scope @pos = 0 @fields = { "__as_string" => (NativeFnInternal.new (Proc.new do as_string end)), "__as_code_string" => (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 |
Instance Method Details
#add(other) ⇒ Object
412 413 414 |
# File 'lib/sdx/vm/datatypes.rb', line 412 def add(other) return List.new [*@internal, (Variable.new other, (get_type other), @scope || @internal[0].scope)] end |
#as_code_string ⇒ Object
388 389 390 391 392 393 394 395 396 |
# File 'lib/sdx/vm/datatypes.rb', line 388 def as_code_string s = "" @internal.each do |item| s += (codify item) + ", " end s = "[" + s[0..-3] s += "]" Str.new s end |
#as_string ⇒ Object
378 379 380 381 382 383 384 385 386 |
# File 'lib/sdx/vm/datatypes.rb', line 378 def as_string s = "" @internal.each do |item| s += (stringify item) + ", " end s = "[" + s[0..-3] s += "]" Str.new s end |
#iter ⇒ Object
402 403 404 405 406 407 408 409 410 |
# File 'lib/sdx/vm/datatypes.rb', line 402 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) ⇒ Object
416 417 418 |
# File 'lib/sdx/vm/datatypes.rb', line 416 def mul(other) return List.new @internal * other.internal end |
#reset ⇒ Object
398 399 400 |
# File 'lib/sdx/vm/datatypes.rb', line 398 def reset @pos = 0 end |