Bug 1639772 - Update jsparagus and use ImmutableScriptFlags directly. r=yulia

Differential Revision: https://phabricator.services.mozilla.com/D76267
This commit is contained in:
Tooru Fujisawa 2020-05-29 13:30:51 +00:00
Родитель 9c097cff23
Коммит ff738e2546
24 изменённых файлов: 846 добавлений и 795 удалений

Просмотреть файл

@ -30,7 +30,7 @@ rev = "77a7f5eb12a8d93f2bd71bd4d844405e06743365"
[source."https://github.com/mozilla-spidermonkey/jsparagus"]
git = "https://github.com/mozilla-spidermonkey/jsparagus"
replace-with = "vendored-sources"
rev = "5a49cf936b073da15ba67ce3700fed616960dfb8"
rev = "efc1291d05e5ba8dbb4bd1197937a0291e72742c"
[source."https://github.com/kvark/spirv_cross"]
branch = "wgpu3"

16
Cargo.lock сгенерированный
Просмотреть файл

@ -2367,7 +2367,7 @@ dependencies = [
[[package]]
name = "jsparagus"
version = "0.1.0"
source = "git+https://github.com/mozilla-spidermonkey/jsparagus?rev=5a49cf936b073da15ba67ce3700fed616960dfb8#5a49cf936b073da15ba67ce3700fed616960dfb8"
source = "git+https://github.com/mozilla-spidermonkey/jsparagus?rev=efc1291d05e5ba8dbb4bd1197937a0291e72742c#efc1291d05e5ba8dbb4bd1197937a0291e72742c"
dependencies = [
"jsparagus-ast",
"jsparagus-emitter",
@ -2381,7 +2381,7 @@ dependencies = [
[[package]]
name = "jsparagus-ast"
version = "0.1.0"
source = "git+https://github.com/mozilla-spidermonkey/jsparagus?rev=5a49cf936b073da15ba67ce3700fed616960dfb8#5a49cf936b073da15ba67ce3700fed616960dfb8"
source = "git+https://github.com/mozilla-spidermonkey/jsparagus?rev=efc1291d05e5ba8dbb4bd1197937a0291e72742c#efc1291d05e5ba8dbb4bd1197937a0291e72742c"
dependencies = [
"bumpalo",
"indexmap",
@ -2392,7 +2392,7 @@ dependencies = [
[[package]]
name = "jsparagus-emitter"
version = "0.1.0"
source = "git+https://github.com/mozilla-spidermonkey/jsparagus?rev=5a49cf936b073da15ba67ce3700fed616960dfb8#5a49cf936b073da15ba67ce3700fed616960dfb8"
source = "git+https://github.com/mozilla-spidermonkey/jsparagus?rev=efc1291d05e5ba8dbb4bd1197937a0291e72742c#efc1291d05e5ba8dbb4bd1197937a0291e72742c"
dependencies = [
"bumpalo",
"byteorder",
@ -2405,7 +2405,7 @@ dependencies = [
[[package]]
name = "jsparagus-generated-parser"
version = "0.1.0"
source = "git+https://github.com/mozilla-spidermonkey/jsparagus?rev=5a49cf936b073da15ba67ce3700fed616960dfb8#5a49cf936b073da15ba67ce3700fed616960dfb8"
source = "git+https://github.com/mozilla-spidermonkey/jsparagus?rev=efc1291d05e5ba8dbb4bd1197937a0291e72742c#efc1291d05e5ba8dbb4bd1197937a0291e72742c"
dependencies = [
"bumpalo",
"jsparagus-ast",
@ -2415,12 +2415,12 @@ dependencies = [
[[package]]
name = "jsparagus-json-log"
version = "0.1.0"
source = "git+https://github.com/mozilla-spidermonkey/jsparagus?rev=5a49cf936b073da15ba67ce3700fed616960dfb8#5a49cf936b073da15ba67ce3700fed616960dfb8"
source = "git+https://github.com/mozilla-spidermonkey/jsparagus?rev=efc1291d05e5ba8dbb4bd1197937a0291e72742c#efc1291d05e5ba8dbb4bd1197937a0291e72742c"
[[package]]
name = "jsparagus-parser"
version = "0.1.0"
source = "git+https://github.com/mozilla-spidermonkey/jsparagus?rev=5a49cf936b073da15ba67ce3700fed616960dfb8#5a49cf936b073da15ba67ce3700fed616960dfb8"
source = "git+https://github.com/mozilla-spidermonkey/jsparagus?rev=efc1291d05e5ba8dbb4bd1197937a0291e72742c#efc1291d05e5ba8dbb4bd1197937a0291e72742c"
dependencies = [
"bumpalo",
"jsparagus-ast",
@ -2432,7 +2432,7 @@ dependencies = [
[[package]]
name = "jsparagus-scope"
version = "0.1.0"
source = "git+https://github.com/mozilla-spidermonkey/jsparagus?rev=5a49cf936b073da15ba67ce3700fed616960dfb8#5a49cf936b073da15ba67ce3700fed616960dfb8"
source = "git+https://github.com/mozilla-spidermonkey/jsparagus?rev=efc1291d05e5ba8dbb4bd1197937a0291e72742c#efc1291d05e5ba8dbb4bd1197937a0291e72742c"
dependencies = [
"indexmap",
"jsparagus-ast",
@ -2442,7 +2442,7 @@ dependencies = [
[[package]]
name = "jsparagus-stencil"
version = "0.1.0"
source = "git+https://github.com/mozilla-spidermonkey/jsparagus?rev=5a49cf936b073da15ba67ce3700fed616960dfb8#5a49cf936b073da15ba67ce3700fed616960dfb8"
source = "git+https://github.com/mozilla-spidermonkey/jsparagus?rev=efc1291d05e5ba8dbb4bd1197937a0291e72742c#efc1291d05e5ba8dbb4bd1197937a0291e72742c"
dependencies = [
"jsparagus-ast",
]

Просмотреть файл

@ -72,39 +72,16 @@ class SmooshScriptStencil : public ScriptStencil {
UniquePtr<ImmutableScriptData> immutableData) {
using ImmutableFlags = js::ImmutableScriptFlagsEnum;
// A global script is a top-level context.
bool isTopLevelContext = true;
const JS::ReadOnlyCompileOptions& options = compilationInfo_.options;
// The "input" flags are derived from options.
immutableFlags.setFlag(ImmutableFlags::IsForEval, result_.is_for_eval);
immutableFlags.setFlag(ImmutableFlags::IsModule, result_.is_module);
immutableFlags.setFlag(ImmutableFlags::IsFunction, false);
immutableFlags = result_.immutable_flags;
// FIXME: The following flags should be set in jsparagus.
immutableFlags.setFlag(ImmutableFlags::SelfHosted, options.selfHostingMode);
immutableFlags.setFlag(ImmutableFlags::ForceStrict,
options.forceStrictMode());
immutableFlags.setFlag(ImmutableFlags::HasNonSyntacticScope,
result_.has_non_syntactic_scope);
if (isTopLevelContext) {
immutableFlags.setFlag(ImmutableFlags::NoScriptRval,
options.noScriptRval);
immutableFlags.setFlag(ImmutableFlags::TreatAsRunOnce, options.isRunOnce);
}
// The parser-generated flags.
immutableFlags.setFlag(ImmutableFlags::Strict, result_.strict);
immutableFlags.setFlag(ImmutableFlags::HasModuleGoal,
result_.has_module_goal);
immutableFlags.setFlag(ImmutableFlags::HasInnerFunctions, false);
immutableFlags.setFlag(ImmutableFlags::HasDirectEval, false);
immutableFlags.setFlag(ImmutableFlags::BindingsAccessedDynamically,
result_.bindings_accessed_dynamically);
immutableFlags.setFlag(ImmutableFlags::HasCallSiteObj,
result_.has_call_site_obj);
// TODO: The parser-generated flags for functions.
immutableFlags.setFlag(ImmutableFlags::NeedsFunctionEnvironmentObjects,
result_.needs_function_environment_objects);
immutableFlags.setFlag(ImmutableFlags::NoScriptRval, options.noScriptRval);
immutableFlags.setFlag(ImmutableFlags::TreatAsRunOnce, options.isRunOnce);
immutableScriptData = std::move(immutableData);
@ -432,11 +409,13 @@ JSScript* Smoosh::compileGlobalScript(CompilationInfo& compilationInfo,
return nullptr;
}
bool isFunction = false;
int funLength = 0; // Smoosh support for functions isn't complete yet.
auto immutableScriptData = ImmutableScriptData::new_(
cx, smoosh.main_offset, nfixed, uint32_t(nslots64),
smoosh.body_scope_index, smoosh.num_ic_entries, smoosh.num_type_sets,
smoosh.is_function, funLength,
isFunction, funLength,
mozilla::MakeSpan(smoosh.bytecode.data, smoosh.bytecode.len),
mozilla::Span<const SrcNote>(), mozilla::Span<const uint32_t>(),
scopeNotes, mozilla::Span<const TryNote>());

Просмотреть файл

@ -12,12 +12,12 @@ log = "0.4"
# Disable regex feature for code size.
env_logger = {version = "0.6", default-features = false}
# For non-jsparagus developers.
jsparagus = { git = "https://github.com/mozilla-spidermonkey/jsparagus", rev = "5a49cf936b073da15ba67ce3700fed616960dfb8" }
jsparagus = { git = "https://github.com/mozilla-spidermonkey/jsparagus", rev = "efc1291d05e5ba8dbb4bd1197937a0291e72742c" }
# For local development, replace above with
# jsparagus = { path = "{path to jsparagus}" }
[build-dependencies]
# For non-jsparagus developers.
jsparagus = { git = "https://github.com/mozilla-spidermonkey/jsparagus", rev = "5a49cf936b073da15ba67ce3700fed616960dfb8" }
jsparagus = { git = "https://github.com/mozilla-spidermonkey/jsparagus", rev = "efc1291d05e5ba8dbb4bd1197937a0291e72742c" }
# For local development, replace above with
# jsparagus = { path = "{path to jsparagus}" }

Просмотреть файл

@ -251,15 +251,7 @@ pub struct SmooshResult {
num_type_sets: u32,
/// `See BaseScript::ImmutableFlags`.
strict: bool,
bindings_accessed_dynamically: bool,
has_call_site_obj: bool,
is_for_eval: bool,
is_module: bool,
is_function: bool,
has_non_syntactic_scope: bool,
needs_function_environment_objects: bool,
has_module_goal: bool,
immutable_flags: u32,
all_atoms: *mut c_void,
all_atoms_len: usize,
@ -295,15 +287,7 @@ impl SmooshResult {
body_scope_index: 0,
num_ic_entries: 0,
num_type_sets: 0,
strict: false,
bindings_accessed_dynamically: false,
has_call_site_obj: false,
is_for_eval: false,
is_module: false,
is_function: false,
has_non_syntactic_scope: false,
needs_function_environment_objects: false,
has_module_goal: false,
immutable_flags: 0,
all_atoms: std::ptr::null_mut(),
all_atoms_len: 0,
@ -342,36 +326,45 @@ pub unsafe extern "C" fn smoosh_run(
let text = str::from_utf8(slice::from_raw_parts(text, text_len)).expect("Invalid UTF8");
let allocator = Box::new(bumpalo::Bump::new());
match smoosh(&allocator, text, options) {
Ok(mut result) => {
// The first item is for top-level script.
// TODO: Once jsparagus supports functions, handle them stored in
// trailing items.
let script = result.scripts.remove(0);
let bytecode = CVec::from(script.bytecode);
let gcthings = CVec::from(script.gcthings.into_iter().map(|x| x.into()).collect());
Ok(result) => {
let bytecode = CVec::from(result.script.bytecode);
let gcthings = CVec::from(
result
.script
.base
.gcthings
.into_iter()
.map(|x| x.into())
.collect(),
);
let scopes = CVec::from(result.scopes.into_iter().map(|x| x.into()).collect());
let scope_notes =
CVec::from(script.scope_notes.into_iter().map(|x| x.into()).collect());
let regexps = CVec::from(script.regexps.into_iter().map(|x| x.into()).collect());
let scope_notes = CVec::from(
result
.script
.scope_notes
.into_iter()
.map(|x| x.into())
.collect(),
);
let regexps = CVec::from(
result
.script
.regexps
.into_iter()
.map(|x| x.into())
.collect(),
);
let lineno = script.lineno;
let column = script.column;
let main_offset = script.main_offset;
let max_fixed_slots = script.max_fixed_slots.into();
let maximum_stack_depth = script.maximum_stack_depth;
let body_scope_index = script.body_scope_index;
let num_ic_entries = script.num_ic_entries;
let num_type_sets = script.num_type_sets;
let strict = script.strict;
let bindings_accessed_dynamically = script.bindings_accessed_dynamically;
let has_call_site_obj = script.has_call_site_obj;
let is_for_eval = script.is_for_eval;
let is_module = script.is_module;
let is_function = script.is_function;
let has_non_syntactic_scope = script.has_non_syntactic_scope;
let needs_function_environment_objects = script.needs_function_environment_objects;
let has_module_goal = script.has_module_goal;
let lineno = result.script.lineno;
let column = result.script.column;
let main_offset = result.script.main_offset;
let max_fixed_slots = result.script.max_fixed_slots.into();
let maximum_stack_depth = result.script.maximum_stack_depth;
let body_scope_index = result.script.body_scope_index;
let num_ic_entries = result.script.num_ic_entries;
let num_type_sets = result.script.num_type_sets;
let immutable_flags = result.script.base.immutable_flags.into();
let all_atoms_len = result.atoms.len();
let all_atoms = Box::new(result.atoms);
@ -402,15 +395,7 @@ pub unsafe extern "C" fn smoosh_run(
body_scope_index,
num_ic_entries,
num_type_sets,
strict,
bindings_accessed_dynamically,
has_call_site_obj,
is_for_eval,
is_module,
is_function,
has_non_syntactic_scope,
needs_function_environment_objects,
has_module_goal,
immutable_flags,
all_atoms: opaque_all_atoms,
all_atoms_len,

Просмотреть файл

@ -1 +1 @@
{"files":{"Cargo.toml":"fb09624f3c97bd2e872572b5ffd80751fbf8dd0b31155dc7855c9999a3c7a838","src/array_emitter.rs":"bbc6528321f1d11d7c86c4f2bfdcfc9dced8f0b8b1c30c9f0a5355f300d196b6","src/ast_emitter.rs":"cb4b0b89d4b35d370efb318d882339bded457bf95c4adc05091b09e37e2b94b0","src/block_emitter.rs":"2aad01fd24b4165fe11d0f05949690d6a4010aa52d59203c0b7a923001cb540c","src/compilation_info.rs":"1f8571c8b9956b9f3336b768c5359236d783ead5710869c1a211367f65f0c99a","src/control_structures.rs":"5d7ec0cc3234cba80d27d2f298eb39cefa135a6d0cb66247ebdd0711269867aa","src/dis.rs":"4a335d813fa965482ca0f20a7b9295a55ce7625b577d42bd8b33b156b81c6306","src/emitter.rs":"51ac047b1953bfdaac3fc2d4d1e98f57c1c9fc4c22de3bc87808183ed1389b35","src/emitter_scope.rs":"0908a6a1587dc2eeb63115c483c4b126e214cd0a2bb390b399f5083ba7c48218","src/expression_emitter.rs":"f8e02785dffb179bbe9fe58e45bbfccc08adc3ad0a071a0073bed0feedc8ed9a","src/function_declaration_emitter.rs":"d8d620f66f33bc4be6573d91e1cc1080208b11ce4fac6ba673099ea0ae5b0fb3","src/lib.rs":"48a1d5dd2242d0f308b4349266d72301f27c8ecc91171a45401759d81f4123fb","src/object_emitter.rs":"998423b3d6ef8797fadef6763803627df72fde292b1b34d6a41b2e66a331a181","src/reference_op_emitter.rs":"f3641a7c94f648b146d2e93321a9a1968a5bcedcccdd325c834d4a62eddbb173","src/script_emitter.rs":"44a6be5ecdcde3c32d78d100a205d38be2591c7c2cc109967579af7393e09fe8"},"package":null}
{"files":{"Cargo.toml":"fb09624f3c97bd2e872572b5ffd80751fbf8dd0b31155dc7855c9999a3c7a838","src/array_emitter.rs":"bbc6528321f1d11d7c86c4f2bfdcfc9dced8f0b8b1c30c9f0a5355f300d196b6","src/ast_emitter.rs":"d8963b00a55c54c7e7f39a56aa5a073a0be6192bfdefd80da668c9172baaf857","src/block_emitter.rs":"2aad01fd24b4165fe11d0f05949690d6a4010aa52d59203c0b7a923001cb540c","src/compilation_info.rs":"f353184a8a5a57181ca566f371aca0df17c82117b7f645464fca3108650d5d47","src/control_structures.rs":"5d7ec0cc3234cba80d27d2f298eb39cefa135a6d0cb66247ebdd0711269867aa","src/dis.rs":"4a335d813fa965482ca0f20a7b9295a55ce7625b577d42bd8b33b156b81c6306","src/emitter.rs":"9c413c9fd6905cf5fd70b407aa9b5bb933dd3a4beb6baabab6a215b6621353dd","src/emitter_scope.rs":"0908a6a1587dc2eeb63115c483c4b126e214cd0a2bb390b399f5083ba7c48218","src/expression_emitter.rs":"f8e02785dffb179bbe9fe58e45bbfccc08adc3ad0a071a0073bed0feedc8ed9a","src/function_declaration_emitter.rs":"4d39542d4aea598d0acf82567cd0098bc5f340073c1bab120b6e6648fad67a3f","src/lib.rs":"606d4a228527c8a7639869578019148c38b8fb8a0eeca265ca6982673e4181cc","src/object_emitter.rs":"998423b3d6ef8797fadef6763803627df72fde292b1b34d6a41b2e66a331a181","src/reference_op_emitter.rs":"f3641a7c94f648b146d2e93321a9a1968a5bcedcccdd325c834d4a62eddbb173","src/script_emitter.rs":"44a6be5ecdcde3c32d78d100a205d38be2591c7c2cc109967579af7393e09fe8"},"package":null}

Просмотреть файл

@ -22,7 +22,7 @@ use std::collections::HashSet;
use stencil::opcode::Opcode;
use stencil::regexp::RegExpItem;
use stencil::result::EmitResult;
use stencil::script::{ScriptStencilIndex, ScriptStencilList};
use stencil::script::ScriptStencil;
use crate::control_structures::{
BreakEmitter, CForEmitter, ContinueEmitter, ControlStructureStack, DoWhileEmitter,
@ -35,23 +35,21 @@ pub fn emit_program<'alloc>(
options: &EmitOptions,
mut compilation_info: CompilationInfo<'alloc>,
) -> Result<EmitResult<'alloc>, EmitError> {
let mut scripts = ScriptStencilList::new();
let emitter = AstEmitter::new(options, &mut compilation_info, &mut scripts);
let emitter = AstEmitter::new(options, &mut compilation_info);
match ast {
Program::Script(script) => {
emitter.emit_script(script)?;
}
let script = match ast {
Program::Script(script) => emitter.emit_script(script)?,
_ => {
return Err(EmitError::NotImplemented("TODO: modules"));
}
}
};
Ok(EmitResult::new(
compilation_info.atoms.into(),
compilation_info.slices.into(),
compilation_info.scope_data_map.into(),
scripts.into(),
script,
compilation_info.functions.into(),
))
}
@ -60,7 +58,6 @@ pub struct AstEmitter<'alloc, 'opt> {
pub scope_stack: EmitterScopeStack,
pub options: &'opt EmitOptions,
pub compilation_info: &'opt mut CompilationInfo<'alloc>,
pub scripts: &'opt mut ScriptStencilList,
pub control_stack: ControlStructureStack,
/// Holds the offset of top-level function declarations, to check if the
@ -72,49 +69,33 @@ impl<'alloc, 'opt> AstEmitter<'alloc, 'opt> {
fn new(
options: &'opt EmitOptions,
compilation_info: &'opt mut CompilationInfo<'alloc>,
scripts: &'opt mut ScriptStencilList,
) -> Self {
Self {
emit: InstructionWriter::new(),
scope_stack: EmitterScopeStack::new(),
options,
compilation_info,
scripts,
control_stack: ControlStructureStack::new(),
top_level_function_offsets: HashSet::new(),
}
}
pub fn with_inner<ScriptFn>(
&mut self,
callback: ScriptFn,
) -> Result<ScriptStencilIndex, EmitError>
pub fn with_inner<ScriptFn>(&mut self, callback: ScriptFn) -> Result<ScriptStencil, EmitError>
where
ScriptFn: Fn(&mut AstEmitter) -> Result<(), EmitError>,
{
let script_index = self.scripts.allocate();
let mut inner_emitter = AstEmitter::new(self.options, self.compilation_info);
let inner_script = {
let mut inner_emitter =
AstEmitter::new(self.options, self.compilation_info, self.scripts);
callback(&mut inner_emitter)?;
callback(&mut inner_emitter)?;
inner_emitter.emit.into()
};
self.scripts.populate(script_index, inner_script);
Ok(script_index)
Ok(inner_emitter.emit.into())
}
pub fn lookup_name(&mut self, name: SourceAtomSetIndex) -> NameLocation {
self.scope_stack.lookup_name(name)
}
fn emit_script(mut self, ast: &Script) -> Result<ScriptStencilIndex, EmitError> {
let script_index = self.scripts.allocate();
fn emit_script(mut self, ast: &Script) -> Result<ScriptStencil, EmitError> {
let scope_data_map = &self.compilation_info.scope_data_map;
let function_map = &self.compilation_info.function_map;
@ -139,9 +120,7 @@ impl<'alloc, 'opt> AstEmitter<'alloc, 'opt> {
}
.emit(&mut self)?;
self.scripts.populate(script_index, self.emit.into());
Ok(script_index)
Ok(self.emit.into())
}
fn emit_top_level_function_declaration(&mut self, fun: &Function) -> Result<(), EmitError> {

Просмотреть файл

@ -2,6 +2,7 @@ use ast::associated_data::AssociatedData;
use ast::source_atom_set::SourceAtomSet;
use ast::source_slice_list::SourceSliceList;
use ast::types::Function;
use stencil::function::FunctionStencilList;
use stencil::scope::ScopeDataMap;
pub struct CompilationInfo<'alloc> {
@ -9,6 +10,7 @@ pub struct CompilationInfo<'alloc> {
pub slices: SourceSliceList<'alloc>,
pub scope_data_map: ScopeDataMap,
pub function_map: AssociatedData<&'alloc Function<'alloc>>,
pub functions: FunctionStencilList,
}
impl<'alloc> CompilationInfo<'alloc> {
@ -23,6 +25,10 @@ impl<'alloc> CompilationInfo<'alloc> {
slices,
scope_data_map,
function_map,
// FIXME: This should be created by scope pass, that is the
// list of all functions, with position information and
// inner functions/closed over bindings populated.
functions: FunctionStencilList::new(),
}
}
}

Просмотреть файл

@ -14,16 +14,16 @@ use std::convert::TryInto;
use std::fmt;
use stencil::bytecode_offset::{BytecodeOffset, BytecodeOffsetDiff};
use stencil::frame_slot::FrameSlot;
use stencil::function::{FunctionCreationData, FunctionCreationDataList};
use stencil::function::FunctionStencilIndex;
use stencil::gcthings::{GCThingIndex, GCThingList};
use stencil::opcode::Opcode;
use stencil::regexp::{RegExpItem, RegExpList};
use stencil::scope::ScopeIndex;
use stencil::scope_notes::{ScopeNoteIndex, ScopeNoteList};
use stencil::script::ScriptStencil;
use stencil::script::{ImmutableScriptFlags, ScriptStencil, ScriptStencilBase};
// WARNING
// The following section is generated by update_opcodes.py.
// The following section is generated by update_stencil.py.
// Do mot modify manually.
//
// @@@@ BEGIN TYPES @@@@
@ -118,7 +118,6 @@ pub struct InstructionWriter {
gcthings: GCThingList,
scope_notes: ScopeNoteList,
inner_functions: FunctionCreationDataList,
regexps: RegExpList,
@ -177,7 +176,6 @@ impl InstructionWriter {
gcthings: GCThingList::new(),
atom_to_gcindex_map: HashMap::new(),
scope_notes: ScopeNoteList::new(),
inner_functions: FunctionCreationDataList::new(),
regexps: RegExpList::new(),
last_jump_target_offset: None,
main_offset: BytecodeOffset::from(0usize),
@ -409,8 +407,7 @@ impl InstructionWriter {
}
// WARNING
// The following section is generated by
// crates/emitter/scripts/update_opcodes.py.
// The following section is generated by update_stencil.py.
// Do mot modify manually.
//
// @@@@ BEGIN METHODS @@@@
@ -1372,9 +1369,8 @@ impl InstructionWriter {
}
}
pub fn get_function_gcthing_index(&mut self, fun_data: FunctionCreationData) -> GCThingIndex {
let fun_data_index = self.inner_functions.push(fun_data);
self.gcthings.push_function(fun_data_index)
pub fn get_function_gcthing_index(&mut self, fun_index: FunctionStencilIndex) -> GCThingIndex {
self.gcthings.push_function(fun_index)
}
pub fn get_regexp_gcthing_index(&mut self, regexp: RegExpItem) -> GCThingIndex {
@ -1450,11 +1446,14 @@ impl InstructionWriter {
impl From<InstructionWriter> for ScriptStencil {
fn from(emit: InstructionWriter) -> Self {
Self {
base: ScriptStencilBase {
gcthings: emit.gcthings.into(),
immutable_flags: ImmutableScriptFlags::new(),
},
bytecode: emit.bytecode,
regexps: emit.regexps.into(),
gcthings: emit.gcthings.into(),
scope_notes: emit.scope_notes.into(),
inner_functions: emit.inner_functions.into(),
lineno: 1,
column: 0,
@ -1470,16 +1469,6 @@ impl From<InstructionWriter> for ScriptStencil {
.unwrap(),
num_ic_entries: emit.num_ic_entries.try_into().unwrap(),
num_type_sets: emit.num_type_sets.try_into().unwrap(),
strict: false,
bindings_accessed_dynamically: false,
has_call_site_obj: false,
is_for_eval: false,
is_module: false,
is_function: false,
has_non_syntactic_scope: false,
needs_function_environment_objects: false,
has_module_goal: false,
}
}
}

Просмотреть файл

@ -1,7 +1,7 @@
use crate::ast_emitter::AstEmitter;
use crate::emitter::EmitError;
use ast::source_atom_set::SourceAtomSetIndex;
use stencil::function::{FunctionCreationData, FunctionFlags};
use stencil::function::{FunctionFlags, FunctionStencil};
use stencil::gcthings::GCThingIndex;
/// Create a dummy function with empty script, to implement
@ -12,7 +12,7 @@ pub struct DummyFunctionScriptEmitter {
impl DummyFunctionScriptEmitter {
pub fn emit(self, emitter: &mut AstEmitter) -> Result<GCThingIndex, EmitError> {
let script_index = emitter.with_inner(|_emitter| {
let script = emitter.with_inner(|_emitter| {
Err(EmitError::NotImplemented("TODO: FunctionDeclaration"))
// The following implementing is just a dummy to pass the
@ -36,13 +36,12 @@ impl DummyFunctionScriptEmitter {
*/
})?;
let fun_data = FunctionCreationData::non_lazy(
Some(self.name),
script_index,
FunctionFlags::interpreted_normal(),
);
let fun =
FunctionStencil::non_lazy(Some(self.name), script, FunctionFlags::interpreted_normal());
Ok(emitter.emit.get_function_gcthing_index(fun_data))
let index = emitter.compilation_info.functions.push(fun);
Ok(emitter.emit.get_function_gcthing_index(index))
}
}

Просмотреть файл

@ -74,7 +74,7 @@ mod tests {
)
.expect("Should work!");
let bytecode = &result.scripts[0].bytecode;
let bytecode = &result.script.bytecode;
println!("{}", dis(&bytecode));
bytecode.to_vec()

Просмотреть файл

@ -1 +1 @@
{"files":{"Cargo.toml":"8e424d01abd384e3d5f13bf921c8f4bc58306b3f41825dc821e60c5220efb7e0","src/ast_builder.rs":"8b10743ebbc3390d1158cb44ff5c87fbb653d62521f3e1274565d0061eebe095","src/context_stack.rs":"29331d03cd4c8ee9283cb426ebe893b7ba6ad6d8a69016399c4d92a81cb1363b","src/declaration_kind.rs":"fdfda2fe408cce1c637d17fee0813160619450472c6de9befc36ebeed892cc3c","src/early_error_checker.rs":"150a106a8f0901b72ae40581f0c12f785983514cbc9042404ed6cf4315693d60","src/early_errors.rs":"8674454af7ac5efe51eb6a8e2abe088aad5560e0a0bd88a3eae66c90f1527149","src/error.rs":"507e4dd9c66720f3da2db135c3024392d8aaac5ccdb90c7f7463ccb2eff7efa8","src/lib.rs":"a40b11e1dda1afcccef5fc86a2030c326d38feb31e24596e602930dcad28f1ec","src/parser_tables_generated.rs":"7fca5ebbe071c9a7beb01dc273e844267094d3f865a16e1ab55d63d96258ed32","src/stack_value_generated.rs":"d8696a671368e2565d589922e3a46d20667ed3e17e29953e69b970470e9639ee","src/token.rs":"479f4cb97d2e6bc654a70634f3809817cc73eaf749c845643beb3556b9ead383","src/traits/mod.rs":"bcc2fa63444ba4c763dc996f410a6871f2cdc3bde54e1924ca8cc25cba92674a"},"package":null}
{"files":{"Cargo.toml":"8e424d01abd384e3d5f13bf921c8f4bc58306b3f41825dc821e60c5220efb7e0","src/ast_builder.rs":"8b10743ebbc3390d1158cb44ff5c87fbb653d62521f3e1274565d0061eebe095","src/context_stack.rs":"29331d03cd4c8ee9283cb426ebe893b7ba6ad6d8a69016399c4d92a81cb1363b","src/declaration_kind.rs":"fdfda2fe408cce1c637d17fee0813160619450472c6de9befc36ebeed892cc3c","src/early_error_checker.rs":"150a106a8f0901b72ae40581f0c12f785983514cbc9042404ed6cf4315693d60","src/early_errors.rs":"8674454af7ac5efe51eb6a8e2abe088aad5560e0a0bd88a3eae66c90f1527149","src/error.rs":"507e4dd9c66720f3da2db135c3024392d8aaac5ccdb90c7f7463ccb2eff7efa8","src/lib.rs":"a40b11e1dda1afcccef5fc86a2030c326d38feb31e24596e602930dcad28f1ec","src/parser_tables_generated.rs":"54dc893a76e1317b9e2fccc7e910506fa7959ad81dca8ea3ac77209c53c10988","src/stack_value_generated.rs":"d8696a671368e2565d589922e3a46d20667ed3e17e29953e69b970470e9639ee","src/token.rs":"479f4cb97d2e6bc654a70634f3809817cc73eaf749c845643beb3556b9ead383","src/traits/mod.rs":"bcc2fa63444ba4c763dc996f410a6871f2cdc3bde54e1924ca8cc25cba92674a"},"package":null}

Разница между файлами не показана из-за своего большого размера Загрузить разницу

Просмотреть файл

@ -1 +1 @@
{"files":{"Cargo.toml":"f5439990185662ab31de12c07ef0c842438e3207bdfecc4fa6a9e4d4bea8a0d3","src/bytecode_offset.rs":"2aa7ba8c3cfbbd832092e65b599ab1c5a28d784ccc65d9e351bba656421b9a69","src/copy/AsyncFunctionResolveKind.h":"3851ecbb4728257595dd6e900749d1d8e02558574c00424a7ff0e3ca007fa6ec","src/copy/BytecodeFormatFlags.h":"7dc2932321cf7cf874cd92b6d8076ebd4139492730f3ee5a3b6ed7fc57a0c685","src/copy/CheckIsObjectKind.h":"8f0e112396d966c9221a743d353f62671e04cdace7dd49a59898d94ba0f621b7","src/copy/FunctionFlags.h":"4376653f70711d916bc36c2096165f0be9a50c487b9d471821da1cad80daa3a3","src/copy/FunctionPrefixKind.h":"f540a5c646a519b2d61aa27e4be865e08a31438def00ad5ba4ba2982ad1f2275","src/copy/GeneratorAndAsyncKind.h":"301668ce705970a51abfa94f89fd5db29ef5f129525110860e9e9bf7586ef187","src/copy/GeneratorResumeKind.h":"9e3cd9dc9c7f50937c6c45d73ec092dbfd92c4b56818ae6d1504bcd77078d0a6","src/copy/Opcodes.h":"72e0faa4eb0ed4e59ee2205d0ed6734fc4e7383552545d605eef2201e69d4c99","src/copy/SourceNotes.h":"1e467f4e63d6f40a428e257fecd210bd14664516adf75a45cb17ab02ccd65fd8","src/copy/StencilEnums.h":"e5a1db4af868fd65591ed97594f7aa9a4cde79194da0cabd62b34e950b3b10b4","src/copy/Symbol.h":"f68b32e1b7add89931a1fa82a6888ebf6d875d03b05872469de426844532bf33","src/copy/ThrowMsgKind.h":"da805756961d81a2b50aeb391a02fd59a0aa39a9e3eb6aae21b423b15875ab30","src/frame_slot.rs":"b20c81d67c572f20d06d493b211cd3eaa0432a8294541583643b82df3af2f813","src/function.rs":"ffd2ccce0b8940d281fea1e1294e27b5a943a4b1983bdf5330ccdec2241e1fde","src/gcthings.rs":"5f86caa759785b4961c9fb76e87001d58aa2a30ddf35d339beaa95db5fbdb877","src/lib.rs":"731842a46c397bee8dd06543dab435e8f7465a15e51301de5bca9bc67faa7d36","src/opcode.rs":"2b966f2c5f274a37463e8e932b00cefa160261fe011aea8b0ea1f86e921b8044","src/opcode_info.rs":"a27c6d5602f5ecdcc882a0167614bc7a7754d958124941b4c1c0cdc2b0a894f1","src/regexp.rs":"7436cf545b990bec7dcc51ff28d67deaca9d4ce894468fdad0dd44b25c571cf2","src/result.rs":"6c71556917833498bff1a1419b48d9bea73e4df77b1c3328320aea70f317d1cd","src/scope.rs":"71f5acf81a54a92d8ec9ec1531808a92a3a93c81e09af1a6cd27a1fd23f38a30","src/scope_notes.rs":"9947ba5aba3097321c76adcb5648a478e4a67e088fdc1e01511e51c4ad41a9f3","src/script.rs":"3f25dfef5a4c5aa796387145cab53a7009d15dafde1e1a6f0086b609bccffa84"},"package":null}
{"files":{"Cargo.toml":"f5439990185662ab31de12c07ef0c842438e3207bdfecc4fa6a9e4d4bea8a0d3","src/bytecode_offset.rs":"2aa7ba8c3cfbbd832092e65b599ab1c5a28d784ccc65d9e351bba656421b9a69","src/copy/AsyncFunctionResolveKind.h":"3851ecbb4728257595dd6e900749d1d8e02558574c00424a7ff0e3ca007fa6ec","src/copy/BytecodeFormatFlags.h":"7dc2932321cf7cf874cd92b6d8076ebd4139492730f3ee5a3b6ed7fc57a0c685","src/copy/CheckIsObjectKind.h":"8f0e112396d966c9221a743d353f62671e04cdace7dd49a59898d94ba0f621b7","src/copy/FunctionFlags.h":"4376653f70711d916bc36c2096165f0be9a50c487b9d471821da1cad80daa3a3","src/copy/FunctionPrefixKind.h":"f540a5c646a519b2d61aa27e4be865e08a31438def00ad5ba4ba2982ad1f2275","src/copy/GeneratorAndAsyncKind.h":"301668ce705970a51abfa94f89fd5db29ef5f129525110860e9e9bf7586ef187","src/copy/GeneratorResumeKind.h":"9e3cd9dc9c7f50937c6c45d73ec092dbfd92c4b56818ae6d1504bcd77078d0a6","src/copy/Opcodes.h":"72e0faa4eb0ed4e59ee2205d0ed6734fc4e7383552545d605eef2201e69d4c99","src/copy/SourceNotes.h":"1e467f4e63d6f40a428e257fecd210bd14664516adf75a45cb17ab02ccd65fd8","src/copy/StencilEnums.h":"e5a1db4af868fd65591ed97594f7aa9a4cde79194da0cabd62b34e950b3b10b4","src/copy/Symbol.h":"f68b32e1b7add89931a1fa82a6888ebf6d875d03b05872469de426844532bf33","src/copy/ThrowMsgKind.h":"da805756961d81a2b50aeb391a02fd59a0aa39a9e3eb6aae21b423b15875ab30","src/frame_slot.rs":"b20c81d67c572f20d06d493b211cd3eaa0432a8294541583643b82df3af2f813","src/function.rs":"d73ff97ae6982c2fb5003c80175aefcd4ff64eea737618a9164ae55e89cb24e6","src/gcthings.rs":"6237c13fae9a5cfc67037c6fedf489747db67c38952aad95c322a6b7944211b7","src/lib.rs":"731842a46c397bee8dd06543dab435e8f7465a15e51301de5bca9bc67faa7d36","src/opcode.rs":"b9ebb9f03cebbc731b27cddb5799e34f4af12854a1e89aa459e153e0f087bbeb","src/opcode_info.rs":"a27c6d5602f5ecdcc882a0167614bc7a7754d958124941b4c1c0cdc2b0a894f1","src/regexp.rs":"7436cf545b990bec7dcc51ff28d67deaca9d4ce894468fdad0dd44b25c571cf2","src/result.rs":"0244b908bca220114e05291cca64c5e78edd48af2f0982d9587b4eaed5980eaa","src/scope.rs":"71f5acf81a54a92d8ec9ec1531808a92a3a93c81e09af1a6cd27a1fd23f38a30","src/scope_notes.rs":"9947ba5aba3097321c76adcb5648a478e4a67e088fdc1e01511e51c4ad41a9f3","src/script.rs":"4295a61a9d6c97a70e332be6a04d9c8e04f0d40b782f0a91f91027096a54730d"},"package":null}

Просмотреть файл

@ -1,4 +1,4 @@
use crate::script::ScriptStencilIndex;
use crate::script::{ScriptStencil, ScriptStencilBase};
use ast::source_atom_set::SourceAtomSetIndex;
#[derive(Debug)]
@ -7,7 +7,7 @@ pub struct FunctionFlags {
}
// WARNING
// The following section is generated by update_opcodes.py.
// The following section is generated by update_stencil.py.
// Do mot modify manually.
//
// @@@@ BEGIN TYPES @@@@
@ -125,15 +125,12 @@ impl FunctionFlags {
#[derive(Debug)]
pub struct NonLazyFunctionScript {
script: ScriptStencilIndex,
script: ScriptStencil,
}
#[derive(Debug)]
pub struct LazyFunctionScript {
closed_over_bindings: Vec<SourceAtomSetIndex>,
inner_functions: Vec<FunctionCreationDataIndex>,
force_strict: bool,
strict: bool,
script: ScriptStencilBase,
}
#[derive(Debug)]
@ -142,20 +139,20 @@ pub enum FunctionScript {
Lazy(LazyFunctionScript),
}
/// Partially maps to FunctionCreationData in m-c/js/src/frontend/Stencil.h
/// Maps to JSFunction in m-c/js/src/vm/JSFunction.h, and BaseScript/JSScript
/// in m-c/js/src/vm/JSScript.h, linked from it.
#[derive(Debug)]
pub struct FunctionCreationData {
pub struct FunctionStencil {
name: Option<SourceAtomSetIndex>,
script: FunctionScript,
flags: FunctionFlags,
// FIXME: add more fields
}
impl FunctionCreationData {
#[allow(dead_code)]
impl FunctionStencil {
pub fn non_lazy(
name: Option<SourceAtomSetIndex>,
script: ScriptStencilIndex,
script: ScriptStencil,
flags: FunctionFlags,
) -> Self {
Self {
@ -165,58 +162,78 @@ impl FunctionCreationData {
}
}
pub fn lazy(name: Option<SourceAtomSetIndex>, flags: FunctionFlags) -> Self {
pub fn lazy(
name: Option<SourceAtomSetIndex>,
script: ScriptStencilBase,
flags: FunctionFlags,
) -> Self {
Self {
name,
script: FunctionScript::Lazy(LazyFunctionScript {
closed_over_bindings: Vec::new(),
inner_functions: Vec::new(),
force_strict: false,
strict: false,
}),
script: FunctionScript::Lazy(LazyFunctionScript { script }),
flags,
}
}
pub fn is_non_lazy(&self) -> bool {
match self.script {
FunctionScript::NonLazy(_) => true,
FunctionScript::Lazy(_) => false,
}
}
pub fn is_lazy(&self) -> bool {
match self.script {
FunctionScript::NonLazy(_) => false,
FunctionScript::Lazy(_) => true,
}
}
pub fn non_lazy_script<'a>(&'a self) -> &'a ScriptStencil {
match &self.script {
FunctionScript::NonLazy(nonlazy) => &nonlazy.script,
FunctionScript::Lazy(_) => panic!("unexpeceted function type"),
}
}
}
/// Index into FunctionCreationDataList.items.
/// Index into FunctionStencilList.items.
#[derive(Debug, Clone, Copy)]
pub struct FunctionCreationDataIndex {
pub struct FunctionStencilIndex {
index: usize,
}
impl FunctionCreationDataIndex {
impl FunctionStencilIndex {
fn new(index: usize) -> Self {
Self { index }
}
}
impl From<FunctionCreationDataIndex> for usize {
fn from(index: FunctionCreationDataIndex) -> usize {
impl From<FunctionStencilIndex> for usize {
fn from(index: FunctionStencilIndex) -> usize {
index.index
}
}
/// List of FunctionCreationData.
/// List of FunctionStencil.
#[derive(Debug)]
pub struct FunctionCreationDataList {
items: Vec<FunctionCreationData>,
pub struct FunctionStencilList {
items: Vec<FunctionStencil>,
}
impl FunctionCreationDataList {
impl FunctionStencilList {
pub fn new() -> Self {
Self { items: Vec::new() }
}
pub fn push(&mut self, fun_data: FunctionCreationData) -> FunctionCreationDataIndex {
pub fn push(&mut self, fun_data: FunctionStencil) -> FunctionStencilIndex {
let index = self.items.len();
self.items.push(fun_data);
FunctionCreationDataIndex::new(index)
FunctionStencilIndex::new(index)
}
}
impl From<FunctionCreationDataList> for Vec<FunctionCreationData> {
fn from(list: FunctionCreationDataList) -> Vec<FunctionCreationData> {
impl From<FunctionStencilList> for Vec<FunctionStencil> {
fn from(list: FunctionStencilList) -> Vec<FunctionStencil> {
list.items
}
}

Просмотреть файл

@ -1,4 +1,4 @@
use crate::function::FunctionCreationDataIndex;
use crate::function::FunctionStencilIndex;
use crate::regexp::RegExpIndex;
use crate::scope::ScopeIndex;
use ast::source_atom_set::SourceAtomSetIndex;
@ -8,7 +8,7 @@ use ast::source_atom_set::SourceAtomSetIndex;
#[derive(Debug)]
pub enum GCThing {
Atom(SourceAtomSetIndex),
Function(FunctionCreationDataIndex),
Function(FunctionStencilIndex),
RegExp(RegExpIndex),
Scope(ScopeIndex),
}
@ -50,7 +50,7 @@ impl GCThingList {
GCThingIndex::new(index)
}
pub fn push_function(&mut self, fun_index: FunctionCreationDataIndex) -> GCThingIndex {
pub fn push_function(&mut self, fun_index: FunctionStencilIndex) -> GCThingIndex {
let index = self.things.len();
self.things.push(GCThing::Function(fun_index));
GCThingIndex::new(index)

Просмотреть файл

@ -5,7 +5,7 @@ macro_rules! using_opcode_database {
$macro! {
[
// WARNING
// The following section is generated by update_opcodes.py.
// The following section is generated by update_stencil.py.
// Do mot modify manually.
//
// @@@@ BEGIN OPCODES @@@@
@ -277,7 +277,7 @@ macro_rules! count_rows {
const JSOP_LIMIT: usize = using_opcode_database!(count_rows!());
// WARNING
// The following section is generated by update_opcodes.py.
// The following section is generated by update_stencil.py.
// Do mot modify manually.
//
// @@@@ BEGIN FLAGS @@@@

Просмотреть файл

@ -1,7 +1,9 @@
use crate::function::FunctionStencil;
use crate::scope::ScopeData;
use crate::script::ScriptStencil;
/// The result of emitter.
#[derive(Debug)]
pub struct EmitResult<'alloc> {
pub atoms: Vec<&'alloc str>,
pub slices: Vec<&'alloc str>,
@ -10,7 +12,8 @@ pub struct EmitResult<'alloc> {
/// Emitted scripts.
/// The first item corresponds to the global script, and the remaining
/// items correspond to inner functions.
pub scripts: Vec<ScriptStencil>,
pub script: ScriptStencil,
pub functions: Vec<FunctionStencil>,
}
impl<'alloc> EmitResult<'alloc> {
@ -18,13 +21,15 @@ impl<'alloc> EmitResult<'alloc> {
atoms: Vec<&'alloc str>,
slices: Vec<&'alloc str>,
scopes: Vec<ScopeData>,
scripts: Vec<ScriptStencil>,
script: ScriptStencil,
functions: Vec<FunctionStencil>,
) -> Self {
Self {
atoms,
slices,
scopes,
scripts,
script,
functions,
}
}
}

Просмотреть файл

@ -1,20 +1,174 @@
//! The result of emitter
use crate::frame_slot::FrameSlot;
use crate::function::FunctionCreationData;
use crate::gcthings::GCThing;
use crate::regexp::RegExpItem;
use crate::scope_notes::ScopeNote;
// WARNING
// The following section is generated by update_stencil.py.
// Do mot modify manually.
//
// @@@@ BEGIN TYPES @@@@
#[derive(Debug)]
pub enum ImmutableScriptFlagsEnum {
#[allow(dead_code)]
IsForEval = 1 << 0,
#[allow(dead_code)]
IsModule = 1 << 1,
#[allow(dead_code)]
IsFunction = 1 << 2,
#[allow(dead_code)]
SelfHosted = 1 << 3,
#[allow(dead_code)]
ForceStrict = 1 << 4,
#[allow(dead_code)]
HasNonSyntacticScope = 1 << 5,
#[allow(dead_code)]
NoScriptRval = 1 << 6,
#[allow(dead_code)]
TreatAsRunOnce = 1 << 7,
#[allow(dead_code)]
Strict = 1 << 8,
#[allow(dead_code)]
HasModuleGoal = 1 << 9,
#[allow(dead_code)]
HasInnerFunctions = 1 << 10,
#[allow(dead_code)]
HasDirectEval = 1 << 11,
#[allow(dead_code)]
BindingsAccessedDynamically = 1 << 12,
#[allow(dead_code)]
HasCallSiteObj = 1 << 13,
#[allow(dead_code)]
IsAsync = 1 << 14,
#[allow(dead_code)]
IsGenerator = 1 << 15,
#[allow(dead_code)]
FunHasExtensibleScope = 1 << 16,
#[allow(dead_code)]
FunctionHasThisBinding = 1 << 17,
#[allow(dead_code)]
NeedsHomeObject = 1 << 18,
#[allow(dead_code)]
IsDerivedClassConstructor = 1 << 19,
#[allow(dead_code)]
IsFieldInitializer = 1 << 20,
#[allow(dead_code)]
HasRest = 1 << 21,
#[allow(dead_code)]
NeedsFunctionEnvironmentObjects = 1 << 22,
#[allow(dead_code)]
FunctionHasExtraBodyVarScope = 1 << 23,
#[allow(dead_code)]
ShouldDeclareArguments = 1 << 24,
#[allow(dead_code)]
ArgumentsHasVarBinding = 1 << 25,
#[allow(dead_code)]
AlwaysNeedsArgsObj = 1 << 26,
#[allow(dead_code)]
HasMappedArgsObj = 1 << 27,
#[allow(dead_code)]
IsLikelyConstructorWrapper = 1 << 28,
}
#[derive(Debug)]
pub enum MutableScriptFlagsEnum {
#[allow(dead_code)]
HasRunOnce = 1 << 8,
#[allow(dead_code)]
HasBeenCloned = 1 << 9,
#[allow(dead_code)]
HasScriptCounts = 1 << 10,
#[allow(dead_code)]
HasDebugScript = 1 << 11,
#[allow(dead_code)]
NeedsArgsAnalysis = 1 << 12,
#[allow(dead_code)]
NeedsArgsObj = 1 << 13,
#[allow(dead_code)]
AllowRelazify = 1 << 14,
#[allow(dead_code)]
SpewEnabled = 1 << 15,
#[allow(dead_code)]
BaselineDisabled = 1 << 16,
#[allow(dead_code)]
IonDisabled = 1 << 17,
#[allow(dead_code)]
FailedBoundsCheck = 1 << 18,
#[allow(dead_code)]
FailedShapeGuard = 1 << 19,
#[allow(dead_code)]
HadFrequentBailouts = 1 << 20,
#[allow(dead_code)]
HadOverflowBailout = 1 << 21,
#[allow(dead_code)]
Uninlineable = 1 << 22,
#[allow(dead_code)]
InvalidatedIdempotentCache = 1 << 23,
#[allow(dead_code)]
FailedLexicalCheck = 1 << 24,
}
// @@@@ END TYPES @@@@
#[derive(Debug)]
pub struct ImmutableScriptFlags {
value: u32,
}
impl ImmutableScriptFlags {
pub fn new() -> Self {
Self { value: 0 }
}
pub fn set(&mut self, bit: ImmutableScriptFlagsEnum) {
self.value |= bit as u32;
}
pub fn has(&self, bit: ImmutableScriptFlagsEnum) -> bool {
(self.value & bit as u32) != 0
}
pub fn reset(&mut self, bit: ImmutableScriptFlagsEnum) {
self.value &= !(bit as u32)
}
}
impl From<ImmutableScriptFlags> for u32 {
fn from(flags: ImmutableScriptFlags) -> u32 {
flags.value
}
}
/// Data that is shared across the following:
/// * top level script
/// * non-lazy function script
/// * lazy function script
///
/// Top level script and non-lazy function script use ScriptStencil,
/// instead of ScriptStencilBase.
#[derive(Debug)]
pub struct ScriptStencilBase {
pub immutable_flags: ImmutableScriptFlags,
/// For top level script and non-lazy function script,
/// this is a list of GC things referred by bytecode and scope.
///
/// For lazy function script, this is a list of inner functions and
/// closed over bindings.
pub gcthings: Vec<GCThing>,
}
/// Data used to instantiate the non-lazy script.
/// Maps to js::frontend::ScriptStencil in m-c/js/src/frontend/Stencil.h.
#[derive(Debug)]
pub struct ScriptStencil {
pub base: ScriptStencilBase,
pub bytecode: Vec<u8>,
pub regexps: Vec<RegExpItem>,
pub gcthings: Vec<GCThing>,
pub scope_notes: Vec<ScopeNote>,
pub inner_functions: Vec<FunctionCreationData>,
/// Line and column numbers for the first character of source.
pub lineno: usize,
@ -26,16 +180,6 @@ pub struct ScriptStencil {
pub body_scope_index: u32,
pub num_ic_entries: u32,
pub num_type_sets: u32,
pub strict: bool,
pub bindings_accessed_dynamically: bool,
pub has_call_site_obj: bool,
pub is_for_eval: bool,
pub is_module: bool,
pub is_function: bool,
pub has_non_syntactic_scope: bool,
pub needs_function_environment_objects: bool,
pub has_module_goal: bool,
}
/// Index into ScriptStencilList.scripts.

Различия файлов скрыты, потому что одна или несколько строк слишком длинны

4
third_party/rust/jsparagus/Makefile поставляемый
Просмотреть файл

@ -95,8 +95,8 @@ static-check:
jsdemo: $(PY_OUT)
$(PYTHON) -m js_parser.try_it
update-opcodes-m-u:
$(PYTHON) update_opcodes.py \
update-stencil:
$(PYTHON) update_stencil.py \
../mozilla-unified ./
.PHONY: all check static-check dyn-check jsdemo rust update-opcodes-m-u

Просмотреть файл

@ -1,9 +1,6 @@
#!/usr/bin/env python3
""" Extract opcodes from C++ header.
To use, pipe the output of this command to your clipboard,
then paste it into opcode.rs.
""" Extract stencil data/struct from C++ header.
"""
import argparse
@ -14,7 +11,7 @@ import subprocess
import sys
from textwrap import dedent
parser = argparse.ArgumentParser(description='Update opcode.rs')
parser = argparse.ArgumentParser(description='Update stencil data/struct')
parser.add_argument('PATH_TO_MOZILLA_CENTRAL',
help='Path to mozilla-central')
parser.add_argument('PATH_TO_JSPARAGUS',
@ -69,6 +66,7 @@ def get_source_path(crate, name):
opcode_dest_path = get_source_path('stencil', 'opcode.rs')
emitter_dest_path = get_source_path('emitter', 'emitter.rs')
function_dest_path = get_source_path('stencil', 'function.rs')
script_dest_path = get_source_path('stencil', 'script.rs')
copy_dir = os.path.join(args.PATH_TO_JSPARAGUS,
'crates', 'stencil', 'src', 'copy')
@ -119,87 +117,21 @@ def extract_opcode_flags(paths):
return flags
def filter_enum_body(body):
def remove_comment(body):
block_comment_pat = re.compile(r'/\*.+?\*/', re.M)
line_comment_pat = re.compile(r'//.*')
space_pat = re.compile(r'\s*')
result = ''
for line in block_comment_pat.sub('', body).split('\n'):
line = line_comment_pat.sub('', line)
line = space_pat.sub('', line)
result += line
return result
def extract_function_flags(paths):
ty = 'Flags'
variants_pat = re.compile(
r'enum(?:\s+class)?\s*' + ty + r'\s*:\s*([A-Za-z0-9_]+)\s*\{([^}]+)\}', re.M)
simple_init_pat = re.compile(r'^([A-Za-z0-9_]+)=((:?0x)?[A-Fa-f0-9+]+)$')
bits_init_pat = re.compile(r'^([A-Za-z0-9_]+)=(\d+)<<(\d+)$')
kind_init_pat = re.compile(r'^([A-Za-z0-9_]+)=([A-Za-z0-9_]+)<<([A-Za-z0-9_]+)$')
combined_init_pat = re.compile(r'^([A-Za-z0-9_]+)=([A-Za-z0-9_]+(\|[A-Za-z0-9_]+)*)$')
with open(paths['FunctionFlags.h'], 'r') as f:
content = f.read()
m = variants_pat.search(content)
assert m, f'enum {ty} is not found'
size_type = m.group(1)
body = m.group(2)
assert size_type == 'uint16_t'
body = filter_enum_body(body)
function_flags = []
for variant in body.split(','):
m = simple_init_pat.search(variant)
if m:
name = m.group(1)
value = m.group(2)
function_flags.append((name, value))
continue
m = bits_init_pat.search(variant)
if m:
name = m.group(1)
bits = m.group(2)
shift = m.group(3)
value = f'{bits} << {shift}'
function_flags.append((name, value))
continue
m = kind_init_pat.search(variant)
if m:
name = m.group(1)
bits = m.group(2)
shift = m.group(3)
value = f'(FunctionKind::{bits} as u16) << {shift}'
function_flags.append((name, value))
continue
m = combined_init_pat.search(variant)
if m:
name = m.group(1)
value = m.group(2)
function_flags.append((name, value))
continue
raise Exception(f'unhandled variant {variant}')
return function_flags
def filter_enum_body(body):
space_pat = re.compile(r'\s*')
return space_pat.sub('', body)
size_types = {
@ -213,15 +145,17 @@ size_types = {
}
def extract_enum(types, paths, ty, filename=None):
def extract_enum(types, paths, ty, filename=None, custom_handler=None):
variants_pat = re.compile(
r'enum(?:\s+class)?\s*' + ty + r'\s*:\s*([A-Za-z0-9_]+)\s*\{([^}]+)\}', re.M)
init_pat = re.compile(r'(.+)=(\d+)')
simple_init_pat = re.compile(r'^([A-Za-z0-9_]+)=((:?0x)?[A-Fa-f0-9+]+)$')
bits_init_pat = re.compile(r'^([A-Za-z0-9_]+)=(\d+)<<(\d+)$')
if not filename:
filename = f'{ty}.h'
with open(paths[filename], 'r') as f:
content = f.read()
content = remove_comment(content)
m = variants_pat.search(content)
assert m, f'enum {ty} is not found'
@ -240,20 +174,91 @@ def extract_enum(types, paths, ty, filename=None):
variants = []
i = 0
for variant in body.split(','):
m = init_pat.search(variant)
if variant == '':
# After trailing comma
continue
m = simple_init_pat.search(variant)
if m:
i = int(m.group(2))
variants.append((m.group(1), i))
else:
variants.append((variant, i))
name = m.group(1)
value = m.group(2)
variants.append((name, value))
if value.startswith('0x'):
i = int(value, 16) + 1
else:
i = int(value) + 1
continue
m = bits_init_pat.search(variant)
if m:
name = m.group(1)
bits = m.group(2)
shift = m.group(3)
value = f'{bits} << {shift}'
variants.append((name, value))
# If a bit pattern is inside the variant,
# do not support any variant without initializer.
i = None
continue
if custom_handler:
if custom_handler(variants, variant):
i = None
continue
if i is None:
raise Exception(f'All variants should have initializer : {variant}')
name = variant
value = i
variants.append((name, value))
i += 1
types[ty] = {
'dead': False,
'size': size,
'variants': variants
}
def extract_function_flags(paths):
kind_init_pat = re.compile(r'^([A-Za-z0-9_]+)=([A-Za-z0-9_]+)<<([A-Za-z0-9_]+)$')
combined_init_pat = re.compile(r'^([A-Za-z0-9_]+)=([A-Za-z0-9_]+(\|[A-Za-z0-9_]+)*)$')
def custom_handler(variants, variant):
m = kind_init_pat.search(variant)
if m:
name = m.group(1)
bits = m.group(2)
shift = m.group(3)
value = f'(FunctionKind::{bits} as u16) << {shift}'
variants.append((name, value))
return True
m = combined_init_pat.search(variant)
if m:
name = m.group(1)
value = m.group(2)
variants.append((name, value))
return True
raise Exception(f'unhandled variant {variant}')
types = {}
extract_enum(types, paths, 'Flags', 'FunctionFlags.h',
custom_handler)
assert types['Flags']['size'] == 'u16'
return types['Flags']['variants']
def extract_types(paths):
types = {}
@ -291,6 +296,7 @@ def extract_types(paths):
sys.exit(1)
types[ty] = {
'dead': False,
'size': 'u32',
'variants': variants
}
@ -327,6 +333,7 @@ def extract_types(paths):
sys.exit(1)
types[ty] = {
'dead': False,
'size': 'u8',
'variants': variants
}
@ -345,14 +352,26 @@ def extract_types(paths):
return types
def extract_script_types(paths):
types = {}
extract_enum(types, paths, 'ImmutableScriptFlagsEnum', 'StencilEnums.h')
types['ImmutableScriptFlagsEnum']['dead'] = True
extract_enum(types, paths, 'MutableScriptFlagsEnum', 'StencilEnums.h')
types['MutableScriptFlagsEnum']['dead'] = True
# Remove unused mask that doesn't follow the naming convention.
types['MutableScriptFlagsEnum']['variants'] = \
filter(lambda item: item[0] != 'WarmupResets_MASK',
types['MutableScriptFlagsEnum']['variants'])
return types
def extract_function_types(paths):
types = {}
extract_enum(types, paths, 'FunctionKind', filename='FunctionFlags.h')
#extract_enum(types, paths, 'GeneratorKind',
# filename='GeneratorAndAsyncKind.h')
#extract_enum(types, paths, 'FunctionAsyncKind',
# filename='GeneratorAndAsyncKind.h')
return types
@ -454,10 +473,15 @@ def parse_operands(opcode):
return params
def generate_emit_types(out_f, types):
def generate_types(out_f, types):
for ty in types:
variants = []
for variant, i in types[ty]['variants']:
if types[ty]['dead']:
variants.append(dedent(f"""\
#[allow(dead_code)]
"""))
variants.append(dedent(f"""\
{variant} = {i},
"""))
@ -562,7 +586,7 @@ def generate_emit_methods(out_f, opcodes, types):
"""))
def update_emit(path, types):
def update_emitter(path, types):
sys.path.append(vm_dir)
from jsopcode import get_opcodes
@ -585,7 +609,7 @@ def update_emit(path, types):
elif '@@@@ BEGIN TYPES @@@@' in line:
state = 'types'
out_f.write(line)
generate_emit_types(out_f, types)
generate_types(out_f, types)
elif '@@@@ END TYPES @@@@' in line:
assert state == 'types'
state = 'normal'
@ -613,7 +637,7 @@ def update_function(path, types, flags):
if '@@@@ BEGIN TYPES @@@@' in line:
state = 'types'
out_f.write(line)
generate_emit_types(out_f, types)
generate_types(out_f, types)
format_function_flags(out_f, flags)
elif '@@@@ END TYPES @@@@' in line:
assert state == 'types'
@ -627,6 +651,29 @@ def update_function(path, types, flags):
rustfmt(path)
def update_script(path, types):
tmppath = f'{path}.tmp'
with open(path, 'r') as in_f:
with open(tmppath, 'w') as out_f:
state = 'normal'
for line in in_f:
if '@@@@ BEGIN TYPES @@@@' in line:
state = 'types'
out_f.write(line)
generate_types(out_f, types)
elif '@@@@ END TYPES @@@@' in line:
assert state == 'types'
state = 'normal'
out_f.write(line)
elif state == 'normal':
out_f.write(line)
assert state == 'normal'
os.replace(tmppath, path)
rustfmt(path)
def copy_input(paths):
for name, path in paths.items():
shutil.copyfile(path,
@ -635,14 +682,16 @@ def copy_input(paths):
opcodes = extract_opcodes(input_paths)
opcode_flags = extract_opcode_flags(input_paths)
types = extract_types(input_paths)
emitter_types = extract_types(input_paths)
function_flags = extract_function_flags(input_paths)
function_types = extract_function_types(input_paths)
update_opcode(opcode_dest_path, opcodes, opcode_flags)
update_emit(emitter_dest_path, types)
script_types = extract_script_types(input_paths)
update_opcode(opcode_dest_path, opcodes, opcode_flags)
update_emitter(emitter_dest_path, emitter_types)
update_function(function_dest_path, function_types, function_flags)
update_script(script_dest_path, script_types)
copy_input(input_paths)

2
third_party/rust/nom/.cargo-checksum.json поставляемый

Различия файлов скрыты, потому что одна или несколько строк слишком длинны

101
third_party/rust/nom/.travis.yml поставляемый
Просмотреть файл

@ -1,101 +0,0 @@
language: rust
# sudo is required to enable kcov to use the personality syscall
sudo: required
dist: trusty
cache: cargo
rust:
- nightly
- beta
- stable
- 1.31.0
env:
matrix:
- FEATURES='--features "regexp regexp_macros"'
before_script:
- eval git pull --rebase https://github.com/Geal/nom master
- eval git log --pretty=oneline HEAD~5..HEAD
matrix:
include:
- rust: nightly
env: FEATURES='--no-default-features'
- rust: nightly
env: FEATURES='--no-default-features --features "alloc"'
- rust: stable
env: FEATURES=''
- rust: nightly
env: DOC_FEATURES='--features "std lexical regexp regexp_macros" --no-default-features'
before_script:
- export PATH=$HOME/.cargo/bin:$PATH
script:
- eval cargo doc --verbose $DOC_FEATURES
- rust: nightly
env: FEATURES=''
before_script:
- export PATH=$HOME/.cargo/bin:$PATH
- cargo install cargo-update || echo "cargo-update already installed"
- cargo install cargo-travis || echo "cargo-travis already installed"
- cargo install-update -a
- mkdir -p target/kcov-master
script:
cargo coveralls --verbose --all-features
allow_failures:
- rust: stable
env: FEATURES=''
before_script:
- export PATH=$HOME/.cargo/bin:$PATH
- rustup component add rustfmt-preview
script:
- eval cargo fmt -- --write-mode=diff
notifications:
webhooks:
urls:
- https://webhooks.gitter.im/e/9c035a194ac4fd4cc061
on_success: change
on_failure: always
on_start: false
addons:
apt:
packages:
- libcurl4-openssl-dev
- libelf-dev
- libdw-dev
- binutils-dev
- cmake
sources:
- kalakris-cmake
cache:
directories:
- /home/travis/.cargo
before_cache:
- rm -rf /home/travis/.cargo/registry
script:
- eval cargo build --verbose $FEATURES
- eval cargo test --verbose $FEATURES
after_success: |
case "$TRAVIS_RUST_VERSION" in
nightly)
if [ "${TRAVIS_PULL_REQUEST_BRANCH:-$TRAVIS_BRANCH}" != "master" ]; then
git fetch &&
git checkout master &&
cargo bench --verbose
fi
if [ "$FEATURES" == '--features "regexp regexp_macros"' ]; then
cargo bench --verbose
fi
;;
*)
;;
esac