Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Stdlib separation #812

Merged
merged 8 commits into from
Nov 28, 2024
Merged
Show file tree
Hide file tree
Changes from 7 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion lib/src/metta/interpreter.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ use crate::atom::matcher::*;
use crate::space::*;
use crate::metta::*;
use crate::metta::types::*;
use crate::metta::runner::stdlib::IfEqualOp;
use crate::metta::runner::stdlib::core::IfEqualOp;
use crate::common::collections::CowArray;

use std::fmt::{Debug, Display, Formatter};
Expand Down
27 changes: 1 addition & 26 deletions lib/src/metta/runner/arithmetics.rs
Original file line number Diff line number Diff line change
Expand Up @@ -308,34 +308,9 @@ macro_rules! def_binary_bool_op {
def_binary_bool_op!(AndOp, and, &&);
def_binary_bool_op!(OrOp, or, ||);

// NOTE: xor and flip are absent in Python intentionally for conversion testing
// NOTE: xor is absent in Python intentionally for conversion testing
def_binary_bool_op!(XorOp, xor, ^);

#[derive(Clone, PartialEq, Debug)]
pub struct FlipOp{}

impl Display for FlipOp {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
write!(f, "flip")
}
}

impl Grounded for FlipOp {
fn type_(&self) -> Atom {
Atom::expr([ARROW_SYMBOL, ATOM_TYPE_BOOL])
}

fn as_execute(&self) -> Option<&dyn CustomExecute> {
Some(self)
}
}

impl CustomExecute for FlipOp {
fn execute(&self, _args: &[Atom]) -> Result<Vec<Atom>, ExecError> {
Ok(vec![Atom::gnd(Bool(rand::random()))])
}
}


#[derive(Clone, PartialEq, Debug)]
pub struct NotOp{}
Expand Down
8 changes: 5 additions & 3 deletions lib/src/metta/runner/modules/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@ use regex::Regex;
use super::interpreter::interpret;
use super::stdlib::*;

use std::mem;

mod mod_names;
pub(crate) use mod_names::{ModNameNode, mod_name_from_path, normalize_relative_module_name, mod_name_remove_prefix, ModNameNodeDisplayWrapper};
#[cfg(feature = "pkg_mgmt")]
Expand Down Expand Up @@ -237,7 +239,7 @@ impl MettaMod {
pub(crate) fn remap_imported_deps(&self, mapping: &HashMap<ModId, ModId>) {
let mut deps = self.imported_deps.lock().unwrap();
let mut temp = HashMap::with_capacity(deps.len());
core::mem::swap(&mut temp, &mut *deps);
mem::swap(&mut temp, &mut *deps);
for (dep_mod_id, space) in temp.into_iter() {
let new_mod_id = match mapping.get(&dep_mod_id) {
Some(mapped_id) => *mapped_id,
Expand Down Expand Up @@ -394,8 +396,8 @@ impl ModuleInitState {
match self {
Self::Root(cell) => {
let mut insides_ref = cell.borrow_mut();
let frames = core::mem::take(&mut insides_ref.frames);
let descriptors = core::mem::take(&mut insides_ref.module_descriptors);
let frames = mem::take(&mut insides_ref.frames);
let descriptors = mem::take(&mut insides_ref.module_descriptors);
(frames, descriptors)
},
_ => unreachable!()
Expand Down
Loading
Loading