1 /* extern.h: This include file declares all symbols exported by the interpreter 2 * kernel that may be used by applications or extensions. 3 * 4 * $Id$ 5 * 6 * Copyright 1990, 1991, 1992, 1993, 1994, 1995, Oliver Laumann, Berlin 7 * Copyright 2002, 2003 Sam Hocevar <sam@hocevar.net>, Paris 8 * 9 * This software was derived from Elk 1.2, which was Copyright 1987, 1988, 10 * 1989, Nixdorf Computer AG and TELES GmbH, Berlin (Elk 1.2 has been written 11 * by Oliver Laumann for TELES Telematic Services, Berlin, in a joint project 12 * between TELES and Nixdorf Microprocessor Engineering, Berlin). 13 * 14 * Oliver Laumann, TELES GmbH, Nixdorf Computer AG and Sam Hocevar, as co- 15 * owners or individual owners of copyright in this software, grant to any 16 * person or company a worldwide, royalty free, license to 17 * 18 * i) copy this software, 19 * ii) prepare derivative works based on this software, 20 * iii) distribute copies of this software or derivative works, 21 * iv) perform this software, or 22 * v) display this software, 23 * 24 * provided that this notice is not removed and that neither Oliver Laumann 25 * nor Teles nor Nixdorf are deemed to have made any representations as to 26 * the suitability of this software for any purpose nor are held responsible 27 * for any defects of this software. 28 * 29 * THERE IS ABSOLUTELY NO WARRANTY FOR THIS SOFTWARE. 30 */ 31 32 C_LINKAGE_BEGIN 33 34 /* Autoloading 35 */ 36 extern Object P_Autoload (Object, Object); 37 38 /* Bignums 39 */ 40 extern Object Make_Uninitialized_Bignum (int); 41 extern void Bignum_Normalize_In_Place (struct S_Bignum *); 42 extern double Bignum_To_Double (Object); 43 44 /* Boolean operators 45 */ 46 extern Object P_Booleanp (Object); 47 extern Object P_Not (Object); 48 extern Object P_Eq (Object, Object); 49 extern Object P_Eqv (Object, Object); 50 extern Object P_Equal (Object, Object); 51 extern Object P_Empty_List_Is_False (Object); 52 extern int Eqv (Object, Object); 53 extern int Equal (Object, Object); 54 55 /* Characters 56 */ 57 extern Object Make_Char (int); 58 extern Object P_Charp (Object); 59 extern Object P_Char_Upcase (Object); 60 extern Object P_Char_Downcase (Object); 61 extern Object P_Char_Eq (Object, Object); 62 extern Object P_Char_Less (Object, Object); 63 extern Object P_Char_Greater (Object, Object); 64 extern Object P_Char_Eq_Less (Object, Object); 65 extern Object P_Char_Eq_Greater (Object, Object); 66 extern Object P_Char_CI_Eq (Object, Object); 67 extern Object P_Char_CI_Less (Object, Object); 68 extern Object P_Char_CI_Greater (Object, Object); 69 extern Object P_Char_CI_Eq_Less (Object, Object); 70 extern Object P_Char_CI_Eq_Greater (Object, Object); 71 extern Object P_Char_Upper_Casep (Object); 72 extern Object P_Char_Lower_Casep (Object); 73 extern Object P_Char_Alphabeticp (Object); 74 extern Object P_Char_Numericp (Object); 75 extern Object P_Char_Whitespacep (Object); 76 extern Object P_Char_To_Integer (Object); 77 extern Object P_Integer_To_Char (Object); 78 79 /* Continuations 80 */ 81 extern Object P_Call_With_Current_Continuation (Object); 82 extern Object P_Dynamic_Wind (Object, Object, Object); 83 extern Object P_Control_Pointp (Object); 84 extern Object P_Control_Point_Environment (Object); 85 86 /* Scheme strings --> C Strings 87 */ 88 extern char *Get_String (Object); 89 extern char *Get_Strsym (Object); 90 91 /* Debugging 92 */ 93 extern Object P_Backtrace_List (int, Object*); 94 95 /* Dump 96 */ 97 extern Object P_Dump (Object); 98 99 /* Lexical bindings, environments 100 */ 101 extern Object P_The_Environment (void); 102 extern Object P_Define (Object); 103 extern Object P_Set (Object); 104 extern Object P_Environment_To_List (Object); 105 extern Object P_Define_Macro (Object); 106 extern Object P_Boundp (Object); 107 extern Object P_Global_Environment (void); 108 extern Object P_Environmentp (Object); 109 extern Object The_Environment, Global_Environment; 110 111 /* Error handling 112 */ 113 extern void Primitive_Error (const char*, ...) elk_attribute(__noreturn__); 114 extern void Fatal_Error (const char*, ...) elk_attribute(__noreturn__); 115 extern void Range_Error (Object); 116 extern void Panic (const char*); 117 extern Object P_Error (int, Object*); 118 extern Object P_Reset (void); 119 extern const char *Error_Tag; /* will be removed in the near future */ 120 extern const char *Get_Error_Tag (void); 121 extern void Set_Error_Tag (const char *); 122 extern void Set_App_Name (char *); 123 extern void Reader_Error (Object, char *) elk_attribute(__noreturn__); 124 125 /* Interrupts 126 */ 127 extern Object P_Disable_Interrupts (void); 128 extern Object P_Enable_Interrupts (void); 129 extern void Signal_Exit (int); 130 131 /* Features 132 */ 133 extern Object P_Features (void); 134 extern Object P_Featurep (Object); 135 extern Object P_Provide (Object); 136 extern Object P_Require (int, Object*); 137 138 /* Memory allocation, garbage collection 139 */ 140 extern int GC_Debug; 141 extern Object Alloc_Object (int, int, int); 142 extern void Register_Before_GC (void (*)(void)); 143 extern void Register_After_GC (void (*)(void)); 144 extern Object P_Collect (void); 145 extern Object P_Garbage_Collect_Status (int, Object *); 146 #ifdef GENERATIONAL_GC 147 extern Object P_Collect_Incremental (void); 148 #endif 149 150 /* Files and ports 151 */ 152 extern Object Curr_Input_Port, Curr_Output_Port; 153 extern Object Standard_Input_Port, Standard_Output_Port; 154 extern void Reset_IO (int); 155 extern Object P_Current_Input_Port (void); 156 extern Object P_Current_Output_Port (void); 157 extern Object P_Input_Portp (Object); 158 extern Object P_Output_Portp (Object); 159 extern Object P_Open_Input_File (Object); 160 extern Object P_Open_Output_File (Object); 161 extern Object P_Open_Input_Output_File (Object); 162 extern Object P_Eof_Objectp (Object); 163 extern Object P_With_Input_From_File (Object, Object); 164 extern Object P_With_Output_To_File (Object, Object); 165 extern Object P_Call_With_Input_File (Object, Object); 166 extern Object P_Call_With_Output_File (Object, Object); 167 extern Object P_Open_Input_String (Object); 168 extern Object P_Open_Output_String (void); 169 extern Object P_Port_File_Name (Object); 170 extern Object P_Tilde_Expand (Object); 171 extern Object P_File_Existsp (Object); 172 extern Object P_Close_Input_Port (Object); 173 extern Object P_Close_Output_Port (Object); 174 extern Object P_Port_Line_Number (Object); 175 extern Object Terminate_File (Object); 176 extern Object Make_Port (int, FILE*, Object); 177 extern unsigned int Path_Max (void); 178 179 /* Loading of files 180 */ 181 extern Object P_Load (int, Object*); 182 extern void Load_Source_Port (Object); 183 extern void Load_File (char *); 184 185 /* Pairs and lists 186 */ 187 extern Object P_Cons (Object, Object); 188 extern Object P_Car (Object); 189 extern Object P_Cdr (Object); 190 extern Object P_Set_Car (Object, Object); 191 extern Object P_Set_Cdr (Object, Object); 192 extern Object P_Listp (Object); 193 extern Object P_List (int, Object*); 194 extern Object P_Length (Object); 195 extern Object P_Nullp (Object); 196 extern Object P_Pairp (Object); 197 extern Object P_Cxr (Object, Object); 198 extern Object P_Cddr (Object); 199 extern Object P_Cdar (Object); 200 extern Object P_Cadr (Object); 201 extern Object P_Caar (Object); 202 extern Object P_Cdddr (Object); 203 extern Object P_Cddar (Object); 204 extern Object P_Cdadr (Object); 205 extern Object P_Cdaar (Object); 206 extern Object P_Caddr (Object); 207 extern Object P_Cadar (Object); 208 extern Object P_Caadr (Object); 209 extern Object P_Caaar (Object); 210 extern Object P_Caaaar (Object); 211 extern Object P_Caaadr (Object); 212 extern Object P_Caadar (Object); 213 extern Object P_Caaddr (Object); 214 extern Object P_Cadaar (Object); 215 extern Object P_Cadadr (Object); 216 extern Object P_Caddar (Object); 217 extern Object P_Cadddr (Object); 218 extern Object P_Cdaaar (Object); 219 extern Object P_Cdaadr (Object); 220 extern Object P_Cdadar (Object); 221 extern Object P_Cdaddr (Object); 222 extern Object P_Cddaar (Object); 223 extern Object P_Cddadr (Object); 224 extern Object P_Cdddar (Object); 225 extern Object P_Cddddr (Object); 226 extern Object P_Append (int, Object*); 227 extern Object P_Append_Set (int, Object*); 228 extern Object P_Last_Pair (Object); 229 extern Object P_Reverse (Object); 230 extern Object P_Reverse_Set (Object); 231 extern Object P_List_Tail (Object, Object); 232 extern Object P_List_Ref (Object, Object); 233 extern Object P_Assq (Object, Object); 234 extern Object P_Assv (Object, Object); 235 extern Object P_Assoc (Object, Object); 236 extern Object P_Memq (Object, Object); 237 extern Object P_Memv (Object, Object); 238 extern Object P_Member (Object, Object); 239 extern Object P_Make_List (Object, Object); 240 extern Object Copy_List (Object); 241 extern unsigned int Fast_Length (Object); 242 extern Object Const_Cons (Object, Object); 243 244 /* Startup and termination 245 */ 246 extern Object P_Command_Line_Args (void); 247 extern Object P_Exit (int, Object*); 248 extern void Elk_Init (int, char **av, int, char *); 249 extern void Exit_Handler (void); 250 251 /* malloc() and realloc() 252 */ 253 extern char *Safe_Malloc (unsigned int); 254 extern char *Safe_Realloc (char*, unsigned int); 255 256 /* Numbers 257 */ 258 extern Object Make_Integer (int); 259 extern Object Make_Unsigned (unsigned int); 260 extern Object Make_Long (long int); 261 extern Object Make_Unsigned_Long (unsigned long int); 262 extern Object Make_Reduced_Flonum (double); 263 extern Object Make_Flonum (double); 264 extern Object P_Numberp (Object); 265 extern Object P_Complexp (Object); 266 extern Object P_Realp (Object); 267 extern Object P_Rationalp (Object); 268 extern Object P_Integerp (Object); 269 extern Object P_Abs (Object); 270 extern Object P_Zerop (Object); 271 extern Object P_Positivep (Object); 272 extern Object P_Negativep (Object); 273 extern Object P_Oddp (Object); 274 extern Object P_Evenp (Object); 275 extern Object P_Exactp (Object); 276 extern Object P_Inexactp (Object); 277 extern Object P_Exact_To_Inexact (Object); 278 extern Object P_Inexact_To_Exact (Object); 279 extern Object P_Inc (Object); 280 extern Object P_Dec (Object); 281 extern Object P_Generic_Equal (int, Object*); 282 extern Object P_Generic_Less (int, Object*); 283 extern Object P_Generic_Greater (int, Object*); 284 extern Object P_Generic_Eq_Less (int, Object*); 285 extern Object P_Generic_Eq_Greater (int, Object*); 286 extern Object P_Generic_Plus (int, Object*); 287 extern Object P_Generic_Minus (int, Object*); 288 extern Object P_Generic_Multiply (int, Object*); 289 extern Object P_Generic_Divide (int, Object*); 290 extern Object P_Quotient (Object, Object); 291 extern Object P_Remainder (Object, Object); 292 extern Object P_Modulo (Object, Object); 293 extern Object P_Gcd (int, Object*); 294 extern Object P_Lcm (int, Object*); 295 extern Object P_Floor (Object); 296 extern Object P_Ceiling (Object); 297 extern Object P_Truncate (Object); 298 extern Object P_Round (Object); 299 extern Object P_Sqrt (Object); 300 extern Object P_Exp (Object); 301 extern Object P_Pow (Object, Object); 302 extern Object P_Log (Object); 303 extern Object P_Sin (Object); 304 extern Object P_Cos (Object); 305 extern Object P_Tan (Object); 306 extern Object P_Asin (Object); 307 extern Object P_Acos (Object); 308 extern Object P_Atan (int, Object*); 309 extern Object P_Min (int, Object*); 310 extern Object P_Max (int, Object*); 311 extern Object P_Random (void); 312 extern Object P_Srandom (Object); 313 extern Object P_Number_To_String (int, Object*); 314 extern double Get_Double (Object); 315 extern int Get_Integer (Object); 316 extern unsigned int Get_Unsigned (Object); 317 extern long int Get_Long (Object); 318 extern unsigned long int Get_Unsigned_Long (Object); 319 extern int Get_Exact_Integer (Object); 320 extern unsigned int Get_Exact_Unsigned (Object); 321 extern long int Get_Exact_Long (Object); 322 extern unsigned long int Get_Exact_Unsigned_Long (Object); 323 324 /* Onfork handlers 325 */ 326 extern void Register_Onfork (void (*)(void)); 327 extern void Call_Onfork (void); 328 329 /* Define_Primitive() 330 */ 331 extern void Define_Primitive (Object (*)(), const char*, int, int, 332 enum discipline); 333 334 /* Output 335 */ 336 extern Object P_Write (int, Object*); 337 extern Object P_Display (int, Object*); 338 extern Object P_Write_Char (int, Object*); 339 extern Object P_Newline (int, Object*); 340 extern Object P_Format (int, Object*); 341 extern Object P_Clear_Output_Port (int, Object*); 342 extern Object P_Flush_Output_Port (int, Object*); 343 extern Object P_Print (int, Object*); 344 extern Object P_Get_Output_String (Object); 345 extern void Check_Output_Port (Object); 346 extern void Discard_Output (Object); 347 extern void Printf (Object, const char *, ...); 348 extern void Print_Object (Object, Object, int, int, unsigned int); 349 extern void General_Print_Object (Object, Object, int); 350 extern void Format (Object, const char*, unsigned int, int, Object*); 351 extern int Saved_Errno; 352 353 /* Evaluator, procedures, macros 354 */ 355 extern Object Eval (Object); 356 extern Object P_Eval (int, Object*); 357 extern Object P_Apply (int, Object*); 358 extern Object Funcall (Object, Object, int); 359 extern Object P_Lambda (Object); 360 extern Object P_Map (int, Object*); 361 extern Object P_Procedure_Environment (Object); 362 extern Object P_Procedure_Lambda (Object); 363 extern Object P_For_Each (int, Object*); 364 extern Object P_Procedurep (Object); 365 extern Object P_Macro (Object); 366 extern Object P_Macro_Body (Object); 367 extern Object P_Macro_Expand (Object); 368 extern Object P_Primitivep (Object); 369 extern Object P_Primitive_To_String (Object); 370 extern Object P_Compoundp (Object); 371 extern Object P_Compound_To_String (Object); 372 extern Object P_Macrop (Object); 373 extern Object P_Macro_To_String (Object); 374 extern void Check_Procedure (Object); 375 376 /* Delay and force 377 */ 378 extern Object P_Delay (Object); 379 extern Object P_Force (Object); 380 extern Object P_Promisep (Object); 381 extern Object P_Promise_Environment (Object); 382 383 /* Input 384 */ 385 extern Object P_Read (int, Object*); 386 extern Object P_Read_Char (int, Object*); 387 extern Object P_Peek_Char (int, Object*); 388 extern Object P_Char_Readyp (int, Object*); 389 extern Object P_Unread_Char (int, Object*); 390 extern Object P_Read_String (int, Object*); 391 extern Object P_Clear_Input_Port (int, Object*); 392 extern Object General_Read (Object, int); 393 extern void Check_Input_Port (Object); 394 extern void Discard_Input (Object); 395 extern void Define_Reader (int, READFUN); 396 397 /* Special forms 398 */ 399 extern Object P_Quote (Object); 400 extern Object P_If (Object); 401 extern Object P_Let (Object); 402 extern Object P_Letseq (Object); 403 extern Object P_Letrec (Object); 404 extern Object P_Case (Object); 405 extern Object P_Cond (Object); 406 extern Object P_And (Object); 407 extern Object P_Or (Object); 408 extern Object P_Do (Object); 409 extern Object P_Quasiquote (Object); 410 extern Object P_Fluid_Let (Object); 411 extern Object P_Begin (Object); 412 extern Object P_Begin1 (Object); 413 414 /* Strings 415 */ 416 extern Object Make_String (const char*, unsigned int); 417 extern Object Make_Const_String (const char*, unsigned int); 418 extern Object P_Make_String (int, Object*); 419 extern Object P_Stringp (Object); 420 extern Object P_String (int, Object*); 421 extern Object P_String_To_Number (int, Object*); 422 extern Object P_String_Eq (Object, Object); 423 extern Object P_String_Less (Object, Object); 424 extern Object P_String_Greater (Object, Object); 425 extern Object P_String_Eq_Less (Object, Object); 426 extern Object P_String_Eq_Greater (Object, Object); 427 extern Object P_String_CI_Eq (Object, Object); 428 extern Object P_String_CI_Less (Object, Object); 429 extern Object P_String_CI_Greater (Object, Object); 430 extern Object P_String_CI_Eq_Less (Object, Object); 431 extern Object P_String_CI_Eq_Greater (Object, Object); 432 extern Object P_String_Length (Object); 433 extern Object P_String_Ref (Object, Object); 434 extern Object P_String_Set (Object, Object, Object); 435 extern Object P_Substring (Object, Object, Object); 436 extern Object P_String_Copy (Object); 437 extern Object P_String_Append (int, Object*); 438 extern Object P_List_To_String (Object); 439 extern Object P_String_To_List (Object); 440 extern Object P_Substring_Fill (Object, Object, Object, Object); 441 extern Object P_String_Fill (Object, Object); 442 extern Object P_Substringp (Object, Object); 443 extern Object P_CI_Substringp (Object, Object); 444 extern int String_Getc (Object); 445 extern void String_Ungetc (Object, register int); 446 447 /* Symbols, variables, frequently used Scheme objects 448 */ 449 extern_c Object elk_import Null; 450 extern_c Object elk_import True; 451 extern_c Object elk_import False; 452 extern_c Object elk_import Void; 453 extern_c Object elk_import Newline; 454 extern_c Object elk_import Eof; 455 extern_c Object elk_import Unspecified; 456 extern Object Intern (const char*); 457 extern Object CI_Intern (const char*); 458 extern Object P_Oblist (void); 459 extern Object P_Symbolp (Object); 460 extern Object P_Symbol_To_String (Object); 461 extern Object P_String_To_Symbol (Object); 462 extern Object P_Put (int, Object*); 463 extern Object P_Get (Object, Object); 464 extern Object P_Symbol_Plist (Object); 465 extern void Define_Variable (Object*, const char*, Object); 466 extern void Define_Symbol (Object *, const char*); 467 extern Object Sym_Else; 468 extern Object Var_Get (Object); 469 extern void Var_Set (Object, Object); 470 extern int Var_Is_True (Object); 471 extern unsigned long int Symbols_To_Bits (Object, int, SYMDESCR*); 472 extern Object Bits_To_Symbols (unsigned long int, int, SYMDESCR*); 473 474 /* Termination functions 475 */ 476 extern void Register_Object (Object, GENERIC, PFO, int); 477 extern void Deregister_Object (Object); 478 extern Object Find_Object (int, GENERIC, MATCHFUN, ...); 479 extern void Terminate_Group (GENERIC); 480 extern void Terminate_Type (int); 481 482 /* Types, Define_Type() 483 */ 484 extern TYPEDESCR *Types; 485 extern Object P_Type (Object); 486 extern void Wrong_Type (Object, int) elk_attribute(__noreturn__); 487 extern void Wrong_Type_Combination (Object, const char*) 488 elk_attribute(__noreturn__); 489 extern int Define_Type (int, const char*, int (*)(Object), int, 490 int (*)(Object, Object), int (*)(Object, Object), 491 int (*)(Object, Object, int, int, int), 492 int (*)(Object*, int (*)(Object*)) ); 493 494 /* Vectors 495 */ 496 extern Object Make_Vector (unsigned int, Object); 497 extern Object Make_Const_Vector (unsigned int, Object); 498 extern Object P_Make_Vector (int, Object*); 499 extern Object P_Vectorp (Object); 500 extern Object P_Vector (int, Object*); 501 extern Object P_Vector_Length (Object); 502 extern Object P_Vector_Ref (Object, Object); 503 extern Object P_Vector_Set (Object, Object, Object); 504 extern Object P_Vector_To_List (Object); 505 extern Object P_List_To_Vector (Object); 506 extern Object P_Vector_Fill (Object, Object); 507 extern Object P_Vector_Copy (Object); 508 509 C_LINKAGE_END 510