Skip to content

Commit

Permalink
Add more typed call signatures
Browse files Browse the repository at this point in the history
  • Loading branch information
antonmedv committed Jan 21, 2023
1 parent b062494 commit c2b6f32
Show file tree
Hide file tree
Showing 2 changed files with 79 additions and 1 deletion.
20 changes: 19 additions & 1 deletion vm/func_types/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,20 @@ var types = []interface{}{
new(func(string, rune) int),
new(func(string, string) bool),
new(func(string, string) string),
new(func(interface{}) bool),
new(func(interface{}) float64),
new(func(interface{}) int),
new(func(interface{}) string),
new(func(interface{}) interface{}),
new(func(interface{}) []interface{}),
new(func(interface{}) map[string]interface{}),
new(func([]interface{}) interface{}),
new(func([]interface{}) []interface{}),
new(func([]interface{}) map[string]interface{}),
new(func(interface{}, interface{}) bool),
new(func(interface{}, interface{}) string),
new(func(interface{}, interface{}) interface{}),
new(func(interface{}, interface{}) []interface{}),
}

func main() {
Expand All @@ -78,7 +92,11 @@ func main() {
data.Code += fmt.Sprintf("case %d:\n", i)
args := make([]string, fn.NumIn())
for j := fn.NumIn() - 1; j >= 0; j-- {
data.Code += fmt.Sprintf("arg%v := vm.pop().(%v)\n", j+1, fn.In(j))
cast := fmt.Sprintf(".(%v)", fn.In(j))
if fn.In(j).Kind() == reflect.Interface {
cast = ""
}
data.Code += fmt.Sprintf("arg%v := vm.pop()%v\n", j+1, cast)
args[j] = fmt.Sprintf("arg%v", j+1)
}
data.Code += fmt.Sprintf("return fn.(%v)(%v)\n", fn, strings.Join(args, ", "))
Expand Down
60 changes: 60 additions & 0 deletions vm/generated.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit c2b6f32

Please sign in to comment.