on master help sign in
Merge pull request #1398 from stepcut/fix/master/arduino
d5c5e30David Christiansen
config.mk+4−1
@@ -1,6 +1,9 @@
1CC ?=cc
1CC ?=cc
2CABAL :=cabal
2CABAL :=cabal
3+# IDRIS_ENABLE_STATS should not be set in final release
4+# Any flags defined here which alter the RTS API must also be added to src/IRTS/CodegenC.hs
3−CFLAGS :=-O2 -Wall -DHAS_PTHREAD $(CFLAGS)
5+CFLAGS :=-O2 -Wall -DHAS_PTHREAD -DIDRIS_ENABLE_STATS $(CFLAGS)
6+
4#CABALFLAGS :=
7#CABALFLAGS :=
5## Disable building of Effects
8## Disable building of Effects
6#CABALFLAGS :=-f NoEffects
9#CABALFLAGS :=-f NoEffects
idris.cabal+18−1
@@ -52,12 +52,28 @@ Data-files: idrisdoc/styles.css
52 jsrts/Runtime-node.js
52 jsrts/Runtime-node.js
53 jsrts/jsbn/jsbn.js
53 jsrts/jsbn/jsbn.js
54 jsrts/jsbn/LICENSE
54 jsrts/jsbn/LICENSE
55+ rts/arduino/idris_main.c
56+ rts/idris_bitstring.c
57+ rts/idris_bitstring.h
58+ rts/idris_gc.c
55 rts/idris_gc.h
59 rts/idris_gc.h
60+ rts/idris_gmp.c
56 rts/idris_gmp.h
61 rts/idris_gmp.h
62+ rts/idris_heap.c
63+ rts/idris_heap.h
57 rts/idris_main.c
64 rts/idris_main.c
58− rts/idris_rts.h
65+ rts/idris_net.c
59 rts/idris_net.h
66 rts/idris_net.h
67+ rts/idris_opts.c
68+ rts/idris_opts.h
69+ rts/idris_rts.c
70+ rts/idris_rts.h
71+ rts/idris_stats.c
72+ rts/idris_stats.h
73+ rts/idris_stdfgn.c
60 rts/idris_stdfgn.h
74 rts/idris_stdfgn.h
75+ rts/mini-gmp.c
76+ rts/mini-gmp.h
61 rts/libtest.c
77 rts/libtest.c
62
78
63Extra-source-files:
79Extra-source-files:
@@ -66,6 +82,7 @@ Extra-source-files:
66
82
67 rts/*.c
83 rts/*.c
68 rts/*.h
84 rts/*.h
85+ rts/arduino/*.c
69 rts/windows/*.c
86 rts/windows/*.c
70 rts/Makefile
87 rts/Makefile
71
88
rts/arduino/idris_main.cnew file+29
@@ -0,0 +1,29 @@
1+#include "idris_opts.h"
2+#include "idris_stats.h"
3+#include "idris_rts.h"
4+#include "Arduino.h"
5+
6+// The default options should give satisfactory results under many circumstances.
7+RTSOpts opts = {
8+ .init_heap_size = 128,
9+ .max_stack_size = 128,
10+ .show_summary = 0
11+};
12+
13+// no argv or argc
14+int main() {
15+ init(); // arduino init function
16+
17+ VM* vm = init_vm(opts.max_stack_size, opts.init_heap_size, 1);
18+ _idris__123_runMain0_125_(vm, NULL);
19+
20+#ifdef IDRIS_DEBUG
21+ if (opts.show_summary) {
22+ idris_gcInfo(vm, 1);
23+ }
24+#endif
25+
26+ Stats stats = terminate(vm);
27+
28+ return 0;
29+}
rts/idris_gc.c+3−1
@@ -151,7 +151,9 @@ void idris_gcInfo(VM* vm, int doGC) {
151 printf("Final heap use %d\n", (int)(vm->heap.next - vm->heap.heap));
151 printf("Final heap use %d\n", (int)(vm->heap.next - vm->heap.heap));
152 if (doGC) { idris_gc(vm); }
152 if (doGC) { idris_gc(vm); }
153 printf("Final heap use after GC %d\n", (int)(vm->heap.next - vm->heap.heap));
153 printf("Final heap use after GC %d\n", (int)(vm->heap.next - vm->heap.heap));
154−
154+#ifdef IDRIS_ENABLE_STATS
155 printf("Total allocations %d\n", vm->stats.allocations);
155 printf("Total allocations %d\n", vm->stats.allocations);
156+#endif
156 printf("Number of collections %d\n", vm->stats.collections);
157 printf("Number of collections %d\n", vm->stats.collections);
158+
157}
159}
rts/idris_rts.h+7
@@ -13,6 +13,13 @@
13#include "idris_heap.h"
13#include "idris_heap.h"
14#include "idris_stats.h"
14#include "idris_stats.h"
15
15
16+#ifndef EXIT_SUCCESS
17+#define EXIT_SUCCESS 0
18+#endif
19+#ifndef EXIT_FAILURE
20+#define EXIT_FAILURE 1
21+#endif
22+
16// Closures
23// Closures
17
24
18typedef enum {
25typedef enum {
rts/idris_stats.h+2−2
@@ -1,10 +1,10 @@
1#ifndef _IDRIS_STATS_H
1#ifndef _IDRIS_STATS_H
2#define _IDRIS_STATS_H
2#define _IDRIS_STATS_H
3
3
4+#ifdef IDRIS_ENABLE_STATS
4#include <time.h>
5#include <time.h>
6+#endif
5
7
6−// Should not be defined in release.
7−#define IDRIS_ENABLE_STATS
8
8
9// TODO: measure user time, exclusive/inclusive stats
9// TODO: measure user time, exclusive/inclusive stats
10typedef struct {
10typedef struct {
src/IRTS/CodegenC.hs+2−1
@@ -67,7 +67,8 @@ codegenC' defs out exec incs objs libs flags dbg
67 let gcc = comp ++ " " ++
67 let gcc = comp ++ " " ++
68 gccDbg dbg ++ " " ++
68 gccDbg dbg ++ " " ++
69 gccFlags ++
69 gccFlags ++
70+ -- # Any flags defined here which alter the RTS API must also be added to config.mk
70− " -DHAS_PTHREAD " ++
71+ " -DHAS_PTHREAD -DIDRIS_ENABLE_STATS" ++
71 " -I. " ++ objs ++ " -x c " ++
72 " -I. " ++ objs ++ " -x c " ++
72 (if (exec == Executable) then "" else " -c ") ++
73 (if (exec == Executable) then "" else " -c ") ++
73 " " ++ tmpn ++
74 " " ++ tmpn ++