Serene Runtime 1.0.0
C runtime for the Serene programming language
Loading...
Searching...
No Matches
core.c File Reference
#include "serene/rt/core.h"
#include "serene/rt/context.h"
#include "serene/utils.h"
Include dependency graph for core.c:

Go to the source code of this file.

Functions

srn_value_tsrn_value_make (srn_context_t *ctx, srn_value_tag_t tag, srn_metadata_t *metadata, void *payload)
 Creates a new serene value.
 

Function Documentation

◆ srn_value_make()

srn_value_t * srn_value_make ( srn_context_t * ctx,
srn_value_tag_t tag,
srn_metadata_t * metadata,
void * payload )
nodiscard

Creates a new serene value.

We always heap allocate the values. So, ANY value creation should go through this function

Definition at line 24 of file core.c.

25 {
26 PANIC_IF_NULL(ctx);
27
28 switch (tag) {
29 case VNil:
30 return &nil_v;
31 case VTrue:
32 return &true_v;
33 case VFalse:
34 return &false_v;
35 default:
36 break;
37 }
38
39 srn_value_t *v = ALLOC(ctx, srn_value_t);
40 v->type = tag;
41 v->metadata = metadata;
42
43 // At this point payload should not be null
44 PANIC_IF_NULL(payload);
45
46 switch (tag) {
47 case VI64:
48 v->as.i64 = *(int64_t *)payload;
49 break;
50 case VF64:
51 v->as.f64 = *(double *)payload;
52 break;
53 case VList:
54 v->as.list = (srn_list_t *)payload;
55 break;
56 case VSeq:
57 v->as.seq = (srn_seq_t *)payload;
58 break;
59 case VQuote:
60 PANIC("Not implemented");
61 case VClosure:
62 PANIC("Not implemented");
63 case VNamespace:
64 v->as.ns = (srn_namespace_t *)payload;
65 break;
66 case VString:
67 v->as.string = (srn_string_t *)payload;
68 break;
69 case VSymbol:
70 v->as.symbol = (srn_symbol_t *)payload;
71 break;
72 case VKeyword:
73 v->as.keyword = (srn_keyword_t *)payload;
74 break;
75 case VMap:
76 v->as.map = (srn_map_t *)payload;
77 break;
78 case VError:
79 v->as.error = (srn_error_t *)payload;
80 break;
81 default:
82 PANIC("Should never happen");
83 }
84 return v;
85}
#define ALLOC(ctx, T)
Definition context.h:82
static srn_value_t false_v
Definition core.h:158
@ VQuote
Definition core.h:120
@ VSeq
Definition core.h:119
@ VNamespace
Definition core.h:122
@ VClosure
Definition core.h:121
@ VNil
Definition core.h:113
@ VList
Definition core.h:118
@ VFalse
Definition core.h:115
@ VF64
Definition core.h:117
@ VSymbol
Definition core.h:124
@ VI64
Definition core.h:116
@ VMap
Definition core.h:126
@ VError
VError should be last.
Definition core.h:128
@ VKeyword
Definition core.h:125
@ VTrue
Definition core.h:114
@ VString
Definition core.h:123
static srn_value_t true_v
Definition core.h:157
static srn_value_t nil_v
Definition core.h:156
A keyword: just a name.
Definition keywords.h:29
Since all the values are immutable and persistent.
Definition lists.h:36
A persistent, immutable map.
Definition maps.h:29
A persistent, immutable, indexed sequence.
Definition seqs.h:27
srn_metadata_t * metadata
Definition core.h:133
srn_namespace_t * ns
Definition core.h:141
srn_list_t * list
Definition core.h:145
int64_t i64
We represent all the immidiate numbers with this field and cast as we to an appropriate type.
Definition core.h:138
double f64
Definition core.h:139
srn_seq_t * seq
Definition core.h:147
union srn_value_t::@033047061046230251001111174367071167226300135003 as
IMPORTANT NOTE: The size of this union should never be larger than a word.
srn_error_t * error
Definition core.h:144
srn_map_t * map
Definition core.h:148
srn_symbol_t * symbol
Definition core.h:143
srn_value_tag_t type
Definition core.h:132
srn_keyword_t * keyword
Definition core.h:146
srn_string_t * string
Definition core.h:142
#define PANIC_IF_NULL(ptr)
Definition utils.h:64
#define PANIC(msg)
Definition utils.h:51
Here is the caller graph for this function: