[m-rev.] diff: fix bug in operator handling

Simon Taylor stayl at cs.mu.OZ.AU
Wed Oct 24 20:49:28 AEST 2001



Estimated hours taken: 0.5
Branches: main, release

compiler/mercury_to_mercury.m:
	Use the predicates in library/ops.m to work out
	what is an operator. The tables of operators here
	caused a double maintenance problem. They
	also contained lots of NU-Prolog operators that
	don't occur in library/ops.m.

library/ops.m:
	Add a function version of ops__init_op_table.	

	compiler/mercury_to_mercury.m no longer needs to
	be updated when library/ops.m changes.


Index: compiler/mercury_to_mercury.m
===================================================================
RCS file: /home/mercury1/repository/mercury/compiler/mercury_to_mercury.m,v
retrieving revision 1.193
diff -u -u -r1.193 mercury_to_mercury.m
--- compiler/mercury_to_mercury.m	25 Sep 2001 09:36:51 -0000	1.193
+++ compiler/mercury_to_mercury.m	24 Oct 2001 08:48:47 -0000
@@ -320,7 +320,7 @@
 :- import_module recompilation_version, purity, term_util.
 :- import_module globals, options, termination, foreign.
 
-:- import_module assoc_list, char, int, string, set, lexer, require.
+:- import_module assoc_list, char, int, string, set, lexer, ops, require.
 :- import_module term, term_io, varset.
 
 %-----------------------------------------------------------------------------%
@@ -3272,143 +3272,31 @@
 :- mode mercury_op(in) is semidet.
 
 mercury_op(Op) :-
-	(
-	    (
-		mercury_infix_op(Op)
-	    ;
-		mercury_binary_prefix_op(Op)
-	    ;
-		mercury_unary_prefix_op(Op)
-	    ;
-		mercury_unary_postfix_op(Op)
-	    )
-	->
-		true
-	;
-		fail
-	).
+	ops__lookup_op(ops__init_op_table, Op).
 
 :- pred mercury_binary_prefix_op(string).
 :- mode mercury_binary_prefix_op(in) is semidet.
 
-mercury_binary_prefix_op("some").
-mercury_binary_prefix_op("all").
-mercury_binary_prefix_op("gSome").	/* NU-Prolog */
-mercury_binary_prefix_op("gAll").	/* NU-Prolog */
-mercury_binary_prefix_op("lambda").
+mercury_binary_prefix_op(Op) :-
+	ops__lookup_binary_prefix_op(ops__init_op_table, Op, _, _, _).
 
 :- pred mercury_infix_op(string).
 :- mode mercury_infix_op(in) is semidet.
 
-mercury_infix_op("--->").
-mercury_infix_op("-->").
-mercury_infix_op(":-").
-mercury_infix_op("::").
-mercury_infix_op(":=").
-mercury_infix_op("where").
-mercury_infix_op("sorted").	/* NU-Prolog */
-mercury_infix_op("else").
-mercury_infix_op("then").
-mercury_infix_op(";").
-mercury_infix_op("->").
-mercury_infix_op(",").
-mercury_infix_op("&").
-mercury_infix_op("to").		/* NU-Prolog */
-mercury_infix_op("<=").
-mercury_infix_op("<=>").
-mercury_infix_op("==>").
-mercury_infix_op("=>").
-mercury_infix_op("when").	/* NU-Prolog */
-mercury_infix_op("or").		/* NU-Prolog */
-mercury_infix_op("and").	/* NU-Prolog */
-mercury_infix_op("=").
-mercury_infix_op("=..").
-mercury_infix_op("=:=").	/* Prolog */
-mercury_infix_op("==").		/* Prolog (also for constraints, in cfloat.m) */
-mercury_infix_op("\\=").	/* Prolog */
-mercury_infix_op("\\==").	/* Prolog */
-mercury_infix_op("=\\=").	/* Prolog */
-mercury_infix_op("=^").
-mercury_infix_op(">").
-mercury_infix_op(">=").
-mercury_infix_op("<").
-mercury_infix_op("=<").
-mercury_infix_op("@<").		/* Prolog */
-mercury_infix_op("@=<").	/* Prolog */
-mercury_infix_op("@>").		/* Prolog */
-mercury_infix_op("@>=").	/* Prolog */
-mercury_infix_op("~=").		/* NU-Prolog */
-mercury_infix_op("is").		
-mercury_infix_op(".").		
-mercury_infix_op(":").		
-mercury_infix_op("+").
-mercury_infix_op("++").
-mercury_infix_op("-").
-mercury_infix_op("--").
-mercury_infix_op("/\\").
-mercury_infix_op("\\/").
-mercury_infix_op("*").
-mercury_infix_op("/").
-mercury_infix_op("//").
-mercury_infix_op(">>").
-mercury_infix_op("<<").
-mercury_infix_op("**").
-mercury_infix_op("div").
-mercury_infix_op("mod").
-mercury_infix_op("rem").
-mercury_infix_op("^").
+mercury_infix_op(Op) :-
+	ops__lookup_infix_op(ops__init_op_table, Op, _, _, _).
 
 :- pred mercury_unary_prefix_op(string).
 :- mode mercury_unary_prefix_op(in) is semidet.
 
