Advertisement
GopherAtl

rlvm spec draft

Apr 10th, 2014
134
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.98 KB | None | 0 0
  1. RL - robot language, low-level language run by vm, generally compatible with CC trutles or OC robots
  2. (though individual programs may depend on features exclusive to one or the other)
  3.  
  4. HLRL - high level robot language, a higher-level language which is compiled down to RL.
  5.  
  6. RL has 3 usable registers, b, n, and s, of types bool, number, and string, respectively.
  7. There are also 3 stacks, again, one for each type, used in compound operations.
  8. for the purpose of these instructions, in addition to b, n, and s, sb, sn, and ss will be used
  9. to refer to the values on top of the bool, number, and string stacks, respectively. Unless otherwise stated
  10. any instruction definition that includes sn is implied to have popped a value from the n stack, and same
  11. with ss and sb for the string and boolean stacks. Result values are never automatically pushed to the stack,
  12. but go in the register of the corresponding type, replacing any current value.
  13.  
  14. RL can be written in an asm-like notation, but is executed in a kind of bytecode format.
  15. In RL bytecode, integer literals are encoded as base 64, prefixed with the # symbol followed by the number of
  16. bytes of the numeric literal.
  17.  
  18. Arguments:
  19. side - one of the 6 sides or directions, relative to the robot. u, d, l, r, f, or b.
  20. direction - the four cardinal directions, N, S, E, or W
  21. side4 - the four sides within the plane, like direction but relative to the robot. l,r,f, or b.
  22. axis - x, y, or z, one of the three cardinal axes
  23. reg - one of the three registers, n, b, or s
  24. slot - hex digit, 0-F, for slot # (0=1, F=16)
  25. instructions:
  26.  
  27. immediate values:
  28. #number numeric literals (in bytecode, prefixed with # and a length)
  29. 'string string literals (in bytecode, prefixed with ' and the length, as a single base-64 digit,
  30. giving a max string literal len of 64)
  31. true/false boolean literals ("0" and "1", in bytecode)
  32.  
  33. imm can be any of the 3 immediate types
  34.  
  35.  
  36. robot instructions
  37. M move <side> <#dist>
  38. F face <side4|dir>
  39. D dig <side>
  40. U use <side>
  41. P place <side> <slot>
  42. R drop <side> <slot> <#count>
  43. S suck <side>
  44. G goto <axis> <#coord>
  45. C compare <side> <slot>
  46. T detect <side> <slot>
  47.  
  48. Stack instructions
  49. H push <reg> push a value to the stack of the same type
  50. O pop <reg>
  51. K peek <reg> <#offset> grabs the item #offset from the top of stack (1 = top)
  52. B burn <reg> <#count> burns #count values off the top of the stack of the same type as reg,
  53. without affecting reg
  54.  
  55. operations:
  56. numeric
  57. > gt b=sn>n
  58. < lt b=sn<n
  59. + add n=sn+n
  60. - sub n=sn-n
  61. ^ pow n=sn^n
  62.  
  63. boolean
  64. ! not b=~b
  65. & and b=sb and b
  66. | or b=sb or b
  67.  
  68. common (apply to all three types)
  69. = eq <reg> b = st==t (t can be n, b, or s)
  70.  
  71. flow control
  72. J jump <#addr> jump to address in program
  73. I jif <#addr> jump to address only if b==true
  74. L call <#addr> pushes address of next instruction to special call stack then jumps to address
  75. N return pops and jumps to address on top of call stack
  76.  
  77. other...
  78. V load <imm>
  79. . print <reg>
  80.  
  81. Example programs:
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement