Home My Page Projects Code Snippets Project Openings diderot
Summary Activity Tracker Tasks SCM

SCM Repository

[diderot] Diff of /branches/vis15/src/compiler/target-cpu/gen-strand.sml
ViewVC logotype

Diff of /branches/vis15/src/compiler/target-cpu/gen-strand.sml

Parent Directory Parent Directory | Revision Log Revision Log | View Patch Patch

revision 4350, Tue Aug 2 19:20:11 2016 UTC revision 4351, Wed Aug 3 01:15:46 2016 UTC
# Line 36  Line 36 
36     * parameters.     * parameters.
37     * NOTE: the calling convention generated here must match that used in GenWorld.genInitiallyFun!     * NOTE: the calling convention generated here must match that used in GenWorld.genInitiallyFun!
38     *)     *)
39      fun genStateInit (env, strandName, strandTy, params, def) = let      fun genStateInit (env, strandName, strandPtrTy, params, def) = let
40            val IR.Method{needsW, hasG, body} = def            val IR.Method{needsW, hasG, body} = def
41            val fName = strandName ^ "_init"            val fName = strandName ^ "_init"
42            val (env, params) = List.foldr            val (env, params) = List.foldr
# Line 49  Line 49 
49            val selfParam = if TargetSpec.dualState(Env.target env)            val selfParam = if TargetSpec.dualState(Env.target env)
50                  then RN.selfOutVar                  then RN.selfOutVar
51                  else RN.selfVar                  else RN.selfVar
52            val params =            val params = CL.PARAM([], strandPtrTy, selfParam) :: params
                 CL.PARAM([], strandTy, selfParam) :: params  
53            val params = if hasG            val params = if hasG
54                  then RN.globalsParam :: params                  then RN.globalsParam :: params
55                  else params                  else params
# Line 63  Line 62 
62            end            end
63    
64    (* generate a function definition for a strand method *)    (* generate a function definition for a strand method *)
65      fun genMethodDef (env, strandName, strandTy, methTy, methName, needsWorld, usesGlobals, body) =      fun genMethodDef (env, strandName, strandPtrTy, methTy, methName, needsWorld, usesGlobals, body) =
66            let            let
67            val fName = concat[strandName, "_", methName]            val fName = concat[strandName, "_", methName]
68            val params = if TargetSpec.dualState(Env.target env)            val params = if TargetSpec.dualState(Env.target env)
69                  then [                  then [
70                      CL.PARAM(["const"], strandTy, RN.selfInVar),                      CL.PARAM(["const"], strandPtrTy, RN.selfInVar),
71                      CL.PARAM([], strandTy, RN.selfOutVar)                      CL.PARAM([], strandPtrTy, RN.selfOutVar)
72                    ]                    ]
73                  else [CL.PARAM([], strandTy, RN.selfVar)]                  else [CL.PARAM([], strandPtrTy, RN.selfVar)]
74            val params = if usesGlobals            val params = if usesGlobals
75                  then RN.globalsParam :: params                  then RN.globalsParam :: params
76                  else params                  else params
# Line 83  Line 82 
82            end            end
83    
84    (* generate a function definition for a strand method *)    (* generate a function definition for a strand method *)
85      fun genMethod (env, strandName, strandTy, methTy, methName, IR.Method{needsW, hasG, body}) =      fun genMethod (env, strandName, strandPtrTy, methTy, methName, IR.Method{needsW, hasG, body}) =
86            genMethodDef (            genMethodDef (
87              env, strandName, strandTy, methTy, methName,              env, strandName, strandPtrTy, methTy, methName,
88              needsW, hasG, TreeToCxx.trBlock (env, body))              needsW, hasG, TreeToCxx.trBlock (env, body))
89    
90      fun genInitiallyMethod (_, _, _, NONE) = []      fun genInitiallyMethod (_, _, _, NONE) = []
91        | genInitiallyMethod (env, strandName, strandTy, SOME meth) =        | genInitiallyMethod (env, strandName, strandPtrTy, SOME meth) =
92            [genMethod (env, strandName, strandTy, strandStatusTy, "initially", meth)]            [genMethod (env, strandName, strandPtrTy, strandStatusTy, "initially", meth)]
93    
94      fun genUpdateMethod (env, strandName, strandTy, meth) =      fun genUpdateMethod (env, strandName, strandPtrTy, meth) =
95            genMethod (env, strandName, strandTy, strandStatusTy, "update", meth)            genMethod (env, strandName, strandPtrTy, strandStatusTy, "update", meth)
96    
97      fun genStabilizeMethod (env, strandName, strandTy, NONE) =      fun genStabilizeMethod (env, strandName, strandPtrTy, NONE) = [
           if TargetSpec.dualState(Env.target env)  
             then (*raise Fail "FIXME: default stabilize for dual state"*)[]  
             else [  
98                  genMethodDef (                  genMethodDef (
99                    env, strandName, strandTy, CL.voidTy, "stabilize", false, false, CL.mkBlock[])                env, strandName, strandPtrTy, CL.voidTy, "stabilize", false, false, CL.mkBlock[])
100                ]                ]
101        | genStabilizeMethod (env, strandName, strandTy, SOME meth) =        | genStabilizeMethod (env, strandName, strandPtrTy, SOME meth) =
102            [genMethod (env, strandName, strandTy, CL.voidTy, "stabilize", meth)]            [genMethod (env, strandName, strandPtrTy, CL.voidTy, "stabilize", meth)]
103    
104      fun gen (env, strand) = let      fun gen (env, strand) = let
105            val IR.Strand{name, params, state, stateInit, initM, updateM, stabilizeM} = strand            val IR.Strand{name, params, state, stateInit, initM, updateM, stabilizeM} = strand
106            val name = Atom.toString name            val name = Atom.toString name
107            val strandTy = CL.T_Ptr(CL.T_Named(name ^ "_strand"))            val strandPtrTy = CL.T_Ptr(CL.T_Named(name ^ "_strand"))
108            in {            in {
109              structDef = genStrandStruct (env, name, state),              structDef = genStrandStruct (env, name, state),
110              methods = genStateInit (env, name, strandTy, params, stateInit) ::              methods = genStateInit (env, name, strandPtrTy, params, stateInit) ::
111                genInitiallyMethod (env, name, strandTy, initM) @                genInitiallyMethod (env, name, strandPtrTy, initM) @
112                genUpdateMethod (env, name, strandTy, updateM) ::                genUpdateMethod (env, name, strandPtrTy, updateM) ::
113                genStabilizeMethod (env, name, strandTy, stabilizeM)                genStabilizeMethod (env, name, strandPtrTy, stabilizeM)
114            } end            } end
115    
116    end    end

Legend:
Removed from v.4350  
changed lines
  Added in v.4351

root@smlnj-gforge.cs.uchicago.edu
ViewVC Help
Powered by ViewVC 1.0.0