home: hub: 9ficl

Download patch

ref: 5ca05d32e742d1c43a4abe4ece7bcbe1581f9d3c
parent: 2b5a6794ca492530d5d2fb7ae9d5bd47c3d8c03b
author: grobe0ba <grobe0ba@tcp80.org>
date: Tue Aug 2 08:09:00 CDT 2022

ficl for 9front

--- a/Makefile
+++ b/Makefile
@@ -1,5 +1,5 @@
 SRCDIR=	.
-VPATH=	$(SRCDIR):$(SRCDIR)/softcore
+VPATH=	${SRCDIR}:${SRCDIR}/softcore
 # core:
 OBJECTS= dictionary.o system.o fileaccess.o float.o double.o prefix.o search.o softcore.o stack.o tools.o vm.o primitives.o bit.o lzuncompress.o utility.o hash.o callback.o word.o extras.o $(OBJECTS.$(platform))
 HEADERS= ficl.h $(HEADERS.$(platform))
@@ -13,7 +13,7 @@
 #
 # Flags for shared library
 SHFLAGS = -fPIC
-CFLAGS= $(CFLAGS.$(platform)) -O $(SHFLAGS) -Wall
+CFLAGS= $(CFLAGS.$(platform)) -O ${SHFLAGS} -Wall
 CPPFLAGS= $(CPPFLAGS.$(platform)) -I.
 # Platform dependent flags:
 CFLAGS.unix=	# empty
@@ -23,9 +23,9 @@
 # Default platform is "unix"
 platform=	unix
 #
-CC = cc
+CC = pcc
 LIB = ar cr
-RANLIB = ranlib
+RANLIB = echo
 
 MAJOR = 4
 MINOR = 1.0
@@ -38,35 +38,35 @@
 test:
 	wd="$$(pwd)"; cd test && "$${wd}"/ficl ficltest.fr < /dev/null
 
-ficl: main.o $(HEADERS) libficl.a
-	$(CC) $(CFLAGS) $(LDFLAGS) -o $@ main.o -L. -lficl -lm
+ficl: main.o ${HEADERS} libficl.a
+	${CC} ${CFLAGS} ${LDFLAGS} -o $@ main.o -L. -lficl -lm
 
-lib: libficl.so.$(MAJOR).$(MINOR)
+lib: libficl.so.${MAJOR}.${MINOR}
 
 # static library build
-libficl.a: $(OBJECTS)
-	$(LIB) libficl.a $(OBJECTS)
-	$(RANLIB) libficl.a
+libficl.a: ${OBJECTS}
+	${LIB} libficl.a ${OBJECTS}
+	${RANLIB} libficl.a
 
 # shared library build
-libficl.so.$(MAJOR).$(MINOR): $(OBJECTS)
-	$(CC) $(LDFLAGS) -shared -Wl,-soname,$@ -o $@ $(OBJECTS)
-	ln -sf libficl.so.$(MAJOR).$(MINOR) libficl.so
+libficl.so.${MAJOR}.${MINOR}: ${OBJECTS}
+	${CC} ${LDFLAGS} -shared -Wl,-soname,$@ -o $@ ${OBJECTS}
+	ln -sf libficl.so.${MAJOR}.${MINOR} libficl.so
 
-main: main.o ficl.h sysdep.h libficl.so.$(MAJOR).$(MINOR)
-	$(CC) $(CFLAGS) $(LDFLAGS) -o $@ main.o -L. -lficl -lm
-	ln -sf libficl.so.$(MAJOR).$(MINOR) libficl.so.$(MAJOR)
+main: main.o ficl.h sysdep.h libficl.so.${MAJOR}.${MINOR}
+	${CC} ${CFLAGS} ${LDFLAGS} -o $@ main.o -L. -lficl -lm
+	ln -sf libficl.so.${MAJOR}.${MINOR} libficl.so.${MAJOR}
 
 # depend explicitly to help finding source files in another subdirectory,
 # and repeat commands since gmake doesn't understand otherwise
