functionalscript 0.1.609 → 0.2.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/com/cpp/module.f.mjs +20 -25
- package/com/cpp/testlib.f.mjs +3 -4
- package/com/cs/module.f.mjs +18 -23
- package/com/cs/testlib.f.mjs +3 -5
- package/com/rust/module.f.mjs +25 -30
- package/com/rust/testlib.f.mjs +3 -5
- package/com/test/build.f.mjs +2 -2
- package/com/test/build.mjs +4 -4
- package/com/types/module.f.mjs +5 -12
- package/commonjs/build/module.f.mjs +23 -28
- package/commonjs/build/test.f.mjs +4 -4
- package/commonjs/module/function/module.f.mjs +0 -2
- package/commonjs/module/module.f.mjs +2 -9
- package/commonjs/module.f.mjs +0 -2
- package/commonjs/module.mjs +2 -7
- package/commonjs/package/dependencies/module.f.mjs +5 -10
- package/commonjs/package/dependencies/test.f.mjs +1 -1
- package/commonjs/package/module.f.mjs +6 -13
- package/commonjs/package/test.f.mjs +1 -1
- package/commonjs/path/module.f.mjs +12 -23
- package/commonjs/path/test.f.mjs +11 -11
- package/commonjs/test.mjs +1 -1
- package/dev/module.f.mjs +1 -4
- package/dev/module.mjs +1 -1
- package/dev/test/module.f.mjs +4 -6
- package/djs/module.f.mjs +12 -19
- package/djs/parser/module.f.mjs +18 -24
- package/djs/parser/test.f.mjs +9 -9
- package/djs/test.f.mjs +4 -4
- package/djs/tokenizer/module.f.mjs +18 -23
- package/djs/tokenizer/test.f.mjs +6 -6
- package/fsc/module.f.mjs +17 -24
- package/fsc/test.f.mjs +3 -3
- package/fsm/module.f.mjs +27 -38
- package/fsm/test.f.mjs +8 -8
- package/html/module.f.mjs +14 -23
- package/html/test.f.mjs +4 -4
- package/js/tokenizer/module.f.mjs +55 -62
- package/js/tokenizer/test.f.mjs +6 -6
- package/json/module.f.mjs +18 -31
- package/json/parser/module.f.mjs +9 -14
- package/json/parser/test.f.mjs +7 -7
- package/json/serializer/module.f.mjs +14 -29
- package/json/serializer/test.f.mjs +2 -2
- package/json/test.f.mjs +3 -3
- package/json/tokenizer/module.f.mjs +14 -19
- package/json/tokenizer/test.f.mjs +6 -6
- package/jsr.json +59 -59
- package/nodejs/version/main.mjs +1 -1
- package/nodejs/version/module.f.mjs +2 -7
- package/nodejs/version/test.f.mjs +3 -3
- package/out/com/cpp/module.f.d.mts +4 -0
- package/out/com/cpp/module.f.mjs +123 -0
- package/out/com/cpp/test.f.mjs +40 -0
- package/out/com/cpp/testlib.f.mjs +7 -0
- package/out/com/cs/module.f.d.mts +4 -0
- package/out/com/cs/module.f.mjs +95 -0
- package/out/com/cs/test.f.mjs +43 -0
- package/out/com/cs/testlib.f.mjs +7 -0
- package/{com → out/com}/rust/module.f.d.mts +3 -7
- package/out/com/rust/module.f.mjs +213 -0
- package/out/com/rust/test.f.mjs +123 -0
- package/out/com/rust/testlib.f.mjs +7 -0
- package/{com → out/com}/test/build.f.d.mts +2 -2
- package/out/com/test/build.f.mjs +98 -0
- package/out/com/test/build.mjs +40 -0
- package/{com → out/com}/types/module.f.d.mts +5 -10
- package/out/com/types/module.f.mjs +51 -0
- package/out/com/types/testlib.f.mjs +30 -0
- package/out/commonjs/build/module.f.d.mts +20 -0
- package/out/commonjs/build/module.f.mjs +107 -0
- package/out/commonjs/build/test.f.mjs +102 -0
- package/{commonjs → out/commonjs}/module/function/module.f.d.mts +0 -2
- package/out/commonjs/module/function/module.f.mjs +15 -0
- package/{commonjs → out/commonjs}/module/module.f.d.mts +16 -21
- package/out/commonjs/module/module.f.mjs +48 -0
- package/out/commonjs/module.d.mts +3 -0
- package/{commonjs → out/commonjs}/module.f.d.mts +0 -2
- package/out/commonjs/module.f.mjs +10 -0
- package/out/commonjs/module.mjs +26 -0
- package/out/commonjs/package/dependencies/module.f.d.mts +6 -0
- package/out/commonjs/package/dependencies/module.f.mjs +21 -0
- package/out/commonjs/package/dependencies/test.f.mjs +15 -0
- package/out/commonjs/package/module.f.d.mts +21 -0
- package/out/commonjs/package/module.f.mjs +40 -0
- package/out/commonjs/package/test.f.mjs +27 -0
- package/{commonjs → out/commonjs}/path/module.f.d.mts +25 -32
- package/out/commonjs/path/module.f.mjs +171 -0
- package/out/commonjs/path/test.f.mjs +231 -0
- package/out/commonjs/test.mjs +87 -0
- package/out/dev/index.mjs +2 -0
- package/out/dev/module.f.d.mts +1 -0
- package/out/dev/module.f.mjs +2 -0
- package/out/dev/module.mjs +167 -0
- package/{dev → out/dev}/test/module.f.d.mts +2 -3
- package/out/dev/test/module.f.mjs +134 -0
- package/out/dev/test.f.mjs +58 -0
- package/out/dev/test.mjs +52 -0
- package/{djs → out/djs}/module.f.d.mts +13 -18
- package/out/djs/module.f.mjs +75 -0
- package/{djs → out/djs}/parser/module.f.d.mts +11 -15
- package/out/djs/parser/module.f.mjs +432 -0
- package/out/djs/parser/test.f.mjs +535 -0
- package/out/djs/test.f.mjs +84 -0
- package/out/djs/tokenizer/module.f.d.mts +13 -0
- package/out/djs/tokenizer/module.f.mjs +87 -0
- package/out/djs/tokenizer/test.f.mjs +480 -0
- package/out/fsc/module.f.d.mts +7 -0
- package/out/fsc/module.f.mjs +105 -0
- package/out/fsc/test.f.mjs +19 -0
- package/out/fsm/module.f.d.mts +14 -0
- package/out/fsm/module.f.mjs +80 -0
- package/out/fsm/test.f.mjs +138 -0
- package/out/html/module.f.d.mts +15 -0
- package/out/html/module.f.mjs +94 -0
- package/out/html/test.f.mjs +45 -0
- package/out/issues/test.f.mjs +66 -0
- package/{js → out/js}/tokenizer/module.f.d.mts +10 -15
- package/out/js/tokenizer/module.f.mjs +686 -0
- package/out/js/tokenizer/test.f.mjs +844 -0
- package/out/json/module.f.d.mts +33 -0
- package/out/json/module.f.mjs +89 -0
- package/{json → out/json}/parser/module.f.d.mts +9 -13
- package/out/json/parser/module.f.mjs +224 -0
- package/out/json/parser/test.f.mjs +321 -0
- package/out/json/serializer/module.f.d.mts +36 -0
- package/out/json/serializer/module.f.mjs +67 -0
- package/out/json/serializer/test.f.mjs +87 -0
- package/out/json/test.f.mjs +61 -0
- package/out/json/tokenizer/module.f.d.mts +13 -0
- package/out/json/tokenizer/module.f.mjs +78 -0
- package/out/json/tokenizer/test.f.mjs +420 -0
- package/out/nanvm-lib/tests/test.f.mjs +87 -0
- package/out/nodejs/version/main.mjs +3 -0
- package/{nodejs → out/nodejs}/version/module.f.d.mts +4 -9
- package/out/nodejs/version/module.f.mjs +34 -0
- package/out/nodejs/version/test.f.mjs +97 -0
- package/{prime_field → out/prime_field}/module.f.d.mts +20 -23
- package/out/prime_field/module.f.mjs +87 -0
- package/out/prime_field/test.f.mjs +145 -0
- package/{secp → out/secp}/module.f.d.mts +27 -28
- package/out/secp/module.f.mjs +113 -0
- package/out/secp/test.f.mjs +63 -0
- package/out/sha2/module.f.d.mts +15 -0
- package/out/sha2/module.f.mjs +172 -0
- package/out/sha2/test.f.mjs +86 -0
- package/out/text/ascii/module.f.d.mts +70 -0
- package/out/text/ascii/module.f.mjs +154 -0
- package/out/text/ascii/test.f.mjs +14 -0
- package/out/text/module.f.d.mts +13 -0
- package/out/text/module.f.mjs +19 -0
- package/out/text/sgr/module.f.d.mts +12 -0
- package/out/text/sgr/module.f.mjs +17 -0
- package/out/text/test.f.mjs +19 -0
- package/out/text/utf16/module.f.d.mts +12 -0
- package/out/text/utf16/module.f.mjs +86 -0
- package/out/text/utf16/test.f.mjs +145 -0
- package/out/text/utf8/module.f.d.mts +10 -0
- package/out/text/utf8/module.f.mjs +126 -0
- package/out/text/utf8/test.f.mjs +175 -0
- package/{types → out/types}/array/module.f.d.mts +14 -24
- package/out/types/array/module.f.mjs +95 -0
- package/out/types/array/test.f.mjs +116 -0
- package/out/types/bigfloat/module.f.d.mts +6 -0
- package/out/types/bigfloat/module.f.mjs +77 -0
- package/out/types/bigfloat/test.f.mjs +349 -0
- package/out/types/bigint/module.f.d.mts +29 -0
- package/{types/bigint/module.f.d.mts → out/types/bigint/module.f.mjs} +64 -27
- package/out/types/bigint/test.f.mjs +192 -0
- package/{types → out/types}/btree/find/module.f.d.mts +20 -26
- package/out/types/btree/find/module.f.mjs +137 -0
- package/out/types/btree/find/test.f.mjs +156 -0
- package/out/types/btree/module.f.d.mts +5 -0
- package/out/types/btree/module.f.mjs +34 -0
- package/{types → out/types}/btree/remove/module.f.d.mts +7 -12
- package/out/types/btree/remove/module.f.mjs +209 -0
- package/out/types/btree/remove/test.f.mjs +638 -0
- package/{types → out/types}/btree/set/module.f.d.mts +3 -7
- package/out/types/btree/set/module.f.mjs +114 -0
- package/out/types/btree/set/test.f.mjs +390 -0
- package/out/types/btree/test.f.mjs +83 -0
- package/{types → out/types}/btree/types/module.f.d.mts +0 -2
- package/out/types/btree/types/module.f.mjs +50 -0
- package/out/types/byte_set/module.f.d.mts +25 -0
- package/out/types/byte_set/module.f.mjs +42 -0
- package/out/types/byte_set/test.f.mjs +123 -0
- package/{types → out/types}/function/compare/module.f.d.mts +9 -15
- package/out/types/function/compare/module.f.mjs +22 -0
- package/out/types/function/compare/test.f.mjs +8 -0
- package/{types → out/types}/function/module.f.d.mts +20 -27
- package/out/types/function/module.f.mjs +44 -0
- package/{types → out/types}/function/operator/module.f.d.mts +28 -43
- package/out/types/function/operator/module.f.mjs +60 -0
- package/out/types/function/test.f.mjs +15 -0
- package/out/types/list/module.f.d.mts +82 -0
- package/out/types/list/module.f.mjs +269 -0
- package/out/types/list/test.f.mjs +401 -0
- package/out/types/map/module.f.d.mts +21 -0
- package/out/types/map/module.f.mjs +54 -0
- package/out/types/map/test.f.mjs +115 -0
- package/out/types/nibble_set/module.f.d.mts +16 -0
- package/out/types/nibble_set/module.f.mjs +19 -0
- package/out/types/nibble_set/test.f.mjs +90 -0
- package/out/types/nullable/module.f.d.mts +9 -0
- package/out/types/nullable/module.f.mjs +9 -0
- package/out/types/nullable/test.f.mjs +12 -0
- package/out/types/number/module.f.d.mts +7 -0
- package/out/types/number/module.f.mjs +12 -0
- package/out/types/number/test.f.mjs +126 -0
- package/out/types/object/module.f.d.mts +22 -0
- package/out/types/object/module.f.mjs +27 -0
- package/out/types/object/test.f.mjs +17 -0
- package/out/types/range/module.f.d.mts +6 -0
- package/out/types/range/module.f.mjs +6 -0
- package/out/types/range/test.f.mjs +18 -0
- package/{types → out/types}/range_map/module.f.d.mts +9 -15
- package/out/types/range_map/module.f.mjs +84 -0
- package/out/types/range_map/test.f.mjs +201 -0
- package/out/types/result/module.d.mts +7 -0
- package/{types → out/types}/result/module.f.d.mts +6 -12
- package/out/types/result/module.f.mjs +25 -0
- package/out/types/result/module.mjs +16 -0
- package/{types → out/types}/sorted_list/module.f.d.mts +22 -28
- package/out/types/sorted_list/module.f.mjs +102 -0
- package/out/types/sorted_list/test.f.mjs +66 -0
- package/{types → out/types}/sorted_set/module.f.d.mts +6 -12
- package/out/types/sorted_set/module.f.mjs +29 -0
- package/out/types/sorted_set/test.f.mjs +80 -0
- package/out/types/string/module.f.d.mts +9 -0
- package/out/types/string/module.f.mjs +17 -0
- package/out/types/string/test.f.mjs +58 -0
- package/out/types/string_set/module.f.d.mts +13 -0
- package/out/types/string_set/module.f.mjs +29 -0
- package/out/types/string_set/test.f.mjs +65 -0
- package/package.json +5 -4
- package/prime_field/module.f.mjs +9 -12
- package/prime_field/test.f.mjs +1 -1
- package/secp/module.f.mjs +38 -39
- package/secp/test.f.mjs +4 -4
- package/sha2/module.f.mjs +7 -20
- package/sha2/test.f.mjs +4 -4
- package/text/ascii/module.f.mjs +5 -10
- package/text/ascii/test.f.mjs +3 -3
- package/text/module.f.mjs +7 -14
- package/text/sgr/module.f.mjs +2 -4
- package/text/test.f.mjs +3 -3
- package/text/utf16/module.f.mjs +17 -28
- package/text/utf16/test.f.mjs +5 -5
- package/text/utf8/module.f.mjs +9 -16
- package/text/utf8/test.f.mjs +4 -4
- package/tsconfig.json +2 -2
- package/types/array/module.f.mjs +8 -25
- package/types/array/test.f.mjs +3 -3
- package/types/bigfloat/module.f.mjs +3 -10
- package/types/bigfloat/test.f.mjs +1 -1
- package/types/bigint/module.f.mjs +11 -30
- package/types/bigint/test.f.mjs +1 -1
- package/types/btree/find/module.f.mjs +8 -17
- package/types/btree/find/test.f.mjs +7 -7
- package/types/btree/module.f.mjs +6 -11
- package/types/btree/remove/module.f.mjs +10 -17
- package/types/btree/remove/test.f.mjs +5 -5
- package/types/btree/set/module.f.mjs +4 -9
- package/types/btree/set/test.f.mjs +4 -4
- package/types/btree/test.f.mjs +9 -9
- package/types/btree/types/module.f.mjs +0 -2
- package/types/byte_set/module.f.mjs +14 -39
- package/types/byte_set/test.f.mjs +5 -5
- package/types/function/compare/module.f.mjs +3 -12
- package/types/function/compare/test.f.mjs +1 -1
- package/types/function/module.f.mjs +4 -15
- package/types/function/operator/module.f.mjs +14 -41
- package/types/function/test.f.mjs +1 -1
- package/types/list/module.f.mjs +45 -114
- package/types/list/test.f.mjs +10 -10
- package/types/map/module.f.mjs +15 -30
- package/types/map/test.f.mjs +2 -2
- package/types/nibble_set/module.f.mjs +7 -24
- package/types/nibble_set/test.f.mjs +2 -2
- package/types/nullable/module.f.mjs +2 -9
- package/types/nullable/test.f.mjs +1 -1
- package/types/number/module.f.mjs +8 -19
- package/types/number/test.f.mjs +1 -1
- package/types/object/module.f.mjs +9 -20
- package/types/object/test.f.mjs +1 -1
- package/types/range/module.f.mjs +2 -9
- package/types/range/test.f.mjs +1 -1
- package/types/range_map/module.f.mjs +9 -18
- package/types/range_map/test.f.mjs +32 -32
- package/types/result/module.f.mjs +3 -12
- package/types/result/module.mjs +2 -2
- package/types/sorted_list/module.f.mjs +10 -19
- package/types/sorted_list/test.f.mjs +7 -7
- package/types/sorted_set/module.f.mjs +7 -16
- package/types/sorted_set/test.f.mjs +7 -7
- package/types/string/module.f.mjs +10 -21
- package/types/string/test.f.mjs +2 -2
- package/types/string_set/module.f.mjs +12 -27
- package/types/string_set/test.f.mjs +1 -1
- package/com/cpp/module.f.d.mts +0 -8
- package/com/cs/module.f.d.mts +0 -8
- package/commonjs/build/module.f.d.mts +0 -24
- package/commonjs/module.d.mts +0 -7
- package/commonjs/package/dependencies/module.f.d.mts +0 -10
- package/commonjs/package/module.f.d.mts +0 -27
- package/dev/module.f.d.mts +0 -4
- package/djs/tokenizer/module.f.d.mts +0 -17
- package/fsc/module.f.d.mts +0 -12
- package/fsm/module.f.d.mts +0 -21
- package/html/module.f.d.mts +0 -20
- package/json/module.f.d.mts +0 -41
- package/json/serializer/module.f.d.mts +0 -45
- package/json/tokenizer/module.f.d.mts +0 -17
- package/sha2/module.f.d.mts +0 -23
- package/text/ascii/module.f.d.mts +0 -73
- package/text/module.f.d.mts +0 -18
- package/text/sgr/module.f.d.mts +0 -14
- package/text/utf16/module.f.d.mts +0 -19
- package/text/utf8/module.f.d.mts +0 -15
- package/types/bigfloat/module.f.d.mts +0 -11
- package/types/btree/module.f.d.mts +0 -9
- package/types/byte_set/module.f.d.mts +0 -38
- package/types/list/module.f.d.mts +0 -117
- package/types/map/module.f.d.mts +0 -30
- package/types/nibble_set/module.f.d.mts +0 -26
- package/types/nullable/module.f.d.mts +0 -14
- package/types/number/module.f.d.mts +0 -13
- package/types/object/module.f.d.mts +0 -29
- package/types/range/module.f.d.mts +0 -11
- package/types/result/module.d.mts +0 -7
- package/types/string/module.f.d.mts +0 -15
- package/types/string_set/module.f.d.mts +0 -21
- /package/{com → out/com}/cpp/test.f.d.mts +0 -0
- /package/{com → out/com}/cpp/testlib.f.d.mts +0 -0
- /package/{com → out/com}/cs/test.f.d.mts +0 -0
- /package/{com → out/com}/cs/testlib.f.d.mts +0 -0
- /package/{com → out/com}/rust/test.f.d.mts +0 -0
- /package/{com → out/com}/rust/testlib.f.d.mts +0 -0
- /package/{com → out/com}/test/build.d.mts +0 -0
- /package/{com → out/com}/types/testlib.f.d.mts +0 -0
- /package/{commonjs → out/commonjs}/build/test.f.d.mts +0 -0
- /package/{commonjs → out/commonjs}/package/dependencies/test.f.d.mts +0 -0
- /package/{commonjs → out/commonjs}/package/test.f.d.mts +0 -0
- /package/{commonjs → out/commonjs}/path/test.f.d.mts +0 -0
- /package/{commonjs → out/commonjs}/test.d.mts +0 -0
- /package/{dev → out/dev}/index.d.mts +0 -0
- /package/{dev → out/dev}/module.d.mts +0 -0
- /package/{dev → out/dev}/test.d.mts +0 -0
- /package/{dev → out/dev}/test.f.d.mts +0 -0
- /package/{djs → out/djs}/parser/test.f.d.mts +0 -0
- /package/{djs → out/djs}/test.f.d.mts +0 -0
- /package/{djs → out/djs}/tokenizer/test.f.d.mts +0 -0
- /package/{fsc → out/fsc}/test.f.d.mts +0 -0
- /package/{fsm → out/fsm}/test.f.d.mts +0 -0
- /package/{html → out/html}/test.f.d.mts +0 -0
- /package/{issues → out/issues}/test.f.d.mts +0 -0
- /package/{js → out/js}/tokenizer/test.f.d.mts +0 -0
- /package/{json → out/json}/parser/test.f.d.mts +0 -0
- /package/{json → out/json}/serializer/test.f.d.mts +0 -0
- /package/{json → out/json}/test.f.d.mts +0 -0
- /package/{json → out/json}/tokenizer/test.f.d.mts +0 -0
- /package/{nanvm-lib → out/nanvm-lib}/tests/test.f.d.mts +0 -0
- /package/{nodejs → out/nodejs}/version/main.d.mts +0 -0
- /package/{nodejs → out/nodejs}/version/test.f.d.mts +0 -0
- /package/{prime_field → out/prime_field}/test.f.d.mts +0 -0
- /package/{secp → out/secp}/test.f.d.mts +0 -0
- /package/{sha2 → out/sha2}/test.f.d.mts +0 -0
- /package/{text → out/text}/ascii/test.f.d.mts +0 -0
- /package/{text → out/text}/test.f.d.mts +0 -0
- /package/{text → out/text}/utf16/test.f.d.mts +0 -0
- /package/{text → out/text}/utf8/test.f.d.mts +0 -0
- /package/{types → out/types}/array/test.f.d.mts +0 -0
- /package/{types → out/types}/bigfloat/test.f.d.mts +0 -0
- /package/{types → out/types}/bigint/test.f.d.mts +0 -0
- /package/{types → out/types}/btree/find/test.f.d.mts +0 -0
- /package/{types → out/types}/btree/remove/test.f.d.mts +0 -0
- /package/{types → out/types}/btree/set/test.f.d.mts +0 -0
- /package/{types → out/types}/btree/test.f.d.mts +0 -0
- /package/{types → out/types}/byte_set/test.f.d.mts +0 -0
- /package/{types → out/types}/function/compare/test.f.d.mts +0 -0
- /package/{types → out/types}/function/test.f.d.mts +0 -0
- /package/{types → out/types}/list/test.f.d.mts +0 -0
- /package/{types → out/types}/map/test.f.d.mts +0 -0
- /package/{types → out/types}/nibble_set/test.f.d.mts +0 -0
- /package/{types → out/types}/nullable/test.f.d.mts +0 -0
- /package/{types → out/types}/number/test.f.d.mts +0 -0
- /package/{types → out/types}/object/test.f.d.mts +0 -0
- /package/{types → out/types}/range/test.f.d.mts +0 -0
- /package/{types → out/types}/range_map/test.f.d.mts +0 -0
- /package/{types → out/types}/sorted_list/test.f.d.mts +0 -0
- /package/{types → out/types}/sorted_set/test.f.d.mts +0 -0
- /package/{types → out/types}/string/test.f.d.mts +0 -0
- /package/{types → out/types}/string_set/test.f.d.mts +0 -0
|
@@ -0,0 +1,95 @@
|
|
|
1
|
+
// @ts-self-types="./module.f.d.mts"
|
|
2
|
+
import * as types from '../types/module.f.mjs';
|
|
3
|
+
const { result, paramList } = types;
|
|
4
|
+
import * as text from '../../text/module.f.mjs';
|
|
5
|
+
const { curly } = text;
|
|
6
|
+
import * as list from '../../types/list/module.f.mjs';
|
|
7
|
+
const { flat, map, some, flatMap } = list;
|
|
8
|
+
import * as string from '../../types/string/module.f.mjs';
|
|
9
|
+
const { join } = string;
|
|
10
|
+
import * as O from '../../types/object/module.f.mjs';
|
|
11
|
+
const { entries } = Object;
|
|
12
|
+
/** @type {(v: string) => string} */
|
|
13
|
+
const using = v => `using ${v};`;
|
|
14
|
+
/**
|
|
15
|
+
* @type {(attributes: list.List<string>) =>
|
|
16
|
+
* (type: string) =>
|
|
17
|
+
* (name: string) =>
|
|
18
|
+
* (body: text.Block) =>
|
|
19
|
+
* list.List<text.Item>}
|
|
20
|
+
*/
|
|
21
|
+
const typeDef = attributes => type => name => body => flat([
|
|
22
|
+
map(v => `[${v}]`)(attributes),
|
|
23
|
+
curly(`public ${type}`)(name)(body)
|
|
24
|
+
]);
|
|
25
|
+
const baseTypeMap = {
|
|
26
|
+
bool: 'byte',
|
|
27
|
+
f32: 'float',
|
|
28
|
+
f64: 'double',
|
|
29
|
+
i16: 'short',
|
|
30
|
+
i32: 'int',
|
|
31
|
+
i64: 'long',
|
|
32
|
+
i8: 'sbyte',
|
|
33
|
+
isize: 'IntPtr',
|
|
34
|
+
u16: 'ushort',
|
|
35
|
+
u32: 'uint',
|
|
36
|
+
u64: 'ulong',
|
|
37
|
+
u8: 'byte',
|
|
38
|
+
usize: 'UIntPtr',
|
|
39
|
+
};
|
|
40
|
+
/** @type {(t: types.BaseType) => string} */
|
|
41
|
+
const baseType = t => baseTypeMap[t];
|
|
42
|
+
/** @type {(isUnsafe: boolean) => string} */
|
|
43
|
+
const unsafe = isUnsafe => isUnsafe ? 'unsafe ' : '';
|
|
44
|
+
/** @type {(t: types.Type) => readonly[boolean, string]} */
|
|
45
|
+
const fullType = t => typeof (t) === 'string' ? [false, baseType(t)] :
|
|
46
|
+
t.length === 1 ? [false, t[0]] :
|
|
47
|
+
[true, `${type(t[1])}*`];
|
|
48
|
+
/** @type {(m: types.Type) => string} */
|
|
49
|
+
const type = t => fullType(t)[1];
|
|
50
|
+
/** @type {(f: types.Field) => string} */
|
|
51
|
+
const param = ([name, t]) => `${type(t)} ${name}`;
|
|
52
|
+
const mapParam = map(param);
|
|
53
|
+
/** @type {(f: types.Field) => string} */
|
|
54
|
+
const field = ([name, comType]) => {
|
|
55
|
+
const [isUnsafe, t] = fullType(comType);
|
|
56
|
+
return `public ${unsafe(isUnsafe)}${t} ${name};`;
|
|
57
|
+
};
|
|
58
|
+
/** @type {(field: types.Field) => boolean} */
|
|
59
|
+
const isUnsafeField = field => fullType(field[1])[0];
|
|
60
|
+
const mapIsUnsafeField = map(isUnsafeField);
|
|
61
|
+
const resultVoid = result('void');
|
|
62
|
+
const joinComma = join(', ');
|
|
63
|
+
/** @type {(e: O.Entry<types.FieldArray>) => readonly string[]} */
|
|
64
|
+
const method = ([name, m]) => {
|
|
65
|
+
const paramAndResultList = entries(m);
|
|
66
|
+
const pl = paramList(m);
|
|
67
|
+
const isUnsafe = some(mapIsUnsafeField(paramAndResultList));
|
|
68
|
+
return [
|
|
69
|
+
'[PreserveSig]',
|
|
70
|
+
`${unsafe(isUnsafe)}${resultVoid(type)(m)} ${name}(${joinComma(mapParam(pl))});`
|
|
71
|
+
];
|
|
72
|
+
};
|
|
73
|
+
const struct = typeDef(['StructLayout(LayoutKind.Sequential)'])('struct');
|
|
74
|
+
const mapField = map(field);
|
|
75
|
+
const flatMapMethod = flatMap(method);
|
|
76
|
+
/** @type {(e: O.Entry<types.Definition>) => list.List<text.Item>} */
|
|
77
|
+
const def = ([n, d]) => {
|
|
78
|
+
return !('interface' in d) ?
|
|
79
|
+
struct(n)(mapField(entries(d.struct))) :
|
|
80
|
+
typeDef([`Guid("${d.guid}")`, 'InterfaceType(ComInterfaceType.InterfaceIsIUnknown)'])('interface')(n)(flatMapMethod(entries(d.interface)));
|
|
81
|
+
};
|
|
82
|
+
const flatMapDef = flatMap(def);
|
|
83
|
+
const namespace = curly('namespace');
|
|
84
|
+
/** @type {text.Block} */
|
|
85
|
+
const header = [
|
|
86
|
+
using('System'),
|
|
87
|
+
using('System.Runtime.InteropServices'),
|
|
88
|
+
''
|
|
89
|
+
];
|
|
90
|
+
/** @type {(name: string) => (library: types.Library) => text.Block} */
|
|
91
|
+
export const cs = name => library => {
|
|
92
|
+
const v = flatMapDef(entries(library));
|
|
93
|
+
const ns = namespace(name)(v);
|
|
94
|
+
return flat([header, ns]);
|
|
95
|
+
};
|
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
import cs from './testlib.f.mjs';
|
|
2
|
+
const f = () => {
|
|
3
|
+
const e = 'using System;\n' +
|
|
4
|
+
'using System.Runtime.InteropServices;\n' +
|
|
5
|
+
'\n' +
|
|
6
|
+
'namespace My\n' +
|
|
7
|
+
'{\n' +
|
|
8
|
+
' [StructLayout(LayoutKind.Sequential)]\n' +
|
|
9
|
+
' public struct Slice\n' +
|
|
10
|
+
' {\n' +
|
|
11
|
+
' public unsafe byte* Start;\n' +
|
|
12
|
+
' public UIntPtr Size;\n' +
|
|
13
|
+
' }\n' +
|
|
14
|
+
' [StructLayout(LayoutKind.Sequential)]\n' +
|
|
15
|
+
' public struct ManagedStruct\n' +
|
|
16
|
+
' {\n' +
|
|
17
|
+
' public IMy M;\n' +
|
|
18
|
+
' }\n' +
|
|
19
|
+
' [Guid("C66FB270-2D80-49AD-BB6E-88C1F90B805D")]\n' +
|
|
20
|
+
' [InterfaceType(ComInterfaceType.InterfaceIsIUnknown)]\n' +
|
|
21
|
+
' public interface IMy\n' +
|
|
22
|
+
' {\n' +
|
|
23
|
+
' [PreserveSig]\n' +
|
|
24
|
+
' Slice GetSlice();\n' +
|
|
25
|
+
' [PreserveSig]\n' +
|
|
26
|
+
' void SetSlice(Slice slice);\n' +
|
|
27
|
+
' [PreserveSig]\n' +
|
|
28
|
+
' unsafe byte* GetUnsafe();\n' +
|
|
29
|
+
' [PreserveSig]\n' +
|
|
30
|
+
' unsafe void SetUnsafe(Slice* p, uint size);\n' +
|
|
31
|
+
' [PreserveSig]\n' +
|
|
32
|
+
' byte Some(IMy p);\n' +
|
|
33
|
+
' [PreserveSig]\n' +
|
|
34
|
+
' IMy GetIMy(ushort a, short b);\n' +
|
|
35
|
+
' [PreserveSig]\n' +
|
|
36
|
+
' void SetManagedStruct(ManagedStruct a);\n' +
|
|
37
|
+
' }\n' +
|
|
38
|
+
'}';
|
|
39
|
+
if (cs !== e) {
|
|
40
|
+
throw cs;
|
|
41
|
+
}
|
|
42
|
+
};
|
|
43
|
+
export default f;
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
import * as text from '../../text/module.f.mjs';
|
|
2
|
+
const { flat } = text;
|
|
3
|
+
import * as string from '../../types/string/module.f.mjs';
|
|
4
|
+
const { join } = string;
|
|
5
|
+
import { cs } from './module.f.mjs';
|
|
6
|
+
import library from '../types/testlib.f.mjs';
|
|
7
|
+
export default join('\n')(flat(' ')(cs('My')(library)));
|
|
@@ -1,7 +1,5 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
}
|
|
4
|
-
export default _default;
|
|
1
|
+
/** @type {(library: types.Library) => Text.Block} */
|
|
2
|
+
export const rust: (library: types.Library) => Text.Block;
|
|
5
3
|
export type OptionalProperty<T> = T | {};
|
|
6
4
|
export type Where = {
|
|
7
5
|
readonly where: readonly string[];
|
|
@@ -22,7 +20,5 @@ export type Trait = {
|
|
|
22
20
|
readonly where?: readonly string[];
|
|
23
21
|
readonly content: Text.Block;
|
|
24
22
|
};
|
|
25
|
-
|
|
26
|
-
declare const rust: (library: Types.Library) => Text.Block;
|
|
23
|
+
import * as types from '../types/module.f.mjs';
|
|
27
24
|
import * as Text from '../../text/module.f.mjs';
|
|
28
|
-
import * as Types from '../types/module.f.mjs';
|
|
@@ -0,0 +1,213 @@
|
|
|
1
|
+
// @ts-self-types="./module.f.d.mts"
|
|
2
|
+
import * as types from '../types/module.f.mjs';
|
|
3
|
+
const { paramList } = types;
|
|
4
|
+
import * as Text from '../../text/module.f.mjs';
|
|
5
|
+
import * as O from '../../types/object/module.f.mjs';
|
|
6
|
+
import * as list from '../../types/list/module.f.mjs';
|
|
7
|
+
const { flat, map, flatMap } = list;
|
|
8
|
+
const { entries } = Object;
|
|
9
|
+
import * as func from '../../types/function/module.f.mjs';
|
|
10
|
+
const { fn } = func;
|
|
11
|
+
import * as string from '../../types/string/module.f.mjs';
|
|
12
|
+
const { join } = string;
|
|
13
|
+
/** @type {(field: string) => string} */
|
|
14
|
+
const rustField = field => `pub ${field},`;
|
|
15
|
+
const mapRustField = map(rustField);
|
|
16
|
+
/** @type {(b: list.Thunk<string>) => (name: string) => Text.Block} */
|
|
17
|
+
const rustStruct = b => name => [`#[repr(C)]`, `pub struct ${name} {`, mapRustField(b), `}`];
|
|
18
|
+
const commaJoin = join(', ');
|
|
19
|
+
/** @type {(name: string) => string} */
|
|
20
|
+
const ref = name => `${name}::Ref`;
|
|
21
|
+
/** @type {(name: string) => string} */
|
|
22
|
+
const obj = name => `&${name}::Object`;
|
|
23
|
+
const self = ['&self'];
|
|
24
|
+
/** @type {(p: types.Field) => string} */
|
|
25
|
+
const paramName = ([n]) => n;
|
|
26
|
+
/** @type {(p: types.FieldArray) => list.Thunk<string>} */
|
|
27
|
+
const callList = p => map(paramName)(paramList(p));
|
|
28
|
+
/** @type {(p: types.FieldArray) => string} */
|
|
29
|
+
const call = p => commaJoin(callList(p));
|
|
30
|
+
/** @type {(p: types.FieldArray) => string} */
|
|
31
|
+
const virtualCall = p => commaJoin(flat([['self'], callList(p)]));
|
|
32
|
+
const super_ = 'super::';
|
|
33
|
+
/** @type {(m: types.Method) => string} */
|
|
34
|
+
const assign = ([n]) => `${n}: Self::${n},`;
|
|
35
|
+
const mapAssign = map(assign);
|
|
36
|
+
const this_ = ['this: &Object'];
|
|
37
|
+
/** @type {(n: string) => string} */
|
|
38
|
+
const rustType = n => `pub type ${n} = nanocom::${n}<Interface>;`;
|
|
39
|
+
/**
|
|
40
|
+
* @template T
|
|
41
|
+
* @typedef {T|{}} OptionalProperty
|
|
42
|
+
*/
|
|
43
|
+
/** @typedef {{readonly where: readonly string[]}} Where */
|
|
44
|
+
/**
|
|
45
|
+
* @typedef {OptionalProperty<Where> & {readonly content: Text.Block}} WhereContent
|
|
46
|
+
*/
|
|
47
|
+
/** @type {(h: string) => (wh: WhereContent) => Text.Block} */
|
|
48
|
+
const whereContent = h => wh => {
|
|
49
|
+
const w = 'where' in wh ? [
|
|
50
|
+
h,
|
|
51
|
+
`where`,
|
|
52
|
+
mapComma(wh.where),
|
|
53
|
+
'{'
|
|
54
|
+
] : [`${h} {`];
|
|
55
|
+
const x = [
|
|
56
|
+
wh.content,
|
|
57
|
+
'}',
|
|
58
|
+
];
|
|
59
|
+
return flat([w, x]);
|
|
60
|
+
};
|
|
61
|
+
/**
|
|
62
|
+
* @typedef {{
|
|
63
|
+
* readonly param?: string
|
|
64
|
+
* readonly trait: string
|
|
65
|
+
* readonly type: string
|
|
66
|
+
* readonly where?: readonly string[]
|
|
67
|
+
* readonly content: Text.Block
|
|
68
|
+
* }} Impl
|
|
69
|
+
*/
|
|
70
|
+
/** @type {(impl: Impl) => Text.Block} */
|
|
71
|
+
const rustImpl = i => {
|
|
72
|
+
const p = 'param' in i ? `<${i.param}>` : '';
|
|
73
|
+
const header = `impl${p} ${i.trait} for ${i.type}`;
|
|
74
|
+
return whereContent(header)(i);
|
|
75
|
+
};
|
|
76
|
+
/**
|
|
77
|
+
* @typedef {{
|
|
78
|
+
* readonly pub?: true
|
|
79
|
+
* readonly type: string
|
|
80
|
+
* readonly where?: readonly string[]
|
|
81
|
+
* readonly content: Text.Block
|
|
82
|
+
* }} Trait
|
|
83
|
+
*/
|
|
84
|
+
/** @type {(s: string) => string} */
|
|
85
|
+
const comma = s => `${s},`;
|
|
86
|
+
const mapComma = map(comma);
|
|
87
|
+
/** @type {(t: Trait) => Text.Block} */
|
|
88
|
+
const trait = t => {
|
|
89
|
+
const p = t.pub === true ? 'pub ' : '';
|
|
90
|
+
const h = `${p}trait ${t.type}`;
|
|
91
|
+
return whereContent(h)(t);
|
|
92
|
+
};
|
|
93
|
+
/** @type {(t: Trait) => Text.Block} */
|
|
94
|
+
const traitImpl = t => {
|
|
95
|
+
const i = rustImpl({
|
|
96
|
+
param: 'T',
|
|
97
|
+
trait: t.type,
|
|
98
|
+
type: 'T',
|
|
99
|
+
where,
|
|
100
|
+
content: [],
|
|
101
|
+
});
|
|
102
|
+
return flat([trait({ ...t, where }), i]);
|
|
103
|
+
};
|
|
104
|
+
const where = ['Self: nanocom::Class<Interface = Interface>', 'nanocom::CObject<Self>: Ex'];
|
|
105
|
+
/** @type {(library: types.Library) => Text.Block} */
|
|
106
|
+
export const rust = library => {
|
|
107
|
+
/** @type {(p: string) => (o: (_: string) => string) => (t: types.Type) => string} */
|
|
108
|
+
const type = p => {
|
|
109
|
+
/** @type {(o: (_: string) => string) => (t: types.Type) => string} */
|
|
110
|
+
const f = o => t => {
|
|
111
|
+
if (typeof t === 'string') {
|
|
112
|
+
return t;
|
|
113
|
+
}
|
|
114
|
+
if (t.length === 2) {
|
|
115
|
+
return `*const ${f(ref)(t[1])}`;
|
|
116
|
+
}
|
|
117
|
+
const [id] = t;
|
|
118
|
+
const fullId = `${p}${id}`;
|
|
119
|
+
return 'interface' in library[id] ? o(fullId) : fullId;
|
|
120
|
+
};
|
|
121
|
+
return f;
|
|
122
|
+
};
|
|
123
|
+
/** @type {(p: string) => (o: (_: string) => string) => (f: types.Field) => string} */
|
|
124
|
+
const pf = p => o => ([name, t]) => `${name}: ${type(p)(o)(t)}`;
|
|
125
|
+
const param = pf(super_)(obj);
|
|
126
|
+
const mapParam = map(param);
|
|
127
|
+
const mapField = map(pf('')(ref));
|
|
128
|
+
/** @type {(fa: types.FieldArray) => (name: string) => Text.Block} */
|
|
129
|
+
const struct = fn(entries)
|
|
130
|
+
.then(mapField)
|
|
131
|
+
.then(rustStruct)
|
|
132
|
+
.result;
|
|
133
|
+
/** @type {(first: readonly string[]) => (p: types.FieldArray) => string} */
|
|
134
|
+
const func = first => p => {
|
|
135
|
+
const resultStr = '_' in p ? ` -> ${type(super_)(ref)(p._)}` : '';
|
|
136
|
+
const params = commaJoin(flat([first, mapParam(paramList(p))]));
|
|
137
|
+
return `(${params})${resultStr}`;
|
|
138
|
+
};
|
|
139
|
+
/** @type {(n: string) => (p: types.FieldArray) => string} */
|
|
140
|
+
const virtualFnType = n => p => `extern "system" fn${n}${func(this_)(p)}`;
|
|
141
|
+
/** @type {(m: types.Method) => string} */
|
|
142
|
+
const virtualFn = ([n, p]) => `${n}: unsafe ${virtualFnType('')(p)}`;
|
|
143
|
+
const mapVirtualFn = map(virtualFn);
|
|
144
|
+
/** @type {(m: types.Method) => string} */
|
|
145
|
+
const headerFn = ([n, p]) => `fn ${n}${func(self)(p)}`;
|
|
146
|
+
/** @type {(m: types.Method) => string} */
|
|
147
|
+
const traitFn = m => `${headerFn(m)};`;
|
|
148
|
+
const mapTraitFn = map(traitFn);
|
|
149
|
+
/** @type {(m: types.Method) => Text.Block} */
|
|
150
|
+
const implFn = m => {
|
|
151
|
+
const [n, p] = m;
|
|
152
|
+
return [
|
|
153
|
+
`${headerFn(m)} {`,
|
|
154
|
+
[`unsafe { (self.interface().${n})(${virtualCall(p)}) }`],
|
|
155
|
+
'}'
|
|
156
|
+
];
|
|
157
|
+
};
|
|
158
|
+
const flatMapImplFn = flatMap(implFn);
|
|
159
|
+
/** @type {(m: types.Method) => Text.Block} */
|
|
160
|
+
const impl = ([n, p]) => {
|
|
161
|
+
const type = virtualFnType(` ${n}`)(p);
|
|
162
|
+
return [
|
|
163
|
+
`${type} {`,
|
|
164
|
+
[`unsafe { nanocom::CObject::from_object_unchecked(this) }.${n}(${call(p)})`],
|
|
165
|
+
'}'
|
|
166
|
+
];
|
|
167
|
+
};
|
|
168
|
+
const flatMapImpl = flatMap(impl);
|
|
169
|
+
/** @type {(i: types.Interface) => (name: string) => Text.Block} */
|
|
170
|
+
const interface_ = ({ interface: i, guid }) => name => {
|
|
171
|
+
const e = entries(i);
|
|
172
|
+
return [
|
|
173
|
+
`pub mod ${name} {`,
|
|
174
|
+
[
|
|
175
|
+
rustType('Object'),
|
|
176
|
+
rustType('Ref'),
|
|
177
|
+
rustType('Vmt'),
|
|
178
|
+
],
|
|
179
|
+
rustStruct(mapVirtualFn(e))('Interface'),
|
|
180
|
+
rustImpl({
|
|
181
|
+
trait: 'nanocom::Interface',
|
|
182
|
+
type: 'Interface',
|
|
183
|
+
content: [`const GUID: nanocom::GUID = 0x${guid.replaceAll('-', '_')};`]
|
|
184
|
+
}),
|
|
185
|
+
trait({ pub: true, type: 'Ex', content: mapTraitFn(e) }),
|
|
186
|
+
rustImpl({
|
|
187
|
+
trait: 'Ex',
|
|
188
|
+
type: 'Object',
|
|
189
|
+
content: flatMapImplFn(e)
|
|
190
|
+
}),
|
|
191
|
+
traitImpl({
|
|
192
|
+
pub: true,
|
|
193
|
+
type: 'ClassEx',
|
|
194
|
+
content: ['const VMT: Vmt = Vmt {',
|
|
195
|
+
['iunknown: nanocom::CObject::<Self>::IUNKNOWN,',
|
|
196
|
+
'interface: Interface {',
|
|
197
|
+
mapAssign(e),
|
|
198
|
+
'},',
|
|
199
|
+
],
|
|
200
|
+
'};'
|
|
201
|
+
]
|
|
202
|
+
}),
|
|
203
|
+
traitImpl({
|
|
204
|
+
type: 'PrivateClassEx',
|
|
205
|
+
content: flatMapImpl(e)
|
|
206
|
+
}),
|
|
207
|
+
'}'
|
|
208
|
+
];
|
|
209
|
+
};
|
|
210
|
+
/** @type {(type: O.Entry<types.Definition>) => Text.Block} */
|
|
211
|
+
const def = ([name, type]) => ('interface' in type ? interface_(type) : struct(type.struct))(name);
|
|
212
|
+
return flat([['#![allow(non_snake_case)]'], flatMap(def)(entries(library))]);
|
|
213
|
+
};
|
|
@@ -0,0 +1,123 @@
|
|
|
1
|
+
import rust from './testlib.f.mjs';
|
|
2
|
+
export default () => {
|
|
3
|
+
const e = '#![allow(non_snake_case)]\n' +
|
|
4
|
+
'#[repr(C)]\n' +
|
|
5
|
+
'pub struct Slice {\n' +
|
|
6
|
+
' pub Start: *const u8,\n' +
|
|
7
|
+
' pub Size: usize,\n' +
|
|
8
|
+
'}\n' +
|
|
9
|
+
'#[repr(C)]\n' +
|
|
10
|
+
'pub struct ManagedStruct {\n' +
|
|
11
|
+
' pub M: IMy::Ref,\n' +
|
|
12
|
+
'}\n' +
|
|
13
|
+
'pub mod IMy {\n' +
|
|
14
|
+
' pub type Object = nanocom::Object<Interface>;\n' +
|
|
15
|
+
' pub type Ref = nanocom::Ref<Interface>;\n' +
|
|
16
|
+
' pub type Vmt = nanocom::Vmt<Interface>;\n' +
|
|
17
|
+
' #[repr(C)]\n' +
|
|
18
|
+
' pub struct Interface {\n' +
|
|
19
|
+
' pub GetSlice: unsafe extern "system" fn(this: &Object) -> super::Slice,\n' +
|
|
20
|
+
' pub SetSlice: unsafe extern "system" fn(this: &Object, slice: super::Slice),\n' +
|
|
21
|
+
' pub GetUnsafe: unsafe extern "system" fn(this: &Object) -> *const bool,\n' +
|
|
22
|
+
' pub SetUnsafe: unsafe extern "system" fn(this: &Object, p: *const super::Slice, size: u32),\n' +
|
|
23
|
+
' pub Some: unsafe extern "system" fn(this: &Object, p: &super::IMy::Object) -> bool,\n' +
|
|
24
|
+
' pub GetIMy: unsafe extern "system" fn(this: &Object, a: u16, b: i16) -> super::IMy::Ref,\n' +
|
|
25
|
+
' pub SetManagedStruct: unsafe extern "system" fn(this: &Object, a: super::ManagedStruct),\n' +
|
|
26
|
+
' }\n' +
|
|
27
|
+
' impl nanocom::Interface for Interface {\n' +
|
|
28
|
+
' const GUID: nanocom::GUID = 0xC66FB270_2D80_49AD_BB6E_88C1F90B805D;\n' +
|
|
29
|
+
' }\n' +
|
|
30
|
+
' pub trait Ex {\n' +
|
|
31
|
+
' fn GetSlice(&self) -> super::Slice;\n' +
|
|
32
|
+
' fn SetSlice(&self, slice: super::Slice);\n' +
|
|
33
|
+
' fn GetUnsafe(&self) -> *const bool;\n' +
|
|
34
|
+
' fn SetUnsafe(&self, p: *const super::Slice, size: u32);\n' +
|
|
35
|
+
' fn Some(&self, p: &super::IMy::Object) -> bool;\n' +
|
|
36
|
+
' fn GetIMy(&self, a: u16, b: i16) -> super::IMy::Ref;\n' +
|
|
37
|
+
' fn SetManagedStruct(&self, a: super::ManagedStruct);\n' +
|
|
38
|
+
' }\n' +
|
|
39
|
+
' impl Ex for Object {\n' +
|
|
40
|
+
' fn GetSlice(&self) -> super::Slice {\n' +
|
|
41
|
+
' unsafe { (self.interface().GetSlice)(self) }\n' +
|
|
42
|
+
' }\n' +
|
|
43
|
+
' fn SetSlice(&self, slice: super::Slice) {\n' +
|
|
44
|
+
' unsafe { (self.interface().SetSlice)(self, slice) }\n' +
|
|
45
|
+
' }\n' +
|
|
46
|
+
' fn GetUnsafe(&self) -> *const bool {\n' +
|
|
47
|
+
' unsafe { (self.interface().GetUnsafe)(self) }\n' +
|
|
48
|
+
' }\n' +
|
|
49
|
+
' fn SetUnsafe(&self, p: *const super::Slice, size: u32) {\n' +
|
|
50
|
+
' unsafe { (self.interface().SetUnsafe)(self, p, size) }\n' +
|
|
51
|
+
' }\n' +
|
|
52
|
+
' fn Some(&self, p: &super::IMy::Object) -> bool {\n' +
|
|
53
|
+
' unsafe { (self.interface().Some)(self, p) }\n' +
|
|
54
|
+
' }\n' +
|
|
55
|
+
' fn GetIMy(&self, a: u16, b: i16) -> super::IMy::Ref {\n' +
|
|
56
|
+
' unsafe { (self.interface().GetIMy)(self, a, b) }\n' +
|
|
57
|
+
' }\n' +
|
|
58
|
+
' fn SetManagedStruct(&self, a: super::ManagedStruct) {\n' +
|
|
59
|
+
' unsafe { (self.interface().SetManagedStruct)(self, a) }\n' +
|
|
60
|
+
' }\n' +
|
|
61
|
+
' }\n' +
|
|
62
|
+
' pub trait ClassEx\n' +
|
|
63
|
+
' where\n' +
|
|
64
|
+
' Self: nanocom::Class<Interface = Interface>,\n' +
|
|
65
|
+
' nanocom::CObject<Self>: Ex,\n' +
|
|
66
|
+
' {\n' +
|
|
67
|
+
' const VMT: Vmt = Vmt {\n' +
|
|
68
|
+
' iunknown: nanocom::CObject::<Self>::IUNKNOWN,\n' +
|
|
69
|
+
' interface: Interface {\n' +
|
|
70
|
+
' GetSlice: Self::GetSlice,\n' +
|
|
71
|
+
' SetSlice: Self::SetSlice,\n' +
|
|
72
|
+
' GetUnsafe: Self::GetUnsafe,\n' +
|
|
73
|
+
' SetUnsafe: Self::SetUnsafe,\n' +
|
|
74
|
+
' Some: Self::Some,\n' +
|
|
75
|
+
' GetIMy: Self::GetIMy,\n' +
|
|
76
|
+
' SetManagedStruct: Self::SetManagedStruct,\n' +
|
|
77
|
+
' },\n' +
|
|
78
|
+
' };\n' +
|
|
79
|
+
' }\n' +
|
|
80
|
+
' impl<T> ClassEx for T\n' +
|
|
81
|
+
' where\n' +
|
|
82
|
+
' Self: nanocom::Class<Interface = Interface>,\n' +
|
|
83
|
+
' nanocom::CObject<Self>: Ex,\n' +
|
|
84
|
+
' {\n' +
|
|
85
|
+
' }\n' +
|
|
86
|
+
' trait PrivateClassEx\n' +
|
|
87
|
+
' where\n' +
|
|
88
|
+
' Self: nanocom::Class<Interface = Interface>,\n' +
|
|
89
|
+
' nanocom::CObject<Self>: Ex,\n' +
|
|
90
|
+
' {\n' +
|
|
91
|
+
' extern "system" fn GetSlice(this: &Object) -> super::Slice {\n' +
|
|
92
|
+
' unsafe { nanocom::CObject::from_object_unchecked(this) }.GetSlice()\n' +
|
|
93
|
+
' }\n' +
|
|
94
|
+
' extern "system" fn SetSlice(this: &Object, slice: super::Slice) {\n' +
|
|
95
|
+
' unsafe { nanocom::CObject::from_object_unchecked(this) }.SetSlice(slice)\n' +
|
|
96
|
+
' }\n' +
|
|
97
|
+
' extern "system" fn GetUnsafe(this: &Object) -> *const bool {\n' +
|
|
98
|
+
' unsafe { nanocom::CObject::from_object_unchecked(this) }.GetUnsafe()\n' +
|
|
99
|
+
' }\n' +
|
|
100
|
+
' extern "system" fn SetUnsafe(this: &Object, p: *const super::Slice, size: u32) {\n' +
|
|
101
|
+
' unsafe { nanocom::CObject::from_object_unchecked(this) }.SetUnsafe(p, size)\n' +
|
|
102
|
+
' }\n' +
|
|
103
|
+
' extern "system" fn Some(this: &Object, p: &super::IMy::Object) -> bool {\n' +
|
|
104
|
+
' unsafe { nanocom::CObject::from_object_unchecked(this) }.Some(p)\n' +
|
|
105
|
+
' }\n' +
|
|
106
|
+
' extern "system" fn GetIMy(this: &Object, a: u16, b: i16) -> super::IMy::Ref {\n' +
|
|
107
|
+
' unsafe { nanocom::CObject::from_object_unchecked(this) }.GetIMy(a, b)\n' +
|
|
108
|
+
' }\n' +
|
|
109
|
+
' extern "system" fn SetManagedStruct(this: &Object, a: super::ManagedStruct) {\n' +
|
|
110
|
+
' unsafe { nanocom::CObject::from_object_unchecked(this) }.SetManagedStruct(a)\n' +
|
|
111
|
+
' }\n' +
|
|
112
|
+
' }\n' +
|
|
113
|
+
' impl<T> PrivateClassEx for T\n' +
|
|
114
|
+
' where\n' +
|
|
115
|
+
' Self: nanocom::Class<Interface = Interface>,\n' +
|
|
116
|
+
' nanocom::CObject<Self>: Ex,\n' +
|
|
117
|
+
' {\n' +
|
|
118
|
+
' }\n' +
|
|
119
|
+
'}';
|
|
120
|
+
if (rust !== e) {
|
|
121
|
+
throw rust;
|
|
122
|
+
}
|
|
123
|
+
};
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
import * as text from '../../text/module.f.mjs';
|
|
2
|
+
const { flat } = text;
|
|
3
|
+
import * as string from '../../types/string/module.f.mjs';
|
|
4
|
+
const { join } = string;
|
|
5
|
+
import { rust } from './module.f.mjs';
|
|
6
|
+
import library from '../types/testlib.f.mjs';
|
|
7
|
+
export default join('\n')(flat(' ')(rust(library)));
|
|
@@ -14,7 +14,7 @@ export type Output = {
|
|
|
14
14
|
readonly name: string;
|
|
15
15
|
readonly content: string;
|
|
16
16
|
};
|
|
17
|
-
readonly line:
|
|
17
|
+
readonly line: list.List<list.List<string>>;
|
|
18
18
|
};
|
|
19
19
|
export type Func = (nodejs: NodeJs) => Output;
|
|
20
20
|
/** @type {Func} */
|
|
@@ -23,4 +23,4 @@ declare const cpp: Func;
|
|
|
23
23
|
declare const cs: Func;
|
|
24
24
|
/** @type {Func} */
|
|
25
25
|
declare const rust: Func;
|
|
26
|
-
import * as
|
|
26
|
+
import * as list from '../../types/list/module.f.mjs';
|
|
@@ -0,0 +1,98 @@
|
|
|
1
|
+
import * as list from '../../types/list/module.f.mjs';
|
|
2
|
+
const { flat } = list;
|
|
3
|
+
import cppContent from '../cpp/testlib.f.mjs';
|
|
4
|
+
import csContent from '../cs/testlib.f.mjs';
|
|
5
|
+
import rustContent from '../rust/testlib.f.mjs';
|
|
6
|
+
/**
|
|
7
|
+
* @typedef {|
|
|
8
|
+
* 'aix' |
|
|
9
|
+
* 'android' |
|
|
10
|
+
* 'darwin' |
|
|
11
|
+
* 'freebsd' |
|
|
12
|
+
* 'haiku' |
|
|
13
|
+
* 'linux' |
|
|
14
|
+
* 'openbsd' |
|
|
15
|
+
* 'sunos' |
|
|
16
|
+
* 'win32' |
|
|
17
|
+
* 'cygwin' |
|
|
18
|
+
* 'netbsd'
|
|
19
|
+
* } Platform
|
|
20
|
+
*/
|
|
21
|
+
/**
|
|
22
|
+
* @typedef {{
|
|
23
|
+
* readonly dirname: string
|
|
24
|
+
* readonly platform: Platform
|
|
25
|
+
* }} NodeJs
|
|
26
|
+
*/
|
|
27
|
+
/**
|
|
28
|
+
* @typedef {{
|
|
29
|
+
* readonly file: {
|
|
30
|
+
* readonly name: string
|
|
31
|
+
* readonly content: string
|
|
32
|
+
* }
|
|
33
|
+
* readonly line: list.List<list.List<string>>
|
|
34
|
+
* }} Output
|
|
35
|
+
*/
|
|
36
|
+
/** @typedef {(nodejs: NodeJs) => Output} Func */
|
|
37
|
+
/** @type {(platform: Platform) => readonly string[]} */
|
|
38
|
+
const flags = platform => {
|
|
39
|
+
switch (platform) {
|
|
40
|
+
case 'win32':
|
|
41
|
+
return [];
|
|
42
|
+
case 'linux':
|
|
43
|
+
return ['-std=c++17', '-lstdc++', '-fPIC'];
|
|
44
|
+
default:
|
|
45
|
+
return ['-std=c++17', '-lc++'];
|
|
46
|
+
}
|
|
47
|
+
};
|
|
48
|
+
/** @type {(platform: Platform) => (name: string) => string} */
|
|
49
|
+
const output = platform => name => {
|
|
50
|
+
switch (platform) {
|
|
51
|
+
case 'win32': return `${name}.dll`;
|
|
52
|
+
case 'darwin': return `lib${name}.dylib`;
|
|
53
|
+
default: return `lib${name}.so`;
|
|
54
|
+
}
|
|
55
|
+
};
|
|
56
|
+
/** @type {Func} */
|
|
57
|
+
const cpp = ({ dirname, platform }) => ({
|
|
58
|
+
file: {
|
|
59
|
+
name: `${dirname}/cpp/_result.hpp`,
|
|
60
|
+
content: cppContent(),
|
|
61
|
+
},
|
|
62
|
+
line: [
|
|
63
|
+
flat([
|
|
64
|
+
['clang', '-shared', '-o', output(platform)('testc')],
|
|
65
|
+
flags(platform),
|
|
66
|
+
[`${dirname}/cpp/main.cpp`],
|
|
67
|
+
]),
|
|
68
|
+
],
|
|
69
|
+
});
|
|
70
|
+
/** @type {Func} */
|
|
71
|
+
const cs = ({ dirname, platform }) => ({
|
|
72
|
+
file: {
|
|
73
|
+
name: `${dirname}/cs/_result.cs`,
|
|
74
|
+
content: csContent,
|
|
75
|
+
},
|
|
76
|
+
line: [
|
|
77
|
+
platform === 'win32'
|
|
78
|
+
? ['dotnet', 'run', '--project', `${dirname}/cs/cs.csproj`]
|
|
79
|
+
// .Net on Linux and MacOS doesn't properly support COM object marshalling
|
|
80
|
+
: ['dotnet', 'build', `${dirname}/cs/cs.csproj`]
|
|
81
|
+
],
|
|
82
|
+
});
|
|
83
|
+
/** @type {Func} */
|
|
84
|
+
const rust = ({ dirname }) => ({
|
|
85
|
+
file: {
|
|
86
|
+
name: `${dirname}/rust/src/_result.rs`,
|
|
87
|
+
content: rustContent,
|
|
88
|
+
},
|
|
89
|
+
line: [['cargo', 'build' /**, '--locked' */]]
|
|
90
|
+
});
|
|
91
|
+
export default {
|
|
92
|
+
/** @readonly */
|
|
93
|
+
cpp,
|
|
94
|
+
/** @readonly */
|
|
95
|
+
cs,
|
|
96
|
+
/** @readonly */
|
|
97
|
+
rust,
|
|
98
|
+
};
|
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
import { writeFileSync } from 'node:fs';
|
|
2
|
+
import { execSync } from 'node:child_process';
|
|
3
|
+
import { platform, exit } from 'node:process';
|
|
4
|
+
import build, * as Build from './build.f.mjs';
|
|
5
|
+
const { cpp, cs, rust } = build;
|
|
6
|
+
import * as string from '../../types/string/module.f.mjs';
|
|
7
|
+
const { join } = string;
|
|
8
|
+
const { log, error } = console;
|
|
9
|
+
import * as sgr from '../../text/sgr/module.f.mjs';
|
|
10
|
+
const { bold, reset } = sgr.codes;
|
|
11
|
+
import * as list from '../../types/list/module.f.mjs';
|
|
12
|
+
import { fileURLToPath } from 'node:url';
|
|
13
|
+
import { dirname } from 'node:path';
|
|
14
|
+
const __filename = fileURLToPath(import.meta.url);
|
|
15
|
+
const __dirname = dirname(__filename);
|
|
16
|
+
const nodeJs = {
|
|
17
|
+
dirname: __dirname,
|
|
18
|
+
platform,
|
|
19
|
+
};
|
|
20
|
+
/** @type {(f: Build.Func) => void} */
|
|
21
|
+
const run = f => {
|
|
22
|
+
const { file: { name, content }, line } = f(nodeJs);
|
|
23
|
+
log(`${bold}writing: ${name}${reset}`);
|
|
24
|
+
writeFileSync(name, content);
|
|
25
|
+
for (const i of list.iterable(line)) {
|
|
26
|
+
const cmd = join(' ')(i);
|
|
27
|
+
log(`${bold}running: ${cmd}${reset}`);
|
|
28
|
+
try {
|
|
29
|
+
log(execSync(cmd).toString());
|
|
30
|
+
}
|
|
31
|
+
catch (e) {
|
|
32
|
+
// @ts-ignore
|
|
33
|
+
error(e.output.toString());
|
|
34
|
+
exit(-1);
|
|
35
|
+
}
|
|
36
|
+
}
|
|
37
|
+
};
|
|
38
|
+
run(cpp);
|
|
39
|
+
run(rust);
|
|
40
|
+
run(cs);
|