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 866, Thu Apr 29 20:16:27 2010 UTC revision 867, Thu Apr 29 21:06:21 2010 UTC
# Line 381  Line 381 
381          fun trPred(pred, env, state, thenk : particle_state -> IR.stmt, elsek : particle_state -> IR.stmt) = let          fun trPred(pred, env, state, thenk : particle_state -> IR.stmt, elsek : particle_state -> IR.stmt) = let
382            val PS{pos, vel, size, isDead, color, ...} = state            val PS{pos, vel, size, isDead, color, ...} = state
383            val P.PR{ifstmt, ...} = pred            val P.PR{ifstmt, ...} = pred
           val thenBlk = newBlock(env, thenk)  
           val elseBlk = newBlock(env, elsek)  
384           in           in
385            case ifstmt            case ifstmt
386             of P.WITHIN(d) => mkWithinVar("wv", env, pos, d, fn withinVar =>             of P.WITHIN(d) => mkWithinVar("wv", env, pos, d, fn withinVar =>
387              IR.mkIF(withinVar, goto(state, thenBlk), goto(state, elseBlk)))              IR.mkIF(withinVar, thenk(state), elsek(state)))
388              | P.WITHINVEL(d) => mkWithinVar("wv", env, vel, d, fn withinVar =>              | P.WITHINVEL(d) => mkWithinVar("wv", env, vel, d, fn withinVar =>
389              IR.mkIF(withinVar, goto(state, thenBlk), goto(state, elseBlk)))              IR.mkIF(withinVar, thenk(state), elsek(state)))
390           end           end
391    
392      fun trAct (action, env, state, k : particle_state -> IR.stmt) = let      fun trAct (action, env, state, k : particle_state -> IR.stmt) = let
# Line 516  Line 514 
514                  in                  in
515                    TE(blks, PSV.Set.foldl ins PSV.Map.empty vars)                    TE(blks, PSV.Set.foldl ins PSV.Map.empty vars)
516                  end                  end
517    
518              fun evalActs f [] state = f [] state
519                | evalActs f (psa :: psal) state = (case psa
520                  of P.SEQ(acts) => (case acts
521                     of [] => raise Fail "Should never reach here."
522                      | [act] => trAct(act, env, state, evalActs f psal)
523                      | act :: rest => trAct(act, env, state, evalActs f (P.SEQ(rest) :: psal))
524                    (* end case *))
525                   | P.PRED(pred as P.PR{thenstmt=t, elsestmt=e, ...}) => let
526                       val cblk = newBlock(env, evalActs f psal)
527                       fun trPredActs [] state' = goto(state', cblk)
528                         | trPredActs _ _ = raise Fail "Should never reach here."
529                      in
530                       trPred(pred, env, state, evalActs trPredActs t, evalActs trPredActs e)
531                      end
532                  (* end case *))
533    
534            fun trActs [] state = let            fun trActs [] state = let
535                  val PS{pos, vel, size, isDead, color, dummy} = state                  val PS{pos, vel, size, isDead, color, dummy} = state
536                  in                  in
537                    IR.mkRETURN[ pos, vel, size, isDead, color, dummy ]                    IR.mkRETURN[ pos, vel, size, isDead, color, dummy ]
538                  end (* trActs *)                  end (* trActs *)
539              | trActs (psa :: psal) state = (case psa              | trActs _ _ = raise Fail "Should never reach here"
               of P.SEQ(acts) => (case acts  
                  of [] => raise Fail "Should never reach here."  
                   | [act] => trAct(act, env, state, trActs psal)  
                   | act :: rest => trAct(act, env, state, trActs (P.SEQ(rest) :: psal))  
                 (* end case *))  
                | P.PRED(pred as P.PR{thenstmt=t, elsestmt=e, ...}) =>  
                   trPred(pred, env, state, trActs (t @ psal), trActs (e @ psal))  
               (* end case *))  
540    
541            val entryBlock = newBlock (env, fn pstate => trEmitter(emit, env, pstate, fn state => trActs root_act state))            val entryBlock = newBlock (env, fn pstate => trEmitter(emit, env, pstate, fn state => evalActs trActs root_act state))
542            val outPgm = PSysIR.PGM {            val outPgm = PSysIR.PGM {
543              emitter = entryBlock,              emitter = entryBlock,
544              physics = List.drop(!blks, 1),              physics = List.drop(!blks, 1),

Legend:
Removed from v.866  
changed lines
  Added in v.867

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