Skip to content

Commit

Permalink
Pedantic
Browse files Browse the repository at this point in the history
  • Loading branch information
Wodan58 committed Oct 16, 2023
1 parent fb656ef commit bc0aee7
Show file tree
Hide file tree
Showing 28 changed files with 148 additions and 169 deletions.
6 changes: 3 additions & 3 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.22
* date : 09/07/23
* version : 1.23
* date : 10/12/23
*/
#include "globals.h"

Expand Down Expand Up @@ -196,7 +196,7 @@ PUBLIC void writefactor(pEnv env, Index n, FILE *fp)
else if (nodevalue(n).fil == stderr)
fprintf(fp, "file:stderr");
else
fprintf(fp, "file:%p", nodevalue(n).fil);
fprintf(fp, "file:%p", (void *)nodevalue(n).fil);
return;
default:
error(env, "a factor cannot begin with this symbol");
Expand Down
1 change: 0 additions & 1 deletion fib.joy

This file was deleted.

28 changes: 8 additions & 20 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.76
* date : 09/13/23
* version : 1.77
* date : 10/16/23
*/
#ifndef GLOBALS_H
#define GLOBALS_H
Expand All @@ -19,13 +19,9 @@
#include <math.h>
#include <time.h>
#include <inttypes.h>

#ifdef _MSC_VER
#include <io.h>
#pragma warning(disable : 4267)
#else
#include <unistd.h>
#endif
#include <gc.h>
#include "kvec.h"
#include "khash.h"

#ifdef NOBDW
#define nodetype(n) vec_at(env->memory, n).op
Expand Down Expand Up @@ -154,10 +150,6 @@ typedef struct Token {
Symbol symb;
} Token;

#include <gc.h>
#include "kvec.h"
#include "khash.h"

KHASH_MAP_INIT_STR(Symtab, pEntry)

