package iskra // Rotation encodes transitions on the ternary code lattice. // // type (1) // / \ // left right // / \ // data (3) -------- func (2) // // Right = clockwise: T→F, F→D, D→T // Left = counterclockwise: T→D, D→F, F→T // Stay = same branch // // Punctuation operators mark structural boundaries in code: // block-open ({) = enter sub-scope // block-close (}) = leave sub-scope // separator (;) = statement boundary // list (,) = parameter/argument list type Rotation uint8 const ( RotUnknown Rotation = 0 RotRight Rotation = 1 RotLeft Rotation = 2 RotStay Rotation = 3 RotBlockOpen Rotation = 4 RotBlockClose Rotation = 5 RotSeparator Rotation = 6 RotList Rotation = 7 ) func BranchRotation(from, to uint8) Rotation { if from < BranchType || from > BranchData || to < BranchType || to > BranchData { return RotUnknown } if from == to { return RotStay } if to == (from%3)+1 { return RotRight } return RotLeft } func (r Rotation) IsStructural() bool { return r >= RotBlockOpen } func (r Rotation) String() string { switch r { case RotRight: return "right" case RotLeft: return "left" case RotStay: return "stay" case RotBlockOpen: return "{" case RotBlockClose: return "}" case RotSeparator: return ";" case RotList: return "," default: return "?" } } func (m *MetaEntry) SetRotation(r Rotation) { m.Extra[4] = (m.Extra[4] & 0xF0) | byte(r&0x0F) } func (m *MetaEntry) GetRotation() Rotation { return Rotation(m.Extra[4] & 0x0F) } func (m *MetaEntry) SetBigramTransition(rot Rotation, targetPath TritPath) { m.SetTritPath(targetPath) m.SetRotation(rot) } func (m *MetaEntry) GetBigramTransition() (Rotation, TritPath) { return m.GetRotation(), m.GetTritPath() }