pub struct BytecodeCompiler { /* private fields */ }
Expand description
Compiles JavaScript source code into bytecode.
use jsyc_compiler::{JSSourceCode, BytecodeCompiler};
let js_code = JSSourceCode::new("console.log('Hello World');".into());
let mut compiler = BytecodeCompiler::new();
let bytecode = compiler.compile(&js_code).expect("Failed to compile code");
println!("bytecode: {}", bytecode);
Implementations§
Source§impl BytecodeCompiler
impl BytecodeCompiler
Sourcepub fn add_var_decl(&mut self, decl: String) -> CompilerResult<Reg>
pub fn add_var_decl(&mut self, decl: String) -> CompilerResult<Reg>
Add a variable decleration to the compiler
By adding a variable declaration, you can inform the compiler about the existence of an external declaration. However, this is not necessary since dependencies are tracked and can be retrieved after the compilation through decl_dependencies.
Sourcepub fn decl_dependencies(&self) -> &DeclDepencies
pub fn decl_dependencies(&self) -> &DeclDepencies
Returns all dependencies on external declarations
Usually JavaScript depends on several function and variable declarations from outside
of the current script: such as window
, document
or setInterval
.
§Returns
A list of these dependencies and in which register they are expected to be. This result will be available after BytecodeCompiler::compile ran.
Sourcepub fn compile(&mut self, source: &JSSourceCode) -> BytecodeResult
pub fn compile(&mut self, source: &JSSourceCode) -> BytecodeResult
Compiles the provided JavaScript code into bytecode.
use jsyc_compiler::{JSSourceCode, BytecodeCompiler};
let js_code = JSSourceCode::new("console.log('Hello World');".into());
let mut compiler = BytecodeCompiler::new();
let bytecode = compiler.compile(&js_code).expect("Failed to compile code");
println!("bytecode: {}", bytecode);
Trait Implementations§
Source§impl Clone for BytecodeCompiler
impl Clone for BytecodeCompiler
Source§fn clone(&self) -> BytecodeCompiler
fn clone(&self) -> BytecodeCompiler
Returns a copy of the value. Read more
1.0.0 · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
Performs copy-assignment from
source
. Read moreAuto Trait Implementations§
impl Freeze for BytecodeCompiler
impl RefUnwindSafe for BytecodeCompiler
impl Send for BytecodeCompiler
impl Sync for BytecodeCompiler
impl Unpin for BytecodeCompiler
impl UnwindSafe for BytecodeCompiler
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self>
fn into_either(self, into_left: bool) -> Either<Self, Self>
Converts
self
into a Left
variant of Either<Self, Self>
if into_left
is true
.
Converts self
into a Right
variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
Converts
self
into a Left
variant of Either<Self, Self>
if into_left(&self)
returns true
.
Converts self
into a Right
variant of Either<Self, Self>
otherwise. Read more