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

feat(heap): Component based heap #22

Merged
merged 71 commits into from
Jul 23, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
71 commits
Select commit Hold shift + click to select a range
db6c012
use better methods for tokenizing
sno2 Jun 5, 2023
60793b7
implement comments
sno2 Jun 5, 2023
cddc6fe
basic pratt parser
sno2 Jun 6, 2023
9cc1cc7
implement parens/funcs/indexes
sno2 Jun 6, 2023
591503a
implement func decls
sno2 Jun 6, 2023
17336d7
fix keyword cases
sno2 Jun 6, 2023
57b31b2
array lits and better null node impl
sno2 Jun 6, 2023
34c4dd4
null, true, false
sno2 Jun 6, 2023
42ffc11
ternary and line ending fix
sno2 Jun 6, 2023
f7b1acb
implement for loop
sno2 Jun 6, 2023
155bca3
while loops
sno2 Jun 6, 2023
294a95a
implement labels
sno2 Jun 6, 2023
ecaca22
error on lexical stmts with labels
sno2 Jun 6, 2023
4302135
implement if statements
sno2 Jun 6, 2023
91ef5ac
implement switch statements
sno2 Jun 6, 2023
00060dc
add catch for early exits
sno2 Jun 6, 2023
ee7193a
implement `new` for some cases
sno2 Jun 6, 2023
3bccb81
support object literals
sno2 Jun 6, 2023
bee441b
normalize parser components
sno2 Jun 6, 2023
b1a5b3b
array destructuring
sno2 Jun 6, 2023
99c2162
implement destructuring validation in expressions
sno2 Jun 7, 2023
8a25e55
validate member expressions
sno2 Jun 7, 2023
d60b514
complete member validation
sno2 Jun 7, 2023
ddca11e
support all basic arrow functions
sno2 Jun 7, 2023
d6d918a
support more operators
sno2 Jun 7, 2023
cdaa857
implement all ops
sno2 Jun 7, 2023
8628c22
forgot binary or
sno2 Jun 7, 2023
eedcb2e
fix backstepping on expression statements
sno2 Jun 7, 2023
923e1a2
follow right associativity rules
sno2 Jun 7, 2023
233af4d
implement full? number parsing
sno2 Jun 7, 2023
28d596e
support multiple variable initialization
sno2 Jun 7, 2023
3ace1d8
implement try block
sno2 Jun 7, 2023
6d4c03f
implement unary ops with correct pow precedence
sno2 Jun 7, 2023
c5cf5a3
convert to using oxc parser
sno2 Jun 10, 2023
ec04293
Fill match arms
aapoalas Jun 21, 2023
7580332
Component based heap
aapoalas Jun 21, 2023
2dbd5e0
Move stuff around
Jun 25, 2023
cb9b99d
Begin implementing heap initialization, synchronous imitation of conc…
aapoalas Jun 26, 2023
a6436e5
Make function heap data use indirect object data referencing for own …
aapoalas Jul 14, 2023
02a0de2
Value HeapTrace handle functions
aapoalas Jul 14, 2023
ad468b6
FunctionIndex
aapoalas Jul 14, 2023
906cf66
Fix ObjectIndex in FunctionHeapData and PropertyDescriptor variant na…
aapoalas Jul 14, 2023
0972a20
Deduplicate root and unroot, format
aapoalas Jul 14, 2023
d13ab48
StringHeapData::len()
aapoalas Jul 14, 2023
a48ffd5
Disjointed and confused movement forward, back and sideways
aapoalas Jul 14, 2023
1022001
Move heap data inside heap subfolder, prepare full list of builtins
aapoalas Jul 19, 2023
3553607
Make builtin object indexes an enum, unify heap initialization strategy
aapoalas Jul 20, 2023
11d2544
Move ObjectHeapData to heap/object.rs
aapoalas Jul 20, 2023
20a0882
Move StringHeapData into heap/string.rs
aapoalas Jul 20, 2023
84caeef
Move rest of HeapData structs into appropriate files, hide away some …
aapoalas Jul 20, 2023
c7167bb
Implement well-known symbols
aapoalas Jul 21, 2023
cb18ce0
Fix
aapoalas Jul 21, 2023
8569261
Function heap initialization
aapoalas Jul 21, 2023
ee44101
Implement boolean heap init
aapoalas Jul 21, 2023
e608638
Number heap init
aapoalas Jul 21, 2023
3a95157
Fix
aapoalas Jul 21, 2023
3041bda
Object heap
aapoalas Jul 21, 2023
e53ccb8
Fix heap tracing through accessor descriptors
aapoalas Jul 21, 2023
592afc3
Error heap, fix compile
aapoalas Jul 21, 2023
bda8f52
Change JsBindingFunction return type to use Result
aapoalas Jul 21, 2023
a3561b2
Some stuff
aapoalas Jul 21, 2023
c62f265
Comment
aapoalas Jul 22, 2023
77b7133
Math heap
aapoalas Jul 22, 2023
7cff89f
Begin implementing tests, extract SmallAsciiString slice into a struct
aapoalas Jul 22, 2023
e26156d
Change SmallAsciiString to StackString, allow UTF-8 except for null b…
aapoalas Jul 23, 2023
07c2f9b
Add UTF-16 length method to StackString
aapoalas Jul 23, 2023
d42ed48
DateHeapData
aapoalas Jul 23, 2023
14e523a
Value::Date
aapoalas Jul 23, 2023
6fc6a29
RegExp
aapoalas Jul 23, 2023
2590c4f
Array heap
aapoalas Jul 23, 2023
f4ccca1
Comment on SmallVec usage
aapoalas Jul 23, 2023
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
3 changes: 3 additions & 0 deletions .editorconfig
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
[*.{rs}]
indent_style = space
indent_size = 4
5 changes: 2 additions & 3 deletions Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
[workspace]
members = [
"parser",
"nova_cli",
"nova_vm",
"common",
"tokenizer",
"ast",
"wasm"
]
45 changes: 0 additions & 45 deletions ast/src/lib.rs

