py.Str; py.FromCStr/FromCStrAndLen/FromGoString

This commit is contained in:
xushiwei
2024-07-04 18:34:00 +08:00
parent 23da63767c
commit e55e90db1a
11 changed files with 77 additions and 17 deletions

View File

@@ -28,6 +28,19 @@ import (
// -----------------------------------------------------------------------------
// func pystr(string) *py.Object
func pystr(b llssa.Builder, args []ssa.Value) (ret llssa.Expr) {
if len(args) == 1 {
if c, ok := args[0].(*ssa.Const); ok {
if v := c.Value; v.Kind() == constant.String {
sv := constant.StringVal(v)
return b.PyStr(sv)
}
}
}
panic("pystr(<string-literal>): invalid arguments")
}
// func cstr(string) *int8
func cstr(b llssa.Builder, args []ssa.Value) (ret llssa.Expr) {
if len(args) == 1 {
@@ -175,6 +188,7 @@ var llgoInstrs = map[string]int{
"string": llgoString,
"stringData": llgoStringData,
"funcAddr": llgoFuncAddr,
"pystr": llgoPyStr,
"pyList": llgoPyList,
"sigjmpbuf": llgoSigjmpbuf,
"sigsetjmp": llgoSigsetjmp,
@@ -314,6 +328,8 @@ func (p *context) call(b llssa.Builder, act llssa.DoAction, call *ssa.CallCommon
case llgoPyList:
args := p.compileValues(b, args, fnHasVArg)
ret = b.PyList(args...)
case llgoPyStr:
ret = pystr(b, args)
case llgoCstr:
ret = cstr(b, args)
case llgoAdvance: