Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
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
4 changes: 2 additions & 2 deletions crates/ast/ast.json
Original file line number Diff line number Diff line change
Expand Up @@ -210,7 +210,7 @@
"unicode": "bool"
},
"LiteralStringExpression": {
"value": "SourceAtomSetIndex"
"value": "SourceSliceIndex"
},
"ArrayExpression": "ArrayExpression",
"ArrowExpression": {
Expand Down Expand Up @@ -602,7 +602,7 @@
},
"StaticPropertyName": {
"_type": "struct",
"value": "SourceAtomSetIndex"
"value": "SourceSliceIndex"
},
"NumericLiteral": {
"_type": "struct",
Expand Down
3 changes: 1 addition & 2 deletions crates/ast/generate_ast.py
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ def to_rust_type(self, ast):
if self.name in RUST_BUILTIN_TYPES:
return self.name
if self.name == 'Token':
return "Token"
return "Token<'alloc>"
if self.name in ast.type_decls and ast.type_decls[self.name].has_lifetime:
return "{}<'alloc>".format(self.name)
return self.name
Expand Down Expand Up @@ -429,7 +429,6 @@ def emit_variant_none_call(indent, enum_name, variant_name):
write(0, "#![allow(dead_code)]")
write(0, "")
write(0, "use crate::arena;")
write(0, "use crate::source_atom_set::SourceAtomSetIndex;")
write(0, "use crate::source_slice_list::SourceSliceIndex;")
write(0, "use crate::types::*;")
write(0, "")
Expand Down
1 change: 0 additions & 1 deletion crates/ast/src/source_atom_set.rs
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,6 @@ macro_rules! for_all_common_atoms {
("while", while_, While),
("with", with, With),
("yield", yield_, Yield),
("use strict", use_strict, UseStrict),
("__proto__", __proto__, Proto),
);
}
Expand Down
2 changes: 1 addition & 1 deletion crates/emitter/src/ast_emitter.rs
Original file line number Diff line number Diff line change
Expand Up @@ -453,7 +453,7 @@ impl<'alloc, 'opt> AstEmitter<'alloc, 'opt> {
}

Expression::LiteralStringExpression { value, .. } => {
let str_index = self.emit.get_atom_gcthing_index(*value);
let str_index = self.emit.get_slice_gcthing_index(*value);
self.emit.string(str_index);
}

Expand Down
5 changes: 5 additions & 0 deletions crates/emitter/src/emitter.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
#![allow(dead_code)]

use ast::source_atom_set::SourceAtomSetIndex;
use ast::source_slice_list::SourceSliceIndex;
use byteorder::{ByteOrder, LittleEndian};
use std::cmp;
use std::collections::HashMap;
Expand Down Expand Up @@ -1384,6 +1385,10 @@ impl InstructionWriter {
}
}

pub fn get_slice_gcthing_index(&mut self, slice: SourceSliceIndex) -> GCThingIndex {
self.gcthings.push_slice(slice)
}

pub fn get_function_gcthing_index(&mut self, fun_index: ScriptStencilIndex) -> GCThingIndex {
self.gcthings.push_function(fun_index)
}
Expand Down
14 changes: 5 additions & 9 deletions crates/emitter/src/object_emitter.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
use crate::ast_emitter::AstEmitter;
use crate::emitter::EmitError;
use ast::source_atom_set::SourceAtomSetIndex;
use ast::source_slice_list::SourceSliceIndex;

/// Struct for emitting bytecode for a property where its name is string.
///
Expand All @@ -12,7 +12,7 @@ where
F: Fn(&mut AstEmitter) -> Result<(), EmitError>,
{
pub state: &'a mut ObjectEmitterState,
pub key: SourceAtomSetIndex,
pub key: SourceSliceIndex,
pub value: F,
}

Expand All @@ -34,7 +34,7 @@ where
// [stack] OBJ
}
None => {
let name_index = emitter.emit.get_atom_gcthing_index(self.key);
let name_index = emitter.emit.get_slice_gcthing_index(self.key);

(self.value)(emitter)?;
// [stack] OBJ VALUE
Expand All @@ -46,12 +46,8 @@ where
Ok(())
}

fn to_property_index(
&self,
emitter: &mut AstEmitter,
index: SourceAtomSetIndex,
) -> Option<u32> {
let s = emitter.compilation_info.atoms.get(index);
fn to_property_index(&self, emitter: &mut AstEmitter, index: SourceSliceIndex) -> Option<u32> {
let s = emitter.compilation_info.slices.get(index);
s.parse::<u32>().ok()
}
}
Expand Down
Loading