Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Created ScopeData for Julia's Scope #3890

Merged
merged 5 commits into from
Jul 28, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
29 changes: 19 additions & 10 deletions code/drasil-gool/lib/Drasil/GOOL/AST.hs
Original file line number Diff line number Diff line change
@@ -1,13 +1,14 @@
module Drasil.GOOL.AST (Terminator(..), VisibilityTag(..), QualifiedName, qualName,
FileType(..), isSource, Binding(..), onBinding, BindData(bind, bindDoc), bd,
FileData(filePath, fileMod), fileD, updateFileMod, FuncData(fType, funcDoc),
fd, ModData(name, modDoc), md, updateMod, MethodData(mthdDoc), mthd,
updateMthd, OpData(opPrec, opDoc), od, ParamData(paramVar, paramDoc), pd,
paramName, updateParam, ProgData(progName, progPurp, progMods), progD, emptyProg,
StateVarData(getStVarScp, stVar, destructSts), svd,
TypeData(cType, typeString, typeDoc), td, ValData(valPrec, valInt, valType, val),
vd, updateValDoc, VarData(varBind, varName, varType, varDoc), vard,
CommonThunk, pureValue, vectorize, vectorize2, sumComponents, commonVecIndex,
module Drasil.GOOL.AST (Terminator(..), VisibilityTag(..), ScopeTag(..),
ScopeData(..), sd, QualifiedName, qualName, FileType(..), isSource,
Binding(..), onBinding, BindData(bind, bindDoc), bd, FileData(filePath,
fileMod), fileD, updateFileMod, FuncData(fType, funcDoc), fd, ModData(name,
modDoc), md, updateMod, MethodData(mthdDoc), mthd, updateMthd, OpData(opPrec,
opDoc), od, ParamData(paramVar, paramDoc), pd, paramName, updateParam,
ProgData(progName, progPurp, progMods), progD, emptyProg,
StateVarData(getStVarScp, stVar, destructSts), svd, TypeData(cType,
typeString, typeDoc), td, ValData(valPrec, valInt, valType, val), vd,
updateValDoc, VarData(varBind, varName, varType, varDoc), vard, CommonThunk,
pureValue, vectorize, vectorize2, sumComponents, commonVecIndex,
commonThunkElim, commonThunkDim
) where

Expand Down Expand Up @@ -122,6 +123,14 @@ data StateVarData = SVD {getStVarScp :: VisibilityTag, stVar :: Doc,
svd :: VisibilityTag -> Doc -> (Doc, Terminator) -> StateVarData
svd = SVD

-- Used as the underlying data type for Scopes in the Julia renderer
data ScopeTag = Local | Global

newtype ScopeData = SD {scopeTag :: ScopeTag}

sd :: ScopeTag -> ScopeData
sd = SD

-- Used as the underlying data type for Types in all renderers
data TypeData = TD {cType :: CodeType, typeString :: String, typeDoc :: Doc}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -71,15 +71,15 @@ import qualified Drasil.GOOL.LanguageRenderer.LanguagePolymorphic as G (
increment, objDecNew, print, closeFile, returnStmt, valStmt,
comment, throw, ifCond, tryCatch, construct, param, method, getMethod,
setMethod, function, buildClass, implementingClass, commentedClass,
modFromData, fileDoc, fileFromData, defaultOptSpace)
modFromData, fileDoc, fileFromData, defaultOptSpace, local)
import qualified Drasil.GOOL.LanguageRenderer.CommonPseudoOO as CP (int,
constructor, doxFunc, doxClass, doxMod, extVar, classVar, objVarSelf,
extFuncAppMixedArgs, indexOf, listAddFunc, discardFileLine, intClass,
arrayType, pi, printSt, arrayDec, arrayDecDef, openFileA, forEach, docMain,
mainFunction, buildModule', string, constDecDef, docInOutFunc, bindingError,
notNull, listDecDef, destructorError, stateVarDef, constVar, listSetFunc,
extraClass, listAccessFunc, doubleRender, openFileR, openFileW, stateVar,
inherit, implements, intToIndex, indexToInt)
inherit, implements, intToIndex, indexToInt, global)
import qualified Drasil.GOOL.LanguageRenderer.CLike as C (float, double, char,
listType, void, notOp, andOp, orOp, self, litTrue, litFalse, litFloat,
inlineIf, libFuncAppMixedArgs, libNewObjMixedArgs, listSize, increment1,
Expand All @@ -93,7 +93,7 @@ import Drasil.GOOL.AST (Terminator(..), FileType(..), FileData(..), fileD,
updateMthd, OpData(..), ParamData(..), pd, updateParam, ProgData(..), progD,
TypeData(..), td, ValData(..), vd, updateValDoc, Binding(..), VarData(..),
vard, CommonThunk, pureValue, vectorize, vectorize2, sumComponents,
commonVecIndex, commonThunkElim, commonThunkDim)
commonVecIndex, commonThunkElim, commonThunkDim, ScopeData)
import Drasil.GOOL.Helpers (angles, hicat, toCode, toState, onCodeValue,
onStateValue, on2CodeValues, on2StateValues, on3CodeValues, on3StateValues,
on2StateWrapped, onCodeList, onStateList)
Expand Down Expand Up @@ -268,10 +268,10 @@ instance OpElim CSharpCode where
bOpPrec = opPrec . unCSC

