Commit e8fd4279 authored by Laszlo Domoszlai's avatar Laszlo Domoszlai
Browse files

speed up printing thunks

parent 9d7ba75d
...@@ -70,49 +70,45 @@ void print(bool force) { ...@@ -70,49 +70,45 @@ void print(bool force) {
thunk = thunk->_forward_ptr; thunk = thunk->_forward_ptr;
} }
printf("["); putchar('[');
if (thunk->desc->type == FT_BOXED_LIT) { if (thunk->desc->type == FT_BOXED_LIT) {
if ((FunEntry*) thunk->desc == __INT__) { if ((FunEntry*) thunk->desc == __INT__) {
printf("%d", thunk->_int); printf("%d", thunk->_int);
} else if ((FunEntry*) thunk->desc == __BOOL__) { } else if ((FunEntry*) thunk->desc == __BOOL__) {
if (thunk->_int) { if (thunk->_int) {
printf("True"); fwrite("True",1,4,stdout);
} else { } else {
printf("False"); fwrite("False",1,5,stdout);
} }
} else if ((FunEntry*) thunk->desc == __CHAR__) { } else if ((FunEntry*) thunk->desc == __CHAR__) {
printf("'%c'", (char) thunk->_int); putchar('\'');
putchar((char) thunk->_int);
putchar('\'');
} else if ((FunEntry*) thunk->desc == __REAL__) { } else if ((FunEntry*) thunk->desc == __REAL__) {
printf("%G", thunk->_real); printf("%G", thunk->_real);
} else if ((FunEntry*) thunk->desc == __STRING_PTR__) { } else if ((FunEntry*) thunk->desc == __STRING_PTR__) {
printf("\""); putchar('"');
for(int i=0; i< thunk->_string_ptr->length; i++) fwrite(thunk->_string_ptr->chars,1,thunk->_string_ptr->length,stdout);
{ putchar('"');
printf("%c", thunk->_string_ptr->chars[i]);
}
printf("\"");
} else if ((FunEntry*) thunk->desc == __ARRAY__) { } else if ((FunEntry*) thunk->desc == __ARRAY__) {
if(thunk->_array.type == AET_CHAR) if(thunk->_array.type == AET_CHAR)
{ {
printf("\""); putchar('"');
for(int i=0; i< thunk->_array.length; i++) fwrite(thunk->_array._chars,1,thunk->_array.length,stdout);
{ putchar('"');
printf("%c", thunk->_array._chars[i]);
}
printf("\"");
} }
else else
{ {
bool first = true; bool first = true;
printf("{"); putchar('{');
for(int i=0; i< thunk->_array.length; i++) for(int i=0; i< thunk->_array.length; i++)
{ {
if(!first) if(!first)
{ {
printf(","); putchar(',');
} }
else else
{ {
...@@ -124,15 +120,15 @@ void print(bool force) { ...@@ -124,15 +120,15 @@ void print(bool force) {
case AET_BOOL: case AET_BOOL:
if(thunk->_array._bools[i]) if(thunk->_array._bools[i])
{ {
printf("True"); fwrite("True",1,4,stdout);
} }
else else
{ {
printf("False"); fwrite("False",1,5,stdout);
} }
break; break;
case AET_CHAR: case AET_CHAR:
printf("%c", thunk->_array._chars[i]); putchar(thunk->_array._chars[i]);
break; break;
case AET_INT: case AET_INT:
printf("%d", thunk->_array._ints[i]); printf("%d", thunk->_array._ints[i]);
...@@ -147,7 +143,7 @@ void print(bool force) { ...@@ -147,7 +143,7 @@ void print(bool force) {
} }
} }
printf("}"); putchar('}');
} }
} else { } else {
printf("print: unhandled BOXED LIT\n"); printf("print: unhandled BOXED LIT\n");
...@@ -164,7 +160,7 @@ void print(bool force) { ...@@ -164,7 +160,7 @@ void print(bool force) {
} }
for (int i = 0; i < arity; i++) { for (int i = 0; i < arity; i++) {
printf(" "); putchar(' ');
if (force) peek_a()->desc->eval(); if (force) peek_a()->desc->eval();
print(force); print(force);
...@@ -172,5 +168,5 @@ void print(bool force) { ...@@ -172,5 +168,5 @@ void print(bool force) {
} }
printf("]"); putchar(']');
} }
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment