Commits

bookaa  committed 0392d06

626

  • Participants
  • Parent commits 2b46392

Comments (0)

Files changed (4)

File NameSpace.py

 import OpcodeDef
 import RunState
 import VarDefine
+import NameSpace
 
 class BaseNameSpace():
     def __init__(self):
         if initfunc:
             assert len(initfunc) == 1
             thefunc = initfunc[0]
+            assert thefunc.__class__ is NameSpace.FuncNS
             assert len(thefunc.params) > 0 # the first should be 'self'
             assert len(thefunc.params) == len(params) +1 # +1 is self, not support default param
             funcInstance = RunState.FuncInstance(thefunc, thefunc.params, classInstance)

File OpcodeDef.py

         for s in self.body.Output():
             yield '    ' + s
     def Run(self, rs):
-        pass
+        value = self.condition.GetValue(rs)
+        if value.IfTrue():
+            pass
+        assert False
 
 class Opcode_Return(BaseOpcode):
     def __init__(self, v):
 #!/usr/bin/env python
 
 import VarDefine
+import NameSpace
 
 class RunState():
     def __init__(self, ns, rs):
             return self.varvalue[name]
         fnc = self.SearchFunc('__getattr__')
         if fnc:
-            assert False
+            assert fnc.__class__ is NameSpace.FuncNS
+            funcInstance = FuncInstance(fnc, fnc.params, self)
+            value = VarDefine.Value("classinstance", self)
+            v = VarDefine.Value("string", name)
+            funcInstance.DeclareParameter(fnc.params[0], value)
+            funcInstance.DeclareParameter(fnc.params[1], v)
+            return fnc.Run(funcInstance)
         assert False
     def SearchFunc(self, name):
         for fnc in self.funcs:

File VarDefine.py

 
 class Value():
     def __init__(self, typestr, val):
-        self.typestr = typestr
+        self.typestr = typestr #can be bool, string, number, classinstance
         self.val = val
     def ToString(self):
         if self.typestr == 'number':
             return self.val
         assert False
+    def IsSameValue(self, v):
+        if self.typestr == v.typestr:
+            if self.val == v.val:
+                return True
+        return False
+    def IfTrue(self):
+        if self.typestr == 'bool':
+            return self.val
+        assert False
 
 def IsPythonNumber(s):
     # support more number format later
     def __str__(self):
         return str(self.vleft) + self.op + str(self.vright)
     def GetValue(self, rs):
+        if self.op == '==':
+            v1 = self.vleft.GetValue(rs)
+            v2 = self.vright.GetValue(rs)
+            b = v1.IsSameValue(v2)
+            return Value('bool', b)
         assert False
 
 class StringToken(BaseToken):
     def __str__(self):
         return self.s
     def GetValue(self, rs):
-        assert False
+        return Value('string', self.s[1:-1])
 
 class FuncToken(BaseToken):
     # not really function, but somethine like word(..)