diff: more clpr changes

Fergus Henderson fjh at kryten.cs.mu.OZ.AU
Mon Sep 15 18:25:57 AEST 1997


More clean-ups of the CLP(R) source code.

clpr/clpr/standard.h:
	Define NO_RETURN as `attribute((no_return))' for gcc,
	so that we can avoid some spurious warnings from gcc.
	Also make CLPR_WORDSIZE signed rather than unsigned,
	to avoid some other spurious warnings.

clpr/clpr/main.h:
clpr/clpr/table.h:
clpr/clpr/codegen.h:
clpr/clpr/scan.h:
	New header files.

clpr/clpr/*.c:
	Use the new header files rather than using local
	extern declarations in each .c file.
	Fix a couple of bugs where the functions where
	declared to return `int' rather than `void'.
	Fix a portability problem: use `%p' rather than
	`%x' for printing pointers.
	Various other minor fixes, including at least one
	real bug fix (a missing `return' statement in solver.nlin.c).

clpr/clpr/Makefile:
	Include the new header files in $(HEADERS).

clpr/clpr/Mmakefile:
	Change $(MGNUCFLAGS) to enable some more warnings.

Don't bother reading the diff, it is very boring.
I include it here only for completeness.

cvs diff: Diffing .
Index: Makefile
===================================================================
RCS file: /home/mercury1/repository/clpr/clpr/Makefile,v
retrieving revision 1.4
diff -u -u -r1.4 Makefile
--- 1.4	1997/09/08 18:29:43
+++ Makefile	1997/09/14 18:41:47
@@ -155,7 +155,7 @@
 #         for Silicon Graphics machines
 
 HEADERS = standard.h config.h parse.h symbols.h lib.h compile.h opcodes.h \
-			emul.h solver.h
+			emul.h solver.h main.h codegen.h table.h scan.h
 
 SRC = main.c compile.c init.c scan.c parse.c table.c pio.c codegen.c \
 		emit.c arithgen.c emul.c trace.c lib.c  \
Index: Mmakefile
===================================================================
RCS file: /home/mercury1/repository/clpr/clpr/Mmakefile,v
retrieving revision 1.6
diff -u -u -r1.6 Mmakefile
--- 1.6	1997/09/14 13:08:48
+++ Mmakefile	1997/09/14 18:52:54
@@ -8,8 +8,8 @@
 
 MAIN_TARGET = libclpr
 
-MGNUCFLAGS=--no-ansi --no-check -- -g -W
-# MGNUCFLAGS=--no-ansi --no-check -- -g
+MGNUCFLAGS=--no-ansi --no-check -- -g \
+-Wall -W -Wno-uninitialized -Wno-unused -Wno-parentheses
 
 OBJECTS= arithgen.o codegen.o compile.o debug.o dump.o emit.o emul.o index.o \
 	init.o lib.o main.o meta.o parse.o pio.o scan.o solver.btk.o solver.o \
Index: arithgen.c
===================================================================
RCS file: /home/mercury1/repository/clpr/clpr/arithgen.c,v
retrieving revision 1.7
diff -u -u -r1.7 arithgen.c
--- 1.7	1997/09/08 19:04:24
+++ arithgen.c	1997/09/14 18:02:41
@@ -14,6 +14,8 @@
 #include "compile.h"
 #include "emul.h"
 #include "solver.h"
+#include "main.h"
+#include "codegen.h"
 
 #define is_single_var(eqn) \
 	(is_zero((eqn)->constant) && (eqn)->next && !(eqn)->next->next) 
@@ -54,7 +56,6 @@
 extern void emit_solve_pf0 (void);
 extern CLPR_int free_eqn_nodes (EQN_ptr eqn);
 void CLPR_domain_error (char *s);
-extern void fatal (char *s);
 extern void add_eqns (CLPR_int type, EQN_ptr eqn1, EQN_ptr eqn2, double factor);
 extern void emit_solve_ge0 (void);
 extern void emit_solve_gt0 (void);
@@ -86,7 +87,6 @@
 extern void delete_lable (CLPR_int val);
 extern void assign_p_compiled (CLPR_int name, CLPR_int flag);
 extern void assign_p_first_rule (CLPR_int name, RULE_ptr rule);
-extern void type_error (char *s, ...);
 
 void half_constraint(CLPR_int is_new_reg, CLPR_int i, PTERM *t)
 {
Index: clpr_misc.c
===================================================================
RCS file: /home/mercury1/repository/clpr/clpr/clpr_misc.c,v
retrieving revision 1.6
diff -u -u -r1.6 clpr_misc.c
--- 1.6	1997/09/14 12:09:23
+++ clpr_misc.c	1997/09/14 18:03:16
@@ -1,9 +1,11 @@
 #include <stdio.h>
+#include <stdlib.h>
 #include "standard.h"
 #include "config.h"
 #include "emul.h"
 #include "solver.h"
 #include "clpr_misc.h"
+#include "main.h"
 
 /*---------------------------------------------------------------------------*/
 /*
Index: codegen.c
===================================================================
RCS file: /home/mercury1/repository/clpr/clpr/codegen.c,v
retrieving revision 1.8
diff -u -u -r1.8 codegen.c
--- 1.8	1997/09/08 19:04:33
+++ codegen.c	1997/09/14 18:03:26
@@ -8,6 +8,7 @@
 
 #include <string.h>
 #include <stdarg.h>
+#include <stdlib.h>
 #include "standard.h"
 #include "config.h"
 #include "parse.h"
@@ -16,6 +17,8 @@
 #include "compile.h"
 #include "opcodes.h"
 #include "emul.h"
+#include "main.h"
+#include "codegen.h"
 
 #define MAX_VAR_TO_VREC 256
 #define MAX_DUMP_VARSTRING 4096
@@ -137,7 +140,6 @@
 void compile_body (PTERM *t, CLPR_int last, CLPR_int sav, CLPR_int nvars);
 extern void emit_dyn_call (CLPR_int val);
 extern void emit_callp (char *s, CLPR_int val);
-extern void fatal (char *s);
 void put_arg (PTERM *t, CLPR_int reg, CLPR_int last);
 extern void emit_dump (char *str, CLPR_int *regs);
 extern void emit_restore (void);
@@ -162,7 +164,6 @@
 extern void emit_printf (CLPR_int *regs);
 void freereg (CLPR_int i);
 extern void emit_print (CLPR_int *regs);
-void type_error (char *s, ...);
 extern void emit_read (char *str, CLPR_int num, CLPR_int *regs);
 CLPR_int check_dump_args (PTERM *t);
 extern void emit_retract (CLPR_int *regs);
@@ -173,7 +174,6 @@
 extern void print_term (PTERM *t, CLPR_int priority);
 void cleanup_rulebase (void);
 extern CLPR_int close_input (FILE *stream);
-extern void top_level (void);
 void vars_in_atom (PTERM *t, CLPR_int atom);
 CLPR_int vars_in_term (PTERM *t, CLPR_int atom, CLPR_int arg, CLPR_int constr, CLPR_int arith, CLPR_int level);
 CLPR_int find_target_reg (VREC *v, CLPR_int atom);
@@ -724,7 +724,8 @@
 
 extern FILE *cur_stream;
 extern char *cur_filename;
-void type_error(char *s, ...)
+
+void type_error(const char *s, ...)
 {
 char buf[256];
 va_list l;
Index: codegen.h
===================================================================
RCS file: codegen.h
diff -N codegen.h
--- /dev/null	Mon Sep 15 18:21:32 1997
+++ codegen.h	Mon Sep 15 04:47:48 1997
@@ -0,0 +1,2 @@
+#include "standard.h"
+void type_error (const char *s, ...) NO_RETURN;
Index: compile.c
===================================================================
RCS file: /home/mercury1/repository/clpr/clpr/compile.c,v
retrieving revision 1.6
diff -u -u -r1.6 compile.c
--- 1.6	1997/09/08 19:04:36
+++ compile.c	1997/09/14 18:31:35
@@ -7,6 +7,7 @@
  ***************************************************************/
 
 #include <string.h>
+#include <stdlib.h>
 #include "standard.h"
 #include "config.h"
 #include "parse.h"
@@ -15,6 +16,7 @@
 #include "compile.h"
 #include "emul.h"
 #include "opcodes.h"
+#include "main.h"
 
 #define MIN_CODE_SZ (24000)
 
@@ -70,7 +72,6 @@
 /*---------------------------------------------------------------------------*/
 
 
-extern void fatal (char *s);
 CLPR_int readfile (char *s, CLPR_int clobber);
 extern void compile (char clobber);
 void resolve (CLPR_int warn);
@@ -82,8 +83,6 @@
 extern void lookatvars (PTERM *t);
 extern CLPR_int rungoal (CLPR_int ipc, CLPR_int interactive);
 extern CLPR_int compile_fgoal (PTERM *t);
-extern void warning (char *s, ...);
-extern void interrupt (void);
 extern void restore_context (void);
 CLPR_int p_compiled (CLPR_int name);
 extern void warn_header (void);
@@ -240,7 +239,7 @@
 				warning("%s:%d, goal failed within consult", the_filename(), the_lineno());
 				if (WARN_ABORT) {		
 					fprintf(error_stream, "Aborting\n");
-					interrupt();
+					interrupt(0);
 				}
 			}
 #ifdef FREE_CODE_SPACE
Index: debug.c
===================================================================
RCS file: /home/mercury1/repository/clpr/clpr/debug.c,v
retrieving revision 1.7
diff -u -u -r1.7 debug.c
--- 1.7	1997/09/08 18:46:07
+++ debug.c	1997/09/14 17:59:59
@@ -15,6 +15,7 @@
 #include "opcodes.h"
 #include "emul.h"
 #include "solver.h"
+#include "main.h"
 
 CLPR_int inst_count[MAX_OPCODE + 1];
 
@@ -50,7 +51,6 @@
 extern void printterm (FILE *f, CLPR_int *t);
 extern void output_arith_func (CLPR_int type);
 extern void print_var2pos (FILE *f, CLPR_int *v);
-extern void fatal (char *s);
 
 void check_eq_tableau(void)
 {
@@ -332,7 +332,7 @@
 	if (!hdr) fprintf(outfile, "<NULL hdr>\n");
 	else {
 		i = hdr->eqn->id;
-		fprintf(outfile, "HDR (%x):\n", hdr);
+		fprintf(outfile, "HDR (%p):\n", hdr);
 		fprintf(outfile, "\teqn: "); print_eqn(hdr->eqn);
 		fprintf(outfile, "\teq_occ: "); print_eq_occ(i);
 		fprintf(outfile, "\tineq_occ: "); print_ineq_occ(i);
Index: dump.c
===================================================================
RCS file: /home/mercury1/repository/clpr/clpr/dump.c,v
retrieving revision 1.8
diff -u -u -r1.8 dump.c
--- 1.8	1997/09/14 12:09:25
+++ dump.c	1997/09/14 18:32:06
@@ -17,6 +17,7 @@
 #include "emul.h"
 #include "solver.h"
 #include "symbols.h"
+#include "main.h"
 
 #define MAX_FOURIER_VARS (9999)
 #define MAX_NLIN_VARS (9999)
@@ -153,7 +154,7 @@
 static CLPR_int *collect_vars(CLPR_int *vars, char *names, CLPR_int dump1_or_2_or_3);
 static CLPR_int collect_named_vars(CLPR_int *vars, CLPR_int *names);
 static CLPR_int **collect_atom_vars(CLPR_int *term);
-static CLPR_int collect_assert_vars(CLPR_int *term);
+static void collect_assert_vars(CLPR_int *term);
 static CLPR_int find_flatten_var(CLPR_int *t);
 static void make_equiv_funct_vars(void);
 static void make_equiv_pivot_vars(void);
@@ -203,7 +204,6 @@
 void dump_nlin_eqns (void);
 void dump_remaining_real_vars (void);
 void cleanup_dump (void);
-extern void runtime_error (char *s, ...);
 void add_nlin_eqns (void);
 void add_remaining_real_vars (void);
 extern CLPR_int unify (CLPR_int *t1, CLPR_int *t2);
@@ -218,7 +218,6 @@
 CLPR_int is_pivot_var (CLPR_int v);
 void add_equiv_pivot_var (CLPR_int v, CLPR_int *h, char *s);
 void add_pivot_var (CLPR_int v, CLPR_int *h, char *s);
-extern void fatal (char *s);
 extern CLPR_int is_ground (CLPR_int v, double *c_ptr);
 void get_eval_vars (CLPR_int *t);
 extern void printterm (FILE *f, CLPR_int *t);
@@ -239,10 +238,8 @@
 CLPR_int check_cyclic (CLPR_int v0, CLPR_int v1);
 CLPR_int check_eval_cyclic (CLPR_int *v0, CLPR_int *v1);
 CLPR_int quasi_similar (EQN_ptr eqn1, EQN_ptr eqn2);
-CLPR_int contract (EQN_ptr eqn);
 CLPR_int next_fourier_id (void);
 CLPR_int kohler_merge_count (KOHLER_ptr koh1, KOHLER_ptr koh2);
-CLPR_int expand (EQN_ptr eqn1, EQN_ptr eqn2, double factor);
 void dec_f_neg (CLPR_int id);
 void dec_f_pos (CLPR_int id);
 extern void delete_occ (CLPR_int type, CLPR_int i, CLPR_int v);
@@ -277,6 +274,9 @@
 void special_print_eqn (EQN_ptr eqn);
 extern CLPR_int makenum (CLPR_int v, double c);
 
+static void expand (EQN_ptr eqn1, EQN_ptr eqn2, double factor);
+static void contract (EQN_ptr eqn);
+
 void dump1(FILE *f, CLPR_int *vars, char *names)
 {
 	is_dump_output = TRUE;
@@ -474,7 +474,7 @@
 	return new_vars;
 }
 
-static CLPR_int collect_assert_vars(CLPR_int *term)
+static void collect_assert_vars(CLPR_int *term)
 {
 	collect_deep_vars(term);
 	orig_funct_vars_top = funct_vars_top;
@@ -831,7 +831,7 @@
 CLPR_int i;
 	for (i= 1; i <= flatten_vars_top; i++) {
 		printf("t = "); printterm(stdout, flatten_vars[i].rep);
-		printf(" var = %x",flatten_vars[i].var); 
+		printf(" var = %p",flatten_vars[i].var); 
 /*		printf(" var = "); printterm(stdout, flatten_vars[i].var);  */
 		printf(" new_var = "); printterm(stdout, flatten_vars[i].new_var);
 		printf("\n"); 
@@ -1400,7 +1400,7 @@
 	return count;
 }
 
-CLPR_int contract(EQN_ptr eqn) /*** do not free EQN's ***/
+void contract(EQN_ptr eqn) /*** do not free EQN's ***/
             
 {
 CLPR_int i, j;
@@ -1426,7 +1426,7 @@
 	eqn_i->params->kohler = NULL;
 }
 
-CLPR_int expand(EQN_ptr eqn1, EQN_ptr eqn2, double factor) /*** new eqn = eqn1 + eqn2 * factor ***/
+void expand(EQN_ptr eqn1, EQN_ptr eqn2, double factor) /*** new eqn = eqn1 + eqn2 * factor ***/
                    
               
 {
@@ -2363,7 +2363,7 @@
 		orig_pivot_vars_top, orig_funct_vars_top, 
 		pivot_vars_top, funct_vars_top);
 	for (i = 1; i <= funct_vars_top; i++) {
-		printf("funct_vars[%d] = b:%x, r:%x ", 
+		printf("funct_vars[%d] = b:%p, r:%p ", 
 			i, funct_vars[i].bind, funct_vars[i].rep);
 			print_var2pos(stdout, funct_vars[i].rep);
 /*
Index: emul.c
===================================================================
RCS file: /home/mercury1/repository/clpr/clpr/emul.c,v
retrieving revision 1.7
diff -u -u -r1.7 emul.c
--- 1.7	1997/09/08 19:04:46
+++ emul.c	1997/09/14 18:34:23
@@ -24,6 +24,7 @@
 #include "opcodes.h"
 #include "emul.h"
 #include "solver.h"
+#include "main.h"
 
 #define MIN_HEAP_SZ   256
 #define MIN_LSTACK_SZ 256
@@ -159,7 +160,6 @@
 /*---------------------------------------------------------------------------*/
 
 
-extern void fatal (char *s);
 extern CLPR_int sum_str (register char *s);
 extern void storename (char *s, CLPR_int val, CLPR_int narg);
 extern char *maketag (CLPR_int n, char *extra, char *str, CLPR_int arity);
@@ -170,8 +170,6 @@
 extern CLPR_int free_nl_occ_nodes (NL_OCC_ptr occ);
 void solver_backtrack (CLPR_int i);
 extern CLPR_int wake_runable (void);
-extern void warning (char *s, ...);
-extern void runtime_error (char *s, ...);
 extern CLPR_int p_dynamic (CLPR_int name);
 extern void make_runable (CLPR_int *t);
 extern CLPR_int is_ground (CLPR_int v, double *c_ptr);
@@ -3159,7 +3157,7 @@
 	return TRUE;
 }
 
-CLPR_int push_destructive_trail(CLPR_int *t, CLPR_int val)
+void push_destructive_trail(CLPR_int *t, CLPR_int val)
 {
     if (t < safeheap || (t > lstack && t < lastcp)) { 
 		trail[trtop++] = (CLPR_int *) val;
Index: emul.h
===================================================================
RCS file: /home/mercury1/repository/clpr/clpr/emul.h,v
retrieving revision 1.5
diff -u -u -r1.5 emul.h
--- 1.5	1997/09/08 19:04:49
+++ emul.h	1997/09/14 18:47:48
@@ -101,7 +101,7 @@
 #endif
 #define mask(i) ((i) & (def_tag(0x1) - 1))
 #define addtag(t, i) ((CLPR_int) ((t) | (((CLPR_int)(i)) & (def_tag(0x1) - 1))))
-#define addtag1(t, i) ((CLPR_unsigned) (((CLPR_unsigned) (t)) | (i)))
+#define addtag1(t, i) ((CLPR_int) (((CLPR_int) (t)) | (i)))
 #define add_misctag(i) (i)
 
 /*---------------------------------------------------------------------------*/
@@ -194,3 +194,8 @@
 }
 
 #define caseop(x) case (CLPR_int) x
+
+/*---------------------------------------------------------------------------*/
+
+extern void push_destructive_trail (CLPR_int *t, CLPR_int val);
+
Index: index.c
===================================================================
RCS file: /home/mercury1/repository/clpr/clpr/index.c,v
retrieving revision 1.6
diff -u -u -r1.6 index.c
--- 1.6	1997/09/08 18:46:25
+++ index.c	1997/09/14 17:26:15
@@ -15,6 +15,7 @@
 #include "compile.h"
 #include "opcodes.h"
 #include "emul.h"
+#include "main.h"
 
 #define MAX_INDEX_CHAIN 256 /*** do not increase ***/
 #define MAX_INDEX_CLAUSES 256
@@ -80,7 +81,6 @@
 void add_to_chain (CLPR_int type, CLPR_int val, CLPR_int rule_number);
 extern CLPR_int float_to_int (float f);
 extern void show_pterm (PTERM *t);
-extern void fatal (char *s);
 void gen_switch1type (CLPR_int type);
 void gen_switchtype (void);
 extern void emit_switchdot (char *s, CLPR_int val);
Index: init.c
===================================================================
RCS file: /home/mercury1/repository/clpr/clpr/init.c,v
retrieving revision 1.7
diff -u -u -r1.7 init.c
--- 1.7	1997/09/08 19:04:50
+++ init.c	1997/09/15 08:14:54
@@ -7,6 +7,7 @@
  ***************************************************************/
 
 #include <stdarg.h>
+#include <stdlib.h>
 #include "standard.h"
 #include "config.h"
 #include "parse.h"
@@ -15,6 +16,8 @@
 #include "opcodes.h"
 #include "emul.h"
 #include "solver.h"
+#include "table.h"
+#include "main.h"
 
 char *CLP_SUFFIX;
 
@@ -102,10 +105,7 @@
 
 /*---------------------------------------------------------------------------*/
 
-
-extern struct HASHNODE *add_func (char *name, CLPR_int narg, CLPR_int val);
 extern CLPR_int hashbuiltina (char *s, CLPR_int n);
-extern void fatal (char *s);
 extern void assign_p_protected (CLPR_int name, CLPR_int flag);
 void init_malloc (void);
 extern void init_compiler (void);
@@ -121,7 +121,6 @@
 extern PTERM *func_narg_pterm (PTERM *t, CLPR_int narg);
 extern CLPR_int do_op (char *sym, char *style, CLPR_int pri);
 extern void setconst (char *sym, double num);
-extern void warning (char *s, ...);
 void init_fatal (char *s, ...);
 void test_pmask (void);
 extern void check_solver_sizes (void);
Index: lib.c
===================================================================
RCS file: /home/mercury1/repository/clpr/clpr/lib.c,v
retrieving revision 1.8
diff -u -u -r1.8 lib.c
--- 1.8	1997/09/08 19:28:04
+++ lib.c	1997/09/15 08:15:19
@@ -28,8 +28,10 @@
 
 #include <unistd.h>
 
+#include <stdlib.h>
 #include <ctype.h>
 #include <string.h>
+
 #include "standard.h"
 #include "config.h"
 #include "parse.h"
@@ -38,6 +40,7 @@
 #include "compile.h"
 #include "emul.h"
 #include "opcodes.h"
+#include "main.h"
 
 #define U_SEC (1000000.0)
 #if defined(BSD) && !defined(OS2V2)
@@ -235,18 +238,17 @@
 
 static PTERM *ht_to_pterm(CLPR_int *t, CLPR_int quoted, CLPR_int with_dump);
 static CLPR_int heapify_pterm(PTERM *t, CLPR_int *hp, CLPR_int quoted);
+static void term_printf (FILE *F, char *fmt, CLPR_int fmt_ty,
+			CLPR_int **arg_list);
 
 /*---------------------------------------------------------------------------*/
 
 
 extern void warn_err (char *s, ...);
-extern void fatal (char *s);
 extern CLPR_int make_a_con (CLPR_int *t, CLPR_int val);
 extern CLPR_int hashbuiltina (char *s, CLPR_int n);
 extern CLPR_int myisdigit (char c);
-CLPR_int term_printf (FILE *F, char *fmt, CLPR_int fmt_ty, CLPR_int **arg_list);
 extern CLPR_int is_ground (CLPR_int v, double *c_ptr);
-extern void runtime_error (char *s, ...);
 extern void print_var2pos (FILE *f, CLPR_int *v);
 extern void printterm (FILE *f, CLPR_int *t);
 extern void dump1 (FILE *f, CLPR_int *vars, char *names);
@@ -289,21 +291,18 @@
 extern void assign_p_cut (CLPR_int name, CLPR_int flag);
 extern void assign_p_spy (CLPR_int name, CLPR_int flag);
 extern void delete_lable (CLPR_int val);
-extern void interrupt (void);
 extern CLPR_int makenum (CLPR_int v, double c);
 extern CLPR_int make_a_num (CLPR_int *t, double val);
 extern CLPR_int make_a_nil (CLPR_int *t);
 extern CLPR_int make_a_new_list (CLPR_int *t);
 extern CLPR_int wake_runable (void);
 extern CLPR_int make_a_new_fun (CLPR_int *t, CLPR_int val, CLPR_int arity);
-extern CLPR_int push_destructive_trail (CLPR_int *t, CLPR_int val);
 CLPR_int occurs (CLPR_int *vspot, CLPR_int *t);
 extern CLPR_int equal_param (CLPR_int v1, CLPR_int v2);
 extern CLPR_int do_op (char *sym, char *style, CLPR_int pri);
 extern void assign_p_protected (CLPR_int name, CLPR_int flag);
 extern void printhist (CLPR_int n);
 extern CLPR_int p_spy (CLPR_int name);
-extern void warning (char *s, ...);
 extern void assign_p_dynamic (CLPR_int name, CLPR_int flag);
 extern void print_ineq_tableau (void);
 extern void check_tableaus (void);
@@ -521,7 +520,8 @@
 
 extern CLPR_int slack_id;
  
-CLPR_int term_printf(FILE *F, char *fmt, CLPR_int fmt_ty, CLPR_int **arg_list)
+static void
+term_printf(FILE *F, char *fmt, CLPR_int fmt_ty, CLPR_int **arg_list)
 {
 CLPR_int *t;
 double val;
@@ -532,7 +532,7 @@
 		*arg_list= findbind((CLPR_int *)(pmask(**arg_list)) + 1);
 	} else {
 		warn_err("bad second argument to printf/2");
-		return FALSE;
+		return;
 	}
 	if (CLPR_tag(*t) == TAG_PAR) {
 		if (is_ground(mask(*t), &val)) {
@@ -1392,7 +1392,7 @@
 
 CLPR_int do_abort(void)
 {
-	interrupt();
+	interrupt(0);
 }
 
 CLPR_int do_sh(void)
Index: main.c
===================================================================
RCS file: /home/mercury1/repository/clpr/clpr/main.c,v
retrieving revision 1.7
diff -u -u -r1.7 main.c
--- 1.7	1997/09/08 19:04:55
+++ main.c	1997/09/15 08:15:27
@@ -104,6 +104,7 @@
 #include "parse.h"
 #include "symbols.h"
 #include "emul.h"
+#include "main.h"
 
 #define NARGS_MIN 1            /* minimum command line arguments */
 #define NARGS_MAX 100          /* maximum command line arguments */
@@ -150,9 +151,9 @@
 extern char peek(void);
 #endif
 
-void interrupt(CLPR_int);
-void bus_error(CLPR_int);
-void seg_fault(CLPR_int);
+void interrupt(int) NO_RETURN;
+void bus_error(int) NO_RETURN;
+void seg_fault(int) NO_RETURN;
 
 /*---------------------------------------------------------------------------*/
 
@@ -162,7 +163,6 @@
 
 
 extern void test_system_defaults (void);
-void usage_error (void);
 extern CLPR_int myisdigit (char c);
 extern void cmd_ranseed (CLPR_int i);
 extern void init_scanner (void);
@@ -174,10 +174,11 @@
 extern CLPR_int isatty (CLPR_int);
 extern char readchar (void);
 extern CLPR_int internal_consult (char *s);
-void warning (char *s, ...);
 extern void top_free_things (void);
 extern void files_shutdown (void);
-void final_clean (void);
+
+static void usage_error (void);
+static void final_clean (void);
 
 CLPR_int checkhist(PTERM *t, CLPR_int *np);
 void pushhist (PTERM *g);
@@ -196,7 +197,8 @@
 int CLPR_main(int argc, char **argv)
 {
 char *opt_p;
-CLPR_int i, pc, return_code, goal_number;
+CLPR_int i, pc, return_code;
+volatile CLPR_int goal_number; /* must be volatile because of setjmp() */
 PTERM *t;
 
 	error_stream = stderr;
@@ -398,7 +400,7 @@
 
 /*---------------------------------------------------------------------------*/
 
-void interrupt(CLPR_int sig)
+void interrupt(int sig)
 {
 	signal(SIGINT, SIG_IGN);
 	int_clean();
@@ -412,20 +414,20 @@
 	interrupt(0);
 }
 
-void bus_error(CLPR_int sig)
+void bus_error(int sig)
 {
 	fprintf(error_stream, "Bus error: no core dumped\n");
 	exit(1);
 }
 
-void seg_fault(CLPR_int sig)
+void seg_fault(int sig)
 {
 	fprintf(error_stream, "Segmentation fault: no core dumped\n");
 	fflush(error_stream);
 	exit(1);
 }
 
-void usage_error(void)
+static void usage_error(void)
 {
 	fprintf(error_stream, "Usage: clpr [-{chlst}s <n>] ");
 	fprintf(error_stream, "[-z <real>] [-r <CLPR_int>] [file]\n");
@@ -433,7 +435,7 @@
 	exit(2);
 }
 
-void warning(char *s, ...)
+void warning(const char *s, ...)
 {
 char buf[256];
 	if (WARNING_FLAG) {
@@ -463,7 +465,7 @@
 	}
 }
 
-void runtime_error(char *s, ...)
+void runtime_error(const char *s, ...)
 {
 char buf[256];
 	va_list l;
@@ -475,7 +477,7 @@
 	top_level();
 }
 
-void fatal(char *s)
+void fatal(const char *s)
 {
 	fprintf(stderr, "Fatal Error: %s\n",s);
 	fflush(stderr);
@@ -490,7 +492,7 @@
 		the_lineno());
 }
 
-void final_clean(void)
+static void final_clean(void)
 {
 	clean_temp_file();
 }
Index: main.h
===================================================================
RCS file: main.h
diff -N main.h
--- /dev/null	Mon Sep 15 18:21:32 1997
+++ main.h	Mon Sep 15 18:15:42 1997
@@ -0,0 +1,6 @@
+#include "standard.h"
+extern void top_level(void) NO_RETURN;
+extern void fatal(const char *) NO_RETURN;
+extern void runtime_error(const char *, ...) NO_RETURN;
+extern void interrupt(int) NO_RETURN;
+void warning (const char *s, ...);
Index: meta.c
===================================================================
RCS file: /home/mercury1/repository/clpr/clpr/meta.c,v
retrieving revision 1.7
diff -u -u -r1.7 meta.c
--- 1.7	1997/09/08 19:04:57
+++ meta.c	1997/09/14 17:26:58
@@ -16,6 +16,7 @@
 #include "opcodes.h"
 #include "emul.h"
 #include "solver.h"
+#include "main.h"
 
 #define has_a_hat(t) ((mask(*t) >= ARITH_FUNC_4) && (mask(*t) <= ARITH_FUNC_5))
 
@@ -40,7 +41,6 @@
 CLPR_int suspend_eval (CLPR_int *t1, CLPR_int *t2);
 extern CLPR_int unify (CLPR_int *t1, CLPR_int *t2);
 CLPR_int setup_eqn (CLPR_int *t1, CLPR_int *t);
-extern void fatal (char *s);
 void make_daemon (CLPR_int *t, CLPR_int *d);
 void add_runable (CLPR_int *t);
 extern void push_change_nl_eqn (CLPR_int old_type, CLPR_int pos, NL_EQN_ptr nl_eqn0);
Index: parse.c
===================================================================
RCS file: /home/mercury1/repository/clpr/clpr/parse.c,v
retrieving revision 1.5
diff -u -u -r1.5 parse.c
--- 1.5	1997/09/08 18:46:54
+++ parse.c	1997/09/14 17:49:25
@@ -11,6 +11,9 @@
 #include "standard.h"
 #include "parse.h"
 #include "symbols.h"
+#include "main.h"
+#include "scan.h"
+#include "table.h"
 
 #define NULLPT ((PTERM *) 0)
 
@@ -48,15 +51,6 @@
 	Parse a prolog term with priority n (lower n, higer priority);
 	Usually start with get_pterm(MAXPRI)
 ***/
-
-
-extern CLPR_int scan (void);
-extern CLPR_int is_op_hnode (struct HASHNODE *hnode, CLPR_int ty, CLPR_int *pri, CLPR_int *left, CLPR_int *right);
-extern CLPR_int is_nfix_hnode (struct HASHNODE *hnode);
-extern void synerr (char *s);
-extern void fatal (char *s);
-extern CLPR_int is_punc (char punc);
-extern void zero_vars (void);
 
 PTERM *get_pterm(CLPR_int n)
 {
Index: pio.c
===================================================================
RCS file: /home/mercury1/repository/clpr/clpr/pio.c,v
retrieving revision 1.6
diff -u -u -r1.6 pio.c
--- 1.6	1997/09/08 18:47:00
+++ pio.c	1997/09/14 18:01:11
@@ -15,6 +15,7 @@
 #include "lib.h"
 #include "compile.h"
 #include "emul.h"
+#include "main.h"
 
 extern FILE *outfile;
 extern CLPR_int debug_flg;
@@ -24,7 +25,6 @@
 
 
 void show_pterm (PTERM *t);
-extern void fatal (char *s);
 void print_term (PTERM *t, CLPR_int priority);
 void print_list (PTERM *t);
 extern CLPR_int get_op_priority (char *name, CLPR_int narg, CLPR_int *left, CLPR_int *right);
@@ -65,7 +65,7 @@
 		return;
 	}
 	if (debug_flg > 1)
-		fprintf(outfile,"%s{t %x,%d,%d,%d}",t->str,t,t->ty,t->val,t->narg);
+		fprintf(outfile,"%s{t %p,%d,%d,%d}",t->str,t,t->ty,t->val,t->narg);
 	else if (isalpha(t->str[0]))	
 	    fprintf(outfile,"%s",t->str);
 	else
@@ -304,7 +304,7 @@
 	if (is_heap_ptr(v)) fprintf(f, "_h%d", var2pos(v, CLPR_heap));
 	else if (is_stack_ptr(v)) fprintf(f, "_s%d", var2pos(v, lstack));
 	else {
-		printf("***** v = %x ***** stack=%x heaptop=%x stacktop=%x\n", 
+		printf("***** v = %p ***** stack=%p heaptop=%p stacktop=%p\n", 
 			v, stack, heaptop, stacktop);
 		fflush(stdout);
 		fatal("56912");
Index: scan.c
===================================================================
RCS file: /home/mercury1/repository/clpr/clpr/scan.c,v
retrieving revision 1.4
diff -u -u -r1.4 scan.c
--- 1.4	1997/09/08 18:47:03
+++ scan.c	1997/09/14 17:54:21
@@ -7,11 +7,15 @@
  ***************************************************************/
 
 #include <setjmp.h>
+#include <string.h>
 
 #include "standard.h"
 #include "config.h"
 #include "parse.h"
 #include "symbols.h"
+#include "table.h"
+#include "main.h"
+#include "scan.h"
 
 #define MAX_BUF	    (511)          /* max line length */
 
@@ -170,23 +174,13 @@
 extern PTERM *null_list;
 extern char *cons_str;
 
-extern PTERM *lookup_var(char *var, CLPR_int quick_cmp);
-extern PTERM *lookup_name(char *sym, CLPR_int quick_cmp);
-extern PTERM *lookup_const(char *sym, CLPR_int quick_cmp);
-extern PTERM *new_real(double val);
-extern PTERM *new_str(char *s);
-extern PTERM *new_pt_emptylist(void);
-
 extern struct HASHNODE *hnode_emptylist;
 extern PTERM *null_list;
 
 /*---------------------------------------------------------------------------*/
 
 
-extern char *strncpy (char *, const char *, size_t);
-extern void fatal (char *s);
 void unreadchar (register char c);
-void synerr (char *s);
 
 void init_scanner(void)
 {
Index: scan.h
===================================================================
RCS file: scan.h
diff -N scan.h
--- /dev/null	Mon Sep 15 18:21:32 1997
+++ scan.h	Mon Sep 15 04:47:48 1997
@@ -0,0 +1,4 @@
+#include "standard.h"
+extern void synerr (char *s) NO_RETURN;
+extern CLPR_int scan (void);
+extern CLPR_int is_punc (char punc);
Index: solver.btk.c
===================================================================
RCS file: /home/mercury1/repository/clpr/clpr/solver.btk.c,v
retrieving revision 1.5
diff -u -u -r1.5 solver.btk.c
--- 1.5	1997/09/08 18:47:08
+++ solver.btk.c	1997/09/14 18:22:26
@@ -10,6 +10,7 @@
 #include "config.h"
 #include "emul.h"
 #include "solver.h"
+#include "main.h"
 
 extern NL_EQN_ptr nl_eqn_top;
 extern CLPR_int stamp, trtop, **trail;
@@ -22,7 +23,6 @@
 void restore_ineq_occ_1 (EQN_ptr pres_eqn);
 void restore_occ_2 (EQN_ptr pres_eqn, EQN_ptr prev_eqn);
 void restore_ineq_occ_2 (EQN_ptr pres_eqn, EQN_ptr prev_eqn);
-extern void fatal (char *s);
 void restore_nl_occ (NL_EQN_ptr nl_eqn);
 extern void delete_occ (CLPR_int type, CLPR_int i, CLPR_int v);
 extern void insert_occ (CLPR_int type, CLPR_int i, CLPR_int v);
Index: solver.c
===================================================================
RCS file: /home/mercury1/repository/clpr/clpr/solver.c,v
retrieving revision 1.6
diff -u -u -r1.6 solver.c
--- 1.6	1997/09/08 18:47:11
+++ solver.c	1997/09/14 18:24:52
@@ -6,11 +6,13 @@
  *  File: solver.c                                             *
  ***************************************************************/
 
+#include <stdlib.h>
 #include "standard.h"
 #include "config.h"
 #include "emul.h"
 #include "solver.h"
 #include "opcodes.h"
+#include "main.h"
 
 #define MIN_SOLVER_SZ 256
 
@@ -48,7 +50,6 @@
 /*----------------------------------------------- entry points --------------*/
 
 
-extern void fatal (char *s);
 CLPR_int solve_eqn_1 (CLPR_int v, double c);
 extern CLPR_int solve_parametric_eqn (EQN_ptr eqn, CLPR_int call_ineq_subs);
 extern void backup_null_eqn (CLPR_int id);
Index: solver.eq.c
===================================================================
RCS file: /home/mercury1/repository/clpr/clpr/solver.eq.c,v
retrieving revision 1.5
diff -u -u -r1.5 solver.eq.c
--- 1.5	1997/09/08 18:47:16
+++ solver.eq.c	1997/09/14 18:23:58
@@ -10,6 +10,7 @@
 #include "config.h"
 #include "emul.h"
 #include "solver.h"
+#include "main.h"
 
 extern CLPR_int stamp;
 
@@ -28,10 +29,8 @@
 void tmp_undelete_entry (EQN_ptr eqn);
 void delete_occ (CLPR_int type, CLPR_int i, CLPR_int v);
 void make_solver_binding (ENTRY_ptr *groundings, CLPR_int v, double c);
-void add_eqns (CLPR_int type, EQN_ptr eqn1, EQN_ptr eqn2, double factor);
 CLPR_int check_groundings (ENTRY_ptr groundings);
 extern CLPR_int wakeup (CLPR_int v, double c);
-extern void fatal (char *s);
 void add_simple_entry (CLPR_int type, EQN_ptr eqn, CLPR_int v, double c);
 
 CLPR_int solve_parametric_eqn(EQN_ptr eqn, CLPR_int call_ineq_subs)
@@ -335,10 +334,8 @@
 	return c;
 }
 
-void add_eqns(CLPR_int type, EQN_ptr eqn1, EQN_ptr eqn2, double factor) /*** eqn1 := eqn1 + factor*eqn2 ***/
-         
-                   
-              
+/*** eqn1 := eqn1 + factor*eqn2 ***/
+void add_eqns(CLPR_int type, EQN_ptr eqn1, EQN_ptr eqn2, double factor)
 {
 CLPR_int v1, v2;
 register ENTRY_ptr tmp1, tmp2;
Index: solver.h
===================================================================
RCS file: /home/mercury1/repository/clpr/clpr/solver.h,v
retrieving revision 1.6
diff -u -u -r1.6 solver.h
--- 1.6	1997/09/08 19:05:03
+++ solver.h	1997/09/14 18:47:48
@@ -486,6 +486,26 @@
 
 extern ENTRY_ptr find_entry(EQN_ptr eqn, CLPR_int v);
 
+CLPR_int solve_parametric_eqn(EQN_ptr eqn, CLPR_int call_ineq_subs);
+void delete_occ(CLPR_int type, CLPR_int i, CLPR_int v);
+CLPR_int check_implicits(void); /*** one implicit at a time - recursively ***/
+
+/*** subs v0 in tableau[] by eqn0 ***/
+CLPR_int ineq_substitute(CLPR_int v0, EQN_ptr eqn0);
+
+void backup_null_ineq(CLPR_int id);
+void backup_ineq(EQN_ptr eqn);
+void add_entry(CLPR_int type, EQN_ptr eqn, CLPR_int v, double c);
+void mult_eqn(CLPR_int type, EQN_ptr eqn, double factor);
+
+/*** eqn1 := eqn1 + factor*eqn2 ***/
+void add_eqns(CLPR_int type, EQN_ptr eqn1, EQN_ptr eqn2, double factor);
+
+/*** eqn is read-only ***/
+CLPR_int solve_inequality(CLPR_int strict, EQN_ptr eqn);
+
+CLPR_int free_eqn_nodes(EQN_ptr eqn);
+
 /*-------------------------------------------------- solver globals ---------*/
 
 extern TAB_HDR_NODE_ptr *tableau;
Index: solver.ineq.c
===================================================================
RCS file: /home/mercury1/repository/clpr/clpr/solver.ineq.c,v
retrieving revision 1.5
diff -u -u -r1.5 solver.ineq.c
--- 1.5	1997/09/08 18:47:20
+++ solver.ineq.c	1997/09/14 18:39:04
@@ -10,6 +10,7 @@
 #include "config.h"
 #include "emul.h"
 #include "solver.h"
+#include "main.h"
 
 #define zero_format(eqn) \
 	(is_zero((eqn)->constant) && is_zero((eqn)->params->epsilon))
@@ -52,7 +53,7 @@
 CLPR_int some_implicits (EQN_ptr eqn);
 CLPR_int full_implicits (EQN_ptr eqn);
 CLPR_int solve_ineq_tableau (CLPR_int art_row, CLPR_int *destroyed);
-CLPR_int find_basic_var (void);
+static void find_basic_var (void);
 void find_exit_eqn (void);
 void pivot (CLPR_int flag);
 CLPR_int check_implicits (void);
@@ -60,9 +61,8 @@
 CLPR_int find_implicit_row (CLPR_int v, double *coef, EQN_ptr *eqn);
 void delete_var (CLPR_int v);
 
-CLPR_int solve_inequality(CLPR_int strict, EQN_ptr eqn) /*** eqn is read-only ***/
-           
-            
+/*** eqn is read-only ***/
+CLPR_int solve_inequality(CLPR_int strict, EQN_ptr eqn)
 {
 EQN_ptr eqn2;
 EQN_PARAMS_ptr params;
@@ -243,7 +243,7 @@
  *      output: basic_var, pivot_entry, prev_pivot_entry;
  *******************************************************/
 
-CLPR_int find_basic_var(void) /*** return -1 for implicits, 0 for fail ***/
+void find_basic_var(void) /*** return -1 for implicits, 0 for fail ***/
 {
 register ENTRY_ptr entry, prev_entry;
 
@@ -341,9 +341,8 @@
 	art_params->basic = 0;
 }
 
-CLPR_int ineq_substitute(CLPR_int v0, EQN_ptr eqn0) /*** subs v0 in tableau[] by eqn0 ***/
-       
-             
+/*** subs v0 in tableau[] by eqn0 ***/
+CLPR_int ineq_substitute(CLPR_int v0, EQN_ptr eqn0)
 {
 register ENTRY_ptr entry, entry99;
 register OCC_ptr occ, occ99;
@@ -399,7 +398,9 @@
 void save_orig_ineq(EQN_ptr eqn)	/*** save a COPY ***/
             
 {
-	if (tableau[slack_id]->next) free_eqn_nodes(tableau[slack_id]->next);
+	if (tableau[slack_id]->next) {
+		free_eqn_nodes((EQN_ptr) tableau[slack_id]->next);
+	}
 	tableau[slack_id]->next = (TAB_HDR_NODE_ptr) eqn;
 }
 
Index: solver.nlin.c
===================================================================
RCS file: /home/mercury1/repository/clpr/clpr/solver.nlin.c,v
retrieving revision 1.5
diff -u -u -r1.5 solver.nlin.c
--- 1.5	1997/09/08 18:47:26
+++ solver.nlin.c	1997/09/14 17:44:01
@@ -10,6 +10,7 @@
 #include "config.h"
 #include "emul.h"
 #include "solver.h"
+#include "main.h"
 
 NL_EQN_ptr nl_eqn_top = NULL;
 extern CLPR_int stamp, trtop, **trail;
@@ -17,7 +18,6 @@
 /*---------------------------------------------------------------------------*/
 
 
-extern void fatal (char *s);
 CLPR_int wakeup_mult (double c, NL_OCC_ptr occ);
 CLPR_int wakeup_pow (double c, NL_OCC_ptr occ);
 CLPR_int wakeup_pow0 (double c, NL_OCC_ptr occ);
@@ -767,7 +767,7 @@
 	delete_nl_occ(nl_eqn->params2->occ0);
 	if (c <= 1 && c >= -1 ) {
 		if (c != 1.0) return solve_eqn_1(v0, acos(c));
-		else solve_eqn_1(v0, 0.0);
+		else return solve_eqn_1(v0, 0.0);
 	} else if (c > 0 && c <= 1+EPS) return solve_eqn_1(v0, 0.0);
 	else if (c < 0 && c >= -1-EPS) return solve_eqn_1(v0, PI_VAL); 
 	else {
Index: standard.h
===================================================================
RCS file: /home/mercury1/repository/clpr/clpr/standard.h,v
retrieving revision 1.6
diff -u -u -r1.6 standard.h
--- 1.6	1997/09/08 19:05:05
+++ standard.h	1997/09/15 08:11:00
@@ -22,7 +22,7 @@
 typedef unsigned CLPR_unsigned;
 #endif
 
-#define CLPR_WORDSIZE (sizeof(CLPR_int) * CHAR_BIT)
+#define CLPR_WORDSIZE ((int) (sizeof(CLPR_int) * CHAR_BIT))
 
 extern char *emalloc(CLPR_int n);
 extern CLPR_int *alloc_mem(CLPR_int n);
@@ -90,6 +90,12 @@
 #define stats_count(n) s_count[n]++;
 #else
 #define stats_count(n) 
+#endif
+
+#if __GNUC__
+#define NO_RETURN __attribute__((noreturn))
+#else
+#define NO_RETURN
 #endif
 
 #endif
Index: table.c
===================================================================
RCS file: /home/mercury1/repository/clpr/clpr/table.c,v
retrieving revision 1.6
diff -u -u -r1.6 table.c
--- 1.6	1997/09/08 19:05:07
+++ table.c	1997/09/14 18:27:17
@@ -15,6 +15,7 @@
 #include "lib.h"
 #include "compile.h"
 #include "emul.h"
+#include "main.h"
 
 #define MAXHASH_FUNC (1999)
 #define MAXHASH_VAR (1999)
@@ -57,9 +58,7 @@
 
 
 extern CLPR_int sum_str (register char *s);
-extern void fatal (char *s);
 void numfunc (CLPR_int val, CLPR_int arity, char *s, CLPR_int special);
-extern void warning (char *s, ...);
 
 CLPR_int hash(char *s, CLPR_int siz)
 {
@@ -296,7 +295,7 @@
  *	with value val, used to predefine functors
  *	Not allowed to redefine a name with the same arity
  */
-struct HASHNODE *add_func(char *name, CLPR_int narg, CLPR_int val)
+void add_func(char *name, CLPR_int narg, CLPR_int val)
 {
 CLPR_int h, size, quick_cmp, found=FALSE;
 struct HASHNODE *cur;
Index: table.h
===================================================================
RCS file: table.h
diff -N table.h
--- /dev/null	Mon Sep 15 18:21:32 1997
+++ table.h	Mon Sep 15 04:47:48 1997
@@ -0,0 +1,16 @@
+#include "standard.h"
+#include "parse.h"
+
+extern CLPR_int is_op_hnode (struct HASHNODE *hnode,
+		CLPR_int ty, CLPR_int *pri, CLPR_int *left, CLPR_int *right);
+extern CLPR_int is_nfix_hnode (struct HASHNODE *hnode);
+extern void zero_vars (void);
+
+extern PTERM *lookup_var(char *var, CLPR_int quick_cmp);
+extern PTERM *lookup_name(char *sym, CLPR_int quick_cmp);
+extern PTERM *lookup_const(char *sym, CLPR_int quick_cmp);
+extern PTERM *new_real(double val);
+extern PTERM *new_str(char *s);
+extern PTERM *new_pt_emptylist(void);
+
+extern void add_func (char *name, CLPR_int narg, CLPR_int val);
Index: trace.c
===================================================================
RCS file: /home/mercury1/repository/clpr/clpr/trace.c,v
retrieving revision 1.7
diff -u -u -r1.7 trace.c
--- 1.7	1997/09/08 19:05:09
+++ trace.c	1997/09/14 17:29:06
@@ -15,6 +15,7 @@
 #include "compile.h"
 #include "opcodes.h"
 #include "emul.h"
+#include "main.h"
 
 #define is_switch_inst(val) \
 	(val == SWITCHONNIL || val == SWITCHONDOT || val == SWITCHONCON || \
@@ -247,7 +248,6 @@
 
 CLPR_int print_inst (CLPR_int int_pc);
 void print_spaces (CLPR_int n);
-extern void fatal (char *s);
 
 void clam_trace(CLPR_int int_pc) /*** "ctrace" ***/
            

-- 
Fergus Henderson <fjh at cs.mu.oz.au>   |  "I have always known that the pursuit
WWW: <http://www.cs.mu.oz.au/~fjh>   |  of excellence is a lethal habit"
PGP: finger fjh at 128.250.37.3         |     -- the last words of T. S. Garp.



More information about the developers mailing list