Path: utzoo!utgpu!news-server.csri.toronto.edu!rutgers!cmcl2!yale!think.com!sdd.hp.com!usc!apple!olivea!oliveb!isc-br!ewu!ttork From: ttork@ewu.UUCP (Terry Torkelson) Newsgroups: comp.sys.transputer Subject: Unix Occam Compiler (Part 3 of 4) Keywords: Occam Message-ID: <1339@ewu.UUCP> Date: 14 Nov 90 19:41:17 GMT Distribution: usa Organization: Eastern Washington Univ. Cheney WA Lines: 441 ----------test.shar---------- #! /bin/sh # This is a shell archive, meaning: # 1. Remove everything above the #! /bin/sh line. # 2. Save the resulting text in a file. # 3. Execute the file with /bin/sh (not csh) to create the files: # test # This archive created: Thu Apr 19 16:54:38 1990 export PATH; PATH=/bin:$PATH if test ! -d 'test' then mkdir 'test' fi cd 'test' if test -f 'semaphore.oc' then echo shar: will not over-write existing file "'semaphore.oc'" else cat << \SHAR_EOF > 'semaphore.oc' -- counting semaphore handler using buffered-channels in Occam. extern proc pnum(value n): def MAXSEM = 5: def MAXN = 100: -- maximum size of buffer of semaphores que sempool(MAXN)[MAXSEM]: var nsem: var s: proc setsem(value v, var sn) = seq sn := nsem nsem := nsem + 1 seq j = [0 for v] sempool[sn] ! ANY : proc p(value sn) = sempool[sn] ? ANY : proc v(value sn) = sempool[sn] ! ANY : seq setsem(3, s) -- first run without semahpores par p = [0 for 2] seq q = [0 for 10] pnum(p) -- then run with semaphores par i = [0 for 2] seq k = [0 for 10] seq p(s) pnum(i) v(s) SHAR_EOF fi # end of overwriting check if test -f 'SEM' then echo shar: will not over-write existing file "'SEM'" else cat << \SHAR_EOF > 'SEM' Executed 126 instructions in 66 time 1 1 1 1 1 1 1 1 1 1 0 0 0 0 0 0 0 0 0 0 0 1 0 1 1 0 0 1 0 1 1 0 0 1 1 0 0 1 0 1 SHAR_EOF fi # end of overwriting check if test -f 'RAND' then echo shar: will not over-write existing file "'RAND'" else cat << \SHAR_EOF > 'RAND' Panic: [8 ,101]: deadlock 5 9 6 6 5 3 5 6 8 1 5 6 1 8 7 2 7 5 9 3 8 6 3 8 7 1 3 3 4 4 9 3 8 5 1 9 5 6 3 4 0 9 8 5 1 3 8 8 3 4 SHAR_EOF fi # end of overwriting check if test -f 'TRACE' then echo shar: will not over-write existing file "'TRACE'" else cat << \SHAR_EOF > 'TRACE' [0 , 0] create 1 at 0x48 [1 , 0] opened 0(0) [1 , 0] opened 1(0) [1 , 0] opened 2(0) [1 , 0] open channel table at 0x4E4C - 5 [1 , 0] opened 3(0) [1 , 0] opened 4(0) [1 , 0] opened 5(0) [1 , 0] opened 6(0) [1 , 0] opened 7(0) [1 , 0] opened 8(0) [1 , 0] create 2 at 0xA8 [1 , 0] create 3 at 0xBE [2 , 0] read on 8 [3 , 0] create 4 at 0xD8 [3 , 0] create 5 at 0xD8 [3 , 0] create 6 at 0xD8 [3 , 0] create 7 at 0xD8 [3 , 0] create 8 at 0xD8 [6 ,2000] write on 8 [8 ,4000] write on 8 [5 ,1000] write on 8 [4 , 0] write on 8 [ Sys ] [8] sent 4 bytes from [4 , 0] to [2 , 0] [4 , 1] read on 3 [2 , 1] read on 8 [7 ,3000] write on 8 [ Sys ] [8] sent 4 bytes from [5 ,1000] to [2 , 1] [5 ,1001] read on 4 [2 ,1001] read on 8 [ Sys ] [8] sent 4 bytes from [6 ,2000] to [2 ,1001] [6 ,2001] read on 5 [2 ,2001] read on 8 [ Sys ] [8] sent 4 bytes from [7 ,3000] to [2 ,2001] [7 ,3001] read on 6 [2 ,3001] read on 8 [ Sys ] [8] sent 4 bytes from [8 ,4000] to [2 ,3001] [8 ,4001] read on 7 [2 ,4001] write on 3 [ Sys ] [3] sent 4 bytes from [2 ,4001] to [4 , 1] [2 ,4002] write on 4 [4 ,4002] write on 8 [ Sys ] [4] sent 4 bytes from [2 ,4002] to [5 ,1001] [2 ,4003] write on 5 [5 ,5003] write on 8 [ Sys ] [5] sent 4 bytes from [2 ,4003] to [6 ,2001] [2 ,4004] write on 6 [6 ,6004] write on 8 [ Sys ] [6] sent 4 bytes from [2 ,4004] to [7 ,3001] [2 ,4005] write on 7 [7 ,7005] write on 8 [ Sys ] [7] sent 4 bytes from [2 ,4005] to [8 ,4001] [2 ,4006] read on 8 [8 ,8006] write on 8 [ Sys ] [8] sent 4 bytes from [4 ,4002] to [2 ,4006] [2 ,4007] read on 8 [4 ,4007] read on 3 [ Sys ] [8] sent 4 bytes from [5 ,5003] to [2 ,4007] [5 ,5004] read on 4 [2 ,5004] read on 8 [ Sys ] [8] sent 4 bytes from [6 ,6004] to [2 ,5004] [6 ,6005] read on 5 [2 ,6005] read on 8 [ Sys ] [8] sent 4 bytes from [7 ,7005] to [2 ,6005] [7 ,7006] read on 6 [2 ,7006] read on 8 [2 ,7006] read on 8 b[ Sys ] [8] sent 4 bytes from [8 ,8006] to [2 ,7006] [8 ,8007] read on 7 [2 ,8007] write on 3 [ Sys ] [3] sent 4 bytes from [2 ,8007] to [4 ,4007] [2 ,8008] write on 4 [4 ,8009] ended [ Sys ] [4] sent 4 bytes from [2 ,8008] to [5 ,5004] [2 ,8009] write on 5 [5 ,8010] ended [ Sys ] [5] sent 4 bytes from [2 ,8009] to [6 ,6005] [2 ,8010] write on 6 [6 ,8011] ended [ Sys ] [6] sent 4 bytes from [2 ,8010] to [7 ,7006] [2 ,8011] write on 7 [7 ,8012] ended [ Sys ] [7] sent 4 bytes from [2 ,8011] to [8 ,8007] [2 ,8013] ended [8 ,8013] ended [3 ,8013] ended [1 ,8013] closed 8 [1 ,8013] close channel table at 0x4E4C - 5 [1 ,8013] closed 3 [1 ,8013] closed 4 [1 ,8013] closed 5 [1 ,8013] closed 6 [1 ,8013] closed 7 [1 ,8013] ended Executed 20046 instructions in 8013 time SHAR_EOF fi # end of overwriting check if test -f 'RESULTS' then echo shar: will not over-write existing file "'RESULTS'" else cat << \SHAR_EOF > 'RESULTS' ** compiling simple ** running simple ** compiling pr459 SHAR_EOF fi # end of overwriting check if test -f 'itoa.oc' then echo shar: will not over-write existing file "'itoa.oc'" else cat << \SHAR_EOF > 'itoa.oc' -- convert (positive) integer to string (decimal representation) and print it. extern proc chassign(chan c, value fd, mode): def MAX = 200: -- should be enough.. var str[BYTE MAX]: var x: proc convert(value n, var pos) = var tmp: var nn: seq nn := n pos := MAX -1 while (nn > 0 and pos > 0) seq tmp := nn / 10 tmp := nn - tmp*10 nn := nn / 10 str[BYTE pos] := '0' + tmp pos := pos - 1 : seq chassign(OUTPUT, 1, 1) convert(1223, x) OUTPUT ! str[BYTE x for MAX-x] OUTPUT ! "*n" SHAR_EOF fi # end of overwriting check if test -f 'simple.oc' then echo shar: will not over-write existing file "'simple.oc'" else cat << \SHAR_EOF > 'simple.oc' -- some simple OCCAM constructs. var a: chan c: def N = 20: seq a := 1 while (a < N) a := a + 1 par c ? ANY c ! N seq i = [0 for N] a := a / 2 SHAR_EOF fi # end of overwriting check if test -f 'RESULTS.good' then echo shar: will not over-write existing file "'RESULTS.good'" else cat << \SHAR_EOF > 'RESULTS.good' ** compiling simple ** running simple Executed 62 instructions in 61 time ** compiling pr459 ** running pr459 Executed 1 instructions in 1 time 459 ** compiling randgen ** running randgen ** compiling prog ** running prog with tracing ** compiling itoa ** running itoa seq j = [0 for 1000*n] skip sync ! DONE c ? ANY : proc manager = seq h = [0 for N] seq seq k = [0 for NPROC] sync ? ANY seq l = [0 for NPROC] chtab[l] ! ACK : par manager par p = [0 for NPROC] worker(chtab[p], p) SHAR_EOF fi # end of overwriting check if test -f 'randgen.oc' then echo shar: will not over-write existing file "'randgen.oc'" else cat << \SHAR_EOF > 'randgen.oc' -- random number generator using 'ALT'. produces a random series of N numbers -- in the range 0..MAX. extern proc pnum(value n): def MAX = 10: def N = 50: chan chtab[MAX]: proc select = seq i = [0 for N] alt j = [0 for MAX] chtab[j] ? ANY pnum(j) : proc foreversend(chan c) = while TRUE c ! ANY : par select par k = [0 for MAX] foreversend(chtab[k]) SHAR_EOF fi # end of overwriting check if test -f 'pnum.c' then echo shar: will not over-write existing file "'pnum.c'" else cat << \SHAR_EOF > 'pnum.c' pnum(n) { printf("%d\n", n); } SHAR_EOF fi # end of overwriting check if test -f 'pr459.oc' then echo shar: will not over-write existing file "'pr459.oc'" else cat << \SHAR_EOF > 'pr459.oc' extern proc pnum(value n): pnum(459) SHAR_EOF fi # end of overwriting check cd .. # End of shell archive exit 0 ----------end of test.shar---------- -- - - Terry Torkelson Internet: ttork%ewu@uunet.uu.net - Eastern Washington University uucp: uunet!isc-br!ewu!ttork - tellynet: 509-359-6016