超漢字上で、mrubyを使ってhello worldを表示させる。
Révision | 7139958a63e5c5475916e43bccc4b1cc9c822dad (tree) |
---|---|
l'heure | 2014-07-13 23:58:29 |
Auteur | ornse01 <ornse01@user...> |
Commiter | ornse01 |
add some posix function header end implements for mruby.
@@ -0,0 +1,72 @@ | ||
1 | +#include "posix_include/stdio.h" | |
2 | +#include "posix_include/math.h" | |
3 | +#include <bstring.h> | |
4 | +#include <bstdarg.h> | |
5 | +#include <bstdlib.h> | |
6 | + | |
7 | +double __nan() | |
8 | +{ | |
9 | + static char nan_byte[] = {0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xf8, 0x7f}; | |
10 | + return *(double*)nan_byte; | |
11 | +} | |
12 | + | |
13 | +int isnan(double x) | |
14 | +{ | |
15 | + double nan = NAN; | |
16 | + return memcmp(&x, &nan, sizeof(double)) == 0; | |
17 | +} | |
18 | + | |
19 | +int isinf(double x) | |
20 | +{ | |
21 | + double inf = INFINITY; | |
22 | + return memcmp(&x, &inf, sizeof(double)) == 0; | |
23 | +} | |
24 | + | |
25 | +int isfinite(double x) | |
26 | +{ | |
27 | + return !isinf(x); | |
28 | +} | |
29 | + | |
30 | +int signbit(double x) | |
31 | +{ | |
32 | + return x < 0.0; | |
33 | +} | |
34 | + | |
35 | +double fmod(double x, double y) | |
36 | +{ | |
37 | + return (x - y * (double)((int)(x / y))); | |
38 | +} | |
39 | + | |
40 | +int fprintf(FILE* stream, const char* format, ...) | |
41 | +{ | |
42 | + int ret = 0; | |
43 | + | |
44 | + if (*stream == stderr || *stream == stdout) { | |
45 | + va_list list; | |
46 | + va_start(list, format); | |
47 | + ret = vprintf(format, list); | |
48 | + va_end(list); | |
49 | + } | |
50 | + | |
51 | + return ret; | |
52 | +} | |
53 | + | |
54 | +int snprintf(char *s, size_t len, const char* format, ...) | |
55 | +{ | |
56 | + int ret = 0; | |
57 | + int len0 = (len < 509) ? 509 : len; | |
58 | + char *p; | |
59 | + va_list list; | |
60 | + | |
61 | + p = malloc(sizeof(char)*len0*3); | |
62 | + | |
63 | + va_start(list, format); | |
64 | + ret = sprintf(p, format, list); | |
65 | + va_end(list); | |
66 | + | |
67 | + memcpy(s, p, ret > len ? len : ret); | |
68 | + | |
69 | + free(p); | |
70 | + | |
71 | + return ret; | |
72 | +} |
@@ -0,0 +1 @@ | ||
1 | +#include <bctype.h> |
@@ -0,0 +1 @@ | ||
1 | +#include <berrno.h> |
@@ -0,0 +1,3 @@ | ||
1 | +#include <typedef.h> | |
2 | +#include <bmath.h> | |
3 | + |
@@ -0,0 +1,6 @@ | ||
1 | +#ifndef __LIMITS_H__ | |
2 | +#define __LIMITS_H__ | |
3 | + | |
4 | +#define CHAR_BIT 8 | |
5 | + | |
6 | +#endif |
@@ -0,0 +1,18 @@ | ||
1 | +#include <typedef.h> | |
2 | +#include <bmath.h> | |
3 | + | |
4 | +#ifndef __MATH_H__ | |
5 | +#define __MATH_H__ | |
6 | + | |
7 | +extern double __nan(); | |
8 | + | |
9 | +#define INFINITY ( __infinity() ) | |
10 | +#define NAN ( __nan() ) | |
11 | + | |
12 | +extern int isnan(double x); | |
13 | +extern int isinf(double x); | |
14 | +extern int signbit(double x); | |
15 | +extern double fmod(double x, double y); | |
16 | +extern int isfinite(double x); | |
17 | + | |
18 | +#endif |
@@ -0,0 +1,2 @@ | ||
1 | +#include <machine.h> | |
2 | +#include <bsetjmp.h> |
@@ -0,0 +1,20 @@ | ||
1 | +#ifndef __STDINT_H__ | |
2 | +#define __STDINT_H__ | |
3 | + | |
4 | +typedef unsigned char uint8_t; | |
5 | +typedef unsigned short uint16_t; | |
6 | +typedef unsigned int uint32_t; | |
7 | +typedef char int8_t; | |
8 | +typedef short int16_t; | |
9 | +typedef int int32_t; | |
10 | + | |
11 | +typedef int intptr_t; | |
12 | +typedef unsigned int uintptr_t; | |
13 | + | |
14 | +#define UINT16_MAX (0xFFFF) | |
15 | +#define INT32_MAX (2147483647L) | |
16 | +#define INT32_MIN (-2147483647L-1) | |
17 | + | |
18 | +#define SIZE_MAX (INT32_MAX) | |
19 | + | |
20 | +#endif |
@@ -0,0 +1,11 @@ | ||
1 | +#include <bstdio.h> | |
2 | + | |
3 | +#ifndef __STDIO_H__ | |
4 | +#define __STDIO_H__ | |
5 | + | |
6 | +typedef int FILE; | |
7 | + | |
8 | +#define stderr (0) | |
9 | +#define stdout (1) | |
10 | + | |
11 | +#endif |
@@ -0,0 +1,5 @@ | ||
1 | +#include <basic.h> | |
2 | +#include <bstdlib.h> | |
3 | + | |
4 | +#define EXIT_SUCCESS (0) | |
5 | +#define EXIT_FAILURE (1) |
@@ -0,0 +1,2 @@ | ||
1 | + | |
2 | +#include <bstring.h> |