forked from Rust-related/RustPython
expose ascii! macro as pub
This commit is contained in:
@@ -3,9 +3,7 @@ use criterion::{
|
||||
criterion_group, criterion_main, BatchSize, BenchmarkGroup, BenchmarkId, Criterion, Throughput,
|
||||
};
|
||||
use rustpython_compiler::Mode;
|
||||
use rustpython_vm::ItemProtocol;
|
||||
use rustpython_vm::PyResult;
|
||||
use rustpython_vm::{InitParameter, Interpreter, PySettings};
|
||||
use rustpython_vm::{utils::ascii, InitParameter, Interpreter, ItemProtocol, PyResult, PySettings};
|
||||
use std::path::{Path, PathBuf};
|
||||
use std::{ffi, fs, io};
|
||||
|
||||
@@ -133,7 +131,7 @@ fn bench_rustpy_code(group: &mut BenchmarkGroup<WallTime>, bench: &MicroBenchmar
|
||||
scope
|
||||
.locals
|
||||
.set_item(
|
||||
vm.ctx.new_ascii_literal(crate::utils::ascii!("ITERATIONS")),
|
||||
vm.ctx.new_ascii_literal(ascii!("ITERATIONS")),
|
||||
vm.ctx.new_int(idx),
|
||||
vm,
|
||||
)
|
||||
|
||||
@@ -40,7 +40,7 @@ pub use rustpython_derive::*;
|
||||
|
||||
// This is above everything else so that the defined macros are available everywhere
|
||||
#[macro_use]
|
||||
pub mod macros;
|
||||
pub(crate) mod macros;
|
||||
|
||||
mod anystr;
|
||||
pub mod builtins;
|
||||
|
||||
@@ -249,3 +249,13 @@ cfg_if::cfg_if! {
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
macro_rules! ascii {
|
||||
($x:literal) => {{
|
||||
const _: () = {
|
||||
["not ascii"][!rustpython_vm::utils::bytes_is_ascii($x) as usize];
|
||||
};
|
||||
unsafe { ascii::AsciiStr::from_ascii_unchecked($x.as_bytes()) }
|
||||
}};
|
||||
}
|
||||
pub use ascii;
|
||||
|
||||
@@ -1,11 +1,13 @@
|
||||
use crate::builtins::{pystr::PyStr, PyFloat};
|
||||
use crate::exceptions::IntoPyException;
|
||||
use crate::{
|
||||
builtins::{pystr::PyStr, PyFloat},
|
||||
exceptions::IntoPyException,
|
||||
IntoPyObject, PyObjectRef, PyRef, PyResult, PyValue, TryFromObject, TypeProtocol,
|
||||
VirtualMachine,
|
||||
};
|
||||
use num_traits::ToPrimitive;
|
||||
|
||||
pub use crate::macros::ascii;
|
||||
|
||||
pub enum Either<A, B> {
|
||||
A(A),
|
||||
B(B),
|
||||
@@ -127,8 +129,7 @@ impl ToCString for PyStr {
|
||||
}
|
||||
}
|
||||
|
||||
#[allow(dead_code)]
|
||||
pub(crate) const fn bytes_is_ascii(x: &str) -> bool {
|
||||
pub const fn bytes_is_ascii(x: &str) -> bool {
|
||||
let x = x.as_bytes();
|
||||
let mut i = 0;
|
||||
while i < x.len() {
|
||||
@@ -139,14 +140,3 @@ pub(crate) const fn bytes_is_ascii(x: &str) -> bool {
|
||||
}
|
||||
true
|
||||
}
|
||||
|
||||
macro_rules! ascii {
|
||||
($x:literal) => {{
|
||||
const _: () = {
|
||||
["not ascii"][!crate::utils::bytes_is_ascii($x) as usize];
|
||||
};
|
||||
unsafe { ascii::AsciiStr::from_ascii_unchecked($x.as_bytes()) }
|
||||
}};
|
||||
}
|
||||
|
||||
pub(crate) use ascii;
|
||||
|
||||
Reference in New Issue
Block a user