mirror of
https://gitlab.com/embeddable-common-lisp/ecl.git
synced 2025-12-15 15:21:03 -08:00
[nucl] add Lali-ho I/O
This commit is contained in:
parent
bd65f0c4cc
commit
b07dc53b34
1 changed files with 69 additions and 5 deletions
74
src/c/nucl.c
74
src/c/nucl.c
|
|
@ -82,17 +82,81 @@ void smoke_bytecodes (void)
|
|||
|
||||
cl_object ecl_make_nucl_stream(FILE *f);
|
||||
|
||||
/* -- Lali-ho I/O starts here ----------------------------------------------- */
|
||||
cl_object
|
||||
nucl_alloc_base_string(cl_index s)
|
||||
{
|
||||
int i;
|
||||
cl_object x = ecl_alloc_compact_object(t_base_string, s+1);
|
||||
x->base_string.self = ECL_COMPACT_OBJECT_EXTRA(x);
|
||||
x->base_string.self[s] = '\0';
|
||||
x->base_string.elttype = ecl_aet_bc;
|
||||
x->base_string.flags = 0; /* no fill pointer, not adjustable */
|
||||
x->base_string.displaced = ECL_NIL;
|
||||
x->base_string.dim = x->base_string.fillp = s;
|
||||
return x;
|
||||
}
|
||||
|
||||
cl_object
|
||||
nucl_write(const char *s, cl_object strm)
|
||||
{
|
||||
while(*s != '\0')
|
||||
si_write_char(strm, ECL_CODE_CHAR(*s++));
|
||||
}
|
||||
|
||||
cl_object
|
||||
nucl_print(cl_object self, cl_object strm)
|
||||
{
|
||||
cl_type t = ecl_t_of(self);
|
||||
switch (t) {
|
||||
case t_base_string:
|
||||
nucl_write(self->base_string.self, strm);
|
||||
break;
|
||||
default:
|
||||
{
|
||||
const char *name = ecl_type_info[t].name;
|
||||
nucl_write("#<", strm);
|
||||
nucl_write(name, strm);
|
||||
nucl_write(">", strm);
|
||||
return ECL_NIL;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
cl_object
|
||||
nucl_readl(cl_object self, cl_object strm)
|
||||
{
|
||||
cl_object stack = ecl_make_stack(0), c=ECL_NIL;
|
||||
cl_index idx, size;
|
||||
while (!Null(c = si_read_char(strm, ECL_NIL))) {
|
||||
ecl_stack_push(stack, c);
|
||||
if(ECL_CHAR_CODE(c) == '\n') break;
|
||||
}
|
||||
size = stack->vector.fillp;
|
||||
if(Null(self)) {
|
||||
self = nucl_alloc_base_string(size);
|
||||
} else {
|
||||
self->base_string.self[size] = '\0';
|
||||
}
|
||||
for(idx=0; idx<size; idx++)
|
||||
self->base_string.self[idx] = ECL_CHAR_CODE(stack->vector.self.t[idx]);
|
||||
return self;
|
||||
}
|
||||
/* -- Lali-ho I/O ends here ------------------------------------------------- */
|
||||
|
||||
void
|
||||
smoke_stream (void)
|
||||
{
|
||||
cl_object ostrm = ecl_make_nucl_stream(stdout);
|
||||
char *string = "Hello World!\n", c;
|
||||
cl_object istrm = ecl_make_nucl_stream(stdin);
|
||||
cl_object line = ECL_NIL;
|
||||
char *string = "Hello World> ", c;
|
||||
int i;
|
||||
printf(">>> smoke_stream: stream is %p\n", ostrm);
|
||||
for (i = 0; i<13; i++) {
|
||||
c = string[i];
|
||||
si_write_char(ECL_CODE_CHAR(c), ostrm);
|
||||
}
|
||||
nucl_write(string, ostrm);
|
||||
line = nucl_readl(ECL_NIL, istrm);
|
||||
nucl_print(line, ostrm);
|
||||
ecl_dealloc(line);
|
||||
}
|
||||
|
||||
int main() {
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue