diff --git a/include/Void/Script/Types.hpp b/include/Void/Script/Types.hpp new file mode 100644 index 0000000..806ff42 --- /dev/null +++ b/include/Void/Script/Types.hpp @@ -0,0 +1,72 @@ +#pragma once + +#include +#include +#include +#include +#include + +namespace Void::Script +{ + +using Integer = std::int64_t; + +enum class ErrorKind : std::uint8_t { + compile = 0, + runtime, + allocator_limit, + instruction_limit, + host_call_limit, + result_limit, + host_error, + invalid_input, +}; + +struct Error { + ErrorKind kind{ErrorKind::runtime}; + std::string message; + + [[nodiscard]] bool operator==(const Error&) const = default; +}; + +struct Limits { + /// Total bytes the VM may allocate (including the state and libraries). + std::size_t max_allocator_bytes{1ULL * 1024ULL * 1024ULL}; + /// VM instructions before evaluation is aborted. + std::size_t max_instructions{100'000}; + /// Host function invocations before evaluation is aborted. + std::size_t max_host_calls{1'000}; + /// Maximum number of integer results collected. + std::size_t max_result_integers{1'024}; + /// Maximum number of integer-keyed inputs. + std::size_t max_inputs{256}; +}; + +/// Integer-keyed input exposed to the script as `input[key]`. +struct Input { + Integer key{0}; + Integer value{0}; + + [[nodiscard]] bool operator==(const Input&) const = default; +}; + +/// One host function call observed during a successful evaluation. The caller +/// may commit these effects after `evaluate` returns; the evaluator itself +/// never commits host state. +struct HostInvocation { + std::string host; + std::vector arguments; + Integer result{0}; + + [[nodiscard]] bool operator==(const HostInvocation&) const = default; +}; + +/// Owned result of a successful evaluation. +struct Result { + /// Integer values returned by the chunk, in order. + std::vector integers; + /// Host calls made by the script, in order. + std::vector host_calls; +}; + +} // namespace Void::Script