Skip to content

Commit

Permalink
Patch Tuesday - G
Browse files Browse the repository at this point in the history
  • Loading branch information
Wodan58 committed Jun 25, 2024
1 parent c46de61 commit b1eddfd
Show file tree
Hide file tree
Showing 27 changed files with 139 additions and 144 deletions.
9 changes: 5 additions & 4 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
#
# module : CMakeLists.txt
# version : 1.24
# date : 05/28/24
# version : 1.25
# date : 06/22/24
#
cmake_minimum_required(VERSION 3.5)
project(Joy VERSION 1.0)
Expand Down Expand Up @@ -72,8 +72,9 @@ else()
set(CMAKE_C_FLAGS_RELEASE "${CMAKE_C_FLAGS_RELEASE} ${CF}")
add_definitions(-DCOMP="\\"${CMAKE_C_FLAGS_RELEASE}\\"")
else()
set(CMAKE_C_FLAGS_DEBUG "${CMAKE_C_FLAGS_DEBUG} ${CF} -g -O0 --coverage -fprofile-arcs -ftest-coverage") # debug, no optimization
set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} --coverage") # enabling coverage
set(CMAKE_C_FLAGS_DEBUG # debug, enabling coverage
"${CMAKE_C_FLAGS_DEBUG} ${CF} -O3 --coverage -fprofile-arcs -ftest-coverage")
set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} --coverage")
add_definitions(-DCOMP="\\"${CMAKE_C_FLAGS_DEBUG}\\"")
endif()
target_link_libraries(joy m gc)
Expand Down
12 changes: 7 additions & 5 deletions globals.h
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
/*
module : globals.h
version : 1.48
date : 05/28/24
version : 1.49
date : 06/22/24
*/
#ifndef GLOBALS_H
#define GLOBALS_H
Expand Down Expand Up @@ -47,7 +47,7 @@
#define INPLINEMAX 255
#define BUFFERMAX 80 /* smaller buffer */
#define HELPLINEMAX 72
#define MAXNUM 32 /* even smaller buffer */
#define MAXNUM 40 /* even smaller buffer */
#define FILENAMEMAX 14
#define DISPLAYMAX 10 /* nesting in HIDE & MODULE */
#define INIECHOFLAG 0
Expand Down Expand Up @@ -183,8 +183,10 @@ typedef struct Token {
* The symbol table is accessed through two hash tables, one with name as
* index; the other with function address as index, cast to uint64_t.
*/
KHASHL_MAP_INIT(KH_LOCAL, symtab_t, symtab, kh_cstr_t, int, kh_hash_str, kh_eq_str)
KHASHL_MAP_INIT(KH_LOCAL, funtab_t, funtab, uint64_t, int, kh_hash_uint64, kh_eq_generic)
KHASHL_MAP_INIT(KH_LOCAL, symtab_t, symtab, kh_cstr_t, int, kh_hash_str,
kh_eq_str)
KHASHL_MAP_INIT(KH_LOCAL, funtab_t, funtab, uint64_t, int, kh_hash_uint64,
kh_eq_generic)

/*
* Global variables are stored locally in the main function.
Expand Down
13 changes: 6 additions & 7 deletions lexr.l
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
%{
/*
module : lexr.l
version : 1.33
date : 05/06/24
version : 1.34
date : 06/22/24
*/
#include "globals.h"

Expand Down Expand Up @@ -78,9 +78,7 @@ void new_buffer(void)

void old_buffer(int num)
{
if (--include_stack_ptr < 0)
include_stack_ptr = 0;
if (include_stack[include_stack_ptr])
if (include_stack[--include_stack_ptr])
yy_switch_to_buffer(include_stack[include_stack_ptr]);
yylineno = num; /* restart old file */
linenum = num + 1;
Expand Down Expand Up @@ -153,9 +151,10 @@ INLINE[ \t]* return CONST_;
{comment} { addline('('); addline('*'); BEGIN COMMENT; }
{linecom} { /* default to ECHO */ }
^\$.* { int rv; if (!env->ignore) { rv = system(yytext + 1); if (rv)
{ fflush(stdout); fprintf(stderr, "system: %d\n", rv); } } }
{ fflush(stdout); fprintf(stderr, "system: %u\n", rv & 0xFF);
} } }
[ \b\t\n\v\f\r] ;
[;[\]{}] |
. return yytext[0];

%%
%% /* LCOV_EXCL_LINE */
19 changes: 6 additions & 13 deletions lib/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,33 +1,26 @@
#
# module : CMakeLists.txt
# version : 1.4
# date : 03/23/24
# version : 1.5
# date : 06/21/24
#
macro(exe9 src)
add_custom_target(${src}.out ALL
WORKING_DIRECTORY ${CMAKE_SOURCE_DIR}/lib
DEPENDS joy ${CMAKE_SOURCE_DIR}/lib/${src}.joy
COMMAND joy ${CMAKE_SOURCE_DIR}/lib/${src}.joy >${src}.oud)
COMMAND joy -x ${CMAKE_SOURCE_DIR}/lib/${src}.joy >${src}.oud)
endmacro(exe9)

