示例#1
0
  public void reportNativeException(Exception e, IokeObject message, IokeObject context)
      throws ControlFlow {
    final IokeObject condition =
        IokeObject.as(
                IokeObject.getCellChain(
                    this.condition, message, context, "Error", "NativeException"),
                context)
            .mimic(message, context);
    condition.setCell("message", message);
    condition.setCell("context", context);
    condition.setCell("receiver", context);
    condition.setCell("rootException", e);
    condition.setCell("exceptionType", newText(e.getClass().getName()));

    if (e.getMessage() != null) {
      condition.setCell("exceptionMessage", newText(e.getMessage()));
    } else {
      condition.setCell("exceptionMessage", nil);
    }

    List<Object> ob = new ArrayList<Object>();
    for (StackTraceElement ste : e.getStackTrace()) {
      ob.add(newText(ste.toString()));
    }
    condition.setCell("exceptionStackTrace", newList(ob));
    this.errorCondition(condition);
  }
示例#2
0
 public IokeObject newRegexp(String pattern, String flags, IokeObject context, IokeObject message)
     throws ControlFlow {
   IokeObject obj = this.regexp.allocateCopy(null, null);
   obj.mimicsWithoutCheck(this.regexp);
   obj.setData(Regexp.create(pattern, flags, context, message));
   return obj;
 }
示例#3
0
 public IokeObject newCallFrom(
     IokeObject ctx, IokeObject message, IokeObject surroundingContext, IokeObject on) {
   IokeObject obj = this.call.allocateCopy(null, null);
   obj.mimicsWithoutCheck(this.call);
   obj.setData(new Call(ctx, message, surroundingContext, on));
   return obj;
 }
示例#4
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();
   }
 }
示例#5
0
 public IokeObject newMacro(String doc, IokeObject tp, IokeData impl) throws ControlFlow {
   IokeObject obj = tp.allocateCopy(null, null);
   obj.setDocumentation(doc, null, null);
   obj.mimicsWithoutCheck(tp);
   obj.setData(impl);
   return obj;
 }
示例#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
文件: Range.java 项目: aneeshpu/ioke
 @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));
 }
示例#9
0
 public IokeObject newMessageFrom(IokeObject m, String name, List<Object> args)
     throws ControlFlow {
   Message mess = new Message(this, name);
   mess.setFile(m.getFile());
   mess.setLine(m.getLine());
   mess.setPosition(m.getPosition());
   mess.setArguments(args);
   return createMessage(mess);
 }
示例#10
0
 public IokeObject newNumber(RatNum number) {
   if (number instanceof IntNum) {
     return newNumber((IntNum) number);
   } else {
     IokeObject obj = this.ratio.allocateCopy(null, null);
     obj.mimicsWithoutCheck(this.ratio);
     obj.setData(Number.ratio((IntFraction) number));
     return obj;
   }
 }
示例#11
0
 public IokeObject createIntegratedJavaWrapper(Class clz) {
   IokeObject obj = this.javaWrapper.allocateCopy(null, null);
   obj.mimicsWithoutCheck(registry.wrap(Class.class));
   obj.mimicsWithoutCheck(registry.wrap(clz.getSuperclass()));
   for (Class<?> i : clz.getInterfaces()) {
     obj.mimicsWithoutCheck(registry.wrap(i));
   }
   obj.setData(JavaIntegrationWrapper.wrapWithMethods(clz, obj, this));
   return obj;
 }
示例#12
0
 public IokeObject getSymbol(String name) {
   synchronized (symbolTable) {
     IokeObject obj = symbolTable.get(name);
     if (obj == null) {
       obj = new IokeObject(this, null, new Symbol(name));
       obj.mimicsWithoutCheck(this.symbol);
       symbolTable.put(name, obj);
     }
     return obj;
   }
 }
示例#13
0
 public IokeObject newNumber(IntNum number) {
   IokeObject obj = null;
   obj = numCache.get(number);
   if (obj == null) {
     obj = this.integer.allocateCopy(null, null);
     obj.mimicsWithoutCheck(this.integer);
     obj.setData(Number.integer(number));
     numCache.put(number, obj);
   }
   return obj;
 }
示例#14
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();
   }
 }
示例#15
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();
   }
 }
示例#16
0
  public RescueInfo findActiveRescueFor(IokeObject condition) {
    for (List<RescueInfo> lrp : rescues.get()) {
      for (RescueInfo rp : lrp) {
        for (Object possibleKind : rp.applicableConditions) {
          if (IokeObject.isMimic(condition, IokeObject.as(possibleKind, condition))) {
            return rp;
          }
        }
      }
    }

    return null;
  }
