-Subproject commit 853459cbbf4693c87febaa4be332818cf191a03b
+Subproject commit 86c07142d6942990d228ed1cd4d584e898cfe90f
ANN m_bool type_engine_check_prog(const Env, const Ast);
ANN Func get_func(const Env, const Func_Def);
ANN m_bool traverse_func_template(const Env env, const Func_Def def, const Type_List types);
-ANN ID_List str2list(SymTable *st, const m_str path, m_uint* array_depth);
+ANN ID_List str2list(const Env, const m_str path, m_uint* array_depth);
#endif
OP_CHECK(opck_const_rhs);
OP_CHECK(opck_unary_meta);
+OP_CHECK(opck_unary_meta2);
OP_CHECK(opck_unary);
OP_CHECK(opck_post);
OP_CHECK(opck_rassign);
#define __MEMOIZE
typedef struct Memoize_ * Memoize;
-Memoize memoize_ini(MemPool, const Func, const enum Kind);
+Memoize memoize_ini(const Emitter, const Func, const enum Kind);
void memoize_end(MemPool, Memoize);
INSTR(MemoizeCall);
INSTR(MemoizeStore);
scope_add(&n->info->b, (vtype)s, (vtype)a); \
} \
ANN static inline void nspc_push_##b(MemPool p, const Nspc n) { scope_push(p, &n->info->b); }\
-ANN inline static void nspc_pop_##b (MemPool p, const Nspc n) { scope_pop (p, &n->info->b); }\
+ANN static inline void nspc_pop_##b (MemPool p, const Nspc n) { scope_pop (p, &n->info->b); }\
describe_lookups(A, b)
describe_nspc_func(Value, value)
eGcAdd,
eGcEnd,
eGack,
+ eDotTmplVal,
eOP_MAX,
};
#define GcAdd (f_instr)eGcAdd
#define GcEnd (f_instr)eGcEnd
#define Gack (f_instr)eGack
+#define DotTmplVal (f_instr)eDotTmplVal
#define OP_MAX (f_instr)eOP_MAX
#endif
GcAdd
GcEnd
Gack
-OP_MAX
+DotTmplVal
+OP_MAX
\ No newline at end of file
const m_uint size = v->type->size;
if(isa(v->type, t_class) < 0) {
const Instr instr = emit_kind(emit, size, emit_var, dotstatic);
- instr->m_val = (m_uint)(v->owner_class->nspc->info->class_data + v->offset);
+ instr->m_val = (m_uint)(v->owner->info->class_data + v->offset);
instr->m_val2 = size;
} else {
const Instr instr = emit_add_instr(emit, RegPushImm);
static inline m_bool push_func_code(const Emitter emit, const Func f) {
if(GET_FLAG(f, template) && f->value_ref->owner_class) {
const Instr instr = (Instr)vector_back(&emit->code->instr);
- assert(instr->execute == DotTmpl);
+// assert(instr->execute == DotTmplVal);
+ assert(instr->opcode == DotTmplVal);
size_t len = strlen(f->name);
size_t sz = len - strlen(f->value_ref->owner_class->name);
char c[sz + 1];
dt->overload = f->def->tmpl->base;
dt->tl = tmpl_tl(emit->env, c);
dt->base = f->def;
+ instr->opcode = OP_MAX;
instr->m_val = (m_uint)dt;
instr->m_val2 = strlen(c);
+ instr->execute = DotTmpl;
return GW_OK;
}
if(vector_size(&emit->code->instr)) {
ANN static Instr emit_flow(const Emitter emit, const Type type,
const f_instr f1, const f_instr f2) { GWDEBUG_EXE
- if(isa(type, t_float) > 0) {
+ if(isa(type, t_float) > 0 || isa(type, t_dur) > 0 || isa(type, t_time) > 0)
return emit_add_instr(emit, f2);
- }
return emit_add_instr(emit, f1);
}
func_i->m_val = (m_uint)(func->code ?: (VM_Code)func);
return GW_OK;
}
- const Instr instr = emit_add_instr(emit, !func->def->tmpl ? GET_FLAG(func, member) ? DotFunc : DotStaticFunc : DotTmpl);
- instr->m_val = func->vt_index;
+ if(func->def->tmpl) {
+//const Instr push = emit_add_instr(emit, RegPushImm);
+//push->m_val = func;
+ const Instr instr = emit_add_instr(emit, DotTmplVal);
+//printf("func %p\n", func);
+// instr->m_val = func;
+// instr->m_val2 = SZ_INT;
+ } else {
+ const Instr instr = emit_add_instr(emit, GET_FLAG(func, member) ? DotFunc : DotStaticFunc);
+ instr->m_val = func->vt_index;
+ }
return GW_OK;
}
if(!emit->env->class_def && !GET_FLAG(func_def, global) && !func_def->tmpl)
emit_func_def_global(emit, func->value_ref);
if(emit->memoize && GET_FLAG(func, pure))
- func->code->memoize = memoize_ini(emit->gwion->p, func,
+ func->code->memoize = memoize_ini(emit, func,
kindof(func->def->base->ret_type->size, !func->def->base->ret_type->size));
return GW_OK;
}
#include "oo.h"
#include "env.h"
#include "vm.h"
-#include "type.h"
#include "instr.h"
+#include "emit.h"
+#include "gwion.h"
+#include "type.h"
#include "func.h"
#include "memoize.h"
m_uint arg_sz;
m_uint ret_sz;
struct pool *p;
+ size_t limit;
+ size_t curr;
m_bool member;
enum Kind kind;
};
static void(*mreturn[])(m_bit*, const m_bit*, const m_uint) =
{ memoize_return1, memoize_return2, memoize_return3, memoize_return4};
-Memoize memoize_ini(MemPool p, const Func f, const enum Kind kind) {
- Memoize m = mp_alloc(p, Memoize);
+Memoize memoize_ini(const Emitter emit, const Func f, const enum Kind kind) {
+ Memoize m = mp_alloc(emit->gwion->p, Memoize);
vector_init(&m->v);
m->ret_sz = f->def->base->ret_type->size;
m->kind = kind;
m->member = SZ_INT;
m->arg_sz = f->def->stack_depth - SZ_INT;
}
+ m->limit = emit->memoize;
m->p = new_pool((uint32_t)(m->arg_sz + m->ret_sz));
return m;
}
static inline void memoize_set(Memoize m, const m_bit* arg) {
m_bit* data = _mp_alloc2(m->p);
memcpy(data, arg, m->arg_sz);
- vector_add(&m->v, (vtype)data);
+ if(vector_size(&m->v) < m->limit)
+ vector_add(&m->v, (vtype)data);
+ else
+ vector_set(&m->v, m->curr++ % m->limit, (vtype)data);
}
m_bool memoize_get(VM_Shred shred) {
return GW_OK;
}
-ANN static m_bool name_valid(const m_str a) {
+ANN static m_bool name_valid(Env env, const m_str a) {
const m_uint len = strlen(a);
m_uint lvl = 0;
for(m_uint i = 0; i < len; i++) {
continue;
}
if(c == ',') {
- if(!lvl)
- ERR_B(0, "illegal use of ',' outside of templating in name '%s'.", a)
+ if(!lvl) {
+ gwion_err(env->gwion, 0, "illegal use of ',' outside of templating in name '%s'.", a);
+ return GW_ERROR;
+ }
continue;
}
if(c == '>') {
- if(!lvl)
- ERR_B(0, "illegal templating in name '%s'.", a)
+ if(!lvl) {
+ gwion_err(env->gwion, 0, "illegal templating in name '%s'.", a);
+ return GW_ERROR;
+ }
lvl--;
continue;
}
- ERR_B(0, "illegal character '%c' in name '%s'.", c, a)
+ gwion_err(env->gwion, 0, "illegal character '%c' in name '%s'.", c, a);
+ return GW_ERROR;
}
return !lvl ? 1 : -1;
}
}
}
-ANN static m_bool path_valid(SymTable *st,ID_List* list, const struct Path* p) {
+ANN static m_bool path_valid(const Env env,ID_List* list, const struct Path* p) {
char last = '\0';
for(m_uint i = p->len + 1; --i;) {
const char c = p->path[i - 1];
- if(c != '.' && check_illegal(p->curr, c, i) < 0)
- ERR_B(0, "illegal character '%c' in path '%s'.", c, p->path)
+ if(c != '.' && check_illegal(p->curr, c, i) < 0) {
+ gwion_err(env->gwion, 0, "illegal character '%c' in path '%s'.", c, p->path);
+ return GW_ERROR;
+ }
if(c == '.' || i == 1) {
if((i != 1 && last != '.' && last != '\0') ||
(i == 1 && c != '.')) {
path_valid_inner(p->curr);
- *list = prepend_id_list(st->p, insert_symbol(st, p->curr), *list, 0);
+ *list = prepend_id_list(env->gwion->st->p, insert_symbol(env->gwion->st, p->curr), *list, 0);
memset(p->curr, 0, p->len + 1);
- } else
- ERR_B(0, "path '%s' must not ini or end with '.'.", p->path)
+ } else {
+ gwion_err(env->gwion, 0, "path '%s' must not ini or end with '.'.", p->path);
+ return GW_ERROR;
+ }
}
last = c;
}
return GW_OK;
}
-ANN /* static */ ID_List str2list(SymTable *st, const m_str path, m_uint* array_depth) {
+ANN /* static */ ID_List str2list(const Env env, const m_str path, m_uint* array_depth) {
const m_uint len = strlen(path);
ID_List list = NULL;
m_uint depth = 0;
p.len -= 2;
}
*array_depth = depth;
- if(path_valid(st, &list, &p) < 0) {
+ if(path_valid(env, &list, &p) < 0) {
if(list)
- free_id_list(st->p, list);
+ free_id_list(env->gwion->p, list);
return NULL;
}
CHECK_OO(list)
strncpy(curr, path, p.len);
- list->xid = insert_symbol(st, curr);
+ list->xid = insert_symbol(env->gwion->st, curr);
return list;
}
ANN m_int gwi_add_type(const Gwi gwi, const Type type) {
if(type->name[0] != '@')
- CHECK_BB(name_valid(type->name));
+ CHECK_BB(name_valid(gwi->gwion->env, type->name));
env_add_type(gwi->gwion->env, type);
return (m_int)type->xid;
}
ANN m_int gwi_item_ini(const Gwi gwi, const restrict m_str type, const restrict m_str name) {
DL_Var* v = &gwi->var;
memset(v, 0, sizeof(DL_Var));
- if(!(v->t.xid = str2list(gwi->gwion->st, type, &v->array_depth)))
+ if(!(v->t.xid = str2list(gwi->gwion->env, type, &v->array_depth)))
ERR_B(0, "\t...\tduring var import '%s.%s'.",
gwi->gwion->env->class_def->name, name)
v->var.xid = insert_symbol(gwi->gwion->st, name);
m_uint i = 0;
m_str type_name = get_type_name(env, s, i++);
CHECK_OO(type_name)
- ID_List id = str2list(env->gwion->st, type_name, depth);
+ ID_List id = str2list(env, type_name, depth);
CHECK_OO(id)
Type_Decl* td = new_type_decl(env->gwion->p, id, 0);
Type_List tmp = NULL;
free_arg_list(env->gwion->p, arg_list);
ERR_O(0, "\t...\tat argument '%i'", i + 1)
}
- if((type_path2 = str2list(env->gwion->st, arg->name, &array_depth2)))
+ if((type_path2 = str2list(env, arg->name, &array_depth2)))
free_id_list(env->gwion->p, type_path2);
if(array_depth && array_depth2) {
free_type_decl(env->gwion->p, type_decl);
m_uint i, array_depth = 0;
flag |= ae_flag_builtin;
- if(!(type_path = str2list(env->gwion->st, dl_fun->type, &array_depth)) ||
+ if(!(type_path = str2list(env, dl_fun->type, &array_depth)) ||
!(type_decl = new_type_decl(env->gwion->p, type_path, 0)))
ERR_O(0, "\t...\tduring @ function import '%s' (type).", dl_fun->name)
if(array_depth) {
}
ANN static Func_Def import_fun(const Env env, DL_Func * mfun, const ae_flag flag) {
- CHECK_BO(name_valid(mfun->name));
+ CHECK_BO(name_valid(env, mfun->name));
return make_dll_as_fun(env, mfun, flag);
}
static Type get_type(const Env env, const m_str str) {
m_uint depth = 0;
- const ID_List list = (str && str != (m_str)OP_ANY_TYPE) ? str2list(env->gwion->st, str, &depth) : NULL;
+ const ID_List list = (str && str != (m_str)OP_ANY_TYPE) ? str2list(env, str, &depth) : NULL;
const Type t = (str == (m_str) OP_ANY_TYPE) ? OP_ANY_TYPE : list ? find_type(env, list) : NULL;
if(list)
free_id_list(env->gwion->p, list);
Type_Decl* type_decl = NULL;
const Arg_List args = make_dll_arg_list(env, dl_fun);
flag |= ae_flag_builtin;
- if(!(type_path = str2list(env->gwion->st, dl_fun->type, &array_depth)) ||
+ if(!(type_path = str2list(env, dl_fun->type, &array_depth)) ||
!(type_decl = new_type_decl(env->gwion->p, type_path, 0)))
ERR_O(0, "\t...\tduring fptr import '%s' (type).",
dl_fun->name)
return t;
}
-ANN static Exp make_exp(SymTable *st, const m_str type, const m_str name) {
+ANN static Exp make_exp(const Env env, const m_str type, const m_str name) {
Type_Decl *type_decl;
ID_List id_list;
m_uint array_depth;
Array_Sub array = NULL;
- CHECK_OO((id_list = str2list(st, type, &array_depth)))
+ CHECK_OO((id_list = str2list(env, type, &array_depth)))
if(array_depth) {
- array = new_array_sub(st->p, NULL);
+ array = new_array_sub(env->gwion->p, NULL);
array->depth = array_depth;
}
- type_decl = new_type_decl(st->p, id_list, 0);
- const Var_Decl var_decl = new_var_decl(st->p, insert_symbol(st, name), array, 0);
- const Var_Decl_List var_decl_list = new_var_decl_list(st->p, var_decl, NULL);
- return new_exp_decl(st->p, type_decl, var_decl_list);
+ type_decl = new_type_decl(env->gwion->p, id_list, 0);
+ const Var_Decl var_decl = new_var_decl(env->gwion->p,
+ insert_symbol(env->gwion->st, name), array, 0);
+ const Var_Decl_List var_decl_list = new_var_decl_list(env->gwion->p, var_decl, NULL);
+ return new_exp_decl(env->gwion->p, type_decl, var_decl_list);
}
ANN2(1) m_int gwi_union_ini(const Gwi gwi, const m_str name) {
}
ANN m_int gwi_union_add(const Gwi gwi, const restrict m_str type, const restrict m_str name) {
- const Exp exp = make_exp(gwi->gwion->st, type, name);
+ const Exp exp = make_exp(gwi->gwion->env, type, name);
CHECK_OB(exp);
const Type t = type_decl_resolve(gwi->gwion->env, exp->d.exp_decl.td);
if(!t)
CHECK_BB(gwi_oper_end(gwi, op_eq, EqObject))
CHECK_BB(gwi_oper_end(gwi, op_ne, NeqObject))
CHECK_BB(gwi_oper_ini(gwi, NULL, "Object", "int"))
- CHECK_BB(gwi_oper_add(gwi, opck_unary_meta))
+ CHECK_BB(gwi_oper_add(gwi, opck_unary_meta2))
CHECK_BB(gwi_oper_end(gwi, op_not, IntNot))
gwi_item_ini(gwi, "@null", "null");
gwi_item_end(gwi, 0, NULL);
return unary->exp->type;
}
+OP_CHECK(opck_unary_meta2) {
+ const Exp_Unary* unary = (Exp_Unary*)data;
+ exp_self(unary)->meta = ae_meta_value;
+ return t_int;
+}
+
OP_CHECK(opck_unary) {
const Exp_Unary* unary = (Exp_Unary*)data;
if(unary->exp->meta != ae_meta_var)
CHECK_BB(gwi_oper_ini(gwi, NULL, "int", "int"))
CHECK_BB(gwi_oper_add(gwi, opck_unary_meta))
CHECK_BB(gwi_oper_end(gwi, op_sub, int_negate))
- CHECK_BB(gwi_oper_add(gwi, opck_unary_meta))
+ CHECK_BB(gwi_oper_add(gwi, opck_unary_meta2))
CHECK_BB(gwi_oper_end(gwi, op_not, IntNot))
CHECK_OP(inc, unary, pre_inc)
CHECK_OP(dec, unary, pre_dec)
return import_int_values(gwi);
}
-OP_CHECK(opck_unary_meta2) {
- const Exp_Unary* unary = (Exp_Unary*)data;
- exp_self(unary)->meta = ae_meta_value;
- return t_int;
-}
-
static GWION_IMPORT(values) {
VM* vm = gwi_vm(gwi);
ALLOC_PTR(gwi->gwion->p, d_zero, m_float, 0.0);
struct scope_iter iter = { &a->info->value, 0, 0 };
Value v;
while(scope_iter(&iter, &v) > 0) {
- if(isa(v->type, t_object) > 0 ||
+ if(v->type && (isa(v->type, t_object) > 0 ||
(isa(v->type, t_union) > 0 &&
- (GET_FLAG(v, static) || GET_FLAG(v, global)))) {
+ (GET_FLAG(v, static) || GET_FLAG(v, global))))) {
nspc_release_object(a, v, gwion);
}
REM_REF(v, gwion);
#define describe_find(name, t) \
ANN t find_##name(const Type type, const Symbol xid) { \
- const t val = nspc_lookup_##name##1(type->nspc, xid); \
+ const t val = nspc_lookup_##name##0(type->nspc, xid); \
if(val) \
return val; \
return type->parent ? find_##name(type->parent, xid) : NULL; \
ERR_O(td->exp->pos, "Expression must be of type '%s', not '%s'\n"
"maybe you meant typeof(Expression)", t_class->name, td->exp->type->name);
m_uint depth;
- td->xid = str2list(env->gwion->st, t->name, &depth);
+ td->xid = str2list(env, t->name, &depth);
if(depth) {
Exp base = new_exp_prim_int(env->gwion->p, 0, 0), e = base;
ERR_B(var->pos, "variable %s has already been defined in the same scope...",
s_name(var->xid))
if(var->array && decl->type != t_undefined) {
- if(var->array->exp)
+ if(var->array->exp) {
+ if(GET_FLAG(decl->td, ref))
+ ERR_B(td_pos(decl->td), "ref array must not have array expression.\n"
+ "e.g: int @my_array[];\nnot: int my_array[2];")
CHECK_BB(scan1_exp(env, var->array->exp))
+ }
t = array_type(env, decl->type, var->array->depth);
}
const Value v = var->value = former ? former : new_value(env->gwion->p, t, s_name(var->xid));
&&staticint, &&staticfloat, &&staticother,
&&dotfunc, &&dotstaticfunc, &&staticcode, &&pushstr,
&&gcini, &&gcadd, &&gcend,
- &&gack, &&other
+ &&gack, &®pushimm, &&other
};
const Shreduler s = vm->shreduler;
register VM_Shred shred;
autoloopptr:
*(m_bit**)(*(M_Object*)(mem + instr->m_val + SZ_INT))->data = m_vector_addr(ARRAY(a.obj), *(m_uint*)(mem + instr->m_val));
autoloopcount:
- *(m_uint*)reg = m_vector_size(ARRAY(a.obj)) - ++*(m_uint*)(mem + instr->m_val);
+ *(m_uint*)reg = m_vector_size(ARRAY(a.obj)) - (*(m_uint*)(mem + instr->m_val))++;
reg += SZ_INT;
DISPATCH()
arraytop:
-Subproject commit cb9e371b894ede91c4c0830e1ee494dd50483c02
+Subproject commit adc983bec96f51536b394816048fa7bfe3ccd7c7