Changeset 74


Ignore:
Timestamp:
Mar 4, 2008, 6:08:07 PM (15 years ago)
Author:
Sam Hocevar
Message:
  • Cleaned up stack.hpp and moved it to src/lisp/.
Location:
abuse/trunk
Files:
3 edited
1 moved

Legend:

Unmodified
Added
Removed
  • abuse/trunk/osx/abuse_sdl.pbproj/project.pbxproj

    r73 r74  
    27372737                F5C58193028E0D6D012A168D = {
    27382738                        isa = PBXFileReference;
    2739                         path = stack.hpp;
     2739                        path = lisp/stack.hpp;
    27402740                        refType = 4;
    27412741                };
  • abuse/trunk/src/Makefile.am

    r66 r74  
    5959    gamma.cpp gamma.hpp \
    6060    language.cpp language.hpp \
    61     bus_type.hpp stack.hpp id.hpp netface.hpp isllist.hpp sbar.hpp \
     61    bus_type.hpp id.hpp netface.hpp isllist.hpp sbar.hpp \
    6262    nfserver.hpp exitproc.hpp \
    6363    $(NULL)
  • abuse/trunk/src/lisp/Makefile.am

    r62 r74  
    66    lisp_opt.cpp lisp_opt.hpp \
    77    lisp_gc.cpp lisp_gc.hpp \
     8    stack.hpp \
    89    $(NULL)
    910
  • abuse/trunk/src/lisp/stack.hpp

    r73 r74  
    11/*
    2  *  Abuse - dark 2D side-scrolling platform game
    3  *  Copyright (c) 1995 Crack dot Com
     2 *    Abuse - dark 2D side-scrolling platform game
     3 *    Copyright (c) 1995 Crack dot Com
    44 *
    5  *  This software was released into the Public Domain. As with most public
    6  *  domain software, no warranty is made or implied by Crack dot Com or
    7  *  Jonathan Clark.
     5 *    This software was released into the Public Domain. As with most public
     6 *    domain software, no warranty is made or implied by Crack dot Com or
     7 *    Jonathan Clark.
    88 */
    99
    1010#ifndef __STACK_HPP_
    1111#define __STACK_HPP_
     12
     13#include <stdio.h>
     14
    1215#ifndef NO_LIBS
    13 #include "jmalloc.hpp"
     16#   include "jmalloc.hpp"
    1417#else
    15 #include "fakelib.hpp"
     18#   include "fakelib.hpp"
    1619#endif
    1720
    18 #include <stdio.h>
    19 struct cons_cell;
     21// A fixed-size stack class
     22template<class T> class grow_stack
     23{
     24public:
     25    T **sdata;
     26    long son;
    2027
    21 template<class T> class grow_stack        // stack does not shrink
    22 {
    23   public :
    24   T **sdata;
    25   long son;
    26   long smax;
     28private:
     29    long smax;
    2730
    28   grow_stack(int max_size) {
    29     smax=max_size;
    30     son=0;
    31     sdata=(T **)jmalloc(sizeof(T *)*smax,"pointer stack");
    32   }
    33   void push(T *data)
    34   {
    35     if (son>=smax) { lbreak("stack overflow (%ld)\n",smax); exit(1); }
    36     sdata[son]=data;
    37     son++;
    38   }
    39    
    40   T *pop(long total)
    41   { if (total>son) { lbreak("stack underflow\n"); exit(1); }
    42     son-=total;
    43     return sdata[son];
    44   }
    45   void clean_up()
    46   {
    47     if (son!=0) fprintf(stderr,"Warning cleaning up stack and not empty\n");
    48     jfree(sdata);
    49     sdata=NULL;  son=0;
    50   }
    51 } ;
     31public:
     32    grow_stack(int max_size)
     33    {
     34        smax = max_size;
     35        son = 0;
     36        sdata = (T **)jmalloc(sizeof(T *) * smax, "pointer stack");
     37    }
     38
     39    void push(T *data)
     40    {
     41        if(son >= smax)
     42        {
     43            lbreak("error: stack overflow (%ld >= %ld)\n", son, smax);
     44            exit(1);
     45        }
     46        sdata[son] = data;
     47        son++;
     48    }
     49     
     50    T *pop(long total)
     51    {
     52        if (total > son)
     53        {
     54            lbreak("error: stack underflow\n");
     55            exit(1);
     56        }
     57        son -= total;
     58        return sdata[son];
     59    }
     60
     61    void clean_up()
     62    {
     63        if(son != 0)
     64            fprintf(stderr, "warning: cleaning up stack and not empty\n");
     65        jfree(sdata);
     66        sdata = NULL;
     67        son = 0;
     68    }
     69};
    5270
    5371#endif
Note: See TracChangeset for help on using the changeset viewer.