1
0
mirror of https://github.com/janet-lang/janet synced 2025-05-03 07:54:14 +00:00

Update whitespace and some doc strings.

This commit is contained in:
Calvin Rose 2019-02-25 23:48:04 -05:00
parent 36f92db61e
commit 4713219317
3 changed files with 23 additions and 54 deletions

View File

@ -266,7 +266,6 @@ static void marshal_one_fiber(MarshalState *st, JanetFiber *fiber, int flags) {
marshal_one(st, janet_wrap_fiber(fiber->child), flags + 1); marshal_one(st, janet_wrap_fiber(fiber->child), flags + 1);
} }
void janet_marshal_int(JanetMarshalContext *ctx, int32_t value) { void janet_marshal_int(JanetMarshalContext *ctx, int32_t value) {
MarshalState *st = (MarshalState *)(ctx->m_state); MarshalState *st = (MarshalState *)(ctx->m_state);
pushint(st, value); pushint(st, value);
@ -290,7 +289,6 @@ void janet_marshal_janet(JanetMarshalContext *ctx, Janet x) {
#define MARK_SEEN() \ #define MARK_SEEN() \
janet_table_put(&st->seen, x, janet_wrap_integer(st->nextid++)) janet_table_put(&st->seen, x, janet_wrap_integer(st->nextid++))
static void marshal_one_abstract(MarshalState *st, Janet x, int flags) { static void marshal_one_abstract(MarshalState *st, Janet x, int flags) {
void *abstract = janet_unwrap_abstract(x); void *abstract = janet_unwrap_abstract(x);
const JanetAbstractType *at = janet_abstract_type(abstract); const JanetAbstractType *at = janet_abstract_type(abstract);
@ -306,7 +304,6 @@ static void marshal_one_abstract(MarshalState *st, Janet x, int flags) {
} }
} }
/* The main body of the marshaling function. Is the main /* The main body of the marshaling function. Is the main
* entry point for the mutually recursive functions. */ * entry point for the mutually recursive functions. */
static void marshal_one(MarshalState *st, Janet x, int flags) { static void marshal_one(MarshalState *st, Janet x, int flags) {
@ -519,7 +516,6 @@ typedef struct {
const uint8_t *end; const uint8_t *end;
} UnmarshalState; } UnmarshalState;
#define MARSH_EOS(st, data) do { \ #define MARSH_EOS(st, data) do { \
if ((data) >= (st)->end) janet_panic("unexpected end of source");\ if ((data) >= (st)->end) janet_panic("unexpected end of source");\
} while (0) } while (0)
@ -900,7 +896,6 @@ static const uint8_t *unmarshal_one_fiber(
return data; return data;
} }
void janet_unmarshal_int(JanetMarshalContext *ctx, int32_t *i) { void janet_unmarshal_int(JanetMarshalContext *ctx, int32_t *i) {
UnmarshalState *st = (UnmarshalState *)(ctx->u_state); UnmarshalState *st = (UnmarshalState *)(ctx->u_state);
*i = readint(st, &(ctx->data)); *i = readint(st, &(ctx->data));
@ -916,8 +911,6 @@ void janet_unmarshal_size(JanetMarshalContext *ctx, size_t *i) {
*i = (size_t)readint(st, &(ctx->data)); *i = (size_t)readint(st, &(ctx->data));
}; };
void janet_unmarshal_byte(JanetMarshalContext *ctx, uint8_t *b) { void janet_unmarshal_byte(JanetMarshalContext *ctx, uint8_t *b) {
UnmarshalState *st = (UnmarshalState *)(ctx->u_state); UnmarshalState *st = (UnmarshalState *)(ctx->u_state);
MARSH_EOS(st, ctx->data); MARSH_EOS(st, ctx->data);
@ -951,10 +944,6 @@ static const uint8_t *unmarshal_one_abstract(UnmarshalState *st, const uint8_t *
return NULL; return NULL;
} }
static const uint8_t *unmarshal_one( static const uint8_t *unmarshal_one(
UnmarshalState *st, UnmarshalState *st,
const uint8_t *data, const uint8_t *data,

View File

@ -40,7 +40,6 @@ typedef int64_t ta_int64_t;
typedef float ta_float32_t; typedef float ta_float32_t;
typedef double ta_float64_t; typedef double ta_float64_t;
static char *ta_type_names[] = { static char *ta_type_names[] = {
"uint8", "uint8",
"int8", "int8",
@ -52,7 +51,7 @@ static char *ta_type_names[] = {
"int64", "int64",
"float32", "float32",
"float64", "float64",
"any", "any"
}; };
static size_t ta_type_sizes[] = { static size_t ta_type_sizes[] = {
@ -68,6 +67,7 @@ static size_t ta_type_sizes[] = {
sizeof(ta_float64_t), sizeof(ta_float64_t),
0, 0,
}; };
#define TA_COUNT_TYPES (JANET_TARRAY_TYPE_float64 + 1) #define TA_COUNT_TYPES (JANET_TARRAY_TYPE_float64 + 1)
#define TA_ATOM_MAXSIZE 8 #define TA_ATOM_MAXSIZE 8
#define TA_FLAG_BIG_ENDIAN 1 #define TA_FLAG_BIG_ENDIAN 1
@ -81,8 +81,6 @@ static JanetTArrayType get_ta_type_by_name(const uint8_t *name) {
return 0; return 0;
} }
static JanetTArrayBuffer *ta_buffer_init(JanetTArrayBuffer *buf, size_t size) { static JanetTArrayBuffer *ta_buffer_init(JanetTArrayBuffer *buf, size_t size) {
buf->data = NULL; buf->data = NULL;
if (size > 0) { if (size > 0) {
@ -123,7 +121,6 @@ static void ta_buffer_unmarshal(void *p, JanetMarshalContext *ctx) {
janet_unmarshal_bytes(ctx, buf->data, buf->size); janet_unmarshal_bytes(ctx, buf->data, buf->size);
} }
static const JanetAbstractType ta_buffer_type = { static const JanetAbstractType ta_buffer_type = {
"ta/buffer", "ta/buffer",
ta_buffer_gc, ta_buffer_gc,
@ -134,9 +131,6 @@ static const JanetAbstractType ta_buffer_type = {
ta_buffer_unmarshal, ta_buffer_unmarshal,
}; };
static int ta_mark(void *p, size_t s) { static int ta_mark(void *p, size_t s) {
(void) s; (void) s;
JanetTArrayView *view = (JanetTArrayView *)p; JanetTArrayView *view = (JanetTArrayView *)p;
@ -154,7 +148,6 @@ static void ta_view_marshal(void *p, JanetMarshalContext *ctx) {
janet_marshal_janet(ctx, janet_wrap_abstract(view->buffer)); janet_marshal_janet(ctx, janet_wrap_abstract(view->buffer));
} }
static void ta_view_unmarshal(void *p, JanetMarshalContext *ctx) { static void ta_view_unmarshal(void *p, JanetMarshalContext *ctx) {
JanetTArrayView *view = (JanetTArrayView *)p; JanetTArrayView *view = (JanetTArrayView *)p;
size_t offset; size_t offset;
@ -171,17 +164,13 @@ static void ta_view_unmarshal(void *p, JanetMarshalContext *ctx) {
view->data = view->buffer->data + offset; view->data = view->buffer->data + offset;
} }
#define DEFINE_VIEW_TYPE(thetype) \ #define DEFINE_VIEW_TYPE(thetype) \
typedef struct { \ typedef struct { \
JanetTArrayBuffer * buffer; \ JanetTArrayBuffer * buffer; \
ta_##thetype##_t * data; \ ta_##thetype##_t * data; \
size_t size; \ size_t size; \
size_t stride; \ size_t stride; \
JanetTArrayType type; \ JanetTArrayType type; \
} TA_View_##thetype ; } TA_View_##thetype ;
@ -471,7 +460,6 @@ static Janet cfun_typed_array_slice(int32_t argc, Janet *argv) {
return janet_wrap_array(array); return janet_wrap_array(array);
} }
static Janet cfun_typed_array_copy_bytes(int32_t argc, Janet *argv) { static Janet cfun_typed_array_copy_bytes(int32_t argc, Janet *argv) {
janet_arity(argc, 4, 5); janet_arity(argc, 4, 5);
JanetTArrayView *src = janet_gettarray_view(argv, 0, JANET_TARRAY_TYPE_any); JanetTArrayView *src = janet_gettarray_view(argv, 0, JANET_TARRAY_TYPE_any);
@ -529,65 +517,57 @@ static Janet cfun_typed_array_swap_bytes(int32_t argc, Janet *argv) {
return janet_wrap_nil(); return janet_wrap_nil();
} }
static const JanetReg ta_cfuns[] = { static const JanetReg ta_cfuns[] = {
{ {
"tarray/new", cfun_typed_array_new, "tarray/new", cfun_typed_array_new,
JDOC("(tarray/new type size [stride = 1 [offset = 0 [tarray | buffer]]] )\n\n" JDOC("(tarray/new type size [stride = 1 [offset = 0 [tarray | buffer]]] )\n\n"
"Create new typed array") "Create new typed array.")
}, },
{ {
"tarray/buffer", cfun_typed_array_buffer, "tarray/buffer", cfun_typed_array_buffer,
JDOC("(tarray/buffer (array | size) )\n\n" JDOC("(tarray/buffer (array | size) )\n\n"
"return typed array buffer or create a new buffer ") "Return typed array buffer or create a new buffer.")
}, },
{ {
"tarray/length", cfun_typed_array_size, "tarray/length", cfun_typed_array_size,
JDOC("(tarray/length (array | buffer) )\n\n" JDOC("(tarray/length (array | buffer) )\n\n"
"return typed array or buffer size ") "Return typed array or buffer size.")
}, },
{ {
"tarray/properties", cfun_typed_array_properties, "tarray/properties", cfun_typed_array_properties,
JDOC("(tarray/properties array )\n\n" JDOC("(tarray/properties array )\n\n"
"return typed array properties as a struct") "Return typed array properties as a struct.")
}, },
{ {
"tarray/copy-bytes", cfun_typed_array_copy_bytes, "tarray/copy-bytes", cfun_typed_array_copy_bytes,
JDOC("(tarray/copy-bytes src sindex dst dindex [count=1])\n\n" JDOC("(tarray/copy-bytes src sindex dst dindex [count=1])\n\n"
"copy count elements of src array from index sindex \n" "Copy count elements of src array from index sindex "
"to dst array at position dindex \n" "to dst array at position dindex "
"memory can overlap" "memory can overlap.")
)
}, },
{ {
"tarray/swap-bytes", cfun_typed_array_swap_bytes, "tarray/swap-bytes", cfun_typed_array_swap_bytes,
JDOC("(tarray/swap-bytes src sindex dst dindex [count=1])\n\n" JDOC("(tarray/swap-bytes src sindex dst dindex [count=1])\n\n"
"swap count elements between src array from index sindex \n" "Swap count elements between src array from index sindex "
"and dst array at position dindex \n" "and dst array at position dindex "
"memory can overlap" "memory can overlap.")
)
}, },
{ {
"tarray/slice", cfun_typed_array_slice, "tarray/slice", cfun_typed_array_slice,
JDOC("(tarray/slice tarr [, start=0 [, end=(size tarr)]])\n\n" JDOC("(tarray/slice tarr [, start=0 [, end=(size tarr)]])\n\n"
"Takes a slice of typed array from start to end. The range is half" "Takes a slice of a typed array from start to end. The range is half "
"open, [start, end). Indexes can also be negative, indicating indexing" "open, [start, end). Indexes can also be negative, indicating indexing "
"from the end of the end of the typed array. By default, start is 0 and end is" "from the end of the end of the typed array. By default, start is 0 and end is "
"the size of the typed array. Returns a new janet array.") "the size of the typed array. Returns a new janet array.")
}, },
{ {
"abstract/properties", cfun_abstract_properties, "abstract/properties", cfun_abstract_properties,
JDOC("(abstract/properties tag)\n\n" JDOC("(abstract/properties tag)\n\n"
"return abstract type properties as a struct") "Returns abstract type properties as a struct.")
}, },
{NULL, NULL, NULL} {NULL, NULL, NULL}
}; };
/* Module entry point */ /* Module entry point */
void janet_lib_typed_array(JanetTable *env) { void janet_lib_typed_array(JanetTable *env) {
janet_core_cfuns(env, NULL, ta_cfuns); janet_core_cfuns(env, NULL, ta_cfuns);

View File

@ -289,7 +289,7 @@
<array> <array>
<dict> <dict>
<key>match</key> <key>match</key>
<string>(\\[ne0zft"\\']|\\x[0-9a-fA-F][0-9a-fA-f])</string> <string>(\\[nevr0zft"\\']|\\x[0-9a-fA-F][0-9a-fA-f])</string>
<key>name</key> <key>name</key>
<string>constant.character.escape.janet</string> <string>constant.character.escape.janet</string>
</dict> </dict>