macro(exe8 src)
add_custom_target(${src}.out ALL
WORKING_DIRECTORY ${CMAKE_SOURCE_DIR}/lib
DEPENDS joy ${CMAKE_SOURCE_DIR}/lib/${src}.joy
COMMAND joy ${CMAKE_SOURCE_DIR}/lib/${src}.joy 24 54 >${src}.oud)
COMMAND joy -x ${CMAKE_SOURCE_DIR}/lib/${src}.joy 24 54 >${src}.oud)
endmacro(exe8)

macro(exe7 src)
add_custom_target(${src}.out ALL
WORKING_DIRECTORY ${CMAKE_SOURCE_DIR}/lib
DEPENDS joy ${CMAKE_SOURCE_DIR}/lib/${src}.joy
COMMAND joy -x ${CMAKE_SOURCE_DIR}/lib/${src}.joy >${src}.oud)
endmacro(exe7)

exe8(gcd)
exe9(grmtst)
exe9(alljoy)
exe9(flatjoy)
exe8(gcd)
exe7(grmtst)
exe9(jp-church)
exe9(jp-joytst)
exe9(jp-nestrec)
Expand Down
16 changes: 6 additions & 10 deletions module.c
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
/*
module : module.c
version : 1.13
date : 05/27/24
version : 1.14
date : 06/21/24
*/
#include "globals.h"

Expand Down Expand Up @@ -41,11 +41,9 @@ void undomod(int hide, int modl, int hcnt)
*/
void initmod(pEnv env, char *name)
{
if (++module_index >= DISPLAYMAX) {
module_index = -1;
if (module_index + 1 == DISPLAYMAX)
execerror("index", "display");
}
env->module_stack[module_index].name = name;
env->module_stack[++module_index].name = name;
env->module_stack[module_index].hide = hide_index;
}

Expand All @@ -60,11 +58,9 @@ void initmod(pEnv env, char *name)
*/
void initpriv(pEnv env)
{
if (++hide_index >= DISPLAYMAX) {
hide_index = -1;
if (hide_index + 1 == DISPLAYMAX)
execerror("index", "display");
}
env->hide_stack[hide_index] = ++hide_count;
env->hide_stack[++hide_index] = ++hide_count;
inside_hide = 1;
}

Expand Down
48 changes: 14 additions & 34 deletions scan.c
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
/*
module : scan.c
version : 1.21
date : 05/27/24
version : 1.22
date : 06/22/24
*/
#include "globals.h"

Expand Down Expand Up @@ -52,22 +52,19 @@ static void redirect(FILE *fp, char *str)
*/
int include(pEnv env, char *name)
{
/*
* mustinclude - determine whether an attempt must be made to include
* usrlib.joy
*/
FILE *fp;
char *path = 0, *str = name;

/*
* usrlib.joy is tried first in the current directory, then in the home
* directory and then in the directory where the joy binary is located.
*
* If all of that fails, no harm done.
* A file is first tried in the current directory.
*/
if ((fp = fopen(name, "r")) != 0)
goto normal;
/*
* usrlib.joy is tried in the home directory and then in the directory
* where the joy binary is located.
*/
if (!strcmp(name, "usrlib.joy")) { /* check usrlib.joy */
if ((fp = fopen(name, "r")) != 0) /* current dir */
goto normal;
if ((path = getenv("HOME")) != 0) { /* unix/cygwin */
str = GC_malloc_atomic(strlen(path) + strlen(name) + 2);
sprintf(str, "%s/%s", path, name);
Expand All @@ -80,33 +77,16 @@ int include(pEnv env, char *name)
if ((fp = fopen(str, "r")) != 0)
goto normal;
}
path = env->pathname; /* joy binary */
if (strcmp(path, ".")) {
str = GC_malloc_atomic(strlen(path) + strlen(name) + 2);
sprintf(str, "%s/%s", path, name);
if ((fp = fopen(str, "r")) != 0)
goto normal;
}
/*
* Failure to open usrlib.joy need not be reported.
*/
return 1;
}
/*
* A file other than usrlib.joy is tried first in the current directory.
*/
if ((fp = fopen(name, "r")) != 0)
goto normal;
/*
* If that fails, the pathname is prepended and the file is tried again.
*/
path = env->pathname;
path = env->pathname; /* joy binary */
if (strcmp(path, ".")) {
str = GC_malloc_atomic(strlen(path) + strlen(name) + 2);
sprintf(str, "%s/%s", path, name);
if ((fp = fopen(str, "r")) != 0)
goto normal;
return 1;
if ((fp = fopen(str, "r")) == 0)
return 1;
}
normal:
/*
Expand Down Expand Up @@ -149,7 +129,7 @@ void my_error(char *str, YYLTYPE *bloc)
fprintf(stderr, "%s\n%*s^\n%*s%s\n", line, leng, "", leng, "", str);
line[0] = 0; /* invalidate line */
abortexecution_(ABORT_RETRY);
}
} /* LCOV_EXCL_LINE */

