Skip to content

Builtin Function Reference Document

This document provides detailed descriptions of various operation code functions and built-in functions, including function features, parameter descriptions, return values, exception scenarios, and usage examples. It covers categories such as encryption, signature verification, arithmetic operations, comparison operations, stack operations (main stack and auxiliary stack), data cloning, slicing, deletion, and pushing, aiming to provide clear and accurate function usage guides for developers.

I. Encryption Functions

1. Rmd160

  • Function Name: Rmd160
  • Short Description: Calculates the RIPEMD160 hash value of the input byte array.
  • Parameters:
    • input_data
      • Type: BYTES
      • Optional/Required: Required
      • Purpose: Raw data for hash calculation
      • Default Value: None
  • Returns:
    • Type: BYTES (fixed length of 20 bytes)
    • Meaning: RIPEMD160 hash result of the input data
  • Example:
    python
    input_bytes: hex = 0x1234567890
    result = Rmd160(input_bytes)

2. Sha1

  • Function Name: Sha1
  • Short Description: Calculates the SHA1 hash value of the input byte array.
  • Parameters:
    • input_data
      • Type: BYTES
      • Optional/Required: Required
      • Purpose: Raw data for hash calculation
      • Default Value: None
  • Returns:
    • Type: BYTES (fixed length of 20 bytes)
    • Meaning: SHA1 hash result of the input data
  • Example:
    python
    input_bytes: hex = 0x1234567890
    result = Sha1(input_bytes)

3. Sha256

  • Function Name: Sha256
  • Short Description: Calculates the SHA256 hash value of the input byte array.
  • Parameters:
    • input_data
      • Type: BYTES
      • Optional/Required: Required
      • Purpose: Raw data for hash calculation
      • Default Value: None
  • Returns:
    • Type: BYTES (fixed length of 32 bytes)
    • Meaning: SHA256 hash result of the input data
  • Example:
    python
    input_bytes: hex = 0x1234567890
    result = Sha256(input_bytes)

4. Hash160

  • Function Name: Hash160
  • Short Description: Performs SHA256 followed by RIPEMD160 combined hash calculation on the input byte array.
  • Parameters:
    • input_data
      • Type: BYTES
      • Optional/Required: Required
      • Purpose: Raw data for combined hash calculation
      • Default Value: None
  • Returns:
    • Type: BYTES (fixed length of 20 bytes)
    • Meaning: Hash result after SHA256+RIPEMD160 calculation on input data
  • Example:
    python
    input_bytes: hex = 0x1234567890
    result = Hash160(input_bytes)

5. Hash256

  • Function Name: Hash256
  • Short Description: Performs double SHA256 hash calculation on the input byte array.
  • Parameters:
    • input_data
      • Type: BYTES
      • Optional/Required: Required
      • Purpose: Raw data for double SHA256 calculation
      • Default Value: None
  • Returns:
    • Type: BYTES (fixed length of 32 bytes)
    • Meaning: Hash result after double SHA256 calculation on input data
  • Example:
    python
    input_bytes: hex = 0x1234567890
    result = Hash256(input_bytes)

6. PartialHash

  • Function Name: PartialHash
  • Short Description: Performs partial hash combination calculation on three input byte arrays.
  • Parameters:
    • part1
      • Type: BYTES
      • Optional/Required: Required
      • Purpose: First part of data for hash calculation
      • Default Value: None
    • part2
      • Type: BYTES
      • Optional/Required: Required
      • Purpose: Second part of data for hash calculation
      • Default Value: None
    • part3
      • Type: BYTES
      • Optional/Required: Required
      • Purpose: Third part of data for hash calculation
      • Default Value: None
  • Returns:
    • Type: BYTES
    • Meaning: Partial hash result after combining three input parts
  • Example:
    python
    p1: hex = 0x1234
    p2: hex = 0x5678
    p3: hex = 0x9012
    result = PartialHash(p1, p2, p3)

II. Signature Verification Functions

