Skip to content

Commit

Permalink
Added Sets in Swift
Browse files Browse the repository at this point in the history
  • Loading branch information
NoahCardoso committed Jul 23, 2024
1 parent ec3fccc commit 51c6c77
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -316,7 +316,7 @@ instance Literal JavaCode where
litInt = G.litInt
litString = G.litString
litArray = CP.litArray braces
litSet = CP.litSetFunc "Set.of"
litSet = CP.litSetFunc jSetOf

litList t es = do
zoom lensVStoMS $ modify (if null es then id else addLangImport $ utilImport
Expand Down
18 changes: 12 additions & 6 deletions code/drasil-gool/lib/GOOL/Drasil/LanguageRenderer/SwiftRenderer.hs
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ import GOOL.Drasil.RendererClasses (MSMthdType, RenderSym,
import qualified GOOL.Drasil.RendererClasses as RC (import', perm, body, block,
type', uOp, bOp, variable, value, function, statement, scope, parameter,
method, stateVar, class', module', blockComment')
import GOOL.Drasil.LanguageRenderer (dot, blockCmtStart, blockCmtEnd,
import GOOL.Drasil.LanguageRenderer (valueList, dot, blockCmtStart, blockCmtEnd,
docCmtStart, bodyStart, bodyEnd, commentStart, elseIfLabel, forLabel,
inLabel, tryLabel, catchLabel, throwLabel, throwsLabel, importLabel, listSep',
printLabel, listSep, piLabel, access, tuple, FuncDocRenderer,
Expand All @@ -70,9 +70,9 @@ import qualified GOOL.Drasil.LanguageRenderer.LanguagePolymorphic as G (
function, docFunc, buildClass, implementingClass, docClass, commentedClass,
modFromData, fileDoc, fileFromData, defaultOptSpace)
import qualified GOOL.Drasil.LanguageRenderer.CommonPseudoOO as CP (classVar,
objVarSelf, intClass, buildModule, docMod', bindingError, extFuncAppMixedArgs,
objVarSelf, intClass, buildModule, docMod', contains, bindingError, extFuncAppMixedArgs,
notNull, listDecDef, destructorError, stateVarDef, constVar, litArray, litSet,
listSetFunc, extraClass, listAccessFunc, doubleRender, double, openFileR,
listSetFunc, litSetFunc, extraClass, listAccessFunc, doubleRender, double, openFileR,
openFileW, self, multiAssign, multiReturn, listDec, funcDecDef,
inOutCall, forLoopError, mainBody, inOutFunc, docInOutFunc', bool, float,
stringRender', string', inherit, implements, intToIndex, indexToInt)
Expand Down Expand Up @@ -312,7 +312,7 @@ instance Literal SwiftCode where
litInt = G.litInt
litString = G.litString
litArray = CP.litArray brackets
litSet = CP.litSet braces
litSet = swiftLitSetFunc swiftSet
litList = litArray

instance MathConstant SwiftCode where
Expand Down Expand Up @@ -443,7 +443,7 @@ instance List SwiftCode where
indexOf = swiftIndexOf

instance Set SwiftCode where
contains = swiftIndexOf
contains = CP.contains swiftContains

instance InternalList SwiftCode where
listSlice' b e s vn vo = swiftListSlice vn vo b e (fromMaybe (litInt 1) s)
Expand Down Expand Up @@ -870,7 +870,7 @@ swiftMain, swiftFoundation, swiftMath, swiftNil, swiftInt, swiftChar,
swiftSeekEnd, swiftClose, swiftJoined, swiftAppendPath, swiftUrls, swiftSplit,
swiftData, swiftEncoding, swiftOf, swiftFrom, swiftTo, swiftBy, swiftAt,
swiftTerm, swiftFor, swiftIn, swiftContentsOf, swiftWriteTo, swiftSep,
swiftSepBy, swiftUnwrap :: String
swiftSepBy, swiftUnwrap, swiftContains, swiftSet :: String
swiftMain = "main"
swiftFoundation = "Foundation"
swiftMath = swiftFoundation
Expand Down Expand Up @@ -913,6 +913,8 @@ swiftWriteTo = "forWritingTo"
swiftSep = "separator"
swiftSepBy = "separatedBy"
swiftUnwrap = "!"
swiftContains = "contains"
swiftSet = "Set"

swiftUnaryMath :: (Monad r) => String -> VSOp r
swiftUnaryMath = addMathImport . unOpPrec
Expand Down Expand Up @@ -943,6 +945,10 @@ swiftLambda ps ex = braces $ parens (hicat listSep'
swiftReadableTypes :: [CodeType]
swiftReadableTypes = [Integer, Double, Float, Boolean, Char]

swiftLitSetFunc :: (RenderSym r) => String -> VSType r -> [SValue r] -> SValue r
swiftLitSetFunc s t es = sequence es >>= (\elems -> mkStateVal (arrayType t)
(text s <> parens (brackets (valueList elems))))

swiftCast :: (RenderSym r) => VSType r -> SValue r -> SValue r
swiftCast t' v' = do
t <- t'
Expand Down

0 comments on commit 51c6c77

Please sign in to comment.