Package kiss.lang

Examples of kiss.lang.Type


  @Override
  public Type union(Type t) {
    // handle optimisable Null cases
    if (t instanceof Null) return this;
    if (t instanceof Maybe) {
      Type ot=((Maybe)t).type;
      if (ot==type) return this;
      if (ot.contains(type)) return t;
      if (type.contains(ot)) return this;
      t=ot; // fall through, just consider the non-null case
    }
    if (type.contains(t)) return this;
   
View Full Code Here


    int n=types.length;
    int cc=0;
    int rep=-1;
    for (int i=0; i<n; i++) {
      Type ti=types[i];
      if (t==ti) return this;
      if (t.contains(ti)) return this;
      if (ti.contains(t)) {
        cc++;
        rep=i;
      }
    }
    if (cc==n) return t; // fully contained by all types
View Full Code Here

  @Override
  public void validate() {
    int n=types.length;
    if (n<2) throw new KissException("Intersection must have at least two members");
    for (int i=0; i<n; i++) {
      Type t=types[i];
      t.validate();
      if (t instanceof Anything) throw new KissException(this+ " should not contain Anything");
    }
  }
View Full Code Here

  public Predicate(KFn fn) {
    this.pred=fn;
  }

  public Type create(KFn fn) {
    Type rt=fn.getReturnType();
    if (rt.cannotBeFalsey()) return Anything.INSTANCE;
    if (rt.cannotBeTruthy()) return Nothing.INSTANCE;
    return new Predicate(fn);
  }
View Full Code Here

 
  @Test public void testIntersections() {
    for (Type a:testTypes) {
      for (Type b: testTypes) {
        if (!(a.isWellBehaved()&&b.isWellBehaved())) continue;
        Type c=a.intersection(b);
        if (!c.equals(b.intersection(a))) throw new KissException(a+ " x "+b);
         assertEquals(c,b.intersection(a));
      }
    }
   
    for (Type a:testTypes) {
View Full Code Here

  }
 
  @Test public void testUnions() {
    for (Type a:testTypes) {
      for (Type b: testTypes) {
        Type c=a.union(b);
       
        for (Object o:testObjects) {
          if (a.checkInstance(o) || b.checkInstance(o)) {
            assertTrue("Union of "+a+" and "+b+" = "+c+ " should include "+o,c.checkInstance(o));
          }
        }
      }
    }
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

    if (cond.isConstant()) {
      return (KissUtils.truthy(cond.eval()))?doThen:doElse;
    }
    if (cond.isPure()) {
      // we can optimise away the test only if cond is pure (i.e. no side effects)
      Type t=cond.getType();
      if (t.cannotBeFalsey()) return doThen;
      if (t.cannotBeTruthy()) return doElse;
    }
   
    if ((cond==this.cond)&&(doThen==this.doThen)&&(doElse==this.doElse)) return this;

    return new If(cond,doThen,doElse);
View Full Code Here

TOP

Related Classes of kiss.lang.Type

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.