NAME

Acme::ExtUtils::XSOne::Test::Calculator::Memory - Memory storage and calculation history

SYNOPSIS

# Import specific functions
use Acme::ExtUtils::XSOne::Test::Calculator::Memory qw(store recall ans clear);

store(0, 42);
my $val = recall(0);   # 42
my $last = ans();      # last calculation result
clear();               # clear all memory and history

# Or use fully qualified names
use Acme::ExtUtils::XSOne::Test::Calculator;

my $count = Acme::ExtUtils::XSOne::Test::Calculator::Memory::history_count();
my ($op, $a, $b, $result) = Acme::ExtUtils::XSOne::Test::Calculator::Memory::get_history_entry(0);

EXPORTABLE FUNCTIONS

All functions can be imported by name:

store recall clear ans history_count get_history_entry
max_memory_slots max_history_entries is_valid_slot
used_slots sum_all_slots add_to

DESCRIPTION

This module provides memory storage and calculation history functionality as part of the Acme::ExtUtils::XSOne::Test::Calculator distribution.

The memory and history are shared across all Calculator submodules, which demonstrates the key feature of ExtUtils::XSOne: multiple XS packages sharing C-level static state.

FUNCTIONS

store

my $success = store($slot, $value);

Stores $value in memory slot $slot. Returns true on success, false if the slot is invalid. Valid slots are 0 through max_memory_slots() - 1.

recall

my $value = recall($slot);

Returns the value stored in memory slot $slot, or 0 if the slot is invalid or empty.

clear

clear();

Clears all memory slots, resets the calculation history, and resets the last result to 0.

ans

my $last = ans();

Returns the result of the last calculation performed by any Calculator submodule.

history_count

my $count = history_count();

Returns the number of entries in the calculation history.

get_history_entry

my ($operation, $operand1, $operand2, $result) = get_history_entry($index);

Returns the history entry at $index as a four-element list: the operation character, two operands, and the result. Croaks if $index is out of range.

max_memory_slots

my $max = max_memory_slots();

Returns the maximum number of memory slots available (currently 10).

max_history_entries

my $max = max_history_entries();

Returns the maximum number of history entries that can be stored (currently 100).

is_valid_slot

my $bool = is_valid_slot($slot);

Returns true if $slot is a valid memory slot number.

used_slots

my $count = used_slots();

Returns the number of memory slots that contain non-zero values.

sum_all_slots

my $total = sum_all_slots();

Returns the sum of all values stored in memory slots.

add_to

add_to($slot, $value);

Adds $value to the current value in memory slot $slot. Does nothing if the slot is invalid.

SEE ALSO

Acme::ExtUtils::XSOne::Test::Calculator, Acme::ExtUtils::XSOne::Test::Calculator::Basic, Acme::ExtUtils::XSOne::Test::Calculator::Scientific, Acme::ExtUtils::XSOne::Test::Calculator::Trig