diff options
author | David Robillard <d@drobilla.net> | 2010-12-28 07:14:59 +0000 |
---|---|---|
committer | David Robillard <d@drobilla.net> | 2010-12-28 07:14:59 +0000 |
commit | 25e58056dc218afe0768081ef1c52974593773c0 (patch) | |
tree | f43ea899bcdf8602c0b95e80a81e9cb98e9a7b90 /src/constrain.cpp | |
parent | 867601738b4fc9a8536a34112f43f33e1541e7fd (diff) | |
download | resp-25e58056dc218afe0768081ef1c52974593773c0.tar.gz resp-25e58056dc218afe0768081ef1c52974593773c0.tar.bz2 resp-25e58056dc218afe0768081ef1c52974593773c0.zip |
Add quote form, to allow expressions literal symbols and lists (lists not yet implemented).
Quoting is a thin lexical concept - a quote of a symbol/list compiles to a symbol/list,
rather than interpreted as code (i.e. a variable/call, respectively). A quote of anything
else is equivalent to its quotee, e.g. a quote of a String is simply that string (the quote
is removed at an early stage by the compiler). There is no Quote data type, or explicit
unquoting, or anything like that.
git-svn-id: http://svn.drobilla.net/resp/resp@365 ad02d1e2-f140-0410-9f75-f8b11f17cedd
Diffstat (limited to 'src/constrain.cpp')
-rw-r--r-- | src/constrain.cpp | 13 |
1 files changed, 13 insertions, 0 deletions
diff --git a/src/constrain.cpp b/src/constrain.cpp index 4bd6c08..f65ad8f 100644 --- a/src/constrain.cpp +++ b/src/constrain.cpp @@ -260,6 +260,17 @@ constrain_match(TEnv& tenv, Constraints& c, const ATuple* call) throw(Error) } static void +constrain_quote(TEnv& tenv, Constraints& c, const ATuple* call) throw(Error) +{ + THROW_IF(call->list_len() != 2, call->loc, "`quote' requires exactly 1 argument"); + switch (call->list_ref(1)->tag()) { + case T_TUPLE: c.constrain(tenv, call, tenv.named("List")); return; + case T_SYMBOL: c.constrain(tenv, call, tenv.named("Symbol")); return; + default: return; + } +} + +static void constrain_call(TEnv& tenv, Constraints& c, const ATuple* call) throw(Error) { const AST* const head = call->head(); @@ -370,6 +381,8 @@ constrain_list(TEnv& tenv, Constraints& c, const ATuple* tup) throw(Error) constrain_let(tenv, c, tup); else if (form == "match") constrain_match(tenv, c, tup); + else if (form == "quote") + constrain_quote(tenv, c, tup); else constrain_call(tenv, c, tup); } |