Commits

Gigih Aji Ibrahim committed adea0cf

support 'val' in class/module declaration

Comments (0)

Files changed (3)

 
 
 class VarDecl(Decl):
-    def __init__(self, loc, name, type, default=None, attrs=[]):
+    def __init__(self, loc, mode, name, type, default=None, attrs=[]):
         assertInstance(name, str)
         assertNoneOrInstance(default, Expr)
 
         super(VarDecl, self).__init__(loc, name)
-        self.setAttr(type=type, default=default,attrs=attrs)
+        self.setAttr(mode=mode, type=type, default=default,attrs=attrs)
 
 
 class ParamDecl(Decl):
         elif tt == 'struct':    return self.pStructDecl(token, attrs)
         elif tt == 'enum':      return self.pEnumDecl(token, attrs)
         elif tt == 'def':       return self.pDefDecl(token, attrs)
-        elif tt == 'var':       return self.pVarDecl(token, attrs)
+        elif tt in ['var', 'val', 'const']: return self.pVarDecl(token, attrs)
         elif tt == 'pass':      return self.pPassDecl(token, attrs)
 
         raise ParseError(self.getLoc(token), "Cannot Parse {}".format(token.value()))
         init = self.pExpr() if self.accept('=') else None
         self.endOfStmt()
 
-        return VarDecl(self.getLoc(token), name, type, init, attrs)
+        return VarDecl(self.getLoc(token), token.value(), name, type, init, attrs)
 
     def pParamDecl(self):
         token   = self.current
         right = self.pExpr(precedence)
 
         if not isinstance(right, NameExpr):
-            print "expected NameExpr but got {}".format(right.__class__.__name__)
+            report.warning(right.loc, "expected NameExpr but got {}".format(right.__class__.__name__))
 
         return NameExpr(self.getLoc(left.loc), right.name, left)
 

src/pygen/generator.py

             self.block(node.stmts)
         
     def runtime(self, modQName, node):
-        """ create runtime spesific code to fullfil the body of definition """
+        """ create runtime specific code to fulfill the body of definition """
          
         rtTable = {
             'std.io': [ ('File', self._rtExtend), ('Error', self._rtAlias)],
         
         if action == False:
             raise CodeGenError(
-               'Compiler cannot generate the code for {name} because the spesific runtime code does not exist.'.format(
+               'Compiler cannot generate the code for {name} because the specific runtime code does not exist.'.format(
                 name=modQName+"."+node.name))
             
         pymodule = modQName.replace('std','rt')