[m-dev.] For review: Bytecode interpreter modification

Levi Cameron l.cameron2 at ugrad.unimelb.edu.au
Wed Jan 17 16:58:16 AEDT 2001


Estimated hours taken: 0.3

Added predicate & function distinction in some bytecodes

compiler/bytecode.m
compiler/bytecode_gen.m
        Fixed where it was not specified whether a predicate
        or function was being referred to.

Levi
l.cameron2 at ugrad.unimelb.edu.au

Index: bytecode.m
===================================================================
RCS file: /home/mercury1/repository/mercury/compiler/bytecode.m,v
retrieving revision 1.43
diff -u -r1.43 bytecode.m
--- bytecode.m	2001/01/08 00:11:47	1.43
+++ bytecode.m	2001/01/12 05:51:01
@@ -58,7 +58,7 @@
 			;	place_arg(byte_reg_type, int, byte_var)
 			;	pickup_arg(byte_reg_type, int, byte_var)
 			;	call(byte_module_id, byte_pred_id,
-					arity, byte_proc_id)
+					arity, byte_pred_or_func, byte_proc_id)
 			;	higher_order_call(byte_var, arity, arity,
 					determinism)
 			;	builtin_binop(binary_op, byte_arg, byte_arg,
@@ -84,7 +84,7 @@
 			;	string_const(string)
 			;	float_const(float)
 			;	pred_const(byte_module_id, byte_pred_id,
-					arity, byte_proc_id)
+					arity, byte_pred_or_func, byte_proc_id)
 			;	code_addr_const(byte_module_id, byte_pred_id,
 					arity, byte_proc_id)
 			;	type_ctor_info_const(byte_module_id, string,
@@ -293,10 +293,11 @@
 output_args(pickup_arg(RegType, RegNum, Var)) -->
 	output_reg(RegType, RegNum),
 	output_var(Var).
-output_args(call(ModuleId, PredId, Arity, ProcId)) -->
+output_args(call(ModuleId, PredId, Arity, IsFunc, ProcId)) -->
 	output_module_id(ModuleId),
 	output_pred_id(PredId),
 	output_length(Arity),
+	output_byte(IsFunc),
 	output_proc_id(ProcId).
 output_args(higher_order_call(PredVar, InVarCount, OutVarCount,
Detism)) -->
 	output_var(PredVar),
@@ -425,10 +426,15 @@
 debug_args(pickup_arg(RegType, RegNum, Var)) -->
 	debug_reg(RegType, RegNum),
 	debug_var(Var).
-debug_args(call(ModuleId, PredId, Arity, ProcId)) -->
+debug_args(call(ModuleId, PredId, Arity, IsFunc, ProcId)) -->
 	debug_module_id(ModuleId),
 	debug_pred_id(PredId),
-	debug_length(Arity),
+	debug_length(Arity), 
+	( { IsFunc = 0 } ->
+		debug_string("pred")
+	;
+		debug_string("func")
+	),
 	debug_proc_id(ProcId).
 debug_args(higher_order_call(PredVar, InVarCount, OutVarCount, Detism))
-->
 	debug_var(PredVar),
@@ -721,11 +727,12 @@
 output_cons_id(float_const(FloatVal)) -->
 	output_byte(3),
 	output_float(FloatVal).
-output_cons_id(pred_const(ModuleId, PredId, Arity, ProcId)) -->
+output_cons_id(pred_const(ModuleId, PredId, Arity, IsFunc, ProcId)) -->
 	output_byte(4),
 	output_module_id(ModuleId),
 	output_pred_id(PredId),
 	output_length(Arity),
+	output_byte(IsFunc),
 	output_proc_id(ProcId).
 output_cons_id(code_addr_const(ModuleId, PredId, Arity, ProcId)) -->
 	output_byte(5),
@@ -766,11 +773,16 @@
 debug_cons_id(float_const(FloatVal)) -->
 	debug_string("float_const"),
 	debug_float(FloatVal).
-debug_cons_id(pred_const(ModuleId, PredId, Arity, ProcId)) -->
+debug_cons_id(pred_const(ModuleId, PredId, Arity, IsFunc, ProcId)) -->
 	debug_string("pred_const"),
 	debug_module_id(ModuleId),
 	debug_pred_id(PredId),
 	debug_length(Arity),
+	( { IsFunc = 0 } ->
+		debug_string("pred")
+	;
+		debug_string("func")
+	),
 	debug_proc_id(ProcId).
 debug_cons_id(code_addr_const(ModuleId, PredId, Arity, ProcId)) -->
 	debug_string("code_addr_const"),
@@ -905,7 +917,7 @@
 byte_code(complex_deconstruct(_, _, _),		26).
 byte_code(place_arg(_, _, _),			27).
 byte_code(pickup_arg(_, _, _),			28).
-byte_code(call(_, _, _, _),			29).
+byte_code(call(_, _, _, _, _),			29).
 byte_code(higher_order_call(_, _, _, _),	30).
 byte_code(builtin_binop(_, _, _, _),		31).
 byte_code(builtin_unop(_, _, _),		32).
@@ -953,7 +965,7 @@
 byte_debug(complex_deconstruct(_, _, _),	"complex_deconstruct").
 byte_debug(place_arg(_, _, _),			"place_arg").
 byte_debug(pickup_arg(_, _, _),			"pickup_arg").
-byte_debug(call(_, _, _, _),			"call").
+byte_debug(call(_, _, _, _, _),			"call").
 byte_debug(higher_order_call(_, _, _, _),	"higher_order_call").
 byte_debug(builtin_binop(_, _, _, _),		"builtin_binop").
 byte_debug(builtin_unop(_, _, _),		"builtin_unop").
Index: bytecode_gen.m
===================================================================
RCS file: /home/mercury1/repository/mercury/compiler/bytecode_gen.m,v
retrieving revision 1.55
diff -u -r1.55 bytecode_gen.m
--- bytecode_gen.m	2001/01/08 00:11:47	1.55
+++ bytecode_gen.m	2001/01/12 05:26:58
@@ -360,6 +360,15 @@
 	proc_info_arg_info(ProcInfo, ArgInfo),
 	assoc_list__from_corresponding_lists(ArgVars, ArgInfo, ArgVarsInfos),
 
+	module_info_preds(ModuleInfo, PredTable),
+	map__lookup(PredTable, PredId, PredInfo),
+	pred_info_get_is_pred_or_func(PredInfo, PredOrFunc),
+	( PredOrFunc = predicate ->	
+		IsFunc = 0
+	;
+		IsFunc = 1
+	),
+
 	call_gen__input_arg_locs(ArgVarsInfos, InputArgs),
 	bytecode_gen__gen_places(InputArgs, ByteInfo, PlaceArgs),
 
@@ -368,7 +377,7 @@
 
 	predicate_id(ModuleInfo, PredId, ModuleName, PredName, Arity),
 	proc_id_to_int(ProcId, ProcInt),
-	Call = node([call(ModuleName, PredName, Arity, ProcInt)]),
+	Call = node([call(ModuleName, PredName, Arity, IsFunc, ProcInt)]),
 	determinism_to_code_model(Detism, CodeModel),
 	( CodeModel = model_semi ->
 		Check = node([semidet_success_check])
@@ -472,7 +481,7 @@
 	bytecode_gen__map_vars(ByteInfo, Args, ByteArgs),
 	bytecode_gen__map_cons_id(ByteInfo, Var, ConsId, ByteConsId),
 	(
-		ByteConsId = pred_const(_, _, _, _)
+		ByteConsId = pred_const(_, _, _, _, _)
 	->
 		Code = node([construct(ByteVar, ByteConsId, ByteArgs)])
 	;
@@ -669,9 +678,19 @@
 		( EvalMethod = normal ->
 			predicate_id(ModuleInfo, PredId,
 				ModuleName, PredName, Arity),
+
+			module_info_preds(ModuleInfo, PredTable),
+			map__lookup(PredTable, PredId, PredInfo),
+			pred_info_get_is_pred_or_func(PredInfo, PredOrFunc),
+			( PredOrFunc = predicate ->	
+				IsFunc = 0
+			;
+				IsFunc = 1
+			),
+				
 			proc_id_to_int(ProcId, ProcInt),
 			ByteConsId = pred_const(ModuleName,
-				PredName, Arity, ProcInt)
+				PredName, Arity, IsFunc, ProcInt)
 		;
 			% XXX
 			error(
--------------------------------------------------------------------------
mercury-developers mailing list
Post messages to:       mercury-developers at cs.mu.oz.au
Administrative Queries: owner-mercury-developers at cs.mu.oz.au
Subscriptions:          mercury-developers-request at cs.mu.oz.au
--------------------------------------------------------------------------



More information about the developers mailing list