X-Git-Url: https://git.saurik.com/cycript.git/blobdiff_plain/d9c911529b1480684bb8b6280410f2d09c8525a1..972562bf68a236b4580b6074415cbf4e07b0a0c6:/Library.cpp diff --git a/Library.cpp b/Library.cpp index b04f2ca..7203225 100644 --- a/Library.cpp +++ b/Library.cpp @@ -19,14 +19,8 @@ **/ /* }}} */ -#include - #include "cycript.hpp" -#include "Pooling.hpp" - -#include - #include #include #include @@ -34,15 +28,17 @@ #include #include -#include "Error.hpp" -#include "Execute.hpp" -#include "Parser.hpp" -#include "String.hpp" +#include -#include "Cycript.tab.hh" -#include "Driver.hpp" +#include #include "ConvertUTF.h" +#include "Driver.hpp" +#include "Error.hpp" +#include "Execute.hpp" +#include "Pooling.hpp" +#include "String.hpp" +#include "Syntax.hpp" template <> ::pthread_key_t CYLocal::key_ = Key_(); @@ -176,6 +172,13 @@ void CYStringify(std::ostringstream &str, const char *data, size_t size) { } void CYNumerify(std::ostringstream &str, double value) { + if (std::isinf(value)) { + if (value < 0) + str << '-'; + str << "Infinity"; + return; + } + char string[32]; // XXX: I want this to print 1e3 rather than 1000 sprintf(string, "%.17g", value); @@ -217,21 +220,23 @@ double CYCastDouble(const char *value) { return CYCastDouble(value, strlen(value)); } +_visible bool CYStartsWith(const CYUTF8String &haystack, const CYUTF8String &needle) { + return haystack.size >= needle.size && strncmp(haystack.data, needle.data, needle.size) == 0; +} + CYUTF8String CYPoolCode(CYPool &pool, std::istream &stream) { CYLocalPool local; - CYDriver driver(stream); - - cy::parser parser(driver); - _assert(parser.parse() == 0); + CYDriver driver(local, stream); + _assert(!driver.Parse()); _assert(driver.errors_.empty()); CYOptions options; CYContext context(options); - driver.program_->Replace(context); + driver.script_->Replace(context); std::stringbuf str; CYOutput out(str, options); - out << *driver.program_; + out << *driver.script_; return $pool.strdup(str.str().c_str()); }