pub struct Context<'a> {Show 16 fields
pub expressions: Arena<Expression>,
pub locals: Arena<LocalVariable>,
pub arguments: Vec<FunctionArgument>,
pub parameters: Vec<Handle<Type>>,
pub parameters_info: Vec<ParameterInfo>,
pub symbol_table: SymbolTable<String, VariableReference>,
pub samplers: FastHashMap<Handle<Expression>, Handle<Expression>>,
pub const_typifier: Typifier,
pub typifier: Typifier,
emitter: Emitter,
stmt_ctx: Option<StmtContext>,
pub body: Block,
pub module: &'a mut Module,
pub is_const: bool,
pub local_expression_kind_tracker: ExpressionKindTracker,
pub global_expression_kind_tracker: &'a mut ExpressionKindTracker,
}
Fields§
§expressions: Arena<Expression>
§locals: Arena<LocalVariable>
§arguments: Vec<FunctionArgument>
The FunctionArgument
s for the final crate::Function
.
Parameters with the out
and inout
qualifiers have Pointer
types
here. For example, an inout vec2 a
argument would be a Pointer
to
a Vector
.
parameters: Vec<Handle<Type>>
The parameter types given in the source code.
The out
and inout
qualifiers don’t affect the types that appear
here. For example, an inout vec2 a
argument would simply be a
Vector
, not a pointer to one.
parameters_info: Vec<ParameterInfo>
§symbol_table: SymbolTable<String, VariableReference>
§samplers: FastHashMap<Handle<Expression>, Handle<Expression>>
§const_typifier: Typifier
§typifier: Typifier
§emitter: Emitter
§stmt_ctx: Option<StmtContext>
§body: Block
§module: &'a mut Module
§is_const: bool
§local_expression_kind_tracker: ExpressionKindTracker
Tracks the expression kind of Expression
s residing in self.expressions
global_expression_kind_tracker: &'a mut ExpressionKindTracker
Tracks the expression kind of Expression
s residing in self.module.global_expressions
Implementations§
source§impl<'a> Context<'a>
impl<'a> Context<'a>
pub fn new( frontend: &Frontend, module: &'a mut Module, is_const: bool, global_expression_kind_tracker: &'a mut ExpressionKindTracker, ) -> Result<Self, Error>
pub fn new_body<F>(&mut self, cb: F) -> Result<Block, Error>
pub fn new_body_with_ret<F, R>(&mut self, cb: F) -> Result<(Block, R), Error>
pub fn with_body<F>(&mut self, body: Block, cb: F) -> Result<Block, Error>
pub fn add_global(&mut self, name: &str, _: GlobalLookup) -> Result<(), Error>
sourcepub fn emit_start(&mut self)
pub fn emit_start(&mut self)
sourcepub fn emit_end(&mut self)
pub fn emit_end(&mut self)
Emits all the expressions captured by the emitter to the current body
§Panics
- If called before calling
emit_start
. - If called twice in a row without calling
emit_start
.
sourcepub fn emit_restart(&mut self)
pub fn emit_restart(&mut self)
Emits all the expressions captured by the emitter to the current body and starts the emitter again
§Panics
- If called before calling
emit_start
.
pub fn add_expression( &mut self, expr: Expression, meta: Span, ) -> Result<Handle<Expression>, Error>
sourcepub fn add_local_var(
&mut self,
name: String,
expr: Handle<Expression>,
mutable: bool,
) -> Option<VariableReference>
pub fn add_local_var( &mut self, name: String, expr: Handle<Expression>, mutable: bool, ) -> Option<VariableReference>
Add variable to current scope
Returns a variable if a variable with the same name was already defined,
otherwise returns None
sourcepub fn add_function_arg(
&mut self,
name_meta: Option<(String, Span)>,
ty: Handle<Type>,
qualifier: ParameterQualifier,
) -> Result<(), Error>
pub fn add_function_arg( &mut self, name_meta: Option<(String, Span)>, ty: Handle<Type>, qualifier: ParameterQualifier, ) -> Result<(), Error>
Add function argument to current scope
sourcepub fn stmt_ctx(&mut self) -> StmtContext
pub fn stmt_ctx(&mut self) -> StmtContext
Returns a StmtContext
to be used in parsing and lowering
§Panics
- If more than one
StmtContext
are active at the same time or if the previous call didn’t use it in lowering.
sourcepub fn lower(
&mut self,
stmt: StmtContext,
frontend: &mut Frontend,
expr: Handle<HirExpr>,
pos: ExprPos,
) -> Result<(Option<Handle<Expression>>, Span), Error>
pub fn lower( &mut self, stmt: StmtContext, frontend: &mut Frontend, expr: Handle<HirExpr>, pos: ExprPos, ) -> Result<(Option<Handle<Expression>>, Span), Error>
Lowers a HirExpr
which might produce a Expression
.
consumes a StmtContext
returning it to the context so that it can be
used again later.
sourcepub fn lower_expect(
&mut self,
stmt: StmtContext,
frontend: &mut Frontend,
expr: Handle<HirExpr>,
pos: ExprPos,
) -> Result<(Handle<Expression>, Span), Error>
pub fn lower_expect( &mut self, stmt: StmtContext, frontend: &mut Frontend, expr: Handle<HirExpr>, pos: ExprPos, ) -> Result<(Handle<Expression>, Span), Error>
Similar to lower
but returns an error if the expression
returns void (ie. doesn’t produce a Expression
).
consumes a StmtContext
returning it to the context so that it can be
used again later.
sourcepub fn lower_expect_inner(
&mut self,
stmt: &StmtContext,
frontend: &mut Frontend,
expr: Handle<HirExpr>,
pos: ExprPos,
) -> Result<(Handle<Expression>, Span), Error>
pub fn lower_expect_inner( &mut self, stmt: &StmtContext, frontend: &mut Frontend, expr: Handle<HirExpr>, pos: ExprPos, ) -> Result<(Handle<Expression>, Span), Error>
internal implementation of lower_expect
this method is only public because it’s used in
function_call
, unless you know what
you’re doing use lower_expect
fn lower_store( &mut self, pointer: Handle<Expression>, value: Handle<Expression>, meta: Span, ) -> Result<(), Error>
sourcefn lower_inner(
&mut self,
stmt: &StmtContext,
frontend: &mut Frontend,
expr: Handle<HirExpr>,
pos: ExprPos,
) -> Result<(Option<Handle<Expression>>, Span), Error>
fn lower_inner( &mut self, stmt: &StmtContext, frontend: &mut Frontend, expr: Handle<HirExpr>, pos: ExprPos, ) -> Result<(Option<Handle<Expression>>, Span), Error>
Internal implementation of lower
pub fn expr_scalar_components( &mut self, expr: Handle<Expression>, meta: Span, ) -> Result<Option<Scalar>, Error>
pub fn expr_power( &mut self, expr: Handle<Expression>, meta: Span, ) -> Result<Option<u32>, Error>
pub fn conversion( &mut self, expr: &mut Handle<Expression>, meta: Span, scalar: Scalar, ) -> Result<(), Error>
pub fn implicit_conversion( &mut self, expr: &mut Handle<Expression>, meta: Span, scalar: Scalar, ) -> Result<(), Error>
pub fn forced_conversion( &mut self, expr: &mut Handle<Expression>, meta: Span, scalar: Scalar, ) -> Result<(), Error>
pub fn binary_implicit_conversion( &mut self, left: &mut Handle<Expression>, left_meta: Span, right: &mut Handle<Expression>, right_meta: Span, ) -> Result<(), Error>
pub fn implicit_splat( &mut self, expr: &mut Handle<Expression>, meta: Span, vector_size: Option<VectorSize>, ) -> Result<(), Error>
pub fn vector_resize( &mut self, size: VectorSize, vector: Handle<Expression>, meta: Span, ) -> Result<Handle<Expression>, Error>
source§impl Context<'_>
impl Context<'_>
sourcefn arg_type_walker(
&mut self,
name: Option<String>,
binding: Binding,
pointer: Handle<Expression>,
ty: Handle<Type>,
f: &mut impl FnMut(&mut Context<'_>, Option<String>, Handle<Expression>, Handle<Type>, Binding),
) -> Result<(), Error>
fn arg_type_walker( &mut self, name: Option<String>, binding: Binding, pointer: Handle<Expression>, ty: Handle<Type>, f: &mut impl FnMut(&mut Context<'_>, Option<String>, Handle<Expression>, Handle<Type>, Binding), ) -> Result<(), Error>
Helper function for building the input/output interface of the entry point
Calls f
with the data of the entry point argument, flattening composite types
recursively
The passed arguments to the callback are:
- The ctx
- The name
- The pointer expression to the global storage
- The handle to the type of the entry point argument
- The binding of the entry point argument
source§impl Context<'_>
impl Context<'_>
sourcepub(crate) fn typifier_grow(
&mut self,
expr: Handle<Expression>,
meta: Span,
) -> Result<(), Error>
pub(crate) fn typifier_grow( &mut self, expr: Handle<Expression>, meta: Span, ) -> Result<(), Error>
Resolves the types of the expressions until expr
(inclusive)
This needs to be done before the typifier
can be queried for
the types of the expressions in the range between the last grow and expr
.
§Note
The resolve_type*
methods (like resolve_type
) automatically
grow the typifier
so calling this method is not necessary when using
them.
pub(crate) fn get_type(&self, expr: Handle<Expression>) -> &TypeInner
sourcepub(crate) fn resolve_type(
&mut self,
expr: Handle<Expression>,
meta: Span,
) -> Result<&TypeInner, Error>
pub(crate) fn resolve_type( &mut self, expr: Handle<Expression>, meta: Span, ) -> Result<&TypeInner, Error>
Gets the type for the result of the expr
expression
Automatically grows the typifier
to expr
so calling
typifier_grow
is not necessary
sourcepub(crate) fn resolve_type_handle(
&mut self,
expr: Handle<Expression>,
meta: Span,
) -> Result<Handle<Type>, Error>
pub(crate) fn resolve_type_handle( &mut self, expr: Handle<Expression>, meta: Span, ) -> Result<Handle<Type>, Error>
Gets the type handle for the result of the expr
expression
Automatically grows the typifier
to expr
so calling
typifier_grow
is not necessary
§Note
Consider using resolve_type
whenever possible
since it doesn’t require adding each type to the types
arena
and it doesn’t need to mutably borrow the Parser
sourcepub(crate) fn invalidate_expression(
&mut self,
expr: Handle<Expression>,
meta: Span,
) -> Result<(), Error>
pub(crate) fn invalidate_expression( &mut self, expr: Handle<Expression>, meta: Span, ) -> Result<(), Error>
Invalidates the cached type resolution for expr
forcing a recomputation