Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- $include $lib/case
- lvar code (user program)
- lvar d_stack (data stack)
- lvar pc (program counter)
- lvar output (output string)
- lvar ram (variables)
- lvar temp
- : dpush (data stack push)
- d_stack @ array_appenditem d_stack !
- ;
- : dpop (data stack pop)
- d_stack @ dup array_last pop array_getitem
- d_stack @ dup array_last pop array_delitem d_stack !
- ;
- : nextchar
- code @ pc @ 1 midstr
- pc ++
- ;
- : goback
- pc --
- ;
- : isdigit?
- ctoi dup 48 >= swap 57 <= and
- ;
- : run
- begin
- ( get a character )
- nextchar
- case
- ctoi dup 97 >= swap 122 <= and when goback nextchar ctoi 97 - dpush end (variable references)
- isdigit? when
- goback
- 0
- begin
- nextchar dup
- isdigit? not if
- break
- then
- ctoi 48 - swap 10 * +
- repeat
- goback pop dpush
- end
- "'" strcmp not when nextchar ctoi dpush end
- "+" strcmp not when dpop dpop + dpush end
- "*" strcmp not when dpop dpop * dpush end
- "&" strcmp not when dpop dpop bitand dpush end
- "|" strcmp not when dpop dpop bitor dpush end
- "^" strcmp not when dpop dpop bitxor dpush end (extension: xor)
- "_" strcmp not when 0 dpop - dpush end
- "-" strcmp not when dpop dpop swap - dpush end
- "/" strcmp not when dpop dpop swap / dpush end
- "M" strcmp not when dpop dpop swap % dpush end (extension: modulo)
- ">" strcmp not when 0 dpop dpop swap > - dpush end
- "<" strcmp not when 0 dpop dpop swap < - dpush end
- "=" strcmp not when 0 dpop dpop swap = - dpush end
- "$" strcmp not when dpop dup dpush dpush end
- "V" strcmp not when dpop dpop dup dpush swap dpush dpush end (extension: over)
- "%" strcmp not when dpop end
- "\\" strcmp not when dpop dpop swap dpush dpush end
- "." strcmp not when output @ dpop intostr strcat output ! end
- "," strcmp not when output @ dpop itoc strcat output ! end
- ":" strcmp not when dpop temp ! dpop ram @ temp @ array_setitem ram ! end
- ";" strcmp not when ram @ dpop array_getitem dpush end
- "!" strcmp not when pc @ dpop pc ! run pc ! end
- "?" strcmp not when pc @ dpop pc ! dpop if run then pc ! end
- "T" strcmp not when pc @ dpop pc ! dpop temp ! dpop if temp @ pc ! then run pc ! end (extension: if/else)
- "O" strcmp not when d_stack @ dup array_count dpop - -- array_getitem dpush end (pick)
- "#" strcmp not when
- pc @ dpop dpop
- begin
- dup pc ! run
- dpop not if break then
- over pc ! run
- repeat
- pop pop pc !
- end
- "[" strcmp not when
- pc @ dpush (push start of lambda)
- 1 temp !
- begin
- nextchar dup
- "[" strcmp not if temp ++ then
- "]" strcmp not if temp -- then
- temp @ 0 =
- until
- end
- "]" strcmp not when 99999 pc ! end ("break" didn't work)
- "@" strcmp not when dpop dpop dpop -3 rotate dpush dpush dpush end
- "{" strcmp not when begin nextchar "}" strcmp not until end
- "\"" strcmp not when
- begin
- nextchar dup
- "\"" strcmp not if
- break
- then
- output @ swap strcat output !
- repeat
- pop
- end
- "~" strcmp not when 0 dpop - -- dpush end
- endcase
- pc @ code @ strlen >
- until
- ;
- : main
- code !
- { }list d_stack !
- { 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 }list ram !
- 1 pc !
- "" output !
- run
- me @ "FALSE: " output @ strcat notify
- ;
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement