PflowDSL: a little language
Pflow.xyz is an SDK for constructing petri-net smart contracts.
This article explores some features of the PflowDSL – which is an internal DSL to build models embedded in solidity code.
This is an excerpt from a demo model deployed to sepolia-optimism testnet. The above model contains every term that the language allows for, here’s a translation to petri-net terminology.
- cell() – [place] declares a memory location in the ‘state’ of the model
- func() – [transition] declares a transformation that mutates state
- arrow() – [arc]connectes cell() –> func() or func() –> cell
- guard() – [inhibitor arc] an arrow used as a ‘if/unless’ precondition
Some additional attributes of the language:
Declarative Style: Using the DSL is essentially describing the structure of the Petri net (places, transitions, arcs) rather than providing step-by-step instructions on how to build it.
- Functional Composition: The DSL uses functions like
cell
,func
,arrow
, andguard
to define individual components and then connect them to form the complete net. - Data-Centric: The core data structures are places and transitions, and the functions operate on and modify these structures.
Syntax:
- Function Calls as Building Blocks: The syntax of function calls in the DSL (
cell(...)
,func(...)
) visually resembles Lisp's s-expression syntax, where everything is enclosed in parentheses and the first element is typically the function name. - Minimal Syntax: The DSL keeps the syntax quite minimal, focusing on the essential elements needed to define the Petri net.
Altogether, the Pflow SDK provides a way to enrich the syntax of your contract using another derived App-specific language.
Notice that in animation below -
The labels of the model can be used to visualize the state of the contract —also including a red/green coloring to indicate the ‘fireable-ness’ of the transition.
In conclusion
Pflow.xyz, with its internal PflowDSL, offers a novel and expressive approach to building Petri-net smart contracts. By enabling a declarative, functional, and data-centric construction of complex state machines, it enhances the clarity and maintainability of your Solidity code.
Learn more about how to make these models! Explore the solidity API: in the pflow.xyz docs. Or, view source code for the demo on sepolia-optimism testnet block explorer.