]> Cypherpunks repositories - gostls13.git/commitdiff
start of coroutine
authorKen Thompson <ken@golang.org>
Mon, 7 Jul 2008 19:29:26 +0000 (12:29 -0700)
committerKen Thompson <ken@golang.org>
Mon, 7 Jul 2008 19:29:26 +0000 (12:29 -0700)
SVN=126152

src/cmd/gc/go.h
src/cmd/gc/go.y
src/cmd/gc/sys.go
src/cmd/gc/sysimport.c
src/cmd/gc/walk.c

index 7f5b3829de00a2ee05ba0934f1dd4d00efa8c95d..9efbb390cbdef4e6cbd31095e645f671146bc9c7 100644 (file)
@@ -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*);
index 67345054d348719b5c79c05596838a5004ea62eb..1d72912f0d48b1e0e4127db03d97679190242a0a 100644 (file)
@@ -388,7 +388,8 @@ semi_stmt:
        }
 |      LGO pexpr '(' oexpr_list ')'
        {
-               $$ = nod(OPROC, $2, $4);
+               $$ = nod(OCALL, $2, $4);
+               $$ = nod(OPROC, $$, N);
        }
 |      LPRINT expr_list
        {
index 24f3a2c504d0c0280cde3c43c4a4aca486251c42..8bac583fc80968b7a0d2e66bacceb77beb02d54f 100644 (file)
@@ -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
 
index c84005054c893ebbadef95afa2691c44f8bde06a..6ff9b4ffbe8c049cbaa6be9fca1cec91dd94bfff 100644 (file)
@@ -3,10 +3,10 @@ char* sysimport =
        "type sys._e002 {}\n"
        "type sys.any 24\n"
        "type sys._e003 *sys.any\n"
-       "type sys._o247 {_e245 sys._e003}\n"
+       "type sys._o254 {_e252 sys._e003}\n"
        "type sys.uint32 6\n"
-       "type sys._i249 {_e246 sys.uint32}\n"
-       "type sys._e001 (sys._e002 sys._o247 sys._i249)\n"
+       "type sys._i256 {_e253 sys.uint32}\n"
+       "type sys._e001 (sys._e002 sys._o254 sys._i256)\n"
        "var !sys.mal sys._e001\n"
        "type sys._e005 {}\n"
        "type sys._e006 {}\n"
@@ -16,181 +16,186 @@ char*     sysimport =
        "type sys._e009 {}\n"
        "type sys._e010 {}\n"
        "type sys.int32 5\n"
-       "type sys._i255 {_e254 sys.int32}\n"
-       "type sys._e008 (sys._e009 sys._e010 sys._i255)\n"
+       "type sys._i262 {_e261 sys.int32}\n"
+       "type sys._e008 (sys._e009 sys._e010 sys._i262)\n"
        "var !sys.panicl sys._e008\n"
        "type sys._e012 {}\n"
        "type sys._e013 {}\n"
        "type sys.bool 12\n"
-       "type sys._i260 {_e259 sys.bool}\n"
-       "type sys._e011 (sys._e012 sys._e013 sys._i260)\n"
+       "type sys._i267 {_e266 sys.bool}\n"
+       "type sys._e011 (sys._e012 sys._e013 sys._i267)\n"
        "var !sys.printbool sys._e011\n"
        "type sys._e015 {}\n"
        "type sys._e016 {}\n"
        "type sys.float64 10\n"
-       "type sys._i265 {_e264 sys.float64}\n"
-       "type sys._e014 (sys._e015 sys._e016 sys._i265)\n"
+       "type sys._i272 {_e271 sys.float64}\n"
+       "type sys._e014 (sys._e015 sys._e016 sys._i272)\n"
        "var !sys.printfloat sys._e014\n"
        "type sys._e018 {}\n"
        "type sys._e019 {}\n"
        "type sys.int64 7\n"
-       "type sys._i270 {_e269 sys.int64}\n"
-       "type sys._e017 (sys._e018 sys._e019 sys._i270)\n"
+       "type sys._i277 {_e276 sys.int64}\n"
+       "type sys._e017 (sys._e018 sys._e019 sys._i277)\n"
        "var !sys.printint sys._e017\n"
        "type sys._e021 {}\n"
        "type sys._e022 {}\n"
        "type sys._e023 25\n"
        "type sys.string *sys._e023\n"
-       "type sys._i275 {_e274 sys.string}\n"
-       "type sys._e020 (sys._e021 sys._e022 sys._i275)\n"
+       "type sys._i282 {_e281 sys.string}\n"
+       "type sys._e020 (sys._e021 sys._e022 sys._i282)\n"
        "var !sys.printstring sys._e020\n"
        "type sys._e025 {}\n"
        "type sys._e026 {}\n"
        "type sys.uint8 2\n"
        "type sys._e027 *sys.uint8\n"
-       "type sys._i280 {_e279 sys._e027}\n"
-       "type sys._e024 (sys._e025 sys._e026 sys._i280)\n"
+       "type sys._i287 {_e286 sys._e027}\n"
+       "type sys._e024 (sys._e025 sys._e026 sys._i287)\n"
        "var !sys.printpointer sys._e024\n"
        "type sys._e029 {}\n"
-       "type sys._o287 {_e284 sys.string}\n"
-       "type sys._i289 {_e285 sys.string _e286 sys.string}\n"
-       "type sys._e028 (sys._e029 sys._o287 sys._i289)\n"
+       "type sys._o294 {_e291 sys.string}\n"
+       "type sys._i296 {_e292 sys.string _e293 sys.string}\n"
+       "type sys._e028 (sys._e029 sys._o294 sys._i296)\n"
        "var !sys.catstring sys._e028\n"
        "type sys._e031 {}\n"
-       "type sys._o297 {_e294 sys.int32}\n"
-       "type sys._i299 {_e295 sys.string _e296 sys.string}\n"
-       "type sys._e030 (sys._e031 sys._o297 sys._i299)\n"
+       "type sys._o304 {_e301 sys.int32}\n"
+       "type sys._i306 {_e302 sys.string _e303 sys.string}\n"
+       "type sys._e030 (sys._e031 sys._o304 sys._i306)\n"
        "var !sys.cmpstring sys._e030\n"
        "type sys._e033 {}\n"
-       "type sys._o308 {_e304 sys.string}\n"
-       "type sys._i310 {_e305 sys.string _e306 sys.int32 _e307 sys.int32}\n"
-       "type sys._e032 (sys._e033 sys._o308 sys._i310)\n"
+       "type sys._o315 {_e311 sys.string}\n"
+       "type sys._i317 {_e312 sys.string _e313 sys.int32 _e314 sys.int32}\n"
+       "type sys._e032 (sys._e033 sys._o315 sys._i317)\n"
        "var !sys.slicestring sys._e032\n"
        "type sys._e035 {}\n"
-       "type sys._o319 {_e316 sys.uint8}\n"
-       "type sys._i321 {_e317 sys.string _e318 sys.int32}\n"
-       "type sys._e034 (sys._e035 sys._o319 sys._i321)\n"
+       "type sys._o326 {_e323 sys.uint8}\n"
+       "type sys._i328 {_e324 sys.string _e325 sys.int32}\n"
+       "type sys._e034 (sys._e035 sys._o326 sys._i328)\n"
        "var !sys.indexstring sys._e034\n"
        "type sys._e037 {}\n"
-       "type sys._o328 {_e326 sys.string}\n"
-       "type sys._i330 {_e327 sys.int64}\n"
-       "type sys._e036 (sys._e037 sys._o328 sys._i330)\n"
+       "type sys._o335 {_e333 sys.string}\n"
+       "type sys._i337 {_e334 sys.int64}\n"
+       "type sys._e036 (sys._e037 sys._o335 sys._i337)\n"
        "var !sys.intstring sys._e036\n"
        "type sys._e039 {}\n"
-       "type sys._o337 {_e334 sys.string}\n"
+       "type sys._o344 {_e341 sys.string}\n"
        "type sys._e040 *sys.uint8\n"
-       "type sys._i339 {_e335 sys._e040 _e336 sys.int32}\n"
-       "type sys._e038 (sys._e039 sys._o337 sys._i339)\n"
+       "type sys._i346 {_e342 sys._e040 _e343 sys.int32}\n"
+       "type sys._e038 (sys._e039 sys._o344 sys._i346)\n"
        "var !sys.byteastring sys._e038\n"
        "type sys._e042 {}\n"
        "type sys._e043 <>\n"
-       "type sys._o348 {_e344 sys._e043}\n"
+       "type sys._o355 {_e351 sys._e043}\n"
        "type sys._e044 *sys.uint8\n"
        "type sys._e045 *sys.uint8\n"
-       "type sys._s355 {}\n"
-       "type sys._e046 *sys._s355\n"
-       "type sys._i350 {_e345 sys._e044 _e346 sys._e045 _e347 sys._e046}\n"
-       "type sys._e041 (sys._e042 sys._o348 sys._i350)\n"
+       "type sys._s362 {}\n"
+       "type sys._e046 *sys._s362\n"
+       "type sys._i357 {_e352 sys._e044 _e353 sys._e045 _e354 sys._e046}\n"
+       "type sys._e041 (sys._e042 sys._o355 sys._i357)\n"
        "var !sys.mkiface sys._e041\n"
        "type sys._e048 {}\n"
-       "type sys._o359 {_e358 sys.int32}\n"
+       "type sys._o366 {_e365 sys.int32}\n"
        "type sys._e049 {}\n"
-       "type sys._e047 (sys._e048 sys._o359 sys._e049)\n"
+       "type sys._e047 (sys._e048 sys._o366 sys._e049)\n"
        "var !sys.argc sys._e047\n"
        "type sys._e051 {}\n"
-       "type sys._o363 {_e362 sys.int32}\n"
+       "type sys._o370 {_e369 sys.int32}\n"
        "type sys._e052 {}\n"
-       "type sys._e050 (sys._e051 sys._o363 sys._e052)\n"
+       "type sys._e050 (sys._e051 sys._o370 sys._e052)\n"
        "var !sys.envc sys._e050\n"
        "type sys._e054 {}\n"
-       "type sys._o368 {_e366 sys.string}\n"
-       "type sys._i370 {_e367 sys.int32}\n"
-       "type sys._e053 (sys._e054 sys._o368 sys._i370)\n"
+       "type sys._o375 {_e373 sys.string}\n"
+       "type sys._i377 {_e374 sys.int32}\n"
+       "type sys._e053 (sys._e054 sys._o375 sys._i377)\n"
        "var !sys.argv sys._e053\n"
        "type sys._e056 {}\n"
-       "type sys._o376 {_e374 sys.string}\n"
-       "type sys._i378 {_e375 sys.int32}\n"
-       "type sys._e055 (sys._e056 sys._o376 sys._i378)\n"
+       "type sys._o383 {_e381 sys.string}\n"
+       "type sys._i385 {_e382 sys.int32}\n"
+       "type sys._e055 (sys._e056 sys._o383 sys._i385)\n"
        "var !sys.envv sys._e055\n"
        "type sys._e058 {}\n"
-       "type sys._o385 {_e382 sys.int32 _e383 sys.float64}\n"
-       "type sys._i387 {_e384 sys.float64}\n"
-       "type sys._e057 (sys._e058 sys._o385 sys._i387)\n"
+       "type sys._o392 {_e389 sys.int32 _e390 sys.float64}\n"
+       "type sys._i394 {_e391 sys.float64}\n"
+       "type sys._e057 (sys._e058 sys._o392 sys._i394)\n"
        "var !sys.frexp sys._e057\n"
        "type sys._e060 {}\n"
-       "type sys._o394 {_e391 sys.float64}\n"
-       "type sys._i396 {_e392 sys.int32 _e393 sys.float64}\n"
-       "type sys._e059 (sys._e060 sys._o394 sys._i396)\n"
+       "type sys._o401 {_e398 sys.float64}\n"
+       "type sys._i403 {_e399 sys.int32 _e400 sys.float64}\n"
+       "type sys._e059 (sys._e060 sys._o401 sys._i403)\n"
        "var !sys.ldexp sys._e059\n"
        "type sys._e062 {}\n"
-       "type sys._o404 {_e401 sys.float64 _e402 sys.float64}\n"
-       "type sys._i406 {_e403 sys.float64}\n"
-       "type sys._e061 (sys._e062 sys._o404 sys._i406)\n"
+       "type sys._o411 {_e408 sys.float64 _e409 sys.float64}\n"
+       "type sys._i413 {_e410 sys.float64}\n"
+       "type sys._e061 (sys._e062 sys._o411 sys._i413)\n"
        "var !sys.modf sys._e061\n"
        "type sys._e064 {}\n"
-       "type sys._o413 {_e410 sys.bool}\n"
-       "type sys._i415 {_e411 sys.float64 _e412 sys.int32}\n"
-       "type sys._e063 (sys._e064 sys._o413 sys._i415)\n"
+       "type sys._o420 {_e417 sys.bool}\n"
+       "type sys._i422 {_e418 sys.float64 _e419 sys.int32}\n"
+       "type sys._e063 (sys._e064 sys._o420 sys._i422)\n"
        "var !sys.isInf sys._e063\n"
        "type sys._e066 {}\n"
-       "type sys._o422 {_e420 sys.bool}\n"
-       "type sys._i424 {_e421 sys.float64}\n"
-       "type sys._e065 (sys._e066 sys._o422 sys._i424)\n"
+       "type sys._o429 {_e427 sys.bool}\n"
+       "type sys._i431 {_e428 sys.float64}\n"
+       "type sys._e065 (sys._e066 sys._o429 sys._i431)\n"
        "var !sys.isNaN sys._e065\n"
        "type sys._e068 {}\n"
-       "type sys._o430 {_e428 sys.float64}\n"
-       "type sys._i432 {_e429 sys.int32}\n"
-       "type sys._e067 (sys._e068 sys._o430 sys._i432)\n"
+       "type sys._o437 {_e435 sys.float64}\n"
+       "type sys._i439 {_e436 sys.int32}\n"
+       "type sys._e067 (sys._e068 sys._o437 sys._i439)\n"
        "var !sys.Inf sys._e067\n"
        "type sys._e070 {}\n"
-       "type sys._o437 {_e436 sys.float64}\n"
+       "type sys._o444 {_e443 sys.float64}\n"
        "type sys._e071 {}\n"
-       "type sys._e069 (sys._e070 sys._o437 sys._e071)\n"
+       "type sys._e069 (sys._e070 sys._o444 sys._e071)\n"
        "var !sys.NaN sys._e069\n"
        "type sys._e073 {}\n"
        "type sys._e075 [sys.any] sys.any\n"
        "type sys._e074 *sys._e075\n"
-       "type sys._o440 {hmap sys._e074}\n"
-       "type sys._i442 {keysize sys.uint32 valsize sys.uint32 keyalg sys.uint32 valalg sys.uint32 hint sys.uint32}\n"
-       "type sys._e072 (sys._e073 sys._o440 sys._i442)\n"
+       "type sys._o447 {hmap sys._e074}\n"
+       "type sys._i449 {keysize sys.uint32 valsize sys.uint32 keyalg sys.uint32 valalg sys.uint32 hint sys.uint32}\n"
+       "type sys._e072 (sys._e073 sys._o447 sys._i449)\n"
        "var !sys.newmap sys._e072\n"
        "type sys._e077 {}\n"
-       "type sys._o450 {val sys.any}\n"
+       "type sys._o458 {val sys.any}\n"
        "type sys._e079 [sys.any] sys.any\n"
        "type sys._e078 *sys._e079\n"
-       "type sys._i452 {hmap sys._e078 key sys.any}\n"
-       "type sys._e076 (sys._e077 sys._o450 sys._i452)\n"
+       "type sys._i460 {hmap sys._e078 key sys.any}\n"
+       "type sys._e076 (sys._e077 sys._o458 sys._i460)\n"
        "var !sys.mapaccess1 sys._e076\n"
        "type sys._e081 {}\n"
-       "type sys._o457 {val sys.any pres sys.bool}\n"
+       "type sys._o466 {val sys.any pres sys.bool}\n"
        "type sys._e083 [sys.any] sys.any\n"
        "type sys._e082 *sys._e083\n"
-       "type sys._i459 {hmap sys._e082 key sys.any}\n"
-       "type sys._e080 (sys._e081 sys._o457 sys._i459)\n"
+       "type sys._i468 {hmap sys._e082 key sys.any}\n"
+       "type sys._e080 (sys._e081 sys._o466 sys._i468)\n"
        "var !sys.mapaccess2 sys._e080\n"
        "type sys._e085 {}\n"
        "type sys._e086 {}\n"
        "type sys._e088 [sys.any] sys.any\n"
        "type sys._e087 *sys._e088\n"
-       "type sys._i464 {hmap sys._e087 key sys.any val sys.any}\n"
-       "type sys._e084 (sys._e085 sys._e086 sys._i464)\n"
+       "type sys._i475 {hmap sys._e087 key sys.any val sys.any}\n"
+       "type sys._e084 (sys._e085 sys._e086 sys._i475)\n"
        "var !sys.mapassign1 sys._e084\n"
        "type sys._e090 {}\n"
        "type sys._e091 {}\n"
        "type sys._e093 [sys.any] sys.any\n"
        "type sys._e092 *sys._e093\n"
-       "type sys._i470 {hmap sys._e092 key sys.any val sys.any pres sys.bool}\n"
-       "type sys._e089 (sys._e090 sys._e091 sys._i470)\n"
+       "type sys._i481 {hmap sys._e092 key sys.any val sys.any pres sys.bool}\n"
+       "type sys._e089 (sys._e090 sys._e091 sys._i481)\n"
        "var !sys.mapassign2 sys._e089\n"
        "type sys._e095 {}\n"
-       "type sys._o480 {_e477 sys.string _e478 sys.bool}\n"
-       "type sys._i482 {_e479 sys.string}\n"
-       "type sys._e094 (sys._e095 sys._o480 sys._i482)\n"
-       "var !sys.readfile sys._e094\n"
-       "type sys._e097 {}\n"
+       "type sys._o489 {_e488 sys.bool}\n"
+       "type sys._e096 {}\n"
+       "type sys._e094 (sys._e095 sys._o489 sys._e096)\n"
+       "var !sys.newproc sys._e094\n"
        "type sys._e098 {}\n"
-       "type sys._i487 {_e486 sys.int32}\n"
-       "type sys._e096 (sys._e097 sys._e098 sys._i487)\n"
-       "var !sys.exit sys._e096\n"
+       "type sys._o495 {_e492 sys.string _e493 sys.bool}\n"
+       "type sys._i497 {_e494 sys.string}\n"
+       "type sys._e097 (sys._e098 sys._o495 sys._i497)\n"
+       "var !sys.readfile sys._e097\n"
+       "type sys._e100 {}\n"
+       "type sys._e101 {}\n"
+       "type sys._i502 {_e501 sys.int32}\n"
+       "type sys._e099 (sys._e100 sys._e101 sys._i502)\n"
+       "var !sys.exit sys._e099\n"
        "))\n"
 ;
index 7d5dcd8bb49badfd84ad484a72d3e670e5fbc4c3..cc3431ebfc110cd4611e62acc62f7bd158e47f3e 100644 (file)
@@ -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)
 {