| 19 | } |
| 20 | |
| 21 | export function compileCast(from: Type, to: Type, isUnsafe: boolean): Script { |
| 22 | if (isUnsafe) return []; |
| 23 | |
| 24 | if (from === PrimitiveType.INT && to instanceof BytesType && to.bound !== undefined) { |
| 25 | return [encodeInt(BigInt(to.bound)), Op.OP_NUM2BIN]; |
| 26 | } |
| 27 | |
| 28 | if (from === PrimitiveType.INT && to === PrimitiveType.BOOL) { |
| 29 | return [Op.OP_0NOTEQUAL]; |
| 30 | } |
| 31 | |
| 32 | if (from instanceof BytesType && to === PrimitiveType.INT) { |
| 33 | return [Op.OP_BIN2NUM]; |
| 34 | } |
| 35 | |
| 36 | return []; |
| 37 | } |
| 38 | |
| 39 | export function compileGlobalFunction(fn: GlobalFunction): Script { |
| 40 | const mapping = { |