Zero-Emulator
view release on metacpan or search on metacpan
lib/Zero/Emulator.pm view on Meta::CPAN
sub AssertNe($$%) #i Assert two memory locations are not equal.
{my ($a, $b, %options) = @_; # First memory address, second memory address
Assert2("Ne", $a, $b);
}
sub AssertTrue($%) #i Assert true.
{my ($a, %options) = @_; # Source operand
Assert1("True", $a);
}
sub Bad(&) #i A bad ending.
{my ($bad) = @_; # What to do on a bad ending
@_ == 1 or confess "One parameter";
(bad=> $bad)
}
sub Block(&%) #i Block of code that can either be restarted or come to a good or a bad ending.
{my ($block, %options) = @_; # Block, options
my ($Start, $Good, $Bad, $End) = (label, label, label, label);
my $g = $options{good};
my $b = $options{bad};
setLabel($Start); # Start
&$block($Start, $Good, $Bad, $End); # Code of block
lib/Zero/Emulator.pm view on Meta::CPAN
sub Dec($) #i Decrement the target.
{my ($target) = @_; # Target address
$assembly->instruction(action=>"dec", xTarget($target))
}
sub Dump() #i Dump all the arrays currently in memory.
{$assembly->instruction(action=>"dump");
}
sub Else(&) #i Else block.
{my ($e) = @_; # Else block subroutine
@_ == 1 or confess "One parameter";
(else=> $e)
}
sub Execute(%) #i Execute the current assembly.
{my (%options) = @_; # Options
$assembly->execute(%options); # Execute the code in the current assembly
}
sub For(&$%) #i For loop 0..range-1 or in reverse.
{my ($block, $range, %options) = @_; # Block, limit, options
if (!exists $options{reverse}) # Ascending order
{my $s = 0; my $e = $range; # Start, end
($s, $e) = @$range if ref($e) =~ m(ARRAY); # Start, end as a reference
my ($Start, $Check, $Next, $End) = (label, label, label, label);
setLabel($Start); # Start
my $i = Mov $s;
setLabel($Check); # Check
lib/Zero/Emulator.pm view on Meta::CPAN
setLabel($Check); # Check
Jlt $End, $i, $e;
&$block($i, $Check, $Next, $End); # Block
setLabel($Next);
Dec $i; # Next
Jmp $Check;
setLabel($End); # End
}
}
sub ForArray(&$$%) #i For loop to process each element of the named area.
{my ($block, $area, $name, %options) = @_; # Block of code, area, area name, options
my $e = ArraySize $area, $name; # End
my $s = 0; # Start
my ($Start, $Check, $Next, $End) = (label, label, label, label);
setLabel($Start); # Start
my $i = Mov $s;
setLabel($Check); # Check
Jge $End, $i, $e;
lib/Zero/Emulator.pm view on Meta::CPAN
Jmp $Check;
setLabel($End); # End
}
sub Free($$) #i Free the memory area named by the target operand after confirming that it has the name specified on the source operand.
{my ($target, $source) = @_; # Target area yielding the id of the area to be freed, source area yielding the name of the area to be freed
my $n = $assembly->ArrayNameToNumber($source);
$assembly->instruction(action=>"free", xTarget($target), xSource($n));
}
sub Good(&) #i A good ending.
{my ($good) = @_; # What to do on a good ending
@_ == 1 or confess "One parameter";
(good=> $good)
}
sub Ifx($$$%) #P Execute then or else clause depending on whether two memory locations are equal.
{my ($cmp, $a, $b, %options) = @_; # Comparison, first memory address, second memory address, then block, else block
confess "Then required" unless $options{then};
if ($options{else})
{my $else = label;
lib/Zero/Emulator.pm view on Meta::CPAN
$assembly->instruction(action=>"subtract", xTarget($target),
xSource($s1), xSource2($s2));
$target
}
sub Tally($) #i Counts instructions when enabled.
{my ($source) = @_; # Tally instructions when true
$assembly->instruction(action=>"tally", xSource($source));
}
sub Then(&) #i Then block.
{my ($t) = @_; # Then block subroutine
@_ == 1 or confess "One parameter";
(then=> $t)
}
sub Trace($) #i Start or stop tracing. Tracing prints each instruction executed and its effect on memory.
{my ($source) = @_; # Trace setting
$assembly->instruction(action=>"trace", xSource($source));
}
lib/Zero/NWayTree.pm view on Meta::CPAN
Jmp $Finish;
};
my $i = FindResult_indexP1($find); # Not a leaf so on an interior key so we can go right then all the way left
my $d = Node_down($node, $i);
GoAllTheWayLeft($find, $d);
};
$find
}
sub Iterate(&$) # Iterate over a tree.
{my ($block, $tree) = @_; # Block of code to execute for each key in tree, tree
my $n = root($tree);
my $f = FindResult_new;
GoAllTheWayLeft($f, $n);
For
{my ($i, $check, $next, $end) = @_; # Parameters
Jeq $end, FindResult_cmp($f), FindResult_notFound;
&$block($f);
( run in 0.955 second using v1.01-cache-2.11-cpan-49f99fa48dc )