shithub: femtolisp

Download patch

ref: 2b3838fc4a8d7c8073eff77b0ee4ee05ea4746a5
parent: c186019e2661ec8b8c301e5d7dc1bcd99f71f48c
author: Sigrid Solveig Haflínudóttir <sigrid@ftrv.se>
date: Wed Dec 11 21:18:37 EST 2024

split opcodes.h into header and C file

--- a/equal.c
+++ b/equal.c
@@ -1,6 +1,5 @@
 #include "flisp.h"
 #include "operators.h"
-#include "opcodes.h"
 #include "cvalues.h"
 #include "equal.h"
 #include "hashing.h"
--- a/flisp.c
+++ b/flisp.c
@@ -8,7 +8,6 @@
 #include "flisp.h"
 #include "operators.h"
 #include "cvalues.h"
-#include "opcodes.h"
 #include "types.h"
 #include "print.h"
 #include "read.h"
--- a/flisp.h
+++ b/flisp.h
@@ -326,6 +326,8 @@
 #include "builtin_fns.h"
 #undef BUILTIN_FN
 
+#include "opcodes.h"
+
 #define N_GC_HANDLES 1024
 
 typedef struct Fl Fl;
--- a/gen.lsp
+++ b/gen.lsp
@@ -104,6 +104,7 @@
                                          (for-each-n f (list-tail lst n) n))))
 
 (let ((c-header     (file "opcodes.h"        :write :create :truncate))
+      (c-code       (file "opcodes.c"        :write :create :truncate))
       (instructions (file "instructions.lsp" :write :create :truncate))
       (builtins     (file "builtins.lsp"     :write :create :truncate))
       (e (table))
@@ -127,18 +128,21 @@
           (set! i (1+ i))))
       opcodes 4)
     (io-write c-header "\tN_OPCODES\n};\n\n")
-    (io-write c-header "static const Builtin builtins[] = {\n")
+    (io-write c-header "extern const Builtin builtins[N_OPCODES];\n")
+    (io-close c-header)
+    (io-write c-code "#include \"flisp.h\"\n\n")
+    (io-write c-code "const Builtin builtins[N_OPCODES] = {\n")
     (for-each
-      (λ (c la) (begin (io-write c-header "\t[")
-                       (write c c-header)
-                       (io-write c-header "] = {\"")
-                       (write (car la) c-header)
-                       (io-write c-header "\", ")
-                       (write (cadr la) c-header)
-                       (io-write c-header "},\n")))
+      (λ (c la) (begin (io-write c-code "\t[")
+                       (write c c-code)
+                       (io-write c-code "] = {\"")
+                       (write (car la) c-code)
+                       (io-write c-code "\", ")
+                       (write (cadr la) c-code)
+                       (io-write c-code "},\n")))
       cl)
