diff options
author | Eduardo Julian | 2021-08-24 05:23:45 -0400 |
---|---|---|
committer | Eduardo Julian | 2021-08-24 05:23:45 -0400 |
commit | 36303d6cb2ce3ab9e36d045b9516c997bd461862 (patch) | |
tree | b9d2f1495143054d61d9af129f36833624db9dac /stdlib/source/library/lux/ffi.rb.lux | |
parent | ec1f31b5a1492d5e0ab260397291d4449483bbd9 (diff) |
Outsourced the syntax for labelled type definitions to macros.
Diffstat (limited to '')
-rw-r--r-- | stdlib/source/library/lux/ffi.rb.lux | 131 |
1 files changed, 67 insertions, 64 deletions
diff --git a/stdlib/source/library/lux/ffi.rb.lux b/stdlib/source/library/lux/ffi.rb.lux index c01b88565..2ba821582 100644 --- a/stdlib/source/library/lux/ffi.rb.lux +++ b/stdlib/source/library/lux/ffi.rb.lux @@ -99,8 +99,9 @@ (type: Virtual_Method Common_Method) (type: Method - (#Static Static_Method) - (#Virtual Virtual_Method)) + (Variant + (#Static Static_Method) + (#Virtual Virtual_Method))) (def: common_method (Parser Common_Method) @@ -121,8 +122,9 @@ ..common_method))) (type: Member - (#Field Field) - (#Method Method)) + (Variant + (#Field Field) + (#Method Method))) (def: member (Parser Member) @@ -134,8 +136,8 @@ (def: input_variables (-> (List Nilable) (List [Bit Code])) (|>> list.enumeration - (list\map (function (_ [idx [nilable? type]]) - [nilable? (|> idx %.nat code.local_identifier)])))) + (list\each (function (_ [idx [nilable? type]]) + [nilable? (|> idx %.nat code.local_identifier)])))) (def: (nilable_type [nilable? type]) (-> Nilable Code) @@ -167,9 +169,10 @@ (.panic! "Nil is an invalid value!")))))) (type: Import - (#Class Text (Maybe Alias) Text (List Member)) - (#Function Static_Method) - (#Constant Field)) + (Variant + (#Class Text (Maybe Alias) Text (List Member)) + (#Function Static_Method) + (#Constant Field))) (def: import (Parser [(Maybe Text) Import]) @@ -214,8 +217,8 @@ (-> Code Code Code (List Nilable) Bit Bit Nilable Code) (let [g!inputs (input_variables inputsT)] (` (def: ((~ g!method) - [(~+ (list\map product.right g!inputs))]) - (-> [(~+ (list\map nilable_type inputsT))] + [(~+ (list\each product.right g!inputs))]) + (-> [(~+ (list\each nilable_type inputsT))] (~ (|> (nilable_type outputT) (try_type try?) (io_type io?)))) @@ -225,7 +228,7 @@ (without_nil g!temp outputT) (` ("ruby apply" (:as ..Function (~ source)) - (~+ (list\map (with_nil g!temp) g!inputs))))))))))) + (~+ (list\each (with_nil g!temp) g!inputs))))))))))) (syntax: .public (import: [[?module import] ..import]) {#.doc (example "Easily import types, methods, functions and constants." @@ -268,58 +271,58 @@ class_import (` ("ruby constant" (~ (code.text class))))] (in (list& (` (type: (~ g!type) (..Object (primitive (~ (code.text class)))))) - (list\map (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\map product.right g!inputs))] - (~ g!object)) - (-> [(~+ (list\map 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\map (with_nil g!temp) g!inputs))))))))))))) - members))))) + (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 |