Skip to content

Commit

Permalink
Use mod for compiler and shared code
Browse files Browse the repository at this point in the history
  • Loading branch information
richarddavison committed Jan 24, 2024
1 parent 10e5cac commit df980c6
Show file tree
Hide file tree
Showing 4 changed files with 10 additions and 8 deletions.
2 changes: 1 addition & 1 deletion build.rs
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ macro_rules! rerun_if_changed {
};
}

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

#[tokio::main]
async fn main() -> StdResult<(), Box<dyn Error>> {
Expand Down
9 changes: 5 additions & 4 deletions src/compiler.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,10 @@ use rquickjs::{Context, Module, Runtime};
use tracing::trace;
use zstd::bulk::Compressor;

use crate::vm::COMPRESSION_DICT;

include!("compiler-common.rs");
use crate::{
compiler_common::{human_file_size, DummyLoader, DummyResolver},
vm::COMPRESSION_DICT,
};

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

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

let rt = Runtime::new().unwrap();
Expand Down
6 changes: 3 additions & 3 deletions src/compiler-common.rs → src/compiler_common.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,23 +6,23 @@ use rquickjs::{
Ctx,
};

struct DummyLoader;
pub struct DummyLoader;

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

struct DummyResolver;
pub struct DummyResolver;

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

fn human_file_size(size: usize) -> String {
pub fn human_file_size(size: usize) -> String {
let fsize = size as f64;
let i = if size == 0 {
0
Expand Down
1 change: 1 addition & 0 deletions src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ mod buffer;
mod bytearray_buffer;
mod child_process;
mod compiler;
mod compiler_common;
mod console;
mod crypto;
mod encoding;
Expand Down

0 comments on commit df980c6

Please sign in to comment.