-
Notifications
You must be signed in to change notification settings - Fork 388
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
WIP p/jaekwon/... #461
Draft
jaekwon
wants to merge
9
commits into
master
Choose a base branch
from
dev/jae/p_jaekwon
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Draft
WIP p/jaekwon/... #461
Changes from 4 commits
Commits
Show all changes
9 commits
Select commit
Hold shift + click to select a range
05ad53e
initial commit
jaekwon 8de1977
add gitkeep for modules to fill
jaekwon c980af8
remove avl/types.gno
jaekwon 7fd2965
gnodev run initial commit
jaekwon 212d539
fix demo with new Iterate signature
jaekwon 54d2b79
people & works brainstorming
jaekwon 1bd8536
...
jaekwon ecdab3b
...
jaekwon 495125c
WIP...
jaekwon File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,68 @@ | ||
package main | ||
|
||
import ( | ||
"os" | ||
|
||
"github.com/gnolang/gno/pkgs/command" | ||
"github.com/gnolang/gno/pkgs/errors" | ||
gno "github.com/gnolang/gno/pkgs/gnolang" | ||
"github.com/gnolang/gno/tests" | ||
) | ||
|
||
type runOptions struct { | ||
Verbose bool `flag:"verbose" help:"verbose"` | ||
RootDir string `flag:"root-dir" help:"clone location of github.com/gnolang/gno (gnodev tries to guess it)"` | ||
// Timeout time.Duration `flag:"timeout" help:"max execution time"` | ||
// VM Options | ||
// UseNativeLibs bool // experimental, but could be useful for advanced developer needs | ||
} | ||
|
||
var defaultRunOptions = runOptions{ | ||
Verbose: false, | ||
RootDir: "", | ||
} | ||
|
||
func runApp(cmd *command.Command, args []string, iopts interface{}) error { | ||
opts := iopts.(runOptions) | ||
if len(args) == 0 { | ||
cmd.ErrPrintfln("Usage: run [flags] file.gno [file2.gno...]") | ||
return errors.New("invalid args") | ||
} | ||
|
||
if opts.RootDir == "" { | ||
opts.RootDir = guessRootDir() | ||
} | ||
|
||
fnames := args | ||
|
||
return runRun(opts.RootDir, opts.Verbose, fnames) | ||
} | ||
|
||
func runRun(rootDir string, verbose bool, fnames []string) error { | ||
stdin := os.Stdin | ||
stdout := os.Stdout | ||
stderr := os.Stderr | ||
|
||
// init store and machine | ||
testStore := tests.TestStore(rootDir, "", stdin, stdout, stderr, tests.ImportModeStdlibsOnly) | ||
if verbose { | ||
testStore.SetLogStoreOps(true) | ||
} | ||
m := gno.NewMachineWithOptions(gno.MachineOptions{ | ||
PkgPath: "main", | ||
Output: stdout, | ||
Store: testStore, | ||
}) | ||
|
||
// read files | ||
files := make([]*gno.FileNode, len(fnames)) | ||
for i, fname := range fnames { | ||
files[i] = gno.MustReadFile(fname) | ||
} | ||
|
||
// run files | ||
m.RunFiles(files...) | ||
m.RunMain() | ||
|
||
return nil | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,6 @@ | ||
package avl | ||
|
||
//---------------------------------------- | ||
// Node | ||
|
||
type Node struct { | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -43,11 +43,39 @@ func (tree *Tree) Remove(key string) (value interface{}, removed bool) { | |
} | ||
|
||
// Shortcut for TraverseInRange. | ||
func (tree *Tree) Iterate(start, end string, cb func(*Node) bool) bool { | ||
return tree.node.TraverseInRange(start, end, true, true, cb) | ||
func (tree *Tree) Iterate(start, end string, cb IterCbFn) bool { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I came across this PR. It looks like a lot of this is already implemented. Perhaps this PR is no longer necessary? |
||
return tree.node.TraverseInRange(start, end, true, true, | ||
func(node *Node) { | ||
cb(node.Key(), node.Value()) | ||
}, | ||
) | ||
} | ||
|
||
// Shortcut for TraverseInRange. | ||
func (tree *Tree) IterateReverse(start, end string, cb func(*Node) bool) bool { | ||
return tree.node.TraverseInRange(start, end, false, true, cb) | ||
func (tree *Tree) ReverseIterate(start, end string, cb IterCbFn) bool { | ||
return tree.node.TraverseInRange(start, end, false, true, | ||
func(node *Node) { | ||
cb(node.Key(), node.Value()) | ||
}, | ||
) | ||
} | ||
|
||
// Shortcut for TraverseByOffset. | ||
func (tree *Tree) IterateByOffset(offset int, count int, cb IterCbFn) bool { | ||
return tree.node.TraverseByOffset(offset, count, true, true, | ||
func(node *Node) { | ||
cb(node.Key(), node.Value()) | ||
}, | ||
) | ||
} | ||
|
||
// Shortcut for TraverseByOffset. | ||
func (tree *Tree) ReverseIterateByOffset(start, end string, cb IterCbFn) bool { | ||
return tree.node.TraverseByOffset(offset, count, false, true, | ||
func(node *Node) { | ||
cb(node.Key(), node.Value()) | ||
}, | ||
) | ||
} | ||
|
||
func IterCbFn func(key string, value interface{}) bool |
Empty file.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,97 @@ | ||
package paginate | ||
|
||
import "strconv" | ||
|
||
type pageFn func(page int, size int, reverse bool) string | ||
|
||
// TODO maybe put somewhere else. | ||
type renderer interface { | ||
Render() string | ||
} | ||
|
||
// TODO this function belongs somewhere convenient. | ||
// escape a URL for markdown. | ||
func escMDURL(s string) string { | ||
// XXX implement | ||
} | ||
|
||
|
||
var itoa = strconv.Itoa | ||
|
||
// pageFn: path function to render paginattion links. if nil, no links are | ||
// rendered. result must start with ':'. | ||
// t: the tree with elements. each value must implement Render() string. | ||
// page: page number starting from 1. | ||
// size: page size. | ||
// reverse: reverse order. // XXX implement | ||
func RenderTreeByPage( | ||
t avl.Tree, | ||
pageFn pageFn, | ||
page int, size int, reverse bool) { | ||
|
||
// sanity checks | ||
if page < 0 { | ||
panic("invalid negative page to RenderTreeByPage") | ||
} | ||
if size <= 0 { | ||
panic("invalid nonpositive size to RenderTreeByPage") | ||
} | ||
|
||
str := "" | ||
numpages := (t.Size() / size) + 1 | ||
|
||
// render pagination | ||
if pageFn == nil { | ||
// do not render pagination | ||
} else if page > numpages { | ||
// page out of bounds. | ||
// [1](...) [2](...) ... [101](...) [102)(...) | ||
// where ... is result of pageFn(). | ||
// TODO: improve this function by renderring | ||
// only the first and last few pages. XXX | ||
for p := 1; p <= numPages; p++ { | ||
pageurl := pageFn(p, size, reverse) | ||
str += "[" + itoa(page) + "](" + | ||
escMDURL(pageurl) + ") " | ||
} | ||
str += "\n" | ||
str += "page " + itoa(page) + " out of bounds\n" | ||
return str | ||
} | ||
// [1](...) *2* [3](...) [4](...) ... [101](...) [102)(...) | ||
// where ... is result of pageFn(). | ||
// TODO: improve this function by only printing the first few, | ||
// the last few, and the ones surrounding the current page. | ||
// Must make this improvement to be strictly "memory correct". | ||
if numpages > 0 { | ||
for p := 1; p <= numPages; p++ { | ||
pageurl := pageFn(p, size, reverse) | ||
str += "[" + itoa(page) + "](" + | ||
escMDURL(pageurl) + ") " | ||
} | ||
str += "\n" | ||
} | ||
|
||
// render tree items | ||
offset := (page-1) * size | ||
t.IterateByOffset(offset, size, | ||
func(key string, value interface{}) bool { | ||
var r = value.(renderer) | ||
str += r.Render() | ||
str += "\n" | ||
str += "\n" | ||
}, | ||
) | ||
|
||
// render pagination again if there are pages. | ||
if numpages > 0 { | ||
for p := 1; p <= numPages; p++ { | ||
pageurl := pageFn(p, size, reverse) | ||
str += "[" + itoa(page) + "](" + | ||
escMDURL(pageurl) + ") " | ||
} | ||
str += "\n" | ||
} | ||
|
||
return str | ||
} |
Empty file.
Empty file.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
package tests | ||
|
||
/* The intent is for this file to run the main test, with data that will go on the chain upon launch */ | ||
|
||
func main() { | ||
// XXX | ||
} |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
❤️