diff options
author | Eduardo Julian | 2022-03-14 01:09:08 -0400 |
---|---|---|
committer | Eduardo Julian | 2022-03-14 01:09:08 -0400 |
commit | b8681fd206d5b5076b9737ee54f0cb0405a898d6 (patch) | |
tree | 6ba25cc4f31ad07b4279828568e9019f26334eca /stdlib/source/library/lux/ffi.rb.lux | |
parent | 6766be5427b1788a44e07151e3fabe33ec4f8b37 (diff) |
Can now add type-vars to imported procedures from scripting languages.
Diffstat (limited to 'stdlib/source/library/lux/ffi.rb.lux')
-rw-r--r-- | stdlib/source/library/lux/ffi.rb.lux | 336 |
1 files changed, 0 insertions, 336 deletions
diff --git a/stdlib/source/library/lux/ffi.rb.lux b/stdlib/source/library/lux/ffi.rb.lux deleted file mode 100644 index 21dae9b6f..000000000 --- a/stdlib/source/library/lux/ffi.rb.lux +++ /dev/null @@ -1,336 +0,0 @@ -(.using - [library - [lux {"-" Alias} - ["@" target] - ["[0]" meta] - [abstract - [monad {"+" do}]] - [control - ["[0]" io] - ["[0]" maybe] - ["<>" parser ("[1]#[0]" monad) - ["<[0]>" code {"+" Parser}]]] - [data - ["[0]" product] - ["[0]" text - ["%" format]] - [collection - ["[0]" list ("[1]#[0]" functor)]]] - [type - abstract] - [macro {"+" with_symbols} - [syntax {"+" syntax:}] - ["[0]" code] - ["[0]" template]]]]) - -(abstract: .public (Object brand) Any) - -(template [<name>] - [(with_expansions [<brand> (template.symbol [<name> "'"])] - (abstract: <brand> Any) - (type: .public <name> - (..Object <brand>)))] - - [Nil] - [Function] - ) - -(template [<name> <type>] - [(type: .public <name> - <type>)] - - [Boolean Bit] - [Integer Int] - [Float Frac] - [String Text] - ) - -(type: Nilable - [Bit Code]) - -(def: nilable - (Parser Nilable) - (let [token (' "?")] - (<| (<>.and (<>.parses? (<code>.this! token))) - (<>.after (<>.not (<code>.this! token))) - <code>.any))) - -(type: Alias - Text) - -(def: alias - (Parser Alias) - (<>.after (<code>.this! (' "as")) <code>.local_symbol)) - -(type: Field - [Bit Text (Maybe Alias) Nilable]) - -(def: static! - (Parser Any) - (<code>.this! (' "static"))) - -(def: field - (Parser Field) - (<code>.form ($_ <>.and - (<>.parses? ..static!) - <code>.local_symbol - (<>.maybe ..alias) - ..nilable))) - -(def: constant - (Parser Field) - (<code>.form ($_ <>.and - (<>#in true) - <code>.local_symbol - (<>.maybe ..alias) - ..nilable))) - -(type: Common_Method - (Record - [#name Text - #alias (Maybe Alias) - #inputs (List Nilable) - #io? Bit - #try? Bit - #output Nilable])) - -(type: Static_Method Common_Method) -(type: Virtual_Method Common_Method) - -(type: Method - (Variant - {#Static Static_Method} - {#Virtual Virtual_Method})) - -(def: common_method - (Parser Common_Method) - ($_ <>.and - <code>.local_symbol - (<>.maybe ..alias) - (<code>.tuple (<>.some ..nilable)) - (<>.parses? (<code>.this! (' "io"))) - (<>.parses? (<code>.this! (' "try"))) - ..nilable)) - -(def: static_method - (<>.after ..static! ..common_method)) - -(def: method - (Parser Method) - (<code>.form (<>.or ..static_method - ..common_method))) - -(type: Member - (Variant - {#Field Field} - {#Method Method})) - -(def: member - (Parser Member) - ($_ <>.or - ..field - ..method - )) - -(def: input_variables - (-> (List Nilable) (List [Bit Code])) - (|>> list.enumeration - (list#each (function (_ [idx [nilable? type]]) - [nilable? (|> idx %.nat code.local_symbol)])))) - -(def: (nilable_type [nilable? type]) - (-> Nilable Code) - (if nilable? - (` (.Maybe (~ type))) - type)) - -(def: (with_nil g!temp [nilable? input]) - (-> Code [Bit Code] Code) - (if nilable? - (` (case (~ input) - {.#Some (~ g!temp)} - (~ g!temp) - - {.#None} - ("ruby object nil"))) - input)) - -(def: (without_nil g!temp [nilable? outputT] output) - (-> Code Nilable Code Code) - (if nilable? - (` (let [(~ g!temp) (~ output)] - (if ("ruby object nil?" (~ g!temp)) - {.#None} - {.#Some (~ g!temp)}))) - (` (let [(~ g!temp) (~ output)] - (if (not ("ruby object nil?" (~ g!temp))) - (~ g!temp) - (.panic! "Nil is an invalid value!")))))) - -(type: Import - (Variant - {#Class Text (Maybe Alias) Text (List Member)} - {#Function Static_Method} - {#Constant Field})) - -(def: import - (Parser [(Maybe Text) Import]) - ($_ <>.and - (<>.maybe <code>.text) - ($_ <>.or - ($_ <>.and - <code>.local_symbol - (<>.maybe ..alias) - (<>.else ["" (list)] - (<code>.tuple (<>.and <code>.text - (<>.some member))))) - (<code>.form ..common_method) - ..constant - ))) - -(def: (with_io with? without) - (-> Bit Code Code) - (if with? - (` ((~! io.io) (~ without))) - without)) - -(def: (io_type io? rawT) - (-> Bit Code Code) - (if io? - (` ((~! io.IO) (~ rawT))) - rawT)) - -(def: (with_try with? without_try) - (-> Bit Code Code) - (if with? - (` (.try (~ without_try))) - without_try)) - -(def: (try_type try? rawT) - (-> Bit Code Code) - (if try? - (` (.Either .Text (~ rawT))) - rawT)) - -(def: (make_function g!method g!temp source inputsT io? try? outputT) - (-> Code Code Code (List Nilable) Bit Bit Nilable Code) - (let [g!inputs (input_variables inputsT)] - (` (def: ((~ g!method) - [(~+ (list#each product.right g!inputs))]) - (-> [(~+ (list#each nilable_type inputsT))] - (~ (|> (nilable_type outputT) - (try_type try?) - (io_type io?)))) - (:expected - (~ (<| (with_io io?) - (with_try try?) - (without_nil g!temp outputT) - (` ("ruby apply" - (:as ..Function (~ source)) - (~+ (list#each (with_nil g!temp) g!inputs))))))))))) - -(syntax: .public (import: [[?module import] ..import]) - (with_symbols [g!temp] - (case import - {#Class [class alias format members]} - (with_symbols [g!object] - (let [qualify (: (-> Text Code) - (function (_ member_name) - (|> format - (text.replaced "[1]" (maybe.else class alias)) - (text.replaced "[0]" member_name) - code.local_symbol))) - g!type (code.local_symbol (maybe.else class alias)) - module_import (: (List Code) - (case ?module - {.#Some module} - (list (` ("ruby import" (~ (code.text module))))) - - {.#None} - (list))) - class_import (` ("ruby constant" (~ (code.text class))))] - (in (list& (` (type: (~ g!type) - (..Object (Primitive (~ (code.text class)))))) - (list#each (function (_ member) - (case member - {#Field [static? field alias fieldT]} - (if static? - (` ((~! syntax:) ((~ (qualify (maybe.else field alias))) []) - (# (~! meta.monad) (~' in) - (list (` (.:as (~ (nilable_type fieldT)) - (.exec - (~+ module_import) - ("ruby constant" (~ (code.text (%.format class "::" field))))))))))) - (` (def: ((~ (qualify field)) - (~ g!object)) - (-> (~ g!type) - (~ (nilable_type fieldT))) - (:expected - (~ (without_nil g!temp fieldT (` ("ruby object get" (~ (code.text field)) - (:as (..Object .Any) (~ g!object)))))))))) - - {#Method method} - (case method - {#Static [method alias inputsT io? try? outputT]} - (..make_function (qualify (maybe.else method alias)) - g!temp - (` ("ruby object get" (~ (code.text method)) - (:as (..Object .Any) - (.exec - (~+ module_import) - ("ruby constant" (~ (code.text (%.format class "::" method)))))))) - inputsT - io? - try? - outputT) - - {#Virtual [method alias inputsT io? try? outputT]} - (let [g!inputs (input_variables inputsT)] - (` (def: ((~ (qualify (maybe.else method alias))) - [(~+ (list#each product.right g!inputs))] - (~ g!object)) - (-> [(~+ (list#each nilable_type inputsT))] - (~ g!type) - (~ (|> (nilable_type outputT) - (try_type try?) - (io_type io?)))) - (:expected - (~ (<| (with_io io?) - (with_try try?) - (without_nil g!temp outputT) - (` ("ruby object do" - (~ (code.text method)) - (~ g!object) - (~+ (list#each (with_nil g!temp) g!inputs))))))))))))) - members))))) - - {#Function [name alias inputsT io? try? outputT]} - (let [imported (` (.exec - (~+ (case ?module - {.#Some module} - (list (` ("ruby import" (~ (code.text module))))) - - {.#None} - (list))) - ("ruby constant" (~ (code.text name)))))] - (in (list (..make_function (code.local_symbol (maybe.else name alias)) - g!temp - imported - inputsT - io? - try? - outputT)))) - - {#Constant [_ name alias fieldT]} - (let [imported (` (.exec - (~+ (case ?module - {.#Some module} - (list (` ("ruby import" (~ (code.text module))))) - - {.#None} - (list))) - ("ruby constant" (~ (code.text name)))))] - (in (list (` ((~! syntax:) ((~ (code.local_symbol (maybe.else name alias))) []) - (# (~! meta.monad) (~' in) - (list (` (.:as (~ (nilable_type fieldT)) (~ imported)))))))))) - ))) |