-mercury_unary_prefix_op("+").
-mercury_unary_prefix_op("-").
-mercury_unary_prefix_op(":-").
-mercury_unary_prefix_op("::").
-mercury_unary_prefix_op("?-").
-mercury_unary_prefix_op("\\").
-mercury_unary_prefix_op("\\+").
-mercury_unary_prefix_op("aditi_bottom_up").
-mercury_unary_prefix_op("aditi_top_down").
-mercury_unary_prefix_op("delete").
-mercury_unary_prefix_op("dynamic").
-mercury_unary_prefix_op("end_module").
-mercury_unary_prefix_op("func").
-mercury_unary_prefix_op("if").
-mercury_unary_prefix_op("import_module").
-mercury_unary_prefix_op("include_module").
-mercury_unary_prefix_op("impure").
-mercury_unary_prefix_op("insert").
-mercury_unary_prefix_op("instance").
-mercury_unary_prefix_op("inst").
-mercury_unary_prefix_op("lib").
-mercury_unary_prefix_op("listing").
-mercury_unary_prefix_op("man").
-mercury_unary_prefix_op("mode").
-mercury_unary_prefix_op("module").
-mercury_unary_prefix_op("nospy").
-mercury_unary_prefix_op("not").
-mercury_unary_prefix_op("once").
-mercury_unary_prefix_op("pragma").
-mercury_unary_prefix_op("pred").
-mercury_unary_prefix_op("promise").
-mercury_unary_prefix_op("pure").
-mercury_unary_prefix_op("rule").	/* NU-Prolog */
-mercury_unary_prefix_op("semipure").
-mercury_unary_prefix_op("sorted").
-mercury_unary_prefix_op("spy").
-mercury_unary_prefix_op("type").
-mercury_unary_prefix_op("typeclass").
-mercury_unary_prefix_op("update").
-mercury_unary_prefix_op("useIf").
-mercury_unary_prefix_op("wait").
-mercury_unary_prefix_op("~").
-mercury_unary_prefix_op("^").
+mercury_unary_prefix_op(Op) :-
+	ops__lookup_prefix_op(ops__init_op_table, Op, _, _).
 
 :- pred mercury_unary_postfix_op(string).
 :- mode mercury_unary_postfix_op(in) is semidet.
 
-mercury_unary_postfix_op("sorted").
+mercury_unary_postfix_op(Op) :-
+	ops__lookup_postfix_op(ops__init_op_table, Op, _, _).
 
 %-----------------------------------------------------------------------------%
 
Index: library/ops.m
===================================================================
RCS file: /home/mercury1/repository/mercury/library/ops.m,v
retrieving revision 1.32
diff -u -u -r1.32 ops.m
--- library/ops.m	19 Sep 2000 04:46:50 -0000	1.32
+++ library/ops.m	24 Oct 2001 10:29:18 -0000
@@ -38,6 +38,8 @@
 :- pred ops__init_op_table(ops__table).
 :- mode ops__init_op_table(uo) is det.
 
+:- func ops__init_op_table = ops__table.
+
 	% check whether a string is the name of an infix operator,
 	% and if it is, return its precedence and associativity.
 :- pred ops__lookup_infix_op(ops__table, string, int, ops__assoc, ops__assoc).
@@ -116,8 +118,8 @@
 ops__lookup_op(_OpTable, Name) :-
 	ops__op_table(Name, _, _, _).
 
-	% Changes here may require changes to compiler/mercury_to_mercury.m,
-	% doc/transition_guide.texi and doc/reference_manual.texi.
+	% Changes here may require changes to doc/transition_guide.texi
+	% and doc/reference_manual.texi.
 :- pred ops__op_table(string, ops__category, ops__specifier, ops__priority).
 :- mode ops__op_table(in, in, out, out) is semidet.
 :- mode ops__op_table(in, out, out, out) is nondet.
@@ -238,6 +240,7 @@
 %     future purpose
 
 ops__init_op_table(ops__table).
+ops__init_op_table = ops__table.
 
 ops__max_priority(1200).
 
--------------------------------------------------------------------------
mercury-reviews mailing list
post:  mercury-reviews at cs.mu.oz.au
administrative address: owner-mercury-reviews at cs.mu.oz.au
unsubscribe: Address: mercury-reviews-request at cs.mu.oz.au Message: unsubscribe
subscribe:   Address: mercury-reviews-request at cs.mu.oz.au Message: subscribe
--------------------------------------------------------------------------



More information about the reviews mailing list