Skip to content

Commit

Permalink
fix: symmetric String/Symbol equality
Browse files Browse the repository at this point in the history
  • Loading branch information
Hirevo committed Jan 11, 2023
1 parent 1b3b45f commit 0e5419f
Show file tree
Hide file tree
Showing 2 changed files with 2 additions and 24 deletions.
13 changes: 1 addition & 12 deletions som-interpreter-ast/src/primitives/symbol.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ use crate::universe::Universe;
use crate::value::Value;

pub static INSTANCE_PRIMITIVES: &[(&str, PrimitiveFn, bool)] =
&[("asString", self::as_string, true), ("=", self::eq, false)];
&[("asString", self::as_string, true)];
pub static CLASS_PRIMITIVES: &[(&str, PrimitiveFn, bool)] = &[];

fn as_string(universe: &mut Universe, args: Vec<Value>) -> Return {
Expand All @@ -22,17 +22,6 @@ fn as_string(universe: &mut Universe, args: Vec<Value>) -> Return {
)))
}

fn eq(_: &mut Universe, args: Vec<Value>) -> Return {
const SIGNATURE: &str = "Symbol>>#=";

expect_args!(SIGNATURE, args, [
sym @ Value::Symbol(_) => sym,
other => other,
]);

Return::Local(Value::Boolean(sym == other))
}

/// Search for an instance primitive matching the given signature.
pub fn get_instance_primitive(signature: &str) -> Option<PrimitiveFn> {
INSTANCE_PRIMITIVES
Expand Down
13 changes: 1 addition & 12 deletions som-interpreter-bc/src/primitives/symbol.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ use crate::value::Value;
use crate::{expect_args, reverse};

pub static INSTANCE_PRIMITIVES: &[(&str, PrimitiveFn, bool)] =
&[("asString", self::as_string, true), ("=", self::eq, false)];
&[("asString", self::as_string, true)];
pub static CLASS_PRIMITIVES: &[(&str, PrimitiveFn, bool)] = &[];

fn as_string(interpreter: &mut Interpreter, universe: &mut Universe) {
Expand All @@ -22,17 +22,6 @@ fn as_string(interpreter: &mut Interpreter, universe: &mut Universe) {
)));
}

fn eq(interpreter: &mut Interpreter, _: &mut Universe) {
const SIGNATURE: &str = "Symbol>>#=";

expect_args!(SIGNATURE, interpreter, [
sym @ Value::Symbol(_) => sym,
other => other,
]);

interpreter.stack.push(Value::Boolean(sym == other));
}

/// Search for an instance primitive matching the given signature.
pub fn get_instance_primitive(signature: &str) -> Option<PrimitiveFn> {
INSTANCE_PRIMITIVES
Expand Down

0 comments on commit 0e5419f

Please sign in to comment.