1. CheckSig

  • Function Name: CheckSig
  • Short Description: Verifies if the signature matches the public key, returns a boolean result.
  • Parameters:
    • public_key
      • Type: BYTES
      • Optional/Required: Required
      • Purpose: Public key for signature verification
      • Default Value: None
    • signature
      • Type: BYTES
      • Optional/Required: Required
      • Purpose: Signature data to be verified
      • Default Value: None
  • Returns:
    • Type: BOOLEAN
    • Meaning: Returns 1 if signature is valid, 0 if invalid
  • Example:
    python
    sig: hex = 0x1234       # Assuming signature byte array
    pub_key: hex = 0x5678   # Corresponding public key
    result = CheckSig(pub_key, sig)

2. CheckSigVerify

  • Function Name: CheckSigVerify
  • Short Description: Verifies if the signature matches the public key, terminates execution if verification fails.
  • Parameters:
    • public_key
      • Type: BYTES
      • Optional/Required: Required
      • Purpose: Public key for signature verification
      • Default Value: None
    • signature
      • Type: BYTES
      • Optional/Required: Required
      • Purpose: Signature data to be verified
      • Default Value: None
  • Returns: None
  • Example:
    python
    # Valid signature (normal execution)
    valid_sig: hex = 0x1234
    pub_key: hex = 0x5678
    CheckSigVerify(pub_key, valid_sig)  # No output, continues execution
    
    # Invalid signature (throws exception and terminates)
    invalid_sig: hex = 0x9012
    CheckSigVerify(pub_key, invalid_sig)  # Terminates execution

3. MultiSig

  • Function Name: MultiSig
  • Short Description: Verifies if the multi-signature collection matches the public key collection (usually requires at least m valid signatures out of n), returns a boolean result.
  • Parameters:
    • public_keys
      • Type: BYTES (serialized data containing multiple public keys)
      • Optional/Required: Required
      • Purpose: Public key collection for verification
      • Default Value: None
    • signatures
      • Type: BYTES (serialized data containing multiple signatures)
      • Optional/Required: Required
      • Purpose: Multi-signature collection to be verified
      • Default Value: None
  • Returns:
    • Type: BOOLEAN
    • Meaning: Returns 1 if multi-signature verification passes, 0 if not
  • Example:
    python
    sigs: hex = 0x1234567890      # Serialized valid signature collection
    pub_keys: hex = 0x0987654321  # Serialized public key collection
    result = MultiSig(pub_keys, sigs)

4. MultiSigVerify

  • Function Name: MultiSigVerify
  • Short Description: Verifies if the multi-signature collection matches the public key collection, terminates execution if verification fails.
  • Parameters:
    • public_keys
      • Type: BYTES (serialized data containing multiple public keys)
      • Optional/Required: Required
      • Purpose: Public key collection for verification
      • Default Value: None
    • signatures
      • Type: BYTES (serialized data containing multiple signatures)
      • Optional/Required: Required
      • Purpose: Multi-signature collection to be verified
      • Default Value: None
  • Returns: None
  • Example:
    python
    # Valid multi-signature (normal execution)
    valid_sigs: hex = 0x1234567890
    pub_keys: hex = 0x0987654321
    MultiSigVerify(pub_keys, valid_sigs)  # No output, continues execution
    
    # Invalid multi-signature (throws exception and terminates)
    invalid_sigs: hex = 0x6789012345
    MultiSigVerify(pub_keys, invalid_sigs)  # Terminates execution

III. Single Operand Arithmetic Functions

1. Inc

  • Function Name: Inc
  • Short Description: Performs an increment operation on the input integer and returns the result.
  • Parameters:
    • x
      • Type: INTEGER
      • Optional/Required: Required
      • Purpose: Integer to be incremented
      • Default Value: None
  • Returns:
    • Type: INTEGER
    • Meaning: Result after incrementing the input integer by 1
  • Example:
    python
    a: int = 5
    result = Inc(a)   # Result: 6

2. Dec

  • Function Name: Dec
  • Short Description: Performs a decrement operation on the input integer and returns the result.
  • Parameters:
    • x
      • Type: INTEGER
      • Optional/Required: Required
      • Purpose: Integer to be decremented
      • Default Value: None
  • Returns:
    • Type: INTEGER
    • Meaning: Result after decrementing the input integer by 1
  • Example:
    python
    a: int = 5
    result = Dec(a)   # Result: 4

