def execute(cls, stack: MichelsonStack, stdout: List[str], context: AbstractContext): a = cast(Union[StringType, BytesType, ListType], stack.pop1()) a.assert_type_in(StringType, BytesType, ListType) if isinstance(a, ListType): a.assert_type_in(ListType) res_type, convert, delim = dispatch_types( a.args[0], mapping={ (StringType, ): (StringType, str, ''), (BytesType, ): (BytesType, bytes, b'') }) res = res_type.from_value(delim.join(map(convert, a))) stdout.append(format_stdout(cls.prim, [a], [res])) else: b = cast(Union[StringType, BytesType], stack.pop1()) res_type, convert = dispatch_types(type(a), type(b), mapping={ (StringType, StringType): (StringType, str), (BytesType, BytesType): (BytesType, bytes) }) res = res_type.from_value(convert(a) + convert(b)) stdout.append(format_stdout(cls.prim, [a, b], [res])) stack.push(res) return cls()
def execute(cls, stack: MichelsonStack, stdout: List[str], context: AbstractContext): a, b = cast( Tuple[Union[IntType, NatType, MutezType, TimestampType], ...], stack.pop2()) q_type, r_type = dispatch_types( type(a), type(b), mapping={ # type: ignore (NatType, NatType): (NatType, NatType), (NatType, IntType): (IntType, NatType), (IntType, NatType): (IntType, NatType), (IntType, IntType): (IntType, NatType), (MutezType, NatType): (MutezType, MutezType), (MutezType, MutezType): (NatType, MutezType) } ) # type: Union[Type[IntType], Type[NatType], Type[TimestampType], Type[MutezType]] if int(b) == 0: res = OptionType.none(PairType.create_type(args=[q_type, r_type])) else: q, r = divmod(int(a), int(b)) if r < 0: r += abs(int(b)) q += 1 items = [q_type.from_value(q), r_type.from_value(r)] res = OptionType.from_some(PairType.from_comb(items)) stack.push(res) stdout.append(format_stdout(cls.prim, [a, b], [res])) # type: ignore return cls(stack_items_added=1)
def execute(cls, stack: MichelsonStack, stdout: List[str], context: AbstractContext): a, b = cast( Tuple[Union[IntType, NatType, MutezType, TimestampType, BLS12_381_G1Type, BLS12_381_G2Type, BLS12_381_FrType], ...], stack.pop2()) res_type, = dispatch_types( type(a), type(b), mapping={ (NatType, NatType): (NatType, ), (NatType, IntType): (IntType, ), (IntType, NatType): (IntType, ), (IntType, IntType): (IntType, ), (TimestampType, IntType): (TimestampType, ), (IntType, TimestampType): (TimestampType, ), (MutezType, MutezType): (MutezType, ), (BLS12_381_FrType, BLS12_381_FrType): (BLS12_381_FrType, ), (BLS12_381_G1Type, BLS12_381_G1Type): (BLS12_381_G1Type, ), (BLS12_381_G2Type, BLS12_381_G2Type): (BLS12_381_G2Type, ) }) res_type = cast( Union[Type[IntType], Type[NatType], Type[TimestampType], Type[MutezType], Type[BLS12_381_G1Type], Type[BLS12_381_G2Type], Type[BLS12_381_FrType]], res_type) if issubclass(res_type, IntType): res = res_type.from_value(int(a) + int(b)) # type: ignore else: res = res_type.from_point(bls12_381.add( a.to_point(), b.to_point())) # type: ignore stack.push(res) stdout.append(format_stdout(cls.prim, [a, b], [res])) # type: ignore return cls(stack_items_added=1)
def execute_boolean_add(prim: str, stack: MichelsonStack, stdout: List[str], add: Callable): a, b = cast(Tuple[Union[BoolType, NatType], ...], stack.pop2()) res_type, convert = dispatch_types(type(a), type(b), mapping={ (BoolType, BoolType): (BoolType, bool), (NatType, NatType): (NatType, int) }) val = add((convert(a), convert(b))) res = res_type.from_value(val) stack.push(res) stdout.append(format_stdout(prim, [a, b], [res]))
def execute(cls, stack: MichelsonStack, stdout: List[str], context: AbstractContext): a = cast(Union[IntType, NatType, BoolType], stack.pop1()) res_type, convert = dispatch_types(type(a), mapping={ (NatType,): (IntType, lambda x: ~int(x)), (IntType,): (IntType, lambda x: ~int(x)), (BoolType,): (BoolType, lambda x: not bool(x)) }) res = res_type.from_value(convert(a)) stack.push(res) stdout.append(format_stdout(cls.prim, [a], [res])) # type: ignore return cls(stack_items_added=1)
def execute(cls, stack: MichelsonStack, stdout: List[str], context: AbstractContext): a, b = cast(Tuple[Union[BoolType, NatType, IntType], ...], stack.pop2()) res_type, convert = dispatch_types(type(a), type(b), mapping={ (BoolType, BoolType): (BoolType, bool), (NatType, NatType): (NatType, int), (NatType, IntType): (NatType, int), (IntType, NatType): (NatType, int), }) res = res_type.from_value(convert(a) & convert(b)) stack.push(res) stdout.append(format_stdout(cls.prim, [a, b], [res])) # type: ignore return cls(stack_items_added=1)
def execute(cls, stack: MichelsonStack, stdout: List[str], context: AbstractContext): a, b = cast( Tuple[Union[IntType, NatType, MutezType, TimestampType], ...], stack.pop2()) res_type, = dispatch_types( type(a), type(b), mapping={ # type: ignore (NatType, NatType): (IntType, ), (NatType, IntType): (IntType, ), (IntType, NatType): (IntType, ), (IntType, IntType): (IntType, ), (TimestampType, IntType): (TimestampType, ), (TimestampType, TimestampType): (IntType, ), (MutezType, MutezType): (MutezType, ) } ) # type: Union[Type[IntType], Type[NatType], Type[TimestampType], Type[MutezType]] res = res_type.from_value(int(a) - int(b)) stack.push(res) stdout.append(format_stdout(cls.prim, [a, b], [res])) # type: ignore return cls(stack_items_added=1)
def execute(cls, stack: MichelsonStack, stdout: List[str], context: AbstractContext): a = cast( Union[IntType, NatType, BLS12_381_FrType, BLS12_381_G1Type, BLS12_381_G2Type], stack.pop1()) res_type, = dispatch_types(type(a), mapping={ (IntType, ): (IntType, ), (NatType, ): (IntType, ), (BLS12_381_FrType, ): (BLS12_381_FrType, ), (BLS12_381_G1Type, ): (BLS12_381_G1Type, ), (BLS12_381_G2Type, ): (BLS12_381_G2Type, ) }) if issubclass(res_type, IntType): res = IntType.from_value(-int(a)) else: res = res_type.from_point(bls12_381.neg(a.to_point())) stack.push(res) stdout.append(format_stdout(cls.prim, [a], [res])) return cls()