[m-rev.] diff: IL back-end: implement hash_string

Fergus Henderson fjh at cs.mu.OZ.AU
Sun Jul 8 18:13:35 AEST 2001


Estimated hours taken: 2
Branches: main

compiler/mlds_to_il.m:
	A partial fix for string switches: implement the `hash_string'
	unary operator.

	(String switches still don't work correctly, due to a problem
	with the array_index operator; I'm working on that.)

Workspace: /home/administrator/ws/ws1
Index: compiler/mlds_to_il.m
===================================================================
RCS file: /home/mercury1/repository/mercury/compiler/mlds_to_il.m,v
retrieving revision 1.33
diff -u -d -r1.33 mlds_to_il.m
--- compiler/mlds_to_il.m	18 Jun 2001 09:18:01 -0000	1.33
+++ compiler/mlds_to_il.m	8 Jul 2001 08:12:09 -0000
@@ -1424,7 +1424,7 @@
 	il_info) is det.
 :- mode unaryop_to_il(in, in, out, in, out) is det.
 
-	% Once upon a time the code generator generated primary tag tests
+	% Once upon a time the MLDS code generator generated primary tag tests
 	% (but we don't use primary tags).
 	% If we make mktag return its operand (since it will always be
 	% called with 0 as its operand), and we make tag return 0, it will
@@ -1439,9 +1439,8 @@
 unaryop_to_il(std_unop(mkbody),	_, comment_node("mkbody (a no-op)")) --> [].
 unaryop_to_il(std_unop(unmkbody), _, comment_node("unmkbody (a no-op)")) --> [].
 
-		% XXX implement this using string__hash
-unaryop_to_il(std_unop(hash_string), _,
-	throw_unimplemented("unimplemented hash_string unop")) --> [].
+unaryop_to_il(std_unop(hash_string), _, node([call(il_mercury_string_hash)]))
+		--> [].
 unaryop_to_il(std_unop(bitwise_complement), _, node([not])) --> [].
 
 		% might want to revisit this and define not to be only
@@ -1561,8 +1560,9 @@
 
 	% XXX we need to know what kind of thing is being indexed
 	% from the array in general. 
-binaryop_to_il(array_index, throw_unimplemented("array index unimplemented")) 
-		--> [].
+binaryop_to_il(array_index, node([
+		ldelem(refany)	% XXX FIXME element type here is wrong
+		])) --> [].
 
 	% String operations.
 binaryop_to_il(str_eq, node([
@@ -2573,6 +2573,15 @@
 il_string_compare = get_static_methodref(il_string_class_name, id("Compare"), 
 	simple_type(int32), [il_string_type, il_string_type]).
 
+	% Note that we need to use the hash function from the Mercury
+	% standard library, rather than the one from the .NET BCL
+	% (Base Class Library), because it must match the one used by
+	% the Mercury compiler when computing the hash tables for
+	% string switches.
+:- func il_mercury_string_hash = methodref.
+il_mercury_string_hash = get_static_methodref(mercury_string_class_name,
+	id("hash_2"), simple_type(int32), [il_string_type]).
+
 :- func il_string_class_name = ilds__class_name.
 il_string_class_name = il_system_name(["String"]).
 
@@ -2582,6 +2591,10 @@
 :- func il_string_type = ilds__type.
 il_string_type = ilds__type([], il_string_simple_type).
 
+:- func mercury_string_class_name = ilds__class_name.
+mercury_string_class_name = mercury_library_name(StringClass) :-
+	sym_name_to_class_name(unqualified("string"), yes, StringClass).
+
 %-----------------------------------------------------------------------------%
 %
 % The mapping to the generic type (used like MR_Box).
@@ -2654,6 +2667,16 @@
 
 :- func il_commit_class_name = ilds__class_name.
 il_commit_class_name = mercury_runtime_name(["Commit"]).
+
+%-----------------------------------------------------------------------------
+
+	% qualifiy a name with "[mercury]mercury."
+:- func mercury_library_name(ilds__namespace_qual_name) = ilds__class_name.
+mercury_library_name(Name) = 
+	append_class_name(mercury_library_namespace_name, Name).
+
+:- func mercury_library_namespace_name = ilds__class_name.
+mercury_library_namespace_name = structured_name("mercury", ["mercury"]).
 
 %-----------------------------------------------------------------------------
 

-- 
Fergus Henderson <fjh at cs.mu.oz.au>  |  "I have always known that the pursuit
The University of Melbourne         |  of excellence is a lethal habit"
WWW: <http://www.cs.mu.oz.au/~fjh>  |     -- the last words of T. S. Garp.
--------------------------------------------------------------------------
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