tinycc-devel
[Top][All Lists]
Advanced

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

Re: [Tinycc-devel] nocode_wanted does not work


From: Sergey Korshunoff
Subject: Re: [Tinycc-devel] nocode_wanted does not work
Date: Mon, 4 Apr 2016 02:21:37 +0300

> Like I said, it's not nice. Making nocode_wanted work seems
> preferable. But if it turns out to be too difficult then there are
> perhaps alternatives
Is it possible to implement "undo" like in editors, i.e. save current generated code state (output position) when nocode_wanted=1 and then restore it when nocode_wanted=0?

PS: The problem with the ({}) is exposed only with while()/for() inside it

2016-04-03 22:39 GMT+03:00 Edmund Grimley Evans <address@hidden>:
Michael:

> Of course, because the whole parsing of the ({block}) still
> generates code.  The nocode_wanted hack currently doesn't work for
> statement expressions, and as Edmund says deserves a little thought
> if it's applied at the right level currently (well I think it's
> clear that it isn't, but the question what the right level is
> remains).

Yes.

I've just been thinking about whether there might be any viable
alternatives to making nocode_wanted work properly, and perhaps there
are, but they're not nice...

For example, when you encounter a statement _expression_ you could
distinguish three cases:

1. If you're in a place where it's impossible to generate code, such
as inside the declaration of a global variable, then stop with an
error. This might imply the limitation (which I think people could
live with) of not being able to handle a global declaration such as:

    int a[sizeof(({ for (;;) ; }), 1)];

(On the other hand, are there any places where it's totally impossible
to generate code? Would it matter if you generated unreachable garbage
code between two functions?)

2. If you're somethere where it's possible to generate code, but you
didn't want there to be any code, then generate an unconditional
branch forwards so it doesn't matter if any garbage code gets
generated while the statement _expression_ is being parsed.

3. If you're inside case 2, or anywhere else where you know that
you're generating unreachable code, then just carry on: if any garbage
code gets generated it won't do any harm.

Like I said, it's not nice. Making nocode_wanted work seems
preferable. But if it turns out to be too difficult then there are
perhaps alternatives.

Edmund

_______________________________________________
Tinycc-devel mailing list
address@hidden
https://lists.nongnu.org/mailman/listinfo/tinycc-devel


reply via email to

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