element.c 2.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081
  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. #include <stdlib.h>
  22. #include "element.h"
  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. element->type = TYPE_ATOM;
  28. element->atom.name = name;
  29. element->atom.global = global;
  30. return element;
  31. }
  32. element_t *create_string(const char *value)
  33. {
  34. element_t *element = (element_t*)malloc(sizeof(element_t));
  35. if (element == NULL) return NULL;
  36. element->type = TYPE_STRING;
  37. element->string.value = value;
  38. return element;
  39. }
  40. element_t *create_number(double value)
  41. {
  42. element_t *element = (element_t*)malloc(sizeof(element_t));
  43. if (element == NULL) return NULL;
  44. element->type = TYPE_NUMBER;
  45. element->number.value = value;
  46. return element;
  47. }
  48. element_t *create_tuple(list_t *list)
  49. {
  50. element_t *element = (element_t*)malloc(sizeof(element_t));
  51. if (element == NULL) return NULL;
  52. element->type = TYPE_TUPLE;
  53. element->tuple.list = *list;
  54. return element;
  55. }
  56. element_t *create_statement(const char *name, list_t *parameters)
  57. {
  58. element_t *element = (element_t*)malloc(sizeof(element_t));
  59. if (element == NULL) return NULL;
  60. element->type = TYPE_STATEMENT;
  61. element->statement.name = name;
  62. element->statement.parameters = *parameters;
  63. return element;
  64. }