1
0
mirror of https://github.com/janet-lang/janet synced 2025-11-01 16:13:02 +00:00

Don't use generated headers for embedded janet

code, use object files.
This commit is contained in:
Calvin Rose
2018-12-06 14:30:11 -05:00
parent 97fade8197
commit 7668cd5772
8 changed files with 45 additions and 49 deletions

View File

@@ -728,7 +728,7 @@ static int cfun(JanetArgs args) {
static const JanetReg cfuns[] = {
{"compile", cfun,
"(compile ast)\n\n"
"(compile ast env [, source])\n\n"
"Compiles an Abstract Sytnax Tree (ast) into a janet function. "
"Pair the compile function with parsing functionality to implement "
"eval. Returns a janet function and does not modify ast. Throws an "

View File

@@ -25,8 +25,9 @@
#include "state.h"
#include "util.h"
/* Generated header */
#include <generated/core.h>
/* Generated bytes */
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
* with native code. */
@@ -809,7 +810,7 @@ JanetTable *janet_core_env(void) {
janet_def(env, "_env", ret, "The environment table for the current scope.");
/* 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;
}

View File

@@ -21,10 +21,11 @@
*/
#include <janet/janet.h>
#include <generated/init.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 i, status;
JanetArray *args;
@@ -46,7 +47,7 @@ int main(int argc, char **argv) {
janet_line_init();
/* 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 */
janet_deinit();

View File

@@ -36,6 +36,7 @@ int main(int argc, const char **argv) {
static const char hex[] = "0123456789ABCDEF";
char buf[BUFSIZE];
size_t bytesRead = 0;
size_t totalRead = 0;
int lineIndex = 0;
int line = 0;
@@ -58,12 +59,13 @@ int main(int argc, const char **argv) {
}
/* Write the header */
fprintf(out, "/* Auto generated - DO NOT EDIT */\n\n");
fprintf(out, "static const unsigned char %s[] = {", argv[3]);
fprintf(out, "/* Auto generated - DO NOT EDIT */\n\n#include <stddef.h>\n\n");
fprintf(out, "static const unsigned char bytes[] = {");
/* Read in chunks from buffer */
while ((bytesRead = fread(buf, 1, sizeof(buf), in)) > 0) {
size_t i;
totalRead += bytesRead;
for (i = 0; i < bytesRead; ++i) {
int byte = ((uint8_t *)buf) [i];
@@ -89,6 +91,11 @@ int main(int argc, const char **argv) {
/* Write the tail */
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 */
fclose(in);
fclose(out);

View File

@@ -21,9 +21,11 @@
*/
#include <janet/janet.h>
#include <generated/webinit.h>
#include <emscripten.h>
extern const unsigned char *janet_gen_webinit;
extern size_t janet_gen_webinit_size;
static JanetFiber *repl_fiber = NULL;
static JanetBuffer *line_buffer = NULL;
static const uint8_t *line_prompt = NULL;
@@ -78,7 +80,7 @@ void repl_init(void) {
/* Run startup script */
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) {
printf("start up error.\n");
janet_deinit();