Skip to content

Commit

Permalink
* tlo now contains constructors in original order (#11)
Browse files Browse the repository at this point in the history
  • Loading branch information
DedAzaMarks authored Nov 10, 2023
1 parent 906000f commit 5fd8e25
Show file tree
Hide file tree
Showing 25 changed files with 167 additions and 319 deletions.
17 changes: 3 additions & 14 deletions cmd/tlo2json/tlo2json.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,10 +11,10 @@ import (
"os"
"strings"

tls "github.com/vkcom/tl/internal/tlcodegen/gentlo/tltls"
"github.com/vkcom/tl/internal/utils"

"golang.org/x/exp/slices"

tls "github.com/vkcom/tl/internal/tlast/gentlo/tltls"
"github.com/vkcom/tl/internal/utils"
)

func main() {
Expand All @@ -41,17 +41,6 @@ func main() {
}
return strings.Compare(valAV4.Id, valBV4.Id)
})
slices.SortFunc(v4.Functions, func(a, b tls.CombinatorUnion) int {
valAV4, okA := a.AsV4()
if !okA {
panic("invalid union interpretation for tls.combinator_v4: " + valAV4.String())
}
valBV4, okB := b.AsV4()
if !okB {
panic("invalid union interpretation for tls.combinator_v4: " + valAV4.String())
}
return strings.Compare(valAV4.Id, valBV4.Id)
})
out, err := v4.WriteJSON(nil)
if err != nil {
_, _ = fmt.Fprintf(os.Stderr, "error on creating json: %v", err)
Expand Down
File renamed without changes.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions internal/tlast/gentlo/tlgen2_version.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
tlgen2 version 2022.06.30, hash of source code - 02f843f247465e376a64c154a2c95807b2dfd6e766c1a71b024dfa87f5a75449

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

21 changes: 3 additions & 18 deletions internal/tlast/qt_combined2tl.qtpl
Original file line number Diff line number Diff line change
@@ -1,23 +1,8 @@
{% import "fmt" %}
{% import "sort" %}
{%- code
func modifierToFlag(m Modifier) int32 {
switch m.Name {
case "@any":
return 0
case "@read":
return 1
case "@write":
return 2
case "@readwrite":
return 1 | 2
case "@internal":
return 4
case "@kphp":
return 8
default:
return 0
}
func compareModifiers(a, b Modifier) bool {
return modifierToFlag([]Modifier{a}) < modifierToFlag([]Modifier{b})
}
-%}

Expand All @@ -26,7 +11,7 @@ func modifierToFlag(m Modifier) int32 {
{%- code
modifiers := append([]Modifier(nil), descriptor.Modifiers...)
sort.Slice(modifiers, func(i, j int) bool {
return modifierToFlag(modifiers[i]) < modifierToFlag(modifiers[j])
return compareModifiers(modifiers[i], modifiers[j])
})
haveKphp := false
for _, m := range modifiers {
Expand Down
21 changes: 3 additions & 18 deletions internal/tlast/qt_combined2tl.qtpl.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

8 changes: 4 additions & 4 deletions internal/tlast/tldot.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ func createNode(s *strings.Builder, parent, child, nodeName string, color string
_, _ = fmt.Fprintf(s, "%s -> %s;\n", parent, child)
}

func (tl *TL) ToDot() string {
func (tl TL) ToDot() string {
var s, t, f strings.Builder
s.WriteString("digraph TL { splines=\"ortho\";\nordering=in;\ngraph[ordering=in];\n")
tlID := fmt.Sprintf("\"%pTL\"", tl)
Expand All @@ -35,9 +35,9 @@ func (tl *TL) ToDot() string {
createNode(&f, tlID, functionsID, "Functions", "white")
t.WriteString("subgraph types { ordering=in;\ngraph[ordering=in];\n")
f.WriteString("subgraph functions { ordering=in;\ngraph[ordering=in];\n")
for i := 0; i < len(*tl); i++ {
x := (*tl)[i]
id := fmt.Sprintf("\"%pCombinator\"", x)
for i := 0; i < len(tl); i++ {
x := tl[i]
id := fmt.Sprintf("\"%pCombinator\"", &x)
if x.IsFunction {
createNode(&f, functionsID, id, "Function", "white")
x.toDot(&f)
Expand Down
Loading

0 comments on commit 5fd8e25

Please sign in to comment.