3. Neg

  • Function Name: Neg
  • Short Description: Takes the opposite of the input integer and returns the result.
  • Parameters:
    • x
      • Type: INTEGER
      • Optional/Required: Required
      • Purpose: Integer to take the opposite of
      • Default Value: None
  • Returns:
    • Type: INTEGER
    • Meaning: Opposite of the input integer
  • Example:
    python
    a: int = 5
    result = Neg(a)   # Result: -5

4. Abs

  • Function Name: Abs
  • Short Description: Takes the absolute value of the input integer and returns the result.
  • Parameters:
    • x
      • Type: INTEGER
      • Optional/Required: Required
      • Purpose: Integer to take the absolute value of
      • Default Value: None
  • Returns:
    • Type: INTEGER
    • Meaning: Absolute value of the input integer
  • Example:
    python
    a: int = -5
    result = Abs(a)   # Result: 5

5. Not

  • Function Name: Not
  • Short Description: Performs a logical NOT operation on the input integer, returns a boolean value.
  • Parameters:
    • x
      • Type: INTEGER
      • Optional/Required: Required
      • Purpose: Integer to perform logical NOT on
      • Default Value: None
  • Returns:
    • Type: BOOLEAN
    • Meaning: Returns 1 if input is 0, otherwise returns 0
  • Example:
    python
    a: int = 5
    result = Not(a)   # Result: 0

6. ZeroNotEqual

  • Function Name: ZeroNotEqual
  • Short Description: Checks if the input integer is not equal to 0, returns a boolean value.
  • Parameters:
    • x
      • Type: INTEGER
      • Optional/Required: Required
      • Purpose: Integer to be checked
      • Default Value: None
  • Returns:
    • Type: BOOLEAN
    • Meaning: Returns 1 if input is non-zero, 0 if input is 0
  • Example:
    python
    a: int = 0
    result = ZeroNotEqual(a)   # Result: 0

IV. Double Operand Arithmetic Functions

1. Add

  • Function Name: Add
  • Short Description: Calculates the sum of two integers and returns the result.
  • Parameters:
    • a
      • Type: INTEGER
      • Optional/Required: Required
      • Purpose: First addend
      • Default Value: None
    • b
      • Type: INTEGER
      • Optional/Required: Required
      • Purpose: Second addend
      • Default Value: None
  • Returns:
    • Type: INTEGER
    • Meaning: Sum of the two input integers
  • Example:
    python
    a: int = 2
    b: int = 3
    result = Add(a, b)   # Result: 5

2. Sub

  • Function Name: Sub
  • Short Description: Calculates the difference of the first integer minus the second integer and returns the result.
  • Parameters:
    • a
      • Type: INTEGER
      • Optional/Required: Required
      • Purpose: Minuend
      • Default Value: None
    • b
      • Type: INTEGER
      • Optional/Required: Required
      • Purpose: Subtrahend
      • Default Value: None
  • Returns:
    • Type: INTEGER
    • Meaning: Result of a - b
  • Example:
    python
    a: int = 5
    b: int = 3
    result = Sub(a, b)   # Result: 2

3. Mul

  • Function Name: Mul
  • Short Description: Calculates the product of two integers and returns the result.
  • Parameters:
    • a
      • Type: INTEGER
      • Optional/Required: Required
      • Purpose: First multiplier
      • Default Value: None
    • b
      • Type: INTEGER
      • Optional/Required: Required
      • Purpose: Second multiplier
      • Default Value: None
  • Returns:
    • Type: INTEGER
    • Meaning: Product of the two input integers
  • Example:
    python
    a: int = 2
    b: int = 3
    result = Mul(a, b)   # Result: 6

4. Div

  • Function Name: Div
  • Short Description: Calculates the quotient of the first integer divided by the second integer and returns the result.
  • Parameters:
    • a
      • Type: INTEGER
      • Optional/Required: Required
      • Purpose: Dividend
      • Default Value: None
    • b
      • Type: INTEGER
      • Optional/Required: Required
      • Purpose: Divisor (cannot be 0)
      • Default Value: None
  • Returns:
    • Type: INTEGER
    • Meaning: Quotient of a divided by b (integer part)
  • Example:
    python
    a: int = 10
    b: int = 2
    result = Div(a, b)   # Result: 5

