Skip to content

Commit bcff25d

Browse files
committed
The big rewrite
1 parent 93a16eb commit bcff25d

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

139 files changed

+7182
-11322
lines changed

Cargo.lock

+526-58
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Cargo.toml

+13-19
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,14 @@
1-
[package]
2-
authors = ["delskayn <[email protected]>"]
3-
edition = "2018"
4-
name = "js"
5-
version = "0.1.0"
1+
[workspace]
2+
members = [
3+
"crates/token",
4+
"crates/lexer",
5+
"crates/common",
6+
"crates/compiler",
7+
"crates/parser",
8+
"crates/ast",
9+
"crates/runtime",
10+
"toyjs"
11+
]
612

7-
[dependencies]
8-
unicode-xid = "0.2.0"
9-
log = "0.4.8"
10-
fxhash = "0.2.1"
11-
lexical-core = "0.7.4"
12-
gc = "0.3.6"
13-
14-
[[example]]
15-
name = "ecma"
16-
path = "examples/ecma.rs"
17-
18-
[dev-dependencies]
19-
walkdir = "2.3.1"
20-
env_logger = "0.7.1"
13+
[profile.release]
14+
debug = true

README.md

-86
This file was deleted.

crates/ast/.gitignore

Whitespace-only changes.

crates/ast/Cargo.toml

+11
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
[package]
2+
name = "toyjs_ast"
3+
version = "0.1.0"
4+
authors = ["Mees Delzenne <[email protected]>"]
5+
edition = "2018"
6+
7+
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
8+
9+
[dependencies]
10+
bumpalo = { version = "3.4.0", features = ["boxed","collections"]}
11+
common = { package="toyjs_common",path = "../common/" }

crates/ast/src/lib.rs

+141
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,141 @@
1+
use bumpalo::{boxed::Box, collections::Vec};
2+
use common::interner::StringId;
3+
4+
mod variables;
5+
pub use variables::*;
6+
7+
#[derive(Debug, PartialEq)]
8+
pub struct Script<'a>(pub Vec<'a, Stmt<'a>>);
9+
10+
#[derive(Debug, PartialEq)]
11+
pub enum Stmt<'a> {
12+
Empty,
13+
Let(VariableId, Option<Expr<'a>>),
14+
Var(VariableId, Option<Expr<'a>>),
15+
Const(VariableId, Vec<'a, Expr<'a>>),
16+
Expr(Vec<'a, Expr<'a>>),
17+
Break,
18+
Continue,
19+
If(Vec<'a, Expr<'a>>, Box<'a, Stmt<'a>>),
20+
While(Vec<'a, Expr<'a>>, Box<'a, Stmt<'a>>),
21+
DoWhile(Box<'a, Stmt<'a>>, Vec<'a, Expr<'a>>),
22+
For,
23+
Block(Vec<'a, Stmt<'a>>),
24+
}
25+
26+
#[derive(Debug, PartialEq)]
27+
pub enum BinaryOperator<'a> {
28+
Ternary(Box<'a, Expr<'a>>),
29+
NullCoalessing(Box<'a, Expr<'a>>),
30+
TenaryNull,
31+
In,
32+
InstanceOf,
33+
Add,
34+
Subtract,
35+
Multiply,
36+
Divide,
37+
Modulo,
38+
Exponentiate,
39+
ShiftLeft,
40+
ShiftRight,
41+
ShiftRightUnsigned,
42+
BitwiseAnd,
43+
BitwiseXor,
44+
BitwiseOr,
45+
Less,
46+
LessEqual,
47+
Greater,
48+
GreaterEqual,
49+
Equal,
50+
StrictEqual,
51+
NotEqual,
52+
StrictNotEqual,
53+
And,
54+
Or,
55+
Index,
56+
}
57+
58+
#[derive(Debug, PartialEq)]
59+
pub enum AssignOperator {
60+
Assign,
61+
Add,
62+
Subtract,
63+
Multiply,
64+
Divide,
65+
Modulo,
66+
Exponentiate,
67+
ShiftLeft,
68+
ShiftRight,
69+
ShiftRightUnsigned,
70+
BitwiseAnd,
71+
BitwiseXor,
72+
BitwiseOr,
73+
}
74+
75+
#[derive(Debug, PartialEq)]
76+
pub enum PrefixOperator {
77+
Not,
78+
Delete,
79+
Void,
80+
TypeOf,
81+
Positive,
82+
Negative,
83+
BinaryNot,
84+
AddOne,
85+
SubtractOne,
86+
}
87+
88+
#[derive(Debug, PartialEq)]
89+
pub enum PostfixOperator<'a> {
90+
AddOne,
91+
SubtractOne,
92+
Dot(StringId),
93+
Index(Box<'a, Expr<'a>>),
94+
}
95+
96+
#[derive(Debug, PartialEq)]
97+
pub enum Expr<'a> {
98+
Binary(Box<'a, Expr<'a>>, BinaryOperator<'a>, Box<'a, Expr<'a>>),
99+
Assign(Box<'a, Expr<'a>>, AssignOperator, Box<'a, Expr<'a>>),
100+
UnaryPrefix(PrefixOperator, Box<'a, Expr<'a>>),
101+
UnaryPostfix(Box<'a, Expr<'a>>, PostfixOperator<'a>),
102+
Prime(PrimeExpr<'a>),
103+
}
104+
105+
impl<'a> Expr<'a> {
106+
pub fn is_assignable(&self) -> bool {
107+
match *self {
108+
Expr::Prime(ref x) => match x {
109+
PrimeExpr::Variable(_) => true,
110+
PrimeExpr::Literal(_) => false,
111+
PrimeExpr::Covered(_) => false,
112+
PrimeExpr::Object(_) => false,
113+
},
114+
Expr::Assign(..) => false,
115+
Expr::Binary(..) => false,
116+
Expr::UnaryPrefix(..) => false,
117+
Expr::UnaryPostfix(_, ref op) => match *op {
118+
PostfixOperator::Dot(_) => true,
119+
PostfixOperator::Index(_) => true,
120+
PostfixOperator::AddOne => false,
121+
PostfixOperator::SubtractOne => false,
122+
},
123+
}
124+
}
125+
}
126+
127+
#[derive(Debug, PartialEq)]
128+
pub enum PrimeExpr<'a> {
129+
Literal(Literal),
130+
Variable(VariableId),
131+
Covered(Vec<'a, Expr<'a>>),
132+
Object(Vec<'a, (StringId, Expr<'a>)>),
133+
}
134+
135+
#[derive(Debug, Clone, Copy, PartialEq)]
136+
pub enum Literal {
137+
String(StringId),
138+
Integer(i32),
139+
Float(f64),
140+
Boolean(bool),
141+
}

0 commit comments

Comments
 (0)