-Subproject commit e04d8382825ddf63f52b834dee13d8b85902fb21
+Subproject commit 0112a154df71cafe08e69427e0d8487cb9bdcafb
};
ANEW ANN Func new_func(const m_str, const Func_Def);
-ANN2(1,2) Symbol func_symbol(const m_str, const m_str, const m_str, const m_uint);
+ANN2(1,2) Symbol func_symbol(const Env, const m_str, const m_str, const m_str, const m_uint);
ANN2(1,3,4) m_bool check_lambda(const Env, const Type, Exp_Lambda*, const Func_Def);
#endif
Emitter emit;
VM* vm;
struct Map_ freearg;
+ SymTable *st;
};
ANN m_bool gwion_ini(const Gwion, struct Arg_*);
#ifndef __PARSE
#define __PARSE
+
+#include "gwion.h"
+#define insert_symbol(a) insert_symbol(env->gwion->st, (a))
+
+
#define RET_NSPC(exp) \
++env->scope->depth; \
nspc_push_value(env->curr); \
ANN2(2) ANEW Type new_type(const m_uint xid, const m_str name, const Type);
ANEW ANN Type type_copy(const Type type);
-ANN m_str get_type_name(const m_str, const m_uint);
+ANN m_str get_type_name(const Env, const m_str, const m_uint);
ANN Value find_value(const Type, const Symbol);
ANN Func find_func(const Type, const Symbol);
ANN m_bool isa(const Type, const Type) __attribute__((pure));
ANN m_bool isres(const Symbol);
-ANN Type array_type(const Type, const m_uint);
+ANN Type array_type(const Env, const Type, const m_uint);
ANN Type find_common_anc(const Type, const Type) __attribute__((pure));
ANN m_uint id_list_len(ID_List);
ANN void type_path(const m_str, const ID_List);
ANN Type array_base(Type) __attribute__((pure));
ANN m_bool type_ref(Type) __attribute__((pure));
__attribute__((returns_nonnull))
-ANN Type template_parent(const Type type);
+ANN Type template_parent(const Env, const Type type);
static inline Type actual_type(const Type t) {
return isa(t, t_class) > 0 ? t->d.base_type : t;
}
static m_bool check(struct Gwion_* gwion, struct Compiler* c) {
CHECK_BB(compiler_open(c))
- CHECK_OB((c->ast = parse(c->name, c->file)))
+ CHECK_OB((c->ast = parse(gwion->st, c->name, c->file)))
gwion->env->name = c->name;
return type_engine_check_prog(gwion->env, c->ast);
}
#include "import.h"
#include "switch.h"
+#undef insert_symbol
+#define insert_symbol(a) insert_symbol(emit->env->gwion->st, (a))
+
typedef struct Local_ {
m_uint size;
m_uint offset;
if(type->nspc->pre_ctor)
emit_ext_ctor(emit, type->nspc->pre_ctor);
if(GET_FLAG(type, template) && GET_FLAG(type, builtin)) {
- const Type t = template_parent(type);
+ const Type t = template_parent(emit->env, type);
if(t->nspc->pre_ctor)
emit_ext_ctor(emit, t->nspc->pre_ctor);
}
ArrayInfo* info = mp_alloc(ArrayInfo);
vector_init(&info->type);
for(m_uint i = 1; i < t->array_depth; ++i)
- vector_add(&info->type, (vtype)array_type(base, i));
+ vector_add(&info->type, (vtype)array_type(emit->env, base, i));
vector_add(&info->type, (vtype)t);
info->depth = (m_int)t->array_depth;
info->base = base;
static const f_instr allocmember[] = { RegPushImm, RegPushImm2, RegPushImm3, AllocMember4 };
static const f_instr allocword[] = { AllocWord, AllocWord2, AllocWord3, AllocWord4 };
-ANN static inline Exp this_exp(const Type t, const uint pos) {
+ANN static inline Exp this_exp(const Emitter emit, const Type t, const uint pos) {
const Exp exp = new_exp_prim_id(insert_symbol("this"), pos);
exp->type = t;
return exp;
}
-ANN static inline Exp dot_this_exp(const Exp_Primary* prim, const Type t) {
- const Exp exp = this_exp(t, prim->self->pos);
+ANN static inline Exp dot_this_exp(const Emitter emit, const Exp_Primary* prim, const Type t) {
+ const Exp exp = this_exp(emit, t, prim->self->pos);
const Exp dot = new_exp_dot(exp, prim->d.var);
dot->d.exp_dot.t_base = t;
return dot;
}
-ANN static inline Exp dot_static_exp(const Exp_Primary* prim, const Type t) {
+ANN static inline Exp dot_static_exp(const Emitter emit, const Exp_Primary* prim, const Type t) {
const Symbol s = insert_symbol(t->name);
const Exp e = new_exp_prim_id(s, prim->self->pos);
const Value val = nspc_lookup_value1(t->nspc->parent, s);
ANN static m_bool emit_symbol_owned(const Emitter emit, const Exp_Primary* prim) {
const Value v = prim->value;
- const Exp dot = !GET_FLAG(v, static) ?
- dot_this_exp(prim, v->owner_class) : dot_static_exp(prim, v->owner_class);
+ const Exp dot = (!GET_FLAG(v, static) ? dot_this_exp : dot_static_exp)(emit, prim, v->owner_class);
dot->type = v->type;
dot->emit_var = prim->self->emit_var;
const m_bool ret = emit_exp_dot(emit, &dot->d.exp_dot);
return gwion->vm;
}
ANN m_bool gwion_ini(const Gwion gwion, Arg* arg) {
+ gwion->st = new_symbol_table(65347);
gwion->vm = new_vm();
gwion->emit = new_emitter();
gwion->env = new_env();
free_vm(gwion->vm);
free_plug(gwion);
map_release(&gwion->freearg);
- free_symbols();
+ free_symbols(gwion->st);
}
}
return GW_OK;
}
-ANN static Type fptr_type(Exp_Binary* bin) {
+ANN static Type fptr_type(const Env env, Exp_Binary* bin) {
const Func l_func = bin->lhs->type->d.func;
const Func r_func = bin->rhs->type->d.func;
const Nspc nspc = l_func->value_ref->owner;
const m_str c = s_name(l_func->def->name);
const Value v = l_func->value_ref;
for(m_uint i = 0; i <= v->offset; ++i) {
- const Symbol sym = func_symbol(nspc->name, c, NULL, i);
+ const Symbol sym = func_symbol(env, nspc->name, c, NULL, i);
const Func f = nspc_lookup_func1(nspc, sym); // was lookup2
CHECK_OO(f)
if(compat_func(r_func->def, f->def) > 0)
r_fdef->ret_type->name, l_fdef->ret_type->name)
if(isa(bin->lhs->type, t_fptr) > 0 && isa(bin->lhs->type, bin->rhs->type) > 0)
return bin->rhs->type;
- return fptr_type(bin);
+ return fptr_type(env, bin);
}
static OP_CHECK(opck_fptr_cast) {
m_uint len;
};
-ANN static ID_List templater_def(const Templater* templater) {
+ANN static ID_List templater_def(SymTable *st, const Templater* templater) {
ID_List list[templater->n];
- list[0] = new_id_list(insert_symbol(templater->list[0]), 0);
+ list[0] = new_id_list(insert_symbol(st, templater->list[0]), 0);
for(m_uint i = 1; i < templater->n; i++) {
- list[i] = new_id_list(insert_symbol(templater->list[i]), 0);
+ list[i] = new_id_list(insert_symbol(st, templater->list[i]), 0);
list[i - 1]->next = list[i];
}
return list[0];
}
}
-ANN static m_bool path_valid(ID_List* list, const struct Path* p) {
+ANN static m_bool path_valid(SymTable *st,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((i != 1 && last != '.' && last != '\0') ||
(i == 1 && c != '.')) {
path_valid_inner(p->curr);
- *list = prepend_id_list(insert_symbol(p->curr), *list, 0);
+ *list = prepend_id_list(insert_symbol(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)
return GW_OK;
}
-ANN static ID_List str2list(const m_str path, m_uint* array_depth) {
+ANN static ID_List str2list(SymTable *st, 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(&list, &p) < 0) {
+ if(path_valid(st, &list, &p) < 0) {
if(list)
free_id_list(list);
return NULL;
}
CHECK_OO(list)
strncpy(curr, path, p.len);
- list->xid = insert_symbol(curr);
+ list->xid = insert_symbol(st, curr);
return list;
}
if(type->nspc)
ERR_B(0, "during import: class '%s' already imported.", type->name)
if(gwi->templater.n) {
- const ID_List types = templater_def(&gwi->templater);
- type->def = new_class_def(0, insert_symbol(type->name), NULL, NULL);
+ const ID_List types = templater_def(gwi->gwion->st,&gwi->templater);
+ type->def = new_class_def(0, insert_symbol(gwi->gwion->st, type->name), NULL, NULL);
type->def->tmpl = new_tmpl_class(types, -1);
type->def->type = type;
SET_FLAG(type, template);
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(type, &v->array_depth)))
+ if(!(v->t.xid = str2list(gwi->gwion->st, 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(name);
+ v->var.xid = insert_symbol(gwi->gwion->st, name);
return GW_OK;
}
ANN Type_Decl* str2decl(const Env env, const m_str s, m_uint *depth) {
m_uint i = 0;
- m_str type_name = get_type_name(s, i++);
+ m_str type_name = get_type_name(env, s, i++);
CHECK_OO(type_name)
- ID_List id = str2list(type_name, depth);
+ ID_List id = str2list(env->gwion->st, type_name, depth);
CHECK_OO(id)
Type_Decl* td = new_type_decl(id, 0);
Type_List tmp = NULL;
free_id_list(id);
return NULL;
}
- while((type_name = get_type_name(s, i++))) {
+ while((type_name = get_type_name(env, s, i++))) {
m_uint d = 0;
if(!tmp)
td->types = tmp = str2tl(env, type_name, &d);
free_arg_list(arg_list);
ERR_O(0, "\t...\tat argument '%i'", i + 1)
}
- if((type_path2 = str2list(arg->name, &array_depth2)))
+ if((type_path2 = str2list(env->gwion->st, arg->name, &array_depth2)))
free_id_list(type_path2);
if(array_depth && array_depth2) {
free_type_decl(type_decl);
ERR_O(0, "array subscript specified incorrectly for built-in module")
}
array_sub = make_dll_arg_list_array(array_sub, &array_depth, array_depth2);
- var_decl = new_var_decl(insert_symbol(arg->name), array_sub, 0);
+ var_decl = new_var_decl(insert_symbol(env->gwion->st, arg->name), array_sub, 0);
arg_list = new_arg_list(type_decl, var_decl, arg_list);
}
return arg_list;
m_uint i, array_depth = 0;
flag |= ae_flag_builtin;
- if(!(type_path = str2list(dl_fun->type, &array_depth)) ||
+ if(!(type_path = str2list(env->gwion->st, dl_fun->type, &array_depth)) ||
!(type_decl = new_type_decl(type_path, 0)))
ERR_O(0, "\t...\tduring @ function import '%s' (type).", dl_fun->name)
if(array_depth) {
}
name = dl_fun->name;
arg_list = make_dll_arg_list(env, dl_fun);
- func_def = new_func_def(type_decl, insert_symbol(name), arg_list, NULL, flag);
+ func_def = new_func_def(type_decl, insert_symbol(env->gwion->st, name), arg_list, NULL, flag);
func_def->d.dl_func_ptr = (void*)(m_uint)dl_fun->addr;
return func_def;
}
CHECK_OB(def)
if(gwi->templater.n) {
def = new_func_def(NULL, NULL, NULL, NULL, 0);
- const ID_List list = templater_def(&gwi->templater);
+ const ID_List list = templater_def(gwi->gwion->st, &gwi->templater);
def->tmpl = new_tmpl_list(list, -1);
SET_FLAG(def, template);
}
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(str, &depth) : NULL;
+ const ID_List list = (str && str != (m_str)OP_ANY_TYPE) ? str2list(env->gwion->st, 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(list);
- return t ? (depth ? array_type(t, depth) : t) : NULL;
+ return t ? (depth ? array_type(env, t, depth) : t) : NULL;
}
ANN2(1,2) static int import_op(const Env env, const DL_Oper* op,
Type_Decl* type_decl = NULL;
const Arg_List args = make_dll_arg_list(env, dl_fun);
flag |= ae_flag_builtin;
- if(!(type_path = str2list(dl_fun->type, &array_depth)) ||
+ if(!(type_path = str2list(env->gwion->st, dl_fun->type, &array_depth)) ||
!(type_decl = new_type_decl(type_path, 0)))
ERR_O(0, "\t...\tduring fptr import '%s' (type).",
dl_fun->name)
- return new_stmt_fptr(insert_symbol(dl_fun->name), type_decl, args, flag);
+ return new_stmt_fptr(insert_symbol(env->gwion->st, dl_fun->name), type_decl, args, flag);
}
ANN m_int gwi_fptr_end(const Gwi gwi, const ae_flag flag) {
return GW_OK;
}
-ANN static Exp make_exp(const m_str type, const m_str name) {
+ANN static Exp make_exp(SymTable *st, 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(type, &array_depth)))
+ CHECK_OO((id_list = str2list(st, type, &array_depth)))
if(array_depth) {
array = new_array_sub(NULL);
array->depth = array_depth;
}
type_decl = new_type_decl(id_list, 0);
- const Var_Decl var_decl = new_var_decl(insert_symbol(name), array, 0);
+ const Var_Decl var_decl = new_var_decl(insert_symbol(st, name), array, 0);
const Var_Decl_List var_decl_list = new_var_decl_list(var_decl, NULL);
return new_exp_decl(type_decl, var_decl_list);
}
ANN2(1) m_int gwi_union_ini(const Gwi gwi, const m_str name) {
if(name)
- gwi->union_data.xid = insert_symbol(name);
+ gwi->union_data.xid = insert_symbol(gwi->gwion->st, name);
return GW_OK;
}
ANN m_int gwi_union_add(const Gwi gwi, const restrict m_str type, const restrict m_str name) {
- const Exp exp = make_exp(type, name);
+ const Exp exp = make_exp(gwi->gwion->st, type, name);
CHECK_OB(exp);
const Type t = type_decl_resolve(gwi->gwion->env, exp->d.exp_decl.td);
if(!t)
}
ANN m_int gwi_enum_add(const Gwi gwi, const m_str name, const m_uint i) {
- const ID_List list = new_id_list(insert_symbol(name), 0);
+ const ID_List list = new_id_list(insert_symbol(gwi->gwion->st, name), 0);
DL_Enum* d = &gwi->enum_data;
ALLOC_PTR(addr, m_int, i);
vector_add(&gwi->enum_data.addr, (vtype)addr);
ANN m_int gwi_enum_end(const Gwi gwi) {
DL_Enum* d = &gwi->enum_data;
- const Stmt stmt = new_stmt_enum(d->base, d->t ? insert_symbol(d->t) : NULL);
+ const Stmt stmt = new_stmt_enum(d->base, d->t ? insert_symbol(gwi->gwion->st, d->t) : NULL);
if(traverse_stmt_enum(gwi->gwion->env, &stmt->d.stmt_enum) < 0) {
free_id_list(d->base);
return GW_ERROR;
#include "value.h"
#include "template.h"
-ANN static Func_Def from_base(const struct dottmpl_ *dt, const Type t) {
- const Symbol sym = func_symbol(t->name, s_name(dt->base->name),
+ANN static Func_Def from_base(const Env env, const struct dottmpl_ *dt, const Type t) {
+ const Symbol sym = func_symbol(env, t->name, s_name(dt->base->name),
"template", dt->overload);
const Value v = nspc_lookup_value1(t->nspc, sym);
CHECK_OO(v)
const Func_Def base = v->d.func_ref->def;
- const Func_Def def = new_func_def(base->td, insert_symbol(v->name),
+ const Func_Def def = new_func_def(base->td, insert_symbol(env->gwion->st, v->name),
base->arg_list, base->d.code, base->flag);
def->tmpl = new_tmpl_list(base->tmpl->list, dt->overload);
SET_FLAG(def, template);
char str[instr->m_val2 + strlen(t->name) + 1];
strcpy(str, name);
strcpy(str + instr->m_val2, t->name);
- const Func f = nspc_lookup_func1(t->nspc, insert_symbol(str));
+ const Func f = nspc_lookup_func1(t->nspc, insert_symbol(emit->env->gwion->st, str));
if(f) {
if(!f->code) {
dt->def = f->def;//
shred->reg += SZ_INT;
return;
} else {
- const Func_Def def = from_base(dt, t);
+ const Func_Def def = from_base(emit->env, dt, t);
if(!def)
continue;
dt->def = def; //
#include "object.h"
#include "import.h"
#include "operator.h"
+#include "gwion.h"
ANN void exception(const VM_Shred shred, const m_str c) {
err_msg(0, "%s: shred[id=%" UINT_F ":%s], PC=[%" UINT_F "]",
M_Object new_string(const VM_Shred shred, const m_str str) {
const M_Object o = new_object(shred, t_string);
- STRING(o) = s_name(insert_symbol(str));
+ STRING(o) = s_name(insert_symbol(shred->info->vm->gwion->st, str));
return o;
}
#include "import.h"
#include "emit.h"
#include "operator.h"
+#include "gwion.h"
static OP_CHECK(opck_ptr_assign) {
const Exp_Binary* bin = (Exp_Binary*)data;
Type t = bin->lhs->type;
do {
- if(!strcmp(t->name, get_type_name(bin->rhs->type->name, 1))) {
+ if(!strcmp(t->name, get_type_name(env, bin->rhs->type->name, 1))) {
if(bin->lhs->meta != ae_meta_var)
ERR_N(0, "left side operand is constant")
bin->lhs->emit_var = 1;
static OP_CHECK(opck_ptr_deref) {
const Exp_Unary* unary = (Exp_Unary*)data;
- unary->self->type = nspc_lookup_type1(unary->exp->type->owner, insert_symbol(get_type_name(unary->exp->type->name, 1)));
+ unary->self->type = nspc_lookup_type1(unary->exp->type->owner, insert_symbol(env->gwion->st, get_type_name(env, unary->exp->type->name, 1)));
return unary->self->type;
}
static OP_CHECK(opck_implicit_ptr) {
const struct Implicit* imp = (struct Implicit*)data;
const Exp e = (Exp)imp->e;
- if(!strcmp(get_type_name(imp->t->name, 1), e->type->name)) {
+ if(!strcmp(get_type_name(env, imp->t->name, 1), e->type->name)) {
if(e->meta == ae_meta_value)
ERR_N(0, "can't cast constant to Ptr");
e->cast_to = imp->t;
#include "instr.h"
#include "object.h"
#include "import.h"
+#include "gwion.h"
ANN static void push_string(const VM_Shred shred, const M_Object obj, const m_str c) {
- STRING(obj) = s_name(insert_symbol(c));
+ STRING(obj) = s_name(insert_symbol(shred->info->vm->gwion->st, c));
*(M_Object*)REG(-SZ_INT) = (M_Object)obj;
_release(obj, shred);
}
#include "nspc.h"
#include "mpool.h"
#include "switch.h"
+#include "vm.h"
+#include "parse.h"
ANN static struct Env_Scope_ *new_scope(void) {
struct Env_Scope_ *a = mp_alloc(Env_Scope);
#include "type.h"
#include "context.h"
#include "nspc.h"
+#include "vm.h"
+#include "parse.h"
ANN Map env_label(const Env env) {
return &env->context->lbls;
#include "env.h"
#include "type.h"
#include "nspc.h"
+#include "vm.h"
+#include "parse.h"
ANN static void free_type(Type a, void *gwion) {
if(GET_FLAG(a, template))
return t->d.base_type;
}
-ANN Type array_type(const Type base, const m_uint depth) {
+ANN Type array_type(const Env env, const Type base, const m_uint depth) {
m_uint i = depth + 1;
size_t len = strlen(base->name);
char name[len + 2* depth + 1];
}
__attribute__((returns_nonnull))
-ANN Type template_parent(const Type type) {
- const m_str name = get_type_name(type->name, 0);
+ANN Type template_parent(const Env env, const Type type) {
+ const m_str name = get_type_name(env, type->name, 0);
return nspc_lookup_type1(type->nspc->parent, insert_symbol(name));
}
return 0;
}
-ANN m_str get_type_name(const m_str s, const m_uint index) {
+ANN m_str get_type_name(const Env env, const m_str s, const m_uint index) {
m_str name = strstr(s, "<");
m_uint i = 0;
m_uint lvl = 0;
return err_msg(e->pos, "array init [...] contains incompatible types ...");
}
-ANN static inline Type prim_array_match(Exp e) {
+ANN static inline Type prim_array_match(const Env env, Exp e) {
const Type type = e->type;
do CHECK_BO(prim_array_inner(e->type, type, e))
while((e = e->next));
- return array_type(type->array_depth ? array_base(type) : type, type->array_depth + 1);
+ return array_type(env, type->array_depth ? array_base(type) : type, type->array_depth + 1);
}
ANN static Type prim_array(const Env env, const Exp_Primary* primary) {
if(!e)
ERR_O(primary->self->pos, "must provide values/expressions for array [...]")
CHECK_OO(check_exp(env, e))
- return (array->type = prim_array_match(e));
+ return (array->type = prim_array_match(env, e));
}
ANN static Value check_non_res_value(const Env env, const Exp_Primary* primary) {
if(!v || !GET_FLAG(v, checked)) {
err_msg(primary->self->pos,
"variable %s not legit at this point.", s_name(primary->d.var));
- did_you_mean(s_name(primary->d.var));
+ did_you_mean(env->gwion->st, s_name(primary->d.var));
return NULL;
}
if(env->func && !GET_FLAG(v, const) && v->owner)
array->array->depth, t_base->array_depth)
}
return depth == t_base->array_depth ? array_base(t_base) :
- array_type(array_base(t_base), t_base->array_depth - depth);
+ array_type(env, array_base(t_base), t_base->array_depth - depth);
}
ANN static Type_List mk_type_list(const Env env, const Type type) {
return exp->args ? !!check_exp(env, exp->args) : -1;
}
-ANN static inline Value template_get_ready(const Value v, const m_str tmpl, const m_uint i) {
- const Symbol sym = func_symbol(v->owner->name, v->name, tmpl, i);
+ANN static inline Value template_get_ready(const Env env, const Value v, const m_str tmpl, const m_uint i) {
+ const Symbol sym = func_symbol(env, v->owner->name, v->name, tmpl, i);
return v->owner_class ? find_value(v->owner_class, sym) :
nspc_lookup_value1(v->owner, sym);
}
for(m_uint i = 0; i < v->offset + 1; ++i) {
Func_Def def = NULL;
Func_Def base = NULL;
- Value value = template_get_ready(v, tmpl_name, i);
+ Value value = template_get_ready(env, v, tmpl_name, i);
if(value) {
if(env->func == value->d.func_ref) {
free(tmpl_name);
}
base = def = value->d.func_ref->def;
if(!def->tmpl) {
- if(!(value = template_get_ready(v, "template", i)))
+ if(!(value = template_get_ready(env, v, "template", i)))
continue;
base = value->d.func_ref->def;
def->tmpl = new_tmpl_list(base->tmpl->list, (m_int)i);
}
} else {
- if(!(value = template_get_ready(v, "template", i)))
+ if(!(value = template_get_ready(env, v, "template", i)))
continue;
base = value->d.func_ref->def;
def = new_func_def(base->td, insert_symbol(v->name),
if(!GET_FLAG(ptr, checked))
check_class_def(env, ptr->def);
}
- t = depth ? array_type(ptr, depth) : ptr;
+ t = depth ? array_type(env, ptr, depth) : ptr;
stmt->v = new_value(t, s_name(stmt->sym));
SET_FLAG(stmt->v, checked);
nspc_add_value(env->curr, stmt->sym, stmt->v);
}
ANN static inline Func get_overload(const Env env, const Func_Def def, const m_uint i) {
- const Symbol sym = func_symbol(env->curr->name, s_name(def->name), NULL, i);
+ const Symbol sym = func_symbol(env, env->curr->name, s_name(def->name), NULL, i);
return nspc_lookup_func1(env->curr, sym);
}
return variadic;
}
-ANN static void operator_func(Func f) {
+ANN static void operator_func(const Func f) {
const Arg_List a = f->def->arg_list;
const m_bool is_unary = GET_FLAG(f->def, unary);
const Type l = is_unary ? NULL : a->type;
#include <string.h>
#include "env.h"
#include "type.h"
+#include "vm.h"
+#include "gwion.h"
ANN Func get_func(const Env env, const Func_Def def) {
Func f = def->func;
CHECK_OO(f)
char c[len + elen + 1];
memcpy(c, f->name, len);
strcpy(c + len, env->class_def->name);
- return nspc_lookup_func1(env->class_def->nspc, insert_symbol(c));
+ return nspc_lookup_func1(env->class_def->nspc, insert_symbol(env->gwion->st, c));
}
return f;
}
-ANN2(1,2) Symbol func_symbol(const m_str nspc, const m_str base,
+ANN2(1,2) Symbol func_symbol(const Env env, const m_str nspc, const m_str base,
const m_str tmpl, const m_uint i) {
char* name;
CHECK_BO(asprintf(&name, "%s%s%s%s@%" UINT_F "@%s",
base, !tmpl ? "" : "<", !tmpl ? "" : tmpl, !tmpl ? "" : ">",
i, nspc))
- const Symbol sym = insert_symbol(name);
+ const Symbol sym = insert_symbol(env->gwion->st, name);
free(name);
return sym;
}
#include "func.h"
#include "nspc.h"
#include "operator.h"
+#include "gwion.h"
typedef Type (*f_type)(const Env env, const Exp exp);
for(size_t i = 0; i < len; i++)
c[i] = type->name[i];
c[len] = 0;
- return nspc_lookup_type1(env->curr, insert_symbol(c));
+ return nspc_lookup_type1(env->curr, insert_symbol(env->gwion->st, c));
}
return t->parent;
}
#include "value.h"
#include "func.h"
#include "nspc.h"
+#include "vm.h"
+#include "parse.h"
ANN m_bool scan0_class_def(const Env env, const Class_Def class_def);
-ANN static Value mk_class(const Type base) {
+ANN static Value mk_class(const Env env, const Type base) {
const Type t = type_copy(t_class);
const Value v = new_value(t, base->name);
t->d.base_type = base;
t->flag = stmt->td->flag;
stmt->type = t;
nspc_add_type(t->owner, stmt->xid, t);
- stmt->value = mk_class(t);
+ stmt->value = mk_class(env, t);
return GW_OK;
}
stmt->t = t;
if(stmt->xid) {
nspc_add_type(nspc, stmt->xid, t);
- mk_class(t);
+ mk_class(env, t);
}
return GW_OK;
}
-ANN static Type union_type(const Nspc nspc, const Symbol s, const m_bool add) {
+ANN static Type union_type(const Env env, const Nspc nspc, const Symbol s, const m_bool add) {
const m_str name = s_name(s);
const Type t = type_copy(t_union);
t->name = name;
t->owner = nspc;
if(add) {
nspc_add_type(nspc, s, t);
- mk_class(t);
+ mk_class(env, t);
}
return t;
}
CHECK_BB(scan0_defined(env, stmt->xid, stmt->self->pos))
const Nspc nspc = !GET_FLAG(stmt, global) ?
env->curr : env->global_nspc;
- const Type t = union_type(nspc, stmt->type_xid ?: stmt->xid,
+ const Type t = union_type(env, nspc, stmt->type_xid ?: stmt->xid,
!!stmt->type_xid);
stmt->value = new_value(t, s_name(stmt->xid));
stmt->value->owner_class = env->class_def;
} else if(stmt->type_xid) {
const Nspc nspc = !GET_FLAG(stmt, global) ?
env->curr : env->global_nspc;
- stmt->type = union_type(nspc, stmt->type_xid, 1);
+ stmt->type = union_type(env, nspc, stmt->type_xid, 1);
}
return GW_OK;
}
while((body = body->next));
env_pop(env, scope);
}
- (void)mk_class(class_def->type);
+ (void)mk_class(env, class_def->type);
if(GET_FLAG(class_def, global))
env->curr = (Nspc)vector_pop(&env->scope->nspc_stack);
return GW_OK;
#include "nspc.h"
#include "value.h"
#include "optim.h"
+#include "vm.h"
#include "parse.h"
#define FAKE_FUNC ((Func)1)
if(var->array) {
if(var->array->exp)
CHECK_BB(scan1_exp(env, var->array->exp))
- t = array_type(decl->type, var->array->depth);
+ t = array_type(env, decl->type, var->array->depth);
}
const Value v = var->value = former ? former : new_value(t, s_name(var->xid));
nspc_add_value(nspc, var->xid, v);
return var->value;
}
-ANN static m_bool scan2_args(const Func_Def f) { GWDEBUG_EXE
+ANN static m_bool scan2_args(const Env env, const Func_Def f) { GWDEBUG_EXE
Arg_List list = f->arg_list;
do {
const Var_Decl var = list->var_decl;
if(var->array)
- list->type = array_type(list->type, var->array->depth);
+ list->type = array_type(env, list->type, var->array->depth);
var->value = arg_value(list);
var->value->offset = f->stack_depth;
f->stack_depth += list->type->size;
struct Func_Def_ d = { .stack_depth=0 };
d.arg_list = ptr->args;
if(d.arg_list)
- CHECK_BB(scan2_args(&d))
+ CHECK_BB(scan2_args(env, &d))
const Func_Def def = new_func_def(ptr->td, ptr->xid, ptr->args, NULL, ptr->td->flag);
def->ret_type = ptr->ret_type;
def->stack_depth = d.stack_depth;
const m_bool base = tmpl_list_base(f->tmpl);
const m_bool tmpl = GET_FLAG(overload, template);
if(isa(overload->type, t_function) < 0)
- ERR_B(f->td->xid->pos, "function name '%s' is already used by another value",
- s_name(f->name))
+ ERR_B(f->td->xid->pos, "function name '%s' is already used by another value", overload->name)
if((!tmpl && base) || (tmpl && !base && !GET_FLAG(f, template)))
ERR_B(f->td->xid->pos, "must overload template function with template")
return GW_OK;
}
m_bool ret = compat_func(ff->def, f);
if(ret > 0) {
- const Symbol sym = func_symbol(env->curr->name, func_name,
+ const Symbol sym = func_symbol(env, env->curr->name, func_name,
"template", ff->vt_index);
nspc_add_value(env->curr, sym, value);
if(!overload) {
}
} while(type && (type = type->parent) && (nspc = type->nspc));
--i;
- const Symbol sym = func_symbol(env->curr->name, func_name, "template", i);
+ const Symbol sym = func_symbol(env, env->curr->name, func_name, "template", i);
nspc_add_value(env->curr, sym, value);
if(!overload) {
func->vt_index = i;
}
tmpl_name[tlen+1] = '\0';
vector_release(&v);
- const Symbol sym = func_symbol(env->curr->name, func_name, tmpl_name, (m_uint)f->tmpl->base);
+ const Symbol sym = func_symbol(env, env->curr->name, func_name, tmpl_name, (m_uint)f->tmpl->base);
return s_name(sym);
}
if(tmpl_list_base(f->tmpl))
return scan2_func_def_template(env, f, overload);
if(!f->tmpl) {
- const Symbol sym = func_symbol(env->curr->name, func_name, NULL, overload ? ++overload->offset : 0);
+ const Symbol sym = func_symbol(env, env->curr->name, func_name, NULL, overload ? ++overload->offset : 0);
func_name = s_name(sym);
} else {
if(f->func)
if(GET_FLAG(func->def, variadic))
f->stack_depth += SZ_INT;
f->ret_type = type_decl_resolve(env, f->td);
- return (f->arg_list && f->arg_list->type) ? scan2_args(f) : GW_OK;
+ return (f->arg_list && f->arg_list->type) ? scan2_args(env, f) : GW_OK;
}
}
const Func base = get_func(env, f);
f->func = base;
}
if(f->arg_list)
- CHECK_BB(scan2_args(f))
+ CHECK_BB(scan2_args(env, f))
if(!GET_FLAG(f, builtin) && f->d.code->d.stmt_code.stmt_list)
CHECK_BB(scan2_func_def_code(env, f))
if(!base) {
#include "type.h"
#include "nspc.h"
#include "template.h"
+#include "vm.h"
+#include "parse.h"
-ANN static inline Type owner_type(const Type t) {
+ANN static inline Type owner_type(const Env env, const Type t) {
const Nspc nspc = t->nspc ? t->nspc->parent : NULL;
return (nspc && nspc->parent) ? nspc_lookup_type1(nspc->parent, insert_symbol(nspc->name)) : NULL;
}
-ANEW ANN static Vector get_types(Type t) {
+ANEW ANN static Vector get_types(const Env env, Type t) {
const Vector v = new_vector();
do if(GET_FLAG(t, template))
vector_add(v, (vtype)t->def->tmpl->list.list);
- while((t = owner_type(t)));
+ while((t = owner_type(env, t)));
return v;
}
return list;
}
-ANN static ID_List get_total_type_list(const Type t) {
- const Type parent = owner_type(t);
+ANN static ID_List get_total_type_list(const Env env, const Type t) {
+ const Type parent = owner_type(env, t);
if(!parent)
return t->def->tmpl ? t->def->tmpl->list.list : NULL;
- const Vector v = get_types(parent);
+ const Vector v = get_types(env, parent);
const ID_List base = (ID_List)vector_pop(v);
if(!base) {
free_vector(v);
SET_FLAG(a->type, dtor);
ADD_REF(t->nspc->dtor)
}
- a->tmpl = new_tmpl_class(get_total_type_list(t), 0);
+ a->tmpl = new_tmpl_class(get_total_type_list(env, t), 0);
a->tmpl->base = type->types;
nspc_add_type(t->owner, insert_symbol(a->type->name), a->type);
return a->type;
#include "oo.h"
#include "env.h"
#include "type.h"
+#include "vm.h"
+#include "parse.h"
ANN Type type_decl_resolve(const Env env, const Type_Decl* td) {
Type t = find_type(env, td->xid);
CHECK_OO(t)
CHECK_OO((t = scan_type(env, t, td)))
- return !td->array ? t : array_type(t, td->array->depth);
+ return !td->array ? t : array_type(env, t, td->array->depth);
}
struct td_info {
return info.str;
}
-ANN static inline void* type_unknown(const ID_List id) {
+#include "vm.h"
+#include "gwion.h"
+ANN static inline void* type_unknown(const Env env, const ID_List id) {
char path[id_list_len(id)];
type_path(path, id);
err_msg(id->pos, "unknown type '%s'", path);
- did_you_mean(s_name(id->xid));
+ did_you_mean(env->gwion->st, s_name(id->xid));
return NULL;
}
ANN Type known_type(const Env env, const Type_Decl* td) {
const Type t = type_decl_resolve(env, td);
- return t ? prim_ref(t, td) : type_unknown(td->xid);
+ return t ? prim_ref(t, td) : type_unknown(env, td->xid);
}
#include "env.h"
#include "value.h"
#include "type.h"
+#include "vm.h"
+#include "parse.h"
ANN m_bool isres(const Symbol xid) {
const m_str s = s_name(xid);
-Subproject commit 1e9a605aeb73cef2853972984b90e6dc43324d84
+Subproject commit f2f9ab4bec6cffc26da671aa5d1907bb05b2a5ad