Package kiss.lang

Examples of kiss.lang.Expression.eval()


  @Override
  public Expression optimise() {
    Expression b=body.optimise();
    Type bt=body.getType();
    if (b.isConstant()) {
      Object val=b.eval();
      if (type.checkInstance(val)) throw new KissException("Impossible to cast value "+val+" to type: "+type);
      // TODO: is this logic sound? what about interface casts?
      return b;
    }
    Type t=type;
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();
  }
 
  public static IPersistentVector expectVector(Object x) {
    if (x instanceof IPersistentVector) {
      return (IPersistentVector)x;
View Full Code Here

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

  @Test
  public void testIf() {
    assertEquals(2,If.create(Constant.create(null), Constant.create(1), Constant.create(2)).eval());
View Full Code Here

  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
Copyright © 2018 www.massapi.com. 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.