Skip to content

Commit

Permalink
Found proper scope for more variables
Browse files Browse the repository at this point in the history
  • Loading branch information
B-rando1 committed Jul 13, 2024
1 parent 95fc057 commit 3b6f656
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 11 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -491,7 +491,7 @@ genClass :: (OOProg r) => (Name -> Maybe Name -> Description -> [CSStateVar r]
genClass f (M.ClassDef n i desc svs cs ms) = let svar Pub = pubDVar
svar Priv = privDVar
in do
svrs <- mapM (\(SV s v) -> fmap (svar s . var' (codeName v) local . -- TODO: get scope from state
svrs <- mapM (\(SV s v) -> fmap (svar s . var' (codeName v) local .
convTypeOO) (codeType v)) svs
f n i desc svrs (mapM (genFunc publicMethod svs) cs)
(mapM (genFunc publicMethod svs) ms)
Expand All @@ -514,7 +514,7 @@ genFunc f svs (FDef (FuncDef n desc parms o rd s)) = do
genFunc _ svs (FDef (CtorDef n desc parms i s)) = do
g <- get
inits <- mapM (convExpr . snd) i
initvars <- mapM ((\iv -> fmap (var' (codeName iv) local . convTypeOO) -- TODO: get scope from state
initvars <- mapM ((\iv -> fmap (var' (codeName iv) local . convTypeOO)
(codeType iv)) . fst) i
stmts <- mapM convStmt s
vars <- mapM mkVar (fstdecl (sysinfodb $ codeSpec g) s
Expand Down
13 changes: 6 additions & 7 deletions code/drasil-code/lib/Language/Drasil/Code/Imperative/Modules.hs
Original file line number Diff line number Diff line change
Expand Up @@ -226,9 +226,9 @@ genInputClass scp = do
genClass inps csts = do
vals <- mapM (convExpr . (^. codeExpr)) csts
inputVars <- mapM (\x -> fmap (pubDVar .
var' (codeName x) local . convTypeOO) (codeType x)) inps -- TODO: get scope from state
var' (codeName x) local . convTypeOO) (codeType x)) inps
constVars <- zipWithM (\c vl -> fmap (\t -> constVarFunc (conRepr g)
(var (codeName c) (convTypeOO t) local) vl) (codeType c)) -- TODO: get scope from state
(var (codeName c) (convTypeOO t) local) vl) (codeType c))
csts vals
let getFunc Primary = primaryClass
getFunc Auxiliary = auxClass
Expand Down Expand Up @@ -414,7 +414,7 @@ genInputFormat s = do
genInFormat _ = do
ins <- getInputFormatIns
outs <- getInputFormatOuts
bod <- readData dd
bod <- readData dd local
desc <- inFmtFuncDesc
mthd <- getFunc s giName desc ins outs bod
return $ Just mthd
Expand Down Expand Up @@ -460,7 +460,7 @@ genConstClass scp = do
genClass [] = return Nothing
genClass vs = do
vals <- mapM (convExpr . (^. codeExpr)) vs
vars <- mapM (\x -> fmap (var' (codeName x) local . convTypeOO) -- TODO: get scope from state
vars <- mapM (\x -> fmap (var' (codeName x) local . convTypeOO)
(codeType x)) vs
let constVars = zipWith (constVarFunc (conRepr g)) vars vals
getFunc Primary = primaryClass
Expand Down Expand Up @@ -561,12 +561,11 @@ genOutputFormat :: (OOProg r) => GenState (Maybe (SMethod r))
genOutputFormat = do
g <- get
woName <- genICName WriteOutput
let genOutput :: (OOProg r) => Maybe String -> GenState
(Maybe (SMethod r))
let genOutput :: (OOProg r) => Maybe String -> GenState (Maybe (SMethod r))
genOutput Nothing = return Nothing
genOutput (Just _) = do
let l_outfile = "outputfile"
var_outfile = var l_outfile outfile local -- TODO: get scope from state
var_outfile = var l_outfile outfile local
v_outfile = valueOf var_outfile
parms <- getOutputParams
outp <- mapM (\x -> do
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -795,9 +795,11 @@ swiftArgVal v' = do
mkVal (valueType v) (swiftInOutArg <> RC.value v)

-- Putting "gool" in these names to avoid name conflicts
-- The `local` is a hack, but Swift doesn't care about scope
-- and I don't want to change the IOStatement API just for this
swiftContentsVar, swiftLineVar :: SVariable SwiftCode
swiftContentsVar = var "goolContents" (listType $ listType string) local -- TODO: get scope from state
swiftLineVar = var "goolLine" (listType string) local -- TODO: get scope from state
swiftContentsVar = var "goolContents" (listType $ listType string) local
swiftLineVar = var "goolLine" (listType string) local

swiftContentsVal, swiftLineVal :: SValue SwiftCode
swiftContentsVal = valueOf swiftContentsVar
Expand Down

0 comments on commit 3b6f656

Please sign in to comment.