From 0e97f0797dfa861441ca0d3d9b8384ebd0b709ca Mon Sep 17 00:00:00 2001 From: Eduardo Julian Date: Sat, 30 Oct 2021 01:29:16 -0400 Subject: Got extension-handler types to line-up in non-hosted compilers. --- stdlib/source/library/lux/meta.lux | 58 +++++++++--------- .../language/lux/phase/extension/directive/lux.lux | 68 ++++++++++++++++++++-- 2 files changed, 96 insertions(+), 30 deletions(-) (limited to 'stdlib') diff --git a/stdlib/source/library/lux/meta.lux b/stdlib/source/library/lux/meta.lux index 4a8658eb1..a32be80ad 100644 --- a/stdlib/source/library/lux/meta.lux +++ b/stdlib/source/library/lux/meta.lux @@ -1,30 +1,30 @@ (.using - [library - [lux {"-" type macro try} - [abstract - [functor {"+" Functor}] - [apply {"+" Apply}] - ["[0]" monad {"+" Monad do}]] - [control - ["[0]" maybe] - ["[0]" try {"+" Try}]] - [data - ["[0]" product] - ["[0]" text ("[1]#[0]" monoid order)] - [collection - ["[0]" list ("[1]#[0]" monoid monad)] - [dictionary - ["[0]" plist]]]] - [macro - ["[0]" code]] - [math - [number - ["n" nat] - ["i" int]]] - [meta - ["[0]" symbol ("[1]#[0]" codec equivalence)]]]] - [/ - ["[0]" location]]) + [library + [lux {"-" type macro try} + [abstract + [functor {"+" Functor}] + [apply {"+" Apply}] + ["[0]" monad {"+" Monad do}]] + [control + ["[0]" maybe] + ["[0]" try {"+" Try}]] + [data + ["[0]" product] + ["[0]" text ("[1]#[0]" monoid order)] + [collection + ["[0]" list ("[1]#[0]" monoid monad)] + [dictionary + ["[0]" plist]]]] + [macro + ["[0]" code]] + [math + [number + ["n" nat] + ["i" int]]] + [meta + ["[0]" symbol ("[1]#[0]" codec equivalence)]]]] + [/ + ["[0]" location]]) ... (type: (Meta a) ... (-> Lux (Try [Lux a]))) @@ -664,3 +664,9 @@ {try.#Failure error} {try.#Success [lux {try.#Failure error}]}))) + +(def: .public target + (Meta Text) + (function (_ lux) + {try.#Success [lux + (value@ [.#info .#target] lux)]})) diff --git a/stdlib/source/library/lux/tool/compiler/language/lux/phase/extension/directive/lux.lux b/stdlib/source/library/lux/tool/compiler/language/lux/phase/extension/directive/lux.lux index a0ed6f3e6..12a13781c 100644 --- a/stdlib/source/library/lux/tool/compiler/language/lux/phase/extension/directive/lux.lux +++ b/stdlib/source/library/lux/tool/compiler/language/lux/phase/extension/directive/lux.lux @@ -1,6 +1,7 @@ (.using [library [lux "*" + ["@" target] ["[0]" meta] [abstract ["[0]" monad {"+" do}]] @@ -11,17 +12,20 @@ ["<>" parser ["<[0]>" code {"+" Parser}]]] [data + ["[0]" binary] ["[0]" product] ["[0]" text ["%" format {"+" format}]] [collection - ["[0]" dictionary]]] + ["[0]" dictionary] + ["[0]" array] + ["[0]" list ("[1]#[0]" functor)]]] [macro ["[0]" code]] [math [number ["n" nat]]] - ["[0]" type {"+" :sharing} + ["[0]" type {"+" :sharing} ("[1]#[0]" equivalence) ["[0]" check]]]] ["[0]" /// {"+" Extender} ["[1][0]" bundle] @@ -351,6 +355,50 @@ (define_alias alias def_name)))] (in /////directive.no_requirements)))])) +... TODO: Stop requiring these types and the "swapped" function below to make types line-up. +(template [ ] + [(def: + Type + (with_expansions [ binary.Binary] + (let [_ ] + {.#Named (symbol ) + })))] + + [Binary|Python (Primitive "bytearray")] + [Binary|DEFAULT (type (array.Array (I64 Any)))] + ) + +(def: (swapped original replacement) + (-> Type Type Type Type) + (function (again type) + (if (type#= original type) + replacement + (case type + {.#Primitive name parameters} + {.#Primitive name (list#each again parameters)} + + (^template [] + [{ left right} + { (again left) (again right)}]) + ([.#Sum] + [.#Product] + [.#Function] + [.#Apply]) + + (^or {.#Parameter _} + {.#Var _} + {.#Ex _}) + type + + (^template [] + [{ closure body} + { closure (again body)}]) + ([.#UnivQ] + [.#ExQ]) + + {.#Named name anonymous} + {.#Named name (again anonymous)})))) + (template [ ] [(def: ( [anchorT expressionT directiveT] extender) (All (_ anchor expression directive) @@ -360,9 +408,21 @@ (case inputsC+ (^ (list nameC valueC)) (do phase.monad - [[_ _ name] (evaluate! archive Text nameC) + [target_platform (/////directive.lifted_analysis + (///.lifted meta.target)) + [_ _ name] (evaluate! archive Text nameC) [_ handlerV] ( archive (:as Text name) - (type ) + (let [raw_type (type )] + (case target_platform + (^or (^ (static @.jvm)) + (^ (static @.js))) + raw_type + + (^ (static @.python)) + (swapped binary.Binary Binary|Python raw_type) + + _ + (swapped binary.Binary Binary|DEFAULT raw_type))) valueC) _ (<| (///.install extender (:as Text name)) -- cgit v1.2.3