]>
git.saurik.com Git - cycript.git/blob - Syntax.cpp
1 /* Cycript - Optimizing JavaScript Compiler/Runtime
2 * Copyright (C) 2009-2015 Jay Freeman (saurik)
5 /* GNU Affero General Public License, Version 3 {{{ */
7 * This program is free software: you can redistribute it and/or modify
8 * it under the terms of the GNU Affero General Public License as published by
9 * the Free Software Foundation, either version 3 of the License, or
10 * (at your option) any later version.
12 * This program is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 * GNU Affero General Public License for more details.
17 * You should have received a copy of the GNU Affero General Public License
18 * along with this program. If not, see <http://www.gnu.org/licenses/>.
27 // XXX: this implementation will break if value[size] is a digit
28 double CYCastDouble(const char *value
, size_t size
) {
30 double number(strtod(value
, &end
));
31 if (end
!= value
+ size
)
36 double CYCastDouble(const char *value
) {
37 return CYCastDouble(value
, strlen(value
));
40 double CYCastDouble(CYUTF8String value
) {
41 return CYCastDouble(value
.data
, value
.size
);
45 ::pthread_key_t CYLocal
<CYPool
>::key_
= Key_();
47 CYRange
DigitRange_ (0x3ff000000000000LLU
, 0x000000000000000LLU
); // 0-9
48 CYRange
WordStartRange_(0x000001000000000LLU
, 0x7fffffe87fffffeLLU
); // A-Za-z_$
49 CYRange
WordEndRange_ (0x3ff001000000000LLU
, 0x7fffffe87fffffeLLU
); // A-Za-z_$0-9
53 // XXX: this really should not be here ... :/
66 CYFile(void *data
, size_t size
) :
73 static void CYFileExit(void *data
) {
74 CYFile
*file(reinterpret_cast<CYFile
*>(data
));
75 _syscall(munmap(file
->data_
, file
->size_
));
78 void *CYPoolFile(CYPool
&pool
, const char *path
, size_t *psize
) {
79 int fd(_syscall_(open(path
, O_RDONLY
), 1, ENOENT
));
84 _syscall(fstat(fd
, &stat
));
85 size_t size(stat
.st_size
);
91 base
= pool
.strndup("", 0);
93 _syscall(base
= mmap(NULL
, size
, PROT_READ
, MAP_SHARED
, fd
, 0));
95 CYFile
*file(new (pool
) CYFile(base
, size
));
96 pool
.atexit(&CYFileExit
, file
);
103 CYUTF8String
CYPoolFileUTF8String(CYPool
&pool
, const char *path
) {
105 data
.data
= reinterpret_cast<char *>(CYPoolFile(pool
, path
, &data
.size
));