mirror of
https://github.com/janet-lang/janet
synced 2024-11-28 11:09:54 +00:00
Whitespace
This commit is contained in:
parent
740367ec5c
commit
3481ee5747
@ -1,16 +1,16 @@
|
|||||||
/*
|
/*
|
||||||
* Copyright (c) 2017 Calvin Rose
|
* Copyright (c) 2017 Calvin Rose
|
||||||
*
|
*
|
||||||
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||||
* of this software and associated documentation files (the "Software"), to
|
* of this software and associated documentation files (the "Software"), to
|
||||||
* deal in the Software without restriction, including without limitation the
|
* deal in the Software without restriction, including without limitation the
|
||||||
* rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
|
* rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
|
||||||
* sell copies of the Software, and to permit persons to whom the Software is
|
* sell copies of the Software, and to permit persons to whom the Software is
|
||||||
* furnished to do so, subject to the following conditions:
|
* furnished to do so, subject to the following conditions:
|
||||||
*
|
*
|
||||||
* The above copyright notice and this permission notice shall be included in
|
* The above copyright notice and this permission notice shall be included in
|
||||||
* all copies or substantial portions of the Software.
|
* all copies or substantial portions of the Software.
|
||||||
*
|
*
|
||||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||||
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||||
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||||
@ -91,7 +91,7 @@ static int debug_run(Gst *vm, FILE *in) {
|
|||||||
if (*reader == '\0') {
|
if (*reader == '\0') {
|
||||||
if (!fgets(buffer, sizeof(buffer), in)) {
|
if (!fgets(buffer, sizeof(buffer), in)) {
|
||||||
/* Add possible end of line */
|
/* Add possible end of line */
|
||||||
if (p.status == GST_PARSER_PENDING)
|
if (p.status == GST_PARSER_PENDING)
|
||||||
gst_parse_cstring(&p, "\n");
|
gst_parse_cstring(&p, "\n");
|
||||||
/* Check that parser is complete */
|
/* Check that parser is complete */
|
||||||
if (p.status != GST_PARSER_FULL && p.status != GST_PARSER_ROOT) {
|
if (p.status != GST_PARSER_FULL && p.status != GST_PARSER_ROOT) {
|
||||||
@ -173,7 +173,7 @@ int main(int argc, const char **argv) {
|
|||||||
const char *filename;
|
const char *filename;
|
||||||
FILE *f;
|
FILE *f;
|
||||||
filename = argv[1];
|
filename = argv[1];
|
||||||
f = fopen(filename, "rb");
|
f = fopen(filename, "rb");
|
||||||
status = debug_run(&vm, f);
|
status = debug_run(&vm, f);
|
||||||
} else {
|
} else {
|
||||||
status = debug_repl(&vm);
|
status = debug_repl(&vm);
|
||||||
|
@ -1,16 +1,16 @@
|
|||||||
/*
|
/*
|
||||||
* Copyright (c) 2017 Calvin Rose
|
* Copyright (c) 2017 Calvin Rose
|
||||||
*
|
*
|
||||||
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||||
* of this software and associated documentation files (the "Software"), to
|
* of this software and associated documentation files (the "Software"), to
|
||||||
* deal in the Software without restriction, including without limitation the
|
* deal in the Software without restriction, including without limitation the
|
||||||
* rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
|
* rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
|
||||||
* sell copies of the Software, and to permit persons to whom the Software is
|
* sell copies of the Software, and to permit persons to whom the Software is
|
||||||
* furnished to do so, subject to the following conditions:
|
* furnished to do so, subject to the following conditions:
|
||||||
*
|
*
|
||||||
* The above copyright notice and this permission notice shall be included in
|
* The above copyright notice and this permission notice shall be included in
|
||||||
* all copies or substantial portions of the Software.
|
* all copies or substantial portions of the Software.
|
||||||
*
|
*
|
||||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||||
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||||
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||||
|
@ -1,16 +1,16 @@
|
|||||||
/*
|
/*
|
||||||
* Copyright (c) 2017 Calvin Rose
|
* Copyright (c) 2017 Calvin Rose
|
||||||
*
|
*
|
||||||
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||||
* of this software and associated documentation files (the "Software"), to
|
* of this software and associated documentation files (the "Software"), to
|
||||||
* deal in the Software without restriction, including without limitation the
|
* deal in the Software without restriction, including without limitation the
|
||||||
* rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
|
* rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
|
||||||
* sell copies of the Software, and to permit persons to whom the Software is
|
* sell copies of the Software, and to permit persons to whom the Software is
|
||||||
* furnished to do so, subject to the following conditions:
|
* furnished to do so, subject to the following conditions:
|
||||||
*
|
*
|
||||||
* The above copyright notice and this permission notice shall be included in
|
* The above copyright notice and this permission notice shall be included in
|
||||||
* all copies or substantial portions of the Software.
|
* all copies or substantial portions of the Software.
|
||||||
*
|
*
|
||||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||||
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||||
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||||
@ -131,7 +131,7 @@ static GstValue quote(Gst *vm, GstValue x) {
|
|||||||
GstValue *q = gst_tuple_begin(vm, 2);
|
GstValue *q = gst_tuple_begin(vm, 2);
|
||||||
q[0] = gst_string_cv(vm, "quote");
|
q[0] = gst_string_cv(vm, "quote");
|
||||||
q[1] = x; /* lit contains the var container of the environment */
|
q[1] = x; /* lit contains the var container of the environment */
|
||||||
return gst_wrap_tuple(gst_tuple_end(vm, q));
|
return gst_wrap_tuple(gst_tuple_end(vm, q));
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Push a new scope in the compiler and return
|
/* Push a new scope in the compiler and return
|
||||||
@ -424,7 +424,7 @@ static int symbol_resolve(GstCompiler *c, GstValue x, uint16_t *level, uint16_t
|
|||||||
}
|
}
|
||||||
if (flags) *flags = 0;
|
if (flags) *flags = 0;
|
||||||
*out = check;
|
*out = check;
|
||||||
return 2;
|
return 2;
|
||||||
}
|
}
|
||||||
/* Check for nil named literal */
|
/* Check for nil named literal */
|
||||||
check = gst_table_get(gst_env_nils(c->vm, c->env), x);
|
check = gst_table_get(gst_env_nils(c->vm, c->env), x);
|
||||||
@ -1132,7 +1132,7 @@ static SpecialFormHelper get_special(const GstValue *form) {
|
|||||||
name[1] == 'a' &&
|
name[1] == 'a' &&
|
||||||
name[2] == 'r') {
|
name[2] == 'r') {
|
||||||
return compile_var;
|
return compile_var;
|
||||||
}
|
}
|
||||||
if (gst_string_length(name) == 7 &&
|
if (gst_string_length(name) == 7 &&
|
||||||
name[1] == 'a' &&
|
name[1] == 'a' &&
|
||||||
name[2] == 'r' &&
|
name[2] == 'r' &&
|
||||||
@ -1141,7 +1141,7 @@ static SpecialFormHelper get_special(const GstValue *form) {
|
|||||||
name[5] == 't' &&
|
name[5] == 't' &&
|
||||||
name[6] == '!') {
|
name[6] == '!') {
|
||||||
return compile_varset;
|
return compile_varset;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
case 'w':
|
case 'w':
|
||||||
|
10
core/ds.c
10
core/ds.c
@ -1,16 +1,16 @@
|
|||||||
/*
|
/*
|
||||||
* Copyright (c) 2017 Calvin Rose
|
* Copyright (c) 2017 Calvin Rose
|
||||||
*
|
*
|
||||||
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||||
* of this software and associated documentation files (the "Software"), to
|
* of this software and associated documentation files (the "Software"), to
|
||||||
* deal in the Software without restriction, including without limitation the
|
* deal in the Software without restriction, including without limitation the
|
||||||
* rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
|
* rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
|
||||||
* sell copies of the Software, and to permit persons to whom the Software is
|
* sell copies of the Software, and to permit persons to whom the Software is
|
||||||
* furnished to do so, subject to the following conditions:
|
* furnished to do so, subject to the following conditions:
|
||||||
*
|
*
|
||||||
* The above copyright notice and this permission notice shall be included in
|
* The above copyright notice and this permission notice shall be included in
|
||||||
* all copies or substantial portions of the Software.
|
* all copies or substantial portions of the Software.
|
||||||
*
|
*
|
||||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||||
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||||
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||||
@ -281,11 +281,11 @@ void gst_table_put(Gst *vm, GstTable *t, GstValue key, GstValue value) {
|
|||||||
/* Find next key in an object. Returns nil if no next key. */
|
/* Find next key in an object. Returns nil if no next key. */
|
||||||
GstValue gst_table_next(GstTable *t, GstValue key) {
|
GstValue gst_table_next(GstTable *t, GstValue key) {
|
||||||
const GstValue *bucket, *end;
|
const GstValue *bucket, *end;
|
||||||
end = t->data + t->capacity;
|
end = t->data + t->capacity;
|
||||||
if (key.type == GST_NIL) {
|
if (key.type == GST_NIL) {
|
||||||
bucket = t->data;
|
bucket = t->data;
|
||||||
} else {
|
} else {
|
||||||
bucket = gst_table_find(t, key);
|
bucket = gst_table_find(t, key);
|
||||||
if (!bucket || bucket[0].type == GST_NIL)
|
if (!bucket || bucket[0].type == GST_NIL)
|
||||||
return gst_wrap_nil();
|
return gst_wrap_nil();
|
||||||
bucket += 2;
|
bucket += 2;
|
||||||
|
10
core/gc.c
10
core/gc.c
@ -1,16 +1,16 @@
|
|||||||
/*
|
/*
|
||||||
* Copyright (c) 2017 Calvin Rose
|
* Copyright (c) 2017 Calvin Rose
|
||||||
*
|
*
|
||||||
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||||
* of this software and associated documentation files (the "Software"), to
|
* of this software and associated documentation files (the "Software"), to
|
||||||
* deal in the Software without restriction, including without limitation the
|
* deal in the Software without restriction, including without limitation the
|
||||||
* rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
|
* rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
|
||||||
* sell copies of the Software, and to permit persons to whom the Software is
|
* sell copies of the Software, and to permit persons to whom the Software is
|
||||||
* furnished to do so, subject to the following conditions:
|
* furnished to do so, subject to the following conditions:
|
||||||
*
|
*
|
||||||
* The above copyright notice and this permission notice shall be included in
|
* The above copyright notice and this permission notice shall be included in
|
||||||
* all copies or substantial portions of the Software.
|
* all copies or substantial portions of the Software.
|
||||||
*
|
*
|
||||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||||
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||||
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||||
@ -93,7 +93,7 @@ void gst_mark_value(Gst *vm, GstValue x) {
|
|||||||
* the main function for doing the garbage collection mark phase. */
|
* the main function for doing the garbage collection mark phase. */
|
||||||
void gst_mark(Gst *vm, GstValueUnion x, GstType type) {
|
void gst_mark(Gst *vm, GstValueUnion x, GstType type) {
|
||||||
switch (type) {
|
switch (type) {
|
||||||
default:
|
default:
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case GST_STRING:
|
case GST_STRING:
|
||||||
@ -220,7 +220,7 @@ void gst_sweep(Gst *vm) {
|
|||||||
if (current->tags & GST_MEMTAG_TUPLE)
|
if (current->tags & GST_MEMTAG_TUPLE)
|
||||||
gst_cache_remove_tuple(vm, (char *)(current + 1));
|
gst_cache_remove_tuple(vm, (char *)(current + 1));
|
||||||
if (current->tags & GST_MEMTAG_USER) {
|
if (current->tags & GST_MEMTAG_USER) {
|
||||||
GstUserdataHeader *h = (GstUserdataHeader *)(current + 1);
|
GstUserdataHeader *h = (GstUserdataHeader *)(current + 1);
|
||||||
if (h->type->finalize) {
|
if (h->type->finalize) {
|
||||||
h->type->finalize(vm, h + 1, h->size);
|
h->type->finalize(vm, h + 1, h->size);
|
||||||
}
|
}
|
||||||
|
12
core/ids.c
12
core/ids.c
@ -1,16 +1,16 @@
|
|||||||
/*
|
/*
|
||||||
* Copyright (c) 2017 Calvin Rose
|
* Copyright (c) 2017 Calvin Rose
|
||||||
*
|
*
|
||||||
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||||
* of this software and associated documentation files (the "Software"), to
|
* of this software and associated documentation files (the "Software"), to
|
||||||
* deal in the Software without restriction, including without limitation the
|
* deal in the Software without restriction, including without limitation the
|
||||||
* rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
|
* rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
|
||||||
* sell copies of the Software, and to permit persons to whom the Software is
|
* sell copies of the Software, and to permit persons to whom the Software is
|
||||||
* furnished to do so, subject to the following conditions:
|
* furnished to do so, subject to the following conditions:
|
||||||
*
|
*
|
||||||
* The above copyright notice and this permission notice shall be included in
|
* The above copyright notice and this permission notice shall be included in
|
||||||
* all copies or substantial portions of the Software.
|
* all copies or substantial portions of the Software.
|
||||||
*
|
*
|
||||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||||
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||||
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||||
@ -161,7 +161,7 @@ static GstValue gst_cache_add(Gst *vm, GstValue x) {
|
|||||||
GstValue *bucket = gst_cache_find(vm, x, &status);
|
GstValue *bucket = gst_cache_find(vm, x, &status);
|
||||||
if (!status) {
|
if (!status) {
|
||||||
if ((vm->cache_count + vm->cache_deleted) * 2 > vm->cache_capacity) {
|
if ((vm->cache_count + vm->cache_deleted) * 2 > vm->cache_capacity) {
|
||||||
gst_cache_resize(vm, vm->cache_count * 4);
|
gst_cache_resize(vm, vm->cache_count * 4);
|
||||||
bucket = gst_cache_find(vm, x, &status);
|
bucket = gst_cache_find(vm, x, &status);
|
||||||
}
|
}
|
||||||
/* Mark the memory for the gc */
|
/* Mark the memory for the gc */
|
||||||
@ -231,7 +231,7 @@ GstValue *gst_struct_begin(Gst *vm, uint32_t count) {
|
|||||||
char *data = gst_zalloc(vm, sizeof(uint32_t) * 2 + 4 * count * sizeof(GstValue));
|
char *data = gst_zalloc(vm, sizeof(uint32_t) * 2 + 4 * count * sizeof(GstValue));
|
||||||
GstValue *st = (GstValue *) (data + 2 * sizeof(uint32_t));
|
GstValue *st = (GstValue *) (data + 2 * sizeof(uint32_t));
|
||||||
gst_struct_length(st) = count;
|
gst_struct_length(st) = count;
|
||||||
return st;
|
return st;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Find an item in a struct */
|
/* Find an item in a struct */
|
||||||
@ -334,7 +334,7 @@ GstValue gst_struct_next(const GstValue *st, GstValue key) {
|
|||||||
if (key.type == GST_NIL) {
|
if (key.type == GST_NIL) {
|
||||||
bucket = st;
|
bucket = st;
|
||||||
} else {
|
} else {
|
||||||
bucket = gst_struct_find(st, key);
|
bucket = gst_struct_find(st, key);
|
||||||
if (!bucket || bucket[0].type == GST_NIL)
|
if (!bucket || bucket[0].type == GST_NIL)
|
||||||
return gst_wrap_nil();
|
return gst_wrap_nil();
|
||||||
bucket += 2;
|
bucket += 2;
|
||||||
|
22
core/parse.c
22
core/parse.c
@ -1,16 +1,16 @@
|
|||||||
/*
|
/*
|
||||||
* Copyright (c) 2017 Calvin Rose
|
* Copyright (c) 2017 Calvin Rose
|
||||||
*
|
*
|
||||||
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||||
* of this software and associated documentation files (the "Software"), to
|
* of this software and associated documentation files (the "Software"), to
|
||||||
* deal in the Software without restriction, including without limitation the
|
* deal in the Software without restriction, including without limitation the
|
||||||
* rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
|
* rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
|
||||||
* sell copies of the Software, and to permit persons to whom the Software is
|
* sell copies of the Software, and to permit persons to whom the Software is
|
||||||
* furnished to do so, subject to the following conditions:
|
* furnished to do so, subject to the following conditions:
|
||||||
*
|
*
|
||||||
* The above copyright notice and this permission notice shall be included in
|
* The above copyright notice and this permission notice shall be included in
|
||||||
* all copies or substantial portions of the Software.
|
* all copies or substantial portions of the Software.
|
||||||
*
|
*
|
||||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||||
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||||
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||||
@ -307,13 +307,13 @@ static int string_state(GstParser *p, uint8_t c) {
|
|||||||
case '\'': next = '\''; break;
|
case '\'': next = '\''; break;
|
||||||
case 'z': next = '\0'; break;
|
case 'z': next = '\0'; break;
|
||||||
case 'e': next = 27; break;
|
case 'e': next = 27; break;
|
||||||
case 'h':
|
case 'h':
|
||||||
top->buf.string.state = STRING_STATE_ESCAPE_HEX;
|
top->buf.string.state = STRING_STATE_ESCAPE_HEX;
|
||||||
top->buf.string.count = 0;
|
top->buf.string.count = 0;
|
||||||
top->buf.string.accum = 0;
|
top->buf.string.accum = 0;
|
||||||
return 1;
|
return 1;
|
||||||
case 'u':
|
case 'u':
|
||||||
top->buf.string.state = STRING_STATE_ESCAPE_HEX;
|
top->buf.string.state = STRING_STATE_ESCAPE_HEX;
|
||||||
top->buf.string.count = 0;
|
top->buf.string.count = 0;
|
||||||
top->buf.string.accum = 0;
|
top->buf.string.accum = 0;
|
||||||
return 1;
|
return 1;
|
||||||
@ -331,8 +331,8 @@ static int string_state(GstParser *p, uint8_t c) {
|
|||||||
p_error(p, "invalid hexidecimal digit");
|
p_error(p, "invalid hexidecimal digit");
|
||||||
return 1;
|
return 1;
|
||||||
} else {
|
} else {
|
||||||
top->buf.string.accum *= 16;
|
top->buf.string.accum *= 16;
|
||||||
top->buf.string.accum += digit;
|
top->buf.string.accum += digit;
|
||||||
}
|
}
|
||||||
top->buf.string.accum += digit;
|
top->buf.string.accum += digit;
|
||||||
if (++top->buf.string.count == 2) {
|
if (++top->buf.string.count == 2) {
|
||||||
@ -394,7 +394,7 @@ static int form_state(GstParser *p, uint8_t c) {
|
|||||||
x.type = GST_TABLE;
|
x.type = GST_TABLE;
|
||||||
x.data.table = gst_table(p->vm, array->count);
|
x.data.table = gst_table(p->vm, array->count);
|
||||||
for (i = 0; i < array->count; i += 2) {
|
for (i = 0; i < array->count; i += 2) {
|
||||||
gst_table_put(p->vm, x.data.table, array->data[i], array->data[i + 1]);
|
gst_table_put(p->vm, x.data.table, array->data[i], array->data[i + 1]);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
parser_pop(p);
|
parser_pop(p);
|
||||||
@ -413,7 +413,7 @@ void gst_parse_byte(GstParser *p, uint8_t c) {
|
|||||||
p->index = 0;
|
p->index = 0;
|
||||||
p->comment = GST_PCOMMENT_EXPECTING;
|
p->comment = GST_PCOMMENT_EXPECTING;
|
||||||
} else {
|
} else {
|
||||||
++p->index;
|
++p->index;
|
||||||
}
|
}
|
||||||
/* Check comments */
|
/* Check comments */
|
||||||
switch (p->comment) {
|
switch (p->comment) {
|
||||||
|
@ -1,16 +1,16 @@
|
|||||||
/*
|
/*
|
||||||
* Copyright (c) 2017 Calvin Rose
|
* Copyright (c) 2017 Calvin Rose
|
||||||
*
|
*
|
||||||
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||||
* of this software and associated documentation files (the "Software"), to
|
* of this software and associated documentation files (the "Software"), to
|
||||||
* deal in the Software without restriction, including without limitation the
|
* deal in the Software without restriction, including without limitation the
|
||||||
* rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
|
* rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
|
||||||
* sell copies of the Software, and to permit persons to whom the Software is
|
* sell copies of the Software, and to permit persons to whom the Software is
|
||||||
* furnished to do so, subject to the following conditions:
|
* furnished to do so, subject to the following conditions:
|
||||||
*
|
*
|
||||||
* The above copyright notice and this permission notice shall be included in
|
* The above copyright notice and this permission notice shall be included in
|
||||||
* all copies or substantial portions of the Software.
|
* all copies or substantial portions of the Software.
|
||||||
*
|
*
|
||||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||||
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||||
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||||
@ -101,7 +101,7 @@ static int64_t bytes2int(const uint8_t *bytes) {
|
|||||||
* deserialization. If successful, the resulting value is
|
* deserialization. If successful, the resulting value is
|
||||||
* passed by reference. */
|
* passed by reference. */
|
||||||
static const char *gst_deserialize_impl(
|
static const char *gst_deserialize_impl(
|
||||||
Gst *vm,
|
Gst *vm,
|
||||||
const uint8_t *data,
|
const uint8_t *data,
|
||||||
const uint8_t *end,
|
const uint8_t *end,
|
||||||
const uint8_t **newData,
|
const uint8_t **newData,
|
||||||
@ -141,11 +141,11 @@ static const char *gst_deserialize_impl(
|
|||||||
/* Small integer */
|
/* Small integer */
|
||||||
if (*data < 201) {
|
if (*data < 201) {
|
||||||
ret.type = GST_INTEGER;
|
ret.type = GST_INTEGER;
|
||||||
ret.data.integer = *data - 100;
|
ret.data.integer = *data - 100;
|
||||||
*newData = data + 1;
|
*newData = data + 1;
|
||||||
*out = ret;
|
*out = ret;
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Main switch for types */
|
/* Main switch for types */
|
||||||
switch (*data++) {
|
switch (*data++) {
|
||||||
@ -168,7 +168,7 @@ static const char *gst_deserialize_impl(
|
|||||||
break;
|
break;
|
||||||
|
|
||||||
case 204: /* Long number (double) */
|
case 204: /* Long number (double) */
|
||||||
ret.type = GST_REAL;
|
ret.type = GST_REAL;
|
||||||
read_dbl(ret.data.real);
|
read_dbl(ret.data.real);
|
||||||
break;
|
break;
|
||||||
|
|
||||||
@ -188,9 +188,9 @@ static const char *gst_deserialize_impl(
|
|||||||
for (i = 0; i < length; ++i) {
|
for (i = 0; i < length; ++i) {
|
||||||
GstValue k, v;
|
GstValue k, v;
|
||||||
if ((err = gst_deserialize_impl(vm, data, end, &data, visited, &k, depth)))
|
if ((err = gst_deserialize_impl(vm, data, end, &data, visited, &k, depth)))
|
||||||
return err;
|
return err;
|
||||||
if ((err = gst_deserialize_impl(vm, data, end, &data, visited, &v, depth)))
|
if ((err = gst_deserialize_impl(vm, data, end, &data, visited, &v, depth)))
|
||||||
return err;
|
return err;
|
||||||
gst_struct_put(buffer, k, v);
|
gst_struct_put(buffer, k, v);
|
||||||
}
|
}
|
||||||
ret.data.st = gst_struct_end(vm, buffer);
|
ret.data.st = gst_struct_end(vm, buffer);
|
||||||
@ -224,7 +224,7 @@ static const char *gst_deserialize_impl(
|
|||||||
gst_array_push(vm, visited, ret);
|
gst_array_push(vm, visited, ret);
|
||||||
for (i = 0; i < length; ++i)
|
for (i = 0; i < length; ++i)
|
||||||
if ((err = gst_deserialize_impl(vm, data, end, &data, visited, buffer + i, depth)))
|
if ((err = gst_deserialize_impl(vm, data, end, &data, visited, buffer + i, depth)))
|
||||||
return err;
|
return err;
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case 209: /* Tuple */
|
case 209: /* Tuple */
|
||||||
@ -247,7 +247,7 @@ static const char *gst_deserialize_impl(
|
|||||||
uint8_t statusbyte;
|
uint8_t statusbyte;
|
||||||
t = gst_thread(vm, gst_wrap_nil(), 64);
|
t = gst_thread(vm, gst_wrap_nil(), 64);
|
||||||
ret = gst_wrap_thread(t);
|
ret = gst_wrap_thread(t);
|
||||||
gst_array_push(vm, visited, ret);
|
gst_array_push(vm, visited, ret);
|
||||||
err = gst_deserialize_impl(vm, data, end, &data, visited, &ret, depth);
|
err = gst_deserialize_impl(vm, data, end, &data, visited, &ret, depth);
|
||||||
if (err != NULL) return err;
|
if (err != NULL) return err;
|
||||||
if (ret.type == GST_NIL) {
|
if (ret.type == GST_NIL) {
|
||||||
@ -421,7 +421,7 @@ static const char *gst_deserialize_impl(
|
|||||||
case 215: /* LUdata */
|
case 215: /* LUdata */
|
||||||
{
|
{
|
||||||
/* TODO enable deserialization of userdata through registration
|
/* TODO enable deserialization of userdata through registration
|
||||||
* to names in vm. */
|
* to names in vm. */
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
|
|
||||||
@ -513,7 +513,7 @@ static const char *gst_serialize_impl(
|
|||||||
case GST_BOOLEAN:
|
case GST_BOOLEAN:
|
||||||
write_byte(x.data.boolean ? 202 : 203);
|
write_byte(x.data.boolean ? 202 : 203);
|
||||||
return NULL;
|
return NULL;
|
||||||
case GST_REAL:
|
case GST_REAL:
|
||||||
write_byte(204);
|
write_byte(204);
|
||||||
write_dbl(x.data.real);
|
write_dbl(x.data.real);
|
||||||
return NULL;
|
return NULL;
|
||||||
@ -551,9 +551,9 @@ static const char *gst_serialize_impl(
|
|||||||
write_u32(gst_struct_length(x.data.st));
|
write_u32(gst_struct_length(x.data.st));
|
||||||
for (i = 0; i < count; i += 2) {
|
for (i = 0; i < count; i += 2) {
|
||||||
if (data[i].type != GST_NIL) {
|
if (data[i].type != GST_NIL) {
|
||||||
err = gst_serialize_impl(vm, buffer, visited, nextId, data[i], depth);
|
err = gst_serialize_impl(vm, buffer, visited, nextId, data[i], depth);
|
||||||
if (err != NULL) return err;
|
if (err != NULL) return err;
|
||||||
err = gst_serialize_impl(vm, buffer, visited, nextId, data[i + 1], depth);
|
err = gst_serialize_impl(vm, buffer, visited, nextId, data[i + 1], depth);
|
||||||
if (err != NULL) return err;
|
if (err != NULL) return err;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -562,7 +562,7 @@ static const char *gst_serialize_impl(
|
|||||||
count = gst_tuple_length(x.data.tuple);
|
count = gst_tuple_length(x.data.tuple);
|
||||||
write_u32(count);
|
write_u32(count);
|
||||||
for (i = 0; i < count; ++i) {
|
for (i = 0; i < count; ++i) {
|
||||||
err = gst_serialize_impl(vm, buffer, visited, nextId, x.data.tuple[i], depth);
|
err = gst_serialize_impl(vm, buffer, visited, nextId, x.data.tuple[i], depth);
|
||||||
if (err != NULL) return err;
|
if (err != NULL) return err;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -579,7 +579,7 @@ static const char *gst_serialize_impl(
|
|||||||
/* Check reference types */
|
/* Check reference types */
|
||||||
switch (x.type) {
|
switch (x.type) {
|
||||||
default:
|
default:
|
||||||
return "unable to serialize type";
|
return "unable to serialize type";
|
||||||
|
|
||||||
case GST_STRING:
|
case GST_STRING:
|
||||||
write_byte(205);
|
write_byte(205);
|
||||||
@ -610,9 +610,9 @@ static const char *gst_serialize_impl(
|
|||||||
write_u32(x.data.table->count);
|
write_u32(x.data.table->count);
|
||||||
for (i = 0; i < count; i += 2) {
|
for (i = 0; i < count; i += 2) {
|
||||||
if (data[i].type != GST_NIL) {
|
if (data[i].type != GST_NIL) {
|
||||||
err = gst_serialize_impl(vm, buffer, visited, nextId, data[i], depth);
|
err = gst_serialize_impl(vm, buffer, visited, nextId, data[i], depth);
|
||||||
if (err != NULL) return err;
|
if (err != NULL) return err;
|
||||||
err = gst_serialize_impl(vm, buffer, visited, nextId, data[i + 1], depth);
|
err = gst_serialize_impl(vm, buffer, visited, nextId, data[i + 1], depth);
|
||||||
if (err != NULL) return err;
|
if (err != NULL) return err;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -634,7 +634,7 @@ static const char *gst_serialize_impl(
|
|||||||
count = x.data.array->count;
|
count = x.data.array->count;
|
||||||
write_u32(count);
|
write_u32(count);
|
||||||
for (i = 0; i < count; ++i) {
|
for (i = 0; i < count; ++i) {
|
||||||
err = gst_serialize_impl(vm, buffer, visited, nextId, x.data.array->data[i], depth);
|
err = gst_serialize_impl(vm, buffer, visited, nextId, x.data.array->data[i], depth);
|
||||||
if (err != NULL) return err;
|
if (err != NULL) return err;
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
@ -664,8 +664,8 @@ static const char *gst_serialize_impl(
|
|||||||
for (i = 0; i < framecount; ++i) {
|
for (i = 0; i < framecount; ++i) {
|
||||||
uint32_t j, size;
|
uint32_t j, size;
|
||||||
GstValue callee = gst_frame_callee(stack);
|
GstValue callee = gst_frame_callee(stack);
|
||||||
GstFuncEnv *env = gst_frame_env(stack);
|
GstFuncEnv *env = gst_frame_env(stack);
|
||||||
err = gst_serialize_impl(vm, buffer, visited, nextId, callee, depth);
|
err = gst_serialize_impl(vm, buffer, visited, nextId, callee, depth);
|
||||||
if (err != NULL) return err;
|
if (err != NULL) return err;
|
||||||
if (env)
|
if (env)
|
||||||
err = gst_serialize_impl(vm, buffer, visited, nextId, gst_wrap_funcenv(env), depth);
|
err = gst_serialize_impl(vm, buffer, visited, nextId, gst_wrap_funcenv(env), depth);
|
||||||
@ -684,7 +684,7 @@ static const char *gst_serialize_impl(
|
|||||||
for (j = 0; j < size; ++j) {
|
for (j = 0; j < size; ++j) {
|
||||||
err = gst_serialize_impl(vm, buffer, visited, nextId, stack[j], depth);
|
err = gst_serialize_impl(vm, buffer, visited, nextId, stack[j], depth);
|
||||||
if (err != NULL) return err;
|
if (err != NULL) return err;
|
||||||
}
|
}
|
||||||
/* Next stack frame */
|
/* Next stack frame */
|
||||||
stack += size + GST_FRAME_SIZE;
|
stack += size + GST_FRAME_SIZE;
|
||||||
}
|
}
|
||||||
@ -700,7 +700,7 @@ static const char *gst_serialize_impl(
|
|||||||
write_u32(def->flags);
|
write_u32(def->flags);
|
||||||
write_u32(def->literalsLen);
|
write_u32(def->literalsLen);
|
||||||
for (i = 0; i < def->literalsLen; ++i) {
|
for (i = 0; i < def->literalsLen; ++i) {
|
||||||
err = gst_serialize_impl(vm, buffer, visited, nextId, def->literals[i], depth);
|
err = gst_serialize_impl(vm, buffer, visited, nextId, def->literals[i], depth);
|
||||||
if (err != NULL) return err;
|
if (err != NULL) return err;
|
||||||
}
|
}
|
||||||
write_u32(def->byteCodeLen);
|
write_u32(def->byteCodeLen);
|
||||||
|
30
core/stl.c
30
core/stl.c
@ -1,16 +1,16 @@
|
|||||||
/*
|
/*
|
||||||
* Copyright (c) 2017 Calvin Rose
|
* Copyright (c) 2017 Calvin Rose
|
||||||
*
|
*
|
||||||
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||||
* of this software and associated documentation files (the "Software"), to
|
* of this software and associated documentation files (the "Software"), to
|
||||||
* deal in the Software without restriction, including without limitation the
|
* deal in the Software without restriction, including without limitation the
|
||||||
* rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
|
* rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
|
||||||
* sell copies of the Software, and to permit persons to whom the Software is
|
* sell copies of the Software, and to permit persons to whom the Software is
|
||||||
* furnished to do so, subject to the following conditions:
|
* furnished to do so, subject to the following conditions:
|
||||||
*
|
*
|
||||||
* The above copyright notice and this permission notice shall be included in
|
* The above copyright notice and this permission notice shall be included in
|
||||||
* all copies or substantial portions of the Software.
|
* all copies or substantial portions of the Software.
|
||||||
*
|
*
|
||||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||||
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||||
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||||
@ -218,7 +218,7 @@ int gst_stl_to_int(Gst *vm) {
|
|||||||
if (x.type == GST_REAL)
|
if (x.type == GST_REAL)
|
||||||
gst_c_return(vm, gst_wrap_integer((GstInteger) x.data.real));
|
gst_c_return(vm, gst_wrap_integer((GstInteger) x.data.real));
|
||||||
else
|
else
|
||||||
gst_c_throwc(vm, "expected number");
|
gst_c_throwc(vm, "expected number");
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Convert to integer */
|
/* Convert to integer */
|
||||||
@ -228,7 +228,7 @@ int gst_stl_to_real(Gst *vm) {
|
|||||||
if (x.type == GST_INTEGER)
|
if (x.type == GST_INTEGER)
|
||||||
gst_c_return(vm, gst_wrap_real((GstReal) x.data.integer));
|
gst_c_return(vm, gst_wrap_real((GstReal) x.data.integer));
|
||||||
else
|
else
|
||||||
gst_c_throwc(vm, "expected number");
|
gst_c_throwc(vm, "expected number");
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Get a slice of a sequence */
|
/* Get a slice of a sequence */
|
||||||
@ -447,14 +447,14 @@ int gst_stl_thread(Gst *vm) {
|
|||||||
if (callee.type != GST_FUNCTION && callee.type != GST_CFUNCTION)
|
if (callee.type != GST_FUNCTION && callee.type != GST_CFUNCTION)
|
||||||
gst_c_throwc(vm, "expected function in thread constructor");
|
gst_c_throwc(vm, "expected function in thread constructor");
|
||||||
if (parent.type == GST_THREAD) {
|
if (parent.type == GST_THREAD) {
|
||||||
t->parent = parent.data.thread;
|
t->parent = parent.data.thread;
|
||||||
} else if (parent.type != GST_NIL) {
|
} else if (parent.type != GST_NIL) {
|
||||||
gst_c_throwc(vm, "expected thread/nil as parent");
|
gst_c_throwc(vm, "expected thread/nil as parent");
|
||||||
} else {
|
} else {
|
||||||
t->parent = vm->thread;
|
t->parent = vm->thread;
|
||||||
}
|
}
|
||||||
if (errorParent.type == GST_THREAD) {
|
if (errorParent.type == GST_THREAD) {
|
||||||
t->errorParent = errorParent.data.thread;
|
t->errorParent = errorParent.data.thread;
|
||||||
} else if (errorParent.type != GST_NIL) {
|
} else if (errorParent.type != GST_NIL) {
|
||||||
gst_c_throwc(vm, "expected thread/nil as error parent");
|
gst_c_throwc(vm, "expected thread/nil as error parent");
|
||||||
} else {
|
} else {
|
||||||
@ -574,9 +574,9 @@ int gst_stl_next(Gst *vm) {
|
|||||||
GstValue ds = gst_arg(vm, 0);
|
GstValue ds = gst_arg(vm, 0);
|
||||||
GstValue key = gst_arg(vm, 1);
|
GstValue key = gst_arg(vm, 1);
|
||||||
if (ds.type == GST_TABLE) {
|
if (ds.type == GST_TABLE) {
|
||||||
gst_c_return(vm, gst_table_next(ds.data.table, key));
|
gst_c_return(vm, gst_table_next(ds.data.table, key));
|
||||||
} else if (ds.type == GST_STRUCT) {
|
} else if (ds.type == GST_STRUCT) {
|
||||||
gst_c_return(vm, gst_struct_next(ds.data.st, key));
|
gst_c_return(vm, gst_struct_next(ds.data.st, key));
|
||||||
} else {
|
} else {
|
||||||
gst_c_throwc(vm, "expected table or struct");
|
gst_c_throwc(vm, "expected table or struct");
|
||||||
}
|
}
|
||||||
@ -743,7 +743,7 @@ int gst_stl_var(Gst *vm) {
|
|||||||
static GstUserType gst_stl_filetype = {
|
static GstUserType gst_stl_filetype = {
|
||||||
"std.file",
|
"std.file",
|
||||||
NULL,
|
NULL,
|
||||||
NULL,
|
NULL,
|
||||||
NULL,
|
NULL,
|
||||||
NULL
|
NULL
|
||||||
};
|
};
|
||||||
@ -754,7 +754,7 @@ int gst_stl_open(Gst *vm) {
|
|||||||
const uint8_t *fmode = gst_to_string(vm, gst_arg(vm, 1));
|
const uint8_t *fmode = gst_to_string(vm, gst_arg(vm, 1));
|
||||||
FILE *f;
|
FILE *f;
|
||||||
FILE **fp;
|
FILE **fp;
|
||||||
if (gst_count_args(vm) < 2 || gst_arg(vm, 0).type != GST_STRING
|
if (gst_count_args(vm) < 2 || gst_arg(vm, 0).type != GST_STRING
|
||||||
|| gst_arg(vm, 1).type != GST_STRING)
|
|| gst_arg(vm, 1).type != GST_STRING)
|
||||||
gst_c_throwc(vm, "expected filename and filemode");
|
gst_c_throwc(vm, "expected filename and filemode");
|
||||||
f = fopen((const char *)fname, (const char *)fmode);
|
f = fopen((const char *)fname, (const char *)fmode);
|
||||||
@ -884,7 +884,7 @@ static GstInteger gst_stl_debugp_helper(Gst *vm, GstBuffer *b, GstTable *seen, G
|
|||||||
if (next == -1)
|
if (next == -1)
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
} else if (gst_seq_view(x, &data, &len)) {
|
} else if (gst_seq_view(x, &data, &len)) {
|
||||||
for (i = 0; i < len; ++i) {
|
for (i = 0; i < len; ++i) {
|
||||||
next = gst_stl_debugp_helper(vm, b, seen, data[i], next, depth);
|
next = gst_stl_debugp_helper(vm, b, seen, data[i], next, depth);
|
||||||
@ -892,7 +892,7 @@ static GstInteger gst_stl_debugp_helper(Gst *vm, GstBuffer *b, GstTable *seen, G
|
|||||||
return -1;
|
return -1;
|
||||||
if (i != len - 1)
|
if (i != len - 1)
|
||||||
gst_buffer_push(vm, b, ' ');
|
gst_buffer_push(vm, b, ' ');
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
gst_buffer_push(vm, b, close);
|
gst_buffer_push(vm, b, close);
|
||||||
}
|
}
|
||||||
@ -1020,7 +1020,7 @@ static int gst_stl_parser_status(Gst *vm) {
|
|||||||
if (p == NULL)
|
if (p == NULL)
|
||||||
gst_c_throwc(vm, "expected parser");
|
gst_c_throwc(vm, "expected parser");
|
||||||
switch (p->status) {
|
switch (p->status) {
|
||||||
case GST_PARSER_ERROR:
|
case GST_PARSER_ERROR:
|
||||||
cstr = "error";
|
cstr = "error";
|
||||||
break;
|
break;
|
||||||
case GST_PARSER_FULL:
|
case GST_PARSER_FULL:
|
||||||
@ -1052,7 +1052,7 @@ static int gst_stl_parse(Gst *vm) {
|
|||||||
gst_parse_byte(&p, data[i]);
|
gst_parse_byte(&p, data[i]);
|
||||||
}
|
}
|
||||||
switch (p.status) {
|
switch (p.status) {
|
||||||
case GST_PARSER_ERROR:
|
case GST_PARSER_ERROR:
|
||||||
gst_c_throwc(vm, p.error);
|
gst_c_throwc(vm, p.error);
|
||||||
break;
|
break;
|
||||||
case GST_PARSER_FULL:
|
case GST_PARSER_FULL:
|
||||||
|
@ -1,16 +1,16 @@
|
|||||||
/*
|
/*
|
||||||
* Copyright (c) 2017 Calvin Rose
|
* Copyright (c) 2017 Calvin Rose
|
||||||
*
|
*
|
||||||
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||||
* of this software and associated documentation files (the "Software"), to
|
* of this software and associated documentation files (the "Software"), to
|
||||||
* deal in the Software without restriction, including without limitation the
|
* deal in the Software without restriction, including without limitation the
|
||||||
* rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
|
* rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
|
||||||
* sell copies of the Software, and to permit persons to whom the Software is
|
* sell copies of the Software, and to permit persons to whom the Software is
|
||||||
* furnished to do so, subject to the following conditions:
|
* furnished to do so, subject to the following conditions:
|
||||||
*
|
*
|
||||||
* The above copyright notice and this permission notice shall be included in
|
* The above copyright notice and this permission notice shall be included in
|
||||||
* all copies or substantial portions of the Software.
|
* all copies or substantial portions of the Software.
|
||||||
*
|
*
|
||||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||||
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||||
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||||
@ -122,8 +122,8 @@ GstValue *gst_thread_beginframe(Gst *vm, GstThread *thread, GstValue callee, uin
|
|||||||
gst_frame_env(newStack) = NULL;
|
gst_frame_env(newStack) = NULL;
|
||||||
gst_frame_size(newStack) = 0;
|
gst_frame_size(newStack) = 0;
|
||||||
gst_frame_callee(newStack) = callee;
|
gst_frame_callee(newStack) = callee;
|
||||||
thread->count += frameOffset;
|
thread->count += frameOffset;
|
||||||
|
|
||||||
/* Ensure the extra space and initialize to nil */
|
/* Ensure the extra space and initialize to nil */
|
||||||
gst_thread_pushnil(vm, thread, arity);
|
gst_thread_pushnil(vm, thread, arity);
|
||||||
|
|
||||||
|
@ -1,16 +1,16 @@
|
|||||||
/*
|
/*
|
||||||
* Copyright (c) 2017 Calvin Rose
|
* Copyright (c) 2017 Calvin Rose
|
||||||
*
|
*
|
||||||
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||||
* of this software and associated documentation files (the "Software"), to
|
* of this software and associated documentation files (the "Software"), to
|
||||||
* deal in the Software without restriction, including without limitation the
|
* deal in the Software without restriction, including without limitation the
|
||||||
* rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
|
* rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
|
||||||
* sell copies of the Software, and to permit persons to whom the Software is
|
* sell copies of the Software, and to permit persons to whom the Software is
|
||||||
* furnished to do so, subject to the following conditions:
|
* furnished to do so, subject to the following conditions:
|
||||||
*
|
*
|
||||||
* The above copyright notice and this permission notice shall be included in
|
* The above copyright notice and this permission notice shall be included in
|
||||||
* all copies or substantial portions of the Software.
|
* all copies or substantial portions of the Software.
|
||||||
*
|
*
|
||||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||||
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||||
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||||
@ -179,7 +179,7 @@ int gst_seq_view(GstValue seq, const GstValue **data, uint32_t *len) {
|
|||||||
*data = seq.data.st;
|
*data = seq.data.st;
|
||||||
*len = gst_tuple_length(seq.data.st);
|
*len = gst_tuple_length(seq.data.st);
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1,16 +1,16 @@
|
|||||||
/*
|
/*
|
||||||
* Copyright (c) 2017 Calvin Rose
|
* Copyright (c) 2017 Calvin Rose
|
||||||
*
|
*
|
||||||
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||||
* of this software and associated documentation files (the "Software"), to
|
* of this software and associated documentation files (the "Software"), to
|
||||||
* deal in the Software without restriction, including without limitation the
|
* deal in the Software without restriction, including without limitation the
|
||||||
* rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
|
* rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
|
||||||
* sell copies of the Software, and to permit persons to whom the Software is
|
* sell copies of the Software, and to permit persons to whom the Software is
|
||||||
* furnished to do so, subject to the following conditions:
|
* furnished to do so, subject to the following conditions:
|
||||||
*
|
*
|
||||||
* The above copyright notice and this permission notice shall be included in
|
* The above copyright notice and this permission notice shall be included in
|
||||||
* all copies or substantial portions of the Software.
|
* all copies or substantial portions of the Software.
|
||||||
*
|
*
|
||||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||||
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||||
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||||
@ -284,7 +284,7 @@ int gst_compare(GstValue x, GstValue y) {
|
|||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Get a value out af an associated data structure.
|
/* Get a value out af an associated data structure.
|
||||||
* Returns possible c error message, and NULL for no error. The
|
* Returns possible c error message, and NULL for no error. The
|
||||||
* useful return value is written to out on success */
|
* useful return value is written to out on success */
|
||||||
const char *gst_get(GstValue ds, GstValue key, GstValue *out) {
|
const char *gst_get(GstValue ds, GstValue key, GstValue *out) {
|
||||||
|
14
core/vm.c
14
core/vm.c
@ -1,16 +1,16 @@
|
|||||||
/*
|
/*
|
||||||
* Copyright (c) 2017 Calvin Rose
|
* Copyright (c) 2017 Calvin Rose
|
||||||
*
|
*
|
||||||
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||||
* of this software and associated documentation files (the "Software"), to
|
* of this software and associated documentation files (the "Software"), to
|
||||||
* deal in the Software without restriction, including without limitation the
|
* deal in the Software without restriction, including without limitation the
|
||||||
* rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
|
* rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
|
||||||
* sell copies of the Software, and to permit persons to whom the Software is
|
* sell copies of the Software, and to permit persons to whom the Software is
|
||||||
* furnished to do so, subject to the following conditions:
|
* furnished to do so, subject to the following conditions:
|
||||||
*
|
*
|
||||||
* The above copyright notice and this permission notice shall be included in
|
* The above copyright notice and this permission notice shall be included in
|
||||||
* all copies or substantial portions of the Software.
|
* all copies or substantial portions of the Software.
|
||||||
*
|
*
|
||||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||||
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||||
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||||
@ -46,13 +46,13 @@ int gst_continue(Gst *vm) {
|
|||||||
|
|
||||||
/* Main interpreter loop */
|
/* Main interpreter loop */
|
||||||
for (;;) {
|
for (;;) {
|
||||||
|
|
||||||
switch (*pc) {
|
switch (*pc) {
|
||||||
|
|
||||||
default:
|
default:
|
||||||
gst_error(vm, "unknown opcode");
|
gst_error(vm, "unknown opcode");
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case GST_OP_FLS: /* Load False */
|
case GST_OP_FLS: /* Load False */
|
||||||
temp.type = GST_BOOLEAN;
|
temp.type = GST_BOOLEAN;
|
||||||
temp.data.boolean = 0;
|
temp.data.boolean = 0;
|
||||||
@ -250,7 +250,7 @@ int gst_continue(Gst *vm) {
|
|||||||
temp = stack[pc[1]];
|
temp = stack[pc[1]];
|
||||||
gst_frame_size(stack) = newStackIndex - GST_FRAME_SIZE;
|
gst_frame_size(stack) = newStackIndex - GST_FRAME_SIZE;
|
||||||
gst_frame_ret(stack) = pc[2];
|
gst_frame_ret(stack) = pc[2];
|
||||||
gst_frame_pc(stack) = pc + 3;
|
gst_frame_pc(stack) = pc + 3;
|
||||||
if (newStackIndex < GST_FRAME_SIZE)
|
if (newStackIndex < GST_FRAME_SIZE)
|
||||||
gst_error(vm, "invalid call instruction");
|
gst_error(vm, "invalid call instruction");
|
||||||
vm->thread->count += newStackIndex;
|
vm->thread->count += newStackIndex;
|
||||||
@ -339,7 +339,7 @@ int gst_continue(Gst *vm) {
|
|||||||
pc += kvs;
|
pc += kvs;
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case GST_OP_TUP: /* Tuple literal */
|
case GST_OP_TUP: /* Tuple literal */
|
||||||
{
|
{
|
||||||
uint32_t i;
|
uint32_t i;
|
||||||
|
@ -1,15 +1,15 @@
|
|||||||
(print "Running basic tests...")
|
(print "\nRunning basic tests...\n")
|
||||||
|
|
||||||
(var num-tests-passed 0)
|
(var num-tests-passed 0)
|
||||||
(var num-tests-run 0)
|
(var num-tests-run 0)
|
||||||
(def assert (fn [x e]
|
(def assert (fn [x e]
|
||||||
(varset! num-tests-run (+ 1 num-tests-run))
|
(varset! num-tests-run (+ 1 num-tests-run))
|
||||||
(if x
|
(if x
|
||||||
(do
|
(do
|
||||||
(print " \e[32m✔\e[0m" e)
|
(print " \e[32m✔\e[0m" e)
|
||||||
(varset! num-tests-passed (+ 1 num-tests-passed))
|
(varset! num-tests-passed (+ 1 num-tests-passed))
|
||||||
x)
|
x)
|
||||||
(do
|
(do
|
||||||
(print " \e[31m✘\e[0m" e)
|
(print " \e[31m✘\e[0m" e)
|
||||||
x))))
|
x))))
|
||||||
|
|
||||||
@ -27,7 +27,7 @@
|
|||||||
(assert (>= 6 5 4 4 3 2 1) "greater than or equal to integers")
|
(assert (>= 6 5 4 4 3 2 1) "greater than or equal to integers")
|
||||||
(assert (>= 6.0 5.0 4.0 4.0 3.0 2.0 1.0) "greater than or equal to reals")
|
(assert (>= 6.0 5.0 4.0 4.0 3.0 2.0 1.0) "greater than or equal to reals")
|
||||||
|
|
||||||
(assert (< nil 1.0 1 false true "hi"
|
(assert (< nil 1.0 1 false true "hi"
|
||||||
(array 1 2 3)
|
(array 1 2 3)
|
||||||
(tuple 1 2 3)
|
(tuple 1 2 3)
|
||||||
(table "a" "b" "c" false)
|
(table "a" "b" "c" false)
|
||||||
@ -41,7 +41,7 @@
|
|||||||
(assert true "true literal")
|
(assert true "true literal")
|
||||||
(assert (not nil) "nil literal")
|
(assert (not nil) "nil literal")
|
||||||
(assert (= 7 (bor 3 4)) "bit or")
|
(assert (= 7 (bor 3 4)) "bit or")
|
||||||
(assert (= 0 (band 3 4)) "bit and")
|
(assert (= 0 (band 3 4)) "bit and")
|
||||||
|
|
||||||
(var accum 1)
|
(var accum 1)
|
||||||
(var count 0)
|
(var count 0)
|
||||||
|
Loading…
Reference in New Issue
Block a user