Skip to main content

Compiler

Struct Compiler 

Source
pub struct Compiler {
    pub registry: Arc<ParserRegistry>,
    pub last_css: String,
    pub transformer: Transformer,
    pub stats: Option<CompileStats>,
    pub thread_pool_config: ThreadPoolConfig,
    pub compile_cache: HashMap<CompileCacheKey, CompileCacheValue>,
    pub cache_size_limit: usize,
    pub hot_cache: Option<(CompileCacheKey, CompileResult)>,
}
Expand description

Nargo 编译器

负责协调各个编译阶段,集成 nargo-parser、nargo-transformer 等组件,并提供编译配置和优化选项。

Fields§

§registry: Arc<ParserRegistry>

解析器注册表

§last_css: String

上次生成的 CSS

§transformer: Transformer

转换器

§stats: Option<CompileStats>

编译统计信息

§thread_pool_config: ThreadPoolConfig

线程池配置

§compile_cache: HashMap<CompileCacheKey, CompileCacheValue>

编译缓存

§cache_size_limit: usize

缓存大小限制(默认 1000)

§hot_cache: Option<(CompileCacheKey, CompileResult)>

热编译路径快速缓存

Implementations§

Source§

impl Compiler

Source

pub fn new() -> Self

创建新的编译器实例

Source

pub fn with_cache_size_limit(self, limit: usize) -> Self

设置缓存大小限制

§Arguments
  • limit - 缓存大小限制
§Returns

返回编译器实例,便于链式调用

Source

pub fn with_thread_pool_config(self, config: ThreadPoolConfig) -> Self

设置线程池配置

§Arguments
  • config - 线程池配置
§Returns

返回编译器实例,便于链式调用

Source

pub fn compile(&mut self, name: &str, source: &str) -> Result<CompileResult>

编译 Nargo 源代码

§Arguments
  • name - 组件名称
  • source - Nargo 源代码
§Returns

编译结果

Source

pub fn compile_with_options( &mut self, name: &str, source: &str, options: CompileOptions, ) -> Result<CompileResult>

使用自定义选项编译 Nargo 源代码

§Arguments
  • name - 组件名称
  • source - Nargo 源代码
  • options - 编译选项
§Returns

编译结果

Source

pub fn compile_to_ir( &mut self, name: &str, source: &str, options: &mut CompileOptions, ) -> Result<IRModule>

编译源代码到 IR 模块

§Arguments
  • name - 组件名称
  • source - Nargo 源代码
  • options - 编译选项
§Returns

IR 模块

Source

pub fn get_css(&self) -> String

获取上次生成的 CSS

§Returns

CSS 代码

Source

pub fn get_stats(&self) -> Option<&CompileStats>

获取编译统计信息

§Returns

编译统计信息

Source

pub fn reset(&mut self)

重置编译器状态

Source

pub fn compile_parallel( &self, files: &HashMap<String, String>, options: CompileOptions, ) -> Result<HashMap<String, CompileResult>>

并行编译多个 Nargo 源代码文件

§Arguments
  • files - 文件名和源代码的映射
  • options - 编译选项
§Returns

编译结果的映射,键为文件名,值为编译结果

Trait Implementations§

Source§

impl Clone for Compiler

Source§

fn clone(&self) -> Self

Returns a duplicate of the value. Read more
1.0.0 · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Default for Compiler

Source§

fn default() -> Self

Returns the “default value” for a type. Read more

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> IntoEither for T

Source§

fn into_either(self, into_left: bool) -> Either<Self, Self>

Converts self into a Left variant of Either<Self, Self> if into_left is true. Converts self into a Right variant of Either<Self, Self> otherwise. Read more
Source§

fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
where F: FnOnce(&Self) -> bool,

Converts self into a Left variant of Either<Self, Self> if into_left(&self) returns true. Converts self into a Right variant of Either<Self, Self> otherwise. Read more
Source§

impl<T> Pointable for T

Source§

const ALIGN: usize

The alignment of pointer.
Source§

type Init = T

The type for initializers.
Source§

unsafe fn init(init: <T as Pointable>::Init) -> usize

Initializes a with the given initializer. Read more
Source§

unsafe fn deref<'a>(ptr: usize) -> &'a T

Dereferences the given pointer. Read more
Source§

unsafe fn deref_mut<'a>(ptr: usize) -> &'a mut T

Mutably dereferences the given pointer. Read more
Source§

unsafe fn drop(ptr: usize)

Drops the object pointed to by the given pointer. Read more
Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
Source§

impl<V, T> VZip<V> for T
where V: MultiLane<T>,

Source§

fn vzip(self) -> V