Changeset 3711:a539aff0e476 in livinglogic.python.xist

Show
Ignore:
Timestamp:
02/28/09 13:25:06 (9 years ago)
Author:
Walter Doerwald <walter@…>
Branch:
default
Message:

Add a reversed function to UL4 (issue #5). Bump file format version.

Files:
3 modified

Legend:

Unmodified
Added
Removed
  • NEWS.rst

    r3710 r3711  
    77    and ``hasclass`` now support multiple values. The operator matches the 
    88    node if t matches with any of the given values. 
     9 
     10*   A new function ``reversed`` is now available in UL4 templates. It returns 
     11    an iterator that will output the items of any sequence in reverse order. 
    912 
    1013 
  • src/ll/ul4c.py

    r3703 r3711  
    624624    is a generator) or :meth:`renders` (which returns a string). 
    625625    """ 
    626     version = "8" 
     626    version = "9" 
    627627 
    628628    def __init__(self): 
     
    11271127    def _pythonsource_dispatch_callfunc1_type(self, opcode): 
    11281128        self.lines.append("%sreg%d = ul4c._type(reg%d)" % (self.indent, opcode.r1, opcode.r2)) 
     1129 
     1130    def _pythonsource_dispatch_callfunc1_reversed(self, opcode): 
     1131        self.lines.append("%sreg%d = reversed(reg%d)" % (self.indent, opcode.r1, opcode.r2)) 
    11291132 
    11301133    def _pythonsource_dispatch_callfunc2_range(self, opcode): 
  • test/test_ul4.py

    r3702 r3711  
    907907    check("template", code, x=ul4c.compile("")) 
    908908    check("", code, x=1j) 
     909 
     910 
     911def test_function_reversed(): 
     912    checkrunerror("function u?'reversed' unknown", u"<?print reversed()?>") 
     913    checkrunerror("function u?'reversed' unknown", u"<?print reversed(1, 2)?>") 
     914    code = u"<?for i in reversed(x)?>(<?print i?>)<?end for?>" 
     915    check("(3)(2)(1)", code, x="123") 
     916    check("(3)(2)(1)", code, x=[1, 2, 3]) 
     917    check("(3)(2)(1)", code, x=(1, 2, 3)) 
    909918 
    910919