Skip to content

Commit 8b03dd2

Browse files
authored
Merge pull request #1503 from clasp-developers/print-quasiquote
Improve printing of quasiquote
2 parents 0652710 + c02ae16 commit 8b03dd2

File tree

16 files changed

+189
-134
lines changed

16 files changed

+189
-134
lines changed

RELEASE_NOTES.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,9 @@
1010
* Support for Linux AARCH64.
1111
* LLVM17 support. LLVM15 and LLVM16 are still supported.
1212

13+
## Changed
14+
* Improved printing of backquote and unquote.
15+
1316
## Fixed
1417
* Avoid segmentation faults from incorrectly calling MP:PROCESS-JOIN in
1518
EXT:RUN-PROGRAM.

include/clasp/core/cons.h

Lines changed: 15 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -91,7 +91,7 @@ T_sp oEighth(T_sp o);
9191
T_sp oNinth(T_sp o);
9292
T_sp oTenth(T_sp o);
9393

94-
#define CONS_CAR(x) (gctools::reinterpret_cast_smart_ptr<::core::Cons_O>(x)->ocar())
94+
#define CONS_CAR(x) (gctools::reinterpret_cast_smart_ptr<::core::Cons_O>(x)->car())
9595
#define CONS_CDR(x) (gctools::reinterpret_cast_smart_ptr<::core::Cons_O>(x)->cdr())
9696
#define CAR(x) oCar(x)
9797
#define CDR(x) oCdr(x)
@@ -121,7 +121,7 @@ namespace core {
121121
friend T_sp oCdr(T_sp o);
122122
#ifdef USE_PRECISE_GC
123123
public: // Garbage collector functions
124-
uintptr_t rawRefCar() const { return (uintptr_t)this->ocar().raw_(); }
124+
uintptr_t rawRefCar() const { return (uintptr_t)this->car().raw_(); }
125125
uintptr_t rawRefCdr() const { return (uintptr_t)this->cdr().raw_(); }
126126
void rawRefSetCar(uintptr_t val) { T_sp tval((gctools::Tagged)val); this->setCarNoValidate(tval); }
127127
void rawRefSetCdr(uintptr_t val) { T_sp tval((gctools::Tagged)val); this->setCdrNoValidate(tval); }
@@ -182,7 +182,7 @@ namespace core {
182182
}
183183

184184
public: // basic access
185-
inline T_sp ocar() const { return _Car.load(std::memory_order_relaxed); }
185+
inline T_sp car() const { return _Car.load(std::memory_order_relaxed); }
186186
inline T_sp cdr() const { return _Cdr.load(std::memory_order_relaxed); }
187187
inline void setCarNoValidate(T_sp o) {
188188
_Car.store(o, std::memory_order_relaxed);
@@ -245,14 +245,14 @@ namespace core {
245245
T_sp cdr = this->cdr();
246246
if (UNLIKELY(!cdr.consp()))
247247
return nil<T_O>();
248-
return cdr.unsafe_cons()->ocar();
248+
return cdr.unsafe_cons()->car();
249249
}
250250

251251
/*! Get the data for the first element */
252252
template <class o_class>
253253
gctools::smart_ptr<o_class> car() {
254-
ASSERTNOTNULL(this->ocar());
255-
return gc::As<gc::smart_ptr<o_class>>(this->ocar());
254+
ASSERTNOTNULL(this->car());
255+
return gc::As<gc::smart_ptr<o_class>>(this->car());
256256
};
257257
T_sp setf_nth(cl_index index, T_sp val);
258258
/*! Return the last cons (not the last element) of list.
@@ -266,7 +266,7 @@ namespace core {
266266
/*! Recursively hash the car and cdr parts - until the HashGenerator fills up */
267267
inline void sxhash_(HashGenerator &hg) const {
268268
if (hg.isFilling())
269-
hg.hashObject(this->ocar());
269+
hg.hashObject(this->car());
270270
if (hg.isFilling())
271271
hg.hashObject(this->cdr());
272272
}
@@ -325,6 +325,7 @@ namespace core {
325325
void describe(T_sp stream);
326326
string __repr__() const;
327327
void __write__(T_sp stream) const;
328+
bool maybe_write_quoted_form(bool tail, T_sp stream) const;
328329

329330
/*!Set the owner of every car in the list
330331
*/
@@ -350,10 +351,10 @@ namespace core {
350351
// These are necessary because atomics are not copyable.
351352
// More specifically they are necessary if you want to store conses in vectors,
352353
// which the hash table code does.
353-
Cons_O(const Cons_O& other) : _Car(other.ocar()), _Cdr(other.cdr()) {};
354+
Cons_O(const Cons_O& other) : _Car(other.car()), _Cdr(other.cdr()) {};
354355
Cons_O& operator=(const Cons_O& other) {
355356
if (this != &other) {
356-
setCar(other.ocar());
357+
setCar(other.car());
357358
setCdr(other.cdr());
358359
}
359360
return *this;
@@ -385,7 +386,7 @@ CL_DOCSTRING("Return the first object in a list.")
385386
DOCGROUP(clasp)
386387
CL_DEFUN inline core::T_sp oCar(T_sp obj) {
387388
if (obj.consp())
388-
return obj.unsafe_cons()->ocar();
389+
return obj.unsafe_cons()->car();
389390
if (obj.nilp())
390391
return obj;
391392
TYPE_ERROR(obj, cl::_sym_Cons_O);
@@ -638,15 +639,15 @@ CL_DOCSTRING("Return the tenth object in a list.")
638639
DOCGROUP(clasp)
639640
CL_DEFUN inline T_sp oTenth(T_sp o) { return oCar(oCdr(oCdr(oCdr(oCdr(oCdr(oCdr(oCdr(oCdr(oCdr(o)))))))))); }
640641

641-
inline T_sp cons_car(T_sp x) {ASSERT(x.consp());return gctools::reinterpret_cast_smart_ptr<Cons_O>(x)->ocar();};
642+
inline T_sp cons_car(T_sp x) {ASSERT(x.consp());return gctools::reinterpret_cast_smart_ptr<Cons_O>(x)->car();};
642643

643644
inline T_sp cons_cdr(T_sp x) {ASSERT(x.consp());return gctools::reinterpret_cast_smart_ptr<Cons_O>(x)->cdr();};
644645

645-
inline T_sp cons_car(Cons_sp x) {ASSERT(x.consp());return x->ocar();};
646+
inline T_sp cons_car(Cons_sp x) {ASSERT(x.consp());return x->car();};
646647

647648
inline T_sp cons_cdr(Cons_sp x) {ASSERT(x.consp());return x->cdr();};
648649

649-
inline T_sp cons_car(Cons_O* x) {return x->ocar();};
650+
inline T_sp cons_car(Cons_O* x) {return x->car();};
650651

651652
inline T_sp cons_cdr(Cons_O* x) {return x->cdr();};
652653

@@ -709,7 +710,7 @@ template <class T>
709710
void fillVec0(core::List_sp c, gctools::Vec0<T> &vec) {
710711
vec.clear();
711712
for (auto me : (List_sp)(c)) {
712-
vec.emplace_back(gc::As<T>(me->ocar()));
713+
vec.emplace_back(gc::As<T>(me->car()));
713714
}
714715
}
715716

src/core/bytecode.cc

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -370,7 +370,7 @@ gctools::return_type bytecode_vm(VirtualMachine& vm,
370370
case vm_cell_ref: {
371371
DBG_VM1("cell-ref\n");
372372
T_sp cons((gctools::Tagged)vm.pop(sp));
373-
vm.push(sp, cons.unsafe_cons()->ocar().raw_());
373+
vm.push(sp, cons.unsafe_cons()->car().raw_());
374374
pc++;
375375
break;
376376
}
@@ -1487,10 +1487,10 @@ List_sp bytecode_bindings_for_pc(BytecodeModule_sp module, void* pc, T_O** fp) {
14871487
size_t end = entry->end().unsafe_fixnum();
14881488
if ((start <= bpc) && (bpc < end)) {
14891489
for (Cons_sp cur : entry->bindings()) {
1490-
T_sp tinfo = cur->ocar();
1490+
T_sp tinfo = cur->car();
14911491
if (gc::IsA<Cons_sp>(tinfo)) {
14921492
Cons_sp info = gc::As_unsafe<Cons_sp>(tinfo);
1493-
T_sp name = info->ocar();
1493+
T_sp name = info->car();
14941494
T_sp cdr = info->cdr();
14951495
if (cdr.fixnump()) {
14961496
gc::Fixnum index = cdr.unsafe_fixnum();
@@ -1500,11 +1500,11 @@ List_sp bytecode_bindings_for_pc(BytecodeModule_sp module, void* pc, T_O** fp) {
15001500
bindings << Cons_O::create(name, value);
15011501
} else if (gc::IsA<Cons_sp>(cdr)) {
15021502
// indirect cell
1503-
T_sp tindex = gc::As_unsafe<Cons_sp>(cdr)->ocar();
1503+
T_sp tindex = gc::As_unsafe<Cons_sp>(cdr)->car();
15041504
if (tindex.fixnump()) {
15051505
gc::Fixnum index = tindex.unsafe_fixnum();
15061506
T_sp cell((gctools::Tagged)(*(fp+index+1)));
1507-
T_sp value = gc::As<Cons_sp>(cell)->ocar();
1507+
T_sp value = gc::As<Cons_sp>(cell)->car();
15081508
bindings << Cons_O::create(name, value);
15091509
}
15101510
}

src/core/bytecode_compiler.cc

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -968,7 +968,7 @@ static void resolve_debug_vars(BytecodeDebugVars_sp info) {
968968
else
969969
info->setEnd(clasp_make_fixnum(0));
970970
for (Cons_sp cur : info->bindings()) {
971-
T_sp tentry = cur->ocar();
971+
T_sp tentry = cur->car();
972972
if (gc::IsA<Cons_sp>(tentry)) {
973973
Cons_sp entry = gc::As_unsafe<Cons_sp>(tentry);
974974
T_sp tlvinfo = entry->cdr();

src/core/compiler.cc

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1570,7 +1570,7 @@ void ltvc_fill_list_varargs(gctools::GCRootsInModule *roots, T_O *list, size_t l
15701570
for (; len != 0; --len) {
15711571
Cons_sp cur_cons = gc::As<Cons_sp>(cur);
15721572
Cons_sp cur_vargs = gc::As<Cons_sp>(vargs);
1573-
cur_cons->rplaca(cur_vargs->ocar());
1573+
cur_cons->rplaca(cur_vargs->car());
15741574
cur = cur_cons->cdr();
15751575
vargs = cur_vargs->cdr();
15761576
}

src/core/cons.cc

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -416,7 +416,7 @@ bool Cons_O::equal(T_sp obj) const {
416416
if (!obj.consp()) return false;
417417
if (this == obj.unsafe_cons()) return true;
418418
List_sp other = obj;
419-
if (!cl__equal(this->ocar(), CONS_CAR(other))) return false;
419+
if (!cl__equal(this->car(), CONS_CAR(other))) return false;
420420
T_sp this_cdr = this->cdr();
421421
T_sp other_cdr = cons_cdr(other);
422422
return cl__equal(this_cdr, other_cdr);
@@ -426,7 +426,7 @@ bool Cons_O::equalp(T_sp obj) const {
426426
if (!obj.consp()) return false;
427427
if (this == obj.unsafe_cons()) return true;
428428
List_sp other = obj;
429-
if (!cl__equalp(this->ocar(), oCar(other)))
429+
if (!cl__equalp(this->car(), oCar(other)))
430430
return false;
431431
T_sp this_cdr = this->cdr();
432432
T_sp other_cdr = oCdr(other);
@@ -647,7 +647,7 @@ List_sp Cons_O::copyTree() const {
647647

648648
List_sp Cons_O::copyTreeCar() const {
649649

650-
T_sp obj = this->ocar();
650+
T_sp obj = this->car();
651651
ASSERTNOTNULL(obj);
652652
Cons_sp rootCopy = Cons_O::create(nil<T_O>(), nil<T_O>());
653653
List_sp cobj;
@@ -691,13 +691,13 @@ void Cons_O::describe(T_sp stream)
691691

692692
string Cons_O::__repr__() const {
693693
Cons_sp start = this->asSmartPtr();
694-
T_sp car = start->ocar();
694+
T_sp car = start->car();
695695
T_sp cdr = start->cdr();
696696
stringstream sout;
697697
sout << "(" << _safe_rep_(car);
698698
while (cdr.consp()) {
699699
Cons_sp p = gc::As<Cons_sp>(cdr);
700-
car = p->ocar();
700+
car = p->car();
701701
sout << " " << _safe_rep_(car);
702702
cdr = oCdr(p);
703703
}

src/core/corePackage.cc

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -503,6 +503,7 @@ SYMBOL_EXPORT_SC_(ClPkg, hash_table_p);
503503
SYMBOL_EXPORT_SC_(CorePkg, STARenablePrintPrettySTAR);
504504
SYMBOL_EXPORT_SC_(CorePkg, STARcircle_counterSTAR);
505505
SYMBOL_EXPORT_SC_(CorePkg, STARcircle_stackSTAR);
506+
SYMBOL_EXPORT_SC_(CorePkg, STARquasiquoteSTAR);
506507
SYMBOL_EXPORT_SC_(CorePkg, dynamicGo);
507508
SYMBOL_EXPORT_SC_(CorePkg, localGo);
508509
SYMBOL_EXPORT_SC_(ClPkg, _DIVIDE_);
@@ -846,7 +847,7 @@ void testConses() {
846847
fastTimer.start();
847848
for (int i = 0; i < times; ++i) {
848849
for (auto c : l.full()) {
849-
T_sp t = c->ocar();
850+
T_sp t = c->car();
850851
fastCount += unbox_fixnum(gc::As<Fixnum_sp>(t));
851852
}
852853
}
@@ -859,7 +860,7 @@ void testConses() {
859860
normalTimer.start();
860861
for (int i = 0; i < times; ++i) {
861862
for (auto c : l) {
862-
T_sp t = c->ocar();
863+
T_sp t = c->car();
863864
normalCount += unbox_fixnum(gc::As<Fixnum_sp>(t));
864865
}
865866
}
@@ -1064,6 +1065,10 @@ void CoreExposer_O::define_essential_globals(LispPtr lisp) {
10641065
_sym_STARprintPackageSTAR->defparameter(nil<T_O>());
10651066
_sym_STARcircle_counterSTAR->defparameter(nil<T_O>());
10661067
_sym_STARcircle_stackSTAR->defparameter(nil<T_O>());
1068+
// *quasiquote* is currently a dynamically bound plist of stream to nil/t values. It indicates whether or not the current stream
1069+
// in inside a quasiquote during printing. This is used so that unquote forms print correctly inside of a quasiquote but print as
1070+
// normal forms outside of a quasiquote.
1071+
_sym_STARquasiquoteSTAR->defparameter(nil<T_O>());
10671072
_sym_STARdebugReaderSTAR->defparameter(nil<T_O>());
10681073
_sym__PLUS_known_typep_predicates_PLUS_->defparameter(nil<T_O>());
10691074
cl::_sym_STARloadPathnameSTAR->defparameter(nil<T_O>());

src/core/mpPackage.cc

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -157,7 +157,7 @@ struct SafeRegisterDeregisterProcessWithLisp {
157157
void do_start_thread_inner(Process_sp process, core::List_sp bindings) {
158158
if (bindings.consp()) {
159159
core::Cons_sp pair = gc::As<core::Cons_sp>(CONS_CAR(bindings));
160-
core::DynamicScopeManager scope(gc::As<core::Symbol_sp>(pair->ocar()),core::eval::evaluate(pair->cdr(),nil<core::T_O>()));
160+
core::DynamicScopeManager scope(gc::As<core::Symbol_sp>(pair->car()),core::eval::evaluate(pair->cdr(),nil<core::T_O>()));
161161
do_start_thread_inner(process,CONS_CDR(bindings));
162162
} else {
163163
core::List_sp args = process->_Arguments;

src/core/unwind.cc

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,7 @@ DynEnv_O::SearchStatus sjlj_throw_search(T_sp tag, CatchDynEnv_sp& dest) {
6161
#ifdef UNWIND_INVALIDATE_STRICT
6262
void sjlj_unwind_invalidate(DestDynEnv_sp dest) {
6363
for (T_sp iter = my_thread->dynEnvStackGet();
64-
iter.notnilp() && (iter->ocar() != dest);
64+
iter.notnilp() && (iter->car() != dest);
6565
iter = CONS_CDR(iter))
6666
iter->invalidate();
6767
}

0 commit comments

Comments
 (0)