shithub: femtolisp

Download patch

ref: f001b95402211734a1a6ac053e73fb4183ee7958
parent: 3ed9ff527d835053ec068ab90b8ee373aa99e4f1
author: Sigrid Solveig Haflínudóttir <sigrid@ftrv.se>
date: Fri Oct 25 21:41:01 EDT 2024

split main function into plan9 and posix ones to avoid using ifdefs (mostly)

--- a/Makefile
+++ b/Makefile
@@ -8,30 +8,6 @@
 LDFLAGS?=
 
 OBJS=\
-	flmain.o\
-	flisp.o\
-	builtins.o\
-	string.o\
-	equalhash.o\
-	table.o\
-	iostream.o\
-	operators.o\
-	cvalues.o\
-	read.o\
-	print.o\
-	equal.o\
-	types.o\
-	bitvector-ops.o\
-	bitvector.o\
-	dump.o\
-	hashing.o\
-	htable.o\
-	ios.o\
-	llt.o\
-	ptrhash.o\
-	random.o\
-	timefuncs.o\
-	utf8.o\
 	3rd/mp/mpadd.o\
 	3rd/mp/mpaux.o\
 	3rd/mp/mpcmp.o\
@@ -64,6 +40,31 @@
 	3rd/utf/runeistype.o\
 	3rd/utf/runetotype.o\
 	3rd/utf/utfnlen.o\
+	bitvector-ops.o\
+	bitvector.o\
+	builtins.o\
+	cvalues.o\
+	dump.o\
+	equal.o\
+	equalhash.o\
+	flisp.o\
+	flmain.o\
+	hashing.o\
+	htable.o\
+	ios.o\
+	iostream.o\
+	llt.o\
+	main_posix.o\
+	operators.o\
+	print.o\
+	ptrhash.o\
+	random.o\
+	read.o\
+	string.o\
+	table.o\
+	timefuncs.o\
+	types.o\
+	utf8.o\
 
 .PHONY: all default test bootstrap clean
 
@@ -82,7 +83,8 @@
 	${CC} -o $@ -c $< ${CFLAGS}
 
 flisp.o: flisp.c flisp.h operators.h cvalues.h maxstack.inc opcodes.h builtin_fns.h
-flmain.o: flmain.c boot.h flisp.h cvalues.h builtin_fns.h
+flmain.o: flmain.c boot.h flisp.h cvalues.h
+main_posix.o: main_posix.c builtin_fns.h
 3rd/utf/runeistype.o: 3rd/utf/runeistypedata
 3rd/utf/runetotype.o: 3rd/utf/runetotypedata
 
--- a/flmain.c
+++ b/flmain.c
@@ -20,12 +20,8 @@
 
 extern fltype_t *iostreamtype;
 
-#if defined(__plan9__)
-void
-#else
 int
-#endif
-main(int argc, char **argv)
+flmain(int argc, char **argv)
 {
 	static const char bootraw[] = {
 #include "boot.h"
@@ -34,12 +30,6 @@
 	ios_t *s;
 	int r;
 
-#if defined(__plan9__)
-	argv0 = argv[0];
-	setfcr(FPPDBL|FPRNR|FPOVFL);
-	tmfmtinstall();
-#endif
-
 	fl_init(512*1024);
 
 	f = cvalue(iostreamtype, sizeof(ios_t));
@@ -59,9 +49,5 @@
 		ios_putc('\n', ios_stderr);
 		break;
 	}
-#if defined(__plan9__)
-	exit(r);
-#else
 	return r;
-#endif
 }
--- /dev/null
+++ b/main_plan9.c
@@ -1,0 +1,12 @@
+#include "platform.h"
+
+int flmain(int argc, char **argv);
+
+void
+main(int argc, char **argv)
+{
+	argv0 = argv[0];
+	setfcr(FPPDBL|FPRNR|FPOVFL);
+	tmfmtinstall();
+	exit(flmain(argc, argv));
+}
--- /dev/null
+++ b/main_posix.c
@@ -1,0 +1,9 @@
+#include "platform.h"
+
+int flmain(int argc, char **argv);
+
+int
+main(int argc, char **argv)
+{
+	return flmain(argc, argv);
+}
--- a/mkfile
+++ b/mkfile
@@ -10,32 +10,33 @@
 	flisp.h\
 
 OFILES=\
+	3rd/mt19937-64.$O\
+	3rd/wcwidth.$O\
+	bitvector-ops.$O\
+	bitvector.$O\
 	builtins.$O\
+	cvalues.$O\
+	dump.$O\
+	equal.$O\
 	equalhash.$O\
 	flisp.$O\
 	flmain.$O\
-	iostream.$O\
-	string.$O\
-	table.$O\
-	operators.$O\
-	cvalues.$O\
-	read.$O\
-	print.$O\
-	equal.$O\
-	types.$O\
-	bitvector-ops.$O\
-	bitvector.$O\
-	dump.$O\
 	hashing.$O\
 	htable.$O\
 	ios.$O\
+	iostream.$O\
 	llt.$O\
+	main_plan9.$O\
+	operators.$O\
+	print.$O\
 	ptrhash.$O\
 	random.$O\
+	read.$O\
+	string.$O\
+	table.$O\
 	timefuncs.$O\
+	types.$O\
 	utf8.$O\
-	3rd/mt19937-64.$O\
-	3rd/wcwidth.$O\
 
 default:V: all
 
@@ -47,7 +48,7 @@
 builtin_fns.h:
 	sed -n 's/^BUILTIN[_]?(\(".*)/BUILTIN_FN\1/gp' *.c >$target
 
-flmain.$O: boot.h builtin_fns.h
+main_plan9.$O: boot.h builtin_fns.h
 flisp.$O: maxstack.inc opcodes.h builtin_fns.h
 
 %.$O: %.c