5. Mod

  • Function Name: Mod
  • Short Description: Calculates the remainder of the first integer divided by the second integer and returns the result.
  • Parameters:
    • a
      • Type: INTEGER
      • Optional/Required: Required
      • Purpose: Dividend
      • Default Value: None
    • b
      • Type: INTEGER
      • Optional/Required: Required
      • Purpose: Divisor (cannot be 0)
      • Default Value: None
  • Returns:
    • Type: INTEGER
    • Meaning: Remainder of a divided by b
  • Example:
    python
    a: int = 10
    b: int = 3
    result = Mod(a, b)   # Result: 1

V. Bit Shift Functions

1. Lshift

  • Function Name: Lshift
  • Short Description: Shifts the first integer left by the number of bits specified by the second integer and returns the result.
  • Parameters:
    • a
      • Type: INTEGER
      • Optional/Required: Required
      • Purpose: Integer to be left-shifted
      • Default Value: None
    • b
      • Type: INTEGER
      • Optional/Required: Required
      • Purpose: Number of bits to shift (must be ≥0)
      • Default Value: None
  • Returns:
    • Type: INTEGER
    • Meaning: Result after left-shifting a by b bits
  • Example:
    python
    a: int = 4
    b: int = 2
    result = Lshift(a, b)   # Result: 16

2. Rshift

  • Function Name: Rshift
  • Short Description: Shifts the first integer right by the number of bits specified by the second integer and returns the result.
  • Parameters:
    • a
      • Type: INTEGER
      • Optional/Required: Required
      • Purpose: Integer to be right-shifted
      • Default Value: None
    • b
      • Type: INTEGER
      • Optional/Required: Required
      • Purpose: Number of bits to shift (must be ≥0)
      • Default Value: None
  • Returns:
    • Type: INTEGER
    • Meaning: Result after right-shifting a by b bits
  • Example:
    python
    a: int = 8
    b: int = 3
    result = Rshift(a, b)   # Result: 1

VI. Non-Numeric Comparison Functions

1. Equal

  • Function Name: Equal
  • Short Description: Checks if two byte arrays are equal, returns a boolean value.
  • Parameters:
    • bytes1
      • Type: BYTES
      • Optional/Required: Required
      • Purpose: First byte array to compare
      • Default Value: None
    • bytes2
      • Type: BYTES
      • Optional/Required: Required
      • Purpose: Second byte array to compare
      • Default Value: None
  • Returns:
    • Type: BOOLEAN
    • Meaning: Returns 1 if the two byte arrays are identical, otherwise 0
  • Example:
    python
    a: string = "hello"
    b: string = "hello"
    result = Equal(a, b)   # Result: 1

2. EqualVerify

  • Function Name: EqualVerify
  • Short Description: Checks if two byte arrays are equal, terminates execution if not equal.
  • Parameters:
    • bytes1
      • Type: BYTES
      • Optional/Required: Required
      • Purpose: First byte array to compare
      • Default Value: None
    • bytes2
      • Type: BYTES
      • Optional/Required: Required
      • Purpose: Second byte array to compare
      • Default Value: None
  • Returns: None
  • Example:
    python
    # Equal case (normal execution)
    a: string = "hello"
    b: string = "hello"
    EqualVerify(a, b)  # No output, continues execution
    
    # Unequal case (throws exception and terminates)
    a: string = "hello"
    b: string = "world"
    EqualVerify(a, b)  # Terminates execution

VII. Numeric Comparison Functions

1. NumEqual

  • Function Name: NumEqual
  • Short Description: Checks if two integers are equal, returns a boolean value.
  • Parameters:
    • num1
      • Type: INTEGER
      • Optional/Required: Required
      • Purpose: First integer to compare
      • Default Value: None
    • num2
      • Type: INTEGER
      • Optional/Required: Required
      • Purpose: Second integer to compare
      • Default Value: None
  • Returns:
    • Type: BOOLEAN
    • Meaning: Returns 1 if the two integers are numerically equal, otherwise 0
  • Example:
    python
    a: int = 5
    b: int = 5
    result = NumEqual(a, b)   # Result: 1

