Skip to content

Commit

Permalink
Merge pull request #53 from GuanceCloud/chore-update
Browse files Browse the repository at this point in the history
Chore update
  • Loading branch information
vircoys authored Aug 15, 2024
2 parents 6372938 + 4178628 commit 21f3924
Show file tree
Hide file tree
Showing 35 changed files with 266 additions and 322 deletions.
2 changes: 1 addition & 1 deletion internal/cmd/platypus/run/run.go
Original file line number Diff line number Diff line change
Expand Up @@ -123,7 +123,7 @@ func runScript(ctx context.Context, options *Options, script *plruntime.Script)
tn = pt.Time
measurement = pt.Measurement

errR := engine.RunScriptWithRMapIn(script, pt, nil)
errR := script.Run(pt, nil)
if errR != nil {
return fmt.Errorf("run script error: %w", errR)
}
Expand Down
4 changes: 2 additions & 2 deletions pkg/ast/ast.go
Original file line number Diff line number Diff line change
Expand Up @@ -72,9 +72,9 @@ func (t NodeType) String() string {
case TypeNilLiteral:
return "NilLiteral"
case TypeListLiteral:
return "ListInitExpr"
return "ListLiteral"
case TypeMapLiteral:
return "MapInitExpr"
return "MapLiteral"
case TypeParenExpr:
return "ParenExpr"
case TypeAttrExpr:
Expand Down
3 changes: 2 additions & 1 deletion pkg/ast/expr.go
Original file line number Diff line number Diff line change
Expand Up @@ -292,7 +292,8 @@ type CallExpr struct {

Name string

Param []*Node
Param []*Node
ParamNormalized []*Node

PrivateData interface{}

Expand Down
20 changes: 1 addition & 19 deletions pkg/engine/engine.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@ import (
"path/filepath"

plruntime "github.com/GuanceCloud/platypus/pkg/engine/runtime"
"github.com/GuanceCloud/platypus/pkg/errchain"
"github.com/GuanceCloud/platypus/pkg/parser"
)

Expand All @@ -35,8 +34,7 @@ func ParseScript(scripts map[string]string,
Ast: stmts,
}

if err := CheckScript(p, check); err != nil {
// TODO
if err := p.Check(check); err != nil {
retErrMap[name] = err
continue
}
Expand All @@ -51,22 +49,6 @@ func ParseScript(scripts map[string]string,
return retMap, retErrMap
}

func RunScriptWithoutMapIn(proc *plruntime.Script, data plruntime.InputWithoutMap, signal plruntime.Signal) *errchain.PlError {
return plruntime.RunScriptWithoutMapIn(proc, data, signal)
}

func RunScriptWithRMapIn(proc *plruntime.Script, data plruntime.InputWithRMap, signal plruntime.Signal) *errchain.PlError {
return plruntime.RunScriptWithRMapIn(proc, data, signal)
}

func RunScriptRef(ctx *plruntime.Context, proc *plruntime.Script) *errchain.PlError {
return plruntime.RefRunScript(ctx, proc)
}

func CheckScript(proc *plruntime.Script, funcsCheck map[string]plruntime.FuncCheck) *errchain.PlError {
return plruntime.CheckScript(proc, funcsCheck)
}

func ReadPlScriptFromDir(dirPath string) (map[string]string, map[string]string, error) {
ret := map[string]string{}
retPath := map[string]string{}
Expand Down
3 changes: 1 addition & 2 deletions pkg/engine/op_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@ import (
"testing"
"time"

"github.com/GuanceCloud/platypus/pkg/engine/runtime"
"github.com/GuanceCloud/platypus/pkg/inimpl/guancecloud/funcs"
"github.com/GuanceCloud/platypus/pkg/inimpl/guancecloud/input"
"github.com/stretchr/testify/assert"
Expand Down Expand Up @@ -111,7 +110,7 @@ for a = 0; a < 12; a = a + 1 {

pt := input.GetPoint()
pt = input.InitPt(pt, "test", nil, nil, time.Now())
err := runtime.RunScriptWithRMapIn(script, pt, nil)
err := script.Run(pt, nil)
if err != nil {
t.Fatal(err.Error())
}
Expand Down
34 changes: 17 additions & 17 deletions pkg/engine/runtime/checkstmt.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ type ContextCheck struct {
continuestmt bool
}

func RunStmtsCheck(ctx *Context, ctxCheck *ContextCheck, nodes ast.Stmts) *errchain.PlError {
func RunStmtsCheck(ctx *Task, ctxCheck *ContextCheck, nodes ast.Stmts) *errchain.PlError {
for _, node := range nodes {
if err := RunStmtCheck(ctx, ctxCheck, node); err != nil {
return err
Expand All @@ -28,7 +28,7 @@ func RunStmtsCheck(ctx *Context, ctxCheck *ContextCheck, nodes ast.Stmts) *errch
return nil
}

func RunStmtCheck(ctx *Context, ctxCheck *ContextCheck, node *ast.Node) *errchain.PlError {
func RunStmtCheck(ctx *Task, ctxCheck *ContextCheck, node *ast.Node) *errchain.PlError {
if node == nil {
return nil
}
Expand Down Expand Up @@ -87,7 +87,7 @@ func RunStmtCheck(ctx *Context, ctxCheck *ContextCheck, node *ast.Node) *errchai
return nil
}

func RunListInitExprCheck(ctx *Context, ctxCheck *ContextCheck, expr *ast.ListLiteral) *errchain.PlError {
func RunListInitExprCheck(ctx *Task, ctxCheck *ContextCheck, expr *ast.ListLiteral) *errchain.PlError {
for _, v := range expr.List {
if err := RunStmtCheck(ctx, ctxCheck, v); err != nil {
return err.ChainAppend(ctx.name, expr.LBracket)
Expand All @@ -96,7 +96,7 @@ func RunListInitExprCheck(ctx *Context, ctxCheck *ContextCheck, expr *ast.ListLi
return nil
}

func RunMapInitExprCheck(ctx *Context, ctxCheck *ContextCheck, expr *ast.MapLiteral) *errchain.PlError {
func RunMapInitExprCheck(ctx *Task, ctxCheck *ContextCheck, expr *ast.MapLiteral) *errchain.PlError {
for _, v := range expr.KeyValeList {
switch v[0].NodeType { //nolint:exhaustive
case ast.TypeFloatLiteral, ast.TypeIntegerLiteral,
Expand All @@ -116,11 +116,11 @@ func RunMapInitExprCheck(ctx *Context, ctxCheck *ContextCheck, expr *ast.MapLite
return nil
}

func RunParenExprCheck(ctx *Context, ctxCheck *ContextCheck, expr *ast.ParenExpr) *errchain.PlError {
func RunParenExprCheck(ctx *Task, ctxCheck *ContextCheck, expr *ast.ParenExpr) *errchain.PlError {
return RunStmtCheck(ctx, ctxCheck, expr.Param)
}

func RunAttrExprCheck(ctx *Context, ctxCheck *ContextCheck, expr *ast.AttrExpr) *errchain.PlError {
func RunAttrExprCheck(ctx *Task, ctxCheck *ContextCheck, expr *ast.AttrExpr) *errchain.PlError {
if err := RunStmtCheck(ctx, ctxCheck, expr.Obj); err != nil {
return err
}
Expand All @@ -131,7 +131,7 @@ func RunAttrExprCheck(ctx *Context, ctxCheck *ContextCheck, expr *ast.AttrExpr)
return nil
}

func RunArithmeticExprCheck(ctx *Context, ctxCheck *ContextCheck, expr *ast.ArithmeticExpr) *errchain.PlError {
func RunArithmeticExprCheck(ctx *Task, ctxCheck *ContextCheck, expr *ast.ArithmeticExpr) *errchain.PlError {
if err := RunStmtCheck(ctx, ctxCheck, expr.LHS); err != nil {
return err
}
Expand All @@ -145,7 +145,7 @@ func RunArithmeticExprCheck(ctx *Context, ctxCheck *ContextCheck, expr *ast.Arit
return nil
}

func RunConditionExprCheck(ctx *Context, ctxCheck *ContextCheck, expr *ast.ConditionalExpr) *errchain.PlError {
func RunConditionExprCheck(ctx *Task, ctxCheck *ContextCheck, expr *ast.ConditionalExpr) *errchain.PlError {
if err := RunStmtCheck(ctx, ctxCheck, expr.LHS); err != nil {
return err
}
Expand All @@ -155,14 +155,14 @@ func RunConditionExprCheck(ctx *Context, ctxCheck *ContextCheck, expr *ast.Condi
return nil
}

func RunUnaryExprCheck(ctx *Context, ctxCheck *ContextCheck, expr *ast.UnaryExpr) *errchain.PlError {
func RunUnaryExprCheck(ctx *Task, ctxCheck *ContextCheck, expr *ast.UnaryExpr) *errchain.PlError {
if err := RunStmtCheck(ctx, ctxCheck, expr.RHS); err != nil {
return err
}
return nil
}

func RunIndexExprGetCheck(ctx *Context, ctxCheck *ContextCheck, expr *ast.IndexExpr) *errchain.PlError {
func RunIndexExprGetCheck(ctx *Task, ctxCheck *ContextCheck, expr *ast.IndexExpr) *errchain.PlError {
for _, v := range expr.Index {
if err := RunStmtCheck(ctx, ctxCheck, v); err != nil {
return err
Expand All @@ -171,7 +171,7 @@ func RunIndexExprGetCheck(ctx *Context, ctxCheck *ContextCheck, expr *ast.IndexE
return nil
}

func RunCallExprCheck(ctx *Context, ctxCheck *ContextCheck, expr *ast.CallExpr) *errchain.PlError {
func RunCallExprCheck(ctx *Task, ctxCheck *ContextCheck, expr *ast.CallExpr) *errchain.PlError {
_, ok := ctx.GetFuncCall(expr.Name)
if !ok {
return NewRunError(ctx, fmt.Sprintf(
Expand All @@ -191,7 +191,7 @@ func RunCallExprCheck(ctx *Context, ctxCheck *ContextCheck, expr *ast.CallExpr)
return funcCheck(ctx, expr)
}

func RunAssignmentExprCheck(ctx *Context, ctxCheck *ContextCheck, expr *ast.AssignmentExpr) *errchain.PlError {
func RunAssignmentExprCheck(ctx *Task, ctxCheck *ContextCheck, expr *ast.AssignmentExpr) *errchain.PlError {
if err := RunStmtCheck(ctx, ctxCheck, expr.RHS); err != nil {
return err
}
Expand All @@ -201,7 +201,7 @@ func RunAssignmentExprCheck(ctx *Context, ctxCheck *ContextCheck, expr *ast.Assi
return nil
}

func RunIfElseStmtCheck(ctx *Context, ctxCheck *ContextCheck, stmt *ast.IfelseStmt) *errchain.PlError {
func RunIfElseStmtCheck(ctx *Task, ctxCheck *ContextCheck, stmt *ast.IfelseStmt) *errchain.PlError {
ctx.StackEnterNew()
defer ctx.StackExitCur()

Expand Down Expand Up @@ -230,7 +230,7 @@ func RunIfElseStmtCheck(ctx *Context, ctxCheck *ContextCheck, stmt *ast.IfelseSt
return nil
}

func RunForStmtCheck(ctx *Context, ctxCheck *ContextCheck, stmt *ast.ForStmt) *errchain.PlError {
func RunForStmtCheck(ctx *Task, ctxCheck *ContextCheck, stmt *ast.ForStmt) *errchain.PlError {
ctx.StackEnterNew()
defer ctx.StackExitCur()

Expand Down Expand Up @@ -268,7 +268,7 @@ func RunForStmtCheck(ctx *Context, ctxCheck *ContextCheck, stmt *ast.ForStmt) *e
return nil
}

func RunForInStmtCheck(ctx *Context, ctxCheck *ContextCheck, stmt *ast.ForInStmt) *errchain.PlError {
func RunForInStmtCheck(ctx *Task, ctxCheck *ContextCheck, stmt *ast.ForInStmt) *errchain.PlError {
ctx.StackEnterNew()
defer ctx.StackExitCur()

Expand Down Expand Up @@ -303,15 +303,15 @@ func RunForInStmtCheck(ctx *Context, ctxCheck *ContextCheck, stmt *ast.ForInStmt
return nil
}

func RunBreakStmtCheck(ctx *Context, ctxCheck *ContextCheck, stmt *ast.BreakStmt) *errchain.PlError {
func RunBreakStmtCheck(ctx *Task, ctxCheck *ContextCheck, stmt *ast.BreakStmt) *errchain.PlError {
if len(ctxCheck.forstmt) == 0 {
return NewRunError(ctx, "break not in loop", stmt.Start)
}
ctxCheck.breakstmt = true
return nil
}

func RunContinueStmtCheck(ctx *Context, ctxCheck *ContextCheck, stmt *ast.ContinueStmt) *errchain.PlError {
func RunContinueStmtCheck(ctx *Task, ctxCheck *ContextCheck, stmt *ast.ContinueStmt) *errchain.PlError {
if len(ctxCheck.forstmt) == 0 {
return NewRunError(ctx, "continue not in loop", stmt.Start)
}
Expand Down
Loading

0 comments on commit 21f3924

Please sign in to comment.