github.com/cloudwego/frugal@v0.1.15/internal/binary/decoder/errors_emu.go (about) 1 /* 2 * Copyright 2022 ByteDance Inc. 3 * 4 * Licensed under the Apache License, Version 2.0 (the "License"); 5 * you may not use this file except in compliance with the License. 6 * You may obtain a copy of the License at 7 * 8 * http://www.apache.org/licenses/LICENSE-2.0 9 * 10 * Unless required by applicable law or agreed to in writing, software 11 * distributed under the License is distributed on an "AS IS" BASIS, 12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 * See the License for the specific language governing permissions and 14 * limitations under the License. 15 */ 16 17 package decoder 18 19 import ( 20 `unsafe` 21 22 `github.com/cloudwego/frugal/internal/atm/hir` 23 `github.com/cloudwego/frugal/internal/rt` 24 ) 25 26 func emu_seterr(ctx hir.CallContext, i int, err error) { 27 vv := (*rt.GoIface)(unsafe.Pointer(&err)) 28 ctx.Rp(i, unsafe.Pointer(vv.Itab)) 29 ctx.Rp(i + 1, vv.Value) 30 } 31 32 func emu_gcall_error_eof(ctx hir.CallContext) { 33 if !ctx.Verify("i", "**") { 34 panic("invalid error_eof call") 35 } else { 36 emu_seterr(ctx, 0, error_eof(int(ctx.Au(0)))) 37 } 38 } 39 40 func emu_gcall_error_skip(ctx hir.CallContext) { 41 if !ctx.Verify("i", "**") { 42 panic("invalid error_skip call") 43 } else { 44 emu_seterr(ctx, 0, error_skip(int(ctx.Au(0)))) 45 } 46 } 47 48 func emu_gcall_error_type(ctx hir.CallContext) { 49 if !ctx.Verify("ii", "**") { 50 panic("invalid error_type call") 51 } else { 52 emu_seterr(ctx, 0, error_type(uint8(ctx.Au(0)), uint8(ctx.Au(1)))) 53 } 54 } 55 56 func emu_gcall_error_missing(ctx hir.CallContext) { 57 if !ctx.Verify("*ii", "**") { 58 panic("invalid error_skip call") 59 } else { 60 emu_seterr(ctx, 0, error_missing((*rt.GoType)(ctx.Ap(0)), int(ctx.Au(1)), ctx.Au(2))) 61 } 62 }