Use only putchar() for printing

Этот коммит содержится в:
Ayke van Laethem 2018-04-16 01:56:10 +02:00
родитель 9060e699e4
коммит 139ac45cb1

Просмотреть файл

@ -4,10 +4,10 @@
#include <stdio.h> #include <stdio.h>
#include "runtime.h" #include "runtime.h"
#define print(buf, len) write(STDOUT_FILENO, buf, len)
void __go_printstring(string_t str) { void __go_printstring(string_t str) {
write(STDOUT_FILENO, str.buf, str.len); for (int i = 0; i < str.len; i++) {
putchar(str.buf[i]);
}
} }
void __go_printint(intgo_t n) { void __go_printint(intgo_t n) {
@ -16,23 +16,22 @@ void __go_printint(intgo_t n) {
// TODO: don't recurse, but still be compact (and don't divide/mod // TODO: don't recurse, but still be compact (and don't divide/mod
// more than necessary). // more than necessary).
if (n < 0) { if (n < 0) {
print("-", 1); putchar('-');
n = -n; n = -n;
} }
intgo_t prevdigits = n / 10; intgo_t prevdigits = n / 10;
if (prevdigits != 0) { if (prevdigits != 0) {
__go_printint(prevdigits); __go_printint(prevdigits);
} }
char buf[1] = {(n % 10) + '0'}; putchar((n % 10) + '0');
print(buf, 1);
} }
void __go_printspace() { void __go_printspace() {
print(" ", 1); putchar(' ');
} }
void __go_printnl() { void __go_printnl() {
print("\n", 1); putchar('\n');
} }
void go_main() __asm__("main.main"); void go_main() __asm__("main.main");