instance ScopeSym CSharpCode where
type Scope CSharpCode = Doc
global = toCode empty
mainFn = toCode empty
local = toCode empty
type Scope CSharpCode = ScopeData
global = CP.global
mainFn = local
local = G.local

instance VariableSym CSharpCode where
type Variable CSharpCode = VarData
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ module Drasil.GOOL.LanguageRenderer.CommonPseudoOO (int, constructor, doxFunc,
forLoopError, mainBody, inOutFunc, docInOutFunc', boolRender, bool,
floatRender, float, stringRender', string', inherit, implements, listSize,
listAdd, listAppend, intToIndex, indexToInt, intToIndex', indexToInt',
varDecDef, openFileR', openFileW', openFileA', argExists
varDecDef, openFileR', openFileW', openFileA', argExists, global
) where

import Utils.Drasil (indent, stringList)
Expand Down Expand Up @@ -63,7 +63,7 @@ import Drasil.GOOL.LanguageRenderer.Constructors (mkStmt, mkStmtNoEnd,
mkStateVal, mkStateVar, mkVal, mkVal)
import Drasil.GOOL.LanguageRenderer.LanguagePolymorphic (classVarCheckStatic,
call, initStmts, docFunc, docFuncRepr, docClass, docMod, smartAdd, smartSub)
import Drasil.GOOL.AST (VisibilityTag(..))
import Drasil.GOOL.AST (VisibilityTag(..), ScopeTag(Global), ScopeData, sd)
import Drasil.GOOL.State (FS, CS, lensFStoCS, lensFStoMS, lensCStoMS,
lensMStoVS, lensVStoMS, currParameters, getClassName, getLangImports,
getLibImports, getModuleImports, setClassName, setCurrMain, setMainDoc,
Expand Down Expand Up @@ -91,6 +91,10 @@ intToIndex = id
indexToInt :: SValue r -> SValue r
indexToInt = id

-- Global for langauges that don't use declarations for them
global :: (Monad r) => r ScopeData
global = toCode $ sd Global

-- Python, Java, C#, and C++ --

intRender :: String
Expand Down
24 changes: 12 additions & 12 deletions code/drasil-gool/lib/Drasil/GOOL/LanguageRenderer/CppRenderer.hs
Original file line number Diff line number Diff line change
Expand Up @@ -74,12 +74,12 @@ import qualified Drasil.GOOL.LanguageRenderer.LanguagePolymorphic as G (
increment, objDecNew, print, closeFile, returnStmt, valStmt, comment, throw,
ifCond, tryCatch, construct, param, method, getMethod, setMethod, function,
buildClass, implementingClass, commentedClass, modFromData, fileDoc,
fileFromData, defaultOptSpace)
fileFromData, defaultOptSpace, local)
import Drasil.GOOL.LanguageRenderer.LanguagePolymorphic (classVarCheckStatic)
import qualified Drasil.GOOL.LanguageRenderer.CommonPseudoOO as CP (int,
constructor, doxFunc, doxClass, doxMod, funcType, buildModule, litArray,
call', listSizeFunc, listAccessFunc', string, constDecDef, docInOutFunc,
listSetFunc, extraClass, intToIndex, indexToInt)
listSetFunc, extraClass, intToIndex, indexToInt, global)
import qualified Drasil.GOOL.LanguageRenderer.CLike as C (charRender, float,
double, char, listType, void, notOp, andOp, orOp, self, litTrue, litFalse,
litFloat, inlineIf, libFuncAppMixedArgs, libNewObjMixedArgs, listSize,
Expand All @@ -92,7 +92,7 @@ import Drasil.GOOL.AST (Terminator(..), VisibilityTag(..), Binding(..), onBindin
ModData(..), md, updateMod, OpData(..), ParamData(..), pd, ProgData(..),
progD, emptyProg, StateVarData(..), svd, TypeData(..), td, ValData(..), vd,
VarData(..), vard, CommonThunk, pureValue, vectorize, vectorize2,
sumComponents, commonVecIndex, commonThunkElim, commonThunkDim)
sumComponents, commonVecIndex, commonThunkElim, commonThunkDim, ScopeData)
import Drasil.GOOL.Classes (Pair(..))
import Drasil.GOOL.Helpers (angles, doubleQuotedText, hicat, vibcat,
emptyIfEmpty, toCode, toState, onCodeValue, onStateValue, on2CodeValues,
Expand Down Expand Up @@ -277,7 +277,7 @@ instance (Pair p) => OpElim (p CppSrcCode CppHdrCode) where
bOpPrec o = bOpPrec $ pfst o

instance (Pair p) => ScopeSym (p CppSrcCode CppHdrCode) where
type Scope (p CppSrcCode CppHdrCode) = Doc
type Scope (p CppSrcCode CppHdrCode) = ScopeData
global = pair global global
mainFn = pair mainFn mainFn
local = pair local local
Expand Down Expand Up @@ -1174,10 +1174,10 @@ instance OpElim CppSrcCode where
bOpPrec = opPrec . unCPPSC

instance ScopeSym CppSrcCode where
type Scope CppSrcCode = Doc
global = toCode empty
mainFn = toCode empty
local = toCode empty
type Scope CppSrcCode = ScopeData
global = CP.global
mainFn = local
local = G.local

instance VariableSym CppSrcCode where
type Variable CppSrcCode = VarData
Expand Down Expand Up @@ -1885,10 +1885,10 @@ instance OpElim CppHdrCode where
bOpPrec = opPrec . unCPPHC

instance ScopeSym CppHdrCode where
type Scope CppHdrCode = Doc
global = toCode empty
mainFn = toCode empty
local = toCode empty
type Scope CppHdrCode = ScopeData
global = CP.global
mainFn = local
local = G.local

instance VariableSym CppHdrCode where
type Variable CppHdrCode = VarData
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ import qualified Drasil.GOOL.LanguageRenderer.LanguagePolymorphic as G (
increment, objDecNew, print, closeFile, returnStmt, valStmt, comment, throw,
ifCond, tryCatch, construct, param, method, getMethod, setMethod, function,
buildClass, implementingClass, commentedClass, modFromData, fileDoc,
fileFromData, defaultOptSpace)
fileFromData, defaultOptSpace, local)
import Drasil.GOOL.LanguageRenderer.LanguagePolymorphic (docFuncRepr)
import qualified Drasil.GOOL.LanguageRenderer.CommonPseudoOO as CP (int,
constructor, doxFunc, doxClass, doxMod, extVar, classVar, objVarSelf,
Expand All @@ -83,7 +83,7 @@ import qualified Drasil.GOOL.LanguageRenderer.CommonPseudoOO as CP (int,
docMain, mainFunction, buildModule', bindingError, listDecDef,
destructorError, stateVarDef, constVar, litArray, call', listSizeFunc,
listAccessFunc', notNull, doubleRender, double, openFileR, openFileW,
stateVar, floatRender, float, string', intToIndex, indexToInt)
stateVar, floatRender, float, string', intToIndex, indexToInt, global)
import qualified Drasil.GOOL.LanguageRenderer.CLike as C (float, double, char,
listType, void, notOp, andOp, orOp, self, litTrue, litFalse, litFloat,
inlineIf, libFuncAppMixedArgs, libNewObjMixedArgs, listSize, increment1,
Expand All @@ -97,7 +97,7 @@ import Drasil.GOOL.AST (Terminator(..), VisibilityTag(..), qualName,
updateMod, MethodData(..), mthd, updateMthd, OpData(..), ParamData(..), pd,
ProgData(..), progD, TypeData(..), td, ValData(..), vd, VarData(..), vard,
CommonThunk, pureValue, vectorize, vectorize2, sumComponents, commonVecIndex,
commonThunkElim, commonThunkDim)
commonThunkElim, commonThunkDim, ScopeData)
import Drasil.GOOL.CodeAnalysis (Exception(..), ExceptionType(..), exception,
stdExc, HasException(..))
import Drasil.GOOL.Helpers (emptyIfNull, toCode, toState, onCodeValue,
Expand Down Expand Up @@ -275,10 +275,10 @@ instance OpElim JavaCode where
bOpPrec = opPrec . unJC

instance ScopeSym JavaCode where
type Scope JavaCode = Doc
global = toCode empty
mainFn = toCode empty
local = toCode empty
type Scope JavaCode = ScopeData
global = CP.global
mainFn = local
local = G.local

instance VariableSym JavaCode where
type Variable JavaCode = VarData
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,20 +44,21 @@ import Drasil.GOOL.RendererClassesProc (ProcRenderSym, RenderFile(..),
import qualified Drasil.GOOL.RendererClassesProc as RC (module')
import Drasil.GOOL.LanguageRenderer (printLabel, listSep, listSep',
variableList, parameterList, forLabel, inLabel, tryLabel, catchLabel)
import qualified Drasil.GOOL.LanguageRenderer as R (sqrt, abs, log10, log, exp,
sin, cos, tan, asin, acos, atan, floor, ceil, multiStmt, body, addComments,
blockCmt, docCmt, commentedMod, listSetFunc, commentedItem, break, continue)
import Drasil.GOOL.LanguageRenderer.Constructors (mkVal, mkStateVal, VSOp,
unOpPrec, powerPrec, unExpr, unExpr', binExpr, multPrec, typeUnExpr,
import qualified Drasil.GOOL.LanguageRenderer as R (var, sqrt, abs, log10, log,
exp, sin, cos, tan, asin, acos, atan, floor, ceil, multiStmt, body,
addComments, blockCmt, docCmt, commentedMod, listSetFunc, commentedItem,
break, continue)
import Drasil.GOOL.LanguageRenderer.Constructors (mkVal, mkStateVal, mkStateVar,
VSOp, unOpPrec, powerPrec, unExpr, unExpr', binExpr, multPrec, typeUnExpr,
typeBinExpr, mkStmt, mkStmtNoEnd)
import Drasil.GOOL.LanguageRenderer.LanguagePolymorphic (OptionalSpace(..))
import qualified Drasil.GOOL.LanguageRenderer.LanguagePolymorphic as G (
block, multiBlock, litChar, litDouble, litInt, litString, valueOf, negateOp,
equalOp, notEqualOp, greaterOp, greaterEqualOp, lessOp, lessEqualOp, plusOp,
minusOp, multOp, divideOp, moduloOp, var, call, funcAppMixedArgs, lambda,
minusOp, multOp, divideOp, moduloOp, call, funcAppMixedArgs, lambda,
listAccess, listSet, tryCatch, csc, multiBody, sec, cot, stmt, loopStmt,
emptyStmt, assign, increment, subAssign, print, comment, valStmt, returnStmt,
param, docFunc, throw, arg, argsList, ifCond, smartAdd)
param, docFunc, throw, arg, argsList, ifCond, smartAdd, local)
import qualified Drasil.GOOL.LanguageRenderer.CommonPseudoOO as CP (bool,
boolRender, extVar, funcType, litArray, listDec, listDecDef, listAccessFunc,
listSetFunc, notNull, extFuncAppMixedArgs, functionDoc, listSize, listAdd,
Expand All @@ -75,7 +76,8 @@ import Drasil.GOOL.AST (Terminator(..), FileType(..), FileData(..), fileD,
FuncData(..), ModData(..), md, updateMod, MethodData(..), mthd, OpData(..),
ParamData(..), ProgData(..), TypeData(..), td, ValData(..), vd, VarData(..),
vard, CommonThunk, progD, fd, pd, updateMthd, commonThunkDim, commonThunkElim,
vectorize, vectorize2, commonVecIndex, sumComponents, pureValue)
vectorize, vectorize2, commonVecIndex, sumComponents, pureValue, ScopeTag(..),
ScopeData, sd)
import Drasil.GOOL.Helpers (vibcat, toCode, toState, onCodeValue, onStateValue,
on2CodeValues, on2StateValues, onCodeList, onStateList, emptyIfEmpty)
import Drasil.GOOL.State (VS, lensGStoFS, revFiles, setFileType, lensMStoVS,
Expand Down Expand Up @@ -244,14 +246,14 @@ instance OpElim JuliaCode where
bOpPrec = opPrec . unJLC

instance ScopeSym JuliaCode where
type Scope JuliaCode = Doc
global = toCode empty -- TODO: implement this properly
mainFn = toCode empty
local = toCode empty
type Scope JuliaCode = ScopeData
global = toCode $ sd Global
mainFn = global
local = G.local

instance VariableSym JuliaCode where
type Variable JuliaCode = VarData
var' n _ = G.var n
var' n _ t = mkStateVar n t (R.var n)
constant' = var' -- TODO: add `const` keyword in global scope, and follow Python for local
extVar l n t = modify (addModuleImportVS l) >> CP.extVar l n t
arrayElem i = A.arrayElem (litInt i)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ module Drasil.GOOL.LanguageRenderer.LanguagePolymorphic (fileFromData,
multiBody, block, multiBlock, listInnerType, obj, negateOp, csc, sec,
cot, equalOp, notEqualOp, greaterOp, greaterEqualOp, lessOp, lessEqualOp,
plusOp, minusOp, multOp, divideOp, moduloOp, var, staticVar, objVar,
classVarCheckStatic, arrayElem, litChar, litDouble, litInt, litString,
classVarCheckStatic, arrayElem, local, litChar, litDouble, litInt, litString,
valueOf, arg, argsList, call, funcAppMixedArgs, selfFuncAppMixedArgs,
newObjMixedArgs, lambda, objAccess, objMethodCall, func, get, set, listAdd,
listAppend, listAccess, listSet, getFunc, setFunc,
Expand Down Expand Up @@ -60,7 +60,8 @@ import qualified Drasil.GOOL.RendererClassesOO as S (RenderFile(fileFromData),
RenderClass(intClass, commentedClass))
import qualified Drasil.GOOL.RendererClassesOO as RC (ClassElim(..),
ModuleElim(..))
import Drasil.GOOL.AST (Binding(..), Terminator(..), isSource)
import Drasil.GOOL.AST (Binding(..), Terminator(..), isSource, ScopeTag(Local),
ScopeData, sd)
import Drasil.GOOL.Helpers (doubleQuotedText, vibcat, emptyIfEmpty, toCode,
toState, onStateValue, on2StateValues, onStateList, getInnerType, getNestDegree,
on2StateWrapped)
Expand Down Expand Up @@ -212,6 +213,10 @@ arrayElem i' v' = do
vRender = RC.variable v <> brackets (RC.value i)
mkStateVar vName vType vRender

-- Scope --
local :: (Monad r) => r ScopeData
local = toCode $ sd Local

-- Values --

litChar :: (CommonRenderSym r) => (Doc -> Doc) -> Char -> SValue r
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -70,23 +70,24 @@ import qualified Drasil.GOOL.LanguageRenderer.LanguagePolymorphic as G (
increment, objDecNew, print, closeFile, returnStmt, valStmt, comment, throw,
ifCond, tryCatch, construct, param, method, getMethod, setMethod, function,
buildClass, implementingClass, commentedClass, modFromData, fileDoc,
fileFromData)
fileFromData, local)
import qualified Drasil.GOOL.LanguageRenderer.CommonPseudoOO as CP (int,
constructor, doxFunc, doxClass, doxMod, extVar, classVar, objVarSelf,
extFuncAppMixedArgs, indexOf, listAddFunc, discardFileLine, intClass,
funcType, buildModule, bindingError, notNull, listDecDef, destructorError,
stateVarDef, constVar, litArray, listSetFunc, extraClass, listAccessFunc,
multiAssign, multiReturn, listDec, funcDecDef, inOutCall, forLoopError,
mainBody, inOutFunc, docInOutFunc', listSize, intToIndex, indexToInt,
varDecDef, openFileR', openFileW', openFileA', argExists, forEach')
varDecDef, openFileR', openFileW', openFileA', argExists, forEach', global)
import qualified Drasil.GOOL.LanguageRenderer.Macros as M (ifExists,
decrement1, increment1, runStrategy, stringListVals, stringListLists,
notifyObservers')
import Drasil.GOOL.AST (Terminator(..), FileType(..), FileData(..), fileD,
FuncData(..), fd, ModData(..), md, updateMod, MethodData(..), mthd,
updateMthd, OpData(..), ParamData(..), pd, ProgData(..), progD, TypeData(..),
td, ValData(..), vd, VarData(..), vard, CommonThunk, pureValue, vectorize,
vectorize2, sumComponents, commonVecIndex, commonThunkElim, commonThunkDim)
vectorize2, sumComponents, commonVecIndex, commonThunkElim, commonThunkDim,
ScopeData)
import Drasil.GOOL.Helpers (vibcat, emptyIfEmpty, toCode, toState, onCodeValue,
onStateValue, on2CodeValues, on2StateValues, onCodeList, onStateList,
on2StateWrapped)
Expand Down Expand Up @@ -263,10 +264,10 @@ instance OpElim PythonCode where
bOpPrec = opPrec . unPC

instance ScopeSym PythonCode where
type Scope PythonCode = Doc
global = toCode empty
mainFn = toCode empty
local = toCode empty
type Scope PythonCode = ScopeData
global = CP.global
mainFn = global
local = G.local

instance VariableSym PythonCode where
type Variable PythonCode = VarData
Expand Down
Loading