Add indentation to LuaJIT output

This commit is contained in:
Rerumu 2022-08-20 21:50:47 -04:00
parent 369097c432
commit 7efeffeac6
5 changed files with 191 additions and 120 deletions

View File

@ -16,11 +16,11 @@ macro_rules! impl_write_number {
($name:tt, $numeric:ty) => {
fn $name(number: $numeric, w: &mut dyn Write) -> Result<()> {
match (number.classify(), number.is_sign_negative()) {
(FpCategory::Nan, true) => write!(w, "(0.0 / 0.0) "),
(FpCategory::Nan, false) => write!(w, "-(0.0 / 0.0) "),
(FpCategory::Infinite, true) => write!(w, "-math.huge "),
(FpCategory::Infinite, false) => write!(w, "math.huge "),
_ => write!(w, "{number:e} "),
(FpCategory::Nan, true) => write!(w, "(0.0 / 0.0)"),
(FpCategory::Nan, false) => write!(w, "-(0.0 / 0.0)"),
(FpCategory::Infinite, true) => write!(w, "-math.huge"),
(FpCategory::Infinite, false) => write!(w, "math.huge"),
_ => write!(w, "{number:e}"),
}
}
};
@ -30,9 +30,9 @@ impl DriverNoContext for Select {
fn write(&self, w: &mut dyn Write) -> Result<()> {
write!(w, "(")?;
Condition(self.condition()).write(w)?;
write!(w, "and ")?;
write!(w, " and ")?;
self.on_true().write(w)?;
write!(w, "or ")?;
write!(w, " or ")?;
self.on_false().write(w)?;
write!(w, ")")
}
@ -40,19 +40,19 @@ impl DriverNoContext for Select {
impl DriverNoContext for GetTemporary {
fn write(&self, w: &mut dyn Write) -> Result<()> {
write!(w, "reg_{} ", self.var())
write!(w, "reg_{}", self.var())
}
}
impl DriverNoContext for GetLocal {
fn write(&self, w: &mut dyn Write) -> Result<()> {
write!(w, "loc_{} ", self.var())
write!(w, "loc_{}", self.var())
}
}
impl DriverNoContext for GetGlobal {
fn write(&self, w: &mut dyn Write) -> Result<()> {
write!(w, "GLOBAL_LIST[{}].value ", self.var())
write!(w, "GLOBAL_LIST[{}].value", self.var())
}
}
@ -62,7 +62,7 @@ impl DriverNoContext for LoadAt {
self.pointer().write(w)?;
if self.offset() != 0 {
write!(w, "+ {}", self.offset())?;
write!(w, " + {}", self.offset())?;
}
write!(w, ")")
@ -71,7 +71,7 @@ impl DriverNoContext for LoadAt {
impl DriverNoContext for MemorySize {
fn write(&self, w: &mut dyn Write) -> Result<()> {
write!(w, "memory_at_{}.min ", self.memory())
write!(w, "memory_at_{}.min", self.memory())
}
}
@ -81,8 +81,8 @@ impl_write_number!(write_f64, f64);
impl DriverNoContext for Value {
fn write(&self, w: &mut dyn Write) -> Result<()> {
match self {
Self::I32(i) => write!(w, "{i} "),
Self::I64(i) => write!(w, "{i}LL "),
Self::I32(i) => write!(w, "{i}"),
Self::I64(i) => write!(w, "{i}LL"),
Self::F32(f) => write_f32(*f, w),
Self::F64(f) => write_f64(*f, w),
}
@ -104,7 +104,7 @@ impl DriverNoContext for BinOp {
if let Some(symbol) = self.op_type().as_symbol() {
write!(w, "(")?;
self.lhs().write(w)?;
write!(w, "{symbol} ")?;
write!(w, " {symbol} ")?;
self.rhs().write(w)?;
write!(w, ")")
} else {
@ -127,7 +127,7 @@ impl DriverNoContext for CmpOpBoolean<'_> {
if let Some(symbol) = cmp.op_type().as_symbol() {
cmp.lhs().write(w)?;
write!(w, "{symbol} ")?;
write!(w, " {symbol} ")?;
cmp.rhs().write(w)
} else {
let (head, tail) = cmp.op_type().as_name();
@ -145,7 +145,7 @@ impl DriverNoContext for CmpOp {
fn write(&self, w: &mut dyn Write) -> Result<()> {
write!(w, "(")?;
CmpOpBoolean(self).write(w)?;
write!(w, "and 1 or 0)")
write!(w, " and 1 or 0)")
}
}
@ -157,7 +157,7 @@ impl DriverNoContext for Condition<'_> {
CmpOpBoolean(node).write(w)
} else {
self.0.write(w)?;
write!(w, "~= 0 ")
write!(w, " ~= 0")
}
}
}

View File

@ -6,11 +6,37 @@ use std::{
use wasm_ast::node::BrTable;
#[macro_export]
macro_rules! indentation {
($mng:tt, $w:tt) => {{
let mut iter = 0..$mng.indentation();
iter.try_for_each(|_| write!($w, "\t"))
}};
}
#[macro_export]
macro_rules! indented {
($mng:tt, $w:tt, $($args:tt)*) => {{
indentation!($mng, $w)?;
write!($w, $($args)*)
}};
}
#[macro_export]
macro_rules! line {
($mng:tt, $w:tt, $($args:tt)*) => {{
indentation!($mng, $w)?;
writeln!($w, $($args)*)
}};
}
#[derive(Default)]
pub struct Manager {
table_map: HashMap<usize, usize>,
label_list: Vec<usize>,
num_label: usize,
indentation: usize,
}
impl Manager {
@ -38,6 +64,18 @@ impl Manager {
pub fn pop_label(&mut self) {
self.label_list.pop().unwrap();
}
pub fn indentation(&self) -> usize {
self.indentation
}
pub fn indent(&mut self) {
self.indentation += 1;
}
pub fn dedent(&mut self) {
self.indentation -= 1;
}
}
pub trait Driver {

View File

@ -9,7 +9,7 @@ use wasm_ast::node::{
};
use wasmparser::ValType;
use crate::analyzer::br_table;
use crate::{analyzer::br_table, indentation, indented, line};
use super::{
expression::Condition,
@ -21,13 +21,14 @@ impl Driver for Br {
let level = *mng.label_list().iter().nth_back(self.target()).unwrap();
if !self.align().is_aligned() {
indentation!(mng, w)?;
write_ascending("reg", self.align().new_range(), w)?;
write!(w, " = ")?;
write_ascending("reg", self.align().old_range(), w)?;
write!(w, " ")?;
writeln!(w)?;
}
write!(w, "goto continue_at_{level} ")
line!(mng, w, "goto continue_at_{level}")
}
}
@ -36,7 +37,6 @@ fn to_ordered_table<'a>(list: &'a [Br], default: &'a Br) -> Vec<&'a Br> {
data.sort_by_key(|v| v.target());
data.dedup_by_key(|v| v.target());
data
}
@ -54,39 +54,51 @@ fn write_search_layer(
let br = list[center];
if range.start != center {
write!(w, "if temp < {} then ", br.target())?;
line!(mng, w, "if temp < {} then", br.target())?;
mng.indent();
write_search_layer(range.start..center, list, mng, w)?;
write!(w, "else")?;
mng.dedent();
indented!(mng, w, "else")?;
}
if range.end != center + 1 {
write!(w, "if temp > {} then ", br.target())?;
writeln!(w, "if temp > {} then", br.target())?;
mng.indent();
write_search_layer(center + 1..range.end, list, mng, w)?;
write!(w, "else")?;
mng.dedent();
indented!(mng, w, "else")?;
}
write!(w, " ")?;
writeln!(w)?;
mng.indent();
br.write(mng, w)?;
write!(w, "end ")
mng.dedent();
line!(mng, w, "end")
}
fn write_table_setup(table: &BrTable, mng: &mut Manager, w: &mut dyn Write) -> Result<()> {
let id = mng.get_table_index(table);
write!(w, "if not br_map[{id}] then ")?;
write!(w, "br_map[{id}] = (function() return {{[0] =")?;
line!(mng, w, "if not br_map[{id}] then")?;
mng.indent();
line!(mng, w, "br_map[{id}] = (function()")?;
mng.indent();
indented!(mng, w, "return {{ [0] = ")?;
table
.data()
.iter()
.try_for_each(|v| write!(w, "{},", v.target()))?;
.try_for_each(|v| write!(w, "{}, ", v.target()))?;
write!(w, "}} end)()")?;
write!(w, "end ")?;
writeln!(w, "}}")?;
mng.dedent();
line!(mng, w, "end)()")?;
mng.dedent();
line!(mng, w, "end")?;
write!(w, "temp = br_map[{id}][")?;
indented!(mng, w, "temp = br_map[{id}][")?;
table.condition().write(w)?;
write!(w, "] or {} ", table.default().target())
writeln!(w, "] or {}", table.default().target())
}
impl Driver for BrTable {
@ -111,7 +123,7 @@ impl Driver for BrTable {
impl Driver for Terminator {
fn write(&self, mng: &mut Manager, w: &mut dyn Write) -> Result<()> {
match self {
Self::Unreachable => write!(w, "error(\"out of code bounds\")"),
Self::Unreachable => line!(mng, w, r#"error("out of code bounds")"#),
Self::Br(s) => s.write(mng, w),
Self::BrTable(s) => s.write(mng, w),
}
@ -121,10 +133,11 @@ impl Driver for Terminator {
fn write_inner_block(block: &Block, mng: &mut Manager, w: &mut dyn Write) -> Result<()> {
block.code().iter().try_for_each(|s| s.write(mng, w))?;
match block.last() {
Some(v) => v.write(mng, w),
None => Ok(()),
if let Some(v) = block.last() {
v.write(mng, w)?;
}
Ok(())
}
impl Driver for Block {
@ -134,18 +147,20 @@ impl Driver for Block {
match self.label_type() {
Some(LabelType::Forward) => {
write_inner_block(self, mng, w)?;
write!(w, "::continue_at_{label}::")?;
line!(mng, w, "::continue_at_{label}::")?;
}
Some(LabelType::Backward) => {
write!(w, "::continue_at_{label}::")?;
write!(w, "while true do ")?;
line!(mng, w, "::continue_at_{label}::")?;
line!(mng, w, "while true do")?;
mng.indent();
write_inner_block(self, mng, w)?;
if self.last().is_none() {
write!(w, "break ")?;
line!(mng, w, "break")?;
}
write!(w, "end ")?;
mng.dedent();
line!(mng, w, "end")?;
}
None => write_inner_block(self, mng, w)?,
}
@ -158,29 +173,34 @@ impl Driver for Block {
impl Driver for BrIf {
fn write(&self, mng: &mut Manager, w: &mut dyn Write) -> Result<()> {
write!(w, "if ")?;
indented!(mng, w, "if ")?;
Condition(self.condition()).write(w)?;
write!(w, "then ")?;
writeln!(w, " then")?;
mng.indent();
self.target().write(mng, w)?;
write!(w, "end ")
mng.dedent();
line!(mng, w, "end")
}
}
impl Driver for If {
fn write(&self, mng: &mut Manager, w: &mut dyn Write) -> Result<()> {
write!(w, "if ")?;
indented!(mng, w, "if ")?;
Condition(self.condition()).write(w)?;
write!(w, "then ")?;
writeln!(w, " then")?;
mng.indent();
self.on_true().write(mng, w)?;
mng.dedent();
if let Some(v) = self.on_false() {
write!(w, "else ")?;
line!(mng, w, "else")?;
mng.indent();
v.write(mng, w)?;
mng.dedent();
}
write!(w, "end ")
line!(mng, w, "end")
}
}
@ -262,19 +282,25 @@ impl DriverNoContext for MemoryGrow {
}
}
fn write_stat(stat: &dyn DriverNoContext, mng: &mut Manager, w: &mut dyn Write) -> Result<()> {
indentation!(mng, w)?;
stat.write(w)?;
writeln!(w)
}
impl Driver for Statement {
fn write(&self, mng: &mut Manager, w: &mut dyn Write) -> Result<()> {
match self {
Self::Block(s) => s.write(mng, w),
Self::BrIf(s) => s.write(mng, w),
Self::If(s) => s.write(mng, w),
Self::Call(s) => s.write(w),
Self::CallIndirect(s) => s.write(w),
Self::SetTemporary(s) => s.write(w),
Self::SetLocal(s) => s.write(w),
Self::SetGlobal(s) => s.write(w),
Self::StoreAt(s) => s.write(w),
Self::MemoryGrow(s) => s.write(w),
Self::Call(s) => write_stat(s, mng, w),
Self::CallIndirect(s) => write_stat(s, mng, w),
Self::SetTemporary(s) => write_stat(s, mng, w),
Self::SetLocal(s) => write_stat(s, mng, w),
Self::SetGlobal(s) => write_stat(s, mng, w),
Self::StoreAt(s) => write_stat(s, mng, w),
Self::MemoryGrow(s) => write_stat(s, mng, w),
}
}
}
@ -282,10 +308,10 @@ impl Driver for Statement {
fn write_parameter_list(ast: &FuncData, w: &mut dyn Write) -> Result<()> {
write!(w, "function(")?;
write_ascending("loc", 0..ast.num_param(), w)?;
write!(w, ")")
writeln!(w, ")")
}
fn write_variable_list(ast: &FuncData, w: &mut dyn Write) -> Result<()> {
fn write_variable_list(ast: &FuncData, mng: &mut Manager, w: &mut dyn Write) -> Result<()> {
let mut total = ast.num_param();
for data in ast.local_data().iter().filter(|v| v.0 != 0) {
@ -294,17 +320,17 @@ fn write_variable_list(ast: &FuncData, w: &mut dyn Write) -> Result<()> {
total = range.end;
write!(w, "local ")?;
indented!(mng, w, "local ")?;
write_ascending("loc", range.clone(), w)?;
write!(w, " = ")?;
write_separated(range, |_, w| w.write_all(typed), w)?;
write!(w, " ")?;
writeln!(w)?;
}
if ast.num_stack() != 0 {
write!(w, "local ")?;
indented!(mng, w, "local ")?;
write_ascending("reg", 0..ast.num_stack(), w)?;
write!(w, " ")?;
writeln!(w)?;
}
Ok(())
@ -314,22 +340,26 @@ impl Driver for FuncData {
fn write(&self, mng: &mut Manager, w: &mut dyn Write) -> Result<()> {
let br_map = br_table::visit(self);
mng.indent();
write_parameter_list(self, w)?;
write_variable_list(self, w)?;
write_variable_list(self, mng, w)?;
if !br_map.is_empty() {
write!(w, "local br_map, temp = {{}}, nil ")?;
line!(mng, w, "local br_map, temp = {{}}, nil")?;
}
mng.set_table_map(br_map);
self.code().write(mng, w)?;
if self.num_result() != 0 {
write!(w, "return ")?;
indented!(mng, w, "return ")?;
write_ascending("reg", 0..self.num_result(), w)?;
write!(w, " ")?;
writeln!(w)?;
}
write!(w, "end ")
mng.dedent();
line!(mng, w, "end")
}
}

View File

@ -46,7 +46,7 @@ fn write_named_array(name: &str, len: usize, w: &mut dyn Write) -> Result<()> {
None => return Ok(()),
};
write!(w, "local {name} = table_new({len}, 1)")
writeln!(w, "local {name} = table_new({len}, 1)")
}
fn write_constant(init: &InitExpr, type_info: &TypeInfo, w: &mut dyn Write) -> Result<()> {
@ -56,7 +56,7 @@ fn write_constant(init: &InitExpr, type_info: &TypeInfo, w: &mut dyn Write) -> R
if let Some(Statement::SetTemporary(stat)) = func.code().code().last() {
stat.value().write(w)
} else {
write!(w, r#"error("Valueless constant")"#)
writeln!(w, r#"error("Valueless constant")"#)
}
}
@ -69,7 +69,8 @@ fn write_import_of(list: &[Import], wanted: External, w: &mut dyn Write) -> Resu
.filter(|v| External::from(v.ty) == wanted)
.enumerate()
{
write!(w, r#"{upper}[{i}] = wasm["{module}"].{lower}["{name}"]"#)?;
write!(w, "\t")?;
writeln!(w, r#"{upper}[{i}] = wasm["{module}"].{lower}["{name}"]"#)?;
}
Ok(())
@ -79,13 +80,14 @@ fn write_export_of(list: &[Export], wanted: External, w: &mut dyn Write) -> Resu
let lower = wanted.as_ie_name();
let upper = lower.to_uppercase();
write!(w, "{lower} = {{")?;
writeln!(w, "\t\t{lower} = {{")?;
for Export { name, index, .. } in list.iter().filter(|v| External::from(v.kind) == wanted) {
write!(w, r#"["{name}"] = {upper}[{index}],"#)?;
write!(w, "\t\t\t")?;
writeln!(w, r#"["{name}"] = {upper}[{index}],"#)?;
}
write!(w, "}},")
writeln!(w, "\t\t}},")
}
fn write_import_list(list: &[Import], w: &mut dyn Write) -> Result<()> {
@ -111,9 +113,9 @@ fn write_table_list(wasm: &Module, w: &mut dyn Write) -> Result<()> {
let min = table.initial;
let max = table.maximum.unwrap_or(0xFFFF);
write!(
writeln!(
w,
"TABLE_LIST[{index}] = {{ min = {min}, max = {max}, data = {{}} }}"
"\tTABLE_LIST[{index}] = {{ min = {min}, max = {max}, data = {{}} }}"
)?;
}
@ -129,7 +131,7 @@ fn write_memory_list(wasm: &Module, w: &mut dyn Write) -> Result<()> {
let min = ty.initial;
let max = ty.maximum.unwrap_or(0xFFFF);
write!(w, "MEMORY_LIST[{index}] = rt.allocator.new({min}, {max})")?;
writeln!(w, "\tMEMORY_LIST[{index}] = rt.allocator.new({min}, {max})")?;
}
Ok(())
@ -142,9 +144,9 @@ fn write_global_list(wasm: &Module, type_info: &TypeInfo, w: &mut dyn Write) ->
for (i, global) in global.iter().enumerate() {
let index = offset + i;
write!(w, "GLOBAL_LIST[{index}] = {{ value =")?;
write!(w, "\tGLOBAL_LIST[{index}] = {{ value = ")?;
write_constant(&global.init_expr, type_info, w)?;
write!(w, "}}")?;
writeln!(w, " }}")?;
}
Ok(())
@ -160,13 +162,14 @@ fn write_element_list(list: &[Element], type_info: &TypeInfo, w: &mut dyn Write)
_ => unimplemented!(),
};
write!(w, "do ")?;
write!(w, "local target = TABLE_LIST[{index}].data ")?;
write!(w, "local offset =")?;
writeln!(w, "\tdo")?;
writeln!(w, "\t\tlocal target = TABLE_LIST[{index}].data")?;
write!(w, "\t\tlocal offset = ")?;
write_constant(&init, type_info, w)?;
write!(w, "local data = {{")?;
writeln!(w)?;
write!(w, "\t\tlocal data = {{ ")?;
for item in element.items.get_items_reader().unwrap() {
match item.unwrap() {
@ -175,11 +178,9 @@ fn write_element_list(list: &[Element], type_info: &TypeInfo, w: &mut dyn Write)
}?;
}
write!(w, "}}")?;
write!(w, "table.move(data, 1, #data, offset, target)")?;
write!(w, "end ")?;
writeln!(w, " }}")?;
writeln!(w, "\t\ttable.move(data, 1, #data, offset, target)")?;
writeln!(w, "\tend")?;
}
Ok(())
@ -195,10 +196,9 @@ fn write_data_list(list: &[Data], type_info: &TypeInfo, w: &mut dyn Write) -> Re
} => (memory_index, init_expr),
};
write!(w, "rt.store.string(")?;
write!(w, "MEMORY_LIST[{index}],")?;
write!(w, "\trt.store.string(MEMORY_LIST[{index}], ")?;
write_constant(&init, type_info, w)?;
write!(w, r#","{}")"#, data.data.escape_ascii())?;
writeln!(w, r#","{}")"#, data.data.escape_ascii())?;
}
Ok(())
@ -219,17 +219,19 @@ fn write_local_operation(head: &str, tail: &str, w: &mut dyn Write) -> Result<()
write!(w, "local {head}_{tail} = ")?;
match (head, tail) {
("abs" | "ceil" | "floor" | "sqrt", _) => write!(w, "math.{head} "),
("rem", "i32") => write!(w, "math.fmod "),
("band" | "bor" | "bxor" | "bnot", _) => write!(w, "bit.{head} "),
("shl", _) => write!(w, "bit.lshift "),
("shr", "i32" | "i64") => write!(w, "bit.arshift "),
("shr", "u32" | "u64") => write!(w, "bit.rshift "),
("rotl", _) => write!(w, "bit.rol "),
("rotr", _) => write!(w, "bit.ror "),
("convert", "f32_i64" | "f64_i64") => write!(w, "tonumber "),
_ => write!(w, "rt.{head}.{tail} "),
}
("abs" | "ceil" | "floor" | "sqrt", _) => write!(w, "math.{head}"),
("rem", "i32") => write!(w, "math.fmod"),
("band" | "bor" | "bxor" | "bnot", _) => write!(w, "bit.{head}"),
("shl", _) => write!(w, "bit.lshift"),
("shr", "i32" | "i64") => write!(w, "bit.arshift"),
("shr", "u32" | "u64") => write!(w, "bit.rshift"),
("rotl", _) => write!(w, "bit.rol"),
("rotr", _) => write!(w, "bit.ror"),
("convert", "f32_i64" | "f64_i64") => write!(w, "tonumber"),
_ => write!(w, "rt.{head}.{tail}"),
}?;
writeln!(w)
}
fn write_localize_used(func_list: &[FuncData], w: &mut dyn Write) -> Result<BTreeSet<usize>> {
@ -246,17 +248,17 @@ fn write_localize_used(func_list: &[FuncData], w: &mut dyn Write) -> Result<BTre
}
for mem in &mem_set {
write!(w, "local memory_at_{mem} ")?;
writeln!(w, "local memory_at_{mem}")?;
}
Ok(mem_set)
}
fn write_func_start(wasm: &Module, index: u32, w: &mut dyn Write) -> Result<()> {
write!(w, "FUNC_LIST[{index}] =")?;
write!(w, "FUNC_LIST[{index}] = ")?;
match wasm.name_section().get(&index) {
Some(name) => write!(w, "--[[ {name} ]]"),
Some(name) => write!(w, "--[[ {name} ]] "),
None => Ok(()),
}
}
@ -279,29 +281,30 @@ fn write_module_start(
mem_set: &BTreeSet<usize>,
w: &mut dyn Write,
) -> Result<()> {
write!(w, "local function run_init_code()")?;
writeln!(w, "local function run_init_code()")?;
write_table_list(wasm, w)?;
write_memory_list(wasm, w)?;
write_global_list(wasm, type_info, w)?;
write_element_list(wasm.element_section(), type_info, w)?;
write_data_list(wasm.data_section(), type_info, w)?;
write!(w, "end ")?;
writeln!(w, "end")?;
write!(w, "return function(wasm)")?;
writeln!(w, "return function(wasm)")?;
write_import_list(wasm.import_section(), w)?;
write!(w, "run_init_code()")?;
writeln!(w, "\trun_init_code()")?;
for mem in mem_set {
write!(w, "memory_at_{mem} = MEMORY_LIST[{mem}]")?;
writeln!(w, "\tmemory_at_{mem} = MEMORY_LIST[{mem}]")?;
}
if let Some(start) = wasm.start_section() {
write!(w, "FUNC_LIST[{start}]()")?;
writeln!(w, "\tFUNC_LIST[{start}]()")?;
}
write!(w, "return {{")?;
writeln!(w, "\treturn {{")?;
write_export_list(wasm.export_section(), w)?;
write!(w, "}} end ")
writeln!(w, "\t}}")?;
writeln!(w, "end")
}
/// # Errors
@ -318,7 +321,7 @@ pub fn from_module_typed(wasm: &Module, type_info: &TypeInfo, w: &mut dyn Write)
let func_list = build_func_list(wasm, type_info);
let mem_set = write_localize_used(&func_list, w)?;
write!(w, "local table_new = require(\"table.new\")")?;
writeln!(w, "local table_new = require(\"table.new\")")?;
write_named_array("FUNC_LIST", wasm.function_space(), w)?;
write_named_array("TABLE_LIST", wasm.table_space(), w)?;
write_named_array("MEMORY_LIST", wasm.memory_space(), w)?;

View File

@ -92,9 +92,9 @@ impl Target for LuaJIT {
};
let data = Module::from_data(&bytes);
write!(w, "assert_trap((function() ")?;
writeln!(w, "assert_trap((function()")?;
codegen_luajit::from_module_untyped(&data, w)?;
writeln!(w, " end)(), linked)")
writeln!(w, "end)(), linked)")
}
}
}
@ -140,7 +140,7 @@ impl Target for LuaJIT {
let runtime = codegen_luajit::RUNTIME;
writeln!(w, "local rt = (function()")?;
writeln!(w, "{runtime}")?;
write!(w, "{runtime}")?;
writeln!(w, "end)()")?;
writeln!(w, "{ASSERTION}")
@ -149,7 +149,7 @@ impl Target for LuaJIT {
fn write_module(data: &Module, name: Option<&str>, w: &mut dyn Write) -> Result<()> {
let type_info = TypeInfo::from_module(data);
write!(w, r#"loaded["temp"] = (function() "#)?;
writeln!(w, r#"loaded["temp"] = (function()"#)?;
codegen_luajit::from_module_typed(data, &type_info, w)?;
writeln!(w, "end)()(linked)")?;