~brenns10/funlisp

5e3a75197a4526208bfe8b4188e0014d1218a946 — Stephen Brennan 2 years ago c0ebfb4
Proper linking
2 files changed, 48 insertions(+), 49 deletions(-)

M Doxyfile
M inc/funlisp.h
M Doxyfile => Doxyfile +1 -1
@@ 408,7 408,7 @@ LOOKUP_CACHE_SIZE      = 0
# normally produced when WARNINGS is set to YES.
# The default value is: NO.

EXTRACT_ALL            = NO
EXTRACT_ALL            = YES

# If the EXTRACT_PRIVATE tag is set to YES all private members of a class will
# be included in the documentation.

M inc/funlisp.h => inc/funlisp.h +47 -48
@@ 36,7 36,7 @@ void lisp_runtime_free(lisp_runtime *rt);
/**
 * In funlisp, (almost) everything is a lisp_value. That is, it can be cast to
 * a ``lisp_value *`` and operated on. Integers, Strings, Code, etc. The only
 * thing which is not a lisp_value is the lisp_runtime.
 * thing which is not a lisp_value is the ::lisp_runtime.
 */
typedef struct lisp_value {
	struct lisp_type  *type; /* type object, USE ME TO TYPE CHECK */


@@ 61,7 61,7 @@ typedef struct lisp_type lisp_type;
typedef struct lisp_scope lisp_scope;

/**
 * Lisp is a list-processing language, and lisp_list is a building block for
 * Lisp is a list-processing language, and ::lisp_list is a building block for
 * lists. It is somewhat mis-named, because it actually represents a
 * s-expression, which is just a simple data structure that has two pointers:
 * left and right. Normal lists are a series of s-expressions, such that each


@@ 100,7 100,7 @@ typedef struct lisp_symbol lisp_symbol;
typedef struct lisp_error lisp_error;

/**
 * lisp_integer contains an int object of whatever size the C implementation
 * ::lisp_integer contains an int object of whatever size the C implementation
 * supports.
 */
typedef struct lisp_integer lisp_integer;


@@ 112,7 112,7 @@ typedef struct lisp_string lisp_string;

/**
 * This data structure contains a native C function which may be called by
 * funlisp code. The C function must be of type lisp_builtin_func.
 * funlisp code. The C function must be of type ::lisp_builtin_func.
 */
typedef struct lisp_builtin lisp_builtin;



@@ 122,47 122,47 @@ typedef struct lisp_builtin lisp_builtin;
typedef struct lisp_lambda lisp_lambda;

/**
 * Type object of lisp_type
 * Type object of ::lisp_type
 */
extern lisp_type *type_type;

/**
 * Type object of lisp_scope
 * Type object of ::lisp_scope
 */
extern lisp_type *type_scope;

/**
 * Type object of lisp_list
 * Type object of ::lisp_list
 */
extern lisp_type *type_list;

/**
 * Type object of lisp_symbol
 * Type object of ::lisp_symbol
 */
extern lisp_type *type_symbol;

/**
 * Type object of lisp_error
 * Type object of ::lisp_error
 */
extern lisp_type *type_error;

/**
 * Type object of lisp_integer
 * Type object of ::lisp_integer
 */
extern lisp_type *type_integer;

/**
 * Type object of lisp_string
 * Type object of ::lisp_string
 */
extern lisp_type *type_string;

/**
 * Type object of lisp_builtin
 * Type object of ::lisp_builtin
 */
extern lisp_type *type_builtin;

/**
 * Type object of lisp_lambda
 * Type object of ::lisp_lambda
 */
extern lisp_type *type_lambda;



@@ 176,20 176,19 @@ extern lisp_type *type_lambda;
void lisp_print(FILE *f, lisp_value *value);

/**
 * Evaluate the lisp_value in a given context. Since lisp values represent code
 * as well as data, this is more applicable to some data structures than others.
 * For example, evaluating a scope will not work. However, evaluating a symbol
 * will look it up in the current scope, and evaluating list ``l`` will attempt
 * to call ``(car l)`` with arguments ``(cdr l)``.
 * @param rt runtime associated with scope and value
 * @param scope the scope to use for evaluation (used when looking up symbols)
 * @param value the value (code generally) to evaluate
 * @return the result of evaluating value in scope
 * Evaluate the ::lisp_value in a given context. Since lisp values represent
 * code as well as data, this is more applicable to some data structures than
 * others.  For example, evaluating a scope will not work. However, evaluating a
 * symbol will look it up in the current scope, and evaluating list ``l`` will
 * attempt to call ``(car l)`` with arguments ``(cdr l)``.
 * @param rt runtime associated with scope and value @param scope the scope to
 * use for evaluation (used when looking up symbols) @param value the value
 * (code generally) to evaluate @return the result of evaluating value in scope
 */
lisp_value *lisp_eval(lisp_runtime *rt, lisp_scope *scope, lisp_value *value);

/**
 * Parse a *single* expression from a string, returning it as a lisp_value. If
 * Parse a *single* expression from a string, returning it as a ::lisp_value. If
 * there is no expression, return NULL
 * @param rt runtime to create language objects in
 * @param input string


@@ 200,11 199,11 @@ lisp_value *lisp_parse(lisp_runtime *rt, char *input);

/**
 * Call a callable object with a list of arguments. Many data types are not
 * callable, in which case a lisp_error is returned.
 * callable, in which case a ::lisp_error is returned.
 * @param rt runtime
 * @param scope scope in which we are being evaluated
 * @param callable value to call
 * @param arguments a lisp_list containing arguments (which *have not yet been
 * @param arguments a ::lisp_list containing arguments (which *have not yet been
 * evaluated*)
 */
lisp_value *lisp_call(lisp_runtime *rt, lisp_scope *scope, lisp_value *callable,


@@ 246,7 245,7 @@ lisp_scope *lisp_new_empty_scope(lisp_runtime *rt);
 * be called several times to mark many objects. Marking objects prevents the
 * garbage collector from freeing them. The garbage collector performs a breadth
 * first search starting from your marked objects to find all reachable language
 * objects. Thus, marking an object like a lisp_scope will save all symbols and
 * objects. Thus, marking an object like a ::lisp_scope will save all symbols and
 * language objects contained within it, from being freed. Normal use is to mark
 * and sweep each time you've evaluated something:
 *


@@ 281,12 280,12 @@ void lisp_sweep(lisp_runtime *rt);
 * @param n length of the array
 * @param can_free Does the interpreter take ownership of the memory pointed at
 * by the strings? If so, can_free should be non-zero. If not, it should be 0.
 * @return lisp_list containing lisp_string objects
 * @return ..lisp_list containing ..lisp_string objects
 */
lisp_value *lisp_list_of_strings(lisp_runtime *rt, char **list, size_t n, char can_free);

/**
 * Given a lisp_value, put it inside a list of size 0 and return it.
 * Given a ..lisp_value, put it inside a list of size 0 and return it.
 * @param rt runtime
 * @param entry item to put inside a list
 * @return a singleton list


@@ 295,7 294,7 @@ lisp_value *lisp_singleton_list(lisp_runtime *rt, lisp_value *entry);

/**
 * Lookup the symbol ``main`` in the scope, and run it if it exists. Calls the
 * function with a single argument, a lisp_list of program arguments. argc and
 * function with a single argument, a ..lisp_list of program arguments. argc and
 * argv should not include the main executable (just the script name and args).
 * @param rt runtime
 * @param scope scope to find main in


@@ 324,11 323,11 @@ void lisp_scope_bind(lisp_scope *scope, lisp_symbol *symbol, lisp_value *value);
/**
 * Look up a symbol within a scope. If it is not found in this scope, look
 * within the parent scope etc, until it is found. If it is not found at all,
 * return a lisp_error object.
 * return a ..lisp_error object.
 * @param rt runtime
 * @param scope scope to look in
 * @param symbol symbol to look up
 * @return value found, or a lisp_error when not found
 * @return value found, or a ..lisp_error when not found
 */
lisp_value *lisp_scope_lookup(lisp_runtime *rt, lisp_scope *scope,
                              lisp_symbol *symbol);


@@ 338,13 337,13 @@ lisp_value *lisp_scope_lookup(lisp_runtime *rt, lisp_scope *scope,
 * @param rt runtime
 * @param scope scope to look in
 * @param name string name to look up
 * @return value found, or a lisp_error when not found
 * @return value found, or a ..lisp_error when not found
 */
lisp_value *lisp_scope_lookup_string(lisp_runtime *rt, lisp_scope *scope, char *name);

/**
 * Shortcut to declare a builtin function. Simply takes a function pointer and a
 * string name, and it will internally create the lisp_builtin object with the
 * string name, and it will internally create the ..lisp_builtin object with the
 * correct name, and bind it in the given scope.
 * @param rt runtime
 * @param scope scope to bind builtin in


@@ 422,7 421,7 @@ lisp_value *lisp_quote(lisp_runtime *rt, lisp_value *value);
int lisp_list_length(lisp_list *list);

/**
 * Return true if the lisp_value is "nil" (an empty list).
 * Return true if the ..lisp_value is "nil" (an empty list).
 * @param l value to check
 * @retval 1 (true) if l is nil
 * @retval 0 (false) if l is non-nil


@@ 431,11 430,11 @@ int lisp_nil_p(lisp_value *l);

/**
 * Return a new, "un-owned" string. "Un-owned" means that ``str`` will not be
 * freed when the lisp_string is garbage collected. However, the lisp_string
 * freed when the ..lisp_string is garbage collected. However, the ..lisp_string
 * will still contain the exact reference to ``str``, not a copy. So, your
 * application **must not** free ``str`` until the lisp_string containing it is
 * application **must not** free ``str`` until the ..lisp_string containing it is
 * garbage collected. The safest approach here is if you are certain that your
 * string will not be freed until after the lisp_runtime is freed.
 * string will not be freed until after the ..lisp_runtime is freed.
 *
 * @code
 *     lisp_value *v = (lisp_string *) lisp_string_new_unowned(rt, "hello");


@@ 445,26 444,26 @@ int lisp_nil_p(lisp_value *l);
 * statically allocated.
 * @param rt runtime
 * @param str string which will not be freed by the garbage collector
 * @return lisp_string object pointing to your string
 * @return ..lisp_string object pointing to your string
 */
lisp_string *lisp_string_new_unowned(lisp_runtime *rt, char *str);

/**
 * Return a new string. This function takes a "safe" approach, by copying your
 * string and using the copy. The pointer will be owned by the interpreter and
 * freed when the lisp_string object is garbage collected. This is roughly
 * freed when the ..lisp_string object is garbage collected. This is roughly
 * equivalent to duplicating the string using strdup(), and then creating a new
 * owned string with that pointer.
 * @note This is also safe to use with string literals, but it is not the most
 * efficient way, since the string gets copied.
 * @param rt runtime
 * @param str string to copy and use in an owned string
 * @return a new lisp_string
 * @return a new ..lisp_string
 */
lisp_string *lisp_string_new(lisp_runtime *rt, char *str);

/**
 * Return a pointer to the string contained within a lisp_string. The
 * Return a pointer to the string contained within a ..lisp_string. The
 * application must **not** modify or free the string.
 * @param s the lisp string to access
 * @return the contained string


@@ 510,8 509,8 @@ char *lisp_error_get(lisp_error *e);
 * @param left item to go on the left side of the s-expression, usually a list
 * item
 * @param right item to go on the right side of the s-expression, usually the
 * next lisp_list instance
 * @return newly allocated lisp_list
 * next ..lisp_list instance
 * @return newly allocated ..lisp_list
 */
lisp_list *lisp_list_new(lisp_runtime *rt, lisp_value *left, lisp_value *right);



@@ 538,14 537,14 @@ lisp_value *lisp_list_get_right(lisp_list *l);
lisp_integer *lisp_integer_new(lisp_runtime *rt, int n);

/**
 * Retrieve the integer value from a lisp_integer.
 * @param integer lisp_integer to return from
 * Retrieve the integer value from a ..lisp_integer.
 * @param integer ..lisp_integer to return from
 * @return the int value
 */
int lisp_integer_get(lisp_integer *integer);

/**
 * Create a new lisp_builtin from a function pointer, with a given name.
 * Create a new ..lisp_builtin from a function pointer, with a given name.
 * @warning Builtin names are not garbage collected, since they are almost
 * always static. If you need your name to be dynamically allocated, you'll have
 * to free it after you free the runtime.


@@ 558,11 557,11 @@ lisp_builtin *lisp_builtin_new(lisp_runtime *rt, char *name,
                               lisp_builtin_func call);

/**
 * Return a nil instance. Nil is simply a "special" lisp_list, with left and
 * Return a nil instance. Nil is simply a "special" ..lisp_list, with left and
 * right both set to NULL. It is used to terminate lists. For example, the list
 * ``'(a b)`` is internally: ``lisp_list(a, lisp_list(b, lisp_list(NULL, NULL)))``
 * @note This function is named "new" for uniformity. However, it does't
 * actually allocate a "new" nil value every time. Instead, each lisp_runtime
 * actually allocate a "new" nil value every time. Instead, each ..lisp_runtime
 * has a singleton nil instance, which is never garbage collected.
 * @param rt runtime
 * @return the nil value