-
-
Notifications
You must be signed in to change notification settings - Fork 414
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Co-authored-by: Iban Eguia <[email protected]>
- Loading branch information
Showing
50 changed files
with
1,404 additions
and
760 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
use super::{Executable, Interpreter}; | ||
use crate::{ | ||
builtins::{ResultValue, Value}, | ||
syntax::ast::node::If, | ||
}; | ||
use std::borrow::Borrow; | ||
|
||
impl Executable for If { | ||
fn run(&self, interpreter: &mut Interpreter) -> ResultValue { | ||
Ok(if self.cond().run(interpreter)?.borrow().is_true() { | ||
self.body().run(interpreter)? | ||
} else { | ||
match self.else_node() { | ||
Some(ref else_e) => else_e.run(interpreter)?, | ||
None => Value::undefined(), | ||
} | ||
}) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
use super::{Executable, Interpreter}; | ||
use crate::{ | ||
builtins::value::ResultValue, | ||
syntax::ast::node::{GetConstField, GetField}, | ||
}; | ||
|
||
impl Executable for GetConstField { | ||
fn run(&self, interpreter: &mut Interpreter) -> ResultValue { | ||
let mut obj = self.obj().run(interpreter)?; | ||
if obj.get_type() != "object" || obj.get_type() != "symbol" { | ||
obj = interpreter | ||
.to_object(&obj) | ||
.expect("failed to convert to object"); | ||
} | ||
|
||
Ok(obj.get_field(self.field())) | ||
} | ||
} | ||
|
||
impl Executable for GetField { | ||
fn run(&self, interpreter: &mut Interpreter) -> ResultValue { | ||
let obj = self.obj().run(interpreter)?; | ||
let field = self.field().run(interpreter)?; | ||
|
||
Ok(obj.get_field(field.to_string())) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
//! Object execution. | ||
use super::{Executable, Interpreter}; | ||
use crate::{ | ||
builtins::value::{ResultValue, Value}, | ||
syntax::ast::node::MethodDefinitionKind, | ||
syntax::ast::node::{Object, PropertyDefinition}, | ||
}; | ||
|
||
use std::borrow::Borrow; | ||
|
||
impl Executable for Object { | ||
fn run(&self, interpreter: &mut Interpreter) -> ResultValue { | ||
let global_val = &interpreter | ||
.realm() | ||
.environment | ||
.get_global_object() | ||
.expect("Could not get the global object"); | ||
let obj = Value::new_object(Some(global_val)); | ||
|
||
// TODO: Implement the rest of the property types. | ||
for property in self.properties().iter() { | ||
match property { | ||
PropertyDefinition::Property(key, value) => { | ||
obj.borrow() | ||
.set_field(&key.clone(), value.run(interpreter)?); | ||
} | ||
PropertyDefinition::MethodDefinition(kind, name, func) => { | ||
if let MethodDefinitionKind::Ordinary = kind { | ||
obj.borrow() | ||
.set_field(&name.clone(), func.run(interpreter)?); | ||
} else { | ||
// TODO: Implement other types of MethodDefinitionKinds. | ||
unimplemented!("other types of property method definitions."); | ||
} | ||
} | ||
i => unimplemented!("{:?} type of property", i), | ||
} | ||
} | ||
|
||
Ok(obj) | ||
} | ||
} |
Oops, something went wrong.