[m-rev.] for review: self rval
Peter Ross
petdr at cs.mu.OZ.AU
Thu Jun 21 00:36:46 AEST 2001
Hi,
For Tyson to review. Could you answer the XXX in the code for
rval_to_type please.
===================================================================
Estimated hours taken: 0.5
Branches: main
Add the self rval (ie this pointer in C++) for use on OO backends.
compiler/mlds.m:
Add the self rval.
compiler/ml_elim_nested.m:
compiler/mlds_to_c.m:
compiler/mlds_to_csharp.m:
compiler/mlds_to_il.m:
compiler/mlds_to_java.m:
compiler/mlds_to_mcpp.m:
Code to handle the new rval.
Index: compiler/ml_elim_nested.m
===================================================================
RCS file: /home/staff/zs/imp/mercury/compiler/ml_elim_nested.m,v
retrieving revision 1.26
diff -u -r1.26 ml_elim_nested.m
--- compiler/ml_elim_nested.m 2001/06/08 09:13:34 1.26
+++ compiler/ml_elim_nested.m 2001/06/20 14:25:10
@@ -1009,6 +1009,7 @@
fixup_rval(Y0, Y).
fixup_rval(mem_addr(Lval0), mem_addr(Lval)) -->
fixup_lval(Lval0, Lval).
+fixup_rval(self, self) --> [].
:- pred fixup_lvals(list(mlds__lval), list(mlds__lval), elim_info, elim_info).
:- mode fixup_lvals(in, out, in, out) is det.
Index: compiler/mlds.m
===================================================================
RCS file: /home/staff/zs/imp/mercury/compiler/mlds.m,v
retrieving revision 1.54
diff -u -r1.54 mlds.m
--- compiler/mlds.m 2001/06/08 09:13:38 1.54
+++ compiler/mlds.m 2001/06/20 14:22:42
@@ -1254,8 +1254,13 @@
; binop(binary_op, mlds__rval, mlds__rval)
- ; mem_addr(mlds__lval).
+ ; mem_addr(mlds__lval)
% The address of a variable, etc.
+
+ ; self.
+ % The equivalent of the this pointer in C++. Note that
+ % this rval is valid iff we are targetting an object
+ % oriented backend.
:- type mlds__unary_op
---> box(mlds__type)
Index: compiler/mlds_to_c.m
===================================================================
RCS file: /home/staff/zs/imp/mercury/compiler/mlds_to_c.m,v
retrieving revision 1.87
diff -u -r1.87 mlds_to_c.m
--- compiler/mlds_to_c.m 2001/06/08 09:13:38 1.87
+++ compiler/mlds_to_c.m 2001/06/20 14:26:20
@@ -2709,6 +2709,9 @@
io__write_string("&"),
mlds_output_lval(Lval).
+mlds_output_rval(self) -->
+ { error("mlds_to_c: self rval encountered.\n") }.
+
:- pred mlds_output_unop(mlds__unary_op, mlds__rval, io__state, io__state).
:- mode mlds_output_unop(in, in, di, uo) is det.
Index: compiler/mlds_to_csharp.m
===================================================================
RCS file: /home/staff/zs/imp/mercury/compiler/mlds_to_csharp.m,v
retrieving revision 1.5
diff -u -r1.5 mlds_to_csharp.m
--- compiler/mlds_to_csharp.m 2001/06/08 09:13:41 1.5
+++ compiler/mlds_to_csharp.m 2001/06/20 14:27:10
@@ -329,6 +329,9 @@
write_csharp_rval(mem_addr(_)) -->
{ sorry(this_file, "mem_addr rval") }.
+write_csharp_rval(self) -->
+ { sorry(this_file, "self rval") }.
+
:- pred write_csharp_rval_const(mlds__rval_const, io__state, io__state).
:- mode write_csharp_rval_const(in, di, uo) is det.
write_csharp_rval_const(true) --> io__write_string("1").
Index: compiler/mlds_to_il.m
===================================================================
RCS file: /home/staff/zs/imp/mercury/compiler/mlds_to_il.m,v
retrieving revision 1.33
diff -u -r1.33 mlds_to_il.m
--- compiler/mlds_to_il.m 2001/06/18 09:18:01 1.33
+++ compiler/mlds_to_il.m 2001/06/20 14:31:16
@@ -1385,6 +1385,8 @@
{ Instrs = throw_unimplemented("load mem_addr lval mem_ref") }
).
+load(self, tree__list([instr_node(ldarg(index(0)))])) --> [].
+
:- pred store(mlds__lval, instr_tree, il_info, il_info) is det.
:- mode store(in, out, in, out) is det.
@@ -1718,6 +1720,8 @@
unexpected(this_file, "binop_function_name")
; Rval = mem_addr(_),
unexpected(this_file, "mem_addr_function_name")
+ ; Rval = self,
+ unexpected(this_file, "self_function_name")
).
%-----------------------------------------------------------------------------
@@ -2361,7 +2365,7 @@
Info = Info0
).
- % The following four conversions should never occur or be boxed
+ % The following five conversions should never occur or be boxed
% anyway, but just in case they are we make them reference
% mercury.invalid which is a non-exisitant class. If we try to
% run this code, we'll get a runtime error.
@@ -2379,6 +2383,11 @@
Type = mlds__class_type(qual(ModuleName, ModuleName, "invalid"),
0, mlds__class).
rval_to_type(mem_addr(_), Type, I, I) :-
+ ModuleName = mercury_module_name_to_mlds(unqualified("mercury")),
+ Type = mlds__class_type(qual(ModuleName, ModuleName, "invalid"),
+ 0, mlds__class).
+rval_to_type(self, Type, I, I) :-
+ % XXX trd what is the right thing here?
ModuleName = mercury_module_name_to_mlds(unqualified("mercury")),
Type = mlds__class_type(qual(ModuleName, ModuleName, "invalid"),
0, mlds__class).
Index: compiler/mlds_to_java.m
===================================================================
RCS file: /home/staff/zs/imp/mercury/compiler/mlds_to_java.m,v
retrieving revision 1.5
diff -u -r1.5 mlds_to_java.m
--- compiler/mlds_to_java.m 2001/06/08 09:13:43 1.5
+++ compiler/mlds_to_java.m 2001/06/20 14:31:57
@@ -2013,6 +2013,9 @@
output_rval(mem_addr(_Lval)) -->
{ unexpected(this_file, "output_rval: mem_addr(_) not supported") }.
+output_rval(self) -->
+ { unexpected(this_file, "output_rval: self not supported") }.
+
:- pred output_unop(mlds__unary_op, mlds__rval, io__state, io__state).
:- mode output_unop(in, in, di, uo) is det.
Index: compiler/mlds_to_mcpp.m
===================================================================
RCS file: /home/staff/zs/imp/mercury/compiler/mlds_to_mcpp.m,v
retrieving revision 1.6
diff -u -r1.6 mlds_to_mcpp.m
--- compiler/mlds_to_mcpp.m 2001/06/08 09:13:45 1.6
+++ compiler/mlds_to_mcpp.m 2001/06/20 14:33:04
@@ -427,6 +427,9 @@
write_managed_cpp_rval(mem_addr(_)) -->
io__write_string(" /* mem_addr rval -- unimplemented */ ").
+
+write_managed_cpp_rval(self) -->
+ io__write_string(" /* self rval -- unimplemented */ ").
:- pred write_managed_cpp_rval_const(mlds__rval_const, io__state, io__state).
:- mode write_managed_cpp_rval_const(in, di, uo) is det.
----
Peter Ross
PhD Student University of Melbourne
http://www.cs.mu.oz.au/~petdr/
--------------------------------------------------------------------------
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