-
Notifications
You must be signed in to change notification settings - Fork 49
Description
I now also have a branch with an initial proposal for decorators, where these are just AST transformers. Example:
@metadata
extern main(): string {
return __file;
}The decorator then transforms the source to the following in JavaScript:
(function(__imports, __exports) {
function main() {
var __name = "main", __file = "sandbox/decorators.thin", __line = 1, __column = 0;
return __file;
}
}(
typeof global !== 'undefined' ? global : this,
typeof exports !== 'undefined' ? exports : this
));Or in C:
static const uint32_t __string_0_main[] = {4, S('m', 'a'), S('i', 'n')};
static const uint32_t __string_1_sandbox_decorators_thin[] = {23, S('s', 'a'), S('n', 'd'), S('b', 'o'), S('x', '/'), S('d', 'e'), S('c', 'o'), S('r', 'a'), S('t', 'o'), S('r', 's'), S('.', 't'), S('h',
'i'), S('n', 0)};
static uint16_t *main() {
const uint16_t *__name = (const uint16_t *)__string_0_main;
const uint16_t *__file = (const uint16_t *)__string_1_sandbox_decorators_thin;
int32_t __line = 1;
int32_t __column = 0;
return __file;
}The feature, as proposed, is compatible with all possible backends because it operates on the AST directly. However, to become actually useful, ways to extend the compiler (i.e. through imports of custom modules) must be implemented first.
The reason why I added this so early already is that I was trying to improve the output of assert calls for debugging purposes, but I ultimately realized that some sort of an actually usable stack trace (ideally with source maps) would be a lot better suited for this task. Unfortunately, browsers I have tested do not yet pull useful information from name sections.