From ae7fc0207c8d3281882261642f6a8e0579985aa0 Mon Sep 17 00:00:00 2001 From: Eduardo Julian Date: Wed, 24 Feb 2021 16:39:42 -0400 Subject: Done with Python. --- lux-python/project.clj | 2 +- lux-python/source/program.lux | 108 ++++++++++++++++++++++++++++++++---------- 2 files changed, 84 insertions(+), 26 deletions(-) (limited to 'lux-python') diff --git a/lux-python/project.clj b/lux-python/project.clj index 887cd2b89..88f4cec40 100644 --- a/lux-python/project.clj +++ b/lux-python/project.clj @@ -6,7 +6,7 @@ (defproject com.github.luxlang/lux-python #=(identity version) :description "A Python compiler for Lux." :url ~repo - :license {:name "Lux License v0.1" + :license {:name "Lux License v0.1.1" :url ~(str repo "/blob/master/license.txt")} :scm {:name "git" :url ~(str repo ".git")} diff --git a/lux-python/source/program.lux b/lux-python/source/program.lux index 4fae4b331..166dee982 100644 --- a/lux-python/source/program.lux +++ b/lux-python/source/program.lux @@ -42,7 +42,7 @@ [analysis [macro (#+ Expander)]] [phase - ["." extension (#+ Extender Handler) + ["." extension (#+ Bundle Extender Handler) ["#/." bundle] ["." analysis #_ ["#" python]] @@ -100,6 +100,8 @@ ["#::." (__call__ [[org/python/core/PyObject]] #try org/python/core/PyObject)]) + (import: org/python/core/ThreadState) + (import: org/python/core/PyArray ["#::." (new [(java/lang/Class java/lang/Object) java/lang/Object]) @@ -352,30 +354,86 @@ _.none))))) (for {@.old - (def: extender - Extender - ## TODO: Stop relying on coercions ASAP. - (<| (:coerce Extender) - (function (@self handler)) - (:coerce Handler) - (function (@self name phase)) - (:coerce Phase) - (function (@self archive parameters)) - (:coerce Operation) - (function (@self state)) - (:coerce Try) - try.assume - (:coerce Try) - (do try.monad - [handler (try.from_maybe (..ensure_function handler)) - output (org/python/core/PyFunction::__call__ (|> (host.array org/python/core/PyObject 5) - (host.array_write 0 (org/python/core/PyString::new name)) - (host.array_write 1 (..to_host phase)) - (host.array_write 2 (..to_host archive)) - (host.array_write 3 (..to_host parameters)) - (host.array_write 4 (..to_host state))) - handler)] - (..read output)))) + (as_is (exception: #export (cannot_parse_phase_inputs {arity Nat}) + (exception.report + ["Arity" (%.nat arity)])) + + (def: (host_phase phase) + (All [s i o] + (-> (Phase [Bundle s] i o) + org/python/core/PyObject)) + (host.object [] org/python/core/PyObject [] + [] + ## Methods + (org/python/core/PyObject + [] (__call__ self + {_ org/python/core/ThreadState} + {input/0 org/python/core/PyObject}) + org/python/core/PyObject + (case [(..read input/0)] + [(#try.Success input/0)] + (host_phase (:assume ((:coerce (-> Nat Nat Nat []) phase) + (:coerce Nat input/0)))) + + _ + (error! (exception.construct ..cannot_parse_phase_inputs [1])))) + + (org/python/core/PyObject + [] (__call__ self + {_ org/python/core/ThreadState} + {input/0 org/python/core/PyObject} + {input/1 org/python/core/PyObject}) + org/python/core/PyObject + (case [(..read input/0) (..read input/1)] + [(#try.Success input/0) (#try.Success input/1)] + (host_phase (:assume ((:coerce (-> Nat Nat Nat []) phase) + (:coerce Nat input/0) + (:coerce Nat input/1)))) + + _ + (error! (exception.construct ..cannot_parse_phase_inputs [2])))) + + (org/python/core/PyObject + [] (__call__ self + {_ org/python/core/ThreadState} + {input/0 org/python/core/PyObject} + {input/1 org/python/core/PyObject} + {input/2 org/python/core/PyObject}) + org/python/core/PyObject + (case [(..read input/0) (..read input/1) (..read input/2)] + [(#try.Success input/0) (#try.Success input/1) (#try.Success input/2)] + (..to_host ((:coerce (-> Nat Nat Nat []) phase) + (:coerce Nat input/0) + (:coerce Nat input/1) + (:coerce Nat input/2))) + + _ + (error! (exception.construct ..cannot_parse_phase_inputs [3])))))) + + (def: extender + Extender + ## TODO: Stop relying on coercions ASAP. + (<| (:coerce Extender) + (function (@self handler)) + (:coerce Handler) + (function (@self name phase)) + (:coerce Phase) + (function (@self archive parameters)) + (:coerce Operation) + (function (@self state)) + (:coerce Try) + try.assume + (:coerce Try) + (do try.monad + [handler (try.from_maybe (..ensure_function handler)) + output (org/python/core/PyFunction::__call__ (|> (host.array org/python/core/PyObject 5) + (host.array_write 0 (org/python/core/PyString::new name)) + (host.array_write 1 (..host_phase phase)) + (host.array_write 2 (..to_host archive)) + (host.array_write 3 (..to_host parameters)) + (host.array_write 4 (..to_host state))) + handler)] + (..read output))))) @.python (def: (extender handler) -- cgit v1.2.3