-ansi.o: ficlplatform/ansi.c $(HEADERS)
-	$(CC) $(CFLAGS) $(CPPFLAGS) -c -o $@ $<
-unix.o: ficlplatform/unix.c $(HEADERS)
-	$(CC) $(CFLAGS) $(CPPFLAGS) -c -o $@ $<
+ansi.o: ficlplatform/ansi.c ${HEADERS}
+	${CC} ${CFLAGS} ${CPPFLAGS} -c -o $@ $<
+unix.o: ficlplatform/unix.c ${HEADERS}
+	${CC} ${CFLAGS} ${CPPFLAGS} -c -o $@ $<
 
 # generate softcore source
-softcore.c: $(SOURCES)
-	(cd softcore && exec $(MAKE) softcore.c) && cp softcore/softcore.c .
+softcore.c: ${SOURCES}
+	(cd softcore && exec ${MAKE} softcore.c) && cp softcore/softcore.c .
 
 #
 #       generic object code
@@ -74,13 +74,13 @@
 .SUFFIXES: .cxx .cc .c .o
 
 .c.o:
-	$(CC) $(CFLAGS) $(CPPFLAGS) -c -o $@ $<
+	${CC} ${CFLAGS} ${CPPFLAGS} -c -o $@ $<
 
 .cxx.o:
-	$(CXX) $(CXXFLAGS) $(CPPFLAGS) -c -o $@ $<
+	${CXX} ${CXXFLAGS} ${CPPFLAGS} -c -o $@ $<
 
 .cc.o:
-	$(CXX) $(CXXFLAGS) $(CPPFLAGS) -c -o $@ $<
+	${CXX} ${CXXFLAGS} ${CPPFLAGS} -c -o $@ $<
 #
 #       generic cleanup code
 #
--- a/ficl.h
+++ b/ficl.h
@@ -163,7 +163,7 @@
 	#include "ficlplatform/ansi.h"
 #elif defined(_WIN32)
 	#include "ficlplatform/win32.h"
-#elif defined(unix) || defined(__unix__) || defined(__unix)
+#elif defined(unix) || defined(__unix__) || defined(__unix) || defined(__plan9__)
 	#include "ficlplatform/unix.h"
 #else /* catch-all */
 	#include "ficlplatform/ansi.h"
@@ -212,7 +212,7 @@
 ** (see ficlplatform/win32.c and ficlplatform/unix.c for example)
 */
 #if !defined (FICL_WANT_PLATFORM)
-#define FICL_WANT_PLATFORM (0)
+#define FICL_WANT_PLATFORM (1)
 #endif /* FICL_WANT_PLATFORM */
 
 
@@ -287,7 +287,7 @@
 ** and prefix.fr (if included as part of softcore.c)
 */
 #if !defined FICL_WANT_EXTENDED_PREFIX
-#define FICL_WANT_EXTENDED_PREFIX (0)
+#define FICL_WANT_EXTENDED_PREFIX (1)
 #endif /* FICL_WANT_EXTENDED_PREFIX */
 
 /*
@@ -389,7 +389,7 @@
 ** String constant describing the current operating system.
 */
 #if !defined (FICL_PLATFORM_OS)
-#define FICL_PLATFORM_OS              "unknown"
+#define FICL_PLATFORM_OS              "plan9"
 #endif
 
 /*
@@ -437,7 +437,7 @@
 ** in the absence of another keyword.
 */
 #if !defined FICL_PLATFORM_INLINE
-#define FICL_PLATFORM_INLINE static
+#define FICL_PLATFORM_INLINE static inline
 #endif /* !defined FICL_PLATFORM_INLINE */
 
 /*
--- a/ficlplatform/unix.c
+++ b/ficlplatform/unix.c
@@ -8,7 +8,9 @@
 
 int ficlFileTruncate(ficlFile *ff, ficlUnsigned size)
 {
-	return ftruncate(fileno(ff->f), size);
+	errno = EIO;
+	return -1;
+	/* return ftruncate(fileno(ff->f), size); */
 }
 
 
