Functions are implemented and VM should be able to handle function calls

* VM Signals are used by running functions to dictate whether a function
  should return, or if it should call another function. These signals
  can be injected at any time allowing for user functions to inject
  themselves at runtime.
* obj::Method is gone since it's not being used yet.
* Obj impls must implement as_any(&self) -> &dyn Any now. This allows
  for UserFun and NativeFun to be explicitly cast (among other things,
  in the future).

Signed-off-by: Alek Ratzloff <alekratz@gmail.com>
This commit is contained in:
2020-09-24 15:29:44 -07:00
parent f0032afe12
commit 3976b2135a
11 changed files with 236 additions and 71 deletions

View File

@@ -1,8 +1,9 @@
use crate::{obj::prelude::*, vm::{consts::ConstPool, inst::Inst}};
use shredder::Scan;
use std::io::{self, Write};
/// A compiled package that can be executed by a VM.
#[derive(Debug)]
#[derive(Scan, Debug)]
pub struct Package {
names: Vec<Sym>, // local names mappings
const_pool: ConstPool,
@@ -31,6 +32,7 @@ impl Package {
&self.code
}
/// Dumps a debug output of this package to the given writer.
pub fn dump(&self, writer: &mut dyn Write) -> io::Result<()> {
// column widths
let addr_w = num_digits(self.code().len(), 16).max(4);
@@ -48,9 +50,6 @@ impl Package {
{
let obj_ref = self.const_pool().get(*hdl);
read_obj!(let obj = obj_ref);
// XXX weirdness with coercion, can't deref as a &dyn Obj because
// RwReadLockGuard is not Obj - but using Deref::deref works
let obj: &dyn Obj = std::ops::Deref::deref(obj);
format!("{:?}", obj)
},
),