Пример #1
0
 public Object evaluateFile(String filename, IokeObject message, IokeObject context)
     throws ControlFlow {
   try {
     ((IokeSystem) IokeObject.data(system)).pushCurrentFile(filename);
     if (IokeSystem.isAbsoluteFileName(filename)) {
       return evaluateStream(
           new InputStreamReader(new FileInputStream(new File(filename)), "UTF-8"),
           message,
           context);
     } else {
       return evaluateStream(
           new InputStreamReader(
               new FileInputStream(
                   new File(
                       ((IokeSystem) IokeObject.data(system)).getCurrentWorkingDirectory(),
                       filename)),
               "UTF-8"),
           message,
           context);
     }
   } catch (Exception e) {
     reportNativeException(e, message, context);
     return null;
   } finally {
     ((IokeSystem) IokeObject.data(system)).popCurrentFile();
   }
 }
Пример #2
0
 @Override
 public boolean isEqualTo(IokeObject self, Object other) {
   return ((other instanceof IokeObject)
       && (IokeObject.data(other) instanceof Range)
       && this.inclusive == ((Range) IokeObject.data(other)).inclusive
       && this.from.equals(((Range) IokeObject.data(other)).from)
       && this.to.equals(((Range) IokeObject.data(other)).to));
 }
Пример #3
0
 public Object evaluateStream(String name, Reader reader, IokeObject message, IokeObject context)
     throws ControlFlow {
   try {
     ((IokeSystem) IokeObject.data(system)).pushCurrentFile(name);
     return evaluateStream(reader, message, context);
   } catch (Exception e) {
     reportNativeException(e, message, context);
     return null;
   } finally {
     ((IokeSystem) IokeObject.data(system)).popCurrentFile();
   }
 }
Пример #4
0
 public Object evaluateFile(File f, IokeObject message, IokeObject context) throws ControlFlow {
   try {
     ((IokeSystem) IokeObject.data(system)).pushCurrentFile(f.getCanonicalPath());
     return evaluateStream(
         new InputStreamReader(new FileInputStream(f), "UTF-8"), message, context);
   } catch (Exception e) {
     reportNativeException(e, message, context);
     return null;
   } finally {
     ((IokeSystem) IokeObject.data(system)).popCurrentFile();
   }
 }
Пример #5
0
 public void tearDown() throws ControlFlow.Exit {
   int status = 0;
   List<IokeSystem.AtExitInfo> atExits = IokeSystem.getAtExits(system);
   while (!atExits.isEmpty()) {
     IokeSystem.AtExitInfo atExit = atExits.remove(0);
     try {
       ((Message) IokeObject.data(atExit.message))
           .evaluateCompleteWithoutExplicitReceiver(
               atExit.message, atExit.context, atExit.context.getRealContext());
     } catch (ControlFlow.Exit e) {
       status = 1;
     } catch (ControlFlow e) {
       String name = e.getClass().getName();
       System.err.println(
           "unexpected control flow: " + name.substring(name.indexOf("$") + 1).toLowerCase());
       if (debug) {
         e.printStackTrace(System.err);
       }
       status = 1;
     }
   }
   if (status != 0) {
     throw new ControlFlow.Exit();
   }
 }
Пример #6
0
  public static int extractInt(Object number, IokeObject m, IokeObject context) throws ControlFlow {
    if (!(IokeObject.data(number) instanceof Number)) {
      number = IokeObject.convertToNumber(number, m, context);
    }

    return intValue(number).intValue();
  }
Пример #7
0
  public void withReturningRestart(String name, IokeObject context, RunnableWithControlFlow code)
      throws ControlFlow {
    IokeObject rr =
        IokeObject.as(((Message) IokeObject.data(mimic)).sendTo(mimic, context, restart), context);
    IokeObject.setCell(rr, "name", getSymbol(name), context);
    IokeObject.setCell(rr, "argumentNames", newList(new ArrayList<Object>()), context);

    List<RestartInfo> rrs = new ArrayList<RestartInfo>();
    BindIndex index = getBindIndex();
    rrs.add(0, new RestartInfo(name, rr, rrs, index, null));
    index = index.nextCol();
    registerRestarts(rrs);

    try {
      code.run();
    } catch (ControlFlow.Restart e) {
      RestartInfo ri = null;
      if ((ri = e.getRestart()).token == rrs) {
        return;
      } else {
        throw e;
      }
    } finally {
      unregisterRestarts(rrs);
    }
  }
