A few peeks of Lingling/MLgate (30/11)

Lingling is a technology I am building to facilitate compiler + spec creation. It describes its own 【DSL】 called “MLgate”.

Algebraic Typing

Users trivially type fixtures w.o. hints in response to phase re-evaluation (based on dirty triggers and Defer exceptions).

MLgate presents convenient wrappers over the verify specification.

uh, better meant “footprint” instead of “variable” as to augmentLookup :s

Language components do have to set up some configuration for linking adequate messages and specific-behavior; for instance,

lingling.fig

# $schema=http://www.ryujinx.com/lingling/1.0
ID: org.atelier.luml:1.0.0

ml:
  module: org.atelier.luml

language:
  enable: true
  ID: luml
  name: Luml
  uri: https://www.atelier.org/luml/1.0/lang
  extensions: ["ml", "luml"]

  cast-invoke:
    enable = true
    optional = false

  internal-aliases:
    msg: org.atelier.luml.msg

  message-reports:
    # msg::WrongNumberOfArguments { expected : int, got : int }
    wrong-number-of-arguments: msg::WrongNumberOfArguments

    # msg::NotInvokable { type : Type }
    not-invokable: msg::NotInvokable

Tree traversal

MLgate implicitly enters frames.

(* n : Tree *)

(* master sample *)
fun f () = List.app (fn n' => ...)   (n->children())

val _ = List.filter (fn n' => yesno) (n->children())
val _ = List.exists (fn n' => yesno) (n->children())
val _ = List.all    (fn n' => yesno) (n->children())

val _ = with n' do ... end

Pay-As-You-Go-style

Incremental parsing, analysis and evaluation ---- all that relies on the fact that anything in MLgate can be queried for a copy, hash code, ord and read-from/written-to file system (in form of binary cache).

In terms of cache, Lingling is being formulated to specify build tooling (like Cargo, Deno, CMake, Maven, PIP, Golang…) easily, where we’d be more like Golang, hiding build artifacts into smth like /var/share/<Set-ID>/shadows/home/inexistent/Documents/katanacraft plus subshadows for a specific shadow.

Parsing

Wanna see a bit of how parsing rulesets are formulated?

Some snippets.

ruleset    Form = b:[ between ( (), mode=MODE, reinterpret as Form' ) ] ;

ruleset || Form' =
  | exp ( Exp )
  | stat ( Stat )
  ;

Another one.

ruleset ArrayInitialiser =
	"[" elements:Expression(minPrecedence=Assignment)*{split=","}{trail}{elision=Elision} "]" (":" type:TypeExpression)?
	;

ruleset Elision = "," ;

ruleset definitions are used instead of ANTLR-style ones since they can specify class blocks and MLgate doesn’t limit itself to only few kinds of syntactic variations. Either way, I’m not planning to transpile MLgate to another language, but rather compile it down to some bytecode.

Well, the reference I built so far is extensive and there’s a lot I can show, but I’m leaving it closed-source for the meanwhile. I’m implementing the bootstrap tooling for this technology using Deno.

1 Like

Hi @mryun, thanks for sharing these peeks. Lingling/MLgate looks like an ambitious project.

A few things stood out to me:

  • Algebraic typing with phase re-evaluation: Typing fixtures without hints, driven by dirty triggers and Defer exceptions, is an interesting approach. How do you guarantee termination, or detect cycles, when a deferred type depends on something that is itself re-evaluated?
  • Pay-as-you-go caching: Requiring every value to support copy, hash, ord and binary serialization is a clean uniform contract. How do you handle cache invalidation when a language component’s configuration changes, for example in lingling.fig?
  • ruleset vs. ANTLR-style grammars: I like that rulesets can carry class blocks. How do you handle operator precedence and error recovery? I notice minPrecedence=Assignment in the array initialiser, so I assume precedence is a first-class parameter.
  • Compiling to bytecode: Is the bytecode format meant to be stable and shared across languages defined in Lingling, or specific to each one?

One small note: in the cast-invoke block of the YAML snippet, enable = true and optional = false use = rather than :. If that’s not intentional, it would be invalid YAML.

I understand keeping the reference closed-source for now, but I’d love to see more as it matures, especially the Deno-based bootstrap tooling.