Add self-evaluating symbols that start with ":"
This commit is contained in:
parent
8515d45b1e
commit
c194a34efb
2 changed files with 21 additions and 0 deletions
|
@ -897,6 +897,23 @@ Result<Expression> Compiler::compile_symbol(Context& context,
|
|||
const Value& value) {
|
||||
Expression ex = TRY(Expression::create());
|
||||
|
||||
// Symbol may be self-evaluating (e.g. :foo), in which case we just use it as
|
||||
// its own value
|
||||
|
||||
if (value.is<Symbol>()) {
|
||||
Symbol& sym = *value.to<Symbol>();
|
||||
|
||||
if (sym.size() > 0 && TRY(sym[0]) == ':') {
|
||||
int64_t c = TRY(context.add_const(value));
|
||||
|
||||
uint64_t reg = context.alloc_reg();
|
||||
TRY(ex.add_opcode(Oc::Mov, {0, (int64_t)reg}, {1, (int64_t)c}));
|
||||
|
||||
ex.reg = reg;
|
||||
return std::move(ex);
|
||||
}
|
||||
}
|
||||
|
||||
auto maybe_reg = context.get_var(TRY(value.copy()));
|
||||
|
||||
if (!maybe_reg.has_error()) {
|
||||
|
|
|
@ -9,3 +9,7 @@
|
|||
|
||||
(assert (= (get {1 2 3 4} 3)
|
||||
4))
|
||||
|
||||
;; Accessing collections by symbol
|
||||
(assert (= (get {:foo 1 :bar 2} :bar)
|
||||
2))
|
||||
|
|
Loading…
Reference in a new issue