示例#17
0
文件: Range.java 项目: aneeshpu/ioke
  public String notice(Object obj) throws ControlFlow {
    StringBuilder sb = new StringBuilder();

    sb.append(IokeObject.notice(from));
    if (inclusive) {
      sb.append("..");
    } else {
      sb.append("...");
    }
    sb.append(IokeObject.notice(to));

    return sb.toString();
  }
示例#18
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();
   }
 }
示例#19
0
 public String notice(Object self) {
   if (IokeObject.as(self, (IokeObject) self).isActivatable()) {
     return "fnx(...)";
   } else {
     return "fn(...)";
   }
 }
示例#20
0
 public String inspect(Object self) {
   String args = arguments.getCode();
   if (IokeObject.as(self, (IokeObject) self).isActivatable()) {
     return "fnx(" + args + Message.code(message) + ")";
   } else {
     return "fn(" + args + Message.code(message) + ")";
   }
 }
示例#21
0
 public String getFormattedCode(Object self) throws ControlFlow {
   String args = arguments == null ? "" : arguments.getCode();
   if (IokeObject.as(self, (IokeObject) self).isActivatable()) {
     return "fnx(" + args + "\n  " + Message.formattedCode(message, 2, (IokeObject) self) + ")";
   } else {
     return "fn(" + args + "\n  " + Message.formattedCode(message, 2, (IokeObject) self) + ")";
   }
 }
示例#22
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;
   }
 }
示例#23
0
  public static Object activateWithDataFixed(
      IokeObject self,
      IokeObject dynamicContext,
      IokeObject message,
      Object on,
      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);

    return self.runtime.interpreter.evaluate(lb.message, c, on, c);
  }
示例#24
0
  public List<HandlerInfo> findActiveHandlersFor(IokeObject condition, BindIndex stopIndex) {
    List<HandlerInfo> result = new ArrayList<HandlerInfo>();

    for (List<HandlerInfo> lrp : handlers.get()) {
      for (HandlerInfo rp : lrp) {
        if (rp.index.lessThan(stopIndex)) {
          return result;
        }

        for (Object possibleKind : rp.applicableConditions) {
          if (IokeObject.isMimic(condition, IokeObject.as(possibleKind, condition))) {
            result.add(rp);
          }
        }
      }
    }

    return result;
  }
示例#25
0
  public static void initRuntime(IokeObject obj) throws ControlFlow {
    obj.setKind("Runtime");

    obj.registerMethod(
        obj.runtime.newNativeMethod(
            "returns the node id for the runtime it's called on",
            new TypeCheckingNativeMethod.WithNoArguments("nodeId", obj) {
              @Override
              public Object activate(
                  IokeObject method,
                  Object on,
                  List<Object> args,
                  Map<String, Object> keywords,
                  IokeObject context,
                  IokeObject message)
                  throws ControlFlow {
                Runtime r = (Runtime) IokeObject.data(on);
                return method.runtime.newNumber(r.id);
              }
            }));

    obj.registerMethod(
        obj.runtime.newNativeMethod(
            "creates a new runtime and returns that. be careful using this since it will result in some fairly strange behavior if used incorrectly. it will not copy the state of this runtime, but just create a new one from scratch.",
            new TypeCheckingNativeMethod.WithNoArguments("create", obj) {
              @Override
              public Object activate(
                  IokeObject method,
                  Object on,
                  List<Object> args,
                  Map<String, Object> keywords,
                  IokeObject context,
                  IokeObject message)
                  throws ControlFlow {
                Runtime r = new Runtime(method.runtime.out, method.runtime.in, method.runtime.err);
                r.init();
                IokeObject o = method.runtime.runtime.allocateCopy(null, null);
                o.mimicsWithoutCheck(method.runtime.runtime);
                o.setData(r);
                return o;
              }
            }));
  }
示例#26
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;
 }
示例#27
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);
   }
 }
示例#28
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);
    }
  }
示例#29
0
文件: Range.java 项目: aneeshpu/ioke
 public static String getNotice(Object on) throws ControlFlow {
   return ((Range) (IokeObject.data(on))).notice(on);
 }
示例#30
0
文件: Range.java 项目: aneeshpu/ioke
 public static String getInspect(Object on) throws ControlFlow {
   return ((Range) (IokeObject.data(on))).inspect(on);
 }