Changeset 3407


Ignore:
Timestamp:
Feb 13, 2008, 9:39:44 PM (13 years ago)
Author:
yura
Message:
  • Simpler native.
Location:
to-imperative/trunk
Files:
1 added
1 edited

Legend:

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

    r3404 r3407  
    527527  s.idx;
    528528
    529 $func ConvertTo t.javaType t.var t.convVar = e;
    530 $func ConvertTo2 s.javaType e.varName = e;
    531 
    532 ConvertTo2 s.javaType e.varName, {
    533   s.javaType : \{"boolean"; "char"; "byte"; "short"; "int"; "long";} =
    534     'Symbol.'s.javaType'Value('e.varName')';
    535   '('s.javaType') (('e.varName' instanceof org.refal.plus.Reference) ? ((org.refal.plus.Reference) 'e.varName').object : 'e.varName')';
    536 };
    537 
    538 ConvertTo s.javaType t.var t.convVar,
     529$func ConvertTo t.javaType t.var = e;
     530ConvertTo s.javaType t.var,
    539531  t.var : (s.refType e),
    540532  s.refType : {
    541     SVAR =
    542       (s.javaType' '<Rfp2Java t.convVar>' = '<ConvertTo2 s.javaType <Rfp2Java t.var>'.at(0)'>';');
     533    SVAR = {
     534      s.javaType : \{"boolean"; "char"; "byte"; "short"; "int"; "long";} =
     535        'Symbol.'s.javaType'Value('<Rfp2Java t.var>')';
     536      '('s.javaType') Symbol.objectValue('<Rfp2Java t.var>')';
     537    };
    543538    EVAR =
    544539      <ToChars s.javaType> : e.javaElemType '[]', <ToWord e.javaElemType> :: s.javaElemType,
    545       (s.javaType <Rfp2Java t.convVar>' = new 's.javaElemType'['<Rfp2Java t.var>'.length()];')
    546       ('for (int i = 0; i < '<Rfp2Java t.convVar>'.length; i++)'
    547         (<Rfp2Java t.convVar>'[i] = '<ConvertTo2 s.javaElemType <Rfp2Java t.var>'.at(i)'>';')
    548       );
     540      '('s.javaType') Symbol.toArrayValue('<Rfp2Java t.var>', new 's.javaElemType'['<Rfp2Java t.var>'.length()];';
    549541  };
    550542
    551 $func ConvertFrom s.javaType t.var t.convVar = e;
    552 $func ConvertFrom2 s.javaType e.varName = e;
    553 
    554 ConvertFrom2 s.javaType e.varName, {
    555   s.javaType : \{"boolean"; "char"; "byte"; "short"; "int"; "long";} =
    556     'Symbol.valueOf('e.varName')';
    557   '('e.varName' instanceof java.lang.Comparable) ? ((java.lang.Comparable) 'e.varName') : new org.refal.plus.Reference<'s.javaType'>('e.varName')';
    558 };
     543$func ConvertFrom t.var e.arg = e;
    559544 
    560 ConvertFrom s.javaType t.var t.convVar,
     545ConvertFrom t.var e.arg,
    561546  t.var : (s.refType e),
    562547  s.refType : {
    563     SVAR =
    564       (<Rfp2Java t.var>'.assign('<ConvertFrom2 s.javaType <Rfp2Java t.convVar>>');');
    565     EVAR =
    566       <ToChars s.javaType> : e.javaElemType '[]', <ToWord e.javaElemType> :: s.javaElemType,
    567       ('java.lang.Comparable[] tmp_'<Rfp2Java t.var>' = new java.lang.Comparable['<Rfp2Java t.convVar>'.length];')
    568       ('for (int i = 0; i < tmp_'<Rfp2Java t.var>'.length; i++)'
    569         ('tmp_'<Rfp2Java t.var>'[i] = '<ConvertFrom2 s.javaElemType <Rfp2Java t.convVar>'[i]'>';')
    570       )
    571       (<Rfp2Java t.var>'.assign(tmp_'<Rfp2Java t.var>');');
     548    SVAR = 'Native.sValueOf('e.arg')';
     549    EVAR = 'Native.eValueOf('e.arg')';
    572550  };
    573551
    574 WrapGen s.linkage s.tag t.qname (e.in) (e.out) e.native =
     552WrapGen s.linkage FUNC t.qname (e.in) (e.out) e.native =
    575553  <DeclarationReader <ToWord e.native>> :: s.static s.javaResType s.className s.methodName e.javaArgTypes,
    576   s.tag : \{
    577     FUNC  = ('void') /*empty*/;
    578     "FUNC?" = ('boolean') ('return true;');
    579   } :: (e.return_type) e.return =
    580554  { <Get &Entry> : e t.qname e = <Store &Entry_Name t.qname>;; },
    581555  { ('@RefalFormat("'<ReplaceQuotes <PrintFunctionFormat t.qname>>'")');; } :: e.refalFormat,
    582556  <Del_Pragmas <Gener_Var_Indices 1 (<Vars e.in>) 'arg'>> : e.rfArgTypes s,
    583557  <Del_Pragmas <Gener_Var_Indices 1 (<Vars e.out>) 'res'>> : e.rfResTypes s,
    584   <Del_Pragmas <Gener_Var_Indices 1 (<Vars e.in>) 'convArg'>> : e.rfConvArgTypes s,
    585   <Del_Pragmas <Gener_Var_Indices 1 (<Vars e.out>) 'convRes'>> : e.rfConvResTypes s,
    586   {
    587     s.methodName : "" = 'new ' s.className '(' 0;
    588     s.static : "" = <Rfp2Java <L 0 e.rfConvArgTypes>> '.' s.methodName '(' 1;
    589     s.className '.' s.methodName '(' 0;
     558  <PrintLn 1>,
     559  {
     560    s.methodName : "" = 'new ' s.className 0;
     561    s.static : "" = <ConvertTo s.className <L 0 e.rfArgTypes>> '.' s.methodName 1;
     562    s.className '.' s.methodName 0;
    590563  } :: e.funcHead s.shift,
    591 
    592   {
    593     s.shift : 1 = s.className e.javaArgTypes;
    594     e.javaArgTypes;
    595   } :: e.javaArgTypes2,
    596   0 $iter e.convTo <ConvertTo <L s.num e.javaArgTypes2> <L s.num e.rfArgTypes> <L s.num e.rfConvArgTypes>> <Add s.num 1>
    597     :: e.convTo s.num,
    598   <Length e.rfArgTypes> : s.num =
    599  
    600   s.shift $iter {
    601     e.vars : /**/ = <Rfp2Java <L s.shift e.rfConvArgTypes>> <Add s.shift 1>;
    602     e.vars ',' <Rfp2Java <L s.shift e.rfConvArgTypes>> <Add s.shift 1>;
    603   } :: e.vars s.shift, <Length e.rfConvArgTypes> : s.shift =
    604   e.funcHead e.vars ');' :: v.funcCall,
    605   {
    606     s.methodName : "" = s.className;
    607     s.javaResType;
    608   } :: s.javaResType,
    609   {
    610     e.rfConvResTypes : /**/ = v.funcCall;
    611     s.javaResType ' ' <Rfp2Java e.rfConvResTypes> ' = ' v.funcCall;
    612   } :: v.funcCall,
    613   0 $iter e.convFrom <ConvertFrom s.javaResType <L s.num e.rfResTypes> <L s.num e.rfConvResTypes>> <Add s.num 1>
    614     :: e.convFrom s.num,
    615   <Length e.rfResTypes> : s.num =
     564  <PrintLn 1>,
     565  {
     566    s.shift : 1 = e.rfArgTypes : t e.rfArgTypes2, e.rfArgTypes2;
     567    e.rfArgTypes;
     568  } :: e.rfArgTypes2,
     569  <PrintLn 1>,
     570  0 $iter {
     571    <WriteLn s.num e.javaArgTypes e.rfArgTypes2>,
     572    e.args <ConvertTo <L s.num e.javaArgTypes> <L s.num e.rfArgTypes2>> <Add s.num 1>;
     573  } :: e.args s.num,
     574  <Length e.javaArgTypes> : s.num =
     575  <PrintLn 3>,
     576  e.funcHead '(' e.args ');' :: v.funcCall,
     577  <PrintLn e.rfResTypes>,
     578  e.rfResTypes : {
     579    /**/ = v.funcCall';';
     580    t.rfResType, (<Rfp2Java e.rfResTypes>'.assign('<ConvertFrom t.rfResType v.funcCall>');');
     581  } :: e.body =
     582  <PrintLn 1>,
    616583  ()
    617584  e.refalFormat
    618   ('static '<Access_Mode s.linkage>' 'e.return_type' '
     585  ('static '<Access_Mode s.linkage>' void '
    619586  <Name_To_Java t.qname>' ('<Var_Args_To_Java Expr e.rfArgTypes Result e.rfResTypes>') throws RefalException')
    620   ('{' ('try {' (e.convTo (v.funcCall) e.convFrom e.return) '} catch (java.lang.Exception e) {' ('throw new org.refal.plus.RefalException("'<Get &Module_Name>'", "'<Name_To_Java t.qname>'", e.toString());')'}') '}');
     587  ('{' ('try {' (e.body) '} catch (java.lang.Exception e) {' ('throw new org.refal.plus.RefalException("'<Get &Module_Name>'", "'<Name_To_Java t.qname>'", e.toString());')'}') '}');
    621588  /*
    622589  {
Note: See TracChangeset for help on using the changeset viewer.