picrin/src/main.c

71 lines
1.1 KiB
C
Raw Normal View History

2014-01-17 06:58:31 -05:00
/**
* See Copyright Notice in picrin.h
*/
2013-10-10 03:15:41 -04:00
#include "picrin.h"
2014-09-08 11:09:31 -04:00
void pic_init_contrib(pic_state *);
void pic_load_piclib(pic_state *);
2014-09-08 07:20:08 -04:00
static pic_value
pic_libraries(pic_state *pic)
{
2015-01-22 05:28:31 -05:00
pic_value libs = pic_nil_value(), lib, it;
2014-09-08 07:20:08 -04:00
pic_get_args(pic, "");
2015-01-22 05:28:31 -05:00
pic_for_each (lib, pic->libs, it) {
2014-09-08 07:20:08 -04:00
libs = pic_cons(pic, pic_car(pic, lib), libs);
}
return libs;
}
void
pic_init_picrin(pic_state *pic)
{
pic_add_feature(pic, "r7rs");
pic_deflibrary(pic, "(picrin library)");
pic_defun(pic, "libraries", pic_libraries);
2014-09-08 07:20:08 -04:00
pic_init_contrib(pic);
pic_load_piclib(pic);
2014-09-08 07:20:08 -04:00
}
2016-02-09 11:38:05 -05:00
int picrin_argc;
char **picrin_argv;
char **picrin_envp;
int
main(int argc, char *argv[], char **envp)
{
pic_state *pic;
2014-09-16 03:20:03 -04:00
struct pic_lib *PICRIN_MAIN;
2015-08-26 04:50:28 -04:00
int status;
2015-06-25 13:09:06 -04:00
pic = pic_open(pic_default_allocf, NULL);
2016-02-09 11:38:05 -05:00
picrin_argc = argc;
picrin_argv = argv;
picrin_envp = envp;
pic_try {
pic_init_picrin(pic);
2014-08-31 20:53:19 -04:00
PICRIN_MAIN = pic_find_library(pic, pic_read_cstr(pic, "(picrin main)"));
2014-09-16 03:20:03 -04:00
2016-02-14 10:51:22 -05:00
pic_funcall(pic, PICRIN_MAIN, "main", 0);
2015-08-26 04:50:28 -04:00
status = 0;
2014-01-08 01:38:47 -05:00
}
2014-07-27 22:43:52 -04:00
pic_catch {
2015-05-27 11:14:10 -04:00
pic_print_backtrace(pic, xstderr);
2014-07-29 02:43:59 -04:00
status = 1;
}
pic_close(pic);
2014-07-29 02:43:59 -04:00
return status;
}