-    (io-write c-header "};\n")
-    (io-close c-header)
+    (io-write c-code "};\n")
+    (io-close c-code)
 
     (write `(define Instructions ,e) instructions)
     (io-write instructions "\n\n")
--- a/meson.build
+++ b/meson.build
@@ -47,6 +47,7 @@
 	'ios.c',
 	'iostream.c',
 	'main_posix.c',
+	'opcodes.c',
 	'operators.c',
 	'print.c',
 	'ptrhash.c',
--- a/mkfile
+++ b/mkfile
@@ -8,6 +8,7 @@
 HFILES=\
 	equalhash.h\
 	flisp.h\
+	opcodes.h\
 	plan9/platform.h\
 
 OFILES=\
@@ -27,6 +28,7 @@
 	ios.$O\
 	iostream.$O\
 	main_plan9.$O\
+	opcodes.$O\
 	operators.$O\
 	print.$O\
 	ptrhash.$O\
@@ -48,7 +50,7 @@
 		`{ls `{echo $OFILES | sed 's/\.'$O'/.c/g'} >[2]/dev/null} | sort >$target
 
 cvalues.$O: fl_arith_any.inc
-flisp.$O: maxstack.inc opcodes.h
+flisp.$O: maxstack.inc
 
 plan9/flisp.boot.s:D: flisp.boot
 	aux/data2s boot <flisp.boot >$target
--- /dev/null
+++ b/opcodes.c
@@ -1,0 +1,39 @@
+#include "flisp.h"
+
+const Builtin builtins[N_OPCODES] = {
+	[OP_SETCAR] = {"set-car!", 2},
+	[OP_CDR] = {"cdr", 1},
+	[OP_BOOLEANP] = {"boolean?", 1},
+	[OP_FUNCTIONP] = {"function?", 1},
+	[OP_CADR] = {"cadr", 1},
+	[OP_SETCDR] = {"set-cdr!", 2},
+	[OP_EQ] = {"eq?", 2},
+	[OP_APPLY] = {"apply", -2},
+	[OP_NULLP] = {"null?", 1},
+	[OP_ASET] = {"aset!", -3},
+	[OP_ATOMP] = {"atom?", 1},
+	[OP_NOT] = {"not", 1},
+	[OP_LIST] = {"list", ANYARGS},
+	[OP_CONS] = {"cons", 2},
+	[OP_NUMBERP] = {"number?", 1},
+	[OP_BOUNDP] = {"bound?", 1},
+	[OP_LT] = {"<", 2},
+	[OP_VECTORP] = {"vector?", 1},
+	[OP_CAR] = {"car", 1},
+	[OP_EQV] = {"eqv?", 2},
+	[OP_IDIV] = {"div0", 2},
+	[OP_FIXNUMP] = {"fixnum?", 1},
+	[OP_NUMEQ] = {"=", 2},
+	[OP_SYMBOLP] = {"symbol?", 1},
+	[OP_BUILTINP] = {"builtin?", 1},
+	[OP_SUB] = {"-", -1},
+	[OP_COMPARE] = {"compare", 2},
+	[OP_PAIRP] = {"pair?", 1},
+	[OP_MUL] = {"*", ANYARGS},
+	[OP_FOR] = {"for", 3},
+	[OP_ADD] = {"+", ANYARGS},
+	[OP_AREF] = {"aref", -2},
+	[OP_DIV] = {"/", -1},
+	[OP_VECTOR] = {"vector", ANYARGS},
+	[OP_EQUAL] = {"equal?", 2},
+};
--- a/opcodes.h
+++ b/opcodes.h
@@ -99,40 +99,4 @@
 	N_OPCODES
 };
 
-static const Builtin builtins[] = {
-	[OP_SETCAR] = {"set-car!", 2},
-	[OP_CDR] = {"cdr", 1},
-	[OP_BOOLEANP] = {"boolean?", 1},
-	[OP_FUNCTIONP] = {"function?", 1},
-	[OP_CADR] = {"cadr", 1},
-	[OP_SETCDR] = {"set-cdr!", 2},
-	[OP_EQ] = {"eq?", 2},
-	[OP_APPLY] = {"apply", -2},
-	[OP_NULLP] = {"null?", 1},
-	[OP_ASET] = {"aset!", -3},
-	[OP_ATOMP] = {"atom?", 1},
-	[OP_NOT] = {"not", 1},
-	[OP_LIST] = {"list", ANYARGS},
-	[OP_CONS] = {"cons", 2},
-	[OP_NUMBERP] = {"number?", 1},
-	[OP_BOUNDP] = {"bound?", 1},
-	[OP_LT] = {"<", 2},
-	[OP_VECTORP] = {"vector?", 1},
-	[OP_CAR] = {"car", 1},
-	[OP_EQV] = {"eqv?", 2},
-	[OP_IDIV] = {"div0", 2},
-	[OP_FIXNUMP] = {"fixnum?", 1},
-	[OP_NUMEQ] = {"=", 2},
-	[OP_SYMBOLP] = {"symbol?", 1},
-	[OP_BUILTINP] = {"builtin?", 1},
-	[OP_SUB] = {"-", -1},
-	[OP_COMPARE] = {"compare", 2},
-	[OP_PAIRP] = {"pair?", 1},
-	[OP_MUL] = {"*", ANYARGS},
-	[OP_FOR] = {"for", 3},
-	[OP_ADD] = {"+", ANYARGS},
-	[OP_AREF] = {"aref", -2},
-	[OP_DIV] = {"/", -1},
-	[OP_VECTOR] = {"vector", ANYARGS},
-	[OP_EQUAL] = {"equal?", 2},
-};
+extern const Builtin builtins[N_OPCODES];
--- a/print.c
+++ b/print.c
@@ -1,6 +1,5 @@
 #include "flisp.h"
 #include "operators.h"
-#include "opcodes.h"
 #include "cvalues.h"
 #include "ieee754.h"
 #include "print.h"