struct ShredInfo_ {
VM* vm;
- struct M_Object_* me;
- Vector args;
MemPool mp;
+ struct M_Object_* me;
VM_Code orig;
struct Vector_ frame;
+ struct Vector_ args;
struct Vector_ line;
+ ShredDebugger *dbg;
};
struct ShredTick_ {
-Subproject commit 62ce17641d575fb1c0a16194234be257b4a6b85f
+Subproject commit 4587cd028705ac2766c1897bb5d1e398b0b1de46
m_str data;
FILE* file;
Ast ast;
- Vector args;
+ struct Vector_ args;
enum compile_type type;
};
-ANN static void compiler_name(MemPool p, struct Compiler* c) {
+ANN static void compiler_name(struct Compiler* c) {
m_str d = strdup(c->base);
c->name = strsep(&d, ":");
if(d)
- c->args = new_vector(p);
+ vector_init(&c->args);
while(d)
- vector_add(c->args, (vtype)strdup(strsep(&d, ":")));
+ vector_add(&c->args, (vtype)strdup(strsep(&d, ":")));
free(d);
}
-ANN static inline void compiler_error(MemPool p, const struct Compiler* c) {
- if(c->args) {
- for(m_uint i = 0; i < vector_size(c->args); ++i) {
- const m_str str = (m_str)vector_at(c->args, i);
+ANN static inline void compiler_error(struct Compiler*const c) {
+ if(c->args.ptr) {
+ const Vector v = &c->args;
+ for(m_uint i = 0; i < vector_size(v); ++i) {
+ const m_str str = (m_str)vector_at(v, i);
if(str)
- xfree((m_str)vector_at(c->args, i));
+ xfree((m_str)vector_at(v, i));
}
- free_vector(p, c->args);
+ vector_release(v);
}
}
}
#endif
-ANN static inline m_bool compiler_open(MemPool p, struct Compiler* c) {
+ANN static inline m_bool compiler_open(struct Compiler* c) {
char name[strlen(c->name) + 1];
strcpy(name, c->name);
#ifndef __FUZZING__
}
#endif
if(_compiler_open(c) < 0) {
- compiler_error(p, c);
+ compiler_error(c);
gw_err(_("can't open '%s'\n"), name);
return GW_ERROR;
}
nspc_commit(env->curr);
if(ret > 0 || env->context->global)
vector_add(&env->scope->known_ctx, (vtype)ctx);
- else //nspc_rollback(env->global_nspc);
+ else {//nspc_rollback(env->global_nspc);
+ if(!ctx->error) {
+ gw_err(_("{-}while compiling file `{0}{/}%s{-}`{0}\n"), c->base);
+ ctx->error = 1;
+ }
context_remref(ctx, env->gwion);
+ }
unload_context(ctx, env);
return ret;
}
}
ANN static m_uint _compile(struct Gwion_* gwion, struct Compiler* c) {
- if(compiler_open(gwion->mp, c) < 0)
+ if(compiler_open(c) < 0)
return 0;
- if(_check(gwion, c) < 0) {
- gw_err(_("{-}while compiling file `{0}{/}%s{-}`{0}\n"), c->base);
+ if(_check(gwion, c) < 0)
return 0;
- }
if(gwion->emit->info->code) {
const VM_Shred shred = new_vm_shred(gwion->mp, gwion->emit->info->code);
- shred->info->args = c->args;
+ shred->info->args.ptr = c->args.ptr;
vm_add_shred(gwion->vm, shred);
gwion->emit->info->code = NULL;
return shred->tick->xid;
}
ANN static m_uint compile(struct Gwion_* gwion, struct Compiler* c) {
- compiler_name(gwion->mp, c);
+ compiler_name(c);
MUTEX_LOCK(gwion->data->mutex);
const m_uint ret = _compile(gwion, c);
MUTEX_UNLOCK(gwion->data->mutex);
}
ANN static m_bool emit_exp_cast(const Emitter emit, const Exp_Cast* cast) {
- // no pos ?
- struct Op_Import opi = { .op=insert_symbol("$"), .lhs=cast->exp->type, .rhs=exp_self(cast)->type,
- .data=(uintptr_t)cast };
CHECK_BB(emit_exp(emit, cast->exp));
+ struct Op_Import opi = { .op=insert_symbol("$"), .lhs=cast->exp->type, .rhs=exp_self(cast)->type,
+ .data=(uintptr_t)cast }; // no pos ?
(void)op_emit(emit, &opi);
return GW_OK;
}
ANN static m_bool emit_exp_post(const Emitter emit, const Exp_Postfix* post) {
- // no pos ?
- struct Op_Import opi = { .op=post->op, .lhs=post->exp->type,
- .data=(uintptr_t)post };
CHECK_BB(emit_exp(emit, post->exp));
+ struct Op_Import opi = { .op=post->op, .lhs=post->exp->type,
+ .data=(uintptr_t)post }; // no pos ?
return op_emit(emit, &opi);
}
static MFUN(shred_args) {
const VM_Shred s = ME(o);
- *(m_uint*)RETURN = s->info->args ? vector_size(s->info->args) : 0;
+ *(m_uint*)RETURN = s->info->args.ptr ? vector_size(&s->info->args) : 0;
}
static MFUN(shred_arg) {
const VM_Shred s = ME(o);
const m_int idx = *(m_int*)MEM(SZ_INT);
- if(s->info->args && idx >= 0) {
- const m_str str = (m_str)vector_at(s->info->args, *(m_uint*)MEM(SZ_INT));
+ if(s->info->args.ptr && idx >= 0) {
+ const m_str str = (m_str)vector_at(&s->info->args, *(m_uint*)MEM(SZ_INT));
*(M_Object*)RETURN = str ? new_string(shred->info->mp, shred, str) : NULL;
} else
*(m_uint*)RETURN = 0;
ANN VM_Shred shreduler_get(const Shreduler s) {
Driver *const bbq = s->bbq;
struct ShredTick_ *const tk = s->list;
- if(!tk) {
- if(!vector_size(&s->shreds) && !s->loop)
- bbq->is_running = 0;
- return NULL;
- }
- const m_float time = (m_float)bbq->pos + (m_float)GWION_EPSILON;
- if(tk->wake_time <= time) {
- if((s->list = tk->next))
- s->list->prev = NULL;
- tk->next = tk->prev = NULL;
- s->curr = tk;
- return tk->self;
+ if(tk) {
+ const m_float time = (m_float)bbq->pos + (m_float)GWION_EPSILON;
+ if(tk->wake_time <= time) {
+ if((s->list = tk->next))
+ s->list->prev = NULL;
+ tk->next = tk->prev = NULL;
+ s->curr = tk;
+ return tk->self;
+ }
}
+ if(!s->loop && !vector_size(&s->shreds))
+ bbq->is_running = 0;
return NULL;
}
-ANN static void shreduler_parent(const VM_Shred out, const Vector v) {
- vector_rem2(v, (vtype)out);
- if(!vector_size(v)) {
- vector_release(v);
- out->tick->parent->child.ptr = NULL;
- }
-}
-
ANN static inline void shreduler_child(const Vector v) {
for(m_uint i = vector_size(v) + 1; --i;) {
const VM_Shred child = (VM_Shred)vector_at(v, i - 1);
}
}
-ANN static void shreduler_erase(const Shreduler s, struct ShredTick_ *tk) {
+ANN static void shreduler_erase(const Shreduler s, struct ShredTick_ *const tk) {
if(tk->parent)
- shreduler_parent(tk->self, &tk->parent->child);
+ vector_rem2(&tk->parent->child, (vtype)tk->self);
if(tk->child.ptr)
shreduler_child(&tk->child);
vector_rem2(&s->shreds, (vtype)tk->self);
ANN void shreduler_remove(const Shreduler s, const VM_Shred out, const bool erase) {
MUTEX_LOCK(s->mutex);
- struct ShredTick_ *tk = out->tick;
+ struct ShredTick_ *const tk = out->tick;
if(tk == s->curr)
s->curr = NULL;
else if(tk == s->list)
tk->prev->next = tk->next;
if(tk->next)
tk->next->prev = tk->prev;
- tk->prev = tk->next = NULL;
- if(erase) {
+ if(!erase)
+ tk->prev = tk->next = NULL;
+ else {
shreduler_erase(s, tk);
_release(out->info->me, out);
}
opcode == eHandleEffect;
}
-static inline void setpc(const m_bit *data, const m_uint i) {
+ANN static inline void setpc(const m_bit *data, const m_uint i) {
*(unsigned*)(data+1) = i + 1;
}
ANN static m_bit* tobytecode(MemPool p, const VM_Code code) {
const Vector v = &code->instr;
const m_uint sz = vector_size(v);
- m_bit *ptr = _mp_malloc(p, sz * BYTECODE_SZ);
+ m_bit *const ptr = _mp_malloc(p, sz * BYTECODE_SZ);
struct Vector_ nop;
vector_init(&nop);
for(m_uint i= 0; i < sz; ++i) {
m_bit *const final = _mp_malloc(p, sz * BYTECODE_SZ); // could use smaller size
for(m_uint i= 0, j = 0; i < sz; ++i) {
const Instr instr = (Instr)vector_at(v, i);
- unsigned opcode = instr->opcode;
+ const unsigned opcode = instr->opcode;
if(opcode != eNoOp) {
m_bit *const base = ptr + i*BYTECODE_SZ,
*const data = final + j*BYTECODE_SZ;
sprintf(name, "%s(callback)", base->name);
const Instr instr = (Instr)vector_back(&base->instr);
instr->opcode = eEOC;
- VM_Code code = new_vmcode(mp, &base->instr, base->stack_depth, base->builtin, name);
+ const VM_Code code = new_vmcode(mp, &base->instr,
+ base->stack_depth, base->builtin, name);
code->closure = base->closure;
code->callback = 1;
instr->opcode = eFuncReturn;
m_str code_name_set(MemPool p, const m_str name, const m_str file) {
const size_t len = strlen(name) + strlen(file) + 2;
- m_str str = (const m_str)_mp_malloc(p, len);
+ const m_str str = (const m_str)_mp_malloc(p, len);
sprintf(str, "%s$%s", name, file);
return str;
}
};
static inline struct ShredInfo_ *new_shredinfo(MemPool p, const VM_Code c) {
- struct ShredInfo_ *info = mp_calloc(p, ShredInfo);
+ struct ShredInfo_ *const info = mp_calloc(p, ShredInfo);
info->mp = p;
info->orig = c;
return info;
}
static inline void free_shredinfo(MemPool mp, struct ShredInfo_ *info) {
- if(info->args) { // could be a struct
- const Vector v = info->args;
+ if(info->args.ptr) {
+ const Vector v = &info->args;
LOOP_OPTIM
for(m_uint i = vector_size(v) + 1; --i;)
xfree((void*)vector_at(v, i - 1));
- free_vector(mp, v);
+ vector_release(v);
}
if(info->line.ptr)
vector_release(&info->line);
vector_release(&shred->gc);
if(shred->info->frame.ptr)
vector_release(&shred->info->frame);
+ if(shred->tick->child.ptr)
+ vector_release(&shred->tick->child);
vmcode_remref(shred->info->orig, shred->info->vm->gwion);
const MemPool mp = shred->info->mp;
mp_free(mp, ShredTick, shred->tick);