Add a small Hello World program to be assembled
[zilutils.git] / zilc / element.c
1 /*
2  * element.c
3  *
4  * Copyright (C) 2015 Alexander Andrejevic <theflash AT sdf DOT lonestar DOT org>
5  *
6  * This program is free software: you can redistribute it and/or modify
7  * it under the terms of the GNU Affero General Public License as
8  * published by the Free Software Foundation, either version 3 of the
9  * License, or (at your option) any later version.
10  *
11  * This program is distributed in the hope that it will be useful,
12  * but WITHOUT ANY WARRANTY; without even the implied warranty of
13  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14  * GNU Affero General Public License for more details.
15  *
16  * You should have received a copy of the GNU Affero General Public License
17  * along with this program.  If not, see <http://www.gnu.org/licenses/>
18  *
19  * SPDX-License-Identifier: AGPL-3.0-or-later
20  */
21
22 #include <stdlib.h>
23 #include "element.h"
24
25 element_t *create_atom(const char *name, int global)
26 {
27     element_t *element = (element_t*)malloc(sizeof(element_t));
28     if (element == NULL) return NULL;
29
30     element->type = TYPE_ATOM;
31     element->atom.name = name;
32     element->atom.global = global;
33
34     return element;
35 }
36
37 element_t *create_string(const char *value)
38 {
39     element_t *element = (element_t*)malloc(sizeof(element_t));
40     if (element == NULL) return NULL;
41
42     element->type = TYPE_STRING;
43     element->string.value = value;
44
45     return element;
46 }
47
48 element_t *create_number(double value)
49 {
50     element_t *element = (element_t*)malloc(sizeof(element_t));
51     if (element == NULL) return NULL;
52
53     element->type = TYPE_NUMBER;
54     element->number.value = value;
55
56     return element;
57 }
58
59 element_t *create_tuple(list_t *list)
60 {
61     element_t *element = (element_t*)malloc(sizeof(element_t));
62     if (element == NULL) return NULL;
63
64     element->type = TYPE_TUPLE;
65     element->tuple.list = *list;
66
67     return element;
68 }
69
70 element_t *create_statement(const char *name, list_t *parameters)
71 {
72     element_t *element = (element_t*)malloc(sizeof(element_t));
73     if (element == NULL) return NULL;
74
75     element->type = TYPE_STATEMENT;
76     element->statement.name = name;
77     element->statement.parameters = *parameters;
78
79     return element;
80 }