1// +build gomacro_fast_compact 2 3/* 4 * gomacro - A Go interpreter with Lisp-like macros 5 * 6 * Copyright (C) 2017-2019 Massimiliano Ghilardi 7 * 8 * This Source Code Form is subject to the terms of the Mozilla Public 9 * License, v. 2.0. If a copy of the MPL was not distributed with this 10 * file, You can obtain one at http://mozilla.org/MPL/2.0/. 11 * 12 * 13 * call0ret1_compact.go 14 * 15 * Created on Jun 14, 2017 16 * Author Massimiliano Ghilardi 17 */ 18 19package fast 20 21import ( 22 r "reflect" 23 24 "github.com/cosmos72/gomacro/base" 25) 26 27func (c *Comp) call0ret1(call *Call, maxdepth int) I { 28 expr := call.Fun 29 exprfun := expr.AsX1() 30 31 tret := expr.Type.Out(0) 32 kret := tret.Kind() 33 var ret I 34 35 switch kret { 36 case r.Bool: 37 ret = func(env *Env) bool { 38 return exprfun(env).Call(base.ZeroValues)[0].Bool() 39 } 40 case r.Int: 41 ret = func(env *Env) int { 42 return int(exprfun(env).Call(base.ZeroValues)[0].Int()) 43 } 44 case r.Int8: 45 ret = func(env *Env) int8 { 46 return int8(exprfun(env).Call(base.ZeroValues)[0].Int()) 47 } 48 case r.Int16: 49 ret = func(env *Env) int16 { 50 return int16(exprfun(env).Call(base.ZeroValues)[0].Int()) 51 } 52 case r.Int32: 53 ret = func(env *Env) int32 { 54 return int32(exprfun(env).Call(base.ZeroValues)[0].Int()) 55 } 56 case r.Int64: 57 ret = func(env *Env) int64 { 58 return exprfun(env).Call(base.ZeroValues)[0].Int() 59 } 60 case r.Uint: 61 ret = func(env *Env) uint { 62 return uint(exprfun(env).Call(base.ZeroValues)[0].Uint()) 63 } 64 case r.Uint8: 65 ret = func(env *Env) uint8 { 66 return uint8(exprfun(env).Call(base.ZeroValues)[0].Uint()) 67 } 68 case r.Uint16: 69 ret = func(env *Env) uint16 { 70 return uint16(exprfun(env).Call(base.ZeroValues)[0].Uint()) 71 } 72 case r.Uint32: 73 ret = func(env *Env) uint32 { 74 return uint32(exprfun(env).Call(base.ZeroValues)[0].Uint()) 75 } 76 case r.Uint64: 77 ret = func(env *Env) uint64 { 78 return exprfun(env).Call(base.ZeroValues)[0].Uint() 79 } 80 case r.Uintptr: 81 ret = func(env *Env) uintptr { 82 return uintptr(exprfun(env).Call(base.ZeroValues)[0].Uint()) 83 } 84 case r.Float32: 85 ret = func(env *Env) float32 { 86 return float32(exprfun(env).Call(base.ZeroValues)[0].Float()) 87 } 88 case r.Float64: 89 ret = func(env *Env) float64 { 90 return exprfun(env).Call(base.ZeroValues)[0].Float() 91 } 92 case r.Complex64: 93 ret = func(env *Env) complex64 { 94 return complex64(exprfun(env).Call(base.ZeroValues)[0].Complex()) 95 } 96 case r.Complex128: 97 ret = func(env *Env) complex128 { 98 return exprfun(env).Call(base.ZeroValues)[0].Complex() 99 } 100 case r.String: 101 ret = func(env *Env) string { 102 return exprfun(env).Call(base.ZeroValues)[0].String() 103 } 104 default: 105 ret = func(env *Env) r.Value { 106 return exprfun(env).Call(base.ZeroValues)[0] 107 } 108 } 109 return ret 110} 111