Changeset 2394


Ignore:
Timestamp:
Feb 11, 2007, 3:33:10 PM (14 years ago)
Author:
yura
Message:
  • Stack for variables pool
  • Correct call in CALL-FAILS
  • No WriteLN
File:
1 edited

Legend:

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

    r2390 r2394  
    173173
    174174
    175 
    176 $table Vars;
    177 $table Iter-Vars;
    178 $table TMP-Vars;
    179 $box Var-Idx;
     175$box Block-Tables;
     176
     177$func Init-Block-Table = ;
     178$func Push-Block-Table = ;
     179$func Pop-Block-Table = ;
     180$func Get-Block-Table = s.block-table;
     181
     182Init-Block-Table =
     183  <Table> :: s.block-table,
     184  <Bind s.block-table (VAR-INDEX) (0)>,
     185  <Store &Block-Tables s.block-table>;
     186
     187Push-Block-Table =
     188  <? &Block-Tables> : e.block-tables,
     189  e.block-tables : e s.block-table,
     190  <Store &Block-Tables e.block-tables <Table-Copy s.block-table>>;
     191
     192Pop-Block-Table =
     193  <? &Block-Tables> : e.block-tables s.block-table1 s.block-table2,
     194  <Lookup s.block-table2 VAR-INDEX> : s.i,
     195  <Bind s.block-table1 (VAR-INDEX) (s.i)>,
     196  <Store &Block-Tables e.block-tables s.block-table1>;
     197
     198Get-Block-Table =
     199  <? &Block-Tables> : e s.block-table,
     200  s.block-table;
    180201
    181202$func Bind-Vars s.type e.vars = ;
     
    195216
    196217Bind-Var s.type t.var =
    197   <? &Var-Idx> : s.i,
    198   <Store &Var-Idx <"+" s.i 1>>,
    199   <Bind &Vars (t.var) (s.type s.i)>,
     218  <Lookup <Get-Block-Table> VAR-INDEX> : s.i,
     219  <Bind <Get-Block-Table> (VAR-INDEX) (<"+" s.i 1>)>,
     220  <Bind <Get-Block-Table> (VAR t.var) (s.type s.i)>,
    200221  s.i;
    201222
    202 Lookup-Var t.var = <Lookup &Vars t.var> : s.type s.i = s.type s.i;
     223Lookup-Var t.var = <Lookup <Get-Block-Table> VAR t.var> : s.type s.i = s.type s.i;
    203224
    204225Bind-Iter-Var e.expr t.var1 t.var2 =
    205   <? &Var-Idx> : s.i,
    206   <Store &Var-Idx <"+" s.i 1>>,
     226  <Lookup <Get-Block-Table> VAR-INDEX> : s.i,
     227  <Bind <Get-Block-Table> (VAR-INDEX) (<"+" s.i 1>)>,
    207228  <Bind-Var Expr t.var1> :: s.i1,
    208229  <Bind-Var Expr t.var2> :: s.i2,
    209   <Bind &Iter-Vars (e.expr) (s.i s.i1 s.i2)>,
     230  <Bind <Get-Block-Table> (ITER e.expr) (s.i s.i1 s.i2)>,
    210231  s.i;
    211232
    212 Lookup-Iter-Var e.expr = <Lookup &Iter-Vars e.expr> : s.i s.i1 s.i2 = s.i s.i1 s.i2;
     233Lookup-Iter-Var e.expr = <Lookup <Get-Block-Table> ITER e.expr> : s.i s.i1 s.i2 = s.i s.i1 s.i2;
    213234
    214235Bind-TMP-Var t.var =
    215   <? &Var-Idx> : s.i,
    216   <Store &Var-Idx <"+" s.i 1>>,
    217   <Bind &TMP-Vars (t.var) (s.i)>,
     236  <Lookup <Get-Block-Table> VAR-INDEX> : s.i,
     237  <Bind <Get-Block-Table> (VAR-INDEX) (<"+" s.i 1>)>,
     238  <Bind <Get-Block-Table> (TMP t.var) (s.i)>,
    218239  s.i;
    219240
    220 Lookup-TMP-Var t.var = <Lookup &TMP-Vars t.var> : s.i = s.i;
    221 
    222 $table Labels;
     241Lookup-TMP-Var t.var = <Lookup <Get-Block-Table> TMP t.var> : s.i = s.i;
    223242
    224243$func Bind-Label t.label = s.l;
     
    227246Bind-Label t.label =
    228247  <Label> :: s.l,
    229   <Bind &Labels (t.label) (s.l)>,
     248  <Bind <Get-Block-Table> (LABEL t.label) (s.l)>,
    230249  s.l;
    231250
    232 Lookup-Label t.label = <Lookup &Labels t.label> : s.l = s.l;
     251Lookup-Label t.label = <Lookup <Get-Block-Table> LABEL t.label> : s.l = s.l;
    233252
    234253
     
    288307        FUNC? = 'Z';
    289308      } : s.retType =
    290       <Clear-Table &Vars>,
    291       <Clear-Table &Iter-Vars>,
    292       <Clear-Table &TMP-Vars>,
    293       <Clear-Table &Labels>,
    294       <Store &Var-Idx 0>,
     309      <Init-Block-Table>,
    295310      <Bind-Vars Expr e.args>,
    296311      <Bind-Vars Result e.ress>,
     
    337352
    338353ASAIL-To-JBC {
    339   e t.item e, <WriteLN> <WriteLN t.item > t.item : {
     354  e t.item e, /*<WriteLN> <WriteLN t.item>*/ t.item : {
    340355    (DECL s.type t.var) =
    341356      <Bind-Var s.type t.var> :: s.i,
     
    385400      <MVvisitMethodInsn <MV> &INVOKESPECIAL "org/refal/plus/Expr" "<init>" "(Lorg/refal/plus/Expr;II)V">,
    386401      <MVvisitVarInsn <MV> &ASTORE s.i>;
    387     (LSPLIT t.name (e.min) t.var1 t.var2) =
    388       <Bind-Iter-Var t.name t.var1 t.var2> :: s.i,
    389       <Expr-Ref-To-JBC t.name>,
    390       <Expr-Int-To-JBC e.min>,
    391       <MVvisitMethodInsn <MV> &INVOKEVIRTUAL "org/refal/plus/Expr" "leftSplit" "(I)Lorg/refal/plus/Expr$SplitIterator;">,
    392       <MVvisitVarInsn <MV> &ASTORE s.i>;
    393     (RSPLIT t.name (e.min) t.var1 t.var2) =
    394       <Bind-Iter-Var t.name t.var1 t.var2> :: s.i,
    395       <Expr-Ref-To-JBC t.name>,
    396       <Expr-Int-To-JBC e.min>,
    397       <MVvisitMethodInsn <MV> &INVOKEVIRTUAL "org/refal/plus/Expr" "rightSplit" "(I)Lorg/refal/plus/Expr$SplitIterator;">,
    398       <MVvisitVarInsn <MV> &ASTORE s.i>;
    399402    (IF-INT-CMP s.op (e.arg1) (e.arg2) e.body) =
     403      <Push-Block-Table>,
    400404      <Label> :: s.label,
    401405      <Expr-Int-To-JBC e.arg1>,
     
    408412      <MVvisitJumpInsn <MV> s.op s.label>,
    409413      <ASAIL-To-JBC e.body>,
    410       <MVvisitLabel <MV> s.label>;
     414      <MVvisitLabel <MV> s.label>,
     415      <Pop-Block-Table>;
    411416    (IF t.cond e.body) =
     417      <Push-Block-Table>,
    412418      <Label> :: s.label,
    413419      <Cond-To-JBC t.cond> :: s.if,
    414420      <MVvisitJumpInsn <MV> s.if s.label>,
    415421      <ASAIL-To-JBC e.body>,
    416       <MVvisitLabel <MV> s.label>;
     422      <MVvisitLabel <MV> s.label>,
     423      <Pop-Block-Table>;
     424    (LSPLIT t.name (e.min) t.var1 t.var2) =
     425      <Push-Block-Table>,
     426      <Bind-Iter-Var t.name t.var1 t.var2> :: s.i,
     427      <Expr-Ref-To-JBC t.name>,
     428      <Expr-Int-To-JBC e.min>,
     429      <MVvisitMethodInsn <MV> &INVOKEVIRTUAL "org/refal/plus/Expr" "leftSplit" "(I)Lorg/refal/plus/Expr$SplitIterator;">,
     430      <MVvisitVarInsn <MV> &ASTORE s.i>;
     431    (RSPLIT t.name (e.min) t.var1 t.var2) =
     432      <Push-Block-Table>,
     433      <Bind-Iter-Var t.name t.var1 t.var2> :: s.i,
     434      <Expr-Ref-To-JBC t.name>,
     435      <Expr-Int-To-JBC e.min>,
     436      <MVvisitMethodInsn <MV> &INVOKEVIRTUAL "org/refal/plus/Expr" "rightSplit" "(I)Lorg/refal/plus/Expr$SplitIterator;">,
     437      <MVvisitVarInsn <MV> &ASTORE s.i>;
    417438    (FOR (e.cont-label) (e.break-label) () (e.step) e.body) =
     439      { e.step : /*empty*/, <Push-Block-Table>;; },
    418440      {
    419441        e.cont-label : t.label = <Bind-Label t.label>;
     
    440462      <Step-To-JBC e.step>,
    441463      <MVvisitJumpInsn <MV> &GOTO s.for-label>,
    442       <MVvisitLabel <MV> s.break-label>;
     464      <MVvisitLabel <MV> s.break-label>,
     465      <Pop-Block-Table>;
    443466    (LABEL (t.label) e.body) =
     467      <Push-Block-Table>,
    444468      <Bind-Label t.label> :: s.l,
    445469      <ASAIL-To-JBC e.body>,
    446       <MVvisitLabel <MV> s.l>;
     470      <MVvisitLabel <MV> s.l>,
     471      <Pop-Block-Table>;
    447472    (s.tag t.label), s.tag : \{ CONTINUE; BREAK; } =
    448473      <MVvisitJumpInsn <MV> &GOTO <Lookup-Label t.label>>;
     
    450475      <MVvisitInsn <MV> &"ICONST_0"> <MVvisitInsn <MV> &IRETURN>;
    451476    (TRY e.body) =
     477      <Push-Block-Table>,
    452478      <Label> :: s.start,
    453479      <Label> :: s.end,
     
    459485      <ASAIL-To-JBC e.body>,
    460486      <MVvisitLabel <MV> s.end>,
    461       <MVvisitJumpInsn <MV> &GOTO s.real-end>;
     487      <MVvisitJumpInsn <MV> &GOTO s.real-end>,
     488      <Pop-Block-Table>;
    462489    (CATCH-ERROR e.body) =
     490      <Push-Block-Table>,
    463491      <Get-Trap> :: s.label,
    464492      <MVvisitLabel <MV> s.label>,
     
    466494      <MVvisitVarInsn <MV> &ASTORE <Bind-Var Expr s.label>>,
    467495      <ASAIL-To-JBC e.body>,
    468       <MVvisitLabel <MV> <Pop-Trap>>;
     496      <MVvisitLabel <MV> <Pop-Trap>>,
     497      <Pop-Block-Table>;
    469498    FATAL =
    470499      <MVvisitTypeInsn <MV> &NEW "org/refal/plus/RefalException">,
     
    545574        <MVvisitLdcInsn <MV> <Integer s.i>>,
    546575        <Term-Ref-To-JBC t.term>,
     576        <MVvisitTypeInsn <MV> &CHECKCAST "java/lang/Object">, // TODO!!!
    547577        <MVvisitInsn <MV> &AASTORE>,
    548578        <"+" s.i 1> e.rest;
     
    625655Cond-To-JBC {
    626656  (CALL-FAILS (CALL (e.module s.name) (e.args) (e.ress))) =
     657
    627658    <Qualified-Module-Name e.module> :: s.module,
    628659    <To-Word <Rfp2Java s.name>> :: s.name,
     
    637668        {
    638669          Expr s =
     670            <Bind-TMP-Var t.var> :: s.j,
    639671            <MVvisitTypeInsn <MV> &NEW "org/refal/plus/Result">,
    640672            <MVvisitInsn <MV> &DUP>,
    641             <MVvisitMethodInsn <MV> &INVOKESPECIAL "org/refal/plus/Result" "<init>" "()V">;
     673            <MVvisitInsn <MV> &DUP>,
     674            <MVvisitMethodInsn <MV> &INVOKESPECIAL "org/refal/plus/Result" "<init>" "()V">,
     675            <MVvisitVarInsn <MV> &ASTORE s.j>;
    642676          Result s.i =
    643677            <MVvisitVarInsn <MV> &ALOAD s.i>;
     
    645679    },
    646680    <MVvisitMethodInsn <MV> &INVOKESTATIC s.module s.name s.desc>,
     681    {
     682      e.ress : e t.var e, <Lookup-Var t.var> : Expr s.i,
     683        <Lookup-TMP-Var t.var> :: s.j,
     684        <MVvisitVarInsn <MV> &ALOAD s.j>
     685        <MVvisitMethodInsn <MV> &INVOKEVIRTUAL "org/refal/plus/Result" "getExpr" "()Lorg/refal/plus/Expr;">,
     686        <MVvisitVarInsn <MV> &ASTORE s.i>,
     687        $fail;;
     688    },
    647689    &IFNE;
    648690  (ITER-FAILS e.expr) =
     
    719761        <MVvisitLdcInsn <MV> <Integer s.i>>,
    720762        <Const-Term-To-JBC t.term>,
     763        <MVvisitTypeInsn <MV> &CHECKCAST "java/lang/Object">, // TODO!!!
    721764        <MVvisitInsn <MV> &AASTORE>,
    722765        <"+" s.i 1> e.rest;
Note: See TracChangeset for help on using the changeset viewer.