Skip to content

Engine Writing Conventions

Naming

  • File naming prefix: The engine's name is used as a prefix for all files related to the engine in use. For example, the Ticker Engine would have the following files, all prefixed with ticker:

    • ticker.juvix.md
    • ticker_messages.juvix.md
    • ticker_environment.juvix.md
    • ticker_behaviour.juvix.md

Warning

Juvix Markdownm files have always need to define the corresponding module at the first Juvix code block. See the Juvix Markdown and include Juvix code blocks's tutorial. For example if the file is ticker.juvix.md, it must have the following code block:

module arch.node.engines.ticker;

File structure within the engines directory

The files as listed above must be stored in the engines directory of the arch/node directory. For example, the ticker engine would have the following directory structure:

arch/node/
└── ...
└── engines/
    ├── ...
    ├── ticker.juvix.md
    ├── ticker_messages.juvix.md
    ├── ticker_environment.juvix.md
    └── ticker_behaviour.juvix.md

The ticker.juvix.md file then would contain a brief overview and list of all its components. Check out Ticker Engine as an example for the expected structure.

So next time, if you want to use the ticker engine, then you can import the arch.node.engines.ticker module, adding only one line at the top of the Juvix file where the imports are declared:

...
+ import arch.node.engines.ticker open;

Update indexes

As part of defining an engine type, you must update a few files that act as indexes.

Juvix Everything Index

Add import statements of all the modules related to the new engine to the docs/everything.juvix.md file. The new lines must be added in the "Engines" section. That is, if the engine is the ticker, we expect the following lines:

docs/everything.juvix.md
module everything;
...
{- Engines -}
+ import arch.node.engines.ticker;
+ import arch.node.engines.ticker_messages;
+ import arch.node.engines.ticker_environment;
+ import arch.node.engines.ticker_behaviour;

Anoma Message

All message types must be added to the arch/node/types/anoma_message.juvix.md file. Use the same pattern as the existing message types. For example, if the engine is the ticker, the new type constructor should be MsgTicker along with the corresponding type for the messages, that is, TickerMsg.

arch/node/types/anoma_message.juvix.md
...
module arch.ode.types.anoma_message;
+ import arch.node.engines.ticker_messages open using {TickerMsg};

type Msg :=
+  | MsgTicker TickerMsg

Anoma Environment Index

All environment types must be added to the arch/node/types/anoma_environment.juvix.md file. Similarly to the message types, the new type constructor should be EnvTicker along with the corresponding type for the environment, that is, TickerEnvironment. Do not forget to import the environment type in the Env type.

arch/node/types/anoma_environment.juvix.md
module arch.node.types.anoma_environment;
...
+ import arch.node.engines.ticker_environment open using {TickerEnvironment};
...
type Env :=
+  | EnvTicker TickerEnvironment
(Wiki) links on this page