Exemple #1
0
 @Override
 public void apply(int argc, Stack stack, Env env, Env fenv) {
   checkArgCountMin(argc, 2);
   Array a = stack.pop().asArray();
   if (a.isVector()) {
     try {
       stack.push(a.asVector().get((int) stack.pop().asIntNum().intValue()));
     } catch (ArrayIndexOutOfBoundsException e) {
       throw new LispException(Symbol.intern("index-too-large"), "index too large");
     }
   } else {
     int[] coord = new int[a.dimensions()];
     for (int i = 0; i < a.dimensions(); i++) {
       coord[i] = (int) stack.pop().asIntNum().intValue();
     }
     try {
       stack.push(a.get(coord));
     } catch (ArrayIndexOutOfBoundsException e) {
       throw new LispException(Symbol.intern("index-too-large"), "index too large");
     }
   }
 }
Exemple #2
0
  public static void main(String... args) throws IOException {

    OutputStreamWriter out = (OutputStreamWriter) RT.OUT.deref();
    PrintWriter err = RT.errPrintWriter();
    String path = System.getProperty(PATH_PROP);
    int count = args.length;

    if (path == null) {
      err.println(
          "ERROR: Must set system property "
              + PATH_PROP
              + "\nto the location for compiled .class files."
              + "\nThis directory must also be on your CLASSPATH.");
      System.exit(1);
    }

    boolean warnOnReflection = System.getProperty(REFLECTION_WARNING_PROP, "false").equals("true");
    String uncheckedMathProp = System.getProperty(UNCHECKED_MATH_PROP);
    Object uncheckedMath = Boolean.FALSE;
    if ("true".equals(uncheckedMathProp)) uncheckedMath = Boolean.TRUE;
    else if ("warn-on-boxed".equals(uncheckedMathProp))
      uncheckedMath = Keyword.intern("warn-on-boxed");

    try {
      Var.pushThreadBindings(
          RT.map(
              compile_path,
              path,
              warn_on_reflection,
              warnOnReflection,
              unchecked_math,
              uncheckedMath));

      for (String lib : args) {
        out.write("Compiling " + lib + " to " + path + '\n');
        out.flush();
        compile.invoke(Symbol.intern(lib));
      }
    } finally {
      Var.popThreadBindings();
      try {
        out.flush();
      } catch (IOException e) {
        e.printStackTrace(err);
      }
    }
  }
Exemple #3
0
  protected static Var loadVar(String namespace, String varName) {
    try {
      Symbol namespaceSymbol = Symbol.intern(namespace);
      Namespace ns = Namespace.find(namespaceSymbol);
      if (ns != null) return (Var) ns.getMapping(Symbol.create(varName));

      RT.load(namespace, false);

      ns = Namespace.find(namespaceSymbol);
      if (ns != null) return (Var) ns.getMapping(Symbol.create(varName));

      final String coreFilename = Clj.nsToFilename(namespace);
      RT.loadResourceScript(coreFilename);
      ns = Namespace.find(namespaceSymbol);
      if (ns != null) return (Var) ns.getMapping(Symbol.create(varName));

      throw new RuntimeException(
          "var still not found after load attempts: " + namespace + "/" + varName);
    } catch (Exception e) {
      e.printStackTrace();
      throw new RuntimeException("Failed to load var:" + namespace + "/" + varName, e);
    }
  }