Package kiss.lang

Examples of kiss.lang.Expression


    return s;
  }

  @Override
  public Expression substitute(IPersistentMap bindings) {
    Expression nBody=body.substitute(bindings);
    if (nBody==body) return this;
    if (nBody==null) return null;
    return create(type,nBody);
  }
View Full Code Here


  }
 

  public static Object eval(String s) {
    Object form=read(s);
    Expression ex=kiss.lang.Compiler.compile(Environment.EMPTY,form);
    return ex.eval();
  }
View Full Code Here

    return JavaType.BOOLEAN;
  }
 
  @Override
  public Expression optimise() {
    Expression body=this.body.optimise();
    Type bt=body.getType();
    if (type.contains(bt)) return Constant.TRUE;
    if (type.intersection(bt)==Nothing.INSTANCE) return Constant.FALSE;
    return update(type,body);
  }
View Full Code Here

    }
    return this;
  }
 
  public Expression optimise() {
    Expression nFunc=func.optimise();
   
    if (nFunc.isConstant()) {
      // IFn fn=(IFn)nFunc.eval();
      // TODO: macro expansion here??
    }
   
    Expression[] nParams=new Expression[arity];
    boolean maybeApply=true;
    for (int i=0; i<arity; i++) {
      Expression on=params[i];
      on=on.optimise();
      nParams[i]=on;
      if (on.isConstant()) {
        // OK
      } else {
        maybeApply=false;
      }
    }
View Full Code Here

    return s;
  }

  @Override
  public Expression substitute(IPersistentMap bindings) {
    Expression nfunc=func.substitute(bindings);
    Expression[] nParams=params.clone();
    for (int i=0; i<arity; i++) {
      nParams[i]=params[i].substitute(bindings);
    }
    return update(nfunc,nParams);
View Full Code Here

import clojure.lang.Symbol;

public class EnvironmentTests {

  @Test public void testDef() {
    Expression x=Def.create(Symbol.intern("foo"),Constant.create(1));
    Environment e=Environment.EMPTY;
   
    Environment e2=x.compute(e);
    assertEquals(1,e2.get(Symbol.intern("foo")));
    assertEquals(1,e2.getResult());
  }
View Full Code Here

 
  @Test
  public void testSpecialise() {
    for (Expression e:testExprs) {
      Type ert=e.getType();
      Expression se=e.specialise(e.getType());
      assertTrue("Specialise has widened return type!! "+e, ert.contains(se.getType()));
    }
  }
View Full Code Here

    checkNotConstant(Lookup.create("foo"));
    checkNotConstant(Def.create(Symbol.intern("foo"),Constant.create(1)));
  }
 
  private void checkNotConstant(Expression x) {
    Expression opt=x.optimise();
    assertFalse("Expression is constant: "+x,opt.isConstant());
  }
View Full Code Here

    Expression opt=x.optimise();
    assertFalse("Expression is constant: "+x,opt.isConstant());
  }
 
  private void checkConstant(Object expected,Expression x) {
    Expression opt=x.optimise();
    assertTrue("Expression not constant: "+x,opt.isConstant());
    assertEquals(expected,opt.eval());
  }
View Full Code Here

  @Test
  public void testIf() {
    assertEquals(2,If.create(Constant.create(null), Constant.create(1), Constant.create(2)).eval());
   
    ISeq s=KissUtils.createSeq(Symbol.intern("if"),Symbol.intern("nil"),1,2);
    Expression x=Analyser.analyse(s);
    assertEquals(2,x.eval());

  }
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.