void set_exception(EmObject *ob, char *message, char *value) { EmExceptionObject *eo = (EmExceptionObject *)ob; if (eo->message) { DECREF(eo->message); } eo->message = newstringobject(message); if (eo->value) DECREF(eo->value); if (value) { eo->value = newstringobject(value); } else { eo->value = NULL; } last_exception = ob; }
EmObject * newexceptionobject(char *errtype, char *message) { EmExceptionObject *ob; if ((ob = NEWOBJ(EmExceptionObject, &Exceptiontype)) == NULL) return NULL; ob->errtype = newstringobject(errtype); ob->message = newstringobject(message); if (ob->errtype == NULL || ob->message == NULL) { if (ob->errtype) DECREF(ob->errtype); if (ob->message) DECREF(ob->message); DEL(ob); return NULL; } ob->value = NULL; return (EmObject *) ob; }
static object * lib_repr(amigalibobject *ao) { char buf[300]; sprintf(buf, "<amiga library '%.256s', V %ld.%ld, base %lx, at %lx>", ao->libbase->lib_Node.ln_Name, ao->libbase->lib_Version, ao->libbase->lib_Revision, ao->libbase,(long)ao); return newstringobject(buf); }
object *newmoduleobject(char *name) { moduleobject *m = NEWOBJ(moduleobject, &Moduletype); if (m == NULL) return NULL; m->md_name = newstringobject(name); m->md_dict = newdictobject(); if (m->md_name == NULL || m->md_dict == NULL) { DECREF(m); return NULL; } return (object *)m; }
void init_all(int argc, char **argv) { // process command line arguments char *filename = NULL; FILE *fp = stdin; EmObject *ob; if (argc > 1) filename = argv[1]; if (filename != NULL) { if ((fp = fopen(filename, "r")) == NULL) { fprintf(stderr, "Cannot open file %s\n", filename); exit(1); } source.type = SOURCE_TYPE_FILE; } else { source.type = SOURCE_TYPE_PROMPT; } source.filename = filename; source.fp = fp; // Constant hash table literalTable = newhashobject(); // Add commonly used literals ob = newintobject(1); hashobject_insert_by_string(literalTable, "1", ob); DECREF(ob); ob = newintobject(-1); hashobject_insert_by_string(literalTable, "-1", ob); DECREF(ob); ob = newintobject(0); hashobject_insert_by_string(literalTable, "0", ob); DECREF(ob); ob = newstringobject("*"); hashobject_insert_by_string(literalTable, "*", ob); DECREF(ob); hashobject_insert_by_string(literalTable, "null", &nulobj); // initialize the lexer lexer_init(); // initialize the VM vm_init(); }
object * newmappingobject() { register mappingobject *mp; if (dummy == NULL) { /* Auto-initialize dummy */ dummy = newstringobject("<dummy key>"); if (dummy == NULL) return NULL; } mp = NEWOBJ(mappingobject, &Mappingtype); if (mp == NULL) return NULL; mp->ma_size = primes[0]; mp->ma_table = (mappingentry *) calloc(sizeof(mappingentry), mp->ma_size); if (mp->ma_table == NULL) { DEL(mp); return err_nomem(); } mp->ma_fill = 0; mp->ma_used = 0; return (object *)mp; }