on master help sign in
switch from makeByteString to bytestring constructor

this makes the bytestring constructor more in line with other non-primitive constructor functions

commit40e1d8adc3dce3f1faa38a6fd9600762d7a71bf0 authorAgentM <agentm@themactionfaction.com> dateWed 9 Aug 2017, 15:12 (9 years ago) parentc4193de
6 files changed+23−11
project-m36.cabal+1 src/lib/ProjectM36/AtomFunctions/Basic.hs+2 src/lib/ProjectM36/AtomFunctions/Primitive.hs+1−8 src/lib/ProjectM36/DataTypes/ByteString.hs+18 src/lib/ProjectM36/DataTypes/Interval.hs−2 test/TutorialD/Interpreter.hs+1−1
project-m36.cabal+1
@@ -128,6 +128,7 @@ Library
128128 ProjectM36.DataTypes.List,
129129 ProjectM36.DataTypes.Primitive,
130130 ProjectM36.DataTypes.Interval,
131+ ProjectM36.DataTypes.ByteString,
131132 ProjectM36.MiscUtils,
132133 ProjectM36.Notifications,
133134 ProjectM36.Relation,
src/lib/ProjectM36/AtomFunctions/Basic.hs+2
@@ -5,6 +5,7 @@ import ProjectM36.DataTypes.Day
55import ProjectM36.DataTypes.Either
66import ProjectM36.DataTypes.Maybe
77import ProjectM36.DataTypes.Interval
8+import ProjectM36.DataTypes.ByteString
89import ProjectM36.AtomFunctions.Primitive
910import ProjectM36.AtomFunction
1011import ProjectM36.DataTypes.List
@@ -18,6 +19,7 @@ basicAtomFunctions = HS.unions [primitiveAtomFunctions,
1819 eitherAtomFunctions,
1920 maybeAtomFunctions,
2021 listAtomFunctions,
22+ bytestringAtomFunctions,
2123 intervalAtomFunctions]
2224
2325--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
66import ProjectM36.AtomFunction
77import qualified Data.HashSet as HS
88import qualified Data.Vector as V
9−import qualified Data.ByteString.Base64 as B64
10−import qualified Data.Text.Encoding as TE
119import Control.Monad
1210
1311primitiveAtomFunctions :: AtomFunctions
@@ -45,12 +43,7 @@ primitiveAtomFunctions = HS.fromList [
4543 atomFuncBody = body $ intAtomFuncLessThan True >=> boolAtomNot},
4644 AtomFunction { atomFuncName = "not",
4745 atomFuncType = [BoolAtomType, BoolAtomType],
48− 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) }
46+ atomFuncBody = body $ \(b:_) -> boolAtomNot b }
5447 ]
5548 where
5649 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
77import ProjectM36.AtomFunctionError
88import qualified Data.HashSet as HS
99
10−import Debug.Trace
11−
1210-- in lieu of typeclass support, we just hard-code the types which can be part of an interval
1311supportsInterval :: AtomType -> Bool
1412supportsInterval typ = case typ of
test/TutorialD/Interpreter.hs+1−1
@@ -118,7 +118,7 @@ main = do
118118 ("x:=s; key testconstraint {s#,city} x; insert x relation{tuple{city \"London\", s# \"S1\", sname \"gonk\", status 50}}", Left (InclusionDependencyCheckError "testconstraint")),
119119 ("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),
120120 --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")]]),
122122 --test Maybe Text
123123 ("x:=relation{tuple{a Just \"spam\"}}", mkRelationFromList simpleMaybeTextAttributes [[ConstructedAtom "Just" maybeTextAtomType [TextAtom "spam"]]]),
124124 --test Maybe Int