[m-dev.] For review: Bytecode interpreter modification
Levi Cameron
l.cameron2 at ugrad.unimelb.edu.au
Thu Jan 18 14:50:27 AEDT 2001
Fergus wrote:
> ...
> ...
> Apart from that, this looks fine. Please post another diff once
> you've addressed those comments, but feel free to commit the updated
> version without waiting for another review.
Done.
Here is the new diff:
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/18 03:43:26
@@ -20,7 +20,7 @@
:- type byte_tree == tree(list(byte_code)).
:- type byte_code ---> enter_pred(byte_pred_id, int,
- byte_pred_or_func, int)
+ byte_is_func, int)
; endof_pred
; enter_proc(byte_proc_id, determinism,
int, int, int, list(byte_var_info))
@@ -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_is_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_is_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,
@@ -119,7 +119,7 @@
:- type byte_label_id == int.
:- type byte_var == int.
:- type byte_temp == int.
-:- type byte_pred_or_func == int.
+:- type byte_is_func == int. % 0 if a predicate, 1 if a function
:- pred output_bytecode_file(string::in, list(byte_code)::in,
io__state::di, io__state::uo) is det.
@@ -205,7 +205,7 @@
output_args(enter_pred(PredId, PredArity, IsFunc, ProcCount)) -->
output_pred_id(PredId),
output_length(PredArity),
- output_byte(IsFunc),
+ output_is_func(IsFunc),
output_length(ProcCount).
output_args(endof_pred) --> [].
output_args(enter_proc(ProcId, Detism, LabelCount, LabelId, TempCount,
Vars)) -->
@@ -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_is_func(IsFunc),
output_proc_id(ProcId).
output_args(higher_order_call(PredVar, InVarCount, OutVarCount,
Detism)) -->
output_var(PredVar),
@@ -332,12 +333,7 @@
debug_args(enter_pred(PredId, PredArity, IsFunc, ProcsCount)) -->
debug_pred_id(PredId),
debug_length(PredArity),
- (
- { IsFunc = 0 } ->
- debug_string("pred")
- ;
- debug_string("func")
- ),
+ debug_is_func(IsFunc),
debug_length(ProcsCount).
debug_args(endof_pred) --> [].
debug_args(enter_proc(ProcId, Detism, LabelCount, LabelId, TempCount,
Vars)) -->
@@ -425,10 +421,11 @@
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),
+ debug_is_func(IsFunc),
debug_proc_id(ProcId).
debug_args(higher_order_call(PredVar, InVarCount, OutVarCount, Detism))
-->
debug_var(PredVar),
@@ -519,6 +516,27 @@
debug_int(N).
%---------------------------------------------------------------------------%
+:- pred output_is_func(byte_is_func, io__state, io__state).
+:- mode output_is_func(in, di, uo) is det.
+
+output_is_func(IsFunc) -->
+ ( { IsFunc = 1 ; IsFunc = 0 }
+ -> output_byte(IsFunc)
+ ; { error("Invalid predicate or function specified in bytecode") }
+ ).
+
+:- pred debug_is_func(byte_is_func, io__state, io__state).
+:- mode debug_is_func(in, di, uo) is det.
+
+debug_is_func(IsFunc) -->
+ ( { IsFunc = 1 }
+ -> debug_string("func")
+ ; { IsFunc = 0 }
+ -> debug_string("pred")
+ ; { error("Invalid predicate or function specifier in bytecode") }
+ ).
+
+%---------------------------------------------------------------------------%
:- pred output_length(int, io__state, io__state).
:- mode output_length(in, di, uo) is det.
@@ -721,11 +739,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_is_func(IsFunc),
output_proc_id(ProcId).
output_cons_id(code_addr_const(ModuleId, PredId, Arity, ProcId)) -->
output_byte(5),
@@ -766,11 +785,12 @@
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),
+ debug_is_func(IsFunc),
debug_proc_id(ProcId).
debug_cons_id(code_addr_const(ModuleId, PredId, Arity, ProcId)) -->
debug_string("code_addr_const"),
@@ -905,7 +925,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 +973,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/17 07:25:41
@@ -72,14 +72,7 @@
{ predicate_name(ModuleInfo, PredId, PredName) },
{ list__length(ProcIds, ProcsCount) },
{ pred_info_arity(PredInfo, Arity) },
- { pred_info_get_is_pred_or_func(PredInfo, PredOrFunc) },
- {
- (PredOrFunc = predicate ->
- IsFunc = 0
- ;
- IsFunc = 1
- )
- },
+ { bytecode_gen__get_is_func(PredInfo, IsFunc) },
{ EnterCode = node([enter_pred(PredName, Arity, IsFunc,
ProcsCount)]) },
{ EndofCode = node([endof_pred]) },
@@ -360,6 +353,10 @@
proc_info_arg_info(ProcInfo, ArgInfo),
assoc_list__from_corresponding_lists(ArgVars, ArgInfo, ArgVarsInfos),
+ module_info_preds(ModuleInfo, PredTable),
+ map__lookup(PredTable, PredId, PredInfo),
+ bytecode_gen__get_is_func(PredInfo, IsFunc),
+
call_gen__input_arg_locs(ArgVarsInfos, InputArgs),
bytecode_gen__gen_places(InputArgs, ByteInfo, PlaceArgs),
@@ -368,7 +365,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 +469,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 +666,14 @@
( EvalMethod = normal ->
predicate_id(ModuleInfo, PredId,
ModuleName, PredName, Arity),
+
+ module_info_preds(ModuleInfo, PredTable),
+ map__lookup(PredTable, PredId, PredInfo),
+ bytecode_gen__get_is_func(PredInfo, IsFunc),
+
proc_id_to_int(ProcId, ProcInt),
ByteConsId = pred_const(ModuleName,
- PredName, Arity, ProcInt)
+ PredName, Arity, IsFunc, ProcInt)
;
% XXX
error(
@@ -806,3 +808,14 @@
bytecode_gen__get_counts(byte_info(_, _, _, Label, Temp), Label, Temp).
%---------------------------------------------------------------------------%
+:- pred bytecode_gen__get_is_func(pred_info, byte_is_func).
+:- mode bytecode_gen__get_is_func(in, out) is det.
+
+bytecode_gen__get_is_func(PredInfo, IsFunc) :-
+ pred_info_get_is_pred_or_func(PredInfo, PredOrFunc),
+ (PredOrFunc = predicate ->
+ IsFunc = 0
+ ;
+ IsFunc = 1
+ ).
+
--------------------------------------------------------------------------
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