Get the java.ssdebug grade installing and compiling hello world.

Estimated hours taken: 2
Branches: main

Get the java.ssdebug grade installing and compiling hello world.
Note that currently the jars for the java.ssdebug grade are installed in the
same location as the non-ssdebug jars.  That's not a problem for now,
because the standard library currently has the ssdebug transformations
turned off when it's compiled in the ssdebug grade, so the java.ssdebug
jars are the same as the java jars.  Changing it so that the java.ssdebug
jars are installed in a different location requires getting mmc to
adjust the classpath depending on the grade, which doesn't seem worth
it at this stage.

Also note that the interface files for the ssdb, browser and mdbcomp
libraries need to be installed in the ssdebug grade otherwise mmc
complains that it cannot find files like ssdb.m when compiling
a program.  These interface files are currently only installed
when there is an ssdebug grade.

browser/MDB_FLAGS.in:
mdbcomp/MDBCOMP_FLAGS.in:
ssdb/SSDB_FLAGS.in:
    Generate .module_dep files (needed to compile ssdebug transformed
    programs).

browser/Mmakefile:
    Build and install mer_browser.jar.
    Install the interface files when in an ssdebug grade.

browser/browse.m:
    Avoid a determinism warning.

browser/cterm.m:
browser/declarative_execution.m:
browser/listing.m:
    Get this code compiling in java grades.
    The "if (1 == 1)" before throwing an exception is to avoid
    "unreachable code" errors from the Java compiler.

library/Mmakefile:
    Mention that the ssdebug jars are installed in the
    same spot as the non-ssdebug jars.

mdbcomp/Mmakefile:
    Build and install mer_mdbcomp.jar.
    Install the interface files when in an ssdebug grade.

mdbcomp/rtti_access.m:
    Get this code compiling in Java grades.

scripts/Mercury.config.in:
    Add the ssdb, mdbcomp and browser jars to the classpath.
    If they are not installed they will just be ignored.

ssdb/Mmakefile:
    Build and install mer_ssdb.jar.
    Install the interface files when in an ssdebug grade.

ssdb/ssdb.m:
    Get this code compiling in java grades.
    Flush the output buffers after displaying the prompt so that
    it's always displayed.
This commit is contained in:
Ian MacLarty
2009-09-14 05:58:23 +00:00
parent 0cf7a49062
commit 23d6d4a392
14 changed files with 192 additions and 77 deletions

View File

@@ -6,6 +6,7 @@
--no-shlib-linker-use-install-name
--force-disable-tracing
--no-ssdb
--generate-mmc-deps
-I../library
-I../mdbcomp
-I../browser

View File

