Skip to content

Commit

Permalink
removed benchmark result storage
Browse files Browse the repository at this point in the history
  • Loading branch information
lexa-diky committed Jul 10, 2024
1 parent f43c2d6 commit c495244
Show file tree
Hide file tree
Showing 13 changed files with 86 additions and 50 deletions.
1 change: 0 additions & 1 deletion src/compiler/compiler_source.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
use std::fmt::format;
use std::fs::File;
use std::io::Read;
use std::path::{Path, PathBuf};
Expand Down
2 changes: 1 addition & 1 deletion src/compiler/cst/macros.rs
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@
}

$(
let mut $holder = $holder.ok_or(Error::MissingContent {
let $holder = $holder.ok_or(Error::MissingContent {
node_type: AstNodeType::$option,
})?;
)+
Expand Down
2 changes: 0 additions & 2 deletions src/compiler/cst/mod.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
#![feature(concat_idents)]

pub(crate) use error::*;
pub(crate) use node::*;
pub(crate) use parser::*;
Expand Down
2 changes: 1 addition & 1 deletion src/compiler/cst/parser.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
use std::path::{Path, PathBuf};
use std::path::Path;

use crate::compiler::ast::{AstNode, AstNodeType};
use crate::compiler::cst::Error;
Expand Down
2 changes: 1 addition & 1 deletion src/compiler/hexo_compiler.rs
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ impl HexoCompiler {
) -> Result<Compilation, Error> {
let rst = self.compile_rst(source)?;

Ok(Compilation::from(rst.emits.to_vec()))
Ok(Compilation::from(rst.emits().to_vec()))
}
}

Expand Down
56 changes: 28 additions & 28 deletions src/compiler/native_fn/implementations.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,9 @@ use crate::compiler::native_fn::error::Error;
use crate::compiler::native_fn::signature::{NativeFunction, NativeFunctionSignature};

pub(crate) fn create_len_native_function() -> NativeFunction {
NativeFunction {
signature: NativeFunctionSignature::new("len"),
executor: |arguments: HashMap<String, ByteBuffer>, _| {
NativeFunction::new(
NativeFunctionSignature::new("len"),
|arguments: HashMap<String, ByteBuffer>, _| {
let mut result = ByteBuffer::default();
let arg0 = get_named_argument(&arguments, "utf8")
.unwrap_or_else(|| get_argument_at(&arguments, 0, "len").unwrap());
Expand All @@ -18,41 +18,41 @@ pub(crate) fn create_len_native_function() -> NativeFunction {
result.push_u32_shrunk(len);
Ok(result)
},
}
)
}

pub(crate) fn create_pad_left_native_function() -> NativeFunction {
NativeFunction {
signature: NativeFunctionSignature::new("pad_left"),
executor: |arguments: HashMap<String, ByteBuffer>, _| {
NativeFunction::new(
NativeFunctionSignature::new("pad_left"),
|arguments: HashMap<String, ByteBuffer>, _| {
let mut arg0 = get_argument_at(&arguments, 0, "pad_left")?.clone();
let arg1 = get_argument_at(&arguments, 1, "pad_left")?;

arg0.pad_left(arg1.as_usize_unsafe());

Ok(arg0.clone())
},
}
)
}

pub(crate) fn create_pad_right_native_function() -> NativeFunction {
NativeFunction {
signature: NativeFunctionSignature::new("pad_right"),
executor: |arguments: HashMap<String, ByteBuffer>, _| {
NativeFunction::new(
NativeFunctionSignature::new("pad_right"),
|arguments: HashMap<String, ByteBuffer>, _| {
let mut arg0: ByteBuffer = get_argument_at(&arguments, 0, "pad_right")?.clone();
let arg1 = get_argument_at(&arguments, 1, "pad_right")?;

arg0.pad_right(arg1.as_usize_unsafe());

Ok(arg0.clone())
},
}
)
}

pub(crate) fn create_cmd_native_function() -> NativeFunction {
NativeFunction {
signature: NativeFunctionSignature::new("cmd"),
executor: |arguments: HashMap<String, ByteBuffer>, _| {
NativeFunction::new(
NativeFunctionSignature::new("cmd"),
|arguments: HashMap<String, ByteBuffer>, _| {
let command = get_argument_at(&arguments, 0, "cmd")?
.to_string()
.map_err(|e| Error::Unknown(e.to_string()))?;
Expand All @@ -65,13 +65,13 @@ pub(crate) fn create_cmd_native_function() -> NativeFunction {

Ok(buffer)
},
}
)
}

pub(crate) fn create_read_file_native_function() -> NativeFunction {
return NativeFunction {
signature: NativeFunctionSignature::new("read_file"),
executor: |arguments: HashMap<String, ByteBuffer>, _| {
NativeFunction::new(
NativeFunctionSignature::new("read_file"),
|arguments: HashMap<String, ByteBuffer>, _| {
let arg0 = get_argument_at(&arguments, 0, "read_file")?;

let file_path = arg0
Expand All @@ -89,13 +89,13 @@ pub(crate) fn create_read_file_native_function() -> NativeFunction {

Ok(buffer)
},
};
)
}

pub(crate) fn create_pad_native_function() -> NativeFunction {
return NativeFunction {
signature: NativeFunctionSignature::new("pad"),
executor: |arguments: HashMap<String, ByteBuffer>, _| {
NativeFunction::new(
NativeFunctionSignature::new("pad"),
|arguments: HashMap<String, ByteBuffer>, _| {
let mut buffer = get_argument_at(&arguments, 0, "pad")?.clone();

let left_padding = get_named_argument(&arguments, "left").map(|b| b.as_usize_unsafe());
Expand All @@ -111,13 +111,13 @@ pub(crate) fn create_pad_native_function() -> NativeFunction {

Ok(buffer)
},
};
)
}

pub(crate) fn create_eval_native_function() -> NativeFunction {
return NativeFunction {
signature: NativeFunctionSignature::new("eval"),
executor: |arguments: HashMap<String, ByteBuffer>, compiler| {
NativeFunction::new(
NativeFunctionSignature::new("eval"),
|arguments: HashMap<String, ByteBuffer>, compiler| {
let buffer = get_argument_at(&arguments, 0, "eval")?.clone();
let source = LiteralCompilerSource::anonymous(
buffer.to_string()
Expand All @@ -127,7 +127,7 @@ pub(crate) fn create_eval_native_function() -> NativeFunction {
.map_err(|e| Error::Unknown(e.to_string()))?;
Ok(ByteBuffer::from(result.content))
},
};
)
}

fn get_argument_at<'a>(
Expand Down
2 changes: 1 addition & 1 deletion src/compiler/native_fn/index.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ impl NativeFunctionIndex {
}

pub(crate) fn find(&self, name: String) -> Option<&NativeFunction> {
return self.functions.iter().find(|f| f.signature.name == name);
return self.functions.iter().find(|f| f.signature().name == name);
}

fn create_native_functions() -> Vec<NativeFunction> {
Expand Down
21 changes: 19 additions & 2 deletions src/compiler/native_fn/signature.rs
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,23 @@ type NativeFunctionExecutor = fn(HashMap<String, ByteBuffer>, &HexoCompiler) ->

#[derive(Clone, Debug)]
pub(crate) struct NativeFunction {
pub(crate) signature: NativeFunctionSignature,
pub(crate) executor: NativeFunctionExecutor,
signature: NativeFunctionSignature,
executor: NativeFunctionExecutor,
}

impl NativeFunction {
pub(crate) fn new(signature: NativeFunctionSignature, executor: NativeFunctionExecutor) -> NativeFunction {
NativeFunction {
signature: signature,
executor: executor,
}
}

pub(crate) fn signature(&self) -> &NativeFunctionSignature {
&self.signature
}

pub(crate) fn executor(&self) -> NativeFunctionExecutor {
self.executor
}
}
10 changes: 5 additions & 5 deletions src/compiler/rst/compiler.rs
Original file line number Diff line number Diff line change
Expand Up @@ -27,11 +27,11 @@ impl RstCompiler<'_> {

let bb = self.build_bytes(context_id, &mut context, cst.main().emits())?;

Ok(HexoFile {
path: cst.path().to_path_buf(),
Ok(HexoFile::new(
cst.path().to_path_buf(),
context,
emits: bb,
})
bb,
))
}

fn build_bytes(
Expand Down Expand Up @@ -83,7 +83,7 @@ impl RstCompiler<'_> {
) -> Result<(), Error> {
let native_function = context.get_native_function(function_name.clone());
if native_function.is_some() {
let executor = native_function.unwrap().executor;
let executor = native_function.unwrap().executor();
let mut params_buffer = HashMap::new();

for param in params {
Expand Down
31 changes: 27 additions & 4 deletions src/compiler/rst/node.rs
Original file line number Diff line number Diff line change
@@ -1,10 +1,33 @@
use crate::compiler::rst::compilation_context::CompilationContext;
use crate::util::byte_buffer::ByteBuffer;
use std::path::PathBuf;
use std::path::{Path, PathBuf};

#[derive(Debug)]
pub(crate) struct HexoFile {
pub(crate) path: PathBuf,
pub(crate) context: CompilationContext,
pub(crate) emits: ByteBuffer,
path: PathBuf,
context: CompilationContext,
emits: ByteBuffer,
}

impl HexoFile {

pub(crate) fn new(path: PathBuf, context: CompilationContext, emits: ByteBuffer) -> HexoFile {
HexoFile {
path,
context,
emits,
}
}

pub(crate) fn path(&self) -> &Path {
&self.path.as_path()
}

pub(crate) fn context(&self) -> &CompilationContext {
&self.context
}

pub(crate) fn emits(&self) -> &ByteBuffer {
&self.emits
}
}
1 change: 0 additions & 1 deletion src/main.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
#![feature(test)]

use std::io::Read;

use crate::cli::Cli;

Expand Down
4 changes: 2 additions & 2 deletions src/util/defer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ pub(crate) struct Deferred<F: FnMut()> {

impl<F: FnMut()> Deferred<F> {
pub(crate) fn new(f: F) -> Self {
Deferred { f: f }
Deferred { f }
}
}

Expand All @@ -17,7 +17,7 @@ impl<F: FnMut()> Drop for Deferred<F> {
macro_rules! defer {
($e:stmt) => (
use crate::util::Deferred;
let _deferred = Deferred::new(|| -> () { $e; });
let _deferred = Deferred::new(|| -> () { $e });
)
}

Expand Down
2 changes: 1 addition & 1 deletion src/util/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,5 +3,5 @@ pub(crate) mod id;
pub(crate) mod logger;
mod defer;

pub use defer::*;
pub(crate) use defer::*;

0 comments on commit c495244

Please sign in to comment.