source: to-imperative/trunk/compiler/src/org/refal/plus/compiler/rfp_asail_tpp.rf @ 3591

Last change on this file since 3591 was 3591, checked in by yura, 13 years ago
  • Losted rfp_asail_tpp files.
  • Property svn:eol-style set to native
  • Property svn:keywords set to Author Date Id Revision
File size: 20.0 KB
Line 
1$use Access Apply Arithm Box Class Compare Convert CppMangle List StdIO Table;
2
3$use "org.refal.plus.compiler.rfpc";
4$use "org.refal.plus.compiler.rfp_helper";
5$use "org.refal.plus.compiler.rfp_vars";
6
7$box Int;
8
9$box Module_Name;
10
11$box Current_Namespace;
12
13$box Current_Func;
14
15$box Current_Trace;
16
17$box Entry;
18
19$box Entry_Name;
20
21$box Const_Exprs;
22
23$table Externs;
24
25$table Unavailable_Imports;
26$table Used_Unavailable_Imports;
27
28$table Decls;
29$table Locals;
30
31$table Used_Consts;
32
33$func ASAIL_To_CPP e.body = e.cpp_code;
34
35$func Open_Namespace e.name = e;
36$func Close_Namespace e.name = e;
37
38$func Namespace_Control e.qualifiers = e.namespace_control;
39
40$func Expr_Ref_To_CPP e.ASAIL_Expr_Ref = e.CPP_Expr_Ref;
41
42$func Expr_Int_To_CPP e.ASAIL_Expr_Int = e.CPP_Expr_Int;
43
44$func Step_To_CPP e.step_operators = e.cpp_step_operators;
45
46$func Const_Expr_To_CPP e.ASAIL_const_expr = e.CPP_const_expr;
47
48$func Args_To_CPP (e.prefix) s.Arg_Res_Tag e.ASAIL_Args = e.CPP_Args;
49
50$func Symbol_To_CPP s.RFP_Symbol = e.CPP_String;
51
52$func QName_To_Cpp e.name = e.cpp_name;
53
54$func Name_To_CPP s.decl_type t.name = e.CPP_Name;
55
56$func Cond_To_CPP t.cond = e.CPP_Cond;
57
58$func Infix_To_CPP s.func_for_converting_args_to_cpp s.op e.args = e.cpp_expr;
59
60$func Trace_Enter e.name (e.args) = e.trace;
61$func Trace_Exit  e.name (e.ress) = e.trace;
62$func Trace_Fail  e.name          = e.trace;
63
64$func Extract_Qualifiers t.name = (e.qualifiers) e.name;
65
66
67RFP_ASAIL_To_TPP (MODULE (e.ModuleName) e.asail) =
68  {
69    <Store &Int <Lookup &RFP_Options INT>>;
70    <Store &Int "rftype::Integer">;
71  },
72  <Store &Module_Name e.ModuleName>,
73  <Store &Current_Namespace /*empty*/>,
74  {
75    <Store &Entry <Lookup &RFP_Options ENTRIES>>;
76    <Store &Entry (e.ModuleName Main)>;
77  },
78  <Store &Entry_Name /*empty*/>,
79  <Store &Const_Exprs /*empty*/>,
80  <ClearTable &Externs>,
81  <ClearTable &Unavailable_Imports>,
82  <ClearTable &Used_Unavailable_Imports>,
83  <ClearTable &Decls>,
84  <ClearTable &Locals>,
85  <ClearTable &Used_Consts>,
86  {
87    <ASAIL_To_CPP e.asail> : v.cpp,
88      v.cpp <Map &Close_Namespace (<Get &Current_Namespace>)> :: v.cpp,
89      <Store &Current_Namespace /*empty*/>,
90      <ASAIL_To_CPP <Domain &Used_Unavailable_Imports>> :: e.imp,
91      e.imp <Map &Close_Namespace (<Get &Current_Namespace>)> v.cpp :: v.cpp,
92      <Store &Current_Namespace /*empty*/>,
93      {
94        <Get &Entry_Name> : v.name = ('rfrt::Entry rf_entry (' v.name ');');;
95      } :: e.entry,
96      {
97        <Get &Const_Exprs> : v.c_exprs =
98          <Namespace_Control <Get &Module_Name>> :: e.nc,
99          (/*e.init_consts*/) (/*e.decl_consts*/) v.c_exprs $iter {
100            e.c_exprs : (t.name (e.value) e.decl) e.rest =
101              {
102                <IsInTable &Used_Consts t.name> =
103                  {
104                    t.name : (STATIC e) = <Rfp2Cpp t.name>;
105                    <Name_To_CPP "DECL-OBJ" t.name>;
106                  } :: e.name,
107                  (e.init_consts (e.name ' = new TExpr;') (e.value ';')) (e.decl_consts e.decl) e.rest;
108                (e.init_consts) (e.decl_consts) e.rest;
109              };
110          } :: (e.init_consts) (e.decl_consts) e.c_exprs,
111          e.c_exprs : /*empty*/ =
112          e.nc
113          ('static void init_ () {' (e.init_consts) '}')
114          ('static AtStart init_registrator_ (&init_);')
115          <Map &Close_Namespace (<Get &Current_Namespace>)>
116          (<Store &Current_Namespace /*empty*/>
117            <Namespace_Control <Get &Module_Name>>
118            e.decl_consts
119            <Map &Close_Namespace (<Get &Current_Namespace>)>
120          );
121        ();
122      } :: e.init (e.decl_consts),
123      <Store &Current_Namespace /*empty*/>,
124      ('#include <rf_core.hh>')
125      ('using namespace rfrt;')
126      <ASAIL_To_CPP <List.Sub (<Domain &Decls>) <Domain &Locals>>>
127      <Map &Close_Namespace (<Get &Current_Namespace>)>
128      e.decl_consts
129      v.cpp e.init e.entry;;
130  };
131
132ASAIL_To_CPP e.asail, {
133  e.asail : t.item e.rest, t.item : {
134    (s.tag UNDEF e) = ;
135    (LINENUMBER sN) = ;
136    (NATIVE s.linkage s.tag (e.name) (e.in) (e.out) e.native) =
137        <Del_Pragmas <Gener_Var_Indices 1 (<Vars e.in>) 'arg'>> : e.rfArg s,
138        <Del_Pragmas <Gener_Var_Indices 1 (<Vars e.out>) 'res'>> : e.rfRes s,
139        <ASAIL_To_CPP (s.tag LOCAL (e.name) (e.rfArg) (e.rfRes) (ERROR e.name "Not available"))>;
140    (s.tag IMPORT (e.name) t.args t.ress e.body),
141      s.tag : \{ FUNC; "FUNC?"; },
142      e.name : "org" "refal" "plus" "wrappers" e.n =
143      <Bind &Unavailable_Imports (e.name)
144        (s.tag LOCAL (<ToWord <Intersperse ('_') e.n>>) t.args t.ress
145          (ERROR e.n "Not available"))>;
146    (TFUNC s.linkage t.name (e.args) (e.ress) e.body),
147      <Store &Current_Func t.name>,
148      { <Get &Entry> : e t.name e = <Store &Entry_Name <QName_To_Cpp <Concat t.name>>>;; },
149      {
150        \{
151          <IsInTable &RFP_Options TRACEALL>;
152          <IsInTable &RFP_Trace t.name>;
153        } =
154          <Intersperse ('.') <Concat t.name>> :: e.name,
155          <Store &Current_Trace e.name (e.ress)>,
156          (<Trace_Enter e.name (e.args)>) (<Trace_Exit e.name (e.ress)>);
157        <Store &Current_Trace /*empty*/>,
158          () ();
159      } :: (e.trace_enter) (e.trace_exit),
160      <MapIn &Rfp2Cpp (<Paren e.args>)> :: e.args,
161      <MapIn &Id 'TExpr ' (e.args)> :: e.args,
162      <MapIn &Rfp2Cpp (<Paren e.ress>)> :: e.ress,
163      <MapIn &Id 'tout Expr ' (e.ress)> :: e.ress,
164      <ASAIL_To_CPP e.body> :: e.body,
165      <Extract_Qualifiers t.name> :: (e.qualifiers) e,
166      <Namespace_Control e.qualifiers>
167      ('tfun int '<Name_To_CPP "DECL-FUNC" t.name>' ('<Concat <Intersperse (', ') e.args e.ress>>') {'
168        (e.trace_enter e.body e.trace_exit ('return 0;'))
169      '}');
170    (s.tag s.linkage t.name (e.args) (e.ress) e.body),
171      s.tag : \{ FUNC; "FUNC?"; } =
172      <Store &Current_Func t.name>,
173      { <Get &Entry> : e t.name e = <Store &Entry_Name <QName_To_Cpp <Concat t.name>>>;; },
174      {
175        \{
176          <IsInTable &RFP_Options TRACEALL>;
177          <IsInTable &RFP_Trace t.name>;
178        } =
179          <Intersperse ('.') <Concat t.name>> :: e.name,
180          <Store &Current_Trace e.name (e.ress)>,
181          (<Trace_Enter e.name (e.args)>) (<Trace_Exit e.name (e.ress)>);
182        <Store &Current_Trace /*empty*/>,
183          () ();
184      } :: (e.trace_enter) (e.trace_exit),
185      <Extract_Qualifiers t.name> :: (e.qualifiers) e,
186      <Namespace_Control e.qualifiers>
187      ('RF_FUNC (' <Name_To_CPP "DECL-FUNC" t.name> ', '
188            <Args_To_CPP ('RF_ARG ') Vars e.args> ', '
189            <Args_To_CPP ('RF_RES ') Vars e.ress> ')'
190        (e.trace_enter <ASAIL_To_CPP e.body> e.trace_exit)
191       'RF_END');
192    (TRACE t.name) =
193      <Bind &RFP_Trace (t.name) ()>;
194    ("IF-INT-CMP" s.op (e.arg1) (e.arg2) e.body) =
195      ('if (' <Expr_Int_To_CPP e.arg1> ' 's.op' ' <Expr_Int_To_CPP e.arg2> ')')
196      ('{' (<ASAIL_To_CPP e.body>) '}');
197    (IF t.cond e.body) =
198      ('if (' <Cond_To_CPP t.cond> ')')
199      ('{' (<ASAIL_To_CPP e.body>) '}');
200    (FOR (e.cont_label) (e.break_label) (e.cond) (e.step) e.body) =
201      {
202        e.cont_label : t =
203          ('{'
204            ('{' (<ASAIL_To_CPP e.body>) '}')
205            (LABEL <Rfp2Cpp (LABEL e.cont_label)> ': {}')
206          '}');
207        ('{' (<ASAIL_To_CPP e.body>) '}');
208      } :: e.body,
209      {
210        e.break_label : t = (LABEL <Rfp2Cpp (LABEL e.break_label)> ': {}');;
211      } :: e.break,
212      ('for ( ; ; ' <Step_To_CPP e.step> ')') e.body e.break;
213    (LABEL (e.label) e.body) =
214      ('{' (<ASAIL_To_CPP e.body>) '}')
215      (LABEL <Rfp2Cpp (LABEL e.label)> ': {}');
216    (TRY e.body) =
217      ('RF_TRAP') ('{' (<ASAIL_To_CPP e.body>) '}');
218    ("CATCH-ERROR" e.body) =
219      ('RF_WITH') ('{' (('RF_CLEANUP;') <ASAIL_To_CPP e.body>) '}');
220    RETFAIL =
221      {
222        <Get &Current_Trace> : e.name (e.ress) =
223          <Trace_Fail e.name>;
224        /*empty*/;
225      } :: e.trace_exit,
226      e.trace_exit ('RF_RETFAIL;');
227    FATAL =
228//      <? &Current-Func> : (e.name),
229      ('RF_FUNC_ERROR (unexpected_fail);');
230    (LSPLIT e.expr (e.min) t.var1 t.var2) =
231      ('RF_lsplit (' <Expr_Ref_To_CPP e.expr> ', ' <Expr_Int_To_CPP e.min> ', '
232      <Rfp2Cpp t.var1> ', ' <Rfp2Cpp t.var2> ');');
233    (RSPLIT e.expr (e.min) t.var1 t.var2) =
234      ('RF_rsplit (' <Expr_Ref_To_CPP e.expr> ', ' <Expr_Int_To_CPP e.min> ', '
235      <Rfp2Cpp t.var1> ', ' <Rfp2Cpp t.var2 > ');');
236    (ASSIGN t.var e.expr), t.var : (INT e)  =
237      (<Rfp2Cpp t.var> ' = ' <Expr_Int_To_CPP e.expr> ';');
238    (ASSIGN t.var e.expr) =
239      (<Rfp2Cpp t.var> ' = ' <Expr_Ref_To_CPP e.expr> ';');
240    (DECL t.var e.expr), t.var : (INT e)  =
241      ('int ' <Rfp2Cpp t.var> ' = '<Expr_Int_To_CPP e.expr>';');
242    (DECL s.type t.var) =
243      ('Expr ' <Rfp2Cpp t.var> ';');
244    (DECL s.type t.var e.expr) =
245      ('Expr ' <Rfp2Cpp t.var> ' ('<Expr_Ref_To_CPP e.expr>');');
246    (DROP t.var) =
247      (<Rfp2Cpp t.var> '.drop ();');
248    (CONTINUE t.label) =
249      ('goto ' <Rfp2Cpp (LABEL t.label)> ';');
250    (BREAK t.label) =
251      ('goto ' <Rfp2Cpp (LABEL t.label)> ';');
252    (ERROR e.expr) =
253      ('RF_ERROR (' <Expr_Ref_To_CPP e.expr> ');');
254    (CONSTEXPR IMPORT (e.name) (e.comment) e.expr) =
255      e.name : "org" "refal" "plus" "wrappers" e.n,
256      <Bind &Unavailable_Imports (e.name)
257        (CONSTEXPR LOCAL (<ToWord <Intersperse ('_') e.n>>) () e.expr)>;
258    (CONSTEXPR s.linkage t.name (e.comment) e.expr) =
259      { s.linkage : LOCAL = 'static ';; } :: e.linkage,
260      {
261        t.name : (STATIC e) = (<Get &Module_Name>) (&Rfp2Cpp t.name);
262        <Extract_Qualifiers t.name> (&Name_To_CPP "DECL-OBJ" t.name);
263      } :: (e.qualifiers) e (s.name_producer e.name_arg),
264      <Put &Const_Exprs (t.name
265        (<Const_Expr_To_CPP /*e.expr*/ e.comment>)
266        /*e.qualifiers*/ (e.linkage 'TExpr* ' <Apply s.name_producer e.name_arg> ';'))>;
267    (OBJ s.linkage s.tag t.name) =
268      <Bind &Locals ("DECL-OBJ" t.name) ()>,
269      { s.linkage : LOCAL = 'static ';; } :: e.linkage,
270      <ToChars s.tag> : s1 e2,
271      <Extract_Qualifiers t.name> :: (e.qualifiers) e.n,
272      {
273        s.tag : BOX =
274          <Put &Const_Exprs (t.name
275            ('Expr::create_sym< rftype::NamedObject<rftype::BoxContents> >('
276              'L"'e.n'")'))>;
277//        s.tag : VECTOR =
278//          <Put &Const-Exprs (t.name
279//            ('Expr::create_sym< rftype::NamedObject<rftype::Vector> >('
280//              'L"'e.n'")'))>;
281        <Put &Const_Exprs (t.name
282          ('new rftype::StaticObject<rftype::' s1 <ToLower e2> '>(L"'e.n'")'))>;
283      },
284      <Namespace_Control e.qualifiers>
285      (e.linkage 'Expr ' <Name_To_CPP "DECL-OBJ" t.name> ';');
286    ("DECL-OBJ" t.name) =
287      <Extract_Qualifiers t.name> :: (e.qualifiers) e,
288      <Namespace_Control e.qualifiers>
289      ('extern Expr ' <Name_To_CPP "DECL-OBJ" t.name> ';');
290    ("DECL-FUNC" t.name) =
291      <Extract_Qualifiers t.name> :: (e.qualifiers) e,
292      <Namespace_Control e.qualifiers>
293      ('RF_DECL (' <Name_To_CPP "DECL-FUNC" t.name> ');');
294    (EXTERN t.name) =
295      <Bind &Externs (t.name) ()>,
296      <Extract_Qualifiers t.name> :: (e.qualifiers) e,
297      <Namespace_Control e.qualifiers>
298      ('RF_DECL (' <Name_To_CPP "DECL-FUNC" t.name> ');');
299    /*
300     * s.call can be CALL or TAILCALL or TAILCALL?
301     */
302    (s.call t.name (e.exprs) (e.ress)) =
303      {
304        # \{ s.call : CALL; }, <Get &Current_Trace> : e.full_name (e.ress) =
305          ('if (RF_CALL (' <Name_To_CPP "DECL-FUNC" t.name> ', '
306            <Args_To_CPP () Exprs e.exprs> ', ' <Args_To_CPP () Vars e.ress> '))')
307          ('{' (<Trace_Exit e.full_name (e.ress)> ('return true;')) '}')
308          ('else RF_RETFAIL;');
309        {
310          s.call : "TAILCALL?" = TAILCALL;
311          s.call;
312        } :: s.call,
313          ('RF_' s.call ' (' <Name_To_CPP "DECL-FUNC" t.name> ', '
314            <Args_To_CPP () Exprs e.exprs> ', ' <Args_To_CPP () Vars e.ress> ');');
315      };
316  } :: e.cpp_item,
317    e.cpp_item <ASAIL_To_CPP e.rest>;
318  /*empty*/;
319};
320
321
322$func Term_Ref_To_CPP e = e;
323
324Expr_Ref_To_CPP {
325  /*empty*/ = 'empty';
326  term = <Term_Ref_To_CPP term>;
327  expr = '(' <Infix_To_CPP &Term_Ref_To_CPP "+" <Paren expr>> ')';
328};
329
330Term_Ref_To_CPP {
331  (PAREN e.expr) =
332    <Expr_Ref_To_CPP e.expr> ' ()';
333  (DEREF e.expr (e.pos)) =
334    'Expr (' <Expr_Ref_To_CPP e.expr> ', ' <Expr_Int_To_CPP e.pos> ')';
335  (SUBEXPR e.expr (e.pos) (e.len)) =
336    'Expr (' <Expr_Ref_To_CPP e.expr> ', '
337        <Expr_Int_To_CPP e.pos>   ', ' <Expr_Int_To_CPP e.len> ')';
338  (REF t.name) = <Name_To_CPP "DECL-OBJ" t.name>;
339  "ERROR-EXPR" = 'err';
340  (STATIC t.name) =
341    <Bind &Used_Consts ((STATIC t.name)) ()>,
342    <Get &Current_Namespace> :: e.namespace,
343    {
344      <Get &Module_Name> : e.namespace = /*empty*/;
345      <Get &Module_Name>'::';
346    } :: e.prefix,
347    '*' e.prefix <Rfp2Cpp (STATIC t.name)>;
348  (s.var_tag e.ns t.name) = <Rfp2Cpp (s.var_tag e.ns t.name)>;
349  s.sym, {
350    <IsInt s.sym> =
351      'Expr::create<' <Get &Int> '>("' s.sym '")';
352    <IsWord s.sym> =
353      'Expr::create<rftype::Word>("' <Symbol_To_CPP s.sym> '")';
354  };
355};
356
357Expr_Int_To_CPP {
358  /*empty*/ = /*empty*/;
359  s.ObjectSymbol =
360    {
361      <IsInt s.ObjectSymbol> = s.ObjectSymbol;
362      $error ("Illegal type int-symbol: " s.ObjectSymbol);
363    };
364  (LENGTH e.expr) =
365    <Expr_Ref_To_CPP e.expr> '.get_len ()';
366  (MAX e.args) =
367    'pxx_max (' <Args_To_CPP () Ints e.args> ')';
368  (MIN e.args) =
369    'pxx_min (' <Args_To_CPP () Ints e.args> ')';
370  (INFIX s.op e.args) =
371    '(' <Infix_To_CPP &Expr_Int_To_CPP s.op e.args> ')';
372  (REF t.name) = <Name_To_CPP "DECL-OBJ" t.name>;
373  (s.var_tag t.name) = <Rfp2Cpp (s.var_tag t.name)>;
374  expr = '(' <Infix_To_CPP &Expr_Int_To_CPP "+" <Paren expr>> ')';
375};
376
377Cond_To_CPP {
378  ("CALL-FAILS" (CALL t.name (e.exprs) (e.ress))) =
379    '!RF_CALL (' <Name_To_CPP "DECL-FUNC" t.name> ', '
380          <Args_To_CPP () Exprs e.exprs> ', '
381          <Args_To_CPP () Vars e.ress>   ')';
382  ("SYMBOL?" e.expr (e.pos)) =
383    <Expr_Ref_To_CPP e.expr> '.symbol_at (' <Expr_Int_To_CPP e.pos> ')';
384  ("FLAT-SUBEXPR?" e.expr (e.pos) (e.len)) =
385    <Expr_Ref_To_CPP e.expr> '.flat_at ('
386      <Expr_Int_To_CPP e.pos> ', ' <Expr_Int_To_CPP e.len> ')';
387  ("ITER-FAILS" e.expr) =
388    '!RF_iter(' <Expr_Ref_To_CPP e.expr> ')';
389  (EQ e.expr1 (e.expr2) (e.pos)) =
390    <Expr_Ref_To_CPP e.expr1> '.eq ('
391      <Expr_Ref_To_CPP e.expr2> ', ' <Expr_Int_To_CPP e.pos> ')';
392  ("TERM-EQ" e.expr1 (e.expr2) (e.pos)) =
393    <Expr_Ref_To_CPP e.expr1> '.term_eq ('
394      <Expr_Ref_To_CPP e.expr2> ', ' <Expr_Int_To_CPP e.pos> ')';
395  (NOT t.cond) =
396    '!' <Cond_To_CPP t.cond>;
397};
398
399Infix_To_CPP s.arg2cpp s.op e.args, {
400  e.args : (e.arg) e.rest =
401    <Apply s.arg2cpp e.arg> :: e.arg,
402    <Infix_To_CPP s.arg2cpp s.op e.rest> :: e.rest,
403    {
404      e.arg : v, e.rest : v = e.arg ' ' s.op ' ' e.rest;
405      e.arg e.rest;
406    };;
407};
408
409Step_To_CPP {
410  /*empty*/ = /*empty*/;
411  ("INC-ITER" e.expr) = 'RF_iter(' <Expr_Ref_To_CPP e.expr> ')++';
412  ("DEC-ITER" e.expr) = 'RF_iter(' <Expr_Ref_To_CPP e.expr> ')--';
413};
414
415
416
417$func Const_Expr_Aux e.expr = e.cpp_expr;
418
419Const_Expr_To_CPP {
420  /*empty*/ = 'empty';
421  (SUBEXPR t.name s.pos s.len) = 'Expr (' <Rfp2Cpp t.name> ', ' s.pos ', ' s.len ')';
422                  //FIXME: It is needed to check that s.pos and s.len
423                  //       are in allowable bounds.
424                  //       Set this bounds by options.
425  e.expr =
426    <Const_Expr_Aux () e.expr> : {
427      ' + ' e.cpp_expr = e.cpp_expr;
428      e.cpp_expr = e.cpp_expr;
429    };
430};
431
432Const_Expr_Aux (e.accum) e.expr, {
433  e.expr : s.sym e.rest, <IsChar s.sym> =
434    <Const_Expr_Aux (e.accum <Symbol_To_CPP s.sym>) e.rest>;
435  e.accum : v =
436    '"'e.accum'"' <Const_Expr_Aux () e.expr>;
437//T/    {
438//T/      <CharsToBytes e.accum> : e s.c e,
439//T/        <Gt (s.c) (127)> =
440//T/        ' + rftype::Char::create_expr ("' e.accum '")' <Const_Expr_Aux () e.expr>;
441//T/      //' + Expr::create_seq<Char> (L"' e.accum '")' <Const-Expr-Aux () e.expr>;
442//T/      ' + rftype::Char::create_expr (L"' e.accum '")' <Const_Expr_Aux () e.expr>;
443//T/    };
444  e.expr : t.item e.rest, t.item : {
445    (PAREN e.paren_expr) =
446      ' + (' <Const_Expr_To_CPP e.paren_expr> ') ()';
447    (REF t.name) =
448      ' + ' <Name_To_CPP "DECL-OBJ" t.name>;
449//      ' + Expr::create<ObjectRef>(' <Name-To-CPP t.name> ')';
450    (STATIC e) =
451      <Bind &Used_Consts (t.item) ()>,
452      ' + ' '*' <Rfp2Cpp t.item>;
453    (s.FUNC t.name), s.FUNC : \{ FUNC; "FUNC?"; TFUNC; } =
454      ' + Expr::create_sym<rftype::Func> (' <Name_To_CPP "DECL-FUNC" t.name> ')';
455    s.sym, {
456      <IsInt s.sym> =
457        ' + Expr::create<' <Get &Int> '>("' s.sym '")';
458      <IsWord s.sym> =
459        ' + Expr::create<rftype::Word>("' <Symbol_To_CPP s.sym> '")';
460    };
461  } :: e.cpp_item =
462    e.cpp_item <Const_Expr_Aux () e.rest>;
463  = /*empty*/;
464};
465
466Symbol_To_CPP s.ObjectSymbol, {
467  <ToChars s.ObjectSymbol> () $iter {
468    e.symbol : s.char e.rest, s.char : {
469      '\\' = '\\\\';
470      '\n' = '\\n';
471      '\t' = '\\t';
472//        '\v' = '\\v';
473//        '\b' = '\\b';
474      '\r' = '\\r';
475//        '\f' = '\\f';
476      '\"' = '\\"';
477//      '\'' = '\\\'';
478      s = s.char;
479    } :: e.cpp_char,
480    e.rest (e.cpp_symbol e.cpp_char);
481  } :: e.symbol (e.cpp_symbol),
482    e.symbol : /*empty*/ =
483    e.cpp_symbol;
484};
485
486
487
488Args_To_CPP {
489  (v.prefix) Vars /*empty*/  = 'RF_VOID';
490  (        ) Vars /*empty*/  = '/*void*/';
491  (        ) Vars (e.arg)    = <Rfp2Cpp (e.arg)>;
492  (e.prefix) Exprs /*empty*/ = '/*void*/';
493  (e.prefix) Exprs (e.arg)   = <Expr_Ref_To_CPP e.arg>;
494  (e.prefix) s.tag e.args =
495    e.args () $iter {
496      e.args : (e.arg) e.rest =
497        {
498          e.rest : v = ', ';
499          /*empty*/;
500        } :: e.comma,
501        s.tag : {
502          Vars = e.rest (e.cpp_args <Rfp2Cpp (e.arg)> e.comma);
503          Exprs = e.rest (e.cpp_args <Expr_Ref_To_CPP e.arg> e.comma);
504          Ints = e.rest (e.cpp_args <Expr_Int_To_CPP e.arg> e.comma);
505        };
506    } :: e.args (e.cpp_args),
507    e.args : /*empty*/,
508    (e.prefix) s.tag : {
509      t   Exprs = '(' e.cpp_args ')';
510      ( ) Vars  = '(' e.cpp_args ')';
511      (v) Vars  = '(' e.prefix e.cpp_args ';;)';
512      e         = e.prefix e.cpp_args;
513    };
514};
515
516Name_To_CPP s.decl_type (e.name) =
517  {
518    e.name : "org" "refal" "plus" "wrappers" e.cont =
519      <Bind &Used_Unavailable_Imports (<Lookup &Unavailable_Imports e.name>) ()>,
520      <QName_To_Cpp <Get &Module_Name> <ToWord <Intersperse ('_') e.cont>>>;
521    e.name : "refal" "plus" e.cont =
522      <Bind &Decls (s.decl_type ("refal" e.cont)) ()>,
523      <QName_To_Cpp "refal" e.cont>;
524    <Get &Current_Namespace> :: e.namespace,
525      <Bind &Decls (s.decl_type (e.name)) ()>,
526      {
527        e.name : e.namespace e.cont =
528          <QName_To_Cpp e.cont>;
529        <QName_To_Cpp e.name>;
530      };
531  };
532
533QName_To_Cpp e.name = <Intersperse ('::') e.name>;
534
535Open_Namespace e.name = ('namespace ' e.name ' {');
536Close_Namespace e.name = ('}');
537
538Namespace_Control e.qualifiers =
539  {
540    e.qualifiers : /*empty*/ = <Get &Module_Name>;
541    e.qualifiers : () = /*empty*/;
542    e.qualifiers;
543  } :: e.qualifiers,
544  {
545    <Get &Current_Namespace> : e.qualifiers;
546    <Map &Close_Namespace (<Get &Current_Namespace>)> :: e.close_namespace,
547      <Store &Current_Namespace e.qualifiers>,
548      e.close_namespace <Map &Open_Namespace (e.qualifiers)>;
549  };
550
551Trace_Enter e.name (e.args) =
552  e.args 1 () $iter {
553    e.args : t.arg e.rest =
554      {
555        \{ e.rest : v; <Gt (s.n) (1)>; } = 'printf("%2d: ", 's.n');';
556        'printf("  : ");';
557      } :: e.num,
558      e.rest <Add s.n 1>
559      (e.pr_args ('printf ("           argument "); 'e.num' ('<Rfp2Cpp t.arg>').writeln(stdout);'));
560  } :: e.args s.n (e.pr_args),
561  e.args : /*empty*/ =
562  ('printf ("+ %5u: enter >>> 'e.name' <<<\\n", rfrt::stack->get_depth());') e.pr_args;
563
564Trace_Exit e.name (e.args) =
565  e.args 1 () $iter {
566    e.args : t.arg e.rest =
567      {
568        \{ e.rest : v; <Gt (s.n) (1)>; } = 'printf("%2d: ", 's.n');';
569        'printf("  : ");';
570      } :: e.num,
571      e.rest <Add s.n 1>
572      (e.pr_args
573       ('printf ("           result   "); 'e.num' ('<Rfp2Cpp t.arg>').to_Expr().writeln(stdout);'));
574  } :: e.args s.n (e.pr_args),
575  e.args : /*empty*/ =
576  ('printf ("- %5u: exit  >>> 'e.name' <<<\\n", rfrt::stack->get_depth());') e.pr_args;
577
578Trace_Fail e.name =
579  ('printf ("- %5u: fail  >>> 'e.name' <<<\\n", rfrt::stack->get_depth());');
580
581Extract_Qualifiers t.name, {
582  <IsInTable &Externs t.name> =
583    t.name : (e.n),
584    (()) e.n;
585  <RFP_Extract_Qualifiers t.name>;
586};
587
Note: See TracBrowser for help on using the repository browser.