Invoking primitive operators in non-JS backends

I’m now using a non-JS backend, where Prelude is not available yet.

Things are a bit troublesome because it seems that I can only use function calls to achieve primitive operators now,

For instance, when I want to make a negative number, I have to implement negate, and it seems that I have to use a foreign function and cannot inline it:

I wonder if there’re any approches for inlining those primitive function calls.

In the current compiler this is done as part of backend code generation. The backend needs to match on a specific identifier and generate the inlined code instead (much like how GHC has the GHC.PrimOps namespace).

1 Like

Got it. So do we have a documentation page listing out the namespaces providing inline-able functions?

The namespaces are whatever the backend supports. The JS backend inlines stuff from Prelude.

I want to follow the existing JS conventions, because I want to use the existing codebase.

1 Like