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 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298
|
/*-----------------------------------------------------------------*-C-*---
* File: handc/runtime/interim.c
*
* Copyright (C)1997 Donovan Kolbly <d.kolbly@rscheme.org>
* as part of the RScheme project, licensed for free use.
* See <http://www.rscheme.org/> for the latest information.
*
* File version: 1.19
* File mod date: 1997.11.29 23:10:48
* System build: v0.7.2, 97.12.21
*
* Purpose: miscellaneous accessors, setters & utility code
*------------------------------------------------------------------------*/
#include <rscheme/runtime.h>
#include <rscheme/hashmain.h>
#include <rscheme/hashfn.h>
#include <rscheme/gcserver.h>
#include <string.h>
#include "vinsns.h"
#include <ctype.h>
#include "regs.h"
#ifndef INLINES
#include "interim.ci"
#include "chektype.ci"
#endif
/* #define CASE_INSENSITIVE */
obj rscheme_global[ NUM_RSCHEME_GLOBALS ];
/***************** miscellaneous *****************/
rs_bool TEMPLATE_P( obj thing )
{
return PTR_ISA(thing,template_class);
}
rs_bool BYTE_VECTOR_P( obj thing )
{
return PTR_ISA(thing,byte_vector_class);
}
IEEE_64 extract_float( obj thing )
{
return *(IEEE_64 *)PTR_TO_DATAPTR(thing);
}
obj make_float( IEEE_64 x )
{
obj f = alloc2( double_float_class );
assert( sizeof(IEEE_64) == SLOT(2) ); /* this permits use of `alloc2' */
*(IEEE_64 *)PTR_TO_DATAPTR(f) = x;
return f;
}
IEEE_64 get_float( obj arg, const char *fn, const char *arg_name )
{
if (OBJ_ISA_FIXNUM(arg))
return fx2int(arg);
else if (LONGFLOAT_P(arg))
return extract_float(arg);
scheme_error( "~a: Invalid argument `~a' ~s",
3,
make_string( fn ),
make_string( arg_name ),
REG0 );
return 0.0;
}
obj fluid_assq( obj key )
{
obj s = dynamic_state_reg;
obj c;
while (PAIR_P(s))
{
c = pair_car(s);
if (PAIR_P(c) && EQ(pair_car(c),key))
return c;
s = pair_cdr(s);
}
return FALSE_OBJ;
}
/***************** vectors *****************/
rs_bool VECTOR_P( obj thing )
{
return PTR_ISA(thing,vector_class);
}
obj make_empty_vector( UINT_32 length )
{
return gvec_alloc( length, vector_class );
}
obj vector_ref( obj vector, obj index )
{
if (OBJ_ISA_PTR(vector)
&& EQ(CLASSOF_PTR(vector),vector_class)
&& OBJ_ISA_FIXNUM(index))
{
UINT_32 offset = FXWORDS_TO_RIBYTES(index);
if (offset < SIZEOF_PTR(vector))
{
return gvec_read( vector, offset );
}
else
{
scheme_error("vector-ref: index ~d out of range [0,~d)",
2,
index,
RIBYTES_TO_FXWORDS(SIZEOF_PTR(vector)));
}
}
else
{
scheme_error("(vector-ref ~s ~s): bad arg", 2, vector, index );
}
return FALSE_OBJ;
}
obj vector_set( obj vector, obj index, obj item )
{
if (OBJ_ISA_PTR(vector)
&& EQ(CLASSOF_PTR(vector),vector_class)
&& OBJ_ISA_FIXNUM(index))
{
UINT_32 offset = FXWORDS_TO_RIBYTES(index);
if (offset < SIZEOF_PTR(vector))
{
gvec_write( vector, offset, item );
return item;
}
else
{
scheme_error("vector-ref: index ~d out of range [0,~d)",
2,
index,
RIBYTES_TO_FXWORDS(SIZEOF_PTR(vector)));
}
}
else
{
scheme_error("(vector-ref ~s ~s): bad arg", 2, vector, index );
}
return FALSE_OBJ;
}
/***************** symbols *****************/
rs_bool SYMBOL_P( obj thing )
{
return PTR_ISA(thing,symbol_class);
}
/*
Note that the hash value for a <Symbol>
is the rehash of the hash value for the
string mapping to the symbol
*/
obj intern( obj str )
{
obj hash = hash_string(str);
obj value;
assert( STRING_P(str) );
assert( OBJ_ISA_FIXNUM(hash) );
value = stringtable_lookup( symbol_table, hash, str );
if (EQ(value,FALSE_OBJ))
{
obj new_str;
UINT_32 len = SIZEOF_PTR(str);
new_str = bvec_alloc( len, string_class );
memcpy( PTR_TO_DATAPTR(new_str), PTR_TO_DATAPTR(str), len );
value = make2( symbol_class, new_str, rehash_fixnum( hash ) );
hashtable_install( symbol_table, hash, new_str, value );
}
return value;
}
obj lookup_symbol( const char *str )
{
return intern( make_string(str) );
}
obj symbol_hash( obj symbol )
{
assert( SYMBOL_P(symbol) );
return gvec_read( symbol, SLOT(1) );
}
const char *symbol_text( obj symbol )
{
assert( SYMBOL_P(symbol) );
return string_text( gvec_read(symbol,SLOT(0)) );
}
obj symbol_str( obj symbol )
{
assert( SYMBOL_P(symbol) );
return gvec_read(symbol,SLOT(0));
}
/***************** top-level environments & vars *****************/
obj tlv_name( obj tlv )
{
assert( TLV_P(tlv) );
return gvec_read( tlv, SLOT(0) );
}
void signal_tlv_unbound( obj tlv )
{
raise_exception( 1, 2, literals_reg, tlv );
}
/***************************** INITIALIZATION *****************************/
void init_runtim( void )
{
struct module_descr **p;
unsigned n;
obj *r;
#ifdef RS_PROFILE
rs_profile_init();
#endif
/* set all roots to FALSE */
for (p=master_table; *p; p++)
{
r = (*p)->root_vector;
n = (*p)->num_roots;
while (n > 0)
{
*r++ = FALSE_OBJ;
n--;
}
}
init_stack_cache();
}
#ifdef PLATFORM_IS_LITTLE_ENDIAN
#include "ntohd.ci"
#endif
#if !HAVE_STRERROR
char *strerror( int rc )
{
static char msg[20];
sprintf( msg, "error %d", rc );
return msg;
}
#endif
#ifdef RS_PROFILE
static FILE *fprof = NULL;
void rs_profile_close( void )
{
fclose( fprof );
}
void rs_profile_init( void )
{
fprof = popen( "/home/donovan/rscheme/rsprof > /tmp/rsprof.out", "w" );
/* fprof = fopen( "/tmp/rs.prof", "w" ); */
if (!fprof)
{
fprintf( stderr, "could not open profile file/pipe\n" );
exit(1);
}
}
void rs_profile2( const char *label, UINT_32 value_1, UINT_32 value_2 )
{
fprintf( fprof, "%lu %lu %s\n", value_1, value_2, label );
}
#endif
|