pub struct JsBackend {
pub module: JsModule,
pub fn_map: HashMap<String, String>,
pub fresh_counter: usize,
}Expand description
JavaScript code generation backend.
Compiles LCNF function declarations to a JsModule containing
ES2020+ JavaScript functions.
Fields§
§module: JsModuleThe module being built.
fn_map: HashMap<String, String>Mapping from LCNF names to mangled JS names.
fresh_counter: usizeCounter for generating fresh temporary variable names.
Implementations§
Source§impl JsBackend
impl JsBackend
Sourcepub fn mangle_name(&self, name: &str) -> String
pub fn mangle_name(&self, name: &str) -> String
Mangle an LCNF name into a valid JavaScript identifier.
Rules:
- Replace
.with_ - Replace
'(prime) with_prime - Prefix reserved words with
_
Sourcepub fn compile_module(decls: &[LcnfFunDecl]) -> Result<String, String>
pub fn compile_module(decls: &[LcnfFunDecl]) -> Result<String, String>
Top-level entry point: compile a slice of LCNF function declarations into a JavaScript module string.
Sourcepub fn compile_decl(&mut self, decl: &LcnfFunDecl) -> Result<JsFunction, String>
pub fn compile_decl(&mut self, decl: &LcnfFunDecl) -> Result<JsFunction, String>
Compile a single LCNF function declaration into a JsFunction.
Sourcepub fn compile_expr(
&mut self,
expr: &LcnfExpr,
stmts: &mut Vec<JsStmt>,
) -> Result<JsExpr, String>
pub fn compile_expr( &mut self, expr: &LcnfExpr, stmts: &mut Vec<JsStmt>, ) -> Result<JsExpr, String>
Compile an LCNF expression into a sequence of JS statements, returning the JS expression that holds the result.
Sourcepub fn compile_arg(&self, arg: &LcnfArg) -> JsExpr
pub fn compile_arg(&self, arg: &LcnfArg) -> JsExpr
Compile an LCNF argument (atomic value) into a JS expression.
Sourcepub fn compile_lit(&self, lit: &LcnfLit) -> JsExpr
pub fn compile_lit(&self, lit: &LcnfLit) -> JsExpr
Compile an LCNF literal into a JS expression.
Trait Implementations§
Auto Trait Implementations§
impl Freeze for JsBackend
impl RefUnwindSafe for JsBackend
impl Send for JsBackend
impl Sync for JsBackend
impl Unpin for JsBackend
impl UnsafeUnpin for JsBackend
impl UnwindSafe for JsBackend
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