Skip to content

Commit

Permalink
Prepare frames based on binary type
Browse files Browse the repository at this point in the history
Make decode and preparation of activation frames aware of the binary
type though only MOO is supported at this time.
  • Loading branch information
rdaum committed Jul 5, 2024
1 parent dda80a9 commit 39e500d
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 9 deletions.
18 changes: 10 additions & 8 deletions crates/kernel/src/tasks/vm_host.rs
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ use crate::tasks::task_scheduler_client::TaskSchedulerClient;
use crate::tasks::vm_host::VMHostResponse::{AbortLimit, ContinueOk, DispatchFork, Suspend};
use crate::tasks::{TaskId, VerbCall};
use crate::vm::activation::VmStackFrame;
use crate::vm::vm_call::VerbProgram;
use crate::vm::vm_execute::moo_frame_execute;
use crate::vm::{ExecutionResult, Fork, VerbExecutionRequest};
use crate::vm::{FinallyReason, VMExecState};
Expand Down Expand Up @@ -67,9 +68,10 @@ pub enum VMHostResponse {
RollbackRetry,
}

/// A 'host' for running the MOO virtual machine inside a task.
/// A 'host' for running some kind of interpreter / virtual machine inside a running moor task.
pub struct VmHost {
/// Where we store current execution state for this host.
/// Where we store current execution state for this host. Includes all all activations and the
/// interpreter-specific frames inside them.
vm_exec_state: VMExecState,
/// The maximum stack depth for this task
max_stack_depth: usize,
Expand Down Expand Up @@ -124,13 +126,13 @@ impl VmHost {
command: ParsedCommand,
permissions: Objid,
) {
let binary = Self::decode_program(vi.verbdef().binary_type(), vi.binary());
let program = Self::decode_program(vi.verbdef().binary_type(), vi.binary());
let call_request = VerbExecutionRequest {
permissions,
resolved_verb: vi,
call: verb_call,
command: Some(command),
program: binary,
program,
};

self.start_execution(task_id, call_request)
Expand Down Expand Up @@ -411,11 +413,11 @@ impl VmHost {
self.running = false;
}

pub fn decode_program(binary_type: BinaryType, binary_bytes: Bytes) -> Program {
pub fn decode_program(binary_type: BinaryType, binary_bytes: Bytes) -> VerbProgram {
match binary_type {
BinaryType::LambdaMoo18X => {
Program::from_bytes(binary_bytes).expect("Could not decode MOO program")
}
BinaryType::LambdaMoo18X => VerbProgram::MOO(
Program::from_bytes(binary_bytes).expect("Could not decode MOO program"),
),
_ => panic!("Unsupported binary type {:?}", binary_type),
}
}
Expand Down
6 changes: 6 additions & 0 deletions crates/kernel/src/vm/activation.rs
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ use moor_values::var::{v_empty_list, v_int, v_objid, v_str, v_string, Var, VarTy

use crate::tasks::command_parse::ParsedCommand;
use crate::vm::frame::Frame;
use crate::vm::vm_call::VerbProgram;
use crate::vm::VerbExecutionRequest;
use moor_compiler::Program;
use moor_values::var::Symbol;
Expand Down Expand Up @@ -148,9 +149,14 @@ impl Activation {
matches!(self.frame, VmStackFrame::Bf(_))
}

#[allow(irrefutable_let_patterns)] // We know this is a Moo frame. We're just making room
pub fn for_call(verb_call_request: VerbExecutionRequest) -> Self {
let program = verb_call_request.program;
let verb_owner = verb_call_request.resolved_verb.verbdef().owner();

let VerbProgram::MOO(program) = program else {
unimplemented!("Only MOO programs are supported")
};
let frame = Frame::new(program);
let mut frame = VmStackFrame::Moo(frame);
set_constants(&mut frame);
Expand Down
7 changes: 6 additions & 1 deletion crates/kernel/src/vm/vm_call.rs
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,12 @@ pub struct VerbExecutionRequest {
/// The parsed user command that led to this verb dispatch, if any.
pub command: Option<ParsedCommand>,
/// The decoded MOO Binary that contains the verb to be executed.
pub program: Program,
pub program: VerbProgram,
}

#[derive(Debug, Clone, PartialEq)]
pub enum VerbProgram {
MOO(Program),
}

impl VMExecState {
Expand Down

0 comments on commit 39e500d

Please sign in to comment.