static void js_core_globals (JSInterpPtr interp) { JSNode *n; JSBuiltinInfo *info; JSVirtualMachine *vm = interp->vm; /* Command `error'. */ info = js_vm_builtin_info_create (vm); info->global_method_proc = error_global_method; n = &interp->vm->globals[js_vm_intern (interp->vm, "error")]; js_vm_builtin_create (interp->vm, n, info, interp); if (!interp->options.no_compiler) { /* Command `eval'. */ info = js_vm_builtin_info_create (vm); info->global_method_proc = eval_global_method; n = &interp->vm->globals[js_vm_intern (interp->vm, "eval")]; js_vm_builtin_create (interp->vm, n, info, interp); } /* Command `load'. */ info = js_vm_builtin_info_create (vm); info->global_method_proc = load_global_method; n = &interp->vm->globals[js_vm_intern (interp->vm, "load")]; js_vm_builtin_create (interp->vm, n, info, interp); }
void js_builtin_Number (JSVirtualMachine *vm) { NumberCtx *ctx; JSNode *n; JSBuiltinInfo *info; ctx = js_calloc (vm, 1, sizeof (*ctx)); ctx->s_MAX_VALUE = js_vm_intern (vm, "MAX_VALUE"); ctx->s_MIN_VALUE = js_vm_intern (vm, "MIN_VALUE"); ctx->s_NaN = js_vm_intern (vm, "NaN"); ctx->s_NEGATIVE_INFINITY = js_vm_intern (vm, "NEGATIVE_INFINITY"); ctx->s_POSITIVE_INFINITY = js_vm_intern (vm, "POSITIVE_INFINITY"); info = js_vm_builtin_info_create (vm); vm->prim[JS_INTEGER] = info; vm->prim[JS_FLOAT] = info; vm->prim[JS_NAN] = info; info->method_proc = method; info->property_proc = property; info->obj_context = ctx; info->obj_context_delete = js_free; /* Define it. */ n = &vm->globals[js_vm_intern (vm, "Number")]; js_vm_builtin_create (vm, n, info, NULL); }
void js_builtin_core (JSVirtualMachine *vm) { int i; JSNode *n; /* Properties. */ n = &vm->globals[js_vm_intern (vm, "NaN")]; n->type = JS_NAN; n = &vm->globals[js_vm_intern (vm, "Infinity")]; JS_MAKE_POSITIVE_INFINITY (n); /* Global methods. */ for (i = 0; global_methods[i].name; i++) { JSBuiltinInfo *info; info = js_vm_builtin_info_create (vm); info->global_method_proc = global_methods[i].method; n = &vm->globals[js_vm_intern (vm, global_methods[i].name)]; js_vm_builtin_create (vm, n, info, NULL); } }
void js_builtin_Array (JSVirtualMachine *vm) { ArrayCtx *ctx; JSNode *n; JSBuiltinInfo *info; ctx = js_calloc (vm, 1, sizeof (*ctx)); ctx->s_concat = js_vm_intern (vm, "concat"); ctx->s_join = js_vm_intern (vm, "join"); ctx->s_pop = js_vm_intern (vm, "pop"); ctx->s_push = js_vm_intern (vm, "push"); ctx->s_reverse = js_vm_intern (vm, "reverse"); ctx->s_shift = js_vm_intern (vm, "shift"); ctx->s_slice = js_vm_intern (vm, "slice"); ctx->s_splice = js_vm_intern (vm, "splice"); ctx->s_sort = js_vm_intern (vm, "sort"); ctx->s_unshift = js_vm_intern (vm, "unshift"); ctx->s_length = js_vm_intern (vm, "length"); info = js_vm_builtin_info_create (vm); vm->prim[JS_ARRAY] = info; info->method_proc = method; info->property_proc = property; info->new_proc = new_proc; info->obj_context = ctx; info->obj_context_delete = js_free; /* Define it. */ n = &vm->globals[js_vm_intern (vm, "Array")]; js_vm_builtin_create (vm, n, info, NULL); }
void js_ext_curses (JSInterpPtr interp) { CursesCtx *ctx; JSBuiltinInfo *info; JSNode *n; JSVirtualMachine *vm = interp->vm; /* Class context. */ ctx = js_calloc (vm, 1, sizeof (*ctx)); ctx->s_addstr = js_vm_intern (vm, "addstr"); ctx->s_attron = js_vm_intern (vm, "attron"); ctx->s_attroff = js_vm_intern (vm, "attroff"); ctx->s_beep = js_vm_intern (vm, "beep"); ctx->s_cbreak = js_vm_intern (vm, "cbreak"); ctx->s_clear = js_vm_intern (vm, "clear"); ctx->s_clrtobot = js_vm_intern (vm, "clrtobot"); ctx->s_clrtoeol = js_vm_intern (vm, "clrtoeol"); ctx->s_echo = js_vm_intern (vm, "echo"); ctx->s_endwin = js_vm_intern (vm, "endwin"); ctx->s_getch = js_vm_intern (vm, "getch"); ctx->s_initscr = js_vm_intern (vm, "initscr"); ctx->s_keypad = js_vm_intern (vm, "keypad"); ctx->s_move = js_vm_intern (vm, "move"); ctx->s_mvaddstr = js_vm_intern (vm, "mvaddstr"); ctx->s_mvaddsubstr = js_vm_intern (vm, "mvaddsubstr"); ctx->s_mvgetch = js_vm_intern (vm, "mvgetch"); ctx->s_nocbreak = js_vm_intern (vm, "nocbreak"); ctx->s_noecho = js_vm_intern (vm, "noecho"); ctx->s_refresh = js_vm_intern (vm, "refresh"); ctx->s_standend = js_vm_intern (vm, "standend"); ctx->s_standout = js_vm_intern (vm, "standout"); ctx->s_LINES = js_vm_intern (vm, "LINES"); ctx->s_COLS = js_vm_intern (vm, "COLS"); /* Object information. */ info = js_vm_builtin_info_create (vm); info->method_proc = method; info->property_proc = property; info->obj_context = ctx; info->obj_context_delete = js_free; /* Define it. */ n = &vm->globals[js_vm_intern (vm, "Curses")]; js_vm_builtin_create (vm, n, info, NULL); }
int js_create_global_method (JSInterpPtr interp, char *name, JSGlobalMethodProc proc, void *context, JSFreeProc context_free_proc) { JSNode *n = &interp->vm->globals[js_vm_intern (interp->vm, name)]; JSVirtualMachine *vm = interp->vm; int result = 1; /* Need one toplevel here. */ { JSErrorHandlerFrame handler; /* We must create the toplevel ourself. */ memset (&handler, 0, sizeof (handler)); handler.next = vm->error_handler; vm->error_handler = &handler; if (setjmp (vm->error_handler->error_jmp)) /* An error occurred. */ result = 0; else { JSBuiltinInfo *info; JSGlobalMethodContext *ctx; /* Context. */ ctx = js_calloc (vm, 1, sizeof (*ctx)); ctx->proc = proc; ctx->context = context; ctx->free_proc = context_free_proc; ctx->interp = interp; /* Info. */ info = js_vm_builtin_info_create (vm); info->global_method_proc = js_global_method_stub; /* Create the builtin. */ js_vm_builtin_create (interp->vm, n, info, ctx); } /* Pop the error handler. */ vm->error_handler = vm->error_handler->next; } return result; }
void js_builtin_Function (JSVirtualMachine *vm) { JSNode *n; JSBuiltinInfo *info; info = js_vm_builtin_info_create (vm); vm->prim[JS_FUNC] = info; info->method_proc = method; info->property_proc = property; /* Define it. */ n = &vm->globals[js_vm_intern (vm, "Function")]; js_vm_builtin_create (vm, n, info, NULL); }
void init_builtin_digitalio(JSVirtualMachine *vm) { JSBuiltinInfo *info; JSNode *n; unsigned char i; struct { char *name; JSBuiltinGlobalMethod method; } global_methods[] = { {"pinMode", pinMode_global_method}, {"digitalWrite", digitalWrite_global_method}, {"digitalRead", digitalRead_global_method}, {NULL, NULL} }; for (i = 0; global_methods[i].name; i++) { info = js_vm_builtin_info_create(vm); info->global_method_proc = global_methods[i].method; n = &vm->globals[js_vm_intern(vm, global_methods[i].name)]; js_vm_builtin_create(vm, n, info, NULL); } }