mirror of
https://github.com/tinygo-org/tinygo.git
synced 2026-08-05 19:43:44 +00:00
support print(int)
This commit is contained in:
+21
-2
@@ -4,16 +4,35 @@
|
||||
#include <stdio.h>
|
||||
#include "runtime.h"
|
||||
|
||||
#define print(buf, len) write(STDOUT_FILENO, buf, len)
|
||||
|
||||
void __go_printstring(string_t *str) {
|
||||
write(STDOUT_FILENO, str->buf, str->len);
|
||||
}
|
||||
|
||||
void __go_printint(int32_t n) {
|
||||
// Print integer in signed big-endian base-10 notation, for humans to
|
||||
// read.
|
||||
// TODO: don't recurse, but still be compact (and don't divide/mod
|
||||
// more than necessary).
|
||||
if (n < 0) {
|
||||
print("-", 1);
|
||||
n = -n;
|
||||
}
|
||||
int32_t prevdigits = n / 10;
|
||||
if (prevdigits != 0) {
|
||||
__go_printint(prevdigits);
|
||||
}
|
||||
char buf[1] = {(n % 10) + '0'};
|
||||
print(buf, 1);
|
||||
}
|
||||
|
||||
void __go_printspace() {
|
||||
write(STDOUT_FILENO, " ", 1);
|
||||
print(" ", 1);
|
||||
}
|
||||
|
||||
void __go_printnl() {
|
||||
write(STDOUT_FILENO, "\n", 1);
|
||||
print("\n", 1);
|
||||
}
|
||||
|
||||
void go_main() __asm__("main.main");
|
||||
|
||||
Reference in New Issue
Block a user