From a313d4865c8ff6b2e504af303bc1673f7b476dbe Mon Sep 17 00:00:00 2001 From: Stefano Sanfilippo Date: Sat, 7 Mar 2015 14:12:18 +0100 Subject: [PATCH] Implementing stdlib runtime. --- Runtime.c | 76 +++++++++++++++++++++++++++++++++++++++++++++++++++++++ Runtime.h | 36 ++++++++++++++++++++++++++ 2 files changed, 112 insertions(+) create mode 100644 Runtime.c create mode 100644 Runtime.h diff --git a/Runtime.c b/Runtime.c new file mode 100644 index 0000000..e753f21 --- /dev/null +++ b/Runtime.c @@ -0,0 +1,76 @@ +#include "Runtime.h" + +#include +#include +#include + + +void __Monicelli_main(); + +void __Monicelli_putBool(__Monicelli_Bool value) { + puts(value? "vero": "falso"); +} + +void __Monicelli_putChar(__Monicelli_Char value) { + printf("%c", value); +} + +void __Monicelli_putInt(__Monicelli_Int value) { + printf("%ld", value); +} + +void __Monicelli_putFloat(__Monicelli_Float value) { + printf("%f", value); +} + +void __Monicelli_putDouble(__Monicelli_Double value) { + printf("%lf", value); +} + +__Monicelli_Bool __Monicelli_getBool() { + __Monicelli_Bool tmp; + printf("%s", "? "); + scanf("%c", &tmp); + return tmp != 0? 1: 0; +} + +__Monicelli_Char __Monicelli_getChar() { + __Monicelli_Char tmp; + printf("%s", "? "); + scanf("%c", &tmp); + return tmp; +} + +__Monicelli_Int __Monicelli_getInt() { + __Monicelli_Int tmp; + printf("%s", "? "); + scanf("%ld", &tmp); + return tmp; +} + +__Monicelli_Float __Monicelli_getFloat() { + __Monicelli_Float tmp; + printf("%s", "? "); + scanf("%f", &tmp); + return tmp; +} + +__Monicelli_Double __Monicelli_getDouble() { + __Monicelli_Double tmp; + printf("%s", "? "); + scanf("%lf", &tmp); + return tmp; +} + +void __Monicelli_abort() { + abort(); +} + +void __Monicelli_assert(__Monicelli_Bool condition) { + assert(condition); +} + +int main() { + __Monicelli_main(); +} + diff --git a/Runtime.h b/Runtime.h new file mode 100644 index 0000000..badf559 --- /dev/null +++ b/Runtime.h @@ -0,0 +1,36 @@ +#ifndef RUNTIME_H +#define RUNTIME_H + +#include + +typedef int8_t __Monicelli_Bool; +typedef int8_t __Monicelli_Char; +typedef int64_t __Monicelli_Int; +typedef float __Monicelli_Float; +typedef double __Monicelli_Double; + +#ifdef __cplusplus +extern "C" { +#endif + +void __Monicelli_putBool(__Monicelli_Bool value); +void __Monicelli_putChar(__Monicelli_Char value); +void __Monicelli_putInt(__Monicelli_Int value); +void __Monicelli_putFloat(__Monicelli_Float value); +void __Monicelli_putDouble(__Monicelli_Double value); + +__Monicelli_Bool __Monicelli_getBool(); +__Monicelli_Char __Monicelli_getChar(); +__Monicelli_Int __Monicelli_getInt(); +__Monicelli_Float __Monicelli_getFloat(); +__Monicelli_Double __Monicelli_getDouble(); + +void __Monicelli_abort(); + +void __Monicelli_assert(__Monicelli_Bool condition); + +#ifdef __cplusplus +} +#endif + +#endif