Commit Graph

60 Commits

Author SHA1 Message Date
Peter Ross
d89afe3839 Merge changes from the reuse branch back onto the main branch.
Estimated hours taken: 0.25
Branches: main

Merge changes from the reuse branch back onto the main branch.

compiler/ml_unify_gen.m:
    Handle the case where the tag on the cell to be reused is unknown.

compiler/hlds_goal.m:
    Add a field which records what possible cons_ids the cell to be
    reused can be tagged with.

compiler/builtin_ops.m:
    Add the unary builtin operator strip_tag.

compiler/bytecode.m:
compiler/c_util.m:
compiler/java_util.m:
compiler/llds.m:
compiler/mlds_to_il.m:
compiler/opt_debug.m:
bytecode/mb_disasm.c:
bytecode/mb_exec.c:
    Handle the strip_tag operator.
2001-03-13 12:40:19 +00:00
Levi Cameron
0921310ca5 More work on the bytecode interpreter.
With these changes, it now passes all tests/general/* test cases
  except those with floats.

  Changes to the compiler:
  - Added extra argument to test instruction (string comparisons were
    being treated as integer comparisons; properly deals with different
    atomic type unifications now)
  - Changed bytecode stub functions

  Changes to the bytecode interpreter:
  - Cleaned up comments
  - Forked part of mb_machine to mb_exec
  - Added support for submodules
  - Added support for nondet procedures
  - Added support for cc_xxx procedures
  - Finished higher order calls
  - Added (very basic) debug interface
  - Added support for type information
  - Added memory corruption checking
  - Changed machine state dump formatting
  - Fixed bug in nested switches
  - Resolved builtin__unify and builtin_compare failures
  - Modified bytecode tags generation so .c & .m tag files are separate
  - Header usage rationalised

  Changes to test suite:
  - Added test cases for the bytecode interpreter.
  - More work on the bytecode interpreter.

bytecode/Mmakefile:
        Modified bytecode tags generation so .c & .m tag files are separate.
        mb_machine split into mb_exec.
        test file renamed to simple.m (copy over tests/simple??.m to test).

bytecode/TODO:
        Updated.

bytecode/mb_basetypes.h:
        Removed redundant MB_WORD_BITS (use MR_WORDBITS instead).

bytecode/mb_bytecode.h:
bytecode/mpb_bytecode.c:
        Formatting changes
        Third test instruction argument added.

bytecode/mb_disasm.h:
bytecode/mb_disasm.c:
        Formatting changes.
        Third test instruction argument added.
        Added MB_FMT_INTWIDE.

bytecode/mb_exec.h:
bytecode/mb_exec.c:
bytecode/mb_machine.h:
bytecode/mb_machine.c:
        mb_machine* split into mb_exec* and mb_machine*.
        Almost all instructions now work (see important changes above).

bytecode/mb_interface.h:
bytecode/mb_interface.c:
        Added nondet stub functions.
        Added functions to lookup builtin compiler procedures:
                do_redo, do_fail, __unify, __compare.
        Removed old debugging code.
        Stack layout changed to support nondet procedures.

bytecode/mb_interface_stub.c:
bytecode/mb_interface_stub.h:
        Split off bare minimum of includes for bytecode stubs.
        Added nondet stubs.

bytecode/mb_machine_show.c:
        Made code cleaner (added subfunctions for MB_show_state).
        Added variable names to machine state dump.

bytecode/mb_mem.h:
bytecode/mb_mem.c:
        Added limited memory corruption checking.

bytecode/mb_module.h:
bytecode/mb_module.c:
        Swapped order of temps & vars on stack.
        Fixed nested switches causing random crashes.
        Added nested module support.

bytecode/test/simple??.m:
        Various test files - just to check that it doesn't crash.
        (Most do not output anything & must be verified by stepping through
        manually).

compiler/bytecode.m:
compiler/bytecode_gen.m:
        Added extra argument to test instruction (otherwise
        string comparisons would be treated as integer comparisons).

compiler/code_gen.m:
        Changed call structure name in bytecode stub to resolve
        issues with illegal characters in C structure names.
        Changed bytecode stub header file name.
2001-02-19 02:05:59 +00:00
Levi Cameron
49438027b7 Major changes to bytecode interpreter.
Estimated hours taken: 200

Major changes to bytecode interpreter.
Beginnings of native code integration

bytecode/bytecode.c:
bytecode/bytecode.h:
bytecode/dict.c:
bytecode/dict.h:
bytecode/disasm.c:
bytecode/disasm.h:
bytecode/machine.c:
bytecode/machine.h:
bytecode/mbi_main.c:
bytecode/mdb.m:
bytecode/mem.c:
bytecode/mem.h:
bytecode/slist.c:
bytecode/slist.h:
bytecode/template.c:
bytecode/template.h:
bytecode/util.c:
bytecode/util.h:
        Removed. These are all the old bytecode files from
        before I started. Any parts that were useful have already
        been salvaged and used in the new interpreter.

bytecode/*:
	Added MB_Bytecode_Addr and MB_Native_Addr types to remove abiguity
	as to what type of code an instruction pointer points to, and
	provide compiler help for erroneously mixing pointer types.

bytecode/Mmakefile:
bytecode/Mmake.params:
        Makefile for test bytecode program. Note that any library
        functions that are called from bytecode must be compiled
        with trace information. (So their entry labels can be
        looked up)

bytecode/mb_basetypes.h:
        Added. Contains basic type definitions.

bytecode/mb_bytecode.c:
bytecode/mb_bytecode.h:
        Better error messages.
        Changed var_lists to direct pointers rather than
        lookups through data stacks (much simpler but stop you
        using realloc() on the bytecode argument data)
        Label addresses are computed at module load time rather
        than being looked up each jump
        Added endof_negation_goal
        Temporary stack slot numbers are translated to variable
        numbers (now there is no distinction between temps & vars)
        MB_read_cstring return value convention changed (see comments
	for how to now free the returned memory)
        Added distinction between functions and predicates
        Added enter_else
        Code addresses are all pointers rather than simple ints
	Added MB_Code_Addr type for pred_const and call instructions

bytecode/mb_disasm.c:
bytecode/mb_disasm.h:
        Added endof_negation_goal & enter_else
        Output strings are now easier to read
        MB_listing does not display anything for invalid addresses
        MB_listing takes line length argument

bytecode/mb_interface.c:
bytecode/mb_interface.h:
bytecode/mb_interface_stub.m:
        Interfacing between native/bytecode

bytecode/mb_machine.c:
bytecode/mb_machine.h:
bytecode/mb_machine_def.h:
        Large sections of code branched off into mb_module.?
        Most instructions completed, but not integrated with native
        code.
        Most of mb_machine_def has been removed as the native
        code functions provide the same functionality.

bytecode/mb_machine_show.c:
bytecode/mb_machine_show.h:
        Completely changed. Less information now as a lot of what
        was being displayed before cannot be determined as easily
        now that it is stored in the mercury runtime.

bytecode/mb_mem.c:
bytecode/mb_mem.h:
        Added routines for garbage collected memory

bytecode/mb_module.c:
bytecode/mb_module.h:
        Loading & accessing bytecode. Argument data indexes & id are now
        stored in a single word. (see MB_BCID_xxx macros).
        Call & label addresses are now calculated at load time.

bytecode/mb_stack.c:
bytecode/mb_stack.h:
        Added options for garbage collection of MB_Stack memory

bytecode/mb_util.c:
bytecode/mb_util.h:
        Miscellaneous string functions added and SAY() for debugging

bytecode/simple01.m:
        Added. Simple test program. (replace with whatever
        program is being tested at the time).
2001-02-01 05:20:32 +00:00
Levi Cameron
2ca8f64b76 The beginnings of the new bytecode interpreter.
Estimated hours taken: 40

 The beginnings of the new bytecode interpreter. Probably
 just over half the code is the same or a
 superficially modified revision of the old one.

bytecode/mb_bytecode.c
bytecode/mb_bytecode.h
	Almost identical. Only real change is made MB_read_cstring not use
	any static variables

bytecode/mb_disasm.c
bytecode/mb_disasm.h
	Again, code very similar. Changed all the functions to write to a
	buffer instead of a file and to allow for bytecode indenting. Output
	format string for some instructions changed (hopefully more menaingful
	than just a dump of numbers)

bytecode/mb_machine.c
bytecode/mb_machine.h
	(completely different from old machine.c)
	The actual part that contains an abstract machine.
	 The rest is really just support code.
	 The instruction_table array is how instructions are dispatched. Look
	 at instr_xxxx for the actual interpreter code. Not all instructions
	 are implemented. MB_step and MB_run execute the actual
	  interpreting code

bytecode/mb_machine_show.h
bytecode/mb_machine_show.c
	  displays output showing the state of the machine


bytecode/mb_mem.c
bytecode/mb_mem.h
	  Identical to old mem apart from file name changes

bytecode/mb_util.c
bytecode/mb_util.h
	  took out strdup (not needed) and changed some comments

bytecode/mb_stack.c
bytecode/mb_stack.h
	  word based stack that will reallocate itself if it needs to


bytecode/mbi.c
	  front end for bytecode interpreter

bytecode/mdis.c
	  disassembles a file and dumps it to the screen
2001-01-24 07:42:29 +00:00
Peter Ross
a019dd4f6a Changes to reflect that body is now a binop.
Estimated hours taken: 0.1

disasm.c:
    Changes to reflect that body is now a binop.
2000-10-09 08:30:53 +00:00
Fergus Henderson
d7ed113ec6 Support installing both .par' and non-.par' versions of the GC library.
Estimated hours taken: 3

Support installing both `.par' and non-`.par' versions of the GC library.

scripts/ml.in:
	Change the code for computing which version of the GC library
	to link in so that it also takes the `.par' grade component
	into account, rather than just the `.prof' grade component.
	Add new options `--print-gc-grade' (for use by the top-level
	Mmakefile) and `--print-grade' (for symmetry).

Mmakefile:
	When invoking sub-makes in the boehm_gc directory,
	pass down GC_GRADE instead of PROF.
	Compute the GC_GRADE value using `scripts/ml ... --print-gc-grade`
	rather than computing it manually, since this avoids code duplication.

boehm_gc/Mmakefile:
boehm_gc/Makefile:
boehm_gc/NT_MAKEFILE:
	s/gc$(PROF)/$(GC_GRADE)/g

runtime/Mmakefile:
trace/Mmakefile:
browser/Mmakefile:
bytecode/Mmakefile:
library/Mmakefile:
compiler/Mmakefile:
profiler/Mmakefile:
	Change the code for computing which version of the GC library
	to link in so that it also takes the `.par' grade component
	into account, rather than just the `.prof' grade component.
2000-08-17 05:31:11 +00:00
Fergus Henderson
98b0afa001 Use clean_local' instead of clean' and `realclean_local' instead
Estimated hours taken: 0.75

Mmakefile:
*/Mmakefile:
*/*/Mmakefile:
*/*/*/Mmakefile:
	Use `clean_local' instead of `clean' and `realclean_local' instead
	of `realclean' where appropriate.  This is necessary now that
	`realclean' does not depend on `clean'.
1999-09-16 04:46:31 +00:00
Fergus Henderson
68d2f1c727 Simplify the Mmakefiles. Fix a few minor latent bugs.
Estimated hours taken: 2

Simplify the Mmakefiles.  Fix a few minor latent bugs.

*/Mmakefile:
	- Factor out some common code by defining a new variable M_ENV
	  which holds settings of environment variables for mmc, mgnuc, etc.
	- For consistency, always override MERCURY_C_ALL_INCL_DIRS rather
	  than passing extra `-I' options to mgnuc.
	- Make sure to always include `$(BOEHM_GC)/include' in the search path,
	  so that it will work if we try to compile with `-O6'.
	- Make sure to always include `--cflags $(ALL_CFLAGS)' in MCS, so
	  that the EXTRA_CFLAGS etc. will get passed down to gcc via mmc.
	- Make sure that the Mmakefiles in all directories set
	  all the MC* variables: MCPI, MCSI, MCOI, MCTOI, etc.
