forked from denoland/deno
-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
refactor(ops): Rewrite fast call optimizer and codegen (denoland#16514)
- Loading branch information
1 parent
92764c0
commit bc33a4b
Showing
39 changed files
with
1,702 additions
and
648 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
// Copyright 2018-2022 the Deno authors. All rights reserved. MIT license. | ||
use syn::{ | ||
parse::{Parse, ParseStream}, | ||
punctuated::Punctuated, | ||
Error, Ident, Result, Token, | ||
}; | ||
|
||
#[derive(Copy, Clone, Debug, Default)] | ||
pub struct Attributes { | ||
pub is_unstable: bool, | ||
pub is_v8: bool, | ||
pub must_be_fast: bool, | ||
pub deferred: bool, | ||
} | ||
|
||
impl Parse for Attributes { | ||
fn parse(input: ParseStream) -> Result<Self> { | ||
let vars = Punctuated::<Ident, Token![,]>::parse_terminated(input)?; | ||
|
||
let vars: Vec<_> = vars.iter().map(Ident::to_string).collect(); | ||
let vars: Vec<_> = vars.iter().map(String::as_str).collect(); | ||
for var in vars.iter() { | ||
if !["unstable", "v8", "fast", "deferred"].contains(var) { | ||
return Err(Error::new( | ||
input.span(), | ||
"invalid attribute, expected one of: unstable, v8, fast, deferred", | ||
)); | ||
} | ||
} | ||
Ok(Self { | ||
is_unstable: vars.contains(&"unstable"), | ||
is_v8: vars.contains(&"v8"), | ||
must_be_fast: vars.contains(&"fast"), | ||
deferred: vars.contains(&"deferred"), | ||
}) | ||
} | ||
} |
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,32 @@ | ||
// Copyright 2018-2022 the Deno authors. All rights reserved. MIT license. | ||
|
||
use proc_macro2::{Span, TokenStream}; | ||
use proc_macro_crate::{crate_name, FoundCrate}; | ||
use quote::quote; | ||
use syn::Ident; | ||
|
||
/// Identifier to the `deno_core` crate. | ||
/// | ||
/// If macro called in deno_core, `crate` is used. | ||
/// If macro called outside deno_core, `deno_core` OR the renamed | ||
/// version from Cargo.toml is used. | ||
pub(crate) fn import() -> TokenStream { | ||
let found_crate = | ||
crate_name("deno_core").expect("deno_core not present in `Cargo.toml`"); | ||
|
||
match found_crate { | ||
FoundCrate::Itself => { | ||
// TODO(@littledivy): This won't work for `deno_core` examples | ||
// since `crate` does not refer to `deno_core`. | ||
// examples must re-export deno_core to make this work | ||
// until Span inspection APIs are stabalized. | ||
// | ||
// https://github.com/rust-lang/rust/issues/54725 | ||
quote!(crate) | ||
} | ||
FoundCrate::Name(name) => { | ||
let ident = Ident::new(&name, Span::call_site()); | ||
quote!(#ident) | ||
} | ||
} | ||
} |
Oops, something went wrong.