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) {
thunk = thunk->_forward_ptr;
}
printf("[");
putchar('[');
if (thunk->desc->type == FT_BOXED_LIT) {
if ((FunEntry*) thunk->desc == __INT__) {
printf("%d", thunk->_int);
} else if ((FunEntry*) thunk->desc == __BOOL__) {
if (thunk->_int) {
printf("True");
fwrite("True",1,4,stdout);
} else {
printf("False");
fwrite("False",1,5,stdout);
}
} else if ((FunEntry*) thunk->desc == __CHAR__) {
printf("'%c'", (char) thunk->_int);
putchar('\'');
putchar((char) thunk->_int);
putchar('\'');
} else if ((FunEntry*) thunk->desc == __REAL__) {
printf("%G", thunk->_real);
} else if ((FunEntry*) thunk->desc == __STRING_PTR__) {
printf("\"");
for(int i=0; i< thunk->_string_ptr->length; i++)
{
printf("%c", thunk->_string_ptr->chars[i]);
}
printf("\"");
putchar('"');
fwrite(thunk->_string_ptr->chars,1,thunk->_string_ptr->length,stdout);
putchar('"');
} else if ((FunEntry*) thunk->desc == __ARRAY__) {
if(thunk->_array.type == AET_CHAR)
{
printf("\"");
for(int i=0; i< thunk->_array.length; i++)
{
printf("%c", thunk->_array._chars[i]);
}
printf("\"");
putchar('"');
fwrite(thunk->_array._chars,1,thunk->_array.length,stdout);
putchar('"');
}
else
{
bool first = true;
printf("{");
putchar('{');
for(int i=0; i< thunk->_array.length; i++)
{
if(!first)
{
printf(",");
putchar(',');
}
else
{
......@@ -124,15 +120,15 @@ void print(bool force) {
case AET_BOOL:
if(thunk->_array._bools[i])
{
printf("True");
fwrite("True",1,4,stdout);
}
else
{
printf("False");
fwrite("False",1,5,stdout);
}
break;
case AET_CHAR:
printf("%c", thunk->_array._chars[i]);
putchar(thunk->_array._chars[i]);
break;
case AET_INT:
printf("%d", thunk->_array._ints[i]);
......@@ -147,7 +143,7 @@ void print(bool force) {
}
}
printf("}");
putchar('}');
}
} else {
printf("print: unhandled BOXED LIT\n");
......@@ -164,7 +160,7 @@ void print(bool force) {
}
for (int i = 0; i < arity; i++) {
printf(" ");
putchar(' ');
if (force) peek_a()->desc->eval();
print(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