C Interoperability
Tomo is intended to be used as a complete, standalone programming language, but it's also meant to be easy to integrate with existing C libraries. In order to make this possible, there are a few tools available.
Using C Libraries
In order to link against a compiled shared library, you can use use -lfoo to
cause Tomo to add -lfoo to the linker flags when compiling your final
executable. You can also use use <foo.h> or use ./foo.h to cause Tomo to
insert a corresponding #include when compiling your code.
You can also use ./foo.c or use ./foo.S to use C or assembly source files
from inside a Tomo source file.
Inline C Code
As a final escape hatch, you can use C_code to add code that will be put,
verbatim in the transpiled C code generated by Tomo. There are two forms: one
that creates an expression value and one that creates a block that is executed
without evaluating to anything:
# Inline C block:
C_code `
printf("This is just a block that is executed without a return value\n");
`
# Inline C expression (you must specify a type)
val := C_code : Int32 `int x = 1; x + 1`
Inline C expressions must specify a type and they can be compound statement
expressions. In
other words, if an inline C expression has a type, it will be enclosed
with ({ ...; }) so that you can put semicolon-terminated statements before
the final expression in their own scope if you want.
1 # C Interoperability3 Tomo is intended to be used as a complete, standalone programming language, but4 it's also meant to be easy to integrate with existing C libraries. In order to5 make this possible, there are a few tools available.7 ## Using C Libraries15 from inside a Tomo source file.17 ## Inline C Code20 verbatim in the transpiled C code generated by Tomo. There are two forms: one21 that creates an expression value and one that creates a block that is executed22 without evaluating to anything:25 # Inline C block:26 C_code `27 printf("This is just a block that is executed without a return value\n");28 `30 # Inline C expression (you must specify a type)31 val := C_code : Int32 `int x = 1; x + 1`32 ```34 Inline C expressions must specify a type and they can be [compound statement35 expressions](https://gcc.gnu.org/onlinedocs/gcc/Statement-Exprs.html). In36 other words, if an inline C expression has a type, it will be enclosed38 the final expression in their own scope if you want.