2
use std::fmt::Display;
3
use std::rc::Rc;
4
5
-use bumpalo::collections::{String, Vec};
5
use forget_estree::BinaryOperator;
6
7
use crate::{Function, IdentifierId, InstrIx, InstructionId, ScopeId, Type};
8
9
#[derive(Debug)]
11
-pub struct Instruction<'a> {
10
+pub struct Instruction {
11
pub id: InstructionId,
13
- pub value: InstructionValue<'a>,
12
+ pub value: InstructionValue,
13
}
14
16
-impl<'a> Instruction<'a> {
15
+impl Instruction {
16
pub fn each_identifier_store<F>(&mut self, mut f: F) -> ()
17
where
19
- F: FnMut(&mut LValue<'a>) -> (),
18
+ F: FnMut(&mut LValue) -> (),
19
{
20
match &mut self.value {
21
InstructionValue::DeclareContext(instr) => {
42
43
pub fn try_each_identifier_store<F, E>(&mut self, mut f: F) -> Result<(), E>
44
where
46
- F: FnMut(&mut LValue<'a>) -> Result<(), E>,
45
+ F: FnMut(&mut LValue) -> Result<(), E>,
46
{
47
match &mut self.value {
48
InstructionValue::DeclareContext(instr) => {
70
71
pub fn each_identifier_load<F>(&mut self, mut f: F) -> ()
72
where
74
- F: FnMut(&mut IdentifierOperand<'a>) -> (),
73
+ F: FnMut(&mut IdentifierOperand) -> (),
74
{
75
match &mut self.value {
76
InstructionValue::LoadLocal(instr) => f(&mut instr.place),
150
}
151
152
#[derive(Debug)]
154
-pub enum InstructionValue<'a> {
155
- Array(Array<'a>),
156
- // Await(Await<'a>),
153
+pub enum InstructionValue {
154
+ Array(Array),
155
+ // Await(Await),
156
Binary(Binary),
158
- Call(Call<'a>),
159
- // ComputedDelete(ComputedDelete<'a>),
160
- // ComputedLoad(ComputedLoad<'a>),
161
- // ComputedStore(ComputedStore<'a>),
162
- // Debugger(Debugger<'a>),
163
- DeclareContext(DeclareContext<'a>),
164
- DeclareLocal(DeclareLocal<'a>),
165
- // Destructure(Destructure<'a>),
166
- Function(FunctionExpression<'a>),
167
- JSXElement(JSXElement<'a>),
168
- // JsxFragment(JsxFragment<'a>),
169
- // JsxText(JsxText<'a>),
157
+ Call(Call),
158
+ // ComputedDelete(ComputedDelete),
159
+ // ComputedLoad(ComputedLoad),
160
+ // ComputedStore(ComputedStore),
161
+ // Debugger(Debugger),
162
+ DeclareContext(DeclareContext),
163
+ DeclareLocal(DeclareLocal),
164
+ // Destructure(Destructure),
165
+ Function(FunctionExpression),
166
+ JSXElement(JSXElement),
167
+ // JsxFragment(JsxFragment),
168
+ // JsxText(JsxText),
169
LoadContext(LoadContext),
171
- LoadGlobal(LoadGlobal<'a>),
172
- LoadLocal(LoadLocal<'a>),
173
- // MethodCall(MethodCall<'a>),
174
- // New(New<'a>),
175
- // NextIterable(NextIterable<'a>),
176
- // Object(Object<'a>),
177
- Primitive(Primitive<'a>),
178
- // PropertyDelete(PropertyDelete<'a>),
179
- // PropertyLoad(PropertyLoad<'a>),
180
- // PropertyStore(PropertyStore<'a>),
181
- // RegExp(RegExp<'a>),
182
- // StoreContext(StoreContext<'a>),
183
- StoreLocal(StoreLocal<'a>),
184
- // TaggedTemplate(TaggedTemplate<'a>),
185
- // Template(Template<'a>),
186
- // TypeCast(TypeCast<'a>),
187
- // Unary(Unary<'a>),
170
+ LoadGlobal(LoadGlobal),
171
+ LoadLocal(LoadLocal),
172
+ // MethodCall(MethodCall),
173
+ // New(New),
174
+ // NextIterable(NextIterable),
175
+ // Object(Object),
176
+ Primitive(Primitive),
177
+ // PropertyDelete(PropertyDelete),
178
+ // PropertyLoad(PropertyLoad),
179
+ // PropertyStore(PropertyStore),
180
+ // RegExp(RegExp),
181
+ // StoreContext(StoreContext),
182
+ StoreLocal(StoreLocal),
183
+ // TaggedTemplate(TaggedTemplate),
184
+ // Template(Template),
185
+ // TypeCast(TypeCast),
186
+ // Unary(Unary),
187
Tombstone,
188
}
189
190
#[derive(Debug)]
192
-pub struct Array<'a> {
193
- pub elements: Vec<'a, Option<PlaceOrSpread>>,
191
+pub struct Array {
192
+ pub elements: Vec<Option<PlaceOrSpread>>,
193
}
194
195
#[derive(Debug)]
206
}
207
208
#[derive(Debug)]
210
-pub struct Call<'a> {
209
+pub struct Call {
210
pub callee: Operand,
212
- pub arguments: Vec<'a, PlaceOrSpread>,
211
+ pub arguments: Vec<PlaceOrSpread>,
212
}
213
214
#[derive(Debug)]
216
-pub struct FunctionExpression<'a> {
217
- pub dependencies: Vec<'a, Operand>,
218
- pub lowered_function: Box<Function<'a>>,
215
+pub struct FunctionExpression {
216
+ pub dependencies: Vec<Operand>,
217
+ pub lowered_function: Box<Function>,
218
}
219
220
#[derive(Debug, Clone, PartialEq, Eq)]
222
-pub struct Primitive<'a> {
223
- pub value: PrimitiveValue<'a>,
221
+pub struct Primitive {
222
+ pub value: PrimitiveValue,
223
}
224
225
#[derive(Debug, Clone, PartialEq, Eq)]
227
-pub enum PrimitiveValue<'a> {
226
+pub enum PrimitiveValue {
227
Boolean(bool),
228
Null,
229
Number(Number),
231
- String(String<'a>),
230
+ String(String),
231
Undefined,
232
}
233
235
-impl<'a> PrimitiveValue<'a> {
234
+impl PrimitiveValue {
235
pub fn is_truthy(&self) -> bool {
236
match &self {
237
PrimitiveValue::Boolean(value) => *value,
369
}
370
371
#[derive(Debug)]
373
-pub struct LoadLocal<'a> {
374
- pub place: IdentifierOperand<'a>,
372
+pub struct LoadLocal {
373
+ pub place: IdentifierOperand,
374
}
375
376
#[derive(Debug)]
379
}
380
381
#[derive(Debug, PartialEq, Eq, Clone)]
383
-pub struct LoadGlobal<'a> {
384
- pub name: String<'a>,
382
+pub struct LoadGlobal {
383
+ pub name: String,
384
}
385
386
#[derive(Debug)]
388
-pub struct DeclareLocal<'a> {
389
- pub lvalue: LValue<'a>,
387
+pub struct DeclareLocal {
388
+ pub lvalue: LValue,
389
}
390
391
#[derive(Debug)]
393
-pub struct DeclareContext<'a> {
394
- pub lvalue: LValue<'a>, // note: kind must be InstructionKind::Let
392
+pub struct DeclareContext {
393
+ pub lvalue: LValue, // note: kind must be InstructionKind::Let
394
}
395
396
#[derive(Debug)]
398
-pub struct StoreLocal<'a> {
399
- pub lvalue: LValue<'a>,
397
+pub struct StoreLocal {
398
+ pub lvalue: LValue,
399
pub value: Operand,
400
}
401
402
#[derive(Debug)]
404
-pub struct JSXElement<'a> {
403
+pub struct JSXElement {
404
pub tag: Operand,
406
- pub props: Vec<'a, JSXAttribute<'a>>,
407
- pub children: Option<Vec<'a, Operand>>,
405
+ pub props: Vec<JSXAttribute>,
406
+ pub children: Option<Vec<Operand>>,
407
}
408
409
#[derive(Debug)]
411
-pub enum JSXAttribute<'a> {
410
+pub enum JSXAttribute {
411
Spread { argument: Operand },
413
- Attribute { name: String<'a>, value: Operand },
412
+ Attribute { name: String, value: Operand },
413
}
414
415
#[derive(Clone, Debug)]
419
}
420
421
#[derive(Clone, Debug)]
423
-pub struct IdentifierOperand<'a> {
424
- pub identifier: Identifier<'a>,
422
+pub struct IdentifierOperand {
423
+ pub identifier: Identifier,
424
pub effect: Option<Effect>,
425
}
426
427
#[derive(Debug)]
429
-pub struct LValue<'a> {
430
- pub identifier: IdentifierOperand<'a>,
428
+pub struct LValue {
429
+ pub identifier: IdentifierOperand,
430
pub kind: InstructionKind,
431
}
432
502
}
503
504
#[derive(Clone, Debug)]
506
-pub struct Identifier<'a> {
505
+pub struct Identifier {
506
/// Uniquely identifiers this identifier
507
pub id: IdentifierId,
509
- pub name: Option<String<'a>>,
508
+ pub name: Option<String>,
509
510
pub data: Rc<RefCell<IdentifierData>>,
511
}