typedef struct Env {
Expand All @@ -180,7 +172,7 @@ typedef struct Env {
pEntry location; /* getsym */
Symbol symb; /* scanner */
int hide_stack[DISPLAYMAX];
struct module {
struct my_module {
char *name;
int hide;
} module_stack[DISPLAYMAX];
Expand All @@ -199,7 +191,7 @@ typedef struct Env {
WORD = "ABCD" - up to four chars
LIST of SETs of char [S0 S1 S2 S3]
LISTS - binary tree [left right]
" with info [info left right]
" with info [info left right] "
STRING of 32 chars = 32 * 8 bits = 256 bits = bigset
CHAR = 2 HEX
32 SET = 2 * 16SET
Expand Down Expand Up @@ -242,18 +234,14 @@ PUBLIC void error(pEnv env, char *message);
PUBLIC int redirect(pEnv env, char *name, FILE *fp);
PUBLIC int include(pEnv env, char *name, int error);
PUBLIC void getsym(pEnv env);
/* stackavail.c */
size_t stackavail(void);
/* utils.c */
#ifdef NOBDW
PUBLIC void inimem1(pEnv env, int status);
PUBLIC void inimem2(pEnv env);
PUBLIC void printnode(pEnv env, Index p);
PUBLIC void my_gc(pEnv env);
PUBLIC Index newnode(pEnv env, Operator o, Types u, Index r);
#else
PUBLIC Node *newnode(pEnv env, Operator o, Types u, Node *r);
#endif
PUBLIC Index newnode(pEnv env, Operator o, Types u, Index r);
PUBLIC void my_memoryindex(pEnv env);
PUBLIC void my_memorymax(pEnv env);
/* quit.c */
Expand Down
2 changes: 1 addition & 1 deletion lib/agglib.joy
Original file line number Diff line number Diff line change
Expand Up @@ -111,6 +111,6 @@ LIBRA
AGGLIB == "agglib.joy - aggregate library\n".
(* end LIBRA *)

"agglib is loaded\r\n" putchars.
"agglib is loaded\n" putchars.

(* END agglib.joy *)
Expand Down
4 changes: 2 additions & 2 deletions lib/grmlib.joy
Original file line number Diff line number Diff line change
Expand Up @@ -136,7 +136,7 @@ HIDE
parse-test == pop pop true or;
parse-count == # "count" put stack putln
pop pop succ;
parse-tell == "accept\r\n" putchars pop pop succ
parse-tell == "accept\n" putchars pop pop succ

IN

Expand Down Expand Up @@ -218,6 +218,6 @@ END; (* HIDE, parser *)
GRMLIB == "grmlib.joy - grammar (generating/parsing) library\n".

(* end LIBRA *)
"grmlib is loaded\r\n" putchars.
"grmlib is loaded\n" putchars.

(* END grmlib.joy *)
2 changes: 1 addition & 1 deletion lib/grmtst.joy
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
(* FILE: grmtst.joy *)

"\r\ntesting the grammar library in file grmlib.joy\r\n\n" putchars.
"\ntesting the grammar library in file grmlib.joy\n\n" putchars.

(*
DEFINE old_in == in;
Expand Down
6 changes: 3 additions & 3 deletions lib/inilib.joy
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ LIBRA

(* - - - - - I N P U T O U T P U T - - - - *)

newline == '\r putch '\n putch;
newline == '\n putch;
putln == put newline;
space == '\032 putch;
bell == '\007 putch;
Expand Down Expand Up @@ -97,7 +97,7 @@ LIBRA
[ '_ swons intern body null ]
[ ".joy" concat include ]
[ [ verbose ]
[ putchars " is already loaded\r\n" putchars ]
[ putchars " is already loaded\n" putchars ]
[ pop ]
ifte ]
ifte;
Expand All @@ -117,6 +117,6 @@ LIBRA
INILIB == "inilib.joy - the initial library, assumed everywhere\n".
(* end LIBRA *)

"inilib is loaded\r\n" putchars.
"inilib is loaded\n" putchars.

(* END inilib.joy *)
90 changes: 45 additions & 45 deletions lib/joytut.joy
Original file line number Diff line number Diff line change
Expand Up @@ -15,15 +15,15 @@ toc-of-tutorial ==
q1 ==
"What will the program " putchars
putchars
" leave on the stack ?\r\n" putchars
" leave on the stack ?\n" putchars
i
expecting;
q2 ==
"What will the dots ... have to be, so that\r\n\t" putchars
"What will the dots ... have to be, so that\n\t" putchars
putchars
"\r\nleaves " putchars
"\nleaves " putchars
putchars
" on the stack ?\r\n" putchars
" on the stack ?\n" putchars
i
expecting;

Expand All @@ -33,19 +33,19 @@ sec0 == toc-of-tutorial rest [first i] step;

sec1 == 1 toc-one-heading
ini-stats
[ "One of the data types in Joy is the type of integers.\r\n"
"Literal integers are written in ordinary decimal notation.\r\n"
"The usual binary operators are: + - * /\r\n"
"But these operators are written after their arguments.\r\n" ]
[ "One of the data types in Joy is the type of integers.\n"
"Literal integers are written in ordinary decimal notation.\n"
"The usual binary operators are: + - * /\n"
"But these operators are written after their arguments.\n" ]
putstrings
[get-integer 5 ] "2 3 +" q1
[get-integer 42 ] "7 6 *" q1
[get-integer 37 ] "7 6 * 2 3 + -" q1
[ "The most important aggregate datatype is that of lists.\r\n"
"These are written inside square brackets, like this:\r\n"
" [42 17 3 9 35]\r\n"
"Some important operators for lists are:\r\n"
" first rest cons concat\r\n" ]
[ "The most important aggregate datatype is that of lists.\n"
"These are written inside square brackets, like this:\n"
" [42 17 3 9 35]\n"
"Some important operators for lists are:\n"
" first rest cons concat\n" ]
putstrings
[get-integer 5 ] "[5 4 2 7] first" q1
[get-list [4 2 7] ] "[5 4 2 7] rest" q1
Expand All @@ -58,58 +58,58 @@ put-stats;

sec2 == 2 toc-one-heading
ini-stats
[ "Combinators are similar to operators, they expect something\r\n"
"on the stack. But combinators always expect a quoted program\r\n"
"and perhaps something else. For example, the map combinator\r\n"
"expects a single program and below that an aggregate, e.g. a list.\r\n"
[ "Combinators are similar to operators, they expect something\n"
"on the stack. But combinators always expect a quoted program\n"
"and perhaps something else. For example, the map combinator\n"
"expects a single program and below that an aggregate, e.g. a list.\n"
] putstrings
[get-list [6 4 8] ] "[3 2 4] [dup +] map" q1
[get-quote [10 + ] ]
"[13 12 14]" "[3 2 4] ... map" q2
[ "Another example is the filter combinator, which expects a\r\n"
"program that computes a truth value, and below that an aggregate.\r\n"
[ "Another example is the filter combinator, which expects a\n"
"program that computes a truth value, and below that an aggregate.\n"
] putstrings
[get-list [5 3 7] ] "\r\n\t[5 16 3 7 14] [10 <] filter" q1
"For the next question, provide the shortest answer\r\n" putchars
[get-list [5 3 7] ] "\n\t[5 16 3 7 14] [10 <] filter" q1
"For the next question, provide the shortest answer\n" putchars
[get-quote [20 <] ]
"[15 19 12]" "[5 10 9 11 2] [10 +] map ... filter" q2
put-stats;

sec3 == 3 toc-one-heading
ini-stats
[ "Two more complicated combinators are the ifte and the linrec\r\n"
[ "Two more complicated combinators are the ifte and the linrec\n"
"combinators. The ifte combinator expects three quotation "
"parameters\r\non the stack. In most cases they have been pushed just"
" beforehand.\r\n" ] putstrings
"parameters\non the stack. In most cases they have been pushed just"
" beforehand.\n" ] putstrings
[get-integer 15 ] "5 [7 <] [10 +] [10 -] ifte" q1
[get-integer -2 ] "8 [7 <] [10 +] [10 -] ifte" q1
[ "A programmer wants to write a recursive definition of the\r\n"
"factorial function, which has the form:\r\n"
" factorial ==\r\n"
" ... (* first quote *)\r\n"
" ... (* second quote *)\r\n"
" ... (* third quote *)\r\n"
" ifte\r\n" ]
[ "A programmer wants to write a recursive definition of the\n"
"factorial function, which has the form:\n"
" factorial ==\n"
" ... (* first quote *)\n"
" ... (* second quote *)\n"
" ... (* third quote *)\n"
" ifte\n" ]
putstrings
"What could be used as the first quote?\r\n" putchars
"What could be used as the first quote?\n" putchars
get-quote [[null][0 =][1 <]] expecting-from
"What could be used as the second quote?\r\n" putchars
"What could be used as the second quote?\n" putchars
get-quote [[pop 1][succ][1 +]] expecting-from
"This question is harder:\r\n" putchars
"What could be used as the third quote?\r\n" putchars
"This question is harder:\n" putchars
"What could be used as the third quote?\n" putchars
get-quote [[dup pred factorial *][dup 1 - factorial *]] expecting-from
[ "Later the programmer realises that the factorial function\r\n"
"is only needed in one place of the program, so it would be good\r\nnot"
"to have the definition at all, by using the linrec combinator:\r\n"
" [ null ] (* first quote *)\r\n"
" [ succ ] (* second quote *)\r\n"
" ... (* third quote *)\r\n"
" ... (* fourth quote *)\r\n"
" linrec\r\n" ]
[ "Later the programmer realises that the factorial function\n"
"is only needed in one place of the program, so it would be good\nnot"
"to have the definition at all, by using the linrec combinator:\n"
" [ null ] (* first quote *)\n"
" [ succ ] (* second quote *)\n"
" ... (* third quote *)\n"
" ... (* fourth quote *)\n"
" linrec\n" ]
putstrings
"What could be used as the third quote ?\r\n" putchars
"What could be used as the third quote ?\n" putchars
get-quote [[dup pred][dup 1 -]] expecting-from
"What could be used as the fourth quote ?\r\n" putchars
"What could be used as the fourth quote ?\n" putchars
get-quote [*] expecting
put-stats;

Expand Down
16 changes: 8 additions & 8 deletions lib/jp-joytst.joy
Original file line number Diff line number Diff line change
Expand Up @@ -6,22 +6,22 @@
1 setecho.
(* testing the tracing versions of joy0: joy0s and joy0l *)

2 3 + "\r\nfinal answer = " putchars.
2 3 + "\nfinal answer = " putchars.

[ 2 3 + ] joy0s "\r\nfinal answer = " putchars.
[ 2 3 + ] joy0s "\nfinal answer = " putchars.

[ [ 2 3 + ] joy0s ] joy0s "\r\nfinal answer = " putchars.
[ [ 2 3 + ] joy0s ] joy0s "\nfinal answer = " putchars.

[ [ [ 2 3 + ] joy0s ] joy0s ] joy0s "\r\nfinal answer = " putchars.
[ [ [ 2 3 + ] joy0s ] joy0s ] joy0s "\nfinal answer = " putchars.

[ 2 3 + ] joy0l "\r\nfinal answer = " putchars.
[ 2 3 + ] joy0l "\nfinal answer = " putchars.

[ [ 2 3 + ] joy0l ] joy0l "\r\nfinal answer = " putchars.
[ [ 2 3 + ] joy0l ] joy0l "\nfinal answer = " putchars.

[ [ [ 2 3 + ] joy0l ] joy0l ] joy0l "\r\nfinal answer = " putchars.
[ [ [ 2 3 + ] joy0l ] joy0l ] joy0l "\nfinal answer = " putchars.

(* and as a final absurdity, with no tracing at all: *)

[[[[[ 2 3 +] joy0] joy0] joy0] joy0] joy0 "\r\nfinal answer = "putchars.
[[[[[ 2 3 +] joy0] joy0] joy0] joy0] joy0 "\nfinal answer = "putchars.

(* END jp-joytst.joy *)
2 changes: 1 addition & 1 deletion lib/lazlib.joy
Original file line number Diff line number Diff line change
Expand Up @@ -101,6 +101,6 @@ LIBRA

(* end LIBRA *)

"lazlib is loaded\r\n" putchars.
"lazlib is loaded\n" putchars.

(* END lazlib.joy *)
2 changes: 1 addition & 1 deletion lib/laztst.joy
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
(* FILE: laztst.joy *)
"numlib" libload. (* R.W. *)

"\r\nTesting lazy lists in the library lazlib.joy\r\n" putchars.
"\nTesting lazy lists in the library lazlib.joy\n" putchars.

0 __settracegc.
"lazlib" libload.
Expand Down
14 changes: 7 additions & 7 deletions lib/lsplib.joy
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,7 @@ apply ==
swons ] (* install new frame *)
dip eval (* new-env body *)
popd ] (* restore old env *)
[ "apply: unknown procedure type -\r\n"
[ "apply: unknown procedure type -\n"
putchars abort ] ]
case ]

Expand Down Expand Up @@ -159,10 +159,10 @@ lib0 ==
l-prompt == "L: ";

lisp ==
[ "\r\nLisp interpreter\r\n"
"\t\tTo include the Lisp library, type\r\n"
"\t\t\t[ include \"OK\" \"lsplib.lsp\" ]\r\n"
"GO\r\n\n" ]
[ "\nLisp interpreter\n"
"\t\tTo include the Lisp library, type\n"
"\t\t\t[ include \"OK\" \"lsplib.lsp\" ]\n"
"GO\n\n" ]
putstrings
lib0 (* load lib0 *)
l-prompt putchars get
Expand All @@ -171,12 +171,12 @@ lisp ==
l-prompt putchars get ]
while
pop pop
"exit from Lisp interpreter\r\n" putchars;
"exit from Lisp interpreter\n" putchars;

LSPLIB == "lsplib.joy - (eval-apply) Lisp interpreter\n".

(* end LIBRA *)

"lsplib is loaded\r\n" putchars.
"lsplib is loaded\n" putchars.

(* END lsplib.joy *)
2 changes: 1 addition & 1 deletion lib/lsptst.joy
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
(* FILE: lsptst.joy *)

"\r\nTesting the Lisp interpreter lisp in the library lsplib.joy\r\n"
"\nTesting the Lisp interpreter lisp in the library lsplib.joy\n"
putchars.

"lsplib" libload.
Expand Down
Loading

0 comments on commit bc0aee7

Please sign in to comment.