Package kiss.lang.impl

Examples of kiss.lang.impl.KissException


  public void validate() {
    for (Object o : map) {
      Map.Entry<Symbol, Mapping> ent=(Entry<Symbol, Mapping>) o;
      Symbol key=ent.getKey();
      Mapping m=ent.getValue();
      if (m==null) throw new KissException("Unexcpected null mapping for symbol: "+key);
     
      // check free symbols equals dependencies
      IPersistentSet free=m.getExpression().accumulateFreeSymbols(PersistentHashSet.EMPTY);
      IPersistentSet ds=(IPersistentSet) dependencies.valAt(key);
      if (!free.equiv(ds)) {
        throw new KissException("Mismatched dependencies for symbol: "+key+" free="+free+" deps="+ds);
      }
     
      // check unbound dependencies are consistent
      IPersistentSet unbound=m.getUnbound();
      for (ISeq s=unbound.seq(); s!=null; s=s.next()) {
        Symbol sym=(Symbol)s.first();
        if (isBound(sym)) throw new KissException("Expected symbol to be unbound: "+sym);
      }
     
      // check reverse dependencies
      for (ISeq s=ds.seq(); s!=null; s=s.next()) {
        Symbol sym=(Symbol)s.first();
        IPersistentSet bs=(IPersistentSet) dependents.valAt(sym);
        if (!bs.contains(key)) throw new KissException("Missing back dependency from "+sym+"=>"+key);
      }
    }
  }
View Full Code Here


          } catch (KissException t) {
            // OK!
          }
        }       
      } catch (Throwable t) {
        throw new KissException("Error testing expression "+e,t);
      }
    }
  }
View Full Code Here

  public void testProperties() {
    for (Expression e:testExprs) {
      try {
        e.validate();   
      } catch (Throwable t) {
        throw new KissException("Error testing expression "+e,t);
      }
    }   
  }
View Full Code Here

      return JavaType.create((Class<Object>) form);
    }
    if (form instanceof ISeq) {
      return analyseTypeSeq((ISeq)form);
    }
    throw new KissException("Unrecognised type form: "+form);
  }
View Full Code Here

      String name=sym.getName();
      if (!name.contains(".")) name="java.lang."+name;
      Class<?> c=RT.classForName(name);
      if (c!=null) return JavaType.create(c);
    }
    throw new KissException("Unrecognised type symbol: "+sym);
  }
View Full Code Here

      return Union.create(types);
    } else if (sym.equals(Symbols.I)) {
      Type[] types=analyseSequenceOfTypes(al,1,al.size()-1);
      return Intersection.create(types);
    }
    throw new KissException("Unrecognised type form: "+s);   
  }
View Full Code Here

    if (first instanceof Symbol) {
      Symbol s=(Symbol)first;
      if (s.equals(Symbols.LET)) {
        IPersistentVector v=KissUtils.expectVector(RT.second(form));
        int vc=v.count();
        if ((vc&1)!=0) throw new KissException("let requires an even number of binding forms");
       
        // start with expression body
        Expression e = analyse(RT.nth(form, 2));
       
        for (int i=vc-2; i>=0; i-=2) {
          Symbol sym=KissUtils.expectSymbol(v.nth(i));
          Expression exp=analyse(v.nth(i+1));
          e= Let.create(sym, exp, e);
        }
        return e;
      }
     
      if (s.equals(Symbols.LOOP)) {
        IPersistentVector v=KissUtils.expectVector(RT.second(form));
        int vc=v.count();
        if ((vc&1)!=0) throw new KissException("let requires an even number of binding forms");
       
        Symbol[] syms=new Symbol[vc/2];
        Expression[] initials=new Expression[vc/2];
       
        for (int i=0; i<vc; i+=2) {
          syms[i]=KissUtils.expectSymbol(v.nth(i));
          initials[i+i]=analyse(v.nth(i+1));
        }
        Expression body = analyse(RT.nth(form, 2));
        return Loop.create(syms, initials, body);
      }
     
      if (s.equals(Symbols.RECUR)) {
        int vc=n-1;
        Expression[] values=new Expression[vc];
       
        for (int i=0; i<vc; i++) {
          values[i]=analyse(RT.nth(form,(i+1)));
        }
        return Recur.create(values);
      }
     
      if (s.equals(Symbols.RETURN)) {
        Expression value=analyse(RT.nth(form,1));
        return Return.create(value);
      }
     
      if (s.equals(Symbols.IF)) {
        switch (n) {
        case 4:
          return If.create(analyse(RT.nth(form, 1)), analyse(RT.nth(form, 2)), analyse(RT.nth(form, 3)));
        case 3:
          return If.create(analyse(RT.nth(form, 1)), analyse(RT.nth(form, 2)),Constant.NULL);
        default:
          throw new KissException("Wrong number of forms in if expression: "+n);
        }   
      }
     
      if (s.equals(Symbols.INSTANCE)) {
        switch (n) {
        case 3:
          return InstanceOf.create(analyseType(RT.nth(form, 1)), analyse(RT.nth(form, 2)));
        default:
          throw new KissException("Wrong number of forms in instance? expression: "+n);
        }   
      }
     
      if (s.equals(Symbols.DEF)) {
        if (n!=3) throw new KissException("Wrong number of forms in def expression: "+n);
        Symbol sym=(Symbol)RT.nth(form,1);
        return Def.create(sym,analyse(RT.nth(form, 2)));   
      }

      if (s.equals(Symbols.DO)) {
View Full Code Here

    return false;
  }

  @Override
  public Object eval(Environment e) {
    throw new KissException("Can't evaluate recur");
  }
View Full Code Here

    return false;
  }

  @Override
  public Object eval(Environment e) {
    throw new KissException("Can't evaluate reurn");
  }
View Full Code Here

    return s;
  }
 
  @Override
  public void validate() {
    if (length!=exps.length) throw new KissException("Mismatched length!");
  }
View Full Code Here

TOP

Related Classes of kiss.lang.impl.KissException

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.