Changeset 2725


Ignore:
Timestamp:
Apr 21, 2007, 12:14:54 AM (14 years ago)
Author:
yura
Message:
 
File:
1 edited

Legend:

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

    r2724 r2725  
    1919
    2020$box Entry;
    21 $box Entry_Name;
    22 
    23 $box Func_Name;
    24 
    25 $func Module_To_JBC s.cw e.module = ;
    26 
    27 $func ASAIL_To_JBC e.body = ;
     21$box EntryName;
     22
     23$box FuncName;
     24
     25$func Module_To_JBC e.module = ;
     26
     27$func Module_Item_To_JBC t.item = ;
     28
     29$func Body_To_JBC e.body = ;
     30
     31$func Body_Item_To_JBC t.item = ;
    2832
    2933$func Expr_Ref_To_JBC e.ASAIL_Expr_Ref = ;
     
    6064
    6165$box MVbox;
    62 
    6366$func MV = s;
    64 
    6567MV, <Get &MVbox> : s.mv = s.mv;
     68
     69$box CWbox;
     70$func CW = s;
     71CW, <Get &CWbox> : s.cv = s.cv;
    6672
    6773RFP_ASAIL_To_JBC (MODULE (e.moduleName) e.module) =
     
    7379    <Store &Entry (e.moduleName Main)>;
    7480  },
    75   <Store &Entry_Name /*empty*/>,
     81  <Store &EntryName /*empty*/>,
    7682  <Store &Module_Name e.moduleName>,
    7783  <ToWord <Intersperse ('.') e.moduleName>> :: s.refal_mod_name,
     
    7985  <ToWord <Intersperse ('/') e.moduleName>> :: s.class_name,
    8086  <Store &Class_Name s.class_name>,
    81   <ClassWriter &COMPUTE_MAXS> :: s.cw,
    82   <CWvisit s.cw &V1_4 &ACC_PUBLIC s.class_name <Null> "java/lang/Object" ()>,
    83   <Module_To_JBC s.cw e.module>,
     87  <Store &CWbox <ClassWriter &COMPUTE_MAXS>>,
     88  <CWvisit <CW> &V1_4 &ACC_PUBLIC s.class_name <Null> "java/lang/Object" ()>,
     89  <Module_To_JBC e.module>,
    8490  {
    85     <Get &Entry_Name> : s.name =
    86       /*<ASAIL-To-JBC-Temp s.cw e.module> : e,
     91    <Get &EntryName> : s.name =
     92      /*<ASAIL-To-JBC-Temp <CW> e.module> : e,
    8793      ()
    8894          ('public static void main (java.lang.String[] args) {' (
     
    95101          )'}');;
    96102      } :: e.entry,*/
    97       <Store &MVbox <CWvisitMethod s.cw <Add &ACC_PUBLIC &ACC_STATIC> "main" "([Ljava/lang/String;)V" <Null> ()>>,
     103      <Store &MVbox <CWvisitMethod <CW> <Add &ACC_PUBLIC &ACC_STATIC> "main" "([Ljava/lang/String;)V" <Null> ()>>,
    98104      <MVvisitLdcInsn <MV> <WordToString s.refal_mod_name>>,
    99105      <MVvisitVarInsn <MV> &ALOAD 0>,
     
    107113      <MVvisitEnd <MV>>;;
    108114  },
    109   <Store &MVbox <CWvisitMethod s.cw &ACC_STATIC "<clinit>" "()V" <Null> ()>>,
     115  <Store &MVbox <CWvisitMethod <CW> &ACC_STATIC "<clinit>" "()V" <Null> ()>>,
    110116  {
    111117    <Get &Objects> : e (s.tag s.name) e,
     
    132138  //{
    133139  //  <? &Func-Refs> : e (s.cl-name s.mod-name s.func-name) e,
    134   //    <CWvisitInnerClass s.cw s.cl-name <Null> <Null> &"ACC_STATIC">,
     140  //    <CWvisitInnerClass <CW> s.cl-name <Null> <Null> &"ACC_STATIC">,
    135141  //    $fail;;
    136142  //},
    137   <CWvisitEnd s.cw>,
    138   <Box (<CWtoByteArray s.cw> e.moduleName)> :: s.res,
     143  <CWvisitEnd <CW>>,
     144  <Box (<CWtoByteArray <CW>> e.moduleName)> :: s.res,
    139145  {
    140146    <Get &Func_Refs> : e (s.cl_name s.mod_name s.func_name s.type) e,
     
    270276    <Replicate <Length e.ress> "Lorg/refal/plus/Result;">')' s.retType>;
    271277
    272 Module_To_JBC s.cw e.module, {
    273   e.module : e t.item e, t.item : {
    274     (s.tag IMPORT e) = /*empty*/;
    275     (s.tag s.linkage t.name (e.args) (e.ress) e.body),
    276       s.tag : \{
    277         FUNC  = 'V';
    278         "FUNC?" = 'Z';
    279       } : s.retType =
    280       <Init_Block_Table>,
    281       <Bind_Vars Expr e.args>,
    282       <Bind_Vars Result e.ress>,
    283       <Add &ACC_STATIC <Access_Mode s.linkage>> :: s.accessMode,
    284       t.name : (e s.funcName),
    285       <Store &Func_Name s.funcName>,
    286       <GetJBCName s.funcName> :: s.funcName,
    287       { <Get &Entry> : e t.name e = <Store &Entry_Name s.funcName>;; },
    288       <Function_Description (e.args) (e.ress) s.retType> :: s.desc,
    289       <Store &MVbox <CWvisitMethod s.cw s.accessMode s.funcName s.desc <Null> ("org/refal/plus/RefalException")>>,
    290       {
    291         <PrintFunctionFormat t.name> :: s.format =
    292           <MVvisitAnnotation <MV> "Lorg/refal/plus/RefalFormat;" False> :: s.aw,
    293           <AnnotationVisitor.visit s.aw "value" <WordToString s.format>>,
    294           <AnnotationVisitor.visitEnd s.aw>;;
    295       },
    296       <ASAIL_To_JBC e.body>,
    297       s.tag : {
    298         FUNC  = <MVvisitInsn <MV> &RETURN>;
    299         "FUNC?" = <MVvisitInsn <MV> &ICONST_1> <MVvisitInsn <MV> &IRETURN>;
    300       },
    301       <MVvisitMaxs <MV> 0 0>,
    302       <MVvisitEnd <MV>>;
    303     (CONSTEXPR s.linkage t.qname (e.comment) e.expr) =
    304       t.qname : {
    305         (STATIC (e)) = <GetJBCName t.qname>;
    306         (e s.name) = s.name;
    307       } :: s.name,
    308       <Add &ACC_FINAL <Add &ACC_STATIC <Access_Mode s.linkage>>> :: s.access,
    309       <CWvisitField s.cw s.access s.name "Lorg/refal/plus/Expr;" <Null> <Null>> :: s.fv,
    310       {
    311         <PrintConstDefinition t.qname> :: s.def =
    312           <FVvisitAnnotation s.fv "Lorg/refal/plus/RefalFormat;" False> :: s.aw,
    313           <AnnotationVisitor.visit s.aw "value" <WordToString s.def>>,
    314           <AnnotationVisitor.visitEnd s.aw>;;
    315       },
    316       <FVvisitEnd s.fv>,
    317       <Put &Constants (s.name e.expr)>;
    318     (OBJ s.linkage s.tag t.qname) =
    319       t.qname : (e s.name),
    320       <Add &ACC_FINAL <Add &ACC_STATIC <Access_Mode s.linkage>>> :: s.access,
    321       <CWvisitField s.cw s.access s.name "Lorg/refal/plus/Expr;" <Null> <Null>> :: s.fv,
    322       {
    323         <PrintObjectDefinition t.qname> :: s.def =
    324           <FVvisitAnnotation s.fv "Lorg/refal/plus/RefalFormat;" False> :: s.aw,
    325           <AnnotationVisitor.visit s.aw "value" <WordToString s.def>>,
    326           <AnnotationVisitor.visitEnd s.aw>;;
    327       },
    328       <FVvisitEnd s.fv>,
    329       <Put &Objects (s.tag s.name)>;
    330     ("DECL-OBJ" t.name) = ;
    331     ("DECL-FUNC" t.name) = ;
    332     (TRACE t.name) =
    333       <Bind &RFP_Trace (t.name) ()>;
    334   },
    335     $fail;;
    336 };
    337 
    338 ASAIL_To_JBC {
    339   e t.item e, /*<WriteLN> <WriteLN t.item>*/ t.item : {
    340     (DECL (INT t.var)) =
    341       <Bind_Var Int t.var> :: s;
    342     (DECL s.type t.var) =
    343       <Bind_Var s.type t.var> :: s.i,
    344       s.type : {
    345         Result =
    346           <MVvisitTypeInsn <MV> &NEW "org/refal/plus/Result">,
    347           <MVvisitInsn <MV> &DUP>,
    348           <MVvisitMethodInsn <MV> &INVOKESPECIAL "org/refal/plus/Result" "<init>" "()V">,
    349           <MVvisitVarInsn <MV> &ASTORE s.i>;
    350         Expr =
    351           <MVvisitFieldInsn <MV> &GETSTATIC "org/refal/plus/Expr" "empty" "Lorg/refal/plus/Expr;">,
    352           <MVvisitVarInsn <MV> &ASTORE s.i>;
    353       };
    354     (ASSIGN (INT t.var) e.expr) =
    355       <Lookup_Var t.var> :: s s.i,
    356       <Expr_Int_To_JBC e.expr>,
    357       <MVvisitVarInsn <MV> &ISTORE s.i>;
    358     (ASSIGN t.var e.expr) =
    359       <Lookup_Var t.var> :: s.type s.i,
    360       s.type : {
    361         Result =
    362           <MVvisitVarInsn <MV> &ALOAD s.i>,
    363           <Expr_Ref_To_JBC e.expr>,
    364           <MVvisitMethodInsn <MV> &INVOKEVIRTUAL "org/refal/plus/Result" "assign" "(Lorg/refal/plus/Expr;)V">;
    365         Expr =
    366           <Expr_Ref_To_JBC e.expr>,
    367           <MVvisitVarInsn <MV> &ASTORE s.i>;
    368       };
    369     ("IF-INT-CMP" s.op (e.arg1) (e.arg2) e.body) =
    370       <Push_Block_Table>,
    371       <Label> :: s.label,
    372       <Expr_Int_To_JBC e.arg1>,
    373       <Expr_Int_To_JBC e.arg2>,
    374       s.op : {
    375         "!=" = &IF_ICMPEQ;
    376         "<" = &IF_ICMPGE;
    377         ">" = &IF_ICMPLE;
    378       } :: s.op,
    379       <MVvisitJumpInsn <MV> s.op s.label>,
    380       <ASAIL_To_JBC e.body>,
    381       <MVvisitLabel <MV> s.label>,
    382       <Pop_Block_Table>;
    383     (IF t.cond e.body) =
    384       <Push_Block_Table>,
    385       <Label> :: s.label,
    386       <Cond_To_JBC t.cond> :: s.if,
    387       <MVvisitJumpInsn <MV> s.if s.label>,
    388       <ASAIL_To_JBC e.body>,
    389       <MVvisitLabel <MV> s.label>,
    390       <Pop_Block_Table>;
    391     (LSPLIT t.name (e.min) t.var1 t.var2) =
    392       <Push_Block_Table>,
    393       <Bind_Iter_Var t.name t.var1 t.var2> :: s.i,
    394       <Expr_Ref_To_JBC t.name>,
    395       <Expr_Int_To_JBC e.min>,
    396       <MVvisitMethodInsn <MV> &INVOKEVIRTUAL "org/refal/plus/Expr" "leftSplit" "(I)Lorg/refal/plus/Expr$SplitIterator;">,
    397       <MVvisitVarInsn <MV> &ASTORE s.i>;
    398     (RSPLIT t.name (e.min) t.var1 t.var2) =
    399       <Push_Block_Table>,
    400       <Bind_Iter_Var t.name t.var1 t.var2> :: s.i,
    401       <Expr_Ref_To_JBC t.name>,
    402       <Expr_Int_To_JBC e.min>,
    403       <MVvisitMethodInsn <MV> &INVOKEVIRTUAL "org/refal/plus/Expr" "rightSplit" "(I)Lorg/refal/plus/Expr$SplitIterator;">,
    404       <MVvisitVarInsn <MV> &ASTORE s.i>;
    405     (FOR (e.cont_label) (e.break_label) () (e.step) e.body) =
    406       { e.step : /*empty*/, <Push_Block_Table>;; },
    407       {
    408         e.cont_label : t.label = <Bind_Label t.label>;
    409         <Label>;
    410       } :: s.cont_label,
    411       {
    412         e.break_label : t.label = <Bind_Label t.label>;
    413         <Label>;
    414       } :: s.break_label,
    415       <Label> :: s.for_label,
    416       <MVvisitLabel <MV> s.for_label>,
    417       {
    418         e.step : (s.tag e.expr), s.tag : \{ "INC-ITER"; "DEC-ITER"; } =
    419           <Lookup_Iter_Var e.expr> : s.i s.i1 s.i2,
    420           <MVvisitVarInsn <MV> &ALOAD s.i>,
    421           <MVvisitInsn <MV> &DUP>,
    422           <MVvisitMethodInsn <MV> &INVOKEVIRTUAL "org/refal/plus/Expr$SplitIterator" "getLeft" "()Lorg/refal/plus/Expr;">,
    423           <MVvisitVarInsn <MV> &ASTORE s.i1>,
    424           <MVvisitMethodInsn <MV> &INVOKEVIRTUAL "org/refal/plus/Expr$SplitIterator" "getRight" "()Lorg/refal/plus/Expr;">,
    425           <MVvisitVarInsn <MV> &ASTORE s.i2>;;
    426       },
    427       <ASAIL_To_JBC e.body>,
    428       <MVvisitLabel <MV> s.cont_label>,
    429       <Step_To_JBC e.step>,
    430       <MVvisitJumpInsn <MV> &GOTO s.for_label>,
    431       <MVvisitLabel <MV> s.break_label>,
    432       <Pop_Block_Table>;
    433     (LABEL (t.label) e.body) =
    434       <Push_Block_Table>,
    435       <Bind_Label t.label> :: s.l,
    436       <ASAIL_To_JBC e.body>,
    437       <MVvisitLabel <MV> s.l>,
    438       <Pop_Block_Table>;
    439     (s.tag t.label), s.tag : \{ CONTINUE; BREAK; } =
    440       <MVvisitJumpInsn <MV> &GOTO <Lookup_Label t.label>>;
    441     RETFAIL =
    442       <MVvisitInsn <MV> &ICONST_0> <MVvisitInsn <MV> &IRETURN>;
    443     (TRY e.body) =
    444       <Push_Block_Table>,
    445       <Label> :: s.start,
    446       <Label> :: s.end,
    447       <Label> :: s.real_end,
    448       <Label> :: s.handler,
    449       <Push_Trap s.real_end s.handler>,
    450       <MVvisitTryCatchBlock <MV> s.start s.end s.handler "org/refal/plus/RefalException">,
    451       <MVvisitLabel <MV> s.start>,
    452       <ASAIL_To_JBC e.body>,
    453       <MVvisitLabel <MV> s.end>,
    454       <MVvisitJumpInsn <MV> &GOTO s.real_end>,
    455       <Pop_Block_Table>;
    456     ("CATCH-ERROR" e.body) =
    457       <Push_Block_Table>,
    458       <Get_Trap> :: s.label,
    459       <MVvisitLabel <MV> s.label>,
    460       <MVvisitMethodInsn <MV> &INVOKEVIRTUAL "org/refal/plus/RefalException" "getExpr" "()Lorg/refal/plus/Expr;">,
    461       <MVvisitVarInsn <MV> &ASTORE <Bind_Var Expr s.label>>,
    462       <ASAIL_To_JBC e.body>,
    463       <MVvisitLabel <MV> <Pop_Trap>>,
    464       <Pop_Block_Table>;
    465     FATAL =
    466       <MVvisitTypeInsn <MV> &NEW "org/refal/plus/RefalException">,
    467       <MVvisitInsn <MV> &DUP>,
    468       <Get &Refal_Module_Name> : s.mod_name,
    469       <MVvisitLdcInsn <MV> <WordToString s.mod_name>>,
    470       <Get &Func_Name> : s.fname,
    471       <MVvisitLdcInsn <MV> <WordToString s.fname>>,
    472       <MVvisitLdcInsn <MV> <WordToString "Unexpected fail">>,
    473       <MVvisitMethodInsn <MV> &INVOKESPECIAL "org/refal/plus/RefalException" "<init>" "(Ljava/lang/String;Ljava/lang/String;Ljava/lang/String;)V">,
    474       <MVvisitInsn <MV> &ATHROW>;
    475     (ERROR e.expr) =
    476       <MVvisitTypeInsn <MV> &NEW "org/refal/plus/RefalException">,
    477       <MVvisitInsn <MV> &DUP>,
    478       <Expr_Ref_To_JBC e.expr>,
    479       <MVvisitMethodInsn <MV> &INVOKESPECIAL "org/refal/plus/RefalException" "<init>" "(Lorg/refal/plus/Expr;)V">,
    480       <MVvisitInsn <MV> &ATHROW>;
    481     (s.call (e.module s.name) (e.args) (e.ress)),
    482       s.call : \{ CALL = V; TAILCALL = V; "TAILCALL?" = Z; } :: s.retType =
    483       <Function_Description (e.args) (e.ress) s.retType> :: s.desc,
    484       {
    485         e.args : e (e.arg) e,
    486           <Expr_Ref_To_JBC e.arg>,
    487           $fail;;
    488       },
    489       {
    490         e.ress : e t.var e, <Lookup_Var t.var> :
    491           {
    492             Expr s =
    493               <Bind_TMP_Var t.var> :: s.j,
    494               <MVvisitTypeInsn <MV> &NEW "org/refal/plus/Result">,
    495               <MVvisitInsn <MV> &DUP>,
    496               <MVvisitInsn <MV> &DUP>,
    497               <MVvisitMethodInsn <MV> &INVOKESPECIAL "org/refal/plus/Result" "<init>" "()V">,
    498               <MVvisitVarInsn <MV> &ASTORE s.j>;
    499             Result s.i =
    500               <MVvisitVarInsn <MV> &ALOAD s.i>;
    501           }, $fail;;
    502       },
    503       <MVvisitMethodInsn <MV> &INVOKESTATIC <GetJBCQName e.module s.name> s.desc>,
    504       {
    505         s.call : "TAILCALL?" =
    506           <Label> :: s.label,
    507           <MVvisitJumpInsn <MV> &IFNE s.label>,
    508           <MVvisitInsn <MV> &ICONST_0>,
    509           <MVvisitInsn <MV> &IRETURN>,
    510           <MVvisitLabel <MV> s.label>;;
    511       },
    512       {
    513         e.ress : e t.var e, <Lookup_Var t.var> : Expr s.i,
    514           <Lookup_TMP_Var t.var> :: s.j,
    515           <MVvisitVarInsn <MV> &ALOAD s.j>
     278$func Check_Name s.name = ;
     279Check_Name s = ;
     280
     281
     282Module_To_JBC e.module, <Map &Module_Item_To_JBC (e.module)> : e;
     283
     284Module_Item_To_JBC {
     285  (s.tag IMPORT e) = /*empty*/;
     286  (s.tag s.linkage t.qname (e.args) (e.ress) e.body),
     287    s.tag : \{
     288      FUNC  = 'V';
     289      "FUNC?" = 'Z';
     290    } : s.retType =
     291    t.qname : (e s.name),
     292    <Check_Name s.name>,
     293    <Add &ACC_STATIC <Access_Mode s.linkage>> :: s.access,
     294    <Function_Description (e.args) (e.ress) s.retType> :: s.desc,
     295    <Store &MVbox <CWvisitMethod <CW> s.access s.name s.desc <Null> ("org/refal/plus/RefalException")>>,
     296    {
     297      <PrintFunctionFormat t.qname> :: s.format =
     298        <MVvisitAnnotation <MV> "Lorg/refal/plus/RefalFormat;" False> :: s.aw,
     299        <AnnotationVisitor.visit s.aw "value" <WordToString s.format>>,
     300        <AnnotationVisitor.visitEnd s.aw>;;
     301    },
     302    <Store &FuncName s.name> <Init_Block_Table> <Bind_Vars Expr e.args> <Bind_Vars Result e.ress>,
     303    <Body_To_JBC e.body>,
     304    s.tag : {
     305      FUNC  = <MVvisitInsn <MV> &RETURN>;
     306      "FUNC?" = <MVvisitInsn <MV> &ICONST_1> <MVvisitInsn <MV> &IRETURN>;
     307    },
     308    <MVvisitMaxs <MV> 0 0>,
     309    <MVvisitEnd <MV>>,
     310    { <Get &Entry> : e t.qname e = <Store &EntryName s.name>;; };
     311  (CONSTEXPR s.linkage t.qname (e.comment) e.expr) =
     312    t.qname : {
     313      (STATIC (e)) = <GetJBCName t.qname>;
     314      (e s.name) = s.name;
     315    } :: s.name,
     316    <Check_Name s.name>,
     317    <Add &ACC_FINAL <Add &ACC_STATIC <Access_Mode s.linkage>>> :: s.access,
     318    <CWvisitField <CW> s.access s.name "Lorg/refal/plus/Expr;" <Null> <Null>> :: s.fv,
     319    {
     320      <PrintConstDefinition t.qname> :: s.def =
     321        <FVvisitAnnotation s.fv "Lorg/refal/plus/RefalFormat;" False> :: s.aw,
     322        <AnnotationVisitor.visit s.aw "value" <WordToString s.def>>,
     323        <AnnotationVisitor.visitEnd s.aw>;;
     324    },
     325    <FVvisitEnd s.fv>,
     326    <Put &Constants (s.name e.expr)>;
     327  (OBJ s.linkage s.tag t.qname) =
     328    t.qname : (e s.name),
     329    <Check_Name s.name>,
     330    <Add &ACC_FINAL <Add &ACC_STATIC <Access_Mode s.linkage>>> :: s.access,
     331    <CWvisitField <CW> s.access s.name "Lorg/refal/plus/Expr;" <Null> <Null>> :: s.fv,
     332    {
     333      <PrintObjectDefinition t.qname> :: s.def =
     334        <FVvisitAnnotation s.fv "Lorg/refal/plus/RefalFormat;" False> :: s.aw,
     335        <AnnotationVisitor.visit s.aw "value" <WordToString s.def>>,
     336        <AnnotationVisitor.visitEnd s.aw>;;
     337    },
     338    <FVvisitEnd s.fv>,
     339    <Put &Objects (s.tag s.name)>;
     340  ("DECL-OBJ" t.name) = ;
     341  ("DECL-FUNC" t.name) = ;
     342  (TRACE t.name) =
     343    <Bind &RFP_Trace (t.name) ()>;
     344};
     345
     346Body_To_JBC e.body, <Map &Body_Item_To_JBC (e.body)> : e;
     347
     348Body_Item_To_JBC {
     349  (DECL (INT t.var)) =
     350    <Bind_Var Int t.var> : s;
     351  (DECL s.type t.var) =
     352    <Bind_Var s.type t.var> :: s.i,
     353    s.type : {
     354      Result =
     355        <MVvisitTypeInsn <MV> &NEW "org/refal/plus/Result">,
     356        <MVvisitInsn <MV> &DUP>,
     357        <MVvisitMethodInsn <MV> &INVOKESPECIAL "org/refal/plus/Result" "<init>" "()V">,
     358        <MVvisitVarInsn <MV> &ASTORE s.i>;
     359      Expr =
     360        <MVvisitFieldInsn <MV> &GETSTATIC "org/refal/plus/Expr" "empty" "Lorg/refal/plus/Expr;">,
     361        <MVvisitVarInsn <MV> &ASTORE s.i>;
     362    };
     363  (ASSIGN (INT t.var) e.expr) =
     364    <Lookup_Var t.var> :: s s.i,
     365    <Expr_Int_To_JBC e.expr>,
     366    <MVvisitVarInsn <MV> &ISTORE s.i>;
     367  (ASSIGN t.var e.expr) =
     368    <Lookup_Var t.var> :: s.type s.i,
     369    s.type : {
     370      Result =
     371        <MVvisitVarInsn <MV> &ALOAD s.i>,
     372        <Expr_Ref_To_JBC e.expr>,
     373        <MVvisitMethodInsn <MV> &INVOKEVIRTUAL "org/refal/plus/Result" "assign" "(Lorg/refal/plus/Expr;)V">;
     374      Expr =
     375        <Expr_Ref_To_JBC e.expr>,
     376        <MVvisitVarInsn <MV> &ASTORE s.i>;
     377    };
     378  ("IF-INT-CMP" s.op (e.arg1) (e.arg2) e.body) =
     379    <Push_Block_Table>,
     380    <Label> :: s.label,
     381    <Expr_Int_To_JBC e.arg1>,
     382    <Expr_Int_To_JBC e.arg2>,
     383    s.op : {
     384      "!=" = &IF_ICMPEQ;
     385      "<" = &IF_ICMPGE;
     386      ">" = &IF_ICMPLE;
     387    } :: s.op,
     388    <MVvisitJumpInsn <MV> s.op s.label>,
     389    <Body_To_JBC e.body>,
     390    <MVvisitLabel <MV> s.label>,
     391    <Pop_Block_Table>;
     392  (IF t.cond e.body) =
     393    <Push_Block_Table>,
     394    <Label> :: s.label,
     395    <Cond_To_JBC t.cond> :: s.if,
     396    <MVvisitJumpInsn <MV> s.if s.label>,
     397    <Body_To_JBC e.body>,
     398    <MVvisitLabel <MV> s.label>,
     399    <Pop_Block_Table>;
     400  (LSPLIT t.name (e.min) t.var1 t.var2) =
     401    <Push_Block_Table>,
     402    <Bind_Iter_Var t.name t.var1 t.var2> :: s.i,
     403    <Expr_Ref_To_JBC t.name>,
     404    <Expr_Int_To_JBC e.min>,
     405    <MVvisitMethodInsn <MV> &INVOKEVIRTUAL "org/refal/plus/Expr" "leftSplit" "(I)Lorg/refal/plus/Expr$SplitIterator;">,
     406    <MVvisitVarInsn <MV> &ASTORE s.i>;
     407  (RSPLIT t.name (e.min) t.var1 t.var2) =
     408    <Push_Block_Table>,
     409    <Bind_Iter_Var t.name t.var1 t.var2> :: s.i,
     410    <Expr_Ref_To_JBC t.name>,
     411    <Expr_Int_To_JBC e.min>,
     412    <MVvisitMethodInsn <MV> &INVOKEVIRTUAL "org/refal/plus/Expr" "rightSplit" "(I)Lorg/refal/plus/Expr$SplitIterator;">,
     413    <MVvisitVarInsn <MV> &ASTORE s.i>;
     414  (FOR (e.cont_label) (e.break_label) () (e.step) e.body) =
     415    { e.step : /*empty*/, <Push_Block_Table>;; },
     416    {
     417      e.cont_label : t.label = <Bind_Label t.label>;
     418      <Label>;
     419    } :: s.cont_label,
     420    {
     421      e.break_label : t.label = <Bind_Label t.label>;
     422      <Label>;
     423    } :: s.break_label,
     424    <Label> :: s.for_label,
     425    <MVvisitLabel <MV> s.for_label>,
     426    {
     427      e.step : (s.tag e.expr), s.tag : \{ "INC-ITER"; "DEC-ITER"; } =
     428        <Lookup_Iter_Var e.expr> : s.i s.i1 s.i2,
     429        <MVvisitVarInsn <MV> &ALOAD s.i>,
     430        <MVvisitInsn <MV> &DUP>,
     431        <MVvisitMethodInsn <MV> &INVOKEVIRTUAL "org/refal/plus/Expr$SplitIterator" "getLeft" "()Lorg/refal/plus/Expr;">,
     432        <MVvisitVarInsn <MV> &ASTORE s.i1>,
     433        <MVvisitMethodInsn <MV> &INVOKEVIRTUAL "org/refal/plus/Expr$SplitIterator" "getRight" "()Lorg/refal/plus/Expr;">,
     434        <MVvisitVarInsn <MV> &ASTORE s.i2>;;
     435    },
     436    <Body_To_JBC e.body>,
     437    <MVvisitLabel <MV> s.cont_label>,
     438    <Step_To_JBC e.step>,
     439    <MVvisitJumpInsn <MV> &GOTO s.for_label>,
     440    <MVvisitLabel <MV> s.break_label>,
     441    <Pop_Block_Table>;
     442  (LABEL (t.label) e.body) =
     443    <Push_Block_Table>,
     444    <Bind_Label t.label> :: s.label,
     445    <Body_To_JBC e.body>,
     446    <MVvisitLabel <MV> s.label>,
     447    <Pop_Block_Table>;
     448  (s.tag t.label), s.tag : \{ CONTINUE; BREAK; } =
     449    <MVvisitJumpInsn <MV> &GOTO <Lookup_Label t.label>>;
     450  RETFAIL =
     451    <MVvisitInsn <MV> &ICONST_0> <MVvisitInsn <MV> &IRETURN>;
     452  (TRY e.body) =
     453    <Push_Block_Table>,
     454    <Label> :: s.start,
     455    <Label> :: s.end,
     456    <Label> :: s.real_end,
     457    <Label> :: s.handler,
     458    <Push_Trap s.real_end s.handler>,
     459    <MVvisitTryCatchBlock <MV> s.start s.end s.handler "org/refal/plus/RefalException">,
     460    <MVvisitLabel <MV> s.start>,
     461    <Body_To_JBC e.body>,
     462    <MVvisitLabel <MV> s.end>,
     463    <MVvisitJumpInsn <MV> &GOTO s.real_end>,
     464    <Pop_Block_Table>;
     465  ("CATCH-ERROR" e.body) =
     466    <Push_Block_Table>,
     467    <Get_Trap> :: s.label,
     468    <MVvisitLabel <MV> s.label>,
     469    <MVvisitMethodInsn <MV> &INVOKEVIRTUAL "org/refal/plus/RefalException" "getExpr" "()Lorg/refal/plus/Expr;">,
     470    <MVvisitVarInsn <MV> &ASTORE <Bind_Var Expr s.label>>,
     471    <Body_To_JBC e.body>,
     472    <MVvisitLabel <MV> <Pop_Trap>>,
     473    <Pop_Block_Table>;
     474  FATAL =
     475    <MVvisitTypeInsn <MV> &NEW "org/refal/plus/RefalException">,
     476    <MVvisitInsn <MV> &DUP>,
     477    <Get &Refal_Module_Name> : s.mod_name,
     478    <MVvisitLdcInsn <MV> <WordToString s.mod_name>>,
     479    <Get &FuncName> : s.fname,
     480    <MVvisitLdcInsn <MV> <WordToString s.fname>>,
     481    <MVvisitLdcInsn <MV> <WordToString "Unexpected fail">>,
     482    <MVvisitMethodInsn <MV> &INVOKESPECIAL "org/refal/plus/RefalException" "<init>" "(Ljava/lang/String;Ljava/lang/String;Ljava/lang/String;)V">,
     483    <MVvisitInsn <MV> &ATHROW>;
     484  (ERROR e.expr) =
     485    <MVvisitTypeInsn <MV> &NEW "org/refal/plus/RefalException">,
     486    <MVvisitInsn <MV> &DUP>,
     487    <Expr_Ref_To_JBC e.expr>,
     488    <MVvisitMethodInsn <MV> &INVOKESPECIAL "org/refal/plus/RefalException" "<init>" "(Lorg/refal/plus/Expr;)V">,
     489    <MVvisitInsn <MV> &ATHROW>;
     490  (s.call (e.module s.name) (e.args) (e.ress)),
     491    s.call : \{ CALL = V; TAILCALL = V; "TAILCALL?" = Z; } :: s.retType =
     492    <Function_Description (e.args) (e.ress) s.retType> :: s.desc,
     493    {
     494      e.args : e (e.arg) e,
     495        <Expr_Ref_To_JBC e.arg>,
     496        $fail;;
     497    },
     498    {
     499      e.ress : e t.var e, <Lookup_Var t.var> :
     500        {
     501          Expr s =
     502            <Bind_TMP_Var t.var> :: s.j,
     503            <MVvisitTypeInsn <MV> &NEW "org/refal/plus/Result">,
     504            <MVvisitInsn <MV> &DUP>,
     505            <MVvisitInsn <MV> &DUP>,
     506            <MVvisitMethodInsn <MV> &INVOKESPECIAL "org/refal/plus/Result" "<init>" "()V">,
     507            <MVvisitVarInsn <MV> &ASTORE s.j>;
     508          Result s.i =
     509            <MVvisitVarInsn <MV> &ALOAD s.i>;
     510        }, $fail;;
     511    },
     512    <MVvisitMethodInsn <MV> &INVOKESTATIC <GetJBCQName e.module s.name> s.desc>,
     513    {
     514      s.call : "TAILCALL?" =
     515        <Label> :: s.label,
     516        <MVvisitJumpInsn <MV> &IFNE s.label>,
     517        <MVvisitInsn <MV> &ICONST_0>,
     518        <MVvisitInsn <MV> &IRETURN>,
     519        <MVvisitLabel <MV> s.label>;;
     520    },
     521    {
     522      e.ress : e t.var e, <Lookup_Var t.var> : Expr s.i,
     523        <Lookup_TMP_Var t.var> :: s.j,
     524        <MVvisitVarInsn <MV> &ALOAD s.j>
    516525          <MVvisitMethodInsn <MV> &INVOKEVIRTUAL "org/refal/plus/Result" "getExpr" "()Lorg/refal/plus/Expr;">,
    517           <MVvisitVarInsn <MV> &ASTORE s.i>,
    518           $fail;;
    519       };
    520   }, $fail; e;
    521 };
    522 
     526        <MVvisitVarInsn <MV> &ASTORE s.i>,
     527        $fail;;
     528    };
     529};
    523530
    524531$func Term_Ref_To_JBC t.term = ;
Note: See TracChangeset for help on using the changeset viewer.