Skip to content

Instantly share code, notes, and snippets.

@gingerBill
Last active June 28, 2023 08:48
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save gingerBill/98fe5117a7ba94437a0e7132eb25007f to your computer and use it in GitHub Desktop.
Save gingerBill/98fe5117a7ba94437a0e7132eb25007f to your computer and use it in GitHub Desktop.
Compile Time Execution Problems (Metaprogramming)

Compile Time Execution Problems (Metaprogramming)

2016-11-02

Memory and Types

Compile time execution (CTE) is a stage of the compiler which runs any Odin code the user requests before the creation of the executable. The data modified and generated by this stage will be used as the initialization data for the compiled code.

The CTE stage is an interpreter running the generated single static assignment (SSA) tree for the requested code. When using the memory generated by the interpreter for the compiled code, there are a few problems. The main problem being: pointers will point to invalid memory addresses. This is becaused the memory space of the interpreter is completely different to the memory space of the executable (compiled code).

The table below presents which data types are safe for transferal and which are not.

Key:

  • Y - Yes
  • N - No
  • D - Dependent on elements
  • ? - Highly depends on a lot of factors (most likely no)
Type Safe?
boolean Y
integer Y
float Y
pointer N - Maybe safe if never changed
string Y - Even though (ptr+int) interally, still safe to convert to constant
any N - (ptr+ptr)
array D
vector Y - Elements can only be boolean, integer, or float (thus safe)
slice N - Internally (ptr+int+int)
maybe D
struct D
enum Y
union N - (blob+int)
raw_union N - (blob)
tuple D
proc ? - Need to solve the next problem

Calling procedures (external and internal)

If all the procedures are only from within the code itself, i.e. not a loaded pointer, then it is "safe". However, calling external procedures and passing procedures from the interpreter to external programs will cause problems as many of the procedures are not stored in real memory. This causes numerous problems.

TODO:

  • Look at how other languages solve this problem (e.g. Lua)
  • ???
  • Profit!
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment