class Int
Public Class Methods
new(val=nil)
click to toggle source
# File lib/sdx/vm/datatypes.rb, line 76 def initialize(val=nil) if val != nil @internal = val end @fields = { "__as_str" => (NativeFnInternal.new (Proc.new do as_string end)), "__as_code_str" => (NativeFnInternal.new (Proc.new do as_string end)), "__as_bool" => (NativeFnInternal.new (Proc.new do as_bool end)), "__add" => (NativeFnInternal.new (Proc.new do |other| add other[0] end)), "__sub" => (NativeFnInternal.new (Proc.new do |other| sub other[0] end)), "__mul" => (NativeFnInternal.new (Proc.new do |other| mul other[0] end)), "__div" => (NativeFnInternal.new (Proc.new do |other| div other[0] end)), "__mod" => (NativeFnInternal.new (Proc.new do |other| mod other[0] end)), "__pow" => (NativeFnInternal.new (Proc.new do |other| pow other[0] end)), "__lt" => (NativeFnInternal.new (Proc.new do |other| lt other[0] end)), "__gt" => (NativeFnInternal.new (Proc.new do |other| gt other[0] end)), "__le" => (NativeFnInternal.new (Proc.new do |other| le other[0] end)), "__ge" => (NativeFnInternal.new (Proc.new do |other| ge other[0] 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 137 def add(other) case other when Int when Num else error "Cannot use Int + on #{other.class}" return nil end Int.new @internal + other.internal end
as_bool()
click to toggle source
# File lib/sdx/vm/datatypes.rb, line 133 def as_bool Bool.new true end
as_string()
click to toggle source
# File lib/sdx/vm/datatypes.rb, line 129 def as_string Str.new @internal.to_s end
div(other)
click to toggle source
# File lib/sdx/vm/datatypes.rb, line 170 def div(other) case other when Int when Num else error "Cannot use Int / on #{other.class}" return nil end Num.new (@internal / (other.internal / 1.0)).to_s end
ge(other)
click to toggle source
# File lib/sdx/vm/datatypes.rb, line 236 def ge(other) case other when Int when Num else error "Cannot use Int >= on #{other.class}" return nil end Bool.new @internal >= other.internal end
gt(other)
click to toggle source
# File lib/sdx/vm/datatypes.rb, line 214 def gt(other) case other when Int when Num else error "Cannot use Int > on #{other.class}" return nil end Bool.new @internal > other.internal end
le(other)
click to toggle source
# File lib/sdx/vm/datatypes.rb, line 225 def le(other) case other when Int when Num else error "Cannot use Int <= on #{other.class}" return nil end Bool.new @internal <= other.internal end
lt(other)
click to toggle source
# File lib/sdx/vm/datatypes.rb, line 203 def lt(other) case other when Int when Num else error "Cannot use Int < on #{other.class}" return nil end Bool.new @internal < other.internal end
mod(other)
click to toggle source
# File lib/sdx/vm/datatypes.rb, line 181 def mod(other) case other when Int when Num else error "Cannot use Int % on #{other.class}" return nil end Int.new @internal % other.internal end
mul(other)
click to toggle source
# File lib/sdx/vm/datatypes.rb, line 159 def mul(other) case other when Int when Num else error "Cannot use Int * on #{other.class}" return nil end Int.new @internal * other.internal end
pow(other)
click to toggle source
# File lib/sdx/vm/datatypes.rb, line 192 def pow(other) case other when Int when Num else error "Cannot use Int ^ on #{other.class}" return nil end Int.new @internal ** other.internal end
sub(other)
click to toggle source
# File lib/sdx/vm/datatypes.rb, line 148 def sub(other) case other when Int when Num else error "Cannot use Int - on #{other.class}" return nil end Int.new @internal - other.internal end