s502 assembler
A very simple assembler for the 6502 line of processors written in C
Functions
istack.c File Reference

implement istack member functions More...

#include "debugmalloc.h"
#include <stdlib.h>
#include "istack.h"
#include "logging.h"

Go to the source code of this file.

Functions

istack_ptr istack_new ()
 
int istack_empty (istack_ptr istack)
 
int istack_push (istack_ptr istack, int val)
 
int istack_pop (istack_ptr istack)
 
int istack_top (istack_ptr istack, int def)
 
void istack_free (istack_ptr istack)
 

Detailed Description

implement istack member functions

See istack.h if doxygen again refuses to show doc comments from there!

Definition in file istack.c.

Function Documentation

◆ istack_empty()

int istack_empty ( istack_ptr  istack)

Definition at line 26 of file istack.c.

26  {
27  return (!istack->next);
28 };

References istack_el::next.

◆ istack_free()

void istack_free ( istack_ptr  istack)

Definition at line 59 of file istack.c.

59  {
60  while (!istack_empty(istack)) istack_pop(istack);
61  free(istack);
62 }

References istack_el::istack_empty(), and istack_el::istack_pop().

◆ istack_new()

istack_ptr istack_new ( )

Definition at line 15 of file istack.c.

15  {
16  istack_ptr head = malloc(sizeof(istack_el));
17  if (!head) {
18  ERROR("Memory allocation error in istack_new()!\n");
19  return NULL;
20  }
21  head->next = NULL;
22  return head;
23 }

References ERROR, and istack_el::next.

◆ istack_pop()

int istack_pop ( istack_ptr  istack)

Definition at line 44 of file istack.c.

44  {
45  if (istack_empty(istack)) return -1;
46  istack_ptr elem = istack->next;
47  istack->next = elem->next;
48  free(elem);
49  return 0;
50 }

References istack_el::istack_empty(), and istack_el::next.

◆ istack_push()

int istack_push ( istack_ptr  istack,
int  val 
)

Definition at line 31 of file istack.c.

31  {
32  istack_ptr elem = malloc(sizeof(istack_el));
33  if (!elem) {
34  ERROR("Memory allocation error in istack_push()!\n");
35  return -1;
36  }
37  elem->val = val;
38  elem->next = istack->next;
39  istack->next = elem;
40  return 0;
41 }

References ERROR, istack_el::next, and istack_el::val.

◆ istack_top()

int istack_top ( istack_ptr  istack,
int  def 
)

Definition at line 53 of file istack.c.

53  {
54  if (istack_empty(istack)) return def;
55  return istack->next->val;
56 };

References istack_el::istack_empty(), and istack_el::next.

istack_el::val
int val
stored value
Definition: istack.h:18
istack_el
very simple int stack
Definition: istack.h:16
istack_el::next
struct _istack * next
pointer to next element or NULL
Definition: istack.h:20
istack_el::istack_pop
int istack_pop(istack_ptr istack)
pop the top of the istack
Definition: istack.c:44
istack_el::istack_empty
int istack_empty(istack_ptr istack)
check if the istack is empty or not
Definition: istack.c:26
ERROR
#define ERROR(...)
Fancy-print an error (cause of faliure). Works like printf.
Definition: logging.h:40