Skip to content

Commit

Permalink
Merge pull request #3942 from JacquesCarette/jlSetUpdate
Browse files Browse the repository at this point in the history
Updated Julia to render `Set`s as Sets, not Arrays
  • Loading branch information
JacquesCarette authored Aug 23, 2024
2 parents 801d842 + fc1689f commit e72dd92
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -369,11 +369,11 @@ litArray :: (CommonRenderSym r) => (Doc -> Doc) -> VSType r -> [SValue r] -> SVa
litArray f t es = sequence es >>= (\elems -> mkStateVal (IC.arrayType t)
(f $ valueList elems))

litSet :: (OORenderSym r) => (Doc -> Doc) -> (Doc -> Doc) -> VSType r -> [SValue r] -> SValue r
litSet :: (CommonRenderSym r) => (Doc -> Doc) -> (Doc -> Doc) -> VSType r -> [SValue r] -> SValue r
litSet f1 f2 t es = sequence es >>= (\elems -> mkStateVal (IC.arrayType t)
(f1 $ f2 $ valueList elems))

litSetFunc :: (OORenderSym r) => String -> VSType r -> [SValue r] -> SValue r
litSetFunc :: (CommonRenderSym r) => String -> VSType r -> [SValue r] -> SValue r
litSetFunc s t es = sequence es >>= (\elems -> mkStateVal (IC.arrayType t)
(text s <> parens (valueList elems)))

Expand Down
17 changes: 12 additions & 5 deletions code/drasil-gool/lib/Drasil/GOOL/LanguageRenderer/JuliaRenderer.hs
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ import qualified Drasil.GOOL.LanguageRenderer.CommonPseudoOO as CP (bool,
listSetFunc, notNull, extFuncAppMixedArgs, functionDoc, listSize, listAdd,
listAppend, intToIndex', indexToInt', inOutFunc, docInOutFunc', forLoopError,
varDecDef, openFileR', openFileW', openFileA', multiReturn, multiAssign,
inOutCall, mainBody, argExists, forEach')
inOutCall, mainBody, argExists, forEach', litSet)
import qualified Drasil.GOOL.LanguageRenderer.CLike as C (litTrue, litFalse,
notOp, andOp, orOp, inlineIf, while)
import qualified Drasil.GOOL.LanguageRenderer.AbstractProc as A (fileDoc,
Expand Down Expand Up @@ -181,7 +181,7 @@ instance TypeSym JuliaCode where
infile = jlInfileType
outfile = jlOutfileType
listType = jlListType
setType = listType
setType = jlSetType
arrayType = listType -- Treat arrays and lists the same, as in Python
listInnerType = A.listInnerType
funcType = CP.funcType
Expand Down Expand Up @@ -294,7 +294,7 @@ instance Literal JuliaCode where
litString = G.litString
litArray = litList
litList = jlLitList
litSet = litList
litSet = CP.litSet (text "Set" <>) (parens . brackets)

instance MathConstant JuliaCode where
pi :: SValue JuliaCode
Expand Down Expand Up @@ -399,7 +399,7 @@ instance List JuliaCode where
indexOf = jlIndexOf

instance Set JuliaCode where
contains = jlIndexOf
contains s e = funcApp "in" bool [e, s]

instance InternalList JuliaCode where
listSlice' b e s vn vo = jlListSlice vn vo b e (fromMaybe (litInt 1) s)
Expand Down Expand Up @@ -641,13 +641,14 @@ jlVersion = "1.10.3"

-- Concrete versions of each Julia datatype
jlIntConc, jlFloatConc, jlDoubleConc, jlCharConc, jlStringConc, jlListConc,
jlFile, jlVoid :: String
jlSetConc, jlFile, jlVoid :: String
jlIntConc = "Int64"
jlFloatConc = "Float32"
jlDoubleConc = "Float64"
jlCharConc = "Char"
jlStringConc = "String"
jlListConc = "Array"
jlSetConc = "Set"
jlFile = "IOStream"
jlVoid = "Nothing"

Expand Down Expand Up @@ -956,6 +957,12 @@ jlListType t' = do
let typeName = jlListConc ++ "{" ++ getTypeString t ++ "}"
typeFromData (List $ getType t) typeName (text typeName)

jlSetType :: (CommonRenderSym r) => VSType r -> VSType r
jlSetType t' = do
t <- t'
let typeName = jlSetConc ++ "{" ++ getTypeString t ++ "}"
typeFromData (Set $ getType t) typeName (text typeName)

jlVoidType :: (CommonRenderSym r) => VSType r
jlVoidType = typeFromData Void jlVoid (text jlVoid)

Expand Down

0 comments on commit e72dd92

Please sign in to comment.