Esempio n. 1
0
def root_scope() -> Scope:
    root = Scope(None)
    root.put('+', primitives.Add())
    root.put('-', primitives.Sub())
    root.put('*', primitives.Mult())
    root.put('/', primitives.Div())
    root.put('=', primitives.Add())
    root.put('>', primitives.Gt())
    root.put('<', primitives.Lt())
    root.put('>=', primitives.GtE())
    root.put('<=', primitives.LtE())
    root.put('%', primitives.Mod())
    root.put('and', primitives.And())
    root.put('or', primitives.Or())
    root.put('eqv?', primitives.IsEqv())
    root.put('type-of', primitives.TypeOf())
    root.put('display', primitives.Display())
    root.put('newline', primitives.Newline())
    root.put('car', primitives.Car())
    root.put('cdr', primitives.Cdr())
    root.put('cons', primitives.Cons())
    root.put('sleep', primitives.Sleep())
    root.put('random', primitives.Random())
    root.put('#t', Bool(True))
    root.put('#f', Bool(False))
    return root
Esempio n. 2
0
 def apply(self, args: List[Value]) -> Value:
     if len(args) != 2:
         raise ArgsNotFit(f'argument mismatch for \'eqv?\', expected 2, given: {len(args)}')
     type_of = TypeOf()
     symbol1, symbol2 = type_of.apply(args[0:1]), type_of.apply(args[1:2])
     if symbol1.val != symbol2.val:
         return Bool(False)
     is_eqv: Bool = False
     x, y = args[0], args[1]
     if isinstance(x, NULL_PAIR_VALUE):
         return Bool(True)
     if isinstance(x, Bool) or isinstance(x, Float) or isinstance(x, Int) or isinstance(x, String) or isinstance(x, Symbol):
         # Make PyCharm happy
         if isinstance(y, Bool) or isinstance(y, Float) or isinstance(y, Int) or isinstance(y, String) or isinstance(y, Symbol):
             is_eqv = x.val == y.val
     return Bool(is_eqv)
Esempio n. 3
0
 def apply(self, args: List[Value]) -> Value:
     if len(args) != 2:
         raise ArgsNotFit(f'argument mismatch for \'<=\', expected 2, given: {len(args)}')
     x, y = args[0], args[1]
     if (isinstance(x, Int) or isinstance(x, Float)) and (isinstance(y, Int) or isinstance(y, Float)):
         return Bool(x.val <= y.val)
     raise ArgsNotFit('incorrect argument type for \'<=\', expected number')
Esempio n. 4
0
 def apply(self, args: List[Value]) -> Value:
     ret: bool = True
     for x in args:
         if isinstance(x, Bool):
             ret = x.val and ret
         else:
             raise ArgsNotFit(f'incorrect argument type for \'and\': {x}, expected bool')
     return Bool(ret)
Esempio n. 5
0
 def apply(self, args: List[Value]) -> Value:
     ret: bool = False
     for x in args:
         if isinstance(x, Bool):
             ret = ret or x.val
         else:
             raise ArgsNotFit(
                 'incorrect argument type for \`or\', expected bool')
     return Bool(ret)