aboutsummaryrefslogtreecommitdiff
path: root/examples/working-compiler/interactive-stack.test
blob: a78db219f0cb27904dd80e62ffd0dda0402d2d93 (plain)
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
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
<
  map ==seenThings # from .hu of rawAddress to some name
  map ==usedNames # from name to rawAddress

  { ==suggested ==thing
    thing sys .asm .rawAddress _ ==a txt .produce .hu ==as

    { ==i
      i 0 eq {
        i suggested *
      } {
        i suggested len math .base suggested * |cat fold
      } ? *
    } /toName deffst

    as seenThings .has {
      as seenThings *
    } {
      0 ==i
      {
        i toName ==name
        name usedNames .has
      }' {
        { 1 add } |=i
      }' loop

      name as seenThings =[]
      a name usedNames =[]
      name
    } ? *
  }
> -- /niceName deffd

{ [ "α" "β" "γ" "δ" "ε" "π" "φ" ] niceName } /niceScopeName deffd

<
  [ 0 11 range {
    sys .asm .intToFloat
  }' each ] =*:FLOAT

  sys .out .|writeall =*out

  "0123456789" ==:base10digits
  "0123456789ABCDEF" ==:base16digits

  { _ 0 lt { neg "-" }' { "" }' ? * -01
    [ -01 16 { _ 16 umod base16digits * -01 16 udiv }' rep -- ] reverse str .fromArray cat
  }' /base16encode64 deffd

  { "\e[1;31m<???>\e[0m" out }" /unknown defvd

  [
    { "\e[31m" o txt .produce .i cat "\e[0m" cat out }" # integer
    { "\e[31m\"" o "\"\e[0m" cat cat out }" # string
    { "\e[31m" out o { ==f 0 ==e "+" ==s 0 ==i
      f 0 FLOAT lt { 0 FLOAT f sub =f "-" =s }' rep
      { f 1 FLOAT lt i 500 lt and }' { f 10 FLOAT mul =f e 1 sub =e i 1 add =i }' loop
      { f 10 FLOAT ge i 500 lt and }' { f 10 FLOAT div =f e 1 add =e i 1 add =i }' loop

      i 500 eq {
        s
        f 1 FLOAT lt "0.0e0" "inf" ?
        cat out
      }' {
        {
          0 ==d
          1 10 range { ==i f i FLOAT gt { i =d }' rep } each
          f d sub =f
          f 10 FLOAT mul =f
          d base10digits *
        } /extractDigit deffst

        [
          0 s *
          extractDigit
          0 "." *
          10 |extractDigit rep
          0 "e" *
          e 0 lt {
            0 e sub =e
            0 "-" *
          } rep
          e 0 eq {
            0 "0" *
          } rep
          [
            { e } {
              e 10 mod base10digits *
              e 10 div =e
            } loop
          ] reverse _ len dearray
        ] str .fromArray out
      }' ? *
    } * "\e[0m" out }" # float
    unknown
    unknown # extension area
    { "\e[32m{"
      o [ /f /g /h /a /b /c /d /e ] niceName cat
      "}\e[0m" cat out
    }"
    unknown
    { "\e[36m["
      o [ /A /B /C /D /E /F /G /H ] niceName cat
      "]\e[0m" cat out
    }" # array
    unknown # function type
    { "\e[35m<"
      o niceScopeName cat
      ">\e[0m" cat out
    }"
    unknown # name table
    unknown # stack
    { "<coroutine: " o sys .asm .rawAddress base16encode64 cat ">" cat out }"
    unknown
    unknown
    unknown
    { "[" out }"
    { "{" out }"
    { "\e[34m|\e[0m" out }"
    unknown
  ] /dumpActions deffd

  { ==indent _ ==o
    "" indent { "  " cat }' rep out
    sys .typed .type dumpActions *
    "  " out
  } /dumpIndented deffd

  # dump top stack element
  { 0 ==i "" ==x
    { x sys .typed .type 18 neq } {
      i _' =x
      { 1 add } |=i
    } loop

    { 1 sub } |=i

    { i 0 ge } {
      i _' =x
      { 1 sub } |=i
      x 0 dumpIndented
      " " out
    } loop

    "\n" out
  }
> -- /stackdump deffd

"Welcome to elymas.\n" sys .out .writeall

scope enincludeLine =*eval

1 ==running
{ 0 =running } =*quit

{ running } {
  "\n" sys .out .writeall
  stackdump

  [ "\e[35m" "scope" eval niceScopeName cat "\e[34m >" cat
    quoted { "\e[32m{" } rep "\e[0m " ] |cat fold sys .out .writeall
  65536 sys .in .read _ len { ==line
    line "^(.*)\n$" regex {
      eval
    } {
      "non-terminal input" dump
    } ? *
  } { --
    0 =running
  } ? *
} loop

"\n" sys .out .writeall

# vim: syn=elymas