vita.nv
· 4.6 KiB · Text
Bruto
Playground
||:: equality
|:: equality| :: evaluate :text: "
111> 111< unary equal
"
|:: seek| :: evaluate :text: "
01111 seek right
011 seek left
"
|:: constant equality| :: evaluate :text: "
1001 if
if
01
>0<
else
if
001
>0<
else
if
1001
>1<
else
0001
>0<
end
end
end
else
0
>0<
end
"
|############################################|
|# Here be dragons of the friendliest kind. #|
|############################################|
|:step: :@math: $x|
:steps: $x
|:step:? :steps: $x|
:@math: add $x 1
|:step:|
:steps: 1
|:: evaluate|
:: parse
:: run :stack: 1
:number of stacks: 10
|:: parse? :text: "halt" | :text: '@'
|:: parse? :text: "begin" | :text: '['
|:: parse? :text: "loop" | :text: ']'
|:: parse? :text: "end" | :text: ">0]<"
|:: parse? :text: "if" | :text: ">1<[>[0]<"
|:: parse? :text: "else" | :text: ">0<0]>[<"
|:: parse? :text: "drop" | :text: "[0]"
|:: parse? :text: "dup" | :text: "
if
1 1
else
0 0
end
"
|:: parse? :text: "swap"| :text: "
if
if
1 1
else
1 0
end
else
if
0 1
else
0 0
end
end
"
|:: parse? :text: "and"| :text: "
if
else
drop 0
end
"
|:: parse? :text: "or"| :text: "
if
drop 1
else
end
"
|:: parse? :text: "not"| :text: "
if
0
else
1
end
"
|:: parse? :text: "move unary value left"| :text: "
<0> begin
<1>
loop
"
|:: parse? :text: "move unary value right"| :text: "
>0< begin
>1<
loop
"
|:: parse? :text: "seek left"| :text: "[move unary value left<]"
|:: parse? :text: "seek right"| :text: "[move unary value right>]"
|:: parse? :text: "unary equal"| :text: "
>>1<<1[
if
> if
<1
else
<[]>> drop 0<<0
end
else
> if
[]> drop 0<<0
else
<0
end
end
]
>> if
<< 1
else
<< 0
end
"
|:: parse? :text: '<'| :parsed: <
|:: parse? :text: '>'| :parsed: >
|:: parse? :text: '0'| :parsed: 0
|:: parse? :text: '1'| :parsed: 1
|:: parse? :text: '['| :parsed: [
|:: parse? :text: ']'| :parsed: ]
|:: parse? :text: '@'| :parsed: @
|:: parse? :text: $x |
|:: parse? :parsed: $x| :code: $x
|:: parse|
|:: push to $x :value: $y| :stacks: $x $y
|:: push $x to $y| :stacks: $y $x
|:: peek at $x :value: $y?|
:: push $y to $x
|:: peek at $x?|
:: pop from $x
|:: pop from $x :stacks: $x $y|
:value: $y
:: reset stacks
|:: pop from $x? :stacks: $z $y|
:seen: $z $y
|:: pop from $x :default symbol: $y?|
:value: $y
:: reset stacks
|:: pop from $x|
:value: 0
:: reset stacks
|:: reset stacks? :seen: $x $y|
:stacks: $x $y
|:: reset stacks|
|:: move $direction :@math: $x|
:stack: $x
|:: move left :stack: 1 :number of stacks: $x?|
:stack: $x
|:: move left? :stack: $x|
:@math: subtract $x 1
|:: move right :stack: $x :number of stacks: $x?|
:stack: 1
|:: move right? :stack: $x|
:@math: add $x 1
|:: move $direction?|
:stack: 1
|:: compare and branch :value: 0|
:: seek forward :depth:
|:: compare and branch :value: $x|
|:: seek forward? :code: [|
:executed: [
:depth:
|:: seek forward? :code: ] :depth:? :depth:|
:executed: ]
|:: seek forward :code: ] :depth:|
:executed: ]
|:: seek forward? :code: $x|
:executed: $x
|:: seek forward|
:: stop execution :error: unbalanced loops
|:: seek backward? :executed: ]|
:code: ]
:depth:
|:: seek backward? :executed: [ :depth:? :depth:|
:code: [
|:: seek backward :executed: [ :depth:|
:code: [
|:: seek backward? :executed: $x|
:code: $x
|:: seek backward|
:: stop execution :error: unbalanced loops
|:: step :code: <|
:executed: <
:: move left
|:: step :code: >|
:executed: >
:: move right
|:: step :code: 0 :stack: $x?|
:executed: 0
:: push 0 to $x
|:: step :code: 1 :stack: $x?|
:executed: 1
:: push 1 to $x
|:: step :code: [ :stack: $x?|
:executed: [
:: pop from $x
:: compare and branch
|:: step :code: ]?|
:: seek backward :depth:
|:: step :code: @| :halt:
|:: step :code: $x|
|:: step| :halt:
|:: run :halt:|
:: clean up
|:: run?|
:: step :step:
|:: clean up? :executed: $x|
|:: clean up? :code: $x|
|:: clean up|
| 1 | ||:: equality |
| 2 | |
| 3 | |:: equality| :: evaluate :text: " |
| 4 | 111> 111< unary equal |
| 5 | " |
| 6 | |
| 7 | |:: seek| :: evaluate :text: " |
| 8 | 01111 seek right |
| 9 | 011 seek left |
| 10 | " |
| 11 | |
| 12 | |:: constant equality| :: evaluate :text: " |
| 13 | 1001 if |
| 14 | if |
| 15 | 01 |
| 16 | >0< |
| 17 | else |
| 18 | if |
| 19 | 001 |
| 20 | >0< |
| 21 | else |
| 22 | if |
| 23 | 1001 |
| 24 | >1< |
| 25 | else |
| 26 | 0001 |
| 27 | >0< |
| 28 | end |
| 29 | end |
| 30 | end |
| 31 | else |
| 32 | 0 |
| 33 | >0< |
| 34 | end |
| 35 | " |
| 36 | |
| 37 | |
| 38 | |
| 39 | |
| 40 | |############################################| |
| 41 | |# Here be dragons of the friendliest kind. #| |
| 42 | |############################################| |
| 43 | |
| 44 | |
| 45 | |:step: :@math: $x| |
| 46 | :steps: $x |
| 47 | |:step:? :steps: $x| |
| 48 | :@math: add $x 1 |
| 49 | |:step:| |
| 50 | :steps: 1 |
| 51 | |
| 52 | |:: evaluate| |
| 53 | :: parse |
| 54 | :: run :stack: 1 |
| 55 | :number of stacks: 10 |
| 56 | |
| 57 | |:: parse? :text: "halt" | :text: '@' |
| 58 | |:: parse? :text: "begin" | :text: '[' |
| 59 | |:: parse? :text: "loop" | :text: ']' |
| 60 | |:: parse? :text: "end" | :text: ">0]<" |
| 61 | |:: parse? :text: "if" | :text: ">1<[>[0]<" |
| 62 | |:: parse? :text: "else" | :text: ">0<0]>[<" |
| 63 | |
| 64 | |:: parse? :text: "drop" | :text: "[0]" |
| 65 | |:: parse? :text: "dup" | :text: " |
| 66 | if |
| 67 | 1 1 |
| 68 | else |
| 69 | 0 0 |
| 70 | end |
| 71 | " |
| 72 | |:: parse? :text: "swap"| :text: " |
| 73 | if |
| 74 | if |
| 75 | 1 1 |
| 76 | else |
| 77 | 1 0 |
| 78 | end |
| 79 | else |
| 80 | if |
| 81 | 0 1 |
| 82 | else |
| 83 | 0 0 |
| 84 | end |
| 85 | end |
| 86 | " |
| 87 | |:: parse? :text: "and"| :text: " |
| 88 | if |
| 89 | else |
| 90 | drop 0 |
| 91 | end |
| 92 | " |
| 93 | |
| 94 | |:: parse? :text: "or"| :text: " |
| 95 | if |
| 96 | drop 1 |
| 97 | else |
| 98 | end |
| 99 | " |
| 100 | |
| 101 | |:: parse? :text: "not"| :text: " |
| 102 | if |
| 103 | 0 |
| 104 | else |
| 105 | 1 |
| 106 | end |
| 107 | " |
| 108 | |
| 109 | |:: parse? :text: "move unary value left"| :text: " |
| 110 | <0> begin |
| 111 | <1> |
| 112 | loop |
| 113 | " |
| 114 | |
| 115 | |:: parse? :text: "move unary value right"| :text: " |
| 116 | >0< begin |
| 117 | >1< |
| 118 | loop |
| 119 | " |
| 120 | |
| 121 | |:: parse? :text: "seek left"| :text: "[move unary value left<]" |
| 122 | |:: parse? :text: "seek right"| :text: "[move unary value right>]" |
| 123 | |
| 124 | |:: parse? :text: "unary equal"| :text: " |
| 125 | >>1<<1[ |
| 126 | if |
| 127 | > if |
| 128 | <1 |
| 129 | else |
| 130 | <[]>> drop 0<<0 |
| 131 | end |
| 132 | else |
| 133 | > if |
| 134 | []> drop 0<<0 |
| 135 | else |
| 136 | <0 |
| 137 | end |
| 138 | end |
| 139 | ] |
| 140 | >> if |
| 141 | << 1 |
| 142 | else |
| 143 | << 0 |
| 144 | end |
| 145 | " |
| 146 | |
| 147 | |:: parse? :text: '<'| :parsed: < |
| 148 | |:: parse? :text: '>'| :parsed: > |
| 149 | |:: parse? :text: '0'| :parsed: 0 |
| 150 | |:: parse? :text: '1'| :parsed: 1 |
| 151 | |:: parse? :text: '['| :parsed: [ |
| 152 | |:: parse? :text: ']'| :parsed: ] |
| 153 | |:: parse? :text: '@'| :parsed: @ |
| 154 | |:: parse? :text: $x | |
| 155 | |:: parse? :parsed: $x| :code: $x |
| 156 | |:: parse| |
| 157 | |
| 158 | |:: push to $x :value: $y| :stacks: $x $y |
| 159 | |:: push $x to $y| :stacks: $y $x |
| 160 | |
| 161 | |:: peek at $x :value: $y?| |
| 162 | :: push $y to $x |
| 163 | |:: peek at $x?| |
| 164 | :: pop from $x |
| 165 | |
| 166 | |:: pop from $x :stacks: $x $y| |
| 167 | :value: $y |
| 168 | :: reset stacks |
| 169 | |:: pop from $x? :stacks: $z $y| |
| 170 | :seen: $z $y |
| 171 | |:: pop from $x :default symbol: $y?| |
| 172 | :value: $y |
| 173 | :: reset stacks |
| 174 | |:: pop from $x| |
| 175 | :value: 0 |
| 176 | :: reset stacks |
| 177 | |
| 178 | |:: reset stacks? :seen: $x $y| |
| 179 | :stacks: $x $y |
| 180 | |:: reset stacks| |
| 181 | |
| 182 | |:: move $direction :@math: $x| |
| 183 | :stack: $x |
| 184 | |:: move left :stack: 1 :number of stacks: $x?| |
| 185 | :stack: $x |
| 186 | |:: move left? :stack: $x| |
| 187 | :@math: subtract $x 1 |
| 188 | |:: move right :stack: $x :number of stacks: $x?| |
| 189 | :stack: 1 |
| 190 | |:: move right? :stack: $x| |
| 191 | :@math: add $x 1 |
| 192 | |:: move $direction?| |
| 193 | :stack: 1 |
| 194 | |
| 195 | |:: compare and branch :value: 0| |
| 196 | :: seek forward :depth: |
| 197 | |:: compare and branch :value: $x| |
| 198 | |
| 199 | |:: seek forward? :code: [| |
| 200 | :executed: [ |
| 201 | :depth: |
| 202 | |:: seek forward? :code: ] :depth:? :depth:| |
| 203 | :executed: ] |
| 204 | |:: seek forward :code: ] :depth:| |
| 205 | :executed: ] |
| 206 | |:: seek forward? :code: $x| |
| 207 | :executed: $x |
| 208 | |:: seek forward| |
| 209 | :: stop execution :error: unbalanced loops |
| 210 | |
| 211 | |:: seek backward? :executed: ]| |
| 212 | :code: ] |
| 213 | :depth: |
| 214 | |:: seek backward? :executed: [ :depth:? :depth:| |
| 215 | :code: [ |
| 216 | |:: seek backward :executed: [ :depth:| |
| 217 | :code: [ |
| 218 | |:: seek backward? :executed: $x| |
| 219 | :code: $x |
| 220 | |:: seek backward| |
| 221 | :: stop execution :error: unbalanced loops |
| 222 | |
| 223 | |:: step :code: <| |
| 224 | :executed: < |
| 225 | :: move left |
| 226 | |:: step :code: >| |
| 227 | :executed: > |
| 228 | :: move right |
| 229 | |:: step :code: 0 :stack: $x?| |
| 230 | :executed: 0 |
| 231 | :: push 0 to $x |
| 232 | |:: step :code: 1 :stack: $x?| |
| 233 | :executed: 1 |
| 234 | :: push 1 to $x |
| 235 | |:: step :code: [ :stack: $x?| |
| 236 | :executed: [ |
| 237 | :: pop from $x |
| 238 | :: compare and branch |
| 239 | |:: step :code: ]?| |
| 240 | :: seek backward :depth: |
| 241 | |:: step :code: @| :halt: |
| 242 | |:: step :code: $x| |
| 243 | |:: step| :halt: |
| 244 | |
| 245 | |:: run :halt:| |
| 246 | :: clean up |
| 247 | |:: run?| |
| 248 | :: step :step: |
| 249 | |
| 250 | |:: clean up? :executed: $x| |
| 251 | |:: clean up? :code: $x| |
| 252 | |:: clean up| |