-
+ CFD3ED45F7A9FD06FC15908F04D951F3C5E6D4BDF67F0D34A05DBB62DD4948952F771071F0BAADB050C3094AD20BA58042C677585C5EE6988E6725E227934FE2
tinyscheme/scheme-private.h
(0 . 0)(1 . 210)
2496 /* scheme-private.h */
2497
2498 #ifndef _SCHEME_PRIVATE_H
2499 #define _SCHEME_PRIVATE_H
2500
2501 #include "scheme.h"
2502 /*------------------ Ugly internals -----------------------------------*/
2503 /*------------------ Of interest only to FFI users --------------------*/
2504
2505 #ifdef __cplusplus
2506 extern "C" {
2507 #endif
2508
2509 enum scheme_port_kind {
2510 port_free=0,
2511 port_file=1,
2512 port_string=2,
2513 port_srfi6=4,
2514 port_input=16,
2515 port_output=32,
2516 port_saw_EOF=64
2517 };
2518
2519 typedef struct port {
2520 unsigned char kind;
2521 union {
2522 struct {
2523 FILE *file;
2524 int closeit;
2525 #if SHOW_ERROR_LINE
2526 int curr_line;
2527 char *filename;
2528 #endif
2529 } stdio;
2530 struct {
2531 char *start;
2532 char *past_the_end;
2533 char *curr;
2534 } string;
2535 } rep;
2536 } port;
2537
2538 /* cell structure */
2539 struct cell {
2540 unsigned int _flag;
2541 union {
2542 struct {
2543 char *_svalue;
2544 int _length;
2545 } _string;
2546 num _number;
2547 port *_port;
2548 foreign_func _ff;
2549 struct {
2550 struct cell *_car;
2551 struct cell *_cdr;
2552 } _cons;
2553 } _object;
2554 };
2555
2556 struct scheme {
2557 /* arrays for segments */
2558 func_alloc malloc;
2559 func_dealloc free;
2560
2561 /* return code */
2562 int retcode;
2563 int tracing;
2564
2565
2566 #define CELL_SEGSIZE 5000 /* # of cells in one segment */
2567 #define CELL_NSEGMENT 10 /* # of segments for cells */
2568 char *alloc_seg[CELL_NSEGMENT];
2569 pointer cell_seg[CELL_NSEGMENT];
2570 int last_cell_seg;
2571
2572 /* We use 4 registers. */
2573 pointer args; /* register for arguments of function */
2574 pointer envir; /* stack register for current environment */
2575 pointer code; /* register for current code */
2576 pointer dump; /* stack register for next evaluation */
2577
2578 int interactive_repl; /* are we in an interactive REPL? */
2579
2580 struct cell _sink;
2581 pointer sink; /* when mem. alloc. fails */
2582 struct cell _NIL;
2583 pointer NIL; /* special cell representing empty cell */
2584 struct cell _HASHT;
2585 pointer T; /* special cell representing #t */
2586 struct cell _HASHF;
2587 pointer F; /* special cell representing #f */
2588 struct cell _EOF_OBJ;
2589 pointer EOF_OBJ; /* special cell representing end-of-file object */
2590 pointer oblist; /* pointer to symbol table */
2591 pointer global_env; /* pointer to global environment */
2592 pointer c_nest; /* stack for nested calls from C */
2593
2594 /* global pointers to special symbols */
2595 pointer LAMBDA; /* pointer to syntax lambda */
2596 pointer QUOTE; /* pointer to syntax quote */
2597
2598 pointer QQUOTE; /* pointer to symbol quasiquote */
2599 pointer UNQUOTE; /* pointer to symbol unquote */
2600 pointer UNQUOTESP; /* pointer to symbol unquote-splicing */
2601 pointer FEED_TO; /* => */
2602 pointer COLON_HOOK; /* *colon-hook* */
2603 pointer ERROR_HOOK; /* *error-hook* */
2604 pointer SHARP_HOOK; /* *sharp-hook* */
2605 pointer COMPILE_HOOK; /* *compile-hook* */
2606
2607 pointer free_cell; /* pointer to top of free cells */
2608 long fcells; /* # of free cells */
2609
2610 pointer inport;
2611 pointer outport;
2612 pointer save_inport;
2613 pointer loadport;
2614
2615 #define MAXFIL 64
2616 port load_stack[MAXFIL]; /* Stack of open files for port -1 (LOADing) */
2617 int nesting_stack[MAXFIL];
2618 int file_i;
2619 int nesting;
2620
2621 char gc_verbose; /* if gc_verbose is not zero, print gc status */
2622 char no_memory; /* Whether mem. alloc. has failed */
2623
2624 #define LINESIZE 1024
2625 char linebuff[LINESIZE];
2626 #define STRBUFFSIZE 256
2627 char strbuff[STRBUFFSIZE];
2628
2629 FILE *tmpfp;
2630 int tok;
2631 int print_flag;
2632 pointer value;
2633 int op;
2634
2635 void *ext_data; /* For the benefit of foreign functions */
2636 long gensym_cnt;
2637
2638 struct scheme_interface *vptr;
2639 void *dump_base; /* pointer to base of allocated dump stack */
2640 int dump_size; /* number of frames allocated for dump stack */
2641 };
2642
2643 /* operator code */
2644 enum scheme_opcodes {
2645 #define _OP_DEF(A,B,C,D,E,OP) OP,
2646 #include "opdefines.h"
2647 OP_MAXDEFINED
2648 };
2649
2650
2651 #define cons(sc,a,b) _cons(sc,a,b,0)
2652 #define immutable_cons(sc,a,b) _cons(sc,a,b,1)
2653
2654 int is_string(pointer p);
2655 char *string_value(pointer p);
2656 int is_number(pointer p);
2657 num nvalue(pointer p);
2658 long ivalue(pointer p);
2659 double rvalue(pointer p);
2660 int is_integer(pointer p);
2661 int is_real(pointer p);
2662 int is_character(pointer p);
2663 long charvalue(pointer p);
2664 int is_vector(pointer p);
2665
2666 int is_port(pointer p);
2667
2668 int is_pair(pointer p);
2669 pointer pair_car(pointer p);
2670 pointer pair_cdr(pointer p);
2671 pointer set_car(pointer p, pointer q);
2672 pointer set_cdr(pointer p, pointer q);
2673
2674 int is_symbol(pointer p);
2675 char *symname(pointer p);
2676 int hasprop(pointer p);
2677
2678 int is_syntax(pointer p);
2679 int is_proc(pointer p);
2680 int is_foreign(pointer p);
2681 char *syntaxname(pointer p);
2682 int is_closure(pointer p);
2683 #ifdef USE_MACRO
2684 int is_macro(pointer p);
2685 #endif
2686 pointer closure_code(pointer p);
2687 pointer closure_env(pointer p);
2688
2689 int is_continuation(pointer p);
2690 int is_promise(pointer p);
2691 int is_environment(pointer p);
2692 int is_immutable(pointer p);
2693 void setimmutable(pointer p);
2694
2695 #ifdef __cplusplus
2696 }
2697 #endif
2698
2699 #endif
2700
2701 /*
2702 Local variables:
2703 c-file-style: "k&r"
2704 End:
2705 */