This file was deleted.

1 change: 1 addition & 0 deletions code.js
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
var asd = "foobar"
6 changes: 5 additions & 1 deletion parser/Cargo.toml → nova_cli/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,8 +1,12 @@
[package]
name = "parser"
name = "nova_cli"
version = "0.1.0"
edition = "2021"

# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html

[dependencies]
clap = { version = "4.3", features = ["derive"] }
oxc_parser = "0.0.6"
oxc_ast = "0.0.6"
nova_vm = { path = "../nova_vm" }
64 changes: 64 additions & 0 deletions nova_cli/src/main.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
use clap::{Parser as ClapParser, Subcommand};
use nova_vm::{heap::Heap, VM};
use oxc_ast::SourceType;
use oxc_parser::Parser;

/// A JavaScript engine
#[derive(Debug, ClapParser)] // requires `derive` feature
#[command(name = "nova")]
#[command(about = "A JavaScript engine", long_about = None)]
struct Cli {
#[command(subcommand)]
command: Command,
}

#[derive(Debug, Subcommand)]
enum Command {
/// Parses a file and logs out the AST
Parse {
/// The path of the file to parse
path: String,
},

/// Evaluates a file
Eval {
/// The file to evaluate
path: String,
},
}

fn main() -> Result<(), Box<dyn std::error::Error>> {
let args = Cli::parse();

match args.command {
Command::Parse { path } => {
let file = std::fs::read_to_string(path)?;
let allocator = Default::default();
let source_type: SourceType = Default::default();
let parser = Parser::new(&allocator, &file, source_type.with_typescript(false));
let result = parser.parse();

println!("{:?}", result.program);
}
Command::Eval { path } => {
let file = std::fs::read_to_string(path)?;
let allocator = Default::default();
let source_type: SourceType = Default::default();
let parser = Parser::new(&allocator, &file, source_type.with_typescript(false));
let result = parser.parse();

let mut vm = VM {
source: &file,
pc: 0,
instructions: Vec::new(),
heap: Heap::new(),
};

vm.load_program(result.program);
println!("{:?}", vm.instructions);
vm.interpret();
}
}

Ok(())
}
7 changes: 5 additions & 2 deletions ast/Cargo.toml → nova_vm/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,9 +1,12 @@
[package]
name = "ast"
name = "nova_vm"
version = "0.1.0"
edition = "2021"

# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html

[dependencies]
serde = { version = "1.0.152", features = ["derive"] }
gc = { version = "0.4", features = ["derive"] }
wtf8 = "0.1"
oxc_parser = "0.0.6"
oxc_ast = "0.0.6"
40 changes: 40 additions & 0 deletions nova_vm/src/dyn_ObjectHeapData
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
pub trait ObjectHeapData: Trace + Debug {
fn get_prototype_of(&self, heap: &mut Heap) -> JsResult<Option<ObjectIndex>>;
fn set_prototype_of(&self, heap: &mut Heap, prototype: Option<ObjectIndex>) -> JsResult<bool>;
fn is_extensible(&self, heap: &mut Heap) -> JsResult<bool>;
fn prevent_extensions(&self, heap: &mut Heap) -> JsResult<bool>;
fn get_own_property(
&self,
heap: &mut Heap,
key: PropertyKey,
) -> JsResult<Option<PropertyDescriptor>>;
fn define_own_property(
&self,
heap: &mut Heap,
key: PropertyKey,
descriptor: PropertyDescriptor,
) -> JsResult<bool>;
fn has_property(&self, heap: &mut Heap, key: PropertyKey) -> JsResult<bool>;
fn get(&self, heap: &mut Heap, key: PropertyKey, receiver: &Value) -> JsResult<Value>;
fn set(
&self,
heap: &mut Heap,
key: PropertyKey,
value: Value,
receiver: &Value,
) -> JsResult<bool>;
fn delete(&self, heap: &mut Heap, key: PropertyKey) -> JsResult<bool>;
fn own_property_keys(&self, heap: &mut Heap) -> JsResult<Vec<PropertyKey>>;

// Tracing helpers
fn get_strong_references(&self) -> Vec<Value>;
fn get_weak_references(&self) -> Vec<Value>;
}

pub trait FunctionHeapData: ObjectHeapData {
fn call(&self, this: &Value, args: &[Value]) -> JsResult<Value>;
}

pub trait ConstructorHeapData: FunctionHeapData {
fn construct(&self, args: &[Value], target: ObjectIndex) -> JsResult<Value>;
}
Loading
Loading