2. NumEqualVerify

  • Function Name: NumEqualVerify
  • Short Description: Checks if two integers are equal, terminates execution if not equal.
  • Parameters:
    • num1
      • Type: INTEGER
      • Optional/Required: Required
      • Purpose: First integer to compare
      • Default Value: None
    • num2
      • Type: INTEGER
      • Optional/Required: Required
      • Purpose: Second integer to compare
      • Default Value: None
  • Returns: None
  • Example:
    python
    # Equal case (normal execution)
    a: int = 5
    b: int = 5
    NumEqualVerify(a, b)  # No output, continues execution
    
    # Unequal case (throws exception and terminates)
    a: int = 5
    b: int = 3
    NumEqualVerify(a, b)  # Terminates execution

3. NumNotEqual

  • Function Name: NumNotEqual
  • Short Description: Checks if two integers are not equal, returns a boolean value.
  • Parameters:
    • num1
      • Type: INTEGER
      • Optional/Required: Required
      • Purpose: First integer to compare
      • Default Value: None
    • num2
      • Type: INTEGER
      • Optional/Required: Required
      • Purpose: Second integer to compare
      • Default Value: None
  • Returns:
    • Type: BOOLEAN
    • Meaning: Returns 1 if the two integers are different, otherwise 0
  • Example:
    python
    a: int = 5
    b: int = 3
    result = NumNotEqual(a, b)   # Result: 1

4. LessThan

  • Function Name: LessThan
  • Short Description: Checks if the first integer is less than the second integer, returns a boolean value.
  • Parameters:
    • num1
      • Type: INTEGER
      • Optional/Required: Required
      • Purpose: Left operand in comparison (number being compared)
      • Default Value: None
    • num2
      • Type: INTEGER
      • Optional/Required: Required
      • Purpose: Right operand in comparison (comparison number)
      • Default Value: None
  • Returns:
    • Type: BOOLEAN
    • Meaning: Returns 1 if num1 < num2 holds, otherwise 0
  • Example:
    python
    a: int = 3
    b: int = 5
    result = LessThan(a, b)    # Result: 1

5. GreaterThan

  • Function Name: GreaterThan
  • Short Description: Checks if the first integer is greater than the second integer, returns a boolean value.
  • Parameters:
    • num1
      • Type: INTEGER
      • Optional/Required: Required
      • Purpose: Left operand in comparison (number being compared)
      • Default Value: None
    • num2
      • Type: INTEGER
      • Optional/Required: Required
      • Purpose: Right operand in comparison (comparison number)
      • Default Value: None
  • Returns:
    • Type: BOOLEAN
    • Meaning: Returns 1 if num1 > num2 holds, otherwise 0
  • Example:
    python
    a: int = 5
    b: int = 3
    result = GreaterThan(a, b)   # Result: 1

6. LessOrEqual

  • Function Name: LessOrEqual
  • Short Description: Checks if the first integer is less than or equal to the second integer, returns a boolean value.
  • Parameters:
    • num1
      • Type: INTEGER
      • Optional/Required: Required
      • Purpose: Left operand in comparison (number being compared)
      • Default Value: None
    • num2
      • Type: INTEGER
      • Optional/Required: Required
      • Purpose: Right operand in comparison (comparison number)
      • Default Value: None
  • Returns:
    • Type: BOOLEAN
    • Meaning: Returns 1 if num1 <= num2 holds, otherwise 0
  • Example:
    python
    a: int = 3
    b: int = 5
    result = LessOrEqual(a, b)   # Result: 1

7. GreaterOrEqual

  • Function Name: GreaterOrEqual
  • Short Description: Checks if the first integer is greater than or equal to the second integer, returns a boolean value.
  • Parameters:
    • num1
      • Type: INTEGER
      • Optional/Required: Required
      • Purpose: Left operand in comparison (number being compared)
      • Default Value: None
    • num2
      • Type: INTEGER
      • Optional/Required: Required
      • Purpose: Right operand in comparison (comparison number)
      • Default Value: None
  • Returns:
    • Type: BOOLEAN
    • Meaning: Returns 1 if num1 >= num2 holds, otherwise 0
  • Example:
    python
    a: int = 5
    b: int = 3
    result = GreaterOrEqual(a, b)   # Result: 1

