Serene Runtime 1.0.0-dev
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.

Variables

srn_metadata_t absurd_metadata = {nullptr, nullptr}
 We use this for testing. Defined once in core.c.
srn_value_t nil_v = {.type = VNil}
srn_value_t true_v = {.type = VTrue}
srn_value_t false_v = {.type = VFalse}

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 36 of file core.c.

36 {
37 PANIC_IF_NULL(ctx);
38
39 switch (tag) {
40 case VNil:
41 return &nil_v;
42 case VTrue:
43 return &true_v;
44 case VFalse:
45 return &false_v;
46 default:
47 break;
48 }
49
50 srn_value_t *v = ALLOC(ctx, srn_value_t);
51 v->type = tag;
52 v->metadata = metadata;
53
54 // At this point payload should not be null
55 PANIC_IF_NULL(payload);
56
57 switch (tag) {
58 case VI64:
59 v->as.i64 = *(int64_t *)payload;
60 break;
61 case VF64:
62 v->as.f64 = *(double *)payload;
63 break;
64 case VList:
65 v->as.list = (srn_list_t *)payload;
66 break;
67 case VSeq:
68 v->as.seq = (srn_seq_t *)payload;
69 break;
70 case VQuote:
71 PANIC("Not implemented");
72 case VClosure:
73 PANIC("Not implemented");
74 case VNamespace:
75 v->as.ns = (srn_namespace_t *)payload;
76 break;
77 case VString:
78 v->as.string = (srn_string_t *)payload;
79 break;
80 case VSymbol:
81 v->as.symbol = (srn_symbol_t *)payload;
82 break;
83 case VKeyword:
84 v->as.keyword = (srn_keyword_t *)payload;
85 break;
86 case VMap:
87 v->as.map = (srn_map_t *)payload;
88 break;
89 case VError:
90 v->as.error = (srn_error_t *)payload;
91 break;
92 default:
93 PANIC("Should never happen");
94 }
95 return v;
96}
#define ALLOC(ctx, T)
Definition context.h:84
srn_value_t false_v
Definition core.c:29
srn_value_t true_v
Definition core.c:28
srn_value_t nil_v
Definition core.c:27
@ 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
A runtime error, a tag classifying the failure and a human-readable message.
Definition errors.h:125
A keyword, just a name.
Definition keywords.h:29
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:66
#define PANIC(msg)
Definition utils.h:53
Here is the caller graph for this function:

Variable Documentation

◆ absurd_metadata

srn_metadata_t absurd_metadata = {nullptr, nullptr}

We use this for testing. Defined once in core.c.

Definition at line 26 of file core.c.

26{nullptr, nullptr};

◆ false_v

srn_value_t false_v = {.type = VFalse}

Definition at line 29 of file core.c.

29{.type = VFalse};

◆ nil_v

srn_value_t nil_v = {.type = VNil}

Definition at line 27 of file core.c.

27{.type = VNil};

◆ true_v

srn_value_t true_v = {.type = VTrue}

Definition at line 28 of file core.c.

28{.type = VTrue};