Protocol (MOP) in a “cool” way Not about “metacompilation” as in “supercompilation” Think of “meta(object protocol)compilation” Or simply “types’n’code generation using MOP” No supercompilation today
numbers! Different OS, different hardware, different bits… We want to define a type and work with it everywhere What to do? For example, ASN.1. (works in space (satellites), your cell phone (LTE), your laptop (X.509) too…)
numbers! Different OS, different hardware, different bits… We want to define a type and work with it everywhere What to do? For example, ASN.1. (works in space (satellites), your cell phone (LTE), your laptop (X.509) too…)
a value of a type described in ASN.1. • Various binary encodings (BER, DER etc) and text ones (XML, JSON etc) are defined. • I was focused on BER (Basic Encoding Rules), as LDAP protocol uses it. • Other encoding can be added.
updates as much as needed Creates a maintenance burden: additional sources just to generate, compile and throw away Target is source code – easy to generate and debug The source code must be immutable and so any changes add technical debt Can tune generated code to a certain degree Complicates overall build process Still great for linters, code minimizers etc.
Creates a maintenance burden: any change to the spec itself require manual updates done by a programmer Can handle any case one can imagine More prone to errors Any changes are preserved Way harder to reason about correctness Easy to mix with the main application code With a large spec, writing out types manually is an anti-pattern (still good for early prototypes)
can represent ASN.1 types using Perl 6 ones – We can serialize/parse to/from bytes It does its job! It is tedious to use too In Perl 6 we want and can do better!
don’t want to spend our time as an ASN.1 compiler (can as well create something else!) Make machine program a machine We don’t want to add a maintenance burden
# `use` statement is used in Perl 6 give me Types <file ldap.asn>; use Types <file ldap.asn>; # Use ASN::META library use ASN::META <file ldap.asn>; # Just use types here…
to process LDAP ASN.1 spec • (very incomplete in other areas) • (very open for pull requests) • Visit github.com/Altai-man/ASN-Grammar for more details
implementation in Perl 6 (or, more generally, metaprogramming) Including simple types (integers, strings) Including complex types (sequences, choices) Including recursive types with reference resolution…
implementation in Perl 6 (or, more generally, metaprogramming) Including simple types (integers, strings) Including complex types (sequences, choices) Including recursive types with reference resolution… At compile time!
ASN::META just exports needed types as if they were defined there • Except ASN::META does not have any except compiler-related ones • Do not need to use ASN::BER
ASN::META just exports needed types as if they were defined there • Except ASN::META does not have any except compiler-related ones • Do not need to use ASN::BER (“a lot”, at least)
are great use cases for the first approach There are great use cases for the second approach See a suitable case? Consider utilizing metaprogramming! (maybe even at compile time)
are great use cases for the first approach There are great use cases for the second approach See a suitable case? Consider utilizing metaprogramming! (maybe even at compile time) Perl 6 is a very handy tool to do so!