Serene Runtime 1.0.0
C runtime for the Serene programming language
Loading...
Searching...
No Matches
abi.h File Reference
#include "serene/rt/core.h"
Include dependency graph for abi.h:
This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Typedefs

typedef srn_value_t *(* srn_cprim_fn_t) (srn_context_t *, srn_value_t *, uint32_t)
 Call a C-ABI primitive from Serene (argv shape is uniform):
 

Functions

srn_value_tsrn_apply_c (srn_context_t *ctx, srn_value_t *fn, srn_value_t *argv, uint32_t argc)
 Call Serene (lisp level) functions via C.
 
srn_value_tsrn_call_cprimitive (srn_context_t *ctx, srn_cprim_fn_t fn, srn_value_t *argv, uint32_t argc)
 
srn_value_tsrn_call0 (srn_context_t *ctx, srn_value_t *fun)
 
srn_value_tsrn_call1 (srn_context_t *ctx, srn_value_t *fun, srn_value_t *a0)
 
srn_value_tsrn_call2 (srn_context_t *ctx, srn_value_t *fun, srn_value_t *a0, srn_value_t *a1)
 

Typedef Documentation

◆ srn_cprim_fn_t

typedef srn_value_t *(* srn_cprim_fn_t) (srn_context_t *, srn_value_t *, uint32_t)

Call a C-ABI primitive from Serene (argv shape is uniform):

Definition at line 32 of file abi.h.

Function Documentation

◆ srn_apply_c()

srn_value_t * srn_apply_c ( srn_context_t * ctx,
srn_value_t * fn,
srn_value_t * argv,
uint32_t argc )

Call Serene (lisp level) functions via C.

Definition at line 26 of file abi.c.

26 {
27 if (IS_A(fn, VClosure)) {
28 PANIC_WITH_CTX(ctx, "apply: not a function");
29 }
30 srn_closure_t *cl = AS_CLOSURE(fn);
31 if (cl == nullptr) {
32 PANIC_WITH_CTX(ctx, "Not a closure value");
33 }
34 srn_fnptr_t fnptr = cl->fn;
35 // Internal fn type is (srn_context_t*, srn_value_t**, u32) -> srn_value_t*
36 // using fastcc in IR, but here it's just a plain function pointer; call
37 // through.
38 return fnptr(ctx, argv, argc);
39}
@ VClosure
Definition core.h:121
#define IS_A(value_ref, field)
Definition core.h:162
srn_value_t *(* srn_fnptr_t)(srn_context_t *ctx, srn_value_t *argv, uint32_t argc)
Definition core.h:46
#define AS_CLOSURE(value_ref)
Definition core.h:169
srn_fnptr_t fn
Entry point on the closure, duh!
Definition closures.h:29
#define PANIC_WITH_CTX(ctx, msg)
Definition utils.h:53
Here is the caller graph for this function:

◆ srn_call0()

srn_value_t * srn_call0 ( srn_context_t * ctx,
srn_value_t * fun )

Definition at line 46 of file abi.c.

46 {
47 return srn_apply_c(ctx, fun, nullptr, 0);
48}
srn_value_t * srn_apply_c(srn_context_t *ctx, srn_value_t *fn, srn_value_t *argv, uint32_t argc)
Call Serene (lisp level) functions via C.
Definition abi.c:26
Here is the call graph for this function:

◆ srn_call1()

srn_value_t * srn_call1 ( srn_context_t * ctx,
srn_value_t * fun,
srn_value_t * a0 )

Definition at line 49 of file abi.c.

49 {
50 srn_value_t *argv[1] = {a0};
51 return srn_apply_c(ctx, fun, (srn_value_t *)argv, 1);
52}
Here is the call graph for this function:

◆ srn_call2()

srn_value_t * srn_call2 ( srn_context_t * ctx,
srn_value_t * fun,
srn_value_t * a0,
srn_value_t * a1 )

Definition at line 53 of file abi.c.

53 {
54 srn_value_t *argv[2] = {a0, a1};
55 return srn_apply_c(ctx, fun, (srn_value_t *)argv, 2);
56}
Here is the call graph for this function:

◆ srn_call_cprimitive()

srn_value_t * srn_call_cprimitive ( srn_context_t * ctx,
srn_cprim_fn_t fn,
srn_value_t * argv,
uint32_t argc )

Definition at line 41 of file abi.c.

42 {
43 return f(ctx, argv, argc);
44}