llm
Download
149 lines 4.2 KiBYAMLModified 2026-08-20 raw
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149
Byte.get_bit:
  short: check whether a bit is set
  description: >
    In the binary representation of a byte, check whether a given bit index is
    set to 1 or not.
  note: >
    The bit index must be between 1-8 or a runtime error will be produced.
  return:
    type: 'Bool'
    description: >
      Whether or not the given bit index is set to 1 in the byte.
  args:
    i:
      type: 'Byte'
      description: >
        The byte whose bits are being inspected.
    bit_index:
      type: 'Int'
      description: >
        The index of the bit to check (1-indexed, range 1-8).
  example: |
    assert not Byte(6).get_bit(1)
    assert Byte(6).get_bit(2)
    assert Byte(6).get_bit(3)
    assert not Byte(6).get_bit(4)

Byte.hex:
  short: convert to hexidecimal
  description: >
    Convert a byte to a hexidecimal text representation.
  return:
    type: 'Text'
    description: >
      The byte as a hexidecimal text.
  args:
    byte:
      type: 'Byte'
      description: >
        The byte to convert to hex.
    uppercase:
      type: 'Bool'
      default: 'yes'
      description: >
        Whether or not to use uppercase hexidecimal letters.
    prefix:
      type: 'Bool'
      default: 'no'
      description: >
        Whether or not to prepend a `0x` prefix.
  example: |
    assert Byte(18).hex(prefix=yes) == "0x12"

Byte.is_between:
  short: test if inside a range
  description: >
    Determines if an integer is between two numbers (inclusive).
  return:
    type: 'Bool'
    description: >
      `yes` if `a <= x and x <= b` or `b <= x and x <= a`, otherwise `no`
  args:
    x:
      type: 'Byte'
      description: >
        The integer to be checked.
    low:
      type: 'Byte'
      description: >
        One end of the range to check (inclusive);
    high:
      type: 'Byte'
      description: >
        The other end of the range to check (inclusive);
  example: |
    assert Byte(7).is_between(1, 10)
    assert Byte(7).is_between(10, 1)
    assert not Byte(7).is_between(100, 200)
    assert Byte(7).is_between(1, 7)

Byte.parse:
  short: convert text to a byte
  description: >
    Parse a byte literal from text.
  return:
    type: 'Byte?'
    description: >
      The byte parsed from the text, if successful, otherwise `none`.
  args:
    text:
      type: 'Text'
      description: >
        The text to parse.
    base:
      type: 'Int?'
      default: 'none'
      description: >
        The numeric base to use when parsing the byte. If unspecified, the
        byte's base will be inferred from the text prefix. After any "+" or "-"
        sign, if the text begins with "0x", the base will be assumed to be 16,
        "0o" will assume base 8, "0b" will assume base 2, otherwise the base
        will be assumed to be 10.
    remainder:
      type: '&Text?'
      default: 'none'
      description: >
        If non-none, this argument will be set to the remainder of the text after the matching part.
        If none, parsing will only succeed if the entire text matches.
  example: |
    assert Byte.parse("5") == Byte(5)
    assert Byte.parse("asdf") == none
    assert Byte.parse("123xyz") == none

    remainder : Text
    assert Byte.parse("123xyz", remainder=&remainder) == Byte(123)
    assert remainder == "xyz"

Byte.to:
  short: iterate over a range of bytes
  description: >
    Returns an iterator function that iterates over the range of bytes specified.
  return:
    type: 'func(->Byte?)'
    description: >
      An iterator function that returns each byte in the given range (inclusive).
  args:
    first:
      type: 'Byte'
      description: >
        The starting value of the range.
    last:
      type: 'Byte'
      description: >
        The ending value of the range.
    step:
      type: 'Int8?'
      default: 'none'
      description: >
        An optional step size to use. If unspecified or `none`, the step will be inferred to be `+1` if `last >= first`, otherwise `-1`.
  example: |
    iter := Byte(2).to(4)
    assert iter() == Byte(2)
    assert iter() == Byte(3)
    assert iter() == Byte(4)
    assert iter() == none

    assert [x for x in Byte(2).to(5)] == [Byte(2), Byte(3), Byte(4), Byte(5)]
    assert [x for x in Byte(5).to(2)] == [Byte(5), Byte(4), Byte(3), Byte(2)]
    assert [x for x in Byte(2).to(5, step=2)] == [Byte(2), Byte(4)]