A minimalistic programming language written in C89.
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.

73 lines
1.7 KiB

6 months ago
  1. fn potato do sys.trace return end
  2. fn print_n_utf8_impl do
  3. start:
  4. -1 + swap print_utf8
  5. dup start swap jump_if
  6. end
  7. fn potato2 do
  8. start:
  9. -1 + dup
  10. 65 print_utf8 10 print_utf8
  11. start swap jump_if
  12. end
  13. fn potato3 do
  14. start:
  15. -1 + dup
  16. 66 print_utf8 10 print_utf8
  17. start swap jump_if
  18. end
  19. # Encrypts things by doing `(v + add_key) % modulo_key`
  20. #
  21. # @param array An array of ints representing a string
  22. # @param add_key Should be lower than the add key
  23. # @param modulo_key Should ke higher than all the codepoints of the array
  24. #
  25. # array add_key modulo_key
  26. fn encrypt do
  27. 3 pluck array.size
  28. # array add_key modulo_key index
  29. loop:
  30. 1 - dup 5 pluck
  31. # array add_key modulo_key index index array
  32. array.index
  33. # array add_key modulo_key index v
  34. 4 pluck +
  35. # array add_key modulo_key index (v + add_key)
  36. 3 pluck %
  37. # array add_key modulo_key index ((v + add_key) % modulo_key)
  38. 2 pluck
  39. # array add_key modulo_key index ((v + add_key) % modulo_key) index
  40. 6 pluck
  41. # array add_key modulo_key index ((v + add_key) % modulo_key) index array
  42. array.set
  43. # array add_key modulo_key index
  44. dup 0 != loop jump_if drop drop drop drop
  45. end
  46. # Prints a string as an array of ints
  47. #
  48. # @param array An array of ints representing a string
  49. #
  50. # array
  51. fn string.dump do
  52. dup array.size 0
  53. # array end it
  54. 91 print_utf8
  55. 32 print_utf8
  56. loop:
  57. dup
  58. # array end it it
  59. 4 pluck
  60. # array end it it array
  61. array.index print_int
  62. 32 print_utf8
  63. 1 +
  64. # array end it
  65. 2 pluck 2 pluck > loop jump_if
  66. # array end it
  67. 93 print_utf8
  68. drop drop drop
  69. end