Execute Brain****: Difference between revisions
updated syntax
Drkameleon (talk | contribs) (updated syntax) |
|||
Line 1,385:
=={{header|Arturo}}==
<lang arturo>
;
Tape
DataPointer:
InstructionPointer:
precomputeJumps:
vstack: new []
stack : #()▼
jumphash:
instrPointer
command:
if? command="["
else
if command="]"
set jumphash
instrPointer: instrPointer+1
jumphash
]
StateIsValid: function [][
all? @[
// Compile the program▼
DataPointer < size Tape
InstructionPointer < CodeLength
loop [StateIsValid ~] {▼
command: [chars Code].[InstructionPointer]▼
]
if command="+" -> Tape.[DataPointer]: Tape.[DataPointer]+1▼
if command="-" -> Tape.[DataPointer]: Tape.[DataPointer]-1▼
if command=">" { DataPointer: DataPointer+1, if DataPointer=[size Tape] -> Tape: Tape+0 }▼
if command="<" -> DataPointer: DataPointer-1▼
if command="." -> prints [char Tape.[DataPointer]]▼
if command="," {▼
inp: toNumber|input ~▼
if inp=13 { inp: 10 }▼
if inp=3 { panic "something went wrong!" }▼
▲ Tape.DataPointer: inp
▲ }
if command="[" {▼
if Tape.[DataPointer]=0 -> InstructionPointer: Jumps.[toString InstructionPointer]▼
}▼
if command="]" {▼
if Tape.[DataPointer]!=0 -> InstructionPointer: Jumps.[toString InstructionPointer]▼
}▼
▲ InstructionPointer: InstructionPointer+1
▲ }
interpret: function [].export:[DataPointer,InstructionPointer,Tape][
inc 'DataPointer
when? [","][
set Tape DataPointer inp
▲ if 0 = get Tape
if 0 <> get Tape DataPointer [
inc 'InstructionPointer
]
]
Code: ""
if? 1>size arg -> Code: "++++++++++[>+++++++>++++++++++>+++>+<<<<-]>++.>+.+++++++..+++.>++.<<+++++++++++++++.>.+++.------.--------.>+.>."
else -> Code: read arg\0
▲Code : read &0
▲CodeLength : size Code
▲Jumps : precomputeJumps ~
interpret
{{in}}
|