diff options
author | Eduardo Julian | 2019-03-26 21:23:30 -0400 |
---|---|---|
committer | Eduardo Julian | 2019-03-26 21:23:30 -0400 |
commit | 8df108600f6791237d0079af6b582e6cb306906d (patch) | |
tree | d47d2d0d8cccb58b2baa758057670c35123a187e /stdlib/source | |
parent | e76fd0e68475f65e75c1339cfcef6a8114707472 (diff) |
Got the Python compiler running.
Diffstat (limited to '')
3 files changed, 13 insertions, 9 deletions
diff --git a/stdlib/source/lux/tool/compiler/phase/generation.lux b/stdlib/source/lux/tool/compiler/phase/generation.lux index a22077df4..882e1127f 100644 --- a/stdlib/source/lux/tool/compiler/phase/generation.lux +++ b/stdlib/source/lux/tool/compiler/phase/generation.lux @@ -52,7 +52,7 @@ (signature: #export (Host expression statement) (: (-> Text expression (Error Any)) evaluate!) - (: (-> Text statement (Error Any)) + (: (-> Text statement (Error Nothing)) execute!) (: (-> Name expression (Error [Text Any statement])) define!)) @@ -179,6 +179,11 @@ _ (extension.update (update@ #counter inc))] (wrap count))) +(def: #export (gensym prefix) + (All [anchor expression statement] + (-> Text (Operation anchor expression statement Text))) + (:: //.monad map (|>> %n (format prefix)) ..next)) + (do-template [<name> <inputT>] [(def: #export (<name> label code) (All [anchor expression statement] @@ -210,8 +215,8 @@ (All [anchor expression statement] (-> Name statement (Operation anchor expression statement Any))) (do //.monad - [count ..next - _ (execute! (format "save" (%n count)) code) + [label (..gensym "save") + _ (execute! label code) ?buffer (extension.read (get@ #buffer))] (case ?buffer (#.Some buffer) diff --git a/stdlib/source/lux/tool/compiler/phase/generation/python/function.lux b/stdlib/source/lux/tool/compiler/phase/generation/python/function.lux index c92f6dd37..3ba95e0f3 100644 --- a/stdlib/source/lux/tool/compiler/phase/generation/python/function.lux +++ b/stdlib/source/lux/tool/compiler/phase/generation/python/function.lux @@ -44,7 +44,7 @@ _ (do ////.monad - [@closure (:: @ map (|>> %n (format "closure") _.var) ///.next) + [@closure (:: @ map _.var (///.gensym "closure")) _ (///.save! ["" (_.code @closure)] (_.def @closure (|> (list.enumerate inits) @@ -54,8 +54,6 @@ (_.return (_.var function-name)))))] (wrap (_.apply/* @closure inits))))) -(def: @curried (_.var "curried")) - (def: input (|>> inc //case.register)) @@ -69,7 +67,8 @@ (generate bodyS)))) closureO+ (: (Operation (List (Expression Any))) (monad.map @ (:: //reference.system variable) environment)) - #let [arityO (|> arity .int _.int) + #let [@curried (_.var "curried") + arityO (|> arity .int _.int) @num-args (_.var "num_args") @self (_.var function-name) apply-poly (.function (_ args func) @@ -82,7 +81,7 @@ initialize-self! (list.indices arity))]] (with-closure function-name closureO+ - (_.def @self (list) + (_.def @self (list (_.poly @curried)) ($_ _.then (_.set (list @num-args) (_.len/1 @curried)) (_.cond (list [(|> @num-args (_.= arityO)) diff --git a/stdlib/source/lux/tool/compiler/phase/generation/python/runtime.lux b/stdlib/source/lux/tool/compiler/phase/generation/python/runtime.lux index fd847af16..e3a8a4537 100644 --- a/stdlib/source/lux/tool/compiler/phase/generation/python/runtime.lux +++ b/stdlib/source/lux/tool/compiler/phase/generation/python/runtime.lux @@ -78,7 +78,7 @@ (def: runtime-name (-> Text SVar) (|>> /////name.normalize - (format ..prefix "$") + (format ..prefix "_") _.var)) (def: (feature name definition) |