Changeset 3866


Ignore:
Timestamp:
Jul 23, 2008, 5:07:34 PM (12 years ago)
Author:
yura
Message:
  • Native (from Java to Refal), JBC backend.
Files:
3 edited

Legend:

Unmodified
Added
Removed
  • devel-tools/trunk/eclipse/org.refal.rfpdt.core/src/org/refal/rfpdt/compiler/RefalASGenerator.java

    r3864 r3866  
    166166        if (astNative.isNameAtLeft)
    167167            return;
    168         items.toRight(NATIVE).toRight(EXPORT);
     168        items.toRight(NATIVE);
    169169        AstFuncDecl astFuncDecl = astNative.funcDecl;
    170170        items.toRight(astFuncDecl.retMode.select(FUNC_Q, FUNC));
  • to-imperative/trunk/compiler/refal/org/refal/plus/compiler/NativeJava.rf

    r3589 r3866  
    5353        s.resType : "" = <ToWord e.methodname> "";
    5454        e.methodname : $r e.classname '.' e.methodname1 = <ToWord e.classname> <ToWord e.methodname1>;
     55         "" <ToWord e.methodname>;
    5556  } :: s.className s.methodName,
    5657  s.static s.resType s.className s.methodName;
  • to-imperative/trunk/compiler/refal/org/refal/plus/compiler/rfp_asail_jbc.rf

    r3864 r3866  
    996996  (s.tag IMPORT e) = /*empty*/;
    997997  (s.linkage s.tag t.qname (e.in) (e.out) (NATIVE e.native)) = <WrapGen s.linkage s.tag t.qname (e.in) (e.out) e.native>;
     998  (NATIVE s.tag t.qname (e.in) (e.out) e.native) = <WrapGen2 s.tag t.qname (e.in) (e.out) e.native>;
    998999  (s.tag s.linkage t.qname (e.args) (e.ress) e.body),
    9991000    s.tag : \{
     
    15351536PutArgToStack s.javaArgType e.rfArgTypes s.num =
    15361537  <IIMVvisitVarInsn <MV> <ALOAD> s.num>,
    1537   <L s.num e.rfArgTypes> s.javaArgType : {
     1538  <ConvertRefalToJava <L s.num e.rfArgTypes> s.javaArgType>;
     1539
     1540$func ConvertRefalToJava t.refType s.javaType = ;
     1541ConvertRefalToJava t.refType s.javaType,
     1542  t.refType s.javaType : {
    15381543    \{
    15391544      (SVAR e) Z = "toBoolean";
     
    15501555      (EVAR e) "[J" = "toLongArray";
    15511556    } :: s.methodName,
    1552       <IIMVvisitMethodInsn <MV> <INVOKESTATIC> "org/refal/plus/Native" s.methodName  <ToWord "(Lorg/refal/plus/Expr;)"s.javaArgType>>;
     1557      <IIMVvisitMethodInsn <MV> <INVOKESTATIC> "org/refal/plus/Native" s.methodName  <ToWord "(Lorg/refal/plus/Expr;)"s.javaType>>;
    15531558    {
    15541559      (SVAR e) s =
    15551560        <IIMVvisitMethodInsn <MV> <INVOKESTATIC> "org/refal/plus/Native" "toObject" "(Lorg/refal/plus/Expr;)Ljava/lang/Object;">;
    15561561      (EVAR e) s =
    1557         <ToChars s.javaArgType> : '[' e.elemType, { e.elemType : 'L' e.intName ';', <ToWord e.intName>; <ToWord e.elemType>; } :: s.javaElemType,
     1562        <ToChars s.javaType> : '[' e.elemType, { e.elemType : 'L' e.intName ';', <ToWord e.intName>; <ToWord e.elemType>; } :: s.javaElemType,
    15581563        <IIMVvisitInsn <MV> <DUP>>,
    15591564        <IIMVvisitMethodInsn <MV> <INVOKEVIRTUAL> "org/refal/plus/Expr" "length" "()I">,
     
    15611566        <IIMVvisitMethodInsn <MV> <INVOKESTATIC> "org/refal/plus/Native" "toObjectArray" "(Lorg/refal/plus/Expr;[Ljava/lang/Object;)[Ljava/lang/Object;">;
    15621567    },
    1563       { <ToChars s.javaArgType> : 'L' e.intName ';', <ToWord e.intName>; s.javaArgType; } :: s.javaArgType,
    1564       <IIMVvisitTypeInsn <MV> <CHECKCAST> s.javaArgType>;
     1568      { <ToChars s.javaType> : 'L' e.intName ';', <ToWord e.intName>; s.javaType; } :: s.javaType,
     1569      <IIMVvisitTypeInsn <MV> <CHECKCAST> s.javaType>;
    15651570  };
    15661571
    15671572$func GetResFromStack s.javaResType e.rfResTypes s.num = ;
    1568 GetResFromStack s.javaResType e.rfResTypes s.num = {
    1569   e.rfResTypes : /**/ = ;
    1570   <IIMVvisitVarInsn <MV> <ALOAD> s.num>,
     1573GetResFromStack s.javaResType e.rfResTypes s.num = e.rfResTypes : {
     1574  /**/ = ;
     1575  t.refType =
     1576    <IIMVvisitVarInsn <MV> <ALOAD> s.num>,
    15711577    <IIMVvisitInsn <MV> <SWAP>>,
    1572     e.rfResTypes (<ToChars s.javaResType>) : {
     1578    <ConvertJavaToRefal s.javaResType t.refType>,
     1579    <IIMVvisitMethodInsn <MV> <INVOKEVIRTUAL> "org/refal/plus/Result" "assign" "(Lorg/refal/plus/Expr;)V">;
     1580};
     1581 
     1582$func ConvertJavaToRefal s.javaType t.refType = ;
     1583ConvertJavaToRefal  s.javaType t.refType,
     1584    t.refType (<ToChars s.javaType>) : {
    15731585      (SVAR e) ('L'  e) = "Ljava/lang/Object;"; // Object
    15741586      (SVAR e) ('['  e) = "Ljava/lang/Object;"; // Array
    1575       (SVAR e) (     e) = s.javaResType; // Primitive type
     1587      (SVAR e) (     e) = s.javaType; // Primitive type
    15761588      (EVAR e) ('[L' e) = "[Ljava/lang/Object;"; // Array of objects
    15771589      (EVAR e) ('[[' e) = "[Ljava/lang/Object;"; // Array of arrays
    1578       (EVAR e) ('['  e) = s.javaResType; // Array of primitive type
    1579     } :: s.javaResType,
    1580     <IIMVvisitMethodInsn <MV> <INVOKESTATIC> "org/refal/plus/Native" "toExpr" <ToWord "("s.javaResType")Lorg/refal/plus/Expr;">>,
    1581     <IIMVvisitMethodInsn <MV> <INVOKEVIRTUAL> "org/refal/plus/Result" "assign" "(Lorg/refal/plus/Expr;)V">;
    1582 };
     1590      (EVAR e) ('['  e) = s.javaType; // Array of primitive type
     1591    } :: s.javaType,
     1592    <IIMVvisitMethodInsn <MV> <INVOKESTATIC> "org/refal/plus/Native" "toExpr" <ToWord "("s.javaType")Lorg/refal/plus/Expr;">>;
    15831593
    15841594$func ConvertType s.javaType = s.typeDesc;
     
    16671677  <IIMVvisitMaxs <MV> 0 0>,
    16681678  <IIMVvisitEnd <MV>>;
     1679
     1680$func WrapGen2 s.tag t.qname (e.in) (e.out) e.native = ;
     1681WrapGen2 FUNC t.qname (e.in) (e.out) e.native =
     1682  <Vars e.in> :: e.rfArgTypes,
     1683  <Vars e.out> :: e.rfResTypes,
     1684  <DeclarationReader <ToWord e.native>> : "" s.javaResType "" s.methodName (e.javaArgTypes),
     1685  <ReplaceDots s.javaResType> :: s.javaResType,
     1686  <Map &ReplaceDots (e.javaArgTypes)> :: e.javaArgTypes,
     1687  <ToWord "(" <Map &ConvertType (e.javaArgTypes)> ")" <ConvertResType s.javaResType>> :: s.methodDesc,
     1688  <Store &MVbox <CWvisitMethod <CW> <Add <ACC_STATIC> <ACC_PUBLIC>> s.methodName s.methodName <Null> ("org/refal/plus/RefalException")>>,
     1689  <IIMVvisitCode <MV>>,
     1690  {
     1691    {
     1692      e.javaArgTypes : e.head s.javaArgType e,
     1693        <Length e.head> :: s.index,
     1694        {
     1695          s.javaArgType : { "int"; "boolean"; "char"; "byte"; "short"; "int"; } = <ILOAD>;
     1696          s.javaArgType : "long" = <LLOAD>;
     1697          = <ALOAD>;
     1698        } :: s.instr,
     1699        <IIMVvisitVarInsn <MV> s.instr s.index>,
     1700        <ConvertJavaToRefal s.javaArgType <L s.index e.rfArgTypes>>,
     1701        $fail;;
     1702    }, {
     1703      s.javaResType : "" = ;
     1704      <IIMVvisitTypeInsn <MV> <NEW> "org/refal/plus/Result">,
     1705        <IIMVvisitInsn <MV> <DUP>>,
     1706        <IIMVvisitMethodInsn <MV> <INVOKESPECIAL> "org/refal/plus/Result" "<init>" "()V">,
     1707        <IIMVvisitInsn <MV> <DUP>>,
     1708        <IIMVvisitVarInsn <MV> <ASTORE> <Length e.javaArgTypes>>;
     1709    };
     1710  },{
     1711    t.qname : (e.className s.functionName),
     1712    <Function_Description (e.rfArgTypes) (e.rfResTypes) 'V'> :: s.functionDesc,
     1713      <IIMVvisitMethodInsn <MV> <INVOKESTATIC> <GetJBCQName e.className s.functionName> s.functionDesc>;
     1714  },
     1715  {
     1716    s.javaResType : "" =
     1717      <IIMVvisitInsn <MV> <RETURN>>;
     1718    <IIMVvisitVarInsn <MV> <ALOAD> <Length e.javaArgTypes>>,
     1719      <IIMVvisitMethodInsn <MV> <INVOKEVIRTUAL> "org/refal/plus/Result" "getExpr" "()Lorg/refal/plus/Expr;">,
     1720      <ConvertRefalToJava e.rfResTypes s.javaResType>,
     1721      {
     1722        s.javaResType : { "int"; "boolean"; "char"; "byte"; "short"; "int"; } = <IRETURN>;
     1723        s.javaResType : "long" = <LRETURN>;
     1724        = <ARETURN>;
     1725      } :: s.instr,
     1726      <IIMVvisitInsn <MV> s.instr>;
     1727  },   
     1728  <IIMVvisitMaxs <MV> 0 0>,
     1729  <IIMVvisitEnd <MV>>;
Note: See TracChangeset for help on using the changeset viewer.