VIII. Min/Max Functions

1. Min

  • Function Name: Min
  • Short Description: Returns the smaller value of two integers.
  • Parameters:
    • a
      • Type: INTEGER
      • Optional/Required: Required
      • Purpose: First integer to compare
      • Default Value: None
    • b
      • Type: INTEGER
      • Optional/Required: Required
      • Purpose: Second integer to compare
      • Default Value: None
  • Returns:
    • Type: INTEGER
    • Meaning: The smaller value of the two input integers
  • Example:
    python
    a: int = 3
    b: int = 5
    result= Min(3, 5)    # Result: 3

2. Max

  • Function Name: Max
  • Short Description: Returns the larger value of two integers.
  • Parameters:
    • a
      • Type: INTEGER
      • Optional/Required: Required
      • Purpose: First integer to compare
      • Default Value: None
    • b
      • Type: INTEGER
      • Optional/Required: Required
      • Purpose: Second integer to compare
      • Default Value: None
  • Returns:
    • Type: INTEGER
    • Meaning: The larger value of the two input integers
  • Example:
    python
    a: int = 3
    b: int = 5
    result = Max(3, 5)    # Result: 5

IX. Range Check Functions

1. Within

  • Function Name: Within
  • Short Description: Checks if the first integer is between the second integer (minimum value) and the third integer (maximum value) (inclusive of boundaries).
  • Parameters:
    • min_val
      • Type: INTEGER
      • Optional/Required: Required
      • Purpose: Minimum value of the range (inclusive)
      • Default Value: None
    • max_val
      • Type: INTEGER
      • Optional/Required: Required
      • Purpose: Maximum value of the range (inclusive)
      • Default Value: None
    • num
      • Type: INTEGER
      • Optional/Required: Required
      • Purpose: Integer to check if within range
      • Default Value: None
  • Returns:
    • Type: BOOLEAN
    • Meaning: Returns 1 if num is in the range [min_val, max_val), otherwise 0
  • Example:
    python
    a: int = 5
    b: int = 3
    c: int = 7
    result = Within(a, b, c)    # Result: 1 (3 ≤ 5 < 7)

X. Data Manipulation Functions

1. Cat

  • Function Name: Cat
  • Short Description: Concatenates two byte arrays into one byte array and returns it.
  • Parameters:
    • bytes1
      • Type: BYTES
      • Optional/Required: Required
      • Purpose: Byte array to concatenate first
      • Default Value: None
    • bytes2
      • Type: BYTES
      • Optional/Required: Required
      • Purpose: Byte array to concatenate after
      • Default Value: None
  • Returns:
    • Type: BYTES
    • Meaning: Byte array after concatenating bytes1 and bytes2
  • Example:
    python
    str1: string = "hello"
    str2: string = "world"
    result = Cat(str1, str2)  # Result: "helloworld"

2. Split

  • Function Name: Split
  • Short Description: Splits a byte array by a specified length and returns two byte arrays.
  • Parameters:
    • bytes_data
      • Type: BYTES
      • Optional/Required: Required
      • Purpose: Byte array to be split
      • Default Value: None
    • n
      • Type: INTEGER
      • Optional/Required: Required
      • Purpose: Split length (must be ≥0)
      • Default Value: None
  • Returns:
    • Type: BYTES, BYTES
    • Meaning: First is the first n bytes of bytes_data, second is the remaining bytes
  • Example:
    python
    # Normal split
    str1: string = "helloworld"
    {part1, part2} = Split(str1, 5)
    # Result: part1: "hello"  part2: "world"
    
    # Split length of 0
    str2: string = "test"
    {part1, part2} = Split(str2, 0)
    # Result: part1: ""  part2: "test"
    
    # Split length equal to original array length
    str3: string = "test"
    {part1, part2} = Split("test", 4)
    # Result: part1: "test"  part2: ""

3. Size

  • Function Name: Size
  • Short Description: Returns the length (number of bytes) of the input byte array.
  • Parameters:
    • bytes_data
      • Type: BYTES
      • Optional/Required: Required
      • Purpose: Byte array to calculate length of
      • Default Value: None
  • Returns:
    • Type: INTEGER
    • Meaning: Length of the byte array (number of bytes)
  • Example:
    python
    str: string = "hello"
    result: int = Size(str)  # Output: 5 ("hello" contains 5 bytes)

