unlab-gpu 0.1.0

Micro scripting language for neural networks that uses unmtx-gpu.
Documentation
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
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
//
// Copyright (c) 2026 Ɓukasz Szpakowski
//
// This Source Code Form is subject to the terms of the Mozilla Public
// License, v. 2.0. If a copy of the MPL was not distributed with this
// file, You can obtain one at https://mozilla.org/MPL/2.0/.
//
use std::process::exit;
use clap::Parser;
use clap::Subcommand;
use unlab_gpu::pkg::default_src_factories;
use unlab_gpu::pkg_cmds::list;
use unlab_gpu::pkg_cmds::list_deps;
use unlab_gpu::pkg_cmds::search;
use unlab_gpu::pkg_cmds::search_deps;
use unlab_gpu::pkg_cmds::show;
use unlab_gpu::pkg_cmds::show_dep;
use unlab_gpu::pkg_cmds::update;
use unlab_gpu::pkg_cmds::update_deps;
use unlab_gpu::pkg_cmds::install;
use unlab_gpu::pkg_cmds::install_all;
use unlab_gpu::pkg_cmds::install_deps;
use unlab_gpu::pkg_cmds::remove;
use unlab_gpu::pkg_cmds::check;
use unlab_gpu::pkg_cmds::check_deps;
use unlab_gpu::pkg_cmds::cont;
use unlab_gpu::pkg_cmds::continue_deps;
use unlab_gpu::pkg_cmds::clean;
use unlab_gpu::pkg_cmds::clean_deps;
use unlab_gpu::pkg_cmds::lock;
use unlab_gpu::pkg_cmds::clean_index;
use unlab_gpu::pkg_cmds::clean_cache;
use unlab_gpu::pkg_cmds::clean_work;
use unlab_gpu::pkg_cmds::config;
use unlab_gpu::pkg_cmds::init;
use unlab_gpu::pkg_cmds::new;
use unlab_gpu::pkg_cmds::run;
use unlab_gpu::pkg_cmds::console;
use unlab_gpu::pkg_cmds::doc;
use unlab_gpu::pkg_cmds::test;
use unlab_gpu::pkg_cmds::clean_test;
use unlab_gpu::pkg_cmds::std_doc;
use unlab_gpu::pkg_cmds::std_doc_deps;
use unlab_gpu::Home;
use unlab_gpu::add_std_builtin_funs;

#[derive(Parser, Debug)]
struct SearchArgs
{
    /// Patterns
    patterns: Vec<String>,
}

#[derive(Parser, Debug)]
struct ShowArgs
{
    /// Show package manifest
    #[arg(short, long)]
    manifest: bool,
    /// Show package dependents
    #[arg(short, long)]
    dependents: bool,
    /// Show package paths
    #[arg(short, long)]
    paths: bool,
    /// Package
    package: String,
}

#[derive(Parser, Debug)]
struct UpdateArgs
{
    /// Package
    packages: Vec<String>,
}

#[derive(Parser, Debug)]
struct InstallArgs
{
    /// Update version lists of packages
    #[arg(short, long)]
    update: bool,
    /// Force reinstall installed packages
    #[arg(short, long)]
    force: bool,
    /// Don't install documentations of packages
    #[arg(short, long)]
    no_doc: bool,
    /// Packages
    packages: Vec<String>,
}

#[derive(Parser, Debug)]
struct InstallAllArgs
{
    /// Update version lists of packages
    #[arg(short, long)]
    update: bool,
    /// Force reinstall installed packages
    #[arg(short, long)]
    force: bool,
    /// Don't install documentations of packages
    #[arg(short, long)]
    no_doc: bool,
}
                                       
#[derive(Parser, Debug)]
struct InstallDepsArgs
{
    /// Update version lists of packages
    #[arg(short, long)]
    update: bool,
    /// Force reinstall installed packages
    #[arg(short, long)]
    force: bool,
    /// Don't install documentations of packages
    #[arg(short, long)]
    no_doc: bool,
    /// Lock versions of packages
    #[arg(short, long)]
    lock: bool,
    /// Unlock versions of packages
    #[arg(short = 'm', long)]
    unlock: bool,
}

#[derive(Parser, Debug)]
struct RemoveArgs
{
    /// Packages
    packages: Vec<String>,
}

