fix for bytecode generator

Simon TAYLOR stayl at students.cs.mu.oz.au
Wed Mar 19 17:14:23 AEDT 1997


Hi Bert,

Could you please review these changes.

Simon.


Estimated hours taken: 0.5

compiler/bytecode.m
compiler/bytecode_gen.m
	Fix handling of module qualified cons_ids.

compiler/bytecode.m
	Add some brackets to avoid syntax errors from the new 
	precedence/associativity of mod. This doesn't fix the bugs in
	the code that Fergus pointed out, it just makes it compile.


Index: bytecode.m
===================================================================
RCS file: /home/staff/zs/imp/mercury/compiler/bytecode.m,v
retrieving revision 1.18
diff -u -r1.18 bytecode.m
--- bytecode.m	1997/02/04 08:51:06	1.18
+++ bytecode.m	1997/03/18 06:39:22
@@ -70,7 +70,8 @@
 			;	not_supported
 			.
 
-:- type byte_cons_id	--->	cons(string, arity, byte_cons_tag)
+:- type byte_cons_id	--->	cons(byte_module_id, string,
+					arity, byte_cons_tag)
 			;	int_const(int)
 			;	string_const(string)
 			;	float_const(float)
@@ -80,6 +81,7 @@
 					arity, byte_proc_id)
 			;	base_type_info_const(byte_module_id, string,
 					int)
+			;	char_const(char)
 			.
 
 :- type byte_var_info	--->	var_info(string, type).
@@ -119,7 +121,7 @@
 :- implementation.
 
 :- import_module hlds_pred.
-:- import_module library, int, string, require.
+:- import_module char, library, int, string, require.
 
 :- pred bytecode__version(int::out) is det.
 
@@ -676,8 +678,9 @@
 :- pred output_cons_id(byte_cons_id, io__state, io__state).
 :- mode output_cons_id(in, di, uo) is det.
 
-output_cons_id(cons(Functor, Arity, Tag)) -->
+output_cons_id(cons(ModuleId, Functor, Arity, Tag)) -->
 	output_byte(0),
+	output_string(ModuleId),
 	output_string(Functor),
 	output_two_byte(Arity),
 	output_tag(Tag).
@@ -707,12 +710,17 @@
 	output_module_id(ModuleId),
 	output_string(TypeName),
 	output_byte(TypeArity).
+output_cons_id(char_const(Char)) -->
+	output_byte(7),
+	{ char__to_int(Char, Byte) },
+	output_byte(Byte).
 
 :- pred debug_cons_id(byte_cons_id, io__state, io__state).
 :- mode debug_cons_id(in, di, uo) is det.
 
-debug_cons_id(cons(Functor, Arity, Tag)) -->
+debug_cons_id(cons(ModuleId, Functor, Arity, Tag)) -->
 	debug_string("functor"),
+	debug_string(ModuleId),
 	debug_string(Functor),
 	debug_int(Arity),
 	debug_tag(Tag).
@@ -742,6 +750,10 @@
 	debug_module_id(ModuleId),
 	debug_string(TypeName),
 	debug_int(TypeArity).
+debug_cons_id(char_const(Char)) -->
+	debug_string("char_const"),
+	{ string__from_char_list([Char], String) },
+	debug_string(String).
 
 %---------------------------------------------------------------------------%
 
Index: bytecode_gen.m
===================================================================
RCS file: /home/staff/zs/imp/mercury/compiler/bytecode_gen.m,v
retrieving revision 1.24
diff -u -r1.24 bytecode_gen.m
--- bytecode_gen.m	1997/03/06 05:08:55	1.24
+++ bytecode_gen.m	1997/03/18 06:45:26
@@ -566,17 +566,24 @@
 	(
 		ConsId = cons(Functor, Arity),
 		(
-			Functor = unqualified(FunctorName)
+			% Everything other than characters should
+			% be module qualified.
+			Functor = unqualified(FunctorName),
+			string__to_char_list(FunctorName, FunctorList),
+			( FunctorList = [Char] ->
+				ByteConsId = char_const(Char)
+			;	
+				error("bytecode_gen__map_cons_id: unqualified cons_id is not a char_const")
+			)
 		;
-			% Should have been transformed into a function call
-			% or pred_const.
-			Functor = qualified(_, _),
-			error("bytecode_gen__map_cons_id: qualified cons_id")
-		),
-		bytecode_gen__get_var_type(ByteInfo, Var, Type),
-		code_util__cons_id_to_tag(ConsId, Type, ModuleInfo, ConsTag),
-		bytecode_gen__map_cons_tag(ConsTag, ByteConsTag),
-		ByteConsId = cons(FunctorName, Arity, ByteConsTag)
+			Functor = qualified(ModuleName, FunctorName),
+			bytecode_gen__get_var_type(ByteInfo, Var, Type),
+			code_util__cons_id_to_tag(ConsId,
+				Type, ModuleInfo, ConsTag),
+			bytecode_gen__map_cons_tag(ConsTag, ByteConsTag),
+			ByteConsId = cons(ModuleName, FunctorName,
+				Arity, ByteConsTag)
+		)
 	;
 		ConsId = int_const(IntVal),
 		ByteConsId = int_const(IntVal)




More information about the developers mailing list