Skip to content

Commit

Permalink
Patch Tuesday - B
Browse files Browse the repository at this point in the history
  • Loading branch information
Wodan58 committed Mar 5, 2024
1 parent 59b114a commit df276f3
Show file tree
Hide file tree
Showing 31 changed files with 353 additions and 379 deletions.
9 changes: 4 additions & 5 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ Build|Linux|Windows|Coverity
status|[![GitHub CI build status](https://github.com/Wodan58/Joy/actions/workflows/cmake.yml/badge.svg)](https://github.com/Wodan58/Joy/actions/workflows/cmake.yml)|[![AppVeyor CI build status](https://ci.appveyor.com/api/projects/status/github/Wodan58/Joy?branch=master&svg=true)](https://ci.appveyor.com/project/Wodan58/Joy)|[![Coverity Scan Build Status](https://img.shields.io/coverity/scan/14641.svg)](https://scan.coverity.com/projects/wodan58-joy)

This is the NOBDW version of [Joy1](https://github.com/Wodan58/joy1).
The two versions are drifting apart.
[Joy](http://www.complang.tuwien.ac.at/anton/euroforth/ef01/thun01.pdf) is a
decent language and needs a ditto
[presentation](http://www.complang.tuwien.ac.at/anton/euroforth/ef01/thomas01a.pdf). The original version can be seen [here](https://github.com/Wodan58/joy0).
Expand Down Expand Up @@ -51,7 +50,7 @@ There is a copy of usrlib.joy in the build directory.
Testing
-------

cd test2
cd ../test2
for i in *.joy
do
../build/joy $i >$i.out
Expand All @@ -70,7 +69,7 @@ Implementation|Dependencies
[joy1](https://github.com/Wodan58/joy1)|[BDW garbage collector](https://github.com/ivmai/bdwgc)
[Moy](https://github.com/Wodan58/Moy)|[BDW garbage collector](https://github.com/ivmai/bdwgc) and [Lex & Yacc](https://sourceforge.net/projects/winflexbison/files/win_flex_bison-latest.zip)

Documentation
-------------

Documentation|
-------------|
[Legacy Docs](https://wodan58.github.io)
[User Manual](https://wodan58.github.io/j09imp.html)
4 changes: 2 additions & 2 deletions build/usrlib.joy
Original file line number Diff line number Diff line change
Expand Up @@ -63,12 +63,12 @@ END. (* end HIDE and LIBRA *)

"usrlib is loaded\n" putchars.

# standard-setting.
standard-setting.

"../lib/inilib.joy" include.
(* assuming inilib.joy was included: *)
"agglib" libload.

DEFINE verbose == true. (* Example of over-riding inilib.joy *)
DEFINE verbose == true. (* Example of over-riding inilib.joy *)

(* END usrlib.joy *)
8 changes: 1 addition & 7 deletions doc/JOYimplJOY.md
Original file line number Diff line number Diff line change
Expand Up @@ -34,11 +34,5 @@ savely be removed, as none of the test files in the lib-directory use them.
Comparison
==========

Comparing the different versions of joy is now the task of
Comparing the different versions of joy is the task of
[joyid.joy](https://github.com/Wodan58/Joy/blob/master/doc/joyid.joy).

Summary
=======

This updated version of Joy tries to stay as close to the legacy version as
possible.
16 changes: 8 additions & 8 deletions factor.c
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
/* FILE: factor.c */
/*
* module : factor.c
* version : 1.27
* date : 01/26/24
* version : 1.28
* date : 03/05/24
*/
#include "globals.h"

Expand Down Expand Up @@ -127,7 +127,7 @@ PUBLIC void writefactor(pEnv env, Index n, FILE *fp)
{
int i;
uint64_t set, j;
char *ptr, buf[BUFFERMAX], tmp[BUFFERMAX];
char *ptr, buf[MAXNUM], tmp[MAXNUM];

/*
This cannot happen. Factor has a small number of customers: writeterm,
Expand All @@ -136,22 +136,22 @@ PUBLIC void writefactor(pEnv env, Index n, FILE *fp)
*/
#if 0
if (!n)
execerror("non-empty stack", "print");
execerror("non-empty stack", "writefactor");
#endif
switch (nodetype(n)) {
case USR_:
fprintf(fp, "%s", vec_at(env->symtab, nodevalue(n).ent).name);
return;
case ANON_FUNCT_:
fprintf(fp, "%s", opername(operindex(nodevalue(n).proc)));
fprintf(fp, "%s", opername(operindex(env, nodevalue(n).proc)));
return;
case BOOLEAN_:
fprintf(fp, "%s", nodevalue(n).num ? "true" : "false");
return;
case CHAR_:
if (nodevalue(n).num >= 8 && nodevalue(n).num <= 13)
fprintf(fp, "'\\%c", "btnvfr"[nodevalue(n).num - 8]);
else if (iscntrl(nodevalue(n).num))
else if (iscntrl(nodevalue(n).num) || nodevalue(n).num == 32)
fprintf(fp, "'\\%03d", (int)nodevalue(n).num);
else
fprintf(fp, "'%c", (int)nodevalue(n).num);
Expand Down Expand Up @@ -206,15 +206,15 @@ PUBLIC void writefactor(pEnv env, Index n, FILE *fp)
return;
case FILE_:
if (!nodevalue(n).fil)
fprintf(fp, "file:NULL");
fprintf(fp, "file:NULL"); /* not a legal Joy factor */
else if (nodevalue(n).fil == stdin)
fprintf(fp, "stdin");
else if (nodevalue(n).fil == stdout)
fprintf(fp, "stdout");
else if (nodevalue(n).fil == stderr)
fprintf(fp, "stderr");
else
fprintf(fp, "file:%p", (void *)nodevalue(n).fil);
fprintf(fp, "file:%p", (void *)nodevalue(n).fil); /* no factor */
return;
case BIGNUM_:
fprintf(fp, "%s", nodevalue(n).str);
Expand Down
12 changes: 7 additions & 5 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.86
* date : 02/12/24
* version : 1.87
* date : 03/05/24
*/
#ifndef GLOBALS_H
#define GLOBALS_H
Expand Down Expand Up @@ -56,7 +56,8 @@
#define SHELLESCAPE '$'
#define INPSTACKMAX 10
#define INPLINEMAX 255
#define BUFFERMAX 80
#define BUFFERMAX 80 /* smaller buffer */
#define MAXNUM 32 /* even smaller buffer */
#define ALEN 42 /* module + '.' + member + \0 */
#define DISPLAYMAX 10 /* nesting in HIDE & MODULE */
#define INIECHOFLAG 0
Expand Down Expand Up @@ -163,11 +164,13 @@ typedef struct Token {
} Token;

KHASH_MAP_INIT_STR(Symtab, pEntry)
KHASH_MAP_INIT_INT64(Funtab, pEntry)

typedef struct Env {
vector(Token) *tokens; /* read ahead table */
vector(Entry) *symtab; /* symbol table */
khash_t(Symtab) *hash;
khash_t(Funtab) *prim;
#ifdef NOBDW
clock_t gc_clock;
vector(Node) *memory; /* dynamic memory */
Expand Down Expand Up @@ -195,7 +198,6 @@ typedef struct Env {
unsigned char undeferror;
unsigned char undeferror_set;
unsigned char tracegc;
unsigned char tracegc_set;
unsigned char debugging;
unsigned char ignore;
unsigned char statistics;
Expand All @@ -222,7 +224,7 @@ PUBLIC char *nickname(int ch);
PUBLIC char *opername(int o);
PUBLIC proc_t operproc(int o);
PUBLIC int operflags(int o);
PUBLIC int operindex(proc_t proc);
PUBLIC int operindex(pEnv env, proc_t proc);
/* factor.c */
PUBLIC int readfactor(pEnv env); /* read a JOY factor */
PUBLIC void readterm(pEnv env);
Expand Down
18 changes: 8 additions & 10 deletions interp.c
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
/* FILE: interp.c */
/*
* module : interp.c
* version : 1.79
* date : 02/12/24
* version : 1.80
* date : 03/05/24
*/

/*
Expand Down Expand Up @@ -556,16 +556,14 @@ PUBLIC int operflags(int o)
}

/*
operindex - return the optable entry for an operator; requires search.
operindex - return the optable entry for an operator.
*/
PUBLIC int operindex(proc_t proc)
PUBLIC int operindex(pEnv env, proc_t proc)
{
int i, size;
khiter_t key;

size = sizeof(optable) / sizeof(optable[0]);
for (i = size - 1; i > FILE_; i--)
if (optable[i].proc == proc)
return i;
return ANON_FUNCT_;
if ((key = kh_get(Funtab, env->prim, (int64_t)proc)) != kh_end(env->prim))
return kh_value(env->prim, key);
return ANON_FUNCT_; /* if not found, return the index of ANON_FUNCT_ */
}
/* END of INTERP.C */
4 changes: 2 additions & 2 deletions lib/usrlib.joy
Original file line number Diff line number Diff line change
Expand Up @@ -63,12 +63,12 @@ END. (* end HIDE and LIBRA *)

"usrlib is loaded\n" putchars.

# standard-setting.
standard-setting.

"../lib/inilib.joy" include.
(* assuming inilib.joy was included: *)
"agglib" libload.

DEFINE verbose == true. (* Example of over-riding inilib.joy *)
DEFINE verbose == true. (* Example of over-riding inilib.joy *)

(* END usrlib.joy *)
12 changes: 8 additions & 4 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.90
* date : 02/12/24
* version : 1.91
* date : 03/05/24
*/

/*
Expand Down Expand Up @@ -133,12 +133,15 @@ PRIVATE void inisymboltable(pEnv env) /* initialise */
khiter_t key;

env->hash = kh_init(Symtab);
env->prim = kh_init(Funtab);
for (i = 0; (ent.name = opername(i)) != 0; i++) {
ent.is_user = 0;
ent.flags = operflags(i);
ent.u.proc = operproc(i);
key = kh_put(Symtab, env->hash, ent.name, &rv);
kh_value(env->hash, key) = i;
key = kh_put(Funtab, env->prim, (int64_t)ent.u.proc, &rv);
kh_value(env->prim, key) = i;
vec_push(env->symtab, ent);
}
}
Expand Down Expand Up @@ -574,8 +577,9 @@ PRIVATE void unknown_opt(pEnv env, char *exe, int ch)
PRIVATE int my_main(int argc, char **argv)
{
static unsigned char mustinclude = 1;
char *ptr, *exe; /* exe: name of joy binary */

int i, j, ch;
char *ptr, *exe; /* exe: name of joy binary */
unsigned char helping = 0, unknown = 0;
#ifdef COPYRIGHT
unsigned char verbose = 1;
Expand All @@ -591,7 +595,6 @@ PRIVATE int my_main(int argc, char **argv)
* scan.c after reading EOF on the first input file.
*/
env.startclock = clock();
setbuf(stdout, 0);
#ifdef STATS
my_atexit(report_clock);
#endif
Expand Down Expand Up @@ -750,6 +753,7 @@ PRIVATE int my_main(int argc, char **argv)
options(&env);
if (unknown)
unknown_opt(&env, exe, unknown);
setbuf(stdout, 0); /* necessary when writing to a pipe */
setjmp(begin); /* return here after error or abort */
#ifdef NOBDW
inimem1(&env, 0); /* does not clear the stack */
Expand Down
Loading

0 comments on commit df276f3

Please sign in to comment.