-
Notifications
You must be signed in to change notification settings - Fork 25
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
Introduced LitValue
for expanded literal value handling
#3945
base: main
Are you sure you want to change the base?
Changes from all commits
8270356
40a0cbe
ee62021
493b8c7
a85eecd
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -381,7 +381,21 @@ instance RenderValue JuliaCode where | |
|
||
instance ValueElim JuliaCode where | ||
valuePrec = valPrec . unJLC | ||
valueInt = valInt . unJLC | ||
valueChar sc = case litVal (unJLC sc) of | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I think you should be able to abstract out the
part in a separate function so that it can be re-used across the different renderers |
||
LitChar c -> Just c | ||
_ -> Nothing | ||
valueDouble sc = case litVal (unJLC sc) of | ||
LitDouble d -> Just d | ||
_ -> Nothing | ||
valueFloat sc = case litVal (unJLC sc) of | ||
LitFloat f -> Just f | ||
_ -> Nothing | ||
valueInt sc = case litVal (unJLC sc) of | ||
LitInt i -> Just i | ||
_ -> Nothing | ||
valueString sc = case litVal (unJLC sc) of | ||
LitString s -> Just s | ||
_ -> Nothing | ||
value = val . unJLC | ||
|
||
instance List JuliaCode where | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -50,7 +50,7 @@ import qualified Drasil.GOOL.RendererClassesCommon as S (RenderValue(call), | |
InternalListFunc (listAddFunc, listAppendFunc, listAccessFunc, listSetFunc), | ||
RenderStatement(stmt), InternalIOStmt(..)) | ||
import qualified Drasil.GOOL.RendererClassesCommon as RC (BodyElim(..), | ||
BlockElim(..), InternalVarElim(variable), ValueElim(value, valueInt), | ||
BlockElim(..), InternalVarElim(variable), ValueElim(..), | ||
FunctionElim(..), StatementElim(statement), BlockCommentElim(..)) | ||
import Drasil.GOOL.RendererClassesOO (OORenderSym, RenderFile(commentedMod), | ||
OORenderMethod(intMethod), RenderClass(inherit, implements), | ||
|
@@ -134,16 +134,26 @@ smartAdd v1 v2 = do | |
v1' <- v1 | ||
v2' <- v2 | ||
case (RC.valueInt v1', RC.valueInt v2') of | ||
(Just i1, Just i2) -> litInt (i1 + i2) | ||
_ -> v1 #+ v2 | ||
(Just i1,Just i2) -> litInt (i1 + i2) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I wonder if |
||
_ -> case (RC.valueDouble v1', RC.valueDouble v2') of | ||
(Just d1, Just d2) -> litDouble (d1 + d2) | ||
_ -> case (RC.valueFloat v1', RC.valueFloat v2') of | ||
(Just f1, Just f2) -> IC.litFloat (f1 + f2) | ||
_ -> case (RC.valueString v1', RC.valueString v2') of | ||
(Just s1, Just s2) -> litString (s1 ++ s2) | ||
_ -> v1 #+ v2 | ||
|
||
smartSub :: (CommonRenderSym r) => SValue r -> SValue r -> SValue r | ||
smartSub v1 v2 = do | ||
v1' <- v1 | ||
v2' <- v2 | ||
case (RC.valueInt v1', RC.valueInt v2') of | ||
(Just i1, Just i2) -> litInt (i1 - i2) | ||
_ -> v1 #- v2 | ||
(Just i1,Just i2) -> litInt (i1 - i2) | ||
_ -> case (RC.valueDouble v1', RC.valueDouble v2') of | ||
(Just d1, Just d2) -> litDouble (d1 - d2) | ||
_ -> case (RC.valueFloat v1', RC.valueFloat v2') of | ||
(Just f1, Just f2) -> IC.litFloat (f1 - f2) | ||
_ -> v1 #- v2 | ||
|
||
equalOp :: (Monad r) => VSOp r | ||
equalOp = compEqualPrec "==" | ||
|
@@ -220,16 +230,16 @@ local = toCode $ sd Local | |
-- Values -- | ||
|
||
litChar :: (CommonRenderSym r) => (Doc -> Doc) -> Char -> SValue r | ||
litChar f c = mkStateVal IC.char (f $ if c == '\n' then text "\\n" else D.char c) | ||
litChar f c = valFromData Nothing (LitChar c) IC.char (f $ if c == '\n' then text "\\n" else D.char c) | ||
|
||
litDouble :: (CommonRenderSym r) => Double -> SValue r | ||
litDouble d = mkStateVal IC.double (D.double d) | ||
litDouble d = valFromData Nothing (LitDouble d) IC.double (D.double d) | ||
|
||
litInt :: (CommonRenderSym r) => Integer -> SValue r | ||
litInt i = valFromData Nothing (Just i) IC.int (integer i) | ||
litInt i = valFromData Nothing (LitInt i) IC.int (integer i) | ||
|
||
litString :: (CommonRenderSym r) => String -> SValue r | ||
litString s = mkStateVal IC.string (doubleQuotedText s) | ||
litString s = valFromData Nothing (LitString s) IC.string (doubleQuotedText s) | ||
|
||
valueOf :: (CommonRenderSym r) => SVariable r -> SValue r | ||
valueOf v' = do | ||
|
@@ -278,7 +288,7 @@ lambda f ps' ex' = do | |
ps <- sequence ps' | ||
ex <- ex' | ||
let ft = IC.funcType (map (return . variableType) ps) (return $ valueType ex) | ||
valFromData (Just 0) Nothing ft (f ps ex) | ||
valFromData (Just 0) (LitInt 0) ft (f ps ex) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Here again, why default to 0? |
||
|
||
objAccess :: (CommonRenderSym r) => SValue r -> VSFunction r -> SValue r | ||
objAccess = on2StateWrapped (\v f-> mkVal (functionType f) | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -24,7 +24,7 @@ import Drasil.GOOL.InterfaceCommon (Label, Library, MSBody, MSBlock, VSFunction, | |
FuncAppStatement(..), CommentStatement(..), ControlStatement(..), | ||
VisibilitySym(..), ParameterSym(..), MethodSym(..), ScopeSym(..)) | ||
import Drasil.GOOL.CodeType (CodeType) | ||
import Drasil.GOOL.AST (Binding, Terminator, VisibilityTag, ScopeData) | ||
import Drasil.GOOL.AST (Binding, Terminator, VisibilityTag, LitValue(..), ScopeData) | ||
import Drasil.GOOL.State (MS, VS) | ||
|
||
import Control.Monad.State (State) | ||
|
@@ -148,11 +148,15 @@ class RenderValue r where | |
-- calls. | ||
call :: Maybe Library -> Maybe Doc -> MixedCall r | ||
|
||
valFromData :: Maybe Int -> Maybe Integer -> VSType r -> Doc -> SValue r | ||
valFromData :: Maybe Int -> LitValue -> VSType r -> Doc -> SValue r | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The previous type was more precise! Perhaps |
||
|
||
class ValueElim r where | ||
valuePrec :: r (Value r) -> Maybe Int | ||
valueChar :: r (Value r) -> Maybe Char | ||
valueDouble :: r (Value r) -> Maybe Double | ||
valueFloat :: r (Value r) -> Maybe Float | ||
valueInt :: r (Value r) -> Maybe Integer | ||
valueString :: r (Value r) -> Maybe String | ||
value :: r (Value r) -> Doc | ||
|
||
class InternalListFunc r where | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is suspicious to me: why is the static value defaulting to 0? (same in other places in this PR)