Incorporate some design decisions from old TBC project #4

Open
opened 2025-05-12 00:03:52 -04:00 by lambdabeta · 0 comments
Owner

For reference, here is the "learn X in Y" source of my old TBC project:

#!/usr/bin/tbc

# These are line comments. The VM continues until it reads a newline character
# Otherwise whitespace is ignored outside of string literals and labels

# The VM has effectively 3 types of memory:
#  - Usage memory: allocated manually by the program, starts at a large negative
#  address
#  - Program memory: The bytes of the input stream, loaded at address 0,
#  read and execute only
#  - Stack memory: Starts at a large positive address, grows towards 0

.message: # This is a label, the . starts its name and the : ends it
    # Labels add the current usage memory address to a lookup table. Only
    # "negative" and "program" addresses can be labelled

    # This writes a raw string to the usage memory. The character immediately
    # following the $ is used as the delimiter
    $"Hello, world!"

    # This writes a raw byte string to the usage memory. It is delimited by ;
    x 0A 00;

# Modules are loaded using the ! operation. The module name or file path is
# delimited by ;
!stdlib;

!path/to/my/library;

# The { and } characters are used to effectively "skip" nested sections of
# operations.
#
# The , label is used to label program memory
# The "main" symbol has no special meaning in tbc
,main: {

    # The VM has ? registers:
    #
    # The accumulator - this is the implicit "result" register for most
    # operations
    #
    # The operand - this is the implicit "other" register for most binary
    # operations

    # Each operation is, at least atomically, a single byte
    1 # sets the operand to 1
    m # sets the accumulator to the operand (mov 1)
    2 # sets the operand to 2
    + # adds the operand to the accumulator (add 2)
    s # swaps the accumulator and the operand (swp)


}
For reference, here is the "learn X in Y" source of my old TBC project: ``` #!/usr/bin/tbc # These are line comments. The VM continues until it reads a newline character # Otherwise whitespace is ignored outside of string literals and labels # The VM has effectively 3 types of memory: # - Usage memory: allocated manually by the program, starts at a large negative # address # - Program memory: The bytes of the input stream, loaded at address 0, # read and execute only # - Stack memory: Starts at a large positive address, grows towards 0 .message: # This is a label, the . starts its name and the : ends it # Labels add the current usage memory address to a lookup table. Only # "negative" and "program" addresses can be labelled # This writes a raw string to the usage memory. The character immediately # following the $ is used as the delimiter $"Hello, world!" # This writes a raw byte string to the usage memory. It is delimited by ; x 0A 00; # Modules are loaded using the ! operation. The module name or file path is # delimited by ; !stdlib; !path/to/my/library; # The { and } characters are used to effectively "skip" nested sections of # operations. # # The , label is used to label program memory # The "main" symbol has no special meaning in tbc ,main: { # The VM has ? registers: # # The accumulator - this is the implicit "result" register for most # operations # # The operand - this is the implicit "other" register for most binary # operations # Each operation is, at least atomically, a single byte 1 # sets the operand to 1 m # sets the accumulator to the operand (mov 1) 2 # sets the operand to 2 + # adds the operand to the accumulator (add 2) s # swaps the accumulator and the operand (swp) } ```
Sign in to join this conversation.
No labels
No milestone
No project
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set.

Reference: ARCTIC/arctic#4
No description provided.