mirror of
https://github.com/janet-lang/janet
synced 2024-12-22 22:40:26 +00:00
Add source amalgamation
The amalgamated source concatenates all sources to a file janet.c which can be used for embedding janet, much in the same way as sqlite or mongoose.
This commit is contained in:
parent
4d81fbc238
commit
611543c48b
21
Makefile
21
Makefile
@ -119,17 +119,24 @@ build/init.gen.c: src/mainclient/init.janet build/xxd
|
|||||||
build/webinit.gen.c: src/webclient/webinit.janet build/xxd
|
build/webinit.gen.c: src/webclient/webinit.janet build/xxd
|
||||||
build/xxd $< $@ janet_gen_webinit
|
build/xxd $< $@ janet_gen_webinit
|
||||||
|
|
||||||
|
########################
|
||||||
|
##### Amalgamation #####
|
||||||
|
########################
|
||||||
|
|
||||||
|
amalg: build/janet.c build/janet.h
|
||||||
|
|
||||||
|
build/janet.c: $(JANET_LOCAL_HEADERS) $(JANET_CORE_SOURCES) tools/amalg.janet $(JANET_TARGET)
|
||||||
|
$(JANET_TARGET) tools/amalg.janet > $@
|
||||||
|
|
||||||
|
build/janet.h: src/include/janet/janet.h
|
||||||
|
cp $< $@
|
||||||
|
|
||||||
###################
|
###################
|
||||||
##### Testing #####
|
##### Testing #####
|
||||||
###################
|
###################
|
||||||
|
|
||||||
TEST_SOURCES=$(wildcard ctest/*.c)
|
|
||||||
TEST_PROGRAMS=$(patsubst ctest/%.c,build/%.out,$(TEST_SOURCES))
|
|
||||||
TEST_SCRIPTS=$(wildcard test/suite*.janet)
|
TEST_SCRIPTS=$(wildcard test/suite*.janet)
|
||||||
|
|
||||||
build/%.out: ctest/%.c $(JANET_CORE_OBJECTS)
|
|
||||||
$(CC) $(CFLAGS) -o $@ $^ $(CLIBS)
|
|
||||||
|
|
||||||
repl: $(JANET_TARGET)
|
repl: $(JANET_TARGET)
|
||||||
./$(JANET_TARGET)
|
./$(JANET_TARGET)
|
||||||
|
|
||||||
@ -142,11 +149,9 @@ valgrind: $(JANET_TARGET)
|
|||||||
$(VALGRIND_COMMAND) ./$(JANET_TARGET)
|
$(VALGRIND_COMMAND) ./$(JANET_TARGET)
|
||||||
|
|
||||||
test: $(JANET_TARGET) $(TEST_PROGRAMS)
|
test: $(JANET_TARGET) $(TEST_PROGRAMS)
|
||||||
for f in build/*.out; do "$$f" || exit; done
|
|
||||||
for f in test/*.janet; do ./$(JANET_TARGET) "$$f" || exit; done
|
for f in test/*.janet; do ./$(JANET_TARGET) "$$f" || exit; done
|
||||||
|
|
||||||
valtest: $(JANET_TARGET) $(TEST_PROGRAMS)
|
valtest: $(JANET_TARGET) $(TEST_PROGRAMS)
|
||||||
for f in build/*.out; do $(VALGRIND_COMMAND) "$$f" || exit; done
|
|
||||||
for f in test/*.janet; do $(VALGRIND_COMMAND) ./$(JANET_TARGET) "$$f" || exit; done
|
for f in test/*.janet; do $(VALGRIND_COMMAND) ./$(JANET_TARGET) "$$f" || exit; done
|
||||||
|
|
||||||
callgrind: $(JANET_TARGET)
|
callgrind: $(JANET_TARGET)
|
||||||
@ -203,6 +208,6 @@ uninstall:
|
|||||||
-rm -rf $(INCLUDEDIR)
|
-rm -rf $(INCLUDEDIR)
|
||||||
$(LDCONFIG)
|
$(LDCONFIG)
|
||||||
|
|
||||||
.PHONY: clean install repl debug valgrind test \
|
.PHONY: clean install repl debug valgrind test amalg \
|
||||||
valtest emscripten dist uninstall docs grammar \
|
valtest emscripten dist uninstall docs grammar \
|
||||||
$(TEST_PROGRAM_PHONIES) $(TEST_PROGRAM_VALPHONIES)
|
$(TEST_PROGRAM_PHONIES) $(TEST_PROGRAM_VALPHONIES)
|
||||||
|
@ -20,8 +20,10 @@
|
|||||||
* IN THE SOFTWARE.
|
* IN THE SOFTWARE.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
#ifndef JANET_AMALG
|
||||||
#include <janet/janet.h>
|
#include <janet/janet.h>
|
||||||
#include "gc.h"
|
#include "gc.h"
|
||||||
|
#endif
|
||||||
|
|
||||||
/* Create new userdata */
|
/* Create new userdata */
|
||||||
void *janet_abstract(const JanetAbstractType *atype, size_t size) {
|
void *janet_abstract(const JanetAbstractType *atype, size_t size) {
|
||||||
|
@ -20,9 +20,12 @@
|
|||||||
* IN THE SOFTWARE.
|
* IN THE SOFTWARE.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
#ifndef JANET_AMALG
|
||||||
#include <janet/janet.h>
|
#include <janet/janet.h>
|
||||||
#include "gc.h"
|
#include "gc.h"
|
||||||
#include "util.h"
|
#include "util.h"
|
||||||
|
#endif
|
||||||
|
|
||||||
#include <string.h>
|
#include <string.h>
|
||||||
|
|
||||||
/* Initializes an array */
|
/* Initializes an array */
|
||||||
@ -119,26 +122,26 @@ Janet janet_array_peek(JanetArray *array) {
|
|||||||
|
|
||||||
/* C Functions */
|
/* C Functions */
|
||||||
|
|
||||||
static Janet cfun_new(int32_t argc, Janet *argv) {
|
static Janet cfun_array_new(int32_t argc, Janet *argv) {
|
||||||
janet_fixarity(argc, 1);
|
janet_fixarity(argc, 1);
|
||||||
int32_t cap = janet_getinteger(argv, 0);
|
int32_t cap = janet_getinteger(argv, 0);
|
||||||
JanetArray *array = janet_array(cap);
|
JanetArray *array = janet_array(cap);
|
||||||
return janet_wrap_array(array);
|
return janet_wrap_array(array);
|
||||||
}
|
}
|
||||||
|
|
||||||
static Janet cfun_pop(int32_t argc, Janet *argv) {
|
static Janet cfun_array_pop(int32_t argc, Janet *argv) {
|
||||||
janet_fixarity(argc, 1);
|
janet_fixarity(argc, 1);
|
||||||
JanetArray *array = janet_getarray(argv, 0);
|
JanetArray *array = janet_getarray(argv, 0);
|
||||||
return janet_array_pop(array);
|
return janet_array_pop(array);
|
||||||
}
|
}
|
||||||
|
|
||||||
static Janet cfun_peek(int32_t argc, Janet *argv) {
|
static Janet cfun_array_peek(int32_t argc, Janet *argv) {
|
||||||
janet_fixarity(argc, 1);
|
janet_fixarity(argc, 1);
|
||||||
JanetArray *array = janet_getarray(argv, 0);
|
JanetArray *array = janet_getarray(argv, 0);
|
||||||
return janet_array_peek(array);
|
return janet_array_peek(array);
|
||||||
}
|
}
|
||||||
|
|
||||||
static Janet cfun_push(int32_t argc, Janet *argv) {
|
static Janet cfun_array_push(int32_t argc, Janet *argv) {
|
||||||
janet_arity(argc, 1, -1);
|
janet_arity(argc, 1, -1);
|
||||||
JanetArray *array = janet_getarray(argv, 0);
|
JanetArray *array = janet_getarray(argv, 0);
|
||||||
int32_t newcount = array->count - 1 + argc;
|
int32_t newcount = array->count - 1 + argc;
|
||||||
@ -148,7 +151,7 @@ static Janet cfun_push(int32_t argc, Janet *argv) {
|
|||||||
return argv[0];
|
return argv[0];
|
||||||
}
|
}
|
||||||
|
|
||||||
static Janet cfun_ensure(int32_t argc, Janet *argv) {
|
static Janet cfun_array_ensure(int32_t argc, Janet *argv) {
|
||||||
janet_fixarity(argc, 3);
|
janet_fixarity(argc, 3);
|
||||||
JanetArray *array = janet_getarray(argv, 0);
|
JanetArray *array = janet_getarray(argv, 0);
|
||||||
int32_t newcount = janet_getinteger(argv, 1);
|
int32_t newcount = janet_getinteger(argv, 1);
|
||||||
@ -158,7 +161,7 @@ static Janet cfun_ensure(int32_t argc, Janet *argv) {
|
|||||||
return argv[0];
|
return argv[0];
|
||||||
}
|
}
|
||||||
|
|
||||||
static Janet cfun_slice(int32_t argc, Janet *argv) {
|
static Janet cfun_array_slice(int32_t argc, Janet *argv) {
|
||||||
JanetRange range = janet_getslice(argc, argv);
|
JanetRange range = janet_getslice(argc, argv);
|
||||||
JanetView view = janet_getindexed(argv, 0);
|
JanetView view = janet_getindexed(argv, 0);
|
||||||
JanetArray *array = janet_array(range.end - range.start);
|
JanetArray *array = janet_array(range.end - range.start);
|
||||||
@ -167,7 +170,7 @@ static Janet cfun_slice(int32_t argc, Janet *argv) {
|
|||||||
return janet_wrap_array(array);
|
return janet_wrap_array(array);
|
||||||
}
|
}
|
||||||
|
|
||||||
static Janet cfun_concat(int32_t argc, Janet *argv) {
|
static Janet cfun_array_concat(int32_t argc, Janet *argv) {
|
||||||
int32_t i;
|
int32_t i;
|
||||||
janet_arity(argc, 1, -1);
|
janet_arity(argc, 1, -1);
|
||||||
JanetArray *array = janet_getarray(argv, 0);
|
JanetArray *array = janet_getarray(argv, 0);
|
||||||
@ -191,7 +194,7 @@ static Janet cfun_concat(int32_t argc, Janet *argv) {
|
|||||||
return janet_wrap_array(array);
|
return janet_wrap_array(array);
|
||||||
}
|
}
|
||||||
|
|
||||||
static Janet cfun_insert(int32_t argc, Janet *argv) {
|
static Janet cfun_array_insert(int32_t argc, Janet *argv) {
|
||||||
size_t chunksize, restsize;
|
size_t chunksize, restsize;
|
||||||
janet_arity(argc, 2, -1);
|
janet_arity(argc, 2, -1);
|
||||||
JanetArray *array = janet_getarray(argv, 0);
|
JanetArray *array = janet_getarray(argv, 0);
|
||||||
@ -212,47 +215,47 @@ static Janet cfun_insert(int32_t argc, Janet *argv) {
|
|||||||
return janet_wrap_array(array);
|
return janet_wrap_array(array);
|
||||||
}
|
}
|
||||||
|
|
||||||
static const JanetReg cfuns[] = {
|
static const JanetReg array_cfuns[] = {
|
||||||
{"array/new", cfun_new,
|
{"array/new", cfun_array_new,
|
||||||
JDOC("(array/new capacity)\n\n"
|
JDOC("(array/new capacity)\n\n"
|
||||||
"Creates a new empty array with a pre-allocated capacity. The same as "
|
"Creates a new empty array with a pre-allocated capacity. The same as "
|
||||||
"(array) but can be more efficient if the maximum size of an array is known.")
|
"(array) but can be more efficient if the maximum size of an array is known.")
|
||||||
},
|
},
|
||||||
{"array/pop", cfun_pop,
|
{"array/pop", cfun_array_pop,
|
||||||
JDOC("(array/pop arr)\n\n"
|
JDOC("(array/pop arr)\n\n"
|
||||||
"Remove the last element of the array and return it. If the array is empty, will return nil. Modifies "
|
"Remove the last element of the array and return it. If the array is empty, will return nil. Modifies "
|
||||||
"the input array.")
|
"the input array.")
|
||||||
},
|
},
|
||||||
{"array/peek", cfun_peek,
|
{"array/peek", cfun_array_peek,
|
||||||
JDOC("(array/peek arr)\n\n"
|
JDOC("(array/peek arr)\n\n"
|
||||||
"Returns the last element of the array. Does not modify the array.")
|
"Returns the last element of the array. Does not modify the array.")
|
||||||
},
|
},
|
||||||
{"array/push", cfun_push,
|
{"array/push", cfun_array_push,
|
||||||
JDOC("(array/push arr x)\n\n"
|
JDOC("(array/push arr x)\n\n"
|
||||||
"Insert an element in the end of an array. Modifies the input array and returns it.")
|
"Insert an element in the end of an array. Modifies the input array and returns it.")
|
||||||
},
|
},
|
||||||
{"array/ensure", cfun_ensure,
|
{"array/ensure", cfun_array_ensure,
|
||||||
JDOC("(array/ensure arr capacity)\n\n"
|
JDOC("(array/ensure arr capacity)\n\n"
|
||||||
"Ensures that the memory backing the array has enough memory for capacity "
|
"Ensures that the memory backing the array has enough memory for capacity "
|
||||||
"items. Capacity must be an integer. If the backing capacity is already enough, "
|
"items. Capacity must be an integer. If the backing capacity is already enough, "
|
||||||
"then this function does nothing. Otherwise, the backing memory will be reallocated "
|
"then this function does nothing. Otherwise, the backing memory will be reallocated "
|
||||||
"so that there is enough space.")
|
"so that there is enough space.")
|
||||||
},
|
},
|
||||||
{"array/slice", cfun_slice,
|
{"array/slice", cfun_array_slice,
|
||||||
JDOC("(array/slice arrtup [, start=0 [, end=(length arrtup)]])\n\n"
|
JDOC("(array/slice arrtup [, start=0 [, end=(length arrtup)]])\n\n"
|
||||||
"Takes a slice of array or tuple from start to end. The range is half open, "
|
"Takes a slice of array or tuple from start to end. The range is half open, "
|
||||||
"[start, end). Indexes can also be negative, indicating indexing from the end of the "
|
"[start, end). Indexes can also be negative, indicating indexing from the end of the "
|
||||||
"end of the array. By default, start is 0 and end is the length of the array. "
|
"end of the array. By default, start is 0 and end is the length of the array. "
|
||||||
"Returns a new array.")
|
"Returns a new array.")
|
||||||
},
|
},
|
||||||
{"array/concat", cfun_concat,
|
{"array/concat", cfun_array_concat,
|
||||||
JDOC("(array/concat arr & parts)\n\n"
|
JDOC("(array/concat arr & parts)\n\n"
|
||||||
"Concatenates a variadic number of arrays (and tuples) into the first argument "
|
"Concatenates a variadic number of arrays (and tuples) into the first argument "
|
||||||
"which must an array. If any of the parts are arrays or tuples, their elements will "
|
"which must an array. If any of the parts are arrays or tuples, their elements will "
|
||||||
"be inserted into the array. Otherwise, each part in parts will be appended to arr in order. "
|
"be inserted into the array. Otherwise, each part in parts will be appended to arr in order. "
|
||||||
"Return the modified array arr.")
|
"Return the modified array arr.")
|
||||||
},
|
},
|
||||||
{"array/insert", cfun_insert,
|
{"array/insert", cfun_array_insert,
|
||||||
JDOC("(array/insert arr at & xs)\n\n"
|
JDOC("(array/insert arr at & xs)\n\n"
|
||||||
"Insert all of xs into array arr at index at. at should be an integer "
|
"Insert all of xs into array arr at index at. at should be an integer "
|
||||||
"0 and the length of the array. A negative value for at will index from "
|
"0 and the length of the array. A negative value for at will index from "
|
||||||
@ -264,5 +267,5 @@ static const JanetReg cfuns[] = {
|
|||||||
|
|
||||||
/* Load the array module */
|
/* Load the array module */
|
||||||
void janet_lib_array(JanetTable *env) {
|
void janet_lib_array(JanetTable *env) {
|
||||||
janet_cfuns(env, NULL, cfuns);
|
janet_cfuns(env, NULL, array_cfuns);
|
||||||
}
|
}
|
||||||
|
@ -20,9 +20,12 @@
|
|||||||
* IN THE SOFTWARE.
|
* IN THE SOFTWARE.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#include <setjmp.h>
|
#ifndef JANET_AMALG
|
||||||
#include <janet/janet.h>
|
#include <janet/janet.h>
|
||||||
#include "util.h"
|
#include "util.h"
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#include <setjmp.h>
|
||||||
|
|
||||||
/* Conditionally compile this file */
|
/* Conditionally compile this file */
|
||||||
#ifdef JANET_ASSEMBLER
|
#ifdef JANET_ASSEMBLER
|
||||||
@ -930,7 +933,7 @@ static Janet cfun_disasm(int32_t argc, Janet *argv) {
|
|||||||
return janet_disasm(f->def);
|
return janet_disasm(f->def);
|
||||||
}
|
}
|
||||||
|
|
||||||
static const JanetReg cfuns[] = {
|
static const JanetReg asm_cfuns[] = {
|
||||||
{"asm", cfun_asm,
|
{"asm", cfun_asm,
|
||||||
JDOC("(asm assembly)\n\n"
|
JDOC("(asm assembly)\n\n"
|
||||||
"Returns a new function that is the compiled result of the assembly.\n"
|
"Returns a new function that is the compiled result of the assembly.\n"
|
||||||
@ -948,7 +951,7 @@ static const JanetReg cfuns[] = {
|
|||||||
|
|
||||||
/* Load the library */
|
/* Load the library */
|
||||||
void janet_lib_asm(JanetTable *env) {
|
void janet_lib_asm(JanetTable *env) {
|
||||||
janet_cfuns(env, NULL, cfuns);
|
janet_cfuns(env, NULL, asm_cfuns);
|
||||||
}
|
}
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
@ -20,9 +20,11 @@
|
|||||||
* IN THE SOFTWARE.
|
* IN THE SOFTWARE.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
#ifndef JANET_AMALG
|
||||||
#include <janet/janet.h>
|
#include <janet/janet.h>
|
||||||
#include "gc.h"
|
#include "gc.h"
|
||||||
#include "util.h"
|
#include "util.h"
|
||||||
|
#endif
|
||||||
|
|
||||||
/* Initialize a buffer */
|
/* Initialize a buffer */
|
||||||
JanetBuffer *janet_buffer_init(JanetBuffer *buffer, int32_t capacity) {
|
JanetBuffer *janet_buffer_init(JanetBuffer *buffer, int32_t capacity) {
|
||||||
@ -155,14 +157,14 @@ void janet_buffer_push_u64(JanetBuffer *buffer, uint64_t x) {
|
|||||||
|
|
||||||
/* C functions */
|
/* C functions */
|
||||||
|
|
||||||
static Janet cfun_new(int32_t argc, Janet *argv) {
|
static Janet cfun_buffer_new(int32_t argc, Janet *argv) {
|
||||||
janet_fixarity(argc, 1);
|
janet_fixarity(argc, 1);
|
||||||
int32_t cap = janet_getinteger(argv, 0);
|
int32_t cap = janet_getinteger(argv, 0);
|
||||||
JanetBuffer *buffer = janet_buffer(cap);
|
JanetBuffer *buffer = janet_buffer(cap);
|
||||||
return janet_wrap_buffer(buffer);
|
return janet_wrap_buffer(buffer);
|
||||||
}
|
}
|
||||||
|
|
||||||
static Janet cfun_new_filled(int32_t argc, Janet *argv) {
|
static Janet cfun_buffer_new_filled(int32_t argc, Janet *argv) {
|
||||||
janet_arity(argc, 1, 2);
|
janet_arity(argc, 1, 2);
|
||||||
int32_t count = janet_getinteger(argv, 0);
|
int32_t count = janet_getinteger(argv, 0);
|
||||||
int32_t byte = 0;
|
int32_t byte = 0;
|
||||||
@ -175,7 +177,7 @@ static Janet cfun_new_filled(int32_t argc, Janet *argv) {
|
|||||||
return janet_wrap_buffer(buffer);
|
return janet_wrap_buffer(buffer);
|
||||||
}
|
}
|
||||||
|
|
||||||
static Janet cfun_u8(int32_t argc, Janet *argv) {
|
static Janet cfun_buffer_u8(int32_t argc, Janet *argv) {
|
||||||
int32_t i;
|
int32_t i;
|
||||||
janet_arity(argc, 1, -1);
|
janet_arity(argc, 1, -1);
|
||||||
JanetBuffer *buffer = janet_getbuffer(argv, 0);
|
JanetBuffer *buffer = janet_getbuffer(argv, 0);
|
||||||
@ -185,7 +187,7 @@ static Janet cfun_u8(int32_t argc, Janet *argv) {
|
|||||||
return argv[0];
|
return argv[0];
|
||||||
}
|
}
|
||||||
|
|
||||||
static Janet cfun_word(int32_t argc, Janet *argv) {
|
static Janet cfun_buffer_word(int32_t argc, Janet *argv) {
|
||||||
int32_t i;
|
int32_t i;
|
||||||
janet_arity(argc, 1, -1);
|
janet_arity(argc, 1, -1);
|
||||||
JanetBuffer *buffer = janet_getbuffer(argv, 0);
|
JanetBuffer *buffer = janet_getbuffer(argv, 0);
|
||||||
@ -199,7 +201,7 @@ static Janet cfun_word(int32_t argc, Janet *argv) {
|
|||||||
return argv[0];
|
return argv[0];
|
||||||
}
|
}
|
||||||
|
|
||||||
static Janet cfun_chars(int32_t argc, Janet *argv) {
|
static Janet cfun_buffer_chars(int32_t argc, Janet *argv) {
|
||||||
int32_t i;
|
int32_t i;
|
||||||
janet_arity(argc, 1, -1);
|
janet_arity(argc, 1, -1);
|
||||||
JanetBuffer *buffer = janet_getbuffer(argv, 0);
|
JanetBuffer *buffer = janet_getbuffer(argv, 0);
|
||||||
@ -210,14 +212,14 @@ static Janet cfun_chars(int32_t argc, Janet *argv) {
|
|||||||
return argv[0];
|
return argv[0];
|
||||||
}
|
}
|
||||||
|
|
||||||
static Janet cfun_clear(int32_t argc, Janet *argv) {
|
static Janet cfun_buffer_clear(int32_t argc, Janet *argv) {
|
||||||
janet_fixarity(argc, 1);
|
janet_fixarity(argc, 1);
|
||||||
JanetBuffer *buffer = janet_getbuffer(argv, 0);
|
JanetBuffer *buffer = janet_getbuffer(argv, 0);
|
||||||
buffer->count = 0;
|
buffer->count = 0;
|
||||||
return argv[0];
|
return argv[0];
|
||||||
}
|
}
|
||||||
|
|
||||||
static Janet cfun_popn(int32_t argc, Janet *argv) {
|
static Janet cfun_buffer_popn(int32_t argc, Janet *argv) {
|
||||||
janet_fixarity(argc, 2);
|
janet_fixarity(argc, 2);
|
||||||
JanetBuffer *buffer = janet_getbuffer(argv, 0);
|
JanetBuffer *buffer = janet_getbuffer(argv, 0);
|
||||||
int32_t n = janet_getinteger(argv, 1);
|
int32_t n = janet_getinteger(argv, 1);
|
||||||
@ -230,7 +232,7 @@ static Janet cfun_popn(int32_t argc, Janet *argv) {
|
|||||||
return argv[0];
|
return argv[0];
|
||||||
}
|
}
|
||||||
|
|
||||||
static Janet cfun_slice(int32_t argc, Janet *argv) {
|
static Janet cfun_buffer_slice(int32_t argc, Janet *argv) {
|
||||||
JanetRange range = janet_getslice(argc, argv);
|
JanetRange range = janet_getslice(argc, argv);
|
||||||
JanetByteView view = janet_getbytes(argv, 0);
|
JanetByteView view = janet_getbytes(argv, 0);
|
||||||
JanetBuffer *buffer = janet_buffer(range.end - range.start);
|
JanetBuffer *buffer = janet_buffer(range.end - range.start);
|
||||||
@ -253,7 +255,7 @@ static void bitloc(int32_t argc, Janet *argv, JanetBuffer **b, int32_t *index, i
|
|||||||
*bit = which_bit;
|
*bit = which_bit;
|
||||||
}
|
}
|
||||||
|
|
||||||
static Janet cfun_bitset(int32_t argc, Janet *argv) {
|
static Janet cfun_buffer_bitset(int32_t argc, Janet *argv) {
|
||||||
int bit;
|
int bit;
|
||||||
int32_t index;
|
int32_t index;
|
||||||
JanetBuffer *buffer;
|
JanetBuffer *buffer;
|
||||||
@ -262,7 +264,7 @@ static Janet cfun_bitset(int32_t argc, Janet *argv) {
|
|||||||
return argv[0];
|
return argv[0];
|
||||||
}
|
}
|
||||||
|
|
||||||
static Janet cfun_bitclear(int32_t argc, Janet *argv) {
|
static Janet cfun_buffer_bitclear(int32_t argc, Janet *argv) {
|
||||||
int bit;
|
int bit;
|
||||||
int32_t index;
|
int32_t index;
|
||||||
JanetBuffer *buffer;
|
JanetBuffer *buffer;
|
||||||
@ -271,7 +273,7 @@ static Janet cfun_bitclear(int32_t argc, Janet *argv) {
|
|||||||
return argv[0];
|
return argv[0];
|
||||||
}
|
}
|
||||||
|
|
||||||
static Janet cfun_bitget(int32_t argc, Janet *argv) {
|
static Janet cfun_buffer_bitget(int32_t argc, Janet *argv) {
|
||||||
int bit;
|
int bit;
|
||||||
int32_t index;
|
int32_t index;
|
||||||
JanetBuffer *buffer;
|
JanetBuffer *buffer;
|
||||||
@ -279,7 +281,7 @@ static Janet cfun_bitget(int32_t argc, Janet *argv) {
|
|||||||
return janet_wrap_boolean(buffer->data[index] & (1 << bit));
|
return janet_wrap_boolean(buffer->data[index] & (1 << bit));
|
||||||
}
|
}
|
||||||
|
|
||||||
static Janet cfun_bittoggle(int32_t argc, Janet *argv) {
|
static Janet cfun_buffer_bittoggle(int32_t argc, Janet *argv) {
|
||||||
int bit;
|
int bit;
|
||||||
int32_t index;
|
int32_t index;
|
||||||
JanetBuffer *buffer;
|
JanetBuffer *buffer;
|
||||||
@ -288,7 +290,7 @@ static Janet cfun_bittoggle(int32_t argc, Janet *argv) {
|
|||||||
return argv[0];
|
return argv[0];
|
||||||
}
|
}
|
||||||
|
|
||||||
static Janet cfun_blit(int32_t argc, Janet *argv) {
|
static Janet cfun_buffer_blit(int32_t argc, Janet *argv) {
|
||||||
janet_arity(argc, 2, 5);
|
janet_arity(argc, 2, 5);
|
||||||
JanetBuffer *dest = janet_getbuffer(argv, 0);
|
JanetBuffer *dest = janet_getbuffer(argv, 0);
|
||||||
JanetByteView src = janet_getbytes(argv, 1);
|
JanetByteView src = janet_getbytes(argv, 1);
|
||||||
@ -315,67 +317,67 @@ static Janet cfun_blit(int32_t argc, Janet *argv) {
|
|||||||
return argv[0];
|
return argv[0];
|
||||||
}
|
}
|
||||||
|
|
||||||
static const JanetReg cfuns[] = {
|
static const JanetReg buffer_cfuns[] = {
|
||||||
{"buffer/new", cfun_new,
|
{"buffer/new", cfun_buffer_new,
|
||||||
JDOC("(buffer/new capacity)\n\n"
|
JDOC("(buffer/new capacity)\n\n"
|
||||||
"Creates a new, empty buffer with enough memory for capacity bytes. "
|
"Creates a new, empty buffer with enough memory for capacity bytes. "
|
||||||
"Returns a new buffer.")
|
"Returns a new buffer.")
|
||||||
},
|
},
|
||||||
{"buffer/new-filled", cfun_new_filled,
|
{"buffer/new-filled", cfun_buffer_new_filled,
|
||||||
JDOC("(buffer/new-filled count [, byte=0])\n\n"
|
JDOC("(buffer/new-filled count [, byte=0])\n\n"
|
||||||
"Creates a new buffer of length count filled with byte. "
|
"Creates a new buffer of length count filled with byte. "
|
||||||
"Returns the new buffer.")
|
"Returns the new buffer.")
|
||||||
},
|
},
|
||||||
{"buffer/push-byte", cfun_u8,
|
{"buffer/push-byte", cfun_buffer_u8,
|
||||||
JDOC("(buffer/push-byte buffer x)\n\n"
|
JDOC("(buffer/push-byte buffer x)\n\n"
|
||||||
"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-word", cfun_word,
|
{"buffer/push-word", cfun_buffer_word,
|
||||||
JDOC("(buffer/push-word buffer x)\n\n"
|
JDOC("(buffer/push-word buffer x)\n\n"
|
||||||
"Append a machine word 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, unsigned. 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_buffer_chars,
|
||||||
JDOC("(buffer/push-string buffer str)\n\n"
|
JDOC("(buffer/push-string buffer str)\n\n"
|
||||||
"Push a string onto the end of a buffer. Non string values will be converted "
|
"Push a string onto the end of a buffer. Non string values will be converted "
|
||||||
"to strings before being pushed. Returns the modified buffer. "
|
"to strings before being pushed. Returns the modified buffer. "
|
||||||
"Will throw an error if the buffer overflows.")
|
"Will throw an error if the buffer overflows.")
|
||||||
},
|
},
|
||||||
{"buffer/popn", cfun_popn,
|
{"buffer/popn", cfun_buffer_popn,
|
||||||
JDOC("(buffer/popn buffer n)\n\n"
|
JDOC("(buffer/popn buffer n)\n\n"
|
||||||
"Removes the last n bytes from the buffer. Returns the modified buffer.")
|
"Removes the last n bytes from the buffer. Returns the modified buffer.")
|
||||||
},
|
},
|
||||||
{"buffer/clear", cfun_clear,
|
{"buffer/clear", cfun_buffer_clear,
|
||||||
JDOC("(buffer/clear buffer)\n\n"
|
JDOC("(buffer/clear buffer)\n\n"
|
||||||
"Sets the size of a buffer to 0 and empties it. The buffer retains "
|
"Sets the size of a buffer to 0 and empties it. The buffer retains "
|
||||||
"its memory so it can be efficiently refilled. Returns the modified buffer.")
|
"its memory so it can be efficiently refilled. Returns the modified buffer.")
|
||||||
},
|
},
|
||||||
{"buffer/slice", cfun_slice,
|
{"buffer/slice", cfun_buffer_slice,
|
||||||
JDOC("(buffer/slice bytes [, start=0 [, end=(length bytes)]])\n\n"
|
JDOC("(buffer/slice bytes [, start=0 [, end=(length bytes)]])\n\n"
|
||||||
"Takes a slice of a byte sequence from start to end. The range is half open, "
|
"Takes a slice of a byte sequence from start to end. The range is half open, "
|
||||||
"[start, end). Indexes can also be negative, indicating indexing from the end of the "
|
"[start, end). Indexes can also be negative, indicating indexing from the end of the "
|
||||||
"end of the array. By default, start is 0 and end is the length of the buffer. "
|
"end of the array. By default, start is 0 and end is the length of the buffer. "
|
||||||
"Returns a new buffer.")
|
"Returns a new buffer.")
|
||||||
},
|
},
|
||||||
{"buffer/bit-set", cfun_bitset,
|
{"buffer/bit-set", cfun_buffer_bitset,
|
||||||
JDOC("(buffer/bit-set buffer index)\n\n"
|
JDOC("(buffer/bit-set buffer index)\n\n"
|
||||||
"Sets the bit at the given bit-index. Returns the buffer.")
|
"Sets the bit at the given bit-index. Returns the buffer.")
|
||||||
},
|
},
|
||||||
{"buffer/bit-clear", cfun_bitclear,
|
{"buffer/bit-clear", cfun_buffer_bitclear,
|
||||||
JDOC("(buffer/bit-clear buffer index)\n\n"
|
JDOC("(buffer/bit-clear buffer index)\n\n"
|
||||||
"Clears the bit at the given bit-index. Returns the buffer.")
|
"Clears the bit at the given bit-index. Returns the buffer.")
|
||||||
},
|
},
|
||||||
{"buffer/bit", cfun_bitget,
|
{"buffer/bit", cfun_buffer_bitget,
|
||||||
JDOC("(buffer/bit buffer index)\n\n"
|
JDOC("(buffer/bit buffer index)\n\n"
|
||||||
"Gets the bit at the given bit-index. Returns true if the bit is set, false if not.")
|
"Gets the bit at the given bit-index. Returns true if the bit is set, false if not.")
|
||||||
},
|
},
|
||||||
{"buffer/bit-toggle", cfun_bittoggle,
|
{"buffer/bit-toggle", cfun_buffer_bittoggle,
|
||||||
JDOC("(buffer/bit-toggle buffer index)\n\n"
|
JDOC("(buffer/bit-toggle buffer index)\n\n"
|
||||||
"Toggles the bit at the given bit index in buffer. Returns the buffer.")
|
"Toggles the bit at the given bit index in buffer. Returns the buffer.")
|
||||||
},
|
},
|
||||||
{"buffer/blit", cfun_blit,
|
{"buffer/blit", cfun_buffer_blit,
|
||||||
JDOC("(buffer/blit dest src [, dest-start=0 [, src-start=0 [, src-end=-1]]])\n\n"
|
JDOC("(buffer/blit dest src [, dest-start=0 [, src-start=0 [, src-end=-1]]])\n\n"
|
||||||
"Insert the contents of src into dest. Can optionally take indices that "
|
"Insert the contents of src into dest. Can optionally take indices that "
|
||||||
"indicate which part of src to copy into which part of dest. Indices can be "
|
"indicate which part of src to copy into which part of dest. Indices can be "
|
||||||
@ -385,5 +387,5 @@ static const JanetReg cfuns[] = {
|
|||||||
};
|
};
|
||||||
|
|
||||||
void janet_lib_buffer(JanetTable *env) {
|
void janet_lib_buffer(JanetTable *env) {
|
||||||
janet_cfuns(env, NULL, cfuns);
|
janet_cfuns(env, NULL, buffer_cfuns);
|
||||||
}
|
}
|
||||||
|
@ -20,8 +20,10 @@
|
|||||||
* IN THE SOFTWARE.
|
* IN THE SOFTWARE.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
#ifndef JANET_AMALG
|
||||||
#include <janet/janet.h>
|
#include <janet/janet.h>
|
||||||
#include "gc.h"
|
#include "gc.h"
|
||||||
|
#endif
|
||||||
|
|
||||||
/* Look up table for instructions */
|
/* Look up table for instructions */
|
||||||
enum JanetInstructionType janet_instructions[JOP_INSTRUCTION_COUNT] = {
|
enum JanetInstructionType janet_instructions[JOP_INSTRUCTION_COUNT] = {
|
||||||
|
@ -20,9 +20,11 @@
|
|||||||
* IN THE SOFTWARE.
|
* IN THE SOFTWARE.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
#ifndef JANET_AMALG
|
||||||
#include <janet/janet.h>
|
#include <janet/janet.h>
|
||||||
#include "state.h"
|
#include "state.h"
|
||||||
#include "fiber.h"
|
#include "fiber.h"
|
||||||
|
#endif
|
||||||
|
|
||||||
void janet_panicv(Janet message) {
|
void janet_panicv(Janet message) {
|
||||||
if (janet_vm_fiber != NULL) {
|
if (janet_vm_fiber != NULL) {
|
||||||
|
@ -20,10 +20,12 @@
|
|||||||
* IN THE SOFTWARE.
|
* IN THE SOFTWARE.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
#ifndef JANET_AMALG
|
||||||
#include <janet/janet.h>
|
#include <janet/janet.h>
|
||||||
#include "compile.h"
|
#include "compile.h"
|
||||||
#include "emit.h"
|
#include "emit.h"
|
||||||
#include "vector.h"
|
#include "vector.h"
|
||||||
|
#endif
|
||||||
|
|
||||||
static int fixarity0(JanetFopts opts, JanetSlot *args) {
|
static int fixarity0(JanetFopts opts, JanetSlot *args) {
|
||||||
(void) opts;
|
(void) opts;
|
||||||
|
@ -20,11 +20,13 @@
|
|||||||
* IN THE SOFTWARE.
|
* IN THE SOFTWARE.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
#ifndef JANET_AMALG
|
||||||
#include <janet/janet.h>
|
#include <janet/janet.h>
|
||||||
#include "compile.h"
|
#include "compile.h"
|
||||||
#include "emit.h"
|
#include "emit.h"
|
||||||
#include "vector.h"
|
#include "vector.h"
|
||||||
#include "util.h"
|
#include "util.h"
|
||||||
|
#endif
|
||||||
|
|
||||||
JanetFopts janetc_fopts_default(JanetCompiler *c) {
|
JanetFopts janetc_fopts_default(JanetCompiler *c) {
|
||||||
JanetFopts ret;
|
JanetFopts ret;
|
||||||
@ -724,7 +726,7 @@ static Janet cfun(int32_t argc, Janet *argv) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
static const JanetReg cfuns[] = {
|
static const JanetReg compile_cfuns[] = {
|
||||||
{"compile", cfun,
|
{"compile", cfun,
|
||||||
JDOC("(compile ast env [, source])\n\n"
|
JDOC("(compile ast env [, source])\n\n"
|
||||||
"Compiles an Abstract Syntax Tree (ast) into a janet function. "
|
"Compiles an Abstract Syntax Tree (ast) into a janet function. "
|
||||||
@ -736,5 +738,5 @@ static const JanetReg cfuns[] = {
|
|||||||
};
|
};
|
||||||
|
|
||||||
void janet_lib_compile(JanetTable *env) {
|
void janet_lib_compile(JanetTable *env) {
|
||||||
janet_cfuns(env, NULL, cfuns);
|
janet_cfuns(env, NULL, compile_cfuns);
|
||||||
}
|
}
|
||||||
|
@ -23,8 +23,10 @@
|
|||||||
#ifndef JANET_COMPILE_H
|
#ifndef JANET_COMPILE_H
|
||||||
#define JANET_COMPILE_H
|
#define JANET_COMPILE_H
|
||||||
|
|
||||||
|
#ifndef JANET_AMALG
|
||||||
#include <janet/janet.h>
|
#include <janet/janet.h>
|
||||||
#include "regalloc.h"
|
#include "regalloc.h"
|
||||||
|
#endif
|
||||||
|
|
||||||
/* Tags for some functions for the prepared inliner */
|
/* Tags for some functions for the prepared inliner */
|
||||||
#define JANET_FUN_DEBUG 1
|
#define JANET_FUN_DEBUG 1
|
||||||
|
@ -20,10 +20,12 @@
|
|||||||
* IN THE SOFTWARE.
|
* IN THE SOFTWARE.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
#ifndef JANET_AMALG
|
||||||
#include <janet/janet.h>
|
#include <janet/janet.h>
|
||||||
#include "compile.h"
|
#include "compile.h"
|
||||||
#include "state.h"
|
#include "state.h"
|
||||||
#include "util.h"
|
#include "util.h"
|
||||||
|
#endif
|
||||||
|
|
||||||
/* Generated bytes */
|
/* Generated bytes */
|
||||||
extern const unsigned char *janet_gen_core;
|
extern const unsigned char *janet_gen_core;
|
||||||
@ -236,7 +238,7 @@ static Janet janet_core_hash(int32_t argc, Janet *argv) {
|
|||||||
return janet_wrap_number(janet_hash(argv[0]));
|
return janet_wrap_number(janet_hash(argv[0]));
|
||||||
}
|
}
|
||||||
|
|
||||||
static const JanetReg cfuns[] = {
|
static const JanetReg corelib_cfuns[] = {
|
||||||
{"native", janet_core_native,
|
{"native", janet_core_native,
|
||||||
JDOC("(native path [,env])\n\n"
|
JDOC("(native path [,env])\n\n"
|
||||||
"Load a native module from the given path. The path "
|
"Load a native module from the given path. The path "
|
||||||
@ -596,7 +598,7 @@ JanetTable *janet_core_env(void) {
|
|||||||
Janet ret = janet_wrap_table(env);
|
Janet ret = janet_wrap_table(env);
|
||||||
|
|
||||||
/* Load main functions */
|
/* Load main functions */
|
||||||
janet_cfuns(env, NULL, cfuns);
|
janet_cfuns(env, NULL, corelib_cfuns);
|
||||||
|
|
||||||
#ifndef JANET_NO_BOOTSTRAP
|
#ifndef JANET_NO_BOOTSTRAP
|
||||||
janet_quick_asm(env, JANET_FUN_YIELD, "debug", 0, 1, debug_asm, sizeof(debug_asm),
|
janet_quick_asm(env, JANET_FUN_YIELD, "debug", 0, 1, debug_asm, sizeof(debug_asm),
|
||||||
|
@ -20,10 +20,12 @@
|
|||||||
* IN THE SOFTWARE.
|
* IN THE SOFTWARE.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
#ifndef JANET_AMALG
|
||||||
#include <janet/janet.h>
|
#include <janet/janet.h>
|
||||||
#include "gc.h"
|
#include "gc.h"
|
||||||
#include "state.h"
|
#include "state.h"
|
||||||
#include "util.h"
|
#include "util.h"
|
||||||
|
#endif
|
||||||
|
|
||||||
/* Implements functionality to build a debugger from within janet.
|
/* Implements functionality to build a debugger from within janet.
|
||||||
* The repl should also be able to serve as pretty featured debugger
|
* The repl should also be able to serve as pretty featured debugger
|
||||||
@ -111,7 +113,7 @@ static void helper_find_fun(int32_t argc, Janet *argv, JanetFuncDef **def, int32
|
|||||||
*bytecode_offset = offset;
|
*bytecode_offset = offset;
|
||||||
}
|
}
|
||||||
|
|
||||||
static Janet cfun_break(int32_t argc, Janet *argv) {
|
static Janet cfun_debug_break(int32_t argc, Janet *argv) {
|
||||||
JanetFuncDef *def;
|
JanetFuncDef *def;
|
||||||
int32_t offset;
|
int32_t offset;
|
||||||
helper_find(argc, argv, &def, &offset);
|
helper_find(argc, argv, &def, &offset);
|
||||||
@ -119,7 +121,7 @@ static Janet cfun_break(int32_t argc, Janet *argv) {
|
|||||||
return janet_wrap_nil();
|
return janet_wrap_nil();
|
||||||
}
|
}
|
||||||
|
|
||||||
static Janet cfun_unbreak(int32_t argc, Janet *argv) {
|
static Janet cfun_debug_unbreak(int32_t argc, Janet *argv) {
|
||||||
JanetFuncDef *def;
|
JanetFuncDef *def;
|
||||||
int32_t offset;
|
int32_t offset;
|
||||||
helper_find(argc, argv, &def, &offset);
|
helper_find(argc, argv, &def, &offset);
|
||||||
@ -127,7 +129,7 @@ static Janet cfun_unbreak(int32_t argc, Janet *argv) {
|
|||||||
return janet_wrap_nil();
|
return janet_wrap_nil();
|
||||||
}
|
}
|
||||||
|
|
||||||
static Janet cfun_fbreak(int32_t argc, Janet *argv) {
|
static Janet cfun_debug_fbreak(int32_t argc, Janet *argv) {
|
||||||
JanetFuncDef *def;
|
JanetFuncDef *def;
|
||||||
int32_t offset;
|
int32_t offset;
|
||||||
helper_find_fun(argc, argv, &def, &offset);
|
helper_find_fun(argc, argv, &def, &offset);
|
||||||
@ -135,7 +137,7 @@ static Janet cfun_fbreak(int32_t argc, Janet *argv) {
|
|||||||
return janet_wrap_nil();
|
return janet_wrap_nil();
|
||||||
}
|
}
|
||||||
|
|
||||||
static Janet cfun_unfbreak(int32_t argc, Janet *argv) {
|
static Janet cfun_debug_unfbreak(int32_t argc, Janet *argv) {
|
||||||
JanetFuncDef *def;
|
JanetFuncDef *def;
|
||||||
int32_t offset;
|
int32_t offset;
|
||||||
helper_find_fun(argc, argv, &def, &offset);
|
helper_find_fun(argc, argv, &def, &offset);
|
||||||
@ -143,7 +145,7 @@ static Janet cfun_unfbreak(int32_t argc, Janet *argv) {
|
|||||||
return janet_wrap_nil();
|
return janet_wrap_nil();
|
||||||
}
|
}
|
||||||
|
|
||||||
static Janet cfun_lineage(int32_t argc, Janet *argv) {
|
static Janet cfun_debug_lineage(int32_t argc, Janet *argv) {
|
||||||
janet_fixarity(argc, 1);
|
janet_fixarity(argc, 1);
|
||||||
JanetFiber *fiber = janet_getfiber(argv, 0);
|
JanetFiber *fiber = janet_getfiber(argv, 0);
|
||||||
JanetArray *array = janet_array(0);
|
JanetArray *array = janet_array(0);
|
||||||
@ -200,7 +202,7 @@ static Janet doframe(JanetStackFrame *frame) {
|
|||||||
return janet_wrap_table(t);
|
return janet_wrap_table(t);
|
||||||
}
|
}
|
||||||
|
|
||||||
static Janet cfun_stack(int32_t argc, Janet *argv) {
|
static Janet cfun_debug_stack(int32_t argc, Janet *argv) {
|
||||||
janet_fixarity(argc, 1);
|
janet_fixarity(argc, 1);
|
||||||
JanetFiber *fiber = janet_getfiber(argv, 0);
|
JanetFiber *fiber = janet_getfiber(argv, 0);
|
||||||
JanetArray *array = janet_array(0);
|
JanetArray *array = janet_array(0);
|
||||||
@ -216,7 +218,7 @@ static Janet cfun_stack(int32_t argc, Janet *argv) {
|
|||||||
return janet_wrap_array(array);
|
return janet_wrap_array(array);
|
||||||
}
|
}
|
||||||
|
|
||||||
static Janet cfun_argstack(int32_t argc, Janet *argv) {
|
static Janet cfun_debug_argstack(int32_t argc, Janet *argv) {
|
||||||
janet_fixarity(argc, 1);
|
janet_fixarity(argc, 1);
|
||||||
JanetFiber *fiber = janet_getfiber(argv, 0);
|
JanetFiber *fiber = janet_getfiber(argv, 0);
|
||||||
JanetArray *array = janet_array(fiber->stacktop - fiber->stackstart);
|
JanetArray *array = janet_array(fiber->stacktop - fiber->stackstart);
|
||||||
@ -225,9 +227,9 @@ static Janet cfun_argstack(int32_t argc, Janet *argv) {
|
|||||||
return janet_wrap_array(array);
|
return janet_wrap_array(array);
|
||||||
}
|
}
|
||||||
|
|
||||||
static const JanetReg cfuns[] = {
|
static const JanetReg debug_cfuns[] = {
|
||||||
{
|
{
|
||||||
"debug/break", cfun_break,
|
"debug/break", cfun_debug_break,
|
||||||
JDOC("(debug/break source byte-offset)\n\n"
|
JDOC("(debug/break source byte-offset)\n\n"
|
||||||
"Sets a breakpoint with source a key at a given byte offset. An offset "
|
"Sets a breakpoint with source a key at a given byte offset. An offset "
|
||||||
"of 0 is the first byte in a file. Will throw an error if the breakpoint location "
|
"of 0 is the first byte in a file. Will throw an error if the breakpoint location "
|
||||||
@ -236,33 +238,33 @@ static const JanetReg cfuns[] = {
|
|||||||
"wil set a breakpoint at the 1000th byte of the file core.janet.")
|
"wil set a breakpoint at the 1000th byte of the file core.janet.")
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
"debug/unbreak", cfun_unbreak,
|
"debug/unbreak", cfun_debug_unbreak,
|
||||||
JDOC("(debug/unbreak source byte-offset)\n\n"
|
JDOC("(debug/unbreak source byte-offset)\n\n"
|
||||||
"Remove a breakpoint with a source key at a given byte offset. An offset "
|
"Remove a breakpoint with a source key at a given byte offset. An offset "
|
||||||
"of 0 is the first byte in a file. Will throw an error if the breakpoint "
|
"of 0 is the first byte in a file. Will throw an error if the breakpoint "
|
||||||
"cannot be found.")
|
"cannot be found.")
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
"debug/fbreak", cfun_fbreak,
|
"debug/fbreak", cfun_debug_fbreak,
|
||||||
JDOC("(debug/fbreak fun [,pc=0])\n\n"
|
JDOC("(debug/fbreak fun [,pc=0])\n\n"
|
||||||
"Set a breakpoint in a given function. pc is an optional offset, which "
|
"Set a breakpoint in a given function. pc is an optional offset, which "
|
||||||
"is in bytecode instructions. fun is a function value. Will throw an error "
|
"is in bytecode instructions. fun is a function value. Will throw an error "
|
||||||
"if the offset is too large or negative.")
|
"if the offset is too large or negative.")
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
"debug/unfbreak", cfun_unfbreak,
|
"debug/unfbreak", cfun_debug_unfbreak,
|
||||||
JDOC("(debug/unfbreak fun [,pc=0])\n\n"
|
JDOC("(debug/unfbreak fun [,pc=0])\n\n"
|
||||||
"Unset a breakpoint set with debug/fbreak.")
|
"Unset a breakpoint set with debug/fbreak.")
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
"debug/arg-stack", cfun_argstack,
|
"debug/arg-stack", cfun_debug_argstack,
|
||||||
JDOC("(debug/arg-stack fiber)\n\n"
|
JDOC("(debug/arg-stack fiber)\n\n"
|
||||||
"Gets all values currently on the fiber's argument stack. Normally, "
|
"Gets all values currently on the fiber's argument stack. Normally, "
|
||||||
"this should be empty unless the fiber signals while pushing arguments "
|
"this should be empty unless the fiber signals while pushing arguments "
|
||||||
"to make a function call. Returns a new array.")
|
"to make a function call. Returns a new array.")
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
"debug/stack", cfun_stack,
|
"debug/stack", cfun_debug_stack,
|
||||||
JDOC("(debug/stack fib)\n\n"
|
JDOC("(debug/stack fib)\n\n"
|
||||||
"Gets information about the stack as an array of tables. Each table "
|
"Gets information about the stack as an array of tables. Each table "
|
||||||
"in the array contains information about a stack frame. The top most, current "
|
"in the array contains information about a stack frame. The top most, current "
|
||||||
@ -279,7 +281,7 @@ static const JanetReg cfuns[] = {
|
|||||||
"\t:tail - boolean indicating a tail call")
|
"\t:tail - boolean indicating a tail call")
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
"debug/lineage", cfun_lineage,
|
"debug/lineage", cfun_debug_lineage,
|
||||||
JDOC("(debug/lineage fib)\n\n"
|
JDOC("(debug/lineage fib)\n\n"
|
||||||
"Returns an array of all child fibers from a root fiber. This function "
|
"Returns an array of all child fibers from a root fiber. This function "
|
||||||
"is useful when a fiber signals or errors to an ancestor fiber. Using this function, "
|
"is useful when a fiber signals or errors to an ancestor fiber. Using this function, "
|
||||||
@ -291,5 +293,5 @@ static const JanetReg cfuns[] = {
|
|||||||
|
|
||||||
/* Module entry point */
|
/* Module entry point */
|
||||||
void janet_lib_debug(JanetTable *env) {
|
void janet_lib_debug(JanetTable *env) {
|
||||||
janet_cfuns(env, NULL, cfuns);
|
janet_cfuns(env, NULL, debug_cfuns);
|
||||||
}
|
}
|
||||||
|
@ -20,10 +20,12 @@
|
|||||||
* IN THE SOFTWARE.
|
* IN THE SOFTWARE.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
#ifndef JANET_AMALG
|
||||||
#include <janet/janet.h>
|
#include <janet/janet.h>
|
||||||
#include "emit.h"
|
#include "emit.h"
|
||||||
#include "vector.h"
|
#include "vector.h"
|
||||||
#include "regalloc.h"
|
#include "regalloc.h"
|
||||||
|
#endif
|
||||||
|
|
||||||
/* Get a register */
|
/* Get a register */
|
||||||
int32_t janetc_allocfar(JanetCompiler *c) {
|
int32_t janetc_allocfar(JanetCompiler *c) {
|
||||||
|
@ -23,7 +23,9 @@
|
|||||||
#ifndef JANET_EMIT_H
|
#ifndef JANET_EMIT_H
|
||||||
#define JANET_EMIT_H
|
#define JANET_EMIT_H
|
||||||
|
|
||||||
|
#ifndef JANET_AMALG
|
||||||
#include "compile.h"
|
#include "compile.h"
|
||||||
|
#endif
|
||||||
|
|
||||||
void janetc_emit(JanetCompiler *c, uint32_t instr);
|
void janetc_emit(JanetCompiler *c, uint32_t instr);
|
||||||
|
|
||||||
|
@ -20,11 +20,13 @@
|
|||||||
* IN THE SOFTWARE.
|
* IN THE SOFTWARE.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
#ifndef JANET_AMALG
|
||||||
#include <janet/janet.h>
|
#include <janet/janet.h>
|
||||||
#include "fiber.h"
|
#include "fiber.h"
|
||||||
#include "state.h"
|
#include "state.h"
|
||||||
#include "gc.h"
|
#include "gc.h"
|
||||||
#include "util.h"
|
#include "util.h"
|
||||||
|
#endif
|
||||||
|
|
||||||
static void fiber_reset(JanetFiber *fiber) {
|
static void fiber_reset(JanetFiber *fiber) {
|
||||||
fiber->maxstack = JANET_STACK_MAX;
|
fiber->maxstack = JANET_STACK_MAX;
|
||||||
@ -296,7 +298,7 @@ void janet_fiber_popframe(JanetFiber *fiber) {
|
|||||||
|
|
||||||
/* CFuns */
|
/* CFuns */
|
||||||
|
|
||||||
static Janet cfun_new(int32_t argc, Janet *argv) {
|
static Janet cfun_fiber_new(int32_t argc, Janet *argv) {
|
||||||
janet_arity(argc, 1, 2);
|
janet_arity(argc, 1, 2);
|
||||||
JanetFunction *func = janet_getfunction(argv, 0);
|
JanetFunction *func = janet_getfunction(argv, 0);
|
||||||
JanetFiber *fiber;
|
JanetFiber *fiber;
|
||||||
@ -345,7 +347,7 @@ static Janet cfun_new(int32_t argc, Janet *argv) {
|
|||||||
return janet_wrap_fiber(fiber);
|
return janet_wrap_fiber(fiber);
|
||||||
}
|
}
|
||||||
|
|
||||||
static Janet cfun_status(int32_t argc, Janet *argv) {
|
static Janet cfun_fiber_status(int32_t argc, Janet *argv) {
|
||||||
janet_fixarity(argc, 1);
|
janet_fixarity(argc, 1);
|
||||||
JanetFiber *fiber = janet_getfiber(argv, 0);
|
JanetFiber *fiber = janet_getfiber(argv, 0);
|
||||||
uint32_t s = (fiber->flags & JANET_FIBER_STATUS_MASK) >>
|
uint32_t s = (fiber->flags & JANET_FIBER_STATUS_MASK) >>
|
||||||
@ -353,19 +355,19 @@ static Janet cfun_status(int32_t argc, Janet *argv) {
|
|||||||
return janet_ckeywordv(janet_status_names[s]);
|
return janet_ckeywordv(janet_status_names[s]);
|
||||||
}
|
}
|
||||||
|
|
||||||
static Janet cfun_current(int32_t argc, Janet *argv) {
|
static Janet cfun_fiber_current(int32_t argc, Janet *argv) {
|
||||||
(void) argv;
|
(void) argv;
|
||||||
janet_fixarity(argc, 0);
|
janet_fixarity(argc, 0);
|
||||||
return janet_wrap_fiber(janet_vm_fiber);
|
return janet_wrap_fiber(janet_vm_fiber);
|
||||||
}
|
}
|
||||||
|
|
||||||
static Janet cfun_maxstack(int32_t argc, Janet *argv) {
|
static Janet cfun_fiber_maxstack(int32_t argc, Janet *argv) {
|
||||||
janet_fixarity(argc, 1);
|
janet_fixarity(argc, 1);
|
||||||
JanetFiber *fiber = janet_getfiber(argv, 0);
|
JanetFiber *fiber = janet_getfiber(argv, 0);
|
||||||
return janet_wrap_integer(fiber->maxstack);
|
return janet_wrap_integer(fiber->maxstack);
|
||||||
}
|
}
|
||||||
|
|
||||||
static Janet cfun_setmaxstack(int32_t argc, Janet *argv) {
|
static Janet cfun_fiber_setmaxstack(int32_t argc, Janet *argv) {
|
||||||
janet_fixarity(argc, 2);
|
janet_fixarity(argc, 2);
|
||||||
JanetFiber *fiber = janet_getfiber(argv, 0);
|
JanetFiber *fiber = janet_getfiber(argv, 0);
|
||||||
int32_t maxs = janet_getinteger(argv, 1);
|
int32_t maxs = janet_getinteger(argv, 1);
|
||||||
@ -376,9 +378,9 @@ static Janet cfun_setmaxstack(int32_t argc, Janet *argv) {
|
|||||||
return argv[0];
|
return argv[0];
|
||||||
}
|
}
|
||||||
|
|
||||||
static const JanetReg cfuns[] = {
|
static const JanetReg fiber_cfuns[] = {
|
||||||
{
|
{
|
||||||
"fiber/new", cfun_new,
|
"fiber/new", cfun_fiber_new,
|
||||||
JDOC("(fiber/new func [,sigmask])\n\n"
|
JDOC("(fiber/new func [,sigmask])\n\n"
|
||||||
"Create a new fiber with function body func. Can optionally "
|
"Create a new fiber with function body func. Can optionally "
|
||||||
"take a set of signals to block from the current parent fiber "
|
"take a set of signals to block from the current parent fiber "
|
||||||
@ -396,7 +398,7 @@ static const JanetReg cfuns[] = {
|
|||||||
"\t0-9 - block a specific user signal")
|
"\t0-9 - block a specific user signal")
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
"fiber/status", cfun_status,
|
"fiber/status", cfun_fiber_status,
|
||||||
JDOC("(fiber/status fib)\n\n"
|
JDOC("(fiber/status fib)\n\n"
|
||||||
"Get the status of a fiber. The status will be one of:\n\n"
|
"Get the status of a fiber. The status will be one of:\n\n"
|
||||||
"\t:dead - the fiber has finished\n"
|
"\t:dead - the fiber has finished\n"
|
||||||
@ -408,19 +410,19 @@ static const JanetReg cfuns[] = {
|
|||||||
"\t:new - the fiber has just been created and not yet run")
|
"\t:new - the fiber has just been created and not yet run")
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
"fiber/current", cfun_current,
|
"fiber/current", cfun_fiber_current,
|
||||||
JDOC("(fiber/current)\n\n"
|
JDOC("(fiber/current)\n\n"
|
||||||
"Returns the currently running fiber.")
|
"Returns the currently running fiber.")
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
"fiber/maxstack", cfun_maxstack,
|
"fiber/maxstack", cfun_fiber_maxstack,
|
||||||
JDOC("(fiber/maxstack fib)\n\n"
|
JDOC("(fiber/maxstack fib)\n\n"
|
||||||
"Gets the maximum stack size in janet values allowed for a fiber. While memory for "
|
"Gets the maximum stack size in janet values allowed for a fiber. While memory for "
|
||||||
"the fiber's stack is not allocated up front, the fiber will not allocated more "
|
"the fiber's stack is not allocated up front, the fiber will not allocated more "
|
||||||
"than this amount and will throw a stack-overflow error if more memory is needed. ")
|
"than this amount and will throw a stack-overflow error if more memory is needed. ")
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
"fiber/setmaxstack", cfun_setmaxstack,
|
"fiber/setmaxstack", cfun_fiber_setmaxstack,
|
||||||
JDOC("(fiber/setmaxstack fib maxstack)\n\n"
|
JDOC("(fiber/setmaxstack fib maxstack)\n\n"
|
||||||
"Sets the maximum stack size in janet values for a fiber. By default, the "
|
"Sets the maximum stack size in janet values for a fiber. By default, the "
|
||||||
"maximum stack size is usually 8192.")
|
"maximum stack size is usually 8192.")
|
||||||
@ -430,5 +432,5 @@ static const JanetReg cfuns[] = {
|
|||||||
|
|
||||||
/* Module entry point */
|
/* Module entry point */
|
||||||
void janet_lib_fiber(JanetTable *env) {
|
void janet_lib_fiber(JanetTable *env) {
|
||||||
janet_cfuns(env, NULL, cfuns);
|
janet_cfuns(env, NULL, fiber_cfuns);
|
||||||
}
|
}
|
||||||
|
@ -23,7 +23,9 @@
|
|||||||
#ifndef JANET_FIBER_H_defined
|
#ifndef JANET_FIBER_H_defined
|
||||||
#define JANET_FIBER_H_defined
|
#define JANET_FIBER_H_defined
|
||||||
|
|
||||||
|
#ifndef JANET_AMALG
|
||||||
#include <janet/janet.h>
|
#include <janet/janet.h>
|
||||||
|
#endif
|
||||||
|
|
||||||
extern JANET_THREAD_LOCAL JanetFiber *janet_vm_fiber;
|
extern JANET_THREAD_LOCAL JanetFiber *janet_vm_fiber;
|
||||||
|
|
||||||
|
@ -20,10 +20,12 @@
|
|||||||
* IN THE SOFTWARE.
|
* IN THE SOFTWARE.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
#ifndef JANET_AMALG
|
||||||
#include <janet/janet.h>
|
#include <janet/janet.h>
|
||||||
#include "state.h"
|
#include "state.h"
|
||||||
#include "symcache.h"
|
#include "symcache.h"
|
||||||
#include "gc.h"
|
#include "gc.h"
|
||||||
|
#endif
|
||||||
|
|
||||||
/* GC State */
|
/* GC State */
|
||||||
JANET_THREAD_LOCAL void *janet_vm_blocks;
|
JANET_THREAD_LOCAL void *janet_vm_blocks;
|
||||||
|
@ -23,7 +23,9 @@
|
|||||||
#ifndef JANET_GC_H
|
#ifndef JANET_GC_H
|
||||||
#define JANET_GC_H
|
#define JANET_GC_H
|
||||||
|
|
||||||
|
#ifndef JANET_AMALG
|
||||||
#include <janet/janet.h>
|
#include <janet/janet.h>
|
||||||
|
#endif
|
||||||
|
|
||||||
/* The metadata header associated with an allocated block of memory */
|
/* The metadata header associated with an allocated block of memory */
|
||||||
#define janet_gc_header(mem) ((JanetGCMemoryHeader *)(mem) - 1)
|
#define janet_gc_header(mem) ((JanetGCMemoryHeader *)(mem) - 1)
|
||||||
@ -36,7 +38,6 @@
|
|||||||
#define janet_gc_type(m) (janet_gc_header(m)->flags & 0xFF)
|
#define janet_gc_type(m) (janet_gc_header(m)->flags & 0xFF)
|
||||||
|
|
||||||
#define janet_gc_mark(m) (janet_gc_header(m)->flags |= JANET_MEM_REACHABLE)
|
#define janet_gc_mark(m) (janet_gc_header(m)->flags |= JANET_MEM_REACHABLE)
|
||||||
#define janet_gc_unmark(m) (janet_gc_header(m)->flags &= ~JANET_MEM_COLOR)
|
|
||||||
#define janet_gc_reachable(m) (janet_gc_header(m)->flags & JANET_MEM_REACHABLE)
|
#define janet_gc_reachable(m) (janet_gc_header(m)->flags & JANET_MEM_REACHABLE)
|
||||||
|
|
||||||
/* Memory header struct. Node of a linked list of memory blocks. */
|
/* Memory header struct. Node of a linked list of memory blocks. */
|
||||||
|
@ -25,9 +25,12 @@
|
|||||||
#define _BSD_SOURCE
|
#define _BSD_SOURCE
|
||||||
|
|
||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
#include <janet/janet.h>
|
|
||||||
#include <errno.h>
|
#include <errno.h>
|
||||||
|
|
||||||
|
#ifndef JANET_AMALG
|
||||||
|
#include <janet/janet.h>
|
||||||
#include "util.h"
|
#include "util.h"
|
||||||
|
#endif
|
||||||
|
|
||||||
#define IO_WRITE 1
|
#define IO_WRITE 1
|
||||||
#define IO_READ 2
|
#define IO_READ 2
|
||||||
@ -45,11 +48,11 @@ struct IOFile {
|
|||||||
int flags;
|
int flags;
|
||||||
};
|
};
|
||||||
|
|
||||||
static int janet_io_gc(void *p, size_t len);
|
static int cfun_io_gc(void *p, size_t len);
|
||||||
|
|
||||||
JanetAbstractType janet_io_filetype = {
|
JanetAbstractType cfun_io_filetype = {
|
||||||
"core/file",
|
"core/file",
|
||||||
janet_io_gc,
|
cfun_io_gc,
|
||||||
NULL
|
NULL
|
||||||
};
|
};
|
||||||
|
|
||||||
@ -93,7 +96,7 @@ static int checkflags(const uint8_t *str) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
static Janet makef(FILE *f, int flags) {
|
static Janet makef(FILE *f, int flags) {
|
||||||
IOFile *iof = (IOFile *) janet_abstract(&janet_io_filetype, sizeof(IOFile));
|
IOFile *iof = (IOFile *) janet_abstract(&cfun_io_filetype, sizeof(IOFile));
|
||||||
iof->file = f;
|
iof->file = f;
|
||||||
iof->flags = flags;
|
iof->flags = flags;
|
||||||
return janet_wrap_abstract(iof);
|
return janet_wrap_abstract(iof);
|
||||||
@ -101,14 +104,14 @@ static Janet makef(FILE *f, int flags) {
|
|||||||
|
|
||||||
/* Open a process */
|
/* Open a process */
|
||||||
#ifdef __EMSCRIPTEN__
|
#ifdef __EMSCRIPTEN__
|
||||||
static Janet janet_io_popen(int32_t argc, Janet *argv) {
|
static Janet cfun_io_popen(int32_t argc, Janet *argv) {
|
||||||
(void) argc;
|
(void) argc;
|
||||||
(void) argv;
|
(void) argv;
|
||||||
janet_panic("not implemented on this platform");
|
janet_panic("not implemented on this platform");
|
||||||
return janet_wrap_nil();
|
return janet_wrap_nil();
|
||||||
}
|
}
|
||||||
#else
|
#else
|
||||||
static Janet janet_io_popen(int32_t argc, Janet *argv) {
|
static Janet cfun_io_popen(int32_t argc, Janet *argv) {
|
||||||
janet_arity(argc, 1, 2);
|
janet_arity(argc, 1, 2);
|
||||||
const uint8_t *fname = janet_getstring(argv, 0);
|
const uint8_t *fname = janet_getstring(argv, 0);
|
||||||
const uint8_t *fmode = NULL;
|
const uint8_t *fmode = NULL;
|
||||||
@ -135,7 +138,7 @@ static Janet janet_io_popen(int32_t argc, Janet *argv) {
|
|||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
static Janet janet_io_fopen(int32_t argc, Janet *argv) {
|
static Janet cfun_io_fopen(int32_t argc, Janet *argv) {
|
||||||
janet_arity(argc, 1, 2);
|
janet_arity(argc, 1, 2);
|
||||||
const uint8_t *fname = janet_getstring(argv, 0);
|
const uint8_t *fname = janet_getstring(argv, 0);
|
||||||
const uint8_t *fmode;
|
const uint8_t *fmode;
|
||||||
@ -164,9 +167,9 @@ static void read_chunk(IOFile *iof, JanetBuffer *buffer, int32_t nBytesMax) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/* Read a certain number of bytes into memory */
|
/* Read a certain number of bytes into memory */
|
||||||
static Janet janet_io_fread(int32_t argc, Janet *argv) {
|
static Janet cfun_io_fread(int32_t argc, Janet *argv) {
|
||||||
janet_arity(argc, 2, 3);
|
janet_arity(argc, 2, 3);
|
||||||
IOFile *iof = janet_getabstract(argv, 0, &janet_io_filetype);
|
IOFile *iof = janet_getabstract(argv, 0, &cfun_io_filetype);
|
||||||
if (iof->flags & IO_CLOSED) janet_panic("file is closed");
|
if (iof->flags & IO_CLOSED) janet_panic("file is closed");
|
||||||
JanetBuffer *buffer;
|
JanetBuffer *buffer;
|
||||||
if (argc == 2) {
|
if (argc == 2) {
|
||||||
@ -210,9 +213,9 @@ static Janet janet_io_fread(int32_t argc, Janet *argv) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/* Write bytes to a file */
|
/* Write bytes to a file */
|
||||||
static Janet janet_io_fwrite(int32_t argc, Janet *argv) {
|
static Janet cfun_io_fwrite(int32_t argc, Janet *argv) {
|
||||||
janet_arity(argc, 1, -1);
|
janet_arity(argc, 1, -1);
|
||||||
IOFile *iof = janet_getabstract(argv, 0, &janet_io_filetype);
|
IOFile *iof = janet_getabstract(argv, 0, &cfun_io_filetype);
|
||||||
if (iof->flags & IO_CLOSED)
|
if (iof->flags & IO_CLOSED)
|
||||||
janet_panic("file is closed");
|
janet_panic("file is closed");
|
||||||
if (!(iof->flags & (IO_WRITE | IO_APPEND | IO_UPDATE)))
|
if (!(iof->flags & (IO_WRITE | IO_APPEND | IO_UPDATE)))
|
||||||
@ -233,9 +236,9 @@ static Janet janet_io_fwrite(int32_t argc, Janet *argv) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/* Flush the bytes in the file */
|
/* Flush the bytes in the file */
|
||||||
static Janet janet_io_fflush(int32_t argc, Janet *argv) {
|
static Janet cfun_io_fflush(int32_t argc, Janet *argv) {
|
||||||
janet_fixarity(argc, 1);
|
janet_fixarity(argc, 1);
|
||||||
IOFile *iof = janet_getabstract(argv, 0, &janet_io_filetype);
|
IOFile *iof = janet_getabstract(argv, 0, &cfun_io_filetype);
|
||||||
if (iof->flags & IO_CLOSED)
|
if (iof->flags & IO_CLOSED)
|
||||||
janet_panic("file is closed");
|
janet_panic("file is closed");
|
||||||
if (!(iof->flags & (IO_WRITE | IO_APPEND | IO_UPDATE)))
|
if (!(iof->flags & (IO_WRITE | IO_APPEND | IO_UPDATE)))
|
||||||
@ -246,7 +249,7 @@ static Janet janet_io_fflush(int32_t argc, Janet *argv) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/* Cleanup a file */
|
/* Cleanup a file */
|
||||||
static int janet_io_gc(void *p, size_t len) {
|
static int cfun_io_gc(void *p, size_t len) {
|
||||||
(void) len;
|
(void) len;
|
||||||
IOFile *iof = (IOFile *)p;
|
IOFile *iof = (IOFile *)p;
|
||||||
if (!(iof->flags & (IO_NOT_CLOSEABLE | IO_CLOSED))) {
|
if (!(iof->flags & (IO_NOT_CLOSEABLE | IO_CLOSED))) {
|
||||||
@ -256,9 +259,9 @@ static int janet_io_gc(void *p, size_t len) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/* Close a file */
|
/* Close a file */
|
||||||
static Janet janet_io_fclose(int32_t argc, Janet *argv) {
|
static Janet cfun_io_fclose(int32_t argc, Janet *argv) {
|
||||||
janet_fixarity(argc, 1);
|
janet_fixarity(argc, 1);
|
||||||
IOFile *iof = janet_getabstract(argv, 0, &janet_io_filetype);
|
IOFile *iof = janet_getabstract(argv, 0, &cfun_io_filetype);
|
||||||
if (iof->flags & IO_CLOSED)
|
if (iof->flags & IO_CLOSED)
|
||||||
janet_panic("file is closed");
|
janet_panic("file is closed");
|
||||||
if (iof->flags & (IO_NOT_CLOSEABLE))
|
if (iof->flags & (IO_NOT_CLOSEABLE))
|
||||||
@ -276,9 +279,9 @@ static Janet janet_io_fclose(int32_t argc, Janet *argv) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/* Seek a file */
|
/* Seek a file */
|
||||||
static Janet janet_io_fseek(int32_t argc, Janet *argv) {
|
static Janet cfun_io_fseek(int32_t argc, Janet *argv) {
|
||||||
janet_arity(argc, 2, 3);
|
janet_arity(argc, 2, 3);
|
||||||
IOFile *iof = janet_getabstract(argv, 0, &janet_io_filetype);
|
IOFile *iof = janet_getabstract(argv, 0, &cfun_io_filetype);
|
||||||
if (iof->flags & IO_CLOSED)
|
if (iof->flags & IO_CLOSED)
|
||||||
janet_panic("file is closed");
|
janet_panic("file is closed");
|
||||||
long int offset = 0;
|
long int offset = 0;
|
||||||
@ -302,9 +305,9 @@ static Janet janet_io_fseek(int32_t argc, Janet *argv) {
|
|||||||
return argv[0];
|
return argv[0];
|
||||||
}
|
}
|
||||||
|
|
||||||
static const JanetReg cfuns[] = {
|
static const JanetReg io_cfuns[] = {
|
||||||
{
|
{
|
||||||
"file/open", janet_io_fopen,
|
"file/open", cfun_io_fopen,
|
||||||
JDOC("(file/open path [,mode])\n\n"
|
JDOC("(file/open path [,mode])\n\n"
|
||||||
"Open a file. path is an absolute or relative path, and "
|
"Open a file. path is an absolute or relative path, and "
|
||||||
"mode is a set of flags indicating the mode to open the file in. "
|
"mode is a set of flags indicating the mode to open the file in. "
|
||||||
@ -318,14 +321,14 @@ static const JanetReg cfuns[] = {
|
|||||||
"\t+ - append to the file instead of overwriting it")
|
"\t+ - append to the file instead of overwriting it")
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
"file/close", janet_io_fclose,
|
"file/close", cfun_io_fclose,
|
||||||
JDOC("(file/close f)\n\n"
|
JDOC("(file/close f)\n\n"
|
||||||
"Close a file and release all related resources. When you are "
|
"Close a file and release all related resources. When you are "
|
||||||
"done reading a file, close it to prevent a resource leak and let "
|
"done reading a file, close it to prevent a resource leak and let "
|
||||||
"other processes read the file.")
|
"other processes read the file.")
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
"file/read", janet_io_fread,
|
"file/read", cfun_io_fread,
|
||||||
JDOC("(file/read f what [,buf])\n\n"
|
JDOC("(file/read f what [,buf])\n\n"
|
||||||
"Read a number of bytes from a file into a buffer. A buffer can "
|
"Read a number of bytes from a file into a buffer. A buffer can "
|
||||||
"be provided as an optional fourth argument, otherwise a new buffer "
|
"be provided as an optional fourth argument, otherwise a new buffer "
|
||||||
@ -337,19 +340,19 @@ static const JanetReg cfuns[] = {
|
|||||||
"\tn (integer) - read up to n bytes from the file")
|
"\tn (integer) - read up to n bytes from the file")
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
"file/write", janet_io_fwrite,
|
"file/write", cfun_io_fwrite,
|
||||||
JDOC("(file/write f bytes)\n\n"
|
JDOC("(file/write f bytes)\n\n"
|
||||||
"Writes to a file. 'bytes' must be string, buffer, or symbol. Returns the "
|
"Writes to a file. 'bytes' must be string, buffer, or symbol. Returns the "
|
||||||
"file.")
|
"file.")
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
"file/flush", janet_io_fflush,
|
"file/flush", cfun_io_fflush,
|
||||||
JDOC("(file/flush f)\n\n"
|
JDOC("(file/flush f)\n\n"
|
||||||
"Flush any buffered bytes to the file system. In most files, writes are "
|
"Flush any buffered bytes to the file system. In most files, writes are "
|
||||||
"buffered for efficiency reasons. Returns the file handle.")
|
"buffered for efficiency reasons. Returns the file handle.")
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
"file/seek", janet_io_fseek,
|
"file/seek", cfun_io_fseek,
|
||||||
JDOC("(file/seek f [,whence [,n]])\n\n"
|
JDOC("(file/seek f [,whence [,n]])\n\n"
|
||||||
"Jump to a relative location in the file. 'whence' must be one of\n\n"
|
"Jump to a relative location in the file. 'whence' must be one of\n\n"
|
||||||
"\t:cur - jump relative to the current file location\n"
|
"\t:cur - jump relative to the current file location\n"
|
||||||
@ -360,7 +363,7 @@ static const JanetReg cfuns[] = {
|
|||||||
"number to handle large files of more the 4GB. Returns the file handle.")
|
"number to handle large files of more the 4GB. Returns the file handle.")
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
"file/popen", janet_io_popen,
|
"file/popen", cfun_io_popen,
|
||||||
JDOC("(file/popen path [,mode])\n\n"
|
JDOC("(file/popen path [,mode])\n\n"
|
||||||
"Open a file that is backed by a process. The file must be opened in either "
|
"Open a file that is backed by a process. The file must be opened in either "
|
||||||
"the :r (read) or the :w (write) mode. In :r mode, the stdout of the "
|
"the :r (read) or the :w (write) mode. In :r mode, the stdout of the "
|
||||||
@ -372,7 +375,8 @@ static const JanetReg cfuns[] = {
|
|||||||
|
|
||||||
/* Module entry point */
|
/* Module entry point */
|
||||||
void janet_lib_io(JanetTable *env) {
|
void janet_lib_io(JanetTable *env) {
|
||||||
janet_cfuns(env, NULL, cfuns);
|
janet_cfuns(env, NULL, io_cfuns);
|
||||||
|
|
||||||
/* stdout */
|
/* stdout */
|
||||||
janet_def(env, "stdout",
|
janet_def(env, "stdout",
|
||||||
makef(stdout, IO_APPEND | IO_NOT_CLOSEABLE | IO_SERIALIZABLE),
|
makef(stdout, IO_APPEND | IO_NOT_CLOSEABLE | IO_SERIALIZABLE),
|
||||||
|
@ -20,13 +20,14 @@
|
|||||||
* IN THE SOFTWARE.
|
* IN THE SOFTWARE.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
#ifndef JANET_AMALG
|
||||||
#include <janet/janet.h>
|
#include <janet/janet.h>
|
||||||
|
|
||||||
#include "state.h"
|
#include "state.h"
|
||||||
#include "vector.h"
|
#include "vector.h"
|
||||||
#include "gc.h"
|
#include "gc.h"
|
||||||
#include "fiber.h"
|
#include "fiber.h"
|
||||||
#include "util.h"
|
#include "util.h"
|
||||||
|
#endif
|
||||||
|
|
||||||
typedef struct {
|
typedef struct {
|
||||||
jmp_buf err;
|
jmp_buf err;
|
||||||
@ -1144,7 +1145,7 @@ static Janet cfun_unmarshal(int32_t argc, Janet *argv) {
|
|||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
static const JanetReg cfuns[] = {
|
static const JanetReg marsh_cfuns[] = {
|
||||||
{
|
{
|
||||||
"marshal", cfun_marshal,
|
"marshal", cfun_marshal,
|
||||||
JDOC("(marshal x [,reverse-lookup [,buffer]])\n\n"
|
JDOC("(marshal x [,reverse-lookup [,buffer]])\n\n"
|
||||||
@ -1174,5 +1175,5 @@ static const JanetReg cfuns[] = {
|
|||||||
|
|
||||||
/* Module entry point */
|
/* Module entry point */
|
||||||
void janet_lib_marsh(JanetTable *env) {
|
void janet_lib_marsh(JanetTable *env) {
|
||||||
janet_cfuns(env, NULL, cfuns);
|
janet_cfuns(env, NULL, marsh_cfuns);
|
||||||
}
|
}
|
||||||
|
@ -20,9 +20,12 @@
|
|||||||
* IN THE SOFTWARE.
|
* IN THE SOFTWARE.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#include <janet/janet.h>
|
|
||||||
#include <math.h>
|
#include <math.h>
|
||||||
|
|
||||||
|
#ifndef JANET_AMALG
|
||||||
|
#include <janet/janet.h>
|
||||||
#include "util.h"
|
#include "util.h"
|
||||||
|
#endif
|
||||||
|
|
||||||
/* Get a random number */
|
/* Get a random number */
|
||||||
Janet janet_rand(int32_t argc, Janet *argv) {
|
Janet janet_rand(int32_t argc, Janet *argv) {
|
||||||
@ -87,7 +90,7 @@ static Janet janet_not(int32_t argc, Janet *argv) {
|
|||||||
return janet_wrap_boolean(!janet_truthy(argv[0]));
|
return janet_wrap_boolean(!janet_truthy(argv[0]));
|
||||||
}
|
}
|
||||||
|
|
||||||
static const JanetReg cfuns[] = {
|
static const JanetReg math_cfuns[] = {
|
||||||
{
|
{
|
||||||
"%", janet_remainder,
|
"%", janet_remainder,
|
||||||
JDOC("(% dividend divisor)\n\n"
|
JDOC("(% dividend divisor)\n\n"
|
||||||
@ -178,7 +181,7 @@ static const JanetReg cfuns[] = {
|
|||||||
|
|
||||||
/* Module entry point */
|
/* Module entry point */
|
||||||
void janet_lib_math(JanetTable *env) {
|
void janet_lib_math(JanetTable *env) {
|
||||||
janet_cfuns(env, NULL, cfuns);
|
janet_cfuns(env, NULL, math_cfuns);
|
||||||
#ifndef JANET_NO_BOOTSTRAP
|
#ifndef JANET_NO_BOOTSTRAP
|
||||||
janet_def(env, "math/pi", janet_wrap_number(3.1415926535897931),
|
janet_def(env, "math/pi", janet_wrap_number(3.1415926535897931),
|
||||||
JDOC("The value pi."));
|
JDOC("The value pi."));
|
||||||
|
@ -20,10 +20,13 @@
|
|||||||
* IN THE SOFTWARE.
|
* IN THE SOFTWARE.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
#ifndef JANET_AMALG
|
||||||
#include <janet/janet.h>
|
#include <janet/janet.h>
|
||||||
|
#include "util.h"
|
||||||
|
#endif
|
||||||
|
|
||||||
#include <stdlib.h>
|
#include <stdlib.h>
|
||||||
#include <time.h>
|
#include <time.h>
|
||||||
#include "util.h"
|
|
||||||
|
|
||||||
#ifdef JANET_WINDOWS
|
#ifdef JANET_WINDOWS
|
||||||
#include <Windows.h>
|
#include <Windows.h>
|
||||||
@ -296,7 +299,7 @@ static Janet os_date(int32_t argc, Janet *argv) {
|
|||||||
return janet_wrap_struct(janet_struct_end(st));
|
return janet_wrap_struct(janet_struct_end(st));
|
||||||
}
|
}
|
||||||
|
|
||||||
static const JanetReg cfuns[] = {
|
static const JanetReg os_cfuns[] = {
|
||||||
{
|
{
|
||||||
"os/which", os_which,
|
"os/which", os_which,
|
||||||
JDOC("(os/which)\n\n"
|
JDOC("(os/which)\n\n"
|
||||||
@ -375,5 +378,5 @@ static const JanetReg cfuns[] = {
|
|||||||
|
|
||||||
/* Module entry point */
|
/* Module entry point */
|
||||||
void janet_lib_os(JanetTable *env) {
|
void janet_lib_os(JanetTable *env) {
|
||||||
janet_cfuns(env, NULL, cfuns);
|
janet_cfuns(env, NULL, os_cfuns);
|
||||||
}
|
}
|
||||||
|
@ -20,8 +20,10 @@
|
|||||||
* IN THE SOFTWARE.
|
* IN THE SOFTWARE.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
#ifndef JANET_AMALG
|
||||||
#include <janet/janet.h>
|
#include <janet/janet.h>
|
||||||
#include "util.h"
|
#include "util.h"
|
||||||
|
#endif
|
||||||
|
|
||||||
/* Check if a character is whitespace */
|
/* Check if a character is whitespace */
|
||||||
static int is_whitespace(uint8_t c) {
|
static int is_whitespace(uint8_t c) {
|
||||||
@ -614,7 +616,7 @@ static JanetAbstractType janet_parse_parsertype = {
|
|||||||
};
|
};
|
||||||
|
|
||||||
/* C Function parser */
|
/* C Function parser */
|
||||||
static Janet cfun_parser(int32_t argc, Janet *argv) {
|
static Janet cfun_parse_parser(int32_t argc, Janet *argv) {
|
||||||
(void) argv;
|
(void) argv;
|
||||||
janet_fixarity(argc, 0);
|
janet_fixarity(argc, 0);
|
||||||
JanetParser *p = janet_abstract(&janet_parse_parsertype, sizeof(JanetParser));
|
JanetParser *p = janet_abstract(&janet_parse_parsertype, sizeof(JanetParser));
|
||||||
@ -622,7 +624,7 @@ static Janet cfun_parser(int32_t argc, Janet *argv) {
|
|||||||
return janet_wrap_abstract(p);
|
return janet_wrap_abstract(p);
|
||||||
}
|
}
|
||||||
|
|
||||||
static Janet cfun_consume(int32_t argc, Janet *argv) {
|
static Janet cfun_parse_consume(int32_t argc, Janet *argv) {
|
||||||
janet_arity(argc, 2, 3);
|
janet_arity(argc, 2, 3);
|
||||||
JanetParser *p = janet_getabstract(argv, 0, &janet_parse_parsertype);
|
JanetParser *p = janet_getabstract(argv, 0, &janet_parse_parsertype);
|
||||||
JanetByteView view = janet_getbytes(argv, 1);
|
JanetByteView view = janet_getbytes(argv, 1);
|
||||||
@ -647,13 +649,13 @@ static Janet cfun_consume(int32_t argc, Janet *argv) {
|
|||||||
return janet_wrap_integer(i);
|
return janet_wrap_integer(i);
|
||||||
}
|
}
|
||||||
|
|
||||||
static Janet cfun_has_more(int32_t argc, Janet *argv) {
|
static Janet cfun_parse_has_more(int32_t argc, Janet *argv) {
|
||||||
janet_fixarity(argc, 1);
|
janet_fixarity(argc, 1);
|
||||||
JanetParser *p = janet_getabstract(argv, 0, &janet_parse_parsertype);
|
JanetParser *p = janet_getabstract(argv, 0, &janet_parse_parsertype);
|
||||||
return janet_wrap_boolean(janet_parser_has_more(p));
|
return janet_wrap_boolean(janet_parser_has_more(p));
|
||||||
}
|
}
|
||||||
|
|
||||||
static Janet cfun_byte(int32_t argc, Janet *argv) {
|
static Janet cfun_parse_byte(int32_t argc, Janet *argv) {
|
||||||
janet_fixarity(argc, 2);
|
janet_fixarity(argc, 2);
|
||||||
JanetParser *p = janet_getabstract(argv, 0, &janet_parse_parsertype);
|
JanetParser *p = janet_getabstract(argv, 0, &janet_parse_parsertype);
|
||||||
int32_t i = janet_getinteger(argv, 1);
|
int32_t i = janet_getinteger(argv, 1);
|
||||||
@ -661,7 +663,7 @@ static Janet cfun_byte(int32_t argc, Janet *argv) {
|
|||||||
return argv[0];
|
return argv[0];
|
||||||
}
|
}
|
||||||
|
|
||||||
static Janet cfun_status(int32_t argc, Janet *argv) {
|
static Janet cfun_parse_status(int32_t argc, Janet *argv) {
|
||||||
janet_fixarity(argc, 1);
|
janet_fixarity(argc, 1);
|
||||||
JanetParser *p = janet_getabstract(argv, 0, &janet_parse_parsertype);
|
JanetParser *p = janet_getabstract(argv, 0, &janet_parse_parsertype);
|
||||||
const char *stat = NULL;
|
const char *stat = NULL;
|
||||||
@ -679,7 +681,7 @@ static Janet cfun_status(int32_t argc, Janet *argv) {
|
|||||||
return janet_ckeywordv(stat);
|
return janet_ckeywordv(stat);
|
||||||
}
|
}
|
||||||
|
|
||||||
static Janet cfun_error(int32_t argc, Janet *argv) {
|
static Janet cfun_parse_error(int32_t argc, Janet *argv) {
|
||||||
janet_fixarity(argc, 1);
|
janet_fixarity(argc, 1);
|
||||||
JanetParser *p = janet_getabstract(argv, 0, &janet_parse_parsertype);
|
JanetParser *p = janet_getabstract(argv, 0, &janet_parse_parsertype);
|
||||||
const char *err = janet_parser_error(p);
|
const char *err = janet_parser_error(p);
|
||||||
@ -687,26 +689,26 @@ static Janet cfun_error(int32_t argc, Janet *argv) {
|
|||||||
return janet_wrap_nil();
|
return janet_wrap_nil();
|
||||||
}
|
}
|
||||||
|
|
||||||
static Janet cfun_produce(int32_t argc, Janet *argv) {
|
static Janet cfun_parse_produce(int32_t argc, Janet *argv) {
|
||||||
janet_fixarity(argc, 1);
|
janet_fixarity(argc, 1);
|
||||||
JanetParser *p = janet_getabstract(argv, 0, &janet_parse_parsertype);
|
JanetParser *p = janet_getabstract(argv, 0, &janet_parse_parsertype);
|
||||||
return janet_parser_produce(p);
|
return janet_parser_produce(p);
|
||||||
}
|
}
|
||||||
|
|
||||||
static Janet cfun_flush(int32_t argc, Janet *argv) {
|
static Janet cfun_parse_flush(int32_t argc, Janet *argv) {
|
||||||
janet_fixarity(argc, 1);
|
janet_fixarity(argc, 1);
|
||||||
JanetParser *p = janet_getabstract(argv, 0, &janet_parse_parsertype);
|
JanetParser *p = janet_getabstract(argv, 0, &janet_parse_parsertype);
|
||||||
janet_parser_flush(p);
|
janet_parser_flush(p);
|
||||||
return argv[0];
|
return argv[0];
|
||||||
}
|
}
|
||||||
|
|
||||||
static Janet cfun_where(int32_t argc, Janet *argv) {
|
static Janet cfun_parse_where(int32_t argc, Janet *argv) {
|
||||||
janet_fixarity(argc, 1);
|
janet_fixarity(argc, 1);
|
||||||
JanetParser *p = janet_getabstract(argv, 0, &janet_parse_parsertype);
|
JanetParser *p = janet_getabstract(argv, 0, &janet_parse_parsertype);
|
||||||
return janet_wrap_integer(p->offset);
|
return janet_wrap_integer(p->offset);
|
||||||
}
|
}
|
||||||
|
|
||||||
static Janet cfun_state(int32_t argc, Janet *argv) {
|
static Janet cfun_parse_state(int32_t argc, Janet *argv) {
|
||||||
size_t i;
|
size_t i;
|
||||||
const uint8_t *str;
|
const uint8_t *str;
|
||||||
size_t oldcount;
|
size_t oldcount;
|
||||||
@ -735,39 +737,39 @@ static Janet cfun_state(int32_t argc, Janet *argv) {
|
|||||||
return janet_wrap_string(str);
|
return janet_wrap_string(str);
|
||||||
}
|
}
|
||||||
|
|
||||||
static const JanetReg cfuns[] = {
|
static const JanetReg parse_cfuns[] = {
|
||||||
{
|
{
|
||||||
"parser/new", cfun_parser,
|
"parser/new", cfun_parse_parser,
|
||||||
JDOC("(parser/new)\n\n"
|
JDOC("(parser/new)\n\n"
|
||||||
"Creates and returns a new parser object. Parsers are state machines "
|
"Creates and returns a new parser object. Parsers are state machines "
|
||||||
"that can receive bytes, and generate a stream of janet values. ")
|
"that can receive bytes, and generate a stream of janet values. ")
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
"parser/has-more", cfun_has_more,
|
"parser/has-more", cfun_parse_has_more,
|
||||||
JDOC("(parser/has-more parser)\n\n"
|
JDOC("(parser/has-more parser)\n\n"
|
||||||
"Check if the parser has more values in the value queue.")
|
"Check if the parser has more values in the value queue.")
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
"parser/produce", cfun_produce,
|
"parser/produce", cfun_parse_produce,
|
||||||
JDOC("(parser/produce parser)\n\n"
|
JDOC("(parser/produce parser)\n\n"
|
||||||
"Dequeue the next value in the parse queue. Will return nil if "
|
"Dequeue the next value in the parse queue. Will return nil if "
|
||||||
"no parsed values are in the queue, otherwise will dequeue the "
|
"no parsed values are in the queue, otherwise will dequeue the "
|
||||||
"next value.")
|
"next value.")
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
"parser/consume", cfun_consume,
|
"parser/consume", cfun_parse_consume,
|
||||||
JDOC("(parser/consume parser bytes [, index])\n\n"
|
JDOC("(parser/consume parser bytes [, index])\n\n"
|
||||||
"Input bytes into the parser and parse them. Will not throw errors "
|
"Input bytes into the parser and parse them. Will not throw errors "
|
||||||
"if there is a parse error. Starts at the byte index given by index. Returns "
|
"if there is a parse error. Starts at the byte index given by index. Returns "
|
||||||
"the number of bytes read.")
|
"the number of bytes read.")
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
"parser/byte", cfun_byte,
|
"parser/byte", cfun_parse_byte,
|
||||||
JDOC("(parser/byte parser b)\n\n"
|
JDOC("(parser/byte parser b)\n\n"
|
||||||
"Input a single byte into the parser byte stream. Returns the parser.")
|
"Input a single byte into the parser byte stream. Returns the parser.")
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
"parser/error", cfun_error,
|
"parser/error", cfun_parse_error,
|
||||||
JDOC("(parser/error parser)\n\n"
|
JDOC("(parser/error parser)\n\n"
|
||||||
"If the parser is in the error state, returns the message associated with "
|
"If the parser is in the error state, returns the message associated with "
|
||||||
"that error. Otherwise, returns nil. Also flushes the parser state and parser "
|
"that error. Otherwise, returns nil. Also flushes the parser state and parser "
|
||||||
@ -775,7 +777,7 @@ static const JanetReg cfuns[] = {
|
|||||||
"parser/error.")
|
"parser/error.")
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
"parser/status", cfun_status,
|
"parser/status", cfun_parse_status,
|
||||||
JDOC("(parser/status parser)\n\n"
|
JDOC("(parser/status parser)\n\n"
|
||||||
"Gets the current status of the parser state machine. The status will "
|
"Gets the current status of the parser state machine. The status will "
|
||||||
"be one of:\n\n"
|
"be one of:\n\n"
|
||||||
@ -784,14 +786,14 @@ static const JanetReg cfuns[] = {
|
|||||||
"\t:root - the parser can either read more values or safely terminate.")
|
"\t:root - the parser can either read more values or safely terminate.")
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
"parser/flush", cfun_flush,
|
"parser/flush", cfun_parse_flush,
|
||||||
JDOC("(parser/flush parser)\n\n"
|
JDOC("(parser/flush parser)\n\n"
|
||||||
"Clears the parser state and parse queue. Can be used to reset the parser "
|
"Clears the parser state and parse queue. Can be used to reset the parser "
|
||||||
"if an error was encountered. Does not reset the line and column counter, so "
|
"if an error was encountered. Does not reset the line and column counter, so "
|
||||||
"to begin parsing in a new context, create a new parser.")
|
"to begin parsing in a new context, create a new parser.")
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
"parser/state", cfun_state,
|
"parser/state", cfun_parse_state,
|
||||||
JDOC("(parser/state parser)\n\n"
|
JDOC("(parser/state parser)\n\n"
|
||||||
"Returns a string representation of the internal state of the parser. "
|
"Returns a string representation of the internal state of the parser. "
|
||||||
"Each byte in the string represents a nested data structure. For example, "
|
"Each byte in the string represents a nested data structure. For example, "
|
||||||
@ -799,7 +801,7 @@ static const JanetReg cfuns[] = {
|
|||||||
"string inside of square brackets inside parentheses. Can be used to augment a REPL prompt.")
|
"string inside of square brackets inside parentheses. Can be used to augment a REPL prompt.")
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
"parser/where", cfun_where,
|
"parser/where", cfun_parse_where,
|
||||||
JDOC("(parser/where parser)\n\n"
|
JDOC("(parser/where parser)\n\n"
|
||||||
"Returns the current line number and column number of the parser's location "
|
"Returns the current line number and column number of the parser's location "
|
||||||
"in the byte stream as a tuple (line, column). Lines and columns are counted from "
|
"in the byte stream as a tuple (line, column). Lines and columns are counted from "
|
||||||
@ -810,5 +812,5 @@ static const JanetReg cfuns[] = {
|
|||||||
|
|
||||||
/* Load the library */
|
/* Load the library */
|
||||||
void janet_lib_parse(JanetTable *env) {
|
void janet_lib_parse(JanetTable *env) {
|
||||||
janet_cfuns(env, NULL, cfuns);
|
janet_cfuns(env, NULL, parse_cfuns);
|
||||||
}
|
}
|
||||||
|
@ -20,11 +20,13 @@
|
|||||||
* IN THE SOFTWARE.
|
* IN THE SOFTWARE.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
#ifndef JANET_AMALG
|
||||||
#include <janet/janet.h>
|
#include <janet/janet.h>
|
||||||
#include <string.h>
|
#include <string.h>
|
||||||
#include "util.h"
|
#include "util.h"
|
||||||
#include "vector.h"
|
#include "vector.h"
|
||||||
#include "util.h"
|
#include "util.h"
|
||||||
|
#endif
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Runtime
|
* Runtime
|
||||||
@ -1043,13 +1045,13 @@ static Peg *compile_peg(Janet x) {
|
|||||||
* C Functions
|
* C Functions
|
||||||
*/
|
*/
|
||||||
|
|
||||||
static Janet cfun_compile(int32_t argc, Janet *argv) {
|
static Janet cfun_peg_compile(int32_t argc, Janet *argv) {
|
||||||
janet_fixarity(argc, 1);
|
janet_fixarity(argc, 1);
|
||||||
Peg *peg = compile_peg(argv[0]);
|
Peg *peg = compile_peg(argv[0]);
|
||||||
return janet_wrap_abstract(peg);
|
return janet_wrap_abstract(peg);
|
||||||
}
|
}
|
||||||
|
|
||||||
static Janet cfun_match(int32_t argc, Janet *argv) {
|
static Janet cfun_peg_match(int32_t argc, Janet *argv) {
|
||||||
janet_arity(argc, 2, -1);
|
janet_arity(argc, 2, -1);
|
||||||
Peg *peg;
|
Peg *peg;
|
||||||
if (janet_checktype(argv[0], JANET_ABSTRACT) &&
|
if (janet_checktype(argv[0], JANET_ABSTRACT) &&
|
||||||
@ -1084,13 +1086,13 @@ static Janet cfun_match(int32_t argc, Janet *argv) {
|
|||||||
return result ? janet_wrap_array(s.captures) : janet_wrap_nil();
|
return result ? janet_wrap_array(s.captures) : janet_wrap_nil();
|
||||||
}
|
}
|
||||||
|
|
||||||
static const JanetReg cfuns[] = {
|
static const JanetReg peg_cfuns[] = {
|
||||||
{"peg/compile", cfun_compile,
|
{"peg/compile", cfun_peg_compile,
|
||||||
JDOC("(peg/compile peg)\n\n"
|
JDOC("(peg/compile peg)\n\n"
|
||||||
"Compiles a peg source data structure into a <core/peg>. This will speed up matching "
|
"Compiles a peg source data structure into a <core/peg>. This will speed up matching "
|
||||||
"if the same peg will be used multiple times.")
|
"if the same peg will be used multiple times.")
|
||||||
},
|
},
|
||||||
{"peg/match", cfun_match,
|
{"peg/match", cfun_peg_match,
|
||||||
JDOC("(peg/match peg text [,start=0])\n\n"
|
JDOC("(peg/match peg text [,start=0])\n\n"
|
||||||
"Match a Parsing Expression Grammar to a byte string and return an array of captured values. "
|
"Match a Parsing Expression Grammar to a byte string and return an array of captured values. "
|
||||||
"Returns nil if text does not match the language defined by peg. The syntax of PEGs are very "
|
"Returns nil if text does not match the language defined by peg. The syntax of PEGs are very "
|
||||||
@ -1101,5 +1103,5 @@ static const JanetReg cfuns[] = {
|
|||||||
|
|
||||||
/* Load the peg module */
|
/* Load the peg module */
|
||||||
void janet_lib_peg(JanetTable *env) {
|
void janet_lib_peg(JanetTable *env) {
|
||||||
janet_cfuns(env, NULL, cfuns);
|
janet_cfuns(env, NULL, peg_cfuns);
|
||||||
}
|
}
|
||||||
|
@ -20,9 +20,11 @@
|
|||||||
* IN THE SOFTWARE.
|
* IN THE SOFTWARE.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
#ifndef JANET_AMALG
|
||||||
#include <janet/janet.h>
|
#include <janet/janet.h>
|
||||||
#include "util.h"
|
#include "util.h"
|
||||||
#include "state.h"
|
#include "state.h"
|
||||||
|
#endif
|
||||||
|
|
||||||
/* Implements a pretty printer for Janet. The pretty printer
|
/* Implements a pretty printer for Janet. The pretty printer
|
||||||
* is farily simple and not that flexible, but fast. */
|
* is farily simple and not that flexible, but fast. */
|
||||||
|
@ -20,8 +20,10 @@
|
|||||||
* IN THE SOFTWARE.
|
* IN THE SOFTWARE.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
#ifndef JANET_AMALG
|
||||||
#include <janet/janet.h>
|
#include <janet/janet.h>
|
||||||
#include "regalloc.h"
|
#include "regalloc.h"
|
||||||
|
#endif
|
||||||
|
|
||||||
void janetc_regalloc_init(JanetcRegisterAllocator *ra) {
|
void janetc_regalloc_init(JanetcRegisterAllocator *ra) {
|
||||||
ra->chunks = NULL;
|
ra->chunks = NULL;
|
||||||
|
@ -20,9 +20,11 @@
|
|||||||
* IN THE SOFTWARE.
|
* IN THE SOFTWARE.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
#ifndef JANET_AMALG
|
||||||
#include <janet/janet.h>
|
#include <janet/janet.h>
|
||||||
#include "state.h"
|
#include "state.h"
|
||||||
#include "vector.h"
|
#include "vector.h"
|
||||||
|
#endif
|
||||||
|
|
||||||
/* Error reporting */
|
/* Error reporting */
|
||||||
void janet_stacktrace(JanetFiber *fiber, const char *errtype, Janet err) {
|
void janet_stacktrace(JanetFiber *fiber, const char *errtype, Janet err) {
|
||||||
|
@ -20,11 +20,13 @@
|
|||||||
* IN THE SOFTWARE.
|
* IN THE SOFTWARE.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
#ifndef JANET_AMALG
|
||||||
#include <janet/janet.h>
|
#include <janet/janet.h>
|
||||||
#include "compile.h"
|
#include "compile.h"
|
||||||
#include "util.h"
|
#include "util.h"
|
||||||
#include "vector.h"
|
#include "vector.h"
|
||||||
#include "emit.h"
|
#include "emit.h"
|
||||||
|
#endif
|
||||||
|
|
||||||
static JanetSlot janetc_quote(JanetFopts opts, int32_t argn, const Janet *argv) {
|
static JanetSlot janetc_quote(JanetFopts opts, int32_t argn, const Janet *argv) {
|
||||||
if (argn != 1) {
|
if (argn != 1) {
|
||||||
|
@ -20,11 +20,14 @@
|
|||||||
* IN THE SOFTWARE.
|
* IN THE SOFTWARE.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#include <janet/janet.h>
|
|
||||||
#include <string.h>
|
#include <string.h>
|
||||||
|
|
||||||
|
#ifndef JANET_AMALG
|
||||||
|
#include <janet/janet.h>
|
||||||
#include "gc.h"
|
#include "gc.h"
|
||||||
#include "util.h"
|
#include "util.h"
|
||||||
#include "state.h"
|
#include "state.h"
|
||||||
|
#endif
|
||||||
|
|
||||||
/* Begin building a string */
|
/* Begin building a string */
|
||||||
uint8_t *janet_string_begin(int32_t length) {
|
uint8_t *janet_string_begin(int32_t length) {
|
||||||
@ -164,13 +167,13 @@ static int32_t kmp_next(struct kmp_state *state) {
|
|||||||
|
|
||||||
/* CFuns */
|
/* CFuns */
|
||||||
|
|
||||||
static Janet cfun_slice(int32_t argc, Janet *argv) {
|
static Janet cfun_string_slice(int32_t argc, Janet *argv) {
|
||||||
JanetRange range = janet_getslice(argc, argv);
|
JanetRange range = janet_getslice(argc, argv);
|
||||||
JanetByteView view = janet_getbytes(argv, 0);
|
JanetByteView view = janet_getbytes(argv, 0);
|
||||||
return janet_stringv(view.bytes + range.start, range.end - range.start);
|
return janet_stringv(view.bytes + range.start, range.end - range.start);
|
||||||
}
|
}
|
||||||
|
|
||||||
static Janet cfun_repeat(int32_t argc, Janet *argv) {
|
static Janet cfun_string_repeat(int32_t argc, Janet *argv) {
|
||||||
janet_fixarity(argc, 2);
|
janet_fixarity(argc, 2);
|
||||||
JanetByteView view = janet_getbytes(argv, 0);
|
JanetByteView view = janet_getbytes(argv, 0);
|
||||||
int32_t rep = janet_getinteger(argv, 1);
|
int32_t rep = janet_getinteger(argv, 1);
|
||||||
@ -187,7 +190,7 @@ static Janet cfun_repeat(int32_t argc, Janet *argv) {
|
|||||||
return janet_wrap_string(janet_string_end(newbuf));
|
return janet_wrap_string(janet_string_end(newbuf));
|
||||||
}
|
}
|
||||||
|
|
||||||
static Janet cfun_bytes(int32_t argc, Janet *argv) {
|
static Janet cfun_string_bytes(int32_t argc, Janet *argv) {
|
||||||
janet_fixarity(argc, 1);
|
janet_fixarity(argc, 1);
|
||||||
JanetByteView view = janet_getbytes(argv, 0);
|
JanetByteView view = janet_getbytes(argv, 0);
|
||||||
Janet *tup = janet_tuple_begin(view.len);
|
Janet *tup = janet_tuple_begin(view.len);
|
||||||
@ -198,7 +201,7 @@ static Janet cfun_bytes(int32_t argc, Janet *argv) {
|
|||||||
return janet_wrap_tuple(janet_tuple_end(tup));
|
return janet_wrap_tuple(janet_tuple_end(tup));
|
||||||
}
|
}
|
||||||
|
|
||||||
static Janet cfun_frombytes(int32_t argc, Janet *argv) {
|
static Janet cfun_string_frombytes(int32_t argc, Janet *argv) {
|
||||||
int32_t i;
|
int32_t i;
|
||||||
uint8_t *buf = janet_string_begin(argc);
|
uint8_t *buf = janet_string_begin(argc);
|
||||||
for (i = 0; i < argc; i++) {
|
for (i = 0; i < argc; i++) {
|
||||||
@ -208,7 +211,7 @@ static Janet cfun_frombytes(int32_t argc, Janet *argv) {
|
|||||||
return janet_wrap_string(janet_string_end(buf));
|
return janet_wrap_string(janet_string_end(buf));
|
||||||
}
|
}
|
||||||
|
|
||||||
static Janet cfun_asciilower(int32_t argc, Janet *argv) {
|
static Janet cfun_string_asciilower(int32_t argc, Janet *argv) {
|
||||||
janet_fixarity(argc, 1);
|
janet_fixarity(argc, 1);
|
||||||
JanetByteView view = janet_getbytes(argv, 0);
|
JanetByteView view = janet_getbytes(argv, 0);
|
||||||
uint8_t *buf = janet_string_begin(view.len);
|
uint8_t *buf = janet_string_begin(view.len);
|
||||||
@ -223,7 +226,7 @@ static Janet cfun_asciilower(int32_t argc, Janet *argv) {
|
|||||||
return janet_wrap_string(janet_string_end(buf));
|
return janet_wrap_string(janet_string_end(buf));
|
||||||
}
|
}
|
||||||
|
|
||||||
static Janet cfun_asciiupper(int32_t argc, Janet *argv) {
|
static Janet cfun_string_asciiupper(int32_t argc, Janet *argv) {
|
||||||
janet_fixarity(argc, 1);
|
janet_fixarity(argc, 1);
|
||||||
JanetByteView view = janet_getbytes(argv, 0);
|
JanetByteView view = janet_getbytes(argv, 0);
|
||||||
uint8_t *buf = janet_string_begin(view.len);
|
uint8_t *buf = janet_string_begin(view.len);
|
||||||
@ -238,7 +241,7 @@ static Janet cfun_asciiupper(int32_t argc, Janet *argv) {
|
|||||||
return janet_wrap_string(janet_string_end(buf));
|
return janet_wrap_string(janet_string_end(buf));
|
||||||
}
|
}
|
||||||
|
|
||||||
static Janet cfun_reverse(int32_t argc, Janet *argv) {
|
static Janet cfun_string_reverse(int32_t argc, Janet *argv) {
|
||||||
janet_fixarity(argc, 1);
|
janet_fixarity(argc, 1);
|
||||||
JanetByteView view = janet_getbytes(argv, 0);
|
JanetByteView view = janet_getbytes(argv, 0);
|
||||||
uint8_t *buf = janet_string_begin(view.len);
|
uint8_t *buf = janet_string_begin(view.len);
|
||||||
@ -262,7 +265,7 @@ static void findsetup(int32_t argc, Janet *argv, struct kmp_state *s, int32_t ex
|
|||||||
s->i = start;
|
s->i = start;
|
||||||
}
|
}
|
||||||
|
|
||||||
static Janet cfun_find(int32_t argc, Janet *argv) {
|
static Janet cfun_string_find(int32_t argc, Janet *argv) {
|
||||||
int32_t result;
|
int32_t result;
|
||||||
struct kmp_state state;
|
struct kmp_state state;
|
||||||
findsetup(argc, argv, &state, 0);
|
findsetup(argc, argv, &state, 0);
|
||||||
@ -273,7 +276,7 @@ static Janet cfun_find(int32_t argc, Janet *argv) {
|
|||||||
: janet_wrap_integer(result);
|
: janet_wrap_integer(result);
|
||||||
}
|
}
|
||||||
|
|
||||||
static Janet cfun_findall(int32_t argc, Janet *argv) {
|
static Janet cfun_string_findall(int32_t argc, Janet *argv) {
|
||||||
int32_t result;
|
int32_t result;
|
||||||
struct kmp_state state;
|
struct kmp_state state;
|
||||||
findsetup(argc, argv, &state, 0);
|
findsetup(argc, argv, &state, 0);
|
||||||
@ -307,7 +310,7 @@ static void replacesetup(int32_t argc, Janet *argv, struct replace_state *s) {
|
|||||||
s->substlen = subst.len;
|
s->substlen = subst.len;
|
||||||
}
|
}
|
||||||
|
|
||||||
static Janet cfun_replace(int32_t argc, Janet *argv) {
|
static Janet cfun_string_replace(int32_t argc, Janet *argv) {
|
||||||
int32_t result;
|
int32_t result;
|
||||||
struct replace_state s;
|
struct replace_state s;
|
||||||
uint8_t *buf;
|
uint8_t *buf;
|
||||||
@ -327,7 +330,7 @@ static Janet cfun_replace(int32_t argc, Janet *argv) {
|
|||||||
return janet_wrap_string(janet_string_end(buf));
|
return janet_wrap_string(janet_string_end(buf));
|
||||||
}
|
}
|
||||||
|
|
||||||
static Janet cfun_replaceall(int32_t argc, Janet *argv) {
|
static Janet cfun_string_replaceall(int32_t argc, Janet *argv) {
|
||||||
int32_t result;
|
int32_t result;
|
||||||
struct replace_state s;
|
struct replace_state s;
|
||||||
JanetBuffer b;
|
JanetBuffer b;
|
||||||
@ -347,7 +350,7 @@ static Janet cfun_replaceall(int32_t argc, Janet *argv) {
|
|||||||
return janet_wrap_string(ret);
|
return janet_wrap_string(ret);
|
||||||
}
|
}
|
||||||
|
|
||||||
static Janet cfun_split(int32_t argc, Janet *argv) {
|
static Janet cfun_string_split(int32_t argc, Janet *argv) {
|
||||||
int32_t result;
|
int32_t result;
|
||||||
JanetArray *array;
|
JanetArray *array;
|
||||||
struct kmp_state state;
|
struct kmp_state state;
|
||||||
@ -370,7 +373,7 @@ static Janet cfun_split(int32_t argc, Janet *argv) {
|
|||||||
return janet_wrap_array(array);
|
return janet_wrap_array(array);
|
||||||
}
|
}
|
||||||
|
|
||||||
static Janet cfun_checkset(int32_t argc, Janet *argv) {
|
static Janet cfun_string_checkset(int32_t argc, Janet *argv) {
|
||||||
uint32_t bitset[8] = {0, 0, 0, 0, 0, 0, 0, 0};
|
uint32_t bitset[8] = {0, 0, 0, 0, 0, 0, 0, 0};
|
||||||
janet_arity(argc, 2, 3);
|
janet_arity(argc, 2, 3);
|
||||||
JanetByteView set = janet_getbytes(argv, 0);
|
JanetByteView set = janet_getbytes(argv, 0);
|
||||||
@ -398,7 +401,7 @@ static Janet cfun_checkset(int32_t argc, Janet *argv) {
|
|||||||
return janet_wrap_true();
|
return janet_wrap_true();
|
||||||
}
|
}
|
||||||
|
|
||||||
static Janet cfun_join(int32_t argc, Janet *argv) {
|
static Janet cfun_string_join(int32_t argc, Janet *argv) {
|
||||||
janet_arity(argc, 1, 2);
|
janet_arity(argc, 1, 2);
|
||||||
JanetView parts = janet_getindexed(argv, 0);
|
JanetView parts = janet_getindexed(argv, 0);
|
||||||
JanetByteView joiner;
|
JanetByteView joiner;
|
||||||
@ -451,7 +454,7 @@ static struct formatter {
|
|||||||
{"F", "%F", "%.*F"}
|
{"F", "%F", "%.*F"}
|
||||||
};
|
};
|
||||||
|
|
||||||
static Janet cfun_number(int32_t argc, Janet *argv) {
|
static Janet cfun_string_number(int32_t argc, Janet *argv) {
|
||||||
janet_arity(argc, 1, 4);
|
janet_arity(argc, 1, 4);
|
||||||
double x = janet_getnumber(argv, 0);
|
double x = janet_getnumber(argv, 0);
|
||||||
struct formatter fmter = formatters[0];
|
struct formatter fmter = formatters[0];
|
||||||
@ -486,7 +489,7 @@ static Janet cfun_number(int32_t argc, Janet *argv) {
|
|||||||
return janet_cstringv(buf);
|
return janet_cstringv(buf);
|
||||||
}
|
}
|
||||||
|
|
||||||
static Janet cfun_pretty(int32_t argc, Janet *argv) {
|
static Janet cfun_string_pretty(int32_t argc, Janet *argv) {
|
||||||
janet_arity(argc, 1, 3);
|
janet_arity(argc, 1, 3);
|
||||||
JanetBuffer *buffer = NULL;
|
JanetBuffer *buffer = NULL;
|
||||||
int32_t depth = 4;
|
int32_t depth = 4;
|
||||||
@ -498,9 +501,9 @@ static Janet cfun_pretty(int32_t argc, Janet *argv) {
|
|||||||
return janet_wrap_buffer(buffer);
|
return janet_wrap_buffer(buffer);
|
||||||
}
|
}
|
||||||
|
|
||||||
static const JanetReg cfuns[] = {
|
static const JanetReg string_cfuns[] = {
|
||||||
{
|
{
|
||||||
"string/slice", cfun_slice,
|
"string/slice", cfun_string_slice,
|
||||||
JDOC("(string/slice bytes [,start=0 [,end=(length str)]])\n\n"
|
JDOC("(string/slice bytes [,start=0 [,end=(length str)]])\n\n"
|
||||||
"Returns a substring from a byte sequence. The substring is from "
|
"Returns a substring from a byte sequence. The substring is from "
|
||||||
"index start inclusive to index end exclusive. All indexing "
|
"index start inclusive to index end exclusive. All indexing "
|
||||||
@ -508,49 +511,49 @@ static const JanetReg cfuns[] = {
|
|||||||
"from the end of the string.")
|
"from the end of the string.")
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
"string/repeat", cfun_repeat,
|
"string/repeat", cfun_string_repeat,
|
||||||
JDOC("(string/repeat bytes n)\n\n"
|
JDOC("(string/repeat bytes n)\n\n"
|
||||||
"Returns a string that is n copies of bytes concatenated.")
|
"Returns a string that is n copies of bytes concatenated.")
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
"string/bytes", cfun_bytes,
|
"string/bytes", cfun_string_bytes,
|
||||||
JDOC("(string/bytes str)\n\n"
|
JDOC("(string/bytes str)\n\n"
|
||||||
"Returns an array of integers that are the byte values of the string.")
|
"Returns an array of integers that are the byte values of the string.")
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
"string/from-bytes", cfun_frombytes,
|
"string/from-bytes", cfun_string_frombytes,
|
||||||
JDOC("(string/from-bytes byte-array)\n\n"
|
JDOC("(string/from-bytes byte-array)\n\n"
|
||||||
"Creates a string from an array of integers with byte values. All integers "
|
"Creates a string from an array of integers with byte values. All integers "
|
||||||
"will be coerced to the range of 1 byte 0-255.")
|
"will be coerced to the range of 1 byte 0-255.")
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
"string/ascii-lower", cfun_asciilower,
|
"string/ascii-lower", cfun_string_asciilower,
|
||||||
JDOC("(string/ascii-lower str)\n\n"
|
JDOC("(string/ascii-lower str)\n\n"
|
||||||
"Returns a new string where all bytes are replaced with the "
|
"Returns a new string where all bytes are replaced with the "
|
||||||
"lowercase version of themselves in ASCII. Does only a very simple "
|
"lowercase version of themselves in ASCII. Does only a very simple "
|
||||||
"case check, meaning no unicode support.")
|
"case check, meaning no unicode support.")
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
"string/ascii-upper", cfun_asciiupper,
|
"string/ascii-upper", cfun_string_asciiupper,
|
||||||
JDOC("(string/ascii-upper str)\n\n"
|
JDOC("(string/ascii-upper str)\n\n"
|
||||||
"Returns a new string where all bytes are replaced with the "
|
"Returns a new string where all bytes are replaced with the "
|
||||||
"uppercase version of themselves in ASCII. Does only a very simple "
|
"uppercase version of themselves in ASCII. Does only a very simple "
|
||||||
"case check, meaning no unicode support.")
|
"case check, meaning no unicode support.")
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
"string/reverse", cfun_reverse,
|
"string/reverse", cfun_string_reverse,
|
||||||
JDOC("(string/reverse str)\n\n"
|
JDOC("(string/reverse str)\n\n"
|
||||||
"Returns a string that is the reversed version of str.")
|
"Returns a string that is the reversed version of str.")
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
"string/find", cfun_find,
|
"string/find", cfun_string_find,
|
||||||
JDOC("(string/find patt str)\n\n"
|
JDOC("(string/find patt str)\n\n"
|
||||||
"Searches for the first instance of pattern patt in string "
|
"Searches for the first instance of pattern patt in string "
|
||||||
"str. Returns the index of the first character in patt if found, "
|
"str. Returns the index of the first character in patt if found, "
|
||||||
"otherwise returns nil.")
|
"otherwise returns nil.")
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
"string/find-all", cfun_findall,
|
"string/find-all", cfun_string_findall,
|
||||||
JDOC("(string/find patt str)\n\n"
|
JDOC("(string/find patt str)\n\n"
|
||||||
"Searches for all instances of pattern patt in string "
|
"Searches for all instances of pattern patt in string "
|
||||||
"str. Returns an array of all indices of found patterns. Overlapping "
|
"str. Returns an array of all indices of found patterns. Overlapping "
|
||||||
@ -559,38 +562,38 @@ static const JanetReg cfuns[] = {
|
|||||||
"occurrences are found, will return an empty array.")
|
"occurrences are found, will return an empty array.")
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
"string/replace", cfun_replace,
|
"string/replace", cfun_string_replace,
|
||||||
JDOC("(string/replace patt subst str)\n\n"
|
JDOC("(string/replace patt subst str)\n\n"
|
||||||
"Replace the first occurrence of patt with subst in the string str. "
|
"Replace the first occurrence of patt with subst in the string str. "
|
||||||
"Will return the new string if patt is found, otherwise returns str.")
|
"Will return the new string if patt is found, otherwise returns str.")
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
"string/replace-all", cfun_replaceall,
|
"string/replace-all", cfun_string_replaceall,
|
||||||
JDOC("(string/replace-all patt subst str)\n\n"
|
JDOC("(string/replace-all patt subst str)\n\n"
|
||||||
"Replace all instances of patt with subst in the string str. "
|
"Replace all instances of patt with subst in the string str. "
|
||||||
"Will return the new string if patt is found, otherwise returns str.")
|
"Will return the new string if patt is found, otherwise returns str.")
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
"string/split", cfun_split,
|
"string/split", cfun_string_split,
|
||||||
JDOC("(string/split delim str)\n\n"
|
JDOC("(string/split delim str)\n\n"
|
||||||
"Splits a string str with delimiter delim and returns an array of "
|
"Splits a string str with delimiter delim and returns an array of "
|
||||||
"substrings. The substrings will not contain the delimiter delim. If delim "
|
"substrings. The substrings will not contain the delimiter delim. If delim "
|
||||||
"is not found, the returned array will have one element.")
|
"is not found, the returned array will have one element.")
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
"string/check-set", cfun_checkset,
|
"string/check-set", cfun_string_checkset,
|
||||||
JDOC("(string/check-set set str)\n\n"
|
JDOC("(string/check-set set str)\n\n"
|
||||||
"Checks if any of the bytes in the string set appear in the string str. "
|
"Checks if any of the bytes in the string set appear in the string str. "
|
||||||
"Returns true if some bytes in set do appear in str, false if no bytes do.")
|
"Returns true if some bytes in set do appear in str, false if no bytes do.")
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
"string/join", cfun_join,
|
"string/join", cfun_string_join,
|
||||||
JDOC("(string/join parts [,sep])\n\n"
|
JDOC("(string/join parts [,sep])\n\n"
|
||||||
"Joins an array of strings into one string, optionally separated by "
|
"Joins an array of strings into one string, optionally separated by "
|
||||||
"a separator string sep.")
|
"a separator string sep.")
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
"string/number", cfun_number,
|
"string/number", cfun_string_number,
|
||||||
JDOC("(string/number x [,format [,maxlen [,precision]]])\n\n"
|
JDOC("(string/number x [,format [,maxlen [,precision]]])\n\n"
|
||||||
"Formats a number as string. The format parameter indicates how "
|
"Formats a number as string. The format parameter indicates how "
|
||||||
"to display the number, either as floating point, scientific, or "
|
"to display the number, either as floating point, scientific, or "
|
||||||
@ -606,7 +609,7 @@ static const JanetReg cfuns[] = {
|
|||||||
"Returns a string representation of x.")
|
"Returns a string representation of x.")
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
"string/pretty", cfun_pretty,
|
"string/pretty", cfun_string_pretty,
|
||||||
JDOC("(string/pretty x [,depth=4 [,buffer=@\"\"]])\n\n"
|
JDOC("(string/pretty x [,depth=4 [,buffer=@\"\"]])\n\n"
|
||||||
"Pretty prints a value to a buffer. Optionally allows setting max "
|
"Pretty prints a value to a buffer. Optionally allows setting max "
|
||||||
"recursion depth, as well as writing to a buffer. Returns the buffer.")
|
"recursion depth, as well as writing to a buffer. Returns the buffer.")
|
||||||
@ -616,5 +619,5 @@ static const JanetReg cfuns[] = {
|
|||||||
|
|
||||||
/* Module entry point */
|
/* Module entry point */
|
||||||
void janet_lib_string(JanetTable *env) {
|
void janet_lib_string(JanetTable *env) {
|
||||||
janet_cfuns(env, NULL, cfuns);
|
janet_cfuns(env, NULL, string_cfuns);
|
||||||
}
|
}
|
||||||
|
@ -44,10 +44,13 @@
|
|||||||
* as it will not fit in the range for a signed 32 bit integer. The string
|
* as it will not fit in the range for a signed 32 bit integer. The string
|
||||||
* '0xbeef' would parse to an integer as it is in the range of an int32_t. */
|
* '0xbeef' would parse to an integer as it is in the range of an int32_t. */
|
||||||
|
|
||||||
#include <janet/janet.h>
|
|
||||||
#include <math.h>
|
#include <math.h>
|
||||||
#include <string.h>
|
#include <string.h>
|
||||||
|
|
||||||
|
#ifndef JANET_AMALG
|
||||||
|
#include <janet/janet.h>
|
||||||
|
#endif
|
||||||
|
|
||||||
/* Lookup table for getting values of characters when parsing numbers. Handles
|
/* Lookup table for getting values of characters when parsing numbers. Handles
|
||||||
* digits 0-9 and a-z (and A-Z). A-Z have values of 10 to 35. */
|
* digits 0-9 and a-z (and A-Z). A-Z have values of 10 to 35. */
|
||||||
static uint8_t digit_lookup[128] = {
|
static uint8_t digit_lookup[128] = {
|
||||||
|
@ -20,9 +20,11 @@
|
|||||||
* IN THE SOFTWARE.
|
* IN THE SOFTWARE.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
#ifndef JANET_AMALG
|
||||||
#include <janet/janet.h>
|
#include <janet/janet.h>
|
||||||
#include "gc.h"
|
#include "gc.h"
|
||||||
#include "util.h"
|
#include "util.h"
|
||||||
|
#endif
|
||||||
|
|
||||||
/* Begin creation of a struct */
|
/* Begin creation of a struct */
|
||||||
JanetKV *janet_struct_begin(int32_t count) {
|
JanetKV *janet_struct_begin(int32_t count) {
|
||||||
@ -218,5 +220,3 @@ int janet_struct_compare(const JanetKV *lhs, const JanetKV *rhs) {
|
|||||||
}
|
}
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
#undef janet_maphash
|
|
||||||
|
@ -25,10 +25,12 @@
|
|||||||
* checks, all symbols are interned so that there is a single copy of it in the
|
* checks, all symbols are interned so that there is a single copy of it in the
|
||||||
* whole program. Equality is then just a pointer check. */
|
* whole program. Equality is then just a pointer check. */
|
||||||
|
|
||||||
|
#ifndef JANET_AMALG
|
||||||
#include <janet/janet.h>
|
#include <janet/janet.h>
|
||||||
#include "state.h"
|
#include "state.h"
|
||||||
#include "gc.h"
|
#include "gc.h"
|
||||||
#include "util.h"
|
#include "util.h"
|
||||||
|
#endif
|
||||||
|
|
||||||
/* Cache state */
|
/* Cache state */
|
||||||
JANET_THREAD_LOCAL const uint8_t **janet_vm_cache = NULL;
|
JANET_THREAD_LOCAL const uint8_t **janet_vm_cache = NULL;
|
||||||
|
@ -23,7 +23,9 @@
|
|||||||
#ifndef JANET_SYMCACHE_H_defined
|
#ifndef JANET_SYMCACHE_H_defined
|
||||||
#define JANET_SYMCACHE_H_defined
|
#define JANET_SYMCACHE_H_defined
|
||||||
|
|
||||||
|
#ifndef JANET_AMALG
|
||||||
#include <janet/janet.h>
|
#include <janet/janet.h>
|
||||||
|
#endif
|
||||||
|
|
||||||
/* Initialize the cache (allocate cache memory) */
|
/* Initialize the cache (allocate cache memory) */
|
||||||
void janet_symcache_init(void);
|
void janet_symcache_init(void);
|
||||||
|
@ -20,9 +20,11 @@
|
|||||||
* IN THE SOFTWARE.
|
* IN THE SOFTWARE.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
#ifndef JANET_AMALG
|
||||||
#include <janet/janet.h>
|
#include <janet/janet.h>
|
||||||
#include "gc.h"
|
#include "gc.h"
|
||||||
#include "util.h"
|
#include "util.h"
|
||||||
|
#endif
|
||||||
|
|
||||||
/* Initialize a table */
|
/* Initialize a table */
|
||||||
JanetTable *janet_table_init(JanetTable *table, int32_t capacity) {
|
JanetTable *janet_table_init(JanetTable *table, int32_t capacity) {
|
||||||
@ -194,13 +196,13 @@ void janet_table_merge_struct(JanetTable *table, const JanetKV *other) {
|
|||||||
|
|
||||||
/* C Functions */
|
/* C Functions */
|
||||||
|
|
||||||
static Janet cfun_new(int32_t argc, Janet *argv) {
|
static Janet cfun_table_new(int32_t argc, Janet *argv) {
|
||||||
janet_fixarity(argc, 1);
|
janet_fixarity(argc, 1);
|
||||||
int32_t cap = janet_getinteger(argv, 0);
|
int32_t cap = janet_getinteger(argv, 0);
|
||||||
return janet_wrap_table(janet_table(cap));
|
return janet_wrap_table(janet_table(cap));
|
||||||
}
|
}
|
||||||
|
|
||||||
static Janet cfun_getproto(int32_t argc, Janet *argv) {
|
static Janet cfun_table_getproto(int32_t argc, Janet *argv) {
|
||||||
janet_fixarity(argc, 1);
|
janet_fixarity(argc, 1);
|
||||||
JanetTable *t = janet_gettable(argv, 0);
|
JanetTable *t = janet_gettable(argv, 0);
|
||||||
return t->proto
|
return t->proto
|
||||||
@ -208,7 +210,7 @@ static Janet cfun_getproto(int32_t argc, Janet *argv) {
|
|||||||
: janet_wrap_nil();
|
: janet_wrap_nil();
|
||||||
}
|
}
|
||||||
|
|
||||||
static Janet cfun_setproto(int32_t argc, Janet *argv) {
|
static Janet cfun_table_setproto(int32_t argc, Janet *argv) {
|
||||||
janet_fixarity(argc, 2);
|
janet_fixarity(argc, 2);
|
||||||
JanetTable *table = janet_gettable(argv, 0);
|
JanetTable *table = janet_gettable(argv, 0);
|
||||||
JanetTable *proto = NULL;
|
JanetTable *proto = NULL;
|
||||||
@ -219,21 +221,21 @@ static Janet cfun_setproto(int32_t argc, Janet *argv) {
|
|||||||
return argv[0];
|
return argv[0];
|
||||||
}
|
}
|
||||||
|
|
||||||
static Janet cfun_tostruct(int32_t argc, Janet *argv) {
|
static Janet cfun_table_tostruct(int32_t argc, Janet *argv) {
|
||||||
janet_fixarity(argc, 1);
|
janet_fixarity(argc, 1);
|
||||||
JanetTable *t = janet_gettable(argv, 0);
|
JanetTable *t = janet_gettable(argv, 0);
|
||||||
return janet_wrap_struct(janet_table_to_struct(t));
|
return janet_wrap_struct(janet_table_to_struct(t));
|
||||||
}
|
}
|
||||||
|
|
||||||
static Janet cfun_rawget(int32_t argc, Janet *argv) {
|
static Janet cfun_table_rawget(int32_t argc, Janet *argv) {
|
||||||
janet_fixarity(argc, 2);
|
janet_fixarity(argc, 2);
|
||||||
JanetTable *table = janet_gettable(argv, 0);
|
JanetTable *table = janet_gettable(argv, 0);
|
||||||
return janet_table_rawget(table, argv[1]);
|
return janet_table_rawget(table, argv[1]);
|
||||||
}
|
}
|
||||||
|
|
||||||
static const JanetReg cfuns[] = {
|
static const JanetReg table_cfuns[] = {
|
||||||
{
|
{
|
||||||
"table/new", cfun_new,
|
"table/new", cfun_table_new,
|
||||||
JDOC("(table/new capacity)\n\n"
|
JDOC("(table/new capacity)\n\n"
|
||||||
"Creates a new empty table with pre-allocated memory "
|
"Creates a new empty table with pre-allocated memory "
|
||||||
"for capacity entries. This means that if one knows the number of "
|
"for capacity entries. This means that if one knows the number of "
|
||||||
@ -241,24 +243,24 @@ static const JanetReg cfuns[] = {
|
|||||||
"can be avoided. Returns the new table.")
|
"can be avoided. Returns the new table.")
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
"table/to-struct", cfun_tostruct,
|
"table/to-struct", cfun_table_tostruct,
|
||||||
JDOC("(table/to-struct tab)\n\n"
|
JDOC("(table/to-struct tab)\n\n"
|
||||||
"Convert a table to a struct. Returns a new struct. This function "
|
"Convert a table to a struct. Returns a new struct. This function "
|
||||||
"does not take into account prototype tables.")
|
"does not take into account prototype tables.")
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
"table/getproto", cfun_getproto,
|
"table/getproto", cfun_table_getproto,
|
||||||
JDOC("(table/getproto tab)\n\n"
|
JDOC("(table/getproto tab)\n\n"
|
||||||
"Get the prototype table of a table. Returns nil if a table "
|
"Get the prototype table of a table. Returns nil if a table "
|
||||||
"has no prototype, otherwise returns the prototype.")
|
"has no prototype, otherwise returns the prototype.")
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
"table/setproto", cfun_setproto,
|
"table/setproto", cfun_table_setproto,
|
||||||
JDOC("(table/setproto tab proto)\n\n"
|
JDOC("(table/setproto tab proto)\n\n"
|
||||||
"Set the prototype of a table. Returns the original table tab.")
|
"Set the prototype of a table. Returns the original table tab.")
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
"table/rawget", cfun_rawget,
|
"table/rawget", cfun_table_rawget,
|
||||||
JDOC("(table/rawget tab key)\n\n"
|
JDOC("(table/rawget tab key)\n\n"
|
||||||
"Gets a value from a table without looking at the prototype table. "
|
"Gets a value from a table without looking at the prototype table. "
|
||||||
"If a table tab does not contain t directly, the function will return "
|
"If a table tab does not contain t directly, the function will return "
|
||||||
@ -269,5 +271,5 @@ static const JanetReg cfuns[] = {
|
|||||||
|
|
||||||
/* Load the table module */
|
/* Load the table module */
|
||||||
void janet_lib_table(JanetTable *env) {
|
void janet_lib_table(JanetTable *env) {
|
||||||
janet_cfuns(env, NULL, cfuns);
|
janet_cfuns(env, NULL, table_cfuns);
|
||||||
}
|
}
|
||||||
|
@ -20,10 +20,12 @@
|
|||||||
* IN THE SOFTWARE.
|
* IN THE SOFTWARE.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
#ifndef JANET_AMALG
|
||||||
#include <janet/janet.h>
|
#include <janet/janet.h>
|
||||||
#include "symcache.h"
|
#include "symcache.h"
|
||||||
#include "gc.h"
|
#include "gc.h"
|
||||||
#include "util.h"
|
#include "util.h"
|
||||||
|
#endif
|
||||||
|
|
||||||
/* Create a new empty tuple of the given size. This will return memory
|
/* Create a new empty tuple of the given size. This will return memory
|
||||||
* which should be filled with Janets. The memory will not be collected until
|
* which should be filled with Janets. The memory will not be collected until
|
||||||
@ -91,13 +93,13 @@ int janet_tuple_compare(const Janet *lhs, const Janet *rhs) {
|
|||||||
|
|
||||||
/* C Functions */
|
/* C Functions */
|
||||||
|
|
||||||
static Janet cfun_slice(int32_t argc, Janet *argv) {
|
static Janet cfun_tuple_slice(int32_t argc, Janet *argv) {
|
||||||
JanetRange range = janet_getslice(argc, argv);
|
JanetRange range = janet_getslice(argc, argv);
|
||||||
JanetView view = janet_getindexed(argv, 0);
|
JanetView view = janet_getindexed(argv, 0);
|
||||||
return janet_wrap_tuple(janet_tuple_n(view.items + range.start, range.end - range.start));
|
return janet_wrap_tuple(janet_tuple_n(view.items + range.start, range.end - range.start));
|
||||||
}
|
}
|
||||||
|
|
||||||
static Janet cfun_prepend(int32_t argc, Janet *argv) {
|
static Janet cfun_tuple_prepend(int32_t argc, Janet *argv) {
|
||||||
janet_arity(argc, 1, -1);
|
janet_arity(argc, 1, -1);
|
||||||
JanetView view = janet_getindexed(argv, 0);
|
JanetView view = janet_getindexed(argv, 0);
|
||||||
Janet *n = janet_tuple_begin(view.len - 1 + argc);
|
Janet *n = janet_tuple_begin(view.len - 1 + argc);
|
||||||
@ -108,7 +110,7 @@ static Janet cfun_prepend(int32_t argc, Janet *argv) {
|
|||||||
return janet_wrap_tuple(janet_tuple_end(n));
|
return janet_wrap_tuple(janet_tuple_end(n));
|
||||||
}
|
}
|
||||||
|
|
||||||
static Janet cfun_append(int32_t argc, Janet *argv) {
|
static Janet cfun_tuple_append(int32_t argc, Janet *argv) {
|
||||||
janet_arity(argc, 1, -1);
|
janet_arity(argc, 1, -1);
|
||||||
JanetView view = janet_getindexed(argv, 0);
|
JanetView view = janet_getindexed(argv, 0);
|
||||||
Janet *n = janet_tuple_begin(view.len - 1 + argc);
|
Janet *n = janet_tuple_begin(view.len - 1 + argc);
|
||||||
@ -117,9 +119,9 @@ static Janet cfun_append(int32_t argc, Janet *argv) {
|
|||||||
return janet_wrap_tuple(janet_tuple_end(n));
|
return janet_wrap_tuple(janet_tuple_end(n));
|
||||||
}
|
}
|
||||||
|
|
||||||
static const JanetReg cfuns[] = {
|
static const JanetReg tuple_cfuns[] = {
|
||||||
{
|
{
|
||||||
"tuple/slice", cfun_slice,
|
"tuple/slice", cfun_tuple_slice,
|
||||||
JDOC("(tuple/slice arrtup [,start=0 [,end=(length arrtup)]])\n\n"
|
JDOC("(tuple/slice arrtup [,start=0 [,end=(length arrtup)]])\n\n"
|
||||||
"Take a sub sequence of an array or tuple from index start "
|
"Take a sub sequence of an array or tuple from index start "
|
||||||
"inclusive to index end exclusive. If start or end are not provided, "
|
"inclusive to index end exclusive. If start or end are not provided, "
|
||||||
@ -127,13 +129,13 @@ static const JanetReg cfuns[] = {
|
|||||||
"Returns the new tuple.")
|
"Returns the new tuple.")
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
"tuple/append", cfun_append,
|
"tuple/append", cfun_tuple_append,
|
||||||
JDOC("(tuple/append tup & items)\n\n"
|
JDOC("(tuple/append tup & items)\n\n"
|
||||||
"Returns a new tuple that is the result of appending "
|
"Returns a new tuple that is the result of appending "
|
||||||
"each element in items to tup.")
|
"each element in items to tup.")
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
"tuple/prepend", cfun_prepend,
|
"tuple/prepend", cfun_tuple_prepend,
|
||||||
JDOC("(tuple/prepend tup & items)\n\n"
|
JDOC("(tuple/prepend tup & items)\n\n"
|
||||||
"Prepends each element in items to tuple and "
|
"Prepends each element in items to tuple and "
|
||||||
"returns a new tuple. Items are prepended such that the "
|
"returns a new tuple. Items are prepended such that the "
|
||||||
@ -144,5 +146,5 @@ static const JanetReg cfuns[] = {
|
|||||||
|
|
||||||
/* Load the tuple module */
|
/* Load the tuple module */
|
||||||
void janet_lib_tuple(JanetTable *env) {
|
void janet_lib_tuple(JanetTable *env) {
|
||||||
janet_cfuns(env, NULL, cfuns);
|
janet_cfuns(env, NULL, tuple_cfuns);
|
||||||
}
|
}
|
||||||
|
@ -20,11 +20,14 @@
|
|||||||
* IN THE SOFTWARE.
|
* IN THE SOFTWARE.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#include <janet/janet.h>
|
|
||||||
#include <inttypes.h>
|
#include <inttypes.h>
|
||||||
|
|
||||||
|
#ifndef JANET_AMALG
|
||||||
|
#include <janet/janet.h>
|
||||||
#include "util.h"
|
#include "util.h"
|
||||||
#include "state.h"
|
#include "state.h"
|
||||||
#include "gc.h"
|
#include "gc.h"
|
||||||
|
#endif
|
||||||
|
|
||||||
/* Base 64 lookup table for digits */
|
/* Base 64 lookup table for digits */
|
||||||
const char janet_base64[65] =
|
const char janet_base64[65] =
|
||||||
|
@ -23,7 +23,9 @@
|
|||||||
#ifndef JANET_UTIL_H_defined
|
#ifndef JANET_UTIL_H_defined
|
||||||
#define JANET_UTIL_H_defined
|
#define JANET_UTIL_H_defined
|
||||||
|
|
||||||
|
#ifndef JANET_AMALG
|
||||||
#include <janet/janet.h>
|
#include <janet/janet.h>
|
||||||
|
#endif
|
||||||
|
|
||||||
/* Omit docstrings in some builds */
|
/* Omit docstrings in some builds */
|
||||||
#ifdef JANET_NO_BOOTSTRAP
|
#ifdef JANET_NO_BOOTSTRAP
|
||||||
|
@ -20,7 +20,9 @@
|
|||||||
* IN THE SOFTWARE.
|
* IN THE SOFTWARE.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
#ifndef JANET_AMALG
|
||||||
#include <janet/janet.h>
|
#include <janet/janet.h>
|
||||||
|
#endif
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Define a number of functions that can be used internally on ANY Janet.
|
* Define a number of functions that can be used internally on ANY Janet.
|
||||||
|
@ -20,7 +20,9 @@
|
|||||||
* IN THE SOFTWARE.
|
* IN THE SOFTWARE.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
#ifndef JANET_AMALG
|
||||||
#include "vector.h"
|
#include "vector.h"
|
||||||
|
#endif
|
||||||
|
|
||||||
/* Grow the buffer dynamically. Used for push operations. */
|
/* Grow the buffer dynamically. Used for push operations. */
|
||||||
void *janet_v_grow(void *v, int32_t increment, int32_t itemsize) {
|
void *janet_v_grow(void *v, int32_t increment, int32_t itemsize) {
|
||||||
|
@ -23,7 +23,9 @@
|
|||||||
#ifndef JANET_VECTOR_H_defined
|
#ifndef JANET_VECTOR_H_defined
|
||||||
#define JANET_VECTOR_H_defined
|
#define JANET_VECTOR_H_defined
|
||||||
|
|
||||||
|
#ifndef JANET_AMALG
|
||||||
#include <janet/janet.h>
|
#include <janet/janet.h>
|
||||||
|
#endif
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* vector code modified from
|
* vector code modified from
|
||||||
|
@ -20,12 +20,14 @@
|
|||||||
* IN THE SOFTWARE.
|
* IN THE SOFTWARE.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
#ifndef JANET_AMALG
|
||||||
#include <janet/janet.h>
|
#include <janet/janet.h>
|
||||||
#include "state.h"
|
#include "state.h"
|
||||||
#include "fiber.h"
|
#include "fiber.h"
|
||||||
#include "gc.h"
|
#include "gc.h"
|
||||||
#include "symcache.h"
|
#include "symcache.h"
|
||||||
#include "util.h"
|
#include "util.h"
|
||||||
|
#endif
|
||||||
|
|
||||||
/* VM state */
|
/* VM state */
|
||||||
JANET_THREAD_LOCAL JanetTable *janet_vm_registry;
|
JANET_THREAD_LOCAL JanetTable *janet_vm_registry;
|
||||||
|
@ -20,7 +20,9 @@
|
|||||||
* IN THE SOFTWARE.
|
* IN THE SOFTWARE.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
#ifndef JANET_AMALG
|
||||||
#include <janet/janet.h>
|
#include <janet/janet.h>
|
||||||
|
#endif
|
||||||
|
|
||||||
void *janet_memalloc_empty(int32_t count) {
|
void *janet_memalloc_empty(int32_t count) {
|
||||||
int32_t i;
|
int32_t i;
|
||||||
|
65
tools/amalg.janet
Normal file
65
tools/amalg.janet
Normal file
@ -0,0 +1,65 @@
|
|||||||
|
# Creates an amalgamated janet.c and janet.h to
|
||||||
|
# allow for easy embedding
|
||||||
|
|
||||||
|
(def {:year YY :month MM :month-day DD} (os/date))
|
||||||
|
|
||||||
|
# Order is important here, as some headers
|
||||||
|
# depend on other headers.
|
||||||
|
(def headers
|
||||||
|
@["src/core/util.h"
|
||||||
|
"src/core/state.h"
|
||||||
|
"src/core/gc.h"
|
||||||
|
"src/core/vector.h"
|
||||||
|
"src/core/fiber.h"
|
||||||
|
"src/core/regalloc.h"
|
||||||
|
"src/core/compile.h"
|
||||||
|
"src/core/emit.h"
|
||||||
|
"src/core/symcache.h"])
|
||||||
|
|
||||||
|
(def sources
|
||||||
|
@["src/core/abstract.c"
|
||||||
|
"src/core/array.c"
|
||||||
|
"src/core/asm.c"
|
||||||
|
"src/core/buffer.c"
|
||||||
|
"src/core/bytecode.c"
|
||||||
|
"src/core/capi.c"
|
||||||
|
"src/core/cfuns.c"
|
||||||
|
"src/core/compile.c"
|
||||||
|
"src/core/corelib.c"
|
||||||
|
"src/core/debug.c"
|
||||||
|
"src/core/emit.c"
|
||||||
|
"src/core/fiber.c"
|
||||||
|
"src/core/gc.c"
|
||||||
|
"src/core/io.c"
|
||||||
|
"src/core/marsh.c"
|
||||||
|
"src/core/math.c"
|
||||||
|
"src/core/os.c"
|
||||||
|
"src/core/parse.c"
|
||||||
|
"src/core/peg.c"
|
||||||
|
"src/core/pp.c"
|
||||||
|
"src/core/regalloc.c"
|
||||||
|
"src/core/run.c"
|
||||||
|
"src/core/specials.c"
|
||||||
|
"src/core/string.c"
|
||||||
|
"src/core/strtod.c"
|
||||||
|
"src/core/struct.c"
|
||||||
|
"src/core/symcache.c"
|
||||||
|
"src/core/table.c"
|
||||||
|
"src/core/tuple.c"
|
||||||
|
"src/core/util.c"
|
||||||
|
"src/core/value.c"
|
||||||
|
"src/core/vector.c"
|
||||||
|
"src/core/vm.c"
|
||||||
|
"src/core/wrap.c"])
|
||||||
|
|
||||||
|
(print "/* Amalgamated build - DO NOT EDIT */")
|
||||||
|
(print "/* Generated " YY "-" (inc MM) "-" (inc DD)
|
||||||
|
" with janet version " janet/version "-" janet/build " */")
|
||||||
|
(print ```#define JANET_AMALG
|
||||||
|
#include "janet.h"```)
|
||||||
|
|
||||||
|
(each h headers (print (slurp h)))
|
||||||
|
(each s sources (print (slurp s)))
|
||||||
|
|
||||||
|
# Relies on this file being built
|
||||||
|
(print (slurp "build/core.gen.c"))
|
@ -60,7 +60,7 @@ int main(int argc, const char **argv) {
|
|||||||
|
|
||||||
/* Write the header */
|
/* Write the header */
|
||||||
fprintf(out, "/* Auto generated - DO NOT EDIT */\n\n#include <stdint.h>\n\n");
|
fprintf(out, "/* Auto generated - DO NOT EDIT */\n\n#include <stdint.h>\n\n");
|
||||||
fprintf(out, "static const unsigned char bytes[] = {");
|
fprintf(out, "static const unsigned char bytes_%s[] = {", argv[3]);
|
||||||
|
|
||||||
/* Read in chunks from buffer */
|
/* Read in chunks from buffer */
|
||||||
while ((bytesRead = fread(buf, 1, sizeof(buf), in)) > 0) {
|
while ((bytesRead = fread(buf, 1, sizeof(buf), in)) > 0) {
|
||||||
@ -91,7 +91,7 @@ int main(int argc, const char **argv) {
|
|||||||
/* Write the tail */
|
/* Write the tail */
|
||||||
fputs("\n};\n\n", out);
|
fputs("\n};\n\n", out);
|
||||||
|
|
||||||
fprintf(out, "const unsigned char *%s = bytes;\n\n", argv[3]);
|
fprintf(out, "const unsigned char *%s = bytes_%s;\n\n", argv[3], argv[3]);
|
||||||
|
|
||||||
/* Write chunk size */
|
/* Write chunk size */
|
||||||
fprintf(out, "int32_t %s_size = %d;\n", argv[3], totalRead);
|
fprintf(out, "int32_t %s_size = %d;\n", argv[3], totalRead);
|
||||||
|
Loading…
Reference in New Issue
Block a user