XI. Number Conversion Functions

1. NumToBin

  • Function Name: NumToBin
  • Short Description: Converts an integer to a byte array of specified length and returns it.
  • Parameters:
    • num
      • Type: INTEGER
      • Optional/Required: Required
      • Purpose: Integer to be converted
      • Default Value: None
    • length
      • Type: INTEGER
      • Optional/Required: Required
      • Purpose: Length of the target byte array (must be ≥0)
      • Default Value: None
  • Returns:
    • Type: BYTES
    • Meaning: Byte array of length length representing the binary of num
  • Example:
    python
    # Convert to 2-byte array
    a: int = 10
    result = NumToBin(a, 2)  # Result: "0x0a00" (little-endian)
    
    # Pad with 0 when insufficient length
    b: int = 5
    result = NumToBin(b, 4)  # Result: "0x05000000"

2. BinToNum

  • Function Name: BinToNum
  • Short Description: Converts a byte array to an integer and returns it.
  • Parameters:
    • bytes_data
      • Type: BYTES
      • Optional/Required: Required
      • Purpose: Byte array to be converted to integer
      • Default Value: None
  • Returns:
    • Type: INTEGER
    • Meaning: Integer parsed from the byte array
  • Example:
    python
    bytes_data: hex = 0x1234
    result = BinToNum(bytes_data)  # Result: 13330

XII. Logical Operations

1. And

  • Function Name: And
  • Short Description: Performs a logical AND operation on two boolean values and returns the result.
  • Parameters:
    • a
      • Type: BOOLEAN
      • Optional/Required: Required
      • Purpose: First boolean operand
      • Default Value: None
    • b
      • Type: BOOLEAN
      • Optional/Required: Required
      • Purpose: Second boolean operand
      • Default Value: None
  • Returns:
    • Type: BOOLEAN
    • Meaning: Logical AND result of a and b
  • Example:
    python
    a: bool = 1
    b: bool = 0
    result = And(a, b)  # Result: 0

2. Or

  • Function Name: Or
  • Short Description: Performs a logical OR operation on two boolean values and returns the result.
  • Parameters:
    • a
      • Type: BOOLEAN
      • Optional/Required: Required
      • Purpose: First boolean operand
      • Default Value: None
    • b
      • Type: BOOLEAN
      • Optional/Required: Required
      • Purpose: Second boolean operand
      • Default Value: None
  • Returns:
    • Type: BOOLEAN
    • Meaning: Logical OR result of a and b
  • Example:
    python
    a: bool = 1
    b: bool = 0
    result = Or(a, b)  # Result: 1

XIII. Other Built-in Functions

1. SetAlt

  • Function Name: SetAlt
  • Short Description: The main stack and auxiliary stack can be regarded as a continuous linear storage space divided by an operation pointer. Moves the operation pointer from the main stack top to the position of the specified variable, assigning it and the elements to its right to the auxiliary stack.
  • Parameters:
    • variable
      • Type: Any type
      • Optional/Required: Required
      • Purpose: Target variable in the main stack to locate the new position of the operation pointer
      • Default Value: None
  • Returns:
    • Type: No return value
    • Meaning: Only adjusts the boundary pointers of main and auxiliary stacks, no specific return content
  • Example:
    python
      # Initial state: Main stack [ x, y, a, c, b ], Auxiliary stack [ d, e ], pointer at main stack top (right of b)
      SetAlt(a);
      # After execution: Main stack [ x, y ], Auxiliary stack [ a, c, b, d, e ], pointer moved to a's position

2. SetMain

  • Function Name: SetMain
  • Short Description: Moves the operation pointer from the auxiliary stack top to the position of the specified variable, assigning it and the elements to its left to the main stack.
  • Parameters:
    • variable
      • Type: Any type
      • Optional/Required: Required
      • Purpose: Target variable in the auxiliary stack to locate the new position of the operation pointer
      • Default Value: None
  • Returns:
    • Type: No return value
    • Meaning: Only adjusts the boundary pointers of main and auxiliary stacks, no specific return content
  • Example:
    python
      # Initial state: Main stack [ x, y ], Auxiliary stack [ a, c, b, d, e ], pointer at auxiliary stack top (a's position)
      SetMain(b);
      # After execution: Main stack [ x, y, a, c, b ], Auxiliary stack [ d, e ], pointer moved to b's position

