Skip to content

Commit

Permalink
Print quoted strings in the runtime (#1969)
Browse files Browse the repository at this point in the history
* Closes #1968
  • Loading branch information
lukaszcz authored Apr 4, 2023
1 parent cc2f060 commit 63a2c51
Show file tree
Hide file tree
Showing 4 changed files with 33 additions and 9 deletions.
27 changes: 19 additions & 8 deletions runtime/src/juvix/io.c
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,18 @@ void io_flush() {
}
}

static void io_print(word_t x) {
if (io_buffer == NULL) {
io_init();
}
io_index += print_to_buf(io_buffer + io_index, PAGE_SIZE - io_index, x);
if (io_index >= PAGE_SIZE) {
io_buffer[PAGE_SIZE - 1] = 0;
print_msg(io_buffer);
error_exit_msg("error: IO buffer overflow");
}
}

static void io_write(word_t x) {
if (io_buffer == NULL) {
io_init();
Expand All @@ -53,12 +65,7 @@ static void io_write(word_t x) {
}
}
} else {
io_index += print_to_buf(io_buffer + io_index, PAGE_SIZE - io_index, x);
if (io_index >= PAGE_SIZE) {
io_buffer[PAGE_SIZE - 1] = 0;
print_msg(io_buffer);
error_exit_msg("error: IO buffer overflow");
}
io_print(x);
}
}

Expand Down Expand Up @@ -112,13 +119,17 @@ void io_trace(word_t x) {
if (x == OBJ_VOID) {
print_msg("void");
} else {
io_print_toplevel(x);
io_write(x);
ASSERT(io_index < PAGE_SIZE);
io_buffer[io_index] = 0;
print_msg(io_buffer);
io_index = 0;
}
}

void io_print_toplevel(word_t x) {
if (x != OBJ_VOID) {
io_write(x);
io_print(x);
ASSERT(io_index < PAGE_SIZE);
io_buffer[io_index] = 0;
print_msg(io_buffer);
Expand Down
7 changes: 6 additions & 1 deletion test/Compilation/Positive.hs
Original file line number Diff line number Diff line change
Expand Up @@ -294,5 +294,10 @@ tests =
"Test047: Local Modules"
$(mkRelDir ".")
$(mkRelFile "test047.juvix")
$(mkRelFile "out/test047.out")
$(mkRelFile "out/test047.out"),
posTest
"Test048: String quoting"
$(mkRelDir ".")
$(mkRelFile "test048.juvix")
$(mkRelFile "out/test048.out")
]
1 change: 1 addition & 0 deletions tests/Compilation/positive/out/test048.out
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
"hello!\n\b\t\r"
7 changes: 7 additions & 0 deletions tests/Compilation/positive/test048.juvix
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
-- String quoting
module test048;

open import Stdlib.Prelude;

main : String;
main := "hello!\n\b\t\r";

0 comments on commit 63a2c51

Please sign in to comment.