Changeset 3404


Ignore:
Timestamp:
Feb 12, 2008, 4:17:35 PM (13 years ago)
Author:
yura
Message:
  • Symbol.valueOf and Symbol.{boolean,...)Value method.
Location:
to-imperative/trunk
Files:
3 edited

Legend:

Unmodified
Added
Removed
  • to-imperative/trunk/compiler/rfp_asail_java.rf

    r3366 r3404  
    531531
    532532ConvertTo2 s.javaType e.varName, {
    533   s.javaType : \{
    534     "boolean" = 'java.lang.Boolean.parseBoolean((java.lang.String) 'e.varName')';
    535     "char" = '((java.lang.Character) 'e.varName').charValue()';
    536     "byte" = '((java.math.BigInteger) 'e.varName').byteValue()';
    537     "short" = '((java.math.BigInteger) 'e.varName').shortValue()';
    538     "int" = '((java.math.BigInteger) 'e.varName').intValue()';
    539     "long" = '((java.math.BigInteger) 'e.varName').longValue()';
    540   };
     533  s.javaType : \{"boolean"; "char"; "byte"; "short"; "int"; "long";} =
     534    'Symbol.'s.javaType'Value('e.varName')';
    541535  '('s.javaType') (('e.varName' instanceof org.refal.plus.Reference) ? ((org.refal.plus.Reference) 'e.varName').object : 'e.varName')';
    542536};
     
    559553
    560554ConvertFrom2 s.javaType e.varName, {
    561   s.javaType : \{
    562     "boolean" = 'java.lang.String.valueOf('e.varName')';
    563     "char" = 'java.lang.Character.valueOf('e.varName')';
    564     \{"byte"; "short"; "int"; "long";} = 'java.math.BigInteger.valueOf('e.varName')';
    565   };
     555  s.javaType : \{"boolean"; "char"; "byte"; "short"; "int"; "long";} =
     556    'Symbol.valueOf('e.varName')';
    566557  '('e.varName' instanceof java.lang.Comparable) ? ((java.lang.Comparable) 'e.varName') : new org.refal.plus.Reference<'s.javaType'>('e.varName')';
    567558};
    568559 
    569560ConvertFrom s.javaType t.var t.convVar,
    570   <WriteLn s.javaType t.var t.convVar>
    571561  t.var : (s.refType e),
    572562  s.refType : {
     
    606596  0 $iter e.convTo <ConvertTo <L s.num e.javaArgTypes2> <L s.num e.rfArgTypes> <L s.num e.rfConvArgTypes>> <Add s.num 1>
    607597    :: e.convTo s.num,
    608   <WriteLn 'A' s.num <Length e.rfArgTypes>>,
    609598  <Length e.rfArgTypes> : s.num =
    610599 
  • to-imperative/trunk/compiler/rfp_asail_jbc.rf

    r3366 r3404  
    846846$func ConvertTo s.javaArgType = ;
    847847
    848 ConvertTo {
    849   Z = <MVvisitTypeInsn <MV> &CHECKCAST "java/lang/String">,
    850     <MVvisitMethodInsn <MV> &INVOKESTATIC "java/lang/Boolean" "parseBoolean" "(Ljava/lang/String;)Z">;
    851   C = <MVvisitTypeInsn <MV> &CHECKCAST "java/lang/Character">,
    852     <MVvisitMethodInsn <MV> &INVOKEVIRTUAL "java/lang/Character" "charValue" "()C">;
    853   B = <MVvisitTypeInsn <MV> &CHECKCAST "java/math/BigInteger">,
    854     <MVvisitMethodInsn <MV> &INVOKEVIRTUAL "java/math/BigInteger" "byteValue" "()B">;
    855   S = <MVvisitTypeInsn <MV> &CHECKCAST "java/math/BigInteger">,
    856     <MVvisitMethodInsn <MV> &INVOKEVIRTUAL "java/math/BigInteger" "shortValue" "()S">;
    857   I = <MVvisitTypeInsn <MV> &CHECKCAST "java/math/BigInteger">,
    858     <MVvisitMethodInsn <MV> &INVOKEVIRTUAL "java/math/BigInteger" "intValue" "()I">;
    859   J = <MVvisitTypeInsn <MV> &CHECKCAST "java/math/BigInteger">,
    860     <MVvisitMethodInsn <MV> &INVOKEVIRTUAL "java/math/BigInteger" "longValue" "()J">;
    861   s.type = <Label> :: s.l,
     848ConvertTo s.type, {
     849  s.type : \{Z = "boolean"; C = "char"; B = "byte"; S = "short"; I = "int"; J = "long";} :: s.typeName =
     850    <MVvisitMethodInsn <MV> &INVOKESTATIC "org/refal/plus/Symbol" <ToWord s.typeName "Value"> <ToWord "(Ljava/lang/Comparable;)" s.type>>;
     851  = <Label> :: s.l,
    862852    <MVvisitInsn <MV> &DUP>,
    863853    <MVvisitTypeInsn <MV> &INSTANCEOF "org/refal/plus/Reference">,
     
    873863    };
    874864};
    875 
    876865
    877866PutArgToStack s.javaArgType e.rfArgTypes s.num =
     
    941930$func ConvertFrom s.javaResType = ;
    942931
    943 ConvertFrom {
    944   Z = <MVvisitMethodInsn <MV> &INVOKESTATIC "java/lang/String" "valueOf" "(Z)Ljava/lang/String;">;
    945   C = <MVvisitMethodInsn <MV> &INVOKESTATIC "java/lang/Character" "valueOf" "(C)Ljava/lang/Character;">;
    946   \{B; S; I;}, <MVvisitInsn <MV> &I2L>, $fail;
    947   \{B; S; I; J;} = <MVvisitMethodInsn <MV> &INVOKESTATIC "java/math/BigInteger" "valueOf" "(J)Ljava/math/BigInteger;">;
    948   s.type = <Label> :: s.l,
     932ConvertFrom s.type, {
     933  s.type : \{Z; C; B; S; I; J;} =
     934    <MVvisitMethodInsn <MV> &INVOKESTATIC "org/refal/plus/Symbol" "valueOf" <ToWord "("s.type")Ljava/lang/Comparable;">>;
     935  <Label> :: s.l,
    949936    <MVvisitInsn <MV> &DUP>,
    950937    <MVvisitTypeInsn <MV> &INSTANCEOF "java/lang/Comparable">,
  • to-imperative/trunk/java/runtime/org/refal/plus/Symbol.java

    r3403 r3404  
    1919    public static final Comparable null_object = new Reference(null);
    2020
    21     public static Comparable newInt (String str) {
     21    public static Comparable valueOf (boolean b) {
     22        return String.valueOf(b);
     23    }
     24
     25    public static Comparable valueOf (char c) {
     26        return Character.valueOf(c);
     27    }
     28
     29    public static Comparable valueOf (byte b) {
     30        return BigInteger.valueOf(b);
     31    }
     32
     33    public static Comparable valueOf (int i) {
     34        return BigInteger.valueOf(i);
     35    }
     36
     37    public static Comparable valueOf (long l) {
     38        return BigInteger.valueOf(l);
     39    }
     40
     41    public static Comparable valueOf (short s) {
     42        return BigInteger.valueOf(s);
     43    }
     44
     45    public static boolean booleanValue (Comparable c) {
     46        return Boolean.parseBoolean((String) c);
     47    }
     48
     49    public static char charValue (Comparable c) {
     50        return ((Character) c).charValue();
     51    }
     52
     53    public static byte byteValue (Comparable c) {
     54        return ((BigInteger) c).byteValue();
     55    }
     56
     57    public static int intValue (Comparable c) {
     58        return ((BigInteger) c).intValue();
     59    }
     60
     61    public static long longValue (Comparable c) {
     62        return ((BigInteger) c).longValue();
     63    }
     64
     65    public static short shortValue (Comparable c) {
     66        return ((BigInteger) c).shortValue();
     67    }
     68
     69    public static Comparable newInt (String str) {
    2270        return new BigInteger(str);
    2371    }
Note: See TracChangeset for help on using the changeset viewer.