Skip to content

Commit

Permalink
fix: runtime init panic (#354)
Browse files Browse the repository at this point in the history
* fix: runtime init panic

Signed-off-by: peefy <[email protected]>

* feat: set fast eval mode as default

Signed-off-by: peefy <[email protected]>

---------

Signed-off-by: peefy <[email protected]>
  • Loading branch information
Peefy authored Jul 26, 2024
1 parent 76ecc85 commit fd00ef8
Show file tree
Hide file tree
Showing 15 changed files with 102 additions and 358 deletions.
4 changes: 3 additions & 1 deletion .github/workflows/main_darwin.yml
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,11 @@ on:
- "releases/*"
jobs:
build-and-test:
# Ref: https://github.com/actions/runner-images/tree/main/images/macos
# Note: The arch of macos-13-xlarge and macos-14 is arm64
strategy:
matrix:
os: [ macos-12, macos-13 ]
os: [ macos-12, macos-13, macos-13-xlarge, macos-14 ]
runs-on: ${{ matrix.os }}
steps:
- name: Git checkout
Expand Down
8 changes: 5 additions & 3 deletions examples/plugin/main.go
Original file line number Diff line number Diff line change
@@ -1,16 +1,18 @@
//go:build native
// +build native

package main

import (
"fmt"

"kcl-lang.io/kcl-go/pkg/kcl"
"kcl-lang.io/kcl-go/pkg/native" // Import the native API
"kcl-lang.io/kcl-go/pkg/kcl" // Import the native API
_ "kcl-lang.io/kcl-go/pkg/plugin/hello_plugin" // Import the hello plugin
)

func main() {
// Note we use `native.MustRun` here instead of `kcl.MustRun`, because it needs the cgo feature.
yaml := native.MustRun("main.k", kcl.WithCode(code)).GetRawYamlResult()
yaml := kcl.MustRun("main.k", kcl.WithCode(code)).GetRawYamlResult()
fmt.Println(yaml)
}

Expand Down
4 changes: 2 additions & 2 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ require (
github.com/chai2010/protorpc v1.1.4
github.com/getkin/kin-openapi v0.126.0
github.com/goccy/go-yaml v1.12.0
github.com/gofrs/flock v0.12.0
github.com/gofrs/flock v0.12.1
github.com/golang/protobuf v1.5.4
github.com/google/go-cmp v0.6.0
github.com/iancoleman/strcase v0.3.0
Expand All @@ -22,7 +22,7 @@ require (
google.golang.org/grpc v1.65.0
google.golang.org/protobuf v1.34.2
gopkg.in/yaml.v3 v3.0.1
kcl-lang.io/kpm v0.9.2
kcl-lang.io/kpm v0.9.3
kcl-lang.io/lib v0.10.0-alpha.1
)

Expand Down
8 changes: 4 additions & 4 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -372,8 +372,8 @@ github.com/go-test/deep v1.0.8 h1:TDsG77qcSprGbC6vTN8OuXp5g+J+b5Pcguhf7Zt61VM=
github.com/go-test/deep v1.0.8/go.mod h1:5C2ZWiW0ErCdrYzpqxLbTX7MG14M9iiw8DgHncVwcsE=
github.com/goccy/go-yaml v1.12.0 h1:/1WHjnMsI1dlIBQutrvSMGZRQufVO3asrHfTwfACoPM=
github.com/goccy/go-yaml v1.12.0/go.mod h1:wKnAMd44+9JAAnGQpWVEgBzGt3YuTaQ4uXoHvE4m7WU=
github.com/gofrs/flock v0.12.0 h1:xHW8t8GPAiGtqz7KxiSqfOEXwpOaqhpYZrTE2MQBgXY=
github.com/gofrs/flock v0.12.0/go.mod h1:FirDy1Ing0mI2+kB6wk+vyyAH+e6xiE+EYA0jnzV9jc=
github.com/gofrs/flock v0.12.1 h1:MTLVXXHf8ekldpJk3AKicLij9MdwOWkZ+a/jHHZby9E=
github.com/gofrs/flock v0.12.1/go.mod h1:9zxTsyu5xtJ9DK+1tFZyibEV7y3uwDxPPfbxeeHCoD0=
github.com/gogo/protobuf v1.1.1/go.mod h1:r8qH/GZQm5c6nD/R0oafs1akxWv10x8SbQlK7atdtwQ=
github.com/golang-collections/collections v0.0.0-20130729185459-604e922904d3 h1:zN2lZNZRflqFyxVaTIU61KNKQ9C0055u9CAfpmqUvo4=
github.com/golang-collections/collections v0.0.0-20130729185459-604e922904d3/go.mod h1:nPpo7qLxd6XL3hWJG/O60sR8ZKfMCiIoNap5GvD12KU=
Expand Down Expand Up @@ -1287,8 +1287,8 @@ honnef.co/go/tools v0.0.1-2020.1.3/go.mod h1:X/FiERA/W4tHapMX5mGpAtMSVEeEUOyHaw9
honnef.co/go/tools v0.0.1-2020.1.4/go.mod h1:X/FiERA/W4tHapMX5mGpAtMSVEeEUOyHaw9vFzvIQ3k=
k8s.io/utils v0.0.0-20230220204549-a5ecb0141aa5 h1:kmDqav+P+/5e1i9tFfHq1qcF3sOrDp+YEkVDAHu7Jwk=
k8s.io/utils v0.0.0-20230220204549-a5ecb0141aa5/go.mod h1:OLgZIPagt7ERELqWJFomSt595RzquPNLL48iOWgYOg0=
kcl-lang.io/kpm v0.9.2 h1:TNQLFWEYj9MEFZXpHGhp4/PHAv3eBogOjpYDyMIFZsU=
kcl-lang.io/kpm v0.9.2/go.mod h1:4HTbPhB4DVtkamnIv5lrRcHtCVwzp4Pf/b+d3TN4nzs=
kcl-lang.io/kpm v0.9.3 h1:lwFSrJTRyAzjygT5Oo/98DxCCiDZmujo46PcmRx54Ck=
kcl-lang.io/kpm v0.9.3/go.mod h1:4HTbPhB4DVtkamnIv5lrRcHtCVwzp4Pf/b+d3TN4nzs=
kcl-lang.io/lib v0.10.0-alpha.1 h1:GMVB75Pc1W29gcl1WlVgdgUscH6h+d9No0fzBH0rNYg=
kcl-lang.io/lib v0.10.0-alpha.1/go.mod h1:tu+tzwGgHLzYZSIxUG/ntipStrxZd6OvutWYPTxS7cs=
oras.land/oras-go v1.2.5 h1:XpYuAwAb0DfQsunIyMfeET92emK8km3W4yEzZvUbsTo=
Expand Down
104 changes: 25 additions & 79 deletions kclvm_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -312,17 +312,11 @@ func TestGetSchemaType(t *testing.T) {
SchemaName: "Person",
Properties: map[string]*gpyrpc.KclType{
"name": {
Type: "str",
Line: 1,
Properties: map[string]*gpyrpc.KclType{},
Required: []string{},
UnionTypes: []*gpyrpc.KclType{},
Decorators: []*gpyrpc.Decorator{},
Examples: map[string]*gpyrpc.Example{},
Type: "str",
Line: 1,
},
},
Required: []string{"name"},
UnionTypes: []*gpyrpc.KclType{},
Required: []string{"name"},
Decorators: []*gpyrpc.Decorator{
{
Name: "info",
Expand All @@ -332,7 +326,6 @@ func TestGetSchemaType(t *testing.T) {
},
},
},
Examples: map[string]*gpyrpc.Example{},
},
}, result)
p, err := filepath.Abs("./testdata/main.k")
Expand All @@ -351,30 +344,17 @@ func TestGetSchemaType(t *testing.T) {
SchemaName: "Person",
Properties: map[string]*gpyrpc.KclType{
"name": {
Type: "str",
Line: 1,
Default: "\"kcl\"",
Properties: map[string]*gpyrpc.KclType{},
Required: []string{},
UnionTypes: []*gpyrpc.KclType{},
Decorators: []*gpyrpc.Decorator{},
Examples: map[string]*gpyrpc.Example{},
Type: "str",
Line: 1,
Default: "\"kcl\"",
},
"age": {
Type: "int",
Line: 2,
Default: "1",
Properties: map[string]*gpyrpc.KclType{},
Required: []string{},
UnionTypes: []*gpyrpc.KclType{},
Decorators: []*gpyrpc.Decorator{},
Examples: map[string]*gpyrpc.Example{},
Type: "int",
Line: 2,
Default: "1",
},
},
Required: []string{"name", "age"},
UnionTypes: []*gpyrpc.KclType{},
Decorators: []*gpyrpc.Decorator{},
Examples: map[string]*gpyrpc.Example{},
Required: []string{"name", "age"},
},
}, result)
}
Expand All @@ -391,19 +371,11 @@ func TestGetSchemaTypeMapping(t *testing.T) {
SchemaName: "Person",
Properties: map[string]*gpyrpc.KclType{
"name": {
Type: "str",
Line: 1,
Properties: map[string]*gpyrpc.KclType{},
Required: []string{},
UnionTypes: []*gpyrpc.KclType{},
Decorators: []*gpyrpc.Decorator{},
Examples: map[string]*gpyrpc.Example{},
Type: "str",
Line: 1,
},
},
Required: []string{"name"},
UnionTypes: []*gpyrpc.KclType{},
Decorators: []*gpyrpc.Decorator{},
Examples: map[string]*gpyrpc.Example{},
Required: []string{"name"},
}
assert2.Equal(t, map[string]*gpyrpc.KclType{
"Person": &personSchema,
Expand All @@ -415,28 +387,15 @@ func TestGetSchemaTypeMapping(t *testing.T) {
BaseSchema: &personSchema,
Properties: map[string]*gpyrpc.KclType{
"name": {
Type: "str",
Line: 1,
Properties: map[string]*gpyrpc.KclType{},
Required: []string{},
UnionTypes: []*gpyrpc.KclType{},
Decorators: []*gpyrpc.Decorator{},
Examples: map[string]*gpyrpc.Example{},
Type: "str",
Line: 1,
},
"count": {
Type: "int",
Line: 2,
Properties: map[string]*gpyrpc.KclType{},
Required: []string{},
UnionTypes: []*gpyrpc.KclType{},
Decorators: []*gpyrpc.Decorator{},
Examples: map[string]*gpyrpc.Example{},
Type: "int",
Line: 2,
},
},
Required: []string{"count", "name"},
UnionTypes: []*gpyrpc.KclType{},
Decorators: []*gpyrpc.Decorator{},
Examples: map[string]*gpyrpc.Example{},
Required: []string{"count", "name"},
},
}, result)

Expand All @@ -456,30 +415,17 @@ func TestGetSchemaTypeMapping(t *testing.T) {
SchemaName: "Person",
Properties: map[string]*gpyrpc.KclType{
"name": {
Type: "str",
Line: 1,
Default: "\"kcl\"",
Properties: map[string]*gpyrpc.KclType{},
Required: []string{},
UnionTypes: []*gpyrpc.KclType{},
Decorators: []*gpyrpc.Decorator{},
Examples: map[string]*gpyrpc.Example{},
Type: "str",
Line: 1,
Default: "\"kcl\"",
},
"age": {
Type: "int",
Line: 2,
Default: "1",
Properties: map[string]*gpyrpc.KclType{},
Required: []string{},
UnionTypes: []*gpyrpc.KclType{},
Decorators: []*gpyrpc.Decorator{},
Examples: map[string]*gpyrpc.Example{},
Type: "int",
Line: 2,
Default: "1",
},
},
Required: []string{"name", "age"},
UnionTypes: []*gpyrpc.KclType{},
Decorators: []*gpyrpc.Decorator{},
Examples: map[string]*gpyrpc.Example{},
Required: []string{"name", "age"},
},
}, result)
}
Expand Down
Loading

0 comments on commit fd00ef8

Please sign in to comment.