Commits

bookaa committed 2b46392

621

Comments (0)

Files changed (3)

 #!/usr/bin/env python
 
+import VarDefine
+
 class BaseOpcode():
     def Output(self):
         raise 'not implement'
     def Output(self):
         yield 'print ' + str(self.v)
     def Run(self, rs):
-        assert False
+        def PrintArgToString(v):
+            if v.__class__ is VarDefine.CombineToken:
+                if v.op == ',':
+                    s1 = PrintArgToString(v.vleft)
+                    s2 = PrintArgToString(v.vright)
+                    return s1 + ' ' + s2
+                if v.op == '.':
+                    runstate = rs.GetVarRunState(v.vleft)
+                    value = v.vright.GetValue(runstate)
+                    return value.ToString()
+                assert False
+            value = v.GetValue(rs)
+            return value.ToString()
+        s = PrintArgToString(self.v)
+        print s
 
 class Opcode_ClassDef(BaseOpcode):
     def __init__(self, classdef):
         if name in self.varvalue:
             assert False
         self.varvalue.setdefault(name, value)
+    def _GetAttr(self, name):
+        assert type(name) is str
+        if name in self.varvalue:
+            return self.varvalue[name]
+        fnc = self.SearchFunc('__getattr__')
+        if fnc:
+            assert False
+        assert False
+    def SearchFunc(self, name):
+        for fnc in self.funcs:
+            if fnc.name == name:
+                return fnc
+        return None
 
 class ClassInstance(RunState):
     def __init__(self, classns, owner_rs):
     def __init__(self, typestr, val):
         self.typestr = typestr
         self.val = val
+    def ToString(self):
+        if self.typestr == 'number':
+            return self.val
+        assert False
 
 def IsPythonNumber(s):
     # support more number format later
     def GetValue(self, rs):
         if IsPythonNumber(self.name):
             return Value("number", self.name)
-        assert False
+        return rs._GetAttr(self.name)
 
 class CombineToken(BaseToken):
     def __init__(self, vleft, vright, op):