1 | /*****************************************************************************/ |
2 | /* */ |
3 | /* wrappedcall.c */ |
4 | /* */ |
5 | /* WrappedCall management */ |
6 | /* */ |
7 | /* */ |
8 | /* */ |
9 | /* (C) 2017, Mega Cat Studios */ |
10 | /* */ |
11 | /* */ |
12 | /* This software is provided 'as-is', without any expressed or implied */ |
13 | /* warranty. In no event will the authors be held liable for any damages */ |
14 | /* arising from the use of this software. */ |
15 | /* */ |
16 | /* Permission is granted to anyone to use this software for any purpose, */ |
17 | /* including commercial applications, and to alter it and redistribute it */ |
18 | /* freely, subject to the following restrictions: */ |
19 | /* */ |
20 | /* 1. The origin of this software must not be misrepresented; you must not */ |
21 | /* claim that you wrote the original software. If you use this software */ |
22 | /* in a product, an acknowledgment in the product documentation would be */ |
23 | /* appreciated but is not required. */ |
24 | /* 2. Altered source versions must be plainly marked as such, and must not */ |
25 | /* be misrepresented as being the original software. */ |
26 | /* 3. This notice may not be removed or altered from any source */ |
27 | /* distribution. */ |
28 | /* */ |
29 | /*****************************************************************************/ |
30 | |
31 | |
32 | |
33 | #include <stdarg.h> |
34 | #include <string.h> |
35 | |
36 | /* common */ |
37 | #include "chartype.h" |
38 | #include "check.h" |
39 | #include "coll.h" |
40 | #include "scanner.h" |
41 | #include "intptrstack.h" |
42 | #include "xmalloc.h" |
43 | |
44 | /* cc65 */ |
45 | #include "codeent.h" |
46 | #include "error.h" |
47 | #include "wrappedcall.h" |
48 | |
49 | |
50 | |
51 | /*****************************************************************************/ |
52 | /* Data */ |
53 | /*****************************************************************************/ |
54 | |
55 | |
56 | /* WrappedCalls */ |
57 | static IntPtrStack WrappedCalls; |
58 | |
59 | |
60 | |
61 | /*****************************************************************************/ |
62 | /* Code */ |
63 | /*****************************************************************************/ |
64 | |
65 | |
66 | |
67 | void PushWrappedCall (void *Ptr, unsigned char Val) |
68 | /* Push the current WrappedCall */ |
69 | { |
70 | if (IPS_IsFull (&WrappedCalls)) { |
71 | Error ("WrappedCall stack overflow" ); |
72 | } else { |
73 | IPS_Push (&WrappedCalls, Val, Ptr); |
74 | } |
75 | } |
76 | |
77 | |
78 | |
79 | void PopWrappedCall (void) |
80 | /* Remove the current WrappedCall */ |
81 | { |
82 | if (IPS_GetCount (&WrappedCalls) < 1) { |
83 | Error ("WrappedCall stack is empty" ); |
84 | } else { |
85 | IPS_Drop (&WrappedCalls); |
86 | } |
87 | } |
88 | |
89 | |
90 | |
91 | void GetWrappedCall (void **Ptr, unsigned char *Val) |
92 | /* Get the current WrappedCall */ |
93 | { |
94 | if (IPS_GetCount (&WrappedCalls) < 1) { |
95 | *Ptr = NULL; |
96 | *Val = 0; |
97 | } else { |
98 | long Temp; |
99 | IPS_Get (&WrappedCalls, &Temp, Ptr); |
100 | *Val = (unsigned char) Temp; |
101 | } |
102 | } |
103 | |