forked from qingkaishi/z3
-
Notifications
You must be signed in to change notification settings - Fork 0
/
example-raw.ts
57 lines (43 loc) · 1.67 KB
/
example-raw.ts
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
import { init } from './build/wrapper';
// demonstrates use of the raw API
(async () => {
let { em, Z3 } = await init();
Z3.global_param_set('verbose', '10');
console.log('verbosity:', Z3.global_param_get('verbose'));
let config = Z3.mk_config();
let ctx = Z3.mk_context_rc(config);
Z3.del_config(config);
let unicodeStr = [...'hello™'].map(x => x.codePointAt(0)!);
let strAst = Z3.mk_u32string(ctx, unicodeStr);
Z3.inc_ref(ctx, strAst);
console.log(Z3.is_string(ctx, strAst));
console.log(Z3.get_string(ctx, strAst));
console.log(Z3.get_string_contents(ctx, strAst, unicodeStr.length));
let bv = Z3.mk_bv_numeral(ctx, [true, true, false]);
let bs = Z3.mk_ubv_to_str(ctx, bv);
console.log(Z3.ast_to_string(ctx, bs));
let intSort = Z3.mk_int_sort(ctx);
let big = Z3.mk_int64(ctx, 42n, intSort);
console.log(Z3.get_numeral_string(ctx, big));
console.log(Z3.get_numeral_int64(ctx, big));
console.log(Z3.get_version());
let head_tail = [Z3.mk_string_symbol(ctx, 'car'), Z3.mk_string_symbol(ctx, 'cdr')];
let nil_con = Z3.mk_constructor(ctx, Z3.mk_string_symbol(ctx, 'nil'), Z3.mk_string_symbol(ctx, 'is_nil'), [], [], []);
let cons_con = Z3.mk_constructor(
ctx,
Z3.mk_string_symbol(ctx, 'cons'),
Z3.mk_string_symbol(ctx, 'is_cons'),
head_tail,
[null, null],
[0, 0],
);
let cell = Z3.mk_datatype(ctx, Z3.mk_string_symbol(ctx, 'cell'), [nil_con, cons_con]);
console.log(Z3.query_constructor(ctx, nil_con, 0));
console.log(Z3.query_constructor(ctx, cons_con, 2));
Z3.dec_ref(ctx, strAst);
Z3.del_context(ctx);
em.PThread.terminateAllThreads();
})().catch(e => {
console.error('error', e);
process.exit(1);
});