Permalink
Browse files

[refactor] jslang: Move some misplaced qmljsimp modules to jslang

  • Loading branch information...
1 parent 51a736b commit 77db9c6f387b28765624b36f9c7d1e73b858814e @BourgerieQuentin BourgerieQuentin committed Oct 17, 2012
View
@@ -11,3 +11,6 @@ compiler/jslang/JsParse
compiler/jslang/JsUtils
compiler/jslang/JsAstRuntime
compiler/jslang/JsPackage
+compiler/jslang/JsRenaming
+compiler/jslang/JsSimpleRenaming
+compiler/jslang/JsCleanUp
View
@@ -8,3 +8,6 @@
<{jspp,jsstat,globalizer}.{ml,byte,native}>:use_libtools, use_libruntime, use_oparuntime, use_ssl, use_appruntime, use_libnet, use_libsecurity, use_qmljsimp
<globalizer.{ml,byte,native}>:use_pplib, use_buildinfos
<jsPackage.ml>:use_buildinfos
+<jsRenaming.ml>: use_graph
+
+<jsRenaming.ml>: with_mlstate_debug
@@ -1,5 +1,5 @@
(*
- Copyright © 2011 MLstate
+ Copyright © 2011, 2012 MLstate
This file is part of Opa.
@@ -341,7 +341,7 @@ let clean_assign ~use_shortcut_assignment stm =
(fun s ->
match s with
- | J.Js_expr (_,e) when not (Imp_Common.does_side_effects e) ->
+ | J.Js_expr (_,e) when not (JsUtils.does_side_effects e) ->
JsCons.Statement.block []
| J.Js_if (label,J.Je_unop(_,J.Ju_not,e),s1,Some s2) ->
@@ -516,7 +516,7 @@ let clean_assign ~use_shortcut_assignment stm =
| J.Je_comma (label,el,e) ->
(* (side_effect_free_expr, e) -> e *)
- let el = List.filter Imp_Common.does_side_effects el in
+ let el = List.filter JsUtils.does_side_effects el in
if el = [] then e else J.Je_comma (label,el,e)
| J.Je_function (label,name_opt,params,body) ->
File renamed without changes.
@@ -1,5 +1,5 @@
(*
- Copyright © 2011 MLstate
+ Copyright © 2011, 2012 MLstate
This file is part of Opa.
@@ -818,7 +818,7 @@ let rename_code_elt code_elt =
acc, J.Je_function (label,name,params,body)
| _ -> tra acc e)
false code_elt in
- if failed then Imp_SimpleRenaming.local_alpha_stm code_elt else code_elt
+ if failed then JsSimpleRenaming.local_alpha_stm code_elt else code_elt
let rename code =
List.map rename_code_elt code
File renamed without changes.
View
@@ -294,3 +294,37 @@ and compare_statement s0 s1 =
| s0, s1 -> Pervasives.compare s0 s1
and compare_code s0 s1 = List.make_compare compare_statement s0 s1
+
+(* a very conservative approximation of which expressions do observable side
+ * effects *)
+let does_side_effects e =
+ JsWalk.OnlyExpr.exists
+ (function
+ | J.Je_hole _
+ | J.Je_new _
+ | J.Je_call (_,_,_,false) -> true
+ | J.Je_unop (_, ( J.Ju_delete
+ | J.Ju_add2_pre
+ | J.Ju_sub2_pre
+ | J.Ju_add2_post
+ | J.Ju_sub2_post), _) -> true
+ | J.Je_binop (_, ( J.Jb_assign
+ | J.Jb_mul_assign
+ | J.Jb_div_assign
+ | J.Jb_mod_assign
+ | J.Jb_add_assign
+ | J.Jb_sub_assign
+ | J.Jb_lsl_assign
+ | J.Jb_lsr_assign
+ | J.Jb_asr_assign
+ | J.Jb_and_assign
+ | J.Jb_xor_assign
+ | J.Jb_or_assign ), _, _) -> true
+
+ | J.Je_runtime (_, e) -> (
+ match e with
+ | JsAstRuntime.SetDistant _ -> true
+ | JsAstRuntime.TaggedString _ -> false
+ )
+ | _ -> false
+ ) e
@@ -83,3 +83,7 @@ val compare_expr : JsAst.expr -> JsAst.expr -> int
val compare_statement : JsAst.statement -> JsAst.statement -> int
val compare_code : JsAst.code -> JsAst.code -> int
+
+(** A very conservative approximation of which expressions do observable side
+ effects *)
+val does_side_effects : JsAst.expr -> bool
View
@@ -29,8 +29,3 @@ compiler/libbsl/BslArgs
compiler/libbsl/BslTracker
compiler/libbsl/BslGeneration
compiler/libbsl/BslJsParse
-
-compiler/libbsl/Imp_SimpleRenaming
-compiler/libbsl/Imp_Common
-compiler/libbsl/Imp_Renaming
-compiler/libbsl/Imp_CleanUp
View
@@ -825,15 +825,15 @@ let build_file ~transform renaming env file =
let apply_conf conf code =
let code =
- if conf.BslJsConf.localrenaming then Imp_Renaming.rename code
+ if conf.BslJsConf.localrenaming then JsRenaming.rename code
else code
in
let code =
- if conf.BslJsConf.cleanup then Imp_CleanUp.clean ~use_shortcut_assignment:true code
+ if conf.BslJsConf.cleanup then JsCleanUp.clean ~use_shortcut_assignment:true code
else code
in
let code =
- if conf.BslJsConf.cleanup then Imp_CleanUp.clean ~use_shortcut_assignment:true code
+ if conf.BslJsConf.cleanup then JsCleanUp.clean ~use_shortcut_assignment:true code
else code in
let code = List.map JsUtils.globalize_native_ident code in
code
@@ -162,10 +162,10 @@ let parse_js_content ~optimized_conf ~key_prefix ~filename ~content =
filename
JsParse.pp e in
- let parsed_code = if optimized_conf.BslJsConf.localrenaming then Imp_Renaming.rename parsed_code else parsed_code in
+ let parsed_code = if optimized_conf.BslJsConf.localrenaming then JsRenaming.rename parsed_code else parsed_code in
(* cleanup does not always reaches a fixpoint on the first try, it is worth applying it twice *)
- let parsed_code = if optimized_conf.BslJsConf.cleanup then Imp_CleanUp.clean ~use_shortcut_assignment:true parsed_code else parsed_code in
- let parsed_code = if optimized_conf.BslJsConf.cleanup then Imp_CleanUp.clean ~use_shortcut_assignment:true parsed_code else parsed_code in
+ let parsed_code = if optimized_conf.BslJsConf.cleanup then JsCleanUp.clean ~use_shortcut_assignment:true parsed_code else parsed_code in
+ let parsed_code = if optimized_conf.BslJsConf.cleanup then JsCleanUp.clean ~use_shortcut_assignment:true parsed_code else parsed_code in
let parsed_code = List.map JsUtils.globalize_native_ident parsed_code in
parsed_code
View
@@ -9,3 +9,4 @@ compiler/qmljsimp/Imp_SumCase
compiler/qmljsimp/Imp_Inlining
compiler/qmljsimp/Imp_Cleaning
compiler/qmljsimp/Imp_Warnings
+compiler/qmljsimp/Imp_Common
File renamed without changes.
File renamed without changes.
@@ -203,7 +203,7 @@ let compile
let stm = Imp_Inlining.local_inline_stm stm in
#<If:JS_IMP$contains "print"> ignore (PassTracker.file ~filename:(Printf.sprintf "js_imp_2_%d_local_inline" _n) _outputer [stm]) #<End>;
(* cleanup, constant folding, etc to make the code as lightweight as possible *)
- let stms = Imp_CleanUp.clean_stm ~use_shortcut_assignment:false stm in
+ let stms = JsCleanUp.clean_stm ~use_shortcut_assignment:false stm in
#<If:JS_IMP$contains "print"> ignore (PassTracker.file ~filename:(Printf.sprintf "js_imp_3_%d_cleanup" _n) _outputer stms) #<End>;
(* now that the code is as small as it can get, we analyse it to know if it is inlinable
* in particular, if inlining inside its body made the code simpler, then we can
@@ -223,7 +223,7 @@ let compile
(* local renaming must be done last, because it generates very tricky code
* when it squashes variables together *)
- let js_code = if options.Qml2jsOptions.alpha_renaming then Imp_Renaming.rename js_code else js_code in
+ let js_code = if options.Qml2jsOptions.alpha_renaming then JsRenaming.rename js_code else js_code in
#<If:JS_IMP$contains "time"> Printf.printf "local renaming: %fs\n%!" (_chrono.Chrono.read ()); _chrono.Chrono.restart () #<End>;
#<If:JS_IMP$contains "print"> ignore (PassTracker.file ~filename:"js_imp_5_local_renaming" _outputer js_code) #<End>;
let js_code, sharing_env = Imp_Sharing.process_code ~pass js_code in
@@ -252,7 +252,7 @@ let compile
in
#<If:JS_IMP$contains "time"> Printf.printf "code sharing: %fs\n%!" (_chrono.Chrono.read ()); _chrono.Chrono.restart () #<End>;
#<If:JS_IMP$contains "print"> ignore (PassTracker.file ~filename:"js_imp_6_code_sharing" _outputer js_code) #<End>;
- let js_code = if options.Qml2jsOptions.cleanup then Imp_CleanUp.clean ~use_shortcut_assignment:true js_code else js_code in
+ let js_code = if options.Qml2jsOptions.cleanup then JsCleanUp.clean ~use_shortcut_assignment:true js_code else js_code in
#<If:JS_IMP$contains "time"> Printf.printf "clean up: %fs\n%!" (_chrono.Chrono.read ()); _chrono.Chrono.restart () #<End>;
#<If:JS_IMP$contains "print"> ignore (PassTracker.file ~filename:"js_imp_7_cleanup" _outputer js_code) #<End>;
let js_code =
View
@@ -509,10 +509,8 @@ compiler/qmljsimp/Imp_Env
compiler/qmljsimp/Imp_MatchGeneration
compiler/qmljsimp/Imp_PatternAnalysis
compiler/qmljsimp/Imp_SumCase
-compiler/qmljsimp/Imp_Renaming
compiler/qmljsimp/Imp_CleanUp
compiler/qmljsimp/Imp_Inlining
-compiler/qmljsimp/Imp_SimpleRenaming
compiler/qmlcps/QmlCpsIL
compiler/qmlcps/QmlCpsRewriter

0 comments on commit 77db9c6

Please sign in to comment.