/* Function: tp_deinit * Destroys a VM instance. * * When you no longer need an instance of tinypy, you can use this to free all * memory used by it. Even when you are using only a single tinypy instance, it * may be good practice to call this function on shutdown. */ void tp_deinit(TP) { while (tp->root.list.val->len) { _tp_list_pop(tp,tp->root.list.val,0,"tp_deinit"); } tp_full(tp); tp_full(tp); tp_delete(tp,tp->root); tp_gc_deinit(tp); tp->mem_used -= sizeof(tp_vm); free(tp); }
tp_vm *_tp_init(void) { int i; tp_vm *tp = (tp_vm*)calloc(sizeof(tp_vm),1); tp->time_limit = TP_NO_LIMIT; tp->clocks = clock(); tp->time_elapsed = 0.0; tp->mem_limit = TP_NO_LIMIT; tp->mem_exceeded = 0; tp->mem_used = sizeof(tp_vm); tp->cur = 0; tp->jmp = 0; tp->ex = tp_None; tp->root = tp_list_nt(tp); for (i=0; i<256; i++) { tp->chars[i][0]=i; } tp_gc_init(tp); tp->_regs = tp_list(tp); for (i=0; i<TP_REGS; i++) { tp_set(tp,tp->_regs,tp_None,tp_None); } tp->builtins = tp_dict(tp); tp->modules = tp_dict(tp); tp->_params = tp_list(tp); for (i=0; i<TP_FRAMES; i++) { tp_set(tp,tp->_params,tp_None,tp_list(tp)); } tp_set(tp,tp->root,tp_None,tp->builtins); tp_set(tp,tp->root,tp_None,tp->modules); tp_set(tp,tp->root,tp_None,tp->_regs); tp_set(tp,tp->root,tp_None,tp->_params); tp_set(tp,tp->builtins,tp_string("MODULES"),tp->modules); tp_set(tp,tp->modules,tp_string("BUILTINS"),tp->builtins); tp_set(tp,tp->builtins,tp_string("BUILTINS"),tp->builtins); tp_obj sys = tp_dict(tp); tp_set(tp, sys, tp_string("version"), tp_string("tinypy 1.2+SVN")); tp_set(tp,tp->modules, tp_string("sys"), sys); tp->regs = tp->_regs.list.val->items; tp_full(tp); return tp; }
void tp_gcinc(TP) { tp->steps += 1; if (tp->steps < TP_GCMAX || tp->grey->len > 0) { _tp_gcinc(tp); _tp_gcinc(tp); } if (tp->steps < TP_GCMAX || tp->grey->len > 0) { return; } tp->steps = 0; tp_full(tp); return; }