Skip to content

major reorg of machines to move files into sub-packages #18

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 4 commits into from
Apr 9, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 9 additions & 9 deletions engine/benchmark_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -34,8 +34,8 @@ import (
"github.com/robbyt/go-polyscript/engine/options"
"github.com/robbyt/go-polyscript/execution/constants"
"github.com/robbyt/go-polyscript/execution/data"
"github.com/robbyt/go-polyscript/machines/risor"
"github.com/robbyt/go-polyscript/machines/starlark"
risorCompiler "github.com/robbyt/go-polyscript/machines/risor/compiler"
starlarkCompiler "github.com/robbyt/go-polyscript/machines/starlark/compiler"
)

// quietHandler is a slog.Handler that discards all logs
Expand Down Expand Up @@ -71,7 +71,7 @@ func BenchmarkEvaluationPatterns(b *testing.B) {
options.WithDefaults(),
options.WithDataProvider(dataProvider),
options.WithLogHandler(quietHandler),
risor.WithGlobals([]string{constants.Ctx}),
risorCompiler.WithGlobals([]string{constants.Ctx}),
)
if err != nil {
b.Fatalf("Failed to create evaluator: %v", err)
Expand All @@ -95,7 +95,7 @@ func BenchmarkEvaluationPatterns(b *testing.B) {
options.WithDefaults(),
options.WithDataProvider(dataProvider),
options.WithLogHandler(quietHandler),
risor.WithGlobals([]string{constants.Ctx}),
risorCompiler.WithGlobals([]string{constants.Ctx}),
)
if err != nil {
b.Fatalf("Failed to create evaluator: %v", err)
Expand Down Expand Up @@ -139,7 +139,7 @@ func BenchmarkDataProviders(b *testing.B) {
options.WithDefaults(),
options.WithDataProvider(dataProvider),
options.WithLogHandler(quietHandler),
risor.WithGlobals([]string{constants.Ctx}),
risorCompiler.WithGlobals([]string{constants.Ctx}),
)
if err != nil {
b.Fatalf("Failed to create evaluator: %v", err)
Expand All @@ -161,7 +161,7 @@ func BenchmarkDataProviders(b *testing.B) {
options.WithDefaults(),
options.WithDataProvider(dataProvider),
options.WithLogHandler(quietHandler),
risor.WithGlobals([]string{constants.Ctx}),
risorCompiler.WithGlobals([]string{constants.Ctx}),
)
if err != nil {
b.Fatalf("Failed to create evaluator: %v", err)
Expand All @@ -188,7 +188,7 @@ func BenchmarkDataProviders(b *testing.B) {
options.WithDefaults(),
options.WithDataProvider(compositeProvider),
options.WithLogHandler(quietHandler),
risor.WithGlobals([]string{constants.Ctx}),
risorCompiler.WithGlobals([]string{constants.Ctx}),
)
if err != nil {
b.Fatalf("Failed to create evaluator: %v", err)
Expand Down Expand Up @@ -245,7 +245,7 @@ message = "Hello, " + name + "!"
options.WithDefaults(),
options.WithDataProvider(staticProvider),
options.WithLogHandler(quietHandler),
risor.WithGlobals([]string{constants.Ctx}),
risorCompiler.WithGlobals([]string{constants.Ctx}),
)
if err != nil {
b.Fatalf("Failed to create Risor evaluator: %v", err)
Expand All @@ -266,7 +266,7 @@ message = "Hello, " + name + "!"
options.WithDefaults(),
options.WithDataProvider(staticProvider),
options.WithLogHandler(quietHandler),
starlark.WithGlobals([]string{constants.Ctx}),
starlarkCompiler.WithGlobals([]string{constants.Ctx}),
)
if err != nil {
b.Fatalf("Failed to create Starlark evaluator: %v", err)
Expand Down
8 changes: 4 additions & 4 deletions engine/evaluator_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ import (
"github.com/robbyt/go-polyscript/engine/options"
"github.com/robbyt/go-polyscript/execution/constants"
"github.com/robbyt/go-polyscript/execution/data"
"github.com/robbyt/go-polyscript/machines/risor"
risorCompiler "github.com/robbyt/go-polyscript/machines/risor/compiler"
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"
)
Expand All @@ -32,7 +32,7 @@ method + " " + greeting
`,
options.WithLogHandler(handler),
options.WithDataProvider(provider),
risor.WithGlobals([]string{constants.Ctx}),
risorCompiler.WithGlobals([]string{constants.Ctx}),
)
require.NoError(t, err)
require.NotNil(t, evaluator)
Expand Down Expand Up @@ -86,7 +86,7 @@ func TestEvaluatorWithPrepErrors(t *testing.T) {
evaluator, err := polyscript.FromRisorString(`ctx["static"]`,
options.WithLogHandler(handler),
options.WithDataProvider(staticProvider),
risor.WithGlobals([]string{constants.Ctx}),
risorCompiler.WithGlobals([]string{constants.Ctx}),
)
require.NoError(t, err)

Expand All @@ -108,7 +108,7 @@ func TestEvaluatorWithPrepErrors(t *testing.T) {
evaluator, err = polyscript.FromRisorString(`ctx["request"]["ID"] || "no id"`,
options.WithLogHandler(handler),
options.WithDataProvider(contextProvider),
risor.WithGlobals([]string{constants.Ctx}),
risorCompiler.WithGlobals([]string{constants.Ctx}),
)
require.NoError(t, err)

Expand Down
4 changes: 2 additions & 2 deletions examples/data-prep/extism/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ import (
"github.com/robbyt/go-polyscript/engine/options"
"github.com/robbyt/go-polyscript/execution/constants"
"github.com/robbyt/go-polyscript/execution/data"
"github.com/robbyt/go-polyscript/machines/extism"
"github.com/robbyt/go-polyscript/machines/extism/compiler"
)

// ExtismEvaluator is a type alias to make testing cleaner
Expand All @@ -41,7 +41,7 @@ func createExtismEvaluator(
wasmFilePath,
options.WithLogHandler(logger.Handler()),
options.WithDataProvider(compositeProvider),
extism.WithEntryPoint("greet"),
compiler.WithEntryPoint("greet"),
)
}

Expand Down
4 changes: 2 additions & 2 deletions examples/data-prep/risor/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ import (
"github.com/robbyt/go-polyscript/engine/options"
"github.com/robbyt/go-polyscript/execution/constants"
"github.com/robbyt/go-polyscript/execution/data"
"github.com/robbyt/go-polyscript/machines/risor"
"github.com/robbyt/go-polyscript/machines/risor/compiler"
)

// RisorEvaluator is a type alias to make testing cleaner
Expand Down Expand Up @@ -47,7 +47,7 @@ func createRisorEvaluator(
options.WithDefaults(),
options.WithLogHandler(logger.Handler()),
options.WithDataProvider(compositeProvider),
risor.WithGlobals(globals),
compiler.WithGlobals(globals),
)
}

Expand Down
4 changes: 2 additions & 2 deletions examples/data-prep/starlark/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ import (
"github.com/robbyt/go-polyscript/engine/options"
"github.com/robbyt/go-polyscript/execution/constants"
"github.com/robbyt/go-polyscript/execution/data"
"github.com/robbyt/go-polyscript/machines/starlark"
"github.com/robbyt/go-polyscript/machines/starlark/compiler"
)

// StarlarkEvaluator is a type alias to make testing cleaner
Expand Down Expand Up @@ -49,7 +49,7 @@ func createStarlarkEvaluator(
options.WithDefaults(),
options.WithLogHandler(logger.Handler()),
options.WithDataProvider(compositeProvider),
starlark.WithGlobals(globals),
compiler.WithGlobals(globals),
)
}

Expand Down
4 changes: 2 additions & 2 deletions examples/multiple-instantiation/extism/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ import (
"github.com/robbyt/go-polyscript/engine/options"
"github.com/robbyt/go-polyscript/execution/constants"
"github.com/robbyt/go-polyscript/execution/data"
"github.com/robbyt/go-polyscript/machines/extism"
"github.com/robbyt/go-polyscript/machines/extism/compiler"
)

// ExtismEvaluator is a type alias to make testing cleaner
Expand Down Expand Up @@ -67,7 +67,7 @@ func createEvaluator(handler slog.Handler) (ExtismEvaluator, error) {
wasmFilePath,
options.WithLogHandler(handler),
options.WithDataProvider(dataProvider),
extism.WithEntryPoint("greet"),
compiler.WithEntryPoint("greet"),
)
if err != nil {
logger.Error("Failed to create evaluator", "error", err)
Expand Down
4 changes: 2 additions & 2 deletions examples/multiple-instantiation/risor/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ import (
"github.com/robbyt/go-polyscript/engine/options"
"github.com/robbyt/go-polyscript/execution/constants"
"github.com/robbyt/go-polyscript/execution/data"
"github.com/robbyt/go-polyscript/machines/risor"
"github.com/robbyt/go-polyscript/machines/risor/compiler"
)

// RisorEvaluator is a type alias to make testing cleaner
Expand Down Expand Up @@ -40,7 +40,7 @@ func createEvaluator(handler slog.Handler) (RisorEvaluator, error) {
options.WithDefaults(),
options.WithLogHandler(handler),
options.WithDataProvider(ctxProvider),
risor.WithGlobals(globals),
compiler.WithGlobals(globals),
)
if err != nil {
logger.Error("Failed to create evaluator", "error", err)
Expand Down
4 changes: 2 additions & 2 deletions examples/multiple-instantiation/starlark/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ import (
"github.com/robbyt/go-polyscript/engine/options"
"github.com/robbyt/go-polyscript/execution/constants"
"github.com/robbyt/go-polyscript/execution/data"
"github.com/robbyt/go-polyscript/machines/starlark"
"github.com/robbyt/go-polyscript/machines/starlark/compiler"
)

// StarlarkEvaluator is a type alias to make testing cleaner
Expand Down Expand Up @@ -40,7 +40,7 @@ func createEvaluator(handler slog.Handler) (StarlarkEvaluator, error) {
options.WithDefaults(),
options.WithLogHandler(handler),
options.WithDataProvider(ctxProvider),
starlark.WithGlobals(globals),
compiler.WithGlobals(globals),
)
if err != nil {
logger.Error("Failed to create evaluator", "error", err)
Expand Down
4 changes: 2 additions & 2 deletions examples/simple/extism/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ import (
"github.com/robbyt/go-polyscript"
"github.com/robbyt/go-polyscript/engine/options"
"github.com/robbyt/go-polyscript/execution/data"
"github.com/robbyt/go-polyscript/machines/extism"
"github.com/robbyt/go-polyscript/machines/extism/compiler"
)

// findWasmFile searches for the Extism WASM file in various likely locations
Expand Down Expand Up @@ -66,7 +66,7 @@ func runExtismExample(handler slog.Handler) (map[string]any, error) {
options.WithDefaults(),
options.WithLogHandler(handler),
options.WithDataProvider(dataProvider),
extism.WithEntryPoint("greet"),
compiler.WithEntryPoint("greet"),
)
if err != nil {
logger.Error("Failed to create evaluator", "error", err)
Expand Down
4 changes: 2 additions & 2 deletions examples/simple/risor/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ import (
"github.com/robbyt/go-polyscript/engine/options"
"github.com/robbyt/go-polyscript/execution/constants"
"github.com/robbyt/go-polyscript/execution/data"
"github.com/robbyt/go-polyscript/machines/risor"
"github.com/robbyt/go-polyscript/machines/risor/compiler"
)

//go:embed testdata/script.risor
Expand Down Expand Up @@ -39,7 +39,7 @@ func runRisorExample(handler slog.Handler) (map[string]any, error) {
options.WithDefaults(), // Add defaults option to ensure all required fields are set
options.WithLogHandler(handler),
options.WithDataProvider(dataProvider),
risor.WithGlobals(globals),
compiler.WithGlobals(globals),
)
if err != nil {
logger.Error("Failed to create evaluator", "error", err)
Expand Down
4 changes: 2 additions & 2 deletions examples/simple/starlark/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ import (
"github.com/robbyt/go-polyscript/engine/options"
"github.com/robbyt/go-polyscript/execution/constants"
"github.com/robbyt/go-polyscript/execution/data"
"github.com/robbyt/go-polyscript/machines/starlark"
"github.com/robbyt/go-polyscript/machines/starlark/compiler"
)

//go:embed testdata/script.star
Expand Down Expand Up @@ -39,7 +39,7 @@ func runStarlarkExample(handler slog.Handler) (map[string]any, error) {
options.WithDefaults(),
options.WithLogHandler(handler),
options.WithDataProvider(dataProvider),
starlark.WithGlobals(globals),
compiler.WithGlobals(globals),
)
if err != nil {
logger.Error("Failed to create evaluator", "error", err)
Expand Down
22 changes: 0 additions & 22 deletions execution/script/compilerOptions.go

This file was deleted.

8 changes: 0 additions & 8 deletions execution/script/errors.go

This file was deleted.

42 changes: 42 additions & 0 deletions execution/script/executableContent_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
package script

import (
"testing"

machineTypes "github.com/robbyt/go-polyscript/machines/types"
"github.com/stretchr/testify/require"
)

func TestExecutableContent(t *testing.T) {
t.Parallel()

t.Run("GetSource", func(t *testing.T) {
mockContent := new(MockExecutableContent)
expectedSource := "print('Hello, World!')"
mockContent.On("GetSource").Return(expectedSource)

source := mockContent.GetSource()
require.Equal(t, expectedSource, source, "Expected source to match")
mockContent.AssertExpectations(t)
})

t.Run("GetByteCode", func(t *testing.T) {
mockContent := new(MockExecutableContent)
expectedByteCode := []byte{0x01, 0x02, 0x03}
mockContent.On("GetByteCode").Return(expectedByteCode)

byteCode := mockContent.GetByteCode()
require.Equal(t, expectedByteCode, byteCode, "Expected bytecode to match")
mockContent.AssertExpectations(t)
})

t.Run("GetMachineType", func(t *testing.T) {
mockContent := new(MockExecutableContent)
expectedType := machineTypes.Risor
mockContent.On("GetMachineType").Return(expectedType)

machineType := mockContent.GetMachineType()
require.Equal(t, expectedType, machineType, "Expected machine type to match")
mockContent.AssertExpectations(t)
})
}
1 change: 0 additions & 1 deletion execution/script/executableUnit_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@ import (
var emptyScriptData = make(map[string]any)

// Mock implementations

type mockLoader struct {
mock.Mock
}
Expand Down
7 changes: 1 addition & 6 deletions execution/script/mocks.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ func (m *MockCompiler) Compile(scriptReader io.ReadCloser) (ExecutableContent, e
return execContent, args.Error(1)
}

// MockExecutableContent is a mock implementation of the ExecutableContent interface.
// MockExecutableContent is a mock implementation of the ExecutableContent interface for testing.
type MockExecutableContent struct {
mock.Mock
}
Expand All @@ -41,8 +41,3 @@ func (m *MockExecutableContent) GetMachineType() machineTypes.Type {
args := m.Called()
return args.Get(0).(machineTypes.Type)
}

func (m *MockExecutableContent) GetBodyChecksum() string {
args := m.Called()
return args.String(0)
}
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package extism
package adapters

import (
"context"
Expand All @@ -10,14 +10,14 @@ type ExtismExecutable struct {
GetExtismExecutable func() *extismSDK.CompiledPlugin
}

// compiledPlugin is an interface for abstracting the extismSDK.CompiledPlugin
type compiledPlugin interface {
Instance(ctx context.Context, config extismSDK.PluginInstanceConfig) (pluginInstance, error)
// CompiledPlugin is an interface for abstracting the extismSDK.CompiledPlugin
type CompiledPlugin interface {
Instance(ctx context.Context, config extismSDK.PluginInstanceConfig) (PluginInstance, error)
Close(ctx context.Context) error
}

// pluginInstance is an interface for abstracting the extismSDK.Plugin
type pluginInstance interface {
// PluginInstance is an interface for abstracting the extismSDK.Plugin
type PluginInstance interface {
Call(name string, data []byte) (uint32, []byte, error)
CallWithContext(ctx context.Context, name string, data []byte) (uint32, []byte, error)
FunctionExists(name string) bool
Expand Down
Loading