Package wyrl.core

Examples of wyrl.core.Type


    return target;
  }

  public int translate(int level, Expr.BinOp code, Environment environment,
      SpecFile file) {
    Type type = code.attribute(Attribute.Type.class).type;
    Type lhs_t = code.lhs.attribute(Attribute.Type.class).type;
    Type rhs_t = code.rhs.attribute(Attribute.Type.class).type;
    int lhs = translate(level, code.lhs, environment, file);

    String body;

    if (code.op == Expr.BOp.IS && code.rhs instanceof Expr.Constant) {
      // special case for runtime type tests
      Expr.Constant c = (Expr.Constant) code.rhs;
      Type test = (Type) c.value;
      int typeIndex = register(test);
      body = "Runtime.accepts(type" + typeIndex + ", automaton, r" + lhs
          + ", SCHEMA)";
    } else if (code.op == Expr.BOp.AND) {
      // special case to ensure short-circuiting of AND.
View Full Code Here


    return target;
  }

  public int translate(int level, Expr.NaryOp code, Environment environment,
      SpecFile file) {
    Type type = code.attribute(Attribute.Type.class).type;
    String body = "new Automaton.";

    if (code.op == Expr.NOp.LISTGEN) {
      body += "List(";
    } else if (code.op == Expr.NOp.BAGGEN) {
View Full Code Here

    return target;
  }

  public int translate(int level, Expr.ListAccess code,
      Environment environment, SpecFile file) {
    Type type = code.attribute(Attribute.Type.class).type;
    int src = translate(level, code.src, environment, file);
    int idx = translate(level, code.index, environment, file);
    src = coerceFromRef(level, code.src, src, environment);
    idx = coerceFromRef(level, code.index, idx, environment);
View Full Code Here

    return target;
  }

  public int translate(int level, Expr.ListUpdate code,
      Environment environment, SpecFile file) {
    Type type = code.attribute(Attribute.Type.class).type;
    int src = translate(level, code.src, environment, file);
    int idx = translate(level, code.index, environment, file);
    int value = translate(level, code.value, environment, file);

    src = coerceFromRef(level, code.src, src, environment);
View Full Code Here

    return target;
  }

  public int translate(int level, Expr.Constructor code,
      Environment environment, SpecFile file) {
    Type type = code.attribute(Attribute.Type.class).type;
    String body;

    if (code.argument == null) {
      body = code.name;
    } else {
View Full Code Here

      Environment environment, SpecFile file) {
    Integer operand = environment.get(code.var);
    if (operand != null) {
      return operand;
    } else {
      Type type = code.attribute(Attribute.Type.class).type;
      int target = environment.allocate(type);
      myOut(level, type2JavaType(type) + " r" + target + " = " + code.var
          + ";");
      return target;
    }
View Full Code Here

    }
  }

  public int translate(int level, Expr.Substitute code,
      Environment environment, SpecFile file) {
    Type type = code.attribute(Attribute.Type.class).type;

    // first, translate all subexpressions and make sure they are
    // references.
    int src = translate(level, code.src, environment, file);
    src = coerceFromValue(level, code.src, src, environment);
View Full Code Here

    return target;
  }

  public int translate(int level, Expr.TermAccess code,
      Environment environment, SpecFile file) {
    Type type = code.attribute(Attribute.Type.class).type;

    // first translate src expression, and coerce to a value
    int src = translate(level, code.src, environment, file);
    src = coerceFromRef(level, code.src, src, environment);
View Full Code Here

    return target;
  }

  public int translate(int level, Expr.Comprehension expr,
      Environment environment, SpecFile file) {
    Type type = expr.attribute(Attribute.Type.class).type;
    int target = environment.allocate(type);

    // first, translate all source expressions
    int[] sources = new int[expr.sources.size()];
    for (int i = 0; i != sources.length; ++i) {
      Pair<Expr.Variable, Expr> p = expr.sources.get(i);
      int operand = translate(level, p.second(), environment, file);
      operand = coerceFromRef(level, p.second(), operand, environment);
      sources[i] = operand;
    }

    // TODO: initialise result set
    myOut(level, "Automaton.List t" + target + " = new Automaton.List();");
    int startLevel = level;

    // initialise result register if needed
    switch (expr.cop) {
    case NONE:
      myOut(level, type2JavaType(type) + " r" + target + " = true;");
      myOut(level, "outer:");
      break;
    case SOME:
      myOut(level, type2JavaType(type) + " r" + target + " = false;");
      myOut(level, "outer:");
      break;
    }

    // second, generate all the for loops
    for (int i = 0; i != sources.length; ++i) {
      Pair<Expr.Variable, Expr> p = expr.sources.get(i);
      Expr.Variable variable = p.first();
      Expr source = p.second();
      Type.Collection sourceType = (Type.Collection) source
          .attribute(Attribute.Type.class).type;
      Type elementType = variable.attribute(Attribute.Type.class).type;
      int index = environment.allocate(elementType, variable.var);
      myOut(level++, "for(int i" + index + "=0;i" + index + "<r"
          + sources[i] + ".size();i" + index + "++) {");
      String rhs = "r" + sources[i] + ".get(i" + index + ")";
      // FIXME: need a more general test for a reference type
View Full Code Here

    throw new RuntimeException("unknown type encountered: " + type);
  }

  public int coerceFromValue(int level, Expr expr, int register,
      Environment environment) {
    Type type = expr.attribute(Attribute.Type.class).type;
    if (type instanceof Type.Ref) {
      return register;
    } else {
      Type.Ref refType = Type.T_REF(type);
      int result = environment.allocate(refType);
View Full Code Here

TOP

Related Classes of wyrl.core.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.