提交 2f5995a2 编写于 作者: chai2010's avatar chai2010

panic 参数限制为 string

上级 92ec97e8
......@@ -53,7 +53,7 @@ func (m *Module) EmitUnOp(x Value, op wat.OpCode) (insts []wat.Inst, ret_type Va
insts = append(insts, wat.NewInstEqz(toWatType(ret_type)))
default:
logger.Fatal("Todo: %[1]v: %[1]T", op)
logger.Fatalf("Todo: %[1]v: %[1]T", op)
}
return
......
......@@ -457,6 +457,20 @@ func (check *Checker) builtin(x *operand, call *ast.CallExpr, id builtinId) (_ b
}
case _Panic:
filename := check.fset.Position(x.pos()).Filename
// panic 语义变化: func panic(msg: string)
if strings.HasSuffix(filename, ".wa") {
// 放松检查, bool 变量放到运行时处理
if !isString(x.typ) {
check.invalidArg(x.pos(), "%s is not a string type", x)
return
}
if nargs != 1 {
check.errorf(call.Pos(), "%v expects %d or %d arguments; found %d", call, 1, 2, nargs)
return
}
}
// panic(x)
// record panic call if inside a function with result parameters
// (for use in Checker.isTerminating)
......
// 版权 @2023 凹语言 作者。保留所有权利。
import "math/bits" => _
func main {
println("hello math")
}
......@@ -494,7 +494,7 @@ func Div(hi, lo, y: uint) => (quo, rem: uint) {
// Div32 panics for y == 0 (division by zero) or y <= hi (quotient overflow).
func Div32(hi, lo, y: uint32) => (quo, rem: uint32) {
if y != 0 && y <= hi {
panic(overflowError)
// panic(overflowError)
}
z := uint64(hi)<<32 | uint64(lo)
quo, rem = uint32(z/uint64(y)), uint32(z%uint64(y))
......@@ -511,10 +511,10 @@ func Div64(hi, lo, y: uint64) => (quo, rem: uint64) {
mask32 = two32 - 1
)
if y == 0 {
panic(divideError)
// panic(divideError)
}
if y <= hi {
panic(overflowError)
// panic(overflowError)
}
s := uint(LeadingZeros64(y))
......
......@@ -69,6 +69,11 @@ func waPrintI32(i: i32) {
print_i32(i)
}
#wa:linkname $runtime.waPrintU32
func waPrintU32(i: u32) {
print_u32(i)
}
#wa:linkname $runtime.waPrintRune
func waPrintRune(ch: i32) {
putchar(ch)
......@@ -96,3 +101,12 @@ func print_i32(i: i32) {
print_i32(i/10)
print_i32(i%10)
}
func print_u32(i: u32) {
if i < 10 {
putchar(i32(i)+'0')
return
}
print_u32(i/10)
print_u32(i%10)
}
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册