All unit tests passing! This is slightly a fix because there is a bug with
the character read after reading a number not being correctly pushed back onto the input stream, but...
This commit is contained in:
parent
6eab3a531a
commit
2d9f4b0439
10 changed files with 85 additions and 34 deletions
|
|
@ -121,11 +121,12 @@ struct cons_pointer make_string( char c, struct cons_pointer tail) {
|
|||
|
||||
if ( check_tag( tail, STRINGTAG) || check_tag( tail, NILTAG)) {
|
||||
pointer = allocate_cell( STRINGTAG);
|
||||
struct cons_space_object* cell = &conspages[pointer.page]->cell[pointer.offset];
|
||||
struct cons_space_object* cell = &pointer2cell(pointer);
|
||||
|
||||
inc_ref(tail);
|
||||
cell->payload.string.character = (uint32_t) c;
|
||||
cell->payload.string.cdr = tail;
|
||||
cell->payload.string.cdr.page = tail.page;
|
||||
cell->payload.string.cdr.offset = tail.offset;
|
||||
} else {
|
||||
fprintf( stderr, "Warning: only NIL and STRING can be appended to STRING\n");
|
||||
}
|
||||
|
|
|
|||
|
|
@ -53,17 +53,17 @@
|
|||
/**
|
||||
* true if conspointer points to the special cell NIL, else false
|
||||
*/
|
||||
#define nilp(conspoint) (check_tag(conspoint,NILTAG)==0)
|
||||
#define nilp(conspoint) (check_tag(conspoint,NILTAG))
|
||||
|
||||
/**
|
||||
* true if conspointer points to a cons cell, else false
|
||||
*/
|
||||
#define consp(conspoint) (check_tag(conspoint,CONSTAG)==0)
|
||||
#define consp(conspoint) (check_tag(conspoint,CONSTAG))
|
||||
|
||||
/**
|
||||
* true if conspointer points to a string cell, else false
|
||||
*/
|
||||
#define stringp(conspoint) (check_tag(conspoint,STRINGTAG)==0)
|
||||
#define stringp(conspoint) (check_tag(conspoint,STRINGTAG))
|
||||
|
||||
/**
|
||||
* An indirect pointer to a cons cell
|
||||
|
|
|
|||
|
|
@ -18,16 +18,15 @@
|
|||
#include "read.h"
|
||||
|
||||
int main (int argc, char *argv[]) {
|
||||
// printf( "Post scarcity software environment version %s\n", VERSION);
|
||||
fprintf( stderr, "Post scarcity software environment version %s\n", VERSION);
|
||||
initialise_cons_pages();
|
||||
|
||||
fprintf( stderr, "\n:: ");
|
||||
struct cons_pointer input = read( stdin);
|
||||
//inc_ref( input);
|
||||
//printf( "\n:: ");
|
||||
fprintf( stderr, "\n{%d,%d}=> ", input.page, input.offset);
|
||||
print( stdout, input);
|
||||
|
||||
// dump_pages(stdout);
|
||||
// printf( "Tag2uint(\"FREE\") = %d\n", tag2uint("FREE"));
|
||||
dump_pages(stderr);
|
||||
|
||||
return(0);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -16,7 +16,7 @@
|
|||
*/
|
||||
struct cons_pointer make_integer( int value) {
|
||||
struct cons_pointer result = allocate_cell( INTEGERTAG);
|
||||
struct cons_space_object* cell = &conspages[result.page]->cell[result.offset];
|
||||
struct cons_space_object* cell = &pointer2cell(result);
|
||||
cell->payload.integer.value = value;
|
||||
|
||||
return result;
|
||||
|
|
|
|||
60
src/print.c
60
src/print.c
|
|
@ -17,17 +17,51 @@
|
|||
#include "integer.h"
|
||||
#include "print.h"
|
||||
|
||||
void print_string_contents( FILE* output, struct cons_pointer pointer) {
|
||||
if ( check_tag( pointer, STRINGTAG)) {
|
||||
struct cons_space_object* cell = &pointer2cell(pointer);
|
||||
char c = cell->payload.string.character;
|
||||
|
||||
if ( c != '\0') {
|
||||
fputc( c, output);
|
||||
}
|
||||
print_string_contents( output, cell->payload.string.cdr);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
void print_string( FILE* output, struct cons_pointer pointer) {
|
||||
fputc( '"', output);
|
||||
print_string_contents( output, pointer);
|
||||
fputc( '"', output);
|
||||
}
|
||||
|
||||
|
||||
void print_list_contents( FILE* output, struct cons_pointer pointer) {
|
||||
if ( check_tag( pointer, CONSTAG)) {
|
||||
struct cons_space_object* cell = &pointer2cell(pointer);
|
||||
|
||||
print( output, cell->payload.cons.car);
|
||||
|
||||
if ( !nilp( cell->payload.cons.cdr)) {
|
||||
fputc( ' ', output);
|
||||
}
|
||||
print_list_contents( output, cell->payload.cons.cdr);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
void print_list( FILE* output, struct cons_pointer pointer) {
|
||||
fputc( '(', output);
|
||||
print_list_contents( output, pointer);
|
||||
fputc( ')', output);
|
||||
}
|
||||
|
||||
void print( FILE* output, struct cons_pointer pointer) {
|
||||
struct cons_space_object cell = pointer2cell( pointer);
|
||||
|
||||
if ( check_tag( pointer, CONSTAG)) {
|
||||
fputc( '(', output);
|
||||
for (struct cons_pointer p = pointer; consp( p);
|
||||
p = pointer2cell( p).payload.cons.cdr) {
|
||||
print( output, p);
|
||||
fputc( ' ', output);
|
||||
}
|
||||
fputc( ')', output);
|
||||
print_list( output, pointer);
|
||||
} else if ( check_tag( pointer, INTEGERTAG)) {
|
||||
fprintf( output, "%ld", cell.payload.integer.value);
|
||||
} else if ( check_tag( pointer, NILTAG)) {
|
||||
|
|
@ -35,17 +69,7 @@ void print( FILE* output, struct cons_pointer pointer) {
|
|||
} else if ( check_tag( pointer, REALTAG)) {
|
||||
fprintf( output, "%Lf", cell.payload.real.value);
|
||||
} else if ( check_tag( pointer, STRINGTAG)) {
|
||||
fputc( '"', output);
|
||||
for (struct cons_pointer p = pointer; stringp( p);
|
||||
p = pointer2cell( p).payload.string.cdr) {
|
||||
// TODO: That's potentially a UTF character, needs more handling.
|
||||
char c = (char)pointer2cell( p).payload.string.character;
|
||||
|
||||
if ( c != '\0') {
|
||||
fprintf( output, "%c", c);
|
||||
}
|
||||
}
|
||||
fputc( '"', output);
|
||||
print_string( output, pointer);
|
||||
} else if ( check_tag( pointer, TRUETAG)) {
|
||||
fprintf( output, "T");
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue