Skip to content

Implementing builtins

tybor edited this page Feb 15, 2013 · 1 revision

A built-in is a multipart beast. You need to know:

  • how to define the function
  • how to call the function

for each supported back-end (currently, C, maybe Java, and the interpreter).

Let's talk C only: in src/smarteiffel/generation/c

In SmartEiffel parlance, a function call is the "mapping" of the function. The class C_MAPPER takes care of that by either generating a function call or inlining the code. For some builtins, the "call" is replaced by some inline code. That's not the case for deep_twin.

For deep_twin, we need a "wrapper" (a helper function): see C_NATIVE_NEED_WRAPPER.visit_native_built_in Therefore, the mapping is the standard one (i.e. generation of a C function call to a C function that will also be generated).

The content of the wrapper itself is defined in C_LIVE_TYPE_COMPILER.visit_run_feature_8 which prepares the signature and calls cpp.native_function_mapper.compile(visited)

Clone this wiki locally