Changeset 220


Ignore:
Timestamp:
Nov 2, 2002, 11:43:08 PM (18 years ago)
Author:
orlov
Message:

* empty log message *

Location:
to-imperative/branches/pragma/compiler
Files:
3 edited

Legend:

Unmodified
Added
Removed
  • to-imperative/branches/pragma/compiler/rfp_asail.rf

    r219 r220  
    44
    55$use Apply Box Class Convert StdIO Table;
     6$use "rfpc";
    67$use "rfp_helper";
    78
    8 // Constructs legal C++ name from e.Name and stores it in the &RFP-CPP-Names table
     9$box Func-Names;
     10$table Func-Table;
     11$box Var-Names;
     12$table Var-Table;
     13
     14$func ASAIL-To-CPP e.body = e.cpp-code;
     15
     16// Constructs legal C++ name from e.Name and stores it in the appropriate box
     17// and table
    918$func Name-To-CPP t.Name = e.legal-cpp-name;
    1019
     
    3948$func Op-Arg-To-CPP s.op = s.func-for-converting-args-to-cpp;
    4049
    41 RFP-ASAIL-To-CPP e.asail, {
     50RFP-ASAIL-To-CPP e.asail =
     51  <Store &Func-Names /*empty*/>,
     52  <RFP-Clear-Table &Func-Table>,
     53  <ASAIL-To-CPP e.asail>;
     54
     55ASAIL-To-CPP e.asail, {
    4256  e.asail : t.item e.rest, t.item : {
    4357    (FUNC t.name (e.args) (e.ress) e.body) =
    44 //      {
    45 //        /*
    46 //         * Insert an empty line between functions.
    47 //         */
    48 //        e.rest : v = ();
    49 //        /*empty*/;
    50 //      } :: e.space,
     58      <Store &Var-Names /*empty*/>,
     59      <RFP-Clear-Table &Var-Table>,
    5160      ('RF_FUNC (' <Name-To-CPP t.name> ', '
    5261        '(' <Args-To-CPP ('RF_ARG ') Vars e.args> '), '
    5362        '(' <Args-To-CPP ('RF_RES ') Vars e.ress> '))'
    54           (<RFP-ASAIL-To-CPP e.body>)
     63          (<ASAIL-To-CPP e.body>)
    5564       'RF_END');
    5665    (IF (e.cond) e.body) =
    5766      ('if (' <Cond-To-CPP e.cond> ')')
    58       ('{' (<RFP-ASAIL-To-CPP e.body>) '}');
     67      ('{' (<ASAIL-To-CPP e.body>) '}');
    5968    (FOR (e.label) (e.cond) (e.step) e.body) =
    6069      {
     
    6271      } :: e.label,
    6372      ('for ( ; ' <Cond-To-CPP e.cond> '; ' <Step-To-CPP e.step> ')')
    64       ('{' (<RFP-ASAIL-To-CPP e.body>) e.label '}');
     73      ('{' (<ASAIL-To-CPP e.body>) e.label '}');
    6574    (LABEL t.label e.body) =
    66       ('{' (<RFP-ASAIL-To-CPP e.body>) '}')
     75      ('{' (<ASAIL-To-CPP e.body>) '}')
    6776      (LABEL <Name-To-CPP (LABEL t.label)> ': {}');
    6877    (TRY e.body) =
    69       ('try {' (<RFP-ASAIL-To-CPP e.body>) '}');
     78      ('try {' (<ASAIL-To-CPP e.body>) '}');
    7079    (CATCH-ERROR e.body) =
    71       ('with {' (<RFP-ASAIL-To-CPP e.body>) '}');
     80      ('with {' (<ASAIL-To-CPP e.body>) '}');
    7281    RETURN = ('return true;');
    7382    RETFAIL = ('retfail;');
     
    111120      '(' <Args-To-CPP () Exprs e.exprs> '), (' <Args-To-CPP () Vars e.ress> '));');
    112121  } :: e.cpp-item,
    113     e.cpp-item <RFP-ASAIL-To-CPP e.rest>;
     122    e.cpp-item <ASAIL-To-CPP e.rest>;
    114123  /*empty*/;
    115124};
     
    144153    t.item : {
    145154      s.ObjectSymbol = <Symbol-To-CPP s.ObjectSymbol>;
    146       (PAREN e.expr) = '(' <Expr-Ref-To-CPP 0 e.expr> ') ()';
     155      (PAREN e.expr) = <Expr-Ref-To-CPP 0 e.expr> ' ()';
    147156      (EXPR e.expr) =
    148157        'Expr (' <Chars-To-CPP e.expr> ')';
     
    177186        };
    178187      (LENGTH e.expr) =
    179         '(int) (' <Expr-Ref-To-CPP 0 e.expr> ').get_len ()';
     188        '(int) ' <Expr-Ref-To-CPP 0 e.expr> '.get_len ()';
    180189      (MAX e.args) =
    181190        'max (' <Args-To-CPP () Ints e.args> ')';
     
    204213        '(' <Args-To-CPP () Vars e.ress> '))';
    205214      (SYMBOL? e.expr (e.pos)) =
    206         '(' <Expr-Ref-To-CPP 0 e.expr> ').symbol_at (' <Expr-Int-To-CPP e.pos> ')';
     215         <Expr-Ref-To-CPP 0 e.expr> '.symbol_at (' <Expr-Int-To-CPP e.pos> ')';
    207216      (FLAT-SUBEXPR? e.expr (e.pos) (e.len)) =
    208         '(' <Expr-Ref-To-CPP 0 e.expr> ').flat_at ('
     217         <Expr-Ref-To-CPP 0 e.expr> '.flat_at ('
    209218          <Expr-Int-To-CPP e.pos> ', ' <Expr-Int-To-CPP e.len> ')';
    210219      /*
     
    224233              <Expr-Int-To-CPP e.len> ')';
    225234      (NOT e.cond) =
    226         '!(' <Cond-To-CPP e.cond> ')';
     235        '!' <Cond-To-CPP e.cond>;
    227236      (INFIX s.op e.args) =
    228237        '(' <Infix-To-CPP <Op-Arg-To-CPP s.op> s.op e.args> ')';
     
    237246      /*empty*/;
    238247    } :: e.cpp-op,
    239     '(' <Apply s.arg2cpp e.arg> ')' e.cpp-op <Infix-To-CPP s.arg2cpp s.op e.rest>;;
     248    <Apply s.arg2cpp e.arg> e.cpp-op <Infix-To-CPP s.arg2cpp s.op e.rest>;;
    240249};
    241250
     
    278287};
    279288
    280 $box Used-Names;
    281 
    282289/*
    283290 * Gets function name or variable and returns legal C++ name corresponding to
    284291 * it. If is called with such parameter at the first time then stores C++ name
    285  * in the &RFP-CPP-Names table for further using.
     292 * in the appropriate table for further using. Also put new name in the
     293 * appropriate box. Box and table for variables is updated for each new
     294 * function and box and table for functions is updated for each new module.
    286295 */
    287296Name-To-CPP term =
    288297  term : {
    289     (VAR (e.QualifiedName)) = e.QualifiedName;
    290     (LABEL (e.QualifiedName)) = e.QualifiedName;
    291     (e.QualifiedName) = e.QualifiedName;  // function name
    292   } :: e.QualifiedName,
     298    (VAR (e.QualifiedName)) = e.QualifiedName &Var-Names &Var-Table;
     299    (LABEL (e.QualifiedName)) = e.QualifiedName &Var-Names &Var-Table;
     300    (e.QualifiedName) = e.QualifiedName &Func-Names &Func-Table;  // function name
     301  } :: e.QualifiedName s.used-names s.table,
    293302  {
    294     <Lookup &RFP-CPP-Names e.QualifiedName>;
     303    <Lookup s.table e.QualifiedName>;
    295304    e.QualifiedName : s.first e.last,
    296305      <Word-To-CPP-Chars s.first> :: e.first,
     
    302311      } :: (e.first) e.last,
    303312      e.first <Build-CPP-Name e.last> :: e.name,
    304       <Find-Unused-Name (<? &Used-Names>) e.name> :: e.name,
    305       <Put &Used-Names (e.name)>,
    306       <Bind &RFP-CPP-Names (e.QualifiedName) (e.name)>,
     313      <Find-Unused-Name (<? s.used-names>) e.name> :: e.name,
     314      <Put s.used-names (e.name)>,
     315      <Bind s.table (e.QualifiedName) (e.name)>,
    307316      e.name;
    308317  };
  • to-imperative/branches/pragma/compiler/rfp_asail.rfi

    r219 r220  
    33// $Date$
    44
    5 /*
    6  * Table for storing legal C++ names of functions and variables. Only functions
    7  * names will appear in result program as are. For variables they are obtained
    8  * from indexes and to be preceded by some prefix. For e.Key e.QualifiedName is
    9  * used.
    10  */
    11 $table RFP-CPP-Names;
    12 
    135$func RFP-ASAIL-To-CPP e.asail = e.cpp;
    146
  • to-imperative/branches/pragma/compiler/rfpc.rf

    r219 r220  
    132132          <Channel> :: s.channel,
    133133          <Open-File s.channel e.file R>,
    134           AS-AIL <Read! s.channel>;
     134          AS-AIL (AS-AIL AS-AIL <Read! s.channel> <Read! s.channel>);
    135135        <PrintLN! &StdErr "Error: unknown extension" e.ext " in " e.file> = $fail;
    136136      } : s.type (s.tag t.ModuleName e.Items),
Note: See TracChangeset for help on using the changeset viewer.