Changeset 3698


Ignore:
Timestamp:
Apr 14, 2008, 9:36:41 PM (13 years ago)
Author:
yura
Message:
  • Refal Box is Reference<org.refal.plus.Box>.
Location:
to-imperative/trunk/java/java
Files:
5 edited

Legend:

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

    r3683 r3698  
    1 /*
    2  * $Id$
    3  *
    4  * vim: set syntax=java expandtab shiftwidth=4 tabstop=4:
    5  */
     1// $Id$
    62
    73package org.refal.plus;
    84
    9 public class Box implements Comparable<Box> {
     5public class Box {
    106    public Expr expr;
    117
     
    2319
    2420    @Override
    25     public java.lang.String toString () {
    26         return '&' + super.toString();
    27     }
    28 
    29     public int compareTo (Box box) {
    30         return RefalRuntime.compare(this, box);
    31     }
    32 
    33     public static class Named extends Box {
    34         static {
    35             RefalRuntime.setPriorityTheSame(Named.class, Box.class);
    36         }
    37 
    38         private final String name;
    39 
    40         public Named (String n) {
    41             super();
    42             name = n;
    43         }
    44 
    45         public Named (String n, Expr expr) {
    46             super(expr);
    47             name = n;
    48         }
    49 
    50         public Named (String n, Comparable<?> obj) {
    51             super(obj);
    52             name = n;
    53         }
    54 
    55         @Override
    56         public String toString () {
    57             return "&" + name;
    58         }
     21    public String toString () {
     22        return expr.toString();
    5923    }
    6024}
  • to-imperative/trunk/java/java/org/refal/plus/Symbol.java

    r3691 r3698  
    1919    }
    2020
     21
    2122    public static Comparable<?> newBox (String name) {
    22         return new Box.Named(name);
     23        return new Reference<Box>(name, new Box());
    2324    }
    2425
     
    4445    }
    4546
     47    public static Comparable<?> newBox (Comparable<?> term) {
     48        return new Reference<Box>(new Box(term));
     49    }
    4650   
     51
     52    public static Box getBox (Expr expr) throws ClassCastException {
     53        assert expr.length() == 1;
     54        return (Box) ((Reference<?>) expr.at(0)).object;
     55    }
     56
    4757    public static Table getTable (Expr expr) throws ClassCastException {
    4858        assert expr.length() == 1;
  • to-imperative/trunk/java/java/refal/plus/Box.java

    r3423 r3698  
    1 /*
    2  * $Id$
    3  *
    4  * vim: set syntax=java expandtab shiftwidth=4 tabstop=4:
    5  */
     1// $Id$
    62
    73package refal.plus;
     
    117import org.refal.plus.RefalFormat;
    128import org.refal.plus.Result;
     9import org.refal.plus.Symbol;
    1310
    1411public final class Box {
     
    1916    @RefalFormat("$func Box e.Exp = s.Box;")
    2017    public static void Box (Expr e, Result res) {
    21         res.assign(new org.refal.plus.Box(e));
     18        Symbol.setToResult(new org.refal.plus.Box(e), res);
    2219    }
    2320
    2421    @RefalFormat("$func Get s.Box = e.Exp;")
    2522    public static void Get (Expr box, Result res) throws RefalException {
    26         assert box.length() == 1;
    2723        try {
    28             res.assign(((org.refal.plus.Box) box.at(0)).expr);
     24            res.assign(Symbol.getBox(box).expr);
    2925        } catch (ClassCastException _) {
    3026            throw new RefalException("Box", "Get", "Invalid argument");
     
    3632        assert box.length() == 1;
    3733        try {
    38             ((org.refal.plus.Box) box.at(0)).expr = e;
     34            Symbol.getBox(box).expr = e;
    3935        } catch (ClassCastException _) {
    4036            throw new RefalException("Box", "Store", "Invalid argument");
     
    4339
    4440    @RefalFormat("$func Put s.Box e.Exp = ;")
    45     public static void Put (Expr box, Expr e) throws RefalException {
    46         Result res = new Result();
    47         Get(box, res);
    48         Store(box, Expr.concat(res.getExpr(), e));
     41    public static void Put (Expr b, Expr e) throws RefalException {
     42        org.refal.plus.Box box = Symbol.getBox(b);
     43        box.expr = Expr.concat(box.expr, e);
    4944    }
    5045}
  • to-imperative/trunk/java/java/refal/plus/Class.java

    r3423 r3698  
    1 /*
    2  * $Id$
    3  *
    4  * vim: set syntax=java expandtab shiftwidth=4 tabstop=4:
    5  */
     1// $Id$
    62
    73package refal.plus;
    84
    95import java.lang.String;
    10 import java.util.List;
    11 import java.util.Map;
     6import java.math.BigInteger;
    127
     8import org.refal.plus.Box;
     9import org.refal.plus.Channel;
    1310import org.refal.plus.Expr;
     11import org.refal.plus.Func;
    1412import org.refal.plus.RefalFormat;
    1513import org.refal.plus.Reference;
     14import org.refal.plus.Table;
     15import org.refal.plus.Vector;
    1616
    1717public final class Class {
     
    1919    private Class () {}
    2020
     21    /** Returns <code>null</code> if argument is not a term */
     22    private static Comparable<?> getTerm (Expr e) {
     23        if (e.length() == 1)
     24            return e.at(0);
     25        return null;
     26    }
     27
     28    /** Returns <code>null</code> if argument is not the Reference */
     29    private static Object getObject (Expr e) {
     30        if (e.length() == 1) {
     31            Comparable<?> term = e.at(0);
     32            if (term instanceof Reference)
     33                return ((Reference<?>) e.at(0)).object;
     34        }
     35        return null;
     36    }
     37
    2138    @RefalFormat("$func? IsBox e.Exp = ;")
    2239    public static boolean IsBox (Expr e) {
    23         return e.length() == 1 && e.at(0) instanceof org.refal.plus.Box;
     40        return getObject(e) instanceof Box;
    2441    }
    2542
    2643    @RefalFormat("$func? IsChannel e.Exp = ;")
    2744    public static boolean IsChannel (Expr e) {
    28         return e.length() == 1 && e.at(0) instanceof org.refal.plus.Channel;
     45        return getTerm(e) instanceof Channel;
    2946    }
    3047
    3148    @RefalFormat("$func? IsChar e.Exp = ;")
    3249    public static boolean IsChar (Expr e) {
    33         return e.length() == 1 && e.at(0) instanceof Character;
     50        return getTerm(e) instanceof Character;
    3451    }
    3552
    3653    @RefalFormat("$func? IsDigit e.Exp = ;")
    3754    public static boolean IsDigit (Expr e) {
    38         try {
    39             return e.length() == 1 && Character.isDigit(((Character) e.at(0)).charValue());
    40         } catch (ClassCastException _) {
    41             return false;
    42         }
     55        Comparable<?> term = getTerm(e);
     56        if (term instanceof Character)
     57            return Character.isDigit(((Character) term).charValue());
     58        return false;
    4359    }
    4460
    4561    @RefalFormat("$func? IsFunc e.Exp = ;")
    4662    public static boolean IsFunc (Expr e) {
    47         return e.length() == 1 && e.at(0) instanceof org.refal.plus.Func;
     63        return getTerm(e) instanceof Func;
    4864    }
    4965
    5066    @RefalFormat("$func? IsInt e.Exp = ;")
    5167    public static boolean IsInt (Expr e) {
    52         return e.length() == 1 && e.at(0) instanceof java.math.BigInteger;
     68        return getTerm(e) instanceof BigInteger;
    5369    }
    5470
    5571    @RefalFormat("$func? IsLetter e.Exp = ;")
    5672    public static boolean IsLetter (Expr e) {
    57         try {
    58             return e.length() == 1 && Character.isLetter(((Character) e.at(0)).charValue());
    59         } catch (ClassCastException _) {
    60             return false;
    61         }
     73        Comparable<?> term = getTerm(e);
     74        if (term instanceof Character)
     75            return Character.isLetter(((Character) term).charValue());
     76        return false;
    6277    }
    6378
    64     @SuppressWarnings("unchecked")
    6579    @RefalFormat("$func? IsString e.Exp = ;")
    6680    public static boolean IsString (Expr e) {
    67         try {
    68             return e.length() == 1 && (((Reference<StringBuffer>) e.at(0)).object instanceof StringBuffer);
    69         } catch (ClassCastException _) {
    70             return false;
    71         }
     81        return getObject(e) instanceof StringBuffer;
    7282    }
    7383
    74     @SuppressWarnings("unchecked")
    7584    @RefalFormat("$func? IsTable e.Exp = ;")
    7685    public static boolean IsTable (Expr e) {
    77         try {
    78             return e.length() == 1 && (((Reference<Map<Expr, Expr>>) e.at(0)).object instanceof Map);
    79         } catch (ClassCastException _) {
    80             return false;
    81         }
     86        return getObject(e) instanceof Table;
    8287    }
    8388
    84     @SuppressWarnings("unchecked")
    8589    @RefalFormat("$func? IsVector e.Exp = ;")
    8690    public static boolean IsVector (Expr e) {
    87         try {
    88             return e.length() == 1 && (((Reference<List<Expr>>) e.at(0)).object instanceof List);
    89         } catch (ClassCastException _) {
    90             return false;
    91         }
     91        return getObject(e) instanceof Vector;
    9292    }
    9393
  • to-imperative/trunk/java/java/refal/plus/File.java

    r3693 r3698  
    1 /*
    2  * $Id$
    3  *
    4  * vim: set syntax=java expandtab shiftwidth=4 tabstop=4:
    5  */
     1// $Id$
    62
    73package refal.plus;
     
    1511import org.refal.plus.RefalFormat;
    1612import org.refal.plus.Result;
     13import org.refal.plus.Symbol;
    1714
    1815public final class File {
     
    2219    /** {@value} Ex: ':' or ';' */
    2320    @RefalFormat("$box PathSeparator;")
    24     public static final Expr PathSeparator = new Expr(new org.refal.plus.Box(new Character(
    25             java.io.File.pathSeparatorChar)));
     21    public static final Expr PathSeparator = new Expr(Symbol.newBox(new Character(java.io.File.pathSeparatorChar)));
    2622
    2723    /** {@value} Ex: '/' or '\\' */
    2824    @RefalFormat("$box DirSeparator;")
    29     public static final Expr DirSeparator = new Expr(new org.refal.plus.Box(new Character(java.io.File.separatorChar)));
     25    public static final Expr DirSeparator = new Expr(Symbol.newBox(new Character(java.io.File.separatorChar)));
    3026
    3127    @RefalFormat("$func? Exists e.fname = ;")
Note: See TracChangeset for help on using the changeset viewer.