Back to index

plt-scheme  4.2.1
embed-in-c.c
Go to the documentation of this file.
00001 #include "scheme.h"
00002 
00003 static int run(Scheme_Env *e, int argc, char *argv[])
00004 {
00005   Scheme_Object *curout = NULL, *v = NULL, *a[2] = {NULL, NULL};
00006   Scheme_Config *config = NULL;
00007   int i;
00008   mz_jmp_buf * volatile save = NULL, fresh;
00009   
00010   MZ_GC_DECL_REG(8);
00011   MZ_GC_VAR_IN_REG(0, e);
00012   MZ_GC_VAR_IN_REG(1, curout);
00013   MZ_GC_VAR_IN_REG(2, save);
00014   MZ_GC_VAR_IN_REG(3, config);
00015   MZ_GC_VAR_IN_REG(4, v);
00016   MZ_GC_ARRAY_VAR_IN_REG(5, a, 2);
00017   
00018   MZ_GC_REG();
00019 
00020   scheme_set_collects_path(scheme_make_path(MZ_COLLECTION_PATH));
00021   scheme_init_collection_paths(e, scheme_null);
00022 
00023   v = scheme_intern_symbol("scheme/base");
00024   scheme_namespace_require(v);
00025   
00026   config = scheme_current_config();
00027   curout = scheme_get_param(config, MZCONFIG_OUTPUT_PORT);
00028   
00029   for (i = 1; i < argc; i++) {
00030     save = scheme_current_thread->error_buf;
00031     scheme_current_thread->error_buf = &fresh;
00032     if (scheme_setjmp(scheme_error_buf)) {
00033       scheme_current_thread->error_buf = save;
00034       return -1; /* There was an error */
00035     } else {
00036       v = scheme_eval_string(argv[i], e);
00037       scheme_display(v, curout);
00038       v = scheme_make_char('\n');
00039       scheme_display(v, curout);
00040     }
00041   }
00042 
00043   /* RESET: */
00044   e = scheme_basic_env();
00045   scheme_init_collection_paths(e, scheme_null);
00046   v = scheme_intern_symbol("scheme/base");
00047   scheme_namespace_require(v);
00048 
00049   /* read-eval-print loop, uses initial Scheme_Env: */
00050   a[0] = scheme_intern_symbol("scheme/base");
00051   a[1] = scheme_intern_symbol("read-eval-print-loop");
00052   v = scheme_dynamic_require(2, a);
00053   scheme_apply(v, 0, NULL);
00054   scheme_current_thread->error_buf = save;
00055   
00056   MZ_GC_UNREG();
00057   
00058   return 0;
00059 }
00060   
00061 int main(int argc, char *argv[])
00062 {
00063   return scheme_main_setup(1, run, argc, argv);
00064 }