emit_add_instr(emit, RegPushNow);
else if(prim->d.var == insert_symbol("maybe"))
emit_add_instr(emit, RegPushMaybe);
- else if(prim->d.var == insert_symbol("__func__")) {
- const Instr instr = emit_add_instr(emit, RegPushStr);
- instr->m_val = (m_uint)s_name(insert_symbol(emit->env->func ?
- emit->env->func->name : emit->env->class_def ?
- emit->env->class_def->name : emit->env->name));
- } else
+ else
emit_symbol(emit, prim);
return GW_OK;
}
strcpy(c, prim->d.str);
CHECK_BB(escape_str(emit, c, exp_self(prim)->pos));
} else c[0] = '\0';
- const Instr instr = emit_add_instr(emit, RegPushStr);
- instr->m_val = (m_uint)s_name(insert_symbol(c));
+ const Value v = prim->value;
+ const Symbol sym = insert_symbol(c);
+ if(!v->d.ptr)
+ v->d.ptr = (m_uint*)new_string2(emit->gwion->mp, NULL, s_name(sym));
+ regpushi(emit, (m_uint)v->d.ptr);
+ emit_add_instr(emit, RegAddRef);
return GW_OK;
}
return env->class_def;
}
-ANN static Type prim_id(const Env env, const Exp_Primary* primary) {
+ANN static Type prim_str(const Env env, Exp_Primary *const prim) {
+ if(!prim->value) {
+ const m_str str = prim->d.str;
+ const Value v = new_value(env->gwion->mp, t_string, str);
+ char c[strlen(str) + 8];
+ sprintf(c, "%s:string", str);
+ nspc_add_value(env_nspc(env), insert_symbol(c), v);
+ prim->value = v;
+ }
+ return t_string;
+}
+
+ANN static Type prim_id(const Env env, Exp_Primary* primary) {
const m_str str = s_name(primary->d.var);
if(!strcmp(str, "this"))
return check_exp_prim_this(env, primary);
- else
+ else if(!strcmp(str, "__func__")) {
+ primary->primary_type = ae_primary_str;
+ primary->d.str = env->func ? env->func->name : env->class_def ?
+ env->class_def->name : env->name;
+ return prim_str(env, primary);
+ } else
return prim_id_non_res(env, primary);
}
}
describe_prim_xxx(num, t_int)
describe_prim_xxx(float, t_float)
-describe_prim_xxx(str, t_string)
describe_prim_xxx(nil, t_void)
typedef Type (*_type_func)(const Env, const void*);