Polly 19.0.0git
Classes | Macros | Typedefs | Enumerations | Functions | Variables
imcalc.c File Reference
#include <assert.h>
#include <ctype.h>
#include <errno.h>
#include <limits.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <strings.h>
#include <getopt.h>
#include <unistd.h>
#include "imath.h"
#include "imrat.h"
#include "iprime.h"

Go to the source code of this file.

Classes

struct  cstate_t
 
struct  calcop_t
 

Macros

#define BUFFER_SIZE   16384 /* max. length of input values, in chars */
 

Typedefs

typedef mp_result(* op_func) (cstate_t *)
 

Enumerations

enum  token_t { t_eof , t_symbol , t_number , t_error }
 

Functions

static mp_result state_init (cstate_t *sp, mp_size n_elts)
 
static void state_clear (cstate_t *sp)
 
static void stack_flush (cstate_t *sp)
 
static mp_result stack_push (cstate_t *sp, mp_int elt)
 
static mp_result stack_pop (cstate_t *sp)
 
static mp_result mem_insert (cstate_t *sp, const char *name, mp_int value)
 
static mp_result mem_recall (cstate_t *sp, const char *name, mp_int value)
 
static mp_result mem_clear (cstate_t *sp)
 
static mp_result cf_abs (cstate_t *sp)
 
static mp_result cf_neg (cstate_t *sp)
 
static mp_result cf_add (cstate_t *sp)
 
static mp_result cf_sub (cstate_t *sp)
 
static mp_result cf_mul (cstate_t *sp)
 
static mp_result cf_divmod (cstate_t *sp)
 
static mp_result cf_div (cstate_t *sp)
 
static mp_result cf_mod (cstate_t *sp)
 
static mp_result cf_expt (cstate_t *sp)
 
static mp_result cf_exptmod (cstate_t *sp)
 
static mp_result cf_square (cstate_t *sp)
 
static mp_result cf_invmod (cstate_t *sp)
 
static mp_result cf_gcd (cstate_t *sp)
 
static mp_result cf_xgcd (cstate_t *sp)
 
static mp_result cf_sqrt (cstate_t *sp)
 
static mp_result cf_root (cstate_t *sp)
 
static mp_result cf_cmplt (cstate_t *sp)
 
static mp_result cf_cmpgt (cstate_t *sp)
 
static mp_result cf_cmple (cstate_t *sp)
 
static mp_result cf_cmpge (cstate_t *sp)
 
static mp_result cf_cmpeq (cstate_t *sp)
 
static mp_result cf_cmpne (cstate_t *sp)
 
static mp_result cf_inc (cstate_t *sp)
 
static mp_result cf_dec (cstate_t *sp)
 
static mp_result cf_fact (cstate_t *sp)
 
static mp_result cf_pprint (cstate_t *sp)
 
static mp_result cf_print (cstate_t *sp)
 
static mp_result cf_pstack (cstate_t *sp)
 
static mp_result cf_clstk (cstate_t *sp)
 
static mp_result cf_pop (cstate_t *sp)
 
static mp_result cf_dup (cstate_t *sp)
 
static mp_result cf_copy (cstate_t *sp)
 
static mp_result cf_swap (cstate_t *sp)
 
static mp_result cf_rot (cstate_t *sp)
 
static mp_result cf_pick (cstate_t *sp)
 
static mp_result cf_setr (cstate_t *sp)
 
static mp_result cf_setbin (cstate_t *sp)
 
static mp_result cf_help (cstate_t *sp)
 
static mp_result cf_store (cstate_t *sp)
 
static mp_result cf_recall (cstate_t *sp)
 
static mp_result cf_cmem (cstate_t *sp)
 
static mp_result cf_pmem (cstate_t *sp)
 
static mp_result cf_qrecall (cstate_t *sp)
 
static token_t next_token (FILE *ifp, char *buf, int size)
 
static mp_result read_number (char *buf, mp_int *out)
 
static int find_command (cstate_t *ops)
 
static void print_value (mp_int v)
 
static mp_result run_file (FILE *ifp, cstate_t *op_state)
 
int main (int argc, char *argv[])
 

Variables

static calcop_t g_ops []
 
static mp_result MP_INPUT
 
static int g_output_radix = 10
 
static FILE * g_output_file = NULL
 

