diff --git a/cl/_testgop/matrix/in.gop b/cl/_testgop/_matrix/in.gop similarity index 100% rename from cl/_testgop/matrix/in.gop rename to cl/_testgop/_matrix/in.gop diff --git a/cl/_testgop/unit/in.gop b/cl/_testgop/unit/in.gop new file mode 100644 index 000000000..e4977a1cc --- /dev/null +++ b/cl/_testgop/unit/in.gop @@ -0,0 +1,5 @@ +import "time" + +func Wait(time.Duration) {} + +wait 0.5µs diff --git a/cl/_testgop/unit/out.go b/cl/_testgop/unit/out.go new file mode 100644 index 000000000..d55d250c5 --- /dev/null +++ b/cl/_testgop/unit/out.go @@ -0,0 +1,9 @@ +package main + +import "time" + +func Wait(time.Duration) { +} +func main() { + Wait(500) +} diff --git a/cl/compile_testdir_test.go b/cl/compile_testdir_test.go index 122cf7205..f41cd71cf 100644 --- a/cl/compile_testdir_test.go +++ b/cl/compile_testdir_test.go @@ -22,6 +22,10 @@ import ( "github.com/goplus/gop/cl/cltest" ) +func TestTestgop(t *testing.T) { + cltest.FromDir(t, "", "./_testgop") +} + func TestTestc(t *testing.T) { cltest.FromDir(t, "", "./_testc") } diff --git a/cl/expr.go b/cl/expr.go index dec29bf9b..56ce39c1a 100644 --- a/cl/expr.go +++ b/cl/expr.go @@ -813,12 +813,15 @@ func compileCallArgs(ctx *blockCtx, pfn *gogen.Element, fn *fnType, v *ast.CallE if typetype { return } + case *ast.NumberUnitLit: + compileNumberUnitLit(ctx, expr, fn.arg(i, ellipsis)) default: compileExpr(ctx, arg) } } if needInferFunc { - typ, err := gogen.InferFunc(ctx.pkg, pfn, fn.sig, nil, ctx.cb.InternalStack().GetArgs(len(v.Args)), flags) + args := ctx.cb.InternalStack().GetArgs(len(v.Args)) + typ, err := gogen.InferFunc(ctx.pkg, pfn, fn.sig, nil, args, flags) if err != nil { return err } @@ -977,6 +980,12 @@ func compileFuncLit(ctx *blockCtx, v *ast.FuncLit) { } } +func compileNumberUnitLit(ctx *blockCtx, v *ast.NumberUnitLit, expected types.Type) { + ctx.cb.ValWithUnit( + &goast.BasicLit{ValuePos: v.ValuePos, Kind: gotoken.Token(v.Kind), Value: v.Value}, + expected, v.Unit) +} + func compileBasicLit(ctx *blockCtx, v *ast.BasicLit) { cb := ctx.cb switch kind := v.Kind; kind { diff --git a/go.mod b/go.mod index bf802983c..f3c2d9ca4 100644 --- a/go.mod +++ b/go.mod @@ -3,8 +3,8 @@ module github.com/goplus/gop go 1.18 require ( + github.com/goplus/gogen v1.16.2-0.20241107075831-8fd274c85e06 github.com/fsnotify/fsnotify v1.8.0 - github.com/goplus/gogen v1.16.1 github.com/goplus/llgo v0.9.7 github.com/goplus/mod v0.13.12 github.com/qiniu/x v1.13.10 diff --git a/go.sum b/go.sum index 579abc973..b3a5c4914 100644 --- a/go.sum +++ b/go.sum @@ -1,7 +1,7 @@ +github.com/goplus/gogen v1.16.2-0.20241107075831-8fd274c85e06 h1:TZhHNYHia8bP8JoTO5utGWFTLBp2JrdyWukX/tnA/n4= +github.com/goplus/gogen v1.16.2-0.20241107075831-8fd274c85e06/go.mod h1:6TQYbabXDF9LCdDkOOzHmfg1R4ENfXQ3XpHa9RhTSD8= github.com/fsnotify/fsnotify v1.8.0 h1:dAwr6QBTBZIkG8roQaJjGof0pp0EeF+tNV7YBP3F/8M= github.com/fsnotify/fsnotify v1.8.0/go.mod h1:8jBTzvmWwFyi3Pb8djgCCO5IBqzKJ/Jwo8TRcHyHii0= -github.com/goplus/gogen v1.16.1 h1:f55LIfyTO5GcXxCfwXKqLKiQV3AORvn9PSGCncWvB1A= -github.com/goplus/gogen v1.16.1/go.mod h1:6TQYbabXDF9LCdDkOOzHmfg1R4ENfXQ3XpHa9RhTSD8= github.com/goplus/llgo v0.9.7 h1:LRF2Fq9ts4QrVxOPZufexalbIoJ1oiBERjCWQ45wxbg= github.com/goplus/llgo v0.9.7/go.mod h1:5Fs+08NslqofJ7xtOiIXugkurYOoQvY02ZkFNWA1uEI= github.com/goplus/mod v0.13.12 h1:Trwk6j3i9VvBuW6/9ZxmkoFlEL2v3HKQu0Na1c6DAdw= diff --git a/parser/_testdata/unit/parser.expect b/parser/_testdata/unit/parser.expect index e71a03670..5f01ff09e 100644 --- a/parser/_testdata/unit/parser.expect +++ b/parser/_testdata/unit/parser.expect @@ -18,9 +18,9 @@ ast.FuncDecl: ast.CallExpr: Fun: ast.Ident: - Name: step + Name: wait Args: ast.NumberUnitLit: Kind: INT Value: 1 - Unit: cm + Unit: µs diff --git a/parser/_testdata/unit/step.gop b/parser/_testdata/unit/step.gop index 5588cd873..b0f1553d9 100644 --- a/parser/_testdata/unit/step.gop +++ b/parser/_testdata/unit/step.gop @@ -1 +1 @@ -step 1cm +wait 1µs diff --git a/scanner/scanner.go b/scanner/scanner.go index 4d4ff8ccc..3842de771 100644 --- a/scanner/scanner.go +++ b/scanner/scanner.go @@ -510,7 +510,7 @@ func (s *Scanner) scanNumber() (token.Token, string) { } else if s.ch == 'r' { tok = token.RAT s.next() - } else if s.ch >= 'a' && s.ch <= 'z' || s.ch >= 'A' && s.ch <= 'Z' { + } else if isLetter(s.ch) { s.needUnit = true }