Skip to content

Commit

Permalink
Merge branch 'master' into projectileSRS
Browse files Browse the repository at this point in the history
  • Loading branch information
samm82 committed Jun 27, 2019
2 parents d03a0bb + a654a7a commit 33f099e
Show file tree
Hide file tree
Showing 53 changed files with 508 additions and 436 deletions.
37 changes: 11 additions & 26 deletions code/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,8 @@ PACKAGE_GEN_TARGET = BUILD DOC GRAPH
#####

# Current list of examples
EXAMPLES = tiny glassbr nopcm swhs ssp gamephys projectile template
SRC_EXAMPLES = glassbr nopcm
EXAMPLES = $(SRC_EXAMPLES) tiny swhs ssp gamephys projectile template

# where they live
TINY_DIR = Tiny
Expand Down Expand Up @@ -48,9 +49,9 @@ DCP_E_SUFFIX = _deploy_code_path

GEN_EXAMPLES = $(addsuffix $(GEN_E_SUFFIX), $(EXAMPLES))
TEST_EXAMPLES = $(addsuffix $(TEST_E_SUFFIX), $(EXAMPLES))
MOVE_DF_EXAMPLES = $(addsuffix $(MOVE_DF_E_SUFFIX), $(EXAMPLES))
MOVE_DF_EXAMPLES = $(addsuffix $(MOVE_DF_E_SUFFIX), $(SRC_EXAMPLES))
TEX_EXAMPLES = $(addsuffix $(TEX_E_SUFFIX), $(EXAMPLES))
CODE_EXAMPLES = $(addsuffix $(CODE_E_SUFFIX), $(EXAMPLES))
CODE_EXAMPLES = $(addsuffix $(CODE_E_SUFFIX), $(SRC_EXAMPLES))
DCP_EXAMPLES = $(addsuffix $(DCP_E_SUFFIX), $(EXAMPLES))

EXAMPLE_GEN_TARGET = GEN TEST MOVE_DF TEX CODE DCP
Expand Down Expand Up @@ -144,14 +145,13 @@ $(filter %$(GRAPH_P_SUFFIX), $(GRAPH_PACKAGES)): %$(GRAPH_P_SUFFIX): check_stack
graphs: $(GRAPH_PACKAGES)
###

%$(MOVE_DF_E_SUFFIX): EXAMPLE=$(shell echo $* | tr a-z A-Z)
%$(MOVE_DF_E_SUFFIX): EDIR=$($(EXAMPLE)_DIR)
$(filter %$(MOVE_DF_E_SUFFIX), $(MOVE_DF_EXAMPLES)): %$(MOVE_DF_E_SUFFIX): %$(GEN_E_SUFFIX)