#[derive(Parser, Debug)]
struct ContinueArgs
{
    /// Don't install documentations of packages
    #[arg(short, long)]
    no_doc: bool,
}

#[derive(Parser, Debug)]
struct ConfigArgs
{
    /// Set account for package name
    #[arg(short, long)]
    account: Option<String>,
    /// Set domain for library name
    #[arg(short, long)]
    domain: Option<String>,
}

#[derive(Parser, Debug)]
struct InitArgs
{
    /// Package name
    #[arg(short, long)]
    name: Option<String>,
    /// Account for package name 
    #[arg(short, long)]
    account: Option<String>,
    /// Domain for library name
    #[arg(short, long)]
    domain: Option<String>,
    /// Use binary template
    #[arg(short, long)]
    bin: bool,
    /// Use library template
    #[arg(short, long)]
    lib: bool,
    /// Use template tests
    #[arg(short, long)]
    tests: bool,
    /// Directory
    dir: Option<String>,
}

#[derive(Parser, Debug)]
struct NewArgs
{
    /// Package name
    #[arg(short, long)]
    name: Option<String>,
    /// Account for package name 
    #[arg(short, long)]
    account: Option<String>,
    /// Domain for library name
    #[arg(short, long)]
    domain: Option<String>,
    /// Use binary template
    #[arg(short, long)]
    bin: bool,
    /// Use library template
    #[arg(short, long)]
    lib: bool,
    /// Use template of tests
    #[arg(short, long)]
    tests: bool,
    /// Directory
    dir: String,
}

#[derive(Parser, Debug)]
struct RunArgs
{
    /// Don't handle CTRL-C
    #[arg(short, long)]
    no_ctrl_c: bool,
    /// Don't show plotter windows
    #[arg(short = 'p', long)]
    no_plotter_windows: bool,
    /// Binary name
    bin_name: String,
    /// Arguments
    args: Vec<String>,
}

#[derive(Parser, Debug)]
struct ConsoleArgs
{
    /// Don't handle CTRL-C
    #[arg(short, long)]
    no_ctrl_c: bool,
    /// Don't show plotter windows
    #[arg(short = 'p', long)]
    no_plotter_windows: bool,
}

#[derive(Parser, Debug)]
struct TestArgs
{
    /// Run tests in test suite
    #[arg(short = 's', long)]
    test_suite: bool,
    /// Show output
    #[arg(short = 'o', long)]
    show_output: bool,
    /// Don't handle output for tests
    #[arg(short, long)]
    no_handled_output: bool,
    /// Test name or test suite name
    name: Option<String>,
}

#[derive(Subcommand, Debug)]
enum Subcmd
{
    /// List packages 
    List,
    /// List dependencies of current package
    ListDeps,
    /// Search packages
    Search(SearchArgs),
    /// Search dependencies of current package
    SearchDeps(SearchArgs),
    /// Show package details
    Show(ShowArgs),
    /// Show dependency details of current package
    ShowDep(ShowArgs),
    /// Update version lists of packages
    Update(UpdateArgs),
    /// Update version lists of dependencies of current package
    UpdateDeps(UpdateArgs),
    /// Install packages
    Install(InstallArgs),
    /// Reinstall all packages
    InstallAll(InstallAllArgs),
    /// Install depedencies of current package
    InstallDeps(InstallDepsArgs),
    /// Remove packages
    Remove(RemoveArgs),
    /// Check whether last operation was interrupted for packages
    Check,
    /// Check whether last operation was interrupted for current package
    CheckDeps,
    /// Continue interrupted last operation for packages
    Continue(ContinueArgs),
    /// Continue interrupted last operation for current package
    ContinueDeps(ContinueArgs),
    /// Clean after interrupted preparation to last operation for packages
    Clean,
    /// Clean after interrupted preparation to last operation for current package
    CleanDeps,
    /// Lock versions of dependencies of current package
    Lock,
    /// Clean index with version lists of packages
    CleanIndex,
    /// Clean cache with archives of packages
    CleanCache,
    /// Clean work directory
    CleanWork,
    /// Show or set configuration
    Config(ConfigArgs),
    /// Create new package in existent directory
    Init(InitArgs),
    /// Create new package
    New(NewArgs),
    /// Run binary for current package
    Run(RunArgs),
    /// Run interpreter for current package
    Console(ConsoleArgs),
    /// Generate documentation for current package
    Doc,
    /// Execute tests for current package
    Test(TestArgs),
    /// Clean test directory in work directory
    CleanTest,
    /// Generate documentation of standard library
    StdDoc,
    /// Generate documentation of standard library for current package
    StdDocDeps,
}

