Skip to content

Conversation

@ejpbruel2
Copy link
Contributor

Now for the magic. We're going to use template metaprogramming to obtain the properties of a function at compile time. Once we have that information, we can use it to do two different things.

First, we can use template metaprogramming to automatically generate all the boilerplate code for each function (checking if there are enough arguments, checking the type and obtaining the value of each argumetn, etc). The result will be a wrapper function with a signature that the interpreter can consume, regardless of the signature of the function being wrapped.

Second, we can use template metaprogramming to automatically generate an object, called a descriptor, that returns the run-time type of a function. More specifically, it uses the Type class we defined earlier to describe the run-time type of the result and parameters of the function. Later on, we will use this information to print a function table that can be consumed by the JavaScript side of the interpreter to automatically generate wrappers on that side, too.

Between wrappers and descriptors, descriptors are the easiest to understand, so we'll begin there. I'm using several C++11 features here that you may not be familiar with. If that's the case, it might be beneficial for you to read up on them. In particular, I'm using parameter packs to define template classes with zero or more template arguments:
http://en.cppreference.com/w/cpp/language/parameter_pack

Type result;
std::size_t parameters_size;
const Type* parameters;
};

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

why is parameters a pointer, and not say, a vector?

static constexpr Type value[] = {Type_of<typename std::remove_const<
typename std::remove_reference<Ts>::type>::type>::value...};
};

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this is very difficult for me to review, because even though I understand the function of parameter packs, i do not have any hands on experience with them. How do we deal with this?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants