mirror of
https://github.com/Mercury-Language/mercury.git
synced 2025-12-16 14:25:56 +00:00
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.
This commit is contained in:
@@ -14,50 +14,51 @@
|
||||
#include "mb_basetypes.h"
|
||||
#include "mb_util.h"
|
||||
|
||||
/* Stack structure */
|
||||
typedef struct MB_Stack_Struct {
|
||||
MB_Word *data;
|
||||
MB_Word sp;
|
||||
MB_Word max_size: (MB_WORD_BITS-1);
|
||||
MB_Word max_size: (MR_WORDBITS-1);
|
||||
MB_Word gc : 1;
|
||||
} MB_Stack;
|
||||
|
||||
/*
|
||||
** Allocates space for a new stack. 'gc' indicates whether the stack region
|
||||
** should be allocated with the garbage collector (see mb_mem.h) or with the
|
||||
** C malloc (the garbage collector won't follow references from the c malloc
|
||||
** area)
|
||||
** should be allocated with the conservative garbage collector (see mb_mem.h)
|
||||
** with C's malloc (the garbage collector won't follow references from the C
|
||||
** malloc area)
|
||||
**
|
||||
** For the garbage collector, assumes that data is not atomic
|
||||
*/
|
||||
MB_Stack MB_stack_new(MB_Word init_size, MB_Bool gc);
|
||||
|
||||
/* get number of words already pushed on stack */
|
||||
/* Get number of words already pushed on stack */
|
||||
MB_Word MB_stack_size(MB_Stack *s);
|
||||
|
||||
/* pushes a value onto the stack. Return index of pushed word */
|
||||
/* Pushes a value onto the stack. Return index of pushed word */
|
||||
MB_Word MB_stack_push(MB_Stack *s, MB_Word x);
|
||||
|
||||
/* removes a value off the stack */
|
||||
/* Removes a value off the stack */
|
||||
MB_Word MB_stack_pop(MB_Stack *s);
|
||||
|
||||
/* allocates space for multiple places on the stack */
|
||||
/* return value is index of lowest word */
|
||||
/* Allocates space for multiple places on the stack */
|
||||
/* Return value is index of lowest word */
|
||||
MB_Word MB_stack_alloc(MB_Stack *s, MB_Word num_words);
|
||||
|
||||
/* remove multiple items off the stack */
|
||||
/* Remove multiple items off the stack */
|
||||
void MB_stack_free(MB_Stack *s, MB_Word num_words);
|
||||
|
||||
/* peek at an item at a given stack index */
|
||||
/* Peek at an item at a given stack index */
|
||||
MB_Word MB_stack_peek(MB_Stack *s, MB_Word idx);
|
||||
|
||||
/* peek at an item index items away from the top of the stack */
|
||||
/* Peek at an item index items away from the top of the stack */
|
||||
MB_Word MB_stack_peek_rel(MB_Stack *s, MB_Word idx);
|
||||
|
||||
/* get the address for the item at index
|
||||
/* Get the address for the item at index
|
||||
** NOTE: if you add or remove items, this value could change */
|
||||
MB_Word *MB_stack_peek_p(MB_Stack *s, MB_Word idx);
|
||||
|
||||
/* get the address for the item at index relative to the top of the stack */
|
||||
/* Get the address for the item at index relative to the top of the stack */
|
||||
MB_Word *MB_stack_peek_rel_p(MB_Stack *s, MB_Word idx);
|
||||
|
||||
/* Set the value of an item on the stack */
|
||||
@@ -66,15 +67,8 @@ void MB_stack_poke(MB_Stack *s, MB_Word idx, MB_Word x);
|
||||
/* Set the value of an item on the stack, idx items from the top */
|
||||
void MB_stack_poke_rel(MB_Stack *s, MB_Word rel_idx, MB_Word value);
|
||||
|
||||
/* deallocate space for the stack */
|
||||
/* Deallocate space for the stack */
|
||||
void MB_stack_delete(MB_Stack *s);
|
||||
|
||||
/*
|
||||
** Uses the stack to allocate num elements of type, returns pointer to first
|
||||
** element (rounds total memory allocated up to a multiple of sizeof(MB_Word))
|
||||
*/
|
||||
#define MB_STACK_ALLOC(stack, type, num) \
|
||||
MB_STACK_ALLOC((stack), MB_NUMBLOCKS(num * sizeof(type), sizeof(MB_Word))
|
||||
|
||||
#endif /* MB_STACK_H */
|
||||
|
||||
|
||||
Reference in New Issue
Block a user