Skip to content
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

Added err outport for Println. #860

Draft
wants to merge 6 commits into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from 1 commit
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
Prev Previous commit
Next Next commit
Changed Tap implementation to fix possible deadlocks. Adjusted for_wi…
…th_range_and_if test to use errors.Lift. Changed errors_lift test to not print out a number anymore. Adjusted examples and other tests for new println implementation.
  • Loading branch information
MDH0 committed Feb 14, 2025
commit 52db95fe46348807e552bb84a27581850cd7e182
2 changes: 1 addition & 1 deletion e2e/cli/build_windows/neva.yml
Original file line number Diff line number Diff line change
@@ -1 +1 @@
neva: 0.31.0
neva: 0.31.2
2 changes: 1 addition & 1 deletion e2e/cli/new_and_run/neva.yml
Original file line number Diff line number Diff line change
@@ -1 +1 @@
neva: 0.31.0
neva: 0.31.2
8 changes: 4 additions & 4 deletions e2e/compiler_error_unused_outport/main/main.neva
Original file line number Diff line number Diff line change
Expand Up @@ -3,17 +3,17 @@ import { fmt }
def Main(start any) (stop any) {
sub1 SubComponent
sub2 SubComponent
panic Panic
---
:start -> 'Hi, Neva!' -> sub1:data
sub1:stop-> :stop
'1' -> sub2
[sub1:err, sub2:err] -> panic
}

