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 3927, Sat Jun 4 21:20:01 2016 UTC revision 3952, Sat Jun 11 17:20:27 2016 UTC
# Line 35  Line 35 
35    (* generate the strand-state initialization code.  The variables are the strand    (* generate the strand-state initialization code.  The variables are the strand
36     * parameters.     * parameters.
37     *)     *)
38      fun genStateInit (env, strandName, strandTy, params, body) = let      fun genStateInit (env, strandName, strandTy, params, def) = let
39              val IR.Method{usesGlobals, needsWorld, body} = def
40            val fName = strandName ^ "_init"            val fName = strandName ^ "_init"
41            val (env, params) = List.foldr            val (env, params) = List.foldr
42                  (fn (x, (env, ps)) => let                  (fn (x, (env, ps)) => let
# Line 49  Line 50 
50                  else RN.selfVar                  else RN.selfVar
51            val params =            val params =
52                  CL.PARAM([], strandTy, selfParam) :: params                  CL.PARAM([], strandTy, selfParam) :: params
53            val params = if #hasGlobals(Env.target env)            val params = if usesGlobals
54                  then RN.globalsParam :: params                  then RN.globalsParam :: params
55                  else params                  else params
56              val params = if needsWorld
57                    then RN.worldParam :: params
58                    else params
59            val body = TreeToCxx.trBlock (env, body)            val body = TreeToCxx.trBlock (env, body)
60            in            in
61              CL.D_Func(["static"], CL.voidTy, fName, params, body)              CL.D_Func(["static"], CL.voidTy, fName, params, body)
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, body) = let      fun genMethodDef (env, strandName, strandTy, methTy, methName, usesGlobals, needsWorld, body) = let
66            val fName = concat[strandName, "_", methName]            val fName = concat[strandName, "_", methName]
67            val stateParams = if TargetSpec.dualState(Env.target env)            val stateParams = if TargetSpec.dualState(Env.target env)
68                  then [                  then [
# Line 66  Line 70 
70                      CL.PARAM([], strandTy, RN.selfOutVar)                      CL.PARAM([], strandTy, RN.selfOutVar)
71                    ]                    ]
72                  else [CL.PARAM([], strandTy, RN.selfVar)]                  else [CL.PARAM([], strandTy, RN.selfVar)]
73            val params = if #hasGlobals(Env.target env)            val params = if usesGlobals
74                  then RN.globalsParam :: stateParams                  then RN.globalsParam :: stateParams
75                  else stateParams                  else stateParams
76              val params = if needsWorld
77                    then RN.worldParam :: stateParams
78                    else stateParams
79            in            in
80              CL.D_Func(["static"], methTy, fName, params, body)              CL.D_Func(["static"], methTy, fName, params, body)
81            end            end
82    
83    (* generate a function definition for a strand method *)    (* generate a function definition for a strand method *)
84      fun genMethod (env, strandName, strandTy, methTy, methName, body) =      fun genMethod (env, strandName, strandTy, methTy, methName, IR.Method{usesGlobals, needsWorld, body}) =
85            genMethodDef (env, strandName, strandTy, methTy, methName, TreeToCxx.trBlock (env, body))            genMethodDef (
86                env, strandName, strandTy, methTy, methName,
87                usesGlobals, needsWorld, TreeToCxx.trBlock (env, body))
88    
89      fun genInitiallyMethod (_, _, _, NONE) = []      fun genInitiallyMethod (_, _, _, NONE) = []
90        | genInitiallyMethod (env, strandName, strandTy, SOME body) =        | genInitiallyMethod (env, strandName, strandTy, SOME meth) =
91            [genMethod (env, strandName, strandTy, strandStatusTy, "initially", body)]            [genMethod (env, strandName, strandTy, strandStatusTy, "initially", meth)]
92    
93      fun genUpdateMethod (env, strandName, strandTy, body) =      fun genUpdateMethod (env, strandName, strandTy, meth) =
94            genMethod (env, strandName, strandTy, strandStatusTy, "update", body)            genMethod (env, strandName, strandTy, strandStatusTy, "update", meth)
95    
96      fun genStabilizeMethod (env, strandName, strandTy, NONE) =      fun genStabilizeMethod (env, strandName, strandTy, NONE) =
97            if TargetSpec.dualState(Env.target env)            if TargetSpec.dualState(Env.target env)
98              then raise Fail "FIXME: default stabilize for dual state"              then raise Fail "FIXME: default stabilize for dual state"
99              else [genMethodDef (env, strandName, strandTy, CL.voidTy, "stabilize", CL.mkBlock[])]              else [
100        | genStabilizeMethod (env, strandName, strandTy, SOME body) =                  genMethodDef (
101            [genMethod (env, strandName, strandTy, CL.voidTy, "stabilize", body)]                    env, strandName, strandTy, CL.voidTy, "stabilize", false, false, CL.mkBlock[])
102                  ]
103          | genStabilizeMethod (env, strandName, strandTy, SOME meth) =
104              [genMethod (env, strandName, strandTy, CL.voidTy, "stabilize", meth)]
105    
106      fun gen (env, strand) = let      fun gen (env, strand) = let
107            val IR.Strand{name, params, state, stateInit, initM, updateM, stabilizeM} = strand            val IR.Strand{name, params, state, stateInit, initM, updateM, stabilizeM} = strand

Legend:
Removed from v.3927  
changed lines
  Added in v.3952

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