create regress_simple for JavaScript
[liba.git] / javascript / src / liba.cc
blobb0536252213f699e9249f0b2bacfd8fd1413633e
1 #include "a/a.h"
2 #include <emscripten/bind.h>
3 #if defined(__has_feature) && __has_feature(address_sanitizer)
4 #include <sanitizer/lsan_interface.h>
5 #endif /* -fsanitize=address */
7 namespace
10 static emscripten::val js_concat(emscripten::val x)
12 emscripten::val val = emscripten::val::array();
13 return val["concat"].call<emscripten::val>("apply", val, x);
16 static a_float *js_array_num_get(emscripten::val const &x, a_float *p, a_size n)
18 a_size length = x["length"].as<a_size>();
19 n = (length >= n ? length : n) * sizeof(a_float);
20 p = a_cast_s(a_float *, a_alloc(p, n));
21 for (a_size i = 0; i < length; ++i)
23 p[i] = x[i].as<a_float>();
25 return p;
28 static emscripten::val js_array_num_new(a_float const *p, a_size n)
30 return emscripten::val(emscripten::typed_memory_view(n, p));
33 static a_u32 hash_bkdr(std::string const &str, a_u32 val)
35 return a_hash_bkdr_(str.data(), str.length(), val);
38 static a_u32 hash_sdbm(std::string const &str, a_u32 val)
40 return a_hash_sdbm_(str.data(), str.length(), val);
43 } /* namespace */
45 #include "a/crc.h"
47 struct crc8
49 a_u8 table[0x100];
50 std::vector<a_byte> pack_;
51 A_INLINE emscripten::val table_r() const
53 return emscripten::val(emscripten::typed_memory_view(0x100, table));
55 A_INLINE a_u8 operator()(std::string const &block, a_u8 value = 0) const
57 return a_crc8(table, block.data(), block.length(), value);
59 A_INLINE emscripten::val pack(std::string const &block, a_u8 value = 0)
61 size_t n = block.length();
62 size_t m = block.length() + sizeof(value);
63 if (pack_.size() < m) { pack_.resize(m); }
64 std::copy(block.data(), block.data() + n, pack_.data());
65 *(pack_.data() + n) = a_crc8(table, block.data(), n, value);
66 return emscripten::val(emscripten::typed_memory_view(m, pack_.data()));
68 A_INLINE crc8 *gen(a_u8 poly, bool reversed = false)
70 reversed ? a_crc8l_init(table, poly) : a_crc8m_init(table, poly);
71 return this;
73 A_INLINE crc8(a_u8 poly, bool reversed = false)
75 gen(poly, reversed);
79 struct crc16
81 a_u16 table[0x100];
82 std::vector<a_byte> pack_;
83 a_u16 (*eval)(a_u16 const[0x100], void const *, a_size, a_u16);
84 A_INLINE emscripten::val table_r() const
86 return emscripten::val(emscripten::typed_memory_view(0x100, table));
88 A_INLINE a_u16 operator()(std::string const &block, a_u16 value = 0) const
90 return eval(table, block.data(), block.length(), value);
92 A_INLINE emscripten::val pack(std::string const &block, a_u16 value = 0)
94 size_t n = block.length();
95 size_t m = block.length() + sizeof(value);
96 if (pack_.size() < m) { pack_.resize(m); }
97 std::copy(block.data(), block.data() + n, pack_.data());
98 value = eval(table, block.data(), n, value);
99 a_byte *p = pack_.data() + n;
100 eval == a_crc16m ? a_u16_setb(p, value) : a_u16_setl(p, value);
101 return emscripten::val(emscripten::typed_memory_view(m, pack_.data()));
103 A_INLINE crc16 *gen(a_u16 poly, bool reversed = false)
105 if (reversed)
107 a_crc16l_init(table, poly);
108 eval = a_crc16l;
110 else
112 a_crc16m_init(table, poly);
113 eval = a_crc16m;
115 return this;
117 A_INLINE crc16(a_u16 poly, bool reversed = false)
119 gen(poly, reversed);
123 struct crc32
125 a_u32 table[0x100];
126 std::vector<a_byte> pack_;
127 a_u32 (*eval)(a_u32 const[0x100], void const *, a_size, a_u32);
128 A_INLINE emscripten::val table_r() const
130 return emscripten::val(emscripten::typed_memory_view(0x100, table));
132 A_INLINE a_u32 operator()(std::string const &block, a_u32 value = 0) const
134 return eval(table, block.data(), block.length(), value);
136 A_INLINE emscripten::val pack(std::string const &block, a_u32 value = 0)
138 size_t n = block.length();
139 size_t m = block.length() + sizeof(value);
140 if (pack_.size() < m) { pack_.resize(m); }
141 std::copy(block.data(), block.data() + n, pack_.data());
142 value = eval(table, block.data(), n, value);
143 a_byte *p = pack_.data() + n;
144 eval == a_crc32m ? a_u32_setb(p, value) : a_u32_setl(p, value);
145 return emscripten::val(emscripten::typed_memory_view(m, pack_.data()));
147 A_INLINE crc32 *gen(a_u32 poly, bool reversed = false)
149 if (reversed)
151 a_crc32l_init(table, poly);
152 eval = a_crc32l;
154 else
156 a_crc32m_init(table, poly);
157 eval = a_crc32m;
159 return this;
161 A_INLINE crc32(a_u32 poly, bool reversed = false)
163 gen(poly, reversed);
167 #if defined(WASM_BIGINT)
168 struct crc64
170 a_u64 table[0x100];
171 std::vector<a_byte> pack_;
172 a_u64 (*eval)(a_u64 const[0x100], void const *, a_size, a_u64);
173 A_INLINE emscripten::val table_r() const
175 return emscripten::val(emscripten::typed_memory_view(0x100, table));
177 A_INLINE emscripten::val operator()(std::string const &block, a_u64 value = 0) const
179 return emscripten::val(eval(table, block.data(), block.length(), value));
181 A_INLINE emscripten::val pack(std::string const &block, a_u64 value = 0)
183 size_t n = block.length();
184 size_t m = block.length() + sizeof(value);
185 if (pack_.size() < m) { pack_.resize(m); }
186 std::copy(block.data(), block.data() + n, pack_.data());
187 value = eval(table, block.data(), n, value);
188 a_byte *p = pack_.data() + n;
189 eval == a_crc64m ? a_u64_setb(p, value) : a_u64_setl(p, value);
190 return emscripten::val(emscripten::typed_memory_view(m, pack_.data()));
192 A_INLINE crc64 *gen(a_u64 poly, bool reversed = false)
194 if (reversed)
196 a_crc64l_init(table, poly);
197 eval = a_crc64l;
199 else
201 a_crc64m_init(table, poly);
202 eval = a_crc64m;
204 return this;
206 A_INLINE crc64(a_u64 poly, bool reversed = false)
208 gen(poly, reversed);
211 #endif /* WASM_BIGINT */
213 #include "a/hpf.h"
215 struct hpf: public a_hpf
217 A_INLINE a_float alpha_r() const { return alpha; }
218 A_INLINE a_float output_r() const { return output; }
219 A_INLINE a_float input_r() const { return input; }
220 A_INLINE hpf(a_float fc, a_float ts)
222 alpha = A_HPF_GEN(fc, ts);
223 output = 0;
224 input = 0;
226 A_INLINE hpf(a_float alpha_)
228 alpha = alpha_;
229 output = 0;
230 input = 0;
232 A_INLINE hpf *gen(a_float fc, a_float ts)
234 a_hpf::gen(fc, ts);
235 return this;
237 A_INLINE a_float operator()(a_float x)
239 return a_hpf::operator()(x);
241 A_INLINE hpf *zero()
243 a_hpf::zero();
244 return this;
248 #include "a/lpf.h"
250 struct lpf: public a_lpf
252 A_INLINE a_float alpha_r() const { return alpha; }
253 A_INLINE a_float output_r() const { return output; }
254 A_INLINE lpf(a_float fc, a_float ts)
256 alpha = A_LPF_GEN(fc, ts);
257 output = 0;
259 A_INLINE lpf(a_float alpha_)
261 alpha = alpha_;
262 output = 0;
264 A_INLINE lpf *gen(a_float fc, a_float ts)
266 a_lpf::gen(fc, ts);
267 return this;
269 A_INLINE a_float operator()(a_float x)
271 return a_lpf::operator()(x);
273 A_INLINE lpf *zero()
275 a_lpf::zero();
276 return this;
280 #include "a/mf.h"
282 struct mf
284 static unsigned int const NUL;
285 static a_float gauss(a_float x, a_float sigma, a_float c)
287 return a_mf_gauss(x, sigma, c);
289 static unsigned int const GAUSS;
290 static a_float gauss2(a_float x, a_float sigma1, a_float c1, a_float sigma2, a_float c2)
292 return a_mf_gauss2(x, sigma1, c1, sigma2, c2);
294 static unsigned int const GAUSS2;
295 static a_float gbell(a_float x, a_float a, a_float b, a_float c)
297 return a_mf_gbell(x, a, b, c);
299 static unsigned int const GBELL;
300 static a_float sig(a_float x, a_float a, a_float c)
302 return a_mf_sig(x, a, c);
304 static unsigned int const SIG;
305 static a_float dsig(a_float x, a_float a1, a_float c1, a_float a2, a_float c2)
307 return a_mf_dsig(x, a1, c1, a2, c2);
309 static unsigned int const DSIG;
310 static a_float psig(a_float x, a_float a1, a_float c1, a_float a2, a_float c2)
312 return a_mf_psig(x, a1, c1, a2, c2);
314 static unsigned int const PSIG;
315 static a_float trap(a_float x, a_float a, a_float b, a_float c, a_float d)
317 return a_mf_trap(x, a, b, c, d);
319 static unsigned int const TRAP;
320 static a_float tri(a_float x, a_float a, a_float b, a_float c)
322 return a_mf_tri(x, a, b, c);
324 static unsigned int const TRI;
325 static a_float lins(a_float x, a_float a, a_float b)
327 return a_mf_lins(x, a, b);
329 static unsigned int const LINS;
330 static a_float linz(a_float x, a_float a, a_float b)
332 return a_mf_linz(x, a, b);
334 static unsigned int const LINZ;
335 static a_float s(a_float x, a_float a, a_float b)
337 return a_mf_s(x, a, b);
339 static unsigned int const S;
340 static a_float z(a_float x, a_float a, a_float b)
342 return a_mf_z(x, a, b);
344 static unsigned int const Z;
345 static a_float pi(a_float x, a_float a, a_float b, a_float c, a_float d)
347 return a_mf_pi(x, a, b, c, d);
349 static unsigned int const PI;
351 unsigned int const mf::NUL = A_MF_NUL;
352 unsigned int const mf::GAUSS = A_MF_GAUSS;
353 unsigned int const mf::GAUSS2 = A_MF_GAUSS2;
354 unsigned int const mf::GBELL = A_MF_GBELL;
355 unsigned int const mf::SIG = A_MF_SIG;
356 unsigned int const mf::DSIG = A_MF_DSIG;
357 unsigned int const mf::PSIG = A_MF_PSIG;
358 unsigned int const mf::TRAP = A_MF_TRAP;
359 unsigned int const mf::TRI = A_MF_TRI;
360 unsigned int const mf::LINS = A_MF_LINS;
361 unsigned int const mf::LINZ = A_MF_LINZ;
362 unsigned int const mf::S = A_MF_S;
363 unsigned int const mf::Z = A_MF_Z;
364 unsigned int const mf::PI = A_MF_PI;
366 #include "a/pid.h"
368 struct pid: public a_pid
370 A_INLINE pid *set_kpid(a_float kp_, a_float ki_, a_float kd_)
372 a_pid::set_kpid(kp_, ki_, kd_);
373 return this;
375 A_INLINE a_float run(a_float set, a_float fdb_)
377 return a_pid::run(set, fdb_);
379 A_INLINE a_float pos(a_float set, a_float fdb_)
381 return a_pid::pos(set, fdb_);
383 A_INLINE a_float inc(a_float set, a_float fdb_)
385 return a_pid::inc(set, fdb_);
387 A_INLINE pid *zero()
389 a_pid::zero();
390 return this;
392 A_INLINE pid()
394 kp = 1;
395 ki = 0;
396 kd = 0;
397 summax = +A_FLOAT_INF;
398 summin = -A_FLOAT_INF;
399 outmax = +A_FLOAT_INF;
400 outmin = -A_FLOAT_INF;
401 a_pid_init(this);
403 A_INLINE a_float kp_r() const { return kp; }
404 A_INLINE void kp_w(a_float kp_) { kp = kp_; }
405 A_INLINE a_float ki_r() const { return ki; }
406 A_INLINE void ki_w(a_float ki_) { ki = ki_; }
407 A_INLINE a_float kd_r() const { return kd; }
408 A_INLINE void kd_w(a_float kd_) { kd = kd_; }
409 A_INLINE a_float summax_r() const { return summax; }
410 A_INLINE void summax_w(a_float summax_) { summax = summax_; }
411 A_INLINE a_float summin_r() const { return summin; }
412 A_INLINE void summin_w(a_float summin_) { summin = summin_; }
413 A_INLINE a_float outmax_r() const { return outmax; }
414 A_INLINE void outmax_w(a_float outmax_) { outmax = outmax_; }
415 A_INLINE a_float outmin_r() const { return outmin; }
416 A_INLINE void outmin_w(a_float outmin_) { outmin = outmin_; }
417 A_INLINE a_float sum_r() const { return sum; }
418 A_INLINE a_float out_r() const { return out; }
419 A_INLINE a_float fdb_r() const { return fdb; }
420 A_INLINE a_float err_r() const { return err; }
423 #include "a/pid_fuzzy.h"
425 struct pid_fuzzy: public a_pid_fuzzy
427 A_INLINE pid_fuzzy *set_rule(emscripten::val const &me_,
428 emscripten::val const &mec_,
429 emscripten::val const &mkp_,
430 emscripten::val const &mki_,
431 emscripten::val const &mkd_)
433 union
435 a_float const *p;
436 a_float *o;
437 } u;
438 nrule = me_["length"].as<unsigned int>();
439 u.p = me;
440 emscripten::val val = js_concat(me_);
441 me = js_array_num_get(val, u.o, 0);
442 val.delete_(val);
443 u.p = mec;
444 val = js_concat(mec_);
445 mec = js_array_num_get(val, u.o, 0);
446 val.delete_(val);
447 u.p = mkp;
448 val = js_concat(mkp_);
449 mkp = js_array_num_get(val, u.o, 0);
450 val.delete_(val);
451 u.p = mki;
452 val = js_concat(mki_);
453 mki = js_array_num_get(val, u.o, 0);
454 val.delete_(val);
455 u.p = mkd;
456 val = js_concat(mkd_);
457 mkd = js_array_num_get(val, u.o, 0);
458 val.delete_(val);
459 return this;
461 A_INLINE pid_fuzzy *set_opr(unsigned int opr_)
463 a_pid_fuzzy::set_opr(opr_);
464 return this;
466 A_INLINE pid_fuzzy *set_nfuzz(unsigned int num)
468 void *ptr = a_alloc(a_pid_fuzzy::bfuzz(), A_PID_FUZZY_BFUZZ(num));
469 a_pid_fuzzy::set_bfuzz(ptr, num);
470 return this;
472 A_INLINE pid_fuzzy *set_kpid(a_float kp_, a_float ki_, a_float kd_)
474 a_pid_fuzzy::set_kpid(kp_, ki_, kd_);
475 return this;
477 A_INLINE a_float run(a_float set, a_float fdb)
479 return a_pid_fuzzy::run(set, fdb);
481 A_INLINE a_float pos(a_float set, a_float fdb)
483 return a_pid_fuzzy::pos(set, fdb);
485 A_INLINE a_float inc(a_float set, a_float fdb)
487 return a_pid_fuzzy::inc(set, fdb);
489 A_INLINE pid_fuzzy *zero()
491 a_pid_fuzzy::zero();
492 return this;
494 A_INLINE pid_fuzzy()
496 pid.kp = kp = 1;
497 pid.ki = ki = 0;
498 pid.kd = kd = 0;
499 pid.summax = +A_FLOAT_INF;
500 pid.summin = -A_FLOAT_INF;
501 pid.outmax = +A_FLOAT_INF;
502 pid.outmin = -A_FLOAT_INF;
503 me = nullptr;
504 mec = nullptr;
505 mkp = nullptr;
506 mki = nullptr;
507 mkd = nullptr;
508 idx = nullptr;
509 val = nullptr;
510 nrule = 0;
511 nfuzz = 0;
512 opr = a_fuzzy_equ;
513 a_pid_fuzzy_init(this);
515 A_INLINE ~pid_fuzzy()
517 union
519 a_float const *p;
520 a_float *o;
521 } u;
522 a_alloc(a_pid_fuzzy_bfuzz(this), 0);
523 u.p = me;
524 a_alloc(u.o, 0);
525 u.p = mec;
526 a_alloc(u.o, 0);
527 u.p = mkp;
528 a_alloc(u.o, 0);
529 u.p = mki;
530 a_alloc(u.o, 0);
531 u.p = mkd;
532 a_alloc(u.o, 0);
534 A_INLINE a_float kp_r() const { return kp; }
535 A_INLINE void kp_w(a_float kp_) { kp = kp_; }
536 A_INLINE a_float ki_r() const { return ki; }
537 A_INLINE void ki_w(a_float ki_) { ki = ki_; }
538 A_INLINE a_float kd_r() const { return kd; }
539 A_INLINE void kd_w(a_float kd_) { kd = kd_; }
540 A_INLINE a_float summax_r() const { return pid.summax; }
541 A_INLINE void summax_w(a_float summax) { pid.summax = summax; }
542 A_INLINE a_float summin_r() const { return pid.summin; }
543 A_INLINE void summin_w(a_float summin) { pid.summin = summin; }
544 A_INLINE a_float outmax_r() const { return pid.outmax; }
545 A_INLINE void outmax_w(a_float outmax) { pid.outmax = outmax; }
546 A_INLINE a_float outmin_r() const { return pid.outmin; }
547 A_INLINE void outmin_w(a_float outmin) { pid.outmin = outmin; }
548 A_INLINE a_float sum_r() const { return pid.sum; }
549 A_INLINE a_float out_r() const { return pid.out; }
550 A_INLINE a_float fdb_r() const { return pid.fdb; }
551 A_INLINE a_float err_r() const { return pid.err; }
552 A_INLINE unsigned int nrule_r() const { return nrule; }
553 A_INLINE unsigned int nfuzz_r() const { return nfuzz; }
554 static unsigned int const CAP;
555 static unsigned int const CAP_ALGEBRA;
556 static unsigned int const CAP_BOUNDED;
557 static unsigned int const CUP;
558 static unsigned int const CUP_ALGEBRA;
559 static unsigned int const CUP_BOUNDED;
560 static unsigned int const EQU;
562 unsigned int const pid_fuzzy::CAP = A_PID_FUZZY_CAP;
563 unsigned int const pid_fuzzy::CAP_ALGEBRA = A_PID_FUZZY_CAP_ALGEBRA;
564 unsigned int const pid_fuzzy::CAP_BOUNDED = A_PID_FUZZY_CAP_BOUNDED;
565 unsigned int const pid_fuzzy::CUP = A_PID_FUZZY_CUP;
566 unsigned int const pid_fuzzy::CUP_ALGEBRA = A_PID_FUZZY_CUP_ALGEBRA;
567 unsigned int const pid_fuzzy::CUP_BOUNDED = A_PID_FUZZY_CUP_BOUNDED;
568 unsigned int const pid_fuzzy::EQU = A_PID_FUZZY_EQU;
570 #include "a/pid_neuro.h"
572 struct pid_neuro: public a_pid_neuro
574 A_INLINE pid_neuro *set_kpid(a_float k_, a_float kp, a_float ki, a_float kd)
576 a_pid_neuro::set_kpid(k_, kp, ki, kd);
577 return this;
579 A_INLINE pid_neuro *set_wpid(a_float wp_, a_float wi_, a_float wd_)
581 a_pid_neuro::set_wpid(wp_, wi_, wd_);
582 return this;
584 A_INLINE a_float run(a_float set, a_float fdb)
586 return a_pid_neuro::run(set, fdb);
588 A_INLINE a_float inc(a_float set, a_float fdb)
590 return a_pid_neuro::inc(set, fdb);
592 A_INLINE pid_neuro *zero()
594 a_pid_neuro::zero();
595 return this;
597 A_INLINE pid_neuro()
599 pid.summax = +A_FLOAT_INF;
600 pid.summin = -A_FLOAT_INF;
601 pid.outmax = +A_FLOAT_INF;
602 pid.outmin = -A_FLOAT_INF;
603 pid.kp = k = 1;
604 pid.ki = 0;
605 pid.kd = 0;
606 wp = A_FLOAT_C(0.1);
607 wi = A_FLOAT_C(0.1);
608 wd = A_FLOAT_C(0.1);
609 a_pid_neuro_init(this);
611 A_INLINE a_float k_r() const { return k; }
612 A_INLINE void k_w(a_float k_) { k = k_; }
613 A_INLINE a_float kp_r() const { return pid.kp; }
614 A_INLINE void kp_w(a_float kp) { pid.kp = kp; }
615 A_INLINE a_float ki_r() const { return pid.ki; }
616 A_INLINE void ki_w(a_float ki) { pid.ki = ki; }
617 A_INLINE a_float kd_r() const { return pid.kd; }
618 A_INLINE void kd_w(a_float kd) { pid.kd = kd; }
619 A_INLINE a_float wp_r() const { return wp; }
620 A_INLINE void wp_w(a_float wp_) { wp = wp_; }
621 A_INLINE a_float wi_r() const { return wi; }
622 A_INLINE void wi_w(a_float wi_) { wi = wi_; }
623 A_INLINE a_float wd_r() const { return wd; }
624 A_INLINE void wd_w(a_float wd_) { wd = wd_; }
625 A_INLINE a_float outmax_r() const { return pid.outmax; }
626 A_INLINE void outmax_w(a_float outmax) { pid.outmax = outmax; }
627 A_INLINE a_float outmin_r() const { return pid.outmin; }
628 A_INLINE void outmin_w(a_float outmin) { pid.outmin = outmin; }
629 A_INLINE a_float out_r() const { return pid.out; }
630 A_INLINE a_float fdb_r() const { return pid.fdb; }
631 A_INLINE a_float err_r() const { return pid.err; }
632 A_INLINE a_float ec_r() const { return ec; }
635 #include "a/regress_simple.h"
637 struct regress_simple: public a_regress_simple
639 A_INLINE a_float coef_r() const { return coef; }
640 A_INLINE void coef_w(a_float coef_) { coef = coef_; }
641 A_INLINE a_float bias_r() const { return bias; }
642 A_INLINE void bias_w(a_float bias_) { bias = bias_; }
643 A_INLINE regress_simple(a_float a = 1, a_float b = 0)
645 a_regress_simple::init(a, b);
647 A_INLINE a_float eval(a_float val) const
649 return a_regress_simple::eval(val);
651 A_INLINE a_float evar(a_float val) const
653 return a_regress_simple::evar(val);
655 A_INLINE regress_simple *ols_(emscripten::val const &x_, emscripten::val const &y_, a_float x_mean, a_float y_mean)
657 a_size n = x_["length"].as<a_size>();
658 a_float *x = js_array_num_get(x_, nullptr, n);
659 a_float *y = js_array_num_get(y_, nullptr, n);
660 a_regress_simple::ols(n, x, y, x_mean, y_mean);
661 a_alloc(y, 0);
662 a_alloc(x, 0);
663 return this;
665 A_INLINE regress_simple *olsx(emscripten::val const &x_, emscripten::val const &y_, a_float x_mean)
667 a_size n = x_["length"].as<a_size>();
668 a_float *x = js_array_num_get(x_, nullptr, n);
669 a_float *y = js_array_num_get(y_, nullptr, n);
670 a_regress_simple::olsx(n, x, y, x_mean);
671 a_alloc(y, 0);
672 a_alloc(x, 0);
673 return this;
675 A_INLINE regress_simple *olsy(emscripten::val const &x_, emscripten::val const &y_, a_float y_mean)
677 a_size n = x_["length"].as<a_size>();
678 a_float *x = js_array_num_get(x_, nullptr, n);
679 a_float *y = js_array_num_get(y_, nullptr, n);
680 a_regress_simple::olsy(n, x, y, y_mean);
681 a_alloc(y, 0);
682 a_alloc(x, 0);
683 return this;
685 A_INLINE regress_simple *ols(emscripten::val const &x_, emscripten::val const &y_)
687 a_size n = x_["length"].as<a_size>();
688 a_float *x = js_array_num_get(x_, nullptr, n);
689 a_float *y = js_array_num_get(y_, nullptr, n);
690 a_regress_simple::ols(n, x, y);
691 a_alloc(y, 0);
692 a_alloc(x, 0);
693 return this;
695 A_INLINE regress_simple *zero()
697 a_regress_simple::zero();
698 return this;
702 #include "a/tf.h"
704 struct tf: public a_tf
706 void set_num_(emscripten::val const &num_, a_float *num)
708 a_uint num_n = num_["length"].as<a_uint>();
709 a_float *p = js_array_num_get(num_, num, a_size_c(num_n) * 2);
710 a_tf_set_num(this, num_n, p, p + num_n);
712 void set_den_(emscripten::val const &den_, a_float *den)
714 a_uint den_n = den_["length"].as<a_uint>();
715 a_float *p = js_array_num_get(den_, den, a_size_c(den_n) * 2);
716 a_tf_set_den(this, den_n, p, p + den_n);
718 A_INLINE tf(emscripten::val const &num, emscripten::val const &den)
720 set_num_(num, nullptr);
721 set_den_(den, nullptr);
723 ~tf()
725 union
727 a_float const *p;
728 a_float *o;
729 } u;
730 u.p = num_p;
731 a_alloc(u.o, 0);
732 u.p = den_p;
733 a_alloc(u.o, 0);
735 A_INLINE emscripten::val input_r() const { return js_array_num_new(input, num_n); }
736 A_INLINE emscripten::val output_r() const { return js_array_num_new(output, den_n); }
737 A_INLINE emscripten::val num_r() const { return js_array_num_new(num_p, num_n); }
738 A_INLINE emscripten::val den_r() const { return js_array_num_new(den_p, den_n); }
739 A_INLINE tf *set_num(emscripten::val const &num)
741 union
743 a_float const *p;
744 a_float *o;
745 } u = {num_p};
746 set_num_(num, u.o);
747 return this;
749 A_INLINE tf *set_den(emscripten::val const &den)
751 union
753 a_float const *p;
754 a_float *o;
755 } u = {den_p};
756 set_den_(den, u.o);
757 return this;
759 A_INLINE a_float operator()(a_float x) const
761 return a_tf::operator()(x);
763 A_INLINE tf *zero()
765 a_tf::zero();
766 return this;
770 #include "a/trajbell.h"
772 struct trajbell: public a_trajbell
774 A_INLINE a_float gen(a_float jm_, a_float am_, a_float vm_, a_float p0_, a_float p1_,
775 a_float v0_ = 0, a_float v1_ = 0)
777 return a_trajbell::gen(jm_, am_, vm_, p0_, p1_, v0_, v1_);
779 A_INLINE a_float pos(a_float x) const { return a_trajbell::pos(x); }
780 A_INLINE a_float vel(a_float x) const { return a_trajbell::vel(x); }
781 A_INLINE a_float acc(a_float x) const { return a_trajbell::acc(x); }
782 A_INLINE a_float jer(a_float x) const { return a_trajbell::jer(x); }
783 A_INLINE a_float t_r() const { return t; }
784 A_INLINE a_float tv_r() const { return tv; }
785 A_INLINE a_float ta_r() const { return ta; }
786 A_INLINE a_float td_r() const { return td; }
787 A_INLINE a_float taj_r() const { return taj; }
788 A_INLINE a_float tdj_r() const { return tdj; }
789 A_INLINE a_float p0_r() const { return p0; }
790 A_INLINE a_float p1_r() const { return p1; }
791 A_INLINE a_float v0_r() const { return v0; }
792 A_INLINE a_float v1_r() const { return v1; }
793 A_INLINE a_float vm_r() const { return vm; }
794 A_INLINE a_float jm_r() const { return jm; }
795 A_INLINE a_float am_r() const { return am; }
796 A_INLINE a_float dm_r() const { return dm; }
799 #include "a/trajpoly3.h"
801 struct trajpoly3: public a_trajpoly3
803 A_INLINE trajpoly3(a_float ts, a_float p0, a_float p1,
804 a_float v0 = 0, a_float v1 = 0)
806 a_trajpoly3_gen(this, ts, p0, p1, v0, v1);
808 A_INLINE a_float pos(a_float x) const { return a_trajpoly3::pos(x); }
809 A_INLINE a_float vel(a_float x) const { return a_trajpoly3::vel(x); }
810 A_INLINE a_float acc(a_float x) const { return a_trajpoly3::acc(x); }
811 A_INLINE emscripten::val p_r() const { return js_array_num_new(p, A_LEN(p)); }
812 A_INLINE emscripten::val v_r() const { return js_array_num_new(v, A_LEN(v)); }
813 A_INLINE emscripten::val a_r() const { return js_array_num_new(a, A_LEN(a)); }
816 #include "a/trajpoly5.h"
818 struct trajpoly5: public a_trajpoly5
820 A_INLINE trajpoly5(a_float ts, a_float p0, a_float p1,
821 a_float v0 = 0, a_float v1 = 0,
822 a_float a0 = 0, a_float a1 = 0)
824 a_trajpoly5_gen(this, ts, p0, p1, v0, v1, a0, a1);
826 A_INLINE a_float pos(a_float x) const { return a_trajpoly5::pos(x); }
827 A_INLINE a_float vel(a_float x) const { return a_trajpoly5::vel(x); }
828 A_INLINE a_float acc(a_float x) const { return a_trajpoly5::acc(x); }
829 A_INLINE emscripten::val p_r() const { return js_array_num_new(p, A_LEN(p)); }
830 A_INLINE emscripten::val v_r() const { return js_array_num_new(v, A_LEN(v)); }
831 A_INLINE emscripten::val a_r() const { return js_array_num_new(a, A_LEN(a)); }
834 #include "a/trajpoly7.h"
836 struct trajpoly7: public a_trajpoly7
838 A_INLINE trajpoly7(a_float ts, a_float p0, a_float p1,
839 a_float v0 = 0, a_float v1 = 0,
840 a_float a0 = 0, a_float a1 = 0,
841 a_float j0 = 0, a_float j1 = 0)
843 a_trajpoly7_gen(this, ts, p0, p1, v0, v1, a0, a1, j0, j1);
845 A_INLINE a_float pos(a_float x) const { return a_trajpoly7::pos(x); }
846 A_INLINE a_float vel(a_float x) const { return a_trajpoly7::vel(x); }
847 A_INLINE a_float acc(a_float x) const { return a_trajpoly7::acc(x); }
848 A_INLINE a_float jer(a_float x) const { return a_trajpoly7::jer(x); }
849 A_INLINE emscripten::val p_r() const { return js_array_num_new(p, A_LEN(p)); }
850 A_INLINE emscripten::val v_r() const { return js_array_num_new(v, A_LEN(v)); }
851 A_INLINE emscripten::val a_r() const { return js_array_num_new(a, A_LEN(a)); }
852 A_INLINE emscripten::val j_r() const { return js_array_num_new(j, A_LEN(j)); }
855 #include "a/trajtrap.h"
857 struct trajtrap: public a_trajtrap
859 A_INLINE a_float gen(a_float vm, a_float ac_, a_float de_, a_float p0_, a_float p1_,
860 a_float v0_ = 0, a_float v1_ = 0)
862 return a_trajtrap::gen(vm, ac_, de_, p0_, p1_, v0_, v1_);
864 A_INLINE a_float pos(a_float x) const { return a_trajtrap::pos(x); }
865 A_INLINE a_float vel(a_float x) const { return a_trajtrap::vel(x); }
866 A_INLINE a_float acc(a_float x) const { return a_trajtrap::acc(x); }
867 A_INLINE a_float t_r() const { return t; }
868 A_INLINE a_float p0_r() const { return p0; }
869 A_INLINE a_float p1_r() const { return p1; }
870 A_INLINE a_float v0_r() const { return v0; }
871 A_INLINE a_float v1_r() const { return v1; }
872 A_INLINE a_float vc_r() const { return vc; }
873 A_INLINE a_float ta_r() const { return ta; }
874 A_INLINE a_float td_r() const { return td; }
875 A_INLINE a_float pa_r() const { return pa; }
876 A_INLINE a_float pd_r() const { return pd; }
877 A_INLINE a_float ac_r() const { return ac; }
878 A_INLINE a_float de_r() const { return de; }
881 #include "a/version.h"
883 struct version: public a_version
885 A_INLINE a_int cmp(version const &ver) const
887 return a_version::cmp(ver);
889 A_INLINE a_bool operator<(version const &ver) const
891 return a_version::operator<(ver);
893 A_INLINE a_bool operator>(version const &ver) const
895 return a_version::operator>(ver);
897 A_INLINE a_bool operator<=(version const &ver) const
899 return a_version::operator<=(ver);
901 A_INLINE a_bool operator>=(version const &ver) const
903 return a_version::operator>=(ver);
905 A_INLINE a_bool operator==(version const &ver) const
907 return a_version::operator==(ver);
909 A_INLINE a_bool operator!=(version const &ver) const
911 return a_version::operator!=(ver);
913 A_INLINE version *parse(std::string const &ver)
915 a_version::parse(ver.c_str());
916 return this;
918 A_INLINE std::string toString() const
920 char str[48];
921 a_version::tostr(str, sizeof(str));
922 return std::string(str);
924 A_INLINE version(unsigned int major_ = 0,
925 unsigned int minor_ = 0,
926 unsigned int third_ = 0,
927 unsigned int extra_ = 0)
929 major = major_;
930 minor = minor_;
931 third = third_;
932 extra = extra_;
933 alpha_[0] = '.';
934 alpha_[1] = 0;
935 alpha_[2] = 0;
936 alpha_[3] = 0;
938 A_INLINE void major_w(unsigned int major_) { major = major_; }
939 A_INLINE unsigned int major_r() const { return major; }
940 A_INLINE void minor_w(unsigned int minor_) { minor = minor_; }
941 A_INLINE unsigned int minor_r() const { return minor; }
942 A_INLINE void third_w(unsigned int third_) { third = third_; }
943 A_INLINE unsigned int third_r() const { return third; }
944 A_INLINE void extra_w(unsigned int extra_) { extra = extra_; }
945 A_INLINE unsigned int extra_r() const { return extra; }
946 A_INLINE void alpha_w(std::string const &str)
948 a_version::set_alpha(str.c_str());
950 A_INLINE std::string alpha_r() const
952 char str[sizeof(alpha_) + 1];
953 a_version::alpha(str);
954 return std::string(str);
956 static unsigned int const MAJOR;
957 static unsigned int const MINOR;
958 static unsigned int const PATCH;
959 static a_u32 const TWEAK;
961 unsigned int const version::MAJOR = A_VERSION_MAJOR;
962 unsigned int const version::MINOR = A_VERSION_MINOR;
963 unsigned int const version::PATCH = A_VERSION_PATCH;
964 a_u32 const version::TWEAK = A_VERSION_TWEAK;
966 #if __has_warning("-Wglobal-constructors")
967 #pragma clang diagnostic ignored "-Wglobal-constructors"
968 #endif /* -Wglobal-constructors */
969 EMSCRIPTEN_BINDINGS(liba) // NOLINT
971 emscripten::function("isqrt", a_u32_sqrt);
972 emscripten::function("rsqrt", a_f64_rsqrt);
973 emscripten::function("hash_bkdr", hash_bkdr);
974 emscripten::function("hash_sdbm", hash_sdbm);
975 emscripten::class_<mf>("mf")
976 .class_property("NUL", &mf::NUL)
977 .class_function("gauss", &mf::gauss)
978 .class_property("GAUSS", &mf::GAUSS)
979 .class_function("gauss2", &mf::gauss2)
980 .class_property("GAUSS2", &mf::GAUSS2)
981 .class_function("gbell", &mf::gbell)
982 .class_property("GBELL", &mf::GBELL)
983 .class_function("sig", &mf::sig)
984 .class_property("SIG", &mf::SIG)
985 .class_function("dsig", &mf::dsig)
986 .class_property("DSIG", &mf::DSIG)
987 .class_function("psig", &mf::psig)
988 .class_property("PSIG", &mf::PSIG)
989 .class_function("trap", &mf::trap)
990 .class_property("TRAP", &mf::TRAP)
991 .class_function("tri", &mf::tri)
992 .class_property("TRI", &mf::TRI)
993 .class_function("lins", &mf::lins)
994 .class_property("LINS", &mf::LINS)
995 .class_function("linz", &mf::linz)
996 .class_property("LINZ", &mf::LINZ)
997 .class_function("s", &mf::s)
998 .class_property("S", &mf::S)
999 .class_function("z", &mf::z)
1000 .class_property("Z", &mf::Z)
1001 .class_function("pi", &mf::pi)
1002 .class_property("PI", &mf::PI);
1003 emscripten::class_<crc8>("crc8")
1004 .constructor<a_u8>()
1005 .constructor<a_u8, bool>()
1006 .property("table", &crc8::table_r)
1007 .function("eval", &crc8::operator())
1008 .function("pack", &crc8::pack)
1009 .function("gen", &crc8::gen, emscripten::allow_raw_pointers());
1010 emscripten::class_<crc16>("crc16")
1011 .constructor<a_u16>()
1012 .constructor<a_u16, bool>()
1013 .property("table", &crc16::table_r)
1014 .function("eval", &crc16::operator())
1015 .function("pack", &crc16::pack)
1016 .function("gen", &crc16::gen, emscripten::allow_raw_pointers());
1017 emscripten::class_<crc32>("crc32")
1018 .constructor<a_u32>()
1019 .constructor<a_u32, bool>()
1020 .property("table", &crc32::table_r)
1021 .function("eval", &crc32::operator())
1022 .function("pack", &crc32::pack)
1023 .function("gen", &crc32::gen, emscripten::allow_raw_pointers());
1024 #if defined(WASM_BIGINT)
1025 emscripten::class_<crc64>("crc64")
1026 .constructor<a_u64>()
1027 .constructor<a_u64, bool>()
1028 .property("table", &crc64::table_r)
1029 .function("eval", &crc64::operator())
1030 .function("pack", &crc64::pack)
1031 .function("gen", &crc64::gen, emscripten::allow_raw_pointers());
1032 #endif /* WASM_BIGINT */
1033 emscripten::class_<hpf>("hpf")
1034 .constructor<a_float>()
1035 .constructor<a_float, a_float>()
1036 .function("iter", &hpf::operator())
1037 .function("gen", &hpf::gen, emscripten::allow_raw_pointers())
1038 .function("zero", &hpf::zero, emscripten::allow_raw_pointers())
1039 .property("alpha", &hpf::alpha_r)
1040 .property("output", &hpf::output_r)
1041 .property("input", &hpf::input_r);
1042 emscripten::class_<lpf>("lpf")
1043 .constructor<a_float>()
1044 .constructor<a_float, a_float>()
1045 .function("iter", &lpf::operator())
1046 .function("gen", &lpf::gen, emscripten::allow_raw_pointers())
1047 .function("zero", &lpf::zero, emscripten::allow_raw_pointers())
1048 .property("alpha", &lpf::alpha_r)
1049 .property("output", &lpf::output_r);
1050 emscripten::class_<pid>("pid")
1051 .constructor<>()
1052 .function("set_kpid", &pid::set_kpid, emscripten::allow_raw_pointers())
1053 .function("zero", &pid::zero, emscripten::allow_raw_pointers())
1054 .function("run", &pid::run)
1055 .function("pos", &pid::pos)
1056 .function("inc", &pid::inc)
1057 .property("kp", &pid::kp_r, &pid::kp_w)
1058 .property("ki", &pid::ki_r, &pid::ki_w)
1059 .property("kd", &pid::kd_r, &pid::kd_w)
1060 .property("summax", &pid::summax_r, &pid::summax_w)
1061 .property("summin", &pid::summin_r, &pid::summin_w)
1062 .property("outmax", &pid::outmax_r, &pid::outmax_w)
1063 .property("outmin", &pid::outmin_r, &pid::outmin_w)
1064 .property("sum", &pid::sum_r)
1065 .property("out", &pid::out_r)
1066 .property("fdb", &pid::fdb_r)
1067 .property("err", &pid::err_r);
1068 emscripten::class_<pid_fuzzy>("pid_fuzzy")
1069 .constructor<>()
1070 .function("set_opr", &pid_fuzzy::set_opr, emscripten::allow_raw_pointers())
1071 .function("set_nfuzz", &pid_fuzzy::set_nfuzz, emscripten::allow_raw_pointers())
1072 .function("set_rule", &pid_fuzzy::set_rule, emscripten::allow_raw_pointers())
1073 .function("set_kpid", &pid_fuzzy::set_kpid, emscripten::allow_raw_pointers())
1074 .function("zero", &pid_fuzzy::zero, emscripten::allow_raw_pointers())
1075 .function("run", &pid_fuzzy::run)
1076 .function("pos", &pid_fuzzy::pos)
1077 .function("inc", &pid_fuzzy::inc)
1078 .class_property("CAP", &pid_fuzzy::CAP)
1079 .class_property("CAP_ALGEBRA", &pid_fuzzy::CAP_ALGEBRA)
1080 .class_property("CAP_BOUNDED", &pid_fuzzy::CAP_BOUNDED)
1081 .class_property("CUP", &pid_fuzzy::CUP)
1082 .class_property("CUP_ALGEBRA", &pid_fuzzy::CUP_ALGEBRA)
1083 .class_property("CUP_BOUNDED", &pid_fuzzy::CUP_BOUNDED)
1084 .class_property("EQU", &pid_fuzzy::EQU)
1085 .property("kp", &pid_fuzzy::kp_r, &pid_fuzzy::kp_w)
1086 .property("ki", &pid_fuzzy::ki_r, &pid_fuzzy::ki_w)
1087 .property("kd", &pid_fuzzy::kd_r, &pid_fuzzy::kd_w)
1088 .property("summax", &pid_fuzzy::summax_r, &pid_fuzzy::summax_w)
1089 .property("summin", &pid_fuzzy::summin_r, &pid_fuzzy::summin_w)
1090 .property("outmax", &pid_fuzzy::outmax_r, &pid_fuzzy::outmax_w)
1091 .property("outmin", &pid_fuzzy::outmin_r, &pid_fuzzy::outmin_w)
1092 .property("sum", &pid_fuzzy::sum_r)
1093 .property("out", &pid_fuzzy::out_r)
1094 .property("fdb", &pid_fuzzy::fdb_r)
1095 .property("err", &pid_fuzzy::err_r)
1096 .property("nrule", &pid_fuzzy::nrule_r)
1097 .property("nfuzz", &pid_fuzzy::nfuzz_r, &pid_fuzzy::set_nfuzz);
1098 emscripten::class_<pid_neuro>("pid_neuro")
1099 .constructor<>()
1100 .function("set_kpid", &pid_neuro::set_kpid, emscripten::allow_raw_pointers())
1101 .function("set_wpid", &pid_neuro::set_wpid, emscripten::allow_raw_pointers())
1102 .function("zero", &pid_neuro::zero, emscripten::allow_raw_pointers())
1103 .function("run", &pid_neuro::run)
1104 .function("inc", &pid_neuro::inc)
1105 .property("k", &pid_neuro::k_r, &pid_neuro::k_w)
1106 .property("kp", &pid_neuro::kp_r, &pid_neuro::kp_w)
1107 .property("ki", &pid_neuro::ki_r, &pid_neuro::ki_w)
1108 .property("kd", &pid_neuro::kd_r, &pid_neuro::kd_w)
1109 .property("wp", &pid_neuro::wp_r, &pid_neuro::wp_w)
1110 .property("wi", &pid_neuro::wi_r, &pid_neuro::wi_w)
1111 .property("wd", &pid_neuro::wd_r, &pid_neuro::wd_w)
1112 .property("outmax", &pid_neuro::outmax_r, &pid_neuro::outmax_w)
1113 .property("outmin", &pid_neuro::outmin_r, &pid_neuro::outmin_w)
1114 .property("out", &pid_neuro::out_r)
1115 .property("fdb", &pid_neuro::fdb_r)
1116 .property("err", &pid_neuro::err_r)
1117 .property("ec", &pid_neuro::ec_r);
1118 emscripten::class_<regress_simple>("regress_simple")
1119 .constructor<>()
1120 .constructor<a_float>()
1121 .constructor<a_float, a_float>()
1122 .function("eval", &regress_simple::eval)
1123 .function("evar", &regress_simple::evar)
1124 .function("ols_", &regress_simple::ols_, emscripten::allow_raw_pointers())
1125 .function("olsx", &regress_simple::olsx, emscripten::allow_raw_pointers())
1126 .function("olsy", &regress_simple::olsy, emscripten::allow_raw_pointers())
1127 .function("ols", &regress_simple::ols, emscripten::allow_raw_pointers())
1128 .function("zero", &regress_simple::zero, emscripten::allow_raw_pointers())
1129 .property("coef", &regress_simple::coef_r, &regress_simple::coef_w)
1130 .property("bias", &regress_simple::bias_r, &regress_simple::bias_w);
1131 emscripten::class_<tf>("tf")
1132 .constructor<emscripten::val, emscripten::val>()
1133 .function("set_num", &tf::set_num, emscripten::allow_raw_pointers())
1134 .function("set_den", &tf::set_den, emscripten::allow_raw_pointers())
1135 .function("zero", &tf::zero, emscripten::allow_raw_pointers())
1136 .function("iter", &tf::operator())
1137 .property("input", &tf::input_r)
1138 .property("output", &tf::output_r)
1139 .property("num", &tf::num_r, &tf::set_num)
1140 .property("den", &tf::den_r, &tf::set_den);
1141 emscripten::class_<trajbell>("trajbell")
1142 .constructor<>()
1143 .function("gen", &trajbell::gen)
1144 .function("pos", &trajbell::pos)
1145 .function("vel", &trajbell::vel)
1146 .function("acc", &trajbell::acc)
1147 .function("jer", &trajbell::jer)
1148 .property("t", &trajbell::t_r)
1149 .property("tv", &trajbell::tv_r)
1150 .property("ta", &trajbell::ta_r)
1151 .property("td", &trajbell::td_r)
1152 .property("taj", &trajbell::taj_r)
1153 .property("tdj", &trajbell::tdj_r)
1154 .property("p0", &trajbell::p0_r)
1155 .property("p1", &trajbell::p1_r)
1156 .property("v0", &trajbell::v0_r)
1157 .property("v1", &trajbell::v1_r)
1158 .property("vm", &trajbell::vm_r)
1159 .property("jm", &trajbell::jm_r)
1160 .property("am", &trajbell::am_r)
1161 .property("dm", &trajbell::dm_r);
1162 emscripten::class_<trajpoly3>("trajpoly3")
1163 .constructor<a_float, a_float, a_float>()
1164 .constructor<a_float, a_float, a_float, a_float, a_float>()
1165 .function("pos", &trajpoly3::pos)
1166 .function("vel", &trajpoly3::vel)
1167 .function("acc", &trajpoly3::acc)
1168 .property("p", &trajpoly3::p_r)
1169 .property("v", &trajpoly3::v_r)
1170 .property("a", &trajpoly3::a_r);
1171 emscripten::class_<trajpoly5>("trajpoly5")
1172 .constructor<a_float, a_float, a_float>()
1173 .constructor<a_float, a_float, a_float, a_float, a_float>()
1174 .constructor<a_float, a_float, a_float, a_float, a_float, a_float, a_float>()
1175 .function("pos", &trajpoly5::pos)
1176 .function("vel", &trajpoly5::vel)
1177 .function("acc", &trajpoly5::acc)
1178 .property("p", &trajpoly5::p_r)
1179 .property("v", &trajpoly5::v_r)
1180 .property("a", &trajpoly5::a_r);
1181 emscripten::class_<trajpoly7>("trajpoly7")
1182 .constructor<a_float, a_float, a_float>()
1183 .constructor<a_float, a_float, a_float, a_float, a_float>()
1184 .constructor<a_float, a_float, a_float, a_float, a_float, a_float, a_float>()
1185 .constructor<a_float, a_float, a_float, a_float, a_float, a_float, a_float, a_float, a_float>()
1186 .function("pos", &trajpoly7::pos)
1187 .function("vel", &trajpoly7::vel)
1188 .function("acc", &trajpoly7::acc)
1189 .function("jer", &trajpoly7::jer)
1190 .property("p", &trajpoly7::p_r)
1191 .property("v", &trajpoly7::v_r)
1192 .property("a", &trajpoly7::a_r)
1193 .property("j", &trajpoly7::j_r);
1194 emscripten::class_<trajtrap>("trajtrap")
1195 .constructor<>()
1196 .function("gen", &trajtrap::gen)
1197 .function("pos", &trajtrap::pos)
1198 .function("vel", &trajtrap::vel)
1199 .function("acc", &trajtrap::acc)
1200 .property("t", &trajtrap::t_r)
1201 .property("p0", &trajtrap::p0_r)
1202 .property("p1", &trajtrap::p1_r)
1203 .property("v0", &trajtrap::v0_r)
1204 .property("v1", &trajtrap::v1_r)
1205 .property("vc", &trajtrap::vc_r)
1206 .property("ta", &trajtrap::ta_r)
1207 .property("td", &trajtrap::td_r)
1208 .property("pa", &trajtrap::pa_r)
1209 .property("pd", &trajtrap::pd_r)
1210 .property("ac", &trajtrap::ac_r)
1211 .property("de", &trajtrap::de_r);
1212 emscripten::class_<version>("version")
1213 .constructor<>()
1214 .constructor<a_uint>()
1215 .constructor<a_uint, a_uint>()
1216 .constructor<a_uint, a_uint, a_uint>()
1217 .constructor<a_uint, a_uint, a_uint, a_uint>()
1218 .property("major", &version::major_r, &version::major_w)
1219 .property("minor", &version::minor_r, &version::minor_w)
1220 .property("third", &version::third_r, &version::third_w)
1221 .property("extra", &version::extra_r, &version::extra_w)
1222 .property("alpha", &version::alpha_r, &version::alpha_w)
1223 .function("parse", &version::parse, emscripten::allow_raw_pointers())
1224 .function("cmp", &version::cmp)
1225 .function("lt", &version::operator<)
1226 .function("gt", &version::operator>)
1227 .function("le", &version::operator<=)
1228 .function("ge", &version::operator>=)
1229 .function("eq", &version::operator==)
1230 .function("ne", &version::operator!=)
1231 .function("toString", &version::toString)
1232 .class_property("MAJOR", &version::MAJOR)
1233 .class_property("MINOR", &version::MINOR)
1234 .class_property("PATCH", &version::PATCH)
1235 .class_property("TWEAK", &version::TWEAK)
1236 .class_function("check", &a_version_check);
1237 emscripten::constant("VERSION", std::string(A_VERSION));
1238 #if defined(__has_feature) && __has_feature(address_sanitizer)
1239 emscripten::function("do_leak_check", &__lsan_do_recoverable_leak_check);
1240 #endif /* -fsanitize=address */