[Top][All Lists]

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [Tinycc-devel] Teaching tcc a new language, like c++?

From: Jared Maddox
Subject: Re: [Tinycc-devel] Teaching tcc a new language, like c++?
Date: Mon, 16 Dec 2013 22:00:26 -0600

> Date: Mon, 16 Dec 2013 10:34:18 +0100
> From: Kevin Ingwersen <address@hidden>
> To: address@hidden
> Subject: [Tinycc-devel] Teaching tcc a new language, like c++?
> Message-ID: <address@hidden>
> Content-Type: text/plain; charset=windows-1252
> Hey!
> I was just looking into the source, and especially at the actual ?compiler?
> part, in order to see if one could add a language to it.
> Is that possible? Because if so, I was curios about trying to get C++
> working.
> Kind regards, Ingwie

I've had a personal interest in this sort of thing before, but my
final conclusion was that C++ has a nice list of features, but that
the actual language as it exists is somewhat clumsy. For example,
templates have traditionally introduced a lex/parse error when this is
    template1< template2< type >>
The >> at the end would until recently get parsed as an operation
instead of a closing bracket for the templates, correct parsing
requires an exception to the rules, automatically making things more
complicated. In comparison, this:
    template1(< template2(< type >)>)
has no valid C parse that I know of, thus posing no such threat. If
you look around online you should be able to find plenty of defects,
which a slightly better design could have avoided, as well as
questions such as "what are pointers-to-members useful for?". So, if
you really want to do this, then I'd suggest doing something INSPIRED
by C++ instead of doing C++ itself. This will also make it easier,
since you won't have to worry about accidentally violating the
language spec.

If you decide to go the "inspired by" route, then I'd suggest taking a
look at features from several other languages too, e.g. Java's
interfaces (if I was working on an OO language, I'd use C++ casting
operators + Java interfaces, with a configuration syntax derived from
C/C++ structures, instead of inheritance), arrays-as-values (C itself
only has arrays-as-pointers), and some sort of alternative to the
syntax involving pointers. I'd suggest looking at Vala and LPC too,
though both of those have garbage collection, which I assume to be
beyond your intentions.

Incidentally, if you actually do decide to go through with this
(whether C++ or something else with OO and a C flavor), I know a way
to incorporate exception handling into ordinary C-style function
calls: place two jumps immediately after the call, one to jump over
the second, and the second to jump to the exception handler. A return
works like normal, but an exception modifies the return location first
to return to the second jump instead of the first jump. Afterwards,
you just need to patch the target address of the second jump to
wherever the exception handler code is, which shouldn't be too

reply via email to

[Prev in Thread] Current Thread [Next in Thread]