diff --git a/Cargo.lock b/Cargo.lock
index c8c8e330..6a1c06ae 100644
--- a/Cargo.lock
+++ b/Cargo.lock
@@ -1100,6 +1100,29 @@ version = "0.2.9"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "28dea519a9695b9977216879a3ebfddf92f1c08c05d984f8996aecd6ecdc811d"
+[[package]]
+name = "flatbuffers"
+version = "24.3.25"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "8add37afff2d4ffa83bc748a70b4b1370984f6980768554182424ef71447c35f"
+dependencies = [
+ "bitflags 1.3.2",
+ "rustc_version",
+]
+
+[[package]]
+name = "flexbuffers"
+version = "2.0.0"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "15d14128f06405808ce75bfebe11e9b0f9da18719ede6d7bdb1702d6bfe0f7e8"
+dependencies = [
+ "bitflags 1.3.2",
+ "byteorder",
+ "num_enum",
+ "serde",
+ "serde_derive",
+]
+
[[package]]
name = "flume"
version = "0.11.0"
@@ -1774,6 +1797,7 @@ dependencies = [
"clap_derive",
"color-eyre",
"eyre",
+ "moor-compiler",
"moor-values",
"owo-colors",
"rpc-common",
@@ -1934,6 +1958,7 @@ dependencies = [
"escargot",
"eyre",
"futures-util",
+ "moor-compiler",
"moor-moot",
"moor-values",
"rpc-async-client",
@@ -1959,6 +1984,8 @@ dependencies = [
"daumtils",
"decorum",
"enum-primitive-derive",
+ "flatbuffers",
+ "flexbuffers",
"im",
"itertools 0.13.0",
"lazy_static",
@@ -2059,6 +2086,27 @@ dependencies = [
"autocfg",
]
+[[package]]
+name = "num_enum"
+version = "0.5.11"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "1f646caf906c20226733ed5b1374287eb97e3c2a5c227ce668c1f2ce20ae57c9"
+dependencies = [
+ "num_enum_derive",
+]
+
+[[package]]
+name = "num_enum_derive"
+version = "0.5.11"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "dcbff9bc912032c62bf65ef1d5aea88983b420f4f839db1e9b0c281a25c9c799"
+dependencies = [
+ "proc-macro-crate",
+ "proc-macro2",
+ "quote",
+ "syn 1.0.109",
+]
+
[[package]]
name = "object"
version = "0.32.2"
@@ -2382,6 +2430,16 @@ dependencies = [
"syn 2.0.72",
]
+[[package]]
+name = "proc-macro-crate"
+version = "1.3.1"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "7f4c021e1093a56626774e81216a4ce732a735e5bad4868a03f3ed65ca0c3919"
+dependencies = [
+ "once_cell",
+ "toml_edit 0.19.15",
+]
+
[[package]]
name = "proc-macro2"
version = "1.0.86"
@@ -3366,7 +3424,7 @@ dependencies = [
"serde",
"serde_spanned",
"toml_datetime",
- "toml_edit",
+ "toml_edit 0.22.17",
]
[[package]]
@@ -3378,6 +3436,17 @@ dependencies = [
"serde",
]
+[[package]]
+name = "toml_edit"
+version = "0.19.15"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "1b5bb770da30e5cbfde35a2d7b9b8a2c4b8ef89548a7a6aeab5c9a576e3e7421"
+dependencies = [
+ "indexmap",
+ "toml_datetime",
+ "winnow 0.5.40",
+]
+
[[package]]
name = "toml_edit"
version = "0.22.17"
@@ -3388,7 +3457,7 @@ dependencies = [
"serde",
"serde_spanned",
"toml_datetime",
- "winnow",
+ "winnow 0.6.16",
]
[[package]]
@@ -3946,6 +4015,15 @@ version = "0.52.6"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "589f6da84c646204747d1270a2a5661ea66ed1cced2631d546fdfb155959f9ec"
+[[package]]
+name = "winnow"
+version = "0.5.40"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "f593a95398737aeed53e489c785df13f3618e41dbcd6718c6addbf1395aa6876"
+dependencies = [
+ "memchr",
+]
+
[[package]]
name = "winnow"
version = "0.6.16"
diff --git a/Cargo.toml b/Cargo.toml
index 288acdc4..e48d7fb6 100644
--- a/Cargo.toml
+++ b/Cargo.toml
@@ -101,6 +101,8 @@ daumtils = { git = "https://github.com/rdaum/daumtils.git", version = "0.2.0" }
decorum = "0.3" # For ordering & comparing our floats
encoding_rs = "0.8.34"
enum-primitive-derive = "0.3"
+flatbuffers = "24.3.25"
+flexbuffers = "2.0.0"
im = "15.1"
inventory = "0.3.15"
itertools = "0.13.0"
diff --git a/crates/compiler/src/ast.rs b/crates/compiler/src/ast.rs
index c0382aa1..1c143339 100644
--- a/crates/compiler/src/ast.rs
+++ b/crates/compiler/src/ast.rs
@@ -12,10 +12,10 @@
// this program. If not, see .
//
-use moor_values::var::Symbol;
+use moor_values::Symbol;
use std::fmt::Display;
-use moor_values::var::Var;
+use moor_values::Var;
/// The abstract syntax tree produced by the parser and converted by codegen into opcodes.
use crate::names::UnboundName;
diff --git a/crates/compiler/src/builtins.rs b/crates/compiler/src/builtins.rs
index 289866c7..4d71c6d5 100644
--- a/crates/compiler/src/builtins.rs
+++ b/crates/compiler/src/builtins.rs
@@ -14,9 +14,9 @@
use bincode::{Decode, Encode};
use lazy_static::lazy_static;
-use moor_values::var::Symbol;
-use moor_values::var::VarType;
-use moor_values::var::VarType::TYPE_MAP;
+use moor_values::Symbol;
+use moor_values::VarType;
+use moor_values::VarType::TYPE_MAP;
/// Global registry of built-in function names.
use std::collections::HashMap;
use ArgCount::{Q, U};
diff --git a/crates/compiler/src/codegen.rs b/crates/compiler/src/codegen.rs
index 6d3c3776..7f22129a 100644
--- a/crates/compiler/src/codegen.rs
+++ b/crates/compiler/src/codegen.rs
@@ -18,8 +18,8 @@ use std::sync::Arc;
use tracing::error;
-use moor_values::var::Var;
-use moor_values::var::Variant;
+use moor_values::Var;
+use moor_values::Variant;
use crate::ast::{
Arg, BinaryOp, CatchCodes, Expr, ScatterItem, ScatterKind, Stmt, StmtNode, UnaryOp,
diff --git a/crates/compiler/src/codegen_tests.rs b/crates/compiler/src/codegen_tests.rs
index 413dfa88..ceda89aa 100644
--- a/crates/compiler/src/codegen_tests.rs
+++ b/crates/compiler/src/codegen_tests.rs
@@ -21,9 +21,9 @@ mod tests {
use crate::opcode::{ScatterArgs, ScatterLabel};
use crate::CompileOptions;
use moor_values::model::CompileError;
- use moor_values::var::Error::{E_INVARG, E_INVIND, E_PERM, E_PROPNF, E_RANGE};
- use moor_values::var::Objid;
- use moor_values::var::Symbol;
+ use moor_values::Error::{E_INVARG, E_INVIND, E_PERM, E_PROPNF, E_RANGE};
+ use moor_values::Objid;
+ use moor_values::Symbol;
use moor_values::SYSTEM_OBJECT;
#[test]
diff --git a/crates/compiler/src/decompile.rs b/crates/compiler/src/decompile.rs
index b6c9e293..e7c712b8 100644
--- a/crates/compiler/src/decompile.rs
+++ b/crates/compiler/src/decompile.rs
@@ -12,8 +12,8 @@
// this program. If not, see .
//
-use moor_values::var::{v_err, v_int, v_none, v_objid, Var};
-use moor_values::var::{v_float, Variant};
+use moor_values::{v_err, v_int, v_none, v_objid, Var};
+use moor_values::{v_float, Variant};
use std::collections::{HashMap, VecDeque};
use crate::ast::{
diff --git a/crates/compiler/src/lib.rs b/crates/compiler/src/lib.rs
index c0aa8f3c..deea43cd 100644
--- a/crates/compiler/src/lib.rs
+++ b/crates/compiler/src/lib.rs
@@ -37,7 +37,7 @@ pub use crate::names::{Name, UnboundNames};
pub use crate::opcode::{Op, ScatterLabel};
pub use crate::parse::CompileOptions;
pub use crate::program::{Program, EMPTY_PROGRAM};
-pub use crate::unparse::unparse;
+pub use crate::unparse::{to_literal, unparse};
#[macro_use]
extern crate pest_derive;
diff --git a/crates/compiler/src/names.rs b/crates/compiler/src/names.rs
index 4fd498b3..7bdd0d76 100644
--- a/crates/compiler/src/names.rs
+++ b/crates/compiler/src/names.rs
@@ -15,7 +15,7 @@
use crate::GlobalName;
use bincode::{Decode, Encode};
use moor_values::model::CompileError;
-use moor_values::var::Symbol;
+use moor_values::Symbol;
use std::collections::HashMap;
use strum::IntoEnumIterator;
diff --git a/crates/compiler/src/opcode.rs b/crates/compiler/src/opcode.rs
index 8aa98e2f..68c67f31 100644
--- a/crates/compiler/src/opcode.rs
+++ b/crates/compiler/src/opcode.rs
@@ -16,8 +16,8 @@ use crate::builtins::BuiltinId;
use crate::labels::{Label, Offset};
use crate::names::Name;
use bincode::{Decode, Encode};
-use moor_values::var::Error;
-use moor_values::var::Objid;
+use moor_values::Error;
+use moor_values::Objid;
#[derive(Clone, Debug, PartialEq, PartialOrd, Encode, Decode)]
pub enum Op {
diff --git a/crates/compiler/src/parse.rs b/crates/compiler/src/parse.rs
index b004b83a..23b76c87 100644
--- a/crates/compiler/src/parse.rs
+++ b/crates/compiler/src/parse.rs
@@ -19,18 +19,18 @@ use std::collections::HashMap;
use std::rc::Rc;
use std::str::FromStr;
-use moor_values::var::{v_none, Symbol};
use moor_values::SYSTEM_OBJECT;
+use moor_values::{v_none, Symbol};
use pest::pratt_parser::{Assoc, Op, PrattParser};
pub use pest::Parser as PestParser;
use tracing::{instrument, warn};
-use moor_values::var::Error::{
+use moor_values::Error::{
E_ARGS, E_DIV, E_FLOAT, E_INVARG, E_INVIND, E_MAXREC, E_NACC, E_NONE, E_PERM, E_PROPNF,
E_QUOTA, E_RANGE, E_RECMOVE, E_TYPE, E_VARNF, E_VERBNF,
};
-use moor_values::var::Objid;
-use moor_values::var::{v_err, v_float, v_int, v_objid, v_str, v_string};
+use moor_values::Objid;
+use moor_values::{v_err, v_float, v_int, v_objid, v_str, v_string};
use crate::ast::Arg::{Normal, Splice};
use crate::ast::StmtNode::Scope;
@@ -1189,9 +1189,9 @@ pub fn unquote_str(s: &str) -> Result {
#[cfg(test)]
mod tests {
- use moor_values::var::Error::{E_INVARG, E_PROPNF, E_VARNF};
- use moor_values::var::{v_err, v_float, v_int, v_obj, v_str};
- use moor_values::var::{v_none, Symbol};
+ use moor_values::Error::{E_INVARG, E_PROPNF, E_VARNF};
+ use moor_values::{v_err, v_float, v_int, v_obj, v_str};
+ use moor_values::{v_none, Symbol};
use crate::ast::Arg::{Normal, Splice};
use crate::ast::Expr::{Call, Id, Prop, Value, Verb};
diff --git a/crates/compiler/src/program.rs b/crates/compiler/src/program.rs
index 34247093..c23e0ba9 100644
--- a/crates/compiler/src/program.rs
+++ b/crates/compiler/src/program.rs
@@ -15,10 +15,11 @@
use crate::labels::{JumpLabel, Label};
use crate::names::{Name, Names};
use crate::opcode::Op;
+use crate::unparse::to_literal;
use bincode::{Decode, Encode};
use bytes::Bytes;
use lazy_static::lazy_static;
-use moor_values::var::Var;
+use moor_values::Var;
use moor_values::{AsByteBuffer, CountingWriter, DecodingError, EncodingError, BINCODE_CONFIG};
use std::fmt::{Display, Formatter};
use std::sync::Arc;
@@ -84,7 +85,7 @@ impl Display for Program {
fn fmt(&self, f: &mut Formatter<'_>) -> std::fmt::Result {
// Write literals indexed by their offset #
for (i, l) in self.literals.iter().enumerate() {
- writeln!(f, "L{}: {}", i, l.to_literal())?;
+ writeln!(f, "L{}: {}", i, to_literal(l))?;
}
// Write jump labels indexed by their offset & showing position & optional name
diff --git a/crates/compiler/src/unparse.rs b/crates/compiler/src/unparse.rs
index 74e04505..ae789e50 100644
--- a/crates/compiler/src/unparse.rs
+++ b/crates/compiler/src/unparse.rs
@@ -13,7 +13,7 @@
//
use moor_values::util::quote_str;
-use moor_values::var::Variant;
+use moor_values::{Var, Variant};
use crate::ast::{Expr, Stmt, StmtNode};
use crate::decompile::DecompileError;
@@ -109,13 +109,13 @@ impl<'a> Unparse<'a> {
}
}
- fn unparse_var(&self, var: &moor_values::var::Var, aggressive: bool) -> String {
+ fn unparse_var(&self, var: &moor_values::Var, aggressive: bool) -> String {
if !aggressive {
- return format!("{var}");
+ return to_literal(var);
}
if let Variant::Str(s) = var.variant() {
- let s = s.as_str();
+ let s = s.as_string();
// If the string contains anything that isn't alphanumeric and _, it's
// not a valid ident and needs to be quoted. Likewise if it begins with a non-alpha/underscore
@@ -123,12 +123,12 @@ impl<'a> Unparse<'a> {
|| (s.chars().next().unwrap().is_numeric() && !s.starts_with('_'));
if !needs_quotes {
- s.into()
+ s
} else {
- format!("({})", quote_str(s))
+ format!("({})", quote_str(&s))
}
} else {
- format!("{var}")
+ to_literal(var)
}
}
@@ -190,7 +190,7 @@ impl<'a> Unparse<'a> {
Expr::Unary(op, expr) => Ok(format!("{}{}", op, brace_if_lower(expr))),
Expr::Prop { location, property } => {
let location = match (&**location, &**property) {
- (Expr::Value(var), Expr::Value(_)) if var.is_root() => String::from("$"),
+ (Expr::Value(var), Expr::Value(_)) if var.is_sysobj() => String::from("$"),
_ => format!("{}.", brace_if_lower(location)),
};
let prop = match &**property {
@@ -205,7 +205,7 @@ impl<'a> Unparse<'a> {
args,
} => {
let location = match (&**location, &**verb) {
- (Expr::Value(var), Expr::Value(_)) if var.is_root() => String::from("$"),
+ (Expr::Value(var), Expr::Value(_)) if var.is_sysobj() => String::from("$"),
_ => format!("{}:", brace_if_lower(location)),
};
let verb = match &**verb {
@@ -727,6 +727,50 @@ pub fn annotate_line_numbers(start_line_no: usize, tree: &mut [Stmt]) -> usize {
line_no
}
+/// Utility function to produce a MOO literal from a Var/Variant.
+/// This is kept in `compiler` and not in `values` because it's specific to the MOO language, and
+/// other languages could have different representations.
+pub fn to_literal(v: &Var) -> String {
+ match v.variant() {
+ Variant::None => "None".to_string(),
+ Variant::Obj(oid) => {
+ format!("{}", oid)
+ }
+ Variant::Int(i) => i.to_string(),
+ Variant::Float(f) => {
+ format!("{f:?}")
+ }
+ Variant::List(l) => {
+ let mut result = String::new();
+ result.push('{');
+ for (i, v) in l.iter().enumerate() {
+ if i > 0 {
+ result.push_str(", ");
+ }
+ result.push_str(to_literal(&v).as_str());
+ }
+ result.push('}');
+ result
+ }
+ Variant::Str(s) => quote_str(&s.as_string()),
+ Variant::Map(m) => {
+ let mut result = String::new();
+ result.push('[');
+ for (i, (k, v)) in m.iter().enumerate() {
+ if i > 0 {
+ result.push_str(", ");
+ }
+ result.push_str(to_literal(&k).as_str());
+ result.push_str(" -> ");
+ result.push_str(to_literal(&v).as_str());
+ }
+ result.push(']');
+ result
+ }
+ Variant::Err(e) => e.name().to_string(),
+ }
+}
+
#[cfg(test)]
mod tests {
use super::*;
diff --git a/crates/console-host/Cargo.toml b/crates/console-host/Cargo.toml
index ecaa5482..005a57a2 100644
--- a/crates/console-host/Cargo.toml
+++ b/crates/console-host/Cargo.toml
@@ -12,6 +12,7 @@ rust-version.workspace = true
description = "A tool to connect to a local or remote moor daemon and interact with it via the TTY."
[dependencies]
+moor-compiler = { path = "../compiler" }
moor-values = { path = "../values" }
rpc-common = { path = "../rpc-common" }
rpc-sync-client = { path = "../rpc-sync-client" }
diff --git a/crates/console-host/src/main.rs b/crates/console-host/src/main.rs
index e2a7f9ad..7bcfefe2 100644
--- a/crates/console-host/src/main.rs
+++ b/crates/console-host/src/main.rs
@@ -20,19 +20,19 @@ use std::time::SystemTime;
use clap::Parser;
use clap_derive::Parser;
use color_eyre::owo_colors::OwoColorize;
-use moor_values::var::Objid;
-use rustyline::config::Configurer;
-use rustyline::error::ReadlineError;
-use rustyline::{ColorMode, DefaultEditor, ExternalPrinter};
-use tracing::{debug, error, info, trace, warn};
-use uuid::Uuid;
-
+use moor_compiler::to_literal;
+use moor_values::Objid;
use rpc_common::{
AuthToken, BroadcastEvent, ClientToken, ConnectionEvent, RpcRequest, RpcResponse, RpcResult,
BROADCAST_TOPIC,
};
use rpc_sync_client::RpcSendClient;
use rpc_sync_client::{broadcast_recv, events_recv};
+use rustyline::config::Configurer;
+use rustyline::error::ReadlineError;
+use rustyline::{ColorMode, DefaultEditor, ExternalPrinter};
+use tracing::{debug, error, info, trace, warn};
+use uuid::Uuid;
#[derive(Parser, Debug)]
struct Args {
@@ -249,14 +249,18 @@ fn console_loop(
}
match events_recv(client_id, &narr_sub_socket) {
Ok(ConnectionEvent::Narrative(_, msg)) => {
- printer
- .print(
- (match msg.event() {
- moor_values::tasks::Event::Notify(s, _content_type) => s,
- })
- .to_string(),
- )
- .unwrap();
+ let var = match msg.event() {
+ moor_values::tasks::Event::Notify(s, _content_type) => s,
+ };
+ match var.variant() {
+ moor_values::Variant::Str(s) => {
+ printer.print(s.as_string().to_string()).unwrap();
+ }
+ _ => {
+ let literal = to_literal(&var);
+ printer.print(format!("{}", literal.yellow())).unwrap();
+ }
+ }
}
Ok(ConnectionEvent::SystemMessage(o, msg)) => {
printer
diff --git a/crates/daemon/src/connections.rs b/crates/daemon/src/connections.rs
index d6323b30..07cc23f1 100644
--- a/crates/daemon/src/connections.rs
+++ b/crates/daemon/src/connections.rs
@@ -17,7 +17,7 @@ use std::time::{Duration, SystemTime};
use uuid::Uuid;
use moor_kernel::tasks::sessions::SessionError;
-use moor_values::var::Objid;
+use moor_values::Objid;
use rpc_common::RpcRequestError;
pub const CONNECTION_TIMEOUT_DURATION: Duration = Duration::from_secs(30);
diff --git a/crates/daemon/src/connections_rb.rs b/crates/daemon/src/connections_rb.rs
index a9bd0596..bcf1367c 100644
--- a/crates/daemon/src/connections_rb.rs
+++ b/crates/daemon/src/connections_rb.rs
@@ -27,8 +27,8 @@ use uuid::Uuid;
use bytes::Bytes;
use daumtils::SliceRef;
use moor_kernel::tasks::sessions::SessionError;
-use moor_values::var::Objid;
use moor_values::AsByteBuffer;
+use moor_values::Objid;
use relbox::{relation_info_for, RelBox, RelationId, RelationInfo, Transaction};
use rpc_common::RpcRequestError;
@@ -444,7 +444,7 @@ impl ConnectionsDB for ConnectionsRb {
mod tests {
use std::sync::Arc;
- use moor_values::var::Objid;
+ use moor_values::Objid;
use crate::connections::ConnectionsDB;
use crate::connections_rb::ConnectionsRb;
diff --git a/crates/daemon/src/connections_wt.rs b/crates/daemon/src/connections_wt.rs
index b05e056c..f697191e 100644
--- a/crates/daemon/src/connections_wt.rs
+++ b/crates/daemon/src/connections_wt.rs
@@ -31,7 +31,7 @@ use bytes::Bytes;
use moor_db_wiredtiger::{WiredTigerRelDb, WiredTigerRelTransaction, WiredTigerRelation};
use moor_kernel::tasks::sessions::SessionError;
use moor_values::model::{CommitResult, ValSet};
-use moor_values::var::Objid;
+use moor_values::Objid;
use moor_values::{AsByteBuffer, DecodingError, EncodingError};
use rpc_common::RpcRequestError;
@@ -484,7 +484,7 @@ impl ConnectionsDB for ConnectionsWT {
mod tests {
use std::sync::Arc;
- use moor_values::var::Objid;
+ use moor_values::Objid;
use crate::connections::ConnectionsDB;
use crate::connections_wt::ConnectionsWT;
diff --git a/crates/daemon/src/rpc_server.rs b/crates/daemon/src/rpc_server.rs
index e335b1d8..1d3382f3 100644
--- a/crates/daemon/src/rpc_server.rs
+++ b/crates/daemon/src/rpc_server.rs
@@ -31,11 +31,11 @@ use moor_kernel::SchedulerClient;
use moor_values::tasks::SchedulerError::CommandExecutionError;
use moor_values::tasks::{CommandError, NarrativeEvent, TaskId};
use moor_values::util::parse_into_words;
-use moor_values::var::Objid;
-use moor_values::var::Symbol;
-use moor_values::var::Variant;
-use moor_values::var::{v_objid, v_string};
+use moor_values::Objid;
+use moor_values::Symbol;
+use moor_values::Variant;
use moor_values::SYSTEM_OBJECT;
+use moor_values::{v_objid, v_string};
use rpc_common::RpcResponse::{LoginResult, NewConnection};
use rpc_common::{
AuthToken, BroadcastEvent, ClientToken, ConnectType, ConnectionEvent, RpcRequest,
diff --git a/crates/daemon/src/rpc_session.rs b/crates/daemon/src/rpc_session.rs
index 2029922f..4acd5eab 100644
--- a/crates/daemon/src/rpc_session.rs
+++ b/crates/daemon/src/rpc_session.rs
@@ -20,7 +20,7 @@ use uuid::Uuid;
use moor_kernel::tasks::sessions::{Session, SessionError};
use moor_values::tasks::NarrativeEvent;
-use moor_values::var::Objid;
+use moor_values::Objid;
use crate::rpc_server::RpcServer;
diff --git a/crates/db-wiredtiger/src/wtrel/rel_transaction.rs b/crates/db-wiredtiger/src/wtrel/rel_transaction.rs
index e08ce568..e2f94fc3 100644
--- a/crates/db-wiredtiger/src/wtrel/rel_transaction.rs
+++ b/crates/db-wiredtiger/src/wtrel/rel_transaction.rs
@@ -582,7 +582,7 @@ mod tests {
use moor_db::RelationalTransaction;
use moor_values::model::{ObjSet, ValSet};
- use moor_values::var::Objid;
+ use moor_values::Objid;
use TestRelation::{CompositeToOne, OneToOne, OneToOneSecondaryIndexed, Sequences};
use crate::wtrel::rel_db::WiredTigerRelDb;
diff --git a/crates/db-wiredtiger/third-party/wiredtiger b/crates/db-wiredtiger/third-party/wiredtiger
index 4b37cbe4..f8a6f387 160000
--- a/crates/db-wiredtiger/third-party/wiredtiger
+++ b/crates/db-wiredtiger/third-party/wiredtiger
@@ -1 +1 @@
-Subproject commit 4b37cbe4e3992389e0bfb903ba8ca88791f6e4ca
+Subproject commit f8a6f387e6753237f69463af8d2b7e66bf5aecc9
diff --git a/crates/db/src/db_loader_client.rs b/crates/db/src/db_loader_client.rs
index bc480a81..fcec48cd 100644
--- a/crates/db/src/db_loader_client.rs
+++ b/crates/db/src/db_loader_client.rs
@@ -25,9 +25,9 @@ use moor_values::model::{CommitResult, WorldStateError};
use moor_values::model::{HasUuid, PropPerms, ValSet};
use moor_values::model::{PropDef, PropDefs};
use moor_values::util::BitEnum;
-use moor_values::var::Objid;
-use moor_values::var::Symbol;
-use moor_values::var::Var;
+use moor_values::Objid;
+use moor_values::Symbol;
+use moor_values::Var;
use crate::db_worldstate::DbTxWorldState;
use crate::loader::LoaderInterface;
diff --git a/crates/db/src/db_worldstate.rs b/crates/db/src/db_worldstate.rs
index ca523921..256400d9 100644
--- a/crates/db/src/db_worldstate.rs
+++ b/crates/db/src/db_worldstate.rs
@@ -29,11 +29,11 @@ use moor_values::model::{PropAttrs, PropFlag};
use moor_values::model::{PropDef, PropDefs};
use moor_values::model::{VerbDef, VerbDefs};
use moor_values::util::BitEnum;
-use moor_values::var::Symbol;
-use moor_values::var::Variant;
-use moor_values::var::{v_int, v_objid, Var};
-use moor_values::var::{v_listv, Objid};
+use moor_values::Objid;
+use moor_values::Variant;
use moor_values::NOTHING;
+use moor_values::{v_int, v_objid, Var};
+use moor_values::{v_list, Symbol};
use crate::worldstate_transaction::WorldStateTransaction;
@@ -234,7 +234,7 @@ impl WorldState for DbTxWorldState {
return self.location_of(perms, obj).map(Var::from);
} else if pname == *CONTENTS_SYM {
let contents: Vec<_> = self.contents_of(perms, obj)?.iter().map(v_objid).collect();
- return Ok(v_listv(contents));
+ return Ok(v_list(&contents));
} else if pname == *OWNER_SYM {
return self.owner_of(obj).map(Var::from);
} else if pname == *PROGRAMMER_SYM {
@@ -355,7 +355,7 @@ impl WorldState for DbTxWorldState {
let Variant::Str(name) = value.variant() else {
return Err(WorldStateError::PropertyTypeMismatch);
};
- self.tx.set_object_name(obj, name.to_string())?;
+ self.tx.set_object_name(obj, name.as_string())?;
return Ok(());
}
@@ -750,7 +750,13 @@ impl WorldState for DbTxWorldState {
// Then grab aliases property.
let aliases = match self.retrieve_property(perms, obj, *ALIASES_SYM) {
Ok(a) => match a.variant() {
- Variant::List(a) => a.iter().map(|v| v.to_string()).collect(),
+ Variant::List(a) => a
+ .iter()
+ .map(|v| match v.variant() {
+ Variant::Str(s) => s.as_string(),
+ _ => "".to_string(),
+ })
+ .collect(),
_ => {
vec![]
}
diff --git a/crates/db/src/loader.rs b/crates/db/src/loader.rs
index 3cdee37a..d5d459da 100644
--- a/crates/db/src/loader.rs
+++ b/crates/db/src/loader.rs
@@ -24,8 +24,8 @@ use moor_values::model::{CommitResult, WorldStateError};
use moor_values::model::{ObjAttrs, PropPerms};
use moor_values::model::{PropDef, PropDefs};
use moor_values::util::BitEnum;
-use moor_values::var::Objid;
-use moor_values::var::Var;
+use moor_values::Objid;
+use moor_values::Var;
/// Interface exposed to be used by the textdump loader. Overlap of functionality with what
/// WorldState could provide, but potentially different constraints/semantics (e.g. no perms checks)
diff --git a/crates/db/src/relational_worldstate.rs b/crates/db/src/relational_worldstate.rs
index 234a9c83..9d830dcb 100644
--- a/crates/db/src/relational_worldstate.rs
+++ b/crates/db/src/relational_worldstate.rs
@@ -24,9 +24,9 @@ use moor_values::model::{
WorldStateError,
};
use moor_values::util::BitEnum;
-use moor_values::var::Symbol;
-use moor_values::var::{v_none, Objid, Var};
+use moor_values::Symbol;
use moor_values::NOTHING;
+use moor_values::{v_none, Objid, Var};
use std::collections::{HashMap, HashSet, VecDeque};
use uuid::Uuid;
diff --git a/crates/db/src/worldstate_tests.rs b/crates/db/src/worldstate_tests.rs
index a23947e5..6536f28e 100644
--- a/crates/db/src/worldstate_tests.rs
+++ b/crates/db/src/worldstate_tests.rs
@@ -23,10 +23,10 @@ use moor_values::model::{CommitResult, WorldStateError};
use moor_values::model::{HasUuid, Named};
use moor_values::model::{ObjAttrs, PropFlag, ValSet};
use moor_values::util::BitEnum;
-use moor_values::var::Objid;
-use moor_values::var::Symbol;
-use moor_values::var::{v_int, v_str};
+use moor_values::Objid;
+use moor_values::Symbol;
use moor_values::NOTHING;
+use moor_values::{v_int, v_str};
pub fn perform_test_create_object(begin_tx: F)
where
diff --git a/crates/db/src/worldstate_transaction.rs b/crates/db/src/worldstate_transaction.rs
index ebb5f910..15120711 100644
--- a/crates/db/src/worldstate_transaction.rs
+++ b/crates/db/src/worldstate_transaction.rs
@@ -24,9 +24,9 @@ use moor_values::model::{ObjSet, PropPerms};
use moor_values::model::{PropDef, PropDefs};
use moor_values::model::{VerbDef, VerbDefs};
use moor_values::util::BitEnum;
-use moor_values::var::Objid;
-use moor_values::var::Symbol;
-use moor_values::var::Var;
+use moor_values::Objid;
+use moor_values::Symbol;
+use moor_values::Var;
/// A trait defining a generic interface to a database for storing the per-attribute values
/// of our objects and their properties and verbs. Used by DbTxWorldState.
diff --git a/crates/kernel/benches/vm_benches.rs b/crates/kernel/benches/vm_benches.rs
index 0d223a7b..a91a306d 100644
--- a/crates/kernel/benches/vm_benches.rs
+++ b/crates/kernel/benches/vm_benches.rs
@@ -35,8 +35,8 @@ use moor_values::model::{BinaryType, VerbFlag};
use moor_values::model::{WorldState, WorldStateSource};
use moor_values::tasks::AbortLimitReason;
use moor_values::util::BitEnum;
-use moor_values::var::{List, Symbol};
-use moor_values::{AsByteBuffer, NOTHING, SYSTEM_OBJECT};
+use moor_values::{AsByteBuffer, Var, NOTHING, SYSTEM_OBJECT};
+use moor_values::Symbol;
fn create_worldstate() -> WiredTigerDB {
let (ws_source, _) = WiredTigerDB::open(None);
@@ -51,7 +51,7 @@ fn create_worldstate() -> WiredTigerDB {
pub fn prepare_call_verb(
world_state: &mut dyn WorldState,
verb_name: &str,
- args: List,
+ args: Vec,
max_ticks: usize,
) -> VmHost {
let mut vm_host = VmHost::new(0, 20, max_ticks, Duration::from_secs(15));
@@ -95,7 +95,7 @@ fn prepare_vm_execution(
BinaryType::LambdaMoo18X,
)
.unwrap();
- let vm_host = prepare_call_verb(tx.as_mut(), "test", List::new(), max_ticks);
+ let vm_host = prepare_call_verb(tx.as_mut(), "test", vec![], max_ticks);
assert_eq!(tx.commit().unwrap(), CommitResult::Success);
vm_host
}
diff --git a/crates/kernel/src/builtins/bf_list_sets.rs b/crates/kernel/src/builtins/bf_list_sets.rs
index 00bf9333..33a0901b 100644
--- a/crates/kernel/src/builtins/bf_list_sets.rs
+++ b/crates/kernel/src/builtins/bf_list_sets.rs
@@ -15,16 +15,16 @@
use std::ops::BitOr;
use moor_compiler::offset_for_builtin;
-use moor_values::var::Error::{E_ARGS, E_INVARG, E_TYPE};
-use moor_values::var::Variant;
-use moor_values::var::{v_empty_list, v_int, v_list, v_string};
-use moor_values::var::{v_listv, Error};
+use moor_values::Error::{E_ARGS, E_INVARG, E_TYPE};
+use moor_values::{
+ v_empty_list, v_int, v_list, v_list_iter, v_string, IndexMode, Sequence, VarType,
+};
+use moor_values::{Error, Variant};
use onig::{Region, SearchOptions, SyntaxOperator};
use crate::bf_declare;
use crate::builtins::BfRet::Ret;
use crate::builtins::{BfCallState, BfErr, BfRet, BuiltinFunction};
-use crate::vm::moo_execute::one_to_zero_index;
fn bf_is_member(bf_args: &mut BfCallState<'_>) -> Result {
if bf_args.args.len() != 2 {
@@ -35,7 +35,7 @@ fn bf_is_member(bf_args: &mut BfCallState<'_>) -> Result {
// is not *really* a correct place for it, but `bf_list_sets_and_maps_too_i_guess.rs` is a bit silly.
match container.variant() {
Variant::List(list) => {
- if list.contains_case_sensitive(value) {
+ if list.index_in(value, true).map_err(BfErr::Code)?.is_some() {
Ok(Ret(v_int(1)))
} else {
Ok(Ret(v_int(0)))
@@ -43,7 +43,7 @@ fn bf_is_member(bf_args: &mut BfCallState<'_>) -> Result {
}
Variant::Map(map) => Ok(Ret(v_int(
map.iter()
- .position(|(_item_key, item_value)| value.eq_case_sensitive(item_value))
+ .position(|(_item_key, item_value)| value.eq_case_sensitive(&item_value))
.map(|pos| pos + 1)
.unwrap_or(0) as i64,
))),
@@ -56,48 +56,38 @@ fn bf_listinsert(bf_args: &mut BfCallState<'_>) -> Result {
if bf_args.args.len() < 2 || bf_args.args.len() > 3 {
return Err(BfErr::Code(E_ARGS));
}
- let len = bf_args.args.len();
- let value = bf_args.args[1].clone();
- if len == 2 {
- let list = &mut bf_args.args[0];
- let Variant::List(list) = list.variant_mut() else {
- return Err(BfErr::Code(E_TYPE));
- };
- Ok(Ret(list.push(value)))
- } else {
- let index = bf_args.args[2].clone();
- let list = &mut bf_args.args[0];
- let Variant::List(list) = list.variant_mut() else {
- return Err(BfErr::Code(E_TYPE));
- };
- let index = match one_to_zero_index(&index) {
- Ok(i) => i,
- Err(e) => return Err(BfErr::Code(e)),
- };
- Ok(Ret(list.insert(index as isize, value)))
+ let value = &bf_args.args[1];
+ let list = &bf_args.args[0];
+ if list.type_code() != VarType::TYPE_LIST {
+ return Err(BfErr::Code(E_TYPE));
+ }
+ // If two args, treat as push. If three, treat as insert.
+ if bf_args.args.len() == 2 {
+ return Ok(Ret(list.push(value).map_err(BfErr::Code)?));
}
+ let index = &bf_args.args[2];
+ let res = list.insert(index, value, IndexMode::OneBased);
+ Ok(Ret(res.map_err(BfErr::Code)?))
}
+
bf_declare!(listinsert, bf_listinsert);
fn bf_listappend(bf_args: &mut BfCallState<'_>) -> Result {
if bf_args.args.len() < 2 || bf_args.args.len() > 3 {
return Err(BfErr::Code(E_ARGS));
}
- let value = bf_args.args[1].clone();
- let list = &mut bf_args.args[0];
- let Variant::List(mut list) = list.variant().clone() else {
+ let value = &bf_args.args[1];
+ let list = &bf_args.args[0];
+ if list.type_code() != VarType::TYPE_LIST {
return Err(BfErr::Code(E_TYPE));
- };
- let new_list = if bf_args.args.len() == 2 {
- list.push(value.clone())
- } else {
- let index = bf_args.args[2].variant();
- let Variant::Int(index) = index else {
- return Err(BfErr::Code(E_TYPE));
- };
- list.insert(*index as isize, value.clone())
- };
- Ok(Ret(new_list))
+ }
+ // If two args, treat as push. If three, treat as insert.
+ if bf_args.args.len() == 2 {
+ return Ok(Ret(list.push(value).map_err(BfErr::Code)?));
+ }
+ let index = &bf_args.args[2];
+ let res = list.insert(index, value, IndexMode::ZeroBased);
+ Ok(Ret(res.map_err(BfErr::Code)?))
}
bf_declare!(listappend, bf_listappend);
@@ -106,15 +96,10 @@ fn bf_listdelete(bf_args: &mut BfCallState<'_>) -> Result {
return Err(BfErr::Code(E_ARGS));
}
let index = bf_args.args[1].clone();
- let list = bf_args.args[0].variant_mut();
- let Variant::List(list) = list else {
- return Err(BfErr::Code(E_TYPE));
- };
- let index = match one_to_zero_index(&index) {
- Ok(i) => i,
- Err(e) => return Err(BfErr::Code(e)),
- };
- Ok(Ret(list.remove_at(index)))
+ let list = &bf_args.args[0];
+ Ok(Ret(list
+ .remove_at(&index, IndexMode::OneBased)
+ .map_err(BfErr::Code)?))
}
bf_declare!(listdelete, bf_listdelete);
@@ -125,14 +110,12 @@ fn bf_listset(bf_args: &mut BfCallState<'_>) -> Result {
let index = bf_args.args[2].clone();
let value = bf_args.args[1].clone();
let list = &mut bf_args.args[0];
- let Variant::List(ref mut list) = list.variant_mut() else {
+ if list.type_code() != VarType::TYPE_LIST {
return Err(BfErr::Code(E_TYPE));
- };
- let index = match one_to_zero_index(&index) {
- Ok(i) => i,
- Err(e) => return Err(BfErr::Code(e)),
- };
- Ok(Ret(list.set(index as usize, value.clone())))
+ }
+ Ok(Ret(list
+ .index_set(&index, &value, IndexMode::OneBased)
+ .map_err(BfErr::Code)?))
}
bf_declare!(listset, bf_listset);
@@ -142,13 +125,10 @@ fn bf_setadd(bf_args: &mut BfCallState<'_>) -> Result {
}
let value = bf_args.args[1].clone();
let list = &mut bf_args.args[0];
- let Variant::List(ref mut list) = list.variant_mut() else {
+ let Variant::List(list) = list.variant() else {
return Err(BfErr::Code(E_TYPE));
};
- if !list.contains(&value) {
- return Ok(Ret(list.push(value.clone())));
- }
- Ok(Ret(bf_args.args[0].clone()))
+ Ok(Ret(list.set_add(&value).map_err(BfErr::Code)?))
}
bf_declare!(setadd, bf_setadd);
@@ -157,11 +137,11 @@ fn bf_setremove(bf_args: &mut BfCallState<'_>) -> Result {
return Err(BfErr::Code(E_ARGS));
}
let value = bf_args.args[1].clone();
- let list = bf_args.args[0].variant_mut();
- let Variant::List(ref mut list) = list else {
+ let list = bf_args.args[0].variant();
+ let Variant::List(list) = list else {
return Err(BfErr::Code(E_TYPE));
};
- Ok(Ret(list.setremove(&value)))
+ Ok(Ret(list.set_remove(&value).map_err(BfErr::Code)?))
}
bf_declare!(setremove, bf_setremove);
@@ -290,18 +270,21 @@ fn do_re_match(bf_args: &mut BfCallState<'_>, reverse: bool) -> Result>(),
+ .map(|(start, end)| v_list(&[v_int(*start as i64), v_int(*end as i64)])),
);
Ok(Ret(v_list(&[
v_int(overall.0 as i64),
@@ -399,7 +382,7 @@ fn bf_substitute(bf_args: &mut BfCallState<'_>) -> Result {
return Err(BfErr::Code(E_INVARG));
}
- let (Some(a), Some(b)) = (subs.get(2), subs.get(3)) else {
+ let (Ok(a), Ok(b)) = (subs.index(2), subs.index(3)) else {
return Err(BfErr::Code(E_INVARG));
};
let (Variant::List(subs), Variant::Str(source)) = (a.variant(), b.variant()) else {
@@ -415,7 +398,7 @@ fn bf_substitute(bf_args: &mut BfCallState<'_>) -> Result {
if sub.len() != 2 {
return Err(BfErr::Code(E_INVARG));
}
- let (Some(start), Some(end)) = (sub.get(0), sub.get(1)) else {
+ let (Ok(start), Ok(end)) = (sub.index(0), sub.index(1)) else {
return Err(BfErr::Code(E_INVARG));
};
let (Variant::Int(start), Variant::Int(end)) = (start.variant(), end.variant()) else {
@@ -424,7 +407,7 @@ fn bf_substitute(bf_args: &mut BfCallState<'_>) -> Result {
mysubs.push((*start as isize, *end as isize));
}
- match substitute(template.as_str(), &mysubs, source.as_str()) {
+ match substitute(&template.as_string(), &mysubs, &source.as_string()) {
Ok(r) => Ok(Ret(v_string(r))),
Err(e) => Err(BfErr::Code(e)),
}
diff --git a/crates/kernel/src/builtins/bf_maps.rs b/crates/kernel/src/builtins/bf_maps.rs
index 632bdc4f..36f76b66 100644
--- a/crates/kernel/src/builtins/bf_maps.rs
+++ b/crates/kernel/src/builtins/bf_maps.rs
@@ -15,9 +15,9 @@
use crate::bf_declare;
use crate::builtins::{BfCallState, BfErr, BfRet, BuiltinFunction};
use moor_compiler::offset_for_builtin;
-use moor_values::var::Error::{E_ARGS, E_RANGE, E_TYPE};
-use moor_values::var::{v_bool, v_listv, Var, Variant};
-
+use moor_values::Associative;
+use moor_values::Error::{E_ARGS, E_RANGE, E_TYPE};
+use moor_values::{v_bool, v_list, Var, Variant};
/// Returns a copy of map with the value corresponding to key removed. If key is not a valid key, then E_RANGE is raised.
fn bf_mapdelete(bf_args: &mut BfCallState<'_>) -> Result {
if bf_args.args.len() != 2 {
@@ -35,7 +35,7 @@ fn bf_mapdelete(bf_args: &mut BfCallState<'_>) -> Result {
return Err(BfErr::Code(E_TYPE));
}
- let (nm, Some(_)) = m.remove(&bf_args.args[1]) else {
+ let (nm, Some(_)) = m.remove(&bf_args.args[1], false) else {
return Err(BfErr::Code(E_RANGE));
};
@@ -54,7 +54,7 @@ fn bf_mapkeys(bf_args: &mut BfCallState<'_>) -> Result {
let keys: Vec = m.iter().map(|kv| kv.0.clone()).collect();
- Ok(BfRet::Ret(v_listv(keys)))
+ Ok(BfRet::Ret(v_list(&keys)))
}
bf_declare!(mapkeys, bf_mapkeys);
@@ -69,7 +69,7 @@ fn bf_mapvalues(bf_args: &mut BfCallState<'_>) -> Result {
let values: Vec = m.iter().map(|kv| kv.1.clone()).collect();
- Ok(BfRet::Ret(v_listv(values)))
+ Ok(BfRet::Ret(v_list(&values)))
}
bf_declare!(mapvalues, bf_mapvalues);
@@ -89,9 +89,10 @@ fn bf_maphaskey(bf_args: &mut BfCallState<'_>) -> Result {
return Err(BfErr::Code(E_TYPE));
}
- let v = m.get(&bf_args.args[1]);
-
- Ok(BfRet::Ret(v_bool(v.is_some())))
+ let contains = m
+ .contains_key(&bf_args.args[1], false)
+ .map_err(BfErr::Code)?;
+ Ok(BfRet::Ret(v_bool(contains)))
}
bf_declare!(maphaskey, bf_maphaskey);
diff --git a/crates/kernel/src/builtins/bf_num.rs b/crates/kernel/src/builtins/bf_num.rs
index 1adab5be..5f3ddb78 100644
--- a/crates/kernel/src/builtins/bf_num.rs
+++ b/crates/kernel/src/builtins/bf_num.rs
@@ -16,9 +16,9 @@ use decorum::R64;
use rand::Rng;
use moor_compiler::offset_for_builtin;
-use moor_values::var::Error::{E_ARGS, E_INVARG, E_TYPE};
-use moor_values::var::Variant;
-use moor_values::var::{v_float, v_int, v_str};
+use moor_values::Error::{E_ARGS, E_INVARG, E_TYPE};
+use moor_values::Variant;
+use moor_values::{v_float, v_int, v_str};
use crate::bf_declare;
use crate::builtins::BfRet::Ret;
diff --git a/crates/kernel/src/builtins/bf_objects.rs b/crates/kernel/src/builtins/bf_objects.rs
index 73b53bca..e7d3eb6f 100644
--- a/crates/kernel/src/builtins/bf_objects.rs
+++ b/crates/kernel/src/builtins/bf_objects.rs
@@ -20,12 +20,11 @@ use moor_values::model::Named;
use moor_values::model::WorldStateError;
use moor_values::model::{ObjFlag, ValSet};
use moor_values::util::BitEnum;
-use moor_values::var::v_listv;
-use moor_values::var::Error::{E_ARGS, E_INVARG, E_NACC, E_PERM, E_TYPE};
-use moor_values::var::Symbol;
-use moor_values::var::{v_bool, v_int, v_none, v_objid, v_str};
-use moor_values::var::{List, Variant};
-use moor_values::NOTHING;
+use moor_values::Error::{E_ARGS, E_INVARG, E_NACC, E_PERM, E_TYPE};
+use moor_values::{v_bool, v_int, v_none, v_objid, v_str};
+use moor_values::{v_list, Sequence, Symbol};
+use moor_values::{v_list_iter, NOTHING};
+use moor_values::Variant;
use crate::bf_declare;
use crate::builtins::BfRet::{Ret, VmInstr};
@@ -109,7 +108,7 @@ fn bf_children(bf_args: &mut BfCallState<'_>) -> Result {
.map_err(world_state_bf_err)?;
let children = children.iter().map(v_objid).collect::>();
- Ok(Ret(v_listv(children)))
+ Ok(Ret(v_list(&children)))
}
bf_declare!(children, bf_children);
@@ -170,7 +169,7 @@ fn bf_create(bf_args: &mut BfCallState<'_>) -> Result {
location: new_obj,
this: new_obj,
player: bf_args.exec_state.top().player,
- args: List::new(),
+ args: vec![],
argstr: "".to_string(),
caller: bf_args.exec_state.top().this,
},
@@ -261,7 +260,7 @@ fn bf_recycle(bf_args: &mut BfCallState<'_>) -> Result {
}
}
}
- let contents = v_listv(contents);
+ let contents = v_list(&contents);
match bf_args.world_state.find_method_verb_on(
bf_args.task_perms_who(),
obj,
@@ -280,7 +279,7 @@ fn bf_recycle(bf_args: &mut BfCallState<'_>) -> Result {
location: obj,
this: obj,
player: bf_args.exec_state.top().player,
- args: List::new(),
+ args: Vec::new(),
argstr: "".to_string(),
caller: bf_args.exec_state.top().this,
},
@@ -311,14 +310,14 @@ fn bf_recycle(bf_args: &mut BfCallState<'_>) -> Result {
panic!("Invalid trampoline argument for bf_recycle");
};
'inner: loop {
- debug!(?obj, contents = ?contents, "Calling :exitfunc for objects contents");
if contents.is_empty() {
let bf_frame = bf_args.bf_frame_mut();
bf_frame.bf_trampoline_arg = None;
bf_frame.bf_trampoline = Some(BF_RECYCLE_TRAMPOLINE_DONE_MOVE);
continue 'outer;
}
- let (head_obj, contents) = contents.pop_front();
+ let (head_obj, contents) =
+ contents.pop_front().map_err(|_| BfErr::Code(E_INVARG))?;
let Variant::Obj(head_obj) = head_obj.variant() else {
panic!("Invalid trampoline argument for bf_recycle");
};
@@ -348,7 +347,7 @@ fn bf_recycle(bf_args: &mut BfCallState<'_>) -> Result {
location: *head_obj,
this: *head_obj,
player: bf_args.exec_state.top().player,
- args: List::from_slice(&[v_objid(obj)]),
+ args: vec![v_objid(obj)],
argstr: "".to_string(),
caller: bf_args.exec_state.top().this,
},
@@ -449,7 +448,7 @@ fn bf_move(bf_args: &mut BfCallState<'_>) -> Result {
location: whereto,
this: whereto,
player: bf_args.exec_state.top().player,
- args: List::from_slice(&[v_objid(what)]),
+ args: vec![v_objid(what)],
argstr: "".to_string(),
caller: bf_args.exec_state.top().this,
},
@@ -526,7 +525,7 @@ fn bf_move(bf_args: &mut BfCallState<'_>) -> Result {
location: original_location,
this: original_location,
player: bf_args.exec_state.top().player,
- args: List::from_slice(&[v_objid(what)]),
+ args: vec![v_objid(what)],
argstr: "".to_string(),
caller: bf_args.exec_state.top().this,
},
@@ -572,7 +571,7 @@ fn bf_move(bf_args: &mut BfCallState<'_>) -> Result {
location: whereto,
this: whereto,
player: bf_args.exec_state.top().player,
- args: List::from_slice(&[v_objid(what)]),
+ args: vec![v_objid(what)],
argstr: "".to_string(),
caller: bf_args.exec_state.top().this,
},
@@ -620,7 +619,7 @@ fn bf_verbs(bf_args: &mut BfCallState<'_>) -> Result {
.iter()
.map(|v| v_str(v.names().first().unwrap()))
.collect();
- Ok(Ret(v_listv(verbs)))
+ Ok(Ret(v_list(&verbs)))
}
bf_declare!(verbs, bf_verbs);
@@ -640,7 +639,7 @@ fn bf_properties(bf_args: &mut BfCallState<'_>) -> Result {
.properties(bf_args.task_perms_who(), *obj)
.map_err(world_state_bf_err)?;
let props: Vec<_> = props.iter().map(|p| v_str(p.name())).collect();
- Ok(Ret(v_listv(props)))
+ Ok(Ret(v_list(&props)))
}
bf_declare!(properties, bf_properties);
@@ -696,9 +695,7 @@ fn bf_players(bf_args: &mut BfCallState<'_>) -> Result {
}
let players = bf_args.world_state.players().map_err(world_state_bf_err)?;
- Ok(Ret(v_listv(
- players.iter().map(v_objid).collect::>(),
- )))
+ Ok(Ret(v_list_iter(players.iter().map(v_objid))))
}
bf_declare!(players, bf_players);
diff --git a/crates/kernel/src/builtins/bf_properties.rs b/crates/kernel/src/builtins/bf_properties.rs
index f4ca3752..cad2c3c2 100644
--- a/crates/kernel/src/builtins/bf_properties.rs
+++ b/crates/kernel/src/builtins/bf_properties.rs
@@ -15,11 +15,11 @@
use moor_compiler::offset_for_builtin;
use moor_values::model::{PropAttrs, PropFlag};
use moor_values::util::BitEnum;
-use moor_values::var::Error::{E_ARGS, E_INVARG, E_TYPE};
-use moor_values::var::Symbol;
-use moor_values::var::Variant;
-use moor_values::var::{v_bool, v_list, v_none, v_objid, v_string};
-use moor_values::var::{v_empty_list, List};
+use moor_values::Error::{E_ARGS, E_INVARG, E_TYPE};
+use moor_values::Variant;
+use moor_values::{v_bool, v_list, v_none, v_objid, v_string};
+use moor_values::{v_empty_list, List};
+use moor_values::{Sequence, Symbol};
use crate::bf_declare;
use crate::builtins::BfErr::Code;
@@ -43,7 +43,7 @@ fn bf_property_info(bf_args: &mut BfCallState<'_>) -> Result {
.get_property_info(
bf_args.task_perms_who(),
*obj,
- Symbol::mk_case_insensitive(prop_name.as_str()),
+ Symbol::mk_case_insensitive(&prop_name.as_string()),
)
.map_err(world_state_bf_err)?;
let owner = perms.owner();
@@ -66,7 +66,7 @@ fn bf_property_info(bf_args: &mut BfCallState<'_>) -> Result {
bf_declare!(property_info, bf_property_info);
enum InfoParseResult {
- Fail(moor_values::var::Error),
+ Fail(moor_values::Error),
Success(PropAttrs),
}
@@ -75,26 +75,26 @@ fn info_to_prop_attrs(info: &List) -> InfoParseResult {
return InfoParseResult::Fail(E_ARGS);
}
- let owner = info.get(0).unwrap();
+ let owner = info.index(0).unwrap();
let Variant::Obj(owner) = owner.variant() else {
return InfoParseResult::Fail(E_TYPE);
};
- let perms = info.get(1).unwrap();
+ let perms = info.index(1).unwrap();
let Variant::Str(perms) = perms.variant() else {
return InfoParseResult::Fail(E_TYPE);
};
let name = if info.len() == 3 {
- let name = info.get(2).unwrap();
+ let name = info.index(2).unwrap();
let Variant::Str(name) = name.variant() else {
return InfoParseResult::Fail(E_TYPE);
};
- Some(name.to_string())
+ Some(name.as_string())
} else {
None
};
let mut flags = BitEnum::new();
- for c in perms.as_str().chars() {
+ for c in perms.as_string().chars() {
match c {
'r' => flags |= PropFlag::Read,
'w' => flags |= PropFlag::Write,
@@ -138,7 +138,7 @@ fn bf_set_property_info(bf_args: &mut BfCallState<'_>) -> Result {
.set_property_info(
bf_args.task_perms_who(),
*obj,
- Symbol::mk_case_insensitive(prop_name.as_str()),
+ Symbol::mk_case_insensitive(prop_name.as_string().as_str()),
attrs,
)
.map_err(world_state_bf_err)?;
@@ -161,7 +161,7 @@ fn bf_is_clear_property(bf_args: &mut BfCallState<'_>) -> Result {
.is_property_clear(
bf_args.task_perms_who(),
*obj,
- Symbol::mk_case_insensitive(prop_name.as_str()),
+ Symbol::mk_case_insensitive(prop_name.as_string().as_str()),
)
.map_err(world_state_bf_err)?;
Ok(Ret(v_bool(is_clear)))
@@ -183,7 +183,7 @@ fn bf_clear_property(bf_args: &mut BfCallState<'_>) -> Result {
.clear_property(
bf_args.task_perms_who(),
*obj,
- Symbol::mk_case_insensitive(prop_name.as_str()),
+ Symbol::mk_case_insensitive(prop_name.as_string().as_str()),
)
.map_err(world_state_bf_err)?;
Ok(Ret(v_empty_list()))
@@ -218,7 +218,7 @@ fn bf_add_property(bf_args: &mut BfCallState<'_>) -> Result {
bf_args.task_perms_who(),
*location,
*location,
- Symbol::mk_case_insensitive(name.as_str()),
+ Symbol::mk_case_insensitive(name.as_string().as_str()),
attrs.owner.unwrap(),
attrs.flags.unwrap(),
Some(value),
@@ -243,7 +243,7 @@ fn bf_delete_property(bf_args: &mut BfCallState<'_>) -> Result {
.delete_property(
bf_args.task_perms_who(),
*obj,
- Symbol::mk_case_insensitive(prop_name.as_str()),
+ Symbol::mk_case_insensitive(prop_name.as_string().as_str()),
)
.map_err(world_state_bf_err)?;
Ok(Ret(v_empty_list()))
diff --git a/crates/kernel/src/builtins/bf_server.rs b/crates/kernel/src/builtins/bf_server.rs
index f528591a..ee723860 100644
--- a/crates/kernel/src/builtins/bf_server.rs
+++ b/crates/kernel/src/builtins/bf_server.rs
@@ -24,18 +24,18 @@ use moor_compiler::compile;
use moor_compiler::{offset_for_builtin, ArgCount, ArgType, Builtin, BUILTINS};
use moor_values::model::{ObjFlag, WorldStateError};
use moor_values::tasks::NarrativeEvent;
-use moor_values::var::Error::{E_ARGS, E_INVARG, E_INVIND, E_PERM, E_TYPE};
-use moor_values::var::Symbol;
-use moor_values::var::Variant;
-use moor_values::var::{v_bool, v_int, v_list, v_none, v_objid, v_str, v_string, Var};
-use moor_values::var::{v_listv, Error};
+use moor_values::Error::{E_ARGS, E_INVARG, E_INVIND, E_PERM, E_TYPE};
+use moor_values::Symbol;
+use moor_values::Variant;
+use moor_values::{v_bool, v_int, v_list, v_none, v_objid, v_str, v_string, Var};
+use moor_values::{v_list_iter, Error};
use crate::bf_declare;
use crate::builtins::BfRet::{Ret, VmInstr};
use crate::builtins::{world_state_bf_err, BfCallState, BfErr, BfRet, BuiltinFunction};
use crate::vm::ExecutionResult;
use moor_values::tasks::TaskId;
-use moor_values::var::VarType::TYPE_STR;
+use moor_values::VarType::TYPE_STR;
fn bf_noop(bf_args: &mut BfCallState<'_>) -> Result {
error!(
@@ -57,7 +57,7 @@ fn bf_notify(bf_args: &mut BfCallState<'_>) -> Result {
if bf_args.args.len() != 2 {
return Err(BfErr::Code(E_ARGS));
}
- if bf_args.args[1].type_id() != TYPE_STR {
+ if bf_args.args[1].type_code() != TYPE_STR {
return Err(BfErr::Code(E_TYPE));
}
}
@@ -82,7 +82,9 @@ fn bf_notify(bf_args: &mut BfCallState<'_>) -> Result {
let Variant::Str(content_type) = bf_args.args[2].variant() else {
return Err(BfErr::Code(E_TYPE));
};
- Some(Symbol::mk_case_insensitive(content_type.as_str()))
+ Some(Symbol::mk_case_insensitive(
+ content_type.as_string().as_str(),
+ ))
} else {
None
};
@@ -103,14 +105,13 @@ fn bf_connected_players(bf_args: &mut BfCallState<'_>) -> Result {
return Err(BfErr::Code(E_ARGS));
}
- Ok(Ret(v_listv(
+ Ok(Ret(v_list_iter(
bf_args
.session
.connected_players()
.unwrap()
.iter()
- .map(|p| v_objid(*p))
- .collect::>(),
+ .map(|p| v_objid(*p)),
)))
}
bf_declare!(connected_players, bf_connected_players);
@@ -168,28 +169,23 @@ fn bf_callers(bf_args: &mut BfCallState<'_>) -> Result {
// We have to exempt ourselves from the callers list.
let callers = bf_args.exec_state.callers()[1..].to_vec();
- Ok(Ret(v_listv(
- callers
- .iter()
- .map(|c| {
- let callers = vec![
- // this
- v_objid(c.this),
- // verb name
- v_string(c.verb_name.to_string()),
- // 'programmer'
- v_objid(c.programmer),
- // verb location
- v_objid(c.definer),
- // player
- v_objid(c.player),
- // line number
- v_int(c.line_number as i64),
- ];
- v_listv(callers)
- })
- .collect::>(),
- )))
+ Ok(Ret(v_list_iter(callers.iter().map(|c| {
+ let callers = vec![
+ // this
+ v_objid(c.this),
+ // verb name
+ v_string(c.verb_name.to_string()),
+ // 'programmer'
+ v_objid(c.programmer),
+ // verb location
+ v_objid(c.definer),
+ // player
+ v_objid(c.player),
+ // line number
+ v_int(c.line_number as i64),
+ ];
+ v_list(&callers)
+ }))))
}
bf_declare!(callers, bf_callers);
@@ -277,7 +273,7 @@ fn bf_shutdown(bf_args: &mut BfCallState<'_>) -> Result {
let Variant::Str(msg) = bf_args.args[0].variant() else {
return Err(BfErr::Code(E_TYPE));
};
- Some(msg.as_str().to_string())
+ Some(msg.as_string())
};
bf_args
@@ -354,7 +350,7 @@ fn bf_raise(bf_args: &mut BfCallState<'_>) -> Result {
let Variant::Str(msg) = bf_args.args[1].variant() else {
return Err(BfErr::Code(E_TYPE));
};
- Some(msg.to_string())
+ Some(msg.as_string())
} else {
None
};
@@ -449,31 +445,28 @@ fn bf_queued_tasks(bf_args: &mut BfCallState<'_>) -> Result {
// return in form:
// {, , , ,
// , , , , }
- let tasks: Vec<_> = tasks
- .iter()
- .map(|task| {
- let task_id = v_int(task.task_id as i64);
- let start_time = match task.start_time {
- None => v_none(),
- Some(start_time) => {
- let time = start_time.duration_since(SystemTime::UNIX_EPOCH).unwrap();
- v_int(time.as_secs() as i64)
- }
- };
- let x = v_none();
- let y = v_none();
- let programmer = v_objid(task.permissions);
- let verb_loc = v_objid(task.verb_definer);
- let verb_name = v_str(task.verb_name.as_str());
- let line = v_int(task.line_number as i64);
- let this = v_objid(task.this);
- v_list(&[
- task_id, start_time, x, y, programmer, verb_loc, verb_name, line, this,
- ])
- })
- .collect();
-
- Ok(Ret(v_listv(tasks)))
+ let tasks = tasks.iter().map(|task| {
+ let task_id = v_int(task.task_id as i64);
+ let start_time = match task.start_time {
+ None => v_none(),
+ Some(start_time) => {
+ let time = start_time.duration_since(SystemTime::UNIX_EPOCH).unwrap();
+ v_int(time.as_secs() as i64)
+ }
+ };
+ let x = v_none();
+ let y = v_none();
+ let programmer = v_objid(task.permissions);
+ let verb_loc = v_objid(task.verb_definer);
+ let verb_name = v_str(task.verb_name.as_str());
+ let line = v_int(task.line_number as i64);
+ let this = v_objid(task.this);
+ v_list(&[
+ task_id, start_time, x, y, programmer, verb_loc, verb_name, line, this,
+ ])
+ });
+
+ Ok(Ret(v_list_iter(tasks)))
}
bf_declare!(queued_tasks, bf_queued_tasks);
@@ -617,7 +610,7 @@ fn bf_call_function(bf_args: &mut BfCallState<'_>) -> Result {
let args = &bf_args.args[1..];
// Find the function id for the given function name.
- let func_name = Symbol::mk_case_insensitive(func_name.as_str());
+ let func_name = Symbol::mk_case_insensitive(func_name.as_string().as_str());
let builtin = BUILTINS
.find_builtin(func_name)
.ok_or(BfErr::Code(E_ARGS))?;
@@ -690,22 +683,16 @@ fn bf_function_info_to_list(bf: &Builtin) -> Var {
ArgCount::Q(q) => v_int(q as i64),
ArgCount::U => v_int(-1),
};
- let types = bf
- .types
- .iter()
- .map(|t| match t {
- ArgType::Typed(ty) => v_int(*ty as i64),
- ArgType::Any => v_int(-1),
- ArgType::AnyNum => v_int(-2),
- })
- .collect::>();
-
- v_listv(vec![
- v_str(bf.name.as_str()),
+ let types = bf.types.iter().map(|t| match t {
+ ArgType::Typed(ty) => v_int(*ty as i64),
+ ArgType::Any => v_int(-1),
+ ArgType::AnyNum => v_int(-2),
+ });
+
+ v_list(&[v_str(bf.name.as_str()),
min_args,
max_args,
- v_listv(types),
- ])
+ v_list_iter(types)])
}
fn bf_function_info(bf_args: &mut BfCallState<'_>) -> Result {
@@ -717,7 +704,7 @@ fn bf_function_info(bf_args: &mut BfCallState<'_>) -> Result {
let Variant::Str(func_name) = bf_args.args[0].variant() else {
return Err(BfErr::Code(E_TYPE));
};
- let func_name = Symbol::mk_case_insensitive(func_name.as_str());
+ let func_name = Symbol::mk_case_insensitive(&func_name.as_string());
let bf = BUILTINS
.find_builtin(func_name)
.ok_or(BfErr::Code(E_ARGS))?;
@@ -728,12 +715,11 @@ fn bf_function_info(bf_args: &mut BfCallState<'_>) -> Result {
return Ok(Ret(desc));
}
- let bf_list: Vec<_> = BUILTINS
+ let bf_list = BUILTINS
.descriptions()
.filter(|&bf| bf.implemented)
- .map(bf_function_info_to_list)
- .collect();
- Ok(Ret(v_listv(bf_list)))
+ .map(bf_function_info_to_list);
+ Ok(Ret(v_list_iter(bf_list)))
}
bf_declare!(function_info, bf_function_info);
@@ -776,10 +762,10 @@ fn bf_eval(bf_args: &mut BfCallState<'_>) -> Result {
match tramp {
BF_SERVER_EVAL_TRAMPOLINE_START_INITIALIZE => {
- let program_code = program_code.as_str();
- let program = match compile(program_code, bf_args.config.compile_options()) {
+ let program_code = program_code.as_string();
+ let program = match compile(&program_code, bf_args.config.compile_options()) {
Ok(program) => program,
- Err(e) => return Ok(Ret(v_listv(vec![v_int(0), v_string(e.to_string())]))),
+ Err(e) => return Ok(Ret(v_list(&[v_int(0), v_string(e.to_string())]))),
};
let bf_frame = bf_args.bf_frame_mut();
bf_frame.bf_trampoline = Some(BF_SERVER_EVAL_TRAMPOLINE_RESUME);
@@ -794,7 +780,7 @@ fn bf_eval(bf_args: &mut BfCallState<'_>) -> Result {
BF_SERVER_EVAL_TRAMPOLINE_RESUME => {
// Value must be on in our activation's "return value"
let value = bf_args.exec_state.top().frame.return_value();
- Ok(Ret(v_listv(vec![v_bool(true), value])))
+ Ok(Ret(v_list(&[v_bool(true), value])))
}
_ => {
panic!("Invalid trampoline value for bf_eval: {}", tramp);
diff --git a/crates/kernel/src/builtins/bf_strings.rs b/crates/kernel/src/builtins/bf_strings.rs
index 8a3ae962..865adef4 100644
--- a/crates/kernel/src/builtins/bf_strings.rs
+++ b/crates/kernel/src/builtins/bf_strings.rs
@@ -17,9 +17,9 @@ use rand::distributions::Alphanumeric;
use rand::Rng;
use moor_compiler::offset_for_builtin;
-use moor_values::var::Error::{E_ARGS, E_INVARG, E_TYPE};
-use moor_values::var::Variant;
-use moor_values::var::{v_int, v_str, v_string};
+use moor_values::Error::{E_ARGS, E_INVARG, E_TYPE};
+use moor_values::Variant;
+use moor_values::{v_int, v_str, v_string};
use crate::bf_declare;
use crate::builtins::BfRet::Ret;
@@ -68,7 +68,13 @@ fn bf_strsub(bf_args: &mut BfCallState<'_>) -> Result {
);
match (subject, what, with) {
(Variant::Str(subject), Variant::Str(what), Variant::Str(with)) => Ok(Ret(v_str(
- strsub(subject.as_str(), what.as_str(), with.as_str(), case_matters).as_str(),
+ strsub(
+ subject.as_string().as_str(),
+ what.as_string().as_str(),
+ with.as_string().as_str(),
+ case_matters,
+ )
+ .as_str(),
))),
_ => Err(BfErr::Code(E_TYPE)),
}
@@ -114,8 +120,8 @@ fn bf_index(bf_args: &mut BfCallState<'_>) -> Result {
let (subject, what) = (bf_args.args[0].variant(), bf_args.args[1].variant());
match (subject, what) {
(Variant::Str(subject), Variant::Str(what)) => Ok(Ret(v_int(str_index(
- subject.as_str(),
- what.as_str(),
+ subject.as_string().as_str(),
+ what.as_string().as_str(),
case_matters,
)))),
_ => Err(BfErr::Code(E_TYPE)),
@@ -138,8 +144,8 @@ fn bf_rindex(bf_args: &mut BfCallState<'_>) -> Result {
let (subject, what) = (bf_args.args[0].variant(), bf_args.args[1].variant());
match (subject, what) {
(Variant::Str(subject), Variant::Str(what)) => Ok(Ret(v_int(str_rindex(
- subject.as_str(),
- what.as_str(),
+ subject.as_string().as_str(),
+ what.as_string().as_str(),
case_matters,
)))),
_ => Err(BfErr::Code(E_TYPE)),
@@ -153,9 +159,9 @@ fn bf_strcmp(bf_args: &mut BfCallState<'_>) -> Result {
}
let (str1, str2) = (bf_args.args[0].variant(), bf_args.args[1].variant());
match (str1, str2) {
- (Variant::Str(str1), Variant::Str(str2)) => {
- Ok(Ret(v_int(str1.as_str().cmp(str2.as_str()) as i64)))
- }
+ (Variant::Str(str1), Variant::Str(str2)) => Ok(Ret(v_int(
+ str1.as_string().as_str().cmp(str2.as_string().as_str()) as i64,
+ ))),
_ => Err(BfErr::Code(E_TYPE)),
}
}
@@ -187,10 +193,10 @@ fn bf_crypt(bf_args: &mut BfCallState<'_>) -> Result {
let Variant::Str(salt) = bf_args.args[1].variant() else {
return Err(BfErr::Code(E_TYPE));
};
- String::from(salt.as_str())
+ String::from(salt.as_string().as_str())
};
if let Variant::Str(text) = bf_args.args[0].variant() {
- let crypted = pwhash::unix::crypt(text.as_str(), salt.as_str()).unwrap();
+ let crypted = pwhash::unix::crypt(text.as_string().as_str(), salt.as_str()).unwrap();
Ok(Ret(v_string(crypted)))
} else {
Err(BfErr::Code(E_TYPE))
@@ -204,7 +210,7 @@ fn bf_string_hash(bf_args: &mut BfCallState<'_>) -> Result {
}
match bf_args.args[0].variant() {
Variant::Str(s) => {
- let hash_digest = md5::Md5::digest(s.as_str().as_bytes());
+ let hash_digest = md5::Md5::digest(s.as_string().as_bytes());
Ok(Ret(v_str(
format!("{:x}", hash_digest).to_uppercase().as_str(),
)))
diff --git a/crates/kernel/src/builtins/bf_values.rs b/crates/kernel/src/builtins/bf_values.rs
index a2eb5511..1e68acde 100644
--- a/crates/kernel/src/builtins/bf_values.rs
+++ b/crates/kernel/src/builtins/bf_values.rs
@@ -13,19 +13,20 @@
//
use md5::Digest;
-use moor_compiler::offset_for_builtin;
-use moor_values::var::Error::{E_ARGS, E_INVARG, E_TYPE};
-use moor_values::var::Variant;
-use moor_values::var::{v_bool, v_float, v_int, v_obj, v_str};
-use moor_values::AsByteBuffer;
+use moor_compiler::{offset_for_builtin, to_literal};
+use moor_values::Error::{E_ARGS, E_INVARG, E_TYPE};
+use moor_values::Variant;
+use moor_values::{v_bool, v_float, v_int, v_obj, v_str};
+use moor_values::{AsByteBuffer, Sequence};
use crate::bf_declare;
use crate::builtins::BfRet::Ret;
use crate::builtins::{world_state_bf_err, BfCallState, BfErr, BfRet, BuiltinFunction};
+use moor_values::Associative;
fn bf_typeof(bf_args: &mut BfCallState<'_>) -> Result {
let arg = &bf_args.args[0];
- Ok(Ret(v_int(arg.type_id() as i64)))
+ Ok(Ret(v_int(arg.type_code() as i64)))
}
bf_declare!(typeof, bf_typeof);
@@ -36,7 +37,7 @@ fn bf_tostr(bf_args: &mut BfCallState<'_>) -> Result {
Variant::None => result.push_str("None"),
Variant::Int(i) => result.push_str(&i.to_string()),
Variant::Float(f) => result.push_str(format!("{:?}", f).as_str()),
- Variant::Str(s) => result.push_str(s.as_str()),
+ Variant::Str(s) => result.push_str(s.as_string().as_str()),
Variant::Obj(o) => result.push_str(&o.to_string()),
Variant::List(_) => result.push_str("{list}"),
Variant::Map(_) => result.push_str("[map]"),
@@ -51,7 +52,7 @@ fn bf_toliteral(bf_args: &mut BfCallState<'_>) -> Result {
if bf_args.args.len() != 1 {
return Err(BfErr::Code(E_ARGS));
}
- let literal = bf_args.args[0].to_literal();
+ let literal = to_literal(&bf_args.args[0]);
Ok(Ret(v_str(literal.as_str())))
}
bf_declare!(toliteral, bf_toliteral);
@@ -65,7 +66,7 @@ fn bf_toint(bf_args: &mut BfCallState<'_>) -> Result {
Variant::Float(f) => Ok(Ret(v_int(*f as i64))),
Variant::Obj(o) => Ok(Ret(v_int(o.0))),
Variant::Str(s) => {
- let i = s.as_str().parse::();
+ let i = s.as_string().as_str().parse::();
match i {
Ok(i) => Ok(Ret(v_int(i as i64))),
Err(_) => Ok(Ret(v_int(0))),
@@ -84,15 +85,15 @@ fn bf_toobj(bf_args: &mut BfCallState<'_>) -> Result {
match bf_args.args[0].variant() {
Variant::Int(i) => Ok(Ret(v_obj(*i))),
Variant::Float(f) => Ok(Ret(v_obj(*f as i64))),
- Variant::Str(s) if s.as_str().starts_with('#') => {
- let i = s.as_str()[1..].parse::();
+ Variant::Str(s) if s.as_string().as_str().starts_with('#') => {
+ let i = s.as_string().as_str()[1..].parse::();
match i {
Ok(i) => Ok(Ret(v_obj(i))),
Err(_) => Ok(Ret(v_obj(0))),
}
}
Variant::Str(s) => {
- let i = s.as_str().parse::();
+ let i = s.as_string().as_str().parse::();
match i {
Ok(i) => Ok(Ret(v_obj(i))),
Err(_) => Ok(Ret(v_obj(0))),
@@ -111,7 +112,7 @@ fn bf_tofloat(bf_args: &mut BfCallState<'_>) -> Result {
Variant::Int(i) => Ok(Ret(v_float(*i as f64))),
Variant::Float(f) => Ok(Ret(v_float(*f))),
Variant::Str(s) => {
- let f = s.as_str().parse::();
+ let f = s.as_string().as_str().parse::();
match f {
Ok(f) => Ok(Ret(v_float(f))),
Err(_) => Ok(Ret(v_float(0.0))),
@@ -127,11 +128,8 @@ fn bf_equal(bf_args: &mut BfCallState<'_>) -> Result {
if bf_args.args.len() != 2 {
return Err(BfErr::Code(E_ARGS));
}
- let result = match (bf_args.args[0].variant(), bf_args.args[1].variant()) {
- (Variant::Str(s1), Variant::Str(s2)) => s1.as_str() == s2.as_str().to_lowercase(),
- (Variant::Map(m1), Variant::Map(m2)) => m1.eq_case_sensitive(m2),
- _ => bf_args.args[0] == bf_args.args[1],
- };
+ let (a1, a2) = (&bf_args.args[0], &bf_args.args[1]);
+ let result = a1.eq_case_sensitive(a2);
Ok(Ret(v_bool(result)))
}
bf_declare!(equal, bf_equal);
@@ -149,7 +147,7 @@ fn bf_value_hash(bf_args: &mut BfCallState<'_>) -> Result {
if bf_args.args.len() != 1 {
return Err(BfErr::Code(E_ARGS));
}
- let s = bf_args.args[0].to_literal();
+ let s = to_literal(&bf_args.args[0]);
let hash_digest = md5::Md5::digest(s.as_bytes());
Ok(Ret(v_str(
format!("{:x}", hash_digest).to_uppercase().as_str(),
diff --git a/crates/kernel/src/builtins/bf_verbs.rs b/crates/kernel/src/builtins/bf_verbs.rs
index 79c219f4..d1d90636 100644
--- a/crates/kernel/src/builtins/bf_verbs.rs
+++ b/crates/kernel/src/builtins/bf_verbs.rs
@@ -15,12 +15,12 @@
use strum::EnumCount;
use tracing::{error, warn};
-use moor_compiler::compile;
use moor_compiler::offset_for_builtin;
use moor_compiler::program_to_tree;
use moor_compiler::unparse;
use moor_compiler::GlobalName;
use moor_compiler::Program;
+use moor_compiler::{compile, to_literal};
use moor_values::model::ObjFlag;
use moor_values::model::VerbDef;
use moor_values::model::WorldStateError;
@@ -28,14 +28,14 @@ use moor_values::model::{ArgSpec, VerbArgsSpec};
use moor_values::model::{BinaryType, VerbAttrs, VerbFlag};
use moor_values::model::{HasUuid, Named};
use moor_values::util::BitEnum;
-use moor_values::var::Error::{E_ARGS, E_INVARG, E_INVIND, E_PERM, E_TYPE, E_VERBNF};
-use moor_values::var::List;
-use moor_values::var::Objid;
-use moor_values::var::Symbol;
-use moor_values::var::Variant;
-use moor_values::var::{v_empty_list, v_list, v_none, v_objid, v_str, v_string, Var};
-use moor_values::var::{v_listv, Error};
-use moor_values::AsByteBuffer;
+use moor_values::Error::{E_ARGS, E_INVARG, E_INVIND, E_PERM, E_TYPE, E_VERBNF};
+use moor_values::List;
+use moor_values::Objid;
+use moor_values::Symbol;
+use moor_values::Variant;
+use moor_values::{v_empty_list, v_list, v_none, v_objid, v_str, v_string, Var};
+use moor_values::{v_list_iter, Error};
+use moor_values::{AsByteBuffer, Sequence};
use crate::bf_declare;
use crate::builtins::BfRet::Ret;
@@ -65,7 +65,7 @@ fn bf_verb_info(bf_args: &mut BfCallState<'_>) -> Result {
.get_verb(
bf_args.task_perms_who(),
*obj,
- Symbol::mk_case_insensitive(verb_desc.as_str()),
+ Symbol::mk_case_insensitive(&verb_desc.as_string()),
)
.map_err(world_state_bf_err)?,
Variant::Int(verb_index) => {
@@ -112,7 +112,7 @@ bf_declare!(verb_info, bf_verb_info);
fn get_verbdef(obj: Objid, verbspec: Var, bf_args: &BfCallState<'_>) -> Result {
let verbspec_result = match verbspec.variant() {
Variant::Str(verb_desc) => {
- let verb_desc = Symbol::mk_case_insensitive(verb_desc.as_str());
+ let verb_desc = Symbol::mk_case_insensitive(&verb_desc.as_string());
bf_args
.world_state
.get_verb(bf_args.task_perms_who(), obj, verb_desc)
@@ -144,13 +144,13 @@ fn parse_verb_info(info: &List) -> Result {
return Err(E_INVARG);
}
match (
- info.get(0).unwrap().variant(),
- info.get(1).unwrap().variant(),
- info.get(2).unwrap().variant(),
+ info.index(0).unwrap().variant(),
+ info.index(1).unwrap().variant(),
+ info.index(2).unwrap().variant(),
) {
(Variant::Obj(owner), Variant::Str(perms_str), Variant::Str(names)) => {
let mut perms = BitEnum::new();
- for c in perms_str.as_str().chars() {
+ for c in perms_str.as_string().chars() {
match c {
'r' => perms |= VerbFlag::Read,
'w' => perms |= VerbFlag::Write,
@@ -162,7 +162,7 @@ fn parse_verb_info(info: &List) -> Result {
// Split the names string into a list of symbols
let name_strings = names
- .as_str()
+ .as_string()
.split(' ')
.map(Symbol::mk_case_insensitive)
.collect::>();
@@ -212,7 +212,7 @@ fn bf_set_verb_info(bf_args: &mut BfCallState<'_>) -> Result {
.update_verb(
bf_args.task_perms_who(),
*obj,
- Symbol::mk_case_insensitive(verb_name.as_str()),
+ Symbol::mk_case_insensitive(&verb_name.as_string()),
update_attrs,
)
.map_err(world_state_bf_err)?;
@@ -271,15 +271,15 @@ fn parse_verb_args(verbinfo: &List) -> Result {
return Err(E_ARGS);
}
match (
- verbinfo.get(0).unwrap().variant(),
- verbinfo.get(1).unwrap().variant(),
- verbinfo.get(2).unwrap().variant(),
+ verbinfo.index(0).unwrap().variant(),
+ verbinfo.index(1).unwrap().variant(),
+ verbinfo.index(2).unwrap().variant(),
) {
(Variant::Str(dobj_str), Variant::Str(prep_str), Variant::Str(iobj_str)) => {
let (Some(dobj), Some(prep), Some(iobj)) = (
- ArgSpec::from_string(dobj_str.as_str()),
- parse_preposition_spec(prep_str.as_str()),
- ArgSpec::from_string(iobj_str.as_str()),
+ ArgSpec::from_string(&dobj_str.as_string()),
+ parse_preposition_spec(&prep_str.as_string()),
+ ArgSpec::from_string(&iobj_str.as_string()),
) else {
return Err(E_INVARG);
};
@@ -329,7 +329,7 @@ fn bf_set_verb_args(bf_args: &mut BfCallState<'_>) -> Result {
.update_verb(
bf_args.task_perms_who(),
*obj,
- Symbol::mk_case_insensitive(verb_name.as_str()),
+ Symbol::mk_case_insensitive(&verb_name.as_string()),
update_attrs,
)
.map_err(world_state_bf_err)?;
@@ -425,9 +425,7 @@ fn bf_verb_code(bf_args: &mut BfCallState<'_>) -> Result {
return Err(BfErr::Code(E_INVARG));
}
};
- Ok(Ret(v_listv(
- unparsed.iter().map(|s| v_str(s)).collect::>(),
- )))
+ Ok(Ret(v_list_iter(unparsed.iter().map(|s| v_str(s)))))
}
bf_declare!(verb_code, bf_verb_code);
@@ -477,7 +475,7 @@ fn bf_set_verb_code(bf_args: &mut BfCallState<'_>) -> Result {
Variant::Str(line) => line,
_ => return Err(BfErr::Code(E_TYPE)),
};
- code_string.push_str(line.as_str());
+ code_string.push_str(&line.as_string());
code_string.push('\n');
}
// Now try to compile...
@@ -658,7 +656,7 @@ fn bf_disassemble(bf_args: &mut BfCallState<'_>) -> Result {
// Write literals indexed by their offset #
disassembly.push(v_str("LITERALS:"));
for (i, l) in program.literals.iter().enumerate() {
- disassembly.push(v_string(format!("{: >3}: {}", i, l.to_literal())));
+ disassembly.push(v_string(format!("{: >3}: {}", i, to_literal(l))));
}
// Write jump labels indexed by their offset & showing position & optional name
@@ -697,7 +695,7 @@ fn bf_disassemble(bf_args: &mut BfCallState<'_>) -> Result {
disassembly.push(v_string(format!("{: >3}: {:?}{}", i, op, line_no_string)));
}
- Ok(Ret(v_listv(disassembly)))
+ Ok(Ret(v_list(&disassembly)))
}
bf_declare!(disassemble, bf_disassemble);
diff --git a/crates/kernel/src/builtins/mod.rs b/crates/kernel/src/builtins/mod.rs
index f46608e1..0bc33b83 100644
--- a/crates/kernel/src/builtins/mod.rs
+++ b/crates/kernel/src/builtins/mod.rs
@@ -20,10 +20,10 @@ use moor_compiler::{BuiltinId, BUILTINS};
use moor_values::model::Perms;
use moor_values::model::WorldState;
use moor_values::model::WorldStateError;
-use moor_values::var::Error;
-use moor_values::var::Objid;
-use moor_values::var::Symbol;
-use moor_values::var::Var;
+use moor_values::Error;
+use moor_values::Objid;
+use moor_values::Symbol;
+use moor_values::Var;
use crate::builtins::bf_list_sets::register_bf_list_sets;
use crate::builtins::bf_maps::register_bf_maps;
diff --git a/crates/kernel/src/matching/match_env.rs b/crates/kernel/src/matching/match_env.rs
index b84af44e..7bf3f6a3 100644
--- a/crates/kernel/src/matching/match_env.rs
+++ b/crates/kernel/src/matching/match_env.rs
@@ -14,7 +14,7 @@
use moor_values::model::WorldStateError;
use moor_values::model::{ObjSet, ValSet};
-use moor_values::var::Objid;
+use moor_values::Objid;
use moor_values::{AMBIGUOUS, FAILED_MATCH, NOTHING};
use crate::tasks::command_parse::ParseMatcher;
@@ -148,7 +148,7 @@ impl ParseMatcher for MatchEnvironmentParseMatcher {
#[cfg(test)]
mod tests {
- use moor_values::var::Objid;
+ use moor_values::Objid;
use moor_values::{FAILED_MATCH, NOTHING};
use crate::matching::match_env::{
diff --git a/crates/kernel/src/matching/mock_matching_env.rs b/crates/kernel/src/matching/mock_matching_env.rs
index db75219b..f7fdd2fb 100644
--- a/crates/kernel/src/matching/mock_matching_env.rs
+++ b/crates/kernel/src/matching/mock_matching_env.rs
@@ -16,7 +16,7 @@ use std::collections::{HashMap, HashSet};
use moor_values::model::WorldStateError;
use moor_values::model::{ObjSet, ValSet};
-use moor_values::var::Objid;
+use moor_values::Objid;
use moor_values::NOTHING;
use crate::matching::match_env::MatchEnvironment;
diff --git a/crates/kernel/src/matching/ws_match_env.rs b/crates/kernel/src/matching/ws_match_env.rs
index ea438b4a..15e60cb6 100644
--- a/crates/kernel/src/matching/ws_match_env.rs
+++ b/crates/kernel/src/matching/ws_match_env.rs
@@ -15,7 +15,7 @@
use moor_values::model::ObjSet;
use moor_values::model::WorldState;
use moor_values::model::WorldStateError;
-use moor_values::var::Objid;
+use moor_values::Objid;
use crate::matching::match_env::MatchEnvironment;
diff --git a/crates/kernel/src/tasks/command_parse.rs b/crates/kernel/src/tasks/command_parse.rs
index 4c58ee09..2d45fa3a 100644
--- a/crates/kernel/src/tasks/command_parse.rs
+++ b/crates/kernel/src/tasks/command_parse.rs
@@ -19,8 +19,8 @@ use bincode::{Decode, Encode};
use moor_values::model::WorldStateError;
use moor_values::model::{PrepSpec, Preposition};
use moor_values::util;
-use moor_values::var::Objid;
-use moor_values::var::{v_str, Var};
+use moor_values::Objid;
+use moor_values::{v_str, Var};
#[derive(Clone, Eq, PartialEq, Debug, Decode, Encode)]
pub struct ParsedCommand {
@@ -188,7 +188,7 @@ where
mod tests {
use moor_values::model::Preposition;
use moor_values::util::parse_into_words;
- use moor_values::var::v_str;
+ use moor_values::v_str;
use moor_values::FAILED_MATCH;
use crate::matching::match_env::MatchEnvironmentParseMatcher;
diff --git a/crates/kernel/src/tasks/mod.rs b/crates/kernel/src/tasks/mod.rs
index 833037a5..3b46de6c 100644
--- a/crates/kernel/src/tasks/mod.rs
+++ b/crates/kernel/src/tasks/mod.rs
@@ -18,8 +18,8 @@ use std::time::SystemTime;
use bincode::{Decode, Encode};
use moor_compiler::Program;
-use moor_values::var::{List, Objid};
-use moor_values::var::{Symbol, Var};
+use moor_values::Objid;
+use moor_values::{Symbol, Var};
pub use crate::tasks::tasks_db::{NoopTasksDb, TasksDb, TasksDbError};
use crate::vm::Fork;
@@ -75,7 +75,7 @@ pub struct VerbCall {
pub location: Objid,
pub this: Objid,
pub player: Objid,
- pub args: List,
+ pub args: Vec,
pub argstr: String,
pub caller: Objid,
}
@@ -124,9 +124,9 @@ pub mod vm_test_utils {
use moor_compiler::Program;
use moor_values::model::WorldState;
- use moor_values::var::Symbol;
- use moor_values::var::{List, Objid, Var};
+ use moor_values::Symbol;
use moor_values::SYSTEM_OBJECT;
+ use moor_values::{Objid, Var};
use crate::builtins::BuiltinRegistry;
use crate::config::Config;
@@ -217,7 +217,7 @@ pub mod vm_test_utils {
location: SYSTEM_OBJECT,
this: SYSTEM_OBJECT,
player: SYSTEM_OBJECT,
- args: List::from_slice(&args),
+ args,
argstr: "".to_string(),
caller: SYSTEM_OBJECT,
},
@@ -244,7 +244,7 @@ pub mod scheduler_test_utils {
use std::time::Duration;
use moor_values::tasks::{CommandError, SchedulerError};
- use moor_values::var::{Error::E_VERBNF, Objid, Var};
+ use moor_values::{Error::E_VERBNF, Objid, Var};
use super::TaskHandle;
use crate::config::Config;
@@ -316,7 +316,7 @@ pub enum TaskStart {
player: Objid,
vloc: Objid,
verb: Symbol,
- args: List,
+ args: Vec,
argstr: String,
},
/// The scheduler is telling the task to run a task that was forked from another task.
diff --git a/crates/kernel/src/tasks/scheduler.rs b/crates/kernel/src/tasks/scheduler.rs
index a2d159d5..92dc8b59 100644
--- a/crates/kernel/src/tasks/scheduler.rs
+++ b/crates/kernel/src/tasks/scheduler.rs
@@ -34,11 +34,11 @@ use moor_values::model::{CommitResult, Perms};
use moor_values::tasks::{
AbortLimitReason, CommandError, SchedulerError, TaskId, VerbProgramError,
};
-use moor_values::var::Error::{E_INVARG, E_PERM};
-use moor_values::var::Symbol;
-use moor_values::var::{v_err, v_int, v_none, v_string, List, Var};
-use moor_values::var::{Objid, Variant};
+use moor_values::Error::{E_INVARG, E_PERM};
+use moor_values::Symbol;
+use moor_values::{v_err, v_int, v_none, v_string, Var};
use moor_values::{AsByteBuffer, SYSTEM_OBJECT};
+use moor_values::{Objid, Variant};
use crate::builtins::BuiltinRegistry;
use crate::config::Config;
@@ -392,7 +392,7 @@ impl Scheduler {
player,
vloc,
verb,
- args: List::from_slice(&args),
+ args,
argstr,
});
let task_id = self.next_task_id;
@@ -461,7 +461,7 @@ impl Scheduler {
player,
vloc: SYSTEM_OBJECT,
verb: *DO_OUT_OF_BAND_COMMAND,
- args: List::from_slice(&args),
+ args,
argstr,
});
let task_id = self.next_task_id;
diff --git a/crates/kernel/src/tasks/scheduler_client.rs b/crates/kernel/src/tasks/scheduler_client.rs
index c880de5e..d7342434 100644
--- a/crates/kernel/src/tasks/scheduler_client.rs
+++ b/crates/kernel/src/tasks/scheduler_client.rs
@@ -20,8 +20,8 @@ use tracing::{instrument, trace};
use uuid::Uuid;
use moor_compiler::{compile, Program};
-use moor_values::var::Symbol;
-use moor_values::var::{Objid, Var};
+use moor_values::Symbol;
+use moor_values::{Objid, Var};
use crate::config::Config;
use crate::tasks::sessions::Session;
diff --git a/crates/kernel/src/tasks/sessions.rs b/crates/kernel/src/tasks/sessions.rs
index 4e015a84..841b47f6 100644
--- a/crates/kernel/src/tasks/sessions.rs
+++ b/crates/kernel/src/tasks/sessions.rs
@@ -18,7 +18,7 @@ use thiserror::Error;
use uuid::Uuid;
use moor_values::tasks::NarrativeEvent;
-use moor_values::var::Objid;
+use moor_values::Objid;
/// The interface for managing the user I/O connection side of state, exposed by the scheduler to
/// the VM during execution and by the host server to the scheduler.
diff --git a/crates/kernel/src/tasks/suspension.rs b/crates/kernel/src/tasks/suspension.rs
index 2c658d30..80d919c2 100644
--- a/crates/kernel/src/tasks/suspension.rs
+++ b/crates/kernel/src/tasks/suspension.rs
@@ -23,7 +23,7 @@ use bincode::{BorrowDecode, Decode, Encode};
use tracing::{debug, error, info, warn};
use uuid::Uuid;
-use moor_values::var::{Objid, Var};
+use moor_values::{Objid, Var};
use crate::tasks::sessions::{NoopClientSession, Session, SessionFactory};
use crate::tasks::task::Task;
diff --git a/crates/kernel/src/tasks/task.rs b/crates/kernel/src/tasks/task.rs
index 1ff90759..fca8bc54 100644
--- a/crates/kernel/src/tasks/task.rs
+++ b/crates/kernel/src/tasks/task.rs
@@ -40,9 +40,9 @@ use moor_values::tasks::CommandError;
use moor_values::tasks::CommandError::PermissionDenied;
use moor_values::tasks::TaskId;
use moor_values::util::parse_into_words;
-use moor_values::var::Symbol;
-use moor_values::var::{v_int, v_str};
-use moor_values::var::{List, Objid};
+use moor_values::Symbol;
+use moor_values::{v_int, v_str};
+use moor_values::Objid;
use moor_values::{NOTHING, SYSTEM_OBJECT};
use crate::builtins::BuiltinRegistry;
@@ -436,13 +436,13 @@ impl Task {
}
Ok(verb_info) => {
let arguments = parse_into_words(command);
- let arguments = arguments.iter().map(|s| v_str(s)).collect::>();
+ let args = arguments.iter().map(|s| v_str(s)).collect::>();
let verb_call = VerbCall {
verb_name: Symbol::mk("do_command"),
location: SYSTEM_OBJECT,
this: SYSTEM_OBJECT,
player,
- args: List::from_slice(&arguments),
+ args,
argstr: command.to_string(),
caller: SYSTEM_OBJECT,
};
@@ -534,7 +534,7 @@ impl Task {
location: target,
this: target,
player,
- args: List::from_slice(&parsed_command.args),
+ args: parsed_command.args.clone(),
argstr: parsed_command.argstr.clone(),
caller: player,
};
@@ -653,9 +653,9 @@ mod tests {
};
use moor_values::tasks::{CommandError, Event, TaskId};
use moor_values::util::BitEnum;
- use moor_values::var::Error::E_DIV;
- use moor_values::var::Symbol;
- use moor_values::var::{v_int, v_str};
+ use moor_values::Error::E_DIV;
+ use moor_values::Symbol;
+ use moor_values::{v_int, v_str};
use moor_values::{AsByteBuffer, NOTHING, SYSTEM_OBJECT};
use crate::builtins::BuiltinRegistry;
diff --git a/crates/kernel/src/tasks/task_scheduler_client.rs b/crates/kernel/src/tasks/task_scheduler_client.rs
index 57e59209..26968da0 100644
--- a/crates/kernel/src/tasks/task_scheduler_client.rs
+++ b/crates/kernel/src/tasks/task_scheduler_client.rs
@@ -18,9 +18,9 @@ use crossbeam_channel::Sender;
use moor_values::model::Perms;
use moor_values::tasks::{AbortLimitReason, CommandError, Exception, NarrativeEvent, TaskId};
-use moor_values::var::Objid;
-use moor_values::var::Symbol;
-use moor_values::var::Var;
+use moor_values::Objid;
+use moor_values::Symbol;
+use moor_values::Var;
use crate::tasks::task::Task;
use crate::tasks::TaskDescription;
diff --git a/crates/kernel/src/tasks/vm_host.rs b/crates/kernel/src/tasks/vm_host.rs
index fc6afda8..d4d800e0 100644
--- a/crates/kernel/src/tasks/vm_host.rs
+++ b/crates/kernel/src/tasks/vm_host.rs
@@ -31,11 +31,11 @@ use moor_values::model::VerbInfo;
use moor_values::model::WorldState;
use moor_values::model::{BinaryType, ObjFlag};
use moor_values::tasks::{AbortLimitReason, Exception, TaskId};
-use moor_values::var::Error::E_MAXREC;
-use moor_values::var::Var;
-use moor_values::var::{v_none, Symbol};
-use moor_values::var::{List, Objid};
use moor_values::AsByteBuffer;
+use moor_values::Error::E_MAXREC;
+use moor_values::Var;
+use moor_values::{v_none, Symbol};
+use moor_values::Objid;
use crate::builtins::BuiltinRegistry;
use crate::config::Config;
@@ -306,7 +306,7 @@ impl VmHost {
// After this we will loop around and check the result.
result = self.vm_exec_state.call_builtin_function(
bf_offset,
- List::from_slice(&args),
+ args,
&exec_params,
world_state,
session.clone(),
@@ -458,8 +458,8 @@ impl VmHost {
pub fn reset_time(&mut self) {
self.vm_exec_state.start_time = Some(SystemTime::now());
}
- pub fn args(&self) -> List {
- self.vm_exec_state.top().args.clone()
+ pub fn args(&self) -> &Vec {
+ &self.vm_exec_state.top().args
}
}
diff --git a/crates/kernel/src/textdump/load_db.rs b/crates/kernel/src/textdump/load_db.rs
index 6e284c9d..9198f625 100644
--- a/crates/kernel/src/textdump/load_db.rs
+++ b/crates/kernel/src/textdump/load_db.rs
@@ -29,8 +29,8 @@ use moor_values::model::VerbFlag;
use moor_values::model::{ArgSpec, PrepSpec, VerbArgsSpec};
use moor_values::model::{ObjAttrs, ObjFlag};
use moor_values::util::BitEnum;
-use moor_values::var::Objid;
-use moor_values::var::Var;
+use moor_values::Objid;
+use moor_values::Var;
use moor_values::{AsByteBuffer, NOTHING};
use crate::textdump::read::TextdumpReaderError;
diff --git a/crates/kernel/src/textdump/mod.rs b/crates/kernel/src/textdump/mod.rs
index b74bc70d..52f16df9 100644
--- a/crates/kernel/src/textdump/mod.rs
+++ b/crates/kernel/src/textdump/mod.rs
@@ -18,8 +18,8 @@ use std::collections::BTreeMap;
pub use load_db::{read_textdump, textdump_load};
-use moor_values::var::Objid;
-use moor_values::var::Var;
+use moor_values::Objid;
+use moor_values::Var;
pub use read::TextdumpReader;
pub use write::TextdumpWriter;
pub use write_db::make_textdump;
diff --git a/crates/kernel/src/textdump/read.rs b/crates/kernel/src/textdump/read.rs
index 4d99e20b..94b6199a 100644
--- a/crates/kernel/src/textdump/read.rs
+++ b/crates/kernel/src/textdump/read.rs
@@ -21,9 +21,9 @@ use tracing::info;
use moor_compiler::Label;
use moor_values::model::CompileError;
use moor_values::model::WorldStateError;
-use moor_values::var::{v_err, v_float, v_int, v_none, v_objid, v_str, Var, VarType};
-use moor_values::var::{v_listv, Error};
-use moor_values::var::{v_map_pairs, Objid};
+use moor_values::Objid;
+use moor_values::{v_err, v_float, v_int, v_none, v_objid, v_str, Var, VarType};
+use moor_values::{v_list, v_map, Error};
use crate::textdump::{EncodingMode, Object, Propval, Textdump, Verb, Verbdef};
@@ -148,7 +148,7 @@ impl TextdumpReader {
VarType::TYPE_LIST => {
let l_size = self.read_num()?;
let v: Vec = (0..l_size).map(|_l| self.read_var().unwrap()).collect();
- v_listv(v)
+ v_list(&v)
}
VarType::TYPE_MAP => {
let num_pairs = self.read_num()?;
@@ -159,7 +159,7 @@ impl TextdumpReader {
(key, value)
})
.collect();
- v_map_pairs(&pairs)
+ v_map(&pairs)
}
VarType::TYPE_NONE => v_none(),
VarType::TYPE_FLOAT => v_float(self.read_float()?),
diff --git a/crates/kernel/src/textdump/write.rs b/crates/kernel/src/textdump/write.rs
index 01eb55f5..acb2a545 100644
--- a/crates/kernel/src/textdump/write.rs
+++ b/crates/kernel/src/textdump/write.rs
@@ -12,14 +12,14 @@
// this program. If not, see .
//
+use moor_values::{Objid, Sequence};
+use moor_values::{Var, VarType, Variant};
use std::collections::BTreeMap;
use std::io;
-use moor_values::var::Objid;
-use moor_values::var::{Var, VarType, Variant};
-
use crate::textdump::read::TYPE_CLEAR;
use crate::textdump::{EncodingMode, Object, Propval, Textdump, Verb, Verbdef};
+use moor_values::Associative;
pub struct TextdumpWriter {
writer: W,
@@ -61,8 +61,8 @@ impl TextdumpWriter {
EncodingMode::ISO8859_1 => {
//
let encoding = encoding_rs::WINDOWS_1252;
- let s = s.as_str();
- let s = encoding.encode(s);
+ let s = s.as_string();
+ let s = encoding.encode(&s);
let written = self.writer.write(&s.0).unwrap();
assert_eq!(written, s.0.len());
}
@@ -84,8 +84,8 @@ impl TextdumpWriter {
Variant::Map(m) => {
writeln!(self.writer, "{}\n{}", VarType::TYPE_MAP as i64, m.len())?;
for (k, v) in m.iter() {
- self.write_var(k, false)?;
- self.write_var(v, false)?;
+ self.write_var(&k, false)?;
+ self.write_var(&v, false)?;
}
}
Variant::None => {
diff --git a/crates/kernel/src/textdump/write_db.rs b/crates/kernel/src/textdump/write_db.rs
index 7739133f..e304b2f8 100644
--- a/crates/kernel/src/textdump/write_db.rs
+++ b/crates/kernel/src/textdump/write_db.rs
@@ -20,8 +20,8 @@ use moor_values::model::{ArgSpec, PrepSpec, ValSet, VerbArgsSpec};
use moor_values::model::{BinaryType, VerbFlag};
use moor_values::model::{HasUuid, Named};
use moor_values::util::BitEnum;
-use moor_values::var::v_none;
-use moor_values::var::Objid;
+use moor_values::v_none;
+use moor_values::Objid;
use moor_values::{AsByteBuffer, NOTHING};
use crate::textdump::{
diff --git a/crates/kernel/src/vm/activation.rs b/crates/kernel/src/vm/activation.rs
index 6d4e45c8..ce3e033f 100644
--- a/crates/kernel/src/vm/activation.rs
+++ b/crates/kernel/src/vm/activation.rs
@@ -25,11 +25,11 @@ use moor_values::model::VerbDef;
use moor_values::model::VerbInfo;
use moor_values::model::{BinaryType, VerbFlag};
use moor_values::util::BitEnum;
-use moor_values::var::Objid;
-use moor_values::var::Symbol;
-use moor_values::var::{v_empty_list, v_int, v_objid, v_str, v_string, Var, VarType};
-use moor_values::var::{v_empty_str, Error, List, Variant};
+use moor_values::Symbol;
use moor_values::NOTHING;
+use moor_values::{v_empty_list, v_int, v_objid, v_str, v_string, Var, VarType};
+use moor_values::{v_empty_str, Error};
+use moor_values::{v_list, Objid};
use crate::tasks::command_parse::ParsedCommand;
use crate::vm::moo_frame::MooStackFrame;
@@ -52,7 +52,7 @@ pub(crate) struct Activation {
/// The object that is the 'player' role; that is, the active user of this task.
pub(crate) player: Objid,
/// The arguments to the verb or bf being called.
- pub(crate) args: List,
+ pub(crate) args: Vec,
/// The name of the verb that is currently being executed.
pub(crate) verb_name: Symbol,
/// The extended information about the verb that is currently being executed.
@@ -169,10 +169,7 @@ impl Activation {
GlobalName::verb,
v_str(verb_call_request.call.verb_name.as_str()),
);
- frame.set_global_variable(
- GlobalName::args,
- Var::new(Variant::List(verb_call_request.call.args.clone())),
- );
+ frame.set_global_variable(GlobalName::args, v_list(&verb_call_request.call.args));
// From the command, if any...
if let Some(ref command) = verb_call_request.command {
@@ -263,7 +260,7 @@ impl Activation {
verb_info,
verb_name: *EVAL_SYMBOL,
command: None,
- args: List::new(),
+ args: vec![],
permissions,
}
}
@@ -271,7 +268,7 @@ impl Activation {
pub fn for_bf_call(
bf_id: BuiltinId,
bf_name: Symbol,
- args: List,
+ args: Vec,
_verb_flags: BitEnum,
player: Objid,
) -> Self {
diff --git a/crates/kernel/src/vm/exec_state.rs b/crates/kernel/src/vm/exec_state.rs
index 5996c59a..0f688a0e 100644
--- a/crates/kernel/src/vm/exec_state.rs
+++ b/crates/kernel/src/vm/exec_state.rs
@@ -17,9 +17,9 @@ use std::time::{Duration, SystemTime};
use bincode::{Decode, Encode};
use daumtils::PhantomUnsync;
-use moor_values::var::Var;
-use moor_values::var::{Objid, Symbol};
+use moor_values::Var;
use moor_values::NOTHING;
+use moor_values::{Objid, Symbol};
use crate::vm::activation::{Activation, Frame};
use moor_values::tasks::TaskId;
diff --git a/crates/kernel/src/vm/mod.rs b/crates/kernel/src/vm/mod.rs
index 486808c6..f300e917 100644
--- a/crates/kernel/src/vm/mod.rs
+++ b/crates/kernel/src/vm/mod.rs
@@ -26,7 +26,7 @@ pub use exec_state::VMExecState;
use moor_compiler::{BuiltinId, Name};
use moor_compiler::{Offset, Program};
use moor_values::model::VerbInfo;
-use moor_values::var::{Objid, Var};
+use moor_values::{Objid, Var};
pub use vm_call::VerbExecutionRequest;
pub use vm_unwind::FinallyReason;
diff --git a/crates/kernel/src/vm/moo_execute.rs b/crates/kernel/src/vm/moo_execute.rs
index 35d7da85..390b3720 100644
--- a/crates/kernel/src/vm/moo_execute.rs
+++ b/crates/kernel/src/vm/moo_execute.rs
@@ -17,21 +17,22 @@ use std::time::Duration;
use tracing::debug;
-use moor_compiler::{Op, ScatterLabel};
-use moor_values::model::WorldState;
-use moor_values::model::WorldStateError;
-use moor_values::var::Error::{E_ARGS, E_DIV, E_INVARG, E_INVIND, E_RANGE, E_TYPE, E_VARNF};
-use moor_values::var::Symbol;
-use moor_values::var::Variant;
-use moor_values::var::{v_bool, v_empty_list, v_err, v_int, v_list, v_none, v_obj, v_objid, Var};
-use moor_values::var::{v_empty_map, v_float};
-use moor_values::var::{v_listv, Error};
-
use crate::tasks::sessions::Session;
use crate::vm::activation::Frame;
use crate::vm::moo_frame::{CatchType, ScopeType};
use crate::vm::vm_unwind::FinallyReason;
use crate::vm::{ExecutionResult, Fork, VMExecState, VmExecParams};
+use moor_compiler::{Op, ScatterLabel};
+use moor_values::model::WorldState;
+use moor_values::model::WorldStateError;
+
+use moor_values::Error::{E_ARGS, E_DIV, E_INVARG, E_INVIND, E_TYPE, E_VARNF};
+use moor_values::Variant;
+use moor_values::{
+ v_bool, v_empty_list, v_empty_map, v_err, v_float, v_int, v_list, v_none, v_obj, v_objid,
+ IndexMode, Sequence,
+};
+use moor_values::{Symbol, VarType};
macro_rules! binary_bool_op {
( $f:ident, $op:tt ) => {
@@ -57,18 +58,6 @@ macro_rules! binary_var_op {
};
}
-#[inline]
-pub(crate) fn one_to_zero_index(v: &Var) -> Result {
- let Variant::Int(index) = v.variant() else {
- return Err(E_TYPE);
- };
- let index = index - 1;
- if index < 0 {
- return Err(E_RANGE);
- }
- Ok(index as usize)
-}
-
/// Main VM opcode execution for MOO stack frames. The actual meat of the MOO virtual machine.
pub fn moo_frame_execute(
exec_params: &VmExecParams,
@@ -201,7 +190,7 @@ pub fn moo_frame_execute(
// Track iteration count for range; set id to current list element for the count,
// then increment the count, rewind the program counter to the top of the loop, and
// continue.
- f.set_env(id, l.get(count).unwrap().clone());
+ f.set_env(id, l.index(count).unwrap().clone());
f.poke(0, v_int((count + 1) as i64));
}
Op::ForRange {
@@ -299,62 +288,51 @@ pub fn moo_frame_execute(
Op::ImmEmptyList => f.push(v_empty_list()),
Op::ListAddTail => {
let (tail, list) = (f.pop(), f.peek_top_mut());
- let Variant::List(ref mut list) = list.variant_mut() else {
+ if list.type_code() != VarType::TYPE_LIST {
f.pop();
return state.push_error(E_TYPE);
- };
-
+ }
// TODO: quota check SVO_MAX_LIST_CONCAT -> E_QUOTA in list add and append
- let result = list.push(tail);
- f.poke(0, result);
+ let result = list.push(&tail);
+ match result {
+ Ok(v) => {
+ f.poke(0, v);
+ }
+ Err(e) => {
+ f.pop();
+ return state.push_error(e);
+ }
+ }
}
Op::ListAppend => {
let (tail, list) = (f.pop(), f.peek_top_mut());
- let Variant::List(list) = list.variant_mut() else {
+ // Don't allow strings here.
+ if tail.type_code() != list.type_code() || list.type_code() != VarType::TYPE_LIST {
f.pop();
-
- return state.push_error(E_TYPE);
- };
-
- let Variant::List(tail) = tail.take_variant() else {
- f.pop();
-
return state.push_error(E_TYPE);
- };
-
+ }
let new_list = list.append(&tail);
- f.poke(0, new_list);
+ match new_list {
+ Ok(v) => {
+ f.poke(0, v);
+ }
+ Err(e) => {
+ f.pop();
+ return state.push_error(e);
+ }
+ }
}
Op::IndexSet => {
let (rhs, index, lhs) = (f.pop(), f.pop(), f.peek_top_mut());
- match lhs.variant() {
- Variant::Map(m) => {
- if matches!(index.variant(), Variant::Map(_) | Variant::List(_)) {
- f.pop();
- return state.push_error(E_TYPE);
- } else {
- let nmap = m.insert(index, rhs.clone());
- f.poke(0, nmap);
- }
+ let result = lhs.index_set(&index, &rhs, IndexMode::OneBased);
+ match result {
+ Ok(v) => {
+ f.poke(0, v);
}
- _ => {
- let i = match one_to_zero_index(&index) {
- Ok(i) => i,
- Err(e) => {
- f.pop();
- return state.push_error(e);
- }
- };
- match lhs.index_set(i, rhs) {
- Ok(v) => {
- f.poke(0, v);
- }
- Err(e) => {
- f.pop();
- return state.push_error(e);
- }
- }
+ Err(e) => {
+ f.pop();
+ return state.push_error(e);
}
}
}
@@ -367,16 +345,16 @@ pub fn moo_frame_execute(
}
Op::MapInsert => {
let (value, key, map) = (f.pop(), f.pop(), f.peek_top_mut());
- if matches!(key.variant(), Variant::Map(_) | Variant::List(_)) {
- f.pop();
- return state.push_error(E_TYPE);
+ let result = map.index_set(&key, &value, IndexMode::OneBased);
+ match result {
+ Ok(v) => {
+ f.poke(0, v);
+ }
+ Err(e) => {
+ f.pop();
+ return state.push_error(e);
+ }
}
- let Variant::Map(map) = map.variant_mut() else {
- f.pop();
- return state.push_error(E_TYPE);
- };
- let result = map.insert(key, value);
- f.poke(0, result);
}
Op::PutTemp => {
f.temp = f.peek_top().clone();
@@ -406,12 +384,16 @@ pub fn moo_frame_execute(
}
Op::In => {
let (lhs, rhs) = (f.pop(), f.peek_top());
- let r = lhs.index_in(rhs);
- if let Variant::Err(e) = r.variant() {
- f.pop();
- return state.push_error(*e);
+ let r = lhs.index_in(rhs, false, IndexMode::OneBased);
+ match r {
+ Ok(v) => {
+ f.poke(0, v);
+ }
+ Err(e) => {
+ f.pop();
+ return state.push_error(e);
+ }
}
- f.poke(0, r);
}
Op::Mul => {
binary_var_op!(self, f, state, mul);
@@ -484,114 +466,49 @@ pub fn moo_frame_execute(
}
Op::PushRef => {
let (index, value) = f.peek2();
-
- match value.variant() {
- Variant::Map(m) => match m.get(index) {
- Some(v) => {
- f.push(v.clone());
- }
- None => {
- f.pop();
- return state.push_error(E_RANGE);
- }
- },
- _ => {
- let index = match one_to_zero_index(index) {
- Ok(i) => i,
- Err(e) => return state.push_error(e),
- };
- match value.index(index) {
- Err(e) => return state.push_error(e),
- Ok(v) => f.push(v),
- }
+ let result = value.index(index, IndexMode::OneBased);
+ match result {
+ Ok(v) => f.push(v),
+ Err(e) => {
+ f.pop();
+ return state.push_error(e);
}
}
}
Op::Ref => {
let (index, value) = (f.pop(), f.peek_top());
- match value.variant() {
- Variant::Map(m) => {
- let v = match m.get(&index) {
- Some(v) => v.clone(),
- None => {
- f.pop();
- return state.push_error(E_RANGE);
- }
- };
- f.poke(0, v);
- }
- _ => {
- let index = match one_to_zero_index(&index) {
- Ok(i) => i,
- Err(e) => {
- f.pop();
- return state.push_error(e);
- }
- };
-
- match value.index(index) {
- Err(e) => {
- f.pop();
- return state.push_error(e);
- }
- Ok(v) => f.poke(0, v),
- }
+ let result = value.index(&index, IndexMode::OneBased);
+ match result {
+ Ok(v) => f.poke(0, v),
+ Err(e) => {
+ f.pop();
+ return state.push_error(e);
}
}
}
Op::RangeRef => {
let (to, from, base) = (f.pop(), f.pop(), f.peek_top());
- match base.variant() {
- Variant::Map(m) => {
- let r = m.range(from, to);
- f.poke(0, r);
- }
- _ => {
- match (to.variant(), from.variant()) {
- (Variant::Int(to), Variant::Int(from)) => {
- match base.range(*from, *to) {
- Err(e) => {
- f.pop();
- return state.push_error(e);
- }
- Ok(v) => f.poke(0, v),
- }
- }
- (_, _) => return state.push_error(E_TYPE),
- };
- }
+ let result = base.range(&from, &to, IndexMode::OneBased);
+ if let Err(e) = result {
+ f.pop();
+ return state.push_error(e);
}
+ f.poke(0, result.unwrap());
}
Op::RangeSet => {
let (value, to, from, base) = (f.pop(), f.pop(), f.pop(), f.peek_top());
-
- match base.variant() {
- Variant::Map(_) => {
- f.pop();
- return state.push_error(E_TYPE);
- }
- _ => match (to.variant(), from.variant()) {
- (Variant::Int(to), Variant::Int(from)) => {
- match base.range_set(value, *from, *to) {
- Err(e) => {
- f.pop();
- return state.push_error(e);
- }
- Ok(v) => f.poke(0, v),
- }
- }
- _ => {
- f.pop();
- return state.push_error(E_TYPE);
- }
- },
+ let result = base.range_set(&from, &to, &value, IndexMode::OneBased);
+ if let Err(e) = result {
+ f.pop();
+ return state.push_error(e);
}
+ f.poke(0, result.unwrap());
}
Op::Length(offset) => {
let v = f.peek_abs(offset.0 as usize);
match v.len() {
- Ok(l) => f.push(l),
+ Ok(l) => f.push(v_int(l as i64)),
Err(e) => return state.push_error(e),
}
}
@@ -605,7 +522,7 @@ pub fn moo_frame_execute(
let Variant::Obj(obj) = obj.variant() else {
return state.push_error(E_INVIND);
};
- let propname = Symbol::mk_case_insensitive(propname.as_str());
+ let propname = Symbol::mk_case_insensitive(&propname.as_string());
let result = world_state.retrieve_property(a.permissions, *obj, propname);
match result {
Ok(v) => {
@@ -629,7 +546,7 @@ pub fn moo_frame_execute(
let Variant::Obj(obj) = obj.variant() else {
return state.push_error(E_INVIND);
};
- let propname = Symbol::mk_case_insensitive(propname.as_str());
+ let propname = Symbol::mk_case_insensitive(&propname.as_string());
let result = world_state.retrieve_property(a.permissions, *obj, propname);
match result {
Ok(v) => {
@@ -654,7 +571,7 @@ pub fn moo_frame_execute(
}
};
- let propname = Symbol::mk_case_insensitive(propname.as_str());
+ let propname = Symbol::mk_case_insensitive(&propname.as_string());
let update_result =
world_state.update_property(a.permissions, *obj, propname, &rhs.clone());
@@ -711,7 +628,7 @@ pub fn moo_frame_execute(
return state.push_error(E_TYPE);
}
};
- let verb = Symbol::mk_case_insensitive(verb.as_str());
+ let verb = Symbol::mk_case_insensitive(&verb.as_string());
return state.prepare_call_verb(world_state, *obj, verb, args.clone());
}
Op::Return => {
@@ -732,7 +649,7 @@ pub fn moo_frame_execute(
};
return state.call_builtin_function(
*id,
- args.clone(),
+ args.iter().collect(),
exec_params,
world_state,
session,
@@ -896,7 +813,7 @@ pub fn moo_frame_execute(
};
v.push(rest.clone());
}
- let rest = v_listv(v);
+ let rest = v_list(&v);
f.set_env(id, rest);
}
ScatterLabel::Required(id) => {
diff --git a/crates/kernel/src/vm/moo_frame.rs b/crates/kernel/src/vm/moo_frame.rs
index ce17c4d9..fa570e36 100644
--- a/crates/kernel/src/vm/moo_frame.rs
+++ b/crates/kernel/src/vm/moo_frame.rs
@@ -21,8 +21,8 @@ use daumtils::{BitArray, Bitset16};
use crate::vm::FinallyReason;
use moor_compiler::Name;
use moor_compiler::{GlobalName, Label, Op, Program};
-use moor_values::var::Error::E_VARNF;
-use moor_values::var::{v_none, Error, Var};
+use moor_values::Error::E_VARNF;
+use moor_values::{v_none, Error, Var};
/// The MOO stack-frame specific portions of the activation:
/// the value stack, local variables, program, program counter, handler stack, etc.
diff --git a/crates/kernel/src/vm/vm_call.rs b/crates/kernel/src/vm/vm_call.rs
index fe122cc7..52300062 100644
--- a/crates/kernel/src/vm/vm_call.rs
+++ b/crates/kernel/src/vm/vm_call.rs
@@ -16,14 +16,14 @@ use std::sync::Arc;
use tracing::trace;
-use moor_compiler::{BuiltinId, Program, BUILTINS};
+use moor_compiler::{to_literal, BuiltinId, Program, BUILTINS};
use moor_values::model::VerbInfo;
use moor_values::model::WorldState;
use moor_values::model::WorldStateError;
-use moor_values::var::v_int;
-use moor_values::var::Error::{E_INVIND, E_PERM, E_VERBNF};
-use moor_values::var::Symbol;
-use moor_values::var::{List, Objid};
+use moor_values::Error::{E_INVIND, E_PERM, E_VERBNF};
+use moor_values::Symbol;
+use moor_values::{v_int, Var};
+use moor_values::{List, Objid};
use crate::builtins::{BfCallState, BfErr, BfRet};
use crate::tasks::command_parse::ParsedCommand;
@@ -34,9 +34,9 @@ use crate::vm::vm_unwind::FinallyReason;
use crate::vm::{ExecutionResult, Fork};
use crate::vm::{VMExecState, VmExecParams};
-pub(crate) fn args_literal(args: &List) -> String {
+pub(crate) fn args_literal(args: &[Var]) -> String {
args.iter()
- .map(|v| v.to_literal())
+ .map(to_literal)
.collect::>()
.join(", ")
}
@@ -79,7 +79,7 @@ impl VMExecState {
location: this,
this,
player: self.top().player,
- args,
+ args: args.iter().collect(),
// caller her is current-activation 'this', not activation caller() ...
// unless we're a builtin, in which case we're #-1.
argstr: "".to_string(),
@@ -163,7 +163,7 @@ impl VMExecState {
location: parent,
this: self.top().this,
player: self.top().player,
- args: args.clone(),
+ args: args.iter().collect(),
argstr: "".to_string(),
caller,
};
@@ -223,7 +223,7 @@ impl VMExecState {
pub(crate) fn call_builtin_function(
&mut self,
bf_id: BuiltinId,
- args: List,
+ args: Vec,
exec_args: &VmExecParams,
world_state: &mut dyn WorldState,
session: Arc,
@@ -255,7 +255,7 @@ impl VMExecState {
world_state,
session: session.clone(),
// TODO: avoid copy here by using List inside BfCallState
- args: args.iter().collect(),
+ args,
task_scheduler_client: exec_args.task_scheduler_client.clone(),
config: exec_args.config.clone(),
};
@@ -304,7 +304,7 @@ impl VMExecState {
world_state,
session: sessions,
// TODO: avoid copy here by using List inside BfCallState
- args: args.iter().collect(),
+ args,
task_scheduler_client: exec_args.task_scheduler_client.clone(),
config: exec_args.config.clone(),
};
diff --git a/crates/kernel/src/vm/vm_test.rs b/crates/kernel/src/vm/vm_test.rs
index cc2d4b40..d4cf526a 100644
--- a/crates/kernel/src/vm/vm_test.rs
+++ b/crates/kernel/src/vm/vm_test.rs
@@ -21,11 +21,11 @@ mod tests {
use moor_values::model::{BinaryType, VerbFlag};
use moor_values::model::{WorldState, WorldStateSource};
use moor_values::util::BitEnum;
- use moor_values::var::Error::E_DIV;
- use moor_values::var::{
- v_bool, v_empty_list, v_err, v_int, v_list, v_none, v_obj, v_objid, v_str, Var,
+ use moor_values::Error::E_DIV;
+ use moor_values::Objid;
+ use moor_values::{
+ v_bool, v_empty_list, v_err, v_int, v_list, v_map, v_none, v_obj, v_objid, v_str, Var,
};
- use moor_values::var::{v_map_pairs, Objid};
use moor_values::NOTHING;
use moor_values::{AsByteBuffer, SYSTEM_OBJECT};
@@ -39,7 +39,7 @@ mod tests {
use moor_compiler::{compile, UnboundNames};
use moor_compiler::{CompileOptions, Names};
use moor_db_wiredtiger::WiredTigerDB;
- use moor_values::var::Symbol;
+ use moor_values::Symbol;
use test_case::test_case;
fn mk_program(main_vector: Vec, literals: Vec, var_names: Names) -> Program {
@@ -1126,11 +1126,11 @@ mod tests {
#[test_case("return -9223372036854775808;", v_int(i64::MIN); "minint")]
#[test_case("return [ 1 -> 2][1];", v_int(2); "map index")]
#[test_case("return [ 0 -> 1, 1 -> 2, 2 -> 3, 3 -> 4][1..3];",
- v_map_pairs(&[(v_int(1),v_int(2)), (v_int(2),v_int(3))]); "map range")]
+ v_map(&[(v_int(1),v_int(2)), (v_int(2),v_int(3))]); "map range")]
#[test_case(r#"m = [ 1 -> "one", 2 -> "two", 3 -> "three" ]; m[1] = "abc"; return m;"#,
- v_map_pairs(&[(v_int(1),v_str("abc")), (v_int(2),v_str("two")), (v_int(3),v_str("three"))]); "map assignment")]
+ v_map(&[(v_int(1),v_str("abc")), (v_int(2),v_str("two")), (v_int(3),v_str("three"))]); "map assignment")]
#[test_case("return [ 0 -> 1, 1 -> 2, 2 -> 3, 3 -> 4][1..$];",
- v_map_pairs(&[(v_int(1),v_int(2)), (v_int(2),v_int(3),), (v_int(3),v_int(4))]); "map range to end")]
+ v_map(&[(v_int(1),v_int(2)), (v_int(2),v_int(3),), (v_int(3),v_int(4))]); "map range to end")]
#[test_case("l = {1,2,3}; l[2..3] = {6, 7, 8, 9}; return l;",
v_list(&[v_int(1), v_int(6), v_int(7), v_int(8), v_int(9)]); "list assignment to range")]
fn test_run(program: &str, expected_result: Var) {
@@ -1145,4 +1145,22 @@ mod tests {
);
assert_eq!(result, Ok(expected_result));
}
+
+ #[test]
+ fn test_list_assignment_to_range() {
+ let program = r#"l = {1,2,3}; l[2..3] = {6, 7, 8, 9}; return l;"#;
+ let mut state = world_with_test_program(program);
+ let session = Arc::new(NoopClientSession::new());
+ let result = call_verb(
+ state.as_mut(),
+ session,
+ Arc::new(BuiltinRegistry::new()),
+ "test",
+ vec![],
+ );
+ assert_eq!(
+ result,
+ Ok(v_list(&[v_int(1), v_int(6), v_int(7), v_int(8), v_int(9)]))
+ );
+ }
}
diff --git a/crates/kernel/src/vm/vm_unwind.rs b/crates/kernel/src/vm/vm_unwind.rs
index c7ce468e..397ad1ff 100644
--- a/crates/kernel/src/vm/vm_unwind.rs
+++ b/crates/kernel/src/vm/vm_unwind.rs
@@ -17,10 +17,9 @@ use moor_compiler::{Label, Offset, BUILTINS};
use moor_values::model::Named;
use moor_values::model::VerbFlag;
use moor_values::tasks::Exception;
-use moor_values::var::v_listv;
-use moor_values::var::{v_err, v_int, v_list, v_none, v_objid, v_str, Var};
-use moor_values::var::{Error, ErrorPack};
use moor_values::NOTHING;
+use moor_values::{v_err, v_int, v_list, v_none, v_objid, v_str, Var};
+use moor_values::{Error, ErrorPack};
use tracing::trace;
use crate::vm::activation::{Activation, Frame};
@@ -74,7 +73,7 @@ impl VMExecState {
}
};
- stack_list.push(v_listv(traceback_entry));
+ stack_list.push(v_list(&traceback_entry));
}
stack_list
}
diff --git a/crates/kernel/tests/textdump.rs b/crates/kernel/tests/textdump.rs
index 11025c0f..0e70b6d7 100644
--- a/crates/kernel/tests/textdump.rs
+++ b/crates/kernel/tests/textdump.rs
@@ -34,8 +34,8 @@ mod test {
use moor_values::model::WorldStateSource;
use moor_values::model::{CommitResult, ValSet};
use moor_values::model::{HasUuid, Named};
- use moor_values::var::Objid;
- use moor_values::var::Symbol;
+ use moor_values::Objid;
+ use moor_values::Symbol;
use moor_values::{AsByteBuffer, SYSTEM_OBJECT};
fn get_minimal_db() -> File {
diff --git a/crates/kernel/testsuite/common/mod.rs b/crates/kernel/testsuite/common/mod.rs
index 0f413a21..64397dbd 100644
--- a/crates/kernel/testsuite/common/mod.rs
+++ b/crates/kernel/testsuite/common/mod.rs
@@ -37,8 +37,8 @@ use moor_values::model::Named;
use moor_values::model::VerbArgsSpec;
use moor_values::model::WorldStateSource;
use moor_values::model::{BinaryType, VerbFlag};
-use moor_values::var::Objid;
-use moor_values::var::Symbol;
+use moor_values::Objid;
+use moor_values::Symbol;
use moor_values::{AsByteBuffer, SYSTEM_OBJECT};
#[allow(dead_code)]
diff --git a/crates/kernel/testsuite/moot/map.moot b/crates/kernel/testsuite/moot/map.moot
index 09e908fb..63d646b3 100644
--- a/crates/kernel/testsuite/moot/map.moot
+++ b/crates/kernel/testsuite/moot/map.moot
@@ -127,8 +127,10 @@
"[map]"
// Note: item order is different here than in Stunt (but stable). That's *probably* fine.
// Seems like ordering difference between different key types.
+// Note that stunt's is:
+// ""[5 -> 5, #-1 -> #-1, 3.14 -> 3.14, "1" -> {}, "2" -> []]""
; return toliteral($tmp);
-"[#-1 -> #-1, \"1\" -> {}, \"2\" -> [], 5 -> 5, 3.14 -> 3.14]"
+"[#-1 -> #-1, 5 -> 5, 3.14 -> 3.14, \"1\" -> {}, \"2\" -> []]"
// test_that_assignment_copies
; x = [$nothing -> $nothing, "2" -> [], "1" -> {}, 5 -> 5, 3.14 -> 3.14]; y = x; return x == y && "yes" || "no";
diff --git a/crates/kernel/testsuite/moot_suite.rs b/crates/kernel/testsuite/moot_suite.rs
index 4bfe76c2..6183c077 100644
--- a/crates/kernel/testsuite/moot_suite.rs
+++ b/crates/kernel/testsuite/moot_suite.rs
@@ -23,6 +23,7 @@ use eyre::Context;
#[cfg(feature = "relbox")]
use common::create_relbox_db;
use common::{create_wiredtiger_db, testsuite_dir};
+use moor_compiler::to_literal;
use moor_db::Database;
use moor_kernel::tasks::sessions::{SessionError, SessionFactory};
use moor_kernel::tasks::NoopTasksDb;
@@ -36,7 +37,7 @@ use moor_kernel::{
SchedulerClient,
};
use moor_moot::{execute_moot_test, MootRunner};
-use moor_values::var::{v_none, Objid, Var};
+use moor_values::{v_none, Objid, Var};
mod common;
@@ -102,11 +103,11 @@ impl MootRunner for SchedulerMootRunner {
unimplemented!("Not supported on SchedulerMootRunner");
}
- fn read_eval_result(&mut self, player: Objid) -> eyre::Result