fix: (issues/9) Worker does not support port assignment for routers (#11)

Quite a refactor and some code cleanup.

Co-authored-by: James Wells <jwells@dragonheim.net>
Reviewed-on: #11
Co-authored-by: James Wells <jwells@noreply.localhost>
Co-committed-by: James Wells <jwells@noreply.localhost>
This commit is contained in:
James Wells 2021-05-21 23:03:50 +00:00
parent 881a11316d
commit 7d6fbfef24
21 changed files with 451 additions and 271 deletions

20
src/picol/LICENSE Normal file
View file

@ -0,0 +1,20 @@
The MIT License (MIT)
Copyright (c) 2014 Lain dono <lain.dono@gmail.com>
Permission is hereby granted, free of charge, to any person obtaining a copy of
this software and associated documentation files (the "Software"), to deal in
the Software without restriction, including without limitation the rights to
use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of
the Software, and to permit persons to whom the Software is furnished to do so,
subject to the following conditions:
The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

27
src/picol/README.md Normal file
View file

@ -0,0 +1,27 @@
# picol.go
Original http://oldblog.antirez.com/post/picol.html
Sample use:
```golang
func CommandPuts(i *picol.Interp, argv []string, pd interface{}) (string, error) {
if len(argv) != 2 {
return "", fmt.Errorf("Wrong number of args for %s %s", argv[0], argv)
}
fmt.Println(argv[1])
return "", nil
}
...
interp := picol.InitInterp()
// add core functions
interp.RegisterCoreCommands()
// add user function
interp.RegisterCommand("puts", CommandPuts, nil)
// eval
result, err := interp.Eval(string(buf))
if err != nil {
fmt.Println("ERROR", err, result)
} else {
fmt.Println(result)
}
```

View file

@ -0,0 +1,9 @@
proc fib {x} {
if {<= $x 1} {
return 1
} else {
+ [fib [- $x 1]] [fib [- $x 2]]
}
}
puts [fib 20]

15
src/picol/examples/t2.tcl Normal file
View file

@ -0,0 +1,15 @@
proc square {x} {
* $x $x
}
set a 1
while {<= $a 10} {
if {== $a 5} {
puts {Missing five!}
set a [+ $a 1]
continue
}
puts "I can compute that $a*$a = [square $a]"
set a [+ $a 1]
}

View file

@ -0,0 +1,5 @@
proc square {x} {
* $x $x
}
puts [square 5]

46
src/picol/picol/main.go Normal file
View file

@ -0,0 +1,46 @@
package main
import (
"bufio"
"flag"
"fmt"
"io/ioutil"
"os"
picol "git.dragonheim.net/dragonheim/gagent/src/picol"
)
var fname = flag.String("f", "", "file name")
func CommandPuts(i *picol.Interp, argv []string, pd interface{}) (string, error) {
if len(argv) != 2 {
return "", fmt.Errorf("Wrong number of args for %s %s", argv[0], argv)
}
fmt.Println(argv[1])
return "", nil
}
func main() {
flag.Parse()
interp := picol.InitInterp()
interp.RegisterCoreCommands()
interp.RegisterCommand("puts", CommandPuts, nil)
buf, err := ioutil.ReadFile(*fname)
if err == nil {
result, err := interp.Eval(string(buf))
if err != nil {
fmt.Println("ERRROR", result, err)
}
} else {
for {
fmt.Print("picol> ")
scanner := bufio.NewReader(os.Stdin)
clibuf, _ := scanner.ReadString('\n')
result, err := interp.Eval(clibuf[:len(clibuf)-1])
if len(result) != 0 {
fmt.Println("ERRROR", result, err)
}
}
}
}