2000-11-02 21:22:33 +00:00
|
|
|
/*****************************************************************************/
|
|
|
|
/* */
|
2013-05-09 11:56:54 +00:00
|
|
|
/* loop.c */
|
2000-11-02 21:22:33 +00:00
|
|
|
/* */
|
2013-05-09 11:56:54 +00:00
|
|
|
/* Loop management */
|
2000-11-02 21:22:33 +00:00
|
|
|
/* */
|
|
|
|
/* */
|
|
|
|
/* */
|
2004-06-06 10:52:32 +00:00
|
|
|
/* (C) 1998-2004 Ullrich von Bassewitz */
|
2021-04-19 13:50:52 +00:00
|
|
|
/* Roemerstrasse 52 */
|
2003-12-09 16:29:59 +00:00
|
|
|
/* D-70794 Filderstadt */
|
|
|
|
/* EMail: uz@cc65.org */
|
2000-11-02 21:22:33 +00:00
|
|
|
/* */
|
|
|
|
/* */
|
|
|
|
/* This software is provided 'as-is', without any expressed or implied */
|
|
|
|
/* warranty. In no event will the authors be held liable for any damages */
|
|
|
|
/* arising from the use of this software. */
|
|
|
|
/* */
|
|
|
|
/* Permission is granted to anyone to use this software for any purpose, */
|
|
|
|
/* including commercial applications, and to alter it and redistribute it */
|
|
|
|
/* freely, subject to the following restrictions: */
|
|
|
|
/* */
|
|
|
|
/* 1. The origin of this software must not be misrepresented; you must not */
|
|
|
|
/* claim that you wrote the original software. If you use this software */
|
|
|
|
/* in a product, an acknowledgment in the product documentation would be */
|
|
|
|
/* appreciated but is not required. */
|
|
|
|
/* 2. Altered source versions must be plainly marked as such, and must not */
|
|
|
|
/* be misrepresented as being the original software. */
|
|
|
|
/* 3. This notice may not be removed or altered from any source */
|
|
|
|
/* distribution. */
|
|
|
|
/* */
|
|
|
|
/*****************************************************************************/
|
2000-05-28 13:40:48 +00:00
|
|
|
|
|
|
|
|
|
|
|
|
2000-11-02 21:22:33 +00:00
|
|
|
/* common */
|
2003-12-09 16:29:59 +00:00
|
|
|
#include "check.h"
|
2000-11-02 21:22:33 +00:00
|
|
|
#include "xmalloc.h"
|
2000-06-14 21:01:37 +00:00
|
|
|
|
2000-11-02 21:22:33 +00:00
|
|
|
/* cc65 */
|
2000-05-28 13:40:48 +00:00
|
|
|
#include "error.h"
|
2021-02-15 10:37:01 +00:00
|
|
|
#include "loop.h"
|
2004-06-06 10:52:32 +00:00
|
|
|
#include "stackptr.h"
|
2000-05-28 13:40:48 +00:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/*****************************************************************************/
|
2013-05-09 11:56:54 +00:00
|
|
|
/* Data */
|
2000-05-28 13:40:48 +00:00
|
|
|
/*****************************************************************************/
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/* The root */
|
2000-11-02 21:22:33 +00:00
|
|
|
static LoopDesc* LoopStack = 0;
|
2000-05-28 13:40:48 +00:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/*****************************************************************************/
|
2013-05-09 11:56:54 +00:00
|
|
|
/* Code */
|
2000-05-28 13:40:48 +00:00
|
|
|
/*****************************************************************************/
|
|
|
|
|
|
|
|
|
|
|
|
|
2004-06-06 10:52:32 +00:00
|
|
|
LoopDesc* AddLoop (unsigned BreakLabel, unsigned ContinueLabel)
|
2003-12-09 16:29:59 +00:00
|
|
|
/* Create and add a new loop descriptor. */
|
2000-05-28 13:40:48 +00:00
|
|
|
{
|
|
|
|
/* Allocate a new struct */
|
2003-12-09 16:29:59 +00:00
|
|
|
LoopDesc* L = xmalloc (sizeof (LoopDesc));
|
2000-05-28 13:40:48 +00:00
|
|
|
|
|
|
|
/* Fill in the data */
|
2013-05-09 11:56:54 +00:00
|
|
|
L->StackPtr = StackPtr;
|
2003-12-09 16:29:59 +00:00
|
|
|
L->BreakLabel = BreakLabel;
|
2013-05-09 11:56:54 +00:00
|
|
|
L->ContinueLabel = ContinueLabel;
|
2000-05-28 13:40:48 +00:00
|
|
|
|
|
|
|
/* Insert it into the list */
|
2000-11-02 21:22:33 +00:00
|
|
|
L->Next = LoopStack;
|
|
|
|
LoopStack = L;
|
2000-05-28 13:40:48 +00:00
|
|
|
|
|
|
|
/* Return a pointer to the struct */
|
2000-11-02 21:22:33 +00:00
|
|
|
return L;
|
2000-05-28 13:40:48 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
2000-11-02 21:22:33 +00:00
|
|
|
LoopDesc* CurrentLoop (void)
|
2000-05-28 13:40:48 +00:00
|
|
|
/* Return a pointer to the descriptor of the current loop */
|
|
|
|
{
|
2000-11-02 21:22:33 +00:00
|
|
|
return LoopStack;
|
2000-05-28 13:40:48 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
2000-11-02 21:22:33 +00:00
|
|
|
void DelLoop (void)
|
2000-05-28 13:40:48 +00:00
|
|
|
/* Remove the current loop */
|
|
|
|
{
|
2000-11-02 21:22:33 +00:00
|
|
|
LoopDesc* L = LoopStack;
|
2003-12-09 16:29:59 +00:00
|
|
|
CHECK (L != 0);
|
2000-11-02 21:22:33 +00:00
|
|
|
LoopStack = LoopStack->Next;
|
|
|
|
xfree (L);
|
2000-05-28 13:40:48 +00:00
|
|
|
}
|