Commit 0d079a53 authored by Ken Thompson's avatar Ken Thompson

start of coroutine

SVN=126152
parent c0eb7026
......@@ -581,6 +581,7 @@ Node* nodpanic(long);
Node* newcompat(Node*);
Node* stringop(Node*, int);
Node* mapop(Node*, int);
Node* procop(Node*);
Node* convas(Node*);
void arrayconv(Type*, Node*);
Node* colas(Node*, Node*);
......
......@@ -388,7 +388,8 @@ semi_stmt:
}
| LGO pexpr '(' oexpr_list ')'
{
$$ = nod(OPROC, $2, $4);
$$ = nod(OCALL, $2, $4);
$$ = nod(OPROC, $$, N);
}
| LPRINT expr_list
{
......
......@@ -31,10 +31,10 @@ func envv(int32) string;
func frexp(float64) (int32, float64); // break fp into exp,fract
func ldexp(int32, float64) float64; // make fp from exp,fract
func modf(float64) (float64, float64); // break fp into double.double
func isInf(float64, int32) bool; // test for infinity
func isNaN(float64) bool; // test for not-a-number
func Inf(int32) float64; // return signed Inf
func NaN() float64; // return a NaN
func isInf(float64, int32) bool; // test for infinity
func isNaN(float64) bool; // test for not-a-number
func Inf(int32) float64; // return signed Inf
func NaN() float64; // return a NaN
func newmap(keysize uint32, valsize uint32,
keyalg uint32, valalg uint32,
......@@ -44,6 +44,8 @@ func mapaccess2(hmap *map[any]any, key any) (val any, pres bool);
func mapassign1(hmap *map[any]any, key any, val any);
func mapassign2(hmap *map[any]any, key any, val any, pres bool);
func newproc() bool; // create a new coroutine; true is child
func readfile(string) (string, bool); // read file into string; boolean status
func exit(int32);
......@@ -91,6 +93,9 @@ export
mapassign1
mapassign2
// threads/coroutines
newproc
// files
readfile
......
This diff is collapsed.
......@@ -156,6 +156,12 @@ loop:
n = n->nbody;
goto loop;
case OPROC:
if(top != Etop)
goto nottop;
*n = *procop(n);
goto ret;
case OCALLMETH:
case OCALLINTER:
case OCALL:
......@@ -1588,6 +1594,27 @@ nottop:
return N;
}
Node*
procop(Node *n)
{
Node *r, *on;
switch(n->op) {
default:
fatal("mapop: unknown op %E", n->op);
case OPROC: // rewrite if(sys.newproc()) (n->left)
on = syslook("newproc", 0);
r = nod(OIF, N, N);
r->ntest = nod(OCALL, on, N);
r->nbody = n->left;
dump("newproc", r);
walktype(r, Etop);
break;
}
return r;
}
void
diagnamed(Type *t)
{
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment