picrin/src/main.c

80 lines
1.4 KiB
C
Raw Normal View History

2014-01-17 06:58:31 -05:00
/**
* See Copyright Notice in picrin.h
*/
2014-09-15 03:42:57 -04:00
#define PIC_ARENA_SIZE (8 * 1024)
#define PIC_HEAP_PAGE_SIZE (2 * 1024 * 1024)
#define PIC_SYM_POOL_SIZE (2 * 1024)
2013-10-10 03:15:41 -04:00
#include "picrin.h"
2014-09-08 07:20:08 -04:00
#include "picrin/pair.h"
#include "picrin/error.h"
2013-10-10 03:15:41 -04:00
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_features(pic_state *pic)
{
pic_get_args(pic, "");
return pic->features;
2014-09-08 07:20:08 -04:00
}
static pic_value
pic_libraries(pic_state *pic)
{
pic_value libs = pic_nil_value(), lib;
pic_get_args(pic, "");
pic_for_each (lib, pic->libs) {
libs = pic_cons(pic, pic_car(pic, lib), libs);
}
return libs;
}
void
pic_init_picrin(pic_state *pic)
{
pic_add_feature(pic, "r7rs");
2014-09-08 07:20:08 -04:00
pic_deflibrary (pic, "(picrin library)") {
pic_defun(pic, "libraries", pic_libraries);
}
pic_deflibrary (pic, "(scheme base)") {
pic_defun(pic, "features", pic_features);
pic_init_contrib(pic);
pic_load_piclib(pic);
}
}
int
main(int argc, char *argv[], char **envp)
{
pic_state *pic;
2014-09-16 03:20:03 -04:00
struct pic_lib *PICRIN_MAIN;
2014-07-29 02:43:59 -04:00
int status = 0;
2014-09-08 11:09:31 -04:00
pic = pic_open(argc, argv, envp);
2014-08-31 20:53:19 -04:00
pic_init_picrin(pic);
2014-09-16 03:20:03 -04:00
PICRIN_MAIN = pic_find_library(pic, pic_read_cstr(pic, "(picrin main)"));
2014-07-27 22:43:52 -04:00
pic_try {
2014-09-16 03:20:03 -04:00
pic_funcall(pic, PICRIN_MAIN, "main", pic_nil_value());
2014-01-08 01:38:47 -05:00
}
2014-07-27 22:43:52 -04:00
pic_catch {
pic_print_backtrace(pic, pic->err);
2014-07-29 02:43:59 -04:00
status = 1;
}
pic_close(pic);
2014-07-29 02:43:59 -04:00
return status;
}