[m-rev.] For review: Java implementation of std_util library

James Goddard goddardjames at yahoo.com
Tue Jan 20 11:35:23 AEDT 2004


 --- Fergus Henderson <fjh at cs.mu.OZ.AU> wrote: >
> An alternative that would work would be to use an object of a particular
> class that happens to have one field of type java.lang.Object.
> That might be slightly more efficient than using an array,
> because it would avoid any need for array index bounds checks.
> But it's not a big deal.

No problem.  I had it as an array before to conform with the .NET
implementation, but this is just as easy:

-------------------------------------------------------------------
Estimated hours taken: 0.3
Branches: main

Change representation of mutvar(T) for Java back-end in std_util library.

library/std_util.m:
        Defined the type mutvar(T) as mercury.std_util.Mutvar, a trivial class
        with a single member field to hold the variable.

        Modified the implementation of the following procedures in Java:
                new_mutvar/2
                get_mutvar/2
                set_mutvar/2
-------------------------------------------------------------------
Index: std_util.m
===================================================================
RCS file: /home/mercury1/repository/mercury/library/std_util.m,v
retrieving revision 1.289
diff -u -d -r1.289 std_util.m
--- std_util.m  19 Jan 2004 05:10:55 -0000      1.289
+++ std_util.m  20 Jan 2004 00:26:17 -0000
@@ -1408,35 +1408,43 @@
        Ref[0] = X;
 ").

-:- pragma foreign_type(java, mutvar(T), "java.lang.Object[]").
+:- pragma foreign_code("Java",
+"
+       public static class Mutvar {
+               public Object object;
+
+               public Mutvar(Object init) {
+                       object = init;
+               }
+       }
+").
+:- pragma foreign_type(java, mutvar(T), "mercury.std_util.Mutvar").

 :- 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;
+       Ref = new mercury.std_util.Mutvar(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;
+       Ref = new mercury.std_util.Mutvar(X);
 ").

 :- pragma foreign_proc("Java",
        get_mutvar(Ref::in, X::uo),
        [will_not_call_mercury, thread_safe],
 "
-       X = Ref[0];
+       X = Ref.object;
 ").

 :- pragma foreign_proc("Java",
        set_mutvar(Ref::in, X::in),
        [will_not_call_mercury, thread_safe],
 "
-       Ref[0] = X;
+       Ref.object = X;
 ").

 %%% end_module mutvar.



http://personals.yahoo.com.au - Yahoo! Personals
New people, new possibilities. FREE for a limited time.
--------------------------------------------------------------------------
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