def SubComponent(data string) (stop any, err error) {
println fmt.Println?
def SubComponent(data string) (stop any) {
println fmt.Println
panic Panic
---
:data -> println:data
println:res -> :stop
println:err -> panic
}
2 changes: 1 addition & 1 deletion e2e/errors_lift/e2e_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ func Test(t *testing.T) {
require.NoError(t, err)
require.Equal(
t,
"42\n",
"",
string(out),
)

Expand Down
4 changes: 1 addition & 3 deletions e2e/errors_lift/main/main.neva
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,5 @@ def Main(start any) (stop any) {

// Handler doesn't have error outport.
def Handler(data any) (res any) {
println fmt.Println<any>
---
:data -> '42' -> println -> :res
:data -> :res
}
7 changes: 5 additions & 2 deletions e2e/errors_must/main/main.neva
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,11 @@ import {
def Main(start any) (stop any) {
println fmt.Println<any>
must_handle errors.Must<any, any>{Handler}
panic Panic
---
:start -> 'create_me.txt' -> must_handle -> 'success!' -> println -> :stop
:start -> 'create_me.txt' -> must_handle -> 'success!' -> println
println:res -> :stop
println:err -> panic
}

// Handler have error outport.
Expand All @@ -18,5 +21,5 @@ def Handler(data string) (res any, err error) {
---
:data -> write_all:filename
'Hello, io.WriteAll!' -> write_all:data
write_all -> :res
write_all:res -> :res
}
1 change: 0 additions & 1 deletion e2e/for_with_range_and_if/e2e_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@ import (
)

func Test(t *testing.T) {
t.Skip("Remove this skip, until errors.Lift has been implemented.")
for i := 0; i < 10; i++ {
t.Run("", func(t *testing.T) {
cmd := exec.Command("neva", "run", "main")
Expand Down
6 changes: 4 additions & 2 deletions e2e/for_with_range_and_if/main/main.neva
Original file line number Diff line number Diff line change
Expand Up @@ -10,11 +10,13 @@ def Main(start any) (stop any) {
for:err -> panic
}

def PrintAsNum(data bool) (sig any) {
def PrintAsNum(data bool) (res any, err error) {
Ternary, fmt.Println
---
:data -> ternary:if
1 -> ternary:then
0 -> ternary:else
ternary -> println -> :sig
ternary -> println
println:res -> :res
println:err -> :err
}
4 changes: 2 additions & 2 deletions e2e/slow_iteration_with_for/main/main.neva
Original file line number Diff line number Diff line change
Expand Up @@ -14,12 +14,12 @@ def Main(start any) (stop any) {
for:err -> panic
}

def Slow(data int) (sig any, err error) {
def Slow(data int) (res any, err error) {
time.Delay<int>
fmt.Println<int>?
---
:data -> delay:data
$time.second -> delay:dur
delay -> println:data
println:res -> :sig
println:res -> :res
}
13 changes: 7 additions & 6 deletions examples/99_bottles/main.neva
Original file line number Diff line number Diff line change
Expand Up @@ -10,15 +10,16 @@ def Main(start any) (stop any) {
print:err -> panic
}

def Next2Lines(data int) (sig any, err error) {
def Next2Lines(data int) (res any, err error) {
first Tap<int>{FirstLine}?
dec Dec<int>
second SecondLine?
---
:data -> first -> dec -> second -> :sig
:data -> first
first:res -> dec -> second -> :res
}

def FirstLine(data int) (sig any, err error) {
def FirstLine(data int) (res any, err error) {
p1 fmt.Println?
p2 fmt.Println?
p3 fmt.Printf?
Expand All @@ -31,10 +32,10 @@ def FirstLine(data int) (sig any, err error) {
'$0 bottles of beer on the wall, $0 bottles of beer.\n' -> p3:tpl
]
}
[p1:res, p2:res, p3:sig] -> :sig
[p1:res, p2:res, p3:sig] -> :res
}

def SecondLine(data int) (sig any, err error) {
def SecondLine(data int) (res any, err error) {
p1 fmt.Println?
p2 fmt.Println?
p3 fmt.Println?
Expand All @@ -49,5 +50,5 @@ def SecondLine(data int) (sig any, err error) {
'Take one down and pass it around, $0 bottles of beer on the wall.\n\n' -> p4:tpl
]
}
[p1:res, p2:res, p3:res, p4:sig] -> :sig
[p1:res, p2:res, p3:res, p4:sig] -> :res
}
5 changes: 3 additions & 2 deletions examples/file_write_all/main.neva
Original file line number Diff line number Diff line change
@@ -1,12 +1,13 @@
import { io, fmt }

def Main(start any) (stop any) {
io.WriteAll, fmt.Println
io.WriteAll, fmt.Println, Panic
---
:start -> [
'file_writer_example.txt' -> writeAll:filename,
'Hello, io.WriteAll!' -> writeAll:data
]
writeAll:err -> println
[writeAll:res, println] -> :stop
[writeAll:res, println:res] -> :stop
println:err -> panic
}
4 changes: 3 additions & 1 deletion examples/image_png/main.neva
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ def Main(start any) (stop any) {
image.New, image.Encode
NewPixel, NewColor, NewStream,
io.WriteAll, printErr fmt.Println
panic Panic
---
:start -> [
0 -> [newColor:r, newColor:g, newColor:b, newColor:a],
Expand All @@ -44,5 +45,6 @@ def Main(start any) (stop any) {
new:img -> encode:img
encode:data -> writeAll:data
[new:err, encode:err, writeAll:err] -> printErr
[writeAll:res, printErr] -> :stop
[writeAll:res, printErr:res] -> :stop
printErr:err -> panic
}
14 changes: 10 additions & 4 deletions std/builtin/core.neva
Original file line number Diff line number Diff line change
Expand Up @@ -64,13 +64,19 @@ pub def Pass<T>(data T) (res T) {
// sends a signal when finishes. Signal could be of any type, so no need for
// dealing with locks manually. Handler can send error, in that case `Tap` will
// propagate it up to parent node.
pub def Tap<T>(data T) (res T) {
pub def Tap<T>(data T) (res T, err error) {
proxy1 Pass<T>
proxy2 Pass<T>
lock Lock<T>
handler ITapHandler<T>
---
:data -> [handler, lock:data]
handler -> lock:sig
:data -> [lock:data, handler]

handler:res -> proxy1
handler:err -> [proxy2, :err]

[proxy1, proxy2] -> lock:sig
lock -> :res
}

pub interface ITapHandler<T>(T) (any)
pub interface ITapHandler<T>(T) (res any, err error)
Loading