1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78
|
use core:lang;
use core:asm;
use lang:bs:macro;
/**
* A note that we wish to make accessible from the name tree.
*/
class Note {
// Title of the note.
Str title;
// The body text of the note.
Str body;
// Create.
init(Str title, Str body) {
init() {
title = title;
body = body;
}
}
// To string:
void toS(StrBuf to) : override {
to << title << "\n\n";
to << body;
}
}
// Helper function to create a note from the grammar. Acts like the constructor but removes
// indentation from the body.
Note makeNote(Str title, Str body) {
Note(title, body.removeIndentation());
}
/**
* A entity that we can add to the name tree.
*/
class NoteEntity extends Function {
// The note stored in the entity.
Note note;
// Create.
init(SrcPos pos, Str name, Note note) {
init(pos, named{Note}, name, []) {
note = note;
}
Listing l(false, ptrDesc);
l << prolog();
l << fnParam(ptrDesc, objPtr(note));
l << fnCall(named{clone<Note>}.ref, false, ptrDesc, ptrA);
l << fnRet(ptrA);
setCode(DynamicCode(l));
}
}
/**
* Declaration of the named entity.
*/
class NoteDecl extends lang:bs:NamedDecl {
SStr name;
Note note;
init(SStr name, Note note) {
init {
name = name;
note = note;
}
}
protected Named doCreate() : override {
NoteEntity(name.pos, name.v, note);
}
}
|