Beispiel #1
0
static int runRepl()
{
  WrenVM* vm = wrenNewVM(reallocate);

  for (;;)
  {
    printf("> ");
    char line[MAX_LINE];
    fgets(line, MAX_LINE, stdin);

    // TODO: Handle failure.
    wrenInterpret(vm, line);
    // TODO: Figure out how this should work with wren API.
    /*
    ObjFn* fn = compile(vm, line);

    if (fn != NULL)
    {
      Value result = interpret(vm, fn);
      printf("= ");
      printValue(result);
      printf("\n");
    }
    */
  }

  wrenFreeVM(vm);
  return 0;
}
Beispiel #2
0
static void ensureOutsideForeign(WrenVM* vm)
{
  // To test the behavior outside of a foreign method (which we're currently
  // in), create a new separate VM.
  WrenConfiguration config;
  wrenInitConfiguration(&config);
  WrenVM* otherVM = wrenNewVM(&config);

  int before = wrenGetSlotCount(otherVM);

  wrenEnsureSlots(otherVM, 20);

  int after = wrenGetSlotCount(otherVM);

  // Use the slots to make sure they're available.
  for (int i = 0; i < 20; i++)
  {
    wrenSetSlotDouble(otherVM, i, i);
  }

  int sum = 0;

  for (int i = 0; i < 20; i++)
  {
    sum += (int)wrenGetSlotDouble(otherVM, i);
  }

  wrenFreeVM(otherVM);

  char result[100];
  sprintf(result, "%d -> %d (%d)", before, after, sum);
  wrenSetSlotString(vm, 0, result);
}
Beispiel #3
0
static int runRepl()
{
  WrenVM* vm = createVM(NULL);

  printf("\\\\/\"-\n");
  printf(" \\_/   wren v0.0.0\n");

  char line[MAX_LINE_LENGTH];

  for (;;)
  {
    printf("> ");

    if (!fgets(line, MAX_LINE_LENGTH, stdin))
    {
      printf("\n");
      break;
    }

    // TODO: Handle failure.
    wrenInterpret(vm, "Prompt", line);

    // TODO: Automatically print the result of expressions.
  }

  wrenFreeVM(vm);
  return 0;
}
Beispiel #4
0
static int runFile(const char* path)
{
  char* source = readFile(path);
  WrenVM* vm = wrenNewVM(reallocate);

  int result = wrenInterpret(vm, source);

  wrenFreeVM(vm);
  free(source);

  return result;
}
Beispiel #5
0
Datei: vm.c Projekt: 0x73/wren
static void freeVM()
{
  ioShutdown();
  schedulerShutdown();
  
  uv_loop_close(loop);
  free(loop);
  
  wrenFreeVM(vm);

  uv_tty_reset_mode();
}
Beispiel #6
0
int main(int argc, char *argv[])
{
    const char* s = argc > 1 ? argv[1] : DEFAULT_SCRIPT;
    const int c = argc > 2 ? atoi(argv[2]) : DEFAULT_COUNT;
    
    count += c;
    
    char* script = readFile(s);
    if (script == NULL)
    {
        fprintf(stderr, "Could not locate %s\n", s);
        return 1;
    }
    
    WrenConfiguration config;
    wrenInitConfiguration(&config);

    config.bindForeignMethodFn = bindForeignMethod;
    //config.bindForeignClassFn = bindForeignClass;
    //config.loadModuleFn = readModule;
    config.writeFn = write;
    config.errorFn = reportError;

    // Since we're running in a standalone process, be generous with memory.
    config.initialHeapSize = 1024 * 1024 * 100;
    WrenVM* vm = wrenNewVM(&config);
    
    //fprintf(stdout, "Found hello.wren\n%s\n", script);
    
    WrenInterpretResult result = wrenInterpret(vm, script);
    if (result == WREN_RESULT_SUCCESS)
    {
        printf("%lld\n", ts_stop - ts_start);
    }
    else
    {
        fprintf(stderr, "Error executing hello.wren %d\n", result);
    }
        
    wrenFreeVM(vm);
    free(script);
    
    return result;
}
Beispiel #7
0
Wren::~Wren() {
    wrenFreeVM( vm_ );
}