vm.h 3.46 KB
Newer Older
eg's avatar
eg committed
1 2 3
/*
 * v m . h				-- The STklos Virtual Machine
 * 
eg's avatar
eg committed
4
 * Copyright © 2000-2006 Erick Gallesio - I3S-CNRS/ESSI <eg@unice.fr>
eg's avatar
eg committed
5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23
 * 
 * 
 * This program is free software; you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation; either version 2 of the License, or
 * (at your option) any later version.
 * 
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 * 
 * You should have received a copy of the GNU General Public License
 * along with this program; if not, write to the Free Software
 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, 
 * USA.
 * 
 *           Author: Erick Gallesio [eg@unice.fr]
 *    Creation date:  1-Mar-2000 19:51 (eg)
24
 * Last file update: 12-Apr-2006 15:57 (eg)
eg's avatar
eg committed
25 26 27 28 29 30 31 32 33 34 35 36
 */


/*===========================================================================*\
 * Jmp_buf management
 *
 * Things are a little bit complicated because (at least on Linux) the 
 * mask of blocked signal is not properly saved (or you have to use the 
 * non POSIX function sigsetjmp). Following code should work on any POSIX 
 * system.
\*===========================================================================*/
#include <signal.h>
separdau's avatar
separdau committed
37 38 39 40
#include "stklosconf.h"
#ifdef THREADS_LURC
# include <lurc.h>
#endif
eg's avatar
eg committed
41 42

typedef struct {	/* simple wrapper around jmp_buf */
separdau's avatar
separdau committed
43 44 45
#ifdef THREADS_LURC
  lurc_context_t j;
#else
eg's avatar
eg committed
46
  jmp_buf j;
separdau's avatar
separdau committed
47
#endif /* THREADS_LURC */
eg's avatar
eg committed
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
  sigset_t blocked;
} jbuf;


/*===========================================================================*\
 * 
 * 			 C O N T I N U A T I O N S
 * 
\*===========================================================================*/

struct continuation_obj {
  stk_header header;
  int csize;			/* C stack size */
  void *cstart, *cend;		/* Start and end of the C stack */
  int ssize;			/* Scheme stack size */
  void *sstart, *send;		/* Start and end of the Scheme stack */
  
  jbuf state;
  int fresh;
  STk_instr *pc;		/* VM registers */
  SCM *fp;
  SCM *sp;
  SCM env;
  SCM *constants;
  SCM *handlers;
  jbuf *jb;
  //  void *cstack;
  //  void *sstack;
  char stacks[1];
};

#define CONTP(k) 	(BOXED_TYPE_EQ((k), tc_continuation))

SCM STk_make_continuation(void);
SCM STk_restore_continuation(SCM cont, SCM val);

eg's avatar
eg committed
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

/*===========================================================================*\
 * 
 *  			T H R E A D   S U P P O R T
 * 
\*===========================================================================*/

#define MAX_VALS 8	/* static number of values	*/

typedef struct {
  STk_instr *pc;	/* Program Counter		*/
  SCM *fp;		/* Frame pointer		*/
  SCM *sp;		/* Stack pointer		*/
  SCM val;		/* Current value register 	*/
  SCM env;		/* Current environment register */
  SCM *constants;	/* Constants of current code 	*/
  SCM *handlers;	/* Exceptions handlers		*/
  
  SCM r1, r2;		/* general registers		 */
  
  SCM vals[MAX_VALS];	/* registers for multiple values */
  int valc;		/* # of multiple values 	 */
    
  jbuf *top_jmp_buf;  

  SCM *stack;
  int stack_len;
111
  SCM current_module;
112 113 114
  SCM iport, oport,eport; /* Standard ports */
  SCM scheme_thread; 	  /* Scheme associated thread 	*/
  SCM parameters;	  /* Scheme dynamic environement (parameter objects) */
eg's avatar
eg committed
115 116 117
} vm_thread_t;


eg's avatar
eg committed
118 119 120
vm_thread_t *STk_allocate_vm(int stack_size);
vm_thread_t inline *STk_get_current_vm(void);