From 906180830ead1f83fe779a05569e9c0faf6d273c Mon Sep 17 00:00:00 2001 From: fennecdjay Date: Sun, 3 Jul 2022 17:56:55 +0200 Subject: [PATCH] :bug: Resolve __file__ and the like later --- ast | 2 +- src/lib/string.c | 25 ++++++++++++++++++++++--- 2 files changed, 23 insertions(+), 4 deletions(-) diff --git a/ast b/ast index b4c4887f..1df0ae61 160000 --- a/ast +++ b/ast @@ -1 +1 @@ -Subproject commit b4c4887fbcc669621e9138e924342981282ca1f7 +Subproject commit 1df0ae61f40ba13344c26cfde2263f733d84fd18 diff --git a/src/lib/string.c b/src/lib/string.c index 581d7bc5..fc9a69da 100644 --- a/src/lib/string.c +++ b/src/lib/string.c @@ -55,6 +55,13 @@ opck_str(eq, !strcmp(bin->lhs->d.prim.d.string.data, bin->rhs->d.prim.d.string.d static DTOR(string_dtor) { free_mstr(shred->info->mp, STRING(o)); } +ID_CHECK(check_filepp) { + ((Exp_Primary *)prim)->prim_type = ae_prim_str; + ((Exp_Primary *)prim)->d.string.data = env->name; + ((Exp_Primary *)prim)->value = global_string(env, prim->d.string.data, prim_pos(prim)); + return prim->value->type; +} + ID_CHECK(check_funcpp) { ((Exp_Primary *)prim)->prim_type = ae_prim_str; ((Exp_Primary *)prim)->d.string.data = env->func ? env->func->name @@ -65,6 +72,12 @@ ID_CHECK(check_funcpp) { return prim->value->type; } +ID_CHECK(check_linepp) { + ((Exp_Primary *)prim)->prim_type = ae_prim_num; + ((Exp_Primary *)prim)->d.num = prim_pos(prim).first.line; + return env->gwion->type[et_int]; +} + static GACK(gack_string) { const M_Object obj = *(M_Object *)VALUE; INTERP_PRINTF("%s", obj ? STRING(obj) : "(null string)"); @@ -559,8 +572,14 @@ GWION_IMPORT(string) { GWI_BB(gwi_oper_ini(gwi, "int", "string", "string")) GWI_BB(gwi_oper_end(gwi, "@slice", StringSlice)) - struct SpecialId_ spid = { - .ck = check_funcpp, .exec = RegPushMe, .is_const = 1}; - gwi_specialid(gwi, "__func__", &spid); + struct SpecialId_ file_spid = { + .ck = check_filepp, .is_const = 1}; + gwi_specialid(gwi, "__file__", &file_spid); + struct SpecialId_ func_spid = { + .ck = check_funcpp, .is_const = 1}; + gwi_specialid(gwi, "__func__", &func_spid); + struct SpecialId_ line_spid = { + .ck = check_linepp, .is_const = 1}; + gwi_specialid(gwi, "__line__", &line_spid); return GW_OK; } -- 2.43.0