Compile syntax expressions
This commit is contained in:
parent
1958cfb285
commit
b63b17ed5a
3 changed files with 34 additions and 0 deletions
|
@ -600,6 +600,23 @@ Result<Expression> Compiler::compile_quote(Context& context, Symbol& op,
|
|||
|
||||
return std::move(ex);
|
||||
}
|
||||
|
||||
Result<Expression> Compiler::compile_syntax(Context& context, Symbol& op,
|
||||
const Value& expr) {
|
||||
auto quoted = TRY(expr.second());
|
||||
|
||||
uint64_t maxreg = context.maxreg;
|
||||
Expression ex = TRY(Expression::create());
|
||||
|
||||
int64_t quoted_const = TRY(context.add_const(quoted));
|
||||
TRY(ex.add_opcode(Oc::Mov, {0, (int64_t)maxreg}, {1, (int64_t)quoted_const}));
|
||||
|
||||
ex.reg = maxreg;
|
||||
context.maxreg = maxreg + 1;
|
||||
|
||||
return std::move(ex);
|
||||
}
|
||||
|
||||
Result<Expression> Compiler::compile_fn(Context& context, Symbol& op,
|
||||
const Value& expr) {
|
||||
Context ctx = TRY(Context::create(context));
|
||||
|
@ -898,6 +915,8 @@ Result<Expression> Compiler::compile_list(Context& context, const Value& expr) {
|
|||
return compile_let(context, sym, expr);
|
||||
} else if (TRY(sym.cmp("quote")) == 0) {
|
||||
return compile_quote(context, sym, expr);
|
||||
} else if (TRY(sym.cmp("syntax")) == 0) {
|
||||
return compile_syntax(context, sym, expr);
|
||||
} else {
|
||||
return compile_function_call(context, expr);
|
||||
}
|
||||
|
|
|
@ -49,6 +49,8 @@ class Compiler {
|
|||
const Value& expr);
|
||||
Result<Expression> compile_quote(Context& context, Symbol& op,
|
||||
const Value& expr);
|
||||
Result<Expression> compile_syntax(Context& context, Symbol& op,
|
||||
const Value& expr);
|
||||
Result<Expression> compile_fn(Context& context, Symbol& op,
|
||||
const Value& expr);
|
||||
Result<Expression> compile_let(Context& context, Symbol& op,
|
||||
|
|
13
test/string.cpp
Normal file
13
test/string.cpp
Normal file
|
@ -0,0 +1,13 @@
|
|||
#include "common.hpp"
|
||||
#include "die.hpp"
|
||||
#include "reader.hpp"
|
||||
#include "test.hpp"
|
||||
#include "writer.hpp"
|
||||
|
||||
StaticArena<64 * 1024 * 1024> arena;
|
||||
|
||||
TEST_CASE(dict_insert) {
|
||||
auto t = DIEX(build_string("foo", "bar", Value(DIEX(Nil::create()))));
|
||||
|
||||
ASSERT_EQUALS(t, "foobarnil");
|
||||
}
|
Loading…
Reference in a new issue