Skip to content

Commit

Permalink
Patch Tuesday - J
Browse files Browse the repository at this point in the history
  • Loading branch information
Wodan58 committed Sep 3, 2024
1 parent c636686 commit 3b609df
Show file tree
Hide file tree
Showing 59 changed files with 1,028 additions and 200 deletions.
14 changes: 7 additions & 7 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
#
# module : CMakeLists.txt
# version : 1.27
# date : 06/21/24
# version : 1.30
# date : 08/31/24
#
cmake_minimum_required(VERSION 3.5)
project(Joy VERSION 1.0)
Expand All @@ -13,7 +13,7 @@ if("${CMAKE_BUILD_TYPE}" STREQUAL "Debug")
else()
option(RUN_TESTS "Run standard tests" OFF)
endif()
add_executable(joy main.c interp.c scan.c utils.c factor.c module.c optable.c symbol.c undefs.c)
add_executable(joy main.c interp.c scan.c utils.c factor.c module.c optable.c symbol.c undefs.c setraw.c)
add_definitions(-DLINK="\\"${CMAKE_EXE_LINKER_FLAGS}\\"")
add_definitions(-DVERS="BDW ${CMAKE_BUILD_TYPE} ${CMAKE_PROJECT_VERSION}")
#
Expand Down Expand Up @@ -52,8 +52,8 @@ else()
add_dependencies(joy always)
add_custom_target(always
WORKING_DIRECTORY ${CMAKE_SOURCE_DIR}
COMMAND sh table.sh .
COMMAND sh prims.sh .)
COMMAND sh prims.sh .
COMMAND sh table.sh .)
set(CF "-Wall -Wextra -Wpedantic -Werror -Wno-unused-parameter")
if("${CMAKE_BUILD_TYPE}" STREQUAL "Release")
set(CMAKE_C_FLAGS_RELEASE "${CMAKE_C_FLAGS_RELEASE} ${CF}")
Expand All @@ -66,8 +66,8 @@ else()
endif()
target_link_libraries(joy m gc)
if(RUN_TESTS)
add_subdirectory(test1)
add_subdirectory(test2)
add_subdirectory(lib)
add_subdirectory(test2)
add_subdirectory(test4)
endif()
endif()
2 changes: 2 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -49,3 +49,5 @@ Documentation|
-------------|
[Legacy Docs](https://wodan58.github.io)
[User Manual](https://wodan58.github.io/j09imp.html)
[Comparison (PDF)](https://github.com/Wodan58/HET/blob/master/doc/FIB.pdf)
[Maintenance Manual (PDF)](https://github.com/Wodan58/G3/blob/master/JOP.pdf)
20 changes: 14 additions & 6 deletions globals.h
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
/* FILE: globals.h */
/*
* module : globals.h
* version : 1.105
* date : 08/12/24
* version : 1.109
* date : 08/29/24
*/
#ifndef GLOBALS_H
#define GLOBALS_H
Expand All @@ -23,11 +23,17 @@
#include <inttypes.h>

#ifdef _MSC_VER
#define WINDOWS
#endif

#ifdef WINDOWS
#define WIN32_LEAN_AND_MEAN
#include <windows.h> /* pollute name space as much as possible */
#include <io.h> /* also import deprecated POSIX names */
#ifdef _MSC_VER
#pragma warning(disable: 4244 4267 4996)
#define kh_packed /* forget about __attribute__ ((packed)) */
#endif
#else
#include <unistd.h>
#include <termios.h>
Expand Down Expand Up @@ -234,9 +240,9 @@ typedef struct Env {
char *str; /* string */
clock_t startclock; /* main */
char **g_argv; /* command line */
char *homedir; /* HOME or USERPROFILE */
char *pathname; /* pathname of joy binary */
char *homedir; /* HOME or HOMEPATH */
char *mod_name; /* name of module */
vector(char *) *pathnames; /* pathnames to be searched when including */
vector(char) *string; /* value */
vector(char) *pushback; /* push back buffer */
vector(Token) *tokens; /* read ahead table */
Expand All @@ -252,7 +258,7 @@ typedef struct Env {
#ifdef NOBDW
clock_t gc_clock;
Node *memory; /* dynamic memory */
Index conts, dump, dump1, dump2, dump3, dump4, dump5;
Index conts, dump, dump1, dump2, dump3, dump4, dump5, inits;
#endif
Index prog, stck;
int g_argc; /* command line */
Expand Down Expand Up @@ -299,7 +305,7 @@ void fatal(char *str);
/* interp.c */
void exeterm(pEnv env, Index n);
/* scan.c */
void inilinebuffer(FILE *fp, char *str);
void inilinebuffer(pEnv env);
int getch(pEnv env);
void ungetch(int ch);
void error(char *str);
Expand Down Expand Up @@ -349,4 +355,6 @@ int enteratom(pEnv env, char *name);
int compound_def(pEnv env, int ch);
/* undefs.c */
void hide_inner_modules(pEnv env, int flag);
/* setraw.c */
void SetRaw(pEnv env);
#endif
1 change: 0 additions & 1 deletion joy.vim
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,6 @@ syntax match joySpecial /%INCLUDE/
syntax match joySpecial /%PUT/
syntax match joySpecial /%LISTING/
syntax match joySpecial /%TRACE/
syntax match joySpecial /%COMPILE/

if version >= 508 || !exists("did_joy_syntax_inits")
if version < 508
Expand Down
98 changes: 57 additions & 41 deletions main.c
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
/* FILE: main.c */
/*
* module : main.c
* version : 1.99
* date : 08/12/24
* version : 1.103
* date : 08/29/24
*/

/*
Expand Down Expand Up @@ -130,8 +130,7 @@ static jmp_buf begin; /* restart with empty program */

char *bottom_of_stack; /* needed in gc.c */

static void stats(pEnv env);
static void dump(pEnv env);
static void stats(pEnv env), dump(pEnv env);

/*
* abort execution and restart reading from srcfile; the stack is not cleared.
Expand All @@ -145,16 +144,14 @@ void abortexecution_(int num)
/*
* fatal terminates the application with an error message.
*/
#ifdef NOBDW
#ifdef _MSC_VER
#if defined(NOBDW) && defined(_MSC_VER)
void fatal(char *str)
{
fflush(stdout);
fprintf(stderr, "fatal error: %s\n", str);
abortexecution_(ABORT_QUIT);
}
#endif
#endif

/*
* options - print help on startup options and exit: options are those that
Expand Down Expand Up @@ -184,6 +181,7 @@ static void options(void)
printf(" -g : set the __tracegc flag (0-6)\n");
printf(" -h : print this help text and exit\n");
printf(" -i : ignore impure imperative functions\n");
printf(" -k : allow keyboard input in raw mode\n");
printf(" -l : do not read usrlib.joy at startup\n");
printf(" -p : print debug list of tokens\n");
printf(" -s : dump symbol table after execution\n");
Expand All @@ -206,35 +204,33 @@ static int my_main(int argc, char **argv)
{
static unsigned char psdump = 0, pstats = 0;
Env env; /* global variables */
FILE *srcfile;
int i, j, ch, flag;
char *filenam, *ptr, *tmp, *exe;
unsigned char mustinclude = 1, helping = 0, unknown = 0;
int i, j, ch;
char *ptr, *tmp, *exe;
unsigned char mustinclude = 1, helping = 0, unknown = 0, raw = 0,
flag, has_filename = 0;

memset(&env, 0, sizeof(env));
/*
* Start the clock.
*/
env.startclock = clock();
/*
* determine srcfile and filenam; they are stored in inilinebuffer.
*/
srcfile = stdin;
filenam = "stdin";
/*
* establish pathname, to be used when loading libraries, and basename.
* store the directory where the Joy binary is located in the list of
* pathnames to be used when including files. argv[0] is modified such
* that it contains only the basename.
*/
env.pathname = ".";
ptr = strrchr(exe = argv[0], '/');
#ifdef _MSC_VER
vec_init(env.pathnames);
ptr = strrchr(argv[0], '/');
#ifdef WINDOWS
if (!ptr)
ptr = strrchr(argv[0], '\\');
#endif
if (ptr) {
env.pathname = argv[0]; /* split argv[0] in pathname */
*ptr++ = 0;
argv[0] = exe = ptr; /* and basename */
vec_push(env.pathnames, argv[0]);
*ptr++ = 0; /* split in directory */
argv[0] = ptr; /* and basename */
}
exe = argv[0]; /* Joy binary */
/*
* These flags are initialized here, allowing them to be overruled by the
* command line. When set on the command line, they can not be overruled
Expand Down Expand Up @@ -268,6 +264,7 @@ static int my_main(int argc, char **argv)
break;
case 'h' : helping = 1; break;
case 'i' : env.ignore = 1; break;
case 'k' : raw = 1; break; /* terminal raw mode */
case 'l' : mustinclude = 0; break;
case 'p' : env.printing = 1; break;
case 's' : psdump = 1; break;
Expand Down Expand Up @@ -298,24 +295,29 @@ static int my_main(int argc, char **argv)
for (i = 1; i < argc; i++) {
ch = argv[i][0];
if (!isdigit(ch)) {
if ((srcfile = fopen(filenam = argv[i], "r")) == 0) {
fprintf(stderr, "failed to open the file '%s'.\n", filenam);
/*
* The first file should also benefit from include logic.
*/
if (include(&env, argv[i])) {
fprintf(stderr, "failed to open the file '%s'.\n", argv[i]);
return 0;
}
has_filename = 1;
/*
* Overwrite argv[0] with the filename and shift subsequent
* parameters.
*/
if ((ptr = strrchr(argv[0] = filenam, '/')) != 0) {
if ((ptr = strrchr(argv[0] = argv[i], '/')) != 0) {
*ptr++ = 0;
argv[0] = filenam = ptr; /* basename */
argv[0] = ptr; /* Joy program basename */
}
for (--argc; i < argc; i++)
argv[i] = argv[i + 1];
break; /* only one filename */
goto start; /* only one filename; replaces stdin */
} /* end if */
} /* end for */
inilinebuffer(srcfile, filenam);
inilinebuffer(&env); /* initialize with stdin */
start:
/*
* determine argc and argv.
*/
Expand All @@ -333,30 +335,42 @@ static int my_main(int argc, char **argv)
*/
inisymboltable(&env);
/*
* handle options, might print symbol table.
* initialize stack before SetRaw.
*/
if (helping || unknown) {
helping ? options() : opt_unknown(exe, unknown);
goto einde;
}
#ifdef NOBDW
inimem1(&env, 0); /* does not clear the stack */
inimem2(&env);
#endif
/*
* initialize standard output.
*/
setbuf(stdout, 0); /* necessary when writing to a pipe */
if (raw && has_filename) { /* raw requires a filename */
env.autoput = 0; /* disable autoput in usrlib.joy */
env.autoput_set = 1; /* prevent enabling autoput */
SetRaw(&env); /* keep output buffered */
#ifdef NOBDW
env.inits = env.stck; /* remember initial stack */
inimem2(&env); /* store initial stack in definition space */
#endif
} else
setbuf(stdout, 0); /* disable output buffering (pipe) */
/*
* read initial library.
*/
if (mustinclude)
include(&env, "usrlib.joy");
/*
* handle options, might print symbol table.
*/
if (helping || unknown) {
helping ? options() : opt_unknown(exe, unknown);
goto einde;
}
/*
* setup return address of error, abort, or quit.
*/
if (setjmp(begin) == ABORT_QUIT)
goto einde; /* return here after error or abort */
#ifdef NOBDW
inimem1(&env, 0); /* does not clear the stack */
inimem2(&env);
#endif
/*
* (re)initialize code.
*/
Expand All @@ -367,7 +381,7 @@ static int my_main(int argc, char **argv)
if (env.sym == LIBRA || env.sym == HIDE || env.sym == MODULE_ ||
env.sym == CONST_) {
#ifdef NOBDW
inimem1(&env, 1); /* also clears the stack */
inimem1(&env, 1); /* also resets the stack to initial */
#endif
if ((flag = env.sym == MODULE_) != 0)
hide_inner_modules(&env, 1);
Expand Down Expand Up @@ -415,8 +429,10 @@ static int my_main(int argc, char **argv)
env.stck = nextnode1(env.stck);
#endif
}
if (env.autoput)
if (env.autoput) {
putchar('\n');
fflush(stdout);
}
}
}
}
Expand Down
6 changes: 3 additions & 3 deletions makefile
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
#
# module : makefile
# version : 1.11
# date : 03/26/24
# version : 1.12
# date : 08/28/24
#
.POSIX:
.SUFFIXES:
Expand All @@ -12,7 +12,7 @@ LF = -lm -lgc
CFLAGS = $(CF) -DCOMP="\"$(CF)\"" -DLINK="\"$(LF)\"" -DVERS="\"BDW Release 1.0\""
HDRS = globals.h
OBJS = main.o interp.o scan.o utils.o factor.o module.o optable.o symbol.o \
undefs.o
undefs.o setraw.o

joy: prep $(OBJS)
$(CC) -o$@ $(OBJS) $(LF)
Expand Down
Loading

0 comments on commit 3b609df

Please sign in to comment.