src/vm/oba_vm.c
static bool importModule(ObaVM* vm, Value name) {
  name = resolveModule(vm, name);

  const char* source = NULL;
  char* cname = AS_CSTRING(name);

  CoreModule* module = &__core_modules__[0];
  while (module->name != NULL) {
    if (strcmp(module->name, cname) == 0) {
      source = module->source();
      break;
    }
    module++;
  }

  if (source == NULL) return NULL;

  ObjClosure* moduleClosure = compileInModule(vm, name, source);
  if (moduleClosure == NULL) {
    return false;
  }

  push(vm, OBJ_VAL(moduleClosure));
  return callValue(vm, OBJ_VAL(moduleClosure), 0);
}
// TODO(kendal): If the module is already loaded, bail early.
// TODO(kendal): Handle circular imports.
If the module is already loaded, bail early.
If the module is already loaded bail early .
static bool importModule(ObaVM* vm, Value name) {
  name = resolveModule(vm, name);
  const char* source = NULL;
  char* cname = AS_CSTRING(name);
  CoreModule* module = &__core_modules__[0];
  while (module->name != NULL) {
    if (strcmp(module->name, cname) == 0) {
      source = module->source();
      break;
    }
    module++;
  }
  if (source == NULL) return NULL;
  ObjClosure* moduleClosure = compileInModule(vm, name, source);
  if (moduleClosure == NULL) {
    return false;
  }
  push(vm, OBJ_VAL(moduleClosure));
  return callValue(vm, OBJ_VAL(moduleClosure), 0);
}
static bool importModule ( ObaVM * vm , Value name ) { name = resolveModule ( vm , name ) ; const char * source = NULL ; char * cname = AS_CSTRING ( name ) ; CoreModule * module = & __core_modules__ [ 0 ] ; while ( module -> name != NULL ) { if ( strcmp ( module -> name , cname ) == 0 ) { source = module -> source ( ) ; break ; } module ++ ; } if ( source == NULL ) return NULL ; ObjClosure * moduleClosure = compileInModule ( vm , name , source ) ; if ( moduleClosure == NULL ) { return false ; } push ( vm , OBJ_VAL ( moduleClosure ) ) ; return callValue ( vm , OBJ_VAL ( moduleClosure ) , 0 ) ; }
TODO(kendal): If the module is already loaded, bail early.
TODO ( kendal ) : If the module is already loaded bail early .