Changeset 2351
 Timestamp:
 Feb 8, 2007, 6:41:54 PM (14 years ago)
 File:

 1 edited
Legend:
 Unmodified
 Added
 Removed

toimperative/trunk/compiler/rfp_asail_jbc.rf
r2347 r2351 33 33 $box ResAssigns; 34 34 35 $table IterVars;36 37 35 $func ModuleToJBC s.cw e.module = ; 38 36 … … 45 43 $func ExprIntToJBC e.ASAILExprInt = ; 46 44 47 $func StepToJBC e.stepoperators = e.javastepoperators;45 $func StepToJBC e.stepoperators = ; 48 46 49 47 $func ConstExprToJBC e.ASAILconstexpr = e.auxarrays (e.JAVAconstexpr); … … 51 49 $func ExprArgsToJBC e.args = e.auxarrays (e.javaargs); 52 50 53 $func IntArgsToJBC s.acc e.args = e.javaargs;54 55 51 $func SymbolToJBC s.RFPSymbol = e.JAVAString; 56 52 … … 59 55 $func VarToJBC t.var = ; 60 56 61 $func CondToJBC s.acc e.cond = e.JAVACond;57 $func CondToJBC t.cond = s.if; 62 58 63 59 $func InfixToJBC s.funcforconvertingargstojava s.op e.args = ; … … 73 69 RFPASAILToJBC (e.modulename) (e.package) (e.exports) e.module = 74 70 <Store &FreeIdx>, 75 <RFPClearTable &IterVars>,76 71 <RFPClearTable &Inputs>, 77 72 { … … 109 104 110 105 $table Vars; 106 $table IterVars; 111 107 $box VarIdx; 112 108 … … 114 110 $func BindVar s.type t.var = s.i; 115 111 $func LookupVar t.var = s.type s.i; 112 $func BindIterVar e.expr t.var1 t.var2 = s.i; 113 $func LookupIterVar e.expr = s.i s.i1 s.i2; 116 114 117 115 BindVars s.type e.vars = … … 124 122 BindVar s.type t.var = 125 123 <? &VarIdx> : s.i, 124 <Store &VarIdx <"+" s.i 1>>, 126 125 <Bind &Vars (t.var) (s.type s.i)>, 126 s.i; 127 128 LookupVar t.var = <Lookup &Vars t.var> : s.type s.i = s.type s.i; 129 130 BindIterVar e.expr t.var1 t.var2 = 131 <? &VarIdx> : s.i, 127 132 <Store &VarIdx <"+" s.i 1>>, 133 <BindVar Expr t.var1> :: s.i1, 134 <BindVar Expr t.var2> :: s.i2, 135 <Bind &IterVars (e.expr) (s.i s.i1 s.i2)>, 128 136 s.i; 129 137 130 LookupVar t.var = { 131 <Lookup &Vars t.var> : s.type s.i = s.type s.i; 132 Expr 0; // TODO  remove 133 }; 138 LookupIterVar e.expr = <Lookup &IterVars e.expr> : s.i s.i1 s.i2 = s.i s.i1 s.i2; 139 134 140 135 141 $table Labels; … … 159 165 } : s.retType, 160 166 <ClearTable &Vars>, 167 <ClearTable &IterVars>, 168 <ClearTable &Labels>, 161 169 <Store &VarIdx 0>, 162 170 <BindVars Expr e.args>, 163 171 <BindVars Result e.ress>, 164 <ClearTable &Labels>,165 172 <"+" &"ACC_STATIC" <AccessMode t.name>> :: s.accessMode, 166 173 <ToWord <NameToJBC t.name>> :: s.funcName, … … 173 180 FUNC? = <MVvisitInsn <MV> &"ICONST_1"> <MVvisitInsn <MV> &IRETURN>; 174 181 }, 182 <MVvisitMaxs <MV> 0 0>, 175 183 <MVvisitEnd <MV>>; 176 184 (CONSTEXPR s.linkage t.name (e.comment) e.expr) = … … 207 215 (DECL s.type t.var) = 208 216 <BindVar s.type t.var> :: s.i, 209 {210 s.type :Result =217 s.type : { 218 Result = 211 219 <MVvisitTypeInsn <MV> &NEW "org/refal/plus/Expr">, 212 220 <MVvisitInsn <MV> &DUP>, 213 221 <MVvisitMethodInsn <MV> &INVOKESPECIAL "org/refal/plus/Result" "<init>" "()V">, 214 222 <MVvisitVarInsn <MV> &ASTORE s.i>; 215 <MVvisitFieldInsn <MV> &GETSTATIC "org/refal/plus/Expr" "empty" "Lorg/refal/plus/Expr;">, 223 Expr = 224 <MVvisitFieldInsn <MV> &GETSTATIC "org/refal/plus/Expr" "empty" "Lorg/refal/plus/Expr;">, 216 225 <MVvisitVarInsn <MV> &ASTORE s.i>; 217 226 }; 218 RETFAIL = <MVvisitInsn <MV> &"ICONST_0"> <MVvisitInsn <MV> &IRETURN>; 219 (IF (e.cond) e.body) = 220 <Box> :: s.acc, 221 <CondToJBC s.acc e.cond> :: e.jcond, 222 { 223 e.cond : (NOT (CALL e)) = 224 () (<? &ResAssigns> <Store &ResAssigns /*empty*/>); 225 (<? &ResAssigns> <Store &ResAssigns /*empty*/>) (); 226 } :: (e.ifyesassigns) (e.ifnotassigns), 227 <? s.acc> 228 ('if ('e.jcond')') 229 ('{' ( 230 e.ifyesassigns 231 <ASAILToJBCTemp e.body> 232 )'}' ) 233 e.ifnotassigns : e; 234 (FOR (e.contlabel) (e.breaklabel) (e.cond) (e.step) e.body) = 227 (ASSIGN t.var e.expr) = 228 <LookupVar t.var> :: s.type s.i, 229 s.type : { 230 Result = 231 <MVvisitVarInsn <MV> &ALOAD s.i>, 232 <ExprRefToJBC e.expr>, 233 <MVvisitMethodInsn <MV> &INVOKEVIRTUAL "org/refal/plus/Result" "assign" "(Lorg/refal/plus/Expr;)V">; 234 Expr = 235 <ExprRefToJBC e.expr>, 236 <MVvisitVarInsn <MV> &ASTORE s.i>; 237 }; 238 (INT t.var e.expr) = 239 <BindVar Int t.var> :: s.i, 240 <ExprIntToJBC e.expr>, 241 <MVvisitVarInsn <MV> &ISTORE s.i>; 242 (EXPR t.var e.expr) = 243 <BindVar Expr t.var> :: s.i, 244 <ExprRefToJBC e.expr>, 245 <MVvisitVarInsn <MV> &ASTORE s.i>; 246 (DEREF t.var e.expr (e.pos)) = 247 <BindVar Expr t.var> :: s.i, 248 <ExprRefToJBC e.expr>, 249 <ExprIntToJBC e.pos>, 250 <MVvisitMethodInsn <MV> &INVOKEVIRTUAL "org/refal/plus/Expr" "at" "(I)Ljava/lang/Object;">, 251 <MVvisitTypeInsn <MV> &CHECKCAST "org/refal/plus/Expr">, 252 <MVvisitVarInsn <MV> &ASTORE s.i>; 253 (SUBEXPR t.var e.expr (e.pos) (e.len)) = 254 <BindVar Expr t.var> :: s.i, 255 <MVvisitTypeInsn <MV> &NEW "org/refal/plus/Expr">, 256 <MVvisitInsn <MV> &DUP>, 257 <ExprRefToJBC e.expr>, 258 <ExprIntToJBC e.pos>, 259 <ExprIntToJBC e.len>, 260 <MVvisitMethodInsn <MV> &INVOKESPECIAL "org/refal/plus/Expr" "<init>" "(Lorg/refal/plus/Expr;II)V">, 261 <MVvisitVarInsn <MV> &ASTORE s.i>; 262 (LSPLIT t.name (e.min) t.var1 t.var2) = 263 <BindIterVar t.name t.var1 t.var2> :: s.i, 264 <ExprRefToJBC t.name>, 265 <ExprIntToJBC e.min>, 266 <MVvisitMethodInsn <MV> &INVOKEVIRTUAL "org/refal/plus/Expr" "leftSplit" "(I)Lorg/refal/plus/Expr$SplitIterator;">, 267 <MVvisitVarInsn <MV> &ASTORE s.i>; 268 (RSPLIT t.name (e.min) t.var1 t.var2) = 269 <BindIterVar t.name t.var1 t.var2> :: s.i, 270 <ExprRefToJBC t.name>, 271 <ExprIntToJBC e.min>, 272 <MVvisitMethodInsn <MV> &INVOKEVIRTUAL "org/refal/plus/Expr" "rightSplit" "(I)Lorg/refal/plus/Expr$SplitIterator;">, 273 <MVvisitVarInsn <MV> &ASTORE s.i>; 274 (IFINTCMP s.op (e.arg1) (e.arg2) e.body) = 275 <Label> :: s.label, 276 <ExprIntToJBC e.arg1>, 277 <ExprIntToJBC e.arg2>, 278 s.op : { 279 "!=" = &"IF_ICMPEQ"; 280 "<" = &"IF_ICMPGE"; 281 ">" = &"IF_ICMPLE"; 282 } :: s.op, 283 <MVvisitJumpInsn <MV> s.op s.label>, 284 <ASAILToJBC e.body>, 285 <MVvisitLabel <MV> s.label>; 286 (IF t.cond e.body) = 287 <Label> :: s.label, 288 <CondToJBC t.cond> :: s.if, 289 <MVvisitJumpInsn <MV> s.if s.label>, 290 <ASAILToJBC e.body>, 291 <MVvisitLabel <MV> s.label>; 292 (FOR (e.contlabel) (e.breaklabel) () (e.step) e.body) = 235 293 { 236 294 e.contlabel : t.label = <BindLabel t.label>; … … 243 301 <Label> :: s.forlabel, 244 302 <MVvisitLabel <MV> s.forlabel>, 245 //<CondToJBC s.acc e.cond> : e, 246 <MVvisitJumpInsn <MV> &IFEQ s.breaklabel>, 303 { 304 e.step : (s.tag e.expr), s.tag : \{ INCITER; DECITER; } = 305 <LookupIterVar e.expr> : s.i s.i1 s.i2, 306 <MVvisitVarInsn <MV> &ALOAD s.i>, 307 <MVvisitInsn <MV> &DUP>, 308 <MVvisitMethodInsn <MV> &INVOKEVIRTUAL "org/refal/plus/Expr$SplitIterator" "getLeft" "()Lorg/refal/plus/Expr;">, 309 <MVvisitVarInsn <MV> &ASTORE s.i1>, 310 <MVvisitMethodInsn <MV> &INVOKEVIRTUAL "org/refal/plus/Expr$SplitIterator" "getRight" "()Lorg/refal/plus/Expr;">, 311 <MVvisitVarInsn <MV> &ASTORE s.i2>;; 312 }, 247 313 <ASAILToJBC e.body>, 248 314 <MVvisitLabel <MV> s.contlabel>, 249 //<StepToJBC e.step> : e,315 <StepToJBC e.step>, 250 316 <MVvisitJumpInsn <MV> &GOTO s.forlabel>, 251 317 <MVvisitLabel <MV> s.breaklabel>; … … 256 322 (s.tag t.label), s.tag : \{ CONTINUE; BREAK; } = 257 323 <MVvisitJumpInsn <MV> &GOTO <LookupLabel t.label>>; 324 RETFAIL = <MVvisitInsn <MV> &"ICONST_0"> <MVvisitInsn <MV> &IRETURN>; 258 325 (TRY e.body) = 259 326 ('try') ('{' ( … … 271 338 FATAL = 272 339 ('throw new RefalException ("'<? &ModuleName>'", "'<? &FuncName>'", "Unexpected fail");') : e; 273 (LSPLIT t.name (e.min) t.var1 t.var2) =274 <ExprRefToJBC t.name>;/* :: e.a (e.n),275 '_va_' <FreeIndex> :: e.newvar,276 <Bind &IterVars (t.name) (e.newvar t.var1 t.var2)>,277 <Box> :: s.acc,278 <ExprIntToJBC s.acc e.min> :: e.min,279 e.a <? s.acc>280 ('Expr.SplitIterator 'e.newvar' = 'e.n'.leftSplit('e.min');') : e;*/281 (RSPLIT t.name (e.min) t.var1 t.var2) =282 <ExprRefToJBC t.name>;/* :: e.a (e.n),283 '_va_' <FreeIndex> :: e.newvar,284 <Bind &IterVars (t.name) (e.newvar t.var1 t.var2)>,285 <Box> :: s.acc,286 <ExprIntToJBC s.acc e.min> :: e.min,287 e.a <? s.acc>288 ('Expr.SplitIterator 'e.newvar' = 'e.n'.rightSplit('e.min');') : e;*/289 (ASSIGN t.var e.expr) =290 <ExprRefToJBC e.expr>; /*:: e.a (e.jexpr),291 {292 <? &Ress> : e t.var e =293 e.a (<Rfp2Java t.var>'.assign ('e.jexpr');');294 e.a (<Lookup &Result t.var>'.assign ('e.jexpr');');295 e.a (<Rfp2Java t.var>' = 'e.jexpr';');296 } : e;*/297 (INT t.var e.expr) =298 <ExprIntToJBC e.expr>;/* :: e.expr,299 <? s.acc> ('int '<Rfp2Java t.var>' = 'e.expr';') : e;*/300 (EXPR t.var e.expr) =301 <ExprRefToJBC e.expr>; /* :: e.a (e.jexpr),302 e.a ('Expr '<Rfp2Java t.var>' = 'e.jexpr';') : e;*/303 (DEREF t.var e.expr (e.pos)) =304 <ExprRefToJBC e.expr>; /* :: e.a (e.jexpr),305 <Box> :: s.acc,306 <ExprIntToJBC s.acc e.pos> :: e.pos,307 e.a <? s.acc> ('Expr '<Rfp2Java t.var>' = (Expr) 'e.jexpr'.at ('e.pos');') : e;*/308 (SUBEXPR t.var e.expr (e.pos) (e.len)) =309 <ExprRefToJBC e.expr>,310 <ExprIntToJBC e.pos>,311 <ExprIntToJBC e.len>;312 //e.a <? s.acc> ('Expr '<Rfp2Java t.var>' = new Expr ('e.jexpr', 'e.pos', 'e.len');') : e;313 (DROP t.var) =314 (<VarToJBC t.var>'.drop ();') : e;315 340 (ERROR e.expr) = 316 341 <ExprRefToJBC e.expr>; … … 418 443 }; 419 444 420 CondToJBC s.acc expr = expr : {421 /*empty*/ = /*empty*/;422 (CALL t.name (e.args) (e.ress)) =423 <DeclareResults (e.ress)> :: e.decls (e.ress),424 <ExprArgsToJBC e.args Result e.ress> :: e.arrays (e.args),425 <Put s.acc e.arrays e.decls>,426 <NameToJBC t.name>' ('e.args')';427 (SYMBOL? e.expr (e.pos)) =428 <ExprRefToJBC e.expr>;/* :: e.a (e.jexpr),429 <Put s.acc e.a>,430 e.jexpr'.symbolAt ('<ExprIntToJBC s.acc e.pos>')';*/431 (CHECKITER e.expr) = ;432 //<Middle 0 2 <Lookup &IterVars e.expr>>'.isValid ()';433 (EQ e.expr1 (e.expr2) (e.pos)) =434 <ExprRefToJBC e.expr1>,// :: e.a1 (e.jexpr1),435 <ExprRefToJBC e.expr2>;/* :: e.a2 (e.jexpr2),436 <Put s.acc e.a1 e.a2>,437 e.jexpr1'.eq ('e.jexpr2', '<ExprIntToJBC s.acc e.pos>')'; */438 (TERMEQ e.expr1 (e.expr2) (e.pos)) =439 <ExprRefToJBC e.expr1>,// :: e.a1 (e.jexpr1),440 <ExprRefToJBC e.expr2>;/* :: e.a2 (e.jexpr2),441 <Put s.acc e.a1 e.a2>,442 e.jexpr1'.eq ('e.jexpr2', '<ExprIntToJBC s.acc e.pos> ')'; */443 (NOT e.cond) =444 '!' <CondToJBC s.acc e.cond> : e;445 (INFIX s.op e.args) =446 {447 s.op : \{ "+"; ""; "%"; "*"; "/"; },448 <InfixToJBC &ExprIntToJBC s.op e.args>' != 0' : e;449 s.op : \{ "&&"; ""; },450 <InfixToJBC &CondToJBC s.op e.args>;451 s.op : \{ "<"; ">"; "<="; ">="; "=="; "!="; },452 <InfixToJBC &ExprIntToJBC s.op e.args>;453 };454 expr = '(' <InfixToJBC s.acc &CondToJBC "&&" <Paren expr>> ')';455 };456 457 445 InfixToJBC s.arg2java s.op (e.arg) e.args = 458 446 s.op : \{ … … 462 450 "*" = &IMUL; 463 451 "/" = &IDIV; 464 s = &IAND;465 452 } :: s.jbcop, 466 453 <Apply s.arg2java e.arg> : e, … … 472 459 }; 473 460 461 CondToJBC { 462 (CALLFAILS (CALL t.name (e.exprs) (e.ress))) = &IFEQ; /* 463 '!RF_CALL (' <NameToCPP t.name> ', ' 464 <ArgsToCPP () Exprs e.exprs> ', ' 465 <ArgsToCPP () Vars e.ress> ')';*/ 466 (SYMBOL? e.expr (e.pos)) = 467 <ExprRefToJBC e.expr>, 468 <ExprIntToJBC e.pos>, 469 <MVvisitMethodInsn <MV> &INVOKEVIRTUAL "org/refal/plus/Expr" "symbolAt" "(I)Z">, 470 &IFEQ; 471 (ITERFAILS e.expr) = 472 <LookupIterVar e.expr> :: s.i s s, 473 <MVvisitVarInsn <MV> &ALOAD s.i>, 474 <MVvisitMethodInsn <MV> &INVOKEVIRTUAL "org/refal/plus/Expr$SplitIterator" "isValid" "()Z">, 475 &IFNE; 476 (EQ e.expr1 (e.expr2) (e.pos)) = 477 <ExprRefToJBC e.expr1>, 478 <ExprRefToJBC e.expr2>, 479 <ExprIntToJBC e.pos>, 480 <MVvisitMethodInsn <MV> &INVOKEVIRTUAL "org/refal/plus/Expr" "eq" "(Lorg/refal/plus/Expr;I)Z">, 481 &IFEQ; 482 (TERMEQ e.expr1 (e.expr2) (e.pos)) = 483 <ExprRefToJBC e.expr1>, 484 <ExprRefToJBC e.expr2>, 485 <ExprIntToJBC e.pos>, 486 <MVvisitMethodInsn <MV> &INVOKEVIRTUAL "org/refal/plus/Expr" "term_eq" "(Lorg/refal/plus/Expr;I)Z">, 487 &IFEQ; 488 (NOT t.cond) = 489 <CondToJBC t.cond> : { 490 &IFEQ = &IFNE; 491 &IFNE = &IFEQ; 492 }; 493 }; 494 495 474 496 StepToJBC { 475 497 /*empty*/ = /*empty*/; 476 (INCITER e.expr) = <Middle 0 2 <Lookup &IterVars e.expr>>'.next ()'; 477 (DECITER e.expr) = <Middle 0 2 <Lookup &IterVars e.expr>>'.prev ()'; 498 (s.tag e.expr), 499 s.tag : { 500 INCITER = "next"; 501 DECITER = "prev"; 502 } :: s.m = 503 <LookupIterVar e.expr> :: s.i s s, 504 <MVvisitVarInsn <MV> &ALOAD s.i>, 505 <MVvisitMethodInsn <MV> &INVOKEVIRTUAL "org/refal/plus/Expr$SplitIterator" s.m "()Lorg/refal/plus/Expr$SplitIterator;">, 506 <MVvisitInsn <MV> &POP>; 478 507 }; 479 508 … … 557 586 }; 558 587 559 IntArgsToJBC s.acc e.args =560 e.args (/*e.javaargs*/) $iter {561 e.args : (e.arg) e.rest =562 {563 e.rest : v = ', ';564 /*empty*/;565 } :: e.comma,566 e.rest (e.javaargs <ExprIntToJBC s.acc e.arg> e.comma);567 } :: e.args (e.javaargs),568 e.args : /*empty*/ =569 e.javaargs;570 571 588 ExprArgsToJBC e.args = 572 589 e.args (/*e.type*/) (/*e.javaargs*/) (/*e.arrays*/) $iter { … … 599 616 VarToJBC t.var = 600 617 <LookupVar t.var> :: s.type s.i, 601 <MVvisitVarInsn <MV> &ALOAD s.i>, 602 { 603 s.type : Result = 604 <MVvisitMethodInsn <MV> &INVOKEVIRTUAL "org/refal/plus/Result" "getExpr" "()Lorg/refal/plus/Expr;">;; 618 s.type : { 619 Result = 620 <MVvisitVarInsn <MV> &ALOAD s.i>, 621 <MVvisitMethodInsn <MV> &INVOKEVIRTUAL "org/refal/plus/Result" "getExpr" "()Lorg/refal/plus/Expr;">; 622 Expr = 623 <MVvisitVarInsn <MV> &ALOAD s.i>; 624 Int = 625 <MVvisitVarInsn <MV> &ILOAD s.i>; 605 626 }; 606 627
Note: See TracChangeset
for help on using the changeset viewer.