on master help sign in
Merge pull request #591 from eamsden/NullPtr
db0c021Edwin Brady
CONTRIBUTORS+1
@@ -2,6 +2,7 @@ Thanks to the following for their help and contributions:
2
2
3Ozgur Akgun
3Ozgur Akgun
4Ahmad Salim Al-Sibahi
4Ahmad Salim Al-Sibahi
5+Edward Chadwick Amsden
5Nicola Botta
6Nicola Botta
6Edwin Brady
7Edwin Brady
7David Raymond Christiansen
8David Raymond Christiansen
lib/Builtins.idr+3
@@ -369,5 +369,8 @@ strIndex = prim__strIndex
369reverse : String -> String
369reverse : String -> String
370reverse = prim__strRev
370reverse = prim__strRev
371
371
372+null : Ptr
373+null = prim__null
374+
372}
375}
373
376
src/IRTS/CodegenC.hs+1
@@ -446,6 +446,7 @@ doOp v LStdErr [] = v ++ "MKPTR(vm, stderr)"
446doOp v LFork [x] = v ++ "MKPTR(vm, vmThread(vm, " ++ cname (MN 0 "EVAL") ++ ", " ++ creg x ++ "))"
446doOp v LFork [x] = v ++ "MKPTR(vm, vmThread(vm, " ++ cname (MN 0 "EVAL") ++ ", " ++ creg x ++ "))"
447doOp v LPar [x] = v ++ creg x -- "MKPTR(vm, vmThread(vm, " ++ cname (MN 0 "EVAL") ++ ", " ++ creg x ++ "))"
447doOp v LPar [x] = v ++ creg x -- "MKPTR(vm, vmThread(vm, " ++ cname (MN 0 "EVAL") ++ ", " ++ creg x ++ "))"
448doOp v LVMPtr [] = v ++ "MKPTR(vm, vm)"
448doOp v LVMPtr [] = v ++ "MKPTR(vm, vm)"
449+doOp v LNullPtr [] = v ++ "MKPTR(vm, NULL)"
449doOp v (LChInt ITNative) args = v ++ creg (last args)
450doOp v (LChInt ITNative) args = v ++ creg (last args)
450doOp v (LChInt ITChar) args = doOp v (LChInt ITNative) args
451doOp v (LChInt ITChar) args = doOp v (LChInt ITNative) args
451doOp v (LIntCh ITNative) args = v ++ creg (last args)
452doOp v (LIntCh ITNative) args = v ++ creg (last args)
src/IRTS/CodegenJavaScript.hs+3
@@ -991,6 +991,9 @@ translateExpression (SOp op vars)
991 | LStrTail <- op
991 | LStrTail <- op
992 , (arg:_) <- vars = let v = translateVariableName arg in
992 , (arg:_) <- vars = let v = translateVariableName arg in
993 JSRaw $ v ++ ".substr(1," ++ v ++ ".length-1)"
993 JSRaw $ v ++ ".substr(1," ++ v ++ ".length-1)"
994+ | LNullPtr <- op
995+ , (_) <- vars = JSNull
996+
994 where
997 where
995 translateBinaryOp :: String -> LVar -> LVar -> JS
998 translateBinaryOp :: String -> LVar -> LVar -> JS
996 translateBinaryOp f lhs rhs = JSOp f (JSVar lhs) (JSVar rhs)
999 translateBinaryOp f lhs rhs = JSOp f (JSVar lhs) (JSVar rhs)
src/IRTS/Java/JTypes.hs+1
@@ -293,6 +293,7 @@ sourceTypes (LStdErr) = []
293sourceTypes (LFork) = [objectType]
293sourceTypes (LFork) = [objectType]
294sourceTypes (LPar) = [objectType]
294sourceTypes (LPar) = [objectType]
295sourceTypes (LVMPtr) = []
295sourceTypes (LVMPtr) = []
296+sourceTypes (LNullPtr) = [objectType]
296sourceTypes (LNoOp) = repeat objectType
297sourceTypes (LNoOp) = repeat objectType
297
298
298
299
src/IRTS/Lang.hs+1
@@ -54,6 +54,7 @@ data PrimFn = LPlus ArithTy | LMinus ArithTy | LTimes ArithTy
54 | LPar -- evaluate argument anywhere, possibly on another
54 | LPar -- evaluate argument anywhere, possibly on another
55 -- core or another machine. 'id' is a valid implementation
55 -- core or another machine. 'id' is a valid implementation
56 | LVMPtr
56 | LVMPtr
57+ | LNullPtr
57 | LNoOp
58 | LNoOp
58 deriving (Show, Eq)
59 deriving (Show, Eq)
59
60
src/Idris/Primitives.hs+3−1
@@ -169,7 +169,9 @@ primitives =
169 (0, LVMPtr) total,
169 (0, LVMPtr) total,
170 -- Streams
170 -- Streams
171 Prim (UN "prim__stdin") (ty [] PtrType) 0 (p_cantreduce)
171 Prim (UN "prim__stdin") (ty [] PtrType) 0 (p_cantreduce)
172− (0, LStdIn) partial
172+ (0, LStdIn) partial,
173+ Prim (UN "prim__null") (ty [] PtrType) 0 (p_cantreduce)
174+ (0, LNullPtr) total
173 ] ++ concatMap intOps [ITFixed IT8, ITFixed IT16, ITFixed IT32, ITFixed IT64, ITBig, ITNative, ITChar]
175 ] ++ concatMap intOps [ITFixed IT8, ITFixed IT16, ITFixed IT32, ITFixed IT64, ITBig, ITNative, ITChar]
174 ++ concatMap vecOps vecTypes
176 ++ concatMap vecOps vecTypes
175 ++ vecBitcasts vecTypes
177 ++ vecBitcasts vecTypes
test/test033/expectednew file+1
@@ -0,0 +1 @@
1+0
test/test033/runnew file+5
@@ -0,0 +1,5 @@
1+#!/bin/bash
2+gcc -c test033.c
3+idris -o test033 test033.idr
4+./test033
5+rm -f *.ibc *.o test033
test/test033/test033.cnew file+10
@@ -0,0 +1,10 @@
1+#include "test033.h"
2+#include <stddef.h>
3+
4+int testNull(void* p) {
5+ if(p == NULL) {
6+ return 0;
7+ }
8+ return 1;
9+}
10+
test/test033/test033.hnew file+6
@@ -0,0 +1,6 @@
1+#ifndef __TEST033_H__
2+#define __TEST033_H__
3+
4+int testNull(void*);
5+
6+#endif
test/test033/test033.idrnew file+10
@@ -0,0 +1,10 @@
1+module Main
2+
3+%include C "test033.h"
4+%link C "test033.o"
5+
6+testNull : Ptr -> IO Int
7+testNull p = mkForeign (FFun "testNull" [FPtr] FInt) p
8+
9+main : IO ()
10+main = testNull null >>= (putStrLn . show)