Add arrays, making the language turing complete

See tests/rule110.qbl for turing completeness
This commit is contained in:
0x4261756D
2022-12-21 21:48:52 +01:00
parent 2255aaff8b
commit e4a7bcccc0
2 changed files with 334 additions and 83 deletions

View File

@ -1,4 +1,15 @@
//valid,:END:
//valid,00000000000000110000000000000000
//00000000000001110000000000000000
//00000000000011010000000000000000
//00000000000111110000000000000000
//00000000001100010000000000000000
//00000000011100110000000000000000
//00000000110101110000000000000000
//00000001111111010000000000000000
//00000011000001110000000000000000
//00000111000011010000000000000000
//00001101000111110000000000000000
//:END:
function bool bool bool => bool rule110
{
if
@ -24,9 +35,62 @@ function bool bool bool => bool rule110
}
}
function int => bool intToBool
arr val { bool 32 }
15 true val.write
function int => bool int check
{
0 !=
0 dup 1 > -
}
function => fullApply
{
0 false val2.write
true 1
while
{
// i-1 i
1 dup - req
// i a | i a i | a i b | i b a i 1
val.read dup val.read req dup 1
// i a b i+1 | i+1 i a b | i a b c
req swp + req req req val.read
// i d
req rule110
// i d i | i
dup val2.write
checkUp-1
}
1 - false val2.write
}
function int => bool int checkUp
{
// i+1 l i+1
1 + val.length dup < req
}
function int => bool int checkUp-1
{
// i+1 l 1 | l 1 i+1 | i+1 l-1 i+1
1 + val.length 1 req - dup
// i+1 b
< req
}
arr val2 { bool 32 }
function => copyArrays
{
true 0
while
{
dup val2.read
dup val.write
checkUp
}
deq
}
function bool => int boolToInt
@ -41,49 +105,24 @@ function bool => int boolToInt
}
}
true 10
true 32 0 0 0 0 0 0 0 0 0 0 0 0 0 0 1 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
while
function => printArrays
{
check
true 0
while
{
// 32 0 0 0 0 0 0 0 0 0 0 0 0 0 0 1 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
checkAndApply
// 0 0 0 0 0 0 0 0 0 0 0 1 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 true 31 0 0 0
shift-5
dup val.read req boolToInt req print
checkUp
}
deq
"" println
}
function any any any any any any any any any any any any any any any any any any any any any any any any any any any => any any any any any any any any any any any any any any any any any any any any any any any any any any any shift-5
{ }
function int int int int => bool int int int int checkAndApply
true 10
while
{
check apply
}
function int => bool int
{
0 dup 1 > req -
}
function int int int => int int int apply
{
// a b c
intToBool
// b c d
dup intToBool
// c d b e
dup intToBool
// d b e c f
req swp swp
// d e b f c
req req swp
// c d e f b
req rule110
// b c g
req req boolToInt
fullApply
copyArrays
printArrays
check
}
deq