pschachte / wybe

A programming language supporting most of both declarative and imperative programming
MIT License
47 stars 6 forks source link

Add error function #436

Closed pschachte closed 10 months ago

pschachte commented 10 months ago

Closes #434

jimbxb commented 10 months ago

Just want to check: the call_source_location isn't passed into error/1 is it? Meaning the resource usage here is redundant.

pschachte commented 10 months ago

Yes, the source position is passed from the error function to the error proc, so that the source position is the position of the call to the error function. So the use is needed. But you're quite right that result needs a ? flow. I've added a test case to verify, and I had to allow calls to procs with only implicit resources to omit the ! to allow function calls to have implicit resources.

jimbxb commented 10 months ago

Oh, I wasn't aware of that functionality.

When the special resources are threaded though the program, it was my understanding that something like

def foo use call_source_location {
    !bar
}

def bar use call_source_location {
    pass
}

would become

def foo(call_source_location: string) {
    foreign lock move("location of bar call in foo", ?tmp)
    !bar(tmp)
}

def bar(call_source_location: string) {
    pass
}

with the resource not being passed from the foo caller into bar, but instead the location of the call in foo is passed through to bar.

I think the expected behaviour is as described here too, as the implicit resources contain information about the call's source location, not the parent's source location.

pschachte commented 10 months ago

In this example, foo would pass its parameter to bar. The call to foo pass the source location of the call as an argument in the call. So the actual source location is the location of the call to the proc that uses an implicit resource from a proc that doesn't use that resource. Which is what you want so the error function can call the error proc, and have the location of the call to the error function printed out.