Home My Page Projects Code Snippets Project Openings diderot

# SCM Repository

[diderot] View of /branches/vis15/src/compiler/simplify/simplify-vars.sml
 [diderot] / branches / vis15 / src / compiler / simplify / simplify-vars.sml # View of /branches/vis15/src/compiler/simplify/simplify-vars.sml

Mon Nov 23 16:41:51 2015 UTC (5 years, 8 months ago) by jhr
File size: 1678 byte(s)
`working on merge`
```(* simplify-vars.sml
*
* This module analyses the use of variables in the Simple AST and rationalizes
* their use in the following ways:
*
*   -- for any strand parameter that is used in a method, we create a shadow state
*      variable
*
*   -- unused constant and global variables are elminated
*
*   -- unused strand state variables are eliminated
*
*   -- unused local variables are eliminated
*
*   -- strand-invariant state variables (except outputs) and expressions are
*      lifted to global scope
*
* This code is part of the Diderot Project (http://diderot-language.cs.uchicago.edu)
*
* COPYRIGHT (c) 2015 The University of Chicago
*)

structure SimplifyVars : sig

val transform : Simple.program -> Simple.program

end = struct

structure S = Simple

(* analyze an expression using the `doVar` and `doFld`
* functions to analyze variable uses.
*)
fun analyzeExp doVar doFld = let
fun anal (env, e) = (case e
of S.E_Var x => doVar(x, env)
| S.E_Lit _ => env
| S.E_Select(x, fld) => doFld (fld, doVar(x, env))
| S.E_Apply(f, xs, _) => List.foldl doVar env (f::xs)
| S.E_Prim(_, _, xs, _) => List.foldl doVar env xs
| S.E_Tensor(xs, _) => List.foldl doVar env xs
| S.E_Seq(xs, _) => List.foldl doVar env xs
| S.E_Slice(x, indices, _) => let
fun doIndex (NONE, env) = env
| doIndex (SOME ix, env) => doVar(ix, env)
in
doVar (x, List.foldl doIndex env indices)
end
| S.E_Coerce{x, ...} => doVar(x, env)
{"ft_lang_label":"__label__en","ft_lang_prob":0.6710487,"math_prob":0.9160509,"size":1919,"snap":"2021-31-2021-39","text_gpt3_token_len":559,"char_repetition_ratio":0.11958224,"word_repetition_ratio":0.12962963,"special_character_ratio":0.3293382,"punctuation_ratio":0.17662337,"nsfw_num_words":2,"has_unicode_error":false,"math_prob_llama3":0.9615279,"pos_list":[0,1,2],"im_url_duplicate_count":[null,null,null],"WARC_HEADER":"{\"WARC-Type\":\"response\",\"WARC-Date\":\"2021-07-31T01:38:24Z\",\"WARC-Record-ID\":\"<urn:uuid:964e2dc0-9f21-46ad-853d-804bd469e983>\",\"Content-Length\":\"14825\",\"Content-Type\":\"application/http; msgtype=response\",\"WARC-Warcinfo-ID\":\"<urn:uuid:5ac24b62-c511-4f1f-8620-ced6c093061b>\",\"WARC-Concurrent-To\":\"<urn:uuid:e2cc11cc-ddab-4378-ace3-72c1efd6bbae>\",\"WARC-IP-Address\":\"128.135.164.83\",\"WARC-Target-URI\":\"https://smlnj-gforge.cs.uchicago.edu/scm/viewvc.php/branches/vis15/src/compiler/simplify/simplify-vars.sml?view=markup&revision=3457&root=diderot&sortby=file&pathrev=3485\",\"WARC-Payload-Digest\":\"sha1:RROMRY4MO3LMJODHJPIXTPLJGNOBQWHK\",\"WARC-Block-Digest\":\"sha1:J45RXKPGR43IPXR3UW3A6QRJWRQFOVQR\",\"WARC-Identified-Payload-Type\":\"application/xhtml+xml\",\"warc_filename\":\"/cc_download/warc_2021/CC-MAIN-2021-31/CC-MAIN-2021-31_segments_1627046154042.23_warc_CC-MAIN-20210731011529-20210731041529-00304.warc.gz\"}"}