Skip to content

Commit

Permalink
Work on docs
Browse files Browse the repository at this point in the history
  • Loading branch information
cassiebeckley committed Jun 13, 2015
1 parent 9e0865b commit 9945885
Show file tree
Hide file tree
Showing 5 changed files with 28 additions and 11 deletions.
4 changes: 4 additions & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,10 @@ name = "ack"
version = "0.1.0"
authors = ["David Beckley <[email protected]>"]

[[bin]]
name = "ack"
doc = false

[dependencies]
maplit = "0.1.1"
libc = "0.1"
Expand Down
14 changes: 14 additions & 0 deletions src/interpret.rs
Original file line number Diff line number Diff line change
Expand Up @@ -21,13 +21,27 @@ impl GetFromResult for JSResult {
}
}

/// Contains the state for an interpreter thread
#[derive(Debug, Clone)]
pub struct Context {
pub this: Value,
pub local: Object,
pub global: Object
}

impl Context {
/// Creates a top-level context
///
/// `this`, `local`, and `global` are all set to `obj`.
pub fn new(obj: Object) -> Context {
Context {
this: Value::Object(obj.clone()),
local: obj.clone(),
global: obj
}
}
}

#[derive(Debug, Clone)]
pub struct UserFunction {
pub id: Option<ast::Identifier>,
Expand Down
2 changes: 2 additions & 0 deletions src/lib.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
//! Embeddable JavaScript interpreter.
#[macro_use]
extern crate maplit;

Expand Down
4 changes: 2 additions & 2 deletions src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ fn is_interactive() -> bool {
}

fn start_repl() {
let mut ack = Ack::new();
let mut ack = Ack::create_stdlib();

loop {
print!(">>> ");
Expand Down Expand Up @@ -63,7 +63,7 @@ fn run_script<T: io::Read>(mut file: T) -> bool {
s
};

let result = Ack::new().eval(&source);
let result = Ack::create_stdlib().eval(&source);

if let &Err(ref e) = &result {
let mut t = term::stderr().unwrap();
Expand Down
15 changes: 6 additions & 9 deletions src/runtime.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,15 +9,12 @@ pub type Ack = interpret::Context;

/// A high-level interface for the interpreter
impl Ack {
pub fn new() -> Ack {
let obj = create_stdlib();
Ack {
this: interpret::Value::Object(obj.clone()),
local: obj.clone(),
global: obj.clone()
}
/// Create a context with the JavaScript standard library
pub fn create_stdlib() -> Ack {
Context::new(create_stdlib())
}

/// Parse and evaluate `source` in this context
pub fn eval(&mut self, source: &str) -> JSResult {
let parsed = parser::parse(source);

Expand All @@ -31,8 +28,8 @@ impl Ack {
}
}

/// Create a default global object
pub fn create_stdlib() -> interpret::Object {
/// This is private, anyway
fn create_stdlib() -> interpret::Object {
use interpret::*;

let function_prototype = Object::new();
Expand Down

0 comments on commit 9945885

Please sign in to comment.