Refactor import order
This commit is contained in:
parent
2d9c994917
commit
f00a27a38f
@ -1,7 +1,9 @@
|
|||||||
use super::{luajit::LuaJIT, luau::Luau};
|
|
||||||
use crate::backend::helper::writer::Writer;
|
|
||||||
use std::{fmt::Display, io::Result};
|
use std::{fmt::Display, io::Result};
|
||||||
|
|
||||||
|
use crate::backend::helper::writer::Writer;
|
||||||
|
|
||||||
|
use super::{luajit::LuaJIT, luau::Luau};
|
||||||
|
|
||||||
pub struct Infix<T> {
|
pub struct Infix<T> {
|
||||||
rhs: &'static str,
|
rhs: &'static str,
|
||||||
inner: T,
|
inner: T,
|
||||||
|
@ -1,7 +1,9 @@
|
|||||||
use super::data::{Edition, Infix};
|
|
||||||
use crate::backend::helper::writer::Writer;
|
|
||||||
use std::io::Result;
|
use std::io::Result;
|
||||||
|
|
||||||
|
use crate::backend::helper::writer::Writer;
|
||||||
|
|
||||||
|
use super::data::{Edition, Infix};
|
||||||
|
|
||||||
pub struct LuaJIT;
|
pub struct LuaJIT;
|
||||||
|
|
||||||
impl Edition for LuaJIT {
|
impl Edition for LuaJIT {
|
||||||
|
@ -1,7 +1,9 @@
|
|||||||
use super::data::{Edition, Infix};
|
|
||||||
use crate::backend::helper::writer::Writer;
|
|
||||||
use std::io::Result;
|
use std::io::Result;
|
||||||
|
|
||||||
|
use crate::backend::helper::writer::Writer;
|
||||||
|
|
||||||
|
use super::data::{Edition, Infix};
|
||||||
|
|
||||||
pub struct Luau;
|
pub struct Luau;
|
||||||
|
|
||||||
impl Edition for Luau {
|
impl Edition for Luau {
|
||||||
|
@ -1,4 +1,7 @@
|
|||||||
use super::level_2::list_to_range;
|
use std::{fmt::Display, io::Result, ops::Range};
|
||||||
|
|
||||||
|
use parity_wasm::elements::{BrTableData, Instruction};
|
||||||
|
|
||||||
use crate::{
|
use crate::{
|
||||||
backend::{
|
backend::{
|
||||||
edition::data::Edition,
|
edition::data::Edition,
|
||||||
@ -6,8 +9,28 @@ use crate::{
|
|||||||
},
|
},
|
||||||
data::{Arity, Code, Module},
|
data::{Arity, Code, Module},
|
||||||
};
|
};
|
||||||
use parity_wasm::elements::{BrTableData, Instruction};
|
|
||||||
use std::{fmt::Display, io::Result};
|
pub fn list_to_range(list: &[u32]) -> Vec<(Range<usize>, u32)> {
|
||||||
|
let mut result = Vec::new();
|
||||||
|
let mut index = 0;
|
||||||
|
|
||||||
|
while index < list.len() {
|
||||||
|
let start = index;
|
||||||
|
|
||||||
|
loop {
|
||||||
|
index += 1;
|
||||||
|
|
||||||
|
// if end of list or next value is not equal, break
|
||||||
|
if index == list.len() || list[index - 1] != list[index] {
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
result.push((start..index, list[start]));
|
||||||
|
}
|
||||||
|
|
||||||
|
result
|
||||||
|
}
|
||||||
|
|
||||||
#[derive(PartialEq)]
|
#[derive(PartialEq)]
|
||||||
pub enum Label {
|
pub enum Label {
|
||||||
|
@ -1,4 +1,7 @@
|
|||||||
use super::level_1::Body;
|
use std::io::{Result, Write};
|
||||||
|
|
||||||
|
use parity_wasm::elements::Instruction;
|
||||||
|
|
||||||
use crate::{
|
use crate::{
|
||||||
backend::{
|
backend::{
|
||||||
edition::data::Edition,
|
edition::data::Edition,
|
||||||
@ -6,33 +9,8 @@ use crate::{
|
|||||||
},
|
},
|
||||||
data::Module,
|
data::Module,
|
||||||
};
|
};
|
||||||
use parity_wasm::elements::Instruction;
|
|
||||||
use std::{
|
|
||||||
io::{Result, Write},
|
|
||||||
ops::Range,
|
|
||||||
};
|
|
||||||
|
|
||||||
pub fn list_to_range(list: &[u32]) -> Vec<(Range<usize>, u32)> {
|
use super::level_1::Body;
|
||||||
let mut result = Vec::new();
|
|
||||||
let mut index = 0;
|
|
||||||
|
|
||||||
while index < list.len() {
|
|
||||||
let start = index;
|
|
||||||
|
|
||||||
loop {
|
|
||||||
index += 1;
|
|
||||||
|
|
||||||
// if end of list or next value is not equal, break
|
|
||||||
if index == list.len() || list[index - 1] != list[index] {
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
result.push((start..index, list[start]));
|
|
||||||
}
|
|
||||||
|
|
||||||
result
|
|
||||||
}
|
|
||||||
|
|
||||||
pub fn gen_init_expression(code: &[Instruction], w: Writer) -> Result<()> {
|
pub fn gen_init_expression(code: &[Instruction], w: Writer) -> Result<()> {
|
||||||
assert!(code.len() == 2);
|
assert!(code.len() == 2);
|
||||||
|
@ -1,10 +1,13 @@
|
|||||||
use super::level_2::{gen_function, gen_init_expression};
|
use std::io::Result;
|
||||||
|
|
||||||
|
use parity_wasm::elements::{External, ImportCountType, Internal, ResizableLimits};
|
||||||
|
|
||||||
use crate::{
|
use crate::{
|
||||||
backend::{edition::data::Edition, helper::writer::Writer},
|
backend::{edition::data::Edition, helper::writer::Writer},
|
||||||
data::Module,
|
data::Module,
|
||||||
};
|
};
|
||||||
use parity_wasm::elements::{External, ImportCountType, Internal, ResizableLimits};
|
|
||||||
use std::io::Result;
|
use super::level_2::{gen_function, gen_init_expression};
|
||||||
|
|
||||||
const RUNTIME_DATA: &str = "
|
const RUNTIME_DATA: &str = "
|
||||||
local add = rt.add
|
local add = rt.add
|
||||||
|
@ -1,8 +1,10 @@
|
|||||||
use crate::backend::helper::writer::ordered_iter;
|
use std::{borrow::Cow, convert::TryInto};
|
||||||
|
|
||||||
use parity_wasm::elements::{
|
use parity_wasm::elements::{
|
||||||
External, FunctionType, ImportEntry, Instruction, Local, Module as WasmModule, Type,
|
External, FunctionType, ImportEntry, Instruction, Local, Module as WasmModule, Type,
|
||||||
};
|
};
|
||||||
use std::{borrow::Cow, convert::TryInto};
|
|
||||||
|
use crate::backend::helper::writer::ordered_iter;
|
||||||
|
|
||||||
pub struct Code<'a> {
|
pub struct Code<'a> {
|
||||||
pub num_local: u32,
|
pub num_local: u32,
|
||||||
|
@ -1,6 +1,6 @@
|
|||||||
use backend::{edition::data::from_string, translation::level_3};
|
use backend::{edition::data::from_string, translation::level_3};
|
||||||
use data::Module;
|
use data::Module;
|
||||||
use parity_wasm::elements::deserialize_file;
|
use parity_wasm::deserialize_file;
|
||||||
|
|
||||||
mod backend;
|
mod backend;
|
||||||
mod data;
|
mod data;
|
||||||
|
Loading…
x
Reference in New Issue
Block a user