Changeset 216:397b19ac35c7 in livinglogic.java.ul4

Show
Ignore:
Timestamp:
05/10/09 18:48:40 (10 years ago)
Author:
Walter Doerwald <walter@…>
Branch:
default
Message:

Add support for the float function.

Location:
library/src/com/livinglogic/ul4
Files:
5 modified

Legend:

Unmodified
Added
Removed
  • library/src/com/livinglogic/ul4/Compiler.java

    r206 r216  
    1515    { 
    1616        Properties props = new Properties(); 
    17         props.setProperty("python.path", "C:\\jython\\Lib;C:\\ul4"); 
     17        props.setProperty("python.path", "/Users/walter/jython/Lib:/Users/walter/checkouts/LivingLogic.Java.ul4/library/src/com/livinglogic/ul4"); 
    1818        PythonInterpreter.initialize(System.getProperties(), props, new String[] {""}); 
    1919        PythonInterpreter interpreter = new PythonInterpreter(); 
  • library/src/com/livinglogic/ul4/InterpretedTemplate.java

    r213 r216  
    11161116                                    reg[code.r1] = Utils.toInteger(reg[code.r2]); 
    11171117                                    break; 
     1118                                case Opcode.CF1_FLOAT: 
     1119                                    reg[code.r1] = Utils.toFloat(reg[code.r2]); 
     1120                                    break; 
    11181121                                case Opcode.CF1_BOOL: 
    11191122                                    reg[code.r1] = Utils.getBool(reg[code.r2]) ? Boolean.TRUE : Boolean.FALSE; 
     
    19511954                            code(buffer, indent, "reg" + opcode.r1 + " = int(reg" + opcode.r2 + ")"); 
    19521955                            break; 
     1956                        case Opcode.CF1_FLOAT: 
     1957                            code(buffer, indent, "reg" + opcode.r1 + " = float(reg" + opcode.r2 + ")"); 
     1958                            break; 
    19531959                        case Opcode.CF1_BOOL: 
    19541960                            code(buffer, indent, "reg" + opcode.r1 + " = bool(reg" + opcode.r2 + ")"); 
  • library/src/com/livinglogic/ul4/Main.java

    r213 r216  
    99    public static void main(String[] args) 
    1010    { 
    11         Template tmpl = Compiler.compile("<?print ', '.join(reversed([1, 2, 3]))?>"); 
     11        Template tmpl = Compiler.compile("<?print isfloat(float(42))?>"); 
    1212        long start = System.currentTimeMillis(); 
    1313        Map vars = new HashMap(); 
  • library/src/com/livinglogic/ul4/Opcode.java

    r213 r216  
    7777    public static final int CF1_REPR = 2; 
    7878    public static final int CF1_INT = 3; 
    79     public static final int CF1_BOOL = 4; 
    80     public static final int CF1_LEN = 5; 
    81     public static final int CF1_ENUMERATE = 6; 
    82     public static final int CF1_ISNONE = 7; 
    83     public static final int CF1_ISSTR = 8; 
    84     public static final int CF1_ISINT = 9; 
    85     public static final int CF1_ISFLOAT = 10; 
    86     public static final int CF1_ISBOOL = 11; 
    87     public static final int CF1_ISDATE = 12; 
    88     public static final int CF1_ISLIST = 13; 
    89     public static final int CF1_ISDICT = 14; 
    90     public static final int CF1_ISTEMPLATE = 15; 
    91     public static final int CF1_CHR = 16; 
    92     public static final int CF1_ORD = 17; 
    93     public static final int CF1_HEX = 18; 
    94     public static final int CF1_OCT = 19; 
    95     public static final int CF1_BIN = 20; 
    96     public static final int CF1_SORTED = 21; 
    97     public static final int CF1_RANGE = 22; 
    98     public static final int CF1_TYPE = 23; 
    99     public static final int CF1_CSV = 24; 
    100     public static final int CF1_GET = 25; 
    101     public static final int CF1_JSON = 26; 
    102     public static final int CF1_REVERSED = 27; 
     79    public static final int CF1_FLOAT = 4; 
     80    public static final int CF1_BOOL = 5; 
     81    public static final int CF1_LEN = 6; 
     82    public static final int CF1_ENUMERATE = 7; 
     83    public static final int CF1_ISNONE = 8; 
     84    public static final int CF1_ISSTR = 9; 
     85    public static final int CF1_ISINT = 10; 
     86    public static final int CF1_ISFLOAT = 11; 
     87    public static final int CF1_ISBOOL = 12; 
     88    public static final int CF1_ISDATE = 13; 
     89    public static final int CF1_ISLIST = 14; 
     90    public static final int CF1_ISDICT = 15; 
     91    public static final int CF1_ISTEMPLATE = 16; 
     92    public static final int CF1_ISCOLOR = 17; 
     93    public static final int CF1_CHR = 18; 
     94    public static final int CF1_ORD = 19; 
     95    public static final int CF1_HEX = 20; 
     96    public static final int CF1_OCT = 21; 
     97    public static final int CF1_BIN = 22; 
     98    public static final int CF1_SORTED = 23; 
     99    public static final int CF1_RANGE = 24; 
     100    public static final int CF1_TYPE = 25; 
     101    public static final int CF1_CSV = 26; 
     102    public static final int CF1_GET = 27; 
     103    public static final int CF1_JSON = 28; 
     104    public static final int CF1_REVERSED = 29; 
    103105 
    104106    public static final int CF2_RANGE = 0; 
     
    324326        else if (name.equals("int")) 
    325327            return CF1_INT; 
     328        else if (name.equals("float")) 
     329            return CF1_FLOAT; 
    326330        else if (name.equals("bool")) 
    327331            return CF1_BOOL; 
  • library/src/com/livinglogic/ul4/Utils.java

    r213 r216  
    791791    } 
    792792 
     793    public static Object toFloat(String obj) 
     794    { 
     795        return Float.valueOf(obj); 
     796    } 
     797 
     798    public static Object toFloat(Integer obj) 
     799    { 
     800        return new Float(obj.intValue()); 
     801    } 
     802 
     803    public static Object toFloat(Long obj) 
     804    { 
     805        return new Float(obj.longValue()); 
     806    } 
     807 
     808    public static Object toFloat(Float obj) 
     809    { 
     810        return obj; 
     811    } 
     812 
     813    public static Object toFloat(Boolean obj) 
     814    { 
     815        return new Float(obj.booleanValue() ? 1.0 : 0.0); 
     816    } 
     817 
     818    public static Object toFloat(Object obj) 
     819    { 
     820        if (obj instanceof String) 
     821            return toFloat((String)obj); 
     822        else if (obj instanceof Integer) 
     823            return toFloat((Integer)obj); 
     824        else if (obj instanceof Long) 
     825            return toFloat((Long)obj); 
     826        else if (obj instanceof Number) 
     827            return toFloat((Number)obj); 
     828        else if (obj instanceof Boolean) 
     829            return toFloat((Boolean)obj); 
     830        throw new UnsupportedOperationException("Can't convert instance of " + obj.getClass() + " to a float!"); 
     831    } 
     832 
    793833    public static String repr(Object obj) 
    794834    {