示例#1
0
static OBJ TrKernel_eval(VM, OBJ self, int argc, OBJ argv[]) {
  UNUSED(self);
  if (argc < 1) tr_raise(ArgumentError, "string argument required");
  if (argc > 4) tr_raise(ArgumentError, "Too much arguments");
  OBJ string = argv[0];
  TrFrame *f = (argc > 1 && argv[1]) ? TR_CBINDING(argv[1])->frame : vm->frame;
  char *filename = (argc > 2 && argv[1]) ? TR_STR_PTR(argv[2]) : "<eval>";
  size_t lineno = argc > 3 ? TR_FIX2INT(argv[3]) : 0;
  TrBlock *blk = TrBlock_compile(vm, TR_STR_PTR(string), filename, lineno);
  if (!blk) return TR_UNDEF;
  if (vm->debug) TrBlock_dump(vm, blk);
  return TrVM_run(vm, blk, f->self, f->class, kv_size(blk->locals), f->stack);
}
示例#2
0
static OBJ TrKernel_raise(VM, OBJ self, int argc, OBJ argv[]) {
  UNUSED(self);
  OBJ e = TR_NIL;
  switch (argc) {
    case 0:
      e = tr_getglobal("$!");
      break;
    case 1:
      if (TR_IS_A(argv[0], String))
        e = TrException_new(vm, vm->cRuntimeError, argv[0]);
      else
        e = tr_send2(argv[0], "exception");
      break;
    case 2:
      e = tr_send2(argv[0], "exception", argv[1]);
      break;
    default:
      tr_raise(ArgumentError, "wrong number of arguments (%d for 2)", argc);
  }
  TrException_set_backtrace(vm, e, TrVM_backtrace(vm));
  TR_THROW(EXCEPTION, e);
}
示例#3
0
文件: array.c 项目: singpolyma/tinyrb
static OBJ TrArray_set(VM, OBJ self, OBJ at, OBJ x) {
  int i = TrArray_at2index(vm, self, at);
  if (i < 0) tr_raise("IndexError: index %d out of array", i);
  kv_a(OBJ, (TR_CARRAY(self))->kv, i) = x;
  return x;
}