-
Notifications
You must be signed in to change notification settings - Fork 11
Wip/cpp #4
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: master
Are you sure you want to change the base?
Wip/cpp #4
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Good work so far. Mostly just have suggestions for keeping this codebase more in sync with the others.
src/cpp/lib/testml/runtime.cpp
Outdated
_data = _ast["data"]; | ||
} | ||
|
||
json Runtime::exec_expr(json fragment) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The variable 'fragment' should be called 'expr' to match all the other implementations. Let's try to use the same names as much as possible across code bases. If a name conflicts for some reason I typically add an '_' to the end or some other predetermined unique-ifying method.
It's important for maintainers to be able to look at all the code bases and expect similar names, style and layout.
There will be times when people need to add a feature across 20 langs at once, and it should be relatively straightforward.
src/cpp/lib/testml/runtime.cpp
Outdated
|
||
json Runtime::exec_dot(json::array_t fragment) { | ||
json context = {}; // result of last call | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This line has trailing whitespace. I have a vim plugin that highlights it in red :)
Maybe we can add some kind of git check hook to prevent things like this being committed/pushed.
src/cpp/lib/testml/runtime.cpp
Outdated
namespace testml { | ||
|
||
namespace { | ||
bool is_all_lowercase(std::string const& s) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Functions like this should go into a testml/util.cpp
.
src/cpp/lib/testml/runtime.cpp
Outdated
return _currentBlock["point"][name]; | ||
} | ||
|
||
json Runtime::exec_dot(json::array_t fragment) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
fragment should be 'calls'
src/cpp/lib/testml/runtime.cpp
Outdated
return value[0].is_string() && value[0] == "=>"; | ||
} | ||
|
||
void Runtime::run() { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This function should be called 'test'. Also try to put the methods in the same order as the coffee and others. All the others are in sync in this way.
src/cpp/lib/testml/runtime.cpp
Outdated
for (auto& statement : _ast["code"]) { | ||
exec_expr(statement); | ||
} | ||
testml_done(); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This method should be 'testml_end'. I know it's just naming, but let's start out keeping things in sync. Makes it easier for me and others to jump in and help.
@@ -0,0 +1,29 @@ | |||
#include "wrapper.hpp" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why can't the wrapper methods go inside the runtime class? ie Why do we need a separate class here?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It's not a separate class. These functions will supposedly be reused by the Bridge"-r" and the Stdlib class, that's why it's separated into its own file.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm not certain that the bridge classes will (or should) know about and use testml runtime internals, but we can wait and see.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't understand.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@vendethiel now that we forged a common understanding on IRC, I get where you are going.
In TestML lingo a 'method' call like .foo
or .Bar
is called a 'callable'. .foo
is a user defined bridge class callable (because it is lower case) and .Bar
is a stdlib callable. Given that the testml::Bridge
(base class for user defined TestMLBridge
class) and testml::StdLib
both need the wrapper stuff I think that wrapper should be a testml::Callable
class and both testml::Bridge
and testml::StdLib
should inherit from it.
src/cpp/src/testml-run.cpp
Outdated
TestML_Run_TAP::run(file); | ||
// tap.run(); | ||
testml::Bridge bridge; | ||
bridge.bind("add", +[](int a, int b) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
These functions (supposedly user defined) need to be in test/testml-bridge.cpp
. That's where a user will add the C++ methods need to make the tests run.
|
||
using json = nlohmann::json; | ||
|
||
json Bridge::call(std::string const& name, std::vector<json> const& args) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't think the call
method belongs in the bridge base class. This implies that a user defined bridge method would want to call this method directly. Maybe this method should be called can
and it returns the bridge method pointer of the requested method, if found.
@vendethiel can you |
b47ad45
to
e568fdd
Compare
bc2d9c7
to
870b2a2
Compare
@vendethiel you should join #testml again. I'm in a nearby TZ for a while... |
e3477a2
to
870b2a2
Compare
Needed to run: make `test-runtime-cpp` from root dir.
C++ might be better implemented by generating C++ code from the Lingy AST. That's how I did Bash support for testml. Walking a JSON structure seemed like @vendethiel been looking for you on #testml Would like to discuss this approach with you. |
I've been connected a few times a week, rebased the PR late 2018. |
No description provided.