# GlassBR is odd, so it needs some special rules just for itself
$(GLASSBR_EXE)$(MOVE_DF_E_SUFFIX): $(GLASSBR_EXE)$(GEN_E_SUFFIX)
test -d $(BUILD_FOLDER)$(GLASSBR_DIR)/$(EXAMPLE_CODE_SUBFOLDER)python && cp ./datafiles/$(GLASSBR_DIR)/*.txt $(BUILD_FOLDER)$(GLASSBR_DIR)/$(EXAMPLE_CODE_SUBFOLDER)python/
test -d $(BUILD_FOLDER)$(GLASSBR_DIR)/$(EXAMPLE_CODE_SUBFOLDER)java && cp ./datafiles/$(GLASSBR_DIR)/*.txt $(BUILD_FOLDER)$(GLASSBR_DIR)/$(EXAMPLE_CODE_SUBFOLDER)java/
test -d $(BUILD_FOLDER)$(GLASSBR_DIR)/$(EXAMPLE_CODE_SUBFOLDER)csharp && cp ./datafiles/$(GLASSBR_DIR)/*.txt $(BUILD_FOLDER)$(GLASSBR_DIR)/$(EXAMPLE_CODE_SUBFOLDER)csharp/
test -d $(BUILD_FOLDER)$(GLASSBR_DIR)/$(EXAMPLE_CODE_SUBFOLDER)cpp && cp ./datafiles/$(GLASSBR_DIR)/*.txt $(BUILD_FOLDER)$(GLASSBR_DIR)/$(EXAMPLE_CODE_SUBFOLDER)cpp/
test -d $(BUILD_FOLDER)$(EDIR)/$(EXAMPLE_CODE_SUBFOLDER)python && cp ./datafiles/$(EDIR)/*.txt $(BUILD_FOLDER)$(EDIR)/$(EXAMPLE_CODE_SUBFOLDER)python/
test -d $(BUILD_FOLDER)$(EDIR)/$(EXAMPLE_CODE_SUBFOLDER)java && cp ./datafiles/$(EDIR)/*.txt $(BUILD_FOLDER)$(EDIR)/$(EXAMPLE_CODE_SUBFOLDER)java/
test -d $(BUILD_FOLDER)$(EDIR)/$(EXAMPLE_CODE_SUBFOLDER)csharp && cp ./datafiles/$(EDIR)/*.txt $(BUILD_FOLDER)$(EDIR)/$(EXAMPLE_CODE_SUBFOLDER)csharp/
test -d $(BUILD_FOLDER)$(EDIR)/$(EXAMPLE_CODE_SUBFOLDER)cpp && cp ./datafiles/$(EDIR)/*.txt $(BUILD_FOLDER)$(EDIR)/$(EXAMPLE_CODE_SUBFOLDER)cpp/

prog: $(MOVE_DF_EXAMPLES)

Expand All @@ -171,22 +171,7 @@ tex: $(TEX_EXAMPLES)
%$(CODE_E_SUFFIX): EXAMPLE=$(shell echo $* | tr a-z A-Z)
%$(CODE_E_SUFFIX): EDIR=$($(EXAMPLE)_DIR)
$(filter %$(CODE_E_SUFFIX), $(CODE_EXAMPLES)): %$(CODE_E_SUFFIX): %$(MOVE_DF_E_SUFFIX)
@EDIR=$(EDIR) BUILD_FOLDER=$(BUILD_FOLDER) EXAMPLE_CODE_SUBFOLDER=$(EXAMPLE_CODE_SUBFOLDER) MAKE="$(MAKE)" "$(SHELL)" $(SCRIPT_FOLDER)code_build.sh; \
# If you're reading this comment because you got NoPCM working, then you should remove everything below this line until the next target. \
# (Next line with zero idents) Additionally you should remove the "; \" from the line immediately preceeding the comment on the previous line. \
RET=$$?; \
if [ $* = $(NOPCM_EXE) ]; then \
if [ $$RET != 0 ]; then \
echo "$(NOPCM_DIR) failed to compile as expected. Letting it slide...for now."; \
exit 0; \
else \
echo "$(NOPCM_DIR) surprisingly did not fail to compile!"; \
echo "Failing this build because you should check the Drasil makefile and alter the code as indicated by the comment for the currently invoked target"; \
exit 1; \
fi; \
else \
exit $$RET; \
fi
@EDIR=$(EDIR) BUILD_FOLDER=$(BUILD_FOLDER) EXAMPLE_CODE_SUBFOLDER=$(EXAMPLE_CODE_SUBFOLDER) MAKE="$(MAKE)" "$(SHELL)" $(SCRIPT_FOLDER)code_build.sh

code: $(CODE_EXAMPLES)

Expand Down
28 changes: 28 additions & 0 deletions code/datafiles/NoPCM/input.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
#Ac (0.12)
0.12
#C_w (4186.0)
4186.0
#hc (1000.0)
1000.0
#Tinit (40.0)
40.0
#tfinal (50000)
50000
#L (1.5)
1.5
#Tc (50.0)
50.0
#tstep (10.0)
10.0
#rho_w (1000.0)
1000.0
#diam (0.412)
0.412
#AbsTol (1e-10)
1e-10
#RelTol (1e-10)
1e-10
#T_W (FIXME: Outputs as inputs hack)
40.0
#E_W (FIXME: Outputs as inputs hack)
0
70 changes: 38 additions & 32 deletions code/drasil-code/Language/Drasil/Code/Imperative/Import.hs
Original file line number Diff line number Diff line change
Expand Up @@ -66,8 +66,8 @@ chooseConstr Exception = constrExc

chooseInStructure :: (RenderSym repr) => Structure -> Reader (State repr)
[repr (Module repr)]
chooseInStructure Loose = genInputModNoClass
chooseInStructure AsClass = genInputModClass
chooseInStructure Unbundled = genInputModNoClass
chooseInStructure Bundled = genInputModClass

chooseLogging :: (RenderSym repr) => Logging -> (repr (Value repr) ->
repr (Value repr) -> Reader (State repr) (repr (Statement repr)))
Expand All @@ -76,8 +76,8 @@ chooseLogging LogAll = loggedAssign
chooseLogging _ = \x y -> return $ assign x y

initLogFileVar :: (RenderSym repr) => Logging -> [repr (Statement repr)]
initLogFileVar LogVar = [varDec "outfile" outfile]
initLogFileVar LogAll = [varDec "outfile" outfile]
initLogFileVar LogVar = [varDec $ var "outfile" outfile]
initLogFileVar LogAll = [varDec $ var "outfile" outfile]
initLogFileVar _ = []


Expand Down Expand Up @@ -201,7 +201,7 @@ genInputModNoClass :: (RenderSym repr) => Reader (State repr)
genInputModNoClass = do
inpDer <- genInputDerived
inpConstr <- genInputConstraints
return [ buildModule "InputParameters" [] []
return [ buildModule "InputParameters" []
(catMaybes [inpDer, inpConstr])
[]
]
Expand Down Expand Up @@ -363,7 +363,7 @@ genOutputFormat = do
] ) (outputs $ csi $ codeSpec g)
mthd <- publicMethod (mState void) "write_output" parms (return [block $
[
varDec l_outfile outfile,
varDec v_outfile,
openFileW v_outfile (litString "output.txt") ] ++
concat outp ++ [ closeFile v_outfile ]])
return $ Just mthd
Expand Down Expand Up @@ -423,7 +423,7 @@ loggedMethod n vals b =
g <- ask
rest <- b
return $ block [
varDec l_outfile outfile,
varDec v_outfile,
openFileA v_outfile (litString $ logName g),
printFileStr v_outfile ("function " ++ n ++ "("),
printParams vals v_outfile,
Expand All @@ -447,7 +447,7 @@ genModule n maybeMs maybeCs = do
updateState = withReader (\s -> s { currentModule = n })
cs <- maybe (return []) updateState maybeCs
ms <- maybe (return []) updateState maybeMs
return $ buildModule n ls [] ms cs
return $ buildModule n ls ms cs


genMain :: (RenderSym repr) => Reader (State repr) (repr (Module repr))
Expand All @@ -474,14 +474,15 @@ getInputDecl :: (RenderSym repr) => Reader (State repr) (Maybe (repr (
getInputDecl = do
g <- ask
let l_params = "inParams"
getDecl :: (RenderSym repr) => Structure -> [CodeChunk] -> Maybe (repr
(Statement repr))
getDecl _ [] = Nothing
getDecl Loose ins = Just $ multi $ map (\x -> varDec (codeName x)
(convType $ codeType x)) ins
getDecl AsClass _ = Just $ extObjDecNewVoid l_params "InputParameters"
(obj "InputParameters")
return $ getDecl (inStruct g) (inputs $ codeSpec g)
getDecl :: (RenderSym repr) => Structure -> [CodeChunk] ->
Reader (State repr) (Maybe (repr (Statement repr)))
getDecl _ [] = return Nothing
getDecl Unbundled ins = do
vals <- mapM (\x -> variable (codeName x) (convType $ codeType x)) ins
return $ Just $ multi $ map varDec vals
getDecl Bundled _ = return $ Just $ extObjDecNewVoid l_params
"InputParameters" (obj "InputParameters")
getDecl (inStruct g) (inputs $ codeSpec g)

getFuncCall :: (RenderSym repr) => String -> repr (StateType repr) ->
Reader (State repr) [ParamData repr] ->
Expand Down Expand Up @@ -543,17 +544,17 @@ getInputFormatIns :: (RenderSym repr) => Reader (State repr)
getInputFormatIns = do
g <- ask
let getIns :: (RenderSym repr) => Structure -> [repr (Value repr)]
getIns Loose = []
getIns AsClass = [var "inParams" (obj "InputParameters")]
getIns Unbundled = []
getIns Bundled = [var "inParams" (obj "InputParameters")]
return $ var "filename" string : getIns (inStruct g)

getInputFormatOuts :: (RenderSym repr) => Reader (State repr)
[repr (Value repr)]
getInputFormatOuts = do
g <- ask
let getOuts :: (RenderSym repr) => Structure -> [repr (Value repr)]
getOuts Loose = toValues $ extInputs $ csi $ codeSpec g
getOuts AsClass = []
getOuts Unbundled = toValues $ extInputs $ csi $ codeSpec g
getOuts Bundled = []
return $ getOuts (inStruct g)

toValues :: (RenderSym repr) => [CodeChunk] -> [repr (Value repr)]
Expand Down Expand Up @@ -622,10 +623,15 @@ variable s' t' = do
Reader (State repr) (repr (Value repr))
doit s t | member s mm =
maybe (error "impossible") (convExpr . codeEquat) (Map.lookup s mm) --extvar "Constants" s
| s `elem` map codeName (inputs cs) = return $ var "inParams"
(obj "InputParameters") $-> var s t
| s `elem` map codeName (inputs cs) = return $ inputVariable
(inStruct g) s t
| otherwise = return $ var s t
doit s' t'

inputVariable :: (RenderSym repr) => Structure -> String ->
repr (StateType repr) -> repr (Value repr)
inputVariable Unbundled s t = var s t
inputVariable Bundled s t = var "inParams" (obj "InputParameters") $-> var s t

fApp :: (RenderSym repr) => String -> String -> repr (StateType repr) ->
[repr (Value repr)] -> Reader (State repr) (repr (Value repr))
Expand Down Expand Up @@ -670,8 +676,8 @@ mkParam p = PD (paramFunc (codeType p) $ var pName pType) pType pName
getInputParams :: (RenderSym repr) => Structure -> [CodeChunk] ->
[ParamData repr]
getInputParams _ [] = []
getInputParams Loose cs = map mkParam cs
getInputParams AsClass _ = [PD (pointerParam $ var pName pType) pType pName]
getInputParams Unbundled cs = map mkParam cs
getInputParams Bundled _ = [PD (pointerParam $ var pName pType) pType pName]
where pName = "inParams"
pType = obj "InputParameters"

Expand Down Expand Up @@ -798,12 +804,10 @@ genFunc (FDef (FuncDef n i o s)) = do
g <- ask
parms <- getParams i
stmts <- mapM convStmt s
vals <- mapM (\x -> variable (codeName x) (convType $ codeType x))
(fstdecl (sysinfodb $ csi $ codeSpec g) s \\ i)
publicMethod (mState $ convType o) n parms
(return [block $
map (\x -> varDec (codeName x) (convType $ codeType x))
(fstdecl (sysinfodb $ csi $ codeSpec g) s \\ i)
++ stmts
])
(return [block $ map varDec vals ++ stmts])
genFunc (FData (FuncData n ddef)) = genDataFunc n ddef
genFunc (FCD cd) = genCalcFunc cd

Expand Down Expand Up @@ -839,7 +843,9 @@ convStmt (FTry t c) = do
convStmt FContinue = return continue
convStmt (FDec v (C.List t)) = return $ listDec (codeName v) 0
(listType dynamic_ (convType t))
convStmt (FDec v t) = return $ varDec (codeName v) (convType t)
convStmt (FDec v t) = do
val <- variable (codeName v) (convType t)
return $ varDec val
convStmt (FProcCall n l) = do
e' <- convExpr (FCall (asExpr n) l)
return $ valState e'
Expand All @@ -863,8 +869,8 @@ readData :: (RenderSym repr) => DataDesc -> Reader (State repr)
readData ddef = do
inD <- mapM inData ddef
return [block $ [
varDec l_infile infile,
varDec l_line string,
varDec v_infile,
varDec v_line,
listDec l_lines 0 (listType dynamic_ string),
listDec l_linetokens 0 (listType dynamic_ string),
openFileR v_infile v_filename ] ++
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,8 +28,8 @@ module Language.Drasil.Code.Imperative.LanguageRenderer (
constDecDefDocD, notNullDocD, listIndexExistsDocD, funcDocD, castDocD,
sizeDocD, listAccessDocD, listSetDocD, objAccessDocD, castObjDocD, includeD,
breakDocD, continueDocD, staticDocD, dynamicDocD, privateDocD, publicDocD,
addCommentsDocD, valList, appendToBody, getterName, setterName,
setMain, setEmpty, statementsToStateVars
addCommentsDocD, valList, prependToBody, appendToBody, surroundBody,
getterName, setterName, setMain, setEmpty
) where

import Utils.Drasil (capitalize, indent, indentList)
Expand Down Expand Up @@ -314,8 +314,8 @@ plusPlusDocD v = valDoc v <> text "++"
plusPlusDocD' :: ValData -> Doc -> Doc
plusPlusDocD' v plusOp = valDoc v <+> equals <+> valDoc v <+> plusOp <+> int 1

varDecDocD :: Label -> TypeData -> Doc
varDecDocD l st = typeDoc st <+> text l
varDecDocD :: ValData -> Doc
varDecDocD v = typeDoc (valType v) <+> valDoc v

varDecDefDocD :: Label -> TypeData -> ValData -> Doc
varDecDefDocD l st v = typeDoc st <+> text l <+> equals <+> valDoc v
Expand Down Expand Up @@ -655,10 +655,17 @@ dashes s l = replicate (l - length s) '-'
valList :: [ValData] -> Doc
valList vs = hcat (intersperse (text ", ") (map valDoc vs))

prependToBody :: (Doc, Terminator) -> Doc -> Doc
prependToBody s b = vcat [fst $ statementDocD s, maybeBlank, b]
where maybeBlank = if isEmpty b then empty else blank

appendToBody :: Doc -> (Doc, Terminator) -> Doc
appendToBody b s = vcat [b, maybeBlank, fst $ statementDocD s]
where maybeBlank = if isEmpty b then empty else blank

surroundBody :: (Doc, Terminator) -> Doc -> (Doc, Terminator) -> Doc
surroundBody p b a = prependToBody p (appendToBody b a)

getterName :: String -> String
getterName s = "Get" ++ capitalize s

Expand All @@ -669,8 +676,4 @@ setMain :: (Doc, Bool) -> (Doc, Bool)
setMain (d, _) = (d, True)

setEmpty :: (Doc, Terminator) -> (Doc, Terminator)
setEmpty (d, _) = (d, Empty)

-- Hack because modules accept Statement representations of their state variables. Modules should be redesigned/rethought
statementsToStateVars :: Doc -> Doc -> Doc -> (Doc, Terminator) -> Doc
statementsToStateVars s p end (v, _) = s <+> p <+> v <> end
setEmpty (d, _) = (d, Empty)
Original file line number Diff line number Diff line change
Expand Up @@ -38,8 +38,8 @@ import Language.Drasil.Code.Imperative.LanguageRenderer (
notNullDocD, listIndexExistsDocD, funcDocD, castDocD, listSetDocD,
listAccessDocD, objAccessDocD, castObjDocD, breakDocD, continueDocD,
staticDocD, dynamicDocD, privateDocD, publicDocD, dot, new, observerListName,
doubleSlash, addCommentsDocD, valList, appendToBody, getterName, setterName,
setMain, setEmpty, statementsToStateVars)
doubleSlash, addCommentsDocD, valList, surroundBody, getterName, setterName,
setMain, setEmpty)
import Language.Drasil.Code.Imperative.Helpers (Terminator(..), FuncData(..),
fd, ModData(..), md, TypeData(..), td, ValData(..), vd, updateValDoc, liftA4,
liftA5, liftA6, liftA7, liftList, lift1List, lift3Pair, lift4Pair,
Expand Down Expand Up @@ -346,7 +346,7 @@ instance StatementSym CSharpCode where
(&++) v = mkSt <$> fmap plusPlusDocD v
(&~-) v = v &= (v #- litInt 1)

varDec l t = mkSt <$> fmap (varDecDocD l) t
varDec v = mkSt <$> fmap varDecDocD v
varDecDef l t v = mkSt <$> liftA2 (varDecDefDocD l) t v
listDec l n t = mkSt <$> liftA2 (listDecDocD l) (litInt n) t -- this means that the type you declare must already be a list. Not sure how I feel about this. On the bright side, it also means you don't need to pass permanence
listDecDef l t vs = mkSt <$> lift1List (listDecDefDocD l) t vs
Expand Down Expand Up @@ -520,10 +520,10 @@ instance MethodSym CSharpCode where
function n = method n ""

inOutFunc n s p ins [v] b = function n s p (mState (fmap valType v))
(map stateParam ins) (liftA2 appendToBody b $ returnState v)
inOutFunc n s p ins outs b = function n s p (mState void) (nub $ map (\v ->
(map stateParam ins) (liftA3 surroundBody (varDec v) b (returnState v))
inOutFunc n s p ins outs b = function n s p (mState void) (map (\v ->
if v `elem` outs then fmap csRef (stateParam v) else stateParam v) ins ++
map (fmap csRef . stateParam) outs) b
map (fmap csOut . stateParam) (filter (`notElem` ins) outs)) b

instance StateVarSym CSharpCode where
type StateVar CSharpCode = Doc
Expand All @@ -547,10 +547,9 @@ instance ClassSym CSharpCode where

instance ModuleSym CSharpCode where
type Module CSharpCode = ModData
buildModule n _ vs ms cs = fmap (md n (any (snd . unCSC) ms ||
any (snd . unCSC) cs)) (liftList moduleDocD (if null vs && null ms then cs
else pubClass n Nothing (map (liftA4 statementsToStateVars public static_
endStatement) vs) ms : cs))
buildModule n _ ms cs = fmap (md n (any (snd . unCSC) ms ||
any (snd . unCSC) cs)) (liftList moduleDocD (if null ms then cs
else pubClass n Nothing [] ms : cs))

cstop :: Doc -> Doc -> Doc
cstop end inc = vcat [
Expand Down Expand Up @@ -602,11 +601,14 @@ csOpenFileWorA f n w a = valDoc f <+> equals <+> new <+> typeDoc w <>
csRef :: Doc -> Doc
csRef p = text "ref" <+> p

csOut :: Doc -> Doc
csOut p = text "out" <+> p

csInOutCall :: (Label -> CSharpCode (StateType CSharpCode) ->
[CSharpCode (Value CSharpCode)] -> CSharpCode (Value CSharpCode)) -> Label ->
[CSharpCode (Value CSharpCode)] -> [CSharpCode (Value CSharpCode)] ->
CSharpCode (Statement CSharpCode)
csInOutCall f n ins [out] = assign out $ f n (fmap valType out) ins
csInOutCall f n ins outs = valState $ f n void (nub $ map (\v ->
if v `elem` outs then fmap (updateValDoc csRef) v else v) ins ++
map (fmap (updateValDoc csRef)) outs)
map (fmap (updateValDoc csOut)) (filter (`notElem` ins) outs))
Loading

0 comments on commit 33f099e

Please sign in to comment.