• R/O
  • HTTP
  • SSH
  • HTTPS

Commit

Frequently used words (click to add to your profile)

javac++androidlinuxc#windowsobjective-ccocoa誰得qtpythonphprubygameguibathyscaphec計画中(planning stage)翻訳omegatframeworktwitterdomtestvb.netdirectxゲームエンジンbtronarduinopreviewer

超漢字上で、mrubyを使ってhello worldを表示させる。


Commit MetaInfo

Révision7139958a63e5c5475916e43bccc4b1cc9c822dad (tree)
l'heure2014-07-13 23:58:29
Auteurornse01 <ornse01@user...>
Commiterornse01

Message de Log

add some posix function header end implements for mruby.

Change Summary

Modification

--- /dev/null
+++ b/src/posix.c
@@ -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+}
--- /dev/null
+++ b/src/posix_include/ctype.h
@@ -0,0 +1 @@
1+#include <bctype.h>
--- /dev/null
+++ b/src/posix_include/errno.h
@@ -0,0 +1 @@
1+#include <berrno.h>
--- /dev/null
+++ b/src/posix_include/float.h
@@ -0,0 +1,3 @@
1+#include <typedef.h>
2+#include <bmath.h>
3+
--- /dev/null
+++ b/src/posix_include/limits.h
@@ -0,0 +1,6 @@
1+#ifndef __LIMITS_H__
2+#define __LIMITS_H__
3+
4+#define CHAR_BIT 8
5+
6+#endif
--- /dev/null
+++ b/src/posix_include/math.h
@@ -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
--- /dev/null
+++ b/src/posix_include/setjmp.h
@@ -0,0 +1,2 @@
1+#include <machine.h>
2+#include <bsetjmp.h>
--- /dev/null
+++ b/src/posix_include/stdint.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
--- /dev/null
+++ b/src/posix_include/stdio.h
@@ -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
--- /dev/null
+++ b/src/posix_include/stdlib.h
@@ -0,0 +1,5 @@
1+#include <basic.h>
2+#include <bstdlib.h>
3+
4+#define EXIT_SUCCESS (0)
5+#define EXIT_FAILURE (1)
--- /dev/null
+++ b/src/posix_include/string.h
@@ -0,0 +1,2 @@
1+
2+#include <bstring.h>