mirror of
https://github.com/ashinn/chibi-scheme.git
synced 2025-07-03 19:26:36 +02:00
adding sexp_read_from_string and -e, -p command-line options
This commit is contained in:
parent
598e71c950
commit
fde01c5700
3 changed files with 18 additions and 0 deletions
8
eval.c
8
eval.c
|
@ -778,7 +778,15 @@ int main (int argc, char **argv) {
|
||||||
for (i=1; i < argc && argv[i][0] == '-'; i++) {
|
for (i=1; i < argc && argv[i][0] == '-'; i++) {
|
||||||
switch (argv[i][1]) {
|
switch (argv[i][1]) {
|
||||||
case 'e':
|
case 'e':
|
||||||
|
case 'p':
|
||||||
|
obj = sexp_read_from_string(argv[i+1]);
|
||||||
|
res = eval_in_stack(obj, e, stack, 0);
|
||||||
|
if (argv[i][1] == 'p') {
|
||||||
|
sexp_write(res, cur_output_port);
|
||||||
|
sexp_write_char('\n', cur_output_port);
|
||||||
|
}
|
||||||
quit=1;
|
quit=1;
|
||||||
|
i++;
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
errx(1, "unknown option: %s", argv[i]);
|
errx(1, "unknown option: %s", argv[i]);
|
||||||
|
|
9
sexp.c
9
sexp.c
|
@ -753,6 +753,15 @@ sexp sexp_read (sexp in) {
|
||||||
return res;
|
return res;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
sexp sexp_read_from_string(char *str) {
|
||||||
|
sexp s = sexp_make_string(str);
|
||||||
|
sexp in = sexp_make_input_string_port(s);
|
||||||
|
sexp res = sexp_read(in);
|
||||||
|
sexp_free(s);
|
||||||
|
sexp_free(in);
|
||||||
|
return res;
|
||||||
|
}
|
||||||
|
|
||||||
void sexp_init() {
|
void sexp_init() {
|
||||||
if (! sexp_initialized_p) {
|
if (! sexp_initialized_p) {
|
||||||
sexp_initialized_p = 1;
|
sexp_initialized_p = 1;
|
||||||
|
|
1
sexp.h
1
sexp.h
|
@ -232,6 +232,7 @@ char* sexp_read_symbol(sexp in, int init);
|
||||||
sexp sexp_read_number(sexp in, int base);
|
sexp sexp_read_number(sexp in, int base);
|
||||||
sexp sexp_read_raw(sexp in);
|
sexp sexp_read_raw(sexp in);
|
||||||
sexp sexp_read(sexp in);
|
sexp sexp_read(sexp in);
|
||||||
|
sexp sexp_read_from_string(char *str);
|
||||||
sexp sexp_make_input_port(FILE* in);
|
sexp sexp_make_input_port(FILE* in);
|
||||||
sexp sexp_make_output_port(FILE* out);
|
sexp sexp_make_output_port(FILE* out);
|
||||||
sexp sexp_make_input_string_port(sexp str);
|
sexp sexp_make_input_string_port(sexp str);
|
||||||
|
|
Loading…
Add table
Reference in a new issue