Package wyil.lang

Examples of wyil.lang.Constant$Null


    Token name = match(Identifier);
    match(Is);
    Expr e = parseMultiExpression(wf, new HashSet<String>(), false);
    int end = index;
    matchEndLine();
    WhileyFile.Declaration declaration = wf.new Constant(modifiers, e,
        name.text, sourceAttr(start, end - 1));
    wf.add(declaration);
  }
View Full Code Here


   * @return
   * @throws IOException
   */
  private Constant resolveAsConstant(NameID key, HashSet<NameID> visited)
      throws IOException, ResolveError {
    Constant result = constantCache.get(key);
    if (result != null) {
      return result;
    } else if (visited.contains(key)) {
      throw new ResolveError("cyclic constant definition encountered ("
          + key + " -> " + key + ")");
View Full Code Here

          syntaxError(errorMessage(UNKNOWN_VARIABLE), context, expr);
          return null;
        }
      } else if (expr instanceof Expr.BinOp) {
        Expr.BinOp bop = (Expr.BinOp) expr;
        Constant lhs = resolveAsConstant(bop.lhs, context, visited);
        Constant rhs = resolveAsConstant(bop.rhs, context, visited);
        return evaluate(bop, lhs, rhs, context);
      } else if (expr instanceof Expr.UnOp) {
        Expr.UnOp uop = (Expr.UnOp) expr;
        Constant lhs = resolveAsConstant(uop.mhs, context, visited);
        return evaluate(uop, lhs, context);
      } else if (expr instanceof Expr.Set) {
        Expr.Set nop = (Expr.Set) expr;
        ArrayList<Constant> values = new ArrayList<Constant>();
        for (Expr arg : nop.arguments) {
          values.add(resolveAsConstant(arg, context, visited));
        }
        return Constant.V_SET(values);
      } else if (expr instanceof Expr.List) {
        Expr.List nop = (Expr.List) expr;
        ArrayList<Constant> values = new ArrayList<Constant>();
        for (Expr arg : nop.arguments) {
          values.add(resolveAsConstant(arg, context, visited));
        }
        return Constant.V_LIST(values);
      } else if (expr instanceof Expr.Record) {
        Expr.Record rg = (Expr.Record) expr;
        HashMap<String, Constant> values = new HashMap<String, Constant>();
        for (Map.Entry<String, Expr> e : rg.fields.entrySet()) {
          Constant v = resolveAsConstant(e.getValue(), context,
              visited);
          if (v == null) {
            return null;
          }
          values.put(e.getKey(), v);
        }
        return Constant.V_RECORD(values);
      } else if (expr instanceof Expr.Tuple) {
        Expr.Tuple rg = (Expr.Tuple) expr;
        ArrayList<Constant> values = new ArrayList<Constant>();
        for (Expr e : rg.fields) {
          Constant v = resolveAsConstant(e, context, visited);
          if (v == null) {
            return null;
          }
          values.add(v);
        }
        return Constant.V_TUPLE(values);
      } else if (expr instanceof Expr.Map) {
        Expr.Map rg = (Expr.Map) expr;
        HashSet<Pair<Constant, Constant>> values = new HashSet<Pair<Constant, Constant>>();
        for (Pair<Expr, Expr> e : rg.pairs) {
          Constant key = resolveAsConstant(e.first(), context,
              visited);
          Constant value = resolveAsConstant(e.second(), context,
              visited);
          if (key == null || value == null) {
            return null;
          }
          values.add(new Pair<Constant, Constant>(key, value));
View Full Code Here

      String target;
      int opr;
      int cnt;
      int idx;
      String alt;
      Constant con;
      String nam;

      //bodyAddLineNL(  "// HELP needed for Switch"  );
      Codes.Switch cod = (Codes.Switch) codIn;
      branches = cod.branches;
View Full Code Here

    }

    public void writeCodeConstant(Code codIn){
      String tmp;
      int targ;
      Constant val;
      String nam;

      Codes.Const cod = (Codes.Const) codIn;
      targ = cod.target();
      val = cod.constant;
View Full Code Here

    for(Map.Entry<JvmConstant,Integer> entry : constants.entrySet()) {
      JvmConstant c = entry.getKey();
      if(c instanceof JvmValue) {
        nvalues++;
        Constant constant = ((JvmValue)c).value;
        int index = entry.getValue();

        // First, create the static final field that will hold this constant
        String name = "constant$" + index;
        ArrayList<Modifier> fmods = new ArrayList<Modifier>();
        fmods.add(Modifier.ACC_PRIVATE);
        fmods.add(Modifier.ACC_STATIC);
        fmods.add(Modifier.ACC_FINAL);
        JvmType type = convertType(constant.type());
        ClassFile.Field field = new ClassFile.Field(name, type, fmods);
        cf.fields().add(field);

        // Now, create code to intialise this field
        translate(constant,0,lambdas,bytecodes);
View Full Code Here

    return freeSlot;
  }

  private void translate(Codes.Const c, int freeSlot, HashMap<JvmConstant,Integer> constants,
      ArrayList<ClassFile> lambdas, ArrayList<Bytecode> bytecodes) {
    Constant constant = c.constant;
    JvmType jt = convertType(constant.type());

    if (constant instanceof Constant.Decimal || constant instanceof Constant.Bool
        || constant instanceof Constant.Null || constant instanceof Constant.Byte) {
      translate(constant,freeSlot,lambdas,bytecodes);
    } else {
      int id = JvmValue.get(constant,constants);
      String name = "constant$" + id;
      bytecodes.add(new Bytecode.GetField(owner, name, jt, Bytecode.FieldMode.STATIC));
      // the following is necessary to prevent in-place updates of our
      // constants!
      addIncRefs(constant.type(),bytecodes);
    }
    bytecodes.add(new Bytecode.Store(c.target(), jt));
  }
View Full Code Here

    ArrayList<jasm.util.Pair<Integer, String>> cases = new ArrayList();
    boolean canUseSwitchBytecode = true;
    for (Pair<Constant, String> p : c.branches) {
      // first, check whether the switch value is indeed an integer.
      Constant v = (Constant) p.first();
      if (!(v instanceof Constant.Integer)) {
        canUseSwitchBytecode = false;
        break;
      }
      // second, check whether integer value can fit into a Java int
      Constant.Integer vi = (Constant.Integer) v;
      int iv = vi.value.intValue();
      if (!BigInteger.valueOf(iv).equals(vi.value)) {
        canUseSwitchBytecode = false;
        break;
      }
      // ok, we're all good so far
      cases.add(new jasm.util.Pair(iv, p.second()));
    }

    if (canUseSwitchBytecode) {
      JvmType.Function ftype = new JvmType.Function(T_INT);
      bytecodes.add(new Bytecode.Load(c.operand,convertType((Type) c.type)));
      bytecodes.add(new Bytecode.Invoke(WHILEYINT, "intValue", ftype,
          Bytecode.InvokeMode.VIRTUAL));
      bytecodes.add(new Bytecode.Switch(c.defaultTarget, cases));
    } else {
      // ok, in this case we have to fall back to series of the if
      // conditions. Not ideal.
      for (Pair<Constant, String> p : c.branches) {
        Constant value = p.first();
        String target = p.second();
        translate(value, freeSlot, lambdas, bytecodes);
        bytecodes
            .add(new Bytecode.Load(c.operand, convertType(c.type)));
        translateIfGoto(value.type(), Codes.Comparator.EQ, target, entry,
            freeSlot + 1, bytecodes);
      }
      bytecodes.add(new Bytecode.Goto(c.defaultTarget));
    }
  }
View Full Code Here

      bytecodes.add(new Bytecode.InstanceOf(JAVA_LANG_STRING));
      bytecodes.add(new Bytecode.If(Bytecode.IfMode.NE, trueTarget));

    } else {
      // Fall-back to an external (recursive) check
      Constant constant = Constant.V_TYPE(test);
      int id = JvmValue.get(constant,constants);
      String name = "constant$" + id;

      bytecodes.add(new Bytecode.GetField(owner, name, WHILEYTYPE, Bytecode.FieldMode.STATIC));
View Full Code Here

TOP

Related Classes of wyil.lang.Constant$Null

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.