source: to-imperative/trunk/compiler/refal/org/refal/plus/compiler/rfp_asail_java.rf @ 3731

Last change on this file since 3731 was 3731, checked in by yura, 13 years ago
  • Static function Expr.create(Comparable) instead of constructor.
  • Property svn:eol-style set to native
  • Property svn:keywords set to Author Date Id Revision
File size: 20.2 KB
Line 
1$use Access Apply Arithm Box Class Compare Convert JavaMangle 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$use "org.refal.plus.compiler.NativeJava";
7
8$box Int;
9
10$box Module_Name;
11
12$box Entry;
13
14$box Entry_Name;
15
16$box Current_Namespace;
17
18$box Func_Name;
19
20$box Ress;
21$table Result;
22$box Res_Assigns;
23
24$table Iter_Vars;
25
26$func ASAIL_To_Java e.body = e.java_code;
27
28$func Expr_Ref_To_Java e.ASAIL_Expr_Ref = e.JAVA_Expr_Ref;
29
30$func Expr_Int_To_Java e.ASAIL_Expr_Int = e.JAVA_Expr_Int;
31
32$func Step_To_Java e.step_operators = e.java_step_operators;
33
34$func Const_Expr_To_Java e.ASAIL_const_expr = e.JAVA_const_expr;
35
36$func Expr_Args_To_Java e.args = e.java_args;
37
38$func Int_Args_To_Java e.args = e.java_args;
39
40$func Var_Args_To_Java e.args = e.java_args;
41
42$func Symbol_To_Java s.RFP_Symbol = e.JAVA_String;
43
44$func Name_To_Java t.name = e.JAVA_Name;
45
46$func Var_To_Java t.var = e.java_var;
47
48$func Cond_To_Java s.acc t.cond = e.JAVA_Cond;
49
50$func Infix_To_Java s.func_for_converting_args_to_java s.op e.args = e.java_expr;
51
52$func Access_Mode s.linkage = e.java_access_mode;
53$func WrapGen s.linkage s.tag t.qname (e.in) (e.out) e.native = e.java_code;
54
55$box Free_Idx;
56
57$func Free_Index = e.free_index;
58
59$func Declare_Results (e.ress) e.acc_java_ress = e.decls (e.java_ress);
60
61
62
63RFP_ASAIL_To_Java (MODULE (e.moduleName) e.asail) =
64  <Store &Free_Idx>,
65  <ClearTable &Iter_Vars>,
66  {
67    <Store &Int <Lookup &RFP_Options INT>>;
68    <Store &Int BigInteger>;
69  },
70  <Store &Current_Namespace e.moduleName>,
71  {
72    <Store &Entry <Lookup &RFP_Options ENTRIES>>;
73    <Store &Entry (e.moduleName Main)>;
74  },
75  <Store &Entry_Name /*empty*/>,
76  <ToWord <Intersperse ('.') e.moduleName>> :: s.refal_mod_name,
77  <Store &Module_Name s.refal_mod_name>,
78  {
79    <ASAIL_To_Java e.asail> : v.java,
80      e.moduleName : e.package s.class,
81      {
82        e.package : v = ('package '<Intersperse ('.') e.package>';');;
83      } :: e.package,
84      {
85        <Get &Entry_Name> : (e s.name) =
86          ()
87          ('public static void main (final java.lang.String[] args) {' (
88            ('new Thread('
89              ('new Runnable() {'(
90                ('public void run () {'(
91                  ('RefalRuntime.setArgs ("'s.refal_mod_name'", args);')
92                  ('try {' (s.name' (new Result ());')
93                  )'} catch (RefalException e) {'(
94                    ('java.lang.System.out.println ("$error: " + e);')
95                    ('java.lang.System.exit (100);')
96                  )'}')
97                )'}')
98              '}).start();')
99            )
100          )'}');;
101      } :: e.entry,
102      e.package ('import org.refal.plus.*;')('public class 's.class' {' (v.java e.entry) '}');;
103  } :: e.java,
104  (e.moduleName) (e.java);
105
106$func ReplaceQuotes s = s;
107
108ReplaceQuotes s.expr =
109  (<ToChars s.expr>) $iter {
110    e.expr : e.head '\'' e.tail = e.items e.head '\\\'' (e.tail);
111    e.items e.expr ();
112  } :: e.items (e.expr), e.expr : /*empty*/ =
113  (e.items) $iter {
114    e.expr : e.head '\"' e.tail = e.items e.head '\\\"' (e.tail);
115    e.items e.expr ();
116  } :: e.items (e.expr), e.expr : /*empty*/ =
117  <ToWord e.items>;
118
119ASAIL_To_Java e.asail, {
120  e.asail : t.item e.rest, t.item : {
121    (s.tag IMPORT e) = /*empty*/;
122    (LINENUMBER sN) = /*empty*/;
123    (NATIVE s.linkage s.tag t.qname (e.in) (e.out) e.native) = <WrapGen s.linkage s.tag t.qname (e.in) (e.out) e.native>;
124    (s.tag s.linkage t.name (e.args) (e.ress) e.body),
125      s.tag : \{
126        FUNC  = ('void') /*empty*/;
127        TFUNC  = ('void') /*empty*/;
128        "FUNC?" = ('boolean') ('return true;');
129      } :: (e.return_type) e.return =
130      <Store &Ress e.ress>,
131      <ClearTable &Result>,
132      { <Get &Entry> : e t.name e = <Store &Entry_Name t.name>;; },
133      <Store &Func_Name <Name_To_Java t.name>>,
134      { ('@RefalFormat("'<ReplaceQuotes <PrintFunctionFormat t.name>>'")');; } :: e.refalFormat,
135      ()
136      e.refalFormat
137      ('static '<Access_Mode s.linkage>' 'e.return_type' '
138      <Get &Func_Name>' ('<Var_Args_To_Java Expr e.args Result e.ress>') throws RefalException')
139      ('{' (<ASAIL_To_Java e.body> e.return) '}');
140    (TRACE t.name) =
141      <Bind &RFP_Trace (t.name) ()>;
142    ("IF-INT-CMP" s.op (e.arg1) (e.arg2) e.body) =
143      <Expr_Int_To_Java e.arg1> ' 's.op' ' <Expr_Int_To_Java e.arg2> :: e.cond,
144      ('if (' e.cond ')')
145      ('{' (<ASAIL_To_Java e.body>) '}');
146    (IF t.cond e.body) =
147      <Box> :: s.acc,
148      <Cond_To_Java s.acc t.cond> :: e.j_cond,
149      {
150        t.cond : ("CALL-FAILS" e) =
151          () (<Get &Res_Assigns> <Store &Res_Assigns /*empty*/>);
152        (<Get &Res_Assigns> <Store &Res_Assigns /*empty*/>) ();
153      } :: (e.if_yes_assigns) (e.if_not_assigns),
154      <Get s.acc>
155      ('if ('e.j_cond')')
156      ('{' (
157      e.if_yes_assigns
158      <ASAIL_To_Java e.body>
159      )'}' )
160      e.if_not_assigns;
161    (FOR (e.cont_label) (e.break_label) () (e.step) e.body) =
162      {
163        e.cont_label : t = <Rfp2Java (LABEL e.cont_label)> ': ';;
164      } :: e.cont,
165      {
166        e.break_label : t = <Rfp2Java (LABEL e.break_label)> ': ';;
167      } :: e.break,
168      {
169        e.step : (s.d e.var), s.d : \{ "INC-ITER"; "DEC-ITER"; } =
170          <Lookup &Iter_Vars e.var> : e.new_var t.var1 t.var2,
171          ('Expr '<Rfp2Java t.var1>' = 'e.new_var'.getLeft();')
172          ('Expr '<Rfp2Java t.var2>' = 'e.new_var'.getRight();');;
173      } :: e.split_vars,
174      (e.break e.cont 'for ( ; ; '<Step_To_Java e.step>')')
175      ('{' (
176      e.split_vars <Get &Res_Assigns> <Store &Res_Assigns /*empty*/>
177      <ASAIL_To_Java e.body>
178      ) '}');
179    (LABEL (e.label) e.body) =
180      (<Rfp2Java (LABEL e.label)>': {' (<ASAIL_To_Java e.body>) '}');
181    (TRY e.body) =
182      ('try') ('{' (
183      ('if (false)'
184      ('throw new RefalException ("'<Get &Module_Name>'", "'<Get &Func_Name>'", '
185      '"This is for avoiding \'Unreachable code\' errors");'
186      )   )
187      <ASAIL_To_Java e.body>
188      ) '}');
189    ("CATCH-ERROR" e.body) =
190      ('catch (RefalException error) {' (
191      ('Expr err = error.getExpr ();')
192      (<ASAIL_To_Java e.body>)
193      ) '}');
194    RETFAIL = ('return false;');
195    FATAL =
196      ('throw new RefalException ("'<Get &Module_Name>'", "'<Get &Func_Name>'", "Unexpected fail");');
197    (LSPLIT t.name (e.min) t.var1 t.var2) =
198      <Expr_Ref_To_Java t.name> :: e.n,
199      '_va_' <Free_Index> :: e.new_var,
200      <Bind &Iter_Vars (t.name) (e.new_var t.var1 t.var2)>,
201      <Expr_Int_To_Java e.min> :: e.min,
202      ('Expr.SplitIterator 'e.new_var' = 'e.n'.leftSplit('e.min');');
203    (RSPLIT t.name (e.min) t.var1 t.var2) =
204      <Expr_Ref_To_Java t.name> :: e.n,
205      '_va_' <Free_Index> :: e.new_var,
206      <Bind &Iter_Vars (t.name) (e.new_var t.var1 t.var2)>,
207      <Expr_Int_To_Java e.min> :: e.min,
208      ('Expr.SplitIterator 'e.new_var' = 'e.n'.rightSplit('e.min');');
209    (DECL (INT t.var) e.expr) = ('int '<Rfp2Java t.var>' = '<Expr_Int_To_Java e.expr>';');
210    (ASSIGN (INT t.var) e.expr) =
211      (<Rfp2Java t.var>' = '<Expr_Int_To_Java e.expr>';');
212    (DECL s.type t.var e.expr) =
213      <Rfp2Java t.var> :: e.j_var,
214      <Expr_Ref_To_Java e.expr> :: e.j_expr,
215      {
216        s.type : Result =
217          <Bind &Result (t.var) (e.j_var)>,
218          ('Result 'e.j_var' = new Result ('e.j_expr');');
219        <Unbind &Result t.var>,
220          ('Expr 'e.j_var' = 'e.j_expr';');
221      };
222    (ASSIGN t.var e.expr) =
223      <Expr_Ref_To_Java e.expr> :: e.j_expr,
224      {
225        <Get &Ress> : e t.var e =
226          (<Rfp2Java t.var>'.assign ('e.j_expr');');
227        (<Lookup &Result t.var>'.assign ('e.j_expr');');
228        (<Rfp2Java t.var>' = 'e.j_expr';');
229      };
230    (DROP t.var) =
231      (<Var_To_Java t.var>'.drop ();');
232    (CONTINUE t.label) =
233      ('continue '<Rfp2Java (LABEL t.label)>';');
234    (BREAK t.label) =
235      ('break '<Rfp2Java (LABEL t.label)>';');
236    (ERROR e.expr) =
237      ('throw new RefalException ('<Expr_Ref_To_Java e.expr>');');
238    (CONSTEXPR s.linkage t.name (e.comment) e.expr),
239      {
240        t.name : (STATIC e) = <Rfp2Java t.name>;
241        <Name_To_Java t.name>;
242      } :: e.n,
243      <Const_Expr_To_Java e.expr> :: e.j_expr,
244      { ('@RefalFormat("'<ReplaceQuotes <PrintConstDefinition t.name>>'")');; } :: e.refalDecl,
245      e.refalDecl
246      ('static '<Access_Mode s.linkage>' final Expr 'e.n' = 'e.j_expr';');
247    (OBJ s.linkage s.tag t.name) =
248      <ToChars s.tag> : s1 e2,
249      s1 <ToLower e2> :: e.class_name,
250      t.name :  (e s.n),
251      { ('@RefalFormat("'<ReplaceQuotes <PrintObjectDefinition t.name>>'")');; } :: e.refalDecl,
252      e.refalDecl
253      ('static '<Access_Mode s.linkage>' final Expr '<Name_To_Java t.name>
254      ' = Expr.create (Symbol.new'e.class_name' ("'s.n'"));');
255    ("DECL-OBJ" t.name) = ;
256    ("DECL-FUNC" t.name) = ;
257    /*
258    * s.call can be CALL or TAILCALL or TAILCALL?
259    */
260    (s.call t.name (e.args) (e.ress)) =
261      <Declare_Results (e.ress)> :: e.decls (e.ress),
262      <Expr_Args_To_Java e.args Result e.ress> :: e.args,
263      <Name_To_Java t.name>' ('e.args')' :: e.c,
264      {
265        s.call : "TAILCALL?" =
266          e.decls ('if (!'e.c') {' ('return false;') '}');
267        e.decls (e.c';') <Get &Res_Assigns>
268          <Store &Res_Assigns /*empty*/>;
269      };
270  } :: e.java_item,
271    {
272      e.java_item : ('break ' e) = e.java_item;
273      e.java_item <ASAIL_To_Java e.rest>;
274    };
275  /*empty*/;
276};
277
278Declare_Results {
279  (t.var e.r) e.ress, {
280    <IsInTable &Result t.var> = <Declare_Results (e.r) e.ress (<Rfp2Java t.var>)>;
281    <Get &Ress> : e t.var e     = <Declare_Results (e.r) e.ress (<Rfp2Java t.var>)>;
282    '_va_' <Free_Index> :: e.new_var,
283      <Put &Res_Assigns (<Rfp2Java t.var>' = 'e.new_var'.getExpr ();')> =
284      ('Result 'e.new_var' = new Result ();') <Declare_Results (e.r) e.ress (e.new_var)>;
285  };
286  () e.ress = (e.ress);
287};
288
289
290$func ToRight (e.term) = '.toRight ('e.term')';
291ToRight (e.term) = '.toRight ('e.term')';
292
293$func Term_Ref_To_Java term = (e.j_term);
294
295Expr_Ref_To_Java {
296  /*empty*/ = 'Expr.empty';
297  (PAREN e.expr) =
298    'Expr.create ('<Expr_Ref_To_Java e.expr>')';
299  term =
300    <Term_Ref_To_Java term> :: (e.term),
301    e.term;
302  t1 t2 =
303    <Term_Ref_To_Java t1> :: (e.t1),
304    <Term_Ref_To_Java t2> :: (e.t2),
305    'Expr.concat ('e.t1', 'e.t2')';
306  expr =
307    'Expr.getConcatenator ()' <Map &ToRight (<Map &Term_Ref_To_Java (expr)>)> '.yield ()';
308};
309
310Term_Ref_To_Java term = term : {
311  (PAREN e.expr) =
312    ('(Comparable<?>) '<Expr_Ref_To_Java e.expr>);
313  (DEREF e.expr (e.pos)) =
314    ('(Expr) '<Expr_Ref_To_Java e.expr>'.at ('<Expr_Int_To_Java e.pos>')');
315  (SUBEXPR e.expr (e.pos) (e.len)) =
316    (<Expr_Ref_To_Java e.expr>'.subexpr ('<Expr_Int_To_Java e.pos>', '<Expr_Int_To_Java e.len>')');
317  (REF t.name) = (<Name_To_Java t.name>);
318  "ERROR-EXPR" = ('err');
319  (s.var_tag e.ns t.name) = (<Var_To_Java term>);
320};
321
322Expr_Int_To_Java {
323//  /*empty*/ = /*empty*/;
324  s.ObjectSymbol =
325    {
326      <IsInt s.ObjectSymbol> = s.ObjectSymbol;
327      $error ("Illegal int-symbol: " s.ObjectSymbol);
328        //FIXME: It is needed to check that
329        //       s.ObjectSymbol is less than 2^31 or another limit.
330        //           Set this limit in option.
331    };
332  (LENGTH e.expr) =
333    <Expr_Ref_To_Java e.expr>'.length ()';
334  (MAX e.args) =
335    'java.lang.Math.max ('<Int_Args_To_Java e.args>')';
336  (MIN e.args) =
337    'java.lang.Math.min ('<Int_Args_To_Java e.args>')';
338  (INFIX s.op e.args) =
339    '(' <Infix_To_Java &Expr_Int_To_Java s.op e.args> ')';
340//  (REF t.name) = <Name-To-Java t.name>;
341  (INT t.var) = <Rfp2Java t.var>;
342  expr = '(' <Infix_To_Java &Expr_Int_To_Java "+" <Paren expr>> ')';
343};
344
345Cond_To_Java s.acc t.cond = t.cond : {
346  ("CALL-FAILS" (CALL t.name (e.exprs) (e.ress))) =
347    <Declare_Results (e.ress)> :: e.decls (e.ress),
348    <Expr_Args_To_Java e.exprs Result e.ress> :: e.args,
349    <Put s.acc e.decls>,
350    '!'<Name_To_Java t.name>' ('e.args')';
351  ("ITER-FAILS" e.expr) =
352    '!'<Middle 0 2 <Lookup &Iter_Vars e.expr>>'.isValid ()';
353  ("SYMBOL?" e.expr (e.pos)) =
354    <Expr_Ref_To_Java e.expr>'.isSymbolAt ('<Expr_Int_To_Java e.pos>')';
355  (EQ e.expr1 (e.expr2) (e.pos)) =
356    <Expr_Ref_To_Java e.expr1> :: e.j_expr1,
357    <Expr_Ref_To_Java e.expr2> :: e.j_expr2,
358    e.j_expr1'.equals ('e.j_expr2', '<Expr_Int_To_Java e.pos>')';
359  ("TERM-EQ" e.expr1 (e.expr2) (e.pos)) =
360    <Expr_Ref_To_Java e.expr1> :: e.j_expr1,
361    <Expr_Ref_To_Java e.expr2> :: e.j_expr2,
362    e.j_expr1'.termEquals ('e.j_expr2', '<Expr_Int_To_Java e.pos> ')';
363  (NOT t.not_cond) =
364    '!' <Cond_To_Java s.acc t.not_cond>;
365};
366
367Infix_To_Java s.arg2java s.op e.args, {
368  e.args : (e.arg) e.rest =
369    <Apply s.arg2java e.arg> :: e.arg,
370    <Infix_To_Java s.arg2java s.op e.rest> :: e.rest,
371    {
372      e.arg : v, e.rest : v = e.arg ' ' s.op ' ' e.rest;
373      e.arg e.rest;
374    };;
375};
376
377Step_To_Java {
378  /*empty*/ = /*empty*/;
379  ("INC-ITER" e.expr) = <Middle 0 2 <Lookup &Iter_Vars e.expr>>'.next ()';
380  ("DEC-ITER" e.expr) = <Middle 0 2 <Lookup &Iter_Vars e.expr>>'.prev ()';
381};
382
383$func Const_Expr_Aux (e.accum) e.expr = e.java_expr;
384
385Const_Expr_To_Java {
386  /*empty*/ = 'Expr.empty';
387  (SUBEXPR t.name s.pos s.len) = <Rfp2Java t.name>'.subexpr ('s.pos', 's.len')';
388                  //FIXME: It is needed to check that
389                  //       s.pos and s.len is less than 2^31 or another limit.
390                  //         Set this limit in option.
391  e.expr =
392    <Const_Expr_Aux () e.expr> : {
393      (e1) = {
394        e1 : \{
395          '(Comparable<?>)' e;
396          'Symbol.new' e;
397        } =
398          'Expr.create ('e1')';
399        e1;
400      };
401      (e1) (e2) = 'Expr.concat ('e1', 'e2')';
402      e.concat  = 'Expr.getConcatenator ('<Length e.expr>')' <Map &ToRight (e.concat)> '.yield ()';
403    };
404};
405
406Const_Expr_Aux (e.accum) e.expr, {
407  e.expr : s.sym e.rest, <IsChar s.sym> =
408    <Const_Expr_Aux (e.accum <Symbol_To_Java s.sym>) e.rest>;
409  e.accum : v =
410    <Const_Expr_Aux () e.expr> :: e.j_expr,
411    ('Expr.fromSequence ("'e.accum'")') e.j_expr;
412  e.expr : t.item e.rest, t.item : {
413    (PAREN e.paren_expr) =
414      ('(Comparable<?>) '<Const_Expr_To_Java e.paren_expr>);
415    (REF t.name) =
416      (<Name_To_Java t.name>);
417    (STATIC e) =
418      (<Rfp2Java t.item>);
419    ("FUNC?" t.name) =
420      ('Symbol.newFunc("'<Name_To_Java t.name>'", new Func () {'
421        ('public boolean eval (Expr arg, Result res) throws RefalException {'
422          ('return '<Name_To_Java t.name>' (arg, res);')
423        '}')
424      '})');
425    (s.FUNC t.name), s.FUNC : \{ FUNC; TFUNC; } =
426      ('Symbol.newFunc("'<Name_To_Java t.name>'", new Func () {'
427        ('public boolean eval (Expr arg, Result res) throws RefalException {'
428          ((<Name_To_Java t.name>' (arg, res);')('return true;'))
429        '}')
430      '})');
431    s.sym, {
432      <IsInt s.sym> =
433        ('Symbol.newInt ("'s.sym'")');
434      <IsWord s.sym> =
435        ('Symbol.newWord ("'<Symbol_To_Java s.sym>'")');
436    };
437  } :: e.java_item =
438    e.java_item <Const_Expr_Aux () e.rest>;
439  = /*empty*/;
440};
441
442Symbol_To_Java s.ObjectSymbol, {
443  <ToChars s.ObjectSymbol> () $iter {
444    e.symbol : s.char e.rest, s.char : {
445      '\\' = '\\\\';
446      '\n' = '\\n';
447      '\t' = '\\t';
448//        '\v' = '\\v';
449//        '\b' = '\\b';
450      '\r' = '\\r';
451//        '\f' = '\\f';
452      '\"' = '\\"';
453//      '\'' = '\\\'';
454      s = s.char;
455    } :: e.java_char,
456    e.rest (e.java_symbol e.java_char);
457  } :: e.symbol (e.java_symbol),
458    e.symbol : /*empty*/ =
459    e.java_symbol;
460};
461
462Int_Args_To_Java e.args =
463  e.args (/*e.java-args*/) $iter {
464    e.args : (e.arg) e.rest =
465      {
466        e.rest : v = ', ';
467        /*empty*/;
468      } :: e.comma,
469      e.rest (e.java_args <Expr_Int_To_Java e.arg> e.comma);
470    } :: e.args (e.java_args),
471  e.args : /*empty*/ =
472  e.java_args;
473
474Var_Args_To_Java e.args =
475  e.args (/*e.type*/) (/*e.java-args*/) $iter {
476    e.args : s.t e.rest =
477      e.rest (s.t) (e.java_args);
478    e.args : t.arg e.rest =
479      {
480        e.rest : e (e) e = ', ';
481        /*empty*/;
482      } :: e.comma,
483      e.rest (e.type) (e.java_args e.type' '<Rfp2Java t.arg> e.comma);
484    } :: e.args (e.type) (e.java_args),
485  e.args : /*empty*/ =
486  e.java_args;
487
488Expr_Args_To_Java e.args =
489  e.args (/*e.type*/) (/*e.java-args*/) $iter {
490    e.args : s.t e.rest =
491      e.rest (s.t) (e.java_args);
492    e.args : (e.arg) e.rest =
493      {
494        e.rest : e (e) e = ', ';
495        /*empty*/;
496      } :: e.comma,
497      {
498        e.type : /*empty*/ =
499          e.rest (e.type) (e.java_args <Expr_Ref_To_Java e.arg> e.comma);
500        e.rest (e.type) (e.java_args e.arg e.comma);
501      };
502  } :: e.args (e.type) (e.java_args),
503  e.args : /*empty*/ =
504  e.java_args;
505
506Name_To_Java (e.obj_name) =
507  <Get &Current_Namespace> :: e.namespace,
508  {
509    e.obj_name : e.namespace e.cont = e.cont;
510    e.obj_name;
511  } :: e.name,
512  <ToWord <Intersperse ('.') e.name>>;
513
514Var_To_Java t.var = {
515  <Lookup &Result t.var>'.getExpr ()';
516  <Rfp2Java t.var>;
517};
518
519Access_Mode {
520  EXPORT = 'public';
521  s = ;
522};
523
524Free_Index =
525  <Get &Free_Idx> : {
526    /*empty*/ = 1;
527    s.idx     = <Add s.idx 1>;
528  } :: s.idx,
529  <Store &Free_Idx s.idx>,
530  s.idx;
531
532$func ConvertTo t.javaType t.var = e;
533ConvertTo s.javaType t.var,
534  t.var s.javaType : {
535    \{
536      (SVAR e) "boolean" = "toBoolean";
537      (SVAR e) "char"    = "toChar";
538      (SVAR e) "byte"    = "toByte";
539      (SVAR e) "short"   = "toShort";
540      (SVAR e) "int"     = "toInt";
541      (SVAR e) "long"    = "toLong";
542      (EVAR e) "boolean[]" = "toBooleanArray";
543      (EVAR e) "char[]"    = "toCharArray";
544      (EVAR e) "byte[]"    = "toByteArray";
545      (EVAR e) "short[]"   = "toShortArray";
546      (EVAR e) "int[]"     = "toIntArray";
547      (EVAR e) "long[]"    = "toLongArray";
548    } :: s.methodName,
549      'Native.'s.methodName'('<Rfp2Java t.var>')';
550    (SVAR e) s =
551      '(('s.javaType') Native.objectValue('<Rfp2Java t.var>'))';
552    (EVAR e) s =
553      <ToChars s.javaType> : e.javaElemType '[]', <ToWord e.javaElemType> :: s.javaElemType =
554      '(('s.javaType') Native.objectArrayValue('<Rfp2Java t.var>', new 's.javaElemType'['<Rfp2Java t.var>'.length()]))';
555  };
556
557$func ConvertFrom t.var s.javaType e.arg = e;
558ConvertFrom (s.refType e) s.javaType e.arg,
559  s.refType <ToChars s.javaType> : {
560    SVAR e '[]' = '(Object) ';
561    SVAR e      = ;
562    EVAR e '[]' = ;
563  } :: e.type,
564  'Native.toExpr('e.type e.arg')';
565
566WrapGen s.linkage FUNC t.qname (e.in) (e.out) e.native =
567  { <Get &Entry> : e t.qname e = <Store &Entry_Name t.qname>;; },
568  <DeclarationReader <ToWord e.native>> :: s.static s.javaResType s.className s.methodName e.javaArgTypes,
569  { ('@RefalFormat("'<ReplaceQuotes <PrintFunctionFormat t.qname>>'")');; } :: e.refalFormat,
570  <Del_Pragmas <Gener_Var_Indices 1 (<Vars e.in>) 'arg'>> : e.rfArgs s,
571  <Del_Pragmas <Gener_Var_Indices 1 (<Vars e.out>) 'res'>> : e.rfRes s,
572  {
573    s.methodName : "" = 'new ' s.className 0;
574    s.static : "" = <ConvertTo s.className <L 0 e.rfArgs>> '.' s.methodName 1;
575    s.className '.' s.methodName 0;
576  } :: e.funcHead s.shift,
577  {
578    e.javaArgTypes : (e.javaArgTypes2) =
579      <Middle s.shift 0 e.rfArgs> :: e.rfArgs,     
580      0 $iter {
581        {e.args : /**/ = /**/; ', ';} :: e.comma,
582          e.args e.comma <ConvertTo <L s.num e.javaArgTypes2> <L s.num e.rfArgs>> <Add s.num 1>;
583      } :: e.args s.num,
584      <Length e.javaArgTypes2> : s.num = e.funcHead '(' e.args ')';
585    e.funcHead;
586  } :: e.funcCall,
587  e.rfRes : {
588    /**/ = e.funcCall';';
589    t.rfResType, (<Rfp2Java e.rfRes>'.assign('<ConvertFrom t.rfResType s.javaResType e.funcCall>');');
590  } :: e.body =
591  ()
592  e.refalFormat
593  ('static '<Access_Mode s.linkage>' void ' <Name_To_Java t.qname>' ('<Var_Args_To_Java Expr e.rfArgs Result e.rfRes>') throws RefalException {'
594  ('try {' (e.body) '} catch (java.lang.Exception e) {' ('throw new org.refal.plus.RefalException("'<Get &Module_Name>'", "'<Name_To_Java t.qname>'", e.toString());')'}')
595  '}' );
596/*
597  {
598    e.javaArgTypes : e.head s.javaArgType e,
599      <PutArgToStack <ConvertType s.javaArgType> e.rfArgTypes <Add s.shift <Length e.head>>>, $fail;;
600  },
601  <ToWord "(" <Map &ConvertType (e.javaArgTypes)> ")" <ConvertResType s.javaResType>> :: s.methodDesc,
602  <MVvisitMethodInsn <MV> s.opcode s.className s.methodName s.methodDesc>,
603  {
604    s.methodName : "" = s.className;
605    s.javaResType;
606  } :: s.javaResType,   
607  <GetResFromStack <ConvertType s.javaResType> e.rfResTypes <Length e.rfArgTypes>>,
608  s.tag : {
609    FUNC  = <MVvisitInsn <MV> &RETURN>;
610    "FUNC?" = <MVvisitInsn <MV> &ICONST_1> <MVvisitInsn <MV> &IRETURN>;
611  },
612  <MVvisitMaxs <MV> 0 0>,
613  <MVvisitEnd <MV>>,
614  { <Get &Entry> : e t.qname e = <Store &EntryName s.functionName>;; };*/
Note: See TracBrowser for help on using the repository browser.