EEL_object *eel_load_buffer(EEL_vm *vm, const char *source, unsigned len, EEL_sflags flags) { EEL_state *es = VMP->state; EEL_object *m = eel_load_buffer_nc(vm, source, len, flags); if(!m) return NULL; #if 0 eel_clear_errors(es); eel_clear_warnings(es); #endif eel_try(es) { EEL_xno x; eel_compile(es, m, flags); x = eel_callnf(es->vm, m, "__init_module", NULL); if(x) eel_cerror(es, "Could not initialize module '%s'! (%s)", eel_table_getss(o2EEL_module(m)->exports, "__modname"), eel_x_name(vm, x)); } eel_except { eel_lexer_invalidate(es); eel_o_disown_nz(m); return NULL; } return m; }
void eel_s_rename(EEL_state *es, EEL_symbol *s, const char *name) { if(s->name) eel_o_disown_nz(s->name); s->name = eel_ps_new(es->vm, name); if(!s->name) eel_serror(es, "Could not rename symbol!" " (Failed to create new EEL_string.)"); }
void eel_s_free(EEL_state *es, EEL_symbol *s) { /* Unlink */ if(s->parent) eel_s_unlink(s->parent, s); /* Cleanup */ while(s->symbols) eel_s_free(es, s->symbols); switch(s->type) { case EEL_SUNDEFINED: case EEL_SKEYWORD: case EEL_SVARIABLE: case EEL_SUPVALUE: case EEL_SBODY: case EEL_SNAMESPACE: break; case EEL_SCONSTANT: eel_v_disown(&s->v.value); break; case EEL_SCLASS: case EEL_SMODULE: case EEL_SFUNCTION: if(s->v.object) eel_o_disown_nz(s->v.object); break; case EEL_SOPERATOR: eel_operator_free(s->v.op); break; } if(s->name) eel_o_disown_nz(s->name); /* Destroy */ eel_free(es->vm, s); }
EEL_symbol *eel_s_find(EEL_state *es, EEL_symbol *table, const char *name, EEL_symtypes type) { EEL_symbol *sym = table->symbols; EEL_object *no = eel_ps_new(es->vm, name); if(!no) eel_serror(es, "Could not get name object!"); while(sym) { if((sym->type == type) && (sym->name == no)) break; sym = sym->next; } eel_o_disown_nz(no); return sym; }
static EEL_object *eel_load_buffer_nc(EEL_vm *vm, const char *source, unsigned len, EEL_sflags flags) { EEL_state *es = VMP->state; EEL_value v; EEL_object *m; EEL_xno x = eel_o_construct(es->vm, EEL_CMODULE, NULL, 0, &v); if(x) return NULL; m = v.objref.v; eel_try(es) load_buffer(vm, o2EEL_module(m), source, len); eel_except { eel_o_disown_nz(m); return NULL; } return m; }
static void eel__unstrap(EEL_state *es) { EEL_classdef *cd; int crc = es->classes[EEL_CCLASS]->refcount; int src = es->classes[EEL_CSTRING]->refcount; if((crc != 2) || (src != 2)) { eel_msg(es, EEL_EM_VMWARNING, "Classes CCLASS and CSTRING refcounts " "are %d and %d respectively,\n" "while they should both be 2 at this " "point. This means there is\n" "a memory leak somewhere (EEL or script " "bug), and as a result,\n" "EEL cannot safely clean up properly.", crc, src); eel_perror(es->vm, 1); return; } /* Kill CCLASS name -> CSTRING -> CCLASS cycle */ cd = o2EEL_classdef(es->classes[EEL_CCLASS]); eel_o_disown(&cd->name); /* * Now, we destroy CSTRING's name, and as a result, * CSTRING no longer needs itself, thus commits suicide, * and as a side effect, no longer needs CCLASS. */ cd = o2EEL_classdef(es->classes[EEL_CSTRING]); eel_o_disown(&cd->name); /* * Finally, terminate CCLASS' ownership of itself. * (*_nz() because debug code will prevent deletion * of classes not in the class table.) */ eel_o_disown_nz(es->classes[EEL_CCLASS]); es->classes[EEL_CCLASS] = NULL; }