-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
created new NativeFunctionDefinition
- Loading branch information
Showing
6 changed files
with
54 additions
and
23 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
use crate::compiler::compiler_source::LiteralCompilerSource; | ||
use crate::compiler::native_fn::{ | ||
get_argument_at, Error, NativeFunction, NativeFunctionDefinition, NativeFunctionSignature, | ||
}; | ||
use crate::util::byte_buffer::ByteBuffer; | ||
|
||
#[derive(Default)] | ||
pub(crate) struct EvalNativeFunctionDef {} | ||
|
||
impl NativeFunctionDefinition for EvalNativeFunctionDef { | ||
fn create(&self) -> NativeFunction { | ||
NativeFunction::new( | ||
NativeFunctionSignature::new_unsafe("eval"), | ||
|arguments, compiler| { | ||
let buffer = get_argument_at(arguments, 0, "eval")?.clone(); | ||
let source = LiteralCompilerSource::anonymous( | ||
buffer | ||
.to_string() | ||
.map_err(|e| Error::Unknown(e.to_string()))?, | ||
); | ||
let result = compiler | ||
.compile(&source) | ||
.map_err(|e| Error::Unknown(e.to_string()))?; | ||
Ok(ByteBuffer::from(result.content)) | ||
}, | ||
) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
mod eval; | ||
pub(crate) use eval::EvalNativeFunctionDef; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters