Re: C++ in the kernel



On 2007-10-30 09:36, Bakul Shah <bakul@xxxxxxxxxxxxx> wrote:
The structured macro paper referenced on the K wiki page also
seems rather interesting. A powerful macro facility needs to
be well integrated with the language (much like Lisp or
Scheme's macros) so that you can write for instance

critical_section(lock) {
...
bar:
...
if (cond1) break;
...
if (cond2) goto foo;
...
if (cond3) goto bar;
...
if (cond4) return; // from enclosing function
...
}
...
foo:

and have it transform to vanilla C code that does proper
unlocking on any exit. To a first approximation I think of
them as compile time "functions" that take identifiers and code
as arguments and return code.

That sounds interesting indeed. Even userlevel code can benefit
greatly from a structured macro enhancement to plain, vanilla C.
I've been reading a lot about macros in both C and Lisp Usenet
groups, but I am not sure how feasible it would be to have in
a C-like language the deeply integrated macros like:

(exception-handling-code
(critical-section (lock)
...))

without an equivalently advanced mechanism for handling
exceptions in the case the macros fail. At least, not in a
way that doesn't make the C-like language sufficiently unportable
to be tricky to implement & use.

For example, in the critical_section() macro above, 'break' is
a quite 'plain' C feature, but it should suddenly grow enough
knowledge about the encapsulating macro to DTRT. The 'return'
keyword is similar. Anything that is related to scope of the
lock object too, and we are already in our way to design something
that is superficialy similar to C but only in a very basic level
of syntax :/

Coming up with something that is semantically well defined &
integrates well with C can not be easy. All budding feature
designers ought to read Tony Hoare's "Hints on programming
language design". Still relevant after 33 years. Search for
cb-p193-hoare.pdf.

Right on the spot, indeed.

_______________________________________________
freebsd-arch@xxxxxxxxxxx mailing list
http://lists.freebsd.org/mailman/listinfo/freebsd-arch
To unsubscribe, send any mail to "freebsd-arch-unsubscribe@xxxxxxxxxxx"



Relevant Pages

  • Re: Programming By The Seat Of Your Pants
    ... the only way I'm going to learn Lisp ... was Python, a better scripting language. ... Not much in the way of libraries. ... then add a macro layer that allows you to write things the way you want to ...
    (comp.lang.lisp)
  • Re: Python gets macros - now XML does too
    ... > I think the main advantage: You use Lisp within a Lisp macro to generate ... > generation part in another language than the description to generate the ... MetaL compiler flow module provides support for level 0 (macro ... Despite currently I only use PHP because I only develop Web ...
    (comp.lang.lisp)
  • Re: What you can do with macros in Lisp
    ... > Imagine you have a language with a CASE expression. ... > equivalent to writing a macro system...) ... as explained in Paul Graham's "On Lisp" in his extended coverage ... macro calls by function calls encapsulating the bodies in closure ...
    (comp.lang.lisp)
  • Re: A "killer" macro
    ... could be included as a feature in another language, ... The "killer" macro, in CL ... of the functional features of Lisp. ... When confronted by fellow programmers with the question "so why is ...
    (comp.lang.lisp)
  • Re: Spell Check Protected Form with Bookmarks
    ... Language ID = wdEnglishUS. ... Bookmarks are not set to calculate on exit. ... The macro to check spelling works, but it assumes that you are working ... because the text fields get set back to not spell check and it does not ...
    (microsoft.public.word.spelling.grammar)