on master help sign in
switch from makeByteString to bytestring constructor
40e1d8aAgentM
project-m36.cabal+1
@@ -128,6 +128,7 @@ Library
128 ProjectM36.DataTypes.List,
128 ProjectM36.DataTypes.List,
129 ProjectM36.DataTypes.Primitive,
129 ProjectM36.DataTypes.Primitive,
130 ProjectM36.DataTypes.Interval,
130 ProjectM36.DataTypes.Interval,
131+ ProjectM36.DataTypes.ByteString,
131 ProjectM36.MiscUtils,
132 ProjectM36.MiscUtils,
132 ProjectM36.Notifications,
133 ProjectM36.Notifications,
133 ProjectM36.Relation,
134 ProjectM36.Relation,
src/lib/ProjectM36/AtomFunctions/Basic.hs+2
@@ -5,6 +5,7 @@ import ProjectM36.DataTypes.Day
5import ProjectM36.DataTypes.Either
5import ProjectM36.DataTypes.Either
6import ProjectM36.DataTypes.Maybe
6import ProjectM36.DataTypes.Maybe
7import ProjectM36.DataTypes.Interval
7import ProjectM36.DataTypes.Interval
8+import ProjectM36.DataTypes.ByteString
8import ProjectM36.AtomFunctions.Primitive
9import ProjectM36.AtomFunctions.Primitive
9import ProjectM36.AtomFunction
10import ProjectM36.AtomFunction
10import ProjectM36.DataTypes.List
11import ProjectM36.DataTypes.List
@@ -18,6 +19,7 @@ basicAtomFunctions = HS.unions [primitiveAtomFunctions,
18 eitherAtomFunctions,
19 eitherAtomFunctions,
19 maybeAtomFunctions,
20 maybeAtomFunctions,
20 listAtomFunctions,
21 listAtomFunctions,
22+ bytestringAtomFunctions,
21 intervalAtomFunctions]
23 intervalAtomFunctions]
22
24
23--these special atom functions aren't scripted so they can't be serialized normally. Instead, the body remains in the binary and the serialization/deserialization happens by name only.
25--these special atom functions aren't scripted so they can't be serialized normally. Instead, the body remains in the binary and the serialization/deserialization happens by name only.
src/lib/ProjectM36/AtomFunctions/Primitive.hs+1−8
@@ -6,8 +6,6 @@ import ProjectM36.AtomFunctionError
6import ProjectM36.AtomFunction
6import ProjectM36.AtomFunction
7import qualified Data.HashSet as HS
7import qualified Data.HashSet as HS
8import qualified Data.Vector as V
8import qualified Data.Vector as V
9−import qualified Data.ByteString.Base64 as B64
10−import qualified Data.Text.Encoding as TE
11import Control.Monad
9import Control.Monad
12
10
13primitiveAtomFunctions :: AtomFunctions
11primitiveAtomFunctions :: AtomFunctions
@@ -45,12 +43,7 @@ primitiveAtomFunctions = HS.fromList [
45 atomFuncBody = body $ intAtomFuncLessThan True >=> boolAtomNot},
43 atomFuncBody = body $ intAtomFuncLessThan True >=> boolAtomNot},
46 AtomFunction { atomFuncName = "not",
44 AtomFunction { atomFuncName = "not",
47 atomFuncType = [BoolAtomType, BoolAtomType],
45 atomFuncType = [BoolAtomType, BoolAtomType],
48− atomFuncBody = body $ \(b:_) -> boolAtomNot b },
46+ atomFuncBody = body $ \(b:_) -> boolAtomNot b }
49− AtomFunction { atomFuncName = "makeByteString",
50− atomFuncType = [TextAtomType, ByteStringAtomType],
51− atomFuncBody = body $ \(TextAtom textIn:_) -> case B64.decode (TE.encodeUtf8 textIn) of
52− Left err -> Left (AtomFunctionBytesDecodingError err)
53− Right bs -> pure (ByteStringAtom bs) }
54 ]
47 ]
55 where
48 where
56 body = AtomFunctionBody Nothing
49 body = AtomFunctionBody Nothing
src/lib/ProjectM36/DataTypes/ByteString.hsnew file+18
@@ -0,0 +1,18 @@
1+module ProjectM36.DataTypes.ByteString where
2+import ProjectM36.Base
3+import ProjectM36.AtomFunctionError
4+import ProjectM36.AtomFunctionBody
5+import qualified Data.HashSet as HS
6+import qualified Data.ByteString.Base64 as B64
7+import qualified Data.Text.Encoding as TE
8+
9+bytestringAtomFunctions :: AtomFunctions
10+bytestringAtomFunctions = HS.fromList [
11+ AtomFunction { atomFuncName = "bytestring",
12+ atomFuncType = [TextAtomType, ByteStringAtomType],
13+ atomFuncBody = compiledAtomFunctionBody $ \(TextAtom textIn:_) -> case B64.decode (TE.encodeUtf8 textIn) of
14+ Left err -> Left (AtomFunctionBytesDecodingError err)
15+ Right bs -> pure (ByteStringAtom bs)
16+ }
17+ ]
18+
src/lib/ProjectM36/DataTypes/Interval.hs−2
@@ -7,8 +7,6 @@ import ProjectM36.DataTypes.Primitive
7import ProjectM36.AtomFunctionError
7import ProjectM36.AtomFunctionError
8import qualified Data.HashSet as HS
8import qualified Data.HashSet as HS
9
9
10−import Debug.Trace
11−
12-- in lieu of typeclass support, we just hard-code the types which can be part of an interval
10-- in lieu of typeclass support, we just hard-code the types which can be part of an interval
13supportsInterval :: AtomType -> Bool
11supportsInterval :: AtomType -> Bool
14supportsInterval typ = case typ of
12supportsInterval typ = case typ of
test/TutorialD/Interpreter.hs+1−1
@@ -118,7 +118,7 @@ main = do
118 ("x:=s; key testconstraint {s#,city} x; insert x relation{tuple{city \"London\", s# \"S1\", sname \"gonk\", status 50}}", Left (InclusionDependencyCheckError "testconstraint")),
118 ("x:=s; key testconstraint {s#,city} x; insert x relation{tuple{city \"London\", s# \"S1\", sname \"gonk\", status 50}}", Left (InclusionDependencyCheckError "testconstraint")),
119 ("y:=s; key testconstraint {s#} y; insert y relation{tuple{city \"London\", s# \"S6\", sname \"gonk\", status 50}}; x:=y{s#} = s{s#} union relation{tuple{s# \"S6\"}}", Right relationTrue),
119 ("y:=s; key testconstraint {s#} y; insert y relation{tuple{city \"London\", s# \"S6\", sname \"gonk\", status 50}}; x:=y{s#} = s{s#} union relation{tuple{s# \"S6\"}}", Right relationTrue),
120 --test binary bytestring data type
120 --test binary bytestring data type
121− ("x:=relation{tuple{y makeByteString(\"dGVzdGRhdGE=\")}}", mkRelationFromList byteStringAttributes [[ByteStringAtom (TE.encodeUtf8 "testdata")]]),
121+ ("x:=relation{tuple{y bytestring(\"dGVzdGRhdGE=\")}}", mkRelationFromList byteStringAttributes [[ByteStringAtom (TE.encodeUtf8 "testdata")]]),
122 --test Maybe Text
122 --test Maybe Text
123 ("x:=relation{tuple{a Just \"spam\"}}", mkRelationFromList simpleMaybeTextAttributes [[ConstructedAtom "Just" maybeTextAtomType [TextAtom "spam"]]]),
123 ("x:=relation{tuple{a Just \"spam\"}}", mkRelationFromList simpleMaybeTextAttributes [[ConstructedAtom "Just" maybeTextAtomType [TextAtom "spam"]]]),
124 --test Maybe Int
124 --test Maybe Int