mod array_emitter; mod ast_emitter; mod block_emitter; mod compilation_info; mod control_structures; mod dis; mod emitter; mod emitter_scope; mod expression_emitter; mod function_declaration_emitter; mod object_emitter; mod reference_op_emitter; mod script_emitter;
externcrate jsparagus_ast as ast; externcrate jsparagus_scope as scope; externcrate jsparagus_stencil as stencil;
use ast::source_atom_set::SourceAtomSet; use ast::source_slice_list::SourceSliceList; use scope::{ScopeBuildError, ScopePassResult}; use stencil::result::EmitResult;
// Error case for scope analysis will be removed once all syntax is // supported. Use field instead of Result type here for simplicity. match error {
Some(ScopeBuildError::NotImplemented(s)) => { return Err(EmitError::NotImplemented(s));
}
None => {}
}
#[cfg(test)] mod tests { externcrate jsparagus_parser as parser;
usesuper::{emit, EmitOptions}; usecrate::dis::*; use ast::source_atom_set::SourceAtomSet; use ast::source_slice_list::SourceSliceList; use bumpalo::Bump; use parser::{parse_script, ParseOptions}; use std::cell::RefCell; use std::convert::TryInto; use std::rc::Rc; use stencil::opcode::*; use stencil::script::SourceExtent;
fn bytecode(source: &str) -> Vec<u8> { let alloc = &Bump::new(); let parse_options = ParseOptions::new(); let atoms = Rc::new(RefCell::new(SourceAtomSet::new())); let slices = Rc::new(RefCell::new(SourceSliceList::new())); let source_len = source.len(); let parse_result =
parse_script(alloc, source, &parse_options, atoms.clone(), slices.clone())
.expect("Failed to parse"); // println!("{:?}", parse_result);
let extent = SourceExtent::top_level_script(source_len.try_into().unwrap(), 1, 0); let emit_options = EmitOptions::new(extent);
let result = emit(
alloc.alloc(ast::types::Program::Script(parse_result.unbox())),
&emit_options,
atoms.replace(SourceAtomSet::new_uninitialized()),
slices.replace(SourceSliceList::new()),
)
.expect("Should work!");
let script_data_index: usize = result.scripts[0]
.immutable_script_data
.expect("Top level script should have ImmutableScriptData")
.into(); let script_data = &result.script_data_list[script_data_index]; let bytecode = &script_data.bytecode;
Die Informationen auf dieser Webseite wurden
nach bestem Wissen sorgfältig zusammengestellt. Es wird jedoch weder Vollständigkeit, noch Richtigkeit,
noch Qualität der bereit gestellten Informationen zugesichert.
Bemerkung:
Die farbliche Syntaxdarstellung und die Messung sind noch experimentell.