on master help sign in
Add a prim__systemInfo primitive.
cc9b104niklas
idris.cabal+1
@@ -90,6 +90,7 @@ Extra-source-files:
90 libs/base/Language/Reflection/*.idr
90 libs/base/Language/Reflection/*.idr
91 libs/base/Makefile
91 libs/base/Makefile
92 libs/base/Network/*.idr
92 libs/base/Network/*.idr
93+ libs/base/System/*.idr
93 libs/base/System/Concurrency/*.idr
94 libs/base/System/Concurrency/*.idr
94 libs/base/Syntax/*.idr
95 libs/base/Syntax/*.idr
95
96
jsrts/Runtime-browser.js+11
@@ -1,3 +1,14 @@
1var __IDRRT__print = function(s) {
1var __IDRRT__print = function(s) {
2 console.log(s);
2 console.log(s);
3};
3};
4+
5+
6+var __IDRRT__systemInfo = function(index) {
7+ switch(index) {
8+ case 0:
9+ return "javascript";
10+ case 1:
11+ return navigator.platform;
12+ }
13+ return "";
14+}
jsrts/Runtime-node.js+11
@@ -4,3 +4,14 @@ var __IDRRT__print = (function() {
4 util.print(s);
4 util.print(s);
5 };
5 };
6})();
6})();
7+
8+var __IDRRT__systemInfo = function(index) {
9+ var os = require('os')
10+ switch(index) {
11+ case 0:
12+ return "node";
13+ case 1:
14+ return os.platform();
15+ }
16+ return "";
17+}
libs/base/System/Info.idrnew file+13
@@ -0,0 +1,13 @@
1+module System.Info
2+
3+||| The Idris backend in use
4+backend : String
5+backend = prim__systemInfo 0
6+
7+||| The operating system in use.
8+os : String
9+os = prim__systemInfo 1
10+
11+||| The triple this program was targeted for
12+targetTriple : String
13+targetTriple = prim__systemInfo 2
libs/base/base.ipkg+1
@@ -6,6 +6,7 @@ modules = System,
6 Network.Cgi, Network.Socket,
6 Network.Cgi, Network.Socket,
7 Debug.Trace,
7 Debug.Trace,
8
8
9+ System.Info,
9 System.Concurrency.Raw, System.Concurrency.Process,
10 System.Concurrency.Raw, System.Concurrency.Process,
10
11
11 Decidable.Decidable, Decidable.Order,
12 Decidable.Decidable, Decidable.Order,
rts/Makefile+2−1
@@ -5,7 +5,8 @@ OBJS = idris_rts.o idris_heap.o idris_gc.o idris_gmp.o idris_bitstring.o \
5HDRS = idris_rts.h idris_heap.h idris_gc.h idris_gmp.h idris_bitstring.h \
5HDRS = idris_rts.h idris_heap.h idris_gc.h idris_gmp.h idris_bitstring.h \
6 idris_opts.h idris_stats.h mini-gmp.h idris_stdfgn.h idris_net.h
6 idris_opts.h idris_stats.h mini-gmp.h idris_stdfgn.h idris_net.h
7CFLAGS:=-fPIC $(CFLAGS)
7CFLAGS:=-fPIC $(CFLAGS)
8−CFLAGS += $(GMP_INCLUDE_DIR) $(GMP)
8+CFLAGS += $(GMP_INCLUDE_DIR) $(GMP) -DIDRIS_TARGET_OS="\"$(OS)\""
9+CFLAGS += -DIDRIS_TARGET_TRIPLE="\"$(MACHINE)\""
9
10
10ifeq ($(OS), windows)
11ifeq ($(OS), windows)
11 OBJS += windows/idris_stdfgn.o windows/idris_net.o
12 OBJS += windows/idris_stdfgn.o windows/idris_net.o
rts/idris_rts.c+13
@@ -506,6 +506,19 @@ VAL idris_strRev(VM* vm, VAL str) {
506 return cl;
506 return cl;
507}
507}
508
508
509+VAL idris_systemInfo(VM* vm, VAL index) {
510+ int i = GETINT(index);
511+ switch(i) {
512+ case 0: // backend
513+ return MKSTR(vm, "c");
514+ case 1:
515+ return MKSTR(vm, IDRIS_TARGET_OS);
516+ case 2:
517+ return MKSTR(vm, IDRIS_TARGET_TRIPLE);
518+ }
519+ return MKSTR(vm, "");
520+}
521+
509VAL MKBUFFERc(VM* vm, Buffer* buf) {
522VAL MKBUFFERc(VM* vm, Buffer* buf) {
510 Closure* cl = allocate(vm, sizeof(Closure) + sizeof *buf + buf->cap, 1);
523 Closure* cl = allocate(vm, sizeof(Closure) + sizeof *buf + buf->cap, 1);
511 SETTY(cl, BUFFER);
524 SETTY(cl, BUFFER);
rts/idris_rts.h+6
@@ -279,6 +279,12 @@ VAL idris_peekB64Native(VM* vm, VAL buf, VAL off);
279VAL idris_peekB64LE(VM* vm, VAL buf, VAL off);
279VAL idris_peekB64LE(VM* vm, VAL buf, VAL off);
280VAL idris_peekB64BE(VM* vm, VAL buf, VAL off);
280VAL idris_peekB64BE(VM* vm, VAL buf, VAL off);
281
281
282+// system infox
283+// used indices:
284+// 0 returns backend
285+// 1 returns OS
286+VAL idris_systemInfo(VM* vm, VAL index);
287+
282// Command line args
288// Command line args
283
289
284extern int __idris_argc;
290extern int __idris_argc;
src/IRTS/CodegenC.hs+2
@@ -493,6 +493,8 @@ doOp v (LChInt ITNative) args = v ++ creg (last args)
493doOp v (LChInt ITChar) args = doOp v (LChInt ITNative) args
493doOp v (LChInt ITChar) args = doOp v (LChInt ITNative) args
494doOp v (LIntCh ITNative) args = v ++ creg (last args)
494doOp v (LIntCh ITNative) args = v ++ creg (last args)
495doOp v (LIntCh ITChar) args = doOp v (LIntCh ITNative) args
495doOp v (LIntCh ITChar) args = doOp v (LIntCh ITNative) args
496+
497+doOp v LSystemInfo [x] = v ++ "idris_systemInfo(vm, " ++ creg x ++ ")"
496doOp v LNoOp args = v ++ creg (last args)
498doOp v LNoOp args = v ++ creg (last args)
497doOp _ op _ = "FAIL /* " ++ show op ++ " */"
499doOp _ op _ = "FAIL /* " ++ show op ++ " */"
498
500
src/IRTS/CodegenJavaScript.hs+2
@@ -2508,6 +2508,8 @@ translateExpression (SOp op vars)
2508 JSNum (JSInt 1),
2508 JSNum (JSInt 1),
2509 JSBinOp "-" (JSProj (JSIdent v) "length") (JSNum (JSInt 1))
2509 JSBinOp "-" (JSProj (JSIdent v) "length") (JSNum (JSInt 1))
2510 ]
2510 ]
2511+ | LSystemInfo <- op
2512+ , (arg:_) <- vars = jsCall "__IDRRT__systemInfo" [JSVar arg]
2511 | LNullPtr <- op
2513 | LNullPtr <- op
2512 , (_) <- vars = JSNull
2514 , (_) <- vars = JSNull
2513
2515
src/IRTS/Lang.hs+2
@@ -55,6 +55,8 @@ data PrimFn = LPlus ArithTy | LMinus ArithTy | LTimes ArithTy
55 -- Buffers
55 -- Buffers
56 | LAllocate
56 | LAllocate
57 | LAppendBuffer
57 | LAppendBuffer
58+ -- system info
59+ | LSystemInfo
58 -- Note that for Bits8 only Native endianness is actually used
60 -- Note that for Bits8 only Native endianness is actually used
59 -- and the user-exposed interface for Bits8 doesn't mention
61 -- and the user-exposed interface for Bits8 doesn't mention
60 -- endianness
62 -- endianness
src/Idris/Primitives.hs+3−1
@@ -184,7 +184,9 @@ primitives =
184 Prim (sUN "prim__allocate") (ty [AType (ATInt (ITFixed IT64))] BufferType) 1 (p_allocate)
184 Prim (sUN "prim__allocate") (ty [AType (ATInt (ITFixed IT64))] BufferType) 1 (p_allocate)
185 (1, LAllocate) total,
185 (1, LAllocate) total,
186 Prim (sUN "prim__appendBuffer") (ty [BufferType, AType (ATInt (ITFixed IT64)), AType (ATInt (ITFixed IT64)), AType (ATInt (ITFixed IT64)), AType (ATInt (ITFixed IT64)), BufferType] BufferType) 6 (p_appendBuffer)
186 Prim (sUN "prim__appendBuffer") (ty [BufferType, AType (ATInt (ITFixed IT64)), AType (ATInt (ITFixed IT64)), AType (ATInt (ITFixed IT64)), AType (ATInt (ITFixed IT64)), BufferType] BufferType) 6 (p_appendBuffer)
187− (6, LAppendBuffer) partial
187+ (6, LAppendBuffer) partial,
188+ Prim (sUN "prim__systemInfo") (ty [AType (ATInt ITNative)] StrType) 1 (p_cantreduce)
189+ (1, LSystemInfo) total
188 ] ++ concatMap intOps [ITFixed IT8, ITFixed IT16, ITFixed IT32, ITFixed IT64, ITBig, ITNative, ITChar]
190 ] ++ concatMap intOps [ITFixed IT8, ITFixed IT16, ITFixed IT32, ITFixed IT64, ITBig, ITNative, ITChar]
189 ++ concatMap vecOps vecTypes
191 ++ concatMap vecOps vecTypes
190 ++ concatMap fixedOps [ITFixed IT8, ITFixed IT16, ITFixed IT32, ITFixed IT64] -- ITNative, ITChar, ATFloat ] ++ vecTypes
192 ++ concatMap fixedOps [ITFixed IT8, ITFixed IT16, ITFixed IT32, ITFixed IT64] -- ITNative, ITChar, ATFloat ] ++ vecTypes