Changeset 2357


Ignore:
Timestamp:
Feb 9, 2007, 9:44:40 PM (14 years ago)
Author:
yura
Message:
  • Perm- Advances in Java-bytecode generation:
Location:
to-imperative/trunk
Files:
2 deleted
5 edited

Legend:

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

    r2355 r2357  
    584584};
    585585
    586 $func Const-Expr-Aux (e.accum) e.expr = (e.arrays) e.java-expr;
     586$func Const-Term-To-JBC t.term = ;
     587$func Get-String-From-Const-Expr e.expr = (e.chars) e.expr;
     588$func Convert-Const-Expr e.expr = e.expr;
    587589
    588590Const-Expr-To-JBC {
    589591  /*empty*/ = <MVvisitFieldInsn <MV> &GETSTATIC "org/refal/plus/Expr" "empty" "Lorg/refal/plus/Expr;">;
    590   /*(SUBEXPR t.name s.pos s.len) =
     592  (SUBEXPR t.name s.pos s.len) =
    591593    t.name : \{
    592       (REF (s.module s.name)) = <Qualified-Module-Name s.module> s.name;
    593       (STATIC (e)) = <To-Word <Intersperse ('/') <? &Module-Name>>> t.term;
     594      (REF (s.module s.obj-name)) = <Qualified-Module-Name s.module> s.obj-name;
     595      (STATIC (e)) = <To-Word <Intersperse ('/') <? &Module-Name>>> t.name;
    594596    } :: s.module t.name =
    595597    <To-Word <Rfp2Java t.name>> :: s.name,
     598    <MVvisitTypeInsn <MV> &NEW "org/refal/plus/Expr">,
     599    <MVvisitInsn <MV> &DUP>,
    596600    <MVvisitFieldInsn <MV> &GETSTATIC s.module s.name "Lorg/refal/plus/Expr;">,
    597601    <MVvisitLdcInsn <MV> <Integer s.pos>>,
     
    601605                  //       не превышают допустимых величин.
    602606                  //       Задавать эти величины опциями.
    603   e.expr =
    604     <Const-Expr-Aux () e.expr> : {
     607
     608  e.expr = <Convert-Const-Expr e.expr> :: e.expr,
    605609    <MVvisitLdcInsn <MV> <Integer <Length e.expr>>>,
    606610    <MVvisitTypeInsn <MV> &ANEWARRAY "org/refal/plus/Expr">,
     
    609613        <MVvisitInsn <MV> &DUP>,
    610614        <MVvisitLdcInsn <MV> <Integer s.i>>,
    611         <Term-Ref-To-JBC t.term>,
     615        <Const-Term-To-JBC t.term>,
    612616        <MVvisitInsn <MV> &AASTORE>,
    613617        <"+" s.i 1> e.rest;
    614618    } :: s.i e.expr,
    615     e.expr : empty =
    616     <MVvisitMethodInsn <MV> &INVOKESTATIC "org/refal/plus/Expr" "concat" "([Lorg/refal/plus/Expr;)Lorg/refal/plus/Expr;">;*/
     619    e.expr : /*empry*/ =
     620    <MVvisitMethodInsn <MV> &INVOKESTATIC "org/refal/plus/Expr" "concat" "([Lorg/refal/plus/Expr;)Lorg/refal/plus/Expr;">;
    617621
    618622
     
    631635};
    632636
    633 Const-Expr-Aux (e.accum) e.expr, {
    634 /*  e.expr : s.sym e.rest, <Char? s.sym> =
    635     <Const-Expr-Aux (e.accum <Symbol-To-JBC s.sym>) e.rest>;
    636   e.accum : v =
    637     <Const-Expr-Aux () e.expr> :: (e.arrays) e.j-expr,
    638     (e.arrays) ('Expr.fromSequence ("'e.accum'")') e.j-expr;
    639   e.expr : t.item e.rest, t.item : {
    640     (PAREN e.paren-expr) =
    641       <Const-Expr-To-JBC e.paren-expr> :: e.arrays (e.j-expr),
    642       (e.arrays) ('new Expr ('e.j-expr')');
    643     (REF t.name) =
    644       () (<Name-To-JBC t.name>);
    645     (STATIC e) =
    646       () (<Rfp2Java t.item>);
    647     (FUNC? t.name) = () ('new Expr (new Func () {'
    648       ('public boolean eval (Expr arg, Result res) throws RefalException {'
    649         ('return '<Name-To-JBC t.name>' (arg, res);')
    650       '}') '})');
    651     (FUNC t.name) = () ('new Expr (new Func () {'
    652       ('public boolean eval (Expr arg, Result res) throws RefalException {'
    653         ((<Name-To-JBC t.name>' (arg, res);')
    654          ('return true;'))
    655       '}') '})');
    656     s.sym, {
    657       <Int? s.sym> =
    658         {
    659           <? &Int> : BigInteger =
    660             <Bind &Inputs ('java.math.BigInteger') ()>;;
    661         },
    662         () ('new Expr (new '<? &Int>' ("'s.sym'"))');
    663       <Word? s.sym> =
    664         () ('new Expr (new Word ("'<Symbol-To-JBC s.sym>'"))');
    665     };
    666   } :: (e.arrays) e.java-item =
    667     <Const-Expr-Aux () e.rest> :: (e.new-arrays) e.java-rest,
    668     (e.arrays e.new-arrays) e.java-item e.java-rest;*/
    669   = () /*empty*/;
     637Get-String-From-Const-Expr e.expr,
     638  () e.expr F $iter {
     639    e.expr : s.sym e.rest, <Char? s.sym> = (e.chars <Symbol-To-JBC s.sym>) e.rest F;
     640    (e.chars) e.expr T;
     641  } :: (e.chars) e.expr s.flag, s.flag : T,
     642  (e.chars) e.expr;
     643
     644Convert-Const-Expr e.expr,
     645  () e.expr $iter {
     646    <Get-String-From-Const-Expr e.expr> :: (e.chars) e.expr,
     647      {
     648        e.chars : v = (e.res (CHARS e.chars)) e.expr;
     649        e.expr : t.term e.rest, (e.res t.term) e.rest;
     650      };
     651  } :: (e.res) e.expr, e.expr : /*empry*/,
     652  e.res;
     653
     654Const-Term-To-JBC {
     655  (CHARS e.chars) =
     656    <MVvisitLdcInsn <MV> <StringToObject <To-Word e.chars>>>,
     657    <MVvisitMethodInsn <MV> &INVOKESTATIC "org/refal/plus/Expr" "fromSequence" "(Ljava/lang/CharSequence;)Lorg/refal/plus/Expr;">;
     658  (PAREN e.expr) =
     659    <MVvisitTypeInsn <MV> &NEW "org/refal/plus/Expr">,
     660    <MVvisitInsn <MV> &DUP>,
     661    <Const-Expr-To-JBC e.expr>,
     662    <MVvisitMethodInsn <MV> &INVOKESPECIAL "org/refal/plus/Expr" "<init>" "(Lorg/refal/plus/Expr;)V">;
     663  t.term, t.term : \{
     664    (REF (s.module s.obj-name)) = <Qualified-Module-Name s.module> s.obj-name;
     665    (STATIC (e)) = <To-Word <Intersperse ('/') <? &Module-Name>>> t.term;
     666  } :: s.module t.name =
     667    <To-Word <Rfp2Java t.name>> :: s.name,
     668    <MVvisitFieldInsn <MV> &GETSTATIC s.module s.name "Lorg/refal/plus/Expr;">;
     669/*
     670  (FUNC? t.name) = () ('new Expr (new Func () {'
     671    ('public boolean eval (Expr arg, Result res) throws RefalException {'
     672      ('return '<Name-To-JBC t.name>' (arg, res);')
     673    '}') '})');
     674  (FUNC t.name) = () ('new Expr (new Func () {'
     675    ('public boolean eval (Expr arg, Result res) throws RefalException {'
     676      ((<Name-To-JBC t.name>' (arg, res);')
     677       ('return true;'))
     678    '}') '})');*/
     679  s.sym, {
     680    <Int? s.sym> =
     681      {
     682        <? &Int> : BigInteger =
     683          //<Bind &Inputs ('java.math.BigInteger') ()>;
     684          <MVvisitTypeInsn <MV> &NEW "org/refal/plus/Expr">,
     685          <MVvisitInsn <MV> &DUP>,
     686          <MVvisitLdcInsn <MV> <Integer s.sym>>,
     687          <MVvisitInsn <MV> &I2L>;
     688          <MVvisitMethodInsn <MV> &INVOKESTATIC "java/math/BigInteger" "valueOf" "(J)Ljava/math/BigInteger;">,
     689          <MVvisitMethodInsn <MV> &INVOKESPECIAL "org/refal/plus/Expr" "<init>" "(Ljava/math/BigInteger;)V">;
     690        //    () ('new Expr (new '<? &Int>' ("'s.sym'"))');
     691      };
     692    <Word? s.sym> =
     693      <MVvisitTypeInsn <MV> &NEW "org/refal/plus/Expr">,
     694      <MVvisitInsn <MV> &DUP>,
     695      <MVvisitTypeInsn <MV> &NEW "org/refal/plus/Word">,
     696      <MVvisitInsn <MV> &DUP>,
     697      <MVvisitLdcInsn <MV> <To-Word <Symbol-To-JBC s.sym>>>,
     698      <MVvisitMethodInsn <MV> &INVOKESPECIAL "org/refal/plus/Word" "<init>" "(Ljava.lang.String;)V">,
     699      <MVvisitMethodInsn <MV> &INVOKESPECIAL "org/refal/plus/Expr" "<init>" "(Lorg/refal/plus/Word;)V">;
     700  };
    670701};
    671702
  • to-imperative/trunk/java/org/refal/plus/library/Java.java

    r2308 r2357  
    3232        res.assign(null_expr);
    3333    }
     34
     35    public static void StringToObject (Expr expr, Result res)
     36    {
     37        Word word = (Word)expr.at(0);
     38        res.assign(word.toString());
     39    }
    3440}
  • to-imperative/trunk/lib/Java.rf

    r2318 r2357  
    22
    33Null = 0;
     4StringToObject s.str = s.str;
  • to-imperative/trunk/lib/Java.rfi

    r2309 r2357  
    22
    33$func Null = s;
    4 
     4$func StringToObject s = s;
  • to-imperative/trunk/samples/perm.rf

    r760 r2357  
    1010      $fail;
    1111    =
    12 //      <PrintLN e1>
     12      <PrintLN e1>
    1313    ;
    1414  };;
    1515};
    1616
    17 Main = <Perm () ('1234567890')>;
     17Main = <Perm () ('12345')>;
Note: See TracChangeset for help on using the changeset viewer.