Codegen fixes

This commit is contained in:
Madpwnhammer 2022-12-02 18:25:48 +03:00
parent cbd01c39da
commit e6b2bf868a
2 changed files with 18 additions and 8 deletions

View File

@ -178,10 +178,12 @@ function bhl_type_ref($type_str)
{
if(preg_match('~((\w|\.)+)\[\]~', $type_str, $ms))
return "types.TArr(\"{$ms[1]}\")";
else if(preg_match('~func\s+((\w|\.)+)\s+\(\)~', $type_str, $ms))
return "types.TFunc(\"{$ms[1]}\")";
else if(preg_match('~func\s+((\w|\.)+)\s+\(((\w|\.)+)\)~', $type_str, $ms))
return "types.TFunc(\"{$ms[1]}\", \"{$ms[3]}\")";
else if(preg_match('~async\s+func\s+((\w|\.)+)\s*\(\)~', $type_str, $ms))
return "types.TFunc(true, \"{$ms[1]}\")";
else if(preg_match('~func\s+((\w|\.)+)\s*\(\)~', $type_str, $ms))
return "types.TFunc(false, \"{$ms[1]}\")";
else if(preg_match('~func\s+((\w|\.)+)\s*\(((\w|\.)+)\)~', $type_str, $ms))
return "types.TFunc(false, \"{$ms[1]}\", \"{$ms[3]}\")";
else if(preg_match('~((\w|\.)+)\,((\w|\.)+)~', $type_str, $ms))
return "types.T(\"{$ms[1]}\", \"{$ms[3]}\")";
else
@ -204,7 +206,8 @@ function bhl_gen_type(\mtgType $type = null)
{
$ret_type = $type->getReturnType() ? bhl_gen_type($type->getReturnType()) : 'void';
$str = "func $ret_type(";
$str = "";
$str .= "func $ret_type(";
foreach($type->getArgs() as $arg)
$str .= bhl_gen_type($arg->getType()) . ",";
$str = rtrim($str, ',');

View File

@ -74,7 +74,7 @@
{% if o.args %},{% endif %}
{{ _self.func_decl_args(o) }}
);
{{scope}}.{{o.name|ns_prefix}}Define(fn)
{{scope}}.{{o.name|ns_prefix}}Define(fn);
}
{%- endmacro -%}
@ -314,7 +314,14 @@
{%- macro func_decl_args(fn) -%}
{%- for arg in fn.args -%}
new FuncArgSymbol("{{arg.name}}", {{arg.type|bhl_type_ref}},
new FuncArgSymbol("{{arg.name}}",
{%-if has_token(arg, 'bhl_async') -%}
{{('async ' ~ (arg.type|bhl_type))|bhl_type_ref}},
{%-else-%}
{{arg.type|bhl_type_ref}},
{%-endif-%}
{%-if has_token(arg, 'bhl_ref_arg') -%}
true
{%-else-%}
@ -588,7 +595,7 @@
//setter not allowed
null
{%- endif ~%}
);
));
}
{%- endmacro -%}