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 1134, Tue Apr 26 21:46:29 2011 UTC revision 1137, Sun May 1 20:39:30 2011 UTC
# Line 754  Line 754 
754            (* end case *))            (* end case *))
755           end)           end)
756    
757           | P.LOOKUP (varName) => let
758             fun findVar (IR.V{name, ...}) = name = varName
759            in
760             (case (List.find findVar state)
761               of SOME v => k v
762                | NONE => raise Fail("Compiler Error: Undefined variable: " ^ varName)
763             (* end case *))
764            end
765    
766            (* end case expr *))            (* end case expr *))
767    
768            (* generate code to produce a random particle state from a domain *)            (* generate code to produce a random particle state from a domain *)
# Line 892  Line 901 
901                          PSV.Map.insert (map, x, x')                          PSV.Map.insert (map, x, x')
902                     end (* ins *)                     end (* ins *)
903                  in                  in
                  List.app printVar (PSV.Set.listItems pgm_vars);  
904                   TE( blks, PSV.Set.foldl insv PSV.Map.empty pgm_vars )                   TE( blks, PSV.Set.foldl insv PSV.Map.empty pgm_vars )
905                  end (* env *)                  end (* env *)
906    
# Line 902  Line 910 
910                   | oneAct :: rest => evalActs oneAct state (fn state' => (evalActs (P.SEQ(rest)) state' f))                   | oneAct :: rest => evalActs oneAct state (fn state' => (evalActs (P.SEQ(rest)) state' f))
911                  (* end case *))                  (* end case *))
912    
913                 | P.PRED(cond, thenAct, elseAct) =>                 | P.PRED(cond, thenAct, elseAct) => let
914                       val joinBlk = newBlock (env, state, fn state' => f state')
915                       fun joinActs state = IR.mkGOTO(joinBlk, state)
916                      in
917                   trPred(cond, env, state,                   trPred(cond, env, state,
918                     fn state' => evalActs thenAct state' f,                       fn state' => evalActs thenAct state' joinActs,
919                     fn state' => evalActs elseAct state' f                       fn state' => evalActs elseAct state' joinActs
920                   )                   )
921                      end
922    
923                 | P.DIE => IR.DISCARD                 | P.DIE => IR.DISCARD
924    
# Line 928  Line 940 
940                     fn thisVar => f (replaceStateVar(thisVar, state))))                     fn thisVar => f (replaceStateVar(thisVar, state))))
941                  end                  end
942    
943                   | P.LET(P.V(varName), exp, act) =>
944                     trExpr(exp, env, state, fn newVar => let
945    
946                       val joinBlk = newBlock(env, state, f)
947    
948                       fun inOriginalState (IR.V{name=vn, ...}) = let
949                         fun nameCompare (IR.V{name=vn1, ...}) = vn = vn1
950                        in
951                         List.exists nameCompare state
952                        end
953    
954                       fun gotoJoinBlk state' = goto(List.filter inOriginalState state', joinBlk)
955    
956                       val IR.V{varType, ...} = newVar
957                       val newParam = IR.newParam(varName, varType)
958                       val newState = newParam :: state
959    
960                       val blk = newBlock(env, newState, fn state' => evalActs act state' gotoJoinBlk)
961                      in
962                       goto(newState, blk)
963                      end
964                     )
965    
966                (* end case *))                (* end case *))
967    
968            (* 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. *)

Legend:
Removed from v.1134  
changed lines
  Added in v.1137

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