Skip to content

Commit

Permalink
update the 7 only files of gofork
Browse files Browse the repository at this point in the history
  • Loading branch information
diyism committed Sep 28, 2022
1 parent 5181e98 commit 046e70d
Show file tree
Hide file tree
Showing 6 changed files with 117 additions and 30 deletions.
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,8 @@ _testmain.go
/test/pass.out
/test/run.out
/test/times.out
/test-gofork/test
/test-gofork/go.mod

# This file includes artifacts of Go build that should not be checked in.
# For files created by specific development environment (e.g. editor),
Expand Down
110 changes: 83 additions & 27 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,42 +1,98 @@
# The Go Programming Language
# goFork (v1.19.1):

Go is an open source programming language that makes it easy to build simple,
reliable, and efficient software.
Fork golang to support Allman/Horstmann style of curly braces

![Gopher image](https://golang.org/doc/gopher/fiveyears.jpg)
*Gopher image by [Renee French][rf], licensed under [Creative Commons 3.0 Attributions license][cc3-by].*
The google guys don't like allman style, but it's very easy to support allman style, just added only 13 lines of code into golang compiler.

Our canonical Git repository is located at https://go.googlesource.com/go.
There is a mirror of the repository at https://github.com/golang/go.
Allman/Horstmann style is for we human, K&R style is for google robots!

Unless otherwise noted, the Go source files are distributed under the
BSD-style license found in the LICENSE file.
![Gopher image](https://avatars.githubusercontent.com/u/86223803)

### Download and Install
# Compile goFork:
```bash
sudo rm -rf /usr/local/go && wget -qO- https://golang.org/dl/go1.18.1.linux-amd64.tar.gz | sudo tar -xvz -C /usr/local
export -n GOROOT ; hash -d go
sudo mv /usr/local/go /usr/local/go.golang
git clone --depth 1 --recursive https://github.com/gofork-org/go.git
#or: wget https://github.com/gofork-org/go/archive/refs/heads/master.zip && unzip master.zip
cp -r ./go/bin.bootstrap ./go/bin
cd ./go/src
#bootstrap depends on ./pkg/tool/linux_amd64/compile(23MB bin), ./bin/go(15MB bin), can't simply copy them into goFork, will be not compatible with ./src/
export GOROOT_BOOTSTRAP=/usr/local/go.golang
./all.bash #need 50 seconds to build gofork compiler

#### Binary Distributions
cd ../test-gofork
../bin/go mod init test
../bin/go build -ldflags="-s -w"
./test

Official binary distributions are available at https://go.dev/dl/.
#if everything is ok, we can replace golang with gofork:
sudo cp -r ../ /usr/local/go
sudo export PATH=$PATH:/usr/local/go/bin #or append ":/usr/local/go/bin" into PATH in /etc/environment

After downloading a binary release, visit https://go.dev/doc/install
for installation instructions.
#if you have "git pull" again, you should run ./all.bash again to match the ./bin/go with the latest ./src(stdlib)
```

#### Install From Source
# test-gofork/test.go, Allman/Horstmann style:

If a binary distribution is not available for your combination of
operating system and architecture, visit
https://go.dev/doc/install/source
for source installation instructions.
```go
package main
import
( "fmt"
)

### Contributing

Go is the work of thousands of contributors. We appreciate your help!
func main()
{ if false
{ fmt.Println("jack")
fmt.Println("gofork")
} else
{ fmt/
.Println("hello")
fmt.Println("gofork")
}

To contribute, please read the contribution guidelines at https://go.dev/doc/contribute.
var a="hello"

Note that the Go project uses the issue tracker for bug reports and
proposals only. See https://go.dev/wiki/Questions for a list of
places to ask questions about the Go language.
{ var b="gofork"
fmt.Println(a, b)
}
}

[rf]: https://reneefrench.blogspot.com/
[cc3-by]: https://creativecommons.org/licenses/by/3.0/
```

Notes:

1. In this style, the '{' at the beginning of the line needs to be followed by a whitespace or a tab

2. A seperate code block needs a precedent empty line

While gofork keeps support for golang's K&R style:

```go
package main
import(
"fmt"
)


func main() {
if false {
fmt.Println("jack")
fmt.Println("gofork")
} else {
fmt.
Println("hello")
fmt.Println("gofork")
}

var a="hello"
{
var b="gofork"
fmt.Println(a, b)
}
}

```

Note: the '{' at the beginning of the line should not be followed by a whitespace or a tab
2 changes: 1 addition & 1 deletion src/all.bash
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,6 @@ if [ ! -f make.bash ]; then
fi
OLDPATH="$PATH"
. ./make.bash "$@" --no-banner
bash run.bash --no-rebuild
#bash run.bash --no-rebuild
PATH="$OLDPATH"
$GOTOOLDIR/dist banner # print build info
20 changes: 20 additions & 0 deletions src/cmd/compile/internal/syntax/scanner.go
Original file line number Diff line number Diff line change
Expand Up @@ -117,6 +117,20 @@ redo:
s.tok = _EOF

case '\n':
s.nextch()
for s.ch == ' ' || s.ch == '\t' || s.ch == '\r' {
s.nextch()
}
if s.ch == '{' {
s.nextch()
if s.ch == ' ' || s.ch == '\t' {
s.nextch()
s.tok = _Lbrace
break
}
}
s.rewind()

s.nextch()
s.lit = "newline"
s.tok = _Semi
Expand Down Expand Up @@ -229,6 +243,12 @@ redo:

case '/':
s.nextch()

if s.ch == '\n' {
s.nextch()
goto redo
}

if s.ch == '/' {
s.nextch()
s.lineComment()
Expand Down
10 changes: 10 additions & 0 deletions src/go/scanner/scanner.go
Original file line number Diff line number Diff line change
Expand Up @@ -859,6 +859,16 @@ scanAgain:
// we only reach here if s.insertSemi was
// set in the first place and exited early
// from s.skipWhitespace()

for s.ch == ' ' || s.ch == '\t' || s.ch == '\r' {
s.next()
}
if s.ch == '{' && (s.peek() == ' ' || s.peek() == '\t') {
s.next()
tok = token.LBRACE
break
}

s.insertSemi = false // newline consumed
return pos, token.SEMICOLON, "\n"
case '"':
Expand Down
3 changes: 1 addition & 2 deletions src/runtime/mgcpacer.go
Original file line number Diff line number Diff line change
Expand Up @@ -719,8 +719,7 @@ func (c *gcControllerState) endCycle(now int64, procs int, userForced bool) {
//
// Note that because we only care about the ratio, assistDuration and procs cancel out.
scanWork := c.heapScanWork.Load() + c.stackScanWork.Load() + c.globalsScanWork.Load()
currentConsMark := (float64(c.heapLive-c.triggered) * (utilization + idleUtilization)) /
(float64(scanWork) * (1 - utilization))
currentConsMark := (float64(c.heapLive-c.triggered) * (utilization + idleUtilization)) / (float64(scanWork) * (1 - utilization))

// Update cons/mark controller. The time period for this is 1 GC cycle.
//
Expand Down

0 comments on commit 046e70d

Please sign in to comment.