The Midio Engine
Last updated
Was this helpful?
Last updated
Was this helpful?
Midio compiled to bytecode, meaning that before the node graph is executed, it is compiled to a list of instructions, which is then executed by the [Midio VM](#The Midio VM). This makes the code run a lot faster than it would if we had to interpret the node graph during execution.
The Midio engine is a virtual machine that executes the bytecode produced by the compiler. It is responsible for hooking up all the native functionality that the code depends on, like all external functions, and services.
The bytecode is executed in Midio processes, of which several can run concurrently, executing different flows.
A process represents an isolated environment for bytecode to be executed in. It contains its own call stack, and its own memory heap, and is not able to affect other processes directly.
Processes are created by supplying it a module to run. It can then be handed to the scheduler, which will eventually schedule it for execution.
A process can be in one of the following states:
Runnable - The process is ready to be scheduled by the scheduler
DoneAndWaitingForCleanup - The process is done executing, and is waiting for the engine to clean up its resources, like heap and stack.
Error - The process has experienced an error, and is waiting for cleanup.
Paused - The process is paused for debugging purposes
Stepping - The process is in debugger state, and the middle of performing a single. The difference from being Runnable is that the process will enter the Paused state as soon as it hits an instruction corresponding to a node, like a CallFunction
instruction.
Services are not something the user directly interfaces with, but are accessed through various functions in the .
Services are components that provide various capabilities to your programs, such as offering an HTTP server, scheduling flows at specific intervals, and more. These services are shared between processes and are instantiated automatically when a node that requires the service is used. This process is entirely transparent to the user, and the way you interact with services is through funtions whose implementation happen to use them.
Currently, you cannot create your own service, but this will eventually be possible.
Some existing services include:
HttpServer: Enables the creation of HTTP APIs. Some functions that use this service include HttpEndpoint
and HttpResponse
.
Scheduler: Allows scheduling of flows to run at specific intervals. The Timer
event uses this sevices.
Testing: Offers a way for tests to report their results. Some nodes using this service includes the Test
event and the various assertion functions, like: AssertEqual
, AssertTrue
and AssertFalse
.
Ephemeral Store: Provides an in-memory key-value store (non-persistent) for storing data between various flow executions. This service is accessed through the functions in the EphemeralStore
module.
Midio programs are stored using a textual representation, which maps almost one to one with the visual representation.
Midio is a declarative programming language with a textual representation, designed for node-based programming. Its primary features include the ability to define modules, functions, events, and properties, as well as supporting native implementation through external functions. This section provides an overview of the syntax used in Midio.
!!! note The midio textual representation is not designed to be written by hand, but is means to at least be understandable by a human. The syntax is easy enough to understand, but it is hard to get a sense of what a program is doing by only looking at the textual representation.
Modules in Midio are containers for functions and other elements. The hidden attribute determines whether the module should be visible in the editor or not.
Functions in Midio can be either user-defined or external (native) functions.
User-defined functions:
External functions:
External functions have a native implementation in Rust and cannot have a body.
Inputs, and outputs are defined within functions using the in, out, and event keywords:
Parameters provide compile-time information to nodes, while attributes are optional values that can be used to configure modules, functions, events, inputs, or outputs:
Attributes are enclosed in parentheses, following the element they belong to:
Properties in Midio are used to store values and are declared with a type:
Identifiers in Midio follow conventional rules from languages like JavaScript, C, or Rust, which include:
Starting with a letter, underscore
Continuing with any combination of letters, digits, underscores, or dollar signs
In the body of user-defined functions, instances of other functions and arrows are used to connect them:
This is a general overview of the syntax used in Midio. The language is designed to support a node-based programming paradigm, allowing for a flexible and visual approach to developing software.