Skip to content

Commit

Permalink
添加 raw 内置函数; 重新禁止 unsafe 包
Browse files Browse the repository at this point in the history
  • Loading branch information
chai2010 committed Nov 23, 2023
1 parent 9a86768 commit 4bc4e68
Show file tree
Hide file tree
Showing 4 changed files with 20 additions and 1 deletion.
2 changes: 2 additions & 0 deletions internal/backends/compiler_c/compile_func.go
Original file line number Diff line number Diff line change
Expand Up @@ -607,6 +607,8 @@ func (g *functionGenerator) genBuiltin(call *ssa.CallCommon) cir.Expr {
fn_type := ctypes.NewFuncType(cir.ToCType(call.Value.(*ssa.Builtin).Type().(*types.Signature).Results()), args_type)
function := cir.NewVar("$wartc::Append", fn_type)
return cir.NewCallExpr(function, args)
case "raw":
logger.Fatal("Todo.raw:", call.Value)
}
logger.Fatal("Todo:", call.Value)
return nil
Expand Down
16 changes: 16 additions & 0 deletions internal/types/builtins.go
Original file line number Diff line number Diff line change
Expand Up @@ -527,6 +527,22 @@ func (check *Checker) builtin(x *operand, call *ast.CallExpr, id builtinId) (_ b
check.recordBuiltinType(call.Fun, makeSig(x.typ))
}

case _Raw:
if _, ok := x.typ.Underlying().(*Slice); !ok {
check.invalidArg(x.pos(), "%s is not a slice", x.typ)
return
}

retType := NewSlice(Typ[Uint8])
if check.Types != nil {
check.recordBuiltinType(
call.Fun, makeSig(retType, x.typ),
)
}

x.mode = value
x.typ = retType

case _Printf:
S := x.typ
if s, _ := S.Underlying().(*Basic); s == nil || (s.kind != String && s.kind != UntypedString) {
Expand Down
2 changes: 2 additions & 0 deletions internal/types/universe.go
Original file line number Diff line number Diff line change
Expand Up @@ -156,6 +156,7 @@ const (
_Recover

// wa
_Raw
_Printf

// wz
Expand Down Expand Up @@ -192,6 +193,7 @@ var predeclaredFuncs = [...]struct {
_Real: {"real", 1, false, expression},
_Recover: {"recover", 0, false, statement},

_Raw: {"raw", 1, false, expression},
_Printf: {"printf", 1, true, statement},

_长: {"长", 1, false, expression},
Expand Down
1 change: 0 additions & 1 deletion waroot/waroot.go
Original file line number Diff line number Diff line change
Expand Up @@ -159,7 +159,6 @@ var stdPkgs = []string{
"unicode", // API 部分
"unicode/ctypes", // API 完整, 测试已覆盖
"unicode/utf8", // API 完整, 测试已覆盖
"unsafe",
}

var wzStdPkgs = []string{
Expand Down

0 comments on commit 4bc4e68

Please sign in to comment.