Commits

bookaa committed d8f12a0

702

  • Participants
  • Parent commits c440871

Comments (0)

Files changed (3)

File MainBrain.py

 class MainBrain():
     def __init__(self):
         self.langDef = None
-        self.globalns = NameSpace.BaseNameSpace()
+        self.globalns = NameSpace.ModuleNS('DefaultModule')
 
     def DefineInLang(self, strLang):
         assert not self.langDef

File NameSpace.py

                 yield s
 
     def OutputCpp(self):
+        yield '// head file -------------'
         for s in self.OutputCpp_H():
             yield s
         yield '//-------------'
             yield s
 
     def OutputCpp_H(self):
-        yield '// head file -------------'
+        assert False
         runstate = RunState.RunState(self, None)
 
         value = VarDefine.Value('string', 'UserCpp')
         runstate.SetVarValue(var, value)
 
         self.Run(runstate)
+
+        for s in runstate.OutputCpp_H():
+            yield '    ' + s
         pass
 
-
     def OutputCpp_Cpp(self):
         yield '// cpp file -------------'
 
     def RegisterVar(self, v):
         self.vars.append(v)
 
+class ModuleNS(BaseNameSpace):
+    def __init__(self, name):
+        BaseNameSpace.__init__(self)
+        self.name = name
+    def OutputCpp_H(self):
+        runstate = RunState.RunState(self, None)
+
+        value = VarDefine.Value('string', 'UserCpp')
+        var = VarDefine.NameToken('__name__')
+        runstate.SetVarValue(var, value)
+
+        self.Run(runstate)
+
+        yield 'class class_%s' % self.name
+        yield '{'
+        for s in runstate.OutputCpp_H():
+            yield '    ' + s
+        yield '};'
+        yield 'extern class class_%s the_%s;' % (self.name, self.name)
+
 class ClassNS(BaseNameSpace):
     def __init__(self, name):
         BaseNameSpace.__init__(self)
         else:
             assert not params #no param, it must be no __init__
         return value
+    def OutputCpp_H(self, rs):
+        classInstance = RunState.ClassInstance(self, rs)
+        self.Run(classInstance)
+
+        yield 'class ' + self.name
+        yield '{'
+        initfunc = [k for k in classInstance.funcs if k.name == '__init__']
+        if initfunc:
+            assert len(initfunc) == 1
+            thefunc = initfunc[0]
+            classInstance.funcs.remove(thefunc)
+            pass
+
+        for s in classInstance.OutputCpp_H():
+            yield '    ' + s
+        yield '};'
 
 class FuncNS(BaseNameSpace):
     def __init__(self, name, params):
             if fnc.name == name:
                 return fnc
         return None
+    def OutputCpp_H(self):
+        for theclass in self.classes:
+            for s in theclass.OutputCpp_H(self):
+                yield s
+        pass
 
 class ClassInstance(RunState):
     def __init__(self, classns, owner_rs):