#[derive(Parser, Debug)]
#[command(version)]
struct Args
{
    /// Unlab-gpu home directory
    #[arg(short = 'H', long)]
    home_dir: Option<String>,
    /// Binary path
    #[arg(short = 'B', long)]
    bin_path: Option<String>,
    /// Library path
    #[arg(short = 'L', long)]
    lib_path: Option<String>,
    /// Documentation path
    #[arg(short = 'D', long)]
    doc_path: Option<String>,
    /// Add directory to binary path
    #[arg(short, long)]
    bin_dir: Vec<String>,
    /// Add directory to library path
    #[arg(short, long)]
    lib_dir: Vec<String>,
    /// Add directory to documentation path
    #[arg(short, long)]
    doc_dir: Vec<String>,
    #[clap(subcommand)]
    subcommand: Subcmd,
}

fn main()
{
    let args = Args::parse();
    let add_dirs = |home: &mut Home| {
        match home.add_dirs_to_bin_path(args.bin_dir.as_slice()) {
            Ok(()) => (),
            Err(err) => {
                eprintln!("{}", err);
                return false;
            },
        }
        match home.add_dirs_to_lib_path(args.lib_dir.as_slice()) {
            Ok(()) => (),
            Err(err) => {
                eprintln!("{}", err);
                return false;
            },
        }
        match home.add_dirs_to_doc_path(args.doc_dir.as_slice()) {
            Ok(()) => (),
            Err(err) => {
                eprintln!("{}", err);
                return false;
            },
        }
        true
    };
    let src_factories = default_src_factories();
    let exit_code = match &args.subcommand {
        Subcmd::List => {
            list(&args.home_dir, &args.bin_path, &args.lib_path, &args.doc_path, src_factories, add_dirs)
        },
        Subcmd::ListDeps => {
            list_deps(&args.home_dir, &args.bin_path, &args.lib_path, &args.doc_path, src_factories, add_dirs)
        },
        Subcmd::Search(args2) => {
            search(args2.patterns.as_slice(), &args.home_dir, &args.bin_path, &args.lib_path, &args.doc_path, src_factories, add_dirs)
        },
        Subcmd::SearchDeps(args2) => {
            search_deps(args2.patterns.as_slice(), &args.home_dir, &args.bin_path, &args.lib_path, &args.doc_path, src_factories, add_dirs)
        },
        Subcmd::Show(args2) => {
            show(args2.package.as_str(), args2.manifest, args2.dependents, args2.paths, &args.home_dir, &args.bin_path, &args.lib_path, &args.doc_path, src_factories, add_dirs)
        },
        Subcmd::ShowDep(args2) => {
            show_dep(args2.package.as_str(), args2.manifest, args2.dependents, args2.paths, &args.home_dir, &args.bin_path, &args.lib_path, &args.doc_path, src_factories, add_dirs)
        },
        Subcmd::Update(args2) => {
            update(args2.packages.as_slice(), &args.home_dir, &args.bin_path, &args.lib_path, &args.doc_path, src_factories, add_dirs)
        },
        Subcmd::UpdateDeps(args2) => {
            update_deps(args2.packages.as_slice(), &args.home_dir, &args.bin_path, &args.lib_path, &args.doc_path, src_factories, add_dirs)
        },
        Subcmd::Install(args2) => {
            install(args2.packages.as_slice(), args2.update, args2.force, !args2.no_doc, &args.home_dir, &args.bin_path, &args.lib_path, &args.doc_path, src_factories, add_dirs)
        },
        Subcmd::InstallAll(args2) => {
            install_all(args2.update, args2.force, !args2.no_doc, &args.home_dir, &args.bin_path, &args.lib_path, &args.doc_path, src_factories, add_dirs)
        },
        Subcmd::InstallDeps(args2) => {
            install_deps(args2.update, args2.force, !args2.no_doc, args2.lock, args2.unlock, &args.home_dir, &args.bin_path, &args.lib_path, &args.doc_path, src_factories, add_dirs)
        },
        Subcmd::Remove(args2) => {
            remove(args2.packages.as_slice(), &args.home_dir, &args.bin_path, &args.lib_path, &args.doc_path, src_factories, add_dirs)
        },
        Subcmd::Check => {
            check(&args.home_dir, &args.bin_path, &args.lib_path, &args.doc_path, src_factories, add_dirs)
        },
        Subcmd::CheckDeps => {
            check_deps(&args.home_dir, &args.bin_path, &args.lib_path, &args.doc_path, src_factories, add_dirs)
        },
        Subcmd::Continue(args2) => {
            cont(!args2.no_doc, &args.home_dir, &args.bin_path, &args.lib_path, &args.doc_path, src_factories, add_dirs)
        },
        Subcmd::ContinueDeps(args2) => {
            continue_deps(!args2.no_doc, &args.home_dir, &args.bin_path, &args.lib_path, &args.doc_path, src_factories, add_dirs)
        },
        Subcmd::Clean => {
            clean(&args.home_dir, &args.bin_path, &args.lib_path, &args.doc_path, src_factories, add_dirs)
        },
        Subcmd::CleanDeps => {
            clean_deps(&args.home_dir, &args.bin_path, &args.lib_path, &args.doc_path, src_factories, add_dirs)
        },
        Subcmd::Lock => {
            lock(&args.home_dir, &args.bin_path, &args.lib_path, &args.doc_path, src_factories, add_dirs)
        },
        Subcmd::CleanIndex => {
            clean_index(&args.home_dir, &args.bin_path, &args.lib_path, &args.doc_path, add_dirs)
        },
        Subcmd::CleanCache => {
            clean_cache(&args.home_dir, &args.bin_path, &args.lib_path, &args.doc_path, add_dirs)
        },
        Subcmd::CleanWork => {
            clean_work(&args.home_dir, &args.bin_path, &args.lib_path, &args.doc_path, add_dirs)
        },
        Subcmd::Config(args2) => {
            config(&args2.account, &args2.domain, &args.home_dir, &args.bin_path, &args.lib_path, &args.doc_path, add_dirs)
        },
        Subcmd::Init(args2) => {
            init(&args2.dir, &args2.name, &args2.account, &args2.domain, args2.bin, args2.lib, args2.tests, &args.home_dir, &args.bin_path, &args.lib_path, &args.doc_path, add_dirs)
        },
        Subcmd::New(args2) => {
            new(args2.dir.as_str(), &args2.name, &args2.account, &args2.domain, args2.bin, args2.lib, args2.tests, &args.home_dir, &args.bin_path, &args.lib_path, &args.doc_path, add_dirs)
        },
        Subcmd::Run(args2) => {
            run(args2.bin_name.as_str(), args2.args.clone(), !args2.no_ctrl_c, !args2.no_plotter_windows, &args.home_dir, &args.bin_path, &args.lib_path, &args.doc_path, add_dirs, add_std_builtin_funs)
        },
        Subcmd::Console(args2) => {
            console(!args2.no_ctrl_c, !args2.no_plotter_windows, &args.home_dir, &args.bin_path, &args.lib_path, &args.doc_path, add_dirs, add_std_builtin_funs)
        },
        Subcmd::Doc => {
            doc(&args.home_dir, &args.bin_path, &args.lib_path, &args.doc_path, src_factories, add_dirs)
        },
        Subcmd::Test(args2) => {
            test(&args2.name, args2.test_suite, args2.show_output, !args2.no_handled_output, &args.home_dir, &args.bin_path, &args.lib_path, &args.doc_path, add_dirs, add_std_builtin_funs)
        },
        Subcmd::CleanTest => {
            clean_test(&args.home_dir, &args.bin_path, &args.lib_path, &args.doc_path, add_dirs)
        },
        Subcmd::StdDoc => {
            std_doc(&args.home_dir, &args.bin_path, &args.lib_path, &args.doc_path, src_factories, add_dirs)
        },
        Subcmd::StdDocDeps => {
            std_doc_deps(&args.home_dir, &args.bin_path, &args.lib_path, &args.doc_path, src_factories, add_dirs)
        },
    };
    match exit_code {
        Some(exit_code) => exit(exit_code),
        None => (),
    }
}