-
Notifications
You must be signed in to change notification settings - Fork 71
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Split cairo-lang-macro crate into two (api <> abi)
commit-id:54582a03
- Loading branch information
Showing
12 changed files
with
197 additions
and
137 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
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,15 @@ | ||
[package] | ||
name = "cairo-lang-macro-stable" | ||
version = "1.0.0" | ||
edition.workspace = true | ||
|
||
authors.workspace = true | ||
categories = ["development-tools"] | ||
description = "Cairo procedural macro stable ABI interface primitives." | ||
homepage.workspace = true | ||
keywords = ["scarb"] | ||
license.workspace = true | ||
readme = "README.md" | ||
repository.workspace = true | ||
|
||
[dependencies] |
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,3 @@ | ||
# cairo-lang-macro-stable | ||
|
||
Stable interface for Scarb procedural macros. |
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,55 @@ | ||
use std::ffi::CString; | ||
use std::os::raw::c_char; | ||
|
||
/// Token stream. | ||
/// | ||
/// This struct implements FFI-safe stable ABI. | ||
#[repr(C)] | ||
#[derive(Debug)] | ||
pub struct StableTokenStream(*mut c_char); | ||
|
||
#[repr(C)] | ||
#[derive(Debug)] | ||
pub enum StableAuxData { | ||
None, | ||
Some(*mut c_char), | ||
} | ||
|
||
/// Procedural macro result. | ||
/// | ||
/// This struct implements FFI-safe stable ABI. | ||
#[repr(C)] | ||
#[derive(Debug)] | ||
pub enum StableProcMacroResult { | ||
/// Plugin has not taken any action. | ||
Leave, | ||
/// Plugin generated [`StableTokenStream`] replacement. | ||
Replace { | ||
token_stream: StableTokenStream, | ||
aux_data: StableAuxData, | ||
}, | ||
/// Plugin ordered item removal. | ||
Remove, | ||
} | ||
|
||
impl StableTokenStream { | ||
pub fn new(s: *mut c_char) -> Self { | ||
Self(s) | ||
} | ||
|
||
/// Convert to String. | ||
/// | ||
/// # Safety | ||
pub unsafe fn to_string(&self) -> String { | ||
raw_to_string(self.0) | ||
} | ||
} | ||
|
||
unsafe fn raw_to_string(raw: *mut c_char) -> String { | ||
if raw.is_null() { | ||
String::default() | ||
} else { | ||
let cstr = CString::from_raw(raw); | ||
cstr.to_string_lossy().to_string() | ||
} | ||
} |
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 was deleted.
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
Oops, something went wrong.