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 63b37d1 commit 39f6fd2
Show file tree
Hide file tree
Showing 108 changed files with 1,276 additions and 1,188 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.26
# date : 03/23/24
# version : 1.27
# date : 06/21/24
#
cmake_minimum_required(VERSION 3.5)
project(Joy VERSION 1.0)
Expand Down Expand Up @@ -59,8 +59,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
92 changes: 49 additions & 43 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.31
* date : 04/19/24
* version : 1.33
* date : 06/24/24
*/
#include "globals.h"

Expand All @@ -11,9 +11,9 @@
*/
static uint64_t list2set(pEnv env, Index n)
{
uint64_t set = 0;
uint64_t set;

while (n) {
for (set = 0; n; POP(n))
switch (nodetype(n)) {
case CHAR_:
case INTEGER_:
Expand All @@ -26,26 +26,25 @@ static uint64_t list2set(pEnv env, Index n)
error("numeric expected in set");
break;
}
n = nextnode1(n);
}
return set;
}

/*
* readfactor - read a factor from srcfile and push it on the stack.
* In case of error nothing is pushed; the rv return value:
* success=1, failure=0.
* In case of an error nothing is pushed on the stack and rv is set to 0.
*/
int readfactor(pEnv env, int ch, int *rv) /* read a JOY factor */
{
int index;
Entry ent;
uint64_t set;

*rv = 0;
*rv = 1; /* assume that a factor will be read */
switch (env->sym) {
case USR_:
if ((index = lookup(env, env->str)) == 0) {
error("no such field in module");
*rv = 0; /* no factor was read */
break;
}
ent = vec_at(env->symtab, index);
Expand All @@ -55,60 +54,59 @@ int readfactor(pEnv env, int ch, int *rv) /* read a JOY factor */
exeterm(env, ent.u.body);
else
(*ent.u.proc)(env);
} else if (ent.is_user) {
env->bucket.ent = index;
env->stck = newnode(env, USR_, env->bucket, env->stck);
} else {
env->bucket.proc = ent.u.proc;
env->stck = newnode(env, ANON_FUNCT_, env->bucket, env->stck);
}
*rv = 1;
} else if (ent.is_user)
NULLARY(USR_NEWNODE, index);
else
NULLARY(ANON_FUNCT_NEWNODE, ent.u.proc);
break;

#if 0
/* A boolean is no longer returned by the scanner */
case BOOLEAN_:
NULLARY(BOOLEAN_NEWNODE, env->num);
break;
#endif

case CHAR_:
NULLARY(CHAR_NEWNODE, env->num);
break;

case INTEGER_:
env->bucket.num = env->num;
env->stck = newnode(env, env->sym, env->bucket, env->stck);
*rv = 1;
NULLARY(INTEGER_NEWNODE, env->num);
break;

case STRING_:
env->bucket.str = env->str;
env->stck = newnode(env, env->sym, env->bucket, env->stck);
*rv = 1;
NULLARY(STRING_NEWNODE, env->str);
break;

case FLOAT_:
env->bucket.dbl = env->dbl;
env->stck = newnode(env, env->sym, env->bucket, env->stck);
*rv = 1;
NULLARY(FLOAT_NEWNODE, env->dbl);
break;

case '{':
ch = getsym(env, ch);
ch = readterm(env, ch);
env->bucket.set = list2set(env, nodevalue(env->stck).lis);
env->stck = newnode(env, SET_, env->bucket, nextnode1(env->stck));
set = list2set(env, nodevalue(env->stck).lis);
UNARY(SET_NEWNODE, set);
if (env->sym != '}')
error("'}' expected");
*rv = 1;
break;

case '[':
ch = getsym(env, ch);
ch = readterm(env, ch);
if (env->sym != ']')
error("']' expected");
*rv = 1;
break;

case '(':
error("'(' not implemented");
*rv = 0; /* no factor was read */
break;

default:
error("a factor cannot begin with this symbol");
*rv = 0; /* no factor was read */
break;
}
return ch;
Expand All @@ -122,8 +120,7 @@ int readterm(pEnv env, int ch)
{
int rv = 0, first = 1;

env->bucket.lis = 0;
env->stck = newnode(env, LIST_, env->bucket, env->stck);
NULLARY(LIST_NEWNODE, 0);
while (1) {
if (strchr(".;]}", env->sym) ||
(env->sym >= LIBRA && env->sym <= CONST_))
Expand All @@ -133,20 +130,20 @@ int readterm(pEnv env, int ch)
if (first) {
first = 0;
nodevalue(nextnode1(env->stck)).lis = env->stck;
env->stck = nextnode1(env->stck);
POP(env->stck);
nextnode1(nodevalue(env->stck).lis) = 0;
env->dump = newnode(env, LIST_, nodevalue(env->stck),env->dump);
env->dump = LIST_NEWNODE(nodevalue(env->stck).lis, env->dump);
} else {
nextnode1(nodevalue(env->dump).lis) = env->stck;
env->stck = nextnode1(env->stck);
POP(env->stck);
nextnode2(nodevalue(env->dump).lis) = 0;
nodevalue(env->dump).lis = nextnode1(nodevalue(env->dump).lis);
}
}
ch = getsym(env, ch);
}
if (!first)
env->dump = nextnode1(env->dump);
POP(env->dump);
return ch;
}
#else
Expand All @@ -158,8 +155,7 @@ int readterm(pEnv env, int ch)
int rv = 0;
Index *dump = 0;

env->bucket.lis = 0;
env->stck = newnode(env, LIST_, env->bucket, env->stck);
NULLARY(LIST_NEWNODE, 0);
dump = &nodevalue(env->stck).lis;
while (1) {
if (strchr(".;]}", env->sym) ||
Expand All @@ -185,7 +181,7 @@ void writefactor(pEnv env, Index n, FILE *fp)
{
int i;
uint64_t set, j;
char *ptr, buf[MAXNUM], tmp[MAXNUM];
char *ptr, buf[BUFFERMAX], tmp[MAXNUM];

#if 0
/*
Expand Down Expand Up @@ -236,7 +232,11 @@ void writefactor(pEnv env, Index n, FILE *fp)

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)
Expand Down Expand Up @@ -283,7 +283,11 @@ void writefactor(pEnv env, Index n, FILE *fp)
break;

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

default:
Expand All @@ -293,19 +297,20 @@ void writefactor(pEnv env, Index n, FILE *fp)
}

/*
* writeterm - print the contents of a list in readable format to stdout.
* 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);
if ((n = nextnode1(n)) != 0)
POP(n);
if (n)
putc(' ', fp);
}
}

/*
* writedump - print the contents of a dump in readable format to stdout,
* writedump - print the contents of a dump in readable format to fp,
* with a limit of 10 factors.
*/
#ifdef NOBDW
Expand All @@ -315,7 +320,8 @@ void writedump(pEnv env, Index n, FILE *fp)

for (i = 0; n && i < 10; i++) {
writefactor(env, n, fp);
if ((n = nextnode1(n)) != 0)
POP(n);
if (n)
putc(' ', fp);
}
}
Expand Down
Loading

0 comments on commit 39f6fd2

Please sign in to comment.