Changeset 3413


Ignore:
Timestamp:
Feb 14, 2008, 3:10:40 PM (13 years ago)
Author:
yura
Message:
  • $native in toJBC backend.
Location:
to-imperative/trunk
Files:
3 edited

Legend:

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

    r3412 r3413  
    540540      {
    541541        s.javaElemType : \{"boolean"; "char"; "byte"; "short"; "int"; "long";} =
    542           'Native.arrayValue('<Rfp2Java t.var>', new 's.javaElemType'['<Rfp2Java t.var>'.length()])';
    543         '(('s.javaType') Native.arrayValue('<Rfp2Java t.var>', new 's.javaElemType'['<Rfp2Java t.var>'.length()]))';
     542          'Native.'s.javaElemType'ArrayValue('<Rfp2Java t.var>')';
     543        '(('s.javaType') Native.objectArrayValue('<Rfp2Java t.var>', new 's.javaElemType'['<Rfp2Java t.var>'.length()]))';
    544544      };
    545545  };
     
    554554
    555555WrapGen s.linkage FUNC t.qname (e.in) (e.out) e.native =
    556         <PrintLn>
    557         <PrintLn e.native>
     556  { <Get &Entry> : e t.qname e = <Store &Entry_Name t.qname>;; },
    558557  <DeclarationReader <ToWord e.native>> :: s.static s.javaResType s.className s.methodName e.javaArgTypes,
    559   { <Get &Entry> : e t.qname e = <Store &Entry_Name t.qname>;; },
    560558  { ('@RefalFormat("'<ReplaceQuotes <PrintFunctionFormat t.qname>>'")');; } :: e.refalFormat,
    561559  <Del_Pragmas <Gener_Var_Indices 1 (<Vars e.in>) 'arg'>> : e.rfArgs s,
    562560  <Del_Pragmas <Gener_Var_Indices 1 (<Vars e.out>) 'res'>> : e.rfRes s,
    563         <WriteLn s.static s.javaResType s.className s.methodName e.javaArgTypes>,
    564561  {
    565562    s.methodName : "" = 'new ' s.className 0;
     
    567564    s.className '.' s.methodName 0;
    568565  } :: e.funcHead s.shift,
    569         <PrintLn e.funcHead>,
    570   {
    571                         <PrintLn "1 " e.javaArgTypes " " s.shift " " e.rfArgs>,
     566  {
    572567    e.javaArgTypes : (e.javaArgTypes2) =
    573568      <Middle s.shift 0 e.rfArgs> :: e.rfArgs,     
    574                         <PrintLn "1 " e.rfArgs>,
    575569      0 $iter {
    576570        {e.args : /**/ = /**/; ', ';} :: e.comma,
     
    580574    e.funcHead;
    581575  } :: e.funcCall,
    582         <PrintLn e.funcCall>,
    583576  e.rfRes : {
    584577    /**/ = e.funcCall';';
  • to-imperative/trunk/compiler/rfp_asail_jbc.rf

    r3404 r3413  
    841841
    842842$func PutArgToStack s.javaArgType e.rfArgTypes s.num = ;
    843 
    844 $func GetResFromStack s.javaResType e.rfResTypes s.num = ;
    845 
    846 $func ConvertTo s.javaArgType = ;
    847 
    848 ConvertTo 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,
    852     <MVvisitInsn <MV> &DUP>,
    853     <MVvisitTypeInsn <MV> &INSTANCEOF "org/refal/plus/Reference">,
    854     <MVvisitJumpInsn <MV> &IFEQ s.l>,
    855     <MVvisitTypeInsn <MV> &CHECKCAST "org/refal/plus/Reference">,
    856     <MVvisitFieldInsn <MV> &GETFIELD "org/refal/plus/Reference" "object" "Ljava/lang/Object;">,
    857     <MVvisitLabel <MV> s.l>,
    858     <ToChars s.type> : {
    859       '[' e =
    860         <MVvisitTypeInsn <MV> &CHECKCAST s.type>;
    861       'L' e.intName ';',
    862         <MVvisitTypeInsn <MV> &CHECKCAST <ToWord e.intName>>;
    863     };
    864 };
    865 
    866843PutArgToStack s.javaArgType e.rfArgTypes s.num =
     844  <WriteLn s.javaArgType e.rfArgTypes s.num>,
    867845  <MVvisitVarInsn <MV> &ALOAD s.num>,
    868846  <L s.num e.rfArgTypes> : {
     
    870848      <MVvisitInsn <MV> &ICONST_0>,
    871849      <MVvisitMethodInsn <MV> &INVOKEVIRTUAL "org/refal/plus/Expr" "at" "(I)Ljava/lang/Comparable;">,
    872       <ConvertTo s.javaArgType>;
     850      {
     851        s.javaArgType : \{Z = "booleanValue"; C = "charValue"; B = "byteValue"; S = "shortValue"; I = "intValue"; J = "longValue";} :: s.methodName =
     852          <MVvisitMethodInsn <MV> &INVOKESTATIC "org/refal/plus/Native" s.methodName  <ToWord "(Ljava/lang/Comparable;)"s.javaArgType>>;
     853        <MVvisitMethodInsn <MV> &INVOKESTATIC "org/refal/plus/Native" "objectValue" "(Ljava/lang/Comparable;)Ljava/lang/Object;">,
     854          {         
     855            <ToChars s.javaArgType> : 'L' e.intName ';',
     856              <ToWord e.intName>;
     857            s.javaArgType;
     858          } :: s.javaArgType2,
     859          <MVvisitTypeInsn <MV> &CHECKCAST s.javaArgType2>;
     860      };
    873861    (EVAR e) =
    874862      <ToChars s.javaArgType> : '[' e.elemType,
    875       <ToWord e.elemType> :: s.javaElemType,
    876       <Label> :: s.l1,
    877       <Label> :: s.l2,
    878       <MVvisitInsn <MV> &DUP>,
    879       <MVvisitMethodInsn <MV> &INVOKEVIRTUAL "org/refal/plus/Expr" "length" "()I">,
    880       s.javaElemType : {
    881         Z = <MVvisitIntInsn <MV> &NEWARRAY &T_BOOLEAN>;
    882         C = <MVvisitIntInsn <MV> &NEWARRAY &T_CHAR>;
    883         B = <MVvisitIntInsn <MV> &NEWARRAY &T_BYTE>;
    884         S = <MVvisitIntInsn <MV> &NEWARRAY &T_SHORT>;
    885         I = <MVvisitIntInsn <MV> &NEWARRAY &T_INT>;
    886         F = <MVvisitIntInsn <MV> &NEWARRAY &T_FLOAT>;
    887         J = <MVvisitIntInsn <MV> &NEWARRAY &T_LONG>;
    888         D = <MVvisitIntInsn <MV> &NEWARRAY &T_DOUBLE>;
    889         s.javaElemType, <ToChars s.javaElemType> : '[' e =
    890           <MVvisitTypeInsn <MV> &ANEWARRAY s.javaElemType>;
    891         s = <ToChars s.javaElemType> : 'L' e.intName ';',
    892           <MVvisitTypeInsn <MV> &ANEWARRAY <ToWord e.intName>>;
    893       },
    894       <MVvisitInsn <MV> &ICONST_0>,
    895       <MVvisitLabel <MV> s.l1>,
    896       <MVvisitInsn <MV> &DUP2>,
    897       <MVvisitInsn <MV> &SWAP>,
    898       <MVvisitInsn <MV> &ARRAYLENGTH>,
    899       <MVvisitJumpInsn <MV> &IF_ICMPEQ s.l2>,
    900       <MVvisitInsn <MV> &DUP2_X1>,
    901       <MVvisitInsn <MV> &POP>,
    902       <MVvisitInsn <MV> &DUP2_X2>,
    903       <MVvisitInsn <MV> &POP>,
    904       <MVvisitInsn <MV> &DUP2_X1>,
    905       <MVvisitInsn <MV> &DUP2>,
    906       <MVvisitInsn <MV> &POP>,
    907       <MVvisitMethodInsn <MV> &INVOKEVIRTUAL  "org/refal/plus/Expr" "at" "(I)Ljava/lang/Comparable;">,
    908       <ConvertTo s.javaElemType>,
    909       s.javaElemType : {
    910         Z = <MVvisitInsn <MV> &BASTORE>;
    911         C = <MVvisitInsn <MV> &CASTORE>;
    912         B = <MVvisitInsn <MV> &BASTORE>;
    913         S = <MVvisitInsn <MV> &SASTORE>;
    914         I = <MVvisitInsn <MV> &IASTORE>;
    915         F = <MVvisitInsn <MV> &FASTORE>;
    916         J = <MVvisitInsn <MV> &LASTORE>;
    917         D = <MVvisitInsn <MV> &DASTORE>;
    918         s = <MVvisitInsn <MV> &AASTORE>;
    919       },
    920       <MVvisitInsn <MV> &POP>,
    921       <MVvisitInsn <MV> &ICONST_1>,
    922       <MVvisitInsn <MV> &IADD>,
    923       <MVvisitJumpInsn <MV> &GOTO s.l1>,
    924       <MVvisitLabel <MV> s.l2>,
    925       <MVvisitInsn <MV> &POP>,
    926       <MVvisitInsn <MV> &SWAP>,
    927       <MVvisitInsn <MV> &POP>;
     863      <ToWord e.elemType> :: s.javaElemType =
     864  <WriteLn " " s.javaElemType>,
     865      {
     866        s.javaElemType : \{Z = "booleanArrayValue"; C = "charArrayValue"; B = "byteArrayValue"; S = "shortArrayValue"; I = "intArrayValue"; J = "longArrayValue";} :: s.methodName =
     867          <MVvisitMethodInsn <MV> &INVOKESTATIC "org/refal/plus/Native" s.methodName <ToWord "(Lorg/refal/plus/Expr;)"s.javaArgType>>;
     868        <MVvisitInsn <MV> &DUP>,
     869          <MVvisitMethodInsn <MV> &INVOKEVIRTUAL "org/refal/plus/Expr" "length" "()I">,
     870          {         
     871            <ToChars s.javaElemType> : '[' e =
     872              <MVvisitTypeInsn <MV> &ANEWARRAY s.javaElemType>;
     873            <ToChars s.javaElemType> : 'L' e.intName ';',
     874              <MVvisitTypeInsn <MV> &ANEWARRAY <ToWord e.intName>>;
     875          },
     876          <MVvisitMethodInsn <MV> &INVOKESTATIC "org/refal/plus/Native" "objectArrayValue" "(Lorg/refal/plus/Expr;[Ljava/lang/Object;)[Ljava/lang/Object;">,
     877          {         
     878            <ToChars s.javaArgType> : 'L' e.intName ';',
     879              <ToWord e.intName>;
     880            s.javaArgType;
     881          } :: s.javaArgType2,
     882          <MVvisitTypeInsn <MV> &CHECKCAST s.javaArgType2>;
     883      };
    928884  };
    929885
    930 $func ConvertFrom s.javaResType = ;
    931 
    932 ConvertFrom 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,
    936     <MVvisitInsn <MV> &DUP>,
    937     <MVvisitTypeInsn <MV> &INSTANCEOF "java/lang/Comparable">,
    938     <MVvisitJumpInsn <MV> &IFNE s.l>,
    939     <MVvisitTypeInsn <MV> &NEW "org/refal/plus/Reference">,
    940     <MVvisitInsn <MV> &DUP_X1>,
    941     <MVvisitInsn <MV> &SWAP>,
    942     <MVvisitMethodInsn <MV> &INVOKESPECIAL "org/refal/plus/Reference" "<init>" "(Ljava/lang/Object;)V">,
    943     <MVvisitLabel <MV> s.l>,
    944     <MVvisitTypeInsn <MV> &CHECKCAST "java/lang/Comparable">;
    945 };
    946 
     886$func GetResFromStack s.javaResType e.rfResTypes s.num = ;
    947887GetResFromStack s.javaResType e.rfResTypes s.num = {
    948888  e.rfResTypes : /**/ = ;
     
    951891    e.rfResTypes : {
    952892      (SVAR e) =
    953         <ConvertFrom s.javaResType>,
     893        <MVvisitMethodInsn <MV> &INVOKESTATIC "org/refal/plus/Native" "sValueOf" <ToWord "("s.javaResType")Ljava/lang/Comparable;">>,
    954894        <MVvisitMethodInsn <MV> &INVOKEVIRTUAL "org/refal/plus/Result" "assign" "(Ljava/lang/Comparable;)V">;
    955895      (EVAR e) =
    956         <ToChars s.javaResType> : '[' e.elemType,
    957         <ToWord e.elemType> :: s.javaElemType,
    958         <Label> :: s.l1,
    959         <Label> :: s.l2,
    960         <Label> :: s.l3,
    961         <Label> :: s.l4,
    962         <MVvisitInsn <MV> &DUP>,
    963         <MVvisitJumpInsn <MV> &IFNULL s.l3>,
    964         <MVvisitInsn <MV> &DUP>,
    965         <MVvisitInsn <MV> &ARRAYLENGTH>,
    966         <MVvisitJumpInsn <MV> &GOTO s.l4>,
    967         <MVvisitLabel <MV> s.l3>,
    968         <MVvisitInsn <MV> &ICONST_0>,
    969         <MVvisitLabel <MV> s.l4>,
    970         <MVvisitTypeInsn <MV> &ANEWARRAY "java/lang/Comparable">,
    971         <MVvisitInsn <MV> &ICONST_0>,
    972         <MVvisitLabel <MV> s.l1>,
    973         <MVvisitInsn <MV> &DUP2>,
    974         <MVvisitInsn <MV> &SWAP>,
    975         <MVvisitInsn <MV> &ARRAYLENGTH>,
    976         <MVvisitJumpInsn <MV> &IF_ICMPEQ s.l2>,
    977         <MVvisitInsn <MV> &DUP2_X1>,
    978         <MVvisitInsn <MV> &POP>,
    979         <MVvisitInsn <MV> &DUP2_X2>,
    980         <MVvisitInsn <MV> &POP>,
    981         <MVvisitInsn <MV> &DUP2_X1>,
    982         <MVvisitInsn <MV> &DUP2>,
    983         <MVvisitInsn <MV> &POP>,
    984         s.javaElemType : {
    985           Z = <MVvisitInsn <MV> &BALOAD>;
    986           C = <MVvisitInsn <MV> &CALOAD>;
    987           B = <MVvisitInsn <MV> &BALOAD>;
    988           S = <MVvisitInsn <MV> &SALOAD>;
    989           I = <MVvisitInsn <MV> &IALOAD>;
    990           F = <MVvisitInsn <MV> &FALOAD>;
    991           J = <MVvisitInsn <MV> &LALOAD>;
    992           D = <MVvisitInsn <MV> &DALOAD>;
    993           s = <MVvisitInsn <MV> &AALOAD>;
    994         },
    995         <ConvertFrom s.javaResType>,
    996         <MVvisitInsn <MV> &AASTORE>,
    997         <MVvisitInsn <MV> &POP>,
    998         <MVvisitInsn <MV> &ICONST_1>,
    999         <MVvisitInsn <MV> &IADD>,
    1000         <MVvisitJumpInsn <MV> &GOTO s.l1>,
    1001         <MVvisitLabel <MV> s.l2>,
    1002         <MVvisitInsn <MV> &POP>,
    1003         <MVvisitInsn <MV> &SWAP>,
    1004         <MVvisitInsn <MV> &POP>,
    1005         <MVvisitMethodInsn <MV> &INVOKEVIRTUAL "org/refal/plus/Result" "assign" "([Ljava/lang/Comparable;)V">;
     896        {
     897          <ToWord s.javaResType> : '[L' e = "[Ljava/lang/Object;";
     898          s.javaResType;
     899        } :: s.javaResType,
     900        <MVvisitMethodInsn <MV> &INVOKESTATIC "org/refal/plus/Native" "eValueOf" <ToWord "("s.javaResType")Lorg/refal/plus/Expr;">>,
     901        <MVvisitMethodInsn <MV> &INVOKEVIRTUAL "org/refal/plus/Result" "assign" "(Lorg/refal/plus/Expr;)V">;
    1006902    };
    1007903};
     
    1033929ReplaceDots s.str = <ToWord <Subst ('.') (('/')) <ToChars s.str>>>;
    1034930
    1035 WrapGen s.linkage s.tag t.qname (e.in) (e.out) e.native =
     931WrapGen s.linkage FUNC t.qname (e.in) (e.out) e.native =
     932  t.qname : (e s.functionName),
     933  { <Get &Entry> : e t.qname e = <Store &EntryName s.functionName>;; },
    1036934  <DeclarationReader <ToWord e.native>> :: s.static s.javaResType s.className s.methodName e.javaArgTypes,
    1037   <ReplaceDots s.javaResType> <ReplaceDots s.className> <Map &ReplaceDots (e.javaArgTypes)> :: s.javaResType s.className e.javaArgTypes,
    1038   s.tag : \{
    1039     FUNC  = 'V';
    1040     "FUNC?" = 'Z';
    1041   } : s.retType =
    1042   t.qname : (e s.functionName),
    1043   <Check_Name s.functionName>,
     935  <ReplaceDots s.javaResType> :: s.javaResType,
     936  <ReplaceDots s.className> :: s.className,
    1044937  <Add &ACC_STATIC <Access_Mode s.linkage>> :: s.access,
    1045938  <Vars e.in> :: e.rfArgTypes,
    1046939  <Vars e.out> :: e.rfResTypes,
    1047   <Function_Description (e.rfArgTypes) (e.rfResTypes) s.retType> :: s.desc,
     940  <Function_Description (e.rfArgTypes) (e.rfResTypes) 'V'> :: s.desc,
    1048941  <Store &MVbox <CWvisitMethod <CW> s.access s.functionName s.desc <Null> ("org/refal/plus/RefalException")>>,
    1049942  {
     
    1063956  } :: s.shift,
    1064957  {
    1065     e.javaArgTypes : e.head s.javaArgType e,
    1066       <PutArgToStack <ConvertType s.javaArgType> e.rfArgTypes <Add s.shift <Length e.head>>>, $fail;;
     958    e.javaArgTypes : /**/ =
     959      {
     960        s.static : "" = &GETFIELD;
     961        &GETSTATIC;
     962      } :: s.opcode,
     963      <MVvisitFieldInsn <MV> s.opcode s.className s.methodName <ConvertType s.javaResType>>;
     964    e.javaArgTypes : (e.javaArgTypes2),
     965      <Map &ReplaceDots (e.javaArgTypes2)> :: e.javaArgTypes,
     966      {
     967        e.javaArgTypes : e.head s.javaArgType e,
     968          <PutArgToStack <ConvertType s.javaArgType> e.rfArgTypes <Add s.shift <Length e.head>>>, $fail;;
     969      },
     970      {
     971        s.methodName : "" = &INVOKESPECIAL "<init>";
     972        s.static : "" = &INVOKEVIRTUAL s.methodName;
     973        = &INVOKESTATIC s.methodName;
     974        // &INVOKEINTERFACE
     975      } :: s.opcode s.methodName,
     976      <ToWord "(" <Map &ConvertType (e.javaArgTypes)> ")" <ConvertResType s.javaResType>> :: s.methodDesc,
     977      <MVvisitMethodInsn <MV> s.opcode s.className s.methodName s.methodDesc>;
    1067978  },
    1068979  {
    1069     s.methodName : "" = &INVOKESPECIAL "<init>";
    1070     s.static : "" = &INVOKEVIRTUAL s.methodName;
    1071     = &INVOKESTATIC s.methodName;
    1072     // &INVOKEINTERFACE
    1073   } :: s.opcode s.methodName,
    1074   <ToWord "(" <Map &ConvertType (e.javaArgTypes)> ")" <ConvertResType s.javaResType>> :: s.methodDesc,
    1075   <MVvisitMethodInsn <MV> s.opcode s.className s.methodName s.methodDesc>,
    1076   {
    1077     s.methodName : "" = s.className;
     980    s.javaResType : "" = s.className;
    1078981    s.javaResType;
    1079982  } :: s.javaResType,   
    1080983  <GetResFromStack <ConvertType s.javaResType> e.rfResTypes <Length e.rfArgTypes>>,
    1081   s.tag : {
    1082     FUNC  = <MVvisitInsn <MV> &RETURN>;
    1083     "FUNC?" = <MVvisitInsn <MV> &ICONST_1> <MVvisitInsn <MV> &IRETURN>;
    1084   },
     984  <MVvisitInsn <MV> &RETURN>,
    1085985  <MVvisitMaxs <MV> 0 0>,
    1086   <MVvisitEnd <MV>>,
    1087   { <Get &Entry> : e t.qname e = <Store &EntryName s.functionName>;; };
     986  <MVvisitEnd <MV>>;
  • to-imperative/trunk/java/runtime/org/refal/plus/Native.java

    r3408 r3413  
    124124    }
    125125
    126     // T[] arrayValue (Expr expr, T[] arr)
     126    // T[] arrayValue (Expr expr)
    127127   
    128     public static boolean[] arrayValue (Expr expr, boolean[] arr) {
    129         assert expr.length() == arr.length;
    130         int length = arr.length;
     128    public static boolean[] booleanArrayValue (Expr expr) {
     129        int length = expr.length();
     130        boolean[] arr = new boolean[length];
    131131        for (int i = 0; i < length; i++)
    132132            arr[i] = booleanValue(expr.at(i));
     
    134134    }
    135135
    136     public static char[] arrayValue (Expr expr, char[] arr) {
    137         assert expr.length() == arr.length;
    138         int length = arr.length;
     136    public static char[] charArrayValue (Expr expr) {
     137        int length = expr.length();
     138        char[] arr = new char[length];
    139139        for (int i = 0; i < length; i++)
    140140            arr[i] = charValue(expr.at(i));
     
    142142    }
    143143
    144     public static byte[] arrayValue (Expr expr, byte[] arr) {
    145         assert expr.length() == arr.length;
    146         int length = arr.length;
     144    public static byte[] byteArrayValue (Expr expr) {
     145        int length = expr.length();
     146        byte[] arr = new byte[length];
    147147        for (int i = 0; i < length; i++)
    148148            arr[i] = byteValue(expr.at(i));
     
    150150    }
    151151
    152     public static short[] arrayValue (Expr expr, short[] arr) {
    153         assert expr.length() == arr.length;
    154         int length = arr.length;
     152    public static short[] shortArrayValue (Expr expr) {
     153        int length = expr.length();
     154        short[] arr = new short[length];
    155155        for (int i = 0; i < length; i++)
    156156            arr[i] = shortValue(expr.at(i));
     
    158158    }
    159159
    160     public static int[] arrayValue (Expr expr, int[] arr) {
    161         assert expr.length() == arr.length;
    162         int length = arr.length;
     160    public static int[] intArrayValue (Expr expr) {
     161        int length = expr.length();
     162        int[] arr = new int[length];
    163163        for (int i = 0; i < length; i++)
    164164            arr[i] = intValue(expr.at(i));
     
    166166    }
    167167
    168     public static long[] arrayValue (Expr expr, long[] arr) {
    169         assert expr.length() == arr.length;
    170         int length = arr.length;
     168    public static long[] longArrayValue (Expr expr) {
     169        int length = expr.length();
     170        long[] arr = new long[length];
    171171        for (int i = 0; i < length; i++)
    172172            arr[i] = longValue(expr.at(i));
     
    174174    }
    175175
    176     public static Object[] arrayValue (Expr expr, Object[] arr) {
     176    public static Object[] objectArrayValue (Expr expr, Object[] arr) {
    177177        assert expr.length() == arr.length;
    178178        int length = arr.length;
Note: See TracChangeset for help on using the changeset viewer.