llgo/ssa: Builtin
This commit is contained in:
@@ -571,10 +571,9 @@ func (p *context) call(b llssa.Builder, act llssa.DoAction, call *ssa.CallCommon
|
|||||||
if fn == "ssa:wrapnilchk" { // TODO(xsw): check nil ptr
|
if fn == "ssa:wrapnilchk" { // TODO(xsw): check nil ptr
|
||||||
arg := args[0]
|
arg := args[0]
|
||||||
ret = p.compileValue(b, arg)
|
ret = p.compileValue(b, arg)
|
||||||
// log.Println("wrapnilchk:", ret.TypeOf())
|
|
||||||
} else {
|
} else {
|
||||||
args := p.compileValues(b, args, kind)
|
args := p.compileValues(b, args, kind)
|
||||||
ret = b.BuiltinDo(act, fn, args...)
|
ret = b.Do(act, llssa.Builtin(fn), args...)
|
||||||
}
|
}
|
||||||
case *ssa.Function:
|
case *ssa.Function:
|
||||||
aFn, pyFn, ftype := p.compileFunction(cv)
|
aFn, pyFn, ftype := p.compileFunction(cv)
|
||||||
|
|||||||
28
ssa/expr.go
28
ssa/expr.go
@@ -43,6 +43,26 @@ func (v Expr) IsNil() bool {
|
|||||||
|
|
||||||
// -----------------------------------------------------------------------------
|
// -----------------------------------------------------------------------------
|
||||||
|
|
||||||
|
type builtinTy struct {
|
||||||
|
name string
|
||||||
|
}
|
||||||
|
|
||||||
|
func (p builtinTy) Underlying() types.Type {
|
||||||
|
panic("don't call")
|
||||||
|
}
|
||||||
|
|
||||||
|
func (p builtinTy) String() string {
|
||||||
|
return "builtinTy"
|
||||||
|
}
|
||||||
|
|
||||||
|
// Builtin returns a builtin function expression.
|
||||||
|
func Builtin(name string) Expr {
|
||||||
|
tbi := &aType{raw: rawType{&builtinTy{name}}, kind: vkBuiltin}
|
||||||
|
return Expr{Type: tbi}
|
||||||
|
}
|
||||||
|
|
||||||
|
// -----------------------------------------------------------------------------
|
||||||
|
|
||||||
type pyVarTy struct {
|
type pyVarTy struct {
|
||||||
mod Expr
|
mod Expr
|
||||||
name string
|
name string
|
||||||
@@ -742,6 +762,9 @@ func (b Builder) Call(fn Expr, args ...Expr) (ret Expr) {
|
|||||||
case vkFuncDecl:
|
case vkFuncDecl:
|
||||||
sig = raw.(*types.Signature)
|
sig = raw.(*types.Signature)
|
||||||
ll = fn.ll
|
ll = fn.ll
|
||||||
|
case vkBuiltin:
|
||||||
|
bi := raw.(*builtinTy)
|
||||||
|
return b.BuiltinCall(bi.name, args...)
|
||||||
default:
|
default:
|
||||||
log.Panicf("unreachable: %d(%T)\n", kind, raw)
|
log.Panicf("unreachable: %d(%T)\n", kind, raw)
|
||||||
}
|
}
|
||||||
@@ -791,11 +814,6 @@ func (b Builder) Do(da DoAction, fn Expr, args ...Expr) (ret Expr) {
|
|||||||
// `fn` indicates the function: one of the built-in functions from the
|
// `fn` indicates the function: one of the built-in functions from the
|
||||||
// Go spec (excluding "make" and "new").
|
// Go spec (excluding "make" and "new").
|
||||||
func (b Builder) BuiltinCall(fn string, args ...Expr) (ret Expr) {
|
func (b Builder) BuiltinCall(fn string, args ...Expr) (ret Expr) {
|
||||||
return b.BuiltinDo(Call, fn, args...)
|
|
||||||
}
|
|
||||||
|
|
||||||
// BuiltinDo call a builtin function with an action.
|
|
||||||
func (b Builder) BuiltinDo(da DoAction, fn string, args ...Expr) (ret Expr) {
|
|
||||||
switch fn {
|
switch fn {
|
||||||
case "len":
|
case "len":
|
||||||
if len(args) == 1 {
|
if len(args) == 1 {
|
||||||
|
|||||||
@@ -44,6 +44,7 @@ const (
|
|||||||
vkFuncDecl
|
vkFuncDecl
|
||||||
vkFuncPtr
|
vkFuncPtr
|
||||||
vkClosure
|
vkClosure
|
||||||
|
vkBuiltin
|
||||||
vkPyFuncRef
|
vkPyFuncRef
|
||||||
vkPyVarRef
|
vkPyVarRef
|
||||||
vkTuple
|
vkTuple
|
||||||
|
|||||||
Reference in New Issue
Block a user