Skip to content

Commit

Permalink
Patch Tuesday - K
Browse files Browse the repository at this point in the history
  • Loading branch information
Wodan58 committed Sep 24, 2024
1 parent 3b609df commit 5462a26
Show file tree
Hide file tree
Showing 281 changed files with 2,094 additions and 3,042 deletions.
6 changes: 5 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
joy1.tar
bdwgc
gc-8.2.8
build
.vs
G3
usrlib.joy
ATTIC
46 changes: 13 additions & 33 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,60 +1,40 @@
#
# module : CMakeLists.txt
# version : 1.30
# date : 08/31/24
# version : 1.40
# date : 09/24/24
#
cmake_minimum_required(VERSION 3.5)
project(Joy VERSION 1.0)
if("${CMAKE_BUILD_TYPE}" STREQUAL "")
set(CMAKE_BUILD_TYPE "Release")
endif()
if("${CMAKE_BUILD_TYPE}" STREQUAL "Debug")
option(RUN_TESTS "Run standard tests" ON)
option(RUN_TEST "Run standard tests" ON)
else()
option(RUN_TESTS "Run standard tests" OFF)
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)
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)
add_definitions(-DLINK="\\"${CMAKE_EXE_LINKER_FLAGS}\\"")
add_definitions(-DVERS="BDW ${CMAKE_BUILD_TYPE} ${CMAKE_PROJECT_VERSION}")
#
# MSVC: cmake --build . --config Release
# MSVC: cmake --build . --config Release
#
# The gc-8.2.8 must be built separately. Best is to disable libatomic_ops.
# It is configured as a subdirectory of joy1.
#
if(CMAKE_CXX_COMPILER_ID MATCHES "MSVC")
set(CMAKE_VERBOSE_MAKEFILE ON)
option(BUILD_SHARED_LIBS OFF)
option(BUILD_TESTING OFF)
option(build_cord OFF)
option(enable_docs OFF)
option(enable_threads OFF)
option(enable_parallel_mark OFF)
option(enable_thread_local_alloc OFF)
option(enable_threads_discovery OFF)
option(enable_throw_bad_alloc_library OFF)
option(enable_gcj_support OFF)
option(enable_java_finalization OFF)
option(enable_atomic_uncollectable OFF)
option(enable_disclaim OFF)
option(enable_munmap OFF)
option(enable_dynamic_loading OFF)
option(enable_register_main_static_data OFF)
option(enable_handle_fork OFF)
option(install_headers OFF)
option(disable_gc_debug ON)
option(disable_single_obj_compilation ON)
option(disable_handle_fork ON)
option(without_libatomic_ops ON)
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -DGC_NOT_DLL -D_CRT_SECURE_NO_DEPRECATE")
add_definitions(-DCOMP="\\"${CMAKE_C_FLAGS}\\"")
target_link_libraries(joy bdwgc/Release/gc)
include_directories(bdwgc/include)
add_subdirectory(bdwgc)
target_link_libraries(joy ../gc-8.2.8/build/Release/gc)
else()
add_dependencies(joy always)
add_custom_target(always
WORKING_DIRECTORY ${CMAKE_SOURCE_DIR}
COMMAND sh prims.sh .
COMMAND sh table.sh .)
set(CF "-Wall -Wextra -Wpedantic -Werror -Wno-unused-parameter")
set(CF "-Wall -Wextra -Wpedantic -Werror -Wno-unused-parameter -Wno-unused-result")
if("${CMAKE_BUILD_TYPE}" STREQUAL "Release")
set(CMAKE_C_FLAGS_RELEASE "${CMAKE_C_FLAGS_RELEASE} ${CF}")
add_definitions(-DCOMP="\\"${CMAKE_C_FLAGS_RELEASE}\\"")
Expand All @@ -65,7 +45,7 @@ else()
add_definitions(-DCOMP="\\"${CMAKE_C_FLAGS_DEBUG}\\"")
endif()
target_link_libraries(joy m gc)
if(RUN_TESTS)
if(RUN_TEST)
add_subdirectory(lib)
add_subdirectory(test2)
add_subdirectory(test4)
Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
Joy1
----
====

Build|Linux|Windows|Coverity
---|---|---|---
Expand Down
32 changes: 32 additions & 0 deletions doc/JOYimplJOY.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,3 +6,35 @@ Changes

This updated version of Joy is slightly different from the legacy version,
this version: JOY - compiled at 16:57:51 on Mar 17 2003.

- Some bugs have been removed. No guarantee can be given that none are left:
the code base is simply too large to allow such a guarantee.

- Better datastructures are used. This allows growth of symbol table,
tokenlist, symbols, and include search directories.

- A build system has been added, allowing easy addition or removal of new
builtins.

- 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.

Compiler
========

There is some conditional compilation, activated by -DBYTECODE that adds an
option to compile Joy source code.

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.

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

Also, the compiler is not very good at this moment.
Binary file added doc/Wynn.ico
Binary file not shown.
27 changes: 27 additions & 0 deletions error.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
/*
* module : error.c
* version : 1.2
* date : 09/18/24
*/
#include "globals.h"

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

