Enzo
Loading...
Searching...
No Matches
Runtime.h
1#pragma once
2#include "Engine/Core/Types.h"
3#include <memory>
4#include <span>
5#include <variant>
6#include <vector>
7
8namespace enzo::expr {
9class ExpressionContext;
10}
11
12namespace enzo::script {
13class ScriptContext;
14}
15
16namespace enzo::daslang {
17
19using ScriptArgument = std::variant<intT, void*>;
20
22inline constexpr size_t maxScriptArguments = 32;
23
42{
43 public:
45
48 bool evalFloat(
49 const String& functionName,
50 const expr::ExpressionContext* context,
51 floatT& result,
52 String& error
53 );
54
57 bool evalInt(
58 const String& functionName,
59 const expr::ExpressionContext* context,
60 intT& result,
61 String& error
62 );
63
66 bool evalString(
67 const String& functionName,
68 const expr::ExpressionContext* context,
69 String& result,
70 String& error
71 );
72
76 bool run(
77 const String& functionName,
78 std::span<const ScriptArgument> arguments,
79 const script::ScriptContext* context,
80 size_t primitiveIndex,
81 String& error
82 );
83
86 std::vector<bool> getWrittenArguments(const String& functionName) const;
87
89 std::vector<String> takeWarnings();
90
97 std::shared_ptr<CompiledProgram> clone() const;
98
99 private:
100 friend class Runtime;
101 struct Impl;
102
103 explicit CompiledProgram(Impl impl);
104
105 std::unique_ptr<Impl> impl_;
106};
107
119{
120 public:
121 static Runtime& instance();
122
128 std::shared_ptr<CompiledProgram>
129 compile(const String& name, const String& source, String& error);
130
131 Runtime(const Runtime&) = delete;
132 Runtime& operator=(const Runtime&) = delete;
133
134 private:
135 Runtime();
136 ~Runtime();
137};
138
139} // namespace enzo::daslang
Basic attribute, parameter, and node types for Enzo.
A compiled daslang program ready to run.
Definition Runtime.h:42
std::vector< bool > getWrittenArguments(const String &functionName) const
Returns whether the function writes each of its arguments, in argument order.
Definition Runtime.cpp:164
bool evalString(const String &functionName, const expr::ExpressionContext *context, String &result, String &error)
Evaluates an exported function as a string.
Definition Runtime.cpp:132
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.
Definition Runtime.cpp:148
bool evalInt(const String &functionName, const expr::ExpressionContext *context, intT &result, String &error)
Evaluates an exported function as an integer.
Definition Runtime.cpp:119
std::shared_ptr< CompiledProgram > clone() const
Returns a copy that shares the compiled program and runs in its own context.
Definition Runtime.cpp:180
bool evalFloat(const String &functionName, const expr::ExpressionContext *context, floatT &result, String &error)
Evaluates an exported function as a float.
Definition Runtime.cpp:106
std::vector< String > takeWarnings()
Returns the warnings the runs added and clears them.
Definition Runtime.cpp:178
Shared host for the daslang runtime.
Definition Runtime.h:119
std::shared_ptr< CompiledProgram > compile(const String &name, const String &source, String &error)
Compiles source text into a reusable script.
Definition Runtime.cpp:212
The world a single expression evaluation reads and writes to.
Definition ExpressionContext.h:28
The world a script reads during one cook of a node.
Definition ScriptContext.h:28
Definition Runtime.cpp:26