Skip to content

Commit

Permalink
feat(vm): allow func as an external return type
Browse files Browse the repository at this point in the history
  • Loading branch information
lmichaelis committed Aug 5, 2023
1 parent 0044b99 commit 72759be
Showing 1 changed file with 6 additions and 3 deletions.
9 changes: 6 additions & 3 deletions include/phoenix/vm.hh
Original file line number Diff line number Diff line change
Expand Up @@ -834,7 +834,7 @@ namespace phoenix {
template <typename T>
typename std::enable_if<is_instance_ptr_v<T> || std::is_convertible_v<T, float> ||
std::is_convertible_v<T, std::int32_t> || std::is_same_v<T, std::string> ||
std::is_same_v<T, std::string_view>,
std::is_same_v<T, std::string_view> || std::is_same_v<T, func>,
void>::type
push_value_from_external(T v) { // clang-format on
if constexpr (is_instance_ptr_v<T>) {
Expand All @@ -843,6 +843,8 @@ namespace phoenix {
push_float(static_cast<float>(v));
} else if constexpr (std::is_convertible_v<std::int32_t, T>) {
push_int(static_cast<std::int32_t>(v));
} else if constexpr (std::is_same_v<func, T>) {
push_int(static_cast<std::int32_t>(v.value->index()));
} else if constexpr (std::is_same_v<T, std::string> || std::is_same_v<T, std::string_view>) {
push_string(v);
} else {
Expand Down Expand Up @@ -874,7 +876,8 @@ namespace phoenix {

template <typename R>
typename std::enable_if<is_instance_ptr_v<R> || std::is_same_v<R, float> || std::is_same_v<R, std::int32_t> ||
std::is_same_v<R, std::string> || std::is_same_v<R, void>,
std::is_same_v<R, func> || std::is_same_v<R, std::string> ||
std::is_same_v<R, void>,
void>::type
check_call_return_type(const symbol* sym) {
if constexpr (is_instance_ptr_v<R>) {
Expand All @@ -883,7 +886,7 @@ namespace phoenix {
} else if constexpr (std::is_same_v<float, R>) {
if (sym->rtype() != datatype::float_)
throw vm_exception {"invalid return type for function " + sym->name()};
} else if constexpr (std::is_same_v<int32_t, R>) {
} else if constexpr (std::is_same_v<int32_t, R> || std::is_same_v<func, R>) {
if (sym->rtype() != datatype::integer && sym->rtype() != datatype::function)
throw vm_exception {"invalid return type for function " + sym->name()};
} else if constexpr (std::is_same_v<std::string, R>) {
Expand Down

0 comments on commit 72759be

Please sign in to comment.