Skip to content

Commit

Permalink
Patch Tuesday - L
Browse files Browse the repository at this point in the history
  • Loading branch information
Wodan58 committed Oct 15, 2024
1 parent 5462a26 commit 4b7cf6d
Show file tree
Hide file tree
Showing 94 changed files with 1,075 additions and 759 deletions.
7 changes: 4 additions & 3 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
#
# module : CMakeLists.txt
# version : 1.40
# date : 09/24/24
# version : 1.43
# date : 10/11/24
#
cmake_minimum_required(VERSION 3.5)
project(Joy VERSION 1.0)
Expand All @@ -14,7 +14,8 @@ else()
option(RUN_TEST "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 setraw.c repl.c write.c error.c print.c)
symbol.c undefs.c setraw.c repl.c write.c error.c print.c
)
add_definitions(-DLINK="\\"${CMAKE_EXE_LINKER_FLAGS}\\"")
add_definitions(-DVERS="BDW ${CMAKE_BUILD_TYPE} ${CMAKE_PROJECT_VERSION}")
#
Expand Down
5 changes: 1 addition & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -19,11 +19,8 @@ Build instructions
Build with MSVC
---------------

Install bdwgc in a bdwgc-subdirectory.
Install BDW in subdirectory gc-8.2.8

mkdir build
cd build
cmake ..
cmake --build . --config Release
copy Release\joy.exe

Expand Down
46 changes: 35 additions & 11 deletions doc/JOYimplJOY.md
Original file line number Diff line number Diff line change
Expand Up @@ -16,25 +16,49 @@ this version: JOY - compiled at 16:57:51 on Mar 17 2003.
- A build system has been added, allowing easy addition or removal of new
builtins.

- Some builtins have been added, positioned after `quit`. If they are not used
and CONST is also not used, the language is the same as it was in 2003.

- CONST and its synonym INLINE have been added. They allow compile time
evaluation.

- Some builtins have been added, positioned after quit. If they are not used
and CONST is also not used, the language is the same as it was in 2003.

- The user manual has been updated with annotations, documenting some of the
above.

Stating that this repository differs slightly from the legacy version is a bit
of an understatement. All source files have been modified. The statement is
true w.r.t. the language. The aim of this repository is to not change the
language.

Roadmap
=======

If the programming language is changed, it might use one of the following:

Extensions
----------

