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.
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.
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).
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
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.
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'.
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.
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'.
^
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.
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.
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.
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.
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.
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().
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.
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.
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.
Estimated hours taken: 0.1
Small changes to Mmakefile.
bytecode/Mmakefile:
Now linking with libmer and libgc. Added $(MERCURY_DIR)/runtime
to link path.