From: Mike D. Lowis Date: Sun, 24 Mar 2013 21:54:34 +0000 (-0400) Subject: commit new type constructors X-Git-Url: https://git.mdlowis.com/?a=commitdiff_plain;h=cc8744fe72f9dc89e418ec85125124bdb68c446b;p=proto%2Fsclpl.git commit new type constructors --- diff --git a/source/runtime/types/types.c b/source/runtime/types/types.c new file mode 100644 index 0000000..fa08d49 --- /dev/null +++ b/source/runtime/types/types.c @@ -0,0 +1,42 @@ +/** + @file types.c + @brief See header for details + $Revision$ + $HeadURL$ +*/ +#include "types.h" + +var_t new_num(double val) +{ + /* Allocate the space */ + num_t* number = (num_t*)gc_allocate( sizeof(num_t) ); + /* Populate header info */ + /* Populate data */ + number->data = val; + /* return the object */ + return (var_t)number; +} + +var_t new_cell(var_t first, var_t rest) +{ + /* Allocate the space */ + cell_t* cell = (cell_t*)gc_allocate( sizeof(cell_t) ); + /* Populate header info */ + /* Populate data */ + cell->first = first; + cell->rest = rest; + /* return the object */ + return (var_t)cell; +} + +var_t new_char(uint32_t val) +{ + /* Allocate the space */ + char_t* character = (char_t*)gc_allocate( sizeof(char_t) ); + /* Populate header info */ + /* Populate data */ + character->data = val; + /* return the object */ + return (var_t)character; +} + diff --git a/source/runtime/types/types.h b/source/runtime/types/types.h new file mode 100644 index 0000000..ba2b703 --- /dev/null +++ b/source/runtime/types/types.h @@ -0,0 +1,49 @@ +/** + @file types.h + @brief TODO: Describe this file + $Revision$ + $HeadURL$ +*/ +#ifndef TYPES_H +#define TYPES_H + +#include +#include + +typedef struct { + long info; +} header_t; + +typedef struct { + header_t header; + long data[1]; +} object_t; + +typedef const object_t* var_t; + +typedef struct { + header_t header; + double data; +} num_t; + +var_t new_num(double val); + +typedef struct { + header_t header; + var_t first; + var_t rest; +} cell_t; + +var_t new_cell(var_t first, var_t rest); + +typedef struct { + header_t header; + uint32_t data; +} char_t; + +var_t new_char(uint32_t val); + +//extern var_t True; +//extern var_t False; + +#endif /* TYPES_H */