gene.hoon 5.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394
  1. /- *sock
  2. |%
  3. +| %ska
  4. +$ barn [sub=sock for=*]
  5. +$ nomm :: SKA-analyzed nock
  6. $~ [%one **]
  7. $% [%par nomm nomm]
  8. [%zer @ ?] :: safety-tagged lookup
  9. [%one *]
  10. [%two nomm nomm sock (unit *) ?] :: subject knowledge and known formula, safety-tag on metaformula
  11. [%thr nomm]
  12. [%fou nomm ?] :: safety-tagged increment
  13. [%fiv nomm nomm]
  14. [%six nomm nomm nomm]
  15. [%sev nomm nomm]
  16. :: we omit 8, translating it to 7 + autocons
  17. :: we omit 9, translating it to 7 + 2
  18. [%ten [@ nomm] nomm ?] :: safety-tagged edit
  19. [%els @ nomm]
  20. [%eld [@ nomm] nomm ?] :: safety-tagged hint formula
  21. [%twe nomm nomm]
  22. ==
  23. +$ farm [yard=(map barn [does=nomm says=boot]) wood=(list barn)]
  24. +| %lin
  25. +$ berm [sub=sock for=* ax=@ gen=@tas] :: local label
  26. +$ plow :: noun<->ssa map
  27. $% [%fork left=plow rite=plow safe=?] :: cons of two mappings
  28. [%tine @] :: use this SSA value at this axis
  29. [%disc ~] :: no uses here or below
  30. ==
  31. +$ line :: destination
  32. $% [%moat wher=berm what=plow] :: place result in SSA values specified by what, go wher
  33. [%rift troo=berm fals=berm] :: branch on result
  34. [%pond ~] :: tail position, return result in a register
  35. ==
  36. +$ bran :: instructions in a block
  37. $% [%imm * @] :: Write a noun to an SSA value
  38. [%mov @ @] :: Copy an SSA value
  39. [%inc @ @] :: Define second SSA register as increment of first
  40. [%unc @ @] :: Define a second SSA register as increment of first, without checking atomicity
  41. [%con @ @ @] :: Construct a cell, first SSA head, second SSA tail, third SSA result
  42. [%hed @ @] :: Take the head of first SSA and place in second.
  43. :: Crash if first SSA not a cell
  44. [%hud @ @] :: Take the head of the first SSA, known to be a cell
  45. [%tal @ @] :: Take tail head of first SSA and place in second.
  46. :: Crash if first SSA not a cell
  47. [%tul @ @] :: Take the tail of the first SSA, known to be a cell
  48. ==
  49. :: These instructions end a block.
  50. :: A block ends either because we need to transfer control
  51. :: elsewhere (hop), we need to branch (clq, eqq, brn), we need a saved
  52. :: control point to return to (lnk, call, hnt, spy), or we are done and
  53. :: transfering control to another arm (jmp, lnt), our caller (don), or
  54. :: the crash handler (bom).
  55. ::
  56. :: The bec and eye instructions are intermediate forms only, and are
  57. :: translated into cal and jmp respectively once enough information is
  58. :: available about their targets. They exist because when linearizing
  59. :: and registerizing (mutually) recursive arms, there will be some call
  60. :: targets for which we do not know subject use maps and thus cannot yet
  61. :: build calls to. Once all arms are registerized, we scan for bec and
  62. :: eye and replace them with jmp and call with registers appropriately
  63. :: split.
  64. +$ germ :: instructions ending a block
  65. $% [%clq @ berm berm] :: Branch left if the SSA value is a cell, right otherwise
  66. [%eqq @ @ berm berm] :: Branch left if SSA registers are equal, right otherwise
  67. [%brn @ berm berm] :: Branch left if SSA register is 0, right if 1
  68. [%hop berm] :: Go to berm unconditionally (local direct jump)
  69. [%lnk @ @ @ berm] :: Call formula in first SSA register with subject in second,
  70. :: result in third, return to berm
  71. [%cal barn (list @) @ berm] :: Call arm given by barn, subject in first SSA register,
  72. :: result in second, return to berm
  73. [%bec barn @ @ berm] :: Not quite a call: we need to know the subject registerization of an arm.
  74. :: see %eye
  75. [%lnt @ @] :: Jump to formula in first SSA register with subject in second
  76. [%jmp barn (list @)] :: Jump to the code at the label in tail position,
  77. :: with the subject in the SSA register
  78. [%eye barn @] :: Look before you jump: we need to know the subject registerization of an arm
  79. :: before we jump to it. Until then, here's a register with
  80. :: the whole subject
  81. [%spy @ @ @ berm] :: Scry with the ref/path pair in the first 2 SSA registers
  82. :: define the third as the result
  83. [%hnt @ berm] :: Treat the result in the SSA register as a hint and continue to the given label
  84. [%don @] :: Finish the procedure, returning the value in the SSA
  85. [%bom ~] :: Crash
  86. ==
  87. +$ pool (list [axe=@ ssa=@ saf=?]) :: entry point subject uses: ordered subject/ssa/safety
  88. +$ lock [body=(list bran) bend=germ] :: basic block: instructions + a terminator or branch
  89. +$ lake (map berm lock) :: code table of basic blocks
  90. +$ rice [goes=lake uses=pool lump=@] :: entry information and code table for an arm
  91. +$ sack [does=rice says=boot] :: code table entry: basic blocks + SKA result for an arm
  92. +$ town [land=(map barn sack) lamb=@] :: code table
  93. --