Changeset 3702:0d2d659c033e in livinglogic.python.xist

Show
Ignore:
Timestamp:
02/15/09 18:35:39 (10 years ago)
Author:
Walter Doerwald <walter@…>
Branch:
default
Message:

Add a two-argument version of int() to UL4.

Files:
4 modified

Legend:

Unmodified
Added
Removed
  • NEWS.rst

    r3700 r3702  
    66    Passing parameters can be done via keyword arguments or with the ``**`` 
    77    syntax like when using the ``render`` tag. 
     8 
     9*   A new version of the ``int`` function has been added to UL4: When called with 
     10    two arguments, the first must be a string, and the second is treated as the 
     11    base for the conversion. 
    812 
    913 
  • docs/UL4.rst

    r3701 r3702  
    537537 
    538538``int(foo)`` converts ``foo`` to an integer. ``foo`` can be a string, a float, 
    539 a boolean or an integer. 
     539a boolean or an integer. ``int`` can also be called with two arguments. In this 
     540case the first argument must be a string and the second is the number base for 
     541the conversion. 
    540542 
    541543 
  • src/ll/ul4c.py

    r3700 r3702  
    11371137        self.lines.append("%sreg%d = itertools.izip(reg%d, reg%d)" % (self.indent, opcode.r1, opcode.r2, opcode.r3)) 
    11381138 
     1139    def _pythonsource_dispatch_callfunc2_int(self, opcode): 
     1140        self.lines.append("%sreg%d = int(reg%d, reg%d)" % (self.indent, opcode.r1, opcode.r2, opcode.r3)) 
     1141 
    11391142    def _pythonsource_dispatch_callfunc3_range(self, opcode): 
    11401143        self.lines.append("%sreg%d = xrange(reg%d, reg%d, reg%d)" % (self.indent, opcode.r1, opcode.r2, opcode.r3, opcode.r4)) 
  • test/test_ul4.py

    r3700 r3702  
    586586def test_function_int(): 
    587587    checkrunerror("function u?'int' unknown", u"<?print int()?>") 
    588     checkrunerror("function u?'int' unknown", u"<?print int(1, 2)?>") 
     588    checkrunerror("function u?'int' unknown", u"<?print int(1, 2, 3)?>") 
    589589    checkrunerror("int\\(\\) argument must be a string or a number, not 'NoneType'", u"<?print int(data)?>", data=None) 
    590590    check("1", u"<?print int(data)?>", data=True) 
     
    593593    check("4", u"<?print int(data)?>", data=4.2) 
    594594    check("42", u"<?print int(data)?>", data="42") 
     595    check("66", u"<?print int(data, 16)?>", data="42") 
    595596    checkrunerror("invalid literal for int\\(\\) with base 10: 'foo'", u"<?print int(data)?>", data="foo") 
    596597