Data update
This commit is contained in:
parent
5150844a7d
commit
4bb20c9b71
7735 changed files with 38060 additions and 199180 deletions
|
|
@ -1,68 +0,0 @@
|
|||
with Ada.Text_IO;
|
||||
|
||||
procedure Subleq is
|
||||
|
||||
Storage_Size: constant Positive := 2**8; -- increase or decrease memory
|
||||
Steps: Natural := 999; -- "emergency exit" to stop endless loops
|
||||
|
||||
subtype Address is Integer range -1 .. (Storage_Size-1);
|
||||
subtype Memory_Location is Address range 0 .. Address'Last;
|
||||
|
||||
type Storage is array(Memory_Location) of Integer;
|
||||
|
||||
package TIO renames Ada.Text_IO;
|
||||
package IIO is new TIO.Integer_IO(Integer);
|
||||
|
||||
procedure Read_Program(Mem: out Storage) is
|
||||
Idx: Memory_Location := 0;
|
||||
begin
|
||||
while not TIO.End_Of_Line loop
|
||||
IIO.Get(Mem(Idx));
|
||||
Idx := Idx + 1;
|
||||
end loop;
|
||||
exception
|
||||
when others => TIO.Put_Line("Reading program: Something went wrong!");
|
||||
end Read_Program;
|
||||
|
||||
procedure Execute_Program(Mem: in out Storage) is
|
||||
PC: Integer := 0; -- program counter
|
||||
function Source return Integer is (Mem(PC));
|
||||
function Dest return Integer is (Mem(PC+1));
|
||||
function Branch return Integer is (Mem(PC+2));
|
||||
function Next return Integer is (PC+3);
|
||||
begin
|
||||
while PC >= 0 and Steps >= 0 loop
|
||||
Steps := Steps -1;
|
||||
if Source = -1 then -- read input
|
||||
declare
|
||||
Char: Character;
|
||||
begin
|
||||
TIO.Get (Char);
|
||||
Mem(Dest) := Character'Pos (Char);
|
||||
end;
|
||||
PC := Next;
|
||||
elsif Dest = -1 then -- write output
|
||||
TIO.Put(Character'Val(Mem(Source)));
|
||||
PC := Next;
|
||||
else -- subtract and branch if less or equal
|
||||
Mem(Dest) := Mem(Dest) - Mem(Source);
|
||||
if Mem(Dest) <= 0 then
|
||||
PC := Branch;
|
||||
else
|
||||
PC := Next;
|
||||
end if;
|
||||
end if;
|
||||
end loop;
|
||||
TIO.Put_Line(if PC >= 0 then "Emergency exit: program stopped!" else "");
|
||||
exception
|
||||
when others => TIO.Put_Line("Failure when executing Program");
|
||||
end Execute_Program;
|
||||
|
||||
Memory: Storage := (others => 0); -- no initial "junk" in memory!
|
||||
|
||||
begin
|
||||
|
||||
Read_Program(Memory);
|
||||
Execute_Program(Memory);
|
||||
|
||||
end Subleq;
|
||||
|
|
@ -8,10 +8,10 @@ run: function [prog][
|
|||
|
||||
ip: ip + 3
|
||||
|
||||
if? A = neg 1 -> mem\[B]: to :integer first input ""
|
||||
else [
|
||||
if? B = neg 1 -> prints to :char mem\[A]
|
||||
else [
|
||||
switch A = neg 1 -> mem\[B]: to :integer first input ""
|
||||
[
|
||||
switch B = neg 1 -> prints to :char mem\[A]
|
||||
[
|
||||
mem\[B]: mem\[B] - mem\[A]
|
||||
if mem\[B] =< 0 -> ip: C
|
||||
]
|
||||
|
|
|
|||
|
|
@ -1,81 +0,0 @@
|
|||
identification division.
|
||||
program-id. subleq-program.
|
||||
data division.
|
||||
working-storage section.
|
||||
01 subleq-source-code.
|
||||
05 source-string pic x(2000).
|
||||
01 subleq-virtual-machine.
|
||||
05 memory-table.
|
||||
10 memory pic s9999
|
||||
occurs 500 times.
|
||||
05 a pic s9999.
|
||||
05 b pic s9999.
|
||||
05 c pic s9999.
|
||||
05 instruction-pointer pic s9999.
|
||||
05 input-output-character pic x.
|
||||
01 working-variables.
|
||||
05 loop-counter pic 9999.
|
||||
05 instruction-counter pic 9999.
|
||||
05 string-pointer pic 9999.
|
||||
05 adjusted-index-a pic 9999.
|
||||
05 adjusted-index-b pic 9999.
|
||||
05 output-character-code pic 9999.
|
||||
procedure division.
|
||||
read-source-paragraph.
|
||||
accept source-string from console.
|
||||
display 'READING SUBLEQ PROGRAM... ' with no advancing.
|
||||
move 1 to string-pointer.
|
||||
move 0 to instruction-counter.
|
||||
perform split-source-paragraph varying loop-counter from 1 by 1
|
||||
until loop-counter is greater than 500
|
||||
or string-pointer is greater than 2000.
|
||||
display instruction-counter with no advancing.
|
||||
display ' WORDS READ.'.
|
||||
execute-paragraph.
|
||||
move 1 to instruction-pointer.
|
||||
move 0 to instruction-counter.
|
||||
display 'BEGINNING RUN... '.
|
||||
display ''.
|
||||
perform execute-instruction-paragraph
|
||||
until instruction-pointer is negative.
|
||||
display ''.
|
||||
display 'HALTED AFTER ' instruction-counter ' INSTRUCTIONS.'.
|
||||
stop run.
|
||||
execute-instruction-paragraph.
|
||||
add 1 to instruction-counter.
|
||||
move memory(instruction-pointer) to a.
|
||||
add 1 to instruction-pointer.
|
||||
move memory(instruction-pointer) to b.
|
||||
add 1 to instruction-pointer.
|
||||
move memory(instruction-pointer) to c.
|
||||
add 1 to instruction-pointer.
|
||||
if a is equal to -1 then perform input-paragraph.
|
||||
if b is equal to -1 then perform output-paragraph.
|
||||
if a is not equal to -1 and b is not equal to -1
|
||||
then perform subtraction-paragraph.
|
||||
split-source-paragraph.
|
||||
unstring source-string delimited by all spaces
|
||||
into memory(loop-counter)
|
||||
with pointer string-pointer.
|
||||
add 1 to instruction-counter.
|
||||
input-paragraph.
|
||||
display '> ' with no advancing.
|
||||
accept input-output-character from console.
|
||||
add 1 to b giving adjusted-index-b.
|
||||
move function ord(input-output-character)
|
||||
to memory(adjusted-index-b).
|
||||
subtract 1 from memory(adjusted-index-b).
|
||||
output-paragraph.
|
||||
add 1 to a giving adjusted-index-a.
|
||||
add 1 to memory(adjusted-index-a) giving output-character-code.
|
||||
move function char(output-character-code)
|
||||
to input-output-character.
|
||||
display input-output-character with no advancing.
|
||||
subtraction-paragraph.
|
||||
add 1 to c.
|
||||
add 1 to a giving adjusted-index-a.
|
||||
add 1 to b giving adjusted-index-b.
|
||||
subtract memory(adjusted-index-a) from memory(adjusted-index-b).
|
||||
if memory(adjusted-index-b) is equal to zero
|
||||
or memory(adjusted-index-b) is negative
|
||||
then move c to instruction-pointer.
|
||||
|
|
@ -1,37 +0,0 @@
|
|||
function Invoke-Subleq ([int[]]$Program)
|
||||
{
|
||||
[int]$ip, [string]$output = $null
|
||||
|
||||
try
|
||||
{
|
||||
while ($ip -ge 0)
|
||||
{
|
||||
if ($Program[$ip] -eq -1)
|
||||
{
|
||||
$Program[$Program[$ip + 1]] = [int](Read-Host -Prompt SUBLEQ)[0]
|
||||
}
|
||||
elseif ($Program[$ip + 1] -eq -1)
|
||||
{
|
||||
$output += "$([char]$Program[$Program[$ip]])"
|
||||
}
|
||||
else
|
||||
{
|
||||
$Program[$Program[$ip + 1]] -= $Program[$Program[$ip]]
|
||||
|
||||
if ($Program[$Program[$ip + 1]] -le 0)
|
||||
{
|
||||
$ip = $Program[$ip + 2]
|
||||
continue
|
||||
}
|
||||
}
|
||||
|
||||
$ip += 3
|
||||
}
|
||||
|
||||
return $output
|
||||
}
|
||||
catch [IndexOutOfRangeException],[Exception]
|
||||
{
|
||||
Write-Host "$($Error[0].Exception.Message)" -ForegroundColor Red
|
||||
}
|
||||
}
|
||||
|
|
@ -1 +0,0 @@
|
|||
Invoke-Subleq -Program 15,17,-1,17,-1,-1,16,1,-1,16,3,-1,15,15,0,0,-1,72,101,108,108,111,44,32,119,111,114,108,100,33,10,0
|
||||
Loading…
Add table
Add a link
Reference in a new issue