diff options
Diffstat (limited to 'stdlib')
19 files changed, 32 insertions, 262 deletions
diff --git a/stdlib/source/lux/control/parser/binary.lux b/stdlib/source/lux/control/parser/binary.lux index 5f8ccc122..8d01d2d48 100644 --- a/stdlib/source/lux/control/parser/binary.lux +++ b/stdlib/source/lux/control/parser/binary.lux @@ -144,13 +144,11 @@ (def: #export text ..utf8/64) -(template [<name> <with-offset> <bits> <size>] - [(def: #export (<with-offset> extra-count valueP) - (All [v] (-> Nat (Parser v) (Parser (Row v)))) +(template [<name> <bits> <size>] + [(def: #export (<name> valueP) + (All [v] (-> (Parser v) (Parser (Row v)))) (do //.monad - [count (|> <bits> - (//@map .nat) - (:: @ map (n/- extra-count)))] + [count (//@map .nat <bits>)] (loop [index 0 output (:share [v] {(Parser v) @@ -162,16 +160,12 @@ [value valueP] (recur (.inc index) (row.add value output))) - (//@wrap output))))) - - (def: #export <name> - (All [v] (-> (Parser v) (Parser (Row v)))) - (<with-offset> 0))] + (//@wrap output)))))] - [row/8 row/8' ..bits/8 ..size/8] - [row/16 row/16' ..bits/16 ..size/16] - [row/32 row/32' ..bits/32 ..size/32] - [row/64 row/64' ..bits/64 ..size/64] + [row/8 ..bits/8 ..size/8] + [row/16 ..bits/16 ..size/16] + [row/32 ..bits/32 ..size/32] + [row/64 ..bits/64 ..size/64] ) (def: #export maybe diff --git a/stdlib/source/lux/target/jvm/attribute.lux b/stdlib/source/lux/target/jvm/attribute.lux index 2f4361960..fef8598e8 100644 --- a/stdlib/source/lux/target/jvm/attribute.lux +++ b/stdlib/source/lux/target/jvm/attribute.lux @@ -6,9 +6,7 @@ [control ["." state (#+ State)] ["." try] - ["." exception (#+ exception:)] - ["<>" parser - ["<2>" binary (#+ Parser)]]] + ["." exception (#+ exception:)]] [data ["." product] [format @@ -111,33 +109,6 @@ [@name (//constant/pool.utf8 ..code-name)] (wrap (code' @name specification)))) -(exception: #export invalid-attribute) - -(def: #export (parser pool) - (-> Pool (Parser Attribute)) - (let [?@constant (|> ..constant-name - //constant/pool.find-utf8 - (state.run pool) - product.right) - ?@code (|> ..code-name - //constant/pool.find-utf8 - (state.run pool) - product.right) - (^open "_@.") (try.equivalence //index.equivalence)] - (<>.rec - (function (_ parser) - (do <>.monad - [@name //index.parser - length //unsigned.u4-parser] - (cond (_@= ?@constant (#try.Success @name)) - (:: @ map (..constant' @name) /constant.parser) - - (_@= ?@code (#try.Success @name)) - (:: @ map (..code' @name) (/code.parser parser)) - - ## else - (<>.fail (exception.construct ..invalid-attribute [])))))))) - (def: #export (writer value) (Writer Attribute) (case value diff --git a/stdlib/source/lux/target/jvm/attribute/code.lux b/stdlib/source/lux/target/jvm/attribute/code.lux index dff626c5c..44b3b1b5b 100644 --- a/stdlib/source/lux/target/jvm/attribute/code.lux +++ b/stdlib/source/lux/target/jvm/attribute/code.lux @@ -3,9 +3,6 @@ [type (#+ :share)] [abstract ["." equivalence (#+ Equivalence)]] - [control - ["<>" parser - ["<2>" binary (#+ Parser)]]] [data ["." binary (#+ Binary)] [format @@ -62,23 +59,6 @@ )) ## https://docs.oracle.com/javase/specs/jvms/se8/html/jvms-4.html#jvms-4.7.3 -(def: #export (parser parser) - (All [Attribute] (-> (Parser Attribute) (Parser (Code Attribute)))) - ($_ <>.and - ## u2 max_stack; - ## u2 max_locals; - ///resources.parser - ## u4 code_length; - ## u1 code[code_length]; - <2>.binary/32 - ## u2 exception_table_length; - ## exception_table[exception_table_length]; - (<2>.row/16 /exception.parser) - ## u2 attributes_count; - ## attribute_info attributes[attributes_count]; - (<2>.row/16 parser) - )) - (def: #export (writer writer code) (All [Attribute] (-> (Writer Attribute) (Writer (Code Attribute)))) ($_ binaryF@compose diff --git a/stdlib/source/lux/target/jvm/attribute/code/exception.lux b/stdlib/source/lux/target/jvm/attribute/code/exception.lux index 19de9c789..003bad74f 100644 --- a/stdlib/source/lux/target/jvm/attribute/code/exception.lux +++ b/stdlib/source/lux/target/jvm/attribute/code/exception.lux @@ -2,9 +2,6 @@ [lux #* [abstract ["." equivalence (#+ Equivalence)]] - [control - ["<>" parser ("#@." functor) - ["<2>" binary (#+ Parser)]]] [data [format [".F" binary (#+ Writer)]]]] @@ -46,15 +43,6 @@ ////unsigned.u2-bytes )) -(def: #export parser - (Parser Exception) - ($_ <>.and - ////jump.parser - ////jump.parser - ////jump.parser - ////index.parser - )) - (def: #export writer (Writer Exception) ($_ binaryF.and diff --git a/stdlib/source/lux/target/jvm/attribute/constant.lux b/stdlib/source/lux/target/jvm/attribute/constant.lux index ec3f534a3..4dae93140 100644 --- a/stdlib/source/lux/target/jvm/attribute/constant.lux +++ b/stdlib/source/lux/target/jvm/attribute/constant.lux @@ -2,9 +2,6 @@ [lux #* [abstract [equivalence (#+ Equivalence)]] - [control - ["<>" parser ("#@." functor) - ["<2>" binary (#+ Parser)]]] [data [format [binary (#+ Writer)]]]] @@ -24,10 +21,6 @@ (def: #export length ///unsigned.u2-bytes) -(def: #export parser - (Parser Constant) - ///index.parser) - (def: #export writer (Writer Constant) ///index.writer) diff --git a/stdlib/source/lux/target/jvm/class.lux b/stdlib/source/lux/target/jvm/class.lux index a99637dcd..bc3670110 100644 --- a/stdlib/source/lux/target/jvm/class.lux +++ b/stdlib/source/lux/target/jvm/class.lux @@ -5,8 +5,6 @@ ["." equivalence (#+ Equivalence)] ["." monad (#+ do)]] [control - ["<>" parser - ["<2>" binary (#+ Parser)]] ["." state (#+ State)]] [data [number (#+) @@ -113,32 +111,6 @@ #methods (row.from-list =methods) #attributes attributes})) -(def: #export parser - (Parser Class) - (do <>.monad - [magic //magic.parser - minor-version //version.parser - major-version //version.parser - constant-pool //constant/pool.parser - modifier //modifier.parser - this //index.parser - super //index.parser - interfaces (<2>.row/16 //index.parser) - fields (<2>.row/16 (//field.parser constant-pool)) - methods (<2>.row/16 (//method.parser constant-pool)) - attributes (<2>.row/16 (//attribute.parser constant-pool))] - (wrap {#magic magic - #minor-version minor-version - #major-version major-version - #constant-pool constant-pool - #modifier modifier - #this this - #super super - #interfaces interfaces - #fields fields - #methods methods - #attributes attributes}))) - (def: #export (writer class) (Writer Class) (`` ($_ binaryF@compose diff --git a/stdlib/source/lux/target/jvm/constant.lux b/stdlib/source/lux/target/jvm/constant.lux index 36c131b00..c157d4abb 100644 --- a/stdlib/source/lux/target/jvm/constant.lux +++ b/stdlib/source/lux/target/jvm/constant.lux @@ -3,9 +3,6 @@ [abstract [monad (#+ do)] ["." equivalence (#+ Equivalence)]] - [control - ["<>" parser ("#@." functor) - ["<2>" binary (#+ Parser)]]] [data [number ["." int] @@ -27,10 +24,6 @@ (type: #export UTF8 Text) -(def: utf8-parser - (Parser UTF8) - <2>.utf8/16) - (def: utf8-writer (Writer UTF8) binaryF.utf8/16) @@ -50,10 +43,6 @@ (|>> :representation) //index.equivalence)) - (def: class-parser - (Parser Class) - (<>@map (|>> :abstraction) //index.parser)) - (def: class-writer (Writer Class) (|>> :representation //index.writer)) @@ -91,17 +80,14 @@ [string String (Index UTF8)] ) - (template [<parser-name> <writer-name> <type> <read> <write> <parser> <writer>] - [(def: <parser-name> - (Parser <type>) - (<>@map (|>> <read> :abstraction) <parser>)) - (def: <writer-name> + (template [<writer-name> <type> <write> <writer>] + [(def: <writer-name> (Writer <type>) (|>> :representation <write> <writer>))] - [long-parser long-writer Long .int (<|) <2>.bits/64 binaryF.bits/64] - [double-parser double-writer Double frac.bits-to-frac frac.frac-to-bits <2>.bits/64 binaryF.bits/64] - [string-parser string-writer String (<|) (<|) //index.parser //index.writer] + [long-writer Long (<|) binaryF.bits/64] + [double-writer Double frac.frac-to-bits binaryF.bits/64] + [string-writer String (<|) //index.writer] ) ) @@ -113,27 +99,21 @@ {#class (Index Class) #name-and-type (Index (Name-And-Type of))}) -(template [<type> <equivalence> <parser> <writer>] +(template [<type> <equivalence> <writer>] [(def: #export <equivalence> (Equivalence (<type> Any)) ($_ equivalence.product //index.equivalence //index.equivalence)) - (def: <parser> - (Parser <type>) - ($_ <>.and - //index.parser - //index.parser)) - (def: <writer> (Writer (<type> Any)) ($_ binaryF.and //index.writer //index.writer))] - [Name-And-Type name-and-type-equivalence name-and-type-parser name-and-type-writer] - [Reference reference-equivalence reference-parser reference-writer] + [Name-And-Type name-and-type-equivalence name-and-type-writer] + [Reference reference-equivalence reference-writer] ) (type: #export Constant @@ -191,34 +171,6 @@ ## ) ) -(def: #export parser - (Parser Constant) - (with-expansions [<constants> (as-is [#UTF8 /tag.utf8 ..utf8-parser] - ## TODO: Integer - ## TODO: Float - [#Long /tag.long ..long-parser] - [#Double /tag.double ..double-parser] - [#Class /tag.class ..class-parser] - [#String /tag.string ..string-parser] - [#Field /tag.field ..reference-parser] - [#Method /tag.method ..reference-parser] - [#Interface-Method /tag.interface-method ..reference-parser] - [#Name-And-Type /tag.name-and-type ..name-and-type-parser] - ## TODO: Method-Handle - ## TODO: Method-Type - ## TODO: Invoke-Dynamic - )] - (do <>.monad - [tag /tag.parser] - (`` (cond (~~ (template [<case> <tag> <parser>] - [(/tag;= <tag> tag) - (:: @ map (|>> <case>) <parser>)] - - <constants>)) - - ## else - (<>.fail "Cannot parse constant.")))))) - (def: #export writer (Writer Constant) (with-expansions [<constants> (as-is [#UTF8 /tag.utf8 ..utf8-writer] diff --git a/stdlib/source/lux/target/jvm/constant/pool.lux b/stdlib/source/lux/target/jvm/constant/pool.lux index 212c3cb9e..773607858 100644 --- a/stdlib/source/lux/target/jvm/constant/pool.lux +++ b/stdlib/source/lux/target/jvm/constant/pool.lux @@ -6,9 +6,7 @@ [control ["." state (#+ State)] ["." try (#+ Try)] - ["." exception (#+ exception:)] - ["<>" parser ("#@." functor) - ["<2>" binary (#+ Parser)]]] + ["." exception (#+ exception:)]] [data [number ["." int] @@ -194,10 +192,6 @@ [interface-method #//.Interface-Method Method] ) -(def: #export parser - (Parser Pool) - (<2>.row/16' ..offset //.parser)) - (def: #export writer (Writer Pool) (binaryF.row/16' ..offset //.writer)) diff --git a/stdlib/source/lux/target/jvm/constant/tag.lux b/stdlib/source/lux/target/jvm/constant/tag.lux index ffbe59390..a3da84812 100644 --- a/stdlib/source/lux/target/jvm/constant/tag.lux +++ b/stdlib/source/lux/target/jvm/constant/tag.lux @@ -2,9 +2,6 @@ [lux #* [abstract [equivalence (#+ Equivalence)]] - [control - ["<>" parser ("#@." functor) - ["<2>" binary (#+ Parser)]]] [data [format [binary (#+ Writer)]]] @@ -46,10 +43,6 @@ [18 invoke-dynamic] ) - (def: #export parser - (Parser Tag) - (<>@map (|>> :abstraction) unsigned.u1-parser)) - (def: #export writer (Writer Tag) (|>> :representation unsigned.u1-writer)) diff --git a/stdlib/source/lux/target/jvm/encoding/signed.lux b/stdlib/source/lux/target/jvm/encoding/signed.lux index 7765d4402..c5a7776b3 100644 --- a/stdlib/source/lux/target/jvm/encoding/signed.lux +++ b/stdlib/source/lux/target/jvm/encoding/signed.lux @@ -3,9 +3,6 @@ [abstract [equivalence (#+ Equivalence)] [order (#+ Order)]] - [control - ["<>" parser ("#@." functor) - ["<2>" binary (#+ Parser)]]] [data [number ["." i64]] @@ -66,16 +63,12 @@ ) ) -(template [<parser-name> <writer-name> <type> <parser> <writer> <post-read>] - [(def: #export <parser-name> - (Parser <type>) - (<>@map (|>> .int <post-read>) <parser>)) - - (def: #export <writer-name> +(template [<writer-name> <type> <writer>] + [(def: #export <writer-name> (Writer <type>) (|>> ..int <writer>))] - [s1-parser s1-writer S1 <2>.bits/8 binaryF.bits/8 ..s1] - [s2-parser s2-writer S2 <2>.bits/16 binaryF.bits/16 ..s2] - [s4-parser s4-writer S4 <2>.bits/32 binaryF.bits/32 ..s4] + [s1-writer S1 binaryF.bits/8] + [s2-writer S2 binaryF.bits/16] + [s4-writer S4 binaryF.bits/32] ) diff --git a/stdlib/source/lux/target/jvm/encoding/unsigned.lux b/stdlib/source/lux/target/jvm/encoding/unsigned.lux index 892d2f86d..b0b8ff312 100644 --- a/stdlib/source/lux/target/jvm/encoding/unsigned.lux +++ b/stdlib/source/lux/target/jvm/encoding/unsigned.lux @@ -3,9 +3,6 @@ [abstract [equivalence (#+ Equivalence)] [order (#+ Order)]] - [control - ["<>" parser ("#@." functor) - ["<2>" binary (#+ Parser)]]] [data [number ["." i64]] @@ -64,16 +61,12 @@ ) ) -(template [<parser-name> <writer-name> <type> <parser> <writer> <post-read>] - [(def: #export <parser-name> - (Parser <type>) - (<>@map (|>> .nat <post-read>) <parser>)) - - (def: #export <writer-name> +(template [<writer-name> <type> <writer>] + [(def: #export <writer-name> (Writer <type>) (|>> ..nat <writer>))] - [u1-parser u1-writer U1 <2>.bits/8 binaryF.bits/8 ..u1] - [u2-parser u2-writer U2 <2>.bits/16 binaryF.bits/16 ..u2] - [u4-parser u4-writer U4 <2>.bits/32 binaryF.bits/32 ..u4] + [u1-writer U1 binaryF.bits/8] + [u2-writer U2 binaryF.bits/16] + [u4-writer U4 binaryF.bits/32] ) diff --git a/stdlib/source/lux/target/jvm/field.lux b/stdlib/source/lux/target/jvm/field.lux index f050a13a5..a2cc35f45 100644 --- a/stdlib/source/lux/target/jvm/field.lux +++ b/stdlib/source/lux/target/jvm/field.lux @@ -5,9 +5,7 @@ ["." equivalence (#+ Equivalence)] ["." monad (#+ do)]] [control - ["." state (#+ State)] - ["<>" parser - ["<2>" binary (#+ Parser)]]] + ["." state (#+ State)]] [data [number (#+) [i64 (#+)]] @@ -51,14 +49,6 @@ //index.equivalence (row.equivalence //attribute.equivalence))) -(def: #export (parser pool) - (-> Pool (Parser Field)) - ($_ <>.and - modifier.parser - //index.parser - //index.parser - (<2>.row/16 (//attribute.parser pool)))) - (def: #export (writer field) (Writer Field) (`` ($_ binaryF@compose diff --git a/stdlib/source/lux/target/jvm/index.lux b/stdlib/source/lux/target/jvm/index.lux index 32ad5d428..430276f4b 100644 --- a/stdlib/source/lux/target/jvm/index.lux +++ b/stdlib/source/lux/target/jvm/index.lux @@ -2,9 +2,6 @@ [lux #* [abstract ["." equivalence (#+ Equivalence)]] - [control - ["<>" parser ("#@." functor) - ["<2>" binary (#+ Parser)]]] [data [format [binary (#+ Writer)]]] @@ -33,10 +30,6 @@ ..number //unsigned.equivalence)) - (def: #export parser - (All [kind] (Parser (Index kind))) - (<>@map ..index //unsigned.u2-parser)) - (def: #export writer (All [kind] (Writer (Index kind))) (|>> ..number //unsigned.u2-writer)) diff --git a/stdlib/source/lux/target/jvm/magic.lux b/stdlib/source/lux/target/jvm/magic.lux index 0fc0bad14..ff2d119e4 100644 --- a/stdlib/source/lux/target/jvm/magic.lux +++ b/stdlib/source/lux/target/jvm/magic.lux @@ -13,8 +13,5 @@ Magic (//unsigned.u4 (hex "CAFEBABE"))) -(def: #export parser - //unsigned.u4-parser) - (def: #export writer //unsigned.u4-writer) diff --git a/stdlib/source/lux/target/jvm/method.lux b/stdlib/source/lux/target/jvm/method.lux index 88d43f5b4..2b47be482 100644 --- a/stdlib/source/lux/target/jvm/method.lux +++ b/stdlib/source/lux/target/jvm/method.lux @@ -6,9 +6,7 @@ ["." monad (#+ do)]] [control ["." try] - ["." state (#+ State)] - ["<>" parser - ["<2>" binary (#+ Parser)]]] + ["." state (#+ State)]] [data [number (#+) [i64 (#+)]] @@ -87,14 +85,6 @@ //index.equivalence (row.equivalence //attribute.equivalence))) -(def: #export (parser pool) - (-> Pool (Parser Method)) - ($_ <>.and - //modifier.parser - //index.parser - //index.parser - (<2>.row/16 (//attribute.parser pool)))) - (def: #export (writer field) (Writer Method) (`` ($_ binaryF@compose diff --git a/stdlib/source/lux/target/jvm/modifier.lux b/stdlib/source/lux/target/jvm/modifier.lux index 0b2770b94..f7024b669 100644 --- a/stdlib/source/lux/target/jvm/modifier.lux +++ b/stdlib/source/lux/target/jvm/modifier.lux @@ -5,8 +5,7 @@ ["." monoid (#+ Monoid)]] [control ["<>" parser - ["<c>" code] - ["<2>" binary (#+ Parser)]]] + ["<c>" code]]] [data ["." number (#+ hex) ["." i64]] @@ -65,10 +64,6 @@ Modifier (:: ..monoid identity)) - (def: #export parser - (All [of] (Parser (Modifier of))) - (:: <>.functor map (|>> :abstraction) //unsigned.u2-parser)) - (def: #export writer (All [of] (Writer (Modifier of))) (|>> :representation //unsigned.u2-writer)) diff --git a/stdlib/source/lux/target/jvm/program/jump.lux b/stdlib/source/lux/target/jvm/program/jump.lux index 00b66bede..19f667cfe 100644 --- a/stdlib/source/lux/target/jvm/program/jump.lux +++ b/stdlib/source/lux/target/jvm/program/jump.lux @@ -11,9 +11,6 @@ (def: #export equivalence ///signed.equivalence) -(def: #export parser - ///signed.s2-parser) - (def: #export writer ///signed.s2-writer) diff --git a/stdlib/source/lux/target/jvm/program/resources.lux b/stdlib/source/lux/target/jvm/program/resources.lux index 980104e72..fa83c4071 100644 --- a/stdlib/source/lux/target/jvm/program/resources.lux +++ b/stdlib/source/lux/target/jvm/program/resources.lux @@ -2,9 +2,6 @@ [lux #* [abstract ["." equivalence (#+ Equivalence)]] - [control - ["<>" parser - ["<2>" binary (#+ Parser)]]] [data [format [".F" binary (#+ Writer) ("#@." monoid)]]]] @@ -37,15 +34,6 @@ ///unsigned.equivalence )) -(def: #export parser - (Parser Resources) - ($_ <>.and - ## u2 max_stack; - ///unsigned.u2-parser - ## u2 max_locals; - ///unsigned.u2-parser - )) - (def: #export (writer resources) (Writer Resources) ($_ binaryF@compose diff --git a/stdlib/source/lux/target/jvm/version.lux b/stdlib/source/lux/target/jvm/version.lux index 7c80928a8..48d2dcaa9 100644 --- a/stdlib/source/lux/target/jvm/version.lux +++ b/stdlib/source/lux/target/jvm/version.lux @@ -29,8 +29,5 @@ [56 v12] ) -(def: #export parser - //unsigned.u2-parser) - (def: #export writer //unsigned.u2-writer) |