#define _GNU_SOURCE
#include <substrate.h>
-#include "Struct.hpp"
+#include "cycript.h"
#include "sig/parse.hpp"
#include "sig/ffi_type.hpp"
#include "Pooling.hpp"
+#include "Struct.hpp"
#include <unistd.h>
#include <CoreFoundation/CFLogUtilities.h>
#include <CFNetwork/CFNetwork.h>
-#include <Foundation/Foundation.h>
-
-#include <JavaScriptCore/JSBase.h>
-#include <JavaScriptCore/JSValueRef.h>
-#include <JavaScriptCore/JSObjectRef.h>
-#include <JavaScriptCore/JSContextRef.h>
-#include <JavaScriptCore/JSStringRef.h>
-#include <JavaScriptCore/JSStringRefCF.h>
#include <WebKit/WebScriptObject.h>
} while (false)
-#define _pooled _H<NSAutoreleasePool> _pool([[NSAutoreleasePool alloc] init], true);
-
static JSContextRef Context_;
static JSClassRef Functor_;
@end
-JSContextRef JSGetContext() {
+extern "C" JSContextRef CYGetJSContext() {
return Context_;
}
return value == nil ? JSValueMakeNull(context) : [value cy$JSValueInContext:context];
}
-void CYThrow(JSContextRef context, id error, JSValueRef *exception) {
+extern "C" void CYThrowNSError(JSContextRef context, id error, JSValueRef *exception) {
*exception = CYCastJSValue(context, error);
}
@end
-CFStringRef JSValueToJSONCopy(JSContextRef context, JSValueRef value) {
+extern "C" CFStringRef CYCopyJSONString(JSContextRef context, JSValueRef value) {
id object(CYCastNSObject(context, value));
return reinterpret_cast<CFStringRef>([(object == nil ? @"null" : [object cy$toJSON]) retain]);
}
JSStringRef script(JSStringCreateWithCFString(code));
CFRelease(code);
- JSValueRef result(JSEvaluateScript(JSGetContext(), script, NULL, NULL, 0, NULL));
+ JSValueRef result(JSEvaluateScript(CYGetJSContext(), script, NULL, NULL, 0, NULL));
JSStringRelease(script);
CFHTTPMessageRef response(CFHTTPMessageCreateResponse(kCFAllocatorDefault, 200, NULL, kCFHTTPVersion1_1));
CFHTTPMessageSetHeaderFieldValue(response, CFSTR("Content-Type"), CFSTR("application/json; charset=utf-8"));
- CFStringRef json(JSValueToJSONCopy(JSGetContext(), result));
+ CFStringRef json(CYCopyJSONString(CYGetJSContext(), result));
CFDataRef body(CFStringCreateExternalRepresentation(kCFAllocatorDefault, json, kCFStringEncodingUTF8, NULL));
CFRelease(json);
if (NSMutableArray *entry = [Bridge_ objectForKey:name])
switch ([[entry objectAtIndex:0] intValue]) {
case 0:
- return JSEvaluateScript(JSGetContext(), CYJSString([entry objectAtIndex:1]), NULL, NULL, 0, NULL);
+ return JSEvaluateScript(CYGetJSContext(), CYJSString([entry objectAtIndex:1]), NULL, NULL, 0, NULL);
case 1:
return CYMakeFunction(context, [name cy$symbol], [[entry objectAtIndex:1] UTF8String]);
case 2:
};
CYDriver::CYDriver(const std::string &filename) :
+ state_(CYClear),
+ data_(NULL),
+ size_(0),
filename_(filename),
source_(NULL)
{
ScannerDestroy();
}
-extern int cydebug;
-
-void cy::parser::error(const cy::parser::location_type &loc, const std::string &msg) {
- std::cerr << loc << ": " << msg << std::endl;
-}
-
-void CYConsole(FILE *fin, FILE *fout, FILE *ferr) {
- cydebug = 1;
- CYDriver driver("<stdin>");
- cy::parser parser(driver);
- if (parser.parse() == 0)
- driver.source_->Part(std::cout);
+void cy::parser::error(const cy::parser::location_type &location, const std::string &message) {
+ CYDriver::Error error;
+ error.location_ = location;
+ error.message_ = message;
+ driver.errors_.push_back(error);
}
MSInitialize { _pooled
length_ = JSStringCreateWithUTF8CString("length");
JSValueRef exception(NULL);
- JSValueRef value(JSObjectGetProperty(JSGetContext(), global, CYJSString("Array"), &exception));
+ JSValueRef value(JSObjectGetProperty(CYGetJSContext(), global, CYJSString("Array"), &exception));
CYThrow(context, exception);
- Array_ = JSValueToObject(JSGetContext(), value, &exception);
+ Array_ = JSValueToObject(CYGetJSContext(), value, &exception);
CYThrow(context, exception);
}