mirror of
https://github.com/ashinn/chibi-scheme.git
synced 2025-05-19 13:49:17 +02:00
Chibi uses a lot of #if conditioned code so that configuration management can be done entirely with the C preprocessor. Originally this also involved conditional includes of .c files from other source files. The alterative, which this change switches to, is to compile and link all files, and for uneeded files conditionally eliminate their entire bodies so they compile to empty object files. Pros for conditionally including all code into one large file: * Don't need to declare most functions (keeps .h files small). * Can keep most functions static/inlined (keeps objects small). * Don't need to even distribute uneeded files with the default Makefile (e.g. can prune opt/* from dist for minimal builds). Pros for linking multiple possibly empty files: * Extensions and third-party libs probably want the exported declarations anyway. * Static analysis tools work better (e.g. flymake on what previously was an included file). * Can build each file in parallel (i.e. make -j for faster builds). * Can build and link in just the changed files, instead of having to recompile the whole thing. For Chibi these are all minor points - it will be small regardless, and will build fast regardless - but the arguments for splitting seem stronger. Note the new shared lib is about 1k larger, but that can be trimmed down later.
216 lines
12 KiB
C
216 lines
12 KiB
C
/* eval.h -- headers for eval library */
|
|
/* Copyright (c) 2009-2011 Alex Shinn. All rights reserved. */
|
|
/* BSD-style license: http://synthcode.com/license.txt */
|
|
|
|
#ifndef SEXP_EVAL_H
|
|
#define SEXP_EVAL_H
|
|
|
|
#ifdef __cplusplus
|
|
extern "C" {
|
|
#endif
|
|
|
|
#include "chibi/sexp.h"
|
|
|
|
/************************* additional types ***************************/
|
|
|
|
#define sexp_init_file "init-"
|
|
#define sexp_init_file_suffix ".scm"
|
|
#define sexp_meta_file "meta.scm"
|
|
#define sexp_leap_seconds_file "leap.txt"
|
|
|
|
enum sexp_core_form_names {
|
|
SEXP_CORE_DEFINE = 1,
|
|
SEXP_CORE_SET,
|
|
SEXP_CORE_LAMBDA,
|
|
SEXP_CORE_IF,
|
|
SEXP_CORE_BEGIN,
|
|
SEXP_CORE_QUOTE,
|
|
SEXP_CORE_SYNTAX_QUOTE,
|
|
SEXP_CORE_DEFINE_SYNTAX,
|
|
SEXP_CORE_LET_SYNTAX,
|
|
SEXP_CORE_LETREC_SYNTAX
|
|
};
|
|
|
|
enum sexp_opcode_classes {
|
|
SEXP_OPC_GENERIC = 1,
|
|
SEXP_OPC_TYPE_PREDICATE,
|
|
SEXP_OPC_PREDICATE,
|
|
SEXP_OPC_ARITHMETIC,
|
|
SEXP_OPC_ARITHMETIC_CMP,
|
|
SEXP_OPC_IO,
|
|
SEXP_OPC_CONSTRUCTOR,
|
|
SEXP_OPC_GETTER,
|
|
SEXP_OPC_SETTER,
|
|
SEXP_OPC_PARAMETER,
|
|
SEXP_OPC_FOREIGN,
|
|
SEXP_OPC_NUM_OP_CLASSES
|
|
};
|
|
|
|
SEXP_API struct sexp_opcode_struct* sexp_primitive_opcodes;
|
|
|
|
/**************************** prototypes ******************************/
|
|
|
|
SEXP_API void sexp_scheme_init (void);
|
|
SEXP_API sexp sexp_make_eval_context (sexp context, sexp stack, sexp env, sexp_uint_t size, sexp_uint_t max_size);
|
|
SEXP_API sexp sexp_make_child_context (sexp context, sexp lambda);
|
|
SEXP_API sexp sexp_compile_error (sexp ctx, const char *message, sexp obj);
|
|
SEXP_API sexp sexp_analyze (sexp context, sexp x);
|
|
SEXP_API sexp sexp_simplify (sexp ctx, sexp self, sexp_sint_t n, sexp ast);
|
|
SEXP_API sexp sexp_make_lambda (sexp ctx, sexp params);
|
|
SEXP_API sexp sexp_make_ref (sexp ctx, sexp name, sexp cell);
|
|
SEXP_API void sexp_generate (sexp ctx, sexp name, sexp loc, sexp lam, sexp x);
|
|
SEXP_API void sexp_emit (sexp ctx, unsigned char c);
|
|
SEXP_API void sexp_emit_return (sexp ctx);
|
|
#if SEXP_USE_NATIVE_X86
|
|
SEXP_API void sexp_emit_enter (sexp ctx);
|
|
SEXP_API void sexp_bless_bytecode (sexp ctx, sexp bc);
|
|
#else
|
|
#define sexp_emit_enter(ctx)
|
|
#define sexp_bless_bytecode(ctx, bc)
|
|
#endif
|
|
SEXP_API sexp sexp_complete_bytecode (sexp ctx);
|
|
SEXP_API void sexp_shrink_bcode (sexp ctx, sexp_uint_t i);
|
|
SEXP_API void sexp_expand_bcode (sexp ctx, sexp_uint_t size);
|
|
SEXP_API void sexp_stack_trace (sexp ctx, sexp out);
|
|
SEXP_API sexp sexp_free_vars (sexp context, sexp x, sexp fv);
|
|
SEXP_API int sexp_param_index (sexp lambda, sexp name);
|
|
SEXP_API sexp sexp_compile_op (sexp context, sexp self, sexp_sint_t n, sexp obj, sexp env);
|
|
SEXP_API sexp sexp_eval_op (sexp context, sexp self, sexp_sint_t n, sexp obj, sexp env);
|
|
SEXP_API sexp sexp_eval_string (sexp context, const char *str, sexp_sint_t len, sexp env);
|
|
SEXP_API sexp sexp_load_op (sexp context, sexp self, sexp_sint_t n, sexp expr, sexp env);
|
|
SEXP_API sexp sexp_exception_type_op (sexp ctx, sexp self, sexp_sint_t n, sexp exn);
|
|
SEXP_API sexp sexp_make_env_op (sexp context, sexp self, sexp_sint_t n);
|
|
SEXP_API sexp sexp_make_null_env_op (sexp context, sexp self, sexp_sint_t n, sexp version);
|
|
SEXP_API sexp sexp_make_primitive_env (sexp context, sexp version);
|
|
SEXP_API sexp sexp_make_standard_env_op (sexp context, sexp self, sexp_sint_t n, sexp version);
|
|
SEXP_API void sexp_set_parameter (sexp ctx, sexp env, sexp name, sexp value);
|
|
SEXP_API sexp sexp_load_standard_ports (sexp context, sexp env, FILE* in, FILE* out, FILE* err, int no_close);
|
|
SEXP_API sexp sexp_load_standard_env (sexp context, sexp env, sexp version);
|
|
SEXP_API sexp sexp_find_module_file (sexp ctx, const char *file);
|
|
SEXP_API sexp sexp_load_module_file (sexp ctx, const char *file, sexp env);
|
|
SEXP_API sexp sexp_find_module_file_op (sexp ctx, sexp self, sexp_sint_t n, sexp file);
|
|
SEXP_API sexp sexp_load_module_file_op (sexp ctx, sexp self, sexp_sint_t n, sexp file, sexp env);
|
|
SEXP_API sexp sexp_add_module_directory_op (sexp ctx, sexp self, sexp_sint_t n, sexp dir, sexp appendp);
|
|
SEXP_API sexp sexp_current_environment (sexp ctx, sexp self, sexp_sint_t n);
|
|
SEXP_API sexp sexp_meta_environment (sexp ctx, sexp self, sexp_sint_t n);
|
|
SEXP_API sexp sexp_extend_env (sexp ctx, sexp env, sexp vars, sexp value);
|
|
SEXP_API sexp sexp_env_import_op (sexp ctx, sexp self, sexp_sint_t n, sexp to, sexp from, sexp ls, sexp immutp);
|
|
SEXP_API sexp sexp_env_exports_op (sexp ctx, sexp self, sexp_sint_t n, sexp env);
|
|
SEXP_API sexp sexp_identifierp_op(sexp ctx, sexp self, sexp_sint_t n, sexp x);
|
|
SEXP_API sexp sexp_identifier_eq_op(sexp ctx, sexp self, sexp_sint_t n, sexp a, sexp b, sexp c, sexp d);
|
|
SEXP_API sexp sexp_make_synclo_op(sexp ctx, sexp self, sexp_sint_t n, sexp env, sexp fv, sexp expr);
|
|
SEXP_API sexp sexp_strip_synclos(sexp ctx, sexp self, sexp_sint_t n, sexp x);
|
|
SEXP_API sexp sexp_syntactic_closure_expr_op(sexp ctx, sexp self, sexp_sint_t n, sexp x);
|
|
SEXP_API sexp sexp_open_input_file_op(sexp ctx, sexp self, sexp_sint_t n, sexp x);
|
|
SEXP_API sexp sexp_open_output_file_op(sexp ctx, sexp self, sexp_sint_t n, sexp x);
|
|
SEXP_API sexp sexp_open_binary_input_file(sexp ctx, sexp self, sexp_sint_t n, sexp x);
|
|
SEXP_API sexp sexp_open_binary_output_file(sexp ctx, sexp self, sexp_sint_t n, sexp x);
|
|
SEXP_API sexp sexp_close_port_op(sexp ctx, sexp self, sexp_sint_t n, sexp x);
|
|
SEXP_API sexp sexp_env_define (sexp ctx, sexp env, sexp sym, sexp val);
|
|
SEXP_API sexp sexp_env_cell (sexp env, sexp sym, int localp);
|
|
SEXP_API sexp sexp_env_ref (sexp env, sexp sym, sexp dflt);
|
|
SEXP_API sexp sexp_parameter_ref (sexp ctx, sexp param);
|
|
SEXP_API sexp sexp_warn_undefs_op (sexp ctx, sexp self, sexp_sint_t n, sexp from, sexp to, sexp res);
|
|
SEXP_API sexp sexp_make_lit (sexp ctx, sexp value);
|
|
SEXP_API sexp sexp_make_opcode (sexp, sexp, sexp, sexp, sexp, sexp, sexp, sexp, sexp, sexp, sexp, sexp, sexp_proc1);
|
|
SEXP_API sexp sexp_make_procedure_op (sexp ctx, sexp self, sexp_sint_t n, sexp flags, sexp num_args, sexp bc, sexp vars);
|
|
SEXP_API sexp sexp_define_foreign_aux (sexp ctx, sexp env, const char *name, int num_args, int flags, sexp_proc1 f, sexp data);
|
|
SEXP_API sexp sexp_register_optimization(sexp ctx, sexp self, sexp_sint_t n, sexp f, sexp i);
|
|
#if SEXP_USE_UTF8_STRINGS
|
|
SEXP_API sexp sexp_read_utf8_char (sexp ctx, sexp port, int i);
|
|
SEXP_API void sexp_string_utf8_set (sexp ctx, sexp str, sexp index, sexp ch);
|
|
SEXP_API sexp sexp_string_utf8_index_ref (sexp ctx, sexp self, sexp_sint_t n, sexp str, sexp i);
|
|
SEXP_API sexp sexp_string_utf8_index_set (sexp ctx, sexp self, sexp_sint_t n, sexp str, sexp i, sexp ch);
|
|
#endif
|
|
#if SEXP_USE_GREEN_THREADS
|
|
SEXP_API sexp sexp_dk (sexp ctx, sexp self, sexp_sint_t n, sexp val);
|
|
SEXP_API sexp sexp_thread_parameters (sexp ctx, sexp self, sexp_sint_t n);
|
|
SEXP_API sexp sexp_thread_parameters_set (sexp ctx, sexp self, sexp_sint_t n, sexp val);
|
|
#endif
|
|
SEXP_API sexp sexp_string_cmp_op (sexp ctx, sexp self, sexp_sint_t n, sexp a, sexp b, sexp ci);
|
|
#if SEXP_USE_RATIOS
|
|
SEXP_API sexp sexp_ratio_numerator_op (sexp ctx, sexp self, sexp_sint_t n, sexp rat);
|
|
SEXP_API sexp sexp_ratio_denominator_op (sexp ctx, sexp self, sexp_sint_t n, sexp rat);
|
|
#endif
|
|
#if SEXP_USE_COMPLEX
|
|
SEXP_API sexp sexp_complex_real_op (sexp ctx, sexp self, sexp_sint_t n, sexp rat);
|
|
SEXP_API sexp sexp_complex_imag_op (sexp ctx, sexp self, sexp_sint_t n, sexp rat);
|
|
#endif
|
|
|
|
#if SEXP_USE_MATH
|
|
SEXP_API sexp sexp_exp(sexp ctx, sexp self, sexp_sint_t n, sexp z);
|
|
SEXP_API sexp sexp_log(sexp ctx, sexp self, sexp_sint_t n, sexp z);
|
|
SEXP_API sexp sexp_sin(sexp ctx, sexp self, sexp_sint_t n, sexp z);
|
|
SEXP_API sexp sexp_cos(sexp ctx, sexp self, sexp_sint_t n, sexp z);
|
|
SEXP_API sexp sexp_tan(sexp ctx, sexp self, sexp_sint_t n, sexp z);
|
|
SEXP_API sexp sexp_asin(sexp ctx, sexp self, sexp_sint_t n, sexp z);
|
|
SEXP_API sexp sexp_acos(sexp ctx, sexp self, sexp_sint_t n, sexp z);
|
|
SEXP_API sexp sexp_atan(sexp ctx, sexp self, sexp_sint_t n, sexp z);
|
|
SEXP_API sexp sexp_sqrt(sexp ctx, sexp self, sexp_sint_t n, sexp z);
|
|
SEXP_API sexp sexp_round(sexp ctx, sexp self, sexp_sint_t n, sexp x);
|
|
SEXP_API sexp sexp_trunc(sexp ctx, sexp self, sexp_sint_t n, sexp x);
|
|
SEXP_API sexp sexp_floor(sexp ctx, sexp self, sexp_sint_t n, sexp x);
|
|
SEXP_API sexp sexp_ceiling(sexp ctx, sexp self, sexp_sint_t n, sexp x);
|
|
#endif
|
|
SEXP_API sexp sexp_expt_op(sexp ctx, sexp self, sexp_sint_t n, sexp z1, sexp z2);
|
|
|
|
#if SEXP_USE_NATIVE_X86
|
|
SEXP_API sexp sexp_write_char_op(sexp ctx, sexp self, sexp_sint_t n, sexp ch, sexp out);
|
|
SEXP_API sexp sexp_newline_op(sexp ctx, sexp self, sexp_sint_t n, sexp out);
|
|
SEXP_API sexp sexp_read_char_op(sexp ctx, sexp self, sexp_sint_t n, sexp in);
|
|
SEXP_API sexp sexp_peek_char_op(sexp ctx, sexp self, sexp_sint_t n, sexp in);
|
|
SEXP_API sexp sexp_exact_to_inexact(sexp ctx, sexp self, sexp_sint_t n, sexp i);
|
|
SEXP_API sexp sexp_inexact_to_exact(sexp ctx, sexp self, sexp_sint_t n, sexp x);
|
|
SEXP_API sexp sexp_char_upcase(sexp ctx, sexp self, sexp_sint_t n, sexp ch);
|
|
SEXP_API sexp sexp_char_downcase(sexp ctx, sexp self, sexp_sint_t n, sexp ch);
|
|
#endif
|
|
|
|
#define sexp_define_foreign(c,e,s,n,f) sexp_define_foreign_aux(c,e,s,n,0,(sexp_proc1)f,NULL)
|
|
#define sexp_define_foreign_opt(c,e,s,n,f,d) sexp_define_foreign_aux(c,e,s,n,1,(sexp_proc1)f,d)
|
|
|
|
SEXP_API sexp sexp_define_foreign_param (sexp ctx, sexp env, const char *name, int num_args, sexp_proc1 f, const char *param);
|
|
|
|
#define sexp_env_key(x) sexp_car(x)
|
|
#define sexp_env_value(x) sexp_cdr(x)
|
|
#define sexp_env_next_cell(x) sexp_pair_source(x)
|
|
#define sexp_env_push(ctx, env, tmp, name, value) (tmp=sexp_cons(ctx,name,value), sexp_env_next_cell(tmp)=sexp_env_bindings(env), sexp_env_bindings(env)=tmp)
|
|
#define sexp_env_push_rename(ctx, env, tmp, name, value) (tmp=sexp_cons(ctx,name,value), sexp_env_next_cell(tmp)=sexp_env_renames(env), sexp_env_renames(env)=tmp)
|
|
|
|
#if SEXP_USE_TYPE_DEFS
|
|
SEXP_API sexp sexp_make_type_predicate_op (sexp ctx, sexp self, sexp_sint_t n, sexp name, sexp type);
|
|
SEXP_API sexp sexp_make_constructor_op (sexp ctx, sexp self, sexp_sint_t n, sexp name, sexp type);
|
|
SEXP_API sexp sexp_make_getter_op (sexp ctx, sexp self, sexp_sint_t n, sexp name, sexp type, sexp index);
|
|
SEXP_API sexp sexp_make_setter_op (sexp ctx, sexp self, sexp_sint_t n, sexp name, sexp type, sexp index);
|
|
SEXP_API sexp sexp_type_slot_offset_op (sexp ctx, sexp self, sexp_sint_t n, sexp type, sexp index);
|
|
#endif
|
|
|
|
#if SEXP_USE_SIMPLIFY
|
|
SEXP_API int sexp_rest_unused_p (sexp lambda);
|
|
#else
|
|
#define sexp_rest_unused_p(lambda) 0
|
|
#endif
|
|
|
|
/* simplify primitive API interface */
|
|
#define sexp_make_synclo(ctx, a, b, c) sexp_make_synclo_op(ctx, NULL, 3, a, b, c)
|
|
#define sexp_make_procedure(ctx, f, n, b, v) sexp_make_procedure_op(ctx, NULL, 4, f, n, b, v)
|
|
#define sexp_make_env(ctx) sexp_make_env_op(ctx, NULL, 0)
|
|
#define sexp_make_null_env(ctx, v) sexp_make_null_env_op(ctx, NULL, 0, v)
|
|
#define sexp_make_standard_env(ctx) sexp_make_standard_env_op(ctx, NULL, 0)
|
|
#define sexp_add_module_directory(ctx, d, a) sexp_add_module_directory_op(ctx, NULL, 1, d, a)
|
|
#define sexp_eval(ctx, x, e) sexp_eval_op(ctx, NULL, 2, x, e)
|
|
#define sexp_load(ctx, f, e) sexp_load_op(ctx, NULL, 2, f, e)
|
|
#define sexp_env_import(ctx, a, b, c, d) sexp_env_import_op(ctx, NULL, 4, a, b, c, d)
|
|
#define sexp_identifierp(ctx, x) sexp_identifierp_op(ctx, NULL, 1, x)
|
|
#define sexp_identifier_to_symbol(ctx, x) sexp_syntactic_closure_expr_op(ctx, NULL, 1, x)
|
|
#define sexp_identifier_eq(ctx, a, b, c, d) sexp_identifier_eq_op(ctx, NULL, 4, a, b, c, d)
|
|
#define sexp_open_input_file(ctx, x) sexp_open_input_file_op(ctx, NULL, 1, x)
|
|
#define sexp_open_output_file(ctx, x) sexp_open_output_file_op(ctx, NULL, 1, x)
|
|
#define sexp_close_port(ctx, x) sexp_close_port_op(ctx, NULL, 1, x)
|
|
#define sexp_warn_undefs(ctx, from, to, res) sexp_warn_undefs_op(ctx, NULL, 3, from, to, res)
|
|
#define sexp_string_cmp(ctx, a, b, c) sexp_string_cmp_op(ctx, NULL, 3, a, b, c)
|
|
|
|
#ifdef __cplusplus
|
|
} /* extern "C" */
|
|
#endif
|
|
|
|
#endif /* ! SEXP_EVAL_H */
|