A crumb of cleanup.
This commit is contained in:
parent
11525e9531
commit
bd6b26331b
|
@ -59,9 +59,7 @@
|
||||||
(def compile (fn (words) (
|
(def compile (fn (words) (
|
||||||
(def name (second words))
|
(def name (second words))
|
||||||
(def code (get-code (rest (rest words))))
|
(def code (get-code (rest (rest words))))
|
||||||
(prnl (cat "name:" name " code: " code))
|
|
||||||
(h-insert dictionary name code)
|
(h-insert dictionary name code)
|
||||||
(prnl (h-get dictionary name))
|
|
||||||
)))
|
)))
|
||||||
|
|
||||||
(def not (fn (bool)
|
(def not (fn (bool)
|
||||||
|
@ -80,30 +78,30 @@
|
||||||
|
|
||||||
(def noterr (fn (e) (not (iserr e))))
|
(def noterr (fn (e) (not (iserr e))))
|
||||||
|
|
||||||
(def _fmap (fn (words) (
|
(def fmap (fn (words) (
|
||||||
;(prnl (cat "fmap: " word))
|
|
||||||
(def word (at 0 words))
|
(def word (at 0 words))
|
||||||
|
|
||||||
(if (iserr word) () (
|
(if (iserr word) () (
|
||||||
; Define a user function
|
; Define a user function
|
||||||
(if (= ":" word) (compile words) (
|
(if (= ":" word) (compile words) (
|
||||||
; Or read a user-defined function
|
; Or read a user-defined function
|
||||||
(if (noterr (h-get dictionary word)) (_fmap (h-get dictionary word)) (
|
(if (noterr (h-get dictionary word)) (fmap (h-get dictionary word)) (
|
||||||
; Or check the operations table
|
; Or check the operations table
|
||||||
(if (noterr (switch word operations)) () (
|
(if (noterr (switch word operations)) () (
|
||||||
; Or evaluate
|
; Or evaluate
|
||||||
(if (noterr (eval word)) (stkadd (eval word)) (
|
(def evaluated-word (eval word))
|
||||||
|
(if (noterr evaluated-word) (stkadd evaluated-word) (
|
||||||
; Or add as a string
|
; Or add as a string
|
||||||
(stkadd word)
|
(stkadd word)
|
||||||
))))))
|
))))))
|
||||||
(_fmap (rest words))
|
(fmap (rest words))
|
||||||
))
|
))
|
||||||
))
|
))
|
||||||
)))
|
)))
|
||||||
|
|
||||||
(def fmap (fn (text) (
|
(def feval (fn (text) (
|
||||||
(def words (get-words text))
|
(def words (get-words text))
|
||||||
(_fmap words)
|
(fmap words)
|
||||||
)))
|
)))
|
||||||
|
|
||||||
(def esc (ch 27))
|
(def esc (ch 27))
|
||||||
|
@ -113,7 +111,7 @@
|
||||||
; Override the normal REPL prompt
|
; Override the normal REPL prompt
|
||||||
(set prompt fprompt)
|
(set prompt fprompt)
|
||||||
(set preprocess (fn (text) (
|
(set preprocess (fn (text) (
|
||||||
(fmap text)
|
(feval text)
|
||||||
(prn nl)
|
(prn nl)
|
||||||
"" ; Have the underlying REPL do nothing
|
"" ; Have the underlying REPL do nothing
|
||||||
)))
|
)))
|
||||||
|
|
|
@ -46,7 +46,7 @@ void deleteTable(struct ObjectTable* table)
|
||||||
|
|
||||||
#ifndef HASHLESS_ENV
|
#ifndef HASHLESS_ENV
|
||||||
|
|
||||||
static size_t hash(const char* str, struct ObjectTable* table)
|
size_t hash(const char* str, unused const struct ObjectTable* table)
|
||||||
{
|
{
|
||||||
size_t hash = 5381;
|
size_t hash = 5381;
|
||||||
char c;
|
char c;
|
||||||
|
@ -125,6 +125,9 @@ static size_t hash(unused const char* str, struct ObjectTable* table)
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
/**
|
||||||
|
* \return The hash value of the given name
|
||||||
|
*/
|
||||||
size_t addStripped(struct ObjectTable* table, char* name, struct StrippedObject object)
|
size_t addStripped(struct ObjectTable* table, char* name, struct StrippedObject object)
|
||||||
{
|
{
|
||||||
extendTable(table);
|
extendTable(table);
|
||||||
|
@ -146,10 +149,6 @@ size_t addStripped(struct ObjectTable* table, char* name, struct StrippedObject
|
||||||
return initial;
|
return initial;
|
||||||
}
|
}
|
||||||
|
|
||||||
///
|
|
||||||
/// \param table
|
|
||||||
/// \param name Should be a new allocation
|
|
||||||
/// \param object Should already be cloned
|
|
||||||
size_t addToTable(struct ObjectTable* table, char* name, Object object)
|
size_t addToTable(struct ObjectTable* table, char* name, Object object)
|
||||||
{
|
{
|
||||||
return addStripped(table, name, (struct StrippedObject) {
|
return addStripped(table, name, (struct StrippedObject) {
|
||||||
|
|
14
src/hash.h
14
src/hash.h
|
@ -11,10 +11,20 @@ struct ObjectTable {
|
||||||
|
|
||||||
struct ObjectTable buildTable(size_t capacity);
|
struct ObjectTable buildTable(size_t capacity);
|
||||||
|
|
||||||
/// Returns the hash of the inserted object
|
/// Hash the given string
|
||||||
|
/// \param str The string to hash
|
||||||
|
/// \param table The table the hash should be generated for (currently ignored by the actual hashing implementation)
|
||||||
|
/// \return The hash value of the given string
|
||||||
|
size_t hash(const char* str, const struct ObjectTable* table);
|
||||||
|
|
||||||
|
/// \param table Where to insert the object
|
||||||
|
/// \param name Should be a new allocation
|
||||||
|
/// \param object Should already be cloned
|
||||||
|
/// \return The hash value of the name used to insert
|
||||||
size_t addToTable(struct ObjectTable* table, char* name, Object object);
|
size_t addToTable(struct ObjectTable* table, char* name, Object object);
|
||||||
|
|
||||||
struct StrippedObject* getWithHash(struct ObjectTable* table, size_t hash);
|
/// \todo
|
||||||
|
struct StrippedObject* getWithHash(struct ObjectTable* table, const char* name, size_t hash);
|
||||||
|
|
||||||
struct StrippedObject* getFromTable(struct ObjectTable* table, const char* name);
|
struct StrippedObject* getFromTable(struct ObjectTable* table, const char* name);
|
||||||
|
|
||||||
|
|
|
@ -776,8 +776,6 @@ inline Object symFromSlice(const char* string, int len)
|
||||||
return o;
|
return o;
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Creates a stringy object with room for a reference-count prefix and trailing null byte.
|
|
||||||
/// Thus, withLen(3, TYPE_STRING) will actually allocate a 5-byte "string".
|
|
||||||
inline Object withLen(size_t len, enum Type type)
|
inline Object withLen(size_t len, enum Type type)
|
||||||
{
|
{
|
||||||
Object o = newObject(type);
|
Object o = newObject(type);
|
||||||
|
|
|
@ -289,6 +289,8 @@ Object stringFromSlice(const char* string, int len);
|
||||||
|
|
||||||
Object symFromSlice(const char* string, int len);
|
Object symFromSlice(const char* string, int len);
|
||||||
|
|
||||||
|
/// Creates a stringy object with room for a reference-count prefix and trailing null byte.
|
||||||
|
/// Thus, withLen(3, TYPE_STRING) will actually allocate a 5-byte "string".
|
||||||
Object withLen(size_t len, enum Type type);
|
Object withLen(size_t len, enum Type type);
|
||||||
|
|
||||||
Object boolObject(int b);
|
Object boolObject(int b);
|
||||||
|
|
Loading…
Reference in New Issue