-
Notifications
You must be signed in to change notification settings - Fork 7
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
wip(std): experiment with reduce and math operators as reducers
- Loading branch information
Showing
17 changed files
with
132 additions
and
24 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
package test | ||
|
||
import ( | ||
"context" | ||
"os" | ||
"os/exec" | ||
"testing" | ||
"time" | ||
|
||
"github.com/stretchr/testify/require" | ||
) | ||
|
||
func Test(t *testing.T) { | ||
err := os.Chdir("..") | ||
require.NoError(t, err) | ||
|
||
wd, err := os.Getwd() | ||
require.NoError(t, err) | ||
defer os.Chdir(wd) | ||
|
||
for i := 0; i < 100; i++ { | ||
cmd := exec.Command("neva", "run", "filter_list") | ||
|
||
// Set a timeout for the command | ||
ctx, cancel := context.WithTimeout(context.Background(), 5*time.Second) | ||
defer cancel() | ||
cmd = exec.CommandContext(ctx, cmd.Path, cmd.Args[1:]...) | ||
|
||
out, err := cmd.CombinedOutput() | ||
if err != nil { | ||
if ctx.Err() == context.DeadlineExceeded { | ||
t.Fatal("Command timed out after 5 seconds") | ||
} | ||
require.NoError(t, err) | ||
} | ||
|
||
require.Equal( | ||
t, | ||
"55\n", | ||
string(out), | ||
) | ||
|
||
require.Equal(t, 0, cmd.ProcessState.ExitCode()) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
const lst list<int> = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10] | ||
|
||
flow Main(start) (stop) { | ||
Iter, Reduce{AddReducer}, Println | ||
--- | ||
:start -> ( | ||
$lst -> iter -> reduce -> println -> :stop | ||
) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
package funcs | ||
|
||
import ( | ||
"context" | ||
|
||
"github.com/nevalang/neva/internal/runtime" | ||
) | ||
|
||
type intAddReducer struct{} | ||
|
||
func (intAddReducer) Create( | ||
io runtime.IO, | ||
_ runtime.Msg, | ||
) (func(ctx context.Context), error) { | ||
firstIn, err := io.In.Single("first") | ||
if err != nil { | ||
return nil, err | ||
} | ||
|
||
secondIn, err := io.In.Single("second") | ||
if err != nil { | ||
return nil, err | ||
} | ||
|
||
resOut, err := io.Out.Single("res") | ||
if err != nil { | ||
return nil, err | ||
} | ||
|
||
return func(ctx context.Context) { | ||
for { | ||
firstMsg, ok := firstIn.Receive(ctx) | ||
if !ok { | ||
return | ||
} | ||
|
||
secondMsg, ok := secondIn.Receive(ctx) | ||
if !ok { | ||
return | ||
} | ||
|
||
resMsg := runtime.NewIntMsg(firstMsg.Int() + secondMsg.Int()) | ||
if !resOut.Send(ctx, resMsg) { | ||
return | ||
} | ||
} | ||
}, nil | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters