X-Git-Url: https://git.saurik.com/cycript.git/blobdiff_plain/2e43a0b0c288f70981ab2715c8135ac7b9cd0f1b..97bec96b43b66ab78af95d2b6c6c24f0d0a8006a:/Syntax.cpp diff --git a/Syntax.cpp b/Syntax.cpp index 9fa3074..c568102 100644 --- a/Syntax.cpp +++ b/Syntax.cpp @@ -1,5 +1,5 @@ -/* Cycript - Optimizing JavaScript Compiler/Runtime - * Copyright (C) 2009-2015 Jay Freeman (saurik) +/* Cycript - The Truly Universal Scripting Language + * Copyright (C) 2009-2016 Jay Freeman (saurik) */ /* GNU Affero General Public License, Version 3 {{{ */ @@ -24,6 +24,7 @@ #include "Syntax.hpp" +// XXX: this implementation will break if value[size] is a digit double CYCastDouble(const char *value, size_t size) { char *end; double number(strtod(value, &end)); @@ -36,9 +37,71 @@ double CYCastDouble(const char *value) { return CYCastDouble(value, strlen(value)); } +double CYCastDouble(CYUTF8String value) { + return CYCastDouble(value.data, value.size); +} + template <> ::pthread_key_t CYLocal::key_ = Key_(); CYRange DigitRange_ (0x3ff000000000000LLU, 0x000000000000000LLU); // 0-9 CYRange WordStartRange_(0x000001000000000LLU, 0x7fffffe87fffffeLLU); // A-Za-z_$ CYRange WordEndRange_ (0x3ff001000000000LLU, 0x7fffffe87fffffeLLU); // A-Za-z_$0-9 + + + +// XXX: this really should not be here ... :/ + +#include +#include +#include +#include + +#include "String.hpp" + +struct CYFile { + void *data_; + size_t size_; + + CYFile(void *data, size_t size) : + data_(data), + size_(size) + { + } +}; + +static void CYFileExit(void *data) { + CYFile *file(reinterpret_cast(data)); + _syscall(munmap(file->data_, file->size_)); +} + +void *CYPoolFile(CYPool &pool, const char *path, size_t *psize) { + int fd(_syscall_(open(path, O_RDONLY), 1, ENOENT)); + if (fd == -1) + return NULL; + + struct stat stat; + _syscall(fstat(fd, &stat)); + size_t size(stat.st_size); + + *psize = size; + + void *base; + if (size == 0) + base = pool.strndup("", 0); + else { + _syscall(base = mmap(NULL, size, PROT_READ, MAP_SHARED, fd, 0)); + + CYFile *file(new (pool) CYFile(base, size)); + pool.atexit(&CYFileExit, file); + } + + _syscall(close(fd)); + return base; +} + +CYUTF8String CYPoolFileUTF8String(CYPool &pool, const char *path) { + CYUTF8String data; + data.data = reinterpret_cast(CYPoolFile(pool, path, &data.size)); + return data; +}