1
0
mirror of https://github.com/janet-lang/janet synced 2024-11-25 17:57:17 +00:00

Merge remote-tracking branch 'upstream/master' into typed-array-work

This commit is contained in:
J.-F. Cap 2019-02-24 22:25:33 +01:00
commit c81bf42f6b
6 changed files with 29 additions and 9 deletions

View File

@ -244,5 +244,4 @@ uninstall:
-rm -rf $(INCLUDEDIR) -rm -rf $(INCLUDEDIR)
.PHONY: clean install repl debug valgrind test amalg \ .PHONY: clean install repl debug valgrind test amalg \
valtest emscripten dist uninstall docs grammar format \ valtest emscripten dist uninstall docs grammar format
$(TEST_PROGRAM_PHONIES) $(TEST_PROGRAM_VALPHONIES)

View File

@ -32,6 +32,7 @@ static int is_whitespace(uint8_t c) {
|| c == '\n' || c == '\n'
|| c == '\r' || c == '\r'
|| c == '\0' || c == '\0'
|| c == '\v'
|| c == '\f'; || c == '\f';
} }
@ -207,6 +208,8 @@ static int checkescape(uint8_t c) {
return '\0'; return '\0';
case 'f': case 'f':
return '\f'; return '\f';
case 'v':
return '\v';
case 'e': case 'e':
return 27; return 27;
case '"': case '"':

View File

@ -989,15 +989,24 @@ static JanetAbstractType peg_type = {
NULL NULL
}; };
/* Used to ensure that if we place several arrays in one memory chunk, each
* array will be correctly aligned */
static size_t size_padded(size_t offset, size_t size) {
size_t x = size + offset - 1;
return x - (x % size);
}
/* Convert Builder to Peg (Janet Abstract Value) */ /* Convert Builder to Peg (Janet Abstract Value) */
static Peg *make_peg(Builder *b) { static Peg *make_peg(Builder *b) {
size_t bytecode_start = size_padded(sizeof(Peg), sizeof(uint32_t));
size_t bytecode_size = janet_v_count(b->bytecode) * sizeof(uint32_t); size_t bytecode_size = janet_v_count(b->bytecode) * sizeof(uint32_t);
size_t constants_start = size_padded(bytecode_start + bytecode_size, sizeof(Janet));
size_t constants_size = janet_v_count(b->constants) * sizeof(Janet); size_t constants_size = janet_v_count(b->constants) * sizeof(Janet);
size_t total_size = bytecode_size + constants_size + sizeof(Peg); size_t total_size = constants_start + constants_size;
char *mem = janet_abstract(&peg_type, total_size); char *mem = janet_abstract(&peg_type, total_size);
Peg *peg = (Peg *)mem; Peg *peg = (Peg *)mem;
peg->bytecode = (uint32_t *)(mem + sizeof(Peg)); peg->bytecode = (uint32_t *)(mem + bytecode_start);
peg->constants = (Janet *)(mem + sizeof(Peg) + bytecode_size); peg->constants = (Janet *)(mem + constants_start);
peg->num_constants = janet_v_count(b->constants); peg->num_constants = janet_v_count(b->constants);
memcpy(peg->bytecode, b->bytecode, bytecode_size); memcpy(peg->bytecode, b->bytecode, bytecode_size);
memcpy(peg->constants, b->constants, constants_size); memcpy(peg->constants, b->constants, constants_size);

View File

@ -136,6 +136,15 @@ static void janet_escape_string_impl(JanetBuffer *buffer, const uint8_t *str, in
case '\0': case '\0':
janet_buffer_push_bytes(buffer, (const uint8_t *)"\\0", 2); janet_buffer_push_bytes(buffer, (const uint8_t *)"\\0", 2);
break; break;
case '\f':
janet_buffer_push_bytes(buffer, (const uint8_t *)"\\f", 2);
break;
case '\v':
janet_buffer_push_bytes(buffer, (const uint8_t *)"\\v", 2);
break;
case 27:
janet_buffer_push_bytes(buffer, (const uint8_t *)"\\e", 2);
break;
case '\\': case '\\':
janet_buffer_push_bytes(buffer, (const uint8_t *)"\\\\", 2); janet_buffer_push_bytes(buffer, (const uint8_t *)"\\\\", 2);
break; break;

View File

@ -717,7 +717,7 @@ struct JanetAbstractHead {
JanetGCObject gc; JanetGCObject gc;
const JanetAbstractType *type; const JanetAbstractType *type;
size_t size; size_t size;
char data[]; long long data[]; /* Use long long to ensure most general alignment */
}; };
/* Some function definition flags */ /* Some function definition flags */

View File

@ -37,13 +37,13 @@
(def should-color (or (specials sym) (core-env sym))) (def should-color (or (specials sym) (core-env sym)))
(paint (if should-color :coresym :symbol) text)) (paint (if should-color :coresym :symbol) text))
~{:ws (set " \t\r\f\n\0") ~{:ws (set " \t\r\f\n\v\0")
:readermac (set "';~,") :readermac (set "';~,")
:symchars (+ (range "09" "AZ" "az" "\x80\xFF") (set "!$%&*+-./:<?=>@^_|")) :symchars (+ (range "09" "AZ" "az" "\x80\xFF") (set "!$%&*+-./:<?=>@^_|"))
:token (some :symchars) :token (some :symchars)
:hex (range "09" "af" "AF") :hex (range "09" "af" "AF")
:escape (* "\\" (+ (set "ntrzf0\"\\e") :escape (* "\\" (+ (set "ntrvzf0\"\\e")
(* "x" :hex :hex) (* "x" :hex :hex)
(error (constant "bad hex escape")))) (error (constant "bad hex escape"))))
:comment ,(<-c :comment ~(* "#" (any (if-not (+ "\n" -1) 1)))) :comment ,(<-c :comment ~(* "#" (any (if-not (+ "\n" -1) 1))))