1/** 2 * Copyright (c) 2021-2025 Huawei Device Co., Ltd. 3 * Licensed under the Apache License, Version 2.0 (the "License"); 4 * you may not use this file except in compliance with the License. 5 * You may obtain a copy of the License at 6 * 7 * http://www.apache.org/licenses/LICENSE-2.0 8 * 9 * Unless required by applicable law or agreed to in writing, software 10 * distributed under the License is distributed on an "AS IS" BASIS, 11 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 * See the License for the specific language governing permissions and 13 * limitations under the License. 14 */ 15 16// Autogenerated file. DO NOT EDIT 17package std.core; 18 19{% set maxarity=16 %} 20 21{%- macro typeParamsDeclList(narg, rest) -%} 22<{% for i in range(narg) -%} 23in P{{i + 1}}, {{""}} 24{%- endfor -%} 25{%- if rest %}in PR, {% endif %}{{rvar}}out R> 26{%- endmacro %} 27 28{%- macro typeParamsList(narg, rest) -%} 29<{% for i in range(narg) -%} 30P{{i + 1}}, {{""}} 31{%- endfor -%} 32{%- if rest %}{{rest}}, {% endif %}R> 33{%- endmacro %} 34 35{% macro erasedTypeArgsList(narg) -%} 36<{% for i in range(narg) %}Any, {% endfor %}Any> 37{%- endmacro %} 38 39{%- macro signature(narg, rest) -%} 40({% for i in range(narg) -%} 41p{{i + 1}}: P{{i + 1}}{% if not loop.last or rest %}, {% endif %} 42{%- endfor -%} 43{%- if rest %}...r: FixedArray<PR>{% endif %}): R 44{%- endmacro %} 45 46{%- macro erasedSignature(narg, rest) -%} 47({% for i in range(narg) -%} 48p{{i + 1}}: Any{% if not loop.last or rest %}, {% endif %} 49{%- endfor -%} 50{%- if rest %}...r: FixedArray<Any>{% endif %}): Any 51{%- endmacro %} 52 53{%- macro listArgs(from, to) -%} 54{% for i in range(from, to) -%} 55p{{i + 1}}{% if not loop.last %}, {% endif %} 56{%- endfor %} 57{%- endmacro %} 58 59{%- macro listArgArrayLoads(to) -%} 60{% for i in range(to) -%} 61r[{{i}}]{% if not loop.last %}, {% endif %} 62{%- endfor %} 63{%- endmacro %} 64 65{%- macro invokeName(narg, suffix) %}invoke{{suffix}}{{narg}}{% endmacro %} 66 67native function getFunctionObjectNameFromAnnotation(func: Object): string; 68 69export @interface NamedFunctionObject { 70 name: string; 71} 72 73export interface Function { 74 unsafeCall(...r: FixedArray<Any>): Any 75 get name(): string; 76} 77 78export interface FunctionN<R> extends Function { 79 invokeN(...r: FixedArray<Any>): R; 80} 81 82export interface __FunctionN extends FunctionN<Any> {} 83 84export abstract class LambdaN implements __FunctionN {} 85 86{%- macro defineChainingHelper(name, narg, erasedArgs) -%} 87export interface __{{name}}{{narg}} extends {{name}}{{narg}}{{erasedTypeArgsList(erasedArgs)}} 88{%- endmacro %} 89 90{%- macro defineLambdaHelper(lambda, name, narg) -%} 91export abstract class {{lambda}}{{narg}} implements __{{name}}{{narg}} 92{%- endmacro %} 93 94{% for narg in range(maxarity + 1) %} 95export interface FunctionR{{ narg }}{{ typeParamsDeclList(narg, True) }} 96 extends Function{% if not loop.last %}, __FunctionR{{narg + 1}}{% endif %} 97{ 98 {{invokeName(narg, "R")}}{{ signature(narg, True) }}; 99} 100export interface Function{{ narg }}{{ typeParamsDeclList(narg) }} 101 extends FunctionR{{narg}}{{ typeParamsList(narg, "Any") }}{% if not loop.last %}, __Function{{narg + 1}}{% endif %} 102{ 103 {{invokeName(narg)}}{{ signature(narg) }}; 104} 105{{ defineChainingHelper("FunctionR", narg, narg + 1) }} {} 106{{ defineChainingHelper("Function", narg, narg) }} {} 107{{ defineLambdaHelper("LambdaR", "FunctionR", narg) }} { 108 109 get name(): string { 110 return getFunctionObjectNameFromAnnotation(this as Object) 111 } 112 113 abstract {{invokeName(narg, "R")}}{{erasedSignature(narg, True)}}; 114{%- if narg == 0 %} 115 final unsafeCall(...r: FixedArray<Any>): Any { 116 return this.{{invokeName(narg, "R")}}(...r) 117 } 118{%- else %} 119 final unsafeCall(...r: FixedArray<Any>): Any { 120 if (r.length < {{narg}}) { throw new ArgumentsUnderapplicationError() } 121 return this.{{invokeName(narg, "R")}}({{listArgArrayLoads(narg)}}{{", " if narg != 0 }} 122 ...Runtime.removeFrontElementsStub(r, {{narg}})) 123 } 124{%- endif %} 125{%- for extNarg in range(narg + 1, maxarity + 1) %} 126 final {{invokeName(extNarg, "R")}}{{erasedSignature(extNarg, True) }} { 127 return this.{{invokeName(narg, "R")}}({{listArgs(0, narg)}}{{", " if narg != 0 }} 128 ...Runtime.addFrontElementsStub(r, [{{listArgs(narg, extNarg)}}])) 129 } 130{%- endfor %} 131} 132{{ defineLambdaHelper("Lambda", "Function", narg) }} { 133 abstract {{invokeName(narg)}}{{erasedSignature(narg)}}; 134 final unsafeCall(...r: FixedArray<Any>): Any { 135 if (r.length < {{narg}}) { throw new ArgumentsUnderapplicationError() } 136 return this.{{invokeName(narg)}}({{listArgArrayLoads(narg)}}) 137 } 138 139 get name(): string { 140 return getFunctionObjectNameFromAnnotation(this as Object) 141 } 142 143{%- for extNarg in range(narg + 1, maxarity + 1) %} 144 final {{invokeName(extNarg)}} {{erasedSignature(extNarg, False)}} { 145 return this.{{invokeName(narg)}}({{listArgs(0, narg)}}) 146 } 147{%- endfor %} 148{%- for extNarg in range(narg, maxarity + 1) %} 149 final {{invokeName(extNarg, "R")}}{{erasedSignature(extNarg, True) }} { 150 return this.{{invokeName(narg)}}({{listArgs(0, narg)}}) 151 } 152{%- endfor %} 153} 154{% endfor %} 155