/* -*- Mode: C; tab-width: 4 -*- */

#include <gc.h>

/* opcodes with arguments: */
#define OP_PROC			'P'
#define OP_SAVE			'S'
#define OP_LIT			'L'
#define OP_TEST			'?'
#define OP_PRIMOP		'%'
#define OP_DYNREF		'd'
#define OP_DEFINE		'D'
#define OP_VARREF		'v'
#define OP_ASSIGN		'V'
#define OP_DYNASSIGN	'='

/* no-argument opcodes */
#define OP_RESTORE		'R'
#define OP_PUSH			'>'
#define OP_MOVE_ACC2	'2'
#define OP_INVOKE		'I'
#define OP_PRINT		'!'
#define OP_JUMP			'J'
#define OP_HALT			'H'
		
#define PRIM_ADD	'+'
#define PRIM_SUB	'-'
#define PRIM_MUL	'*'
#define PRIM_DIV	'/'
#define PRIM_EQ		'='
#define PRIM_GT		'>'
#define PRIM_LT		'<'

#define UNPACK_WORD(p) ((int)(*p)) | (((int)(*(p+1)))<<8)
#define UNPACK_LONG(p) ((int)(*p)) | (((int)(*(p+1)))<<8) | (((int)(*(p+2)))<<16) | (((int)(*(p+3)))<<24)

typedef struct _value_list {
  void * value;
  struct _value_list * next;
} value_list;

typedef struct _lexical_environment {
  value_list * values;
  struct _lexical_environment * next;
} lexical_environment;

typedef struct _symbol_table {
  char * symbol;
  void * value;
  struct _symbol_table * next;
} symbol_table;

typedef struct _continuation {
  char * code;
  value_list * val;
  lexical_environment * lex_env;
  struct _continuation * next;
} continuation;

typedef struct _closure {
  char * code;
  lexical_environment * lex_env;
} closure;

#ifdef _WIN32
#  define INLINE
#else
#  define INLINE inline
#endif