if ((ptr = strrchr(op, '/')) != 0)
ptr++;
else
ptr = op;
if ((str = strrchr(ptr, '.')) != 0 && str[1] == 'c')
leng = str - ptr;
else
leng = strlen(ptr);
fflush(stdout);
fprintf(stderr, "run time error: %s needed for %.*s\n", message, leng, ptr);
abortexecution_(ABORT_RETRY);
} /* LCOV_EXCL_LINE */
160 changes: 3 additions & 157 deletions factor.c
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
/* FILE: factor.c */
/*
* module : factor.c
* version : 1.33
* date : 06/24/24
* version : 1.35
* date : 09/16/24
*/
#include "globals.h"

Expand All @@ -20,7 +19,7 @@ static uint64_t list2set(pEnv env, Index n)
if (nodevalue(n).num < 0 || nodevalue(n).num >= SETSIZE)
error("small numeric expected in set");
else
set |= (uint64_t)1 << nodevalue(n).num;
set |= (uint64_t)1 << nodevalue(n).set;
break;
default:
error("numeric expected in set");
Expand Down Expand Up @@ -173,156 +172,3 @@ int readterm(pEnv env, int ch)
return ch;
}
#endif

/*
* writefactor - print a factor in readable format to stdout.
*/
void writefactor(pEnv env, Index n, FILE *fp)
{
int i;
uint64_t set, j;
char *ptr, buf[BUFFERMAX], tmp[MAXNUM];

#if 0
/*
* This cannot happen. writefactor has a small number of customers: writeterm,
* main, put, fput. They all check that the stack is not empty, so this code
* only serves as a reminder for future customers.
*/
if (!n)
execerror("non-empty stack", "writefactor");
#endif
switch (nodetype(n)) {
case USR_:
fprintf(fp, "%s", vec_at(env->symtab, nodevalue(n).ent).name);
break;

case ANON_FUNCT_:
fprintf(fp, "%s", opername(operindex(env, nodevalue(n).proc)));
break;

case BOOLEAN_:
fprintf(fp, "%s", nodevalue(n).num ? "true" : "false");
break;

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) || nodevalue(n).num == 32)
fprintf(fp, "'\\%03d", (int)nodevalue(n).num);
else
fprintf(fp, "'%c", (int)nodevalue(n).num);
break;

case INTEGER_:
fprintf(fp, "%" PRId64, nodevalue(n).num);
break;

case SET_:
putc('{', fp);
for (i = 0, j = 1, set = nodevalue(n).set; i < SETSIZE; i++, j <<= 1)
if (set & j) {
fprintf(fp, "%d", i);
set &= ~j;
if (set)
putc(' ', fp);
}
putc('}', fp);
break;

case STRING_:
putc('"', fp);
#ifdef NOBDW
for (ptr = (char *)&nodevalue(n); *ptr; ptr++)
#else
for (ptr = nodevalue(n).str; *ptr; ptr++)
#endif
if (*ptr == '"')
fprintf(fp, "\\\"");
else if (*ptr >= 8 && *ptr <= 13)
fprintf(fp, "\\%c", "btnvfr"[*ptr - 8]);
else if (iscntrl((int)*ptr))
fprintf(fp, "\\%03d", *ptr);
else
putc(*ptr, fp);
putc('"', fp);
break;

case LIST_:
putc('[', fp);
writeterm(env, nodevalue(n).lis, fp);
putc(']', fp);
break;

case FLOAT_:
sprintf(buf, "%g", nodevalue(n).dbl); /* exponent character is e */
if ((ptr = strchr(buf, '.')) == 0) { /* locate decimal point */
if ((ptr = strchr(buf, 'e')) == 0) {/* locate start of exponent */
i = buf[strlen(buf) - 1];
if (isdigit(i)) /* check digit present */
strcat(buf, ".0"); /* add decimal point and 0 */
} else {
strcpy(tmp, ptr); /* save exponent */
sprintf(ptr, ".0%s", tmp); /* insert decimal point + 0 */
}
}
fprintf(fp, "%s", buf);
break;

case FILE_:
if (!nodevalue(n).fil)
fprintf(fp, "NULL");
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, "%p", (void *)nodevalue(n).fil);
break;

case BIGNUM_:
#ifdef NOBDW
fprintf(fp, "%s", (char *)&nodevalue(n));
#else
fprintf(fp, "%s", nodevalue(n).str);
#endif
break;

default:
error("a factor cannot begin with this symbol");
break;
}
}

/*
* writeterm - print the contents of a list in readable format to fp.
*/
void writeterm(pEnv env, Index n, FILE *fp)
{
while (n) {
writefactor(env, n, fp);
POP(n);
if (n)
putc(' ', fp);
}
}

/*
* writedump - print the contents of a dump in readable format to fp,
* with a limit of 10 factors.
*/
#ifdef NOBDW
void writedump(pEnv env, Index n, FILE *fp)
{
int i;

for (i = 0; n && i < 10; i++) {
writefactor(env, n, fp);
POP(n);
if (n)
putc(' ', fp);
}
}
#endif
Loading

0 comments on commit 5462a26

Please sign in to comment.