07f7ffe239c007a49f81de864626b212bc55366b
[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
20 #include <stdlib.h>
21 #include "element.h"
22
23 element_t *create_atom(const char *name, int global)
24 {
25     element_t *element = (element_t*)malloc(sizeof(element_t));
26     if (element == NULL) return NULL;
27
28     element->type = TYPE_ATOM;
29     element->atom.name = name;
30     element->atom.global = global;
31
32     return element;
33 }
34
35 element_t *create_string(const char *value)
36 {
37     element_t *element = (element_t*)malloc(sizeof(element_t));
38     if (element == NULL) return NULL;
39
40     element->type = TYPE_STRING;
41     element->string.value = value;
42
43     return element;
44 }
45
46 element_t *create_number(double value)
47 {
48     element_t *element = (element_t*)malloc(sizeof(element_t));
49     if (element == NULL) return NULL;
50
51     element->type = TYPE_NUMBER;
52     element->number.value = value;
53
54     return element;
55 }
56
57 element_t *create_tuple(list_t *list)
58 {
59     element_t *element = (element_t*)malloc(sizeof(element_t));
60     if (element == NULL) return NULL;
61
62     element->type = TYPE_TUPLE;
63     element->tuple.list = *list;
64
65     return element;
66 }
67
68 element_t *create_statement(const char *name, list_t *parameters)
69 {
70     element_t *element = (element_t*)malloc(sizeof(element_t));
71     if (element == NULL) return NULL;
72
73     element->type = TYPE_STATEMENT;
74     element->statement.name = name;
75     element->statement.parameters = *parameters;
76
77     return element;
78 }