From: fennecdjay Date: Thu, 11 Jul 2019 13:59:38 +0000 (+0200) Subject: :art: Improve Shred X-Git-Tag: nightly~2348^2~5 X-Git-Url: http://10.10.0.4:5575/?a=commitdiff_plain;h=ecda3c80d69761882efafbae4cddc2510a18ff69;p=gwion.git :art: Improve Shred --- diff --git a/examples/implicit_fptr.gw b/examples/implicit_fptr.gw new file mode 100644 index 00000000..5184a945 --- /dev/null +++ b/examples/implicit_fptr.gw @@ -0,0 +1,8 @@ +typedef void t_ptr(); +fun void test(t_ptr p) { + <<< p >>>; +} +fun void test() { +} + +test => test; diff --git a/examples/implicit_fptr_class.gw b/examples/implicit_fptr_class.gw new file mode 100644 index 00000000..8c1f0fcc --- /dev/null +++ b/examples/implicit_fptr_class.gw @@ -0,0 +1,11 @@ +class C { +typedef void t_ptr(); +fun void test(t_ptr p) { + <<< p >>>; +} +fun void test() { +} + +test => test; +} +C c; diff --git a/examples/implicit_fptr_tmpl.gw b/examples/implicit_fptr_tmpl.gw new file mode 100644 index 00000000..621474fa --- /dev/null +++ b/examples/implicit_fptr_tmpl.gw @@ -0,0 +1,8 @@ +typedef void t_ptr<~A~>(); +fun void test(t_ptr p) { + <<< p >>>; +} +fun void t<~A~>() { +} + +t => test; diff --git a/examples/shred.gw b/examples/shred.gw index 29c873c1..cb479da3 100644 --- a/examples/shred.gw +++ b/examples/shred.gw @@ -12,3 +12,10 @@ for (int i; i < me.args(); i++) #!me.exit(); #! call to non existant arg <<< me.arg(-1) >>>; +<<< me.dir() >>>; +<<< me.path() >>>; +<<< me.name() >>>; + +<<< me.code_dir() >>>; +<<< me.code_path() >>>; +<<< me.code_name() >>>; diff --git a/src/lib/shred.c b/src/lib/shred.c index 3e23a30c..41a6a722 100644 --- a/src/lib/shred.c +++ b/src/lib/shred.c @@ -102,6 +102,15 @@ static MFUN(shred_arg) { #define PATH_CHR '\\' #endif +#define describe_name(name, src) \ +static MFUN(shred##name##_name) { \ + const VM_Shred s = ME(o); \ + const m_str str = code_name((src), 0); \ + *(m_uint*)RETURN = (m_uint)new_string(shred->info->mp, shred, str); \ +} +describe_name(, s->info->name) +describe_name(_code, s->code->name) + #define describe_path_and_dir(name, src) \ static MFUN(shred##name##_path) { \ const VM_Shred s = ME(o); \ @@ -254,12 +263,18 @@ GWION_IMPORT(shred) { gwi_func_arg(gwi, "int", "n"); CHECK_BB(gwi_func_end(gwi, 0)) + gwi_func_ini(gwi, "string", "name", shred_name); + CHECK_BB(gwi_func_end(gwi, 0)) + gwi_func_ini(gwi, "string", "path", shred_path); CHECK_BB(gwi_func_end(gwi, 0)) gwi_func_ini(gwi, "string", "dir", shred_dir); CHECK_BB(gwi_func_end(gwi, 0)) + gwi_func_ini(gwi, "string", "code_name", shred_code_name); + CHECK_BB(gwi_func_end(gwi, 0)) + gwi_func_ini(gwi, "string", "code_path", shred_code_path); CHECK_BB(gwi_func_end(gwi, 0))