Skip to content

Commit

Permalink
print treatment for Extort.
Browse files Browse the repository at this point in the history
  • Loading branch information
dvanhorn committed Oct 11, 2021
1 parent b30d16e commit c888753
Show file tree
Hide file tree
Showing 4 changed files with 34 additions and 28 deletions.
2 changes: 1 addition & 1 deletion extort/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ endif
objs = \
main.o \
values.o \
char.o \
print.o \
io.o

default: runtime.o
Expand Down
27 changes: 1 addition & 26 deletions extort/main.c
Original file line number Diff line number Diff line change
@@ -1,16 +1,13 @@
#include <stdio.h>
#include <inttypes.h>
#include <stdlib.h>
#include "values.h"
#include "print.h"
#include "runtime.h"

FILE* in;
FILE* out;
void (*error_handler)();

void print_result(val_t);
void print_char(val_char_t);

void error_exit()
{
printf("err\n");
Expand All @@ -37,25 +34,3 @@ int main(int argc, char** argv)

return 0;
}

void print_result(val_t x)
{
switch (val_typeof(x)) {
case T_INT:
printf("%" PRId64, val_unwrap_int(x));
break;
case T_BOOL:
printf(val_unwrap_bool(x) ? "#t" : "#f");
break;
case T_CHAR:
print_char(val_unwrap_char(x));
break;
case T_EOF:
printf("#<eof>");
break;
case T_VOID:
break;
case T_INVALID:
printf("internal error");
}
}
25 changes: 24 additions & 1 deletion extort/char.c → extort/print.c
Original file line number Diff line number Diff line change
@@ -1,11 +1,33 @@
#include <stdio.h>
#include <inttypes.h>
#include "types.h"
#include "values.h"

void print_char(val_char_t);
void print_codepoint(val_char_t);
int utf8_encode_char(val_char_t, char *);

void print_result(val_t x)
{
switch (val_typeof(x)) {
case T_INT:
printf("%" PRId64, val_unwrap_int(x));
break;
case T_BOOL:
printf(val_unwrap_bool(x) ? "#t" : "#f");
break;
case T_CHAR:
print_char(val_unwrap_char(x));
break;
case T_EOF:
printf("#<eof>");
break;
case T_VOID:
break;
case T_INVALID:
printf("internal error");
}
}

void print_char(val_char_t c)
{
printf("#\\");
Expand Down Expand Up @@ -64,3 +86,4 @@ int utf8_encode_char(val_char_t c, char *buffer)
return 4;
}
}

8 changes: 8 additions & 0 deletions extort/print.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
#ifndef PRINT_H
#define PRINT_H

#include "values.h"

void print_result(val_t);

#endif

0 comments on commit c888753

Please sign in to comment.