Пример #8
0
 public Object evaluateString(String str, IokeObject message, IokeObject context)
     throws ControlFlow {
   IokeObject msg = parseStream(new StringReader(str), message, context);
   if (msg != null) {
     return ((Message) IokeObject.data(msg)).evaluateComplete(msg);
   } else {
     return nil;
   }
 }
Пример #9
0
 public IokeObject newFile(IokeObject context, File eff) throws ControlFlow {
   IokeObject fileMimic =
       IokeObject.as(
           ((Message) IokeObject.data(FileMessage)).sendTo(FileMessage, context, this.fileSystem),
           context);
   IokeObject obj = fileMimic.allocateCopy(null, null);
   obj.mimicsWithoutCheck(fileMimic);
   obj.setData(new FileSystem.IokeFile(eff));
   return obj;
 }
Пример #10
0
  public Object withRestartReturningArguments(
      RunnableWithControlFlow code, IokeObject context, Restart.JavaRestart... restarts)
      throws ControlFlow {
    List<RestartInfo> rrs = new ArrayList<RestartInfo>();
    BindIndex index = getBindIndex();

    for (Restart.JavaRestart rjr : restarts) {
      IokeObject rr =
          IokeObject.as(
              ((Message) IokeObject.data(mimic)).sendTo(mimic, context, restart), context);
      IokeObject.setCell(rr, "name", getSymbol(rjr.getName()), context);

      List<Object> args = new ArrayList<Object>();
      for (String argName : rjr.getArgumentNames()) {
        args.add(getSymbol(argName));
      }

      IokeObject.setCell(rr, "name", getSymbol(rjr.getName()), context);
      IokeObject.setCell(rr, "argumentNames", newList(args), context);

      String report = rjr.report();
      if (report != null) {
        IokeObject.setCell(
            rr, "report", evaluateString("fn(r, \"" + report + "\")", message, ground), context);
      }

      rrs.add(0, new RestartInfo(rjr.getName(), rr, rrs, index, rjr));
      index = index.nextCol();
    }
    registerRestarts(rrs);

    try {
      code.run();
      return new ArrayList<Object>();
    } catch (ControlFlow.Restart e) {
      RestartInfo ri = null;
      if ((ri = e.getRestart()).token == rrs) {
        Restart.JavaRestart currentRjr = (Restart.JavaRestart) ri.data;
        IokeObject result = currentRjr.invoke(context, e.getArguments());
        return result;
      } else {
        throw e;
      }
    } finally {
      unregisterRestarts(rrs);
    }
  }
Пример #11
0
  public static Object activateWithCallAndDataFixed(
      final IokeObject self,
      IokeObject dynamicContext,
      IokeObject message,
      Object on,
      Object call,
      Map<String, Object> data)
      throws ControlFlow {
    LexicalBlock lb = (LexicalBlock) self.data;
    IokeObject c = self.runtime.newLexicalContext(on, "Lexical activation context", lb.context);

    for (Map.Entry<String, Object> d : data.entrySet()) {
      String s = d.getKey();
      c.setCell(s.substring(0, s.length() - 1), d.getValue());
    }
    lb.arguments.assignArgumentValues(
        c, dynamicContext, message, on, ((Call) IokeObject.data(call)));

    return self.runtime.interpreter.evaluate(lb.message, c, on, c);
  }
Пример #12
0
 public Object withReturningRescue(
     IokeObject context, Object toReturn, RunnableWithReturnAndControlFlow javaRescue)
     throws ControlFlow {
   List<RescueInfo> rescues = new ArrayList<RescueInfo>();
   IokeObject rr =
       IokeObject.as(((Message) IokeObject.data(mimic)).sendTo(mimic, context, rescue), context);
   List<Object> conds = new ArrayList();
   conds.add(this.condition);
   rescues.add(new RescueInfo(rr, conds, rescues, getBindIndex()));
   registerRescues(rescues);
   try {
     return javaRescue.run();
   } catch (ControlFlow.Rescue e) {
     if (e.getRescue().token == rescues) {
       return toReturn;
     } else {
       throw e;
     }
   } finally {
     unregisterRescues(rescues);
   }
 }
