Add example and refine local inlining
Add a new example file `examples/def_local_inlining.myc` to demonstrate and test local inlining. Refine the optimizer to handle local inlining more robustly by: - Passing a `SubstitutionMap` to `visit_node` to track local variable substitutions. - Enabling constant propagation for local variables by checking `sub.locals` in `BoundKind::Get`. - Updating `BoundKind::DefLocal` and `BoundKind::Set` to maintain the substitution map for local variables. - Adjusting `try_beta_reduce` to use the optimizer's `visit_node` with the substitution map for inlining. - Re-indexing upvalues correctly when inlining captured variables into lambdas.
This commit is contained in:
@@ -0,0 +1,23 @@
|
||||
;; examples/def_local_inlining.myc
|
||||
;; Demonstrates potential for DefLocal-Inlining (Phase 2.5)
|
||||
|
||||
(fn []
|
||||
(do
|
||||
;; 1. Simple constant propagation
|
||||
(def x 10)
|
||||
(def y 20)
|
||||
|
||||
;; Expected optimization: (+ 10 20) -> 30
|
||||
(def z (+ x y))
|
||||
|
||||
;; 2. Tracking assignments (Assign-Safety)
|
||||
;; Inlining must be careful with 'assign'.
|
||||
(def result
|
||||
(do
|
||||
(def a 100)
|
||||
(assign a 200)
|
||||
;; Expected optimization: 200
|
||||
a))
|
||||
|
||||
;; 3. Return a tuple of optimized results
|
||||
[z result]))
|
||||
Reference in New Issue
Block a user