@@ -89,7 +89,7 @@ LD_LIBFLAGS-libmer_browser.dylib = -install_name \
#-----------------------------------------------------------------------------#
JAVACFLAGS = -classpath $(LIBRARY_DIR)
JAVACFLAGS = -classpath $(LIBRARY_DIR):$(MDBCOMP_DIR)
MTAGS = $(SCRIPTS_DIR)/mtags
@@ -134,7 +134,12 @@ main: library $(TAGS_FILE_EXISTS)
all: library $(TAGS_FILE_EXISTS) browse_test declarative_test
.PHONY: library
ifeq ("$(findstring java,$(GRADE))","java")
library: jars
else
library: $(LIBS)
endif
.PHONY: depend
depend: MDB_FLAGS $(DEPENDS)
@@ -210,31 +215,23 @@ dates:
#-----------------------------------------------------------------------------#
#
# Some Java compilers require the Java source files to be put in directories
# which match their package names. But the Mercury compiler generates them
# with the package name prefixed to the file name with a ".", not a "/".
# So we copy the Java source files to where the Java compiler expects them
# to be.
#
# XXX This is a hack. We ought to change the Mercury compiler so that it
# generates the Java files with the right names in the first place.
#
JARS = $(BROWSER_LIB_NAME).jar
mdb/%.java: mdb.%.java
[ -d mdb ] || mkdir mdb
cp $< $@
.PHONY: jars
jars: classes
echo jmercury/*.class > $(BROWSER_LIB_NAME).classes
$(JAR) $(JAR_CREATE_FLAGS) $(BROWSER_LIB_NAME).jar @$(BROWSER_LIB_NAME).classes
$(JAR) i $(BROWSER_LIB_NAME).jar
$(RM) $(BROWSER_LIB_NAME).classes
RENAMED_JAVAS = $($(BROWSER_LIB_NAME).javas:mdb.%.java=mdb/%.java)
JAVAS = $(wildcard jmercury/*.java)
RENAMED_CLASSES = $($(BROWSER_LIB_NAME).classes:mdb.%.class=mdb/%.class)
.PHONY:
classes: javas
$(JAVAC) $(ALL_JAVACFLAGS) $(JAVAS)
.PHONY: javas
javas: $(RENAMED_JAVAS)
.PHONY: classes
classes: $(RENAMED_JAVAS)
$(JAVAC) $(ALL_JAVACFLAGS) -d $(classes_subdir) $(RENAMED_JAVAS)
javas: $(BROWSER_LIB_NAME).javas
#-----------------------------------------------------------------------------#
@@ -268,7 +265,12 @@ realclean_local:
# Installation targets
.PHONY: install
ifeq ("$(findstring ssdebug,$(GRADE))","ssdebug")
# The ssdebug grade requires the interface files.
install: install_library install_ints
else
install: install_library
endif
.PHONY: install_dirs
install_dirs:
@@ -277,9 +279,12 @@ install_dirs:
mkdir -p $(INSTALL_GRADE_MODULE_DIR)
[ -d $(INSTALL_MERC_LIB_DIR) ] || mkdir -p $(INSTALL_MERC_LIB_DIR)
ifneq ("$(filter il% java% erlang%,$(GRADE))","")
ifneq ("$(filter il% erlang%,$(GRADE))","")
# there is no browser in the .NET, Java, Erlang backends
# there is no browser in the .NET or Erlang backends
.PHONY: install_ints
install_ints:
.PHONY: install_init
install_init:
@@ -287,8 +292,24 @@ install_init:
.PHONY: install_library
install_library:
else ifneq (,$(findstring java,$(GRADE)))
.PHONY: install_ints
install_ints: lib$(BROWSER_LIB_NAME).install_ints
.PHONY: install_init
install_init:
.PHONY: install_library
install_library: jars
mkdir -p $(INSTALL_JAVA_LIBRARY_DIR)
cp $(JARS) $(INSTALL_JAVA_LIBRARY_DIR)
else
.PHONY: install_ints
install_ints:
.PHONY: install_init
install_init: $(BROWSER_LIB_NAME).init install_dirs
cp `vpath_find $(BROWSER_LIB_NAME).init` $(INSTALL_GRADE_MODULE_DIR)

View File

@@ -756,9 +756,11 @@ do_print_memory_addr(Debugger, Info, MaybePath, !IO) :-
Addr = (MR_Integer) Value;
").
% The debugger does not yet work on non-C backends, so what we return
% does not matter.
get_value_representation(_Value, 0).
% Java doesn't support converting addresses to integers, so we
% just return zero. For other backends the debugger doesn't yet
% work, so it doesn't matter what we return.
get_value_representation(_Value, X) :-
cc_multi_equal(0, X).
:- pred interpret_format_options(option_table(format_option)::in,
maybe_error(maybe(portray_format))::out) is det.

View File

@@ -59,6 +59,10 @@
:- pragma foreign_export("C", match_with_cterm(in, in, out),
"ML_BROWSE_match_with_cterm").
% Dummy types form non-C backends.
:- type cterm ---> cterm.
:- type cargs ---> cargs.
%---------------------------------------------------------------------------%
% Uncomment these and the unsafe_perform_ios below to debug match_with_cterm
@@ -123,6 +127,13 @@ match_with_cterms(UnivArgs, CArgs, Match) :-
Args = Term->MR_term_args;
").
:- pragma foreign_proc("Java",
cterm_deconstruct(_Term::in, _Functor::out, _Args::out),
[will_not_call_mercury, promise_pure],
"
if (1 == 1) throw new Error(\"not supported in java grade\");
").
:- pragma foreign_proc(c,
cterm_head_tail(Args::in, Head::out, Tail::out),
[will_not_call_mercury, promise_pure],
@@ -135,3 +146,11 @@ match_with_cterms(UnivArgs, CArgs, Match) :-
SUCCESS_INDICATOR = MR_TRUE;
}
").
:- pragma foreign_proc("Java",
cterm_head_tail(_Args::in, _Head::out, _Tail::out),
[will_not_call_mercury, promise_pure],
"
if (1 == 1) throw new Error(\"not supported in java grade\");
").

View File

@@ -516,7 +516,7 @@ call_node_maybe_proc_defn_rep(CallNode, MaybeProcDefnRep) :-
:- pred call_node_bytecode_layout(label_layout::in, proc_layout::out)
is semidet.
% Default version for non-C backends.
% Default version for backends other than C or Java.
call_node_bytecode_layout(_, _) :-
semidet_fail.
@@ -538,10 +538,17 @@ call_node_bytecode_layout(_, _) :-
}
").
:- pragma foreign_proc("Java",
call_node_bytecode_layout(_CallLabelLayout::in, _ProcLayout::out),
[will_not_call_mercury, thread_safe, promise_pure],
"
if (1 == 1) throw new Error(\"not supported in java grade\");
").
:- semipure pred have_cached_proc_defn_rep(proc_layout::in, proc_defn_rep::out)
is semidet.
% Default version for non-C backends.
% Default version for backends other than C or Java.
have_cached_proc_defn_rep(_, _) :-
semidet_fail.
@@ -563,6 +570,13 @@ have_cached_proc_defn_rep(_, _) :-
}
").
:- pragma foreign_proc("Java",
have_cached_proc_defn_rep(_ProcLayout::in, _ProcDefnRep::out),
[will_not_call_mercury, thread_safe, promise_semipure],
"
if (1 == 1) throw new Error(\"not supported in java grade\");
").
:- impure pred cache_proc_defn_rep(proc_layout::in, proc_defn_rep::in) is det.
% Default version for non-C backends.

View File

@@ -94,6 +94,8 @@
:- type search_path == list(path_name).
:- pragma foreign_type("C", c_file_ptr, "FILE *", [can_pass_as_mercury_type]).
% stub.
:- pragma foreign_type("Java", c_file_ptr, "java.lang.Object").
% These predicates are called from trace/mercury_trace_internal.c.
%

View File

@@ -533,7 +533,10 @@ ifneq (,$(findstring java,$(GRADE)))
# Copy the jars and NATIVE_SO to INSTALL_JAVA_LIBRARY_DIR. Ignore the exit
# status of last command, since NATIVE_SO may not be available and is not
# essential.
# essential. Note that in the java.ssdebug grade the library will still
# be copied to INSTALL_JAVA_LIBRARY_DIR. That's okay for now, because
# we turn off the ssdebug transformations for the library, so it is equivalent
# to the non-ssdebug grade.
.PHONY: install_library
install_library: jars

View File

@@ -3,6 +3,7 @@
--halt-at-warn
--no-warn-inferred-erroneous
--no-mercury-stdlib-dir
--generate-mmc-deps
--no-ssdb
--no-shlib-linker-use-install-name
-I../library

View File

@@ -120,7 +120,12 @@ endif
all: library all-ints $(TAGS_FILE_EXISTS)
.PHONY: library
ifeq ("$(findstring java,$(GRADE))","java")
library: jars
else
library: $(LIBS)
endif
.PHONY: all-ints
all-ints: $(MDBCOMP_LIB_NAME).int3s $(MDBCOMP_LIB_NAME).ints
@@ -174,31 +179,23 @@ dates:
#-----------------------------------------------------------------------------#
#
# Some Java compilers require the Java source files to be put in directories
# which match their package names. But the Mercury compiler generates them
# with the package name prefixed to the file name with a ".", not a "/".
# So we copy the Java source files to where the Java compiler expects them
# to be.
#
# XXX This is a hack. We ought to change the Mercury compiler so that it
# generates the Java files with the right names in the first place.
#
JARS = $(MDBCOMP_LIB_NAME).jar
mdbcomp/%.java: mdbcomp.%.java
[ -d mdbcomp ] || mkdir mdbcomp
cp $< $@
.PHONY: jars
jars: classes
echo jmercury/*.class > $(MDBCOMP_LIB_NAME).classes
$(JAR) $(JAR_CREATE_FLAGS) $(MDBCOMP_LIB_NAME).jar @$(MDBCOMP_LIB_NAME).classes
$(JAR) i $(MDBCOMP_LIB_NAME).jar
$(RM) $(MDBCOMP_LIB_NAME).classes
RENAMED_JAVAS = $($(MDBCOMP_LIB_NAME).javas:mdbcomp.%.java=mdbcomp/%.java)
JAVAS = $(wildcard jmercury/*.java)
RENAMED_CLASSES = $($(MDBCOMP_LIB_NAME).classes:mdbcomp.%.class=mdbcomp/%.class)
.PHONY:
classes: javas
$(JAVAC) $(ALL_JAVACFLAGS) $(JAVAS)
.PHONY: javas
javas: $(RENAMED_JAVAS)
.PHONY: classes
classes: $(RENAMED_JAVAS)
$(JAVAC) $(ALL_JAVACFLAGS) -d $(classes_subdir) $(RENAMED_JAVAS)
javas: $(MDBCOMP_LIB_NAME).javas
#-----------------------------------------------------------------------------#
@@ -232,7 +229,13 @@ realclean_local:
# Installation targets
.PHONY: install
# The ssdebug grade requires the interface files.
ifeq ("$(findstring ssdebug,$(GRADE))","ssdebug")
install: install_library install_ints
else
install: install_library
endif
.PHONY: install_dirs
install_dirs:
@@ -241,9 +244,12 @@ install_dirs:
mkdir -p $(INSTALL_GRADE_MODULE_DIR)
[ -d $(INSTALL_MERC_LIB_DIR) ] || mkdir -p $(INSTALL_MERC_LIB_DIR)
ifneq ("$(filter il% java% erlang%,$(GRADE))","")
ifneq ("$(filter il% erlang%,$(GRADE))","")
# there is no debugger in the .NET, Java, Erlang backends
# there is no debugger in the .NET or Erlang backends
.PHONY: install_ints
install_ints:
.PHONY: install_init
install_init:
@@ -251,7 +257,23 @@ install_init:
.PHONY: install_library
install_library:
else
else ifneq (,$(findstring java,$(GRADE)))
.PHONY: install_ints
install_ints: lib$(MDBCOMP_LIB_NAME).install_ints
.PHONY: install_init
install_init:
.PHONY: install_library
install_library: jars
mkdir -p $(INSTALL_JAVA_LIBRARY_DIR)
cp $(JARS) $(INSTALL_JAVA_LIBRARY_DIR)
else
.PHONY: install_ints
install_ints:
.PHONY: install_init
install_init: $(MDBCOMP_LIB_NAME).init install_dirs

View File

@@ -546,6 +546,13 @@ get_proc_name(special_proc_label(_, _, _, ProcName , _, _)) = ProcName.
#endif
").
:- pragma foreign_proc("Java",
proc_bytecode_bytes(_ProcLayout::in) = (_ByteCodeBytes::out),
[will_not_call_mercury, thread_safe, promise_pure],
"
if (1 == 1) throw new Error(\"not supported in java grade\");
").
% Default version for non-C backends.
proc_bytecode_bytes(_) = dummy_bytecode_bytes.

View File

@@ -69,6 +69,9 @@ DEFAULT_MCFLAGS=\
--c-flag-to-name-object-file "@OBJFILE_OPT@" \
--java-classpath "$(INSTALL_JAVA_LIBRARY_DIR)/$(RT_LIB_NAME).jar" \
--java-classpath "$(INSTALL_JAVA_LIBRARY_DIR)/$(STD_LIB_NAME).jar" \
--java-classpath "$(INSTALL_JAVA_LIBRARY_DIR)/mer_mdbcomp.jar" \
--java-classpath "$(INSTALL_JAVA_LIBRARY_DIR)/mer_browser.jar" \
--java-classpath "$(INSTALL_JAVA_LIBRARY_DIR)/mer_ssdb.jar" \
--java-flags "@JAVAC_FLAGS_FOR_HEAP_SIZE@" \
--object-file-extension ".@OBJ_SUFFIX@" \
--pic-object-file-extension ".@EXT_FOR_PIC_OBJECTS@" \

View File

@@ -89,7 +89,7 @@ LD_LIBFLAGS-libmer_ssdb.dylib = -install_name \
#-----------------------------------------------------------------------------#
JAVACFLAGS = -classpath $(LIBRARY_DIR)
JAVACFLAGS = -classpath $(LIBRARY_DIR):$(MDBCOMP_DIR):$(BROWSER_DIR)
MTAGS = $(SCRIPTS_DIR)/mtags
@@ -134,7 +134,11 @@ main: library $(TAGS_FILE_EXISTS)
all: library $(TAGS_FILE_EXISTS) browse_test declarative_test
.PHONY: library
ifeq ("$(findstring java,$(GRADE))","java")
library: jars
else
library: $(LIBS)
endif
.PHONY: depend
depend: SSDB_FLAGS $(DEPENDS)
@@ -210,31 +214,22 @@ dates:
#-----------------------------------------------------------------------------#
#
# Some Java compilers require the Java source files to be put in directories
# which match their package names. But the Mercury compiler generates them
# with the package name prefixed to the file name with a ".", not a "/".
# So we copy the Java source files to where the Java compiler expects them
# to be.
#
# XXX This is a hack. We ought to change the Mercury compiler so that it
# generates the Java files with the right names in the first place.
#
JARS = $(SSDB_LIB_NAME).jar
mdb/%.java: mdb.%.java
[ -d mdb ] || mkdir mdb
cp $< $@
.PHONY: jars
jars: classes
echo jmercury/*.class > $(SSDB_LIB_NAME).classes
$(JAR) $(JAR_CREATE_FLAGS) $(SSDB_LIB_NAME).jar @$(SSDB_LIB_NAME).classes
$(JAR) i $(SSDB_LIB_NAME).jar
$(RM) $(SSDB_LIB_NAME).classes
RENAMED_JAVAS = $($(SSDB_LIB_NAME).javas:mdb.%.java=mdb/%.java)
JAVAS = $(wildcard jmercury/*.java)
RENAMED_CLASSES = $($(SSDB_LIB_NAME).classes:mdb.%.class=mdb/%.class)
.PHONY:
classes: javas
$(JAVAC) $(ALL_JAVACFLAGS) $(JAVAS)
.PHONY: javas
javas: $(RENAMED_JAVAS)
.PHONY: classes
classes: $(RENAMED_JAVAS)
$(JAVAC) $(ALL_JAVACFLAGS) -d $(classes_subdir) $(RENAMED_JAVAS)
javas: $(SSDB_LIB_NAME).javas
#-----------------------------------------------------------------------------#
@@ -268,7 +263,7 @@ realclean_local:
# Installation targets
.PHONY: install
install: install_ints install_hdrs install_library
install: install_library install_ints install_hdrs
.PHONY: install_dirs
install_dirs:
@@ -277,9 +272,9 @@ install_dirs:
mkdir -p $(INSTALL_GRADE_MODULE_DIR)
[ -d $(INSTALL_MERC_LIB_DIR) ] || mkdir -p $(INSTALL_MERC_LIB_DIR)
ifneq ("$(filter il% java% erlang%,$(GRADE))","")
ifneq ("$(filter il% erlang%,$(GRADE))","")
# there is no ssdb (YET!) in the .NET, Java, Erlang backends
# there is no ssdb in the .NET or Erlang backends
.PHONY: install_ints
install_ints:
@@ -293,6 +288,22 @@ install_init:
.PHONY: install_library
install_library:
else ifneq (,$(findstring java,$(GRADE)))
.PHONY: install_ints
install_ints: lib$(SSDB_LIB_NAME).install_ints
.PHONY: install_init
install_init:
.PHONY: install_hdrs
install_hdrs: lib$(SSDB_LIB_NAME).install_hdrs
.PHONY: install_library
install_library: jars
mkdir -p $(INSTALL_JAVA_LIBRARY_DIR)
cp $(JARS) $(INSTALL_JAVA_LIBRARY_DIR)
else
.PHONY: install_ints

View File

@@ -6,6 +6,7 @@
--no-shlib-linker-use-install-name
--force-disable-tracing
--no-ssdb
--generate-mmc-deps
-I../library
-I../mdbcomp
-I../browser

View File

@@ -953,6 +953,7 @@ ssdb_cmd_name("exit", ssdb_exit).
read_and_execute_cmd(Event, ShadowStack, Depth, WhatNext, !IO) :-
% XXX use stdout_stream
io.write_string("ssdb> ", !IO),
io.flush_output(!IO),
% Read a string in input and return a string.
io.read_line_as_string(io.stdin_stream, Result, !IO),
(
@@ -1715,6 +1716,13 @@ find_breakpoint_with_num(Num, [BP|ListBreakPoint], BreakPointFound) :-
IO = IO0;
").
:- pragma foreign_proc("Java",
exit_debugger(_IO0::di, _IO::uo),
[will_not_call_mercury, promise_pure, tabled_for_io],
"
System.exit(0);
").
%----------------------------------------------------------------------------%
% Print the current informations at this event point.