Пример #13
0
 public static String getInspect(Object on) throws ControlFlow {
   return ((Range) (IokeObject.data(on))).inspect(on);
 }
Пример #14
0
 public static boolean isInclusive(Object range) {
   return ((Range) IokeObject.data(range)).isInclusive();
 }
Пример #15
0
 public static IokeObject getTo(Object range) {
   return ((Range) IokeObject.data(range)).getTo();
 }
Пример #16
0
 public static String getNotice(Object on) {
   return ((LexicalBlock) (IokeObject.data(on))).notice(on);
 }
Пример #17
0
 public static String getInspect(Object on) {
   return ((LexicalBlock) (IokeObject.data(on))).inspect(on);
 }
Пример #18
0
 public String getCurrentWorkingDirectory() {
   return ((IokeSystem) IokeObject.data(system)).getCurrentWorkingDirectory();
 }
Пример #19
0
 public static IntNum intValue(Object number) {
   return (IntNum) ((Number) IokeObject.data(number)).value;
 }
Пример #20
0
 public static RatNum value(Object number) {
   return ((Number) IokeObject.data(number)).value;
 }
Пример #21
0
  @Override
  public Object activateWithData(
      final IokeObject self,
      IokeObject context,
      IokeObject message,
      Object on,
      Map<String, Object> data)
      throws ControlFlow {
    if (code == null) {
      IokeObject condition =
          IokeObject.as(
                  IokeObject.getCellChain(
                      context.runtime.condition,
                      message,
                      context,
                      "Error",
                      "Invocation",
                      "NotActivatable"),
                  context)
              .mimic(message, context);
      condition.setCell("message", message);
      condition.setCell("context", context);
      condition.setCell("receiver", on);
      condition.setCell("method", self);
      condition.setCell(
          "report",
          context.runtime.newText(
              "You tried to activate a method without any code - did you by any chance activate the DefaultMacro kind by referring to it without wrapping it inside a call to cell?"));
      context.runtime.errorCondition(condition);
      return null;
    }

    IokeObject c = context.runtime.locals.mimic(message, context);
    c.setCell("self", on);
    c.setCell("@", on);
    c.registerMethod(
        c.runtime.newJavaMethod(
            "will return the currently executing macro receiver",
            new JavaMethod.WithNoArguments("@@") {
              @Override
              public Object activate(
                  IokeObject method, IokeObject context, IokeObject message, Object on)
                  throws ControlFlow {
                getArguments()
                    .getEvaluatedArguments(
                        context,
                        message,
                        on,
                        new ArrayList<Object>(),
                        new HashMap<String, Object>());
                return self;
              }
            }));
    c.setCell("currentMessage", message);
    c.setCell("surroundingContext", context);
    c.setCell("call", context.runtime.newCallFrom(c, message, context, IokeObject.as(on, context)));
    for (Map.Entry<String, Object> d : data.entrySet()) {
      String s = d.getKey();
      c.setCell(s.substring(0, s.length() - 1), d.getValue());
    }

    try {
      return ((Message) IokeObject.data(code)).evaluateCompleteWith(code, c, on);
    } catch (ControlFlow.Return e) {
      if (e.context == c) {
        return e.getValue();
      } else {
        throw e;
      }
    }
  }
Пример #22
0
 public void errorCondition(IokeObject cond) throws ControlFlow {
   ((Message) IokeObject.data(errorMessage))
       .sendTo(errorMessage, ground, ground, createMessage(Message.wrap(cond)));
 }
Пример #23
0
 public void setCurrentWorkingDirectory(String cwd) {
   ((IokeSystem) IokeObject.data(system)).setCurrentWorkingDirectory(cwd);
 }
Пример #24
0
 public static String getNotice(Object on) throws ControlFlow {
   return ((Range) (IokeObject.data(on))).notice(on);
 }
Пример #25
0
 public static String getInspect(Object on) {
   return ((Number) (IokeObject.data(on))).inspect(on);
 }
Пример #26
0
 public static String getNotice(Object on) {
   return ((Inspectable) (IokeObject.data(on))).notice(on);
 }
Пример #27
0
 public void addArgument(String arg) {
   ((IokeSystem) IokeObject.data(system)).addArgument(arg);
 }