1999-04-08 12:58:17 +00:00
Fergus Henderson
2873b00e76 Fix a bug that broke grades `*.gc.prof.tr'.
Estimated hours taken: 0.25

Fix a bug that broke grades `*.gc.prof.tr'.
(This change was previously applied to the Mmakefiles
in the runtime, library, compiler, and profiler directories,
but I missed the `bytecode' directory.)

bytecode/Mmakefile:
	When deciding whether to link with -lgc or -lgc_prof,
	match against `*.gc*.prof*' rather than `*.gc*.prof'.
				 ^
1998-01-29 13:56:22 +00:00
Fergus Henderson
04b720630b Update the copyright messages so that (a) they contain the correct years
and (b) they say "Copyright (C) ... _The_ University of Melbourne".
1997-07-27 15:09:59 +00:00
Bert Thompson
6a1fcc80d2 This module is no longer necessary since I've put similar data
Estimated hours taken: 0.1

bytecode/static_data.c:
bytecode/static_data.h:
	This module is no longer necessary since I've put similar data
	in the "machine" module.
1997-06-02 13:58:16 +00:00
Bert Thompson
e2a6038b16 List abstract data type. (Absolutely minimal.)
Estimated hours taken: 0.5

bytecode/slist.c:
bytecode/slist.h:
	List abstract data type. (Absolutely minimal.)
1997-06-02 13:54:16 +00:00
Bert Thompson
ff7b34149e Added exported procedures:
Estimated hours taken: 1

bytecode/dict.c:
bytecode/dict.h:
	Added exported procedures:
		- dict_is_empty
		- dict_first_key
		- dict_next_key
	Also added a simple-minded unit test.
1997-05-29 09:52:58 +00:00
Bert Thompson
dce28cf057 Added target for mdb
Estimated hours taken: 0.1

bytecode/Mmakefile:
	Added target for mdb
1997-05-29 09:48:05 +00:00
Bert Thompson
090732de52 Simple Mercury driver for the bytecode interpreter.
Estimated hours taken: 0.1

bytecode/mdb.m:
	Simple Mercury driver for the bytecode interpreter.
	The driver allows us to initialise the Mercury runtime
	engine and various modules in libmercury without having
	to duplicate code from the runtime.

	This really is overkill and it would make sense to rewrite
	parts of the runtime so that initialisation and startup of
	compiled Mercury code are not so tightly coupled. May revisit
	this later.
1997-05-29 06:20:21 +00:00
Bert Thompson
1be6aa13a3 - Removed "-static" from link line since we can't use
Estimated hours taken: 0.1

bytecode/Mmakefile
	- Removed "-static" from link line since we can't use
	  dlopen and so on with statically linked binaries.
	- Added -DDEBUGGING as C compile flag. Turn it off when
	  the bytecode interpreter is working.
	- Added "dict" module, a dictionary ADT.
1997-05-28 09:36:05 +00:00
Bert Thompson
0c8e9e6187 Added #includes for the headers that these headers depend upon.
Estimated hours taken: 0.1

bytecode/disasm.h:
bytecode/mem.h:
bytecode/util.h:
	Added #includes for the headers that these headers depend upon.
	I'm still not convinced of the wisdom of having #includes inside
	headers. Tracking down the location of a declaration by using
	preprocessed source files is bad enough when nested  #include
	is forbidden.
1997-05-28 09:32:14 +00:00
Bert Thompson
06454f727a Added a dictionary abstract data type. Currently it's implemented as
Estimated hours taken: 2

Added a dictionary abstract data type. Currently it's implemented as
a dirt-simple ordered list, but it should later be reimplemented using a
hash table. Note that C has only very poor support for ADTs
and private data must be included in the header. We trust clients
of the ADT not to use the private data.

bytecode/dict.h:
	Interface of dictionary ADT.
bytecode/dict.c:
	Implementation of dictionary ADT.
1997-05-28 05:58:59 +00:00
Bert Thompson
7f1d65cad6 LIBMBI_OBJS variable was being used before its definition,
Estimated hours taken: 0.1

bytecode/Mmakefile:
	LIBMBI_OBJS variable was being used before its definition,
	hence moved it earlier.
1997-05-27 07:35:09 +00:00
Bert Thompson
afe712d198 Fixed a couple of small problems with the `tags' target.
Estimated hours taken: 0.1

bytecode/Mmakefile:
	Fixed a couple of small problems with the `tags' target.
1997-05-27 07:29:41 +00:00
Bert Thompson
1e42952101 Also generating C tags for headers.
Estimated hours taken: 0.1

bytecode/Mmakefile:
	Also generating C tags for headers.
1997-05-27 07:14:09 +00:00
Fergus Henderson
dc3217a170 Tell cvs to ignore the automatically-generated `depend.mk' file.
Estimated hours taken: 0.1

bytecode/.cvsignore:
	Tell cvs to ignore the automatically-generated `depend.mk' file.
1997-05-23 17:39:32 +00:00
Fergus Henderson
4793bb003e Add new targets libmbi.{a,so}.
Estimated hours taken: 1

bytecode/Mmakefile:
	Add new targets libmbi.{a,so}.
	In profiling grades, link with -lgc_prof rather than -lgc.

bytecode/mbi.c:
	Rename the main() function as BC_mbi_main().

bytecode/mbi_main.c:
	New file, whose main() function just calls BC_mbi_main().
1997-05-07 12:12:29 +00:00
Fergus Henderson
a3644ae6cf More cleanup of the bytecode stuff; in particular, add a `MB_' prefix
Estimated hours taken: 2

More cleanup of the bytecode stuff; in particular, add a `MB_' prefix
to most names.

bytecode/*:
	- Prefix all names defined in header files with `MB_'
	  (except for `TRUE', `FALSE', `DEBUGGING', and `XXXdebug').
	- Add macros `MB_new', `MB_new_array', and `MB_resize_array',
	  and use those instead of using `MB_malloc' and `MB_resize'
	  (formerly `mem_malloc' and `mem_resize') or malloc() and realloc()
	  directly.  Uncomment the definition of MB_strdup() now that it
	  calls MB_malloc().
	- Delete the definitions of `uchar', `uint', `ushort', `ulong'
	  (just spell them out, its clearer and more portable that way).
	- Fix the indentation in a few places I missed on my previous pass.
	- Add a `README' file.
1997-04-26 05:57:14 +00:00
Fergus Henderson
48103ac54c A cleanup of the bytecode stuff.
Estimated hours taken: 2

A cleanup of the bytecode stuff.

bytecode/*:
	Various changes to make it conform to our C coding standard.
	In particular:
		- fix indentation and layout, particularly of switch
		  statements;
		- use `#include "..."' rather than `#include <...>'
		  for user-defined header files

bytecode/Mmakefile:
	Avoid the use of `$^' in hard-coded rules, since it is
	not portable to non-GNU makes (many makes only allow the
	use of variables such as $*, $^, etc. in suffix rules),
	and since it is easy to avoid.
	Also add an XXX comment, since the header dependency handling
	is done twice.

bytecode/bytecode.c:
	s/BIG_ENDING/MR_BIG_ENDIAN/ and s/LITTLE_ENDING/MR_LITTLE_ENDIAN/,
	to match my recent change to runtime/conf.h.in.
	In fact every identifier in the bytecode directory ought to be
	prefixed with `MB_', but I haven't done that in this change.
1997-04-26 03:16:18 +00:00
Bert Thompson
ba415565b5 - Changes to support portable numeric constants in the
Estimated hours taken: 3

A number of changes:
	- Changes to support portable numeric constants in the
	  bytecode file.
	- read_int() now returns a Mercury `Integer', which is platform
	  dependent. However it actually reads a portable, 64-bit,
	  big-endian, 2's complement integer from the bytecode stream.
	- read_float() now returns a Mercury `Float', which is platform
	  dependent.
	- Comment-style changed to agree with C coding standard.
	- malloc and realloc are now used instead of mem_malloc and
	  mem_realloc. Need to look at memory-management in a lot
	  more depth when the bytecode interpreter starts linking
	  in Mercury shared objects.
	- Removed Bytecode-doc since it's now an HTML file in
	  the developer documentation directory of the Mercury web pages.
	- Removed the Makefile since we're now using an Mmakefile.

bytecode/
	bytecode.c
	bytecode.h
		Changes to read_int(), read_float() and others.
	disasm.c
	disasm.h
	machine.c
	machine.h
	mbi.c
	mbi.h
	mdis.c
	mdis.h
	mem.c
	mem.h
	static_data.c
	static_data.h
	template.c
	template.h
	util.c
	util.h
		Divers changes as described above.
	Bytecode-doc
	Mmakefile
		Removed as described above.
1997-04-24 05:31:48 +00:00
Bert Thompson
9b8137b1d9 Small changes to Mmakefile.
Estimated hours taken: 0.1

Small changes to Mmakefile.

bytecode/Mmakefile:
	Now linking with libmer and libgc. Added $(MERCURY_DIR)/runtime
	to link path.
1997-04-24 05:16:04 +00:00
Bert Thompson
fd811ddee7 For consistency with the rest of Mercury, we use an Mmakefile in
Estimated hours taken: 2

For consistency with the rest of Mercury, we use an Mmakefile in
the bytecode directory.

bytecode/Mmakefile:
	Added Mmakefile.
1997-03-26 07:25:38 +00:00
Bert Thompson
eb454beb95 Fixed error in comment. 1997-03-25 03:53:19 +00:00
Bert Thompson
35498c8e44 Made some changes suggested by bromages's code review. 1997-03-25 03:10:28 +00:00
Bert Thompson
4202468422 Made some changes suggested by bromages's code review. 1997-03-25 02:15:45 +00:00
Bert Thompson
12eae5e466 Various inconsequential changes.
This module is still a half-munched Twistie. 8^)
1997-03-25 02:11:01 +00:00
Bert Thompson
3cde83e386 Initial revision 1997-03-20 08:17:33 +00:00
Bert Thompson
caeef88a38 Changed calls to malloc and free etc to calls to mem_malloc, mem_free.
In bytecode stream, cons_id's are now module-qualified.
Made changes to accomodate this.
1997-03-20 08:16:50 +00:00
Bert Thompson
5addf0844f In bytecode stream, cons_id's are now module-qualified.
Made changes to accomodate this.
Added `noop' bytecode.
1997-03-20 08:15:46 +00:00
Bert Thompson
7444bfa1e7 Initial revision 1997-02-13 06:00:17 +00:00
Bert Thompson
52c99f2052 Initial revision 1997-02-11 09:15:43 +00:00
Bert Thompson
00ad612b06 Added rcs_id static string 1997-02-11 08:06:37 +00:00
Bert Thompson
229af11390 Fixed typo. 1997-02-11 08:03:55 +00:00
Bert Thompson
6e17d431d3 Added rcs_id static string 1997-02-11 07:52:16 +00:00
Bert Thompson
1e7c8d4ccf Added comment about freeing the bytecodes that are read. 1997-02-11 07:40:53 +00:00
Bert Thompson
c7f6988bcb Brought up-to-date with version 8 of the bytecode. 1997-02-04 02:24:05 +00:00
Bert Thompson
600f8f1240 Changed all ushorts to shorts. 1997-02-04 01:39:53 +00:00
Bert Thompson
3f47a61531 Replaced the stub quote_cstring with a proper implementation. 1997-02-03 08:02:42 +00:00
Bert Thompson
4498524dbb Nuked some crap. 1997-02-01 13:36:33 +00:00
Bert Thompson
61d3e53678 We use shorts rather than ushorts for most of the stuff in the
bytecode file. A label, for instance, may be negative in enter_disjunct.
(Specifically, in the last enter_disjunct in a disjunction, the
label is -1.)
1997-02-01 13:36:01 +00:00
Bert Thompson
b0a8799252 Moved a lot of definitions related to bytecode from here to
the bytecode module.
1997-02-01 09:22:13 +00:00
Bert Thompson
6f44799b92 Moved code related to printing bytecodes to here from the bytecode module. 1997-02-01 09:21:18 +00:00
Bert Thompson
4eae45fcc1 Made static everything that needn't be exported from this module.
Moved code related to printing out of here. Only code for
parsing the bytestream should be in here.
1997-02-01 09:21:04 +00:00
Bert Thompson
619f65a72e Commented disassemble(). 1997-02-01 09:15:02 +00:00