From 864eae3889afbe68178f0e0ffb73a34eec573e98 Mon Sep 17 00:00:00 2001 From: James Goddard Date: Mon, 19 Jan 2004 05:11:03 +0000 Subject: [PATCH] Implement some library procedures for the Java back end. 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. --- java/runtime/VA_PseudoTypeInfo_Struct0.java | 16 +++ library/std_util.m | 114 ++++++++++++++++++-- 2 files changed, 121 insertions(+), 9 deletions(-) create mode 100644 java/runtime/VA_PseudoTypeInfo_Struct0.java diff --git a/java/runtime/VA_PseudoTypeInfo_Struct0.java b/java/runtime/VA_PseudoTypeInfo_Struct0.java new file mode 100644 index 000000000..d5067e364 --- /dev/null +++ b/java/runtime/VA_PseudoTypeInfo_Struct0.java @@ -0,0 +1,16 @@ +// +// Copyright (C) 2001-2004 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 + } +} diff --git a/library/std_util.m b/library/std_util.m index 958ef51ca..4af54602f 100644 --- a/library/std_util.m +++ b/library/std_util.m @@ -1,5 +1,5 @@ %-----------------------------------------------------------------------------% -% Copyright (C) 1994-2003 The University of Melbourne. +% Copyright (C) 1994-2004 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. %-----------------------------------------------------------------------------% @@ -1048,6 +1048,21 @@ non_cc_call(P::pred(in, out, di, uo) is cc_multi, X::in, More::out, #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 @@ non_cc_call(P::pred(in, out, di, uo) is cc_multi, X::in, More::out, #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 @@ non_cc_call(P::pred(in, out, di, uo) is cc_multi, X::in, More::out, #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 @@ non_cc_call(P::pred(in, out, di, uo) is cc_multi, X::in, More::out, // "). +:- 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 @@ non_cc_call(P::pred(in, out, di, uo) is cc_multi, X::in, More::out, 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 @@ non_cc_call(P::pred(in, out, di, uo) is cc_multi, X::in, More::out, // "). +:- 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 @@ XXX `ui' modes don't work yet :- 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 @@ XXX `ui' modes don't work yet * (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 @@ XXX `ui' modes don't work yet 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 @@ XXX `ui' modes don't work yet 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,8 +1401,6 @@ XXX `ui' modes don't work yet X = Ref[0]; "). -:- pragma inline(set_mutvar/2). - :- pragma foreign_proc("C#", set_mutvar(Ref::in, X::in), [will_not_call_mercury, thread_safe], @@ -1343,6 +1408,37 @@ XXX `ui' modes don't work yet 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], +" + Ref[0] = X; +"). + %%% end_module mutvar. %-----------------------------------------------------------------------------%