[go: up one dir, main page]

Menu

[897c37]: / lpvm / stack.h  Maximize  Restore  History

Download this file

122 lines (92 with data), 3.2 kB

  1
  2
  3
  4
  5
  6
  7
  8
  9
 10
 11
 12
 13
 14
 15
 16
 17
 18
 19
 20
 21
 22
 23
 24
 25
 26
 27
 28
 29
 30
 31
 32
 33
 34
 35
 36
 37
 38
 39
 40
 41
 42
 43
 44
 45
 46
 47
 48
 49
 50
 51
 52
 53
 54
 55
 56
 57
 58
 59
 60
 61
 62
 63
 64
 65
 66
 67
 68
 69
 70
 71
 72
 73
 74
 75
 76
 77
 78
 79
 80
 81
 82
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
/*
** $Id: stack.h,v 1.4 2008/12/18 04:03:43 dredd Exp $
**
** $Source: /cvsroot/swlpc/swlpc/lpvm/stack.h,v $
** $Revision: 1.4 $
** $Date: 2008/12/18 04:03:43 $
** $State: Exp $
**
** Author: Mike McGaughey & Geoff Wong, 1993-1998
** geoff.wong@gmail.com
** mmcgus@yahoo.com
**
** See the file "Copying" distributed with this file.
*/
#ifndef _STACK_H
#define _STACK_H
#include <unistd.h>
#include <string.h>
#include <stdio.h>
#include <stdarg.h>
#include <setjmp.h>
#include <signal.h>
#include <stdint.h>
#include "stralloc.h"
#include "smcodes.h"
#include "value.h"
#include "function.h"
#include "object.h"
#include "xalloc.h"
#include "fatal.h"
#include "error.h"
/* Stack conditions */
typedef enum
{
SE_normal = 0,
SE_timeout = 1,
SE_overflow = 2,
SE_fatal = 3,
SE_handled = 4,
SE_unhandled = 5
} Stack_code;
/* An execution block */
typedef struct EXEC_BLOCK
{
Func * prog;
uint32_t var_offset;
} Exec_block;
struct value * alloc_stack_value();
void Push(struct value *);
/* Pushes a value onto the argument stack */
void Pop(struct value *);
/* Pop the top of the stack into the arg passed to Pop */
int32_t Pushc(int32_t);
/* Push an int onto the top of the control stack */
/* returns 0 for now */
int32_t Popc();
/* Pop the top of the control stack and return the value */
void SsetPC(byte *);
/* Set the program counter at the start of an instruction */
/* block. MUST be set before calling Sexecute() */
byte * SgetPC();
/* Get the current program counter after execution halts */
/* General setup functions for the stack machine */
void Sinit_stack();
/* Initialise the stack machine */
/* MUST be set */
void Sset_current(Obj *, const char *);
/* Set the default operating object for the stack machine */
/* MUST be set before calling Sexecute() */
Obj * Scurrent();
/* Return the current object being operated upon by the */
/* virtual machine. */
Obj * Scaller();
/* Return the object which called the current object */
void Sset_external_handler( void (*exh)(int) );
/* Set the handler function for functions external to the */
/* stack machine */
void Sset_program_handler( Exec_block(*progh)(Obj *, Shared *) );
/* Set the handler function to find program blocks given */
/* an object and function */
void Serror_stream(FILE *);
/* Set the error stream the VM outputs its errors to */
/* If not set errors go to stderr */
void Spush_new_frame(uint32_t args, byte * reta, uint32_t offset, Obj * co, Func * func);
/* update control frame */
uint8_t Sget_frame_args();
/* get number of args for function call */
/* Actually run the stack machine */
Stack_code Sexecute();
/* Actually run the stack machine */
/* Returns an integer representing an error code (if +ve) */
#endif