summaryrefslogtreecommitdiff
path: root/_khb_experiment/test.khs
blob: 54b9507e39b84fe3a4ad9b92ca0c18feaf241ef3 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
proc_integers:
    < @fd[f].n > @fd[f].nmax ? _then1 : _else1 >
_then1:
    -1 >> @fd[f].qo
    < _end1 >
_else1:
    @fd[f].n >> @fd[f].qo
    fd[f].trtmp.n := @fd[f].n + 1
    fd[f].trtmp.nmax := @fd[f].nmax
    fd[f].trtmp.qo := @fd[f].qo
    fd[f].n := @fd[f].trtmp.n
    fd[f].nmax := @fd[f].trtmp.nmax
    fd[f].qo := @fd[f].trtmp.qo
    < proc_integers >
    < _end1 >
_end1:
    fd[f] := ""
    ~ (.qo, .nmax, .n)
    < @fd[f].return >
 
 proc_filter:
    val << @(fd\@f\qi)
    < @val != -1 ? _then2 : _else2 >
_then2:
    < @val % @(fd\@f\n) != 0 ? _then3 : _end3 >
_then3:
    @val >> @(fd\@f\qo)
_end3:
    <proc_filter>
    <_end2>
_else2:
    -1 >> @qo
    <_end2>
_end2:
    fd[f] := ""
    ~ (.qo, .qi, .val, .n)
    < @(fd\@f\return) >

proc_primes:
    .val << @.qi
    < @.val != -1 ? _then4 : _end4 >
_then4:
    @.val >> @stdout
    .c := <>
    | _par_1 |
    .qi := @(.c\in)
    <proc_primes>
_end4:
    fd\@f := ""
    ~ (.val, .qi, .c)
    < @(fd\@f\return) >
_par_1:
    .n := @.val
    .qo := @(.c\out)
    <proc_filter>

proc_main:
    .c := <>
    | _par_2 |
    fd\(@f+1)\qi := @(.c\in)
    f := @f+1
    .return := _ret1
    <proc_primes>
_ret1:
    f := @f-1
    .tmp_retval := @(fd\(@f+1))
    fd\@f := .tmp_retval
    ~(.tmp_retval)
    < .return >
_par_2:
    .n := 2
    .nmax := 5000
    .qo := @(.c\out)
    <proc_integers>