I have an implementation of the "Little Scheme" educational programming language written in D, here".
It has many problems, but the one I want to solve first is the size of the "atoms" (units of data).
Atom
is a struct that has fields for every possible type of data that the language supports. This means that a bool Atom
unnecessarily takes up space in memory with fields for number, string, structure, etc.
Here is the definition:
enum F_Type{
CONS, // Cons pair
STRN, // String/Symbol
NMBR, // Number
EROR, // Error object
BOOL, // Boolean value
FUNC, // Function
}
struct Atom{
F_Type kind; // ---------------- What kind of atom this is
Atom* car; // ----------------- Left `Atom` Pointer
Atom* cdr; // ----------------- Right `Atom` Pointer
double num; // ----------------- Number value
string str; // ----------------- String value, D-string underlies
bool bul; // ----------------- Boolean value
F_Error err = F_Error.NOVALUE; // Error code
}
Question:
Where do I begin my consolidation of space within Atom
? Do I use unions or variants?