mvhooren / jitcat Goto Github PK
View Code? Open in Web Editor NEWA C++17 library for parsing and executing expressions. Allows easy exposure of variables and functions from C++ through built-in reflection functionality.
License: MIT License
A C++17 library for parsing and executing expressions. Allows easy exposure of variables and functions from C++ through built-in reflection functionality.
License: MIT License
.+0
gives an error, but 0+.
equals 0.0f
Because, well, a NAN != NAN
Even 0/0
Expression 1.
produces an int, should be float
When compiling JitCat with Clang or GCC on Linux and running the unit tests, often the unit tests will complete but then report a segmentation fault. This does not happen on Windows when compiling with MSVC or Clang.
I wanted to add more trigonometric functions, and noticed this:
case CatBuiltInFunctionType::Sin:
if (argumentTypes[0].isFloatType())
{
return (float)std::sin(std::any_cast<float>(argumentValues[0]));
}
else
{
return (float)std::sin((float)std::any_cast<int>(argumentValues[0]));
}
happening a lot.
As I understand, this branching would make sense if return type depended on the argument type(s), but in many cases the result is always float - so the only problem is converting type of the argument value - and I see that there is a CatGenericType::convertToFloat()
, that seems to do exactly that.
Wouldn't be better to rewrite these functions like this:
case CatBuiltInFunctionType::Sin:
return (float)std::sin(CatGenericType::convertToFloat(argumentValues[0], argumentTypes[0]));
This is due to an incompatibility between LLVM compiled with C++14 and JitCat compiled with C++17. I have filed a bugreport with LLVM: https://bugs.llvm.org/show_bug.cgi?id=44131
Meanwhile a workaround is to find Compiler.h in the llvm repo and commenting out or delete the #ifdef __cpp_aligned_new
blocks within the allocate_buffer
and deallocate_buffer
functions.
Like this:
inline void *allocate_buffer(size_t Size, size_t Alignment) {
return ::operator new(Size
/*#ifdef __cpp_aligned_new
,
std::align_val_t(Alignment)
#endif*/
);
}
and
inline void deallocate_buffer(void *Ptr, size_t Size, size_t Alignment) {
::operator delete(Ptr
#ifdef __cpp_sized_deallocation
,
Size
#endif
/*#ifdef __cpp_aligned_new
,
std::align_val_t(Alignment)
#endif*/
);
}
SECTION("Tan_obj")
{
Expression<float> testExpression(&context, "abs(nestedObject)");
doChecks(0.0f, true, false, false, testExpression, context);
}
Won't be surprized if there's more, that Tests.cpp is way too big...
LLVM seems to have migrated to C++14, and no longer has its own version of make_unique().
I had to search/replace it with std::make_unique() in the JitCat sources to compile it.
Constants work fine though
I know sometimes people use "log" as log10 and "ln" as natural log, but here I expected it to be consistent with C++ math functions
The BasicExample fails to compile if I just replace the float type with double.
Whoops, my bad - it seems that this type needs to be added to CatGenericTypes first.
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.