Comments (7)
Maybe we should build another macro on top of {.cps.}
that automagically does this and #20 ?
(And maybe then rename the current cps
macro to cpsRaw
or something..)
from cps.
There's a bit of a problem with all this untyped stuff. We have 3 kinds of calls
- A call to a normal proc
- A call to another .cps. proc
- A call to a .cpsMagic. cps primitive proc
If we really want to hold op the illusion of magic, it would be cool if all of these would just look like any other normal call. No magic cps
keyword or cps.foo()
notation, just call a proc and let cps figure it out.
The problem is that I'm not sure if this can be done, since the .cps. macro does not know anything of outer context, so when you call foo()
, it has no way of knowin which of the above 3 cases should apply.
Prove me wrong, and I'll buy you a beer.
from cps.
proc foo(): Cont {.cps.} =
echo "Hello"
continue bar()
echo "There"
proc bar(): Cont {.cps.} =
echo "I'm bar"
from cps.
This can also be a thing soon:
proc foo() {.cps: Cont.} =
echo "Hello"
echo yield bar()
echo "There"
proc bar(): string {.cps: Cont.} =
result = "I'm bar"
from cps.
proc foo(): Cont {.cps.} = echo "Hello" continue bar() echo "There"
I'm against reusing keywords which have a different meaning in a different context. It's confusing for users and you might get bitten if you can't properly distinguish "real" continue
or yield
from your "new" continue
or yield
.
Apart from that, the question was whether we can induce things here, or if we need some kind of explicit keyword or operator. I don't think we can get there without more type info of what is living outside our .cps.
proc, so that's probably a "no" for now.
It's called cps
in the current implementation, which is confusing because it is the same name as the macro. yield
is taken, so let's assume we call it pass
for now, until we find a better name.
Next question, because you seem to thing rvalues can be a thing: Could we use the same keyword for things that do and things that don't result in an rvalue? That should be ok, because if what your calling is a .cps
.` proc that does not "return" something, there is also nothing to discard.
proc foo() {.cps: Cont.} =
pass hello() # Nothing "returned", nothing to discard
echo pass bar() # Nim forces the consume the result `bass bar()` because `bar()` returns a string
echo "There"
proc hell(): {.cps: Cont.} =
echo "hello"
proc bar(): string {.cps: Cont.} =
result = "I'm bar"
from cps.
I'm against reusing keywords which have a different meaning in a different context. It's confusing for users and you might get bitten if you can't properly distinguish "real" continue or yield from your "new" continue or yield.
Well, continue
is invalid with an argument and yield
is invalid outside of iterators. These keywords make sense in a .cps.
context, which the user expressly enabled. It's pretty easy for us to throw an error if .cps.
is applied to an iterator
, right? If there's an iterator inside the .cps.
body, we'll ignore it.
We will never have type information outside of .cps.
, as far as I can tell.
from cps.
Closed in typed branch.
from cps.
Related Issues (20)
- Error: cps doesn't know how to rewrite this into assignment: HOT 1
- The code in the doc doesn't work HOT 3
- support CPS transformations on nnkLambda and non-top-level procs HOT 1
- "... has no type" compilation error on `return`
- Compile time is growing HOT 3
- Handle inner procs HOT 3
- whelp can't process `borrow-ed` symbols HOT 1
- Calling a magic of a different base type is a runtime error instead of compile time
- Unable to overload voodoo/magic by continuation types HOT 3
- Performance benchmarks of tight loops etc. HOT 3
- cpsMagic overloading is broken on master HOT 2
- Cannot create a type referencing a local constant
- move cc syntax hack into continuation legs HOT 1
- lifted variables are not initialized when entering scope
- compiler crash when defining nested proc in continuation proc HOT 1
- CPS leaks under arc on cps-cps calls HOT 1
- CPS leaks when dropping the continuation in a cps-cps call HOT 1
- Support js target HOT 3
- CallNodes = nnkCallKinds HOT 8
- cps calls with variant object member fails due to lack of types
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from cps.