Remove various methods from the VM Process type

These methods can/should be used via a ExecutionContext.
parent d78ebee2
Pipeline #163299942 passed with stages
in 65 minutes and 34 seconds
......@@ -136,7 +136,7 @@ mod tests {
let pointer = process.allocate_empty();
let collection = Collection::new(process.clone());
process.set_register(0, pointer);
process.context_mut().set_register(0, pointer);
let stats = collection.perform(&state);
......@@ -159,8 +159,8 @@ mod tests {
mature.mark();
process.set_register(0, young);
process.set_register(1, mature);
process.context_mut().set_register(0, young);
process.context_mut().set_register(1, mature);
let stats = collection.trace(
&mut process.local_data_mut().mailbox.lock(),
......@@ -184,8 +184,8 @@ mod tests {
.allocator
.allocate_mature(Object::new(object_value::none()));
process.set_register(0, young);
process.set_register(1, mature);
process.context_mut().set_register(0, young);
process.context_mut().set_register(1, mature);
let stats = collection.trace(
&mut process.local_data_mut().mailbox.lock(),
......@@ -213,8 +213,8 @@ mod tests {
young.block_mut().set_fragmented();
process.set_register(0, young);
process.set_register(1, mature);
process.context_mut().set_register(0, young);
process.context_mut().set_register(1, mature);
let stats = collection.trace(
&mut process.local_data_mut().mailbox.lock(),
......@@ -241,8 +241,8 @@ mod tests {
young.block_mut().set_fragmented();
mature.block_mut().set_fragmented();
process.set_register(0, young);
process.set_register(1, mature);
process.context_mut().set_register(0, young);
process.context_mut().set_register(1, mature);
let stats = collection.trace(
&mut process.local_data_mut().mailbox.lock(),
......@@ -334,7 +334,7 @@ mod tests {
.allocator
.allocate_mature(Object::new(object_value::none()));
process.set_register(0, pointer2);
process.context_mut().set_register(0, pointer2);
local_data.allocator.remember_object(pointer1);
local_data.allocator.remember_object(pointer2);
......
......@@ -250,10 +250,10 @@ macro_rules! integer_bool_op {
}
macro_rules! float_op {
($state:expr, $process:expr, $ins:expr, $op:tt) => {{
($state:expr, $process:expr, $context:expr, $ins:expr, $op:tt) => {{
let register = $ins.arg(0);
let rec_ptr = $process.get_register($ins.arg(1));
let arg_ptr = $process.get_register($ins.arg(2));
let rec_ptr = $context.get_register($ins.arg(1));
let arg_ptr = $context.get_register($ins.arg(2));
let rec = rec_ptr.float_value()?;
let arg = arg_ptr.float_value()?;
let result = to_expr!(rec $op arg);
......@@ -261,7 +261,7 @@ macro_rules! float_op {
let obj = $process
.allocate(object_value::float(result), $state.float_prototype);
$process.set_register(register, obj);
$context.set_register(register, obj);
}};
}
......
use crate::arc_without_weak::ArcWithoutWeak;
use crate::block::Block;
use crate::compiled_code::CompiledCodePointer;
use crate::config::Config;
use crate::execution_context::ExecutionContext;
use crate::global_scope::GlobalScopePointer;
use crate::immix::block_list::BlockList;
use crate::immix::copy_object::CopyObject;
use crate::immix::global_allocator::RcGlobalAllocator;
......@@ -267,36 +265,6 @@ impl Process {
}
}
pub fn get_register(&self, register: usize) -> ObjectPointer {
self.local_data().context.get_register(register)
}
pub fn set_register(&self, register: usize, value: ObjectPointer) {
self.local_data_mut().context.set_register(register, value);
}
pub fn set_local(&self, index: usize, value: ObjectPointer) {
self.local_data_mut().context.set_local(index, value);
}
pub fn get_local(&self, index: usize) -> ObjectPointer {
self.local_data().context.get_local(index)
}
pub fn local_exists(&self, index: usize) -> bool {
let local_data = self.local_data();
local_data.context.binding.local_exists(index)
}
pub fn set_global(&self, index: usize, value: ObjectPointer) {
self.local_data_mut().context.set_global(index, value);
}
pub fn get_global(&self, index: usize) -> ObjectPointer {
self.local_data().context.get_global(index)
}
pub fn allocate_empty(&self) -> ObjectPointer {
self.local_data_mut().allocator.allocate_empty()
}
......@@ -413,10 +381,6 @@ impl Process {
self.local_data_mut().mailbox.lock().receive()
}
pub fn global_scope(&self) -> &GlobalScopePointer {
&self.context().global_scope
}
pub fn context(&self) -> &ExecutionContext {
&self.local_data().context
}
......@@ -426,10 +390,6 @@ impl Process {
&mut *self.local_data_mut().context
}
pub fn compiled_code(&self) -> CompiledCodePointer {
self.context().code
}
pub fn has_messages(&self) -> bool {
self.local_data().mailbox.lock().has_messages()
}
......
//! VM functions for working with Inko arrays.
use crate::execution_context::ExecutionContext;
use crate::immix::copy_object::CopyObject;
use crate::object_pointer::ObjectPointer;
use crate::object_value;
......@@ -10,11 +11,12 @@ use crate::vm::state::RcState;
pub fn create(
state: &RcState,
process: &RcProcess,
context: &ExecutionContext,
registers: &[u16],
) -> ObjectPointer {
let values = registers
.iter()
.map(|reg| process.get_register(*reg as usize))
.map(|reg| context.get_register(*reg as usize))
.collect();
process.allocate(object_value::array(values), state.array_prototype)
......
//! VM functions for working with Inko blocks.
use crate::block::Block;
use crate::compiled_code::CompiledCodePointer;
use crate::execution_context::ExecutionContext;
use crate::object_pointer::ObjectPointer;
use crate::object_value;
use crate::process::RcProcess;
......@@ -10,11 +10,11 @@ use crate::vm::state::RcState;
pub fn create(
state: &RcState,
process: &RcProcess,
code: CompiledCodePointer,
context: &ExecutionContext,
code_index: usize,
receiver_opt: Option<ObjectPointer>,
) -> ObjectPointer {
let context = process.context();
let code = context.code.code_object(code_index);
let captures_from = if code.captures {
Some(context.binding.clone())
} else {
......@@ -23,8 +23,7 @@ pub fn create(
let receiver = receiver_opt.unwrap_or(context.binding.receiver);
let block =
Block::new(code, captures_from, receiver, *process.global_scope());
let block = Block::new(code, captures_from, receiver, context.global_scope);
process.allocate(object_value::block(block), state.block_prototype)
}
......
......@@ -334,6 +334,7 @@ impl Machine {
let obj = array::create(
&self.state,
process,
context,
&instruction.arguments[1..=val_count],
);
......@@ -375,11 +376,11 @@ impl Machine {
InstructionType::SetBlock => {
let register = instruction.arg(0);
let cc_index = instruction.arg(1);
let cc = context.code.code_object(cc_index);
let obj = block::create(
&self.state,
process,
cc,
context,
cc_index,
instruction.arg_opt(2).map(|r| context.get_register(r)),
);
......@@ -580,19 +581,19 @@ impl Machine {
integer_bool_op!(self.state, context, instruction, <=);
}
InstructionType::FloatAdd => {
float_op!(self.state, process, instruction, +);
float_op!(self.state, process, context, instruction, +);
}
InstructionType::FloatMul => {
float_op!(self.state, process, instruction, *);
float_op!(self.state, process, context, instruction, *);
}
InstructionType::FloatDiv => {
float_op!(self.state, process, instruction, /);
float_op!(self.state, process, context, instruction, /);
}
InstructionType::FloatSub => {
float_op!(self.state, process, instruction, -);
float_op!(self.state, process, context, instruction, -);
}
InstructionType::FloatMod => {
float_op!(self.state, process, instruction, %);
float_op!(self.state, process, context, instruction, %);
}
InstructionType::FloatToInteger => {
let reg = instruction.arg(0);
......@@ -957,7 +958,7 @@ impl Machine {
InstructionType::LocalExists => {
let reg = instruction.arg(0);
let idx = instruction.arg(1);
let res = process::local_exists(&self.state, process, idx);
let res = process::local_exists(&self.state, context, idx);
context.set_register(reg, res);
}
......@@ -1030,13 +1031,13 @@ impl Machine {
let depth = instruction.arg(1);
let value = context.get_register(instruction.arg(2));
process::set_parent_local(process, local, depth, value)?;
process::set_parent_local(context, local, depth, value)?;
}
InstructionType::GetParentLocal => {
let reg = instruction.arg(0);
let depth = instruction.arg(1);
let local = instruction.arg(2);
let val = process::get_parent_local(process, local, depth)?;
let val = process::get_parent_local(context, local, depth)?;
context.set_register(reg, val)
}
......@@ -1097,6 +1098,7 @@ impl Machine {
self.prepare_new_context(
process,
&instruction,
&context,
&mut new_ctx,
instruction.arg(2),
instruction.arg(3),
......@@ -1112,14 +1114,14 @@ impl Machine {
let idx = instruction.arg(1);
let val = context.get_register(instruction.arg(2));
let res =
process::set_global(&self.state, process, idx, val);
process::set_global(&self.state, context, idx, val);
context.set_register(reg, res);
}
InstructionType::GetGlobal => {
let reg = instruction.arg(0);
let idx = instruction.arg(1);
let val = process.get_global(idx);
let val = context.get_global(idx);
context.set_register(reg, val);
}
......@@ -1139,6 +1141,7 @@ impl Machine {
self.prepare_new_context(
process,
&instruction,
process.context(),
context,
instruction.arg(0),
instruction.arg(1),
......@@ -1618,6 +1621,7 @@ impl Machine {
self.prepare_new_context(
process,
&instruction,
context,
&mut new_ctx,
instruction.arg(3),
instruction.arg(4),
......@@ -2101,29 +2105,33 @@ impl Machine {
fn set_positional_arguments(
&self,
process: &RcProcess,
context: &mut ExecutionContext,
current_context: &ExecutionContext,
new_context: &mut ExecutionContext,
registers: &[u16],
) {
let locals = context.binding.locals_mut();
let locals = new_context.binding.locals_mut();
for (index, register) in registers.iter().enumerate() {
locals[index] = process.get_register(usize::from(*register));
locals[index] =
current_context.get_register(usize::from(*register));
}
}
fn pack_excessive_arguments(
&self,
process: &RcProcess,
context: &mut ExecutionContext,
current_context: &ExecutionContext,
new_context: &mut ExecutionContext,
pack_local: usize,
registers: &[u16],
) {
let locals = context.binding.locals_mut();
let locals = new_context.binding.locals_mut();
let pointers = registers
.iter()
.map(|register| process.get_register(usize::from(*register)))
.map(|register| {
current_context.get_register(usize::from(*register))
})
.collect::<Vec<ObjectPointer>>();
locals[pack_local] = process.allocate(
......@@ -2132,45 +2140,54 @@ impl Machine {
);
}
#[cfg_attr(feature = "cargo-clippy", allow(too_many_arguments))]
fn prepare_new_context(
&self,
process: &RcProcess,
instruction: &Instruction,
context: &mut ExecutionContext,
current_context: &ExecutionContext,
new_context: &mut ExecutionContext,
given_positional: usize,
given_keyword: usize,
pos_start: usize,
) -> Result<(), String> {
self.validate_number_of_arguments(
context.code,
new_context.code,
given_positional,
given_keyword,
)?;
let (excessive, pos_args) =
context.code.number_of_arguments_to_set(given_positional);
let (excessive, pos_args) = new_context
.code
.number_of_arguments_to_set(given_positional);
let pos_end = pos_start + pos_args;
let key_start = pos_start + given_positional;
self.set_positional_arguments(
process,
context,
current_context,
new_context,
&instruction.arguments[pos_start..pos_end],
);
if excessive {
let local_index = context.code.rest_argument_index();
let local_index = new_context.code.rest_argument_index();
let extra = &instruction.arguments[pos_end..key_start];
self.pack_excessive_arguments(process, context, local_index, extra);
self.pack_excessive_arguments(
process,
current_context,
new_context,
local_index,
extra,
);
}
if given_keyword > 0 {
self.prepare_keyword_arguments(
process,
instruction,
context,
current_context,
new_context,
key_start,
);
}
......@@ -2180,19 +2197,19 @@ impl Machine {
fn prepare_keyword_arguments(
&self,
process: &RcProcess,
instruction: &Instruction,
context: &mut ExecutionContext,
current_context: &ExecutionContext,
new_context: &mut ExecutionContext,
keyword_start: usize,
) {
let keyword_args = &instruction.arguments[keyword_start..];
let locals = context.binding.locals_mut();
let locals = new_context.binding.locals_mut();
for slice in keyword_args.chunks(2) {
let key = process.get_register(usize::from(slice[0]));
let val = process.get_register(usize::from(slice[1]));
let key = current_context.get_register(usize::from(slice[0]));
let val = current_context.get_register(usize::from(slice[1]));
if let Some(index) = context.code.argument_position(key) {
if let Some(index) = new_context.code.argument_position(key) {
locals[index] = val;
}
}
......@@ -2206,8 +2223,8 @@ impl Machine {
let mut deferred = Vec::new();
loop {
let code = process.compiled_code();
let context = process.context_mut();
let code = context.code;
let index = context.instruction_index;
for entry in &code.catch_table.entries {
......
//! VM functions for working with Inko processes.
use crate::block::Block;
use crate::duration;
use crate::execution_context::ExecutionContext;
use crate::immix::copy_object::CopyObject;
use crate::object_pointer::ObjectPointer;
use crate::object_value;
......@@ -12,10 +13,10 @@ use std::time::Duration;
pub fn local_exists(
state: &RcState,
process: &RcProcess,
context: &ExecutionContext,
local: usize,
) -> ObjectPointer {
if process.local_exists(local) {
if context.binding.local_exists(local) {
state.true_object
} else {
state.false_object
......@@ -119,13 +120,12 @@ pub fn suspend(
}
pub fn set_parent_local(
process: &RcProcess,
context: &mut ExecutionContext,
local: usize,
depth: usize,
value: ObjectPointer,
) -> Result<(), String> {
if let Some(binding) = process.context_mut().binding.find_parent_mut(depth)
{
if let Some(binding) = context.binding.find_parent_mut(depth) {
binding.set_local(local, value);
Ok(())
......@@ -135,11 +135,11 @@ pub fn set_parent_local(
}
pub fn get_parent_local(
process: &RcProcess,
context: &ExecutionContext,
local: usize,
depth: usize,
) -> Result<ObjectPointer, String> {
if let Some(binding) = process.context().binding.find_parent(depth) {
if let Some(binding) = context.binding.find_parent(depth) {
Ok(binding.get_local(local))
} else {
Err(format!("No binding for depth {}", depth))
......@@ -148,7 +148,7 @@ pub fn get_parent_local(
pub fn set_global(
state: &RcState,
process: &RcProcess,
context: &mut ExecutionContext,
global: usize,
object: ObjectPointer,
) -> ObjectPointer {
......@@ -158,7 +158,7 @@ pub fn set_global(
state.permanent_allocator.lock().copy_object(object)
};
process.set_global(global, value);
context.set_global(global, value);
value
}
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment