github.com/moontrade/wavm-go@v0.3.2-0.20220316110326-d229dd66ad65/func_type.go (about)

     1  package wavm
     2  
     3  // #include <stdlib.h>
     4  // #include "wavm-c.h"
     5  import "C"
     6  import "unsafe"
     7  
     8  type FuncType C.wasm_functype_t
     9  
    10  func NewFuncType(params []*ValType, results []*ValType) *FuncType {
    11  	var _params **C.wasm_valtype_t
    12  	var _results **C.wasm_valtype_t
    13  
    14  	if len(params) > 0 {
    15  		_params = (**C.wasm_valtype_t)(unsafe.Pointer(&params[0]))
    16  	} else {
    17  		_params = nil
    18  	}
    19  	if len(results) > 0 {
    20  		_results = (**C.wasm_valtype_t)(unsafe.Pointer(&results[0]))
    21  	} else {
    22  		_results = nil
    23  	}
    24  
    25  	return (*FuncType)(C.wasm_functype_new(
    26  		_params,
    27  		(C.size_t)(len(params)),
    28  		_results,
    29  		(C.size_t)(len(results)),
    30  	))
    31  }
    32  
    33  func (f *FuncType) Close() error {
    34  	f.Delete()
    35  	return nil
    36  }
    37  
    38  func (f *FuncType) Delete() {
    39  	C.wasm_functype_delete((*C.wasm_functype_t)(f))
    40  }
    41  
    42  func (f *FuncType) NumParams() int {
    43  	return int(C.wasm_functype_num_params((*C.wasm_functype_t)(f)))
    44  }
    45  
    46  func (f *FuncType) Param(index int) *ValType {
    47  	return (*ValType)(C.wasm_functype_param((*C.wasm_functype_t)(f), (C.size_t)(index)))
    48  }
    49  
    50  func (f *FuncType) NumResults() int {
    51  	return int(C.wasm_functype_num_results((*C.wasm_functype_t)(f)))
    52  }
    53  
    54  func (f *FuncType) Result(index int) *ValType {
    55  	return (*ValType)(C.wasm_functype_result((*C.wasm_functype_t)(f), (C.size_t)(index)))
    56  }
    57  
    58  func FuncType_0_0() *FuncType {
    59  	return NewFuncType(nil, nil)
    60  }
    61  
    62  func FuncType_2_0(
    63  	p1 *ValType,
    64  	p2 *ValType,
    65  ) *FuncType {
    66  	p := [2]*ValType{p1, p2}
    67  	return NewFuncType(p[0:2], nil)
    68  }
    69  
    70  func FuncType_3_0(
    71  	p1 *ValType,
    72  	p2 *ValType,
    73  	p3 *ValType,
    74  ) *FuncType {
    75  	p := [3]*ValType{p1, p2, p3}
    76  	return NewFuncType(p[0:3], nil)
    77  }
    78  
    79  func FuncType_0_1(r1 *ValType) *FuncType {
    80  	r := [1]*ValType{r1}
    81  	return NewFuncType(nil, r[0:1])
    82  }
    83  
    84  func FuncType_1_0(
    85  	p1 *ValType,
    86  ) *FuncType {
    87  	p := [1]*ValType{p1}
    88  	return NewFuncType(p[0:1], nil)
    89  }
    90  
    91  func FuncType_1_1(
    92  	p1 *ValType,
    93  	r1 *ValType,
    94  ) *FuncType {
    95  	p := [1]*ValType{p1}
    96  	r := [1]*ValType{r1}
    97  	return NewFuncType(p[0:1], r[0:1])
    98  }
    99  
   100  func FuncType_2_1(
   101  	p1 *ValType,
   102  	p2 *ValType,
   103  	r1 *ValType,
   104  ) *FuncType {
   105  	p := [2]*ValType{p1, p2}
   106  	r := [1]*ValType{r1}
   107  	return NewFuncType(p[0:2], r[0:1])
   108  }
   109  
   110  func FuncType_3_1(
   111  	p1 *ValType,
   112  	p2 *ValType,
   113  	p3 *ValType,
   114  	r1 *ValType,
   115  ) *FuncType {
   116  	p := [3]*ValType{p1, p2, p3}
   117  	r := [1]*ValType{r1}
   118  	return NewFuncType(p[0:3], r[0:1])
   119  }
   120  
   121  func FuncType_0_2(
   122  	r1 *ValType,
   123  	r2 *ValType,
   124  ) *FuncType {
   125  	r := [2]*ValType{r1, r2}
   126  	return NewFuncType(nil, r[0:2])
   127  }
   128  
   129  func FuncType_1_2(
   130  	p1 *ValType,
   131  	r1 *ValType,
   132  	r2 *ValType,
   133  ) *FuncType {
   134  	p := [1]*ValType{p1}
   135  	r := [2]*ValType{r1, r2}
   136  	return NewFuncType(p[0:1], r[0:2])
   137  }
   138  
   139  func FuncType_2_2(
   140  	p1 *ValType,
   141  	p2 *ValType,
   142  	r1 *ValType,
   143  	r2 *ValType,
   144  ) *FuncType {
   145  	p := [2]*ValType{p1, p2}
   146  	r := [2]*ValType{r1, r2}
   147  	return NewFuncType(p[0:2], r[0:2])
   148  }
   149  
   150  func FuncType_3_2(
   151  	p1 *ValType,
   152  	p2 *ValType,
   153  	p3 *ValType,
   154  	r1 *ValType,
   155  	r2 *ValType,
   156  ) *FuncType {
   157  	p := [3]*ValType{p1, p2, p3}
   158  	r := [2]*ValType{r1, r2}
   159  	return NewFuncType(p[0:3], r[0:2])
   160  }
   161  
   162  func FuncType_4_1(
   163  	p1 *ValType,
   164  	p2 *ValType,
   165  	p3 *ValType,
   166  	p4 *ValType,
   167  	r1 *ValType,
   168  ) *FuncType {
   169  	p := [4]*ValType{p1, p2, p3, p4}
   170  	r := [1]*ValType{r1}
   171  	return NewFuncType(p[0:4], r[0:1])
   172  }