Enzo
Loading...
Searching...
No Matches
enzo::daslang::CompiledProgram Class Reference

A compiled daslang program ready to run. More...

#include <Runtime.h>

Classes

struct  Impl
 

Public Member Functions

bool evalFloat (const String &functionName, const expr::ExpressionContext *context, floatT &result, String &error)
 Evaluates an exported function as a float.
 
bool evalInt (const String &functionName, const expr::ExpressionContext *context, intT &result, String &error)
 Evaluates an exported function as an integer.
 
bool evalString (const String &functionName, const expr::ExpressionContext *context, String &result, String &error)
 Evaluates an exported function as a string.
 
bool run (const String &functionName, std::span< const ScriptArgument > arguments, const script::ScriptContext *context, size_t primitiveIndex, String &error)
 Runs an exported function for its side effects.
 
std::vector< bool > getWrittenArguments (const String &functionName) const
 Returns whether the function writes each of its arguments, in argument order.
 
std::vector< String > takeWarnings ()
 Returns the warnings the runs added and clears them.
 
std::shared_ptr< CompiledProgram > clone () const
 Returns a copy that shares the compiled program and runs in its own context.
 

Friends

class Runtime
 

Detailed Description

A compiled daslang program ready to run.

Reused across many evaluations so the cost of compiling is paid once. Each eval helper runs an exported function by name and returns its result.

Example

String error;
auto script = Runtime::instance().compile("expr", source, error);
floatT result = 0;
script->evalFloat("__eval__", result, error);
Note
daslang types stay inside the implementation so consumers never include daslang headers.

Member Function Documentation

◆ clone()

std::shared_ptr< CompiledProgram > enzo::daslang::CompiledProgram::clone ( ) const

Returns a copy that shares the compiled program and runs in its own context.

Returns
The clone, or null when its globals fail to initialise.
Note
A context runs one function at a time, so each thread needs its own clone.

◆ evalFloat()

bool enzo::daslang::CompiledProgram::evalFloat ( const String & functionName,
const expr::ExpressionContext * context,
floatT & result,
String & error )

Evaluates an exported function as a float.

Returns
True on success, false when the function is missing or panics.

◆ evalInt()

bool enzo::daslang::CompiledProgram::evalInt ( const String & functionName,
const expr::ExpressionContext * context,
intT & result,
String & error )

Evaluates an exported function as an integer.

Returns
True on success, false when the function is missing or panics.

◆ evalString()

bool enzo::daslang::CompiledProgram::evalString ( const String & functionName,
const expr::ExpressionContext * context,
String & result,
String & error )

Evaluates an exported function as a string.

Returns
True on success, false when the function is missing or panics.

◆ getWrittenArguments()

std::vector< bool > enzo::daslang::CompiledProgram::getWrittenArguments ( const String & functionName) const

Returns whether the function writes each of its arguments, in argument order.

Returns
One flag per argument, or empty when the function is missing.

◆ run()

bool enzo::daslang::CompiledProgram::run ( const String & functionName,
std::span< const ScriptArgument > arguments,
const script::ScriptContext * context,
size_t primitiveIndex,
String & error )

Runs an exported function for its side effects.

Parameters
primitiveIndexThe input primitive the function's attribute reads go to.
Returns
True on success, false when the function is missing or panics.

The documentation for this class was generated from the following files: