From 28331ad6ab8348da73a890d4bba3c3a0b21d7d2b Mon Sep 17 00:00:00 2001 From: Calvin Rose Date: Sat, 29 Dec 2018 13:07:18 -0500 Subject: [PATCH] Update buffer/push-integer to buffer/push-word. --- src/core/buffer.c | 19 +++++++++++-------- tools/gendoc.janet | 2 +- 2 files changed, 12 insertions(+), 9 deletions(-) diff --git a/src/core/buffer.c b/src/core/buffer.c index a67a729a..1ed1d940 100644 --- a/src/core/buffer.c +++ b/src/core/buffer.c @@ -182,15 +182,18 @@ static int cfun_u8(JanetArgs args) { JANET_RETURN(args, args.v[0]); } -static int cfun_int(JanetArgs args) { +static int cfun_word(JanetArgs args) { int32_t i; JanetBuffer *buffer; JANET_MINARITY(args, 1); JANET_ARG_BUFFER(buffer, args, 0); for (i = 1; i < args.n; i++) { - int32_t integer; - JANET_ARG_INTEGER(integer, args, i); - if (janet_buffer_push_u32(buffer, (uint32_t) integer)) + double number; + uint32_t word; + 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_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. " "Returns the modified buffer. Will throw an error if the buffer overflows." }, - {"buffer/push-integer", cfun_int, - "(buffer/push-integer buffer x)\n\n" - "Append an integer to a buffer. The 4 bytes of the integer are appended " - "in twos complement, big endian order. Returns the modified buffer. Will " + {"buffer/push-word", cfun_word, + "(buffer/push-word buffer x)\n\n" + "Append a machine word to a buffer. The 4 bytes of the integer are appended " + "in twos complement, big endian order, unsigned. Returns the modified buffer. Will " "throw an error if the buffer overflows." }, {"buffer/push-string", cfun_chars, diff --git a/tools/gendoc.janet b/tools/gendoc.janet index 3e81528e..7f175daf 100644 --- a/tools/gendoc.janet +++ b/tools/gendoc.janet @@ -77,7 +77,7 @@ :doc docstring} env-entry binding-type (cond macro :macro - ref (string :var " (" (type ref.0) ")") + ref (string :var " (" (type (get ref 0)) ")") (type val)) source-ref (if-let [[path start end] sm] (string "" path " (" start ":" end ")")