-
Notifications
You must be signed in to change notification settings - Fork 5
Compile
Top-level elements in Emfrp are simply compiled into C's elements as follows:

Note that Emfrp's functions and types are polymorphic but C's are monomorphic. The compiler converts an Emfrp's polymorphic function/type into C's multiple monomorphic functions/structs as it is instantiated.
In expression level, there are no big gaps between Emfrp and C. It is, however, desirable for a great performance to implement some additional optimizing processes on current(v0.1.2) Emfrp's compiler.
The FRP runtime-process is simple too.
In Emfrp, dependencies of time-varying values are expressed by a directed-asyclic-graph(DAG).
Nodes can be statically sorted by order of evaluation.
For example, in case of a directed-graph illustrated by following image,
nodes can be sorted as a -> c -> e -> b -> f -> d.

If nodes are sorted, all runtime-process should do is evaluate nodes in that order while using other evaluated values.
Instances of Emfrp's data-types' entities are not allocated on either stack-area or heap-area. They are allocated on static-area. This is possible because Emfrp doesn't allow recursive data-types and recursive function-calls. In other words, an arbitrary Emfrp's module has limits of allocations for all data-types.
Let's show that by an example:
module Example
in
inputA : Int,
inputB : Int
out
z
use
Std
func padd(p1, p2) = (p1.fst + p2.fst, p1.snd + p2.snd)
node x : (Int, Int) = (inputA, inputB)
node y : (Int, Int) = x `padd` (1, 1)
node z : (Int, Int) = y `padd` y
In case of the module, following facts are able to say:
- Node
xinstantiates oneTuple2(Int, Int)and none of other data-types. - Node
yinstantiates twoTuple2(Int, Int)and none of other data-types. - Node
zinstantiates oneTuple2(Int, Int)and none of other data-types.
And, following facts are able to say:
- When calculating node
x, none of data-types need to be held. - When calculating node
y, only the calculated value of nodexneeds to be held. - When calculating node
z, only the calculated value of nodeyneeds to be held.
From the above, it is able to say that only three (not four!) allocations of data-type Tuple2(Int, Int) is required to calculate whole the module.
In this way, an arbitrary Emfrp's module has limits of allocations for all data-types. Therefor, Emfrp compiler can statically allocate data-types' memory on static-area by its limits.