mirror of
https://github.com/ashinn/chibi-scheme.git
synced 2025-07-08 05:27:35 +02:00
adding i/o port primitives
This commit is contained in:
parent
13a161e797
commit
865e7667f4
1 changed files with 19 additions and 0 deletions
19
eval.c
19
eval.c
|
@ -1073,6 +1073,21 @@ sexp vm(bytecode bc, env e, sexp* stack, unsigned int top) {
|
||||||
return stack[top-1];
|
return stack[top-1];
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/************************ library procedures **************************/
|
||||||
|
|
||||||
|
sexp sexp_open_input_file (sexp path) {
|
||||||
|
return sexp_make_input_port(fopen(sexp_string_data(path), "r"));
|
||||||
|
}
|
||||||
|
|
||||||
|
sexp sexp_open_output_file (sexp path) {
|
||||||
|
return sexp_make_input_port(fopen(sexp_string_data(path), "w"));
|
||||||
|
}
|
||||||
|
|
||||||
|
sexp sexp_close_port (sexp port) {
|
||||||
|
fclose(sexp_port_stream(port));
|
||||||
|
return SEXP_UNDEF;
|
||||||
|
}
|
||||||
|
|
||||||
/*********************** standard environment *************************/
|
/*********************** standard environment *************************/
|
||||||
|
|
||||||
static const struct core_form core_forms[] = {
|
static const struct core_form core_forms[] = {
|
||||||
|
@ -1138,6 +1153,10 @@ _OP(OPC_GENERIC, OP_ERROR, 1, SEXP_STRING, 0, 0, 0, "error"),
|
||||||
{SEXP_OPCODE, OPC_IO, OP_READ_CHAR, 0, 1, 0, SEXP_IPORT, 0, "read-char", (sexp)&cur_input_port, NULL},
|
{SEXP_OPCODE, OPC_IO, OP_READ_CHAR, 0, 1, 0, SEXP_IPORT, 0, "read-char", (sexp)&cur_input_port, NULL},
|
||||||
_FN1(SEXP_PAIR, "reverse", sexp_reverse),
|
_FN1(SEXP_PAIR, "reverse", sexp_reverse),
|
||||||
_FN1(SEXP_PAIR, "list->vector", sexp_list_to_vector),
|
_FN1(SEXP_PAIR, "list->vector", sexp_list_to_vector),
|
||||||
|
_FN1(SEXP_STRING, "open-input-file", sexp_open_input_file),
|
||||||
|
_FN1(SEXP_STRING, "open-output-file", sexp_open_output_file),
|
||||||
|
_FN1(SEXP_IPORT, "close-input-port", sexp_close_port),
|
||||||
|
_FN1(SEXP_OPORT, "close-output-port", sexp_close_port),
|
||||||
_FN2(0, SEXP_PAIR, "memq", sexp_memq),
|
_FN2(0, SEXP_PAIR, "memq", sexp_memq),
|
||||||
_FN2(0, SEXP_PAIR, "assq", sexp_assq),
|
_FN2(0, SEXP_PAIR, "assq", sexp_assq),
|
||||||
_FN2(SEXP_PAIR, SEXP_PAIR, "diffq", sexp_lset_diff),
|
_FN2(SEXP_PAIR, SEXP_PAIR, "diffq", sexp_lset_diff),
|
||||||
|
|
Loading…
Add table
Reference in a new issue