/*
* yyerror - error processing during source file read; location info global.
Expand All @@ -160,4 +140,4 @@ void yyerror(pEnv env, char *str)

bloc.last_column = yylloc.last_column;
my_error(str, &bloc);
}
} /* LCOV_EXCL_LINE */
6 changes: 3 additions & 3 deletions src/abort.c
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
/*
module : abort.c
version : 1.10
date : 03/21/24
version : 1.11
date : 06/22/24
*/
#ifndef ABORT_C
#define ABORT_C
Expand All @@ -13,5 +13,5 @@ Aborts execution of current Joy program, returns to Joy main cycle.
void abort_(pEnv env)
{
abortexecution_(ABORT_RETRY);
}
} /* LCOV_EXCL_LINE */
#endif
6 changes: 3 additions & 3 deletions src/assign.c
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
/*
module : assign.c
version : 1.3
date : 03/21/24
version : 1.4
date : 06/22/24
*/
#ifndef ASSIGN_C
#define ASSIGN_C

/**
Q0 IGNORE_POP 3190 assign : DD V [N] ->
Q0 IGNORE_POP 3140 assign : DD V [N] ->
[IMPURE] Assigns value V to the variable with name N.
*/
void assign_(pEnv env)
Expand Down
6 changes: 3 additions & 3 deletions src/casting.c
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
/*
module : casting.c
version : 1.10
date : 03/05/24
version : 1.11
date : 06/22/24
*/
#ifndef CASTING_C
#define CASTING_C

/**
Q0 OK 3140 casting : DDA X Y -> Z
Q0 OK 3150 casting : DDA X Y -> Z
[EXT] Z takes the value from X and uses the value from Y as its type.
*/
void casting_(pEnv env)
Expand Down
6 changes: 3 additions & 3 deletions src/filetime.c
Original file line number Diff line number Diff line change
@@ -1,15 +1,15 @@
/*
module : filetime.c
version : 1.12
date : 03/05/24
version : 1.13
date : 06/22/24
*/
#ifndef FILETIME_C
#define FILETIME_C

#include <sys/stat.h>

/**
Q0 OK 3150 filetime : DA F -> T
Q0 OK 3160 filetime : DA F -> T
[FOREIGN] T is the modification time of file F.
*/
void filetime_(pEnv env)
Expand Down
6 changes: 3 additions & 3 deletions src/finclude.c
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
/*
module : finclude.c
version : 1.12
date : 05/27/24
version : 1.13
date : 06/22/24
*/
#ifndef FINCLUDE_C
#define FINCLUDE_C

/**
Q0 OK 3160 finclude : DU S -> F ...
Q0 OK 3170 finclude : DU S -> F ...
[FOREIGN] Reads Joy source code from stream S and pushes it onto stack.
*/
void finclude_(pEnv env)
Expand Down
6 changes: 3 additions & 3 deletions src/over.c
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
/*
module : over.c
version : 1.11
date : 03/05/24
version : 1.12
date : 06/22/24
*/
#ifndef OVER_C
#define OVER_C

/**
Q0 OK 3170 over : A X Y -> X Y X
Q0 OK 3180 over : A X Y -> X Y X
[EXT] Pushes an extra copy of the second item X on top of the stack.
*/
void over_(pEnv env)
Expand Down
6 changes: 3 additions & 3 deletions src/pick.c
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
/*
module : pick.c
version : 1.13
date : 03/05/24
version : 1.14
date : 06/22/24
*/
#ifndef PICK_C
#define PICK_C

/**
Q0 OK 3180 pick : DA X Y Z 2 -> X Y Z X
Q0 OK 3190 pick : DA X Y Z 2 -> X Y Z X
[EXT] Pushes an extra copy of nth (e.g. 2) item X on top of the stack.
*/
void pick_(pEnv env)
Expand Down
6 changes: 3 additions & 3 deletions src/quit.c
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
/*
module : quit.c
version : 1.13
date : 04/29/24
version : 1.14
date : 06/22/24
*/
#ifndef QUIT_C
#define QUIT_C
Expand All @@ -13,5 +13,5 @@ Exit from Joy.
void quit_(pEnv env)
{
abortexecution_(ABORT_QUIT);
}
} /* LCOV_EXCL_LINE */
#endif
Loading

0 comments on commit b1eddfd

Please sign in to comment.