arctic/src/arctic.h

60 lines
1.5 KiB
C

/* ARCTIC library header. To be used as a utility by interpreters and compilers.
* Author: Louis A. Burke
*
* Does not require dynamic memory or a c standard library, so as to be easy to
* use on e.g. microcontrollers.
*/
#ifndef ARCTIC_H
#define ARCTIC_H
#ifndef ARCTIC_BUFSIZE
#define ARCTIC_BUFSIZE 1024
#endif /* ARCTIC_BUFSIZE */
/* encoding/decoding */
extern const char ARCTIC_CODE_PAGE[97];
/* scanning */
enum ArcticImmediateKind {
ARCTIC_NONE, ARCTIC_NAME, ARCTIC_INTEGER, ARCTIC_NUMBER
};
struct ArcticScanner {
void *data; /* callback data pointer */
void (*section_callback)(
const char *name, /* the name of the section */
void *data /* callback data */
);
void (*label_callback)(
const char *id, /* the identifier itself */
void *data /* callback data */
);
void (*op_callback)(
char opcode, /* the character code of the operation */
const char *im, /* the immediate value, if it exists */
void *data /* callback data */
);
void (*data_callback)(
const char *init, /* initialization code */
void *data /* callback data */
);
char buf[ARCTIC_BUFSIZE];
};
enum ArcticErrorCode {
ARCTIC_OK = 0,
ARCTIC_UNEXPECTED_CHAR, /* not necessarily an error */
ARCTIC_INVALID_STATE,
ARCTIC_BUFFER_FULL
};
/* returns 0 on success, or an error code */
enum ArcticErrorCode arctic_scan(struct ArcticScanner *scanner, char next);
#endif /* ARCTIC_H */