@@ -31,10 +33,12 @@
 void  ficlCallbackDefaultTextOut(ficlCallback *callback, char *message)
 {
     FICL_IGNORE(callback);
-    if (message != NULL)
-        fputs(message, stdout);
-    else
+    if (message != NULL) {
+        printf("%s", message);
         fflush(stdout);
+    } else {
+        fflush(stdout);
+    }
     return;
 }
 
--- a/ficlplatform/unix.h
+++ b/ficlplatform/unix.h
@@ -3,9 +3,13 @@
 
 
 #define FICL_WANT_PLATFORM (1)
-
-#define FICL_PLATFORM_OS              "unix"
-#define FICL_PLATFORM_ARCHITECTURE    "unknown"
+#define FICL_WANT_FILE (1)
+#define FICL_WANT_FLOAT (1)
+#define FICL_WANT_LOCALS (1)
+#define FICL_WANT_OOP (1)
+#define FICL_WANT_SOFTWORDS (1)
+#define FICL_WANT_EXTENDED_PREFIX (1)
+#define FICL_WANT_USER (1)
 
 #define FICL_PLATFORM_BASIC_TYPES     (1)
 #if defined(__amd64__) || defined(__alpha__)
--- a/fileaccess.c
+++ b/fileaccess.c
@@ -3,6 +3,7 @@
 #include <stdio.h>
 #include <string.h>
 #include <ctype.h>
+#include <unistd.h>
 #include "ficl.h"
 
 #if FICL_WANT_FILE
--- a/lzcompress.c
+++ b/lzcompress.c
@@ -118,7 +118,7 @@
 	if (compressed == NULL)
 		return -1;
 
-	window = buffer = uncompressed;
+	window = buffer = (const unsigned char*)uncompressed;
 
 	outputPosition = 0;
 	remaining = uncompressedSize;
--- a/main.c
+++ b/main.c
@@ -67,7 +67,8 @@
 
     while (returnValue != FICL_VM_STATUS_USER_EXIT)
     {
-        fputs(FICL_PROMPT, stdout);
+        printf("%s", FICL_PROMPT);
+        fflush(stdout);
         if (fgets(buffer, sizeof(buffer), stdin) == NULL) break;
         returnValue = ficlVmEvaluate(vm, buffer);
     }
--- /dev/null
+++ b/mkfile
@@ -1,0 +1,15 @@
+none:VQ:
+	echo usage: mk all, install, clean
+
+all:V: lib bin
+
+bin:V: lib
+	mk -f mkfile.bin install
+
+lib:V:
+	mk -f mkfile.lib install
+
+clean:
+	cd softcore && mk clean && cd ..
+	mk -f mkfile.bin clean
+	mk -f mkfile.lib clean
--- /dev/null
+++ b/mkfile.bin
@@ -1,0 +1,23 @@
+</$objtype/mkfile
+
+CFLAGS=-I. -D__amd64__ -D__plan9__ -DFICL_PLATFORM_ARCHITECTURE="$objtype" -D_POSIX_SOURCE -D_SUSV2_SOURCE
+CC=pcc
+
+BIN=ficl
+
+OFILES=\
+	main.$O
+
+all:V: $O.out
+
+install:V: $O.out
+	cp $O.out ficl
+
+$O.out: main.$O
+	$LD -o $target $OFILES libficl.a
+
+%.$O: %.c
+	pcc $CFLAGS -c -o $target $stem.c
+
+clean:V:
+	rm -f ficl main.$O $O.out
--- /dev/null
+++ b/mkfile.lib
@@ -1,0 +1,45 @@
+</$objtype/mkfile
+
+CFLAGS=-I. -D__amd64__ -D__plan9__ -DFICL_PLATFORM_ARCHITECTURE="$objtype" -D_POSIX_SOURCE -D_SUSV2_SOURCE
+CC=pcc
+
+LIB=libficl.a
+
+OFILES=\
+	dictionary.$O\
+	system.$O\
+	fileaccess.$O\
+	float.$O\
+	double.$O\
+	prefix.$O\
+	search.$O\
+	softcore.$O\
+	stack.$O\
+	tools.$O\
+	vm.$O\
+	primitives.$O\
+	bit.$O\
+	lzuncompress.$O\
+	utility.$O\
+	hash.$O\
+	callback.$O\
+	word.$O\
+	extras.$O\
+	unix.$O
+
+HFILES=\
+	ficlplatform/unix.h
+
+CLEANFILES=libficl.a
+
+</sys/src/cmd/mklib
+
+%.$O: %.c
+	pcc $CFLAGS -c -o $target $stem.c
+
+softcore.$O:
+	cd softcore && mk && cd ..
+	$CC $CFLAGS -c -o softcore.$O softcore/softcore.c
+
+unix.$O:
+	$CC $CFLAGS -Ificlplatform -c -o unix.$O ficlplatform/unix.c
--- a/primitives.c
+++ b/primitives.c
@@ -3509,9 +3509,9 @@
     /*
     ** Set up system's outer interpreter loop - maybe this should be in initSystem?
     */
