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
This commit is contained in:
Levi Cameron
2001-01-24 07:42:29 +00:00
parent cf2b6c80df
commit 2ca8f64b76
18 changed files with 5015 additions and 129 deletions

56
bytecode/mb_stack.h Normal file
View File

@@ -0,0 +1,56 @@
/*
** Copyright (C) 1997 The University of Melbourne.
** This file may only be copied under the terms of the GNU Library General
** Public License - see the file COPYING.LIB in the Mercury distribution.
**
** $Id: mb_stack.h,v 1.1 2001-01-24 07:42:28 lpcam Exp $
**
** High-water marked stack of 'MB_Word's
**
*/
#ifndef MB_STACK_H
#define MB_STACK_H
#include "mb_bytecode.h"
typedef struct {
MB_Word*data;
MB_Word sp;
MB_Word max_size;
} MB_Stack;
/* allocates space for a new stack */
MB_Stack MB_stack_new(MB_Word init_size);
/* get number of words already pushed on stack */
MB_Word MB_stack_size(MB_Stack* s);
/* pushes a value onto the stack */
void MB_stack_push(MB_Stack* s, MB_Word x);
/* 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 */
MB_Word MB_stack_alloc(MB_Stack* s, MB_Word num_words);
/* 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*/
MB_Word MB_stack_peek(MB_Stack* s, MB_Word idx);
/* 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
** 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 */
MB_Word* MB_stack_peek_rel_p(MB_Stack* s, MB_Word idx);
/* Set the value of an item on the stack */
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 */
void MB_stack_delete(MB_Stack* s);
#endif /* MB_STACK_H */