Commits

bookaa committed 653f6ff

729

  • Participants
  • Parent commits eccf4d3

Comments (0)

Files changed (3)

File MainBrain.py

     def Run(self):
         runstate = RunState.MbFrame(self.globalns, None)
 
-        value = VarDefine.RunConstant('str', '__main__')
+        value = VarDefine.wrap('__main__') #RunConstant('str', '__main__')
         var = VarDefine.NameToken('__name__')
         runstate.SetVarValue(var, value)
 
             assert fnc.__class__ is NameSpace.FuncNS
             funcInstance = FuncInstance(fnc, fnc.params, self)
             value = VarDefine.MbObject("classinstance", self)
-            v = VarDefine.RunConstant("str", name)
+            v = VarDefine.wrap(name)
             funcInstance.DeclareParameter(fnc.params[0], value)
             funcInstance.DeclareParameter(fnc.params[1], v)
             return fnc.RunFunc(funcInstance)

File VarDefine.py

         if self.typestr == v.typestr == 'int':
             v1 = int(self.val)
             v2 = int(v.val)
-            return RunConstant('int', str(v1 + v2))
+            return wrap(v1 + v2)
         if self.typestr == v.typestr == 'str':
-            return RunConstant('str', self.val + v.val)
+            return wrap(self.val + v.val)
         assert False
     def Minus(self, v):
         if self.typestr == v.typestr == 'int':
             v1 = int(self.val)
             v2 = int(v.val)
-            return RunConstant('int', str(v1 - v2))
+            return wrap(v1 - v2)
         assert False
     def Times(self, v):
         if self.typestr == v.typestr == 'int':
             v1 = int(self.val)
             v2 = int(v.val)
-            return RunConstant('int', str(v1 * v2))
+            return wrap(v1 * v2)
         assert False
 
 class RunConstant(MbObject):
     def __init__(self, typestr, valstr):
         MbObject.__init__(self, typestr, valstr)
 
+def wrap(x):
+    # should be MbObjectSpace.wrap
+    if isinstance(x, str):
+        return RunConstant('str', x)
+    if isinstance(x, bool):
+        return RunConstant('bool', x)
+    if isinstance(x, int):
+        return RunConstant('int', str(x))
+    assert False
+
 def IsPythonNumber(s):
     # support more number format later
     import re
         return self.name
     def GetValue(self, rs):
         if IsPythonNumber(self.name):
-            return RunConstant("int", self.name)
+            value = int(self.name)
+            return wrap(value) #RunConstant("int", self.name)
         return rs._GetAttr(self.name)
 
 def CheckOpPriority(op1, op2):
             v1 = self.vleft.GetValue(rs)
             v2 = self.vright.GetValue(rs)
             b = v1.IsSameValue(v2)
-            return RunConstant('bool', b)
+            return wrap(b) #RunConstant('bool', b)
         if self.op == '.':
             runstate = rs.GetVarRunState(self.vleft)
             value = self.vright.GetValue(runstate)
     def __str__(self):
         return self.s
     def GetValue(self, rs):
-        return RunConstant('str', self.s[1:-1])
+        s1 = self.s[1:-1]
+        return wrap(s1)
 
 class FuncToken(BaseToken):
     # not really function, but somethine like word(..)