Home My Page Projects Code Snippets Project Openings 3D graphics for Standard ML
Summary Activity SCM

SCM Repository

[sml3d] Diff of /trunk/sml3d/src/particles/compiler/translate.sml
ViewVC logotype

Diff of /trunk/sml3d/src/particles/compiler/translate.sml

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

revision 1120, Wed Apr 13 05:25:17 2011 UTC revision 1129, Mon Apr 25 18:55:18 2011 UTC
# Line 892  Line 892 
892             trExpr(e2, env, state, fn e2var =>             trExpr(e2, env, state, fn e2var =>
893             letPRIM("gtVar", IR.T_BOOL, IR.GT, [e1var, e2var], k)))             letPRIM("gtVar", IR.T_BOOL, IR.GT, [e1var, e2var], k)))
894    
          | P.BOOLVAR (b) => k (psvToIRVar(env, b))  
   
895           | P.AND(c1, c2) =>           | P.AND(c1, c2) =>
896             grabVar(c1, env, state, fn c1Var =>             grabVar(c1, env, state, fn c1Var =>
897             grabVar(c2, env, state, fn c2Var =>             grabVar(c2, env, state, fn c2Var =>
# Line 924  Line 922 
922         vars, state_vars, render_vars         vars, state_vars, render_vars
923      }) = let      }) = let
924        val blks = ref[]        val blks = ref[]
925        fun convertToIR (PSV.SV{name, ty, id, ...}) = IR.newParam("ps_" ^ name, IR.psvTyToIRTy ty)  
926          val demand = IR.getDemand(render)
927          fun getIRNameForSV (v as PSV.SV{name, ...}) =
928           (case (PSV.SVMap.find (render_vars, v))
929             of SOME na => let
930               fun inDemand n = List.exists (fn x => #1 x = "ps_" ^ n) demand
931              in
932               (* Sanity check *)
933               if not (inDemand na) then
934                 raise Fail (String.concat["Variable with name ", name," marked for rendering but not in demand."])
935               else
936                 "ps_" ^ na
937              end
938              | NONE => "ps_" ^ name
939           (* end case *))
940    
941          fun convertToIR (v as PSV.SV{ty, ...}) = IR.newParam(getIRNameForSV v, IR.psvTyToIRTy ty)
942        val env = let        val env = let
943                (* add special globals to free vars *)                (* add special globals to free vars *)
944          val pgm_vars = PSV.Set.union(PSV.Set.singleton epsilon, vars)          val pgm_vars = PSV.Set.union(PSV.Set.singleton epsilon, vars)
# Line 962  Line 976 
976                 | P.DIE => IR.DISCARD                 | P.DIE => IR.DISCARD
977    
978                 | P.ASSIGN(sv, expr) => let                 | P.ASSIGN(sv, expr) => let
979                   val PSV.SV{name, ty, ...} = sv                   val PSV.SV{ty, ...} = sv
980                   fun replaceStateVar (var, []) = [var]                   fun replaceStateVar (var, []) = [var]
981                     | replaceStateVar (var, nv :: svars) = let                     | replaceStateVar (var, nv :: svars) = let
982                       val IR.V{name=nvname, ...} = nv                       val IR.V{name=nvname, ...} = nv
# Line 975  Line 989 
989                      end                      end
990                  in                  in
991                   trExpr(expr, env, state, fn newVar =>                   trExpr(expr, env, state, fn newVar =>
992                   letPRIM("ps_" ^ name, IR.psvTyToIRTy ty, IR.COPY, [newVar],                   letPRIM(getIRNameForSV sv, IR.psvTyToIRTy ty, IR.COPY, [newVar],
993                     fn thisVar => f (replaceStateVar(thisVar, state))))                     fn thisVar => f (replaceStateVar(thisVar, state))))
994                  end                  end
995    
996                (* end case *))                (* end case *))
 (*  
               (case acts  
                  of [] => raise Fail "Should never reach here."  
                   | [act] => trAct(act, env, state, evalActs f psal)  
                   | act :: rest => trAct(act, env, state, evalActs f (P.SEQ(rest) :: psal))  
                 (* end case *))  
                | P.PRED(pred as P.PR{thenstmt=t, elsestmt=e, ...}) => let  
                 val cblk = newBlock(env, userVarsFromState(state), evalActs f psal)  
                 fun trPredActs [] state' = goto(state', cblk)  
                   | trPredActs _ _ = raise Fail "Should never reach here."  
                      in  
                    trPred(pred, env, state, evalActs trPredActs t, evalActs trPredActs e)  
                      end  
               (* end case *))  
 *)  
997    
998            (* The entry block is the first block of the program, or in other words, the emitter. *)            (* The entry block is the first block of the program, or in other words, the emitter. *)
999            val entryBlock = newBlock (            val entryBlock = newBlock (
# Line 1017  Line 1016 
1016    
1017        fun extractVarMap(TE(blks, map)) = map        fun extractVarMap(TE(blks, map)) = map
1018    
1019          fun convertDemand (name, x) = ("ps_" ^ name, x)
1020    
1021            val outPgm = PSysIR.PGM {            val outPgm = PSysIR.PGM {
1022              globals = PSV.Map.filter isGlobal (extractVarMap env),              globals = PSV.Map.filter isGlobal (extractVarMap env),
1023              persistents = [],              persistents = List.map convertDemand demand,
1024              uveOptimized = false,              uveOptimized = false,
1025          emitter = entryBlock,          emitter = entryBlock,
1026              physics = List.nth(!blks, 1),              physics = List.nth(!blks, 1),

Legend:
Removed from v.1120  
changed lines
  Added in v.1129

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