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

start of coroutine

SVN=126152
parent c0eb7026
...@@ -581,6 +581,7 @@ Node* nodpanic(long); ...@@ -581,6 +581,7 @@ Node* nodpanic(long);
Node* newcompat(Node*); Node* newcompat(Node*);
Node* stringop(Node*, int); Node* stringop(Node*, int);
Node* mapop(Node*, int); Node* mapop(Node*, int);
Node* procop(Node*);
Node* convas(Node*); Node* convas(Node*);
void arrayconv(Type*, Node*); void arrayconv(Type*, Node*);
Node* colas(Node*, Node*); Node* colas(Node*, Node*);
......
...@@ -388,7 +388,8 @@ semi_stmt: ...@@ -388,7 +388,8 @@ semi_stmt:
} }
| LGO pexpr '(' oexpr_list ')' | LGO pexpr '(' oexpr_list ')'
{ {
$$ = nod(OPROC, $2, $4); $$ = nod(OCALL, $2, $4);
$$ = nod(OPROC, $$, N);
} }
| LPRINT expr_list | LPRINT expr_list
{ {
......
...@@ -31,10 +31,10 @@ func envv(int32) string; ...@@ -31,10 +31,10 @@ func envv(int32) string;
func frexp(float64) (int32, float64); // break fp into exp,fract func frexp(float64) (int32, float64); // break fp into exp,fract
func ldexp(int32, float64) float64; // make fp from exp,fract func ldexp(int32, float64) float64; // make fp from exp,fract
func modf(float64) (float64, float64); // break fp into double.double func modf(float64) (float64, float64); // break fp into double.double
func isInf(float64, int32) bool; // test for infinity func isInf(float64, int32) bool; // test for infinity
func isNaN(float64) bool; // test for not-a-number func isNaN(float64) bool; // test for not-a-number
func Inf(int32) float64; // return signed Inf func Inf(int32) float64; // return signed Inf
func NaN() float64; // return a NaN func NaN() float64; // return a NaN
func newmap(keysize uint32, valsize uint32, func newmap(keysize uint32, valsize uint32,
keyalg uint32, valalg uint32, keyalg uint32, valalg uint32,
...@@ -44,6 +44,8 @@ func mapaccess2(hmap *map[any]any, key any) (val any, pres bool); ...@@ -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 mapassign1(hmap *map[any]any, key any, val any);
func mapassign2(hmap *map[any]any, key any, val any, pres bool); 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 readfile(string) (string, bool); // read file into string; boolean status
func exit(int32); func exit(int32);
...@@ -91,6 +93,9 @@ export ...@@ -91,6 +93,9 @@ export
mapassign1 mapassign1
mapassign2 mapassign2
// threads/coroutines
newproc
// files // files
readfile readfile
......
This diff is collapsed.
...@@ -156,6 +156,12 @@ loop: ...@@ -156,6 +156,12 @@ loop:
n = n->nbody; n = n->nbody;
goto loop; goto loop;
case OPROC:
if(top != Etop)
goto nottop;
*n = *procop(n);
goto ret;
case OCALLMETH: case OCALLMETH:
case OCALLINTER: case OCALLINTER:
case OCALL: case OCALL:
...@@ -1588,6 +1594,27 @@ nottop: ...@@ -1588,6 +1594,27 @@ nottop:
return N; 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 void
diagnamed(Type *t) 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