Macro Definition Documentation

◆ BUFFER_SIZE

#define BUFFER_SIZE   16384 /* max. length of input values, in chars */

Definition at line 191 of file imcalc.c.

Typedef Documentation

◆ op_func

typedef mp_result(* op_func) (cstate_t *)

Definition at line 76 of file imcalc.c.

Enumeration Type Documentation

◆ token_t

enum token_t
Enumerator
t_eof 
t_symbol 
t_number 
t_error 

Definition at line 194 of file imcalc.c.

Function Documentation

◆ cf_abs()

static mp_result cf_abs ( cstate_t sp)
static

Definition at line 663 of file imcalc.c.

References a(), cstate_t::elts, mp_int_abs, and cstate_t::used.

◆ cf_add()

static mp_result cf_add ( cstate_t sp)
static

Definition at line 675 of file imcalc.c.

References a(), b(), cstate_t::elts, mp_int_add, MP_OK, res, stack_pop(), and cstate_t::used.

◆ cf_clstk()

static mp_result cf_clstk ( cstate_t sp)
static

Definition at line 938 of file imcalc.c.

References MP_OK, and stack_flush().

◆ cf_cmem()

static mp_result cf_cmem ( cstate_t sp)
static

Definition at line 1089 of file imcalc.c.

References mem_clear().

◆ cf_cmpeq()

static mp_result cf_cmpeq ( cstate_t sp)
static

Definition at line 859 of file imcalc.c.

References a(), b(), cstate_t::elts, mp_int_compare, mp_int_set_value, res, stack_pop(), and cstate_t::used.

◆ cf_cmpge()

static mp_result cf_cmpge ( cstate_t sp)
static

Definition at line 849 of file imcalc.c.

References a(), b(), cstate_t::elts, mp_int_compare, mp_int_set_value, res, stack_pop(), and cstate_t::used.

◆ cf_cmpgt()

static mp_result cf_cmpgt ( cstate_t sp)
static

Definition at line 829 of file imcalc.c.

References a(), b(), cstate_t::elts, mp_int_compare, mp_int_set_value, res, stack_pop(), and cstate_t::used.

◆ cf_cmple()

static mp_result cf_cmple ( cstate_t sp)
static

Definition at line 839 of file imcalc.c.

References a(), b(), cstate_t::elts, mp_int_compare, mp_int_set_value, res, stack_pop(), and cstate_t::used.

◆ cf_cmplt()

static mp_result cf_cmplt ( cstate_t sp)
static

Definition at line 819 of file imcalc.c.

References a(), b(), cstate_t::elts, mp_int_compare, mp_int_set_value, res, stack_pop(), and cstate_t::used.

◆ cf_cmpne()

static mp_result cf_cmpne ( cstate_t sp)
static

Definition at line 869 of file imcalc.c.

References a(), b(), cstate_t::elts, mp_int_compare, mp_int_set_value, res, stack_pop(), and cstate_t::used.

◆ cf_copy()

static mp_result cf_copy ( cstate_t sp)
static

◆ cf_dec()

static mp_result cf_dec ( cstate_t sp)
static

Definition at line 885 of file imcalc.c.

References a(), cstate_t::elts, mp_int_sub_value, and cstate_t::used.

◆ cf_div()

static mp_result cf_div ( cstate_t sp)
static

Definition at line 712 of file imcalc.c.

References a(), b(), cstate_t::elts, mp_int_div, MP_OK, res, stack_pop(), and cstate_t::used.

◆ cf_divmod()

static mp_result cf_divmod ( cstate_t sp)
static

Definition at line 705 of file imcalc.c.

References a(), b(), cstate_t::elts, mp_int_div, and cstate_t::used.

◆ cf_dup()

static mp_result cf_dup ( cstate_t sp)
static

◆ cf_expt()

static mp_result cf_expt ( cstate_t sp)
static

Definition at line 732 of file imcalc.c.

References a(), b(), cstate_t::elts, mp_int_expt, mp_int_to_int, MP_OK, res, stack_pop(), and cstate_t::used.

◆ cf_exptmod()

static mp_result cf_exptmod ( cstate_t sp)
static

Definition at line 744 of file imcalc.c.

References a(), b(), cstate_t::elts, m, mp_int_exptmod, MP_OK, res, stack_pop(), and cstate_t::used.