-	system->interpreterLoop[0] = interpret;
-	system->interpreterLoop[1] = (ficlWord *)ficlInstructionBranchParen;
-	system->interpreterLoop[2] = (ficlWord *)(void *)(-2);
+	system->interpreterLoop[0] = (ficlInstruction)interpret;
+	system->interpreterLoop[1] = (ficlInstruction)ficlInstructionBranchParen;
+	system->interpreterLoop[2] = (ficlInstruction)(void *)(-2);
 
     FICL_SYSTEM_ASSERT(system, ficlDictionaryCellsAvailable(dictionary) > 0);
 
--- a/softcore/makesoftcore.c
+++ b/softcore/makesoftcore.c
@@ -203,7 +203,7 @@
 	fprintf(f, "#else /* !FICL_WANT_LZ_SOFTCORE */\n");
 	fprintf(f, "\n");
 	fprintf(f, "static unsigned char ficlSoftcoreCompressed[%d] = {\n", compressedSize);
-	fprintDataAsHex(f, compressed, compressedSize);
+	fprintDataAsHex(f, (char*)compressed, compressedSize);
 	fprintf(f, "\t};\n");
 	fprintf(f, "\n");
 	fprintf(f, "#endif /* !FICL_WANT_LZ_SOFTCORE */\n");
--- /dev/null
+++ b/softcore/mkfile
@@ -1,0 +1,35 @@
+</$cputype/mkfile
+
+SOURCES=\
+	softcore.fr\
+	ifbrack.fr\
+	prefix.fr\
+	prefix.fr\
+	ficl.fr\
+	jhlocal.fr\
+	marker.fr\
+	oo.fr\
+	classes.fr\
+	string.fr\
+	ficllocal.fr\
+	fileaccess.fr
+
+CC=pcc
+
+softcore.c: makesoftcore
+	makesoftcore $SOURCES
+
+makesoftcore: makesoftcore.$O lzcompress.$O bit.$O
+	$LD -o $target $prereq
+
+makesoftcore.$O: makesoftcore.c
+	objtype=$cputype $CC -I.. -c -o $target $prereq
+
+lzcompress.$O: ../lzcompress.c
+	objtype=$cputype $CC -I.. -c -o $target $prereq
+
+bit.$O: ../bit.c
+	objtype=$cputype $CC -I.. -c -o $target $prereq
+
+clean:
+	rm -f *.$O makesoftcore softcore.c
--- a/vm.c
+++ b/vm.c
@@ -2733,7 +2733,7 @@
         }
         else
         {   /* set VM up to interpret text */
-            ficlVmPushIP(vm, &(system->interpreterLoop[0]));
+            ficlVmPushIP(vm, (ficlWord**)&(system->interpreterLoop[0]));
         }
 
         ficlVmInnerLoop(vm, 0);