1
0
mirror of https://github.com/cc65/cc65.git synced 2025-01-12 17:30:50 +00:00

Trampoline stack

This commit is contained in:
Lauri Kasanen 2017-05-01 21:00:28 +03:00
parent 679bfb0ae9
commit d091a57e91
2 changed files with 167 additions and 0 deletions

102
src/cc65/trampoline.c Normal file
View File

@ -0,0 +1,102 @@
/*****************************************************************************/
/* */
/* trampoline.c */
/* */
/* Trampoline management */
/* */
/* */
/* */
/* (C) 2017, Mega Cat Studios */
/* */
/* */
/* 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. */
/* */
/*****************************************************************************/
#include <stdarg.h>
#include <string.h>
/* common */
#include "chartype.h"
#include "check.h"
#include "coll.h"
#include "scanner.h"
#include "intptrstack.h"
#include "xmalloc.h"
/* cc65 */
#include "codeent.h"
#include "error.h"
#include "trampoline.h"
/*****************************************************************************/
/* Data */
/*****************************************************************************/
/* Trampolines */
static IntPtrStack Trampolines;
/*****************************************************************************/
/* Code */
/*****************************************************************************/
void PushTrampoline (void *Ptr, unsigned char Val)
/* Push the current trampoline */
{
if (IPS_IsFull (&Trampolines)) {
Error ("Trampoline stack overflow");
} else {
IPS_Push (&Trampolines, Val, Ptr);
}
}
void PopTrampoline (void)
/* Remove the current trampoline */
{
if (IPS_GetCount (&Trampolines) < 1) {
Error ("Trampoline stack is empty");
} else {
IPS_Drop (&Trampolines);
}
}
void GetTrampoline (void **Ptr, unsigned char *Val)
/* Get the current trampoline */
{
if (IPS_GetCount (&Trampolines) < 1) {
*Ptr = NULL;
*Val = 0;
} else {
long Temp;
IPS_Get (&Trampolines, &Temp, Ptr);
*Val = Temp;
}
}

65
src/cc65/trampoline.h Normal file
View File

@ -0,0 +1,65 @@
/*****************************************************************************/
/* */
/* trampoline.h */
/* */
/* Trampoline management */
/* */
/* */
/* */
/* (C) 2017, Mega Cat Studios */
/* */
/* */
/* 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. */
/* */
/*****************************************************************************/
#ifndef TRAMPOLINE_H
#define TRAMPOLINE_H
#include <stdio.h>
/* common */
#include "attrib.h"
/* cc65 */
#include "opcodes.h"
/*****************************************************************************/
/* Code */
/*****************************************************************************/
void PushTrampoline (void *Ptr, unsigned char Val);
/* Push the current trampoline */
void PopTrampoline (void);
/* Pop the current trampoline */
void GetTrampoline (void **Ptr, unsigned char *Val);
/* Get the current trampoline, if any */
/* End of trampoline.h */
#endif