Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Work in process: performing full inlining during the hpt analysis, an…

…d updating the hpt table as well.
  • Loading branch information...
commit ab742feb89650e9b109d1402ed03f5fcbc57cd7b 1 parent c94ea8d
rgvwille authored
23 EHC/src/ehc/GrinCode/Trf/ApplyUnited.cag
View
@@ -74,20 +74,25 @@ SEM GrBind
| Bind expr.env = Map.empty
SEM GrExpr
- | Seq body.env = -- (const $ "seq with pattern " ++ show @pat.getName ++ "\nexpr = " ++ show @expr.grTrf) >>>
- maybe @lhs.env
- (\val -> -- (const $ "\ninserting " ++ show @pat.getName ++ " for AU ") >>>
+ | Seq body.env = maybe (--(const $ "did not insert expr = " ++ show @expr.grTrf) >>>
+ @lhs.env)
+ (\val -> --(const $ "\ninserting " ++ show @pat.getName ++ " with expr = " ++ show @expr.grTrf) >>>
Map.insert @pat.getName val @lhs.env)
- @expr.mbUnitPNode
+ (case @expr.grTrf of
+ GrExpr_Unit val@(GrVal_Node (GrTag_PApp _ _) _) -> Just val
+ _ -> Nothing
+ )
- | Unit lhs.mbUnitPNode = -- (const $ "found unit, val = " ++ show @val.grTrf) >>>
+ | Unit lhs.mbUnitPNode =
if @val.hasPAppTag
- then Just @val.grTrf
- else Nothing
+ then --(const $ "found PTAGunit, val = " ++ show @val.grTrf) >>>
+ Just @val.grTrf
+ else --(const $ "found notPTAGunit, val = " ++ show @val.grTrf) >>>
+ Nothing
| * - Unit lhs.mbUnitPNode = Nothing
| App (lhs.grTrf,lhs.changed)
- = -- (const $ "\nfound apply, nm = " ++ show @nm) >>>
+ = --(const $ "\nfound apply, nm = " ++ show @nm) >>>
maybe (@loc.grTrf,False)
(\node -> (applyNode @nm @argL.grTrf node,True))
(Map.lookup @nm @lhs.env)
@@ -98,7 +103,7 @@ SEM GrExpr
applyNode nm2 flds2 node@(GrVal_Node (GrTag_PApp needs nm) flds1)
- = -- (const $ "\napplyNode " ++ show nm2 ++ "\nnode = " ++ show node) >>>
+ = --(const $ "\napplyNode " ++ show nm2 ++ "\nnode = " ++ show node) >>>
let n = length flds2
in if n<needs
then GrExpr_Unit (GrVal_Node (GrTag_PApp (needs-n) nm) (flds1++flds2))
15 EHC/src/ehc/GrinCode/Trf/CopyPropagationModded.cag → EHC/src/ehc/GrinCode/Trf/CopyPropagation.cag
View
@@ -12,7 +12,11 @@ Use the left law if both are applicable.
%%]
%%[(8 codegen grin) hs import({%{EH}Base.Common}, {%{EH}GrinCode.Common}, {%{EH}GrinCode}, Data.Maybe, qualified Data.Map as Map)
%%]
-%%[(8 codegen grin) hs import(qualified Debug.Trace as Trace)
+%%[(8 codegen grin) hs import({%{EH}GrinCode.Pretty})
+%%]
+%%[(8 codegen grin) hs import(EH.Util.Pretty)
+%%]
+%%[(8 codegen grin) hs import(Debug.Trace)
%%]
%%[(8 codegen grin) ag import({GrinCode/AbsSyn})
%%]
@@ -36,7 +40,6 @@ ATTR GrPatLam
GrVar
GrTagL
GrTag [ | | self: SELF ]
-
ATTR GrAGItf GrModule AllBind GrExpr AllAlt [ | | changed USE {||} {False}: Bool ]
SEM GrExpr
@@ -121,7 +124,7 @@ testL pat val
GrPatLam_Empty -> case val of
GrVal_Empty -> Just (id,id)
_ -> Nothing -- error "CopyProp: left: empty-pattern does not match"
- GrPatLam_Var v -> Just (Map.insert v val, id)
+ GrPatLam_Var v -> Just (Map.insert v val, id)
GrPatLam_VarNode vs -> case val of
GrVal_Var _ -> Nothing
GrVal_Node t xs -> Just (unifyNodes vs (GrVal_Tag t:xs))
@@ -189,11 +192,7 @@ getHsName nm subst
Nothing -> nm
Just repl -> case repl of
GrVal_Var v -> v
- _ -> -- This previsously was an error.
- Trace.trace ("2CopyPropagation cannot substitute " ++ show repl
- ++ " when substituting name " ++ show nm) $
- nm
-
+ _ -> error ("CopyPropagation cannot substitute for name " ++ show nm ++ "\nvalue " ++ disp (ppGrExpr (GrExpr_Unit repl)) 0 "")
mbSubstTag nm subst
= case Map.lookup nm subst of
26 EHC/src/ehc/GrinCode/Trf/HptInline.cag
View
@@ -0,0 +1,26 @@
+
+%%[(8 codegen grin) hs import({%{EH}GrinCode.Trf.Inline(grInline)})
+%%]
+
+%%[(8 codegen grin) hs import({%{EH}Base.Builtin}, {%{EH}Base.Common}, {%{EH}GrinCode.Common}, {%{EH}GrinCode})
+%%]
+
+%%[(8 codegen grin) hs module {%{EH}GrinCode.Trf.HptInline}
+%%]
+
+%%[(8 codegen grin) hs import(EH.Util.Debug)
+%%]
+
+%%[(20 codegen grin) -8.grInline hs export(hptInline)
+hptInline :: Bool -> HsNameS -> GrInlMp -> (GrModule,HptMap) -> Maybe ((GrModule,HptMap),GrInlMp)
+hptInline allow expNmS inlMp (grMod,hptMap) =
+ let inlineResult = grInline allow expNmS inlMp grMod
+ processInline (grMod,inlMp,varSubs) =
+ let newHptMap = addEnvNamedElems hptMap additions
+ additions :: [(Int,AbstractValue)]
+ additions = -- (\a -> "additions are: " ++ show a) >>>
+ map (\(a,b) -> (getNr b,getEnvVar hptMap (getNr a))) varSubs
+ in seq additions ((grMod,newHptMap),inlMp)
+ in fmap processInline inlineResult
+
+%%]
116 EHC/src/ehc/GrinCode/Trf/Inline.cag
View
@@ -44,7 +44,7 @@ to a loop.
%%]
-- for debugging:
-%%[(8 codegen grin) hs import(EH.Util.Pretty,EH.Util.Utils)
+%%[(8 codegen grin) hs import(EH.Util.Pretty,EH.Util.Utils,EH.Util.Debug)
%%]
%%[(8 codegen grin) hs import(qualified {%{EH}Config} as Cfg)
@@ -54,14 +54,13 @@ to a loop.
%%]
--- for debugging:
%%[(8 codegen grin) hs import(EH.Util.Pretty,EH.Util.Utils)
%%]
%%[(8 codegen grin) hs import({%{EH}Base.Debug})
%%]
--Added
-%%[(8 codegen grin) hs import(qualified Data.Graph as Graph,qualified Data.Tree as Tree,qualified Debug.Trace as Trace,Data.List)
+%%[(8 codegen grin) hs import(qualified Data.Graph as Graph,qualified Data.Tree as Tree,Data.List)
%%]
%%[(8 codegen grin) ag import({GrinCode/InsideCase})
@@ -96,10 +95,9 @@ grInline allow grmod
%%]
%%[(20 codegen grin) -8.grInline hs export(grInline)
-grInline :: Bool -> HsNameS -> GrInlMp -> GrModule -> (Maybe GrModule,GrInlMp)
+grInline :: Bool -> HsNameS -> GrInlMp -> GrModule -> Maybe (GrModule,GrInlMp,VarSubs)
grInline allow expNmS inlMp grmod
- = (if (changed_Syn_GrAGItf t) then Just (trf_Syn_GrAGItf t) else Nothing
- ,gathInlMp_Syn_GrAGItf t)
+ = if (changed_Syn_GrAGItf t) then Just (trf_Syn_GrAGItf t,gathInlMp_Syn_GrAGItf t,varSubs_Syn_GrAGItf t) else Nothing
where t = wrap_GrAGItf (sem_GrAGItf $ GrAGItf_AGItf grmod)
$ Inh_GrAGItf
{ expNmS_Inh_GrAGItf = expNmS
@@ -134,12 +132,30 @@ PRAGMA nocycle
%%]
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
+%%% VarSubs
+%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
+
+%%[(8 codegen grin)
+{
+type VarSubs = [(HsName,HsName)]
+}
+ATTR GrAGItf GrModule AllExpr AllBind [ || varSubs USE {++} {[]} : {VarSubs} ]
+%%]
+
+%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
+%%% Has inlining occured?
+%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
+
+%%[(8 codegen grin)
+ATTR GrAGItf AllNT [ | | changed USE {||} {False} : {Bool} ]
+%%]
+
+%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%%% Globally used vars
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%%[(20 codegen grin)
ATTR GrAGItf GrModule AllBind [ expNmS: HsNameS | | ]
-ATTR GrAGItf AllNT [ | | changed USE {||} {False} : {Bool} ]
%%]
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
@@ -184,7 +200,7 @@ ATTR GrAGItf GrModule AllBind [ allowOmitBind : {Bool} | | ]
%%]
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
-%%% Inlining recursive functions
+%%% Inlining mutual recursive functions
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%%[(8 codegen grin)
@@ -214,26 +230,31 @@ ATTR AllBind [ loopBreakers: {[HsName]} | | ]
ATTR AllBind [ inhBindingNames : {[HsName]} | | ]
ATTR AllBind [ | | synBindingNames USE {++} {[]} : {[HsName]} ]
-SEM GrModule | Mod bindL.loopBreakers = []
- bindL.inhBindingNames = []
+SEM GrModule
+ | Mod bindL.loopBreakers = (\b -> condTrace showLoopBreakers (
+ "\nrecursive bind found,names are:\n" ++ show @bindL.synBindingNames ++
+ "\n loopbreakers are:" ++ show b
+ ) b) $
+ calcLoopBreakers @bindL.dependencies
+ bindL.inhBindingNames = []
{
showLoopBreakers = False
-condTrace c s v = if c then Trace.trace s v else v
+condTrace c s v = if c then (const $ s) >>> v else v
}
+SEM GrBindL
+ | Cons hd.inhBindingNames = @hd.synBindingNames
+
SEM GrBind
- | Bind lhs.dependencies = --(\d -> Trace.trace ("bindingNames = " ++ show @lhs.inhBindingNames
- -- ++ "\ngathMp = " ++ show @loc.gathFviMp
- -- ++ "\ndependencies = " ++ show d) d) $
- [(@nm,filter (\name -> Map.member name @gathFviMp) @lhs.inhBindingNames)]
+ | Bind lhs.dependencies = (\d -> condTrace showLoopBreakers (
+ "bindingNames = " ++ show @lhs.inhBindingNames
+ ++ "\ngathMp = " ++ show @loc.gathFviMp
+ ++ "\ndependencies = " ++ show d
+ ) d) $
+ [(@nm,filter (\name -> Map.member name @gathFviMp) @lhs.inhBindingNames)]
+
lhs.synBindingNames = [@nm]
- | Rec bindL.loopBreakers = (\b -> condTrace showLoopBreakers (
- "\nrecursive bind found,names are:\n" ++ show @bindL.synBindingNames ++
- "\n loopbreakers are:" ++ show b
- ) b) $
- (calcLoopBreakers @bindL.dependencies) ++ @lhs.loopBreakers
- bindL.inhBindingNames = @bindL.synBindingNames
%%]
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
@@ -273,7 +294,7 @@ SEM GrBind
-> (Map.singleton @nm (GrInl_CAF @expr.trf isLoopBreaker), True)
_ | not @isCAF
-- bindings that are used once or more and that aren't a CAF.
- -- TODO: improve this descision for inlining bindings which are used more than once
+ -- TODO: improve this decision for inlining bindings which are used more than once
-- for example:
-- - how many time used (if possible)
-- - determine the cost of the function (with heuristics?)
@@ -288,7 +309,7 @@ SEM GrBind
| otherwise
-> (Map.empty, False) -- don't inline
-
+ | Rec lhs.gathInlMp = Map.empty
%%]
%%[(8 codegen grin)
@@ -372,48 +393,6 @@ SEM GrBind
%%]
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
-%%% Uniq
-%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
-
-%%[(8 codegen grin)
-ATTR AllGrExpr AllBind [ | uniq: Int | ]
-
-SEM GrExpr
- | Call lhs . uniq = @lhs.uniq+1
-
-SEM GrModule
- | Mod loc . uniq = 0
-%%]
-
-%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
-%%% bindId
-%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
-
-%%[(8 codegen grin)
-ATTR AllBind [ | bindId: Int | ]
-ATTR AllGrExpr [ bindId: Int | | ]
-ATTR AllNTNoMod [ bindIdDigits: Int | | ]
-
-SEM GrBind
- | Bind expr.bindId = @lhs.bindId
-
-SEM GrBind
- | Bind lhs.bindId = @lhs.bindId+1
-
-SEM GrModule
- | Mod bindL.bindId = 0
- bindL.bindIdDigits = digits @bindL.bindId
-
-{
-digits :: Int -> Int
-digits i = if i < 10 then 1 + digits (floor (toEnum i / toEnum 10)) else 1
-}
-
-SEM GrBind
- | Bind expr.uniqueIds = (map (\i -> i * 10 ^ @lhs.bindIdDigits + @lhs.bindId) [0..]) \\ @lhs.usedIds
-%%]
-
-%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%%% Transformation: inline
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
@@ -451,7 +430,7 @@ SEM GrExpr
%%[(8 codegen grin)
SEM GrExpr
- | Call (lhs.trf,loc.gathInlNmS,lhs.changed,lhs.uniqueIds)
+ | Call (lhs.trf,loc.gathInlNmS,lhs.changed,lhs.uniqueIds,lhs.varSubs)
= --(const $ "inlining.." ++ show @nm) >>>
--(\(a,b,c,d) -> "uniqueIds for " ++ show @nm ++ " is " ++ show (take 5 d)) >>>
case Map.lookup @nm @lhs.inlMp of
@@ -460,13 +439,14 @@ SEM GrExpr
-> condTrace showInlines ("inlining call " ++ show @nm) $
let argSubsEnv = Map.fromList (zip as (map fromJust @argL.asNmL))
argsSubstituted = substExpr argSubsEnv e
- (newBindingNames,remUniqueIds) = mkUniqueBindings @lhs.uniqueIds argsSubstituted
+ (newBindingNames,remUniqueIds,varSubs) = mkUniqueBindings @lhs.uniqueIds argsSubstituted
in ( @grVarTrf newBindingNames
, Set.insert @nm @grVarInlNmS
, True
, remUniqueIds
+ , varSubs
)
- _ -> (@grVarTrf @trf, @grVarInlNmS, @inlGrVarChanges, @lhs.uniqueIds)
+ _ -> (@grVarTrf @trf, @grVarInlNmS, @inlGrVarChanges, @lhs.uniqueIds, [])
| App (lhs.trf,loc.gathInlNmS,lhs.changed)
= if @lhs.isCAF
5 EHC/src/ehc/GrinCode/Trf/InlineEA.cag
View
@@ -44,6 +44,8 @@ WRAPPER GrAGItf
%%]
%%[(8 codegen grin) hs import(Debug.Trace)
%%]
+%%[(8 codegen grin) hs import(EH.Util.Debug)
+%%]
%%[(8 codegen grin) hs
inlineEA :: Bool -> (GrModule,HptMap) -> (GrModule,HptMap)
@@ -150,7 +152,8 @@ ATTR GrModule
AllGrExpr [ | unique : Int | ]
SEM GrAGItf
- | AGItf module . unique = getEnvSize @lhs.hptMap
+ | AGItf module . unique = -- (\s -> "uniqueStart = " ++ show s) >>>
+ getEnvSize @lhs.hptMap
lhs . hptMap = addEnvElems @lhs.hptMap (map snd (sort @module.newItems))
SEM GrModule
21 EHC/src/ehc/GrinCode/Trf/MkUniqueBindings.cag
View
@@ -26,39 +26,44 @@ WRAPPER GrExpr
type UniqueIds = [Int]
-mkUniqueBindings :: [Int] -> GrExpr -> (GrExpr,[Int])
+mkUniqueBindings :: [Int] -> GrExpr -> (GrExpr,[Int],VarSubs)
mkUniqueBindings uniqueIds e
- = (trf_Syn_GrExpr t,uniqueIds_Syn_GrExpr t)
+ = (trf_Syn_GrExpr t,uniqueIds_Syn_GrExpr t,gathSubs_Syn_GrExpr t)
where t = wrap_GrExpr (sem_GrExpr e)
$ Inh_GrExpr
{ uniqueIds_Inh_GrExpr = uniqueIds
, subs_Inh_GrExpr = Map.empty
}
-type Subs = Map.Map HsName HsName
+type Env = Map.Map HsName HsName
+type VarSubs = [(HsName,HsName)]
%%]
%%[(8 codegen grin) ag
ATTR AllGrExpr [ | uniqueIds : {UniqueIds} | ]
-ATTR AllExpr [ subs : {Subs} | | ]
+ATTR AllExpr [ subs : {Env} | | ]
+ATTR AllExpr [ || gathSubs USE {++} {[]} : {VarSubs} ]
{
mkNewName :: HsName -> Int -> HsName
mkNewName (HNmNr _ origName) unique = HNmNr unique origName
-changeName :: HsName -> (Subs,UniqueIds) -> (Subs,UniqueIds)
+changeName :: HsName -> (Env,UniqueIds) -> (Env,UniqueIds)
changeName name (subs,(uniqueId:remIds)) = (Map.insert name (mkNewName name uniqueId) subs,remIds)
}
SEM GrExpr
- | Seq (loc.subs,expr.uniqueIds) = { -- (\p@(a,_) -> Trace.trace ("loc.subs = " ++ show a) p) $
- foldr changeName (@lhs.subs, @lhs.uniqueIds) @pat.introNmL }
+ | Seq (loc.subs,expr.uniqueIds,lhs.gathSubs) = { -- (\p@(a,_) -> Trace.trace ("loc.subs = " ++ show a) p) $
+ let (newSubs,remIds) = foldr changeName (Map.empty, @lhs.uniqueIds) @pat.introNmL
+ in (@lhs.subs `Map.union` newSubs,remIds,Map.assocs newSubs) }
| Seq body.uniqueIds = @expr.uniqueIds
| Seq lhs.uniqueIds = @body.uniqueIds
SEM GrAlt
- | Alt (loc.subs,expr.uniqueIds) = foldr changeName (@lhs.subs, @lhs.uniqueIds) @pat.introNmL
+ | Alt (loc.subs,expr.uniqueIds,lhs.gathSubs) = {
+ let (newSubs,remIds) = foldr changeName (Map.empty, @lhs.uniqueIds) @pat.introNmL
+ in (@lhs.subs `Map.union` newSubs,remIds,Map.assocs newSubs) }
| Alt lhs.uniqueIds = @expr.uniqueIds
%%]
61 EHC/src/ehc/GrinCode/Trf/UniqueIds.cag
View
@@ -1,26 +1,69 @@
%%[(8 codegen grin)
-ATTR AllNT [ | usedIds USE {++} {[]} : {[Int]} | ]
-{-
--}
+ATTR AllNT [|| gathUsedIds USE {++} {[]} : {[Int]} ]
+ATTR AllGrExpr AllBind [ usedIds : {[Int]} ||]
+
+{
+checkUnique :: (Eq a,Show a) => [a] -> Bool
+checkUnique l = case l of
+ [] -> True
+ (x:xs) -> if elem x xs
+ then error (show x ++ " is not unique,\nxs = " ++ show xs)
+ else checkUnique xs
+
+mustCheckUsedUnique = True
+}
+
SEM GrModule
- | Mod lhs.usedIds = [0..5] ++ @bindL.usedIds ++ @globalL.usedIds
+ | Mod loc.gathUsedIds = let removeWildCards = filter (/= 0)
+ in ([0..5] ++) $
+ (\l -> seq (mustCheckUsedUnique && checkUnique l) l) $
+ removeWildCards (@globalL.gathUsedIds ++ @bindL.gathUsedIds)
+ bindL.usedIds = @loc.gathUsedIds
SEM GrBind
- | Bind lhs.usedIds = ((\i -> [i,i+1]) $ getNr @nm)
- ++ @expr.usedIds
+ | Bind lhs.gathUsedIds = ((\i -> [i,i+1]) $ getNr @nm)
+ ++ @expr.gathUsedIds ++ map getNr @argNmL
{-
-}
SEM GrGlobal
- | Global lhs.usedIds = (getNr @nm : @val.usedIds)
+ | Global lhs.gathUsedIds = (getNr @nm : @val.gathUsedIds)
SEM GrPatLam
| Var BasicNode EnumNode PtrNode OpaqueNode BasicAnnot EnumAnnot PtrAnnot OpaqueAnnot
- lhs.usedIds = [getNr @nm]
+ lhs.gathUsedIds = [getNr @nm]
+
+SEM GrPatAlt
+ | Node lhs.gathUsedIds = map getNr @fldL
SEM GrVar
- | Var lhs.usedIds = [getNr @nm]
+ | Var lhs.gathUsedIds = [getNr @nm]
ATTR AllGrExpr [ | uniqueIds : {[Int]} | ]
+%%]
+
+%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
+%%% bindId
+%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
+
+%%[(8 codegen grin)
+ATTR AllBind [ | bindId: Int | ]
+ATTR AllBind [ bindIdDigits: Int | | ]
+
+SEM GrBind
+ | Bind lhs.bindId = @lhs.bindId+1
+
+SEM GrModule
+ | Mod bindL.bindId = 0
+ bindL.bindIdDigits = digits @bindL.bindId
+
+{
+digits :: Int -> Int
+digits i = if i >= 10 then 1 + digits (floor (toEnum i / toEnum 10)) else 1
+}
+
+SEM GrBind
+ | Bind expr.uniqueIds = --(\l -> "bindIds = " ++ take 2000 (show l)) >>>
+ (map (\i -> i * 10 ^ @lhs.bindIdDigits + @lhs.bindId) [0..]) \\ @lhs.usedIds
%%]
Please sign in to comment.
Something went wrong with that request. Please try again.