Changeset 67:824b882cb1f6 in livinglogic.java.ul4

Show
Ignore:
Timestamp:
05/31/08 22:05:51 (11 years ago)
Author:
Walter Doerwald <walter@…>
Branch:
default
Message:

Convert the last Python code that uses Python AST classes (CallFunc? and CallMeth?)

Files:
1 modified

Legend:

Unmodified
Added
Removed
  • library/src/com/livinglogic/sxtl/l4c.py

    r64 r67  
    274274 
    275275 
    276 class AST(object): 
    277     def __init__(self, start, end): 
    278         self.start = start 
    279         self.end = end 
    280  
    281     def getType(self): 
    282         return self.type 
    283  
    284  
    285 from com.livinglogic.sxtl import Const, None as None_, True as True_, False as False_, Int, Float, Str, Name, GetSlice, Not, Neg, StoreVar, AddVar, SubVar, MulVar, FloorDivVar, TrueDivVar, ModVar, DelVar, GetItem, GetSlice1, GetSlice2, Equal, NotEqual, Contains, NotContains, Add, Sub, Mul, FloorDiv, TrueDiv, Or, And, Mod, GetSlice12, GetAttr, Render, For, For1, For2 
    286  
    287  
    288 class CallFunc(AST): 
    289     def __init__(self, start, end, name, args): 
    290         AST.__init__(self, start, end) 
    291         self.name = name 
    292         self.args = args 
    293  
    294     def __repr__(self): 
    295         if self.args: 
    296             return "%s(%r, %r, %r, %s)" % (self.__class__.__name__, self.start, self.end, self.name, repr(self.args)[1:-1]) 
    297         else: 
    298             return "%s(%r, %r, %r)" % (self.__class__.__name__, self.start, self.end, self.name) 
    299  
    300     def compile(self, template, registers, location): 
    301         if len(self.args) == 0: 
    302             r = registers.alloc() 
    303             template.opcode("callfunc0", r, self.name.name, location) 
    304             return r 
    305         elif len(self.args) == 1: 
    306             r0 = self.args[0].compile(template, registers, location) 
    307             template.opcode("callfunc1", r0, r0, self.name.value, location) 
    308             return r0 
    309         elif len(self.args) == 2: 
    310             r0 = self.args[0].compile(template, registers, location) 
    311             r1 = self.args[1].compile(template, registers, location) 
    312             template.opcode("callfunc2", r0, r0, r1, self.name.value, location) 
    313             registers.free(r1) 
    314             return r0 
    315         else: 
    316             raise ValueError("%d arguments not supported" % len(self.args)) 
    317  
    318  
    319 class CallMeth(AST): 
    320     def __init__(self, start, end, name, obj, args): 
    321         AST.__init__(self, start, end) 
    322         self.name = name 
    323         self.obj = obj 
    324         self.args = args 
    325  
    326     def __repr__(self): 
    327         if self.args: 
    328             return "%s(%r, %r, %r, %r, %s)" % (self.__class__.__name__, self.start, self.end, self.name, self.obj, repr(self.args)[1:-1]) 
    329         else: 
    330             return "%s(%r, %r, %r, %r)" % (self.__class__.__name__, self.start, self.end, self.name, self.obj) 
    331  
    332     def compile(self, template, registers, location): 
    333         if len(self.args) == 0: 
    334             r = self.obj.compile(template, registers, location) 
    335             template.opcode("callmeth0", r, r, self.name.value, location) 
    336             return r 
    337         elif len(self.args) == 1: 
    338             r = self.obj.compile(template, registers, location) 
    339             r0 = self.args[0].compile(template, registers, location) 
    340             template.opcode("callmeth1", r, r, r0, self.name.value, location) 
    341             registers.free(r0) 
    342             return r 
    343         elif len(self.args) == 2: 
    344             r = self.obj.compile(template, registers, location) 
    345             r0 = self.args[0].compile(template, registers, location) 
    346             r1 = self.args[1].compile(template, registers, location) 
    347             template.opcode("callmeth2", r, r, r0, r1, self.name.value, location) 
    348             registers.free(r0) 
    349             registers.free(r1) 
    350             return r 
    351         elif len(self.args) == 3: 
    352             r = self.obj.compile(template, registers, location) 
    353             r0 = self.args[0].compile(template, registers, location) 
    354             r1 = self.args[1].compile(template, registers, location) 
    355             r2 = self.args[2].compile(template, registers, location) 
    356             template.opcode("callmeth3", r, r, r0, r1, r2, self.name.value, location) 
    357             registers.free(r0) 
    358             registers.free(r1) 
    359             registers.free(r2) 
    360             return r 
    361         else: 
    362             raise ValueError("%d arguments not supported" % len(self.args)) 
     276from com.livinglogic.sxtl import Const, None as None_, True as True_, False as False_, Int, Float, Str, Name, GetSlice, Not, Neg, StoreVar, AddVar, SubVar, MulVar, FloorDivVar, TrueDivVar, ModVar, DelVar, GetItem, GetSlice1, GetSlice2, Equal, NotEqual, Contains, NotContains, Add, Sub, Mul, FloorDiv, TrueDiv, Or, And, Mod, GetSlice12, GetAttr, Render, For, For1, For2, CallFunc, CallMeth 
    363277 
    364278 
     
    582496 
    583497    def expr_callfunc0(self, (name, _0, _1)): 
    584         return CallFunc(name.start, _1.end, name, []) 
     498        return CallFunc(name.start, _1.end, name) 
    585499    expr_callfunc0.spark = ['expr10 ::= name ( )'] 
    586500 
    587501    def expr_callfunc1(self, (name, _0, arg0, _1)): 
    588         return CallFunc(name.start, _1.end, name, [arg0]) 
     502        return CallFunc(name.start, _1.end, name, arg0) 
    589503    expr_callfunc1.spark = ['expr10 ::= name ( expr0 )'] 
    590504 
    591505    def expr_callfunc2(self, (name, _0, arg0, _1, arg1, _2)): 
    592         return CallFunc(name.start, _2.end, name, [arg0, arg1]) 
     506        return CallFunc(name.start, _2.end, name, arg0, arg1) 
    593507    expr_callfunc2.spark = ['expr10 ::= name ( expr0 , expr0 )'] 
    594508 
    595509    def expr_callfunc3(self, (name, _0, arg0, _1, arg1, _2, arg2, _3)): 
    596         return CallFunc(name.start, _3.end, name, [arg0, arg1, arg2]) 
     510        return CallFunc(name.start, _3.end, name, arg0, arg1, arg2) 
    597511    expr_callfunc3.spark = ['expr10 ::= name ( expr0 , expr0 , expr0 )'] 
    598512 
     
    602516 
    603517    def expr_callmeth0(self, (expr, _0, name, _1, _2)): 
    604         return CallMeth(expr.start, _2.end, name, expr, []) 
     518        return CallMeth(expr.start, _2.end, expr, name) 
    605519    expr_callmeth0.spark = ['expr9 ::= expr9 . name ( )'] 
    606520 
    607521    def expr_callmeth1(self, (expr, _0, name, _1, arg1, _2)): 
    608         return CallMeth(expr.start, _2.end, name, expr, [arg1]) 
     522        return CallMeth(expr.start, _2.end, expr, name, arg1) 
    609523    expr_callmeth1.spark = ['expr9 ::= expr9 . name ( expr0 )'] 
    610524 
    611525    def expr_callmeth2(self, (expr, _0, name, _1, arg1, _2, arg2, _3)): 
    612         return CallMeth(expr.start, _3.end, name, expr, [arg1, arg2]) 
     526        return CallMeth(expr.start, _3.end, expr, name, arg1, arg2) 
    613527    expr_callmeth2.spark = ['expr9 ::= expr9 . name ( expr0 , expr0 )'] 
    614528 
    615529    def expr_callmeth3(self, (expr, _0, name, _1, arg1, _2, arg2, _3, arg3, _4)): 
    616         return CallMeth(expr.start, _4.end, name, expr, [arg1, arg2, arg3]) 
     530        return CallMeth(expr.start, _4.end, expr, name, arg1, arg2, arg3) 
    617531    expr_callmeth3.spark = ['expr9 ::= expr9 . name ( expr0 , expr0 , expr0 )'] 
    618532