|
|
|
|
|
# Primitive functions
|
|
|
|
|
|
Primitive functions are the basic building blocks of the SaC language.
|
|
|
The idea is that the standard library should be built on top of these functions.
|
|
|
This way anyone can implement their own standard library or use the functions directly and popular symbols like + will not have their meaning set in stone.
|
|
|
|
|
|
But how do these primitive functions work?
|
|
|
|
|
|
I have not found a definitive list of primitive functions.
|
|
|
The best I could find is in the `sac2c` source code in the [`src/libsac2c/tree/prf_info.mac` file](https://gitlab.sac-home.org/sac-group/sac2c/-/blob/develop/src/libsac2c/tree/prf_info.mac).
|
|
|
|
|
|
Here the primitive functions are defined as a list of macros.
|
|
|
But these are not their actual names.
|
|
|
For instance the following definition:
|
|
|
|
|
|
```c
|
|
|
PRF (and_SxS, (PA_S, PA_S, PA_x), 2, AND, NTCCTprf_log_op_SxS, COand, COMPprfOp_SxS,
|
|
|
SCSprf_and_SxS, NULL, NULL, SAAdim_is_0, SAAshp_is_empty, NULL, 0, PPIgetPVSxS,
|
|
|
ICCnone, TEone, NULL, NULL),
|
|
|
```
|
|
|
|
|
|
It defines the `and` function.
|
|
|
Importantly the `SxS` part means that the function takes two arguments of type `S` which stands for scalar.
|
|
|
|
|
|
As such you also have an `and_SxV` function which takes a scalar and a vector and an `and_VxV` function which takes a vector and another vector.
|
|
|
|
|
|
If you actually want to use a primitive function however you have to write it like this: `_and_SxS_()`.
|
|
|
So note how you have to add the underscores to the start and end.
|
|
|
|
|
|
In the file I linked there is this useful comment which explains the different fields in the PRF macro.
|
|
|
|
|
|
---
|
|
|
|
|
|
In the end of compilation there are mostly just the primitive functions left.
|
|
|
These are turned into [intermediate code macros (icm)](./Intermediate-Code-Macros) in the `cg:cpl` traversal.
|
|
|
These icm are then expanded into the actual code by the c preprocessor. |