blob: 789793c9483138b2c100d3ace95f5254f77a67be [file] [log] [blame]
/*
* *****************************************************************************
*
* Copyright 2018 Gavin D. Howard
*
* Permission to use, copy, modify, and/or distribute this software for any
* purpose with or without fee is hereby granted.
*
* THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES WITH
* REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY
* AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT,
* INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM
* LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR
* OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
* PERFORMANCE OF THIS SOFTWARE.
*
* *****************************************************************************
*
* Definitions for bc programs.
*
*/
#ifndef BC_PROGRAM_H
#define BC_PROGRAM_H
#include <stdbool.h>
#include <stdint.h>
#include <status.h>
#include <lang.h>
typedef struct BcProgram {
size_t line_len;
size_t scale;
BcNum ibase;
size_t ibase_t;
BcNum obase;
size_t obase_t;
BcVec results;
BcVec stack;
BcVec funcs;
BcVecO func_map;
BcVec vars;
BcVecO var_map;
BcVec arrays;
BcVecO array_map;
BcVec strings;
BcVec constants;
const char *file;
BcNum last;
BcNum zero;
BcNum one;
size_t nchars;
} BcProgram;
#define BC_PROGRAM_CHECK_STACK(p) ((p)->stack.len > 1)
#define BC_PROGRAM_CHECK_RESULTS(p, l) ((p)->results.len >= (l))
#define BC_PROGRAM_MAIN (0)
#define BC_PROGRAM_READ (1)
typedef unsigned long (*BcProgramBuiltIn)(BcNum*);
// ** Exclude start. **
BcStatus bc_program_init(BcProgram *p, size_t line_len);
void bc_program_free(BcProgram *program);
#ifndef NDEBUG
BcStatus bc_program_print(BcProgram *p);
#endif // NDEBUG
// ** Exclude end. **
BcStatus bc_program_addFunc(BcProgram *p, char *name, size_t *idx);
BcStatus bc_program_reset(BcProgram *p, BcStatus status);
BcStatus bc_program_exec(BcProgram *p);
extern const BcNumBinaryOp bc_program_ops[];
extern const char bc_program_stdin_name[];
extern const char bc_program_ready_prompt[];
#endif // BC_PROGRAM_H