◆ cf_fact()

static mp_result cf_fact ( cstate_t sp)
static

◆ cf_gcd()

static mp_result cf_gcd ( cstate_t sp)
static

Definition at line 774 of file imcalc.c.

References a(), b(), cstate_t::elts, mp_int_gcd, MP_OK, res, stack_pop(), and cstate_t::used.

◆ cf_help()

static mp_result cf_help ( cstate_t sp)
static

Definition at line 1040 of file imcalc.c.

References g_ops, MP_OK, calcop_t::name, and name.

◆ cf_inc()

static mp_result cf_inc ( cstate_t sp)
static

Definition at line 879 of file imcalc.c.

References a(), cstate_t::elts, mp_int_add_value, and cstate_t::used.

◆ cf_invmod()

static mp_result cf_invmod ( cstate_t sp)
static

Definition at line 764 of file imcalc.c.

References a(), cstate_t::elts, m, mp_int_invmod, res, stack_pop(), and cstate_t::used.

◆ cf_mod()

static mp_result cf_mod ( cstate_t sp)
static

Definition at line 722 of file imcalc.c.

References a(), b(), cstate_t::elts, mp_int_mod, MP_OK, res, stack_pop(), and cstate_t::used.

◆ cf_mul()

static mp_result cf_mul ( cstate_t sp)
static

Definition at line 695 of file imcalc.c.

References a(), b(), cstate_t::elts, mp_int_mul, MP_OK, res, stack_pop(), and cstate_t::used.

◆ cf_neg()

static mp_result cf_neg ( cstate_t sp)
static

Definition at line 669 of file imcalc.c.

References a(), cstate_t::elts, mp_int_neg, and cstate_t::used.

◆ cf_pick()

static mp_result cf_pick ( cstate_t sp)
static

Definition at line 1009 of file imcalc.c.

References cstate_t::elts, mp_int_copy, mp_int_to_int, MP_OK, MP_RANGE, n, pos(), res, and cstate_t::used.

◆ cf_pmem()

static mp_result cf_pmem ( cstate_t sp)
static

Definition at line 1091 of file imcalc.c.

References g_output_file, cstate_t::mem, MP_OK, cstate_t::mused, cstate_t::names, and print_value().

◆ cf_pop()

static mp_result cf_pop ( cstate_t sp)
static

Definition at line 944 of file imcalc.c.

References stack_pop().

◆ cf_pprint()

static mp_result cf_pprint ( cstate_t sp)
static

Definition at line 912 of file imcalc.c.

References cstate_t::elts, MP_OK, print_value(), stack_pop(), and cstate_t::used.

◆ cf_print()

static mp_result cf_print ( cstate_t sp)
static

Definition at line 918 of file imcalc.c.

References cstate_t::elts, MP_OK, print_value(), and cstate_t::used.

◆ cf_pstack()

static mp_result cf_pstack ( cstate_t sp)
static

Definition at line 923 of file imcalc.c.

References cstate_t::elts, g_output_file, MP_OK, print_value(), and cstate_t::used.

◆ cf_qrecall()

static mp_result cf_qrecall ( cstate_t sp)
static

Definition at line 1120 of file imcalc.c.

References cstate_t::ibuf, mem_recall(), mp_int_alloc, mp_int_free, MP_MEMORY, MP_OK, res, stack_push(), and val.

◆ cf_recall()

static mp_result cf_recall ( cstate_t sp)
static

◆ cf_root()

static mp_result cf_root ( cstate_t sp)
static

Definition at line 807 of file imcalc.c.

References a(), b(), cstate_t::elts, mp_int_root, mp_int_to_int, MP_OK, res, stack_pop(), and cstate_t::used.

◆ cf_rot()

static mp_result cf_rot ( cstate_t sp)
static

Definition at line 999 of file imcalc.c.

References cstate_t::elts, MP_OK, t, and cstate_t::used.

◆ cf_setbin()

static mp_result cf_setbin ( cstate_t sp)
static

Definition at line 1035 of file imcalc.c.

References g_output_radix, and MP_OK.

◆ cf_setr()

static mp_result cf_setr ( cstate_t sp)
static

◆ cf_sqrt()

static mp_result cf_sqrt ( cstate_t sp)
static

