diff --git a/lib/std/io_printf.c3 b/lib/std/io_printf.c3 index a08d56b8e..ac9ce4938 100644 --- a/lib/std/io_printf.c3 +++ b/lib/std/io_printf.c3 @@ -69,6 +69,10 @@ private fn void! out_str(PrintParam* param, variant arg) case FAILABLE: unreachable(); case DISTINCT: + if (arg.type == String.typeid) + { + return out_substr(param, ((String*)arg).str()); + } return out_str(param, variant { arg.ptr, arg.type.inner }); case POINTER: typeid inner = arg.type.inner; diff --git a/resources/examples/binarydigits.c3 b/resources/examples/binarydigits.c3 index 3b3fd415d..2b4d49a55 100644 --- a/resources/examples/binarydigits.c3 +++ b/resources/examples/binarydigits.c3 @@ -1,13 +1,13 @@ module binarydigits; import std::math; -import libc; +import std::io; fn void main() { for (int i = 0; i < 20; i++) { String s = bin(i); defer s.destroy(); - libc::printf("%s\n", s.zstr()); + io::printf("%s\n", s); } } diff --git a/resources/examples/fannkuch-redux.c3 b/resources/examples/fannkuch-redux.c3 index 1c1c6e549..077fc523f 100644 --- a/resources/examples/fannkuch-redux.c3 +++ b/resources/examples/fannkuch-redux.c3 @@ -1,8 +1,8 @@ module fannkuch; import std::array; +import std::io; +import std::math; import libc; -import std::mem; - fn int fannkuchredux(int n) { @@ -46,7 +46,7 @@ fn int fannkuchredux(int n) { if (r == n) { - libc::printf("%d\n", checksum); + io::printf("%d\n", checksum); return max_flips_count; } @@ -71,6 +71,6 @@ fn int fannkuchredux(int n) fn int main(int argc, char** argv) { int n = argc > 1 ? libc::atoi(argv[1]) : 7; - libc::printf("Pfannkuchen(%d) = %d\n", n, fannkuchredux(n)); + io::printf("Pfannkuchen(%d) = %d\n", n, fannkuchredux(n)); return 0; } \ No newline at end of file diff --git a/resources/examples/fasta.c3 b/resources/examples/fasta.c3 index 92e9ea2d4..0adebf586 100644 --- a/resources/examples/fasta.c3 +++ b/resources/examples/fasta.c3 @@ -1,4 +1,5 @@ module fasta; +import std::io; import libc; const IM = 139968; @@ -59,10 +60,10 @@ fn void repeat_fasta(char[] seq, int n) int i = void; for (i = 0; i < n; i++) { - libc::putchar(seq[i % len]); - if (i % LINELEN == LINELEN - 1) libc::putchar('\n'); + io::putchar(seq[i % len]); + if (i % LINELEN == LINELEN - 1) io::putchar('\n'); } - if (i % LINELEN != 0) libc::putchar('\n'); + if (i % LINELEN != 0) io::putchar('\n'); } fn void random_fasta(char[] symb, double[] probability, int n) @@ -80,10 +81,10 @@ fn void random_fasta(char[] symb, double[] probability, int n) v -= probability[j]; if (v < 0) break; } - libc::putchar(symb[j]); - if (i % LINELEN == LINELEN - 1) libc::putchar('\n'); + io::putchar(symb[j]); + if (i % LINELEN == LINELEN - 1) io::putchar('\n'); } - if (i % LINELEN != 0) libc::putchar('\n'); + if (i % LINELEN != 0) io::putchar('\n'); } fn void main(int argc, char **argv) @@ -91,13 +92,13 @@ fn void main(int argc, char **argv) int n = 1000; if (argc > 1) n = libc::atoi(argv[1]); - libc::printf(">ONE Homo sapiens alu\n"); + io::printf(">ONE Homo sapiens alu\n"); repeat_fasta(alu, n * 2); - libc::printf(">TWO IUB ambiguity codes\n"); + io::printf(">TWO IUB ambiguity codes\n"); random_fasta(iub, iub_p, n * 3); - libc::printf(">THREE Homo sapiens frequency\n"); + io::printf(">THREE Homo sapiens frequency\n"); random_fasta(homosapiens, homosapiens_p, n * 5); } diff --git a/resources/examples/gameoflife.c3 b/resources/examples/gameoflife.c3 index 54c54b4de..e1d52f400 100644 --- a/resources/examples/gameoflife.c3 +++ b/resources/examples/gameoflife.c3 @@ -1,4 +1,6 @@ module game_of_life; +import std::io; +import libc; extern fn void usleep(int time); @@ -14,16 +16,16 @@ struct GameBoard fn void GameBoard.show(GameBoard *board) { - libc::printf("\e[H"); + io::printf("\e[H"); char* current = board.world; for (int y = 0; y < board.h; y++) { for (int x = 0; x < board.w; x++) { - libc::printf(*current ? "\e[07m \e[m" : " "); + io::printf(*current ? "\e[07m \e[m" : " "); current++; } - libc::printf("\e[E"); + io::printf("\e[E"); } libc::fflush(libc::stdout()); } @@ -67,8 +69,8 @@ fn int main(int c, char** v) GameBoard board; board.w = w; board.h = h; - board.world = libc::malloc((ulong)(h * w)); - board.temp = libc::malloc((ulong)(h * w)); + board.world = mem::alloc((ulong)(h * w)); + board.temp = mem::alloc((ulong)(h * w)); for (int i = h * w - 1; i >= 0; i--) { diff --git a/resources/examples/levenshtein.c3 b/resources/examples/levenshtein.c3 index 737ff7abf..d7caa695f 100644 --- a/resources/examples/levenshtein.c3 +++ b/resources/examples/levenshtein.c3 @@ -22,5 +22,5 @@ fn int levenshtein(char[] s, char[] t) int b = levenshtein(s, t[0..^2]); int c = levenshtein(s[0..^2], t); - return @min(@min(a, b), c) + 1; + return min(min(a, b), c) + 1; } \ No newline at end of file diff --git a/resources/rosettacode/antiprime.c3 b/resources/rosettacode/antiprime.c3 index 1f7f52551..ceb4850d4 100644 --- a/resources/rosettacode/antiprime.c3 +++ b/resources/rosettacode/antiprime.c3 @@ -1,8 +1,6 @@ module antiprime; import std::io; -extern fn int printf(char* message, ...); - fn int countDivisors(int n) { if (n < 2) return 1; @@ -25,7 +23,7 @@ fn int main() int d = countDivisors(n); if (d > maxDiv) { - printf("%d ", n); + io::printf("%d ", n); maxDiv = d; count++; }