on master help sign in
Merge pull request #1398 from stepcut/fix/master/arduino

Fix/master/arduino

commitd5c5e306c1932ab40bfee914eb933a1c7946c9f1 authorDavid Christiansen <david@davidchristiansen.dk> dateTue 30 Sep 2014, 17:49 (12 years ago) parent30e8cf1035e15b
7 files changed+65−6
config.mk+4−1 idris.cabal+18−1 rts/arduino/idris_main.c+29 rts/idris_gc.c+3−1 rts/idris_rts.h+7 rts/idris_stats.h+2−2 src/IRTS/CodegenC.hs+2−1
config.mk+4−1
@@ -1,6 +1,9 @@
11CC ?=cc
22CABAL :=cabal
3−CFLAGS :=-O2 -Wall -DHAS_PTHREAD $(CFLAGS)
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
5+CFLAGS :=-O2 -Wall -DHAS_PTHREAD -DIDRIS_ENABLE_STATS $(CFLAGS)
6+
47#CABALFLAGS :=
58## Disable building of Effects
69#CABALFLAGS :=-f NoEffects
idris.cabal+18−1
@@ -52,12 +52,28 @@ Data-files: idrisdoc/styles.css
5252 jsrts/Runtime-node.js
5353 jsrts/jsbn/jsbn.js
5454 jsrts/jsbn/LICENSE
55+ rts/arduino/idris_main.c
56+ rts/idris_bitstring.c
57+ rts/idris_bitstring.h
58+ rts/idris_gc.c
5559 rts/idris_gc.h
60+ rts/idris_gmp.c
5661 rts/idris_gmp.h
62+ rts/idris_heap.c
63+ rts/idris_heap.h
5764 rts/idris_main.c
58− rts/idris_rts.h
65+ rts/idris_net.c
5966 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
6074 rts/idris_stdfgn.h
75+ rts/mini-gmp.c
76+ rts/mini-gmp.h
6177 rts/libtest.c
6278
6379Extra-source-files:
@@ -66,6 +82,7 @@ Extra-source-files:
6682
6783 rts/*.c
6884 rts/*.h
85+ rts/arduino/*.c
6986 rts/windows/*.c
7087 rts/Makefile
7188
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) {
151151 printf("Final heap use %d\n", (int)(vm->heap.next - vm->heap.heap));
152152 if (doGC) { idris_gc(vm); }
153153 printf("Final heap use after GC %d\n", (int)(vm->heap.next - vm->heap.heap));
154−
154+#ifdef IDRIS_ENABLE_STATS
155155 printf("Total allocations %d\n", vm->stats.allocations);
156+#endif
156157 printf("Number of collections %d\n", vm->stats.collections);
158+
157159}
rts/idris_rts.h+7
@@ -13,6 +13,13 @@
1313#include "idris_heap.h"
1414#include "idris_stats.h"
1515
16+#ifndef EXIT_SUCCESS
17+#define EXIT_SUCCESS 0
18+#endif
19+#ifndef EXIT_FAILURE
20+#define EXIT_FAILURE 1
21+#endif
22+
1623// Closures
1724
1825typedef enum {
rts/idris_stats.h+2−2
@@ -1,10 +1,10 @@
11#ifndef _IDRIS_STATS_H
22#define _IDRIS_STATS_H
33
4+#ifdef IDRIS_ENABLE_STATS
45#include <time.h>
6+#endif
57
6−// Should not be defined in release.
7−#define IDRIS_ENABLE_STATS
88
99// TODO: measure user time, exclusive/inclusive stats
1010typedef struct {
src/IRTS/CodegenC.hs+2−1
@@ -67,7 +67,8 @@ codegenC' defs out exec incs objs libs flags dbg
6767 let gcc = comp ++ " " ++
6868 gccDbg dbg ++ " " ++
6969 gccFlags ++
70− " -DHAS_PTHREAD " ++
70+ -- # Any flags defined here which alter the RTS API must also be added to config.mk
71+ " -DHAS_PTHREAD -DIDRIS_ENABLE_STATS" ++
7172 " -I. " ++ objs ++ " -x c " ++
7273 (if (exec == Executable) then "" else " -c ") ++
7374 " " ++ tmpn ++