~swisschili/bluejay

9d151e661aaf3cc697168ef6a439ab8ebd7c52b3 — swissChili 9 months ago 8a4b4ed
Add backquote/quasiquote (`).
3 files changed, 29 insertions(+), 11 deletions(-)

M doc/lisp_reference/lisp_reference.tex
M lib/lisp/std/std.lisp
M src/lisp/compiler.dasc
M doc/lisp_reference/lisp_reference.tex => doc/lisp_reference/lisp_reference.tex +1 -1
@@ 166,7 166,7 @@ The following text styles and symbols are used within this document to indicate 
\section{Function Manipulation}

\definition{
    (\mac{funcall} \param{function} \param{args}\more)\index{funcall} \\
    (\func{funcall} \param{function} \param{args}\more)\index{funcall} \\
    (\func{apply} \param{function} \param{args})\index{apply}
}{
    Call the \type{closure} or \type{function-object} \param{function} with \param{args} and evaluate to \ret{its result}. An error occurs if \param{args} are not acceptable.

M lib/lisp/std/std.lisp => lib/lisp/std/std.lisp +0 -2
@@ 19,8 19,6 @@

;; /Boring utilitites



(defun not (val)
  (nilp val))


M src/lisp/compiler.dasc => src/lisp/compiler.dasc +28 -8
@@ 370,9 370,34 @@ void compile_backquote(struct environment *env, struct local *local,
	else
	{
		value_t fsym = car(val), args = cdr(val);
		int nargs = length(args);
		int nargs = length(args),
			n = length(val);

		if (symstreq(fsym, "unquote"))
		{
			if (nargs != 1)
			{
				err_at(val, "unquote (or ,) takes exactly 1 argument");
			}

		// TODO
			compile_expression(env, local, car(args), false, Dst);
		}
		else
		{
			| push nil;

			for (int i = n - 1; i >= 0; i--)
			{
				compile_backquote(env, local, elt(val, i), Dst);
				| push eax;
				| call_extern cons;
				| add esp, 8;

				// Remove unnecessary pop
				| push eax;
			}
				| pop eax;
		}
	}
}



@@ 552,17 577,12 @@ void compile_expression(struct environment *env, struct local *local,
			{
				compile_expression(env, local, elt(args, i), false, Dst);

				// push the ith item
				| push eax;
				// cons the top two stack items
				| call_extern cons;
				// remove the stack items from use
				| add esp, (2 * value_size);
				// put the new thing on the stack
				| push eax;
			}

			| pop eax;
				| pop eax;
		}
		else if (symstreq(fsym, "lambda"))
		{