Link Search Menu Expand Document

Virtual Machine

Table of Contents

  1. Implementation
  2. CSNadiaVMCommandNotFoundError(Exception)
  3. CSNadiaVM
    1. __init__
    2. has_more_instructions()
    3. preview_next_instruction()
    4. next()
    5. get(name)
    6. pos
  4. CSNadiaVMWriterBuilder
    1. Attributes
    2. __init__
    3. alloc(array_name, size=1)
    4. push(array, index)
    5. pop(array, index)
    6. set(value)
    7. move(direction)
    8. collect()
    9. add()
    10. sub()
    11. mult()
    12. div()
    13. neg()
    14. exit()
    15. write()
    16. clear()
    17. undo(ignore_collect=True)
  5. CSNadiaVMWriter
    1. __init__
    2. alloc(array_name, size=1)
    3. push(array, index)
    4. pop(array, index)
    5. set(value)
    6. move(direction)
    7. collect()
    8. add()
    9. sub()
    10. mult()
    11. div()
    12. neg()
    13. exit()
    14. write()

This submodule contains the low-level virtual machine reader for the minigame code.

Implementation

The Unscripted API and the minigame GUI eventually write files readable by the Nadia Virtual Machine (NVM). The Nadia Virtual Machine is a stack-based virtual machine designed to perform operations specific to the Unscripted minigame.


CSNadiaVMCommandNotFoundError(Exception)

VM command not found.

CSNadiaVM

An implementation of the NadiaVM stack.

__init__

Construct the VM reader.

Arguments

  • path (str): The path to the compiled NadiaVM file (.nvm) to read from.
  • pl (tuple): The coordinates of the player.

has_more_instructions()

Determine if the VM has more instructions to execute.

Returns

  • more (bool): Boolean that will be True if there are more instructions, False otherwise.

preview_next_instruction()

Get the next command in the instruction list without executing it in the VM.

Returns

  • command (str): The command to be executed, excluding parameters, or None if there are no more instructions to execute in the VM.

next()

Execute the next instruction in the VM code.

Raises

get(name)

Get the specified item in the virtual machine.

Arguments

  • name (str): The name of the item to get.

Returns

  • array (list): The specified item, or None if it doesn’t exist.

pos

Get the current player position from the VM execution stack.

Returns

  • player (tuple): A tuple containing the coordinates of the player.

CSNadiaVMWriterBuilder

An list-based implementation of the NadiaVM file writer.

This class is similar to CSNadaVMWriter and contains the same methods; however, CSNadiaVMWriterBuilder uses a list to store its code rather the string that CSNadiaVMWriter uses. This is useful in instances where the builder needs to remove pieces of code or work with the current set of instructions as a list.

Attributes

  • instructions (list): The list of VM commands to write to the VM file.

__init__

Construct the VM writer builder.

Arguments

  • path (str): The path to the compiled NadiaVM file (.nvm) to write to.

alloc(array_name, size=1)

Allocate a space of memory for a given array.

Arguments

  • array_name (str): The name of the array to allocate space for.
  • size (int): The size of the array. Defaults to 1.

push(array, index)

Push the top-most item on the current stack to the given array.

Arguments

  • array (str): The name of the array to push to.
  • index (int): The index of the array to push to.

pop(array, index)

Pop the item from the array at a given index and set it at the top of the execution stack.

Arguments

  • array (str): The array to pop an item from.
  • index (int): The index of the item in the array to pop.

set(value)

Set the top of the stack to a constant value.

Arguments

  • value (any): The value to create a constant for.

move(direction)

Move the player in a given direction.

Arguments

  • direction (str): The direction the player will move in.

collect()

Collect. In the VM, this acts like a pause.

add()

Add the two topmost values on the stack.

sub()

Subtract the two topmost values on the stack.

mult()

Multiply the two topmost values on the stack.

div()

Divide the two topmost values on the stack.

neg()

Negate the topmost value on the stack.

Effectively, this is the equivalent of pushing -1 onto the stack and calling mult.

exit()

Try to exit the world and end execution of the script.

write()

Write the VM code to the requested file.

clear()

Clear all of the current instructions in the VM stack.

undo(ignore_collect=True)

Remove the top of the instruction stack.

Arguments

  • ignore_collect (bool): Whether to ignore the pop and push statements preceding the collect statement. Defaults to True.

CSNadiaVMWriter

An implementation of the NadiaVM file writer.

__init__

Construct the VM writer.

Arguments

  • path (str): The path to the compiled NadiaVM file (.nvm) to write to.

alloc(array_name, size=1)

Allocate a space of memory for a given array.

Arguments

  • array_name (str): The name of the array to allocate space for.
  • size (int): The size of the array. Defaults to 1.

push(array, index)

Push the top-most item on the current stack to the given array.

Arguments

  • array (str): The name of the array to push to.
  • index (int): The index of the array to push to.

pop(array, index)

Pop the item from the array at a given index and set it at the top of the execution stack.

Arguments

  • array (str): The array to pop an item from.
  • index (int): The index of the item in the array to pop.

set(value)

Set the top of the stack to a constant value.

Arguments

  • value (any): The value to create a constant for.

move(direction)

Move the player in a given direction.

Arguments

  • direction (str): The direction the player will move in.

collect()

Collect. In the VM, this acts like a pause.

add()

Add the two topmost values on the stack.

sub()

Subtract the two topmost values on the stack.

mult()

Multiply the two topmost values on the stack.

div()

Divide the two topmost values on the stack.

neg()

Negate the topmost value on the stack.

Effectively, this is the equivalent of pushing -1 onto the stack and calling mult.

exit()

Try to exit the world and end execution of the script.

write()

Write the VM code to the requested file.