mirror of
https://github.com/janet-lang/janet
synced 2024-12-26 00:10:27 +00:00
Don't use generated headers for embedded janet
code, use object files.
This commit is contained in:
parent
97fade8197
commit
7668cd5772
49
Makefile
49
Makefile
@ -49,43 +49,16 @@ else
|
|||||||
endif
|
endif
|
||||||
|
|
||||||
# Source headers
|
# Source headers
|
||||||
JANET_GENERATED_HEADERS= \
|
|
||||||
src/include/generated/core.h \
|
|
||||||
src/include/generated/init.h
|
|
||||||
JANET_HEADERS=$(sort $(wildcard src/include/janet/*.h))
|
JANET_HEADERS=$(sort $(wildcard src/include/janet/*.h))
|
||||||
JANET_LOCAL_HEADERS=$(sort $(wildcard src/*/*.h))
|
JANET_LOCAL_HEADERS=$(sort $(wildcard src/*/*.h))
|
||||||
|
|
||||||
# Source files
|
# Source files
|
||||||
JANET_CORE_SOURCES=$(sort $(wildcard src/core/*.c))
|
JANET_CORE_SOURCES=$(sort $(wildcard src/core/*.c)) src/core/core.gen.c
|
||||||
JANET_MAINCLIENT_SOURCES=$(sort $(wildcard src/mainclient/*.c))
|
JANET_MAINCLIENT_SOURCES=$(sort $(wildcard src/mainclient/*.c)) src/mainclient/init.gen.c
|
||||||
JANET_WEBCLIENT_SOURCES=$(sort $(wildcard src/webclient/*.c))
|
JANET_WEBCLIENT_SOURCES=$(sort $(wildcard src/webclient/*.c)) src/webclient/webinit.gen.c
|
||||||
|
|
||||||
all: $(JANET_TARGET) $(JANET_LIBRARY)
|
all: $(JANET_TARGET) $(JANET_LIBRARY)
|
||||||
|
|
||||||
###################################
|
|
||||||
##### The code generator tool #####
|
|
||||||
###################################
|
|
||||||
|
|
||||||
xxd: src/tools/xxd.c
|
|
||||||
$(CC) $< -o $@
|
|
||||||
|
|
||||||
#############################
|
|
||||||
##### Generated Headers #####
|
|
||||||
#############################
|
|
||||||
|
|
||||||
src/include/generated/init.h: src/mainclient/init.janet xxd
|
|
||||||
./xxd $< $@ janet_gen_init
|
|
||||||
|
|
||||||
src/include/generated/webinit.h: src/webclient/webinit.janet xxd
|
|
||||||
./xxd $< $@ janet_gen_webinit
|
|
||||||
|
|
||||||
src/include/generated/core.h: src/core/core.janet xxd
|
|
||||||
./xxd $< $@ janet_gen_core
|
|
||||||
|
|
||||||
# Only a few files depend on the generated headers
|
|
||||||
src/core/corelib.o: src/include/generated/core.h
|
|
||||||
src/mainclient/main.o: src/include/generated/init.h
|
|
||||||
|
|
||||||
##########################################################
|
##########################################################
|
||||||
##### The main interpreter program and shared object #####
|
##### The main interpreter program and shared object #####
|
||||||
##########################################################
|
##########################################################
|
||||||
@ -119,16 +92,22 @@ JANET_EMTARGET=janet.js
|
|||||||
JANET_WEB_SOURCES=$(JANET_CORE_SOURCES) $(JANET_WEBCLIENT_SOURCES)
|
JANET_WEB_SOURCES=$(JANET_CORE_SOURCES) $(JANET_WEBCLIENT_SOURCES)
|
||||||
JANET_EMOBJECTS=$(patsubst %.c,%.bc,$(JANET_WEB_SOURCES))
|
JANET_EMOBJECTS=$(patsubst %.c,%.bc,$(JANET_WEB_SOURCES))
|
||||||
|
|
||||||
# Only a few files depend on generated headers
|
|
||||||
src/core/corelib.bc: src/include/generated/core.h
|
|
||||||
src/webclient/main.bc: src/include/generated/webinit.h
|
|
||||||
|
|
||||||
%.bc: %.c $(JANET_HEADERS) $(JANET_LOCAL_HEADERS)
|
%.bc: %.c $(JANET_HEADERS) $(JANET_LOCAL_HEADERS)
|
||||||
$(EMCC) $(EMCCFLAGS) -o $@ -c $<
|
$(EMCC) $(EMCCFLAGS) -o $@ -c $<
|
||||||
|
|
||||||
$(JANET_EMTARGET): $(JANET_EMOBJECTS)
|
$(JANET_EMTARGET): $(JANET_EMOBJECTS)
|
||||||
$(EMCC) $(EMCCFLAGS) -shared -o $@ $^
|
$(EMCC) $(EMCCFLAGS) -shared -o $@ $^
|
||||||
|
|
||||||
|
#############################
|
||||||
|
##### Generated C files #####
|
||||||
|
#############################
|
||||||
|
|
||||||
|
xxd: src/tools/xxd.c
|
||||||
|
$(CC) $< -o $@
|
||||||
|
|
||||||
|
%.gen.c: %.janet xxd
|
||||||
|
./xxd $< $@ janet_gen_$(*F)
|
||||||
|
|
||||||
###################
|
###################
|
||||||
##### Testing #####
|
##### Testing #####
|
||||||
###################
|
###################
|
||||||
@ -184,7 +163,7 @@ clean:
|
|||||||
-rm $(JANET_LIBRARY)
|
-rm $(JANET_LIBRARY)
|
||||||
-rm ctest/*.o ctest/*.out
|
-rm ctest/*.o ctest/*.out
|
||||||
-rm src/**/*.o src/**/*.bc vgcore.* *.js *.wasm *.html
|
-rm src/**/*.o src/**/*.bc vgcore.* *.js *.wasm *.html
|
||||||
-rm $(JANET_GENERATED_HEADERS)
|
-rm src/**/*.gen.c
|
||||||
|
|
||||||
install: $(JANET_TARGET)
|
install: $(JANET_TARGET)
|
||||||
mkdir -p $(BINDIR)
|
mkdir -p $(BINDIR)
|
||||||
|
@ -28,10 +28,16 @@ mkdir build\mainclient
|
|||||||
@link /nologo /out:build\xxd.exe build\xxd.obj
|
@link /nologo /out:build\xxd.exe build\xxd.obj
|
||||||
@if errorlevel 1 goto :BUILDFAIL
|
@if errorlevel 1 goto :BUILDFAIL
|
||||||
|
|
||||||
@rem Generate the headers
|
@rem Generate the embedded sources
|
||||||
@build\xxd.exe src\core\core.janet src\include\generated\core.h janet_gen_core
|
@build\xxd.exe src\core\core.janet build\core\core.gen.c janet_gen_core
|
||||||
@if errorlevel 1 goto :BUILDFAIL
|
@if errorlevel 1 goto :BUILDFAIL
|
||||||
@build\xxd.exe src\mainclient\init.janet src\include\generated\init.h janet_gen_init
|
@build\xxd.exe src\mainclient\init.janet build\mainclient\init.gen.c janet_gen_init
|
||||||
|
@if errorlevel 1 goto :BUILDFAIL
|
||||||
|
|
||||||
|
@rem Build the generated sources
|
||||||
|
@%JANET_COMPILE% /Fobuild\core\core.gen.obj build\core\core.gen.c
|
||||||
|
@if errorlevel 1 goto :BUILDFAIL
|
||||||
|
@%JANET_COMPILE% /Fobuild\mainclient\init.gen.obj build\mainclient\init.gen.c
|
||||||
@if errorlevel 1 goto :BUILDFAIL
|
@if errorlevel 1 goto :BUILDFAIL
|
||||||
|
|
||||||
@rem Build the sources
|
@rem Build the sources
|
||||||
|
@ -728,7 +728,7 @@ static int cfun(JanetArgs args) {
|
|||||||
|
|
||||||
static const JanetReg cfuns[] = {
|
static const JanetReg cfuns[] = {
|
||||||
{"compile", cfun,
|
{"compile", cfun,
|
||||||
"(compile ast)\n\n"
|
"(compile ast env [, source])\n\n"
|
||||||
"Compiles an Abstract Sytnax Tree (ast) into a janet function. "
|
"Compiles an Abstract Sytnax Tree (ast) into a janet function. "
|
||||||
"Pair the compile function with parsing functionality to implement "
|
"Pair the compile function with parsing functionality to implement "
|
||||||
"eval. Returns a janet function and does not modify ast. Throws an "
|
"eval. Returns a janet function and does not modify ast. Throws an "
|
||||||
|
@ -25,8 +25,9 @@
|
|||||||
#include "state.h"
|
#include "state.h"
|
||||||
#include "util.h"
|
#include "util.h"
|
||||||
|
|
||||||
/* Generated header */
|
/* Generated bytes */
|
||||||
#include <generated/core.h>
|
extern const unsigned char *janet_gen_core;
|
||||||
|
extern size_t janet_gen_core_size;
|
||||||
|
|
||||||
/* Use LoadLibrary on windows or dlopen on posix to load dynamic libaries
|
/* Use LoadLibrary on windows or dlopen on posix to load dynamic libaries
|
||||||
* with native code. */
|
* with native code. */
|
||||||
@ -809,7 +810,7 @@ JanetTable *janet_core_env(void) {
|
|||||||
janet_def(env, "_env", ret, "The environment table for the current scope.");
|
janet_def(env, "_env", ret, "The environment table for the current scope.");
|
||||||
|
|
||||||
/* Run bootstrap source */
|
/* Run bootstrap source */
|
||||||
janet_dobytes(env, janet_gen_core, sizeof(janet_gen_core), "core.janet", NULL);
|
janet_dobytes(env, janet_gen_core, janet_gen_core_size, "core.janet", NULL);
|
||||||
|
|
||||||
return env;
|
return env;
|
||||||
}
|
}
|
||||||
|
@ -21,10 +21,11 @@
|
|||||||
*/
|
*/
|
||||||
|
|
||||||
#include <janet/janet.h>
|
#include <janet/janet.h>
|
||||||
|
|
||||||
#include <generated/init.h>
|
|
||||||
#include "line.h"
|
#include "line.h"
|
||||||
|
|
||||||
|
extern const unsigned char *janet_gen_init;
|
||||||
|
extern size_t janet_gen_init_size;
|
||||||
|
|
||||||
int main(int argc, char **argv) {
|
int main(int argc, char **argv) {
|
||||||
int i, status;
|
int i, status;
|
||||||
JanetArray *args;
|
JanetArray *args;
|
||||||
@ -46,7 +47,7 @@ int main(int argc, char **argv) {
|
|||||||
janet_line_init();
|
janet_line_init();
|
||||||
|
|
||||||
/* Run startup script */
|
/* Run startup script */
|
||||||
status = janet_dobytes(env, janet_gen_init, sizeof(janet_gen_init), "init.janet", NULL);
|
status = janet_dobytes(env, janet_gen_init, janet_gen_init_size, "init.janet", NULL);
|
||||||
|
|
||||||
/* Deinitialize vm */
|
/* Deinitialize vm */
|
||||||
janet_deinit();
|
janet_deinit();
|
||||||
|
@ -36,6 +36,7 @@ int main(int argc, const char **argv) {
|
|||||||
static const char hex[] = "0123456789ABCDEF";
|
static const char hex[] = "0123456789ABCDEF";
|
||||||
char buf[BUFSIZE];
|
char buf[BUFSIZE];
|
||||||
size_t bytesRead = 0;
|
size_t bytesRead = 0;
|
||||||
|
size_t totalRead = 0;
|
||||||
int lineIndex = 0;
|
int lineIndex = 0;
|
||||||
int line = 0;
|
int line = 0;
|
||||||
|
|
||||||
@ -58,12 +59,13 @@ int main(int argc, const char **argv) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/* Write the header */
|
/* Write the header */
|
||||||
fprintf(out, "/* Auto generated - DO NOT EDIT */\n\n");
|
fprintf(out, "/* Auto generated - DO NOT EDIT */\n\n#include <stddef.h>\n\n");
|
||||||
fprintf(out, "static const unsigned char %s[] = {", argv[3]);
|
fprintf(out, "static const unsigned char bytes[] = {");
|
||||||
|
|
||||||
/* 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) {
|
||||||
size_t i;
|
size_t i;
|
||||||
|
totalRead += bytesRead;
|
||||||
for (i = 0; i < bytesRead; ++i) {
|
for (i = 0; i < bytesRead; ++i) {
|
||||||
int byte = ((uint8_t *)buf) [i];
|
int byte = ((uint8_t *)buf) [i];
|
||||||
|
|
||||||
@ -89,6 +91,11 @@ 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]);
|
||||||
|
|
||||||
|
/* Write chunk size */
|
||||||
|
fprintf(out, "size_t %s_size = %ld;\n", argv[3], totalRead);
|
||||||
|
|
||||||
/* Close the file handles */
|
/* Close the file handles */
|
||||||
fclose(in);
|
fclose(in);
|
||||||
fclose(out);
|
fclose(out);
|
||||||
|
@ -21,9 +21,11 @@
|
|||||||
*/
|
*/
|
||||||
|
|
||||||
#include <janet/janet.h>
|
#include <janet/janet.h>
|
||||||
#include <generated/webinit.h>
|
|
||||||
#include <emscripten.h>
|
#include <emscripten.h>
|
||||||
|
|
||||||
|
extern const unsigned char *janet_gen_webinit;
|
||||||
|
extern size_t janet_gen_webinit_size;
|
||||||
|
|
||||||
static JanetFiber *repl_fiber = NULL;
|
static JanetFiber *repl_fiber = NULL;
|
||||||
static JanetBuffer *line_buffer = NULL;
|
static JanetBuffer *line_buffer = NULL;
|
||||||
static const uint8_t *line_prompt = NULL;
|
static const uint8_t *line_prompt = NULL;
|
||||||
@ -78,7 +80,7 @@ void repl_init(void) {
|
|||||||
|
|
||||||
/* Run startup script */
|
/* Run startup script */
|
||||||
Janet ret;
|
Janet ret;
|
||||||
status = janet_dobytes(env, janet_gen_webinit, sizeof(janet_gen_webinit), "webinit.janet", &ret);
|
status = janet_dobytes(env, janet_gen_webinit, janet_gen_webinit_size, "webinit.janet", &ret);
|
||||||
if (status == JANET_SIGNAL_ERROR) {
|
if (status == JANET_SIGNAL_ERROR) {
|
||||||
printf("start up error.\n");
|
printf("start up error.\n");
|
||||||
janet_deinit();
|
janet_deinit();
|
||||||
|
Loading…
Reference in New Issue
Block a user