Serene Runtime
1.0.0
C runtime for the Serene programming language
Loading...
Searching...
No Matches
lists.c
Go to the documentation of this file.
1
/* -*- C -*-
2
* Serene programming language
3
* Copyright (C) 2019-2026 Sameer Rahmani <
[email protected]
>
4
*
5
* This library is free software: you can redistribute it and/or modify
6
* it under the terms of the GNU Lesser General Public License as published by
7
* the Free Software Foundation, either version 3 of the License, or
8
* (at your option) any later version.
9
*
10
* This library is distributed in the hope that it will be useful,
11
* but WITHOUT ANY WARRANTY; without even the implied warranty of
12
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13
* GNU Lesser General Public License for more details.
14
*
15
* You should have received a copy of the GNU Lesser General Public License
16
* along with this library. If not, see <https://www.gnu.org/licenses/>.
17
*/
18
19
#include "
serene/rt/core/lists.h
"
20
21
#include "
serene/rt/context.h
"
22
23
srn_value_t
srn_make_pair
(
srn_context_t
*ctx,
srn_value_t
left,
srn_value_t
right) {
24
srn_pair_t
*p =
ALLOC
(ctx,
srn_pair_t
);
25
p->
left
= left;
26
p->
right
= right;
27
28
return
(
srn_value_t
)p | TAG_LIST;
29
}
30
31
srn_value_t
srn_make_list
(
srn_context_t
*ctx) {
32
srn_list_t
*l =
ALLOC
(ctx,
srn_list_t
);
33
l->
head
=
nullptr
;
34
l->
length
= 0;
35
}
36
37
/// Add the given value `v` to the front of the list and returns the new list.
38
[[gnu::nonnull(1)]]
srn_value_t
srn_conj_list
(
srn_context_t
*ctx,
srn_list_t
*head,
srn_value_t
v);
context.h
ALLOC
#define ALLOC(ctx, T)
Definition
context.h:82
srn_make_list
srn_value_t srn_make_list(srn_context_t *ctx)
Create a new list and empty list.
Definition
lists.c:31
srn_make_pair
srn_value_t srn_make_pair(srn_context_t *ctx, srn_value_t left, srn_value_t right)
Definition
lists.c:23
srn_conj_list
srn_value_t srn_conj_list(srn_context_t *ctx, srn_list_t *head, srn_value_t v)
Add the given value v to the front of the list and returns the new list.
lists.h
srn_context_t
Definition
context.h:47
srn_list_t
Since all the values are immutable and persistent.
Definition
lists.h:36
srn_list_t::head
srn_pair_t * head
Definition
lists.h:38
srn_list_t::length
size_t length
Definition
lists.h:39
srn_pair_t
Definition
lists.h:28
srn_pair_t::right
srn_value_t right
Definition
lists.h:31
srn_pair_t::left
srn_value_t left
Definition
lists.h:30
srn_value_t
Definition
core.h:131
rt
core
lists.c
Serene Runtime is free software, licensed under the
GNU LGPL v3
License.