

/*
 * variable.c
 *
 * Variable manipulation routines
 *
 */

#include "ztypes.h"

/*
 * load
 *
 * Load and store a variable value.
 *
 */

#ifdef __STDC__
void load (zword_t variable, z_globals *gl)
#else
void load (variable, gl)
zword_t variable;
z_globals *gl;
#endif
{

    store_operand (load_variable (variable, gl), gl);

}/* load */

/*
 * push_var
 *
 * Push a value onto the stack
 *
 */

#ifdef __STDC__
void push_var (zword_t value, z_globals *gl)
#else
void push_var (value, gl)
zword_t value;
z_globals *gl;
#endif
{

    gl->stack[--(gl->sp)] = value;

}/* push_var */

/*
 * pop_var
 *
 * Pop a variable from the stack.
 *
 */

#ifdef __STDC__
void pop_var (zword_t variable, z_globals *gl)
#else
void pop_var (variable, gl)
zword_t variable;
z_globals *gl;
#endif
{

    store_variable (variable, gl->stack[(gl->sp)++], gl);

}/* pop_var */

/*
 * increment
 *
 * Increment a variable.
 *
 */

#ifdef __STDC__
void increment (zword_t variable, z_globals *gl)
#else
void increment (variable, gl)
zword_t variable;
z_globals *gl;
#endif
{

    store_variable (variable, load_variable (variable, gl) + 1, gl);

}/* increment */

/*
 * decrement
 *
 * Decrement a variable.
 *
 */

#ifdef __STDC__
void decrement (zword_t variable, z_globals *gl)
#else
void decrement (variable, gl)
zword_t variable;
z_globals *gl;
#endif
{

    store_variable (variable, load_variable (variable, gl) - 1, gl);

}/* decrement */

/*
 * increment_check
 *
 * Increment a variable and then check its value against a target.
 *
 */

#ifdef __STDC__
void increment_check (zword_t variable, zword_t target, z_globals *gl)
#else
void increment_check (variable, target, gl)
zword_t variable;
zword_t target;
z_globals *gl;
#endif
{
    short value;

    value = (short) load_variable (variable, gl);
    store_variable (variable, ++value, gl);
    conditional_jump (value > (short) target, gl);

}/* increment_check */

/*
 * decrement_check
 *
 * Decrement a variable and then check its value against a target.
 *
 */

#ifdef __STDC__
void decrement_check (zword_t variable, zword_t target, z_globals *gl)
#else
void decrement_check (variable, target, gl)
zword_t variable;
zword_t target;
z_globals *gl;
#endif
{
    short value;

    value = (short) load_variable (variable, gl);
    store_variable (variable, --value, gl);
    conditional_jump (value < (short) target, gl);

}/* decrement_check */





