Skip to content

Commit

Permalink
docs: add year range in bavard generated output by default
Browse files Browse the repository at this point in the history
  • Loading branch information
gbotrel committed Dec 10, 2024
1 parent 25ae527 commit fb19600
Show file tree
Hide file tree
Showing 4 changed files with 49 additions and 82 deletions.
15 changes: 2 additions & 13 deletions amd64/instructions.go
Original file line number Diff line number Diff line change
@@ -1,16 +1,5 @@
// Copyright 2020 ConsenSys Software Inc.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
// Copyright 2020-2024 Consensys Software Inc.
// Licensed under the Apache License, Version 2.0. See the LICENSE file for details.

// Package amd64 contains wrapper to amd64 instructions in Go assembly.
// note that while this package is public, it is tailored for github.com/consensys/goff and github.com/consensys/gurvy
Expand Down
15 changes: 2 additions & 13 deletions amd64/registers.go
Original file line number Diff line number Diff line change
@@ -1,16 +1,5 @@
// Copyright 2020 ConsenSys Software Inc.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
// Copyright 2020-2024 Consensys Software Inc.
// Licensed under the Apache License, Version 2.0. See the LICENSE file for details.

package amd64

Expand Down
36 changes: 18 additions & 18 deletions bavard.go
Original file line number Diff line number Diff line change
@@ -1,16 +1,5 @@
// Copyright 2020 ConsenSys Software Inc.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
// Copyright 2020-2024 Consensys Software Inc.
// Licensed under the Apache License, Version 2.0. See the LICENSE file for details.

// Package bavard contains helper functions to generate consistent code from text/template templates.
// it is used by github.com/consensys/gnark && github.com/consensys/gnark-crypto
Expand All @@ -28,6 +17,7 @@ import (
"strings"
"sync"
"text/template"
"time"

"rsc.io/tmplfunc"
)
Expand Down Expand Up @@ -222,11 +212,21 @@ func aggregate(values []string) string {

// Apache2Header returns a Apache2 header string
func Apache2Header(copyrightHolder string, year int) string {
apache2 := `
// Copyright %d %s
// Licensed under the Apache License, Version 2.0. See the LICENSE file for details.
`
return fmt.Sprintf(apache2, year, copyrightHolder)
// get current year from a timestamp
currentYear := time.Now().Year()
if currentYear > year {
apache2 := `
// Copyright %d-%d %s
// Licensed under the Apache License, Version 2.0. See the LICENSE file for details.
`
return fmt.Sprintf(apache2, year, currentYear, copyrightHolder)
} else {
apache2 := `
// Copyright %d %s
// Licensed under the Apache License, Version 2.0. See the LICENSE file for details.
`
return fmt.Sprintf(apache2, year, copyrightHolder)
}
}

// Apache2 returns a bavard option to be used in Generate writing an apache2 license header in the generated file
Expand Down
65 changes: 27 additions & 38 deletions helpers.go
Original file line number Diff line number Diff line change
@@ -1,16 +1,5 @@
// Copyright 2020 ConsenSys Software Inc.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
// Copyright 2020-2024 Consensys Software Inc.
// Licensed under the Apache License, Version 2.0. See the LICENSE file for details.

package bavard

Expand Down Expand Up @@ -39,30 +28,30 @@ func helpers() template.FuncMap {
"div": div,
"divides": divides,
"first": first,
"gt": gt,
"gt": gt,
"interval": interval,
"iterate": iterate,
"select": _select,
"select": _select,
"last": last,
"list": makeSlice,
"log": fmt.Println,
"lt": lt,
"mod": mod,
"mul": mul,
"mul2": mul2,
"noFirst": noFirst,
"noLast": noLast,
"notNil": notNil,
"pretty": pretty,
"printList": printList,
"reverse": reverse,
"sub": sub,
"supScr": toSuperscript,
"toInt64": toInt64,
"toLower": strings.ToLower,
"toTitle": strings.Title,
"toUpper": strings.ToUpper,
"words64": bigIntToUint64SliceAsString,
"lt": lt,
"mod": mod,
"mul": mul,
"mul2": mul2,
"noFirst": noFirst,
"noLast": noLast,
"notNil": notNil,
"pretty": pretty,
"printList": printList,
"reverse": reverse,
"sub": sub,
"supScr": toSuperscript,
"toInt64": toInt64,
"toLower": strings.ToLower,
"toTitle": strings.Title,
"toUpper": strings.ToUpper,
"words64": bigIntToUint64SliceAsString,
}
}

Expand Down Expand Up @@ -109,7 +98,7 @@ func gt(a, b interface{}) (bool, error) {
func getBitsBig(a big.Int) ([]bool, error) {
l := a.BitLen()
res := make([]bool, l)
for i := 0; i < l; i ++ {
for i := 0; i < l; i++ {
res[i] = a.Bit(i) == 1
}
return res, nil
Expand Down Expand Up @@ -143,9 +132,9 @@ func toBigInt(a interface{}) (big.Int, error) {
case *big.Int:
return *i, nil
/*case string:
var res big.Int
res.SetString(i, 0)
return res, nil*/
var res big.Int
res.SetString(i, 0)
return res, nil*/
default:
n, err := toInt64(i)
return *big.NewInt(n), err
Expand Down Expand Up @@ -506,8 +495,8 @@ var superscripts = map[rune]rune{
}

// toSuperscript writes a number as a "power"
//TODO: Use https://github.com/lynn9388/supsub ?
//Copying supsub
// TODO: Use https://github.com/lynn9388/supsub ?
// Copying supsub
func toSuperscript(a interface{}) (string, error) {
i, err := toInt64(a)

Expand Down

0 comments on commit fb19600

Please sign in to comment.