3. Clone

  • Function Name: Clone
  • Short Description: Clones the specified object in the stack, generates a completely identical copy and pushes it to the stack top.
  • Parameters:
    • No parameters (function locates the target object through stack context)
  • Returns:
    • Type: Same as original object (default BYTES)
    • Meaning: Clone copy of the original object, pushed to stack top
  • Example:
    python
      a = Push(10)
      result = a.Clone();  # Clone variable a

4. Slice

  • Function Name: Slice
  • Short Description: Performs slicing operation on a byte array, supporting three modes: "slice from beginning", "slice to end", "slice specified length".
  • Parameters:
    • start
      • Type: INTEGER
      • Optional/Required: Required
      • Purpose: Slice starting position (-1 means from beginning, positive number means specific index)
      • Default Value: None
    • end
      • Type: INTEGER
      • Optional/Required: Required
      • Purpose: Slice ending position (-1 means to end, positive number means end index or length)
      • Default Value: None
  • Returns:
    • Type: BYTES
    • Meaning: Sub-byte array obtained after slicing, pushed to stack top
  • Example:
    python
      data: hex = 0x01020304
      # Slice from beginning to position 2
      result1 = data.Slice(-1, 2);  # Result: 0x0102
    
      # Slice from position 1 to end
      result2 = data.Slice(1, -1);  # Result: 0x020304
    
      # Slice 2 bytes from position 1
      result3 = data.Slice(1, 2);   # Result: 0x0203

5. Delete

  • Function Name: Delete
  • Short Description: Deletes one or more variables, supporting recursive deletion of struct variables (automatically deletes all their fields).
  • Parameters:
    • variable1, variable2, ...
      • Type: Any type
      • Optional/Required: Required (at least 1)
      • Purpose: Variables to be deleted, supports ordinary variables and struct variables
      • Default Value: None
  • Returns:
    • Type: No return value
    • Meaning: Only performs variable deletion operation, no specific return content
  • Example:
    python
      # Delete single ordinary variable
      Delete(x);  # Delete variable x from main or auxiliary stack
    
      # Delete struct variable (recursive deletion of fields)
      # Existing struct person, containing person.name (string), person.age (integer)
      Delete(person);  # Simultaneously delete person, person.name, person.age
    
      # Batch delete multiple variables
      Delete(a, b, c);  # Batch delete variables a, b, c

6. Push

  • Function Name: Push
  • Short Description: Pushes the specified value (literal or variable) from the fixed area to the main stack, only supports fixed area data.
  • Parameters:
    • value
      • Type: Any type (literal or fixed area variable)
      • Optional/Required: Required
      • Purpose: Data to be pushed from fixed area to main stack
      • Default Value: None
  • Returns:
    • Type: BYTES
    • Meaning: Data pushed to main stack (consistent with input data type, default as BYTES)
  • Example:
    python
      # Push literal
      result = Push(10);  # Push 10 to main stack
    
      # Push fixed area variable
      # Prerequisite: variable msg exists in fixed area
      result = Push(msg);  # Push msg's value to main stack

7. Keep

  • Function Name: Keep
  • Short Description: Zero-cost abstraction function, used to mark retention of specified number of variables.
  • Parameters:
    • variable1, variable2, ...
      • Type: Any type (default as BYTES)
      • Optional/Required: Required (at least 1)
      • Purpose: Variables to be marked for retention
      • Default Value: None
  • Returns:
    • Type: Same type as input parameters (default BYTES)
    • Meaning: Returns values completely identical in number and type to input, only marks retention status
  • Example:
    python
      # Retain single variable
      a = Push(10)
      Keep(a);  # Mark retention of variable a
    
      # Retain multiple variables
      x = Push(123)
      y = Push("hello")
      Keep(x, y);  # Mark retention of variables x, y

Released under the MIT License.