rev: 3827f53bae88e48a594610914ba74b9512ead6dd tukan/testing/conspire-cl.sc -rwxr-xr-x 6.5 KiB View raw Log this file
3827f53bae88 — Leonard Ritter * more work on module system 3 months ago
                                                                                
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
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
#!/usr/bin/env scopes
using import console
using import ...conspire.module

#
    inline static-type (...)
        inline (f)
            static-typify f ...

    inline try-dbop (f ...)
        try
            f ...
        except (err)
            error (err as string)

    @@ static-type ()
    fn close ()
        'swap active-act
            inline (act)
                static-if (none? act)
                else
                    'abort act
        active-module = none

    @@ static-type ()
    fn clear ()
        dispatch active-act
        case Some (act)
            try-dbop
                inline ()
                    'clear act
        default;

    @@ static-type ()
    fn commit ()
        dispatch active-module
        case Some (mod)
            'swap active-act
                inline (act)
                    static-if (none? act)
                    else
                        try
                            'commit act
                        except (err)
                            'abort act
                            error (err as string)
                    try-dbop
                        inline ()
                            'begin-edit mod
        default;

    @@ static-type ()
    fn abort ()
        dispatch active-module
        case Some (mod)
            'swap active-act
                inline (act)
                    static-if (none? act)
                    else
                        'abort act
                    try-dbop
                        inline ()
                            'begin-edit mod
        default;

    inline transaction-error ()
        hide-traceback;
        error "no active transaction available"

    inline with-module (f)
        dispatch active-module
        case Some (mod)
            try-dbop f mod
        default
            transaction-error;

    inline with-act (f)
        dispatch active-act
        case Some (act)
            try-dbop f act
        default
            transaction-error;

    inline with-module-act (f)
        dispatch active-module
        case Some (mod)
            dispatch active-act
            case Some (act)
                try-dbop f mod act
            default
                transaction-error;
        default
            transaction-error;

    @@ static-type string
    fn makestring (str)
        with-act
            inline (act)
                'string act str

    inline maketuple (...)
        with-act
            inline (act)
                local atoms = (arrayof Atom ...)
                'tuple act &atoms (va-countof ...)

    inline... makenumber
    case (value : integer,)
        value as Atom
    case (value : real,)
        value as Atom

    fn... link
    case (source : Atom, label : Atom, target : Atom)
        with-act
            inline (act)
                'link act source label target
    case (edge : Edge, target : Atom)
        with-act
            inline (act)
                'link act edge target

    fn... cut
    case (source : Atom, label : Atom)
        with-act
            inline (act)
                'cut act source label
    case (edge : Edge,)
        with-act
            inline (act)
                'cut act edge

    spice follow2 (value)
        let value = (value as Atom)
        print value
        spice-quote
            print "hello"

    fn... follow
    case (source : Atom, label : Atom)
        with-act
            inline (act)
                'follow act source label
    case (edge : Edge,)
        with-act
            inline (act)
                'follow act edge
    case (value : Atom,)
        with-act
            inline (act)
                let k = ('kind value)
                switch k
                #pass Kind.StringRef
                #pass Kind.BlobRef
                case Atom.Kind.TupleRef
                    let count atoms = ('deref-tuple act value)
                    sc_argument_list_map_new (count as i32)
                        inline (i)
                            atoms @ i
                default
                    `value

    @@ static-type ()
    fn print-stats ()
        with-module-act
            inline (mod act)
                inline dump-fields (info)
                    va-map
                        inline (T)
                            let key = (keyof T)
                            print key
                                getattr info key
                        elementsof (typeof info)
                print "env info:"
                dump-fields ('info mod._env)
                print;
                print "env stat:"
                dump-fields ('stat mod._env)
                print;
                print "blob db stat:"
                dump-fields ('stat act._txn mod._db.blob)
                print;
                print "edge db stat:"
                dump-fields ('stat act._txn mod._db.edge)

#-------------------------------------------------------------------------------

# build scope with which we're going to evaluate commands
let repl-scope =
    do
        #let open clear close commit link cut follow abort follow2
        #let
            string = makestring
            symbol = Atom.symbol
            tuple = maketuple
            number = makenumber
            none = (none as Atom)
            stats = print-stats
            edge = Edge
        #let
            s = symbol
            t = tuple
            n = number
        # must keep sugar support
        indirect-let list-handler-symbol
        let sugar-quote
        locals;

let scope =
    repl-scope
    # use the line below to prepend your symbols to existing globals
    #.. repl-scope
        globals;

#-------------------------------------------------------------------------------

let source-path argc argv = (script-launch-args)

if (argc < 1)
    print
        .. "syntax: " source-path " path/to/database [command ...]"
    exit -1

open (string (argv @ 0))

# transform command line to symbolic list
let cmd =
    fold (cmd = '()) for i in (rrange 1 argc)
        let arg = (argv @ i)
        let str = (string arg)
        let val =
            if (i == 1) `[(Symbol str)]
            else `str
        cons val cmd

# if no shell command has been issued, enter REPL console
if (cmd == '())
    print "Conspire REPL"
    read-eval-print-loop scope false
        .. cache-dir "/conspire.history"
    close;
    exit 0

# otherwise evaluate command (which includes compilation)
let f =
    try
        sc_eval unknown-anchor (list cmd) scope
    except (err)
        print
            'format err
        exit -1
run-stage;
# and execute it in the next stage
f;