--- /dev/null
+/* Cycript - Optimizing JavaScript Compiler/Runtime
+ * Copyright (C) 2009-2013 Jay Freeman (saurik)
+*/
+
+/* GNU General Public License, Version 3 {{{ */
+/*
+ * Cycript is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published
+ * by the Free Software Foundation, either version 3 of the License,
+ * or (at your option) any later version.
+ *
+ * Cycript is distributed in the hope that it will be useful, but
+ * WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with Cycript. If not, see <http://www.gnu.org/licenses/>.
+**/
+/* }}} */
+
+#ifndef CODE_HPP
+#define CODE_HPP
+
+#include <iostream>
+
+#include "String.hpp"
+
+class CYStream :
+ public std::istream
+{
+ private:
+ class CYBuffer :
+ public std::streambuf
+ {
+ public:
+ CYBuffer(const char *start, const char *end) {
+ setg(const_cast<char *>(start), const_cast<char *>(start), const_cast<char *>(end));
+ }
+ } buffer_;
+
+ public:
+ CYStream(const char *start, const char *end) :
+ std::istream(&buffer_),
+ buffer_(start, end)
+ {
+ }
+};
+
+CYUTF8String CYPoolCode(CYPool &pool, std::istream &stream);
+
+#endif//CODE_HPP
#include <sstream>
#include <cmath>
-#include "Parser.hpp"
-
+#include "Code.hpp"
#include "Decode.hpp"
#include "Error.hpp"
#include "JavaScript.hpp"
std::stringstream wrap;
wrap << "(function (exports, require, module) { " << code << "\n});";
- code = CYPoolCode(pool, wrap.str().c_str());
+ code = CYPoolCode(pool, wrap);
JSValueRef value(_jsccall(JSEvaluateScript, context, CYJSString(code), NULL, NULL, 0));
JSObjectRef function(CYCastJSObject(context, value));
#include "Cycript.tab.hh"
#include "Driver.hpp"
+#include "Code.hpp"
static void Skip(const char *data, size_t size, std::ostream &output, size_t &offset, cy::position ¤t, cy::position target) {
while (current.line != target.line || current.column != target.column) {
return CYCastDouble(value, strlen(value));
}
-CYUTF8String CYPoolCode(CYPool &pool, CYUTF8String code) {
+CYUTF8String CYPoolCode(CYPool &pool, std::istream &stream) {
CYLocalPool local;
- CYStream stream(code.data, code.data + code.size);
CYDriver driver(stream);
cy::parser parser(driver);
#include <mach/mach.h>
#endif
+#include "Code.hpp"
#include "Error.hpp"
#include "JavaScript.hpp"
#include "String.hpp"
CYPool pool;
CYUTF8String utf8(CYPoolUTF8String(pool, CYUTF16String(*data, *size)));
- utf8 = CYPoolCode(pool, utf8);
+ CYStream stream(utf8.data, utf8.data + utf8.size);
+ utf8 = CYPoolCode(pool, stream);
CYUTF16String utf16(CYPoolUTF16String(pool, CYUTF8String(utf8.data, utf8.size)));
size_t bytes(utf16.size * sizeof(uint16_t));
virtual void Output(CYOutput &out, CYFlags flags) const;
};
-class CYStream :
- public std::istream
-{
- private:
- class CYBuffer :
- public std::streambuf
- {
- public:
- CYBuffer(const char *start, const char *end) {
- setg(const_cast<char *>(start), const_cast<char *>(start), const_cast<char *>(end));
- }
- } buffer_;
-
- public:
- CYStream(const char *start, const char *end) :
- std::istream(&buffer_),
- buffer_(start, end)
- {
- }
-};
-
struct CYForInitialiser {
virtual ~CYForInitialiser() {
}
#include <sstream>
#include "Pooling.hpp"
-#include "String.hpp"
bool CYRecvAll_(int socket, uint8_t *data, size_t size);
bool CYSendAll_(int socket, const uint8_t *data, size_t size);
CYPool &CYGetGlobalPool();
-CYUTF8String CYPoolCode(CYPool &pool, CYUTF8String code);
-
#endif/*CYCRIPT_HPP*/