Skip to content

Commit

Permalink
Fixed code formatting
Browse files Browse the repository at this point in the history
Removed debug statements
  • Loading branch information
Hirevo committed Aug 5, 2020
1 parent 697375d commit 1dba6c3
Show file tree
Hide file tree
Showing 9 changed files with 42 additions and 33 deletions.
13 changes: 2 additions & 11 deletions som-interpreter-bc/src/interpreter.rs
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ impl Interpreter {
loop {
let frame = match self.current_frame() {
Some(frame) => frame,
None => return dbg!(Some(Value::Nil)),
None => return Some(Value::Nil),
};

let opt_bytecode = frame.borrow().get_current_bytecode();
Expand Down Expand Up @@ -335,21 +335,12 @@ impl Interpreter {
.position(|live_frame| Rc::ptr_eq(&live_frame, &method_frame));

if let Some(count) = escaped_frames {
dbg!(&value);
match frame.borrow().kind() {
FrameKind::Block { .. } => eprintln!("from: blk"),
FrameKind::Method { method, .. } => eprintln!("from: '{}'", method.signature()),
};
(0..count).for_each(|_| self.pop_frame());
self.pop_frame();
if let Some(frame) = self.current_frame() {
match frame.borrow().kind() {
FrameKind::Block { .. } => eprintln!("from: blk"),
FrameKind::Method { method, .. } => eprintln!("to: '{}'", method.signature()),
};
frame.borrow_mut().stack.push(value);
} else {
return dbg!(Some(value));
return Some(value);
}
} else {
// Block has escaped its method frame.
Expand Down
4 changes: 2 additions & 2 deletions som-interpreter-bc/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -19,14 +19,14 @@ pub mod hashcode;
pub mod instance;
/// Facilities for string interning.
pub mod interner;
/// The interpreter's main data structure.
pub mod interpreter;
/// Facilities for manipulating class methods.
pub mod method;
/// Definitions for all supported primitives.
pub mod primitives;
/// The collection of all known SOM objects during execution.
pub mod universe;
/// The interpreter's main data structure.
pub mod interpreter;
/// Facilities for manipulating values.
pub mod value;

Expand Down
8 changes: 5 additions & 3 deletions som-interpreter-bc/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,8 @@ use structopt::StructOpt;

mod shell;

use som_interpreter_bc::universe::Universe;
use som_interpreter_bc::interpreter::Interpreter;
use som_interpreter_bc::universe::Universe;
use som_interpreter_bc::value::Value;

#[derive(Debug, Clone, PartialEq, StructOpt)]
Expand Down Expand Up @@ -42,7 +42,7 @@ fn main() -> anyhow::Result<()> {

let mut interpreter = Interpreter::new();

match dbg!(opts.file) {
match opts.file {
None => {
let mut universe = Universe::with_classpath(opts.classpath)?;
shell::interactive(&mut interpreter, &mut universe, opts.verbose)?
Expand Down Expand Up @@ -80,7 +80,9 @@ fn main() -> anyhow::Result<()> {
.map(Value::String)
.collect();

universe.initialize(&mut interpreter, args).expect("issue running program");
universe
.initialize(&mut interpreter, args)
.expect("issue running program");

interpreter.run(&mut universe);

Expand Down
12 changes: 9 additions & 3 deletions som-interpreter-bc/src/primitives/blocks.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,9 @@ pub mod block1 {
Value::Block(block) => block,
]);

let kind = FrameKind::Block { block: block.clone() };
let kind = FrameKind::Block {
block: block.clone(),
};

interpreter.push_frame(kind);
}
Expand Down Expand Up @@ -57,7 +59,9 @@ pub mod block2 {
argument => argument,
]);

let kind = FrameKind::Block { block: block.clone() };
let kind = FrameKind::Block {
block: block.clone(),
};

let frame = interpreter.push_frame(kind);
frame.borrow_mut().args.push(argument);
Expand Down Expand Up @@ -87,7 +91,9 @@ pub mod block3 {
argument2 => argument2,
]);

let kind = FrameKind::Block { block: block.clone() };
let kind = FrameKind::Block {
block: block.clone(),
};

let frame = interpreter.push_frame(kind);
frame.borrow_mut().args.push(argument1);
Expand Down
2 changes: 1 addition & 1 deletion som-interpreter-bc/src/primitives/integer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,11 @@ use num_traits::ToPrimitive;
use rand::distributions::Uniform;
use rand::Rng;

use crate::{expect_args, reverse};
use crate::interpreter::Interpreter;
use crate::primitives::PrimitiveFn;
use crate::universe::Universe;
use crate::value::Value;
use crate::{expect_args, reverse};

macro_rules! demote {
($frame:expr, $expr:expr) => {{
Expand Down
19 changes: 13 additions & 6 deletions som-interpreter-bc/src/primitives/string.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,11 @@ use std::convert::TryFrom;
use std::hash::Hasher;
use std::rc::Rc;

use crate::{expect_args, reverse};
use crate::interpreter::Interpreter;
use crate::primitives::PrimitiveFn;
use crate::universe::Universe;
use crate::value::Value;
use crate::{expect_args, reverse};

fn length(interpreter: &mut Interpreter, universe: &mut Universe) {
const SIGNATURE: &str = "String>>#length";
Expand Down Expand Up @@ -54,7 +54,10 @@ fn hashcode(interpreter: &mut Interpreter, universe: &mut Universe) {
// Err(err) => panic!("'{}': {}", SIGNATURE, err),
// }

frame.borrow_mut().stack.push(Value::Integer((hasher.finish() as i64).abs()))
frame
.borrow_mut()
.stack
.push(Value::Integer((hasher.finish() as i64).abs()))
}

fn is_letters(interpreter: &mut Interpreter, universe: &mut Universe) {
Expand Down Expand Up @@ -138,7 +141,10 @@ fn concatenate(interpreter: &mut Interpreter, universe: &mut Universe) {
_ => panic!("'{}': wrong types", SIGNATURE),
};

frame.borrow_mut().stack.push(Value::String(Rc::new(format!("{}{}", s1, s2))))
frame
.borrow_mut()
.stack
.push(Value::String(Rc::new(format!("{}{}", s1, s2))))
}

fn as_symbol(interpreter: &mut Interpreter, universe: &mut Universe) {
Expand All @@ -151,9 +157,10 @@ fn as_symbol(interpreter: &mut Interpreter, universe: &mut Universe) {
]);

match value {
Value::String(ref value) => {
frame.borrow_mut().stack.push(Value::Symbol(universe.intern_symbol(value.as_str())))
}
Value::String(ref value) => frame
.borrow_mut()
.stack
.push(Value::Symbol(universe.intern_symbol(value.as_str()))),
Value::Symbol(sym) => frame.borrow_mut().stack.push(Value::Symbol(sym)),
_ => panic!("'{}': invalid self type", SIGNATURE),
}
Expand Down
5 changes: 4 additions & 1 deletion som-interpreter-bc/src/primitives/system.rs
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,10 @@ fn global(interpreter: &mut Interpreter, universe: &mut Universe) {
Value::Symbol(sym) => sym,
]);

frame.borrow_mut().stack.push(universe.lookup_global(sym).unwrap_or(Value::Nil))
frame
.borrow_mut()
.stack
.push(universe.lookup_global(sym).unwrap_or(Value::Nil))
}

fn global_put(interpreter: &mut Interpreter, universe: &mut Universe) {
Expand Down
6 changes: 5 additions & 1 deletion som-interpreter-bc/src/shell.rs
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,11 @@ pub fn interactive(
}

let object_class = universe.object_class();
let class = match compiler::compile_class(&mut universe.interner, &class_def, Some(&object_class)) {
let class = match compiler::compile_class(
&mut universe.interner,
&class_def,
Some(&object_class),
) {
Some(class) => class,
None => {
writeln!(&mut stdout, "could not compile expression")?;
Expand Down
6 changes: 1 addition & 5 deletions som-interpreter-bc/src/value.rs
Original file line number Diff line number Diff line change
Expand Up @@ -64,11 +64,7 @@ impl Value {
}

/// Search for a given method for this value.
pub fn lookup_method(
&self,
universe: &Universe,
signature: Interned,
) -> Option<Rc<Method>> {
pub fn lookup_method(&self, universe: &Universe, signature: Interned) -> Option<Rc<Method>> {
self.class(universe).borrow().lookup_method(signature)
}

Expand Down

0 comments on commit 1dba6c3

Please sign in to comment.