Skip to content

Commit df980c6

Browse files
Use mod for compiler and shared code
1 parent 10e5cac commit df980c6

File tree

4 files changed

+10
-8
lines changed

4 files changed

+10
-8
lines changed

build.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ macro_rules! rerun_if_changed {
2828
};
2929
}
3030

31-
include!("src/compiler-common.rs");
31+
include!("src/compiler_common.rs");
3232

3333
#[tokio::main]
3434
async fn main() -> StdResult<(), Box<dyn Error>> {

src/compiler.rs

+5-4
Original file line numberDiff line numberDiff line change
@@ -4,9 +4,10 @@ use rquickjs::{Context, Module, Runtime};
44
use tracing::trace;
55
use zstd::bulk::Compressor;
66

7-
use crate::vm::COMPRESSION_DICT;
8-
9-
include!("compiler-common.rs");
7+
use crate::{
8+
compiler_common::{human_file_size, DummyLoader, DummyResolver},
9+
vm::COMPRESSION_DICT,
10+
};
1011

1112
fn compress_module(bytes: &[u8]) -> io::Result<Vec<u8>> {
1213
let mut compressor = Compressor::with_dictionary(22, COMPRESSION_DICT)?;
@@ -21,7 +22,7 @@ fn compress_module(bytes: &[u8]) -> io::Result<Vec<u8>> {
2122
}
2223

2324
pub async fn compile_file(input_filename: &Path, output_filename: &Path) -> Result<(), String> {
24-
let resolver: (DummyResolver,) = (DummyResolver,);
25+
let resolver = (DummyResolver,);
2526
let loader = (DummyLoader,);
2627

2728
let rt = Runtime::new().unwrap();

src/compiler-common.rs src/compiler_common.rs

+3-3
Original file line numberDiff line numberDiff line change
@@ -6,23 +6,23 @@ use rquickjs::{
66
Ctx,
77
};
88

9-
struct DummyLoader;
9+
pub struct DummyLoader;
1010

1111
impl Loader for DummyLoader {
1212
fn load(&mut self, _ctx: &Ctx<'_>, name: &str) -> rquickjs::Result<ModuleData> {
1313
Ok(ModuleData::source(name, ""))
1414
}
1515
}
1616

17-
struct DummyResolver;
17+
pub struct DummyResolver;
1818

1919
impl Resolver for DummyResolver {
2020
fn resolve(&mut self, _ctx: &Ctx<'_>, _base: &str, name: &str) -> rquickjs::Result<String> {
2121
Ok(name.into())
2222
}
2323
}
2424

25-
fn human_file_size(size: usize) -> String {
25+
pub fn human_file_size(size: usize) -> String {
2626
let fsize = size as f64;
2727
let i = if size == 0 {
2828
0

src/main.rs

+1
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ mod buffer;
88
mod bytearray_buffer;
99
mod child_process;
1010
mod compiler;
11+
mod compiler_common;
1112
mod console;
1213
mod crypto;
1314
mod encoding;

0 commit comments

Comments
 (0)