1
0
mirror of https://github.com/janet-lang/janet synced 2024-11-28 11:09:54 +00:00

Update buffer/push-integer to buffer/push-word.

This commit is contained in:
Calvin Rose 2018-12-29 13:07:18 -05:00
parent 129ec1e3c5
commit 28331ad6ab
2 changed files with 12 additions and 9 deletions

View File

@ -182,15 +182,18 @@ static int cfun_u8(JanetArgs args) {
JANET_RETURN(args, args.v[0]); JANET_RETURN(args, args.v[0]);
} }
static int cfun_int(JanetArgs args) { static int cfun_word(JanetArgs args) {
int32_t i; int32_t i;
JanetBuffer *buffer; JanetBuffer *buffer;
JANET_MINARITY(args, 1); JANET_MINARITY(args, 1);
JANET_ARG_BUFFER(buffer, args, 0); JANET_ARG_BUFFER(buffer, args, 0);
for (i = 1; i < args.n; i++) { for (i = 1; i < args.n; i++) {
int32_t integer; double number;
JANET_ARG_INTEGER(integer, args, i); uint32_t word;
if (janet_buffer_push_u32(buffer, (uint32_t) integer)) JANET_ARG_NUMBER(number, args, i);
word = (uint32_t) number;
if (number != word) JANET_THROW(args, "cannot convert number to machine word");
if (janet_buffer_push_u32(buffer, word))
JANET_THROW(args, "buffer overflow"); JANET_THROW(args, "buffer overflow");
} }
JANET_RETURN(args, args.v[0]); JANET_RETURN(args, args.v[0]);
@ -276,10 +279,10 @@ static const JanetReg cfuns[] = {
"Append a byte to a buffer. Will expand the buffer as necessary. " "Append a byte to a buffer. Will expand the buffer as necessary. "
"Returns the modified buffer. Will throw an error if the buffer overflows." "Returns the modified buffer. Will throw an error if the buffer overflows."
}, },
{"buffer/push-integer", cfun_int, {"buffer/push-word", cfun_word,
"(buffer/push-integer buffer x)\n\n" "(buffer/push-word buffer x)\n\n"
"Append an integer to a buffer. The 4 bytes of the integer are appended " "Append a machine word to a buffer. The 4 bytes of the integer are appended "
"in twos complement, big endian order. Returns the modified buffer. Will " "in twos complement, big endian order, unsigned. Returns the modified buffer. Will "
"throw an error if the buffer overflows." "throw an error if the buffer overflows."
}, },
{"buffer/push-string", cfun_chars, {"buffer/push-string", cfun_chars,

View File

@ -77,7 +77,7 @@
:doc docstring} env-entry :doc docstring} env-entry
binding-type (cond binding-type (cond
macro :macro macro :macro
ref (string :var " (" (type ref.0) ")") ref (string :var " (" (type (get ref 0)) ")")
(type val)) (type val))
source-ref (if-let [[path start end] sm] source-ref (if-let [[path start end] sm]
(string "<span class=\"source-map\">" path " (" start ":" end ")</span>") (string "<span class=\"source-map\">" path " (" start ":" end ")</span>")