Module: Python::Builtins
- Defined in:
- lib/python/builtins.rb
Constant Summary collapse
- Func =
Primitive objects
PyObject.new(:name => "Func")
- Int =
PyObject.new(:name => "Int")
- Bool =
PyObject.new(:name => "Bool", :bases => [Int])
- None =
PyObject.new(:name => "None")
- True =
PyObject.new(:class => Bool, :name => "True", :entity => 1)
- False =
PyObject.new(:class => Bool, :name => "False", :entity => 0)
- Type =
PyObject.new(:name => "Type")
- AddTwoInt =
Primitiv functions
Func.make_instance{|a, b| Int.make_instance(a.entity + b.entity)}
- SubTwoInt =
Func.make_instance{|a, b| Int.make_instance(a.entity - b.entity)}
- MulTwoInt =
Func.make_instance{|a, b| Int.make_instance(a.entity * b.entity)}
- FloordivTwoInt =
Func.make_instance{|a, b| Int.make_instance(a.entity / b.entity)}
- PosInt =
Func.make_instance{|n| Int.make_instance(+ n.entity)}
- NegInt =
Func.make_instance{|n| Int.make_instance(- n.entity)}
- EQInt =
Func.make_instance{|a, b| a.entity == b.entity ? True : False}
- LTInt =
Func.make_instance{|a, b| a.entity < b.entity ? True : False}
- GTInt =
Func.make_instance{|a, b| a.entity > b.entity ? True : False}
- IntToBool =
Func.make_instance{|n| n.entity == 0 ? False : True}
- Print =
Func.make_instance{|o| puts(o.inspect)}
- ClosureCall =
Func.make_instance do |f, *args| if f.entity[:rest_param_name] unless f.entity[:fix_param_names].length <= args.length raise Syntax::PyCallError.new end else unless f.entity[:fix_param_names].length == args.length raise Syntax::PyCallError.new end end bind = f.entity[:fix_param_names].zip(args).to_h env = Environment.new(bind.merge(:parent => f.entity[:env])) catch(:return) { f.entity[:stat].eval(env) } || None end
- MakeInstance =
Func.make_instance do |cls, *args| if class_having_new = cls.base_traverse{|cls| cls["__new__"]} madeobj = class_having_new["__new__"].call(*args) else madeobj = PyObject.new(:class => cls) end if madeobj[:class] == cls && madeobj.has_special_attr?("__init__") madeobj.call_special_method("__init__", *args) end madeobj end