view interps/egobf/src/egobfi.h @ 12256:821155c00e34 draft

<fizzie> ` sed -e \'s|wisdom|bin|\' < ../bin/culprits > ../bin/cblprits; chmod a+x ../bin/cblprits
author HackEso <hackeso@esolangs.org>
date Sat, 07 Dec 2019 23:36:22 +0000
parents 859f9b4339e6
children
line wrap: on
line source

/*
 * Copyright (c) 2005  Gregor Richards
 *
 * This file is part of egobfi.
 * 
 * egobfi is free software; you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation; either version 2 of the License, or
 * (at your option) any later version.
 * 
 * egobfi is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 * 
 * You should have received a copy of the GNU General Public License
 * along with egobfi; if not, write to the Free Software
 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
 */

#ifndef EGOBFI_H
#define EGOBFI_H

#include <stdint.h>

struct bfi {
    enum { NIL,
            ADD,
            RHT,
            LPO,
            LPC,
            OUT,
            INP,
            DBG,
            ZRO,
            ADDTO,
            FIN
    } cmd;
    int arg1;
    int arg2;
};
            

#define CHKIPSZ(a) if ((a) >= iplen) { \
iplen += 3000; \
iprog = (char *) realloc(iprog, iplen); \
if (iprog == NULL) { perror("realloc"); exit(1); } \
memset(iprog + iplen - 3000, 0, 3000); \
}

#ifndef EGOBFC2M
#define CHKPSZ(a) if ((a) >= plen) { \
plen += 3000; \
prog = (struct bfi *) realloc(prog, plen * sizeof(struct bfi)); \
if (prog == NULL) { perror("realloc"); exit(1); } \
memset(prog + plen - 3000, 0, 3000 * sizeof(struct bfi)); \
}
#else
#define CHKPSZ(a) if ((a) >= plen) { \
plen += 10000; \
prog = realloc(prog, plen); \
if (prog == NULL) { perror("realloc"); exit(1); } \
}
#endif

#define CHKMSZ(a) if ((a) >= mend) { \
mlen += 3000; \
mptr = (USEINT *) ((int) mptr - (int) mem); \
mem = (USEINT *) realloc(mem, mlen * sizeof(USEINT)); \
if (mem == NULL) { perror("realloc"); exit(1); } \
mend = mem + mlen; \
mptr = (USEINT *) ((int) mem + (int) mptr); \
memset(mem + mlen - 3000, 0, 3000 * sizeof(USEINT)); \
}

#define ISBF(a) ((a) == '+' || \
(a) == '-' || \
(a) == '>' || \
(a) == '<' || \
(a) == ']' || \
(a) == '[' || \
(a) == '.' || \
(a) == ',' || \
(a) == '#')

extern int wrapping;
extern int debug;
extern int eof;
extern int compile;
extern int unicode;

#ifdef EGOBFC
extern int bytewidth;
#else
extern USEINT bwmax;
extern USEINT *mem;
extern int mlen;
extern USEINT *mend;
extern USEINT *mptr;
#endif

extern char *iprog;
extern int iplen;
extern int ipptr;

#ifndef EGOBFC2M
extern struct bfi *prog;
extern int plen;
extern int pptr;
#else
extern void (*prog)();
extern void (*tprog)();
extern int plen;
extern int pptr;
#endif

#endif