Using local static functions instead of lambdas
Publish PHP Package / docker (push) Successful in 6s Details

This commit is contained in:
Pavel Shevaev 2024-11-21 11:47:58 +03:00
parent a257a2af6d
commit 7a94a35f7f
1 changed files with 115 additions and 79 deletions

View File

@ -1,5 +1,7 @@
{%- macro reg_func_native(o, scope = 'types.ns', this_prefix = '', this_type = null, fname = null) ~%}
{
{{ _self.func_native_local_fn(o, o.name|ns_last, this_prefix, this_type) }}
var fn =
{{ _self.func_native(o, fname ? fname|trim('"') : o.name|ns_last, this_prefix, this_type) }}
;
@ -8,6 +10,34 @@
}
{%- endmacro -%}
{%- macro func_native_local_fn(o, fname, this_prefix = '', this_type = null) ~%}
#if !BHL_FRONT
static bhl.Coroutine fn_{{fname|trim('"')}}(VM.Frame frm, ValStack stack, FuncArgsInfo args_info, ref BHS status) {
{{ _self.read_args2natives(o, '__', this_type) }}
{%~ if o.returntype %}
var return_val =
{%- endif ~%}
{{this_prefix}}{{ _self.call_native_prefix_func(o, '__') }}
{# pass back and release ref args #}
{%- for arg in o.args -%}
{%- if has_token(arg, 'bhl_ref_arg') ~%}
{{ _self.native2val(arg.type, '__ref_' ~ arg.name, '__' ~ arg.name, true) }};
__{{arg.name}}.Release();
{%- endif -%}
{%- endfor -%}
{{ _self.return_val(o, 'return_val') }}
{{ _self.dispose_args(o, '__') }}
return null;
}
#endif
{%- endmacro -%}
{%- macro func_native(o, fname, this_prefix = '', this_type = null) ~%}
new FuncSymbolNative(new Origin(), "{{fname|trim('"')}}",
@ -27,29 +57,7 @@
{{ count_default_args(o) }},
#if !BHL_FRONT
delegate(VM.Frame frm, ValStack stack, FuncArgsInfo args_info, ref BHS status) {
{{ _self.read_args2natives(o, '__', this_type) }}
{%~ if o.returntype %}
var return_val =
{%- endif ~%}
{{this_prefix}}{{ _self.call_native_prefix_func(o, '__') }}
{# pass back and release ref args #}
{%- for arg in o.args -%}
{%- if has_token(arg, 'bhl_ref_arg') ~%}
{{ _self.native2val(arg.type, '__ref_' ~ arg.name, '__' ~ arg.name, true) }};
__{{arg.name}}.Release();
{%- endif -%}
{%- endfor -%}
{{ _self.return_val(o, 'return_val') }}
{{ _self.dispose_args(o, '__') }}
return null;
}
fn_{{o.name|ns_last}}
#else
null
#endif
@ -61,14 +69,8 @@
{%- macro reg_func_partial(o, scope = 'types.ns') ~%}
{
var fn = new FuncSymbolNative(new Origin(), "{{o.name|ns_last}}",
{%- if has_token(o, 'bhl_coroutine') -%}
FuncAttrib.Coro,
{%- endif ~%}
{{o.returntype|bhl_type_ref}},
{{ count_default_args(o) }},
delegate(VM.Frame frm, ValStack stack, FuncArgsInfo args_info, ref BHS status) {
#if !BHL_FRONT
#if !BHL_FRONT
static bhl.Coroutine fn_{{o.name|ns_last}}(VM.Frame frm, ValStack stack, FuncArgsInfo args_info, ref BHS status) {
{% if has_token(o, 'bhl_coroutine') -%}
var coro = CoroutinePool.New<Script_{{o.name|norm_name}}>(frm.vm);
coro.Init(frm, stack, args_info);
@ -84,10 +86,20 @@
{{_self.return_out_results(o)}}
return null;
{%- endif ~%}
#else
return null;
#endif
}
}
#endif
var fn = new FuncSymbolNative(new Origin(), "{{o.name|ns_last}}",
{%- if has_token(o, 'bhl_coroutine') -%}
FuncAttrib.Coro,
{%- endif ~%}
{{o.returntype|bhl_type_ref}},
{{ count_default_args(o) }},
#if !BHL_FRONT
fn_{{o.name|ns_last}}
#else
null
#endif
{% if o.args %},{% endif %}
{{ _self.func_decl_args(o) }}
);
@ -154,18 +166,8 @@ Script_{{o.name|norm_name}}.Method_{{m.name}}.ReturnValue(frm, stack
{%- macro method_partial(o, m, class_container) ~%}
{
var fn = new FuncSymbolNative(new Origin(), "{{m.name|norm_name}}",
FuncAttrib.None
{% if has_token(m, 'bhl_static') ~%}
| FuncAttrib.Static
{% endif ~%}
{%- if has_token(m, 'bhl_coroutine') -%}
| FuncAttrib.Coro
{%- endif ~%},
{{ m.returntype|bhl_type_ref }},
{{ count_default_args(m) }},
#if !BHL_FRONT
delegate(VM.Frame frm, ValStack stack, FuncArgsInfo args_info, ref BHS status) {
static bhl.Coroutine m_{{m.name|norm_name}}(VM.Frame frm, ValStack stack, FuncArgsInfo args_info, ref BHS status) {
{% if has_token(m, 'bhl_coroutine') -%}
var coro = CoroutinePool.New<Script_{{o.name|norm_name}}.Method_{{m.name|norm_name}}>(frm.vm);
coro.Init(frm, stack, args_info);
@ -178,6 +180,20 @@ Script_{{o.name|norm_name}}.Method_{{m.name}}.ReturnValue(frm, stack
return null;
{%- endif ~%}
}
#endif
var fn = new FuncSymbolNative(new Origin(), "{{m.name|norm_name}}",
FuncAttrib.None
{% if has_token(m, 'bhl_static') ~%}
| FuncAttrib.Static
{% endif ~%}
{%- if has_token(m, 'bhl_coroutine') -%}
| FuncAttrib.Coro
{%- endif ~%},
{{ m.returntype|bhl_type_ref }},
{{ count_default_args(m) }},
#if !BHL_FRONT
m_{{m.name|norm_name}}
#else
null
#endif
@ -190,20 +206,24 @@ Script_{{o.name|norm_name}}.Method_{{m.name}}.ReturnValue(frm, stack
{% if has_token(m, 'bhl_bin_op') ~%}
{
#if !BHL_FRONT
static bhl.Coroutine m_{{m.name|ns_last}}(VM.Frame frm, ValStack stack, FuncArgsInfo args_info, ref BHS status) {
var args = Script_{{o.name|norm_name}}.Method_{{m.name}}.ReadArgs(frm, stack, args_info);
Script_{{o.name|norm_name}}.Method_{{m.name}}.Exec(frm, args {{_self.out_results(m)}});
args.Dispose();
{{_self.return_method_out_results(o, m)}}
return null;
}
#endif
var fn = new FuncSymbolNative(new Origin(), {{token(m, 'bhl_bin_op')}},
FuncAttrib.Static,
{{ m.returntype|bhl_type_ref }},
{{ count_default_args(m) }},
#if !BHL_FRONT
delegate(VM.Frame frm, ValStack stack, FuncArgsInfo args_info, ref BHS status) {
var args = Script_{{o.name|norm_name}}.Method_{{m.name}}.ReadArgs(frm, stack, args_info);
Script_{{o.name|norm_name}}.Method_{{m.name}}.Exec(frm, args {{_self.out_results(m)}});
args.Dispose();
{{_self.return_method_out_results(o, m)}}
return null;
}
m_{{m.name|ns_last}}
#else
null
#endif
@ -654,6 +674,23 @@ Script_{{o.name|norm_name}}.Method_{{m.name}}.ReturnValue(frm, stack
{% else %}
{
{% if not has_token(o, 'bhl_no_new') ~%}
static void ctor_{{o.name|ns_last}}(VM.Frame frm, ref Val v, IType type) {
#if !BHL_FRONT
var o = new {{token_or(o, 'bhl_native_class', o.name)}}({{token_or(o, 'bhl_native_class_params', '')}});
{%if has_token(o, 'bhl_custom_rw') %}
v.Encode(o);
{% else %}
{% if has_token(o, 'POD') %}
o.Reset();
{% endif %}
v.SetObj(o, type);
{% endif %}
#endif
}
{% endif %}
var cl = new ClassSymbolNative(new Origin(), "{{o.name|ns_last}}",
{% if o.parent %}
types.T("{{o.parent}}"),
@ -673,20 +710,7 @@ Script_{{o.name|norm_name}}.Method_{{m.name}}.ReturnValue(frm, stack
//constructor is not allowed
creator: null
{% else ~%}
creator: delegate(VM.Frame frm, ref Val v, IType type) {
#if !BHL_FRONT
var o = new {{token_or(o, 'bhl_native_class', o.name)}}({{token_or(o, 'bhl_native_class_params', '')}});
{%if has_token(o, 'bhl_custom_rw') %}
v.Encode(o);
{% else %}
{% if has_token(o, 'POD') %}
o.Reset();
{% endif %}
v.SetObj(o, type);
{% endif %}
#endif
}
creator: ctor_{{o.name|ns_last}}
{% endif ~%}
#if !BHL_FRONT
, native_type: typeof({{token_or(o, 'bhl_native_class', o.name)}})
@ -733,10 +757,8 @@ Script_{{o.name|norm_name}}.Method_{{m.name}}.ReturnValue(frm, stack
{% set class = token_or(o, 'bhl_native_class', o.name) %}
{
cl.Define(new FieldSymbol(new Origin(), "{{f.name}}", {{f.type|bhl_type_ref}},
{% if token_or(f, 'bhl_get', 1) != 0 ~%}
//getter
delegate(VM.Frame frm, Val ctx, ref Val v, FieldSymbol fld) {
static void get_{{f.name}}(VM.Frame frm, Val ctx, ref Val v, FieldSymbol fld) {
#if !BHL_FRONT
{%~ if has_token(o, 'bhl_custom_rw') ~%}
{{class}} f = new {{class}}();
@ -757,14 +779,10 @@ Script_{{o.name|norm_name}}.Method_{{m.name}}.ReturnValue(frm, stack
{%- endif ~%}
#endif
}
{%- else ~%}
//getter not allowed
null
{%- endif ~%}
,
{% if token_or(f, 'bhl_set', 1) != 0 ~%}
//setter
delegate(VM.Frame frm, ref Val ctx, Val v, FieldSymbol fld) {
static void set_{{f.name}}(VM.Frame frm, ref Val ctx, Val v, FieldSymbol fld) {
#if !BHL_FRONT
{%~ if has_token(o, 'bhl_custom_rw') ~%}
{{class}} f = new {{class}}();
@ -789,9 +807,22 @@ Script_{{o.name|norm_name}}.Method_{{m.name}}.ReturnValue(frm, stack
{%- else ~%}
ctx.SetObj(f, ctx.type);
{%- endif ~%}
#endif
}
{%- endif ~%}
cl.Define(new FieldSymbol(new Origin(), "{{f.name}}", {{f.type|bhl_type_ref}},
{% if token_or(f, 'bhl_get', 1) != 0 ~%}
//getter
get_{{f.name}}
{%- else ~%}
//getter not allowed
null
{%- endif ~%}
,
{% if token_or(f, 'bhl_set', 1) != 0 ~%}
//setter
set_{{f.name}}
{%- else ~%}
//setter not allowed
null
@ -804,6 +835,11 @@ Script_{{o.name|norm_name}}.Method_{{m.name}}.ReturnValue(frm, stack
{%- macro reg_interface(o, scope = 'types.ns') ~%}
{
{% for m in o.getfuncs %}
{{ _self.func_native_local_fn(m, m.name, '__self.', o) }}
{% endfor %}
var ifs = new InterfaceSymbolNative(new Origin(), "{{o.name|ns_last}}", proxy_inherits: null
#if !BHL_FRONT