There are new builtings `assign` and `unassign` and some others in between.
The first one is mentioned in chapter 18 of the book
[Symbolic Processing in Pascal](https://github.com/nickelsworth/sympas/blob/master/text/18-minijoy.org),
and Joy with assignment is called `extended Joy`. These extensions need not
be used and in that case the language is still the same as it was in 2003.

Compiler
========
--------

There is some conditional compilation, activated by -DBYTECODE or -DCOMPILER
that adds the option to compile Joy source code to bytecode or C.

There is some conditional compilation, activated by -DBYTECODE that adds an
option to compile Joy source code.
At this moment there are no repositories with Joy source code that could
benefit from such compilation and because of that, these options are not
activated.

At this moment there is no repository with Joy source code that could benefit
from such compilation and because of that, the -DBYTECODE is not activated.
When activated, they will only be available for joy1 and Moy, not Joy, due to
the incompatible Node type of Joy.

If it is activated, it will only be available for joy1, not Joy, due to the
incompatible Node type of Joy.
Bignum
------

Also, the compiler is not very good at this moment.
There is also a bignum type, but no big numbers. There is no application yet
that would need them.
20 changes: 17 additions & 3 deletions error.c
Original file line number Diff line number Diff line change
@@ -1,18 +1,32 @@
/*
* module : error.c
* version : 1.2
* date : 09/18/24
* version : 1.3
* date : 10/11/24
*/
#include "globals.h"

/*
* print a runtime error to stderr and abort the execution of current program.
*/
void execerror(char *message, char *op)
void execerror(pEnv env, char *message, char *op)
{
int leng = 0;
char *ptr, *str;
#ifdef COMPILER
Entry ent;

if (env->compiling > 0) {
leng = lookup(env, op); /* locate in symbol table */
if (leng < tablesize())
op = nickname(leng);
ent = vec_at(env->symtab, leng);
ent.flags |= IS_USED;
vec_at(env->symtab, leng) = ent;
printstack(env);
fprintf(env->outfp, "%s_(env);\n", op);
return;
}
#endif
if ((ptr = strrchr(op, '/')) != 0)
ptr++;
else
Expand Down
109 changes: 61 additions & 48 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.113
* date : 09/23/24
* version : 1.116
* date : 10/11/24
*/
#ifndef GLOBALS_H
#define GLOBALS_H
Expand All @@ -22,11 +22,21 @@
#include <time.h>
#include <inttypes.h>

/*
* Certain compilers are likely to compile for the Windows platform and that
* means that WINDOWS can be set. Other compilers need to set this explicitly,
* if so desired.
*/
#if defined(_MSC_VER) || defined(__MINGW64_VERSION_MAJOR) || defined(__TINYC__)
#define WINDOWS
#endif

#ifdef _MSC_VER
/*
* The system call doesn't work when Windows is run in S-mode, so it might just
* as well be disabled, regardless of the compiler that is used. It is a bit of
* a security leak anyways.
*/
#ifdef WINDOWS
#define WINDOWS_S
#endif

Expand Down Expand Up @@ -63,37 +73,7 @@
#include "khash.h"
#endif

#define POP(X) X = nextnode1(X)

#define USR_NEWNODE(u, r) \
(env->bucket.ent = u, newnode(env, USR_, env->bucket, r))
#define ANON_FUNCT_NEWNODE(u, r) \
(env->bucket.proc = u, newnode(env, ANON_FUNCT_, env->bucket, r))
#define BOOLEAN_NEWNODE(u, r) \
(env->bucket.num = u, newnode(env, BOOLEAN_, env->bucket, r))
#define CHAR_NEWNODE(u, r) \
(env->bucket.num = u, newnode(env, CHAR_, env->bucket, r))
#define INTEGER_NEWNODE(u, r) \
(env->bucket.num = u, newnode(env, INTEGER_, env->bucket, r))
#define SET_NEWNODE(u, r) \
(env->bucket.set = u, newnode(env, SET_, env->bucket, r))
#define STRING_NEWNODE(u, r) \
(env->bucket.str = u, newnode(env, STRING_, env->bucket, r))
#define LIST_NEWNODE(u, r) \
(env->bucket.lis = u, newnode(env, LIST_, env->bucket, r))
#define FLOAT_NEWNODE(u, r) \
(env->bucket.dbl = u, newnode(env, FLOAT_, env->bucket, r))
#define FILE_NEWNODE(u, r) \
(env->bucket.fil = u, newnode(env, FILE_, env->bucket, r))
#define BIGNUM_NEWNODE(u, r) \
(env->bucket.str = u, newnode(env, BIGNUM_, env->bucket, r))

#define NULLARY(CONSTRUCTOR, VALUE) \
env->stck = CONSTRUCTOR(VALUE, env->stck)
#define UNARY(CONSTRUCTOR, VALUE) \
env->stck = CONSTRUCTOR(VALUE, nextnode1(env->stck))
#define BINARY(CONSTRUCTOR, VALUE) \
env->stck = CONSTRUCTOR(VALUE, nextnode2(env->stck))
#include "macros.h"

#ifdef NOBDW
#define nodetype(n) env->memory[n].op
Expand All @@ -117,6 +97,11 @@
#endif
#endif

/* settings for cflags */
#define IS_ACTIVE 1 /* prevent recursion */
#define IS_USED 2 /* multiple inlining */
#define IS_PRINTED 4 /* print of contents */

/* configure */
#define SHELLESCAPE '$'
#define INPSTACKMAX 10
Expand Down Expand Up @@ -152,6 +137,8 @@ enum {
FILE_,
BIGNUM_,

LIST_PRIME_,

LIBRA,
EQDEF,
HIDE,
Expand Down Expand Up @@ -224,7 +211,7 @@ typedef struct Token {

typedef struct Entry {
char *name;
unsigned char is_user, flags, is_ok, is_root, is_last;
unsigned char is_user, flags, is_ok, is_root, is_last, qcode, nofun, cflags;
union {
Index body;
proc_t proc;
Expand Down Expand Up @@ -275,6 +262,9 @@ typedef struct Env {
Index conts, dump, dump1, dump2, dump3, dump4, dump5, inits;
#endif
Index prog, stck;
#ifdef COMPILER
FILE *declfp, *outfp;
#endif
int g_argc; /* command line */
int hide_stack[DISPLAYMAX];
struct {
Expand All @@ -289,15 +279,15 @@ typedef struct Env {
unsigned char tracegc;
unsigned char undeferror;
unsigned char undeferror_set;
unsigned char bytecoding; /* BDW only */
unsigned char compiling; /* BDW only */
unsigned char debugging;
unsigned char ignore;
unsigned char overwrite;
unsigned char printing;
unsigned char finclude_busy;
unsigned char flibrary_busy;
unsigned char variable_busy;
signed char bytecoding; /* BDW only */
signed char compiling; /* BDW only */
} Env;

typedef struct table_t {
Expand Down Expand Up @@ -344,7 +334,7 @@ void printnode(pEnv env, Index p);
void my_gc(pEnv env);
#endif
/* error.c */
void execerror(char *message, char *op);
void execerror(pEnv env, char *message, char *op);
/* factor.c */
int readfactor(pEnv env, int ch, int *rv); /* read a JOY factor */
int readterm(pEnv env, int ch);
Expand All @@ -359,10 +349,7 @@ void exitmod(void);
char *classify(pEnv env, char *name);
int qualify(pEnv env, char *name);
/* optable.c */
#ifdef BYTECODE
int tablesize(void);
int operqcode(int index);
#endif
char *nickname(int ch);
char *opername(int o);
int operindex(pEnv env, proc_t proc);
Expand All @@ -388,16 +375,42 @@ void writeterm(pEnv env, Index n, FILE *fp);
void bytecode(pEnv env, Node *list);
void initbytes(pEnv env);
void exitbytes(pEnv env);
/* compile.c */
int compile(pEnv env, Node *node);
void initcompile(pEnv env);
void exitcompile(pEnv env);
/* compeval.c */
void compeval(pEnv env, FILE *fp);
/* computil.c */
Node *reverse(Node *cur);
char *outputfile(char *inputfile, char *suffix);
/* dumpbyte.c */
void dumpbyte(pEnv env, FILE *fp);
/* readbyte.c */
void readbyte(pEnv env, FILE *fp, int flag);
unsigned char *readfile(FILE *fp);
/* optimize.c */
void optimize(pEnv env, FILE *fp);
/* readbyte.c */
void readbyte(pEnv env, FILE *fp);
unsigned char *readfile(FILE *fp);
#endif
#ifdef COMPILER
/* compiler.c */
void printnode(pEnv env, Node *node);
void printstack(pEnv env);
void compile(pEnv env, Node *node);
void initcompile(pEnv env);
void exitcompile(pEnv env);
/* computil.c */
Node *reverse(Node *cur);
char *outputfile(char *inputfile, char *suffix);
/* identify.c */
const char *identifier(const char *str);
const char *unidentify(const char *str);
/* instance.c */
int instance(pEnv env, char *name, int qcode);
/* outfiles.c */
void initout(void);
FILE *nextfile(void);
void closefile(FILE *fp);
void printout(FILE *fp);
void closeout(void);
/* readtemp.c */
int testtemp(char *file);
void readtemp(pEnv env, char *file, Node *nodes[], int found, int seqnr);
#endif
#endif
Loading

0 comments on commit 4b7cf6d

Please sign in to comment.