2014-09-08 05:47:20 -04:00
|
|
|
/**
|
|
|
|
* See Copyright Notice in picrin.h
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include "picrin.h"
|
2016-02-20 10:58:58 -05:00
|
|
|
#include "picrin/extra.h"
|
2017-04-03 11:52:59 -04:00
|
|
|
#include "../object.h"
|
|
|
|
|
|
|
|
pic_value
|
2017-04-14 10:40:07 -04:00
|
|
|
pic_load(pic_state *pic, pic_value expr)
|
2017-04-03 11:52:59 -04:00
|
|
|
{
|
2017-04-22 20:16:40 -04:00
|
|
|
return pic_execute(pic, pic_assemble(pic, expr));
|
2014-09-08 05:50:15 -04:00
|
|
|
}
|
2014-09-08 05:47:20 -04:00
|
|
|
|
2014-09-08 05:50:15 -04:00
|
|
|
void
|
2017-04-03 11:52:59 -04:00
|
|
|
pic_load_native(pic_state *pic, const char *str)
|
2014-09-08 05:50:15 -04:00
|
|
|
{
|
2016-06-19 15:49:01 -04:00
|
|
|
pic_value e, port = pic_fmemopen(pic, str, strlen(str), "r");
|
2014-09-08 05:47:20 -04:00
|
|
|
|
2015-06-26 10:45:56 -04:00
|
|
|
pic_try {
|
2017-04-03 11:52:59 -04:00
|
|
|
size_t ai = pic_enter(pic);
|
2017-04-14 12:00:18 -04:00
|
|
|
pic_load(pic, pic_funcall(pic, "read", 1, port));
|
|
|
|
pic_leave(pic, ai);
|
2015-06-26 10:45:56 -04:00
|
|
|
}
|
2016-02-25 06:52:38 -05:00
|
|
|
pic_catch(e) {
|
2016-06-19 15:49:01 -04:00
|
|
|
pic_fclose(pic, port);
|
2016-02-25 06:52:38 -05:00
|
|
|
pic_raise(pic, e);
|
2015-06-26 10:45:56 -04:00
|
|
|
}
|
2016-06-19 15:49:01 -04:00
|
|
|
pic_fclose(pic, port);
|
2014-09-08 05:47:20 -04:00
|
|
|
}
|
2017-04-03 11:52:59 -04:00
|
|
|
|
|
|
|
static pic_value
|
|
|
|
pic_load_load(pic_state *pic)
|
|
|
|
{
|
|
|
|
pic_value program;
|
|
|
|
|
|
|
|
pic_get_args(pic, "o", &program);
|
|
|
|
|
|
|
|
return pic_load(pic, program);
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
pic_init_load(pic_state *pic)
|
|
|
|
{
|
|
|
|
pic_defun(pic, "load", pic_load_load);
|
|
|
|
}
|