Skip to content
GitLab
  • Menu
Projects Groups Snippets
  • /
  • Help
    • Help
    • Support
    • Community forum
    • Submit feedback
    • Contribute to GitLab
  • Sign in / Register
  • sac2c sac2c
  • Project information
    • Project information
    • Activity
    • Labels
    • Members
  • Repository
    • Repository
    • Files
    • Commits
    • Branches
    • Tags
    • Contributors
    • Graph
    • Compare
  • Issues 400
    • Issues 400
    • List
    • Boards
    • Service Desk
    • Milestones
  • Merge requests 12
    • Merge requests 12
  • Deployments
    • Deployments
    • Releases
  • Wiki
    • Wiki
  • External wiki
    • External wiki
  • Activity
  • Graph
  • Create a new issue
  • Commits
  • Issue Boards
Collapse sidebar
  • sac-group
  • sac2csac2c
  • Wiki
  • Concepts
  • Primitive functions

Primitive functions · Changes

Page history
add tutorial about adding a compiler flag authored Apr 07, 2025 by Quinten Cabo's avatar Quinten Cabo
Hide whitespace changes
Inline Side-by-side
concepts/Primitive-functions.md 0 → 100644
View page @ b562eac3
# 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.
Clone repository
  • Styleguide
  • concepts
    • Deprecated Modules
    • Globals
    • Intermediate Code Macros
    • Named Tuples
    • Overloading
    • Preprocessor
    • Primitive functions
    • Runtime Representations
    • input stdin
    • phm xt
    • ref counting methods
    • type famlies
    • type patterns
  • error messages
    • Anthropomorphic error essages
View All Pages