Documentation ¶
Overview ¶
The vm package implements the Romualdo Virtual Machine, which executes the bytecode generated by the Romualdo Language Compiler.
Index ¶
- func CSWFromPath(path string) (*bytecode.CompiledStoryworld, *bytecode.DebugInfo, errs.Error)
- func DeserializeCallFrame(r io.Reader, stack *Stack) (*callFrame, errs.Error)
- func LoadCompiledStoryworldBinaries(cswPath string, diRequired bool) (*bytecode.CompiledStoryworld, *bytecode.DebugInfo, errs.Error)
- func RunCSW(csw *bytecode.CompiledStoryworld, di *bytecode.DebugInfo, trace bool) (err errs.Error)
- type Stack
- type StackView
- type State
- type VM
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func CSWFromPath ¶
CSWFromPath loads the CompiledStoryworld and DebugInfo from the given path, which can be either a compiled Storyworld (*.ras) file or a directory with the Storyworld source code (*.ral).
func DeserializeCallFrame ¶
DeserializeCallFrame deserializes a callFrame from the given io.Reader. The stack parameter will be used for callFrame.stack.stack; you can technically pass a nil here and fill the field later, but things will look much tidier if you pass the right stack here.
func LoadCompiledStoryworldBinaries ¶
func LoadCompiledStoryworldBinaries(cswPath string, diRequired bool) (*bytecode.CompiledStoryworld, *bytecode.DebugInfo, errs.Error)
LoadCompiledStoryworldBinaries loads the CompiledStoryworld from cwPath. It also looks for the corresponding DebugInfo file and loads it if found. If the DebugInfo file is not found, it returns an error only if diRequired is true.
Types ¶
type Stack ¶
type Stack struct {
// contains filtered or unexported fields
}
Stack implements the VM runtime stack, which is a stack of bytecode.Values.
func DeserializeStack ¶
DeserializeStack deserializes a Stack from the given io.Reader.
type StackView ¶
type StackView struct {
// contains filtered or unexported fields
}
StackView provides a read-write view into a Stack. It looks just like a Stack, but uses data owned by a real Stack, and behaves as if its base was at some arbitrary point within that backing Stack.
It's assumed that all accesses made to this view are done while it is the topmost view created on the backing stack.
This behavior matches the use case of call frames.
type State ¶
type State int
State represents the state of a VM.
const ( // StateNew is the state of a VM that has just been created. From here, // you'd typically call VM.Start() or VM.LoadState(). StateNew State = iota // StateWaitingForInput is the state of a VM that has started executing the // Storyworld and is waiting for input from the user. The typical next // action is to call either VM.Step() or VM.SaveState(). VM.LoadState() is // also valid. StateWaitingForInput // StateEndOfStory is the state of a VM that has finished executing the // Storyworld. From here, could simply exit, but calling VM.LoadState() or // VM.Start() are also valid. VM.SaveState() is also possible, but a bit // odd. StateEndOfStory )
type VM ¶
type VM struct { // Swid is the Storyworld ID. It must match the corresponding field in csw. Swid string // Swov is the Storyworld version. When loading a saved state, the // serialized state must be equal to or less than the corresponding field in // csw. In other words, we can deal with saved states from older versions of // the Storyworld, but not from newer versions. Swov int32 // State is the current state of the VM. State State // Options contains the options available to the Player. It is only valid // when VM.State == StateWaitingForInput. Options string // Set DebugTraceExecution to true to make the VM disassemble the code as it // runs through it. DebugTraceExecution bool // contains filtered or unexported fields }
VM is a Romualdo Virtual Machine.
func New ¶
func New(csw *bytecode.CompiledStoryworld, di *bytecode.DebugInfo) *VM
New returns a new Virtual Machine capable of executing the given Storyworld csw. If not nil, the VM will use the given DebugInfo di to provide better error messages.
func (*VM) Deserialize ¶
Deserialize deserializes a VM state from the given io.Reader.