/* Windows I/O port for tinyvm: provides Q, G and J with binary stdio */ #include #include #include int J; static int pk(void) { int c = _fgetc_nolock(stdin); if (c != EOF) _ungetc_nolock(c, stdin); return c == EOF; } char Q(void) { int c = _fgetc_nolock(stdin); J = pk(); return (char)c; } int input_pending(void) { return 0; } void G(char c) { _fputc_nolock(c, stdout); } static void init_io(void) { _setmode(_fileno(stdin), _O_BINARY); _setmode(_fileno(stdout), _O_BINARY); /* the first read establishes eof; startup must not read stdin. */ J = 0; } #if defined(__GNUC__) || defined(__clang__) __attribute__((constructor)) static void init(void) { init_io(); } #elif defined(_MSC_VER) #pragma section(".CRT$XCU", read) static void __cdecl msc_init(void) { init_io(); } __declspec(allocate(".CRT$XCU")) static void (__cdecl *msc_init_fn)(void) = msc_init; #else static void init(void) { init_io(); } #endif