Definition at line 801 of file imcalc.c.

References a(), cstate_t::elts, mp_int_sqrt(), and cstate_t::used.

◆ cf_square()

static mp_result cf_square ( cstate_t sp)
static

Definition at line 758 of file imcalc.c.

References a(), cstate_t::elts, mp_int_sqr, and cstate_t::used.

◆ cf_store()

static mp_result cf_store ( cstate_t sp)
static

◆ cf_sub()

static mp_result cf_sub ( cstate_t sp)
static

Definition at line 685 of file imcalc.c.

References a(), b(), cstate_t::elts, mp_int_sub, MP_OK, res, stack_pop(), and cstate_t::used.

◆ cf_swap()

static mp_result cf_swap ( cstate_t sp)
static

Definition at line 990 of file imcalc.c.

References cstate_t::elts, MP_OK, t, and cstate_t::used.

◆ cf_xgcd()

static mp_result cf_xgcd ( cstate_t sp)
static

◆ find_command()

static int find_command ( cstate_t ops)
static

Definition at line 372 of file imcalc.c.

References g_ops, calcop_t::name, name, and op.

Referenced by run_file().

◆ main()

int main ( int  argc,
char *  argv[] 
)

◆ mem_clear()

static mp_result mem_clear ( cstate_t sp)
static

Definition at line 651 of file imcalc.c.

References cstate_t::mem, mp_int_free, MP_OK, cstate_t::mused, and cstate_t::names.

Referenced by cf_cmem().

◆ mem_insert()

static mp_result mem_insert ( cstate_t sp,
const char *  name,
mp_int  value 
)
static

◆ mem_recall()

static mp_result mem_recall ( cstate_t sp,
const char *  name,
mp_int  value 
)
static

Definition at line 639 of file imcalc.c.

References cstate_t::mem, mp_int_copy, MP_UNDEF, name, and cstate_t::names.

Referenced by cf_qrecall(), and cf_recall().

◆ next_token()

static token_t next_token ( FILE *  ifp,
char *  buf,
int  size 
)
static

Definition at line 282 of file imcalc.c.

References assert, pos(), res, size, t_eof, t_error, t_number, and t_symbol.

Referenced by cf_recall(), cf_store(), and run_file().

◆ print_value()

static void print_value ( mp_int  v)
static

◆ read_number()

static mp_result read_number ( char *  buf,
mp_int out 
)
static

Definition at line 325 of file imcalc.c.

References assert, MP_BADARG, mp_int_alloc, mp_int_free, mp_int_read_string, MP_MEMORY, MP_OK, pos(), and res.

Referenced by run_file().

◆ run_file()

static mp_result run_file ( FILE *  ifp,
cstate_t op_state 
)
static

◆ stack_flush()

static void stack_flush ( cstate_t sp)
static

Definition at line 545 of file imcalc.c.

References assert, cstate_t::elts, mp_int_clear, and cstate_t::used.

Referenced by cf_clstk().

◆ stack_pop()

static mp_result stack_pop ( cstate_t sp)
static

◆ stack_push()

static mp_result stack_push ( cstate_t sp,
mp_int  elt 
)
static

Definition at line 558 of file imcalc.c.

References cstate_t::alloc, cstate_t::elts, MP_MEMORY, MP_OK, and cstate_t::used.

Referenced by cf_copy(), cf_dup(), cf_qrecall(), cf_recall(), cf_xgcd(), and run_file().

◆ state_clear()

static void state_clear ( cstate_t sp)
static

◆ state_init()

static mp_result state_init ( cstate_t sp,
mp_size  n_elts 
)
static

Variable Documentation

◆ g_ops

calcop_t g_ops[]
static

Definition at line 129 of file imcalc.c.

Referenced by cf_help(), find_command(), and run_file().

◆ g_output_file

FILE* g_output_file = NULL
static

Definition at line 206 of file imcalc.c.

Referenced by cf_pmem(), cf_pstack(), main(), and print_value().

◆ g_output_radix

int g_output_radix = 10
static

Definition at line 205 of file imcalc.c.

Referenced by cf_setbin(), cf_setr(), and print_value().

◆ MP_INPUT

mp_result MP_INPUT
static

Definition at line 203 of file imcalc.c.

Referenced by cf_recall(), cf_store(), main(), and run_file().