Skip to content

Commit

Permalink
Archival checkin of converting grind to run on modern systems.
Browse files Browse the repository at this point in the history
  • Loading branch information
davidgiven committed Dec 14, 2024
1 parent a580e28 commit 346a18e
Show file tree
Hide file tree
Showing 40 changed files with 1,173 additions and 1,051 deletions.
1 change: 1 addition & 0 deletions build.lua
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@ installable {
"util/led+pkg",
"util/misc+pkg",
"util/opt+pkg",
"util/grind+pkg",
int
},
}
Expand Down
5 changes: 3 additions & 2 deletions util/LLgen/build.lua
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,7 @@ normalrule {
definerule("llgen",
{
srcs = { type="targets" },
basename = { type="string", default="Lpars" },
},
function(e)
-- Remember this is executed from the caller's directory; local
Expand All @@ -71,8 +72,8 @@ definerule("llgen",
name = e.name,
cwd = e.cwd,
outleaves = {
"Lpars.c",
"Lpars.h",
e.basename..".c",
e.basename..".h",
replace(fs, "$", ".c")
},
ins = {
Expand Down
2 changes: 1 addition & 1 deletion util/grind/avl.cc
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ struct avl_node
struct avl_tree
{
struct avl_node* root; /* root of the avl tree */
int (*cmp)(); /* address of comparison routine */
int (*cmp)(AVLtree* x, AVLtree* y); /* address of comparison routine */
};
/* create definitions for new_avl_tree() and free_avl_tree() */
/* STATICALLOCDEF "avl_tree" 2 */
Expand Down
25 changes: 10 additions & 15 deletions util/grind/avl.h
Original file line number Diff line number Diff line change
Expand Up @@ -13,31 +13,26 @@

typedef struct avl_tree* AVL_tree;

/* extern AVL_tree create_avl_tree(int (*cmp)());
Returns a fresh avl_tree structure. 'cmp' will be used as comparison
/* Returns a fresh avl_tree structure. 'cmp' will be used as comparison
routine for this tree.
*/
extern AVL_tree create_avl_tree();
extern AVL_tree create_avl_tree(int (*cmp)(char* x, char* y));

/* extern add_to_avl_tree(AVL_tree tree, char *n);
Adds the information indicated by 'n' to the avl_tree indicated by 'tree'.
/* Adds the information indicated by 'n' to the avl_tree indicated by 'tree'.
*/
extern add_to_avl_tree();
extern void add_to_avl_tree(AVL_tree tree, char *n);

/* extern char *find_ngt(AVL_tree tree, char *n);
Returns the information in the largest node that still compares <= to 'n',
/* Returns the information in the largest node that still compares <= to 'n',
or 0 if not present.
*/
extern char* find_ngt();
extern char *find_ngt(AVL_tree tree, char *n);

/* extern char *find_nlt(AVL_tree tree, char *n);
Returns the information in the largest node that still compares >= to 'n',
/* Returns the information in the largest node that still compares >= to 'n',
or 0 if not present.
*/
extern char* find_nlt();
extern char *find_nlt(AVL_tree tree, char *n);

/* extern char *find_eq(AVL_tree tree, char *n);
Returns the information in the node that compares equal to 'n',
/* Returns the information in the node that compares equal to 'n',
or 0 if not present.
*/
extern char* find_eq();
extern char *find_eq(AVL_tree tree, char *n);
152 changes: 152 additions & 0 deletions util/grind/build.lua
Original file line number Diff line number Diff line change
@@ -0,0 +1,152 @@
local hh_files = {
"./tree.hh",
"./file.hh",
"./symbol.hh",
"./type.hh",
}

local cc_files = {
"./avl.cc",
"./itemlist.cc",
"./langdep.cc",
"./scope.cc",
}

local hh_bases = basename(filenamesof(hh_files))
local cc_bases = basename(filenamesof(cc_files))

local h_targets = {}
for _, f in ipairs(hh_bases) do
local bf = f:gsub("%..*$", ""):gsub("^$./", "")
h_targets[#h_targets+1] = normalrule {
name = "hh_header/"..bf,
ins = { "./make.allocd", "./"..f },
outleaves = { bf..".h" },
commands = {
"%{ins[1]} < %{ins[2]} > %{outs}"
}
}
end

local c_targets = {}
for _, f in ipairs(cc_bases) do
local bf = f:gsub("%..*$", ""):gsub("^$./", "")
c_targets[#h_targets+1] = normalrule {
name = "cc_header/"..bf,
ins = { "./make.allocd", "./"..f },
outleaves = { bf..".c" },
commands = {
"%{ins[1]} < %{ins[2]} > %{outs}"
}
}
end

normalrule {
name = "tokenfile_g",
ins = { "./make.tokfile", "./tokenname.c" },
outleaves = { "tokenfile.g" },
commands = {
"%{ins[1]} < %{ins[2]} > %{outs}"
}
}

normalrule {
name = "tokenname_c",
ins = { "./make.tokcase", "./tokenname.c" },
outleaves = { "symbol2str.c" },
commands = {
"%{ins[1]} < %{ins[2]} > %{outs}"
}
}

normalrule {
name = "ops",
ins = { "./make.ops", "./operators.ot" },
outleaves = { "ops.c", "ops.h" },
commands = {
"%{ins[1]} %{ins[2]} %{outs[1]} %{outs[2]}"
}
}

llgen {
name = "commands_llgen",
srcs = {
-- order here is important
"+tokenfile_g",
"./commands.g",
}
}

llgen {
name = "db_symtab_llgen",
basename = "DBSpars",
srcs = {
-- order here is important
"./db_symtab.g",
}
}


cprogram {
name = "grind",
srcs = {
"./c.c",
"./do_comm.c",
"./expr.c",
"./idf.c",
"./list.c",
"./main.c",
"./modula-2.c",
"./pascal.c",
"./position.c",
"./print.c",
"./run.c",
"./symbol.c",
"./tokenname.c",
"./tree.c",
"./type.c",
"+tokenname_c",
matching(filenamesof("+commands_llgen"), "%.c$"),
matching(filenamesof("+db_symtab_llgen"), "%.c$"),
matching(filenamesof("+ops"), "%.c$"),
c_targets,
},
deps = {
"modules/src/data+lib",
"modules/src/string+lib",
"modules/src/system+lib",
"+commands_llgen",
"+db_symtab_llgen",
"+ops",
"./class.h",
"./expr.h",
"./idf.h",
"./langdep.h",
"./message.h",
"./misc.h",
"./operator.h",
"./position.h",
"./rd.h",
"./scope.h",
"./token.h",
"./tokenname.h",
"./print.h",
"./itemlist.h",
"h+emheaders",
"modules+headers",
"modules/src/alloc+lib",
"modules/src/idf+lib",
"modules/src/em_data+lib",
h_targets,
}
}

installable {
name = "pkg",
map = {
["$(INSDIR)/bin/grind"] = "+grind",
["$(INSDIR)/share/man/man1/grind.1"] = "./grind.1",
}
}


55 changes: 24 additions & 31 deletions util/grind/c.c
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@
/* Language dependant support; this one is for C */

#include <stdio.h>
#include <stdlib.h>
#include <string.h>

#include "position.h"
#include "class.h"
Expand All @@ -17,14 +19,16 @@

extern FILE *db_out, *db_in;

extern int get_name();

extern double atof();

static int print_string(), print_char(), get_number(), getstring(), get_token(), print_op(),
unop_prio(), binop_prio(), fix_bin_to_pref();

static long array_elsize();
static void print_string(FILE* f, char* s, int len);
static void print_char(int c);
static long array_elsize(long size);
static int binop_prio(int op);
static int unop_prio(int op);
static int getstring(int c);
static int get_number(int c);
static int get_token(int c);
static void print_op(FILE* f, p_tree p);
static void fix_bin_to_pref(p_tree p);

static struct langdep c_lang = { 0,

Expand Down Expand Up @@ -56,8 +60,7 @@ static struct langdep c_lang = { 0,

struct langdep* c_dep = &c_lang;

static void printchar(f, c, esc) FILE* f;
int c;
static void printchar(FILE* f, int c, int esc)
{
c &= 0377;
switch (c)
Expand Down Expand Up @@ -90,16 +93,14 @@ int c;
}
}

static print_char(c) int c;
static void print_char(int c)
{
putc('\'', db_out);
printchar(db_out, c, '\'');
putc('\'', db_out);
}

static print_string(f, s, len) FILE* f;
char* s;
int len;
static void print_string(FILE* f, char* s, int len)
{
char* str = s;

Expand All @@ -111,8 +112,7 @@ int len;

extern long int_size;

static long array_elsize(size)
long size;
static long array_elsize(long size)
{
if (!(int_size % size))
return size;
Expand All @@ -121,8 +121,7 @@ long size;
return ((size + int_size - 1) / int_size) * int_size;
}

static int unop_prio(op)
int op;
static int unop_prio(int op)
{
switch (op)
{
Expand Down Expand Up @@ -181,14 +180,12 @@ int op;
return 1;
}

static int val_in_base(c, base)
int c;
static int val_in_base(int c, int base)
{
return is_dig(c) ? c - '0' : base != 16 ? -1 : is_hex(c) ? (c - 'a' + 10) & 017 : -1;
}

static int get_number(c)
int c;
static int get_number(int c)
{
char buf[512 + 1];
int base = 10;
Expand Down Expand Up @@ -265,8 +262,7 @@ int c;
return REAL;
}

static int get_token(c)
int c;
static int get_token(int c)
{
switch (c)
{
Expand Down Expand Up @@ -394,8 +390,7 @@ int c;
}
}

static int quoted(ch)
int ch;
static int quoted(int ch)
{
/* quoted() replaces an escaped character sequence by the
character meant.
Expand Down Expand Up @@ -437,8 +432,7 @@ int ch;
return ch & 0377;
}

static int getstring(c)
int c;
static int getstring(int c)
{
int ch;
char buf[512];
Expand Down Expand Up @@ -475,8 +469,7 @@ int c;
return STRING;
}

static print_op(f, p) FILE* f;
p_tree p;
static void print_op(FILE* f, p_tree p)
{
switch (p->t_oper)
{
Expand Down Expand Up @@ -603,7 +596,7 @@ p_tree p;
}
}

static fix_bin_to_pref(p) p_tree p;
static void fix_bin_to_pref(p_tree p)
{
switch (p->t_whichoper)
{
Expand Down
Loading

0 comments on commit 346a18e

Please sign in to comment.