33 std::vector<Phasor::Value> cpp_elements;
36 cpp_elements.reserve(c_value.
as.
a.
count);
37 for (
size_t i = 0; i < c_value.
as.
a.
count; ++i)
58 std::vector<std::unique_ptr<
PhasorValue[]>> &array_arena)
71 const auto &str = cpp_value.
asString();
72 auto c_str = std::make_unique<char[]>(str.length() + 1);
73 std::copy(str.begin(), str.end(), c_str.get());
74 c_str[str.length()] =
'\0';
76 string_arena.push_back(std::move(c_str));
80 const auto &cpp_array = *cpp_value.
asArray();
81 size_t count = cpp_array.size();
87 auto c_array = std::make_unique<PhasorValue[]>(count);
88 for (
size_t i = 0; i < count; ++i)
90 c_array[i] =
to_c_value(cpp_array[i], string_arena, array_arena);
94 array_arena.push_back(std::move(c_array));
104 std::vector<std::unique_ptr<char[]>> string_arena;
105 std::vector<std::unique_ptr<PhasorValue[]>> array_arena;
107 std::vector<PhasorValue> c_args;
108 c_args.reserve(args.size());
109 for (
const auto &arg : args)
111 c_args.push_back(
to_c_value(arg, string_arena, array_arena));
114 PhasorValue c_result = c_func(
reinterpret_cast<PhasorVM *
>(vm), (
int)c_args.size(), c_args.data());
PhasorValue(* PhasorNativeFunction)(PhasorVM *vm, int argc, const PhasorValue *argv)
Signature for a native C function that can be registered with the Phasor VM.
static PhasorValue phasor_make_array(const PhasorValue *elements, size_t count)
static PhasorValue phasor_make_float(double f)
static PhasorValue phasor_make_string(const char *s)
static PhasorValue phasor_make_null()
static PhasorValue phasor_make_bool(bool b)
static PhasorValue phasor_make_int(int64_t i)
struct PhasorVM PhasorVM
Phasor Virtual Machine pointer.
void registerNativeFunction(const std::string &name, NativeFunction fn)
Register a native function.
A value in the Phasor VM.
double asFloat() const
Get the value as a double.
std::string asString() const
Get the value as a string.
std::shared_ptr< ArrayInstance > asArray()
Get the value as an array.
int64_t asInt() const
Get the value as an integer.
ValueType getType() const
Get the type of the value.
bool asBool() const
Get the value as a boolean.
static Value createArray(std::vector< Value > elements={})
The Phasor Programming Language and Runtime.
void register_native_c_func(PhasorVM *vm, const char *name, PhasorNativeFunction func)
The concrete implementation of the PhasorRegisterFunction API call.
Phasor::Value from_c_value(const PhasorValue &c_value)
Converts a C-style FFI value to a C++ VM value.
Phasor::Value c_native_func_wrapper(PhasorNativeFunction c_func, Phasor::VM *vm, const std::vector< Phasor::Value > &args)
The "trampoline" that wraps a C function from a plugin.
PhasorValue to_c_value(const Phasor::Value &cpp_value, std::vector< std::unique_ptr< char[]> > &string_arena, std::vector< std::unique_ptr< PhasorValue[]> > &array_arena)
Converts a C++ VM value to a C-style FFI value.
Represents a value in the Phasor VM.
struct PhasorValue::@257106260015165034006071221344325333366100147341::@324103060207145140324203224012174236216253240107 a
const PhasorValue * elements
union PhasorValue::@257106260015165034006071221344325333366100147341 as