MCPcopy Create free account
hub / github.com/crownengine/crown / eval

Method eval

src/resource/shader_resource.cpp:2887–2921  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

2885 }
2886
2887 static s32 eval(const char *expr, u32 num_constants, const char **constant_names, const f32 *constant_values, CompileOptions &opts)
2888 {
2889 namespace el = expression_language;
2890
2891 el::CompileEnvironment env;
2892 env.num_variables = 0;
2893 env.variable_names = NULL;
2894 env.num_constants = num_constants;
2895 env.constant_names = constant_names;
2896 env.constant_values = constant_values;
2897 env.num_functions = countof(function_names);
2898 env.function_names = function_names;
2899 env.function_values = function_values;
2900 env.compute_function = compute_function;
2901
2902 f32 stack_data[32];
2903 f32 variables[32];
2904 expression_language::Stack stack(stack_data, countof(stack_data));
2905
2906 unsigned byte_code[1024];
2907 u32 num = expression_language::compile(expr
2908 , env
2909 , byte_code
2910 , countof(byte_code)
2911 );
2912 ENSURE_OR_RETURN(SHADER_RESOURCE, num <= countof(byte_code), opts);
2913
2914 bool ok = expression_language::run(byte_code, variables, stack);
2915 RETURN_IF_FALSE(SHADER_RESOURCE, ok && stack.size > 0
2916 , opts
2917 , "Failed to evaluate expression: '%s'"
2918 , expr
2919 );
2920 return (bool)stack_data[stack.size - 1];
2921 }
2922
2923 s32 compile_render_state(RenderState::State &state, const char *render_state, const Vector<DynamicString> &defines)
2924 {

Callers

nothing calls this directly

Calls 2

runFunction · 0.85
compileFunction · 0.70

Tested by

no test coverage detected