diff options
author | Keith Packard <keithp@keithp.com> | 2017-12-14 23:04:39 -0800 |
---|---|---|
committer | Keith Packard <keithp@keithp.com> | 2017-12-14 23:04:39 -0800 |
commit | 32f6877288ea6b7eb1cae9a42fbe8e2c5dbb2f08 (patch) | |
tree | 4e23989a62ae144b8cbf1d2fd135ca8a6bd743dc /src/scheme/ao_scheme_atom.c | |
parent | 2e11cae044cd2c053049effd76df9c5adecb84d7 (diff) |
altos/scheme: swap BIGINT and STRING types
This lets BIGINT be a primitive type, allowing it to use all 32 bits
for storage. This does make strings another byte longer, and also
slightly harder to deal with. It's a trade off.
Signed-off-by: Keith Packard <keithp@keithp.com>
Diffstat (limited to 'src/scheme/ao_scheme_atom.c')
-rw-r--r-- | src/scheme/ao_scheme_atom.c | 40 |
1 files changed, 34 insertions, 6 deletions
diff --git a/src/scheme/ao_scheme_atom.c b/src/scheme/ao_scheme_atom.c index cb32b7fe..745c32fe 100644 --- a/src/scheme/ao_scheme_atom.c +++ b/src/scheme/ao_scheme_atom.c @@ -71,8 +71,8 @@ const struct ao_scheme_type ao_scheme_atom_type = { struct ao_scheme_atom *ao_scheme_atoms; -struct ao_scheme_atom * -ao_scheme_atom_intern(char *name) +static struct ao_scheme_atom * +ao_scheme_atom_find(char *name) { struct ao_scheme_atom *atom; @@ -86,15 +86,43 @@ ao_scheme_atom_intern(char *name) return atom; } #endif - ao_scheme_string_stash(0, name); - atom = ao_scheme_alloc(name_size(name)); - name = ao_scheme_string_fetch(0); + return NULL; +} + +static void +ao_scheme_atom_init(struct ao_scheme_atom *atom, char *name) +{ if (atom) { atom->type = AO_SCHEME_ATOM; + strcpy(atom->name, name); atom->next = ao_scheme_atom_poly(ao_scheme_atoms); ao_scheme_atoms = atom; - strcpy(atom->name, name); } +} + +struct ao_scheme_atom * +ao_scheme_string_to_atom(struct ao_scheme_string *string) +{ + struct ao_scheme_atom *atom = ao_scheme_atom_find(string->val); + + if (atom) + return atom; + ao_scheme_string_stash(0, string); + atom = ao_scheme_alloc(name_size(string->val)); + string = ao_scheme_string_fetch(0); + ao_scheme_atom_init(atom, string->val); + return atom; +} + +struct ao_scheme_atom * +ao_scheme_atom_intern(char *name) +{ + struct ao_scheme_atom *atom = ao_scheme_atom_find(name); + if (atom) + return atom; + + atom = ao_scheme_alloc(name_size(name)); + ao_scheme_atom_init(atom, name); return atom; } |