You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Introspection gives us the ability to inspect types, just like reflection but since it is done at compile time, it is completely type safe.
This is a proposal for a Gno add-on transpiler that would compile an extended version of Gno into regular Gno that the VM can execute.
Here is a small example of what we can do with introspection.
Formatting in Go is done by using runtime reflection to get the type information and the analysis on the actual format are done at runtime.
Zig, Dlang, Jai and C++ have similar features.
Conditional compilation
comptime blocks make restrictions that all expressions inside are required to operate on values known at compile time. verb comes from format in the actual code that is left out. This means that format must be a value that is known at compile time. What this code will end up doing is, it will run the switch at compile time and based on weather the verb is 'T' or 'p' that code will end up being compiled in the actual function. The code from the other cases will be discarded.
That gives the ability to be dynamic but generate concrete types that can be analysed by the VM and give us more type safety.
This is obviously not a full spec of the proposed feature.
One of the implementation details is that we need to do monomorphization of the functions that have compile time expressions. When the AST is analysed, for every type/value that the function is called with, we need to generate a different print function, as in the example.
The following invokations will result in having to generate 2 different print functions
Description
Introspection gives us the ability to inspect types, just like reflection but since it is done at compile time, it is completely type safe.
This is a proposal for a Gno add-on transpiler that would compile an extended version of Gno into regular Gno that the VM can execute.
Here is a small example of what we can do with introspection.
Formatting in Go is done by using runtime reflection to get the type information and the analysis on the actual format are done at runtime.
Zig, Dlang, Jai and C++ have similar features.
Conditional compilation
comptime
blocks make restrictions that all expressions inside are required to operate on values known at compile time.verb
comes fromformat
in the actual code that is left out. This means thatformat
must be a value that is known at compile time. What this code will end up doing is, it will run theswitch
at compile time and based on weather theverb
is'T'
or'p'
that code will end up being compiled in the actual function. The code from the other cases will be discarded.That gives the ability to be dynamic but generate concrete types that can be analysed by the VM and give us more type safety.
If
verb
isT
and the type isint
the actual code in the Gno file would be compiled asRunning code during compilation
The
@
symbol tells the compiler to run this function during compilation and produce the result.The code that will actually end up in your Gno file will be
The text was updated successfully, but these errors were encountered: