Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use mod for compiler and shared code #76

Merged
merged 1 commit into from
Jan 24, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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