Skip to content

Commit

Permalink
去除 -d 参数
Browse files Browse the repository at this point in the history
  • Loading branch information
lollipopkit committed Oct 25, 2022
1 parent 57dcf21 commit a55a432
Show file tree
Hide file tree
Showing 10 changed files with 86 additions and 50 deletions.
2 changes: 1 addition & 1 deletion bench_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -33,11 +33,11 @@ func TestMain(m *testing.M) {
for idx := range files {
name := files[idx].Name()
if files[idx].IsDir() || contains(skipTestList, name) || !strings.HasSuffix(name, ".lk") {
println("====================================skip", name)
continue
}
println("=== " + name + " ===")
runVM("test/" + name)
println()
}
}

Expand Down
14 changes: 5 additions & 9 deletions compiler/parser/parser.go
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
package parser

import (
"encoding/json"
"io/ioutil"
"regexp"

. "git.lolli.tech/lollipopkit/lk/compiler/ast"
Expand Down Expand Up @@ -37,13 +35,11 @@ func Parse(chunk, chunkName string) *Block {
lexer := NewLexer(chunk, chunkName)
block := parseBlock(lexer)

if consts.Debug {
data, err := json.MarshalIndent(block, "", " ")
if err != nil {
panic(err)
}
ioutil.WriteFile(chunkName+".ast.json", data, 0644)
}
// data, err := json.MarshalIndent(block, "", " ")
// if err != nil {
// panic(err)
// }
// ioutil.WriteFile(chunkName+".ast.json", data, 0644)

lexer.NextTokenOfKind(TOKEN_EOF)
return block
Expand Down
5 changes: 0 additions & 5 deletions consts/runtime.go

This file was deleted.

28 changes: 0 additions & 28 deletions logger/logger.go

This file was deleted.

4 changes: 0 additions & 4 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,20 +4,16 @@ import (
"flag"
"strings"

"git.lolli.tech/lollipopkit/lk/consts"
"git.lolli.tech/lollipopkit/lk/state"
)

var (
debug = flag.Bool("d", false, "debug mode")
args = []string{}
)

func main() {
flag.Parse()

consts.Debug = *debug

args = flag.Args()
if len(args) == 0 {
repl()
Expand Down
2 changes: 0 additions & 2 deletions state/api_arith.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ import (
"math"

. "git.lolli.tech/lollipopkit/lk/api"
"git.lolli.tech/lollipopkit/lk/logger"
"git.lolli.tech/lollipopkit/lk/number"
)

Expand Down Expand Up @@ -151,6 +150,5 @@ func _arith(a, b any, op operator) any {
}
}
}
logger.W("arith failed: %v %v %v", a, op.metamethod, b)
return nil
}
10 changes: 9 additions & 1 deletion state/api_call.go
Original file line number Diff line number Diff line change
Expand Up @@ -153,7 +153,15 @@ func (self *luaState) Call(nArgs, nResults int) {
self.callGoClosure(nArgs, nResults, c)
}
} else {
panic(fmt.Sprintf("attempt to call on <%#v>", val))
env := func() any {
c := self.stack.closure
if c.goFunc == nil {
return c.proto
}
return c.goFunc
}()
term.Blue(fmt.Sprintf("%#v\n", env))
panic(fmt.Sprintf("attempt to call on %#v", val))
}
}

Expand Down
48 changes: 48 additions & 0 deletions term/size.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
package term

import (
"errors"
"os"
"os/exec"
"strconv"
"strings"
)

type termSize struct {
Height int
Width int
}

var (
ErrTermSizeParseFailed = errors.New("term size parse failed")
)

func Size() (*termSize, error) {
cmd := exec.Command("stty", "size")
cmd.Stdin = os.Stdin
out, err := cmd.Output()
if err != nil {
return nil, err
}

sizeStr := strings.Trim(string(out), "\n")
sizeStrs := strings.Split(sizeStr, " ")
if len(sizeStrs) != 2 {
return nil, ErrTermSizeParseFailed
}

height, err := strconv.ParseInt(sizeStrs[0], 10, 32)
if err != nil {
return nil, err
}

width, err := strconv.ParseInt(sizeStrs[1], 10, 32)
if err != nil {
return nil, err
}

return &termSize{
Height: int(height),
Width: int(width),
}, nil
}
23 changes: 23 additions & 0 deletions test.lk
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
dir := 'test/'
files := os.ls(dir)
skip_files := {
'http_listen.lk'
}

contains := fn(name) {
for _, f in skip_files {
if f == name {
rt true
}
}
rt false
}

for _, file in files {
if string.sub(file, #file - 3) != '.lkc' {
if not contains(file) {
print(fmt('====== %s ======', file))
dofile(dir + file)
}
}
}
File renamed without changes.

0 comments on commit a55a432

Please sign in to comment.