--- microscheme/scheme.h 2015/11/25 10:30:34 1.3 +++ microscheme/scheme.h 2015/11/30 13:07:34 1.9 @@ -1,3 +1,9 @@ +/* + * µscheme + * + * Copyright (C) 2015 Marc Alexander Lehmann + * do as you want with this, attribution appreciated. + */ /* SCHEME.H */ @@ -19,10 +25,6 @@ # define STANDALONE 1 #endif -#define USE_STRCASECMP 1 -#ifndef USE_STRLWR -# define USE_STRLWR 1 -#endif #define SCHEME_EXPORT static #if USE_NO_FEATURES @@ -37,27 +39,24 @@ # define USE_COLON_HOOK 0 # define USE_DL 0 # define USE_PLIST 0 -# define USE_FLOAT 0 +# define USE_REAL 0 # define USE_ERROR_CHECKING 0 # define USE_PRINTF 0 +# define USE_INTCACHE 0 #endif /* - * Leave it defined if you want continuations, and also for the Sharp Zaurus. - * Undefine it if you only care about faster speed and not strict Scheme compatibility. + * Define: much slower, but somewhat smaller evaluation stack implemention, use more memory + * Undefined: faster, somewhat bigger implementation, uses less memory at runtime */ -//#define USE_SCHEME_STACK - -#if USE_DL -# define USE_INTERFACE 1 -#endif +/*#define USE_SCHEME_STACK*/ #ifndef USE_MULTIPLICITY # define USE_MULTIPLICITY 1 #endif -#ifndef USE_FLOAT -# define USE_FLOAT 1 +#ifndef USE_REAL +# define USE_REAL 1 #endif #ifndef USE_MATH /* If math support is needed */ @@ -85,7 +84,7 @@ #endif #ifndef USE_PLIST -# define USE_PLIST 0 +# define USE_PLIST 1 #endif /* To force system errors through user-defined error handling (see *error-hook*) */ @@ -105,18 +104,27 @@ # define USE_PRINTF 1 #endif -#ifndef USE_STRLWR -# define USE_STRLWR 1 +#ifndef USE_IGNORECASE +# define USE_IGNORECASE 1 #endif -#ifndef INLINE -# define INLINE inline +#ifndef USE_INTCACHE +# define USE_INTCACHE 1 #endif #ifndef SHOW_ERROR_LINE /* Show error line in file */ # define SHOW_ERROR_LINE 1 #endif +#if !USE_REAL +# undef USE_MATH +# define USE_MATH 0 +#endif + +/* property lists currently broken to to symbol change*/ +#undef USE_PLIST +#define USE_PLIST 0 + #if USE_MULTIPLICITY # define SCHEME_V sc # define SCHEME_P scheme *SCHEME_V @@ -131,92 +139,59 @@ # define SCHEME_A_ #endif - typedef struct scheme scheme; - typedef struct cell *pointer; - - typedef void *(*func_alloc) (size_t); - typedef void (*func_dealloc) (void *); +typedef struct scheme scheme; +typedef struct cell *pointer; - typedef long IVALUE; /* this is not used consistently yet */ - -#if USE_FLOAT - typedef double RVALUE; -# define num_is_fixnum(n) (n).is_fixnum -# define num_set_fixnum(n,f) (n).is_fixnum = (f) -# define num_ivalue(n) (n).value.ivalue -# define num_rvalue(n) (n).value.rvalue -# define num_set_ivalue(n,i) (n).value.ivalue = (i) -# define num_set_rvalue(n,r) (n).value.rvalue = (r) +typedef long IVALUE; /* this is not used consistently yet */ +#if USE_REAL +typedef double RVALUE; #else - typedef long RVALUE; -# define num_is_fixnum(n) 1 -# define num_set_fixnum(n,f) 0 -# define num_ivalue(n) (n).value.ivalue -# define num_rvalue(n) (n).value.ivalue -# define num_set_ivalue(n,i) (n).value.ivalue = (i) -# define num_set_rvalue(n,r) (n).value.ivalue = (r) -#endif - -/* num, for generic arithmetic */ - typedef struct num - { - union - { - long ivalue; -#if USE_FLOAT - RVALUE rvalue; -#endif - } value; -#if USE_FLOAT - char is_fixnum; +typedef long RVALUE; #endif - } num; /* Used for documentation purposes, to signal functions in 'interface' */ #define INTERFACE static - SCHEME_EXPORT scheme *scheme_init_new (); - SCHEME_EXPORT int scheme_init (SCHEME_P); - SCHEME_EXPORT void scheme_deinit (SCHEME_P); - void scheme_set_input_port_file (SCHEME_P_ int fin); - void scheme_set_input_port_string (SCHEME_P_ char *start, char *past_the_end); - SCHEME_EXPORT void scheme_set_output_port_file (SCHEME_P_ int fin); - void scheme_set_output_port_string (SCHEME_P_ char *start, char *past_the_end); - SCHEME_EXPORT void scheme_load_file (SCHEME_P_ int fin); - SCHEME_EXPORT void scheme_load_named_file (SCHEME_P_ int fin, const char *filename); - SCHEME_EXPORT void scheme_load_string (SCHEME_P_ const char *cmd); - SCHEME_EXPORT pointer scheme_apply0 (SCHEME_P_ const char *procname); - SCHEME_EXPORT pointer scheme_call (SCHEME_P_ pointer func, pointer args); - SCHEME_EXPORT pointer scheme_eval (SCHEME_P_ pointer obj); - void scheme_set_external_data (SCHEME_P_ void *p); - SCHEME_EXPORT void scheme_define (SCHEME_P_ pointer env, pointer symbol, pointer value); - - typedef pointer (*foreign_func) (SCHEME_P_ pointer); - - pointer xcons (SCHEME_P_ pointer a, pointer b, int immutable); - INTERFACE pointer mk_integer (SCHEME_P_ long num); - INTERFACE pointer mk_real (SCHEME_P_ RVALUE num); - INTERFACE pointer mk_symbol (SCHEME_P_ const char *name); - INTERFACE pointer gensym (SCHEME_P); - INTERFACE pointer mk_string (SCHEME_P_ const char *str); - INTERFACE pointer mk_counted_string (SCHEME_P_ const char *str, uint32_t len); - INTERFACE pointer mk_empty_string (SCHEME_P_ uint32_t len, char fill); - INTERFACE pointer mk_character (SCHEME_P_ int c); - INTERFACE pointer mk_foreign_func (SCHEME_P_ foreign_func f); - INTERFACE void putstr (SCHEME_P_ const char *s); - INTERFACE int list_length (SCHEME_P_ pointer a); - INTERFACE int eqv (pointer a, pointer b); +SCHEME_EXPORT scheme *scheme_init_new (); +SCHEME_EXPORT int scheme_init (SCHEME_P); +SCHEME_EXPORT void scheme_deinit (SCHEME_P); +void scheme_set_input_port_file (SCHEME_P_ int fin); +void scheme_set_input_port_string (SCHEME_P_ char *start, char *past_the_end); +SCHEME_EXPORT void scheme_set_output_port_file (SCHEME_P_ int fin); +void scheme_set_output_port_string (SCHEME_P_ char *start, char *past_the_end); +SCHEME_EXPORT void scheme_load_file (SCHEME_P_ int fin); +SCHEME_EXPORT void scheme_load_named_file (SCHEME_P_ int fin, const char *filename); +SCHEME_EXPORT void scheme_load_string (SCHEME_P_ const char *cmd); +SCHEME_EXPORT pointer scheme_apply0 (SCHEME_P_ const char *procname); +SCHEME_EXPORT pointer scheme_call (SCHEME_P_ pointer func, pointer args); +SCHEME_EXPORT pointer scheme_eval (SCHEME_P_ pointer obj); +void scheme_set_external_data (SCHEME_P_ void *p); +SCHEME_EXPORT void scheme_define (SCHEME_P_ pointer env, pointer symbol, pointer value); + +typedef pointer (*foreign_func) (SCHEME_P_ pointer); + +pointer xcons (SCHEME_P_ pointer a, pointer b, int immutable); +INTERFACE pointer mk_integer (SCHEME_P_ IVALUE n); +INTERFACE pointer mk_real (SCHEME_P_ RVALUE n); +INTERFACE pointer mk_symbol (SCHEME_P_ const char *name); +INTERFACE pointer gensym (SCHEME_P); +INTERFACE pointer mk_string (SCHEME_P_ const char *str); +INTERFACE pointer mk_counted_string (SCHEME_P_ const char *str, uint32_t len); +INTERFACE pointer mk_empty_string (SCHEME_P_ uint32_t len, char fill); +INTERFACE pointer mk_character (SCHEME_P_ int c); +INTERFACE pointer mk_foreign_func (SCHEME_P_ foreign_func f); +INTERFACE void putstr (SCHEME_P_ const char *s); +INTERFACE int list_length (SCHEME_P_ pointer a); +INTERFACE int eqv (pointer a, pointer b); #if !STANDALONE - typedef struct scheme_registerable - { - foreign_func f; - const char *name; - } - scheme_registerable; - - void scheme_register_foreign_func_list (SCHEME_P_ scheme_registerable * list, int n); +typedef struct scheme_registerable +{ + foreign_func f; + const char *name; +} scheme_registerable; +void scheme_register_foreign_func_list (SCHEME_P_ scheme_registerable * list, int n); #endif /* !STANDALONE */ #ifdef __cplusplus