[m-dev.] for review: Bytecode changes

Levi Cameron l.cameron2 at ugrad.unimelb.edu.au
Fri Jan 5 13:13:21 AEDT 2001


Estimated hours taken: 0.5

Various changes to bytecode format & generator

compiler/bytecode_gen.m
compiler/bytecode.m
       Added temp slot for semidet procedures
       (to store success indicator, needed because the same fail
       bytecode is used whenever there is a redo needed in any part
       of the program)

       Added label to each enter_proc indicating where the corresponding
       endof_proc is (needed for semidet failure and also used for
       endof_proc to work out the attributes [temp slots, vars etc]
       of the procedure it is in)

       Added enter_negation_goal bytecode so that negations can be
       handled; enter_negation and endof_negation is not enough. Also
       added a temporary stack slot for each negation.

Levi

Index: bytecode_gen.m
===================================================================
RCS file: /home/mercury1/repository/mercury/compiler/bytecode_gen.m,v
retrieving revision 1.54
diff -u -r1.54 bytecode_gen.m
--- bytecode_gen.m	2000/12/20 00:09:53	1.54
+++ bytecode_gen.m	2000/12/20 06:15:06
@@ -132,7 +132,17 @@
 	call_gen__output_arg_locs(Args, OutputArgs),
 	bytecode_gen__gen_places(OutputArgs, ByteInfo, PlaceCode),
 
-	bytecode_gen__goal(Goal, ByteInfo1, ByteInfo, GoalCode),
+	% If semideterministic, reserve temp slot 0 for the return value
+	( CodeModel = model_semi ->
+		bytecode_gen__get_next_temp(ByteInfo1, _FrameTemp, ByteInfo2)
+	;
+		ByteInfo2 = ByteInfo1
+	),
+
+	bytecode_gen__goal(Goal, ByteInfo2, ByteInfo3, GoalCode),
+
+	bytecode_gen__get_next_label(ByteInfo3, EndLabel, ByteInfo),
+	
 	bytecode_gen__get_counts(ByteInfo, LabelCount, TempCount),
 
 	ZeroLabelCode = node([label(ZeroLabel)]),
@@ -149,12 +159,12 @@
 		BodyCode = node(BodyCode0)
 	),
 	proc_id_to_int(ProcId, ProcInt),
-	EnterCode = node([enter_proc(ProcInt, Detism, LabelCount, TempCount,
-		VarInfos)]),
+	EnterCode = node([enter_proc(ProcInt, Detism, LabelCount, EndLabel,
+		TempCount, VarInfos)]),
 	( CodeModel = model_semi ->
-		EndofCode = node([semidet_succeed, endof_proc])
+		EndofCode = node([semidet_succeed, label(EndLabel), endof_proc])
 	;
-		EndofCode = node([endof_proc])
+		EndofCode = node([label(EndLabel), endof_proc])
 	),
 	Code = tree(EnterCode, tree(BodyCode, EndofCode)).
 
@@ -209,10 +219,14 @@
 	;
 		GoalExpr = not(Goal),
 		bytecode_gen__goal(Goal, ByteInfo0, ByteInfo1, SomeCode),
-		bytecode_gen__get_next_label(ByteInfo1, EndLabel, ByteInfo),
-		EnterCode = node([enter_negation(EndLabel)]),
-		EndofCode = node([endof_negation, label(EndLabel)]),
-		Code = tree(EnterCode, tree(SomeCode, EndofCode))
+		bytecode_gen__get_next_label(ByteInfo1, EndLabel, ByteInfo2),
+		bytecode_gen__get_next_temp(ByteInfo2, FrameTemp, ByteInfo),
+		EnterCode = node([enter_negation(FrameTemp, EndLabel)]),
+		EndofCode = node([endof_negation_goal(FrameTemp),
+			label(EndLabel), endof_negation]),
+		Code =  tree(EnterCode,
+			tree(SomeCode,
+			     EndofCode))
 	;
 		GoalExpr = some(_, _, Goal),
 		bytecode_gen__goal(Goal, ByteInfo0, ByteInfo1, SomeCode),
Index: bytecode.m
===================================================================
RCS file: /home/mercury1/repository/mercury/compiler/bytecode.m,v
retrieving revision 1.42
diff -u -r1.42 bytecode.m
--- bytecode.m	2000/12/20 00:07:58	1.42
+++ bytecode.m	2000/12/20 06:14:54
@@ -23,7 +23,7 @@
 					byte_pred_or_func, int)
 			;	endof_pred
 			;	enter_proc(byte_proc_id, determinism,
-					int, int, list(byte_var_info))
+					int, int, int, list(byte_var_info))
 			;	endof_proc
 			;	label(byte_label_id)
 			;	enter_disjunction(byte_label_id)
@@ -40,7 +40,8 @@
 			;	endof_then(byte_label_id)
 			;	enter_else(byte_temp)
 			;	endof_if
-			;	enter_negation(byte_label_id)
+			;	enter_negation(byte_temp, byte_label_id)
+			;	endof_negation_goal(byte_temp)
 			;	endof_negation
 			;	enter_commit(byte_temp)
 			;	endof_commit(byte_temp)
@@ -207,10 +208,11 @@
 	output_byte(IsFunc),
 	output_length(ProcCount).
 output_args(endof_pred) --> [].
-output_args(enter_proc(ProcId, Detism, LabelCount, TempCount, Vars))
-->
+output_args(enter_proc(ProcId, Detism, LabelCount, LabelId, TempCount,
Vars)) -->
 	output_proc_id(ProcId),
 	output_determinism(Detism),
 	output_length(LabelCount),
+	output_label_id(LabelId),
 	output_length(TempCount),
 	{ list__length(Vars, VarCount) },
 	output_length(VarCount),
@@ -229,9 +231,9 @@
 	output_var(Var),
 	output_label_id(LabelId).
 output_args(endof_switch) --> [].
-output_args(enter_switch_arm(ConsId, LabelId)) -->
+output_args(enter_switch_arm(ConsId, NextLabelId)) -->
 	output_cons_id(ConsId),
-	output_label_id(LabelId).
+	output_label_id(NextLabelId).
 output_args(endof_switch_arm(LabelId)) -->
 	output_label_id(LabelId).
 output_args(enter_if(ElseLabelId, FollowLabelId, FramePtrTemp)) -->
@@ -245,8 +247,11 @@
 output_args(enter_else(FramePtrTemp)) -->
 	output_temp(FramePtrTemp).
 output_args(endof_if) --> [].
-output_args(enter_negation(LabelId)) -->
+output_args(enter_negation(FramePtrTemp, LabelId)) -->
+	output_temp(FramePtrTemp),
 	output_label_id(LabelId).
+output_args(endof_negation_goal(FramePtrTemp)) -->
+	output_temp(FramePtrTemp).
 output_args(endof_negation) --> [].
 output_args(enter_commit(Temp)) -->
 	output_temp(Temp).
@@ -335,10 +340,11 @@
 	),
 	debug_length(ProcsCount).
 debug_args(endof_pred) --> [].
-debug_args(enter_proc(ProcId, Detism, LabelCount, TempCount, Vars)) -->
+debug_args(enter_proc(ProcId, Detism, LabelCount, LabelId, TempCount,
Vars)) -->
 	debug_proc_id(ProcId),
 	debug_determinism(Detism),
 	debug_length(LabelCount),
+	debug_label_id(LabelId),
 	debug_length(TempCount),
 	{ list__length(Vars, VarCount) },
 	debug_length(VarCount),
@@ -357,9 +363,9 @@
 	debug_var(Var),
 	debug_label_id(LabelId).
 debug_args(endof_switch) --> [].
-debug_args(enter_switch_arm(ConsId, LabelId)) -->
+debug_args(enter_switch_arm(ConsId, NextLabelId)) -->
 	debug_cons_id(ConsId),
-	debug_label_id(LabelId).
+	debug_label_id(NextLabelId).
 debug_args(endof_switch_arm(LabelId)) -->
 	debug_label_id(LabelId).
 debug_args(enter_if(ElseLabelId, FollowLabelId, FramePtrTemp)) -->
@@ -373,8 +379,11 @@
 debug_args(enter_else(FramePtrTemp)) -->
 	debug_temp(FramePtrTemp).
 debug_args(endof_if) --> [].
-debug_args(enter_negation(LabelId)) -->
+debug_args(enter_negation(FramePtrTemp, LabelId)) -->
+	debug_temp(FramePtrTemp),
 	debug_label_id(LabelId).
+debug_args(endof_negation_goal(FramePtrTemp)) -->
+	debug_temp(FramePtrTemp).
 debug_args(endof_negation) --> [].
 debug_args(enter_commit(Temp)) -->
 	debug_temp(Temp).
@@ -869,7 +878,7 @@
 
 byte_code(enter_pred(_, _, _, _),		 0).
 byte_code(endof_pred,				 1).
-byte_code(enter_proc(_, _, _, _, _),		 2).
+byte_code(enter_proc(_, _, _, _, _, _),		 2).
 byte_code(endof_proc,				 3).
 byte_code(label(_),				 4).
 byte_code(enter_disjunction(_),			 5).
@@ -884,7 +893,7 @@
 byte_code(enter_then(_),			14).
 byte_code(endof_then(_),			15).
 byte_code(endof_if,				16).
-byte_code(enter_negation(_),			17).
+byte_code(enter_negation(_, _),			17).
 byte_code(endof_negation,			18).
 byte_code(enter_commit(_),			19).
 byte_code(endof_commit(_),			20).
@@ -908,13 +917,14 @@
 byte_code(context(_),				38).
 byte_code(not_supported,			39).
 byte_code(enter_else(_),			40).
+byte_code(endof_negation_goal(_),		41).
 
 :- pred byte_debug(byte_code, string).
 :- mode byte_debug(in, out) is det.
 
 byte_debug(enter_pred(_, _, _, _),		"enter_pred").
 byte_debug(endof_pred,				"endof_pred").
-byte_debug(enter_proc(_, _, _, _, _),		"enter_proc").
+byte_debug(enter_proc(_, _, _, _, _, _),	"enter_proc").
 byte_debug(endof_proc,				"endof_proc").
 byte_debug(label(_),				"label").
 byte_debug(enter_disjunction(_),		"enter_disjunction").
@@ -930,7 +940,8 @@
 byte_debug(endof_then(_),			"endof_then").
 byte_debug(enter_else(_),			"enter_else").
 byte_debug(endof_if,				"endof_if").
-byte_debug(enter_negation(_),			"enter_negation").
+byte_debug(enter_negation(_,_),			"enter_negation").
+byte_debug(endof_negation_goal(_),		"endof_negation_goal").
 byte_debug(endof_negation,			"endof_negation").
 byte_debug(enter_commit(_),			"enter_commit").
 byte_debug(endof_commit(_),			"endof_commit").
--------------------------------------------------------------------------
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