[m-rev.] For review: Java implementation of std_util library
James Goddard
goddardjames at yahoo.com
Mon Jan 19 14:16:34 AEDT 2004
Estimated hours taken: 5
Branches: main
Implement some library procedures for the Java back end.
library/std_util.m:
Defined the type mutvar(T) as an array of java.lang.Objects (which
will always be size 1)
Implemented the following procedures in Java:
get_registers/3
check_for_floundering/1
discard_trail_ticket/0
swap_heap_and_solutions_heap/0
partial_deep_copy/3
reset_solutions_heap/1
new_mutvar/2
get_mutvar/2
set_mutvar/2
java/runtime/VA_PseudoTypeInfo_Struct0.java:
This new file is a workaround which allows std_util.m to successfully
compile in grade Java.
Index: library/std_util.m
===================================================================
RCS file: /home/mercury1/repository/mercury/library/std_util.m,v
retrieving revision 1.288
diff -u -d -r1.288 std_util.m
--- library/std_util.m 13 Nov 2003 12:35:08 -0000 1.288
+++ library/std_util.m 19 Jan 2004 03:05:14 -0000
@@ -1048,6 +1048,21 @@
#endif
").
+:- pragma foreign_proc("Java",
+ get_registers(HeapPtr::out, SolutionsHeapPtr::out, TrailPtr::out),
+ [will_not_call_mercury, thread_safe],
+"
+ /*
+ ** Java has a builtin garbage collector,
+ ** so we don't have to worry here about heap reclamation on failure.
+ */
+ HeapPtr = null;
+ SolutionsHeapPtr = null;
+
+ /* XXX No trailing for the Java back-end. */
+ TrailPtr = null;
+").
+
:- impure pred check_for_floundering(trail_ptr::in) is det.
:- pragma foreign_proc("C",
@@ -1070,6 +1085,13 @@
#endif
").
+:- pragma foreign_proc("Java",
+ check_for_floundering(_TrailPtr::in),
+ [will_not_call_mercury, thread_safe],
+"
+ /* XXX No trailing for the Java back-end, so take no action. */
+").
+
%
% Discard the topmost trail ticket.
%
@@ -1094,6 +1116,13 @@
#endif
").
+:- pragma foreign_proc("Java",
+ discard_trail_ticket,
+ [will_not_call_mercury, thread_safe],
+"
+ /* XXX No trailing for the Java back-end, so take no action. */
+").
+
%
% Swap the heap with the solutions heap
%
@@ -1127,6 +1156,16 @@
//
").
+:- pragma foreign_proc("Java",
+ swap_heap_and_solutions_heap,
+ [will_not_call_mercury, thread_safe],
+"
+ /*
+ ** For the Java back-end, as for the .NET back-end, we don't define
+ ** our own heaps. So take no action here.
+ */
+").
+
%
% partial_deep_copy(SolutionsHeapPtr, OldVal, NewVal):
% Make a copy of all of the parts of OldVar that occur between
@@ -1209,6 +1248,31 @@
NewVal = OldVal;
").
+:- pragma foreign_proc("Java",
+ partial_deep_copy(_SolutionsHeapPtr::in, OldVal::in, NewVal::out),
+ [will_not_call_mercury, thread_safe, promise_pure],
+"
+ /*
+ ** For the Java back-end, as for the .NET implementation,
+ ** we don't do heap reclamation on failure,
+ ** so we don't need to worry about making deep copies here.
+ ** Shallow copies will suffice.
+ */
+ NewVal = OldVal;
+").
+:- pragma foreign_proc("Java",
+ partial_deep_copy(_SolutionsHeapPtr::in, OldVal::mdi, NewVal::muo),
+ [will_not_call_mercury, thread_safe, promise_pure],
+"
+ NewVal = OldVal;
+").
+:- pragma foreign_proc("Java",
+ partial_deep_copy(_SolutionsHeapPtr::in, OldVal::di, NewVal::uo),
+ [will_not_call_mercury, thread_safe, promise_pure],
+"
+ NewVal = OldVal;
+").
+
%
% reset_solutions_heap(SolutionsHeapPtr):
% Reset the solutions heap pointer to the specified value,
@@ -1236,6 +1300,13 @@
//
").
+:- pragma foreign_proc("Java",
+ reset_solutions_heap(_SolutionsHeapPtr::in),
+ [will_not_call_mercury, thread_safe],
+"
+ /* As above, we take no action. */
+").
+
%-----------------------------------------------------------------------------%
%%% :- module mutvar.
@@ -1272,6 +1343,8 @@
:- type mutvar(T) ---> mutvar(private_builtin.ref(T)).
:- pragma inline(new_mutvar/2).
+:- pragma inline(get_mutvar/2).
+:- pragma inline(set_mutvar/2).
:- pragma foreign_proc("C",
new_mutvar(X::in, Ref::out),
@@ -1292,8 +1365,6 @@
* (MR_Word *) Ref = X;
").
-:- pragma inline(get_mutvar/2).
-
:- pragma foreign_proc("C",
get_mutvar(Ref::in, X::uo),
[will_not_call_mercury, thread_safe],
@@ -1301,8 +1372,6 @@
X = * (MR_Word *) Ref;
").
-:- pragma inline(set_mutvar/2).
-
:- pragma foreign_proc("C",
set_mutvar(Ref::in, X::in),
[will_not_call_mercury, thread_safe],
@@ -1325,8 +1394,6 @@
Ref[0] = X;
").
-:- pragma inline(get_mutvar/2).
-
:- pragma foreign_proc("C#",
get_mutvar(Ref::in, X::uo),
[will_not_call_mercury, thread_safe],
@@ -1334,9 +1401,38 @@
X = Ref[0];
").
-:- pragma inline(set_mutvar/2).
-
:- pragma foreign_proc("C#",
+ set_mutvar(Ref::in, X::in),
+ [will_not_call_mercury, thread_safe],
+"
+ Ref[0] = X;
+").
+
+:- pragma foreign_type(java, mutvar(T), "java.lang.Object[]").
+
+:- pragma foreign_proc("Java",
+ new_mutvar(X::in, Ref::out),
+ [will_not_call_mercury, thread_safe],
+"
+ Ref = new java.lang.Object[1];
+ Ref[0] = X;
+").
+:- pragma foreign_proc("Java",
+ new_mutvar(X::di, Ref::uo),
+ [will_not_call_mercury, thread_safe],
+"
+ Ref = new java.lang.Object[1];
+ Ref[0] = X;
+").
+
+:- pragma foreign_proc("Java",
+ get_mutvar(Ref::in, X::uo),
+ [will_not_call_mercury, thread_safe],
+"
+ X = Ref[0];
+").
+
+:- pragma foreign_proc("Java",
set_mutvar(Ref::in, X::in),
[will_not_call_mercury, thread_safe],
"
Index: java/runtime/VA_PseudoTypeInfo_Struct0.java
===================================================================
RCS file: java/runtime/VA_PseudoTypeInfo_Struct0.java
diff -N java/runtime/VA_PseudoTypeInfo_Struct0.java
--- /dev/null 1 Jan 1970 00:00:00 -0000
+++ java/runtime/VA_PseudoTypeInfo_Struct0.java 19 Jan 2004 03:06:47 -0000
@@ -0,0 +1,16 @@
+//
+// Copyright (C) 2001-2003 The University of Melbourne.
+// This file may only be copied under the terms of the GNU Library General
+// Public License - see the file COPYING.LIB in the Mercury distribution.
+//
+
+package mercury.runtime;
+
+public class VA_PseudoTypeInfo_Struct0 extends PseudoTypeInfo {
+ public VA_PseudoTypeInfo_Struct0(
+ TypeCtorInfo_Struct type_ctor_info,
+ int arity,
+ Object[] args) {
+ // XXX stub only
+ }
+}
--------------------------------------------------------------------------
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