github.com/goplusjs/reflectx@v0.5.4/icall_gen_117.go (about)

     1  //go:build ignore
     2  // +build ignore
     3  
     4  package main
     5  
     6  import (
     7  	"bytes"
     8  	"fmt"
     9  	"io/ioutil"
    10  	"strconv"
    11  	"strings"
    12  )
    13  
    14  var head = `// +build !js js,wasm
    15  // +build go1.17,goexperiment.regabireflect
    16  
    17  package reflectx
    18  
    19  import (
    20  	"log"
    21  )
    22  
    23  var (
    24  	check_max_itype = true
    25  	check_max_index = true
    26  )
    27  
    28  func icall(t int, i int, max int, ptrto bool, output bool) interface{} {
    29  	if t >= max_itype_index {
    30  		if check_max_itype {
    31  			check_max_itype = false
    32  			log.Println("warning, too many types interface call >", t)
    33  		}
    34  		return func(p, a unsafeptr) {}
    35  	}
    36  	if i >= max_icall_index {
    37  		if check_max_index {
    38  			check_max_index = false
    39  			log.Println("warning, too many methods interface call >", i)
    40  		}
    41  		return func(p, a unsafeptr) {}
    42  	}
    43  	if ptrto {
    44  		if output {
    45  			return icall_ptr_output[t*max_icall_index+i]
    46  		}
    47  		return icall_ptr[t*max_icall_index+i]
    48  	} else {
    49  		if output {
    50  			return icall_typ_output[t*max_icall_index+i]
    51  		}
    52  		return icall_typ[t*max_icall_index+i]
    53  	}
    54  }
    55  
    56  const max_itype_index = $max_itype
    57  const max_icall_index = $max_index
    58  `
    59  
    60  var templ_fn = `	func(p unsafeptr, a iparam) { i_y($itype, $index, p, a, $ptr) },
    61  `
    62  var templ_fn_output = `	func(p unsafeptr, a iparam) iparam { return i_y($itype, $index, p, a, $ptr) },
    63  `
    64  
    65  func main() {
    66  	writeFile("./icall_go117.go", 64, 256)
    67  }
    68  
    69  func writeFile(filename string, max_itype int, max_index int) {
    70  	var buf bytes.Buffer
    71  	r := strings.NewReplacer("$max_itype", strconv.Itoa(max_itype),
    72  		"$max_index", strconv.Itoa(max_index))
    73  	buf.WriteString(r.Replace(head))
    74  
    75  	fnWrite := func(name string, t string, ptr string) {
    76  		buf.WriteString(fmt.Sprintf("\nvar %v = []interface{}{\n", name))
    77  		for i := 0; i < max_itype; i++ {
    78  			for j := 0; j < max_index; j++ {
    79  				r := strings.NewReplacer("$itype", strconv.Itoa(i),
    80  					"$index", strconv.Itoa(j),
    81  					"$ptr", ptr)
    82  				buf.WriteString(r.Replace(t))
    83  			}
    84  		}
    85  		buf.WriteString("}\n")
    86  	}
    87  	fnWrite("icall_typ", templ_fn, "false")
    88  	fnWrite("icall_typ_output", templ_fn_output, "false")
    89  	fnWrite("icall_ptr", templ_fn, "true")
    90  	fnWrite("icall_ptr_output", templ_fn_output, "true")
    91  
    92  	ioutil.WriteFile(filename, buf.Bytes(), 0666)
    93  }