Changeset 2362


Ignore:
Timestamp:
Feb 10, 2007, 3:42:07 AM (14 years ago)
Author:
orlov
Message:
  • When compiling to C++ generate local stubs for all unavailable functions and constants (imported from Java).
Location:
to-imperative/trunk/compiler
Files:
3 edited

Legend:

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

    r2350 r2362  
    2525$table Externs;
    2626
     27$table Unavailable-Imports;
     28$table Used-Unavailable-Imports;
     29
    2730$func ASAIL-To-CPP e.body = e.cpp-code;
    2831
     
    4346$func Symbol-To-CPP s.RFP-Symbol = e.CPP-String;
    4447
    45 $func? Name-To-CPP t.name = e.CPP-Name;
     48$func Name-To-CPP t.name = e.CPP-Name;
    4649
    4750$func Cond-To-CPP t.cond = e.CPP-Cond;
     
    5962  {
    6063    <Store &Int <Lookup &RFP-Options INT>>;
    61     <Store &Int Integer>;
     64    <Store &Int "rftype::Integer">;
    6265  },
    6366  <Store &Module-Name e.ModuleName>,
     
    6972  <Store &Entry-Name /*empty*/>,
    7073  <Store &Const-Exprs /*empty*/>,
    71   <RFP-Clear-Table &Externs>,
     74  <Clear-Table &Externs>,
     75  <Clear-Table &Unavailable-Imports>,
     76  <Clear-Table &Used-Unavailable-Imports>,
    7277  {
    7378    <ASAIL-To-CPP e.asail> : v.cpp,
    7479      {
    75         <? &Current-Namespace> : v = ('}');;  // close last namespace
    76       } :: e.close-namespace,
     80        <? &Current-Namespace> : v = v.cpp ('}'); // close last namespace
     81        v.cpp;
     82      } :: v.cpp,
     83      <Store &Current-Namespace /*empty*/>,
     84      <ASAIL-To-CPP <Domain &Used-Unavailable-Imports>> :: e.imp,
     85      {
     86        <? &Current-Namespace> : v = e.imp ('}') v.cpp; // close last namespace
     87        e.imp v.cpp;
     88      } :: v.cpp,
    7789      <Store &Current-Namespace /*empty*/>,
    7890      {
     
    8193      {
    8294        <? &Const-Exprs> : v.c-exprs =
     95          <Namespace-Control <? &Module-Name>> :: e.nc,
    8396          (/*e.init-consts*/) <? &Const-Exprs> $iter {
    84             e.c-exprs : (e.cpp-name (e.value)) e.rest =
    85               (e.init-consts (e.cpp-name ' = ' e.value ';')) e.rest;
     97            e.c-exprs : (t.name (e.value)) e.rest =
     98              (e.init-consts (<Name-To-CPP t.name> ' = ' e.value ';')) e.rest;
    8699          } :: (e.init-consts) e.c-exprs,
    87100          e.c-exprs : /*empty*/ =
    88           <Namespace-Control <? &Module-Name>>
     101          e.nc
    89102          ('static void init_ ()\n{' (e.init-consts) '}')
    90103          ('static AtStart init_registrator_ (&init_);')
     
    93106      ('namespace refal\n{')
    94107      ('using namespace rfrt;')
    95       v.cpp e.close-namespace e.init e.entry
     108      v.cpp e.init e.entry
    96109      ('}');;
    97110  };
     
    99112ASAIL-To-CPP e.asail, {
    100113  e.asail : t.item e.rest, t.item : {
    101     (s.tag t.name (e.args) (e.ress) e.body),
     114    (s.tag IMPORT t.name t.args t.ress e.body),
     115      s.tag : \{ FUNC; FUNC?; } =
     116      <Bind &Unavailable-Imports (t.name)
     117        (s.tag LOCAL t.name t.args t.ress (ERROR <Concat t.name> "Not available"))>;
     118    (s.tag s.linkage t.name (e.args) (e.ress) e.body),
    102119      s.tag : \{
    103120        FUNC  = ('void') /*empty*/;
     
    202219    (ERROR e.expr) =
    203220      ('RF_ERROR (' <Expr-Ref-To-CPP e.expr> ');');
     221    (CONSTEXPR IMPORT t.name (e.comment) e.expr) =
     222      <Bind &Unavailable-Imports (t.name) (CONSTEXPR LOCAL t.name () e.expr)>;
    204223    (CONSTEXPR s.linkage t.name (e.comment) e.expr) =
    205224      { s.linkage : LOCAL = 'static ';; } :: e.linkage,
     
    207226        t.name : (STATIC e) = (<? &Module-Name>) t.name;
    208227        <Extract-Qualifiers t.name>;
    209       } :: (e.qualifiers) e.name,
    210       <Rfp2Cpp e.name> :: e.cpp-name,
    211       <Put &Const-Exprs (e.cpp-name (<Const-Expr-To-CPP e.expr>))>,
     228      } :: (e.qualifiers) e.n,
     229      <Put &Const-Exprs (t.name (<Const-Expr-To-CPP e.expr>))>,
    212230      <Namespace-Control e.qualifiers>
    213       (e.linkage 'Expr ' e.cpp-name ';');
     231      (e.linkage 'Expr ' <Rfp2Cpp e.n> ';');
    214232    (OBJ s.linkage s.tag t.name) =
    215233      { s.linkage : LOCAL = 'static ';; } :: e.linkage,
    216234      <To-Chars s.tag> : s1 e2,
    217       <Extract-Qualifiers t.name> :: (e.qualifiers) e.name,
    218       <Rfp2Cpp e.name> :: e.cpp-name,
     235      <Extract-Qualifiers t.name> :: (e.qualifiers) e.n,
    219236      {
    220237        s.tag : BOX =
    221           <Put &Const-Exprs (e.cpp-name
     238          <Put &Const-Exprs (t.name
    222239            ('Expr::create_sym< rftype::NamedObject<rftype::BoxContents> >('
    223               'L"'e.name'")'))>;
     240              'L"'e.n'")'))>;
    224241//        s.tag : VECTOR =
    225 //          <Put &Const-Exprs (e.cpp-name
     242//          <Put &Const-Exprs (t.name
    226243//            ('Expr::create_sym< rftype::NamedObject<rftype::Vector> >('
    227 //              'L"'e.name'")'))>;
    228         <Put &Const-Exprs (e.cpp-name
    229           ('new rftype::StaticObject<rftype::' s1 <To-Lower e2> '>(L"'e.name'")'))>;
     244//              'L"'e.n'")'))>;
     245        <Put &Const-Exprs (t.name
     246          ('new rftype::StaticObject<rftype::' s1 <To-Lower e2> '>(L"'e.n'")'))>;
    230247      },
    231248      <Namespace-Control e.qualifiers>
    232       (e.linkage 'Expr ' e.cpp-name ';');
     249      (e.linkage 'Expr ' <Rfp2Cpp e.n> ';');
    233250    (DECL-OBJ t.name) =
    234251      <Extract-Qualifiers t.name> :: (e.qualifiers) e.name,
     
    250267      {
    251268        # \{ s.call : CALL; }, <? &Current-Trace> : e.full-name (e.ress) =
    252           {
    253             ('if (RF_CALL (' <Name-To-CPP t.name> ', '
    254               <Args-To-CPP () Exprs e.exprs> ', ' <Args-To-CPP () Vars e.ress> '))');
    255             <Bind &RFP-Includes (Error) (BOOT)>,
    256               ('if (RF_CALL (' <Name-To-CPP (Error Not-Available)> ', '
    257                 '(' <Const-Expr-To-CPP <Concat t.name>> ', ' <Args-To-CPP () Vars>'))');
    258           }
     269          ('if (RF_CALL (' <Name-To-CPP t.name> ', '
     270            <Args-To-CPP () Exprs e.exprs> ', ' <Args-To-CPP () Vars e.ress> '))')
    259271          ('{' (<Trace-Exit e.full-name (e.ress)> ('return true;')) '}')
    260272          ('else RF_RETFAIL;');
     
    263275          s.call;
    264276        } :: s.call,
    265           {
    266             ('RF_' s.call ' (' <Name-To-CPP t.name> ', '
    267               <Args-To-CPP () Exprs e.exprs> ', ' <Args-To-CPP () Vars e.ress> ');');
    268             <Bind &RFP-Includes (Error) (BOOT)>,
    269               ('RF_' s.call ' (' <Name-To-CPP (Error Not-Available)> ', '
    270                 '(' <Const-Expr-To-CPP <Concat t.name>> '), ' <Args-To-CPP () Vars>');');
    271           };
     277          ('RF_' s.call ' (' <Name-To-CPP t.name> ', '
     278            <Args-To-CPP () Exprs e.exprs> ', ' <Args-To-CPP () Vars e.ress> ');');
    272279      };
    273280  } :: e.cpp-item,
     
    326333    e.prefix <Rfp2Cpp (STATIC t.name)>;
    327334  (s.var-tag e.ns t.name) = <Rfp2Cpp (s.var-tag e.ns t.name)>;
     335  s.sym, {
     336    <Int? s.sym> =
     337      'Expr::create<' <? &Int> '>("' s.sym '")';
     338    <Word? s.sym> =
     339      'Expr::create<rftype::Word>("' <Symbol-To-CPP s.sym> '")';
     340  };
    328341};
    329342
     
    423436      ' + ' <Rfp2Cpp t.item>;
    424437    (s.FUNC t.name), s.FUNC : \{ FUNC; FUNC?; } =
    425       ' + Expr::create_sym<Func> (' <Name-To-CPP t.name> ')';
     438      ' + Expr::create_sym<rftype::Func> (' <Name-To-CPP t.name> ')';
    426439    s.sym, {
    427440      <Int? s.sym> =
    428441        ' + Expr::create<' <? &Int> '>("' s.sym '")';
    429442      <Word? s.sym> =
    430         ' + Expr::create<Word>("' <Symbol-To-CPP s.sym> '")';
     443        ' + Expr::create<rftype::Word>("' <Symbol-To-CPP s.sym> '")';
    431444    };
    432445  } :: e.cpp-item =
     
    485498};
    486499
    487 Name-To-CPP t.obj-name =
    488   <RFP-Extract-Qualifiers t.obj-name> :: (e.qualifiers) e.name,
     500Name-To-CPP t.name =
     501  <RFP-Extract-Qualifiers t.name> :: (e.qualifiers) e.n,
    489502  {
    490503    <Lookup &RFP-Includes e.qualifiers> : LOCAL e 'org' s 'refal' s 'plus' s 'wrappers' e =
    491       $fail;;
     504      <Bind &Used-Unavailable-Imports (<Lookup &Unavailable-Imports t.name>) ()>;;
    492505  },
    493506  <? &Current-Namespace> :: e.namespace,
    494507  {
    495     e.qualifiers : e.namespace e.cont = <Rfp2Cpp e.cont e.name>;
    496     <Rfp2Cpp (e.qualifiers e.name)>;
     508    e.qualifiers : e.namespace e.cont = <Rfp2Cpp e.cont e.n>;
     509    <Rfp2Cpp (e.qualifiers e.n)>;
    497510  };
    498511
  • to-imperative/trunk/compiler/rfp_compile.rf

    r2350 r2362  
    6363$func Comp-Func-Stubs = e.asail-funcs;
    6464
    65 $func Comp-Func s.tag t.name e.params-and-body = e.compiled-func;
     65$func Comp-Func s.linkage s.tag t.name e.params-and-body = e.compiled-func;
    6666
    6767$func Set-Drops (e.declared-exprs) e.comp-func = (e.declared-exprs) e.result-func;
     
    137137    },
    138138    t.item : {
    139       (IMPORT s.tag t.pragma t.name e) =
     139      (IMPORT s.tag t.pragma t.name e),
    140140        {
    141141          t.pragma : (PRAGMA e (FILE e.fname) e) =
    142142            <RFP-Extract-Qualifiers t.name> :: (e.mod-name) e,
    143             <Bind &Includes (INPUT (e.mod-name) e.fname) ()>;;
     143            <Bind &Includes (INPUT (e.mod-name) e.fname) ()>,
     144            {
     145              s.tag : \{ CONST; FUNC; FUNC?; },
     146                e.fname : e 'org' s 'refal' s 'plus' s 'wrappers' e = $fail;;
     147            };;
    144148        },
    145149        () /*empty*/;
     
    153157        {
    154158          <? &Declarations> : $r e (s t.name) e = /*empty*/;
     159          s.link : IMPORT = /*empty*/;
    155160          (DECL-FUNC t.name);
    156161        } :: e.decl,
     
    162167        {
    163168          e.body : (BRANCH t.p e.branch) =
    164             <Comp-Func s.tag t.name <Del-Pragmas (e.in) (e.out) e.branch>>;;
     169            <Comp-Func s.link s.tag t.name <Del-Pragmas (e.in) (e.out) e.branch>>;
     170          <Comp-Func s.link s.tag t.name (<Gener-Vars (e.in) "arg">) (e.out)>;
    165171        } :: e.comp-func,
    166172        (e.decl) e.comp-func;
     
    196202  <Put &Declarations (DECL-FUNC t.stub-name)>,
    197203  <Gener-Vars (e.Fin) "stub"> :: e.He,
    198   <Comp-Func STUB t.stub-name ((EVAR ("arg" 1))) ((EVAR))
     204  <Comp-Func LOCAL STUB t.stub-name ((EVAR ("arg" 1))) ((EVAR))
    199205    (LEFT e.He) (CUTALL) (RESULT (CALL t.name e.He))>;
    200206
    201207
    202208
    203 Comp-Func s.tag t.name (e.in) (e.out) e.Sentence =
     209Comp-Func s.linkage s.tag t.name (e.in) (e.out) e.Sentence =
    204210  <RFP-Clear-Table &Labels>,
    205211  <RFP-Clear-Table &Prep-Vars>,
     
    220226      FUNC? (RETFAIL) ((ERROR e.message));
    221227  } :: s.tag e.fails,
    222   (s.tag t.name (<Vars-Print e.arg-vars>) (<Vars-Print e.res-vars>)
     228  (s.tag s.linkage t.name (<Vars-Print e.arg-vars>) (<Vars-Print e.res-vars>)
    223229    <Comp-Sentence Tail (e.fails) (e.arg) e.Sentence>
    224230  ) :: e.comp-func,
  • to-imperative/trunk/compiler/rfp_helper.rf

    r2068 r2362  
    3939  (e1 s2 s3 e4), <Int? s3> = (e1) s2 s3 e4;
    4040  (e1 s2) = (e1) s2;
     41  (e1) = () e1;
    4142};
    4243
Note: See TracChangeset for help on using the changeset viewer.