Package kiss.lang

Examples of kiss.lang.Expression


    return create(sym, value,body);
  }
 
  @Override
  public Expression optimise() {
    Expression b=body.optimise();
    Expression v=value.optimise();
    if (value.isPure()) {
      IPersistentSet bfree= b.accumulateFreeSymbols(PersistentHashSet.EMPTY);
      if (!(bfree.contains(sym))) {
        return b;
      }
View Full Code Here


    return body.compute(d, bindings);
  }
 
  @Override
  public Expression specialise(Type type) {
    Expression newBody=body.specialise(type);
    return update(sym,value,newBody);
  }
View Full Code Here

    return update(sym,value,newBody);
  }
   
  @Override
  public Expression substitute(IPersistentMap bindings) {
    Expression nv=value.substitute(bindings);
    if (nv==null) return null;
    bindings=bindings.without(sym);
    Expression nbody=body.substitute(bindings);
    if (nbody==null) return null;
   
    return update(sym,nv,nbody);
  }
View Full Code Here

  @Override
  public Expression substitute(IPersistentMap bindings) {
    for (Symbol s:syms) {
      bindings=bindings.without(s);
    }
    Expression nbody=body.substitute(bindings);
    if (nbody==null) return null;
   
    return update(nbody,syms,types);
  }
View Full Code Here

  public Expression optimise() {
    Expression[] es=new Expression[length];
    int j=0;
    boolean found=false;
    for (int i=0; i<length; i++) {
      Expression old=exps[i];
      Expression x=old.optimise();
      if (x!=old) found=true;
      // we can eliminate pure expressions in non-ending position
      if ((i==(length-1))||(!x.isPure())) {
        es[j++]=x;
      }
    }
    if ((!found)&&(j==length)) return this;
    if (j==1) return es[0];
View Full Code Here

  @Override
  public Expression specialise(Type type) {
    // specialise based on the last expression in the do block, since this defines the return value
    if (length==0) return null;
    Expression end=exps[length-1];
    Expression send=end.specialise(type);
    if (send==null) return null;
    if (send==end) return this;
    Expression[] nexps=exps.clone();
    nexps[length-1]=send;
    return create(nexps);
View Full Code Here

  }
 
  @Override
  public Expression substitute(IPersistentMap bindings) {
    int i=0;
    Expression nx=null;
    for (;i<length; i++) {
      Expression x=exps[i];
      nx=x.substitute(bindings);
      if (nx==null) return null;
      if (nx!=x) break;
    }
    if (i==length) return this; // no changes
    Expression[] nexps=exps.clone();
    nexps[i++]=nx;
    for (;i<length; i++) {
      Expression x=exps[i];
      nx=x.substitute(bindings);
      if (nx==null) return null;
      nexps[i]=nx;
    }
    return create(nexps);
  }
View Full Code Here

  }
 
  @Override
  public Expression substitute(IPersistentMap bindings) {
    int i=0;
    Expression nx=null;
    for (;i<length; i++) {
      Expression x=vals.get(i);
      nx=x.substitute(bindings);
      if (nx==null) return null;
      if (nx!=x) break;
    }
    if (i==length) return this; // no changes
    ArrayList<Expression> al=new ArrayList<Expression>();
    for (int j=0; j<i; j++) {
      al.add(vals.get(j));
    }
    al.add(nx);
    for (;i<length; i++) {
      Expression x=vals.get(i);
      nx=x.substitute(bindings);
      if (nx==null) return null;
      al.add(nx);
    }
    return create(al);
  }
View Full Code Here

  }
 
  @Override
  public Expression substitute(IPersistentMap bindings) {
    int i=0;
    Expression nxv=null;
    Expression nxk=null;
    for (;i<length; i++) {
      Expression k=keys.get(i);
      nxk=k.substitute(bindings);
      Expression x=vals.get(i);
      nxv=x.substitute(bindings);
     
      if (nxk==null) return null;
      if (nxk!=k) break;
      if (nxv==null) return null;
      if (nxv!=x) break;     
    }
    if (i==length) return this; // no changes
    ArrayList<Expression> alv=new ArrayList<Expression>();
    ArrayList<Expression> alk=new ArrayList<Expression>();
    for (int j=0; j<i; j++) {
      alk.add(keys.get(j));
      alv.add(vals.get(j));
    }
    alk.add(nxk);
    alv.add(nxv);
    for (;i<length; i++) {
      Expression k=keys.get(i);
      nxk=k.substitute(bindings);
      if (nxk==null) return null;
      alk.add(nxk);

      Expression x=vals.get(i);
      nxv=x.substitute(bindings);
      if (nxv==null) return null;
      alv.add(nxv);
    }
    return create(alk,alv);
  }
View Full Code Here

    return create(syms, nis,body);
  }
 
  @Override
  public Expression optimise() {
    Expression b=body.optimise();
    Expression[] is=initials.clone();
    for (int i=0; i<is.length; i++) {
      is[i]=is[i].optimise();
    }
   
View Full Code Here

TOP

Related Classes of kiss.lang.Expression

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.