From: Jérémie Astor Date: Tue, 26 Nov 2019 03:42:12 +0000 (+0100) Subject: :art: global string X-Git-Tag: nightly~2076^2~7 X-Git-Url: http://10.10.0.4:5575/?a=commitdiff_plain;h=054f58ada550205b216d51b094b70fccf40480dc;p=gwion.git :art: global string --- diff --git a/include/env/env.h b/include/env/env.h index 89e60847..21e78232 100644 --- a/include/env/env.h +++ b/include/env/env.h @@ -51,4 +51,5 @@ ANN m_bool already_defined(const Env env, const Symbol s, const loc_t pos); ANN m_bool type_engine_check_prog(const Env, const Ast); ANN m_bool traverse_func_template(const Env, const Func_Def); ANN2(1,3) void env_err(const Env, const loc_t pos, const m_str fmt, ...); +ANN Value global_string(const Env env, const m_str str); #endif diff --git a/src/lib/string.c b/src/lib/string.c index 829a73c1..d0fb29da 100644 --- a/src/lib/string.c +++ b/src/lib/string.c @@ -170,12 +170,12 @@ static CTOR(string_ctor) { STRING(o) = ""; } -ANN Type check_prim_str(const Env, const m_str *); ID_CHECK(check_funcpp) { ((Exp_Primary*)prim)->prim_type = ae_prim_str; ((Exp_Primary*)prim)->d.str = env->func ? env->func->name : env->class_def ? env->class_def->name : env->name; - return check_prim_str(env, &prim->d.str); + ((Exp_Primary*)prim)->value = global_string(env, prim->d.str); + return prim->value->type; } static GACK(gack_string) { diff --git a/src/oo/env_utils.c b/src/oo/env_utils.c index 97dbe740..039576ef 100644 --- a/src/oo/env_utils.c +++ b/src/oo/env_utils.c @@ -92,3 +92,15 @@ ANN Value mk_class(const Env env, const Type base) { nspc_add_value_front(base->e->owner, sym, v); return v; } + +ANN Value global_string(const Env env, const m_str str) { + char c[strlen(str) + 8]; + sprintf(c, "%s:string", str); + const Symbol sym = insert_symbol(c); + const Value v = nspc_lookup_value0(env->global_nspc, sym); + if(v) + return v; + const Value value = new_value(env->gwion->mp, env->gwion->type[et_string], s_name(sym)); + nspc_add_value_front(env->global_nspc, sym, value); + return value; +} diff --git a/src/parse/check.c b/src/parse/check.c index 8b4dfe64..e4bd38ea 100644 --- a/src/parse/check.c +++ b/src/parse/check.c @@ -250,22 +250,9 @@ ANN static Type prim_id_non_res(const Env env, const Symbol *data) { return v->type; } -ANN static inline Value prim_str_value(const Env env, const Symbol sym) { - const Value v = nspc_lookup_value0(env->global_nspc, sym); - if(v) - return v; - const Value value = new_value(env->gwion->mp, env->gwion->type[et_string], s_name(sym)); - nspc_add_value_front(env->global_nspc, sym, value); - return value; -} - ANN Type check_prim_str(const Env env, const m_str *data) { - if(!prim_self(data)->value) { - const m_str str = *data; - char c[strlen(str) + 8]; - sprintf(c, "%s:string", str); - prim_self(data)->value = prim_str_value(env, insert_symbol(c)); - } + if(!prim_self(data)->value) + prim_self(data)->value = global_string(env, *data); return env->gwion->type[et_string];// prim->value }