Skip to content

Commit

Permalink
code complete: compiling
Browse files Browse the repository at this point in the history
  • Loading branch information
Drew O'Meara committed May 26, 2024
1 parent 6741c68 commit e0ab66f
Show file tree
Hide file tree
Showing 3 changed files with 97 additions and 6 deletions.
4 changes: 2 additions & 2 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ require (
github.com/gogo/protobuf v1.3.2
github.com/pkg/browser v0.0.0-20240102092130-5ac0b6a4141c
github.com/pkg/errors v0.9.1
github.com/rs/cors v1.10.1
github.com/rs/cors v1.11.0
github.com/stretchr/testify v1.9.0
golang.org/x/sync v0.7.0
)
Expand All @@ -17,7 +17,7 @@ require (
github.com/kr/pretty v0.3.1 // indirect
github.com/pmezard/go-difflib v1.0.0 // indirect
github.com/rogpeppe/go-internal v1.12.0 // indirect
golang.org/x/sys v0.19.0 // indirect
golang.org/x/sys v0.20.0 // indirect
gopkg.in/check.v1 v1.0.0-20201130134442-10cb98267c6c // indirect
gopkg.in/yaml.v3 v3.0.1 // indirect
)
8 changes: 4 additions & 4 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,8 @@ github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZN
github.com/rogpeppe/go-internal v1.9.0/go.mod h1:WtVeX8xhTBvf0smdhujwtBcq4Qrzq/fJaraNFVN+nFs=
github.com/rogpeppe/go-internal v1.12.0 h1:exVL4IDcn6na9z1rAb56Vxr+CgyK3nn3O+epU5NdKM8=
github.com/rogpeppe/go-internal v1.12.0/go.mod h1:E+RYuTGaKKdloAfM02xzb0FW3Paa99yedzYV+kq4uf4=
github.com/rs/cors v1.10.1 h1:L0uuZVXIKlI1SShY2nhFfo44TYvDPQ1w4oFkUJNfhyo=
github.com/rs/cors v1.10.1/go.mod h1:XyqrcTp5zjWr1wsJ8PIRZssZ8b/WMcMf71DJnit4EMU=
github.com/rs/cors v1.11.0 h1:0B9GE/r9Bc2UxRMMtymBkHTenPkHDv0CW4Y98GBY+po=
github.com/rs/cors v1.11.0/go.mod h1:XyqrcTp5zjWr1wsJ8PIRZssZ8b/WMcMf71DJnit4EMU=
github.com/stretchr/testify v1.9.0 h1:HtqpIVDClZ4nwg75+f6Lvsy/wHu+3BoSGCbBAcpTsTg=
github.com/stretchr/testify v1.9.0/go.mod h1:r2ic/lqez/lEtzL7wO/rwa5dbSLXVDPFyf8C91i36aY=
github.com/yuin/goldmark v1.1.27/go.mod h1:3hX8gzYuyVAZsxl0MRgGTJEmQBFcNTphYh9decYSb74=
Expand All @@ -48,8 +48,8 @@ golang.org/x/sys v0.0.0-20190215142949-d0b11bdaac8a/go.mod h1:STP8DvDyc/dI5b8T5h
golang.org/x/sys v0.0.0-20190412213103-97732733099d/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
golang.org/x/sys v0.0.0-20200930185726-fdedc70b468f/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
golang.org/x/sys v0.1.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
golang.org/x/sys v0.19.0 h1:q5f1RH2jigJ1MoAWp2KTp3gm5zAGFUTarQZ5U386+4o=
golang.org/x/sys v0.19.0/go.mod h1:/VUhepiaJMQUp4+oa/7Zr1D23ma6VTLIYjOOTFZPUcA=
golang.org/x/sys v0.20.0 h1:Od9JTbYCk261bKm4M/mw7AklTlFYIa0bIp9BgSm1S8Y=
golang.org/x/sys v0.20.0/go.mod h1:/VUhepiaJMQUp4+oa/7Zr1D23ma6VTLIYjOOTFZPUcA=
golang.org/x/text v0.3.0/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ=
golang.org/x/text v0.3.3/go.mod h1:5Zoc/QRtKVWzQhOtBMvqHzDpF6irO9z98xDceosuGiQ=
golang.org/x/tools v0.0.0-20180917221912-90fa682c2a6e/go.mod h1:n7NCudcB/nEzxVGmLbDWY5pfWTLqBcC2KZ6jyYvM4mQ=
Expand Down
91 changes: 91 additions & 0 deletions stdlib/tag/tag.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,99 @@ var (
const (
CanonicWithRune = '.'
CanonicHideRune = '~'

// 8 glyph slots required!
Canonic_PosZero = ' '
Canonic_Pos340 = '.'
Canonic_Pos681 = ':'
Canonic_Pos999 = '*'

Canonic_NegZero = '-'
Canonic_Neg340 = 'o'
Canonic_Neg681 = 'O'
Canonic_Neg999 = '0'
)

// Canonical ASCII digit in a tag.ID visual encoding (3 bits aka base 8)
type CanonicAsciiDigit byte

type CanonicAsciiDigit_Base8 byte
type CanonicBinaryDigit_Base8 byte

type VisualEncoding [64]CanonicAsciiDigit

var CanonicAlphabet = [8]CanonicAsciiDigit{
Canonic_PosZero,
Canonic_Pos340,
Canonic_Pos681,
Canonic_Pos999,

Canonic_NegZero,
Canonic_Neg340,
Canonic_Neg681,
Canonic_Neg999,
}

/* Loops through the bits of this tag.ID in LSB to MSB order and encodes them into a triangular visual encoding:
1: 63 62 61 60 59 58 57
56 55 54 53 52 51 50
49 48 47 46 45 44 43
42 41 40 39 38 37 36
35 34 33 32 31 30 29
28 27 26 25 24 23 22
21 20 19 18 17 16 15
8: 14 13 12 11 10 09
08 07 06 05 04
03 02 01 00
*/

func glyphsInRow(rowIndex int) int {
if rowIndex <= 7 {
return 7
} else {
return rowIndex - 7
}
}

func (id ID) BuildVisualEncoding() VisualEncoding {
enc := VisualEncoding{}
remain := id
digits := 0
for bitsRemain := 192; bitsRemain > 0; bitsRemain -= 3 {
enc[digits] = CanonicAlphabet[remain[0]&0x7]
remain[0] = (remain[1] << 61) | (remain[0] >> 3)
remain[1] = (remain[2] << 61) | (remain[1] >> 3)
digits++
}
return enc
}

func (id ID) AsciiVisualGlyph() string {
enc := id.BuildVisualEncoding()
b := strings.Builder{}
idx := 0
for rowNum := 0; true; rowNum++ {
rowLength := glyphsInRow(rowNum)
for ri := 0; ri < rowLength; ri++ {
b.WriteByte(byte(enc[idx]))
b.WriteByte(' ')
idx++
}
b.WriteRune('\n')
}
b.WriteRune('\n')

for i, digit := range enc {
if glyphsInRow(i) == 0 {
b.WriteRune('\n')
}
b.WriteByte(byte(digit))
}
return b.String()
}

type Literal struct {
ID
Token string // UTF8 human readable exact / canonical glyph or alias of ID -- 24 rune courtesy limit
Expand Down

0 comments on commit e0ab66f

Please sign in to comment.