A Fidget-Symbol based Brainfuck Dialect
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

instr.go 2.1KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127
  1. package fidgetlang
  2. type instruction byte
  3. const (
  4. iIncrPtr instruction = 1 << iota
  5. iDecrPtr
  6. iIncrVal
  7. iDecrVal
  8. iPutVal
  9. iGetVal
  10. iJumpAhead
  11. iJumpBehind
  12. iNop instruction = 0
  13. sIncrPtr = "߷"
  14. sDecrPtr = "߷߷"
  15. sIncrVal = "߷߷߷"
  16. sDecrVal = "߷߷߷߷"
  17. sPutVal = "߷߷߷߷߷"
  18. sGetVal = "߷߷߷߷߷߷"
  19. sJumpAhead = "߷߷߷߷߷߷߷"
  20. sJumpBehind = "߷߷߷߷߷߷߷߷"
  21. sNop = " "
  22. dIncrPtr = "IncrPtr"
  23. dDecrPtr = "DecrPtr"
  24. dIncrVal = "IncrVal"
  25. dDecrVal = "DecrVal"
  26. dPutVal = "PutVal"
  27. dGetVal = "GetVal"
  28. dJumpAhead = "JumpAhead"
  29. dJumpBehind = "JumpBehind"
  30. dNop = "Nop"
  31. )
  32. func stringToInstruction(d string) instruction {
  33. switch d {
  34. case sIncrPtr:
  35. return iIncrPtr
  36. case sDecrPtr:
  37. return iDecrPtr
  38. case sIncrVal:
  39. return iIncrVal
  40. case sDecrVal:
  41. return iDecrVal
  42. case sPutVal:
  43. return iPutVal
  44. case sGetVal:
  45. return iGetVal
  46. case sJumpAhead:
  47. return iJumpAhead
  48. case sJumpBehind:
  49. return iJumpBehind
  50. default:
  51. return iNop
  52. }
  53. }
  54. func instructionToString(i instruction) string {
  55. switch i {
  56. case iIncrPtr:
  57. return sIncrPtr
  58. case iDecrPtr:
  59. return sDecrPtr
  60. case iIncrVal:
  61. return sIncrVal
  62. case iDecrVal:
  63. return sDecrVal
  64. case iPutVal:
  65. return sPutVal
  66. case iGetVal:
  67. return sGetVal
  68. case iJumpAhead:
  69. return sJumpAhead
  70. case iJumpBehind:
  71. return sJumpBehind
  72. default:
  73. return sNop
  74. }
  75. }
  76. func debugToInstruction(d string) instruction {
  77. switch d {
  78. case dIncrPtr:
  79. return iIncrPtr
  80. case dDecrPtr:
  81. return iDecrPtr
  82. case dIncrVal:
  83. return iIncrVal
  84. case dDecrVal:
  85. return iDecrVal
  86. case dPutVal:
  87. return iPutVal
  88. case dGetVal:
  89. return iGetVal
  90. case dJumpAhead:
  91. return iJumpAhead
  92. case dJumpBehind:
  93. return iJumpBehind
  94. default:
  95. return iNop
  96. }
  97. }
  98. func instructionToDebug(i instruction) string {
  99. switch i {
  100. case iIncrPtr:
  101. return dIncrPtr
  102. case iDecrPtr:
  103. return dDecrPtr
  104. case iIncrVal:
  105. return dIncrVal
  106. case iDecrVal:
  107. return dDecrVal
  108. case iPutVal:
  109. return dPutVal
  110. case iGetVal:
  111. return dGetVal
  112. case iJumpAhead:
  113. return dJumpAhead
  114. case iJumpBehind:
  115. return dJumpBehind
  116. default:
  117. return dNop
  118. }
  119. }