MCPcopy Create free account
hub / github.com/CashScript/cashscript / compileCast

Function compileCast

packages/cashc/src/generation/utils.ts:21–37  ·  view source on GitHub ↗
(from: Type, to: Type, isUnsafe: boolean)

Source from the content-addressed store, hash-verified

19}
20
21export 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
39export function compileGlobalFunction(fn: GlobalFunction): Script {
40 const mapping = {

Callers 1

visitCastMethod · 0.85

Calls 1

encodeIntFunction · 0.90

Tested by

no test coverage detected