summaryrefslogtreecommitdiff
path: root/ops/lib.rs
diff options
context:
space:
mode:
authorMatt Mastracci <matthew@mastracci.com>2023-06-24 13:54:10 +0200
committerGitHub <noreply@github.com>2023-06-24 13:54:10 +0200
commit65d9bfb53361bfce6dc594c6a9df92c017dea6cb (patch)
tree63886c7225b52444165be3abd53c4e745ca77512 /ops/lib.rs
parent8d6dbda90ec0593f3f6e10c6696e320bdff7daa9 (diff)
refactor(ops): Adding op2 macro and implementing in a couple of places (#19534)
This is a new op system that will eventually replace `#[op]`. Features - More maintainable, generally less-coupled code - More modern Rust proc-macro libraries - Enforces correct `fast` labelling for fast ops, allowing for visual scanning of fast ops - Explicit marking of `#[string]`, `#[serde]` and `#[smi]` parameters. This first version of op2 supports integer and Option<integer> parameters only, and allows us to start working on converting ops and adding features.
Diffstat (limited to 'ops/lib.rs')
-rw-r--r--ops/lib.rs22
1 files changed, 22 insertions, 0 deletions
diff --git a/ops/lib.rs b/ops/lib.rs
index d7c8b0640..bd8ff9caf 100644
--- a/ops/lib.rs
+++ b/ops/lib.rs
@@ -8,6 +8,7 @@ use proc_macro2::Span;
use proc_macro2::TokenStream as TokenStream2;
use quote::quote;
use quote::ToTokens;
+use std::error::Error;
use syn::parse;
use syn::parse_macro_input;
use syn::punctuated::Punctuated;
@@ -22,6 +23,7 @@ use syn::LifetimeDef;
mod attrs;
mod deno;
mod fast_call;
+mod op2;
mod optimizer;
const SCOPE_LIFETIME: &str = "'scope";
@@ -235,6 +237,26 @@ pub fn op(attr: TokenStream, item: TokenStream) -> TokenStream {
op.gen().into()
}
+#[proc_macro_attribute]
+pub fn op2(attr: TokenStream, item: TokenStream) -> TokenStream {
+ match crate::op2::op2(attr.into(), item.into()) {
+ Ok(output) => output.into(),
+ Err(err) => {
+ let mut err: &dyn Error = &err;
+ let mut output = "Failed to parse #[op2]:\n".to_owned();
+ loop {
+ output += &format!(" - {err}\n");
+ if let Some(source) = err.source() {
+ err = source;
+ } else {
+ break;
+ }
+ }
+ panic!("{output}");
+ }
+ }
+}
+
/// Generate the body of a v8 func for an async op
fn codegen_v8_async(
core: &TokenStream2,