2013-10-09 03:58:35 -04:00
|
|
|
#include <stdio.h>
|
|
|
|
|
2013-10-10 03:15:41 -04:00
|
|
|
#include "picrin.h"
|
|
|
|
|
2013-10-10 04:48:37 -04:00
|
|
|
void
|
|
|
|
test_object_creation(pic_state *pic)
|
|
|
|
{
|
|
|
|
pic_value v;
|
|
|
|
|
|
|
|
{
|
|
|
|
v = pic_intern_cstr(pic, "symbol");
|
|
|
|
pic_debug(pic, v);
|
|
|
|
puts(" [should be `symbol`]");
|
|
|
|
}
|
|
|
|
{
|
|
|
|
v = pic_nil_value();
|
|
|
|
pic_debug(pic, v);
|
|
|
|
puts(" [should be `()`]");
|
|
|
|
}
|
|
|
|
{
|
|
|
|
v = pic_cons(pic, pic_intern_cstr(pic, "foo"), pic_intern_cstr(pic, "bar"));
|
|
|
|
pic_debug(pic, v);
|
|
|
|
puts(" [should be `(foo . bar)`]");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2013-10-09 04:14:48 -04:00
|
|
|
#define LINE_MAX_LENGTH 256
|
|
|
|
|
2013-10-09 03:58:35 -04:00
|
|
|
int
|
|
|
|
main()
|
|
|
|
{
|
2013-10-10 03:15:41 -04:00
|
|
|
pic_state *pic;
|
2013-10-09 04:14:48 -04:00
|
|
|
char line[LINE_MAX_LENGTH], last_char;
|
2013-10-09 04:10:32 -04:00
|
|
|
int char_index;
|
2013-10-11 02:20:53 -04:00
|
|
|
pic_value v;
|
2013-10-11 23:55:05 -04:00
|
|
|
struct pic_proc *proc;
|
2013-10-09 04:10:32 -04:00
|
|
|
|
2013-10-10 03:15:41 -04:00
|
|
|
pic = pic_open();
|
|
|
|
|
2013-10-12 00:06:02 -04:00
|
|
|
//test_object_creation(pic);
|
2013-10-10 04:48:37 -04:00
|
|
|
|
2013-10-09 04:10:32 -04:00
|
|
|
while (1) {
|
|
|
|
printf("> ");
|
|
|
|
|
|
|
|
char_index = 0;
|
|
|
|
while ((last_char = getchar()) != '\n') {
|
|
|
|
if (last_char == EOF)
|
|
|
|
goto eof;
|
2013-10-09 04:14:48 -04:00
|
|
|
if (char_index == LINE_MAX_LENGTH)
|
|
|
|
goto overflow;
|
2013-10-09 04:10:32 -04:00
|
|
|
line[char_index++] = last_char;
|
|
|
|
}
|
|
|
|
line[char_index] = '\0';
|
|
|
|
|
2013-10-12 00:06:02 -04:00
|
|
|
/* read */
|
2013-10-11 02:20:53 -04:00
|
|
|
v = pic_parse(pic, line);
|
2013-10-09 04:10:32 -04:00
|
|
|
|
2013-10-12 00:06:02 -04:00
|
|
|
/* eval */
|
2013-10-11 23:55:05 -04:00
|
|
|
proc = pic_codegen(pic, v, pic->global_env);
|
|
|
|
v = pic_run(pic, proc, pic_nil_value());
|
2013-10-12 00:06:02 -04:00
|
|
|
|
|
|
|
/* print */
|
2013-10-11 23:55:05 -04:00
|
|
|
pic_debug(pic, v);
|
2013-10-12 00:06:02 -04:00
|
|
|
|
2013-10-09 04:10:32 -04:00
|
|
|
printf("\n");
|
|
|
|
}
|
|
|
|
|
|
|
|
eof:
|
|
|
|
puts("");
|
2013-10-09 04:14:48 -04:00
|
|
|
goto exit;
|
|
|
|
|
|
|
|
overflow:
|
|
|
|
puts("** [fatal] line input overflow");
|
|
|
|
goto exit;
|
2013-10-09 04:10:32 -04:00
|
|
|
|
2013-10-09 04:14:48 -04:00
|
|
|
exit:
|
2013-10-10 03:15:41 -04:00
|
|
|
pic_close(pic);
|
|
|
|
|
2013-10-09 03:58:35 -04:00
|
|
|
return 0;
|
|
|
|
}
|