WIP: eval_rom in binary

This commit is contained in:
Yuichi Nishiwaki 2017-04-22 17:44:22 -07:00
parent 89667cf994
commit cfb732afaf
5 changed files with 4599 additions and 1727 deletions

View File

@ -34,7 +34,7 @@ include $(sort $(wildcard contrib/*/nitro.mk))
bootstrap: bin/picrin-bootstrap
bin/picrin-bootstrap:
test -f bin/picrin-bootstrap || { $(MAKE) -C lib lib/mini-picrin && mv lib/mini-picrin bin/picrin-bootstrap; }
test -f bin/picrin-bootstrap || { $(MAKE) -C lib mini-picrin && mv lib/mini-picrin bin/picrin-bootstrap; }
lib/mini-picrin: FORCE
$(MAKE) -C lib mini-picrin
@ -45,7 +45,7 @@ lib/libpicrin.a: FORCE
ext: lib/ext/eval.c
lib/ext/eval.c: piclib/eval.scm
bin/picrin-bootstrap -c piclib/eval.scm | bin/picrin-bootstrap tools/mkeval.scm > lib/ext/eval.c
bin/picrin-bootstrap -c eval_rom piclib/eval.scm | bin/picrin-bootstrap tools/mkeval.scm > lib/ext/eval.c
picrin: $(PICRIN_OBJS) $(CONTRIB_OBJS) ext lib/libpicrin.a
$(CC) $(CFLAGS) -o $@ $(PICRIN_OBJS) $(CONTRIB_OBJS) lib/libpicrin.a $(LDFLAGS)

File diff suppressed because it is too large Load Diff

View File

@ -9,12 +9,16 @@
static size_t offset = 0;
#define DUMP(c) do { printf("0x%02x, ", c); if (++offset == 12) { puts(""); offset = 0; } } while (0)
static void
dump1(pic_state *pic, unsigned char c)
{
DUMP(c);
printf("0x%02x,", c);
if (++offset == 12) {
puts("");
offset = 0;
} else {
putchar(' ');
}
}
static void

View File

@ -28,9 +28,6 @@
# define PIC_USE_FILE 1
#endif
#if !PIC_USE_READ && PIC_USE_EVAL
# error PIC_USE_EVAL requires PIC_USE_READ
#endif
#if !PIC_USE_LIBC && PIC_USE_FILE
# error PIC_USE_FILE requires PIC_USE_LIBC
#endif

View File

@ -1,66 +1,24 @@
(define (generate-rom)
(define open-output-string open-output-bytevector)
(define (get-output-string port)
(list->string (map integer->char (bytevector->list (get-output-bytevector port)))))
(define (with-output-to-string thunk)
(let ((port (open-output-string)))
(parameterize ((current-output-port port))
(thunk)
(let ((s (get-output-string port)))
(close-port port)
s))))
(define text
(with-output-to-string
(lambda ()
(write (read)))))
(define (escape-string s)
(with-output-to-string
(lambda ()
(string-for-each
(lambda (c)
(case c
((#\\) (display "\\\\"))
((#\") (display "\\\""))
((#\newline) (display "\\n"))
(else (display c))))
s))))
(define (group-string i s)
(let loop ((t s) (n (string-length s)) (acc '()))
(if (= n 0)
(reverse acc)
(if (< n i)
(loop "" 0 (cons t acc))
(loop (string-copy t i) (- n i) (cons (string-copy t 0 i) acc))))))
(define lines (map escape-string (group-string 80 text)))
(let loop ((lines lines) (acc ""))
(if (null? lines)
acc
(loop (cdr lines) (string-append acc "\"" (car lines) "\",\n")))))
(for-each
display
`("#include \"picrin.h\"\n"
"#include \"picrin/extra.h\"\n"
"\n"
"#if PIC_USE_EVAL\n"
"static const char eval_rom[][80] = {\n"
,(generate-rom)
"};\n"
"#endif\n"
"#if PIC_USE_EVAL\n"))
(let loop ()
(let ((c (read-u8)))
(unless (eof-object? c)
(write-u8 c)
(loop))))
(for-each
display
`("#endif\n"
"\n"
"void\n"
"pic_init_eval(pic_state *PIC_UNUSED(pic))\n"
"{\n"
"#if PIC_USE_EVAL\n"
" pic_load_native(pic, &eval_rom[0][0]);\n"
" pic_execute(pic, pic_deserialize(pic, eval_rom));\n"
"#endif\n"
"}\n"))