Changeset 2682


Ignore:
Timestamp:
Apr 13, 2007, 9:30:52 PM (14 years ago)
Author:
orlov
Message:
  • Result class extends Expr.
  • Result.get_expr() method isn't needed any more and should be removed some day.
Location:
to-imperative/trunk/java
Files:
4 edited

Legend:

Unmodified
Added
Removed
  • to-imperative/trunk/java/org/refal/plus/Expr.java

    r2655 r2682  
    1111 */
    1212
    13 public final class Expr
     13public class Expr
    1414    implements Comparable, Cloneable
    1515{
    1616    public static final Expr empty = new Expr(0);
    1717
    18     private final Object[] terms;
    19 
    20     private final int start;
    21 
    22     private final int length;
     18    protected Object[] terms;
     19
     20    protected int start;
     21
     22    protected int length;
    2323
    2424    /*
     
    7171
    7272    public boolean isEmpty () {
     73        assert terms != null;
    7374        return length == 0;
    7475    }
     
    7879     */
    7980    public int getLen () {
     81        assert terms != null;
    8082        return length;
    8183    }
     
    8890     */
    8991    public Object at (int i) {
     92        assert terms != null;
    9093        assert 0 <= i && i < length;
    9194        return terms[start + i];
     
    99102     */
    100103    public boolean symbolAt (int i) {
     104        assert terms != null;
    101105        assert 0 <= i && i < length;
    102106        return !(terms[start + i] instanceof Expr);
     
    104108
    105109    public boolean equals (Object o) {
     110        assert terms != null;
    106111        return (o instanceof Expr) && equals((Expr) o);
    107112    }
     
    111116     */
    112117    public boolean equals (Expr e) {
     118        assert terms != null && e.terms != null;
    113119        if (length != e.length)
    114120            return false;
     
    146152     */
    147153    public boolean eq (Expr e, int i) {
     154        assert terms != null && e.terms != null;
    148155        assert i >= 0;
    149156        assert e.length - i >= length;
     
    181188     */
    182189    public boolean termEq (Expr e, int i) {
     190        assert terms != null && e.terms != null;
    183191        assert i >= 0;
    184192        assert i < e.length;
     
    192200    public int compareTo (Object o) {
    193201        Expr e = (Expr) o;
     202        assert terms != null && e.terms != null;
    194203//        if (equals(e))        // Check how this affects efficiency!
    195204//            return 0;
     
    246255     */
    247256    public Expr (Expr e1, Expr e2) {
     257        assert e1.terms != null && e2.terms != null;
    248258        length = e1.length + e2.length;
    249259        if (length == 0) {
     
    297307     */
    298308    public Expr (Expr e1, Object t2) {
     309        assert e1.terms != null;
    299310        length = e1.length + 1;
    300311        int e1_end = e1.start + e1.length;
     
    318329    public Expr(Expr e1, int i1, int len1, Expr e2, int i2, int len2) {
    319330        this(len1 + len2);
     331        assert e1.terms != null && e2.terms != null;
    320332        assert i1 >= 0;
    321333        assert len1 >= 0;
     
    460472     */
    461473    public Object[] toArray() {
     474        assert terms != null;
    462475        Object[] arr = new Object[length];
    463476        System.arraycopy(terms, start, arr, 0, length);
     
    469482     */
    470483    public void toArray (Object[] arr, int where, int what, int len) {
     484        assert terms != null;
    471485        assert length - len >= what;
    472486        System.arraycopy(terms, start + what, arr, where, len);
     
    478492
    479493    public StringBuffer toStringBuffer () {
     494        assert terms != null;
    480495        StringBuffer str = new StringBuffer(length);
    481496        for (int i = start, end = start + length; i < end; i++) {
     
    491506
    492507    public java.lang.String formattedRepresentation () {
     508        assert terms != null;
    493509        if (length == 0) return "";
    494510        StringBuffer str = new StringBuffer(2*length);
     
    535551
    536552    public SplitIterator leftSplit (int l) {
     553        assert terms != null;
    537554        return new SplitIterator(this, l);
    538555    }
    539556
    540557    public SplitIterator rightSplit (int r) {
     558        assert terms != null;
    541559        return new SplitIterator(this, length - r);
    542560    }
     
    580598    public Iterator iterator ()
    581599    {
     600        assert terms != null;
    582601        return new Iterator();
    583602    }
  • to-imperative/trunk/java/org/refal/plus/Result.java

    r2023 r2682  
    55package org.refal.plus;
    66
    7 public final class Result
     7public final class Result extends Expr
    88{
    9     private Expr expr;
    10 
    11     public Result ()
    12     {}
    13 
    14     public void assign (Expr e)
    15     {
    16         expr = e;
     9    /**
     10     * Creates uninitialized expression.
     11     * Should be initailized later by one of assign() methods.
     12     */
     13    public Result () {
     14        terms = null;
    1715    }
    1816
    19     public void assign (Object obj)
    20     {
    21         expr = new Expr(obj);
     17    public void assign(Expr e) {
     18        assert e.terms != null;
     19        assert terms == null;
     20        terms = e.terms;
     21        start = e.start;
     22        length = e.length;
    2223    }
    2324
    24     public void assign (Object[] arr)
    25     {
    26         expr = Expr.fromArray(arr);
     25    public void assign(Object obj) {
     26        assign(new Expr(obj));
     27    }
     28
     29    public void assign(Object[] arr) {
     30        assign(Expr.fromArray(arr));
    2731    }
    2832
    2933    /*
    30      * Do not copy an array.  Use with caution!
     34     * Do not copy an array. Use with caution!
    3135     */
    32     public void assignUnsafe (Object[] arr)
    33     {
    34         expr = Expr.fromArrayUnsafe(arr);
     36    public void assignUnsafe(Object[] arr) {
     37        assign(Expr.fromArrayUnsafe(arr));
    3538    }
    3639
    3740    public Expr getExpr ()
    3841    {
    39         return expr;
     42        return this;
    4043    }
    4144}
  • to-imperative/trunk/java/refal/plus/Box.java

    r2656 r2682  
    3838        Result res = new Result();
    3939        Get(box, res);
    40         Store (box, new Expr(res.getExpr(), e));
     40        Store (box, new Expr(res, e));
    4141    }
    4242}
  • to-imperative/trunk/java/refal/plus/StdIO.java

    r2656 r2682  
    588588          Result _v_Stream1 = new Result();
    589589          Stream.Stream (_c_3, new Expr(StdIn, new Expr(BigInteger.ONE)), _v_Stream1);
    590           Table.Bind (Buffers, StdIn, _v_Stream1.getExpr());
     590          Table.Bind (Buffers, StdIn, _v_Stream1);
    591591      } catch (RefalException _) {}
    592592  }
Note: See TracChangeset for help on using the changeset viewer.