vita.nv
· 3.4 KiB · Text
原始文件
Playground
||:: evaluate :text: "
1 0 swap dup and not drop
"
|############################################|
|# Here be dragons of the friendliest kind. #|
|############################################|
|:: 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: '<'| :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|
:: stop execution :error: pop from an empty or nonexistent stack $x
|:: 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
|:: clean up? :executed: $x|
|:: clean up? :code: $x|
|:: clean up|
| 1 | ||:: evaluate :text: " |
| 2 | 1 0 swap dup and not drop |
| 3 | " |
| 4 | |
| 5 | |
| 6 | |
| 7 | |
| 8 | |############################################| |
| 9 | |# Here be dragons of the friendliest kind. #| |
| 10 | |############################################| |
| 11 | |
| 12 | |:: evaluate| |
| 13 | :: parse |
| 14 | :: run :stack: 1 |
| 15 | :number of stacks: 10 |
| 16 | |
| 17 | |:: parse? :text: "halt" | :text: '@' |
| 18 | |:: parse? :text: "begin" | :text: '[' |
| 19 | |:: parse? :text: "loop" | :text: ']' |
| 20 | |:: parse? :text: "end" | :text: ">0]<" |
| 21 | |:: parse? :text: "if" | :text: ">1<[>[0]<" |
| 22 | |:: parse? :text: "else" | :text: ">0<0]>[<" |
| 23 | |
| 24 | |:: parse? :text: "drop" | :text: "[0]" |
| 25 | |:: parse? :text: "dup" | :text: " |
| 26 | if |
| 27 | 1 1 |
| 28 | else |
| 29 | 0 0 |
| 30 | end |
| 31 | " |
| 32 | |:: parse? :text: "swap"| :text: " |
| 33 | if |
| 34 | if |
| 35 | 1 1 |
| 36 | else |
| 37 | 1 0 |
| 38 | end |
| 39 | else |
| 40 | if |
| 41 | 0 1 |
| 42 | else |
| 43 | 0 0 |
| 44 | end |
| 45 | end |
| 46 | " |
| 47 | |:: parse? :text: "and"| :text: " |
| 48 | if |
| 49 | else |
| 50 | drop 0 |
| 51 | end |
| 52 | " |
| 53 | |
| 54 | |:: parse? :text: "or"| :text: " |
| 55 | if |
| 56 | drop 1 |
| 57 | else |
| 58 | end |
| 59 | " |
| 60 | |
| 61 | |:: parse? :text: "not"| :text: " |
| 62 | if |
| 63 | 0 |
| 64 | else |
| 65 | 1 |
| 66 | end |
| 67 | " |
| 68 | |
| 69 | |:: parse? :text: '<'| :parsed: < |
| 70 | |:: parse? :text: '>'| :parsed: > |
| 71 | |:: parse? :text: '0'| :parsed: 0 |
| 72 | |:: parse? :text: '1'| :parsed: 1 |
| 73 | |:: parse? :text: '['| :parsed: [ |
| 74 | |:: parse? :text: ']'| :parsed: ] |
| 75 | |:: parse? :text: '@'| :parsed: @ |
| 76 | |:: parse? :text: $x | |
| 77 | |:: parse? :parsed: $x| :code: $x |
| 78 | |:: parse| |
| 79 | |
| 80 | |:: push to $x :value: $y| :stacks: $x $y |
| 81 | |:: push $x to $y| :stacks: $y $x |
| 82 | |
| 83 | |:: peek at $x :value: $y?| |
| 84 | :: push $y to $x |
| 85 | |:: peek at $x?| |
| 86 | :: pop from $x |
| 87 | |
| 88 | |:: pop from $x :stacks: $x $y| |
| 89 | :value: $y |
| 90 | :: reset stacks |
| 91 | |:: pop from $x? :stacks: $z $y| |
| 92 | :seen: $z $y |
| 93 | |:: pop from $x :default symbol: $y?| |
| 94 | :value: $y |
| 95 | :: reset stacks |
| 96 | |:: pop from $x| |
| 97 | :: stop execution :error: pop from an empty or nonexistent stack $x |
| 98 | |
| 99 | |:: reset stacks? :seen: $x $y| |
| 100 | :stacks: $x $y |
| 101 | |:: reset stacks| |
| 102 | |
| 103 | |:: move $direction :@math: $x| |
| 104 | :stack: $x |
| 105 | |:: move left :stack: 1 :number of stacks: $x?| |
| 106 | :stack: $x |
| 107 | |:: move left? :stack: $x| |
| 108 | :@math: subtract $x 1 |
| 109 | |:: move right :stack: $x :number of stacks: $x?| |
| 110 | :stack: 1 |
| 111 | |:: move right? :stack: $x| |
| 112 | :@math: add $x 1 |
| 113 | |:: move $direction?| |
| 114 | :stack: 1 |
| 115 | |
| 116 | |:: compare and branch :value: 0| |
| 117 | :: seek forward :depth: |
| 118 | |:: compare and branch :value: $x| |
| 119 | |
| 120 | |:: seek forward? :code: [| |
| 121 | :executed: [ |
| 122 | :depth: |
| 123 | |:: seek forward? :code: ] :depth:? :depth:| |
| 124 | :executed: ] |
| 125 | |:: seek forward :code: ] :depth:| |
| 126 | :executed: ] |
| 127 | |:: seek forward? :code: $x| |
| 128 | :executed: $x |
| 129 | |:: seek forward| |
| 130 | :: stop execution :error: unbalanced loops |
| 131 | |
| 132 | |:: seek backward? :executed: ]| |
| 133 | :code: ] |
| 134 | :depth: |
| 135 | |:: seek backward? :executed: [ :depth:? :depth:| |
| 136 | :code: [ |
| 137 | |:: seek backward :executed: [ :depth:| |
| 138 | :code: [ |
| 139 | |:: seek backward? :executed: $x| |
| 140 | :code: $x |
| 141 | |:: seek backward| |
| 142 | :: stop execution :error: unbalanced loops |
| 143 | |
| 144 | |:: step :code: <| |
| 145 | :executed: < |
| 146 | :: move left |
| 147 | |:: step :code: >| |
| 148 | :executed: > |
| 149 | :: move right |
| 150 | |:: step :code: 0 :stack: $x?| |
| 151 | :executed: 0 |
| 152 | :: push 0 to $x |
| 153 | |:: step :code: 1 :stack: $x?| |
| 154 | :executed: 1 |
| 155 | :: push 1 to $x |
| 156 | |:: step :code: [ :stack: $x?| |
| 157 | :executed: [ |
| 158 | :: pop from $x |
| 159 | :: compare and branch |
| 160 | |:: step :code: ]?| |
| 161 | :: seek backward :depth: |
| 162 | |:: step :code: @| :halt: |
| 163 | |:: step :code: $x| |
| 164 | |:: step| :halt: |
| 165 | |
| 166 | |:: run :halt:| |
| 167 | :: clean up |
| 168 | |:: run?| |
| 169 | :: step |
| 170 | |
| 171 | |:: clean up? :executed: $x| |
| 172 | |:: clean up? :code: $x| |
| 173 | |:: clean up| |
| 174 |