[chbot] GCC and recursion

Charles Manning cdhmanning at gmail.com
Sun Apr 14 01:06:27 BST 2024


There is always an equivalent algorithm using arrays etc to make a manual
stack (ie. looping instead of function calling to get the "recursion".).

Sometimes that's all you've got. eg. Fortran 77 etc does not provide
recursion because it is not stack based (like C).

Function calling recursion is a lot easier and cleaner though.

Have you considered just saying sod it and using RPN for your assembler?
Well for a first cut anyway.







On Sun, Apr 14, 2024 at 6:24 AM Mark Atherton <markaren1 at xtra.co.nz> wrote:

> Didn't pursue it, found a simpler solution.
>
> Just investigating Shunting yard algorithm for Algebraic to RPN
> conversion; can't see how can avoid recursion to process complex
> expressions :)
>
> Hair-loss to follow...
>
> -Mark
>
>
> On 4/13/2024 6:42 PM, Charles Manning wrote:
> > I am curious Mark: did you get the recursion working?
> >
> >
> > On Sat, Mar 30, 2024 at 1:25 PM Mark Atherton <markaren1 at xtra.co.nz
> > <mailto:markaren1 at xtra.co.nz>> wrote:
> >
> >     All,
> >
> >     The cross assembler is x86 based, has a deterministic exit condition,
> >     and debug code showing return values. It only exits once, hence
> >     checking
> >     compiler constraints before looking closer look for stupidity on my
> >     part.
> >
> >     Thanks for all the comments.
> >
> >     Mark
> >
> >     On 3/30/2024 12:15 PM, Volker Kuhlmann wrote:
> >      >> I am building an RPN expression evaluator for the uCPU
> >     assembler; I can't
> >      >> see any other way to go other than to use recursion to do the
> nested
> >      >> processing that I wish.
> >      >
> >      > I agree that that should have nothing to do with gcc, although it
> is
> >      > possible that gcc has quite a few bugs affecting correct code
> >     generation
> >      > for some µC cores. Those are gcc version dependent too.
> >      >
> >      > What architecture are you generating code for? Is your assembler
> >     running
> >      > on x86? It's safe to assume for that that crashes are caused by
> your
> >      > code, not gcc.
> >      >
> >      > Recursive programming relies on having a reliable exit condition,
> >     taken
> >      > before resources like stack run out. An easy way to check is to
> write
> >      > out the parameters for each call on a single line, one line per
> call,
> >      > and any unrestrained criteria show up at the bottom of the screen.
> >      >
> >      >> It could be that the compiler is not generating re-entrant code.
> >      >
> >      > Not for x86. More likely a variable which changes with each call
> >     is not
> >      > local. A compiler bug, if it's for esoteric cores, would still be
> >     down
> >      > on my list.
> >      >
> >      > Why don't you just compile for x86 and test in a high-resource
> >      > environment first?
> >      >
> >      > Volker
> >      >
> >
> >
> >     _______________________________________________
> >     Chchrobotics mailing list Chchrobotics at lists.ourshack.com
> >     <mailto:Chchrobotics at lists.ourshack.com>
> >     https://lists.ourshack.com/mailman/listinfo/chchrobotics
> >     <https://lists.ourshack.com/mailman/listinfo/chchrobotics>
> >     Mail Archives: http://lists.ourshack.com/pipermail/chchrobotics/
> >     <http://lists.ourshack.com/pipermail/chchrobotics/>
> >     Meetings usually 3rd Monday each month. See http://kiwibots.org
> >     <http://kiwibots.org> for venue, directions and dates.
> >     When replying, please edit your Subject line to reflect new subjects.
> >
> >
> > _______________________________________________
> > Chchrobotics mailing list Chchrobotics at lists.ourshack.com
> > https://lists.ourshack.com/mailman/listinfo/chchrobotics
> > Mail Archives: http://lists.ourshack.com/pipermail/chchrobotics/
> > Meetings usually 3rd Monday each month. See http://kiwibots.org for
> venue, directions and dates.
> > When replying, please edit your Subject line to reflect new subjects.
>
>
> _______________________________________________
> Chchrobotics mailing list Chchrobotics at lists.ourshack.com
> https://lists.ourshack.com/mailman/listinfo/chchrobotics
> Mail Archives: http://lists.ourshack.com/pipermail/chchrobotics/
> Meetings usually 3rd Monday each month. See http://kiwibots.org for
> venue, directions and dates.
> When replying, please edit your Subject line to reflect new subjects.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.ourshack.com/pipermail/chchrobotics/attachments/20240414/b20b93c6/attachment.html>


More information about the Chchrobotics mailing list