Showing preview only (2,466K chars total). Download the full file or copy to clipboard to get everything.
Repository: lithdew/quickjs
Branch: master
Commit: aaa42285c9d2
Files: 27
Total size: 2.3 MB
Directory structure:
gitextract_q0zhqzu1/
├── .gitattributes
├── .gitignore
├── LICENSE
├── README.md
├── bridge.c
├── bridge.h
├── cutils.c
├── cutils.h
├── examples/
│ └── main.go
├── go.mod
├── go.sum
├── libbf.c
├── libbf.h
├── libregexp-opcode.h
├── libregexp.c
├── libregexp.h
├── libunicode-table.h
├── libunicode.c
├── libunicode.h
├── list.h
├── quickjs-atom.h
├── quickjs-opcode.h
├── quickjs.c
├── quickjs.go
├── quickjs.h
├── quickjs_test.go
└── version.h
================================================
FILE CONTENTS
================================================
================================================
FILE: .gitattributes
================================================
# Set the default behavior, in case people don't have core.autocrlf set
* text=auto
# Require Unix line endings
* text eol=lf
================================================
FILE: .gitignore
================================================
.idea/
================================================
FILE: LICENSE
================================================
MIT License
Copyright (c) 2020 Kenta Iwasaki <kenta@lithdew.net>
Copyright (c) 2017-2020 Fabrice Bellard
Copyright (c) 2017-2020 Charlie Gordon
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
================================================
FILE: README.md
================================================
# quickjs
[](LICENSE)
[](https://pkg.go.dev/github.com/lithdew/quickjs)
[](https://discord.gg/HZEbkeQ)
Go bindings to [QuickJS](https://bellard.org/quickjs/): a fast, small, and embeddable [ES2020](https://tc39.github.io/ecma262/) JavaScript interpreter.
These bindings are a WIP and do not match full parity with QuickJS' API, though expose just enough features to be usable. The version of QuickJS that these bindings bind to may be located [here](version.h).
These bindings have been tested to cross-compile and run successfully on Linux, Windows, and Mac using gcc-7 and mingw32 without any addtional compiler or linker flags.
## Usage
```
$ go get github.com/lithdew/quickjs
```
## Guidelines
1. Free `quickjs.Runtime` and `quickjs.Context` once you are done using them.
2. Free `quickjs.Value`'s returned by `Eval()` and `EvalFile()`. All other values do not need to be freed, as they get garbage-collected.
3. You may access the stacktrace of an error returned by `Eval()` or `EvalFile()` by casting it to a `*quickjs.Error`.
4. Make new copies of arguments should you want to return them in functions you created.
5. Make sure to call `runtime.LockOSThread()` to ensure that QuickJS always operates in the exact same thread.
## Example
The full example code below may be found by clicking [here](examples/main.go). Find more API examples [here](quickjs_test.go).
```go
package main
import (
"errors"
"flag"
"fmt"
"github.com/lithdew/quickjs"
"strings"
)
func check(err error) {
if err != nil {
var evalErr *quickjs.Error
if errors.As(err, &evalErr) {
fmt.Println(evalErr.Cause)
fmt.Println(evalErr.Stack)
}
panic(err)
}
}
func main() {
runtime := quickjs.NewRuntime()
defer runtime.Free()
context := runtime.NewContext()
defer context.Free()
globals := context.Globals()
// Test evaluating template strings.
result, err := context.Eval("`Hello world! 2 ** 8 = ${2 ** 8}.`")
check(err)
defer result.Free()
fmt.Println(result.String())
fmt.Println()
// Test evaluating numeric expressions.
result, err = context.Eval(`1 + 2 * 100 - 3 + Math.sin(10)`)
check(err)
defer result.Free()
fmt.Println(result.Int64())
fmt.Println()
// Test evaluating big integer expressions.
result, err = context.Eval(`128n ** 16n`)
check(err)
defer result.Free()
fmt.Println(result.BigInt())
fmt.Println()
// Test evaluating big decimal expressions.
result, err = context.Eval(`128l ** 12l`)
check(err)
defer result.Free()
fmt.Println(result.BigFloat())
fmt.Println()
// Test evaluating boolean expressions.
result, err = context.Eval(`false && true`)
check(err)
defer result.Free()
fmt.Println(result.Bool())
fmt.Println()
// Test setting and calling functions.
A := func(ctx *quickjs.Context, this quickjs.Value, args []quickjs.Value) quickjs.Value {
fmt.Println("A got called!")
return ctx.Null()
}
B := func(ctx *quickjs.Context, this quickjs.Value, args []quickjs.Value) quickjs.Value {
fmt.Println("B got called!")
return ctx.Null()
}
globals.Set("A", context.Function(A))
globals.Set("B", context.Function(B))
_, err = context.Eval(`for (let i = 0; i < 10; i++) { if (i % 2 === 0) A(); else B(); }`)
check(err)
fmt.Println()
// Test setting global variables.
_, err = context.Eval(`HELLO = "world"; TEST = false;`)
check(err)
names, err := globals.PropertyNames()
check(err)
fmt.Println("Globals:")
for _, name := range names {
val := globals.GetByAtom(name.Atom)
defer val.Free()
fmt.Printf("'%s': %s\n", name, val)
}
fmt.Println()
// Test evaluating arbitrary expressions from flag arguments.
flag.Parse()
if flag.NArg() == 0 {
return
}
result, err = context.Eval(strings.Join(flag.Args(), " "))
check(err)
defer result.Free()
if result.IsObject() {
names, err := result.PropertyNames()
check(err)
fmt.Println("Object:")
for _, name := range names {
val := result.GetByAtom(name.Atom)
defer val.Free()
fmt.Printf("'%s': %s\n", name, val)
}
} else {
fmt.Println(result.String())
}
}
```
```
$ go run examples/main.go '(() => ({hello: "world", test: 2 ** 3}))()'
Hello world! 2 ** 8 = 256.
197
5192296858534827628530496329220096
1.9342813113834066795e+25
false
A got called!
B got called!
A got called!
B got called!
A got called!
B got called!
A got called!
B got called!
A got called!
B got called!
Globals:
'Object': function Object() {
[native code]
}
'Function': function Function() {
[native code]
}
'Error': function Error() {
[native code]
}
'EvalError': function EvalError() {
[native code]
}
'RangeError': function RangeError() {
[native code]
}
'ReferenceError': function ReferenceError() {
[native code]
}
'SyntaxError': function SyntaxError() {
[native code]
}
'TypeError': function TypeError() {
[native code]
}
'URIError': function URIError() {
[native code]
}
'InternalError': function InternalError() {
[native code]
}
'AggregateError': function AggregateError() {
[native code]
}
'Array': function Array() {
[native code]
}
'parseInt': function parseInt() {
[native code]
}
'parseFloat': function parseFloat() {
[native code]
}
'isNaN': function isNaN() {
[native code]
}
'isFinite': function isFinite() {
[native code]
}
'decodeURI': function decodeURI() {
[native code]
}
'decodeURIComponent': function decodeURIComponent() {
[native code]
}
'encodeURI': function encodeURI() {
[native code]
}
'encodeURIComponent': function encodeURIComponent() {
[native code]
}
'escape': function escape() {
[native code]
}
'unescape': function unescape() {
[native code]
}
'Infinity': Infinity
'NaN': NaN
'undefined': undefined
'__date_clock': function __date_clock() {
[native code]
}
'Number': function Number() {
[native code]
}
'Boolean': function Boolean() {
[native code]
}
'String': function String() {
[native code]
}
'Math': [object Math]
'Reflect': [object Object]
'Symbol': function Symbol() {
[native code]
}
'eval': function eval() {
[native code]
}
'globalThis': [object Object]
'Date': function Date() {
[native code]
}
'RegExp': function RegExp() {
[native code]
}
'JSON': [object JSON]
'Proxy': function Proxy() {
[native code]
}
'Map': function Map() {
[native code]
}
'Set': function Set() {
[native code]
}
'WeakMap': function WeakMap() {
[native code]
}
'WeakSet': function WeakSet() {
[native code]
}
'ArrayBuffer': function ArrayBuffer() {
[native code]
}
'SharedArrayBuffer': function SharedArrayBuffer() {
[native code]
}
'Uint8ClampedArray': function Uint8ClampedArray() {
[native code]
}
'Int8Array': function Int8Array() {
[native code]
}
'Uint8Array': function Uint8Array() {
[native code]
}
'Int16Array': function Int16Array() {
[native code]
}
'Uint16Array': function Uint16Array() {
[native code]
}
'Int32Array': function Int32Array() {
[native code]
}
'Uint32Array': function Uint32Array() {
[native code]
}
'BigInt64Array': function BigInt64Array() {
[native code]
}
'BigUint64Array': function BigUint64Array() {
[native code]
}
'Float32Array': function Float32Array() {
[native code]
}
'Float64Array': function Float64Array() {
[native code]
}
'DataView': function DataView() {
[native code]
}
'Atomics': [object Atomics]
'Promise': function Promise() {
[native code]
}
'BigInt': function BigInt() {
[native code]
}
'BigFloat': function BigFloat() {
[native code]
}
'BigFloatEnv': function BigFloatEnv() {
[native code]
}
'BigDecimal': function BigDecimal() {
[native code]
}
'Operators': function Operators() {
[native code]
}
'A': function() { return proxy.call(this, id, ...arguments); }
'B': function() { return proxy.call(this, id, ...arguments); }
'HELLO': world
'TEST': false
Object:
'hello': world
'test': 8
```
## License
QuickJS is released under the MIT license.
QuickJS bindings are copyright Kenta Iwasaki, with code copyright Fabrice Bellard and Charlie Gordon.
================================================
FILE: bridge.c
================================================
#include "_cgo_export.h"
JSValue InvokeProxy(JSContext *ctx, JSValueConst this_val, int argc, JSValueConst *argv) {
return proxy(ctx, this_val, argc, argv);
}
================================================
FILE: bridge.h
================================================
#include "stdlib.h"
#include "quickjs.h"
extern JSValue InvokeProxy(JSContext *ctx, JSValueConst this_val, int argc, JSValueConst *argv);
static JSValue JS_NewNull() { return JS_NULL; }
static JSValue JS_NewUndefined() { return JS_UNDEFINED; }
static JSValue JS_NewUninitialized() { return JS_UNINITIALIZED; }
static JSValue ThrowSyntaxError(JSContext *ctx, const char *fmt) { return JS_ThrowSyntaxError(ctx, "%s", fmt); }
static JSValue ThrowTypeError(JSContext *ctx, const char *fmt) { return JS_ThrowTypeError(ctx, "%s", fmt); }
static JSValue ThrowReferenceError(JSContext *ctx, const char *fmt) { return JS_ThrowReferenceError(ctx, "%s", fmt); }
static JSValue ThrowRangeError(JSContext *ctx, const char *fmt) { return JS_ThrowRangeError(ctx, "%s", fmt); }
static JSValue ThrowInternalError(JSContext *ctx, const char *fmt) { return JS_ThrowInternalError(ctx, "%s", fmt); }
================================================
FILE: cutils.c
================================================
/*
* C utilities
*
* Copyright (c) 2017 Fabrice Bellard
* Copyright (c) 2018 Charlie Gordon
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in
* all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
* THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
* THE SOFTWARE.
*/
#include <stdlib.h>
#include <stdio.h>
#include <stdarg.h>
#include <string.h>
#include "cutils.h"
void pstrcpy(char *buf, int buf_size, const char *str)
{
int c;
char *q = buf;
if (buf_size <= 0)
return;
for(;;) {
c = *str++;
if (c == 0 || q >= buf + buf_size - 1)
break;
*q++ = c;
}
*q = '\0';
}
/* strcat and truncate. */
char *pstrcat(char *buf, int buf_size, const char *s)
{
int len;
len = strlen(buf);
if (len < buf_size)
pstrcpy(buf + len, buf_size - len, s);
return buf;
}
int strstart(const char *str, const char *val, const char **ptr)
{
const char *p, *q;
p = str;
q = val;
while (*q != '\0') {
if (*p != *q)
return 0;
p++;
q++;
}
if (ptr)
*ptr = p;
return 1;
}
int has_suffix(const char *str, const char *suffix)
{
size_t len = strlen(str);
size_t slen = strlen(suffix);
return (len >= slen && !memcmp(str + len - slen, suffix, slen));
}
/* Dynamic buffer package */
static void *dbuf_default_realloc(void *opaque, void *ptr, size_t size)
{
return realloc(ptr, size);
}
void dbuf_init2(DynBuf *s, void *opaque, DynBufReallocFunc *realloc_func)
{
memset(s, 0, sizeof(*s));
if (!realloc_func)
realloc_func = dbuf_default_realloc;
s->opaque = opaque;
s->realloc_func = realloc_func;
}
void dbuf_init(DynBuf *s)
{
dbuf_init2(s, NULL, NULL);
}
/* return < 0 if error */
int dbuf_realloc(DynBuf *s, size_t new_size)
{
size_t size;
uint8_t *new_buf;
if (new_size > s->allocated_size) {
if (s->error)
return -1;
size = s->allocated_size * 3 / 2;
if (size > new_size)
new_size = size;
new_buf = s->realloc_func(s->opaque, s->buf, new_size);
if (!new_buf) {
s->error = TRUE;
return -1;
}
s->buf = new_buf;
s->allocated_size = new_size;
}
return 0;
}
int dbuf_write(DynBuf *s, size_t offset, const uint8_t *data, size_t len)
{
size_t end;
end = offset + len;
if (dbuf_realloc(s, end))
return -1;
memcpy(s->buf + offset, data, len);
if (end > s->size)
s->size = end;
return 0;
}
int dbuf_put(DynBuf *s, const uint8_t *data, size_t len)
{
if (unlikely((s->size + len) > s->allocated_size)) {
if (dbuf_realloc(s, s->size + len))
return -1;
}
memcpy(s->buf + s->size, data, len);
s->size += len;
return 0;
}
int dbuf_put_self(DynBuf *s, size_t offset, size_t len)
{
if (unlikely((s->size + len) > s->allocated_size)) {
if (dbuf_realloc(s, s->size + len))
return -1;
}
memcpy(s->buf + s->size, s->buf + offset, len);
s->size += len;
return 0;
}
int dbuf_putc(DynBuf *s, uint8_t c)
{
return dbuf_put(s, &c, 1);
}
int dbuf_putstr(DynBuf *s, const char *str)
{
return dbuf_put(s, (const uint8_t *)str, strlen(str));
}
int __attribute__((format(printf, 2, 3))) dbuf_printf(DynBuf *s,
const char *fmt, ...)
{
va_list ap;
char buf[128];
int len;
va_start(ap, fmt);
len = vsnprintf(buf, sizeof(buf), fmt, ap);
va_end(ap);
if (len < sizeof(buf)) {
/* fast case */
return dbuf_put(s, (uint8_t *)buf, len);
} else {
if (dbuf_realloc(s, s->size + len + 1))
return -1;
va_start(ap, fmt);
vsnprintf((char *)(s->buf + s->size), s->allocated_size - s->size,
fmt, ap);
va_end(ap);
s->size += len;
}
return 0;
}
void dbuf_free(DynBuf *s)
{
/* we test s->buf as a fail safe to avoid crashing if dbuf_free()
is called twice */
if (s->buf) {
s->realloc_func(s->opaque, s->buf, 0);
}
memset(s, 0, sizeof(*s));
}
/* Note: at most 31 bits are encoded. At most UTF8_CHAR_LEN_MAX bytes
are output. */
int unicode_to_utf8(uint8_t *buf, unsigned int c)
{
uint8_t *q = buf;
if (c < 0x80) {
*q++ = c;
} else {
if (c < 0x800) {
*q++ = (c >> 6) | 0xc0;
} else {
if (c < 0x10000) {
*q++ = (c >> 12) | 0xe0;
} else {
if (c < 0x00200000) {
*q++ = (c >> 18) | 0xf0;
} else {
if (c < 0x04000000) {
*q++ = (c >> 24) | 0xf8;
} else if (c < 0x80000000) {
*q++ = (c >> 30) | 0xfc;
*q++ = ((c >> 24) & 0x3f) | 0x80;
} else {
return 0;
}
*q++ = ((c >> 18) & 0x3f) | 0x80;
}
*q++ = ((c >> 12) & 0x3f) | 0x80;
}
*q++ = ((c >> 6) & 0x3f) | 0x80;
}
*q++ = (c & 0x3f) | 0x80;
}
return q - buf;
}
static const unsigned int utf8_min_code[5] = {
0x80, 0x800, 0x10000, 0x00200000, 0x04000000,
};
static const unsigned char utf8_first_code_mask[5] = {
0x1f, 0xf, 0x7, 0x3, 0x1,
};
/* return -1 if error. *pp is not updated in this case. max_len must
be >= 1. The maximum length for a UTF8 byte sequence is 6 bytes. */
int unicode_from_utf8(const uint8_t *p, int max_len, const uint8_t **pp)
{
int l, c, b, i;
c = *p++;
if (c < 0x80) {
*pp = p;
return c;
}
switch(c) {
case 0xc0 ... 0xdf:
l = 1;
break;
case 0xe0 ... 0xef:
l = 2;
break;
case 0xf0 ... 0xf7:
l = 3;
break;
case 0xf8 ... 0xfb:
l = 4;
break;
case 0xfc ... 0xfd:
l = 5;
break;
default:
return -1;
}
/* check that we have enough characters */
if (l > (max_len - 1))
return -1;
c &= utf8_first_code_mask[l - 1];
for(i = 0; i < l; i++) {
b = *p++;
if (b < 0x80 || b >= 0xc0)
return -1;
c = (c << 6) | (b & 0x3f);
}
if (c < utf8_min_code[l - 1])
return -1;
*pp = p;
return c;
}
#if 0
#if defined(EMSCRIPTEN) || defined(__ANDROID__)
static void *rqsort_arg;
static int (*rqsort_cmp)(const void *, const void *, void *);
static int rqsort_cmp2(const void *p1, const void *p2)
{
return rqsort_cmp(p1, p2, rqsort_arg);
}
/* not reentrant, but not needed with emscripten */
void rqsort(void *base, size_t nmemb, size_t size,
int (*cmp)(const void *, const void *, void *),
void *arg)
{
rqsort_arg = arg;
rqsort_cmp = cmp;
qsort(base, nmemb, size, rqsort_cmp2);
}
#endif
#else
typedef void (*exchange_f)(void *a, void *b, size_t size);
typedef int (*cmp_f)(const void *, const void *, void *opaque);
static void exchange_bytes(void *a, void *b, size_t size) {
uint8_t *ap = (uint8_t *)a;
uint8_t *bp = (uint8_t *)b;
while (size-- != 0) {
uint8_t t = *ap;
*ap++ = *bp;
*bp++ = t;
}
}
static void exchange_one_byte(void *a, void *b, size_t size) {
uint8_t *ap = (uint8_t *)a;
uint8_t *bp = (uint8_t *)b;
uint8_t t = *ap;
*ap = *bp;
*bp = t;
}
static void exchange_int16s(void *a, void *b, size_t size) {
uint16_t *ap = (uint16_t *)a;
uint16_t *bp = (uint16_t *)b;
for (size /= sizeof(uint16_t); size-- != 0;) {
uint16_t t = *ap;
*ap++ = *bp;
*bp++ = t;
}
}
static void exchange_one_int16(void *a, void *b, size_t size) {
uint16_t *ap = (uint16_t *)a;
uint16_t *bp = (uint16_t *)b;
uint16_t t = *ap;
*ap = *bp;
*bp = t;
}
static void exchange_int32s(void *a, void *b, size_t size) {
uint32_t *ap = (uint32_t *)a;
uint32_t *bp = (uint32_t *)b;
for (size /= sizeof(uint32_t); size-- != 0;) {
uint32_t t = *ap;
*ap++ = *bp;
*bp++ = t;
}
}
static void exchange_one_int32(void *a, void *b, size_t size) {
uint32_t *ap = (uint32_t *)a;
uint32_t *bp = (uint32_t *)b;
uint32_t t = *ap;
*ap = *bp;
*bp = t;
}
static void exchange_int64s(void *a, void *b, size_t size) {
uint64_t *ap = (uint64_t *)a;
uint64_t *bp = (uint64_t *)b;
for (size /= sizeof(uint64_t); size-- != 0;) {
uint64_t t = *ap;
*ap++ = *bp;
*bp++ = t;
}
}
static void exchange_one_int64(void *a, void *b, size_t size) {
uint64_t *ap = (uint64_t *)a;
uint64_t *bp = (uint64_t *)b;
uint64_t t = *ap;
*ap = *bp;
*bp = t;
}
static void exchange_int128s(void *a, void *b, size_t size) {
uint64_t *ap = (uint64_t *)a;
uint64_t *bp = (uint64_t *)b;
for (size /= sizeof(uint64_t) * 2; size-- != 0; ap += 2, bp += 2) {
uint64_t t = ap[0];
uint64_t u = ap[1];
ap[0] = bp[0];
ap[1] = bp[1];
bp[0] = t;
bp[1] = u;
}
}
static void exchange_one_int128(void *a, void *b, size_t size) {
uint64_t *ap = (uint64_t *)a;
uint64_t *bp = (uint64_t *)b;
uint64_t t = ap[0];
uint64_t u = ap[1];
ap[0] = bp[0];
ap[1] = bp[1];
bp[0] = t;
bp[1] = u;
}
static inline exchange_f exchange_func(const void *base, size_t size) {
switch (((uintptr_t)base | (uintptr_t)size) & 15) {
case 0:
if (size == sizeof(uint64_t) * 2)
return exchange_one_int128;
else
return exchange_int128s;
case 8:
if (size == sizeof(uint64_t))
return exchange_one_int64;
else
return exchange_int64s;
case 4:
case 12:
if (size == sizeof(uint32_t))
return exchange_one_int32;
else
return exchange_int32s;
case 2:
case 6:
case 10:
case 14:
if (size == sizeof(uint16_t))
return exchange_one_int16;
else
return exchange_int16s;
default:
if (size == 1)
return exchange_one_byte;
else
return exchange_bytes;
}
}
static void heapsortx(void *base, size_t nmemb, size_t size, cmp_f cmp, void *opaque)
{
uint8_t *basep = (uint8_t *)base;
size_t i, n, c, r;
exchange_f swap = exchange_func(base, size);
if (nmemb > 1) {
i = (nmemb / 2) * size;
n = nmemb * size;
while (i > 0) {
i -= size;
for (r = i; (c = r * 2 + size) < n; r = c) {
if (c < n - size && cmp(basep + c, basep + c + size, opaque) <= 0)
c += size;
if (cmp(basep + r, basep + c, opaque) > 0)
break;
swap(basep + r, basep + c, size);
}
}
for (i = n - size; i > 0; i -= size) {
swap(basep, basep + i, size);
for (r = 0; (c = r * 2 + size) < i; r = c) {
if (c < i - size && cmp(basep + c, basep + c + size, opaque) <= 0)
c += size;
if (cmp(basep + r, basep + c, opaque) > 0)
break;
swap(basep + r, basep + c, size);
}
}
}
}
static inline void *med3(void *a, void *b, void *c, cmp_f cmp, void *opaque)
{
return cmp(a, b, opaque) < 0 ?
(cmp(b, c, opaque) < 0 ? b : (cmp(a, c, opaque) < 0 ? c : a )) :
(cmp(b, c, opaque) > 0 ? b : (cmp(a, c, opaque) < 0 ? a : c ));
}
/* pointer based version with local stack and insertion sort threshhold */
void rqsort(void *base, size_t nmemb, size_t size, cmp_f cmp, void *opaque)
{
struct { uint8_t *base; size_t count; int depth; } stack[50], *sp = stack;
uint8_t *ptr, *pi, *pj, *plt, *pgt, *top, *m;
size_t m4, i, lt, gt, span, span2;
int c, depth;
exchange_f swap = exchange_func(base, size);
exchange_f swap_block = exchange_func(base, size | 128);
if (nmemb < 2 || size <= 0)
return;
sp->base = (uint8_t *)base;
sp->count = nmemb;
sp->depth = 0;
sp++;
while (sp > stack) {
sp--;
ptr = sp->base;
nmemb = sp->count;
depth = sp->depth;
while (nmemb > 6) {
if (++depth > 50) {
/* depth check to ensure worst case logarithmic time */
heapsortx(ptr, nmemb, size, cmp, opaque);
nmemb = 0;
break;
}
/* select median of 3 from 1/4, 1/2, 3/4 positions */
/* should use median of 5 or 9? */
m4 = (nmemb >> 2) * size;
m = med3(ptr + m4, ptr + 2 * m4, ptr + 3 * m4, cmp, opaque);
swap(ptr, m, size); /* move the pivot to the start or the array */
i = lt = 1;
pi = plt = ptr + size;
gt = nmemb;
pj = pgt = top = ptr + nmemb * size;
for (;;) {
while (pi < pj && (c = cmp(ptr, pi, opaque)) >= 0) {
if (c == 0) {
swap(plt, pi, size);
lt++;
plt += size;
}
i++;
pi += size;
}
while (pi < (pj -= size) && (c = cmp(ptr, pj, opaque)) <= 0) {
if (c == 0) {
gt--;
pgt -= size;
swap(pgt, pj, size);
}
}
if (pi >= pj)
break;
swap(pi, pj, size);
i++;
pi += size;
}
/* array has 4 parts:
* from 0 to lt excluded: elements identical to pivot
* from lt to pi excluded: elements smaller than pivot
* from pi to gt excluded: elements greater than pivot
* from gt to n excluded: elements identical to pivot
*/
/* move elements identical to pivot in the middle of the array: */
/* swap values in ranges [0..lt[ and [i-lt..i[
swapping the smallest span between lt and i-lt is sufficient
*/
span = plt - ptr;
span2 = pi - plt;
lt = i - lt;
if (span > span2)
span = span2;
swap_block(ptr, pi - span, span);
/* swap values in ranges [gt..top[ and [i..top-(top-gt)[
swapping the smallest span between top-gt and gt-i is sufficient
*/
span = top - pgt;
span2 = pgt - pi;
pgt = top - span2;
gt = nmemb - (gt - i);
if (span > span2)
span = span2;
swap_block(pi, top - span, span);
/* now array has 3 parts:
* from 0 to lt excluded: elements smaller than pivot
* from lt to gt excluded: elements identical to pivot
* from gt to n excluded: elements greater than pivot
*/
/* stack the larger segment and keep processing the smaller one
to minimize stack use for pathological distributions */
if (lt > nmemb - gt) {
sp->base = ptr;
sp->count = lt;
sp->depth = depth;
sp++;
ptr = pgt;
nmemb -= gt;
} else {
sp->base = pgt;
sp->count = nmemb - gt;
sp->depth = depth;
sp++;
nmemb = lt;
}
}
/* Use insertion sort for small fragments */
for (pi = ptr + size, top = ptr + nmemb * size; pi < top; pi += size) {
for (pj = pi; pj > ptr && cmp(pj - size, pj, opaque) > 0; pj -= size)
swap(pj, pj - size, size);
}
}
}
#endif
================================================
FILE: cutils.h
================================================
/*
* C utilities
*
* Copyright (c) 2017 Fabrice Bellard
* Copyright (c) 2018 Charlie Gordon
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in
* all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
* THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
* THE SOFTWARE.
*/
#ifndef CUTILS_H
#define CUTILS_H
#include <stdlib.h>
#include <inttypes.h>
/* set if CPU is big endian */
#undef WORDS_BIGENDIAN
#define likely(x) __builtin_expect(!!(x), 1)
#define unlikely(x) __builtin_expect(!!(x), 0)
#define force_inline inline __attribute__((always_inline))
#define no_inline __attribute__((noinline))
#define __maybe_unused __attribute__((unused))
#define xglue(x, y) x ## y
#define glue(x, y) xglue(x, y)
#define stringify(s) tostring(s)
#define tostring(s) #s
#ifndef offsetof
#define offsetof(type, field) ((size_t) &((type *)0)->field)
#endif
#ifndef countof
#define countof(x) (sizeof(x) / sizeof((x)[0]))
#endif
typedef int BOOL;
#ifndef FALSE
enum {
FALSE = 0,
TRUE = 1,
};
#endif
void pstrcpy(char *buf, int buf_size, const char *str);
char *pstrcat(char *buf, int buf_size, const char *s);
int strstart(const char *str, const char *val, const char **ptr);
int has_suffix(const char *str, const char *suffix);
static inline int max_int(int a, int b)
{
if (a > b)
return a;
else
return b;
}
static inline int min_int(int a, int b)
{
if (a < b)
return a;
else
return b;
}
static inline uint32_t max_uint32(uint32_t a, uint32_t b)
{
if (a > b)
return a;
else
return b;
}
static inline uint32_t min_uint32(uint32_t a, uint32_t b)
{
if (a < b)
return a;
else
return b;
}
static inline int64_t max_int64(int64_t a, int64_t b)
{
if (a > b)
return a;
else
return b;
}
static inline int64_t min_int64(int64_t a, int64_t b)
{
if (a < b)
return a;
else
return b;
}
/* WARNING: undefined if a = 0 */
static inline int clz32(unsigned int a)
{
return __builtin_clz(a);
}
/* WARNING: undefined if a = 0 */
static inline int clz64(uint64_t a)
{
return __builtin_clzll(a);
}
/* WARNING: undefined if a = 0 */
static inline int ctz32(unsigned int a)
{
return __builtin_ctz(a);
}
/* WARNING: undefined if a = 0 */
static inline int ctz64(uint64_t a)
{
return __builtin_ctzll(a);
}
struct __attribute__((packed)) packed_u64 {
uint64_t v;
};
struct __attribute__((packed)) packed_u32 {
uint32_t v;
};
struct __attribute__((packed)) packed_u16 {
uint16_t v;
};
static inline uint64_t get_u64(const uint8_t *tab)
{
return ((const struct packed_u64 *)tab)->v;
}
static inline int64_t get_i64(const uint8_t *tab)
{
return (int64_t)((const struct packed_u64 *)tab)->v;
}
static inline void put_u64(uint8_t *tab, uint64_t val)
{
((struct packed_u64 *)tab)->v = val;
}
static inline uint32_t get_u32(const uint8_t *tab)
{
return ((const struct packed_u32 *)tab)->v;
}
static inline int32_t get_i32(const uint8_t *tab)
{
return (int32_t)((const struct packed_u32 *)tab)->v;
}
static inline void put_u32(uint8_t *tab, uint32_t val)
{
((struct packed_u32 *)tab)->v = val;
}
static inline uint32_t get_u16(const uint8_t *tab)
{
return ((const struct packed_u16 *)tab)->v;
}
static inline int32_t get_i16(const uint8_t *tab)
{
return (int16_t)((const struct packed_u16 *)tab)->v;
}
static inline void put_u16(uint8_t *tab, uint16_t val)
{
((struct packed_u16 *)tab)->v = val;
}
static inline uint32_t get_u8(const uint8_t *tab)
{
return *tab;
}
static inline int32_t get_i8(const uint8_t *tab)
{
return (int8_t)*tab;
}
static inline void put_u8(uint8_t *tab, uint8_t val)
{
*tab = val;
}
static inline uint16_t bswap16(uint16_t x)
{
return (x >> 8) | (x << 8);
}
static inline uint32_t bswap32(uint32_t v)
{
return ((v & 0xff000000) >> 24) | ((v & 0x00ff0000) >> 8) |
((v & 0x0000ff00) << 8) | ((v & 0x000000ff) << 24);
}
static inline uint64_t bswap64(uint64_t v)
{
return ((v & ((uint64_t)0xff << (7 * 8))) >> (7 * 8)) |
((v & ((uint64_t)0xff << (6 * 8))) >> (5 * 8)) |
((v & ((uint64_t)0xff << (5 * 8))) >> (3 * 8)) |
((v & ((uint64_t)0xff << (4 * 8))) >> (1 * 8)) |
((v & ((uint64_t)0xff << (3 * 8))) << (1 * 8)) |
((v & ((uint64_t)0xff << (2 * 8))) << (3 * 8)) |
((v & ((uint64_t)0xff << (1 * 8))) << (5 * 8)) |
((v & ((uint64_t)0xff << (0 * 8))) << (7 * 8));
}
/* XXX: should take an extra argument to pass slack information to the caller */
typedef void *DynBufReallocFunc(void *opaque, void *ptr, size_t size);
typedef struct DynBuf {
uint8_t *buf;
size_t size;
size_t allocated_size;
BOOL error; /* true if a memory allocation error occurred */
DynBufReallocFunc *realloc_func;
void *opaque; /* for realloc_func */
} DynBuf;
void dbuf_init(DynBuf *s);
void dbuf_init2(DynBuf *s, void *opaque, DynBufReallocFunc *realloc_func);
int dbuf_realloc(DynBuf *s, size_t new_size);
int dbuf_write(DynBuf *s, size_t offset, const uint8_t *data, size_t len);
int dbuf_put(DynBuf *s, const uint8_t *data, size_t len);
int dbuf_put_self(DynBuf *s, size_t offset, size_t len);
int dbuf_putc(DynBuf *s, uint8_t c);
int dbuf_putstr(DynBuf *s, const char *str);
static inline int dbuf_put_u16(DynBuf *s, uint16_t val)
{
return dbuf_put(s, (uint8_t *)&val, 2);
}
static inline int dbuf_put_u32(DynBuf *s, uint32_t val)
{
return dbuf_put(s, (uint8_t *)&val, 4);
}
static inline int dbuf_put_u64(DynBuf *s, uint64_t val)
{
return dbuf_put(s, (uint8_t *)&val, 8);
}
int __attribute__((format(printf, 2, 3))) dbuf_printf(DynBuf *s,
const char *fmt, ...);
void dbuf_free(DynBuf *s);
static inline BOOL dbuf_error(DynBuf *s) {
return s->error;
}
static inline void dbuf_set_error(DynBuf *s)
{
s->error = TRUE;
}
#define UTF8_CHAR_LEN_MAX 6
int unicode_to_utf8(uint8_t *buf, unsigned int c);
int unicode_from_utf8(const uint8_t *p, int max_len, const uint8_t **pp);
static inline int from_hex(int c)
{
if (c >= '0' && c <= '9')
return c - '0';
else if (c >= 'A' && c <= 'F')
return c - 'A' + 10;
else if (c >= 'a' && c <= 'f')
return c - 'a' + 10;
else
return -1;
}
void rqsort(void *base, size_t nmemb, size_t size,
int (*cmp)(const void *, const void *, void *),
void *arg);
#endif /* CUTILS_H */
================================================
FILE: examples/main.go
================================================
package main
import (
"errors"
"flag"
"fmt"
"github.com/lithdew/quickjs"
"strings"
)
func check(err error) {
if err != nil {
var evalErr *quickjs.Error
if errors.As(err, &evalErr) {
fmt.Println(evalErr.Cause)
fmt.Println(evalErr.Stack)
}
panic(err)
}
}
func main() {
runtime := quickjs.NewRuntime()
defer runtime.Free()
context := runtime.NewContext()
defer context.Free()
globals := context.Globals()
// Test evaluating template strings.
result, err := context.Eval("`Hello world! 2 ** 8 = ${2 ** 8}.`")
check(err)
defer result.Free()
fmt.Println(result.String())
fmt.Println()
// Test evaluating numeric expressions.
result, err = context.Eval(`1 + 2 * 100 - 3 + Math.sin(10)`)
check(err)
defer result.Free()
fmt.Println(result.Int64())
fmt.Println()
// Test evaluating big integer expressions.
result, err = context.Eval(`128n ** 16n`)
check(err)
defer result.Free()
fmt.Println(result.BigInt())
fmt.Println()
// Test evaluating big decimal expressions.
result, err = context.Eval(`128l ** 12l`)
check(err)
defer result.Free()
fmt.Println(result.BigFloat())
fmt.Println()
// Test evaluating boolean expressions.
result, err = context.Eval(`false && true`)
check(err)
defer result.Free()
fmt.Println(result.Bool())
fmt.Println()
// Test setting and calling functions.
A := func(ctx *quickjs.Context, this quickjs.Value, args []quickjs.Value) quickjs.Value {
fmt.Println("A got called!")
return ctx.Null()
}
B := func(ctx *quickjs.Context, this quickjs.Value, args []quickjs.Value) quickjs.Value {
fmt.Println("B got called!")
return ctx.Null()
}
globals.Set("A", context.Function(A))
globals.Set("B", context.Function(B))
_, err = context.Eval(`for (let i = 0; i < 10; i++) { if (i % 2 === 0) A(); else B(); }`)
check(err)
fmt.Println()
// Test setting global variables.
_, err = context.Eval(`HELLO = "world"; TEST = false;`)
check(err)
names, err := globals.PropertyNames()
check(err)
fmt.Println("Globals:")
for _, name := range names {
val := globals.GetByAtom(name.Atom)
defer val.Free()
fmt.Printf("'%s': %s\n", name, val)
}
fmt.Println()
// Test evaluating arbitrary expressions from flag arguments.
flag.Parse()
if flag.NArg() == 0 {
return
}
result, err = context.Eval(strings.Join(flag.Args(), " "))
check(err)
defer result.Free()
if result.IsObject() {
names, err := result.PropertyNames()
check(err)
fmt.Println("Object:")
for _, name := range names {
val := result.GetByAtom(name.Atom)
defer val.Free()
fmt.Printf("'%s': %s\n", name, val)
}
} else {
fmt.Println(result.String())
}
}
================================================
FILE: go.mod
================================================
module github.com/lithdew/quickjs
go 1.14
require github.com/stretchr/testify v1.6.1
================================================
FILE: go.sum
================================================
github.com/davecgh/go-spew v1.1.0 h1:ZDRjVQ15GmhC3fiQ8ni8+OwkZQO4DARzQgrnXU1Liz8=
github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM=
github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4=
github.com/stretchr/objx v0.1.0 h1:4G4v2dO3VZwixGIRoQ5Lfboy6nUhCyYzaqnIAPPhYs4=
github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME=
github.com/stretchr/testify v1.6.1 h1:hDPOHmpOpP40lSULcqw7IrRb/u7w6RpDC9399XyoNd0=
github.com/stretchr/testify v1.6.1/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg=
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405 h1:yhCVgyC4o1eVCa2tZl7eS0r+SDo693bJlVdllGtEeKM=
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
gopkg.in/yaml.v3 v3.0.0-20200313102051-9f266ea9e77c h1:dUUwHk2QECo/6vqA44rthZ8ie2QXMNeKRTHCNY2nXvo=
gopkg.in/yaml.v3 v3.0.0-20200313102051-9f266ea9e77c/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM=
================================================
FILE: libbf.c
================================================
/*
* Tiny arbitrary precision floating point library
*
* Copyright (c) 2017-2020 Fabrice Bellard
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in
* all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
* THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
* THE SOFTWARE.
*/
#include <stdlib.h>
#include <stdio.h>
#include <inttypes.h>
#include <math.h>
#include <string.h>
#include <assert.h>
#ifdef __AVX2__
#include <immintrin.h>
#endif
#include "cutils.h"
#include "libbf.h"
/* enable it to check the multiplication result */
//#define USE_MUL_CHECK
/* enable it to use FFT/NTT multiplication */
#define USE_FFT_MUL
/* enable decimal floating point support */
#define USE_BF_DEC
//#define inline __attribute__((always_inline))
#ifdef __AVX2__
#define FFT_MUL_THRESHOLD 100 /* in limbs of the smallest factor */
#else
#define FFT_MUL_THRESHOLD 100 /* in limbs of the smallest factor */
#endif
/* XXX: adjust */
#define DIVNORM_LARGE_THRESHOLD 50
#define UDIV1NORM_THRESHOLD 3
#if LIMB_BITS == 64
#define FMT_LIMB1 "%" PRIx64
#define FMT_LIMB "%016" PRIx64
#define PRId_LIMB PRId64
#define PRIu_LIMB PRIu64
#else
#define FMT_LIMB1 "%x"
#define FMT_LIMB "%08x"
#define PRId_LIMB "d"
#define PRIu_LIMB "u"
#endif
typedef intptr_t mp_size_t;
typedef int bf_op2_func_t(bf_t *r, const bf_t *a, const bf_t *b, limb_t prec,
bf_flags_t flags);
#ifdef USE_FFT_MUL
#define FFT_MUL_R_OVERLAP_A (1 << 0)
#define FFT_MUL_R_OVERLAP_B (1 << 1)
#define FFT_MUL_R_NORESIZE (1 << 2)
static no_inline int fft_mul(bf_context_t *s,
bf_t *res, limb_t *a_tab, limb_t a_len,
limb_t *b_tab, limb_t b_len, int mul_flags);
static void fft_clear_cache(bf_context_t *s);
#endif
#ifdef USE_BF_DEC
static limb_t get_digit(const limb_t *tab, limb_t len, slimb_t pos);
#endif
/* could leading zeros */
static inline int clz(limb_t a)
{
if (a == 0) {
return LIMB_BITS;
} else {
#if LIMB_BITS == 64
return clz64(a);
#else
return clz32(a);
#endif
}
}
static inline int ctz(limb_t a)
{
if (a == 0) {
return LIMB_BITS;
} else {
#if LIMB_BITS == 64
return ctz64(a);
#else
return ctz32(a);
#endif
}
}
static inline int ceil_log2(limb_t a)
{
if (a <= 1)
return 0;
else
return LIMB_BITS - clz(a - 1);
}
/* b must be >= 1 */
static inline slimb_t ceil_div(slimb_t a, slimb_t b)
{
if (a >= 0)
return (a + b - 1) / b;
else
return a / b;
}
/* b must be >= 1 */
static inline slimb_t floor_div(slimb_t a, slimb_t b)
{
if (a >= 0) {
return a / b;
} else {
return (a - b + 1) / b;
}
}
/* return r = a modulo b (0 <= r <= b - 1. b must be >= 1 */
static inline limb_t smod(slimb_t a, slimb_t b)
{
a = a % (slimb_t)b;
if (a < 0)
a += b;
return a;
}
/* signed addition with saturation */
static inline slimb_t sat_add(slimb_t a, slimb_t b)
{
slimb_t r;
r = a + b;
/* overflow ? */
if (((a ^ r) & (b ^ r)) < 0)
r = (a >> (LIMB_BITS - 1)) ^ (((limb_t)1 << (LIMB_BITS - 1)) - 1);
return r;
}
#define malloc(s) malloc_is_forbidden(s)
#define free(p) free_is_forbidden(p)
#define realloc(p, s) realloc_is_forbidden(p, s)
void bf_context_init(bf_context_t *s, bf_realloc_func_t *realloc_func,
void *realloc_opaque)
{
memset(s, 0, sizeof(*s));
s->realloc_func = realloc_func;
s->realloc_opaque = realloc_opaque;
}
void bf_context_end(bf_context_t *s)
{
bf_clear_cache(s);
}
void bf_init(bf_context_t *s, bf_t *r)
{
r->ctx = s;
r->sign = 0;
r->expn = BF_EXP_ZERO;
r->len = 0;
r->tab = NULL;
}
/* return 0 if OK, -1 if alloc error */
int bf_resize(bf_t *r, limb_t len)
{
limb_t *tab;
if (len != r->len) {
tab = bf_realloc(r->ctx, r->tab, len * sizeof(limb_t));
if (!tab && len != 0)
return -1;
r->tab = tab;
r->len = len;
}
return 0;
}
/* return 0 or BF_ST_MEM_ERROR */
int bf_set_ui(bf_t *r, uint64_t a)
{
r->sign = 0;
if (a == 0) {
r->expn = BF_EXP_ZERO;
bf_resize(r, 0); /* cannot fail */
}
#if LIMB_BITS == 32
else if (a <= 0xffffffff)
#else
else
#endif
{
int shift;
if (bf_resize(r, 1))
goto fail;
shift = clz(a);
r->tab[0] = a << shift;
r->expn = LIMB_BITS - shift;
}
#if LIMB_BITS == 32
else {
uint32_t a1, a0;
int shift;
if (bf_resize(r, 2))
goto fail;
a0 = a;
a1 = a >> 32;
shift = clz(a1);
r->tab[0] = a0 << shift;
r->tab[1] = (a1 << shift) | (a0 >> (LIMB_BITS - shift));
r->expn = 2 * LIMB_BITS - shift;
}
#endif
return 0;
fail:
bf_set_nan(r);
return BF_ST_MEM_ERROR;
}
/* return 0 or BF_ST_MEM_ERROR */
int bf_set_si(bf_t *r, int64_t a)
{
int ret;
if (a < 0) {
ret = bf_set_ui(r, -a);
r->sign = 1;
} else {
ret = bf_set_ui(r, a);
}
return ret;
}
void bf_set_nan(bf_t *r)
{
bf_resize(r, 0); /* cannot fail */
r->expn = BF_EXP_NAN;
r->sign = 0;
}
void bf_set_zero(bf_t *r, int is_neg)
{
bf_resize(r, 0); /* cannot fail */
r->expn = BF_EXP_ZERO;
r->sign = is_neg;
}
void bf_set_inf(bf_t *r, int is_neg)
{
bf_resize(r, 0); /* cannot fail */
r->expn = BF_EXP_INF;
r->sign = is_neg;
}
/* return 0 or BF_ST_MEM_ERROR */
int bf_set(bf_t *r, const bf_t *a)
{
if (r == a)
return 0;
if (bf_resize(r, a->len)) {
bf_set_nan(r);
return BF_ST_MEM_ERROR;
}
r->sign = a->sign;
r->expn = a->expn;
memcpy(r->tab, a->tab, a->len * sizeof(limb_t));
return 0;
}
/* equivalent to bf_set(r, a); bf_delete(a) */
void bf_move(bf_t *r, bf_t *a)
{
bf_context_t *s = r->ctx;
if (r == a)
return;
bf_free(s, r->tab);
*r = *a;
}
static limb_t get_limbz(const bf_t *a, limb_t idx)
{
if (idx >= a->len)
return 0;
else
return a->tab[idx];
}
/* get LIMB_BITS at bit position 'pos' in tab */
static inline limb_t get_bits(const limb_t *tab, limb_t len, slimb_t pos)
{
limb_t i, a0, a1;
int p;
i = pos >> LIMB_LOG2_BITS;
p = pos & (LIMB_BITS - 1);
if (i < len)
a0 = tab[i];
else
a0 = 0;
if (p == 0) {
return a0;
} else {
i++;
if (i < len)
a1 = tab[i];
else
a1 = 0;
return (a0 >> p) | (a1 << (LIMB_BITS - p));
}
}
static inline limb_t get_bit(const limb_t *tab, limb_t len, slimb_t pos)
{
slimb_t i;
i = pos >> LIMB_LOG2_BITS;
if (i < 0 || i >= len)
return 0;
return (tab[i] >> (pos & (LIMB_BITS - 1))) & 1;
}
static inline limb_t limb_mask(int start, int last)
{
limb_t v;
int n;
n = last - start + 1;
if (n == LIMB_BITS)
v = -1;
else
v = (((limb_t)1 << n) - 1) << start;
return v;
}
static limb_t mp_scan_nz(const limb_t *tab, mp_size_t n)
{
mp_size_t i;
for(i = 0; i < n; i++) {
if (tab[i] != 0)
return 1;
}
return 0;
}
/* return != 0 if one bit between 0 and bit_pos inclusive is not zero. */
static inline limb_t scan_bit_nz(const bf_t *r, slimb_t bit_pos)
{
slimb_t pos;
limb_t v;
pos = bit_pos >> LIMB_LOG2_BITS;
if (pos < 0)
return 0;
v = r->tab[pos] & limb_mask(0, bit_pos & (LIMB_BITS - 1));
if (v != 0)
return 1;
pos--;
while (pos >= 0) {
if (r->tab[pos] != 0)
return 1;
pos--;
}
return 0;
}
/* return the addend for rounding. Note that prec can be <= 0 (for
BF_FLAG_RADPNT_PREC) */
static int bf_get_rnd_add(int *pret, const bf_t *r, limb_t l,
slimb_t prec, int rnd_mode)
{
int add_one, inexact;
limb_t bit1, bit0;
if (rnd_mode == BF_RNDF) {
bit0 = 1; /* faithful rounding does not honor the INEXACT flag */
} else {
/* starting limb for bit 'prec + 1' */
bit0 = scan_bit_nz(r, l * LIMB_BITS - 1 - bf_max(0, prec + 1));
}
/* get the bit at 'prec' */
bit1 = get_bit(r->tab, l, l * LIMB_BITS - 1 - prec);
inexact = (bit1 | bit0) != 0;
add_one = 0;
switch(rnd_mode) {
case BF_RNDZ:
break;
case BF_RNDN:
if (bit1) {
if (bit0) {
add_one = 1;
} else {
/* round to even */
add_one =
get_bit(r->tab, l, l * LIMB_BITS - 1 - (prec - 1));
}
}
break;
case BF_RNDD:
case BF_RNDU:
if (r->sign == (rnd_mode == BF_RNDD))
add_one = inexact;
break;
case BF_RNDA:
add_one = inexact;
break;
case BF_RNDNA:
case BF_RNDF:
add_one = bit1;
break;
default:
abort();
}
if (inexact)
*pret |= BF_ST_INEXACT;
return add_one;
}
static int bf_set_overflow(bf_t *r, int sign, limb_t prec, bf_flags_t flags)
{
slimb_t i, l, e_max;
int rnd_mode;
rnd_mode = flags & BF_RND_MASK;
if (prec == BF_PREC_INF ||
rnd_mode == BF_RNDN ||
rnd_mode == BF_RNDNA ||
rnd_mode == BF_RNDA ||
(rnd_mode == BF_RNDD && sign == 1) ||
(rnd_mode == BF_RNDU && sign == 0)) {
bf_set_inf(r, sign);
} else {
/* set to maximum finite number */
l = (prec + LIMB_BITS - 1) / LIMB_BITS;
if (bf_resize(r, l)) {
bf_set_nan(r);
return BF_ST_MEM_ERROR;
}
r->tab[0] = limb_mask((-prec) & (LIMB_BITS - 1),
LIMB_BITS - 1);
for(i = 1; i < l; i++)
r->tab[i] = (limb_t)-1;
e_max = (limb_t)1 << (bf_get_exp_bits(flags) - 1);
r->expn = e_max;
r->sign = sign;
}
return BF_ST_OVERFLOW | BF_ST_INEXACT;
}
/* round to prec1 bits assuming 'r' is non zero and finite. 'r' is
assumed to have length 'l' (1 <= l <= r->len). Note: 'prec1' can be
infinite (BF_PREC_INF). 'ret' is 0 or BF_ST_INEXACT if the result
is known to be inexact. Can fail with BF_ST_MEM_ERROR in case of
overflow not returning infinity. */
static int __bf_round(bf_t *r, limb_t prec1, bf_flags_t flags, limb_t l,
int ret)
{
limb_t v, a;
int shift, add_one, rnd_mode;
slimb_t i, bit_pos, pos, e_min, e_max, e_range, prec;
/* e_min and e_max are computed to match the IEEE 754 conventions */
e_range = (limb_t)1 << (bf_get_exp_bits(flags) - 1);
e_min = -e_range + 3;
e_max = e_range;
if (flags & BF_FLAG_RADPNT_PREC) {
/* 'prec' is the precision after the radix point */
if (prec1 != BF_PREC_INF)
prec = r->expn + prec1;
else
prec = prec1;
} else if (unlikely(r->expn < e_min) && (flags & BF_FLAG_SUBNORMAL)) {
/* restrict the precision in case of potentially subnormal
result */
assert(prec1 != BF_PREC_INF);
prec = prec1 - (e_min - r->expn);
} else {
prec = prec1;
}
/* round to prec bits */
rnd_mode = flags & BF_RND_MASK;
add_one = bf_get_rnd_add(&ret, r, l, prec, rnd_mode);
if (prec <= 0) {
if (add_one) {
bf_resize(r, 1); /* cannot fail */
r->tab[0] = (limb_t)1 << (LIMB_BITS - 1);
r->expn += 1 - prec;
ret |= BF_ST_UNDERFLOW | BF_ST_INEXACT;
return ret;
} else {
goto underflow;
}
} else if (add_one) {
limb_t carry;
/* add one starting at digit 'prec - 1' */
bit_pos = l * LIMB_BITS - 1 - (prec - 1);
pos = bit_pos >> LIMB_LOG2_BITS;
carry = (limb_t)1 << (bit_pos & (LIMB_BITS - 1));
for(i = pos; i < l; i++) {
v = r->tab[i] + carry;
carry = (v < carry);
r->tab[i] = v;
if (carry == 0)
break;
}
if (carry) {
/* shift right by one digit */
v = 1;
for(i = l - 1; i >= pos; i--) {
a = r->tab[i];
r->tab[i] = (a >> 1) | (v << (LIMB_BITS - 1));
v = a;
}
r->expn++;
}
}
/* check underflow */
if (unlikely(r->expn < e_min)) {
if (flags & BF_FLAG_SUBNORMAL) {
/* if inexact, also set the underflow flag */
if (ret & BF_ST_INEXACT)
ret |= BF_ST_UNDERFLOW;
} else {
underflow:
ret |= BF_ST_UNDERFLOW | BF_ST_INEXACT;
bf_set_zero(r, r->sign);
return ret;
}
}
/* check overflow */
if (unlikely(r->expn > e_max))
return bf_set_overflow(r, r->sign, prec1, flags);
/* keep the bits starting at 'prec - 1' */
bit_pos = l * LIMB_BITS - 1 - (prec - 1);
i = bit_pos >> LIMB_LOG2_BITS;
if (i >= 0) {
shift = bit_pos & (LIMB_BITS - 1);
if (shift != 0)
r->tab[i] &= limb_mask(shift, LIMB_BITS - 1);
} else {
i = 0;
}
/* remove trailing zeros */
while (r->tab[i] == 0)
i++;
if (i > 0) {
l -= i;
memmove(r->tab, r->tab + i, l * sizeof(limb_t));
}
bf_resize(r, l); /* cannot fail */
return ret;
}
/* 'r' must be a finite number. */
int bf_normalize_and_round(bf_t *r, limb_t prec1, bf_flags_t flags)
{
limb_t l, v, a;
int shift, ret;
slimb_t i;
// bf_print_str("bf_renorm", r);
l = r->len;
while (l > 0 && r->tab[l - 1] == 0)
l--;
if (l == 0) {
/* zero */
r->expn = BF_EXP_ZERO;
bf_resize(r, 0); /* cannot fail */
ret = 0;
} else {
r->expn -= (r->len - l) * LIMB_BITS;
/* shift to have the MSB set to '1' */
v = r->tab[l - 1];
shift = clz(v);
if (shift != 0) {
v = 0;
for(i = 0; i < l; i++) {
a = r->tab[i];
r->tab[i] = (a << shift) | (v >> (LIMB_BITS - shift));
v = a;
}
r->expn -= shift;
}
ret = __bf_round(r, prec1, flags, l, 0);
}
// bf_print_str("r_final", r);
return ret;
}
/* return true if rounding can be done at precision 'prec' assuming
the exact result r is such that |r-a| <= 2^(EXP(a)-k). */
/* XXX: check the case where the exponent would be incremented by the
rounding */
int bf_can_round(const bf_t *a, slimb_t prec, bf_rnd_t rnd_mode, slimb_t k)
{
BOOL is_rndn;
slimb_t bit_pos, n;
limb_t bit;
if (a->expn == BF_EXP_INF || a->expn == BF_EXP_NAN)
return FALSE;
if (rnd_mode == BF_RNDF) {
return (k >= (prec + 1));
}
if (a->expn == BF_EXP_ZERO)
return FALSE;
is_rndn = (rnd_mode == BF_RNDN || rnd_mode == BF_RNDNA);
if (k < (prec + 2))
return FALSE;
bit_pos = a->len * LIMB_BITS - 1 - prec;
n = k - prec;
/* bit pattern for RNDN or RNDNA: 0111.. or 1000...
for other rounding modes: 000... or 111...
*/
bit = get_bit(a->tab, a->len, bit_pos);
bit_pos--;
n--;
bit ^= is_rndn;
/* XXX: slow, but a few iterations on average */
while (n != 0) {
if (get_bit(a->tab, a->len, bit_pos) != bit)
return TRUE;
bit_pos--;
n--;
}
return FALSE;
}
/* Cannot fail with BF_ST_MEM_ERROR. */
int bf_round(bf_t *r, limb_t prec, bf_flags_t flags)
{
if (r->len == 0)
return 0;
return __bf_round(r, prec, flags, r->len, 0);
}
/* for debugging */
static __maybe_unused void dump_limbs(const char *str, const limb_t *tab, limb_t n)
{
limb_t i;
printf("%s: len=%" PRId_LIMB "\n", str, n);
for(i = 0; i < n; i++) {
printf("%" PRId_LIMB ": " FMT_LIMB "\n",
i, tab[i]);
}
}
void mp_print_str(const char *str, const limb_t *tab, limb_t n)
{
slimb_t i;
printf("%s= 0x", str);
for(i = n - 1; i >= 0; i--) {
if (i != (n - 1))
printf("_");
printf(FMT_LIMB, tab[i]);
}
printf("\n");
}
static __maybe_unused void mp_print_str_h(const char *str,
const limb_t *tab, limb_t n,
limb_t high)
{
slimb_t i;
printf("%s= 0x", str);
printf(FMT_LIMB, high);
for(i = n - 1; i >= 0; i--) {
printf("_");
printf(FMT_LIMB, tab[i]);
}
printf("\n");
}
/* for debugging */
void bf_print_str(const char *str, const bf_t *a)
{
slimb_t i;
printf("%s=", str);
if (a->expn == BF_EXP_NAN) {
printf("NaN");
} else {
if (a->sign)
putchar('-');
if (a->expn == BF_EXP_ZERO) {
putchar('0');
} else if (a->expn == BF_EXP_INF) {
printf("Inf");
} else {
printf("0x0.");
for(i = a->len - 1; i >= 0; i--)
printf(FMT_LIMB, a->tab[i]);
printf("p%" PRId_LIMB, a->expn);
}
}
printf("\n");
}
/* compare the absolute value of 'a' and 'b'. Return < 0 if a < b, 0
if a = b and > 0 otherwise. */
int bf_cmpu(const bf_t *a, const bf_t *b)
{
slimb_t i;
limb_t len, v1, v2;
if (a->expn != b->expn) {
if (a->expn < b->expn)
return -1;
else
return 1;
}
len = bf_max(a->len, b->len);
for(i = len - 1; i >= 0; i--) {
v1 = get_limbz(a, a->len - len + i);
v2 = get_limbz(b, b->len - len + i);
if (v1 != v2) {
if (v1 < v2)
return -1;
else
return 1;
}
}
return 0;
}
/* Full order: -0 < 0, NaN == NaN and NaN is larger than all other numbers */
int bf_cmp_full(const bf_t *a, const bf_t *b)
{
int res;
if (a->expn == BF_EXP_NAN || b->expn == BF_EXP_NAN) {
if (a->expn == b->expn)
res = 0;
else if (a->expn == BF_EXP_NAN)
res = 1;
else
res = -1;
} else if (a->sign != b->sign) {
res = 1 - 2 * a->sign;
} else {
res = bf_cmpu(a, b);
if (a->sign)
res = -res;
}
return res;
}
/* Standard floating point comparison: return 2 if one of the operands
is NaN (unordered) or -1, 0, 1 depending on the ordering assuming
-0 == +0 */
int bf_cmp(const bf_t *a, const bf_t *b)
{
int res;
if (a->expn == BF_EXP_NAN || b->expn == BF_EXP_NAN) {
res = 2;
} else if (a->sign != b->sign) {
if (a->expn == BF_EXP_ZERO && b->expn == BF_EXP_ZERO)
res = 0;
else
res = 1 - 2 * a->sign;
} else {
res = bf_cmpu(a, b);
if (a->sign)
res = -res;
}
return res;
}
/* Compute the number of bits 'n' matching the pattern:
a= X1000..0
b= X0111..1
When computing a-b, the result will have at least n leading zero
bits.
Precondition: a > b and a.expn - b.expn = 0 or 1
*/
static limb_t count_cancelled_bits(const bf_t *a, const bf_t *b)
{
slimb_t bit_offset, b_offset, n;
int p, p1;
limb_t v1, v2, mask;
bit_offset = a->len * LIMB_BITS - 1;
b_offset = (b->len - a->len) * LIMB_BITS - (LIMB_BITS - 1) +
a->expn - b->expn;
n = 0;
/* first search the equals bits */
for(;;) {
v1 = get_limbz(a, bit_offset >> LIMB_LOG2_BITS);
v2 = get_bits(b->tab, b->len, bit_offset + b_offset);
// printf("v1=" FMT_LIMB " v2=" FMT_LIMB "\n", v1, v2);
if (v1 != v2)
break;
n += LIMB_BITS;
bit_offset -= LIMB_BITS;
}
/* find the position of the first different bit */
p = clz(v1 ^ v2) + 1;
n += p;
/* then search for '0' in a and '1' in b */
p = LIMB_BITS - p;
if (p > 0) {
/* search in the trailing p bits of v1 and v2 */
mask = limb_mask(0, p - 1);
p1 = bf_min(clz(v1 & mask), clz((~v2) & mask)) - (LIMB_BITS - p);
n += p1;
if (p1 != p)
goto done;
}
bit_offset -= LIMB_BITS;
for(;;) {
v1 = get_limbz(a, bit_offset >> LIMB_LOG2_BITS);
v2 = get_bits(b->tab, b->len, bit_offset + b_offset);
// printf("v1=" FMT_LIMB " v2=" FMT_LIMB "\n", v1, v2);
if (v1 != 0 || v2 != -1) {
/* different: count the matching bits */
p1 = bf_min(clz(v1), clz(~v2));
n += p1;
break;
}
n += LIMB_BITS;
bit_offset -= LIMB_BITS;
}
done:
return n;
}
static int bf_add_internal(bf_t *r, const bf_t *a, const bf_t *b, limb_t prec,
bf_flags_t flags, int b_neg)
{
const bf_t *tmp;
int is_sub, ret, cmp_res, a_sign, b_sign;
a_sign = a->sign;
b_sign = b->sign ^ b_neg;
is_sub = a_sign ^ b_sign;
cmp_res = bf_cmpu(a, b);
if (cmp_res < 0) {
tmp = a;
a = b;
b = tmp;
a_sign = b_sign; /* b_sign is never used later */
}
/* abs(a) >= abs(b) */
if (cmp_res == 0 && is_sub && a->expn < BF_EXP_INF) {
/* zero result */
bf_set_zero(r, (flags & BF_RND_MASK) == BF_RNDD);
ret = 0;
} else if (a->len == 0 || b->len == 0) {
ret = 0;
if (a->expn >= BF_EXP_INF) {
if (a->expn == BF_EXP_NAN) {
/* at least one operand is NaN */
bf_set_nan(r);
} else if (b->expn == BF_EXP_INF && is_sub) {
/* infinities with different signs */
bf_set_nan(r);
ret = BF_ST_INVALID_OP;
} else {
bf_set_inf(r, a_sign);
}
} else {
/* at least one zero and not subtract */
bf_set(r, a);
r->sign = a_sign;
goto renorm;
}
} else {
slimb_t d, a_offset, b_bit_offset, i, cancelled_bits;
limb_t carry, v1, v2, u, r_len, carry1, precl, tot_len, z, sub_mask;
r->sign = a_sign;
r->expn = a->expn;
d = a->expn - b->expn;
/* must add more precision for the leading cancelled bits in
subtraction */
if (is_sub) {
if (d <= 1)
cancelled_bits = count_cancelled_bits(a, b);
else
cancelled_bits = 1;
} else {
cancelled_bits = 0;
}
/* add two extra bits for rounding */
precl = (cancelled_bits + prec + 2 + LIMB_BITS - 1) / LIMB_BITS;
tot_len = bf_max(a->len, b->len + (d + LIMB_BITS - 1) / LIMB_BITS);
r_len = bf_min(precl, tot_len);
if (bf_resize(r, r_len))
goto fail;
a_offset = a->len - r_len;
b_bit_offset = (b->len - r_len) * LIMB_BITS + d;
/* compute the bits before for the rounding */
carry = is_sub;
z = 0;
sub_mask = -is_sub;
i = r_len - tot_len;
while (i < 0) {
slimb_t ap, bp;
BOOL inflag;
ap = a_offset + i;
bp = b_bit_offset + i * LIMB_BITS;
inflag = FALSE;
if (ap >= 0 && ap < a->len) {
v1 = a->tab[ap];
inflag = TRUE;
} else {
v1 = 0;
}
if (bp + LIMB_BITS > 0 && bp < (slimb_t)(b->len * LIMB_BITS)) {
v2 = get_bits(b->tab, b->len, bp);
inflag = TRUE;
} else {
v2 = 0;
}
if (!inflag) {
/* outside 'a' and 'b': go directly to the next value
inside a or b so that the running time does not
depend on the exponent difference */
i = 0;
if (ap < 0)
i = bf_min(i, -a_offset);
/* b_bit_offset + i * LIMB_BITS + LIMB_BITS >= 1
equivalent to
i >= ceil(-b_bit_offset + 1 - LIMB_BITS) / LIMB_BITS)
*/
if (bp + LIMB_BITS <= 0)
i = bf_min(i, (-b_bit_offset) >> LIMB_LOG2_BITS);
} else {
i++;
}
v2 ^= sub_mask;
u = v1 + v2;
carry1 = u < v1;
u += carry;
carry = (u < carry) | carry1;
z |= u;
}
/* and the result */
for(i = 0; i < r_len; i++) {
v1 = get_limbz(a, a_offset + i);
v2 = get_bits(b->tab, b->len, b_bit_offset + i * LIMB_BITS);
v2 ^= sub_mask;
u = v1 + v2;
carry1 = u < v1;
u += carry;
carry = (u < carry) | carry1;
r->tab[i] = u;
}
/* set the extra bits for the rounding */
r->tab[0] |= (z != 0);
/* carry is only possible in add case */
if (!is_sub && carry) {
if (bf_resize(r, r_len + 1))
goto fail;
r->tab[r_len] = 1;
r->expn += LIMB_BITS;
}
renorm:
ret = bf_normalize_and_round(r, prec, flags);
}
return ret;
fail:
bf_set_nan(r);
return BF_ST_MEM_ERROR;
}
static int __bf_add(bf_t *r, const bf_t *a, const bf_t *b, limb_t prec,
bf_flags_t flags)
{
return bf_add_internal(r, a, b, prec, flags, 0);
}
static int __bf_sub(bf_t *r, const bf_t *a, const bf_t *b, limb_t prec,
bf_flags_t flags)
{
return bf_add_internal(r, a, b, prec, flags, 1);
}
limb_t mp_add(limb_t *res, const limb_t *op1, const limb_t *op2,
limb_t n, limb_t carry)
{
slimb_t i;
limb_t k, a, v, k1;
k = carry;
for(i=0;i<n;i++) {
v = op1[i];
a = v + op2[i];
k1 = a < v;
a = a + k;
k = (a < k) | k1;
res[i] = a;
}
return k;
}
limb_t mp_add_ui(limb_t *tab, limb_t b, size_t n)
{
size_t i;
limb_t k, a;
k=b;
for(i=0;i<n;i++) {
if (k == 0)
break;
a = tab[i] + k;
k = (a < k);
tab[i] = a;
}
return k;
}
limb_t mp_sub(limb_t *res, const limb_t *op1, const limb_t *op2,
mp_size_t n, limb_t carry)
{
int i;
limb_t k, a, v, k1;
k = carry;
for(i=0;i<n;i++) {
v = op1[i];
a = v - op2[i];
k1 = a > v;
v = a - k;
k = (v > a) | k1;
res[i] = v;
}
return k;
}
/* compute 0 - op2 */
static limb_t mp_neg(limb_t *res, const limb_t *op2, mp_size_t n, limb_t carry)
{
int i;
limb_t k, a, v, k1;
k = carry;
for(i=0;i<n;i++) {
v = 0;
a = v - op2[i];
k1 = a > v;
v = a - k;
k = (v > a) | k1;
res[i] = v;
}
return k;
}
limb_t mp_sub_ui(limb_t *tab, limb_t b, mp_size_t n)
{
mp_size_t i;
limb_t k, a, v;
k=b;
for(i=0;i<n;i++) {
v = tab[i];
a = v - k;
k = a > v;
tab[i] = a;
if (k == 0)
break;
}
return k;
}
/* r = (a + high*B^n) >> shift. Return the remainder r (0 <= r < 2^shift).
1 <= shift <= LIMB_BITS - 1 */
static limb_t mp_shr(limb_t *tab_r, const limb_t *tab, mp_size_t n,
int shift, limb_t high)
{
mp_size_t i;
limb_t l, a;
assert(shift >= 1 && shift < LIMB_BITS);
l = high;
for(i = n - 1; i >= 0; i--) {
a = tab[i];
tab_r[i] = (a >> shift) | (l << (LIMB_BITS - shift));
l = a;
}
return l & (((limb_t)1 << shift) - 1);
}
/* tabr[] = taba[] * b + l. Return the high carry */
static limb_t mp_mul1(limb_t *tabr, const limb_t *taba, limb_t n,
limb_t b, limb_t l)
{
limb_t i;
dlimb_t t;
for(i = 0; i < n; i++) {
t = (dlimb_t)taba[i] * (dlimb_t)b + l;
tabr[i] = t;
l = t >> LIMB_BITS;
}
return l;
}
/* tabr[] += taba[] * b, return the high word. */
static limb_t mp_add_mul1(limb_t *tabr, const limb_t *taba, limb_t n,
limb_t b)
{
limb_t i, l;
dlimb_t t;
l = 0;
for(i = 0; i < n; i++) {
t = (dlimb_t)taba[i] * (dlimb_t)b + l + tabr[i];
tabr[i] = t;
l = t >> LIMB_BITS;
}
return l;
}
/* size of the result : op1_size + op2_size. */
static void mp_mul_basecase(limb_t *result,
const limb_t *op1, limb_t op1_size,
const limb_t *op2, limb_t op2_size)
{
limb_t i, r;
result[op1_size] = mp_mul1(result, op1, op1_size, op2[0], 0);
for(i=1;i<op2_size;i++) {
r = mp_add_mul1(result + i, op1, op1_size, op2[i]);
result[i + op1_size] = r;
}
}
/* return 0 if OK, -1 if memory error */
/* XXX: change API so that result can be allocated */
int mp_mul(bf_context_t *s, limb_t *result,
const limb_t *op1, limb_t op1_size,
const limb_t *op2, limb_t op2_size)
{
#ifdef USE_FFT_MUL
if (unlikely(bf_min(op1_size, op2_size) >= FFT_MUL_THRESHOLD)) {
bf_t r_s, *r = &r_s;
r->tab = result;
/* XXX: optimize memory usage in API */
if (fft_mul(s, r, (limb_t *)op1, op1_size,
(limb_t *)op2, op2_size, FFT_MUL_R_NORESIZE))
return -1;
} else
#endif
{
mp_mul_basecase(result, op1, op1_size, op2, op2_size);
}
return 0;
}
/* tabr[] -= taba[] * b. Return the value to substract to the high
word. */
static limb_t mp_sub_mul1(limb_t *tabr, const limb_t *taba, limb_t n,
limb_t b)
{
limb_t i, l;
dlimb_t t;
l = 0;
for(i = 0; i < n; i++) {
t = tabr[i] - (dlimb_t)taba[i] * (dlimb_t)b - l;
tabr[i] = t;
l = -(t >> LIMB_BITS);
}
return l;
}
/* WARNING: d must be >= 2^(LIMB_BITS-1) */
static inline limb_t udiv1norm_init(limb_t d)
{
limb_t a0, a1;
a1 = -d - 1;
a0 = -1;
return (((dlimb_t)a1 << LIMB_BITS) | a0) / d;
}
/* return the quotient and the remainder in '*pr'of 'a1*2^LIMB_BITS+a0
/ d' with 0 <= a1 < d. */
static inline limb_t udiv1norm(limb_t *pr, limb_t a1, limb_t a0,
limb_t d, limb_t d_inv)
{
limb_t n1m, n_adj, q, r, ah;
dlimb_t a;
n1m = ((slimb_t)a0 >> (LIMB_BITS - 1));
n_adj = a0 + (n1m & d);
a = (dlimb_t)d_inv * (a1 - n1m) + n_adj;
q = (a >> LIMB_BITS) + a1;
/* compute a - q * r and update q so that the remainder is\
between 0 and d - 1 */
a = ((dlimb_t)a1 << LIMB_BITS) | a0;
a = a - (dlimb_t)q * d - d;
ah = a >> LIMB_BITS;
q += 1 + ah;
r = (limb_t)a + (ah & d);
*pr = r;
return q;
}
/* b must be >= 1 << (LIMB_BITS - 1) */
static limb_t mp_div1norm(limb_t *tabr, const limb_t *taba, limb_t n,
limb_t b, limb_t r)
{
slimb_t i;
if (n >= UDIV1NORM_THRESHOLD) {
limb_t b_inv;
b_inv = udiv1norm_init(b);
for(i = n - 1; i >= 0; i--) {
tabr[i] = udiv1norm(&r, r, taba[i], b, b_inv);
}
} else {
dlimb_t a1;
for(i = n - 1; i >= 0; i--) {
a1 = ((dlimb_t)r << LIMB_BITS) | taba[i];
tabr[i] = a1 / b;
r = a1 % b;
}
}
return r;
}
static int mp_divnorm_large(bf_context_t *s,
limb_t *tabq, limb_t *taba, limb_t na,
const limb_t *tabb, limb_t nb);
/* base case division: divides taba[0..na-1] by tabb[0..nb-1]. tabb[nb
- 1] must be >= 1 << (LIMB_BITS - 1). na - nb must be >= 0. 'taba'
is modified and contains the remainder (nb limbs). tabq[0..na-nb]
contains the quotient with tabq[na - nb] <= 1. */
static int mp_divnorm(bf_context_t *s, limb_t *tabq, limb_t *taba, limb_t na,
const limb_t *tabb, limb_t nb)
{
limb_t r, a, c, q, v, b1, b1_inv, n, dummy_r;
slimb_t i, j;
b1 = tabb[nb - 1];
if (nb == 1) {
taba[0] = mp_div1norm(tabq, taba, na, b1, 0);
return 0;
}
n = na - nb;
if (bf_min(n, nb) >= DIVNORM_LARGE_THRESHOLD) {
return mp_divnorm_large(s, tabq, taba, na, tabb, nb);
}
if (n >= UDIV1NORM_THRESHOLD)
b1_inv = udiv1norm_init(b1);
else
b1_inv = 0;
/* first iteration: the quotient is only 0 or 1 */
q = 1;
for(j = nb - 1; j >= 0; j--) {
if (taba[n + j] != tabb[j]) {
if (taba[n + j] < tabb[j])
q = 0;
break;
}
}
tabq[n] = q;
if (q) {
mp_sub(taba + n, taba + n, tabb, nb, 0);
}
for(i = n - 1; i >= 0; i--) {
if (unlikely(taba[i + nb] >= b1)) {
q = -1;
} else if (b1_inv) {
q = udiv1norm(&dummy_r, taba[i + nb], taba[i + nb - 1], b1, b1_inv);
} else {
dlimb_t al;
al = ((dlimb_t)taba[i + nb] << LIMB_BITS) | taba[i + nb - 1];
q = al / b1;
r = al % b1;
}
r = mp_sub_mul1(taba + i, tabb, nb, q);
v = taba[i + nb];
a = v - r;
c = (a > v);
taba[i + nb] = a;
if (c != 0) {
/* negative result */
for(;;) {
q--;
c = mp_add(taba + i, taba + i, tabb, nb, 0);
/* propagate carry and test if positive result */
if (c != 0) {
if (++taba[i + nb] == 0) {
break;
}
}
}
}
tabq[i] = q;
}
return 0;
}
/* compute r=B^(2*n)/a such as a*r < B^(2*n) < a*r + 2 with n >= 1. 'a'
has n limbs with a[n-1] >= B/2 and 'r' has n+1 limbs with r[n] = 1.
See Modern Computer Arithmetic by Richard P. Brent and Paul
Zimmermann, algorithm 3.5 */
int mp_recip(bf_context_t *s, limb_t *tabr, const limb_t *taba, limb_t n)
{
mp_size_t l, h, k, i;
limb_t *tabxh, *tabt, c, *tabu;
if (n <= 2) {
/* return ceil(B^(2*n)/a) - 1 */
/* XXX: could avoid allocation */
tabu = bf_malloc(s, sizeof(limb_t) * (2 * n + 1));
tabt = bf_malloc(s, sizeof(limb_t) * (n + 2));
if (!tabt || !tabu)
goto fail;
for(i = 0; i < 2 * n; i++)
tabu[i] = 0;
tabu[2 * n] = 1;
if (mp_divnorm(s, tabt, tabu, 2 * n + 1, taba, n))
goto fail;
for(i = 0; i < n + 1; i++)
tabr[i] = tabt[i];
if (mp_scan_nz(tabu, n) == 0) {
/* only happens for a=B^n/2 */
mp_sub_ui(tabr, 1, n + 1);
}
} else {
l = (n - 1) / 2;
h = n - l;
/* n=2p -> l=p-1, h = p + 1, k = p + 3
n=2p+1-> l=p, h = p + 1; k = p + 2
*/
tabt = bf_malloc(s, sizeof(limb_t) * (n + h + 1));
tabu = bf_malloc(s, sizeof(limb_t) * (n + 2 * h - l + 2));
if (!tabt || !tabu)
goto fail;
tabxh = tabr + l;
if (mp_recip(s, tabxh, taba + l, h))
goto fail;
if (mp_mul(s, tabt, taba, n, tabxh, h + 1)) /* n + h + 1 limbs */
goto fail;
while (tabt[n + h] != 0) {
mp_sub_ui(tabxh, 1, h + 1);
c = mp_sub(tabt, tabt, taba, n, 0);
mp_sub_ui(tabt + n, c, h + 1);
}
/* T = B^(n+h) - T */
mp_neg(tabt, tabt, n + h + 1, 0);
tabt[n + h]++;
if (mp_mul(s, tabu, tabt + l, n + h + 1 - l, tabxh, h + 1))
goto fail;
/* n + 2*h - l + 2 limbs */
k = 2 * h - l;
for(i = 0; i < l; i++)
tabr[i] = tabu[i + k];
mp_add(tabr + l, tabr + l, tabu + 2 * h, h, 0);
}
bf_free(s, tabt);
bf_free(s, tabu);
return 0;
fail:
bf_free(s, tabt);
bf_free(s, tabu);
return -1;
}
/* return -1, 0 or 1 */
static int mp_cmp(const limb_t *taba, const limb_t *tabb, mp_size_t n)
{
mp_size_t i;
for(i = n - 1; i >= 0; i--) {
if (taba[i] != tabb[i]) {
if (taba[i] < tabb[i])
return -1;
else
return 1;
}
}
return 0;
}
//#define DEBUG_DIVNORM_LARGE
//#define DEBUG_DIVNORM_LARGE2
/* subquadratic divnorm */
static int mp_divnorm_large(bf_context_t *s,
limb_t *tabq, limb_t *taba, limb_t na,
const limb_t *tabb, limb_t nb)
{
limb_t *tabb_inv, nq, *tabt, i, n;
nq = na - nb;
#ifdef DEBUG_DIVNORM_LARGE
printf("na=%d nb=%d nq=%d\n", (int)na, (int)nb, (int)nq);
mp_print_str("a", taba, na);
mp_print_str("b", tabb, nb);
#endif
assert(nq >= 1);
n = nq;
if (nq < nb)
n++;
tabb_inv = bf_malloc(s, sizeof(limb_t) * (n + 1));
tabt = bf_malloc(s, sizeof(limb_t) * 2 * (n + 1));
if (!tabb_inv || !tabt)
goto fail;
if (n >= nb) {
for(i = 0; i < n - nb; i++)
tabt[i] = 0;
for(i = 0; i < nb; i++)
tabt[i + n - nb] = tabb[i];
} else {
/* truncate B: need to increment it so that the approximate
inverse is smaller that the exact inverse */
for(i = 0; i < n; i++)
tabt[i] = tabb[i + nb - n];
if (mp_add_ui(tabt, 1, n)) {
/* tabt = B^n : tabb_inv = B^n */
memset(tabb_inv, 0, n * sizeof(limb_t));
tabb_inv[n] = 1;
goto recip_done;
}
}
if (mp_recip(s, tabb_inv, tabt, n))
goto fail;
recip_done:
/* Q=A*B^-1 */
if (mp_mul(s, tabt, tabb_inv, n + 1, taba + na - (n + 1), n + 1))
goto fail;
for(i = 0; i < nq + 1; i++)
tabq[i] = tabt[i + 2 * (n + 1) - (nq + 1)];
#ifdef DEBUG_DIVNORM_LARGE
mp_print_str("q", tabq, nq + 1);
#endif
bf_free(s, tabt);
bf_free(s, tabb_inv);
tabb_inv = NULL;
/* R=A-B*Q */
tabt = bf_malloc(s, sizeof(limb_t) * (na + 1));
if (!tabt)
goto fail;
if (mp_mul(s, tabt, tabq, nq + 1, tabb, nb))
goto fail;
/* we add one more limb for the result */
mp_sub(taba, taba, tabt, nb + 1, 0);
bf_free(s, tabt);
/* the approximated quotient is smaller than than the exact one,
hence we may have to increment it */
#ifdef DEBUG_DIVNORM_LARGE2
int cnt = 0;
static int cnt_max;
#endif
for(;;) {
if (taba[nb] == 0 && mp_cmp(taba, tabb, nb) < 0)
break;
taba[nb] -= mp_sub(taba, taba, tabb, nb, 0);
mp_add_ui(tabq, 1, nq + 1);
#ifdef DEBUG_DIVNORM_LARGE2
cnt++;
#endif
}
#ifdef DEBUG_DIVNORM_LARGE2
if (cnt > cnt_max) {
cnt_max = cnt;
printf("\ncnt=%d nq=%d nb=%d\n", cnt_max, (int)nq, (int)nb);
}
#endif
return 0;
fail:
bf_free(s, tabb_inv);
bf_free(s, tabt);
return -1;
}
int bf_mul(bf_t *r, const bf_t *a, const bf_t *b, limb_t prec,
bf_flags_t flags)
{
int ret, r_sign;
if (a->len < b->len) {
const bf_t *tmp = a;
a = b;
b = tmp;
}
r_sign = a->sign ^ b->sign;
/* here b->len <= a->len */
if (b->len == 0) {
if (a->expn == BF_EXP_NAN || b->expn == BF_EXP_NAN) {
bf_set_nan(r);
ret = 0;
} else if (a->expn == BF_EXP_INF || b->expn == BF_EXP_INF) {
if ((a->expn == BF_EXP_INF && b->expn == BF_EXP_ZERO) ||
(a->expn == BF_EXP_ZERO && b->expn == BF_EXP_INF)) {
bf_set_nan(r);
ret = BF_ST_INVALID_OP;
} else {
bf_set_inf(r, r_sign);
ret = 0;
}
} else {
bf_set_zero(r, r_sign);
ret = 0;
}
} else {
bf_t tmp, *r1 = NULL;
limb_t a_len, b_len, precl;
limb_t *a_tab, *b_tab;
a_len = a->len;
b_len = b->len;
if ((flags & BF_RND_MASK) == BF_RNDF) {
/* faithful rounding does not require using the full inputs */
precl = (prec + 2 + LIMB_BITS - 1) / LIMB_BITS;
a_len = bf_min(a_len, precl);
b_len = bf_min(b_len, precl);
}
a_tab = a->tab + a->len - a_len;
b_tab = b->tab + b->len - b_len;
#ifdef USE_FFT_MUL
if (b_len >= FFT_MUL_THRESHOLD) {
int mul_flags = 0;
if (r == a)
mul_flags |= FFT_MUL_R_OVERLAP_A;
if (r == b)
mul_flags |= FFT_MUL_R_OVERLAP_B;
if (fft_mul(r->ctx, r, a_tab, a_len, b_tab, b_len, mul_flags))
goto fail;
} else
#endif
{
if (r == a || r == b) {
bf_init(r->ctx, &tmp);
r1 = r;
r = &tmp;
}
if (bf_resize(r, a_len + b_len)) {
fail:
bf_set_nan(r);
ret = BF_ST_MEM_ERROR;
goto done;
}
mp_mul_basecase(r->tab, a_tab, a_len, b_tab, b_len);
}
r->sign = r_sign;
r->expn = a->expn + b->expn;
ret = bf_normalize_and_round(r, prec, flags);
done:
if (r == &tmp)
bf_move(r1, &tmp);
}
return ret;
}
/* multiply 'r' by 2^e */
int bf_mul_2exp(bf_t *r, slimb_t e, limb_t prec, bf_flags_t flags)
{
slimb_t e_max;
if (r->len == 0)
return 0;
e_max = ((limb_t)1 << BF_EXT_EXP_BITS_MAX) - 1;
e = bf_max(e, -e_max);
e = bf_min(e, e_max);
r->expn += e;
return __bf_round(r, prec, flags, r->len, 0);
}
/* Return e such as a=m*2^e with m odd integer. return 0 if a is zero,
Infinite or Nan. */
slimb_t bf_get_exp_min(const bf_t *a)
{
slimb_t i;
limb_t v;
int k;
for(i = 0; i < a->len; i++) {
v = a->tab[i];
if (v != 0) {
k = ctz(v);
return a->expn - (a->len - i) * LIMB_BITS + k;
}
}
return 0;
}
/* a and b must be finite numbers with a >= 0 and b > 0. 'q' is the
integer defined as floor(a/b) and r = a - q * b. */
static void bf_tdivremu(bf_t *q, bf_t *r,
const bf_t *a, const bf_t *b)
{
if (bf_cmpu(a, b) < 0) {
bf_set_ui(q, 0);
bf_set(r, a);
} else {
bf_div(q, a, b, bf_max(a->expn - b->expn + 1, 2), BF_RNDZ);
bf_rint(q, BF_RNDZ);
bf_mul(r, q, b, BF_PREC_INF, BF_RNDZ);
bf_sub(r, a, r, BF_PREC_INF, BF_RNDZ);
}
}
static int __bf_div(bf_t *r, const bf_t *a, const bf_t *b, limb_t prec,
bf_flags_t flags)
{
bf_context_t *s = r->ctx;
int ret, r_sign;
limb_t n, nb, precl;
r_sign = a->sign ^ b->sign;
if (a->expn >= BF_EXP_INF || b->expn >= BF_EXP_INF) {
if (a->expn == BF_EXP_NAN || b->expn == BF_EXP_NAN) {
bf_set_nan(r);
return 0;
} else if (a->expn == BF_EXP_INF && b->expn == BF_EXP_INF) {
bf_set_nan(r);
return BF_ST_INVALID_OP;
} else if (a->expn == BF_EXP_INF) {
bf_set_inf(r, r_sign);
return 0;
} else {
bf_set_zero(r, r_sign);
return 0;
}
} else if (a->expn == BF_EXP_ZERO) {
if (b->expn == BF_EXP_ZERO) {
bf_set_nan(r);
return BF_ST_INVALID_OP;
} else {
bf_set_zero(r, r_sign);
return 0;
}
} else if (b->expn == BF_EXP_ZERO) {
bf_set_inf(r, r_sign);
return BF_ST_DIVIDE_ZERO;
}
/* number of limbs of the quotient (2 extra bits for rounding) */
precl = (prec + 2 + LIMB_BITS - 1) / LIMB_BITS;
nb = b->len;
n = bf_max(a->len, precl);
{
limb_t *taba, na;
slimb_t d;
na = n + nb;
taba = bf_malloc(s, (na + 1) * sizeof(limb_t));
if (!taba)
goto fail;
d = na - a->len;
memset(taba, 0, d * sizeof(limb_t));
memcpy(taba + d, a->tab, a->len * sizeof(limb_t));
if (bf_resize(r, n + 1))
goto fail1;
if (mp_divnorm(s, r->tab, taba, na, b->tab, nb)) {
fail1:
bf_free(s, taba);
goto fail;
}
/* see if non zero remainder */
if (mp_scan_nz(taba, nb))
r->tab[0] |= 1;
bf_free(r->ctx, taba);
r->expn = a->expn - b->expn + LIMB_BITS;
r->sign = r_sign;
ret = bf_normalize_and_round(r, prec, flags);
}
return ret;
fail:
bf_set_nan(r);
return BF_ST_MEM_ERROR;
}
/* division and remainder.
rnd_mode is the rounding mode for the quotient. The additional
rounding mode BF_RND_EUCLIDIAN is supported.
'q' is an integer. 'r' is rounded with prec and flags (prec can be
BF_PREC_INF).
*/
int bf_divrem(bf_t *q, bf_t *r, const bf_t *a, const bf_t *b,
limb_t prec, bf_flags_t flags, int rnd_mode)
{
bf_t a1_s, *a1 = &a1_s;
bf_t b1_s, *b1 = &b1_s;
int q_sign, ret;
BOOL is_ceil, is_rndn;
assert(q != a && q != b);
assert(r != a && r != b);
assert(q != r);
if (a->len == 0 || b->len == 0) {
bf_set_zero(q, 0);
if (a->expn == BF_EXP_NAN || b->expn == BF_EXP_NAN) {
bf_set_nan(r);
return 0;
} else if (a->expn == BF_EXP_INF || b->expn == BF_EXP_ZERO) {
bf_set_nan(r);
return BF_ST_INVALID_OP;
} else {
bf_set(r, a);
return bf_round(r, prec, flags);
}
}
q_sign = a->sign ^ b->sign;
is_rndn = (rnd_mode == BF_RNDN || rnd_mode == BF_RNDNA);
switch(rnd_mode) {
default:
case BF_RNDZ:
case BF_RNDN:
case BF_RNDNA:
is_ceil = FALSE;
break;
case BF_RNDD:
is_ceil = q_sign;
break;
case BF_RNDU:
is_ceil = q_sign ^ 1;
break;
case BF_RNDA:
is_ceil = TRUE;
break;
case BF_DIVREM_EUCLIDIAN:
is_ceil = a->sign;
break;
}
a1->expn = a->expn;
a1->tab = a->tab;
a1->len = a->len;
a1->sign = 0;
b1->expn = b->expn;
b1->tab = b->tab;
b1->len = b->len;
b1->sign = 0;
/* XXX: could improve to avoid having a large 'q' */
bf_tdivremu(q, r, a1, b1);
if (bf_is_nan(q) || bf_is_nan(r))
goto fail;
if (r->len != 0) {
if (is_rndn) {
int res;
b1->expn--;
res = bf_cmpu(r, b1);
b1->expn++;
if (res > 0 ||
(res == 0 &&
(rnd_mode == BF_RNDNA ||
get_bit(q->tab, q->len, q->len * LIMB_BITS - q->expn)))) {
goto do_sub_r;
}
} else if (is_ceil) {
do_sub_r:
ret = bf_add_si(q, q, 1, BF_PREC_INF, BF_RNDZ);
ret |= bf_sub(r, r, b1, BF_PREC_INF, BF_RNDZ);
if (ret & BF_ST_MEM_ERROR)
goto fail;
}
}
r->sign ^= a->sign;
q->sign = q_sign;
return bf_round(r, prec, flags);
fail:
bf_set_nan(q);
bf_set_nan(r);
return BF_ST_MEM_ERROR;
}
int bf_rem(bf_t *r, const bf_t *a, const bf_t *b, limb_t prec,
bf_flags_t flags, int rnd_mode)
{
bf_t q_s, *q = &q_s;
int ret;
bf_init(r->ctx, q);
ret = bf_divrem(q, r, a, b, prec, flags, rnd_mode);
bf_delete(q);
return ret;
}
static inline int bf_get_limb(slimb_t *pres, const bf_t *a, int flags)
{
#if LIMB_BITS == 32
return bf_get_int32(pres, a, flags);
#else
return bf_get_int64(pres, a, flags);
#endif
}
int bf_remquo(slimb_t *pq, bf_t *r, const bf_t *a, const bf_t *b, limb_t prec,
bf_flags_t flags, int rnd_mode)
{
bf_t q_s, *q = &q_s;
int ret;
bf_init(r->ctx, q);
ret = bf_divrem(q, r, a, b, prec, flags, rnd_mode);
bf_get_limb(pq, q, BF_GET_INT_MOD);
bf_delete(q);
return ret;
}
static __maybe_unused inline limb_t mul_mod(limb_t a, limb_t b, limb_t m)
{
dlimb_t t;
t = (dlimb_t)a * (dlimb_t)b;
return t % m;
}
#if defined(USE_MUL_CHECK)
static limb_t mp_mod1(const limb_t *tab, limb_t n, limb_t m, limb_t r)
{
slimb_t i;
dlimb_t t;
for(i = n - 1; i >= 0; i--) {
t = ((dlimb_t)r << LIMB_BITS) | tab[i];
r = t % m;
}
return r;
}
#endif
static const uint16_t sqrt_table[192] = {
128,128,129,130,131,132,133,134,135,136,137,138,139,140,141,142,143,144,144,145,146,147,148,149,150,150,151,152,153,154,155,155,156,157,158,159,160,160,161,162,163,163,164,165,166,167,167,168,169,170,170,171,172,173,173,174,175,176,176,177,178,178,179,180,181,181,182,183,183,184,185,185,186,187,187,188,189,189,190,191,192,192,193,193,194,195,195,196,197,197,198,199,199,200,201,201,202,203,203,204,204,205,206,206,207,208,208,209,209,210,211,211,212,212,213,214,214,215,215,216,217,217,218,218,219,219,220,221,221,222,222,223,224,224,225,225,226,226,227,227,228,229,229,230,230,231,231,232,232,233,234,234,235,235,236,236,237,237,238,238,239,240,240,241,241,242,242,243,243,244,244,245,245,246,246,247,247,248,248,249,249,250,250,251,251,252,252,253,253,254,254,255,
};
/* a >= 2^(LIMB_BITS - 2). Return (s, r) with s=floor(sqrt(a)) and
r=a-s^2. 0 <= r <= 2 * s */
static limb_t mp_sqrtrem1(limb_t *pr, limb_t a)
{
limb_t s1, r1, s, r, q, u, num;
/* use a table for the 16 -> 8 bit sqrt */
s1 = sqrt_table[(a >> (LIMB_BITS - 8)) - 64];
r1 = (a >> (LIMB_BITS - 16)) - s1 * s1;
if (r1 > 2 * s1) {
r1 -= 2 * s1 + 1;
s1++;
}
/* one iteration to get a 32 -> 16 bit sqrt */
num = (r1 << 8) | ((a >> (LIMB_BITS - 32 + 8)) & 0xff);
q = num / (2 * s1); /* q <= 2^8 */
u = num % (2 * s1);
s = (s1 << 8) + q;
r = (u << 8) | ((a >> (LIMB_BITS - 32)) & 0xff);
r -= q * q;
if ((slimb_t)r < 0) {
s--;
r += 2 * s + 1;
}
#if LIMB_BITS == 64
s1 = s;
r1 = r;
/* one more iteration for 64 -> 32 bit sqrt */
num = (r1 << 16) | ((a >> (LIMB_BITS - 64 + 16)) & 0xffff);
q = num / (2 * s1); /* q <= 2^16 */
u = num % (2 * s1);
s = (s1 << 16) + q;
r = (u << 16) | ((a >> (LIMB_BITS - 64)) & 0xffff);
r -= q * q;
if ((slimb_t)r < 0) {
s--;
r += 2 * s + 1;
}
#endif
*pr = r;
return s;
}
/* return floor(sqrt(a)) */
limb_t bf_isqrt(limb_t a)
{
limb_t s, r;
int k;
if (a == 0)
return 0;
k = clz(a) & ~1;
s = mp_sqrtrem1(&r, a << k);
s >>= (k >> 1);
return s;
}
static limb_t mp_sqrtrem2(limb_t *tabs, limb_t *taba)
{
limb_t s1, r1, s, q, u, a0, a1;
dlimb_t r, num;
int l;
a0 = taba[0];
a1 = taba[1];
s1 = mp_sqrtrem1(&r1, a1);
l = LIMB_BITS / 2;
num = ((dlimb_t)r1 << l) | (a0 >> l);
q = num / (2 * s1);
u = num % (2 * s1);
s = (s1 << l) + q;
r = ((dlimb_t)u << l) | (a0 & (((limb_t)1 << l) - 1));
if (unlikely((q >> l) != 0))
r -= (dlimb_t)1 << LIMB_BITS; /* special case when q=2^l */
else
r -= q * q;
if ((slimb_t)(r >> LIMB_BITS) < 0) {
s--;
r += 2 * (dlimb_t)s + 1;
}
tabs[0] = s;
taba[0] = r;
return r >> LIMB_BITS;
}
//#define DEBUG_SQRTREM
/* tmp_buf must contain (n / 2 + 1 limbs). *prh contains the highest
limb of the remainder. */
static int mp_sqrtrem_rec(bf_context_t *s, limb_t *tabs, limb_t *taba, limb_t n,
limb_t *tmp_buf, limb_t *prh)
{
limb_t l, h, rh, ql, qh, c, i;
if (n == 1) {
*prh = mp_sqrtrem2(tabs, taba);
return 0;
}
#ifdef DEBUG_SQRTREM
mp_print_str("a", taba, 2 * n);
#endif
l = n / 2;
h = n - l;
if (mp_sqrtrem_rec(s, tabs + l, taba + 2 * l, h, tmp_buf, &qh))
return -1;
#ifdef DEBUG_SQRTREM
mp_print_str("s1", tabs + l, h);
mp_print_str_h("r1", taba + 2 * l, h, qh);
mp_print_str_h("r2", taba + l, n, qh);
#endif
/* the remainder is in taba + 2 * l. Its high bit is in qh */
if (qh) {
mp_sub(taba + 2 * l, taba + 2 * l, tabs + l, h, 0);
}
/* instead of dividing by 2*s, divide by s (which is normalized)
and update q and r */
if (mp_divnorm(s, tmp_buf, taba + l, n, tabs + l, h))
return -1;
qh += tmp_buf[l];
for(i = 0; i < l; i++)
tabs[i] = tmp_buf[i];
ql = mp_shr(tabs, tabs, l, 1, qh & 1);
qh = qh >> 1; /* 0 or 1 */
if (ql)
rh = mp_add(taba + l, taba + l, tabs + l, h, 0);
else
rh = 0;
#ifdef DEBUG_SQRTREM
mp_print_str_h("q", tabs, l, qh);
mp_print_str_h("u", taba + l, h, rh);
#endif
mp_add_ui(tabs + l, qh, h);
#ifdef DEBUG_SQRTREM
mp_print_str_h("s2", tabs, n, sh);
#endif
/* q = qh, tabs[l - 1 ... 0], r = taba[n - 1 ... l] */
/* subtract q^2. if qh = 1 then q = B^l, so we can take shortcuts */
if (qh) {
c = qh;
} else {
if (mp_mul(s, taba + n, tabs, l, tabs, l))
return -1;
c = mp_sub(taba, taba, taba + n, 2 * l, 0);
}
rh -= mp_sub_ui(taba + 2 * l, c, n - 2 * l);
if ((slimb_t)rh < 0) {
mp_sub_ui(tabs, 1, n);
rh += mp_add_mul1(taba, tabs, n, 2);
rh += mp_add_ui(taba, 1, n);
}
*prh = rh;
return 0;
}
/* 'taba' has 2*n limbs with n >= 1 and taba[2*n-1] >= 2 ^ (LIMB_BITS
- 2). Return (s, r) with s=floor(sqrt(a)) and r=a-s^2. 0 <= r <= 2
* s. tabs has n limbs. r is returned in the lower n limbs of
taba. Its r[n] is the returned value of the function. */
/* Algorithm from the article "Karatsuba Square Root" by Paul Zimmermann and
inspirated from its GMP implementation */
int mp_sqrtrem(bf_context_t *s, limb_t *tabs, limb_t *taba, limb_t n)
{
limb_t tmp_buf1[8];
limb_t *tmp_buf;
mp_size_t n2;
int ret;
n2 = n / 2 + 1;
if (n2 <= countof(tmp_buf1)) {
tmp_buf = tmp_buf1;
} else {
tmp_buf = bf_malloc(s, sizeof(limb_t) * n2);
if (!tmp_buf)
return -1;
}
ret = mp_sqrtrem_rec(s, tabs, taba, n, tmp_buf, taba + n);
if (tmp_buf != tmp_buf1)
bf_free(s, tmp_buf);
return ret;
}
/* Integer square root with remainder. 'a' must be an integer. r =
floor(sqrt(a)) and rem = a - r^2. BF_ST_INEXACT is set if the result
is inexact. 'rem' can be NULL if the remainder is not needed. */
int bf_sqrtrem(bf_t *r, bf_t *rem1, const bf_t *a)
{
int ret;
if (a->len == 0) {
if (a->expn == BF_EXP_NAN) {
bf_set_nan(r);
} else if (a->expn == BF_EXP_INF && a->sign) {
goto invalid_op;
} else {
bf_set(r, a);
}
if (rem1)
bf_set_ui(rem1, 0);
ret = 0;
} else if (a->sign) {
invalid_op:
bf_set_nan(r);
if (rem1)
bf_set_ui(rem1, 0);
ret = BF_ST_INVALID_OP;
} else {
bf_t rem_s, *rem;
bf_sqrt(r, a, (a->expn + 1) / 2, BF_RNDZ);
bf_rint(r, BF_RNDZ);
/* see if the result is exact by computing the remainder */
if (rem1) {
rem = rem1;
} else {
rem = &rem_s;
bf_init(r->ctx, rem);
}
/* XXX: could avoid recomputing the remainder */
bf_mul(rem, r, r, BF_PREC_INF, BF_RNDZ);
bf_neg(rem);
bf_add(rem, rem, a, BF_PREC_INF, BF_RNDZ);
if (bf_is_nan(rem)) {
ret = BF_ST_MEM_ERROR;
goto done;
}
if (rem->len != 0) {
ret = BF_ST_INEXACT;
} else {
ret = 0;
}
done:
if (!rem1)
bf_delete(rem);
}
return ret;
}
int bf_sqrt(bf_t *r, const bf_t *a, limb_t prec, bf_flags_t flags)
{
bf_context_t *s = a->ctx;
int ret;
assert(r != a);
if (a->len == 0) {
if (a->expn == BF_EXP_NAN) {
bf_set_nan(r);
} else if (a->expn == BF_EXP_INF && a->sign) {
goto invalid_op;
} else {
bf_set(r, a);
}
ret = 0;
} else if (a->sign) {
invalid_op:
bf_set_nan(r);
ret = BF_ST_INVALID_OP;
} else {
limb_t *a1;
slimb_t n, n1;
limb_t res;
/* convert the mantissa to an integer with at least 2 *
prec + 4 bits */
n = (2 * (prec + 2) + 2 * LIMB_BITS - 1) / (2 * LIMB_BITS);
if (bf_resize(r, n))
goto fail;
a1 = bf_malloc(s, sizeof(limb_t) * 2 * n);
if (!a1)
goto fail;
n1 = bf_min(2 * n, a->len);
memset(a1, 0, (2 * n - n1) * sizeof(limb_t));
memcpy(a1 + 2 * n - n1, a->tab + a->len - n1, n1 * sizeof(limb_t));
if (a->expn & 1) {
res = mp_shr(a1, a1, 2 * n, 1, 0);
} else {
res = 0;
}
if (mp_sqrtrem(s, r->tab, a1, n)) {
bf_free(s, a1);
goto fail;
}
if (!res) {
res = mp_scan_nz(a1, n + 1);
}
bf_free(s, a1);
if (!res) {
res = mp_scan_nz(a->tab, a->len - n1);
}
if (res != 0)
r->tab[0] |= 1;
r->sign = 0;
r->expn = (a->expn + 1) >> 1;
ret = bf_round(r, prec, flags);
}
return ret;
fail:
bf_set_nan(r);
return BF_ST_MEM_ERROR;
}
static no_inline int bf_op2(bf_t *r, const bf_t *a, const bf_t *b, limb_t prec,
bf_flags_t flags, bf_op2_func_t *func)
{
bf_t tmp;
int ret;
if (r == a || r == b) {
bf_init(r->ctx, &tmp);
ret = func(&tmp, a, b, prec, flags);
bf_move(r, &tmp);
} else {
ret = func(r, a, b, prec, flags);
}
return ret;
}
int bf_add(bf_t *r, const bf_t *a, const bf_t *b, limb_t prec,
bf_flags_t flags)
{
return bf_op2(r, a, b, prec, flags, __bf_add);
}
int bf_sub(bf_t *r, const bf_t *a, const bf_t *b, limb_t prec,
bf_flags_t flags)
{
return bf_op2(r, a, b, prec, flags, __bf_sub);
}
int bf_div(bf_t *r, const bf_t *a, const bf_t *b, limb_t prec,
bf_flags_t flags)
{
return bf_op2(r, a, b, prec, flags, __bf_div);
}
int bf_mul_ui(bf_t *r, const bf_t *a, uint64_t b1, limb_t prec,
bf_flags_t flags)
{
bf_t b;
int ret;
bf_init(r->ctx, &b);
ret = bf_set_ui(&b, b1);
ret |= bf_mul(r, a, &b, prec, flags);
bf_delete(&b);
return ret;
}
int bf_mul_si(bf_t *r, const bf_t *a, int64_t b1, limb_t prec,
bf_flags_t flags)
{
bf_t b;
int ret;
bf_init(r->ctx, &b);
ret = bf_set_si(&b, b1);
ret |= bf_mul(r, a, &b, prec, flags);
bf_delete(&b);
return ret;
}
int bf_add_si(bf_t *r, const bf_t *a, int64_t b1, limb_t prec,
bf_flags_t flags)
{
bf_t b;
int ret;
bf_init(r->ctx, &b);
ret = bf_set_si(&b, b1);
ret |= bf_add(r, a, &b, prec, flags);
bf_delete(&b);
return ret;
}
static int bf_pow_ui(bf_t *r, const bf_t *a, limb_t b, limb_t prec,
bf_flags_t flags)
{
int ret, n_bits, i;
assert(r != a);
if (b == 0)
return bf_set_ui(r, 1);
ret = bf_set(r, a);
n_bits = LIMB_BITS - clz(b);
for(i = n_bits - 2; i >= 0; i--) {
ret |= bf_mul(r, r, r, prec, flags);
if ((b >> i) & 1)
ret |= bf_mul(r, r, a, prec, flags);
}
return ret;
}
static int bf_pow_ui_ui(bf_t *r, limb_t a1, limb_t b,
limb_t prec, bf_flags_t flags)
{
bf_t a;
int ret;
if (a1 == 10 && b <= LIMB_DIGITS) {
/* use precomputed powers. We do not round at this point
because we expect the caller to do it */
ret = bf_set_ui(r, mp_pow_dec[b]);
} else {
bf_init(r->ctx, &a);
ret = bf_set_ui(&a, a1);
ret |= bf_pow_ui(r, &a, b, prec, flags);
bf_delete(&a);
}
return ret;
}
/* convert to integer (infinite precision) */
int bf_rint(bf_t *r, int rnd_mode)
{
return bf_round(r, 0, rnd_mode | BF_FLAG_RADPNT_PREC);
}
/* logical operations */
#define BF_LOGIC_OR 0
#define BF_LOGIC_XOR 1
#define BF_LOGIC_AND 2
static inline limb_t bf_logic_op1(limb_t a, limb_t b, int op)
{
switch(op) {
case BF_LOGIC_OR:
return a | b;
case BF_LOGIC_XOR:
return a ^ b;
default:
case BF_LOGIC_AND:
return a & b;
}
}
static int bf_logic_op(bf_t *r, const bf_t *a1, const bf_t *b1, int op)
{
bf_t b1_s, a1_s, *a, *b;
limb_t a_sign, b_sign, r_sign;
slimb_t l, i, a_bit_offset, b_bit_offset;
limb_t v1, v2, v1_mask, v2_mask, r_mask;
int ret;
assert(r != a1 && r != b1);
if (a1->expn <= 0)
a_sign = 0; /* minus zero is considered as positive */
else
a_sign = a1->sign;
if (b1->expn <= 0)
b_sign = 0; /* minus zero is considered as positive */
else
b_sign = b1->sign;
if (a_sign) {
a = &a1_s;
bf_init(r->ctx, a);
if (bf_add_si(a, a1, 1, BF_PREC_INF, BF_RNDZ)) {
b = NULL;
goto fail;
}
} else {
a = (bf_t *)a1;
}
if (b_sign) {
b = &b1_s;
bf_init(r->ctx, b);
if (bf_add_si(b, b1, 1, BF_PREC_INF, BF_RNDZ))
goto fail;
} else {
b = (bf_t *)b1;
}
r_sign = bf_logic_op1(a_sign, b_sign, op);
if (op == BF_LOGIC_AND && r_sign == 0) {
/* no need to compute extra zeros for and */
if (a_sign == 0 && b_sign == 0)
l = bf_min(a->expn, b->expn);
else if (a_sign == 0)
l = a->expn;
else
l = b->expn;
} else {
l = bf_max(a->expn, b->expn);
}
/* Note: a or b can be zero */
l = (bf_max(l, 1) + LIMB_BITS - 1) / LIMB_BITS;
if (bf_resize(r, l))
goto fail;
a_bit_offset = a->len * LIMB_BITS - a->expn;
b_bit_offset = b->len * LIMB_BITS - b->expn;
v1_mask = -a_sign;
v2_mask = -b_sign;
r_mask = -r_sign;
for(i = 0; i < l; i++) {
v1 = get_bits(a->tab, a->len, a_bit_offset + i * LIMB_BITS) ^ v1_mask;
v2 = get_bits(b->tab, b->len, b_bit_offset + i * LIMB_BITS) ^ v2_mask;
r->tab[i] = bf_logic_op1(v1, v2, op) ^ r_mask;
}
r->expn = l * LIMB_BITS;
r->sign = r_sign;
bf_normalize_and_round(r, BF_PREC_INF, BF_RNDZ); /* cannot fail */
if (r_sign) {
if (bf_add_si(r, r, -1, BF_PREC_INF, BF_RNDZ))
goto fail;
}
ret = 0;
done:
if (a == &a1_s)
bf_delete(a);
if (b == &b1_s)
bf_delete(b);
return ret;
fail:
bf_set_nan(r);
ret = BF_ST_MEM_ERROR;
goto done;
}
/* 'a' and 'b' must be integers. Return 0 or BF_ST_MEM_ERROR. */
int bf_logic_or(bf_t *r, const bf_t *a, const bf_t *b)
{
return bf_logic_op(r, a, b, BF_LOGIC_OR);
}
/* 'a' and 'b' must be integers. Return 0 or BF_ST_MEM_ERROR. */
int bf_logic_xor(bf_t *r, const bf_t *a, const bf_t *b)
{
return bf_logic_op(r, a, b, BF_LOGIC_XOR);
}
/* 'a' and 'b' must be integers. Return 0 or BF_ST_MEM_ERROR. */
int bf_logic_and(bf_t *r, const bf_t *a, const bf_t *b)
{
return bf_logic_op(r, a, b, BF_LOGIC_AND);
}
/* conversion between fixed size types */
typedef union {
double d;
uint64_t u;
} Float64Union;
int bf_get_float64(const bf_t *a, double *pres, bf_rnd_t rnd_mode)
{
Float64Union u;
int e, ret;
uint64_t m;
ret = 0;
if (a->expn == BF_EXP_NAN) {
u.u = 0x7ff8000000000000; /* quiet nan */
} else {
bf_t b_s, *b = &b_s;
bf_init(a->ctx, b);
bf_set(b, a);
if (bf_is_finite(b)) {
ret = bf_round(b, 53, rnd_mode | BF_FLAG_SUBNORMAL | bf_set_exp_bits(11));
}
if (b->expn == BF_EXP_INF) {
e = (1 << 11) - 1;
m = 0;
} else if (b->expn == BF_EXP_ZERO) {
e = 0;
m = 0;
} else {
e = b->expn + 1023 - 1;
#if LIMB_BITS == 32
if (b->len == 2) {
m = ((uint64_t)b->tab[1] << 32) | b->tab[0];
} else {
m = ((uint64_t)b->tab[0] << 32);
}
#else
m = b->tab[0];
#endif
if (e <= 0) {
/* subnormal */
m = m >> (12 - e);
e = 0;
} else {
m = (m << 1) >> 12;
}
}
u.u = m | ((uint64_t)e << 52) | ((uint64_t)b->sign << 63);
bf_delete(b);
}
*pres = u.d;
return ret;
}
int bf_set_float64(bf_t *a, double d)
{
Float64Union u;
uint64_t m;
int shift, e, sgn;
u.d = d;
sgn = u.u >> 63;
e = (u.u >> 52) & ((1 << 11) - 1);
m = u.u & (((uint64_t)1 << 52) - 1);
if (e == ((1 << 11) - 1)) {
if (m != 0) {
bf_set_nan(a);
} else {
bf_set_inf(a, sgn);
}
} else if (e == 0) {
if (m == 0) {
bf_set_zero(a, sgn);
} else {
/* subnormal number */
m <<= 12;
shift = clz64(m);
m <<= shift;
e = -shift;
goto norm;
}
} else {
m = (m << 11) | ((uint64_t)1 << 63);
norm:
a->expn = e - 1023 + 1;
#if LIMB_BITS == 32
if (bf_resize(a, 2))
goto fail;
a->tab[0] = m;
a->tab[1] = m >> 32;
#else
if (bf_resize(a, 1))
goto fail;
a->tab[0] = m;
#endif
a->sign = sgn;
}
return 0;
fail:
bf_set_nan(a);
return BF_ST_MEM_ERROR;
}
/* The rounding mode is always BF_RNDZ. Return BF_ST_INVALID_OP if there
is an overflow and 0 otherwise. */
int bf_get_int32(int *pres, const bf_t *a, int flags)
{
uint32_t v;
int ret;
if (a->expn >= BF_EXP_INF) {
ret = BF_ST_INVALID_OP;
if (flags & BF_GET_INT_MOD) {
v = 0;
} else if (a->expn == BF_EXP_INF) {
v = (uint32_t)INT32_MAX + a->sign;
} else {
v = INT32_MAX;
}
} else if (a->expn <= 0) {
v = 0;
ret = 0;
} else if (a->expn <= 31) {
v = a->tab[a->len - 1] >> (LIMB_BITS - a->expn);
if (a->sign)
v = -v;
ret = 0;
} else if (!(flags & BF_GET_INT_MOD)) {
ret = BF_ST_INVALID_OP;
if (a->sign) {
v = (uint32_t)INT32_MAX + 1;
if (a->expn == 32 &&
(a->tab[a->len - 1] >> (LIMB_BITS - 32)) == v) {
ret = 0;
}
} else {
v = INT32_MAX;
}
} else {
v = get_bits(a->tab, a->len, a->len * LIMB_BITS - a->expn);
if (a->sign)
v = -v;
ret = 0;
}
*pres = v;
return ret;
}
/* The rounding mode is always BF_RNDZ. Return BF_ST_INVALID_OP if there
is an overflow and 0 otherwise. */
int bf_get_int64(int64_t *pres, const bf_t *a, int flags)
{
uint64_t v;
int ret;
if (a->expn >= BF_EXP_INF) {
ret = BF_ST_INVALID_OP;
if (flags & BF_GET_INT_MOD) {
v = 0;
} else if (a->expn == BF_EXP_INF) {
v = (uint64_t)INT64_MAX + a->sign;
} else {
v = INT64_MAX;
}
} else if (a->expn <= 0) {
v = 0;
ret = 0;
} else if (a->expn <= 63) {
#if LIMB_BITS == 32
if (a->expn <= 32)
v = a->tab[a->len - 1] >> (LIMB_BITS - a->expn);
else
v = (((uint64_t)a->tab[a->len - 1] << 32) |
get_limbz(a, a->len - 2)) >> (64 - a->expn);
#else
v = a->tab[a->len - 1] >> (LIMB_BITS - a->expn);
#endif
if (a->sign)
v = -v;
ret = 0;
} else if (!(flags & BF_GET_INT_MOD)) {
ret = BF_ST_INVALID_OP;
if (a->sign) {
uint64_t v1;
v = (uint64_t)INT64_MAX + 1;
if (a->expn == 64) {
v1 = a->tab[a->len - 1];
#if LIMB_BITS == 32
v1 = (v1 << 32) | get_limbz(a, a->len - 2);
#endif
if (v1 == v)
ret = 0;
}
} else {
v = INT64_MAX;
}
} else {
slimb_t bit_pos = a->len * LIMB_BITS - a->expn;
v = get_bits(a->tab, a->len, bit_pos);
#if LIMB_BITS == 32
v |= (uint64_t)get_bits(a->tab, a->len, bit_pos + 32) << 32;
#endif
if (a->sign)
v = -v;
ret = 0;
}
*pres = v;
return ret;
}
/* The rounding mode is always BF_RNDZ. Return BF_ST_INVALID_OP if there
is an overflow and 0 otherwise. */
int bf_get_uint64(uint64_t *pres, const bf_t *a)
{
uint64_t v;
int ret;
if (a->expn == BF_EXP_NAN) {
goto overflow;
} else if (a->expn <= 0) {
v = 0;
ret = 0;
} else if (a->sign) {
v = 0;
ret = BF_ST_INVALID_OP;
} else if (a->expn <= 64) {
#if LIMB_BITS == 32
if (a->expn <= 32)
v = a->tab[a->len - 1] >> (LIMB_BITS - a->expn);
else
v = (((uint64_t)a->tab[a->len - 1] << 32) |
get_limbz(a, a->len - 2)) >> (64 - a->expn);
#else
v = a->tab[a->len - 1] >> (LIMB_BITS - a->expn);
#endif
ret = 0;
} else {
overflow:
v = UINT64_MAX;
ret = BF_ST_INVALID_OP;
}
*pres = v;
return ret;
}
/* base conversion from radix */
static const uint8_t digits_per_limb_table[BF_RADIX_MAX - 1] = {
#if LIMB_BITS == 32
32,20,16,13,12,11,10,10, 9, 9, 8, 8, 8, 8, 8, 7, 7, 7, 7, 7, 7, 7, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6,
#else
64,40,32,27,24,22,21,20,19,18,17,17,16,16,16,15,15,15,14,14,14,14,13,13,13,13,13,13,13,12,12,12,12,12,12,
#endif
};
static limb_t get_limb_radix(int radix)
{
int i, k;
limb_t radixl;
k = digits_per_limb_table[radix - 2];
radixl = radix;
for(i = 1; i < k; i++)
radixl *= radix;
return radixl;
}
/* return != 0 if error */
static int bf_integer_from_radix_rec(bf_t *r, const limb_t *tab,
limb_t n, int level, limb_t n0,
limb_t radix, bf_t *pow_tab)
{
int ret;
if (n == 1) {
ret = bf_set_ui(r, tab[0]);
} else {
bf_t T_s, *T = &T_s, *B;
limb_t n1, n2;
n2 = (((n0 * 2) >> (level + 1)) + 1) / 2;
n1 = n - n2;
// printf("level=%d n0=%ld n1=%ld n2=%ld\n", level, n0, n1, n2);
B = &pow_tab[level];
if (B->len == 0) {
ret = bf_pow_ui_ui(B, radix, n2, BF_PREC_INF, BF_RNDZ);
if (ret)
return ret;
}
ret = bf_integer_from_radix_rec(r, tab + n2, n1, level + 1, n0,
radix, pow_tab);
if (ret)
return ret;
ret = bf_mul(r, r, B, BF_PREC_INF, BF_RNDZ);
if (ret)
return ret;
bf_init(r->ctx, T);
ret = bf_integer_from_radix_rec(T, tab, n2, level + 1, n0,
radix, pow_tab);
if (!ret)
ret = bf_add(r, r, T, BF_PREC_INF, BF_RNDZ);
bf_delete(T);
}
return ret;
// bf_print_str(" r=", r);
}
/* return 0 if OK != 0 if memory error */
static int bf_integer_from_radix(bf_t *r, const limb_t *tab,
limb_t n, limb_t radix)
{
bf_context_t *s = r->ctx;
int pow_tab_len, i, ret;
limb_t radixl;
bf_t *pow_tab;
radixl = get_limb_radix(radix);
pow_tab_len = ceil_log2(n) + 2; /* XXX: check */
pow_tab = bf_malloc(s, sizeof(pow_tab[0]) * pow_tab_len);
if (!pow_tab)
return -1;
for(i = 0; i < pow_tab_len; i++)
bf_init(r->ctx, &pow_tab[i]);
ret = bf_integer_from_radix_rec(r, tab, n, 0, n, radixl, pow_tab);
for(i = 0; i < pow_tab_len; i++) {
bf_delete(&pow_tab[i]);
}
bf_free(s, pow_tab);
return ret;
}
/* compute and round T * radix^expn. */
int bf_mul_pow_radix(bf_t *r, const bf_t *T, limb_t radix,
slimb_t expn, limb_t prec, bf_flags_t flags)
{
int ret, expn_sign, overflow;
slimb_t e, extra_bits, prec1, ziv_extra_bits;
bf_t B_s, *B = &B_s;
if (T->len == 0) {
return bf_set(r, T);
} else if (expn == 0) {
ret = bf_set(r, T);
ret |= bf_round(r, prec, flags);
return ret;
}
e = expn;
expn_sign = 0;
if (e < 0) {
e = -e;
expn_sign = 1;
}
bf_init(r->ctx, B);
if (prec == BF_PREC_INF) {
/* infinite precision: only used if the result is known to be exact */
ret = bf_pow_ui_ui(B, radix, e, BF_PREC_INF, BF_RNDN);
if (expn_sign) {
ret |= bf_div(r, T, B, T->len * LIMB_BITS, BF_RNDN);
} else {
ret |= bf_mul(r, T, B, BF_PREC_INF, BF_RNDN);
}
} else {
ziv_extra_bits = 16;
for(;;) {
prec1 = prec + ziv_extra_bits;
/* XXX: correct overflow/underflow handling */
/* XXX: rigorous error analysis needed */
extra_bits = ceil_log2(e) * 2 + 1;
ret = bf_pow_ui_ui(B, radix, e, prec1 + extra_bits, BF_RNDN | BF_FLAG_EXT_EXP);
overflow = !bf_is_finite(B);
/* XXX: if bf_pow_ui_ui returns an exact result, can stop
after the next operation */
if (expn_sign)
ret |= bf_div(r, T, B, prec1 + extra_bits, BF_RNDN | BF_FLAG_EXT_EXP);
else
ret |= bf_mul(r, T, B, prec1 + extra_bits, BF_RNDN | BF_FLAG_EXT_EXP);
if (ret & BF_ST_MEM_ERROR)
break;
if ((ret & BF_ST_INEXACT) &&
!bf_can_round(r, prec, flags & BF_RND_MASK, prec1) &&
!overflow) {
/* and more precision and retry */
ziv_extra_bits = ziv_extra_bits + (ziv_extra_bits / 2);
} else {
/* XXX: need to use __bf_round() to pass the inexact
flag for the subnormal case */
ret = bf_round(r, prec, flags) | (ret & BF_ST_INEXACT);
break;
}
}
}
bf_delete(B);
return ret;
}
static inline int to_digit(int c)
{
if (c >= '0' && c <= '9')
return c - '0';
else if (c >= 'A' && c <= 'Z')
return c - 'A' + 10;
else if (c >= 'a' && c <= 'z')
return c - 'a' + 10;
else
return 36;
}
/* add a limb at 'pos' and decrement pos. new space is created if
needed. Return 0 if OK, -1 if memory error */
static int bf_add_limb(bf_t *a, slimb_t *ppos, limb_t v)
{
slimb_t pos;
pos = *ppos;
if (unlikely(pos < 0)) {
limb_t new_size, d, *new_tab;
new_size = bf_max(a->len + 1, a->len * 3 / 2);
new_tab = bf_realloc(a->ctx, a->tab, sizeof(limb_t) * new_size);
if (!new_tab)
return -1;
a->tab = new_tab;
d = new_size - a->len;
memmove(a->tab + d, a->tab, a->len * sizeof(limb_t));
a->len = new_size;
pos += d;
}
a->tab[pos--] = v;
*ppos = pos;
return 0;
}
static int bf_tolower(int c)
{
if (c >= 'A' && c <= 'Z')
c = c - 'A' + 'a';
return c;
}
static int strcasestart(const char *str, const char *val, const char **ptr)
{
const char *p, *q;
p = str;
q = val;
while (*q != '\0') {
if (bf_tolower(*p) != *q)
return 0;
p++;
q++;
}
if (ptr)
*ptr = p;
return 1;
}
static int bf_atof_internal(bf_t *r, slimb_t *pexponent,
const char *str, const char **pnext, int radix,
limb_t prec, bf_flags_t flags, BOOL is_dec)
{
const char *p, *p_start;
int is_neg, radix_bits, exp_is_neg, ret, digits_per_limb, shift;
limb_t cur_limb;
slimb_t pos, expn, int_len, digit_count;
BOOL has_decpt, is_bin_exp;
bf_t a_s, *a;
*pexponent = 0;
p = str;
if (!(flags & BF_ATOF_NO_NAN_INF) && radix <= 16 &&
strcasestart(p, "nan", &p)) {
bf_set_nan(r);
ret = 0;
goto done;
}
is_neg = 0;
if (p[0] == '+') {
p++;
p_start = p;
} else if (p[0] == '-') {
is_neg = 1;
p++;
p_start = p;
} else {
p_start = p;
}
if (p[0] == '0') {
if ((p[1] == 'x' || p[1] == 'X') &&
(radix == 0 || radix == 16) &&
!(flags & BF_ATOF_NO_HEX)) {
radix = 16;
p += 2;
} else if ((p[1] == 'o' || p[1] == 'O') &&
radix == 0 && (flags & BF_ATOF_BIN_OCT)) {
p += 2;
radix = 8;
} else if ((p[1] == 'b' || p[1] == 'B') &&
radix == 0 && (flags & BF_ATOF_BIN_OCT)) {
p += 2;
radix = 2;
} else {
goto no_prefix;
}
/* there must be a digit after the prefix */
if (to_digit((uint8_t)*p) >= radix) {
bf_set_nan(r);
ret = 0;
goto done;
}
no_prefix: ;
} else {
if (!(flags & BF_ATOF_NO_NAN_INF) && radix <= 16 &&
strcasestart(p, "inf", &p)) {
bf_set_inf(r, is_neg);
ret = 0;
goto done;
}
}
if (radix == 0)
radix = 10;
if (is_dec) {
assert(radix == 10);
radix_bits = 0;
a = r;
} else if ((radix & (radix - 1)) != 0) {
radix_bits = 0; /* base is not a power of two */
a = &a_s;
bf_init(r->ctx, a);
} else {
radix_bits = ceil_log2(radix);
a = r;
}
/* skip leading zeros */
/* XXX: could also skip zeros after the decimal point */
while (*p == '0')
p++;
if (radix_bits) {
shift = digits_per_limb = LIMB_BITS;
} else {
radix_bits = 0;
shift = digits_per_limb = digits_per_limb_table[radix - 2];
}
cur_limb = 0;
bf_resize(a, 1);
pos = 0;
has_decpt = FALSE;
int_len = digit_count = 0;
for(;;) {
limb_t c;
if (*p == '.' && (p > p_start || to_digit(p[1]) < radix)) {
if (has_decpt)
break;
has_decpt = TRUE;
int_len = digit_count;
p++;
}
c = to_digit(*p);
if (c >= radix)
break;
digit_count++;
p++;
if (radix_bits) {
shift -= radix_bits;
if (shift <= 0) {
cur_limb |= c >> (-shift);
if (bf_add_limb(a, &pos, cur_limb))
goto mem_error;
if (shift < 0)
cur_limb = c << (LIMB_BITS + shift);
else
cur_limb = 0;
shift += LIMB_BITS;
} else {
cur_limb |= c << shift;
}
} else {
cur_limb = cur_limb * radix + c;
shift--;
if (shift == 0) {
if (bf_add_limb(a, &pos, cur_limb))
goto mem_error;
shift = digits_per_limb;
cur_limb = 0;
}
}
}
if (!has_decpt)
int_len = digit_count;
/* add the last limb and pad with zeros */
if (shift != digits_per_limb) {
if (radix_bits == 0) {
while (shift != 0) {
cur_limb *= radix;
shift--;
}
}
if (bf_add_limb(a, &pos, cur_limb)) {
mem_error:
ret = BF_ST_MEM_ERROR;
if (!radix_bits)
bf_delete(a);
bf_set_nan(r);
goto done;
}
}
/* reset the next limbs to zero (we prefer to reallocate in the
renormalization) */
memset(a->tab, 0, (pos + 1) * sizeof(limb_t));
if (p == p_start) {
ret = 0;
if (!radix_bits)
bf_delete(a);
bf_set_nan(r);
goto done;
}
/* parse the exponent, if any */
expn = 0;
is_bin_exp = FALSE;
if (((radix == 10 && (*p == 'e' || *p == 'E')) ||
(radix != 10 && (*p == '@' ||
(radix_bits && (*p == 'p' || *p == 'P'))))) &&
p > p_start) {
is_bin_exp = (*p == 'p' || *p == 'P');
p++;
exp_is_neg = 0;
if (*p == '+') {
p++;
} else if (*p == '-') {
exp_is_neg = 1;
p++;
}
for(;;) {
int c;
c = to_digit(*p);
if (c >= 10)
break;
if (unlikely(expn > ((BF_RAW_EXP_MAX - 2 - 9) / 10))) {
/* exponent overflow */
if (exp_is_neg) {
bf_set_zero(r, is_neg);
ret = BF_ST_UNDERFLOW | BF_ST_INEXACT;
} else {
bf_set_inf(r, is_neg);
ret = BF_ST_OVERFLOW | BF_ST_INEXACT;
}
goto done;
}
p++;
expn = expn * 10 + c;
}
if (exp_is_neg)
expn = -expn;
}
if (is_dec) {
a->expn = expn + int_len;
a->sign = is_neg;
ret = bfdec_normalize_and_round((bfdec_t *)a, prec, flags);
} else if (radix_bits) {
/* XXX: may overflow */
if (!is_bin_exp)
expn *= radix_bits;
a->expn = expn + (int_len * radix_bits);
a->sign = is_neg;
ret = bf_normalize_and_round(a, prec, flags);
} else {
limb_t l;
pos++;
l = a->len - pos; /* number of limbs */
if (l == 0) {
bf_set_zero(r, is_neg);
ret = 0;
} else {
bf_t T_s, *T = &T_s;
expn -= l * digits_per_limb - int_len;
bf_init(r->ctx, T);
if (bf_integer_from_radix(T, a->tab + pos, l, radix)) {
bf_set_nan(r);
ret = BF_ST_MEM_ERROR;
} else {
T->sign = is_neg;
if (flags & BF_ATOF_EXPONENT) {
/* return the exponent */
*pexponent = expn;
ret = bf_set(r, T);
} else {
ret = bf_mul_pow_radix(r, T, radix, expn, prec, flags);
}
}
bf_delete(T);
}
bf_delete(a);
}
done:
if (pnext)
*pnext = p;
return ret;
}
/*
Return (status, n, exp). 'status' is the floating point status. 'n'
is the parsed number.
If (flags & BF_ATOF_EXPONENT) and if the radix is not a power of
two, the parsed number is equal to r *
(*pexponent)^radix. Otherwise *pexponent = 0.
*/
int bf_atof2(bf_t *r, slimb_t *pexponent,
const char *str, const char **pnext, int radix,
limb_t prec, bf_flags_t flags)
{
return bf_atof_internal(r, pexponent, str, pnext, radix, prec, flags,
FALSE);
}
int bf_atof(bf_t *r, const char *str, const char **pnext, int radix,
limb_t prec, bf_flags_t flags)
{
slimb_t dummy_exp;
return bf_atof_internal(r, &dummy_exp, str, pnext, radix, prec, flags, FALSE);
}
/* base conversion to radix */
#if LIMB_BITS == 64
#define RADIXL_10 UINT64_C(10000000000000000000)
#else
#define RADIXL_10 UINT64_C(1000000000)
#endif
static const uint32_t inv_log2_radix[BF_RADIX_MAX - 1][LIMB_BITS / 32 + 1] = {
#if LIMB_BITS == 32
{ 0x80000000, 0x00000000,},
{ 0x50c24e60, 0xd4d4f4a7,},
{ 0x40000000, 0x00000000,},
{ 0x372068d2, 0x0a1ee5ca,},
{ 0x3184648d, 0xb8153e7a,},
{ 0x2d983275, 0x9d5369c4,},
{ 0x2aaaaaaa, 0xaaaaaaab,},
{ 0x28612730, 0x6a6a7a54,},
{ 0x268826a1, 0x3ef3fde6,},
{ 0x25001383, 0xbac8a744,},
{ 0x23b46706, 0x82c0c709,},
{ 0x229729f1, 0xb2c83ded,},
{ 0x219e7ffd, 0xa5ad572b,},
{ 0x20c33b88, 0xda7c29ab,},
{ 0x20000000, 0x00000000,},
{ 0x1f50b57e, 0xac5884b3,},
{ 0x1eb22cc6, 0x8aa6e26f,},
{ 0x1e21e118, 0x0c5daab2,},
{ 0x1d9dcd21, 0x439834e4,},
{ 0x1d244c78, 0x367a0d65,},
{ 0x1cb40589, 0xac173e0c,},
{ 0x1c4bd95b, 0xa8d72b0d,},
{ 0x1bead768, 0x98f8ce4c,},
{ 0x1b903469, 0x050f72e5,},
{ 0x1b3b433f, 0x2eb06f15,},
{ 0x1aeb6f75, 0x9c46fc38,},
{ 0x1aa038eb, 0x0e3bfd17,},
{ 0x1a593062, 0xb38d8c56,},
{ 0x1a15f4c3, 0x2b95a2e6,},
{ 0x19d630dc, 0xcc7ddef9,},
{ 0x19999999, 0x9999999a,},
{ 0x195fec80, 0x8a609431,},
{ 0x1928ee7b, 0x0b4f22f9,},
{ 0x18f46acf, 0x8c06e318,},
{ 0x18c23246, 0xdc0a9f3d,},
#else
{ 0x80000000, 0x00000000, 0x00000000,},
{ 0x50c24e60, 0xd4d4f4a7, 0x021f57bc,},
{ 0x40000000, 0x00000000, 0x00000000,},
{ 0x372068d2, 0x0a1ee5ca, 0x19ea911b,},
{ 0x3184648d, 0xb8153e7a, 0x7fc2d2e1,},
{ 0x2d983275, 0x9d5369c4, 0x4dec1661,},
{ 0x2aaaaaaa, 0xaaaaaaaa, 0xaaaaaaab,},
{ 0x28612730, 0x6a6a7a53, 0x810fabde,},
{ 0x268826a1, 0x3ef3fde6, 0x23e2566b,},
{ 0x25001383, 0xbac8a744, 0x385a3349,},
{ 0x23b46706, 0x82c0c709, 0x3f891718,},
{ 0x229729f1, 0xb2c83ded, 0x15fba800,},
{ 0x219e7ffd, 0xa5ad572a, 0xe169744b,},
{ 0x20c33b88, 0xda7c29aa, 0x9bddee52,},
{ 0x20000000, 0x00000000, 0x00000000,},
{ 0x1f50b57e, 0xac5884b3, 0x70e28eee,},
{ 0x1eb22cc6, 0x8aa6e26f, 0x06d1a2a2,},
{ 0x1e21e118, 0x0c5daab1, 0x81b4f4bf,},
{ 0x1d9dcd21, 0x439834e3, 0x81667575,},
{ 0x1d244c78, 0x367a0d64, 0xc8204d6d,},
{ 0x1cb40589, 0xac173e0c, 0x3b7b16ba,},
{ 0x1c4bd95b, 0xa8d72b0d, 0x5879f25a,},
{ 0x1bead768, 0x98f8ce4c, 0x66cc2858,},
{ 0x1b903469, 0x050f72e5, 0x0cf5488e,},
{ 0x1b3b433f, 0x2eb06f14, 0x8c89719c,},
{ 0x1aeb6f75, 0x9c46fc37, 0xab5fc7e9,},
{ 0x1aa038eb, 0x0e3bfd17, 0x1bd62080,},
{ 0x1a593062, 0xb38d8c56, 0x7998ab45,},
{ 0x1a15f4c3, 0x2b95a2e6, 0x46aed6a0,},
{ 0x19d630dc, 0xcc7ddef9, 0x5aadd61b,},
{ 0x19999999, 0x99999999, 0x9999999a,},
{ 0x195fec80, 0x8a609430, 0xe1106014,},
{ 0x1928ee7b, 0x0b4f22f9, 0x5f69791d,},
{ 0x18f46acf, 0x8c06e318, 0x4d2aeb2c,},
{ 0x18c23246, 0xdc0a9f3d, 0x3fe16970,},
#endif
};
static const limb_t log2_radix[BF_RADIX_MAX - 1] = {
#if LIMB_BITS == 32
0x20000000,
0x32b80347,
0x40000000,
0x4a4d3c26,
0x52b80347,
0x59d5d9fd,
0x60000000,
0x6570068e,
0x6a4d3c26,
0x6eb3a9f0,
0x72b80347,
0x766a008e,
0x79d5d9fd,
0x7d053f6d,
0x80000000,
0x82cc7edf,
0x8570068e,
0x87ef05ae,
0x8a4d3c26,
0x8c8ddd45,
0x8eb3a9f0,
0x90c10501,
0x92b80347,
0x949a784c,
0x966a008e,
0x982809d6,
0x99d5d9fd,
0x9b74948f,
0x9d053f6d,
0x9e88c6b3,
0xa0000000,
0xa16bad37,
0xa2cc7edf,
0xa4231623,
0xa570068e,
#else
0x2000000000000000,
0x32b803473f7ad0f4,
0x4000000000000000,
0x4a4d3c25e68dc57f,
0x52b803473f7ad0f4,
0x59d5d9fd5010b366,
0x6000000000000000,
0x6570068e7ef5a1e8,
0x6a4d3c25e68dc57f,
0x6eb3a9f01975077f,
0x72b803473f7ad0f4,
0x766a008e4788cbcd,
0x79d5d9fd5010b366,
0x7d053f6d26089673,
0x8000000000000000,
0x82cc7edf592262d0,
0x8570068e7ef5a1e8,
0x87ef05ae409a0289,
0x8a4d3c25e68dc57f,
0x8c8ddd448f8b845a,
0x8eb3a9f01975077f,
0x90c10500d63aa659,
0x92b803473f7ad0f4,
0x949a784bcd1b8afe,
0x966a008e4788cbcd,
0x982809d5be7072dc,
0x99d5d9fd5010b366,
0x9b74948f5532da4b,
0x9d053f6d26089673,
0x9e88c6b3626a72aa,
0xa000000000000000,
0xa16bad3758efd873,
0xa2cc7edf592262d0,
0xa4231623369e78e6,
0xa570068e7ef5a1e8,
#endif
};
/* compute floor(a*b) or ceil(a*b) with b = log2(radix) or
b=1/log2(radix). For is_inv = 0, strict accuracy is not guaranteed
when radix is not a power of two. */
slimb_t bf_mul_log2_radix(slimb_t a1, unsigned int radix, int is_inv,
int is_ceil1)
{
int is_neg;
limb_t a;
BOOL is_ceil;
is_ceil = is_ceil1;
a = a1;
if (a1 < 0) {
a = -a;
is_neg = 1;
} else {
is_neg = 0;
}
is_ceil ^= is_neg;
if ((radix & (radix - 1)) == 0) {
int radix_bits;
/* radix is a power of two */
radix_bits = ceil_log2(radix);
if (is_inv) {
if (is_ceil)
a += radix_bits - 1;
a = a / radix_bits;
} else {
a = a * radix_bits;
}
} else {
const uint32_t *tab;
limb_t b0, b1;
dlimb_t t;
if (is_inv) {
tab = inv_log2_radix[radix - 2];
#if LIMB_BITS == 32
b1 = tab[0];
b0 = tab[1];
#else
b1 = ((limb_t)tab[0] << 32) | tab[1];
b0 = (limb_t)tab[2] << 32;
#endif
t = (dlimb_t)b0 * (dlimb_t)a;
t = (dlimb_t)b1 * (dlimb_t)a + (t >> LIMB_BITS);
a = t >> (LIMB_BITS - 1);
} else {
b0 = log2_radix[radix - 2];
t = (dlimb_t)b0 * (dlimb_t)a;
a = t >> (LIMB_BITS - 3);
}
/* a = floor(result) and 'result' cannot be an integer */
a += is_ceil;
}
if (is_neg)
a = -a;
return a;
}
/* 'n' is the number of output limbs */
static int bf_integer_to_radix_rec(bf_t *pow_tab,
limb_t *out, const bf_t *a, limb_t n,
int level, limb_t n0, limb_t radixl,
unsigned int radixl_bits)
{
limb_t n1, n2, q_prec;
int ret;
assert(n >= 1);
if (n == 1) {
out[0] = get_bits(a->tab, a->len, a->len * LIMB_BITS - a->expn);
} else if (n == 2) {
dlimb_t t;
slimb_t pos;
pos = a->len * LIMB_BITS - a->expn;
t = ((dlimb_t)get_bits(a->tab, a->len, pos + LIMB_BITS) << LIMB_BITS) |
get_bits(a->tab, a->len, pos);
if (likely(radixl == RADIXL_10)) {
/* use division by a constant when possible */
out[0] = t % RADIXL_10;
out[1] = t / RADIXL_10;
} else {
out[0] = t % radixl;
out[1] = t / radixl;
}
} else {
bf_t Q, R, *B, *B_inv;
int q_add;
bf_init(a->ctx, &Q);
bf_init(a->ctx, &R);
n2 = (((n0 * 2) >> (level + 1)) + 1) / 2;
n1 = n - n2;
B = &pow_tab[2 * level];
B_inv = &pow_tab[2 * level + 1];
ret = 0;
if (B->len == 0) {
/* compute BASE^n2 */
ret |= bf_pow_ui_ui(B, radixl, n2, BF_PREC_INF, BF_RNDZ);
/* we use enough bits for the maximum possible 'n1' value,
i.e. n2 + 1 */
ret |= bf_set_ui(&R, 1);
ret |= bf_div(B_inv, &R, B, (n2 + 1) * radixl_bits + 2, BF_RNDN);
}
// printf("%d: n1=% " PRId64 " n2=%" PRId64 "\n", level, n1, n2);
q_prec = n1 * radixl_bits;
ret |= bf_mul(&Q, a, B_inv, q_prec, BF_RNDN);
ret |= bf_rint(&Q, BF_RNDZ);
ret |= bf_mul(&R, &Q, B, BF_PREC_INF, BF_RNDZ);
ret |= bf_sub(&R, a, &R, BF_PREC_INF, BF_RNDZ);
if (ret & BF_ST_MEM_ERROR)
goto fail;
/* adjust if necessary */
q_add = 0;
while (R.sign && R.len != 0) {
if (bf_add(&R, &R, B, BF_PREC_INF, BF_RNDZ))
goto fail;
q_add--;
}
while (bf_cmpu(&R, B) >= 0) {
if (bf_sub(&R, &R, B, BF_PREC_INF, BF_RNDZ))
goto fail;
q_add++;
}
if (q_add != 0) {
if (bf_add_si(&Q, &Q, q_add, BF_PREC_INF, BF_RNDZ))
goto fail;
}
if (bf_integer_to_radix_rec(pow_tab, out + n2, &Q, n1, level + 1, n0,
radixl, radixl_bits))
goto fail;
if (bf_integer_to_radix_rec(pow_tab, out, &R, n2, level + 1, n0,
radixl, radixl_bits)) {
fail:
bf_delete(&Q);
bf_delete(&R);
return -1;
}
bf_delete(&Q);
bf_delete(&R);
}
return 0;
}
/* return 0 if OK != 0 if memory error */
static int bf_integer_to_radix(bf_t *r, const bf_t *a, limb_t radixl)
{
bf_context_t *s = r->ctx;
limb_t r_len;
bf_t *pow_tab;
int i, pow_tab_len, ret;
r_len = r->len;
pow_tab_len = (ceil_log2(r_len) + 2) * 2; /* XXX: check */
pow_tab = bf_malloc(s, sizeof(pow_tab[0]) * pow_tab_len);
if (!pow_tab)
return -1;
for(i = 0; i < pow_tab_len; i++)
bf_init(r->ctx, &pow_tab[i]);
ret = bf_integer_to_radix_rec(pow_tab, r->tab, a, r_len, 0, r_len, radixl,
ceil_log2(radixl));
for(i = 0; i < pow_tab_len; i++) {
bf_delete(&pow_tab[i]);
}
bf_free(s, pow_tab);
return ret;
}
/* a must be >= 0. 'P' is the wanted number of digits in radix
'radix'. 'r' is the mantissa represented as an integer. *pE
contains the exponent. Return != 0 if memory error. */
static int bf_convert_to_radix(bf_t *r, slimb_t *pE,
const bf_t *a, int radix,
limb_t P, bf_rnd_t rnd_mode,
BOOL is_fixed_exponent)
{
slimb_t E, e, prec, extra_bits, ziv_extra_bits, prec0;
bf_t B_s, *B = &B_s;
int e_sign, ret, res;
if (a->len == 0) {
/* zero case */
*pE = 0;
return bf_set(r, a);
}
if (is_fixed_exponent) {
E = *pE;
} else {
/* compute the new exponent */
E = 1 + bf_mul_log2_radix(a->expn - 1, radix, TRUE, FALSE);
}
// bf_print_str("a", a);
// printf("E=%ld P=%ld radix=%d\n", E, P, radix);
for(;;) {
e = P - E;
e_sign = 0;
if (e < 0) {
e = -e;
e_sign = 1;
}
/* Note: precision for log2(radix) is not critical here */
prec0 = bf_mul_log2_radix(P, radix, FALSE, TRUE);
ziv_extra_bits = 16;
for(;;) {
prec = prec0 + ziv_extra_bits;
/* XXX: rigorous error analysis needed */
extra_bits = ceil_log2(e) * 2 + 1;
ret = bf_pow_ui_ui(r, radix, e, prec + extra_bits,
BF_RNDN | BF_FLAG_EXT_EXP);
if (!e_sign)
ret |= bf_mul(r, r, a, prec + extra_bits,
BF_RNDN | BF_FLAG_EXT_EXP);
else
ret |= bf_div(r, a, r, prec + extra_bits,
BF_RNDN | BF_FLAG_EXT_EXP);
if (ret & BF_ST_MEM_ERROR)
return BF_ST_MEM_ERROR;
/* if the result is not exact, check that it can be safely
rounded to an integer */
if ((ret & BF_ST_INEXACT) &&
!bf_can_round(r, r->expn, rnd_mode, prec)) {
/* and more precision and retry */
ziv_extra_bits = ziv_extra_bits + (ziv_extra_bits / 2);
continue;
} else {
ret = bf_rint(r, rnd_mode);
if (ret & BF_ST_MEM_ERROR)
return BF_ST_MEM_ERROR;
break;
}
}
if (is_fixed_exponent)
break;
/* check that the result is < B^P */
/* XXX: do a fast approximate test first ? */
bf_init(r->ctx, B);
ret = bf_pow_ui_ui(B, radix, P, BF_PREC_INF, BF_RNDZ);
if (ret) {
bf_delete(B);
return ret;
}
res = bf_cmpu(r, B);
bf_delete(B);
if (res < 0)
break;
/* try a larger exponent */
E++;
}
*pE = E;
return 0;
}
static void limb_to_a(char *buf, limb_t n, unsigned int radix, int len)
{
int digit, i;
if (radix == 10) {
/* specific case with constant divisor */
for(i = len - 1; i >= 0; i--) {
digit = (limb_t)n % 10;
n = (limb_t)n / 10;
buf[i] = digit + '0';
}
} else {
for(i = len - 1; i >= 0; i--) {
digit = (limb_t)n % radix;
n = (limb_t)n / radix;
if (digit < 10)
digit += '0';
else
digit += 'a' - 10;
buf[i] = digit;
}
}
}
/* for power of 2 radixes */
static void limb_to_a2(char *buf, limb_t n, unsigned int radix_bits, int len)
{
int digit, i;
unsigned int mask;
mask = (1 << radix_bits) - 1;
for(i = len - 1; i >= 0; i--) {
digit = n & mask;
n >>= radix_bits;
if (digit < 10)
digit += '0';
else
digit += 'a' - 10;
buf[i] = digit;
}
}
/* 'a' must be an integer if the is_dec = FALSE or if the radix is not
a power of two. A dot is added before the 'dot_pos' digit. dot_pos
= n_digits does not display the dot. 0 <= dot_pos <=
n_digits. n_digits >= 1. */
static void output_digits(DynBuf *s, const bf_t *a1, int radix, limb_t n_digits,
limb_t dot_pos, BOOL is_dec)
{
limb_t i, v, l;
slimb_t pos, pos_incr;
int digits_per_limb, buf_pos, radix_bits, first_buf_pos;
char buf[65];
bf_t a_s, *a;
if (is_dec) {
digits_per_limb = LIMB_DIGITS;
a = (bf_t *)a1;
radix_bits = 0;
pos = a->len;
pos_incr = 1;
first_buf_pos = 0;
} else if ((radix & (radix - 1)) == 0) {
a = (bf_t *)a1;
radix_bits = ceil_log2(radix);
digits_per_limb = LIMB_BITS / radix_bits;
pos_incr = digits_per_limb * radix_bits;
/* digits are aligned relative to the radix point */
pos = a->len * LIMB_BITS + smod(-a->expn, radix_bits);
first_buf_pos = 0;
} else {
limb_t n, radixl;
digits_per_limb = digits_per_limb_table[radix - 2];
radixl = get_limb_radix(radix);
a = &a_s;
bf_init(a1->ctx, a);
n = (n_digits + digits_per_limb - 1) / digits_per_limb;
if (bf_resize(a, n)) {
dbuf_set_error(s);
goto done;
}
if (bf_integer_to_radix(a, a1, radixl)) {
dbuf_set_error(s);
goto done;
}
radix_bits = 0;
pos = n;
pos_incr = 1;
first_buf_pos = pos * digits_per_limb - n_digits;
}
buf_pos = digits_per_limb;
i = 0;
while (i < n_digits) {
if (buf_pos == digits_per_limb) {
pos -= pos_incr;
if (radix_bits == 0) {
v = get_limbz(a, pos);
limb_to_a(buf, v, radix, digits_per_limb);
} else {
v = get_bits(a->tab, a->len, pos);
limb_to_a2(buf, v, radix_bits, digits_per_limb);
}
buf_pos = first_buf_pos;
first_buf_pos = 0;
}
if (i < dot_pos) {
l = dot_pos;
} else {
if (i == dot_pos)
dbuf_putc(s, '.');
l = n_digits;
}
l = bf_min(digits_per_limb - buf_pos, l - i);
dbuf_put(s, (uint8_t *)(buf + buf_pos), l);
buf_pos += l;
i += l;
}
done:
if (a != a1)
bf_delete(a);
}
static void *bf_dbuf_realloc(void *opaque, void *ptr, size_t size)
{
bf_context_t *s = opaque;
return bf_realloc(s, ptr, size);
}
/* return the length in bytes. A trailing '\0' is added */
static char *bf_ftoa_internal(size_t *plen, const bf_t *a2, int radix,
limb_t prec, bf_flags_t flags, BOOL is_dec)
{
bf_context_t *ctx = a2->ctx;
DynBuf s_s, *s = &s_s;
int radix_bits;
// bf_print_str("ftoa", a2);
// printf("radix=%d\n", radix);
dbuf_init2(s, ctx, bf_dbuf_realloc);
if (a2->expn == BF_EXP_NAN) {
dbuf_putstr(s, "NaN");
} else {
if (a2->sign)
dbuf_putc(s, '-');
if (a2->expn == BF_EXP_INF) {
if (flags & BF_FTOA_JS_QUIRKS)
dbuf_putstr(s, "Infinity");
else
dbuf_putstr(s, "Inf");
} else {
int fmt, ret;
slimb_t n_digits, n, i, n_max, n1;
bf_t a1_s, *a1 = &a1_s;
if ((radix & (radix - 1)) != 0)
radix_bits = 0;
else
radix_bits = ceil_log2(radix);
fmt = flags & BF_FTOA_FORMAT_MASK;
bf_init(ctx, a1);
if (fmt == BF_FTOA_FORMAT_FRAC) {
if (is_dec || radix_bits != 0) {
if (bf_set(a1, a2))
goto fail1;
#ifdef USE_BF_DEC
if (is_dec) {
if (bfdec_round((bfdec_t *)a1, prec, (flags & BF_RND_MASK) | BF_FLAG_RADPNT_PREC) & BF_ST_MEM_ERROR)
goto fail1;
n = a1->expn;
} else
#endif
{
if (bf_round(a1, prec * radix_bits, (flags & BF_RND_MASK) | BF_FLAG_RADPNT_PREC) & BF_ST_MEM_ERROR)
goto fail1;
n = ceil_div(a1->expn, radix_bits);
}
if (flags & BF_FTOA_ADD_PREFIX) {
if (radix == 16)
dbuf_putstr(s, "0x");
else if (radix == 8)
dbuf_putstr(s, "0o");
else if (radix == 2)
dbuf_putstr(s, "0b");
}
if (a1->expn == BF_EXP_ZERO) {
dbuf_putstr(s, "0");
if (prec > 0) {
dbuf_putstr(s, ".");
for(i = 0; i < prec; i++) {
dbuf_putc(s, '0');
}
}
} else {
n_digits = prec + n;
if (n <= 0) {
/* 0.x */
dbuf_putstr(s, "0.");
for(i = 0; i < -n; i++) {
dbuf_putc(s, '0');
}
if (n_digits > 0) {
output_digits(s, a1, radix, n_digits, n_digits, is_dec);
}
} else {
output_digits(s, a1, radix, n_digits, n, is_dec);
}
}
} else {
size_t pos, start;
bf_t a_s, *a = &a_s;
/* make a positive number */
a->tab = a2->tab;
a->len = a2->len;
a->expn = a2->expn;
a->sign = 0;
/* one more digit for the rounding */
n = 1 + bf_mul_log2_radix(bf_max(a->expn, 0), radix, TRUE, TRUE);
n_digits = n + prec;
n1 = n;
if (bf_convert_to_radix(a1, &n1, a, radix, n_digits,
flags & BF_RND_MASK, TRUE))
goto fail1;
start = s->size;
output_digits(s, a1, radix, n_digits, n, is_dec);
/* remove leading zeros because we allocated one more digit */
pos = start;
while ((pos + 1) < s->size && s->buf[pos] == '0' &&
s->buf[pos + 1] != '.')
pos++;
if (pos > start) {
memmove(s->buf + start, s->buf + pos, s->size - pos);
s->size -= (pos - start);
}
}
} else {
#ifdef USE_BF_DEC
if (is_dec) {
if (bf_set(a1, a2))
goto fail1;
if (fmt == BF_FTOA_FORMAT_FIXED) {
n_digits = prec;
n_max = n_digits;
if (bfdec_round((bfdec_t *)a1, prec, (flags & BF_RND_MASK)) & BF_ST_MEM_ERROR)
goto fail1;
} else {
/* prec is ignored */
prec = n_digits = a1->len * LIMB_DIGITS;
/* remove the trailing zero digits */
while (n_digits > 1 &&
get_digit(a1->tab, a1->len, prec - n_digits) == 0) {
n_digits--;
}
n_max = n_digits + 4;
}
n = a1->expn;
} else
#endif
if (radix_bits != 0) {
if (bf_set(a1, a2))
goto fail1;
if (fmt == BF_FTOA_FORMAT_FIXED) {
slimb_t prec_bits;
n_digits = prec;
n_max = n_digits;
/* align to the radix point */
prec_bits = prec * radix_bits -
smod(-a1->expn, radix_bits);
if (bf_round(a1, prec_bits,
(flags & BF_RND_MASK)) & BF_ST_MEM_ERROR)
goto fail1;
} else {
limb_t digit_mask;
slimb_t pos;
/* position of the digit before the most
significant digit in bits */
pos = a1->len * LIMB_BITS +
smod(-a1->expn, radix_bits);
n_digits = ceil_div(pos, radix_bits);
/* remove the trailing zero digits */
digit_mask = ((limb_t)1 << radix_bits) - 1;
while (n_digits > 1 &&
(get_bits(a1->tab, a1->len, pos - n_digits * radix_bits) & digit_mask) == 0) {
n_digits--;
}
n_max = n_digits + 4;
}
n = ceil_div(a1->expn, radix_bits);
} else {
bf_t a_s, *a = &a_s;
/* make a positive number */
a->tab = a2->tab;
a->len = a2->len;
a->expn = a2->expn;
a->sign = 0;
if (fmt == BF_FTOA_FORMAT_FIXED) {
n_digits = prec;
n_max = n_digits;
} else {
slimb_t n_digits_max, n_digits_min;
assert(prec != BF_PREC_INF);
n_digits = 1 + bf_mul_log2_radix(prec, radix, TRUE, TRUE);
/* max number of digits for non exponential
notation. The rational is to have the same rule
as JS i.e. n_max = 21 for 64 bit float in base 10. */
n_max = n_digits + 4;
if (fmt == BF_FTOA_FORMAT_FREE_MIN) {
bf_t b_s, *b = &b_s;
/* find the minimum number of digits by
dichotomy. */
/* XXX: inefficient */
n_digits_max = n_digits;
n_digits_min = 1;
bf_init(ctx, b);
while (n_digits_min < n_digits_max) {
n_digits = (n_digits_min + n_digits_max) / 2;
if (bf_convert_to_radix(a1, &n, a, radix, n_digits,
flags & BF_RND_MASK, FALSE)) {
bf_delete(b);
goto fail1;
}
/* convert back to a number and compare */
ret = bf_mul_pow_radix(b, a1, radix, n - n_digits,
prec,
(flags & ~BF_RND_MASK) |
BF_RNDN);
if (ret & BF_ST_MEM_ERROR) {
bf_delete(b);
goto fail1;
}
if (bf_cmpu(b, a) == 0) {
n_digits_max = n_digits;
} else {
n_digits_min = n_digits + 1;
}
}
bf_delete(b);
n_digits = n_digits_max;
}
}
if (bf_convert_to_radix(a1, &n, a, radix, n_digits,
flags & BF_RND_MASK, FALSE)) {
fail1:
bf_delete(a1);
goto fail;
}
}
if (a1->expn == BF_EXP_ZERO &&
fmt != BF_FTOA_FORMAT_FIXED &&
!(flags & BF_FTOA_FORCE_EXP)) {
/* just output zero */
dbuf_putstr(s, "0");
} else {
if (flags & BF_FTOA_ADD_PREFIX) {
if (radix == 16)
dbuf_putstr(s, "0x");
else if (radix == 8)
dbuf_putstr(s, "0o");
else if (radix == 2)
dbuf_putstr(s, "0b");
}
if (a1->expn == BF_EXP_ZERO)
n = 1;
if ((flags & BF_FTOA_FORCE_EXP) ||
n <= -6 || n > n_max) {
const char *fmt;
/* exponential notation */
output_digits(s, a1, radix, n_digits, 1, is_dec);
if (radix_bits != 0 && radix <= 16) {
if (flags & BF_FTOA_JS_QUIRKS)
fmt = "p%+" PRId_LIMB;
else
fmt = "p%" PRId_LIMB;
dbuf_printf(s, fmt, (n - 1) * radix_bits);
} else {
if (flags & BF_FTOA_JS_QUIRKS)
fmt = "%c%+" PRId_LIMB;
else
fmt = "%c%" PRId_LIMB;
dbuf_printf(s, fmt,
radix <= 10 ? 'e' : '@', n - 1);
}
} else if (n <= 0) {
/* 0.x */
dbuf_putstr(s, "0.");
for(i = 0; i < -n; i++) {
dbuf_putc(s, '0');
}
output_digits(s, a1, radix, n_digits, n_digits, is_dec);
} else {
if (n_digits <= n) {
/* no dot */
output_digits(s, a1, radix, n_digits, n_digits, is_dec);
for(i = 0; i < (n - n_digits); i++)
dbuf_putc(s, '0');
} else {
output_digits(s, a1, radix, n_digits, n, is_dec);
}
}
}
}
bf_delete(a1);
}
}
dbuf_putc(s, '\0');
if (dbuf_error(s))
goto fail;
if (plen)
*plen = s->size - 1;
return (char *)s->buf;
fail:
bf_free(ctx, s->buf);
if (plen)
*plen = 0;
return NULL;
}
char *bf_ftoa(size_t *plen, const bf_t *a, int radix, limb_t prec,
bf_flags_t flags)
{
return bf_ftoa_internal(plen, a, radix, prec, flags, FALSE);
}
/***************************************************************/
/* transcendental functions */
/* Note: the algorithm is from MPFR */
static void bf_const_log2_rec(bf_t *T, bf_t *P, bf_t *Q, limb_t n1,
limb_t n2, BOOL need_P)
{
bf_context_t *s = T->ctx;
if ((n2 - n1) == 1) {
if (n1 == 0) {
bf_set_ui(P, 3);
} else {
bf_set_ui(P, n1);
P->sign = 1;
}
bf_set_ui(Q, 2 * n1 + 1);
Q->expn += 2;
bf_set(T, P);
} else {
limb_t m;
bf_t T1_s, *T1 = &T1_s;
bf_t P1_s, *P1 = &P1_s;
bf_t Q1_s, *Q1 = &Q1_s;
m = n1 + ((n2 - n1) >> 1);
bf_const_log2_rec(T, P, Q, n1, m, TRUE);
bf_init(s, T1);
bf_init(s, P1);
bf_init(s, Q1);
bf_const_log2_rec(T1, P1, Q1, m, n2, need_P);
bf_mul(T, T, Q1, BF_PREC_INF, BF_RNDZ);
bf_mul(T1, T1, P, BF_PREC_INF, BF_RNDZ);
bf_add(T, T, T1, BF_PREC_INF, BF_RNDZ);
if (need_P)
bf_mul(P, P, P1, BF_PREC_INF, BF_RNDZ);
bf_mul(Q, Q, Q1, BF_PREC_INF, BF_RNDZ);
bf_delete(T1);
bf_delete(P1);
bf_delete(Q1);
}
}
/* compute log(2) with faithful rounding at precision 'prec' */
static void bf_const_log2_internal(bf_t *T, limb_t prec)
{
limb_t w, N;
bf_t P_s, *P = &P_s;
bf_t Q_s, *Q = &Q_s;
w = prec + 15;
N = w / 3 + 1;
bf_init(T->ctx, P);
bf_init(T->ctx, Q);
bf_const_log2_rec(T, P, Q, 0, N, FALSE);
bf_div(T, T, Q, prec, BF_RNDN);
bf_delete(P);
bf_delete(Q);
}
/* PI constant */
#define CHUD_A 13591409
#define CHUD_B 545140134
#define CHUD_C 640320
#define CHUD_BITS_PER_TERM 47
static void chud_bs(bf_t *P, bf_t *Q, bf_t *G, int64_t a, int64_t b, int need_g,
limb_t prec)
{
bf_context_t *s = P->ctx;
int64_t c;
if (a == (b - 1)) {
bf_t T0, T1;
bf_init(s, &T0);
bf_init(s, &T1);
bf_set_ui(G, 2 * b - 1);
bf_mul_ui(G, G, 6 * b - 1, prec, BF_RNDN);
bf_mul_ui(G, G, 6 * b - 5, prec, BF_RNDN);
bf_set_ui(&T0, CHUD_B);
bf_mul_ui(&T0, &T0, b, prec, BF_RNDN);
bf_set_ui(&T1, CHUD_A);
bf_add(&T0, &T0, &T1, prec, BF_RNDN);
bf_mul(P, G, &T0, prec, BF_RNDN);
P->sign = b & 1;
bf_set_ui(Q, b);
bf_mul_ui(Q, Q, b, prec, BF_RNDN);
bf_mul_ui(Q, Q, b, prec, BF_RNDN);
bf_mul_ui(Q, Q, (uint64_t)CHUD_C * CHUD_C * CHUD_C / 24, prec, BF_RNDN);
bf_delete(&T0);
bf_delete(&T1);
} else {
bf_t P2, Q2, G2;
bf_init(s, &P2);
bf_init(s, &Q2);
bf_init(s, &G2);
c = (a + b) / 2;
chud_bs(P, Q, G, a, c, 1, prec);
chud_bs(&P2, &Q2, &G2, c, b, need_g, prec);
/* Q = Q1 * Q2 */
/* G = G1 * G2 */
/* P = P1 * Q2 + P2 * G1 */
bf_mul(&P2, &P2, G, prec, BF_RNDN);
if (!need_g)
bf_set_ui(G, 0);
bf_mul(P, P, &Q2, prec, BF_RNDN);
bf_add(P, P, &P2, prec, BF_RNDN);
bf_delete(&P2);
bf_mul(Q, Q, &Q2, prec, BF_RNDN);
bf_delete(&Q2);
if (need_g)
bf_mul(G, G, &G2, prec, BF_RNDN);
bf_delete(&G2);
}
}
/* compute Pi with faithful rounding at precision 'prec' using the
Chudnovsky formula */
static void bf_const_pi_internal(bf_t *Q, limb_t prec)
{
bf_context_t *s = Q->ctx;
int64_t n, prec1;
bf_t P, G;
/* number of serie terms */
n = prec / CHUD_BITS_PER_TERM + 1;
/* XXX: precision analysis */
prec1 = prec + 32;
bf_init(s, &P);
bf_init(s, &G);
chud_bs(&P, Q, &G, 0, n, 0, BF_PREC_INF);
bf_mul_ui(&G, Q, CHUD_A, prec1, BF_RNDN);
bf_add(&P, &G, &P, prec1, BF_RNDN);
bf_div(Q, Q, &P, prec1, BF_RNDF);
bf_set_ui(&P, CHUD_C);
bf_sqrt(&G, &P, prec1, BF_RNDF);
bf_mul_ui(&G, &G, (uint64_t)CHUD_C / 12, prec1, BF_RNDF);
bf_mul(Q, Q, &G, prec, BF_RNDN);
bf_delete(&P);
bf_delete(&G);
}
static int bf_const_get(bf_t *T, limb_t prec, bf_flags_t flags,
BFConstCache *c,
void (*func)(bf_t *res, limb_t prec), int sign)
{
limb_t ziv_extra_bits, prec1;
ziv_extra_bits = 32;
for(;;) {
prec1 = prec + ziv_extra_bits;
if (c->prec < prec1) {
if (c->val.len == 0)
bf_init(T->ctx, &c->val);
func(&c->val, prec1);
c->prec = prec1;
} else {
prec1 = c->prec;
}
bf_set(T, &c->val);
T->sign = sign;
if (!bf_can_round(T, prec, flags & BF_RND_MASK, prec1)) {
/* and more precision and retry */
ziv_extra_bits = ziv_extra_bits + (ziv_extra_bits / 2);
} else {
break;
}
}
return bf_round(T, prec, flags);
}
static void bf_const_free(BFConstCache *c)
{
bf_delete(&c->val);
memset(c, 0, sizeof(*c));
}
int bf_const_log2(bf_t *T, limb_t prec, bf_flags_t flags)
{
bf_context_t *s = T->ctx;
return bf_const_get(T, prec, flags, &s->log2_cache, bf_const_log2_internal, 0);
}
/* return rounded pi * (1 - 2 * sign) */
static int bf_const_pi_signed(bf_t *T, int sign, limb_t prec, bf_flags_t flags)
{
bf_context_t *s = T->ctx;
return bf_const_get(T, prec, flags, &s->pi_cache, bf_const_pi_internal,
sign);
}
int bf_const_pi(bf_t *T, limb_t prec, bf_flags_t flags)
{
return bf_const_pi_signed(T, 0, prec, flags);
}
void bf_clear_cache(bf_context_t *s)
{
#ifdef USE_FFT_MUL
fft_clear_cache(s);
#endif
bf_const_free(&s->log2_cache);
bf_const_free(&s->pi_cache);
}
/* ZivFunc should compute the result 'r' with faithful rounding at
precision 'prec'. For efficiency purposes, the final bf_round()
does not need to be done in the function. */
typedef int ZivFunc(bf_t *r, const bf_t *a, limb_t prec, void *opaque);
static int bf_ziv_rounding(bf_t *r, const bf_t *a,
limb_t prec, bf_flags_t flags,
ZivFunc *f, void *opaque)
{
int rnd_mode, ret;
slimb_t prec1, ziv_extra_bits;
rnd_mode = flags & BF_RND_MASK;
if (rnd_mode == BF_RNDF) {
/* no need to iterate */
f(r, a, prec, opaque);
ret = 0;
} else {
ziv_extra_bits = 32;
for(;;) {
prec1 = prec + ziv_extra_bits;
ret = f(r, a, prec1, opaque);
if (ret & (BF_ST_OVERFLOW | BF_ST_UNDERFLOW | BF_ST_MEM_ERROR)) {
/* overflow or underflow should never happen because
it indicates the rounding cannot be done correctly,
but we do not catch all the cases */
return ret;
}
/* if the result is exact, we can stop */
if (!(ret & BF_ST_INEXACT)) {
ret = 0;
break;
}
if (bf_can_round(r, prec, rnd_mode, prec1)) {
ret = BF_ST_INEXACT;
break;
}
ziv_extra_bits = ziv_extra_bits * 2;
// printf("ziv_extra_bits=%" PRId64 "\n", (int64_t)ziv_extra_bits);
}
}
if (r->len == 0)
return ret;
else
return __bf_round(r, prec, flags, r->len, ret);
}
/* add (1 - 2*e_sign) * 2^e */
static int bf_add_epsilon(bf_t *r, const bf_t *a, slimb_t e, int e_sign,
limb_t prec, int flags)
{
bf_t T_s, *T = &T_s;
int ret;
/* small argument case: result = 1 + epsilon * sign(x) */
bf_init(a->ctx, T);
bf_set_ui(T, 1);
T->sign = e_sign;
T->expn += e;
ret = bf_add(r, r, T, prec, flags);
bf_delete(T);
return ret;
}
/* Compute the exponential using faithful rounding at precision 'prec'.
Note: the algorithm is from MPFR */
static int bf_exp_internal(bf_t *r, const bf_t *a, limb_t prec, void *opaque)
{
bf_context_t *s = r->ctx;
bf_t T_s, *T = &T_s;
slimb_t n, K, l, i, prec1;
assert(r != a);
/* argument reduction:
T = a - n*log(2) with 0 <= T < log(2) and n integer.
*/
bf_init(s, T);
if (a->expn <= -1) {
/* 0 <= abs(a) <= 0.5 */
if (a->sign)
n = -1;
else
n = 0;
} else {
bf_const_log2(T, LIMB_BITS, BF_RNDZ);
bf_div(T, a, T, LIMB_BITS, BF_RNDD);
bf_get_limb(&n, T, 0);
}
K = bf_isqrt((prec + 1) / 2);
l = (prec - 1) / K + 1;
/* XXX: precision analysis ? */
prec1 = prec + (K + 2 * l + 18) + K + 8;
if (a->expn > 0)
prec1 += a->expn;
// printf("n=%ld K=%ld prec1=%ld\n", n, K, prec1);
bf_const_log2(T, prec1, BF_RNDF);
bf_mul_si(T, T, n, prec1, BF_RNDN);
bf_sub(T, a, T, prec1, BF_RNDN);
/* reduce the range of T */
bf_mul_2exp(T, -K, BF_PREC_INF, BF_RNDZ);
/* Taylor expansion around zero :
1 + x + x^2/2 + ... + x^n/n!
= (1 + x * (1 + x/2 * (1 + ... (x/n))))
*/
{
bf_t U_s, *U = &U_s;
bf_init(s, U);
bf_set_ui(r, 1);
for(i = l ; i >= 1; i--) {
bf_set_ui(U, i);
bf_div(U, T, U, prec1, BF_RNDN);
bf_mul(r, r, U, prec1, BF_RNDN);
bf_add_si(r, r, 1, prec1, BF_RNDN);
}
bf_delete(U);
}
bf_delete(T);
/* undo the range reduction */
for(i = 0; i < K; i++) {
bf_mul(r, r, r, prec1, BF_RNDN | BF_FLAG_EXT_EXP);
}
/* undo the argument reduction */
bf_mul_2exp(r, n, BF_PREC_INF, BF_RNDZ | BF_FLAG_EXT_EXP);
return BF_ST_INEXACT;
}
/* crude overflow and underflow tests for exp(a). a_low <= a <= a_high */
static int check_exp_underflow_overflow(bf_context_t *s, bf_t *r,
const bf_t *a_low, const bf_t *a_high,
limb_t prec, bf_flags_t flags)
{
bf_t T_s, *T = &T_s;
bf_t log2_s, *log2 = &log2_s;
slimb_t e_min, e_max;
if (a_high->expn <= 0)
return 0;
e_max = (limb_t)1 << (bf_get_exp_bits(flags) - 1);
e_min = -e_max + 3;
if (flags & BF_FLAG_SUBNORMAL)
e_min -= (prec - 1);
bf_init(s, T);
bf_init(s, log2);
bf_const_log2(log2, LIMB_BITS, BF_RNDU);
bf_mul_ui(T, log2, e_max, LIMB_BITS, BF_RNDU);
/* a_low > e_max * log(2) implies exp(a) > e_max */
if (bf_cmp_lt(T, a_low) > 0) {
/* overflow */
bf_delete(T);
bf_delete(log2);
return bf_set_overflow(r, 0, prec, flags);
}
/* a_high < (e_min - 2) * log(2) implies exp(a) < (e_min - 2) */
bf_const_log2(log2, LIMB_BITS, BF_RNDD);
bf_mul_si(T, log2, e_min - 2, LIMB_BITS, BF_RNDD);
if (bf_cmp_lt(a_high, T)) {
int rnd_mode = flags & BF_RND_MASK;
/* underflow */
bf_delete(T);
bf_delete(log2);
if (rnd_mode == BF_RNDU) {
/* set the smallest value */
bf_set_ui(r, 1);
r->expn = e_min;
} else {
bf_set_zero(r, 0);
}
return BF_ST_UNDERFLOW | BF_ST_INEXACT;
}
bf_delete(log2);
bf_delete(T);
return 0;
}
int bf_exp(bf_t *r, const bf_t *a, limb_t prec, bf_flags_t flags)
{
bf_context_t *s = r->ctx;
int ret;
assert(r != a);
if (a->len == 0) {
if (a->expn == BF_EXP_NAN) {
bf_set_nan(r);
} else if (a->expn == BF_EXP_INF) {
if (a->sign)
bf_set_zero(r, 0);
else
bf_set_inf(r, 0);
} else {
bf_set_ui(r, 1);
}
return 0;
}
ret = check_exp_underflow_overflow(s, r, a, a, prec, flags);
if (ret)
return ret;
if (a->expn < 0 && (-a->expn) >= (prec + 2)) {
/* small argument case: result = 1 + epsilon * sign(x) */
bf_set_ui(r, 1);
return bf_add_epsilon(r, r, -(prec + 2), a->sign, prec, flags);
}
return bf_ziv_rounding(r, a, prec, flags, bf_exp_internal, NULL);
}
static int bf_log_internal(bf_t *r, const bf_t *a, limb_t prec, void *opaque)
{
bf_context_t *s = r->ctx;
bf_t T_s, *T = &T_s;
bf_t U_s, *U = &U_s;
bf_t V_s, *V = &V_s;
slimb_t n, prec1, l, i, K;
assert(r != a);
bf_init(s, T);
/* argument reduction 1 */
/* T=a*2^n with 2/3 <= T <= 4/3 */
{
bf_t U_s, *U = &U_s;
bf_set(T, a);
n = T->expn;
T->expn = 0;
/* U= ~ 2/3 */
bf_init(s, U);
bf_set_ui(U, 0xaaaaaaaa);
U->expn = 0;
if (bf_cmp_lt(T, U)) {
T->expn++;
n--;
}
bf_delete(U);
}
// printf("n=%ld\n", n);
// bf_print_str("T", T);
/* XXX: precision analysis */
/* number of iterations for argument reduction 2 */
K = bf_isqrt((prec + 1) / 2);
/* order of Taylor expansion */
l = prec / (2 * K) + 1;
/* precision of the intermediate computations */
prec1 = prec + K + 2 * l + 32;
bf_init(s, U);
bf_init(s, V);
/* Note: cancellation occurs here, so we use more precision (XXX:
reduce the precision by computing the exact cancellation) */
bf_add_si(T, T, -1, BF_PREC_INF, BF_RNDN);
/* argument reduction 2 */
for(i = 0; i < K; i++) {
/* T = T / (1 + sqrt(1 + T)) */
bf_add_si(U, T, 1, prec1, BF_RNDN);
bf_sqrt(V, U, prec1, BF_RNDF);
bf_add_si(U, V, 1, prec1, BF_RNDN);
bf_div(T, T, U, prec1, BF_RNDN);
}
{
bf_t Y_s, *Y = &Y_s;
bf_t Y2_s, *Y2 = &Y2_s;
bf_init(s, Y);
bf_init(s, Y2);
/* compute ln(1+x) = ln((1+y)/(1-y)) with y=x/(2+x)
= y + y^3/3 + ... + y^(2*l + 1) / (2*l+1)
with Y=Y^2
= y*(1+Y/3+Y^2/5+...) = y*(1+Y*(1/3+Y*(1/5 + ...)))
*/
bf_add_si(Y, T, 2, prec1, BF_RNDN);
bf_div(Y, T, Y, prec1, BF_RNDN);
bf_mul(Y2, Y, Y, prec1, BF_RNDN);
bf_set_ui(r, 0);
for(i = l; i >= 1; i--) {
bf_set_ui(U, 1);
bf_set_ui(V, 2 * i + 1);
bf_div(U, U, V, prec1, BF_RNDN);
bf_add(r, r, U, prec1, BF_RNDN);
bf_mul(r, r, Y2, prec1, BF_RNDN);
}
bf_add_si(r, r, 1, prec1, BF_RNDN);
bf_mul(r, r, Y, prec1, BF_RNDN);
bf_delete(Y);
bf_delete(Y2);
}
bf_delete(V);
bf_delete(U);
/* multiplication by 2 for the Taylor expansion and undo the
argument reduction 2*/
bf_mul_2exp(r, K + 1, BF_PREC_INF, BF_RNDZ);
/* undo the argument reduction 1 */
bf_const_log2(T, prec1, BF_RNDF);
bf_mul_si(T, T, n, prec1, BF_RNDN);
bf_add(r, r, T, prec1, BF_RNDN);
bf_delete(T);
return BF_ST_INEXACT;
}
int bf_log(bf_t *r, const bf_t *a, limb_t prec, bf_flags_t flags)
{
bf_context_t *s = r->ctx;
bf_t T_s, *T = &T_s;
assert(r != a);
if (a->len == 0) {
if (a->expn == BF_EXP_NAN) {
bf_set_nan(r);
return 0;
} else if (a->expn == BF_EXP_INF) {
if (a->sign) {
bf_set_nan(r);
return BF_ST_INVALID_OP;
} else {
bf_set_inf(r, 0);
return 0;
}
} else {
bf_set_inf(r, 1);
return 0;
}
}
if (a->sign) {
bf_set_nan(r);
return BF_ST_INVALID_OP;
}
bf_init(s, T);
bf_set_ui(T, 1);
if (bf_cmp_eq(a, T)) {
bf_set_zero(r, 0);
bf_delete(T);
return 0;
}
bf_delete(T);
return bf_ziv_rounding(r, a, prec, flags, bf_log_internal, NULL);
}
/* x and y finite and x > 0 */
static int bf_pow_generic(bf_t *r, const bf_t *x, limb_t prec, void *opaque)
{
bf_context_t *s = r->ctx;
const bf_t *y = opaque;
bf_t T_s, *T = &T_s;
limb_t prec1;
bf_init(s, T);
/* XXX: proof for the added precision */
prec1 = prec + 32;
bf_log(T, x, prec1, BF_RNDF | BF_FLAG_EXT_EXP);
bf_mul(T, T, y, prec1, BF_RNDF | BF_FLAG_EXT_EXP);
if (bf_is_nan(T))
bf_set_nan(r);
else
bf_exp_internal(r, T, prec1, NULL); /* no overflow/underlow test needed */
bf_delete(T);
return BF_ST_INEXACT;
}
/* x and y finite, x > 0, y integer and y fits on one limb */
static int bf_pow_int(bf_t *r, const bf_t *x, limb_t prec, void *opaque)
{
bf_context_t *s = r->ctx;
const bf_t *y = opaque;
bf_t T_s, *T = &T_s;
limb_t prec1;
int ret;
slimb_t y1;
bf_get_limb(&y1, y, 0);
if (y1 < 0)
y1 = -y1;
/* XXX: proof for the added precision */
prec1 = prec + ceil_log2(y1) * 2 + 8;
ret = bf_pow_ui(r, x, y1 < 0 ? -y1 : y1, prec1, BF_RNDN | BF_FLAG_EXT_EXP);
if (y->sign) {
bf_init(s, T);
bf_set_ui(T, 1);
ret |= bf_div(r, T, r, prec1, BF_RNDN | BF_FLAG_EXT_EXP);
bf_delete(T);
}
return ret;
}
/* x must be a finite non zero float. Return TRUE if there is a
floating point number r such as x=r^(2^n) and return this floating
point number 'r'. Otherwise return FALSE and r is undefined. */
static BOOL check_exact_power2n(bf_t *r, const bf_t *x, slimb_t n)
{
bf_context_t *s = r->ctx;
bf_t T_s, *T = &T_s;
slimb_t e, i, er;
limb_t v;
/* x = m*2^e with m odd integer */
e = bf_get_exp_min(x);
/* fast check on the exponent */
if (n > (LIMB_BITS - 1)) {
if (e != 0)
return FALSE;
er = 0;
} else {
if ((e & (((limb_t)1 << n) - 1)) != 0)
return FALSE;
er = e >> n;
}
/* every perfect odd square = 1 modulo 8 */
v = get_bits(x->tab, x->len, x->len * LIMB_BITS - x->expn + e);
if ((v & 7) != 1)
return FALSE;
bf_init(s, T);
bf_set(T, x);
T->expn -= e;
for(i = 0; i < n; i++) {
if (i != 0)
bf_set(T, r);
if (bf_sqrtrem(r, NULL, T) != 0)
return FALSE;
}
r->expn += er;
return TRUE;
}
/* prec = BF_PREC_INF is accepted for x and y integers and y >= 0 */
int bf_pow(bf_t *r, const bf_t *x, const bf_t *y, limb_t prec, bf_flags_t flags)
{
bf_context_t *s = r->ctx;
bf_t T_s, *T = &T_s;
bf_t ytmp_s;
BOOL y_is_int, y_is_odd;
int r_sign, ret, rnd_mode;
slimb_t y_emin;
if (x->len == 0 || y->len == 0) {
if (y->expn == BF_EXP_ZERO) {
/* pow(x, 0) = 1 */
bf_set_ui(r, 1);
} else if (x->expn == BF_EXP_NAN) {
bf_set_nan(r);
} else {
int cmp_x_abs_1;
bf_set_ui(r, 1);
cmp_x_abs_1 = bf_cmpu(x, r);
if (cmp_x_abs_1 == 0 && (flags & BF_POW_JS_QUIRKS) &&
(y->expn >= BF_EXP_INF)) {
bf_set_nan(r);
} else if (cmp_x_abs_1 == 0 &&
(!x->sign || y->expn != BF_EXP_NAN)) {
/* pow(1, y) = 1 even if y = NaN */
/* pow(-1, +/-inf) = 1 */
} else if (y->expn == BF_EXP_NAN) {
bf_set_nan(r);
} else if (y->expn == BF_EXP_INF) {
if (y->sign == (cmp_x_abs_1 > 0)) {
bf_set_zero(r, 0);
} else {
bf_set_inf(r, 0);
}
} else {
y_emin = bf_get_exp_min(y);
y_is_odd = (y_emin == 0);
if (y->sign == (x->expn == BF_EXP_ZERO)) {
bf_set_inf(r, y_is_odd & x->sign);
if (y->sign) {
/* pow(0, y) with y < 0 */
return BF_ST_DIVIDE_ZERO;
}
} else {
bf_set_zero(r, y_is_odd & x->sign);
}
}
}
return 0;
}
bf_init(s, T);
bf_set(T, x);
y_emin = bf_get_exp_min(y);
y_is_int = (y_emin >= 0);
rnd_mode = flags & BF_RND_MASK;
if (x->sign) {
if (!y_is_int) {
bf_set_nan(r);
bf_delete(T);
return BF_ST_INVALID_OP;
}
y_is_odd = (y_emin == 0);
r_sign = y_is_odd;
/* change the directed rounding mode if the sign of the result
is changed */
if (r_sign && (rnd_mode == BF_RNDD || rnd_mode == BF_RNDU))
flags ^= 1;
bf_neg(T);
} else {
r_sign = 0;
}
bf_set_ui(r, 1);
if (bf_cmp_eq(T, r)) {
/* abs(x) = 1: nothing more to do */
ret = 0;
} else {
/* check the overflow/underflow cases */
{
bf_t al_s, *al = &al_s;
bf_t ah_s, *ah = &ah_s;
limb_t precl = LIMB_BITS;
bf_init(s, al);
bf_init(s, ah);
/* compute bounds of log(abs(x)) * y with a low precision */
/* XXX: compute bf_log() once */
/* XXX: add a fast test before this slow test */
bf_log(al, T, precl, BF_RNDD);
bf_log(ah, T, precl, BF_RNDU);
bf_mul(al, al, y, precl, BF_RNDD ^ y->sign);
bf_mul(ah, ah, y, precl, BF_RNDU ^ y->sign);
ret = check_exp_underflow_overflow(s, r, al, ah, prec, flags);
bf_delete(al);
bf_delete(ah);
if (ret)
goto done;
}
if (y_is_int) {
slimb_t T_bits, e;
int_pow:
T_bits = T->expn - bf_get_exp_min(T);
if (T_bits == 1) {
/* pow(2^b, y) = 2^(b*y) */
bf_mul_si(T, y, T->expn - 1, LIMB_BITS, BF_RNDZ);
bf_get_limb(&e, T, 0);
bf_set_ui(r, 1);
ret = bf_mul_2exp(r, e, prec, flags);
} else if (prec == BF_PREC_INF) {
slimb_t y1;
/* specific case for infinite precision (integer case) */
bf_get_limb(&y1, y, 0);
assert(!y->sign);
/* x must be an integer, so abs(x) >= 2 */
if (y1 >= ((slimb_t)1 << BF_EXP_BITS_MAX)) {
bf_delete(T);
return bf_set_overflow(r, 0, BF_PREC_INF, flags);
}
ret = bf_pow_ui(r, T, y1, BF_PREC_INF, BF_RNDZ);
} else {
if (y->expn <= 31) {
/* small enough power: use exponentiation in all cases */
} else if (y->sign) {
/* cannot be exact */
goto general_case;
} else {
if (rnd_mode == BF_RNDF)
goto general_case; /* no need to track exact results */
/* see if the result has a chance to be exact:
if x=a*2^b (a odd), x^y=a^y*2^(b*y)
x^y needs a precision of at least floor_log2(a)*y bits
*/
bf_mul_si(r, y, T_bits - 1, LIMB_BITS, BF_RNDZ);
bf_get_limb(&e, r, 0);
if (prec < e)
goto general_case;
}
ret = bf_ziv_rounding(r, T, prec, flags, bf_pow_int, (void *)y);
}
} else {
if (rnd_mode != BF_RNDF) {
bf_t *y1;
if (y_emin < 0 && check_exact_power2n(r, T, -y_emin)) {
/* the problem is reduced to a power to an integer */
#if 0
printf("\nn=%" PRId64 "\n", -(int64_t)y_emin);
bf_print_str("T", T);
bf_print_str("r", r);
#endif
bf_set(T, r);
y1 = &ytmp_s;
y1->tab = y->tab;
y1->len = y->len;
y1->sign = y->sign;
y1->expn = y->expn - y_emin;
y = y1;
goto int_pow;
}
}
general_case:
ret = bf_ziv_rounding(r, T, prec, flags, bf_pow_generic, (void *)y);
}
}
done:
bf_delete(T);
r->sign = r_sign;
return ret;
}
/* compute sqrt(-2*x-x^2) to get |sin(x)| from cos(x) - 1. */
static void bf_sqrt_sin(bf_t *r, const bf_t *x, limb_t prec1)
{
bf_context_t *s = r->ctx;
bf_t T_s, *T = &T_s;
bf_init(s, T);
bf_set(T, x);
bf_mul(r, T, T, prec1, BF_RNDN);
bf_mul_2exp(T, 1, BF_PREC_INF, BF_RNDZ);
bf_add(T, T, r, prec1, BF_RNDN);
bf_neg(T);
bf_sqrt(r, T, prec1, BF_RNDF);
bf_delete(T);
}
static int bf_sincos(bf_t *s, bf_t *c, const bf_t *a, limb_t prec)
{
bf_context_t *s1 = a->ctx;
bf_t T_s, *T = &T_s;
bf_t U_s, *U = &U_s;
bf_t r_s, *r = &r_s;
slimb_t K, prec1, i, l, mod, prec2;
int is_neg;
assert(c != a && s != a);
bf_init(s1, T);
bf_init(s1, U);
bf_init(s1, r);
/* XXX: precision analysis */
K = bf_isqrt(prec / 2);
l = prec / (2 * K) + 1;
prec1 = prec + 2 * K + l + 8;
/* after the modulo reduction, -pi/4 <= T <= pi/4 */
if (a->expn <= -1) {
/* abs(a) <= 0.25: no modulo reduction needed */
bf_set(T, a);
mod = 0;
} else {
slimb_t cancel;
cancel = 0;
for(;;) {
prec2 = prec1 + a->expn + cancel;
bf_const_pi(U, prec2, BF_RNDF);
bf_mul_2exp(U, -1, BF_PREC_INF, BF_RNDZ);
bf_remquo(&mod, T, a, U, prec2, BF_RNDN, BF_RNDN);
// printf("T.expn=%ld prec2=%ld\n", T->expn, prec2);
if (mod == 0 || (T->expn != BF_EXP_ZERO &&
(T->expn + prec2) >= (prec1 - 1)))
break;
/* increase the number of bits until the precision is good enough */
cancel = bf_max(-T->expn, (cancel + 1) * 3 / 2);
}
mod &= 3;
}
is_neg = T->sign;
/* compute cosm1(x) = cos(x) - 1 */
bf_mul(T, T, T, prec1, BF_RNDN);
bf_mul_2exp(T, -2 * K, BF_PREC_INF, BF_RNDZ);
/* Taylor expansion:
-x^2/2 + x^4/4! - x^6/6! + ...
*/
bf_set_ui(r, 1);
for(i = l ; i >= 1; i--) {
bf_set_ui(U, 2 * i - 1);
bf_mul_ui(U, U, 2 * i, BF_PREC_INF, BF_RNDZ);
bf_div(U, T, U, prec1, BF_RNDN);
bf_mul(r, r, U, prec1, BF_RNDN);
bf_neg(r);
if (i != 1)
bf_add_si(r, r, 1, prec1, BF_RNDN);
}
bf_delete(U);
/* undo argument reduction:
cosm1(2*x)= 2*(2*cosm1(x)+cosm1(x)^2)
*/
for(i = 0; i < K; i++) {
bf_mul(T, r, r, prec1, BF_RNDN);
bf_mul_2exp(r, 1, BF_PREC_INF, BF_RNDZ);
bf_add(r, r, T, prec1, BF_RNDN);
bf_mul_2exp(r, 1, BF_PREC_INF, BF_RNDZ);
}
bf_delete(T);
if (c) {
if ((mod & 1) == 0) {
bf_add_si(c, r, 1, prec1, BF_RNDN);
} else {
bf_sqrt_sin(c, r, prec1);
c->sign = is_neg ^ 1;
}
c->sign ^= mod >> 1;
}
if (s) {
if ((mod & 1) == 0) {
bf_sqrt_sin(s, r, prec1);
s->sign = is_neg;
} else {
bf_add_si(s, r, 1, prec1, BF_RNDN);
}
s->sign ^= mod >> 1;
}
bf_delete(r);
return BF_ST_INEXACT;
}
static int bf_cos_internal(bf_t *r, const bf_t *a, limb_t prec, void *opaque)
{
return bf_sincos(NULL, r, a, prec);
}
int bf_cos(bf_t *r, const bf_t *a, limb_t prec, bf_flags_t flags)
{
if (a->len == 0) {
if (a->expn == BF_EXP_NAN) {
bf_set_nan(r);
return 0;
} else if (a->expn == BF_EXP_INF) {
bf_set_nan(r);
return BF_ST_INVALID_OP;
} else {
bf_set_ui(r, 1);
return 0;
}
}
/* small argument case: result = 1+r(x) with r(x) = -x^2/2 +
O(X^4). We assume r(x) < 2^(2*EXP(x) - 1). */
if (a->expn < 0) {
slimb_t e;
e = 2 * a->expn - 1;
if (e < -(prec + 2)) {
bf_set_ui(r, 1);
return bf_add_epsilon(r, r, e, 1, prec, flags);
}
}
return bf_ziv_rounding(r, a, prec, flags, bf_cos_internal, NULL);
}
static int bf_sin_internal(bf_t *r, const bf_t *a, limb_t prec, void *opaque)
{
return bf_sincos(r, NULL, a, prec);
}
int bf_sin(bf_t *r, const bf_t *a, limb_t prec, bf_flags_t flags)
{
if (a->len == 0) {
if (a->expn == BF_EXP_NAN) {
bf_set_nan(r);
return 0;
} else if (a->expn == BF_EXP_INF) {
bf_set_nan(r);
return BF_ST_INVALID_OP;
} else {
bf_set_zero(r, a->sign);
return 0;
}
}
/* small argument case: result = x+r(x) with r(x) = -x^3/6 +
O(X^5). We assume r(x) < 2^(3*EXP(x) - 2). */
if (a->expn < 0) {
slimb_t e;
e = sat_add(2 * a->expn, a->expn - 2);
if (e < a->expn - bf_max(prec + 2, a->len * LIMB_BITS + 2)) {
bf_set(r, a);
return bf_add_epsilon(r, r, e, 1 - a->sign, prec, flags);
}
}
return bf_ziv_rounding(r, a, prec, flags, bf_sin_internal, NULL);
}
static int bf_tan_internal(bf_t *r, const bf_t *a, limb_t prec, void *opaque)
{
bf_context_t *s = r->ctx;
bf_t T_s, *T = &T_s;
limb_t prec1;
/* XXX: precision analysis */
prec1 = prec + 8;
bf_init(s, T);
bf_sincos(r, T, a, prec1);
bf_div(r, r, T, prec1, BF_RNDF);
bf_delete(T);
return BF_ST_INEXACT;
}
int bf_tan(bf_t *r, const bf_t *a, limb_t prec, bf_flags_t flags)
{
assert(r != a);
if (a->len == 0) {
if (a->expn == BF_EXP_NAN) {
bf_set_nan(r);
return 0;
} else if (a->expn == BF_EXP_INF) {
bf_set_nan(r);
return BF_ST_INVALID_OP;
} else {
bf_set_zero(r, a->sign);
return 0;
}
}
/* small argument case: result = x+r(x) with r(x) = x^3/3 +
O(X^5). We assume r(x) < 2^(3*EXP(x) - 1). */
if (a->expn < 0) {
slimb_t e;
e = sat_add(2 * a->expn, a->expn - 1);
if (e < a->expn - bf_max(prec + 2, a->len * LIMB_BITS + 2)) {
bf_set(r, a);
return bf_add_epsilon(r, r, e, a->sign, prec, flags);
}
}
return bf_ziv_rounding(r, a, prec, flags, bf_tan_internal, NULL);
}
/* if add_pi2 is true, add pi/2 to the result (used for acos(x) to
avoid cancellation) */
static int bf_atan_internal(bf_t *r, const bf_t *a, limb_t prec,
void *opaque)
{
bf_context_t *s = r->ctx;
BOOL add_pi2 = (BOOL)(intptr_t)opaque;
bf_t T_s, *T = &T_s;
bf_t U_s, *U = &U_s;
bf_t V_s, *V = &V_s;
bf_t X2_s, *X2 = &X2_s;
int cmp_1;
slimb_t prec1, i, K, l;
/* XXX: precision analysis */
K = bf_isqrt((prec + 1) / 2);
l = prec / (2 * K) + 1;
prec1 = prec + K + 2 * l + 32;
// printf("prec=%d K=%d l=%d prec1=%d\n", (int)prec, (int)K, (int)l, (int)prec1);
bf_init(s, T);
cmp_1 = (a->expn >= 1); /* a >= 1 */
if (cmp_1) {
bf_set_ui(T, 1);
bf_div(T, T, a, prec1, BF_RNDN);
} else {
bf_set(T, a);
}
/* abs(T) <= 1 */
/* argument reduction */
bf_init(s, U);
bf_init(s, V);
bf_init(s, X2);
for(i = 0; i < K; i++) {
/* T = T / (1 + sqrt(1 + T^2)) */
bf_mul(U, T, T, prec1, BF_RNDN);
bf_add_si(U, U, 1, prec1, BF_RNDN);
bf_sqrt(V, U, prec1, BF_RNDN);
bf_add_si(V, V, 1, prec1, BF_RNDN);
bf_div(T, T, V, prec1, BF_RNDN);
}
/* Taylor series:
x - x^3/3 + ... + (-1)^ l * y^(2*l + 1) / (2*l+1)
*/
bf_mul(X2, T, T, prec1, BF_RNDN);
bf_set_ui(r, 0);
for(i = l; i >= 1; i--) {
bf_set_si(U, 1);
bf_set_ui(V, 2 * i + 1);
bf_div(U, U, V, prec1, BF_RNDN);
bf_neg(r);
bf_add(r, r, U, prec1, BF_RNDN);
bf_mul(r, r, X2, prec1, BF_RNDN);
}
bf_neg(r);
bf_add_si(r, r, 1, prec1, BF_RNDN);
bf_mul(r, r, T, prec1, BF_RNDN);
/* undo the argument reduction */
bf_mul_2exp(r, K, BF_PREC_INF, BF_RNDZ);
bf_delete(U);
bf_delete(V);
bf_delete(X2);
i = add_pi2;
if (cmp_1 > 0) {
/* undo the inversion : r = sign(a)*PI/2 - r */
bf_neg(r);
i += 1 - 2 * a->sign;
}
/* add i*(pi/2) with -1 <= i <= 2 */
if (i != 0) {
bf_const_pi(T, prec1, BF_RNDF);
if (i != 2)
bf_mul_2exp(T, -1, BF_PREC_INF, BF_RNDZ);
T->sign = (i < 0);
bf_add(r, T, r, prec1, BF_RNDN);
}
bf_delete(T);
return BF_ST_INEXACT;
}
int bf_atan(bf_t *r, const bf_t *a, limb_t prec, bf_flags_t flags)
{
bf_context_t *s = r->ctx;
bf_t T_s, *T = &T_s;
int res;
if (a->len == 0) {
if (a->expn == BF_EXP_NAN) {
bf_set_nan(r);
return 0;
} else if (a->expn == BF_EXP_INF) {
/* -PI/2 or PI/2 */
bf_const_pi_signed(r, a->sign, prec, flags);
bf_mul_2exp(r, -1, BF_PREC_INF, BF_RNDZ);
return BF_ST_INEXACT;
} else {
bf_set_zero(r, a->sign);
return 0;
}
}
bf_init(s, T);
bf_set_ui(T, 1);
res = bf_cmpu(a, T);
bf_delete(T);
if (res == 0) {
/* short cut: abs(a) == 1 -> +/-pi/4 */
bf_const_pi_signed(r, a->sign, prec, flags);
bf_mul_2exp(r, -2, BF_PREC_INF, BF_RNDZ);
return BF_ST_INEXACT;
}
/* small argument case: result = x+r(x) with r(x) = -x^3/3 +
O(X^5). We assume r(x) < 2^(3*EXP(x) - 1). */
if (a->expn < 0) {
slimb_t e;
e = sat_add(2 * a->expn, a->expn - 1);
if (e < a->expn - bf_max(prec + 2, a->len * LIMB_BITS + 2)) {
bf_set(r, a);
return bf_add_epsilon(r, r, e, 1 - a->sign, prec, flags);
}
}
return bf_ziv_rounding(r, a, prec, flags, bf_atan_internal, (void *)FALSE);
}
static int bf_atan2_internal(bf_t *r, const bf_t *y, limb_t prec, void *opaque)
{
bf_context_t *s = r->ctx;
const bf_t *x = opaque;
bf_t T_s, *T = &T_s;
limb_t prec1;
int ret;
if (y->expn == BF_EXP_NAN || x->expn == BF_EXP_NAN) {
bf_set_nan(r);
return 0;
}
/* compute atan(y/x) assumming inf/inf = 1 and 0/0 = 0 */
bf_init(s, T);
prec1 = prec + 32;
if (y->expn == BF_EXP_INF && x->expn == BF_EXP_INF) {
bf_set_ui(T, 1);
T->sign = y->sign ^ x->sign;
} else if (y->expn == BF_EXP_ZERO && x->expn == BF_EXP_ZERO) {
bf_set_zero(T, y->sign ^ x->sign);
} else {
bf_div(T, y, x, prec1, BF_RNDF);
}
ret = bf_atan(r, T, prec1, BF_RNDF);
if (x->sign) {
/* if x < 0 (it includes -0), return sign(y)*pi + atan(y/x) */
bf_const_pi(T, prec1, BF_RNDF);
T->sign = y->sign;
bf_add(r, r, T, prec1, BF_RNDN);
ret |= BF_ST_INEXACT;
}
bf_delete(T);
return ret;
}
int bf_atan2(bf_t *r, const bf_t *y, const bf_t *x,
limb_t prec, bf_flags_t flags)
{
return bf_ziv_rounding(r, y, prec, flags, bf_atan2_internal, (void *)x);
}
static int bf_asin_internal(bf_t *r, const bf_t *a, limb_t prec, void *opaque)
{
bf_context_t *s = r->ctx;
BOOL is_acos = (BOOL)(intptr_t)opaque;
bf_t T_s, *T = &T_s;
limb_t prec1, prec2;
/* asin(x) = atan(x/sqrt(1-x^2))
acos(x) = pi/2 - asin(x) */
prec1 = prec + 8;
/* increase the precision in x^2 to compensate the cancellation in
(1-x^2) if x is close to 1 */
/* XXX: use less precision when possible */
if (a->expn >= 0)
prec2 = BF_PREC_INF;
else
prec2 = prec1;
bf_init(s, T);
bf_mul(T, a, a, prec2, BF_RNDN);
bf_neg(T);
bf_add_si(T, T, 1, prec2, BF_RNDN);
bf_sqrt(r, T, prec1, BF_RNDN);
bf_div(T, a, r, prec1, BF_RNDN);
if (is_acos)
bf_neg(T);
bf_atan_internal(r, T, prec1, (void *)(intptr_t)is_acos);
bf_delete(T);
return BF_ST_INEXACT;
}
int bf_asin(bf_t *r, const bf_t *a, limb_t prec, bf_flags_t flags)
{
bf_context_t *s = r->ctx;
bf_t T_s, *T = &T_s;
int res;
if (a->len == 0) {
if (a->expn == BF_EXP_NAN) {
bf_set_nan(r);
return 0;
} else if (a->expn == BF_EXP_INF) {
bf_set_nan(r);
return BF_ST_INVALID_OP;
} else {
bf_set_zero(r, a->sign);
return 0;
}
}
bf_init(s, T);
bf_set_ui(T, 1);
res = bf_cmpu(a, T);
bf_delete(T);
if (res > 0) {
bf_set_nan(r);
return BF_ST_INVALID_OP;
}
/* small argument case: result = x+r(x) with r(x) = x^3/6 +
O(X^5). We assume r(x) < 2^(3*EXP(x) - 2). */
if (a->expn < 0) {
slimb_t e;
e = sat_add(2 * a->expn, a->expn - 2);
if (e < a->expn - bf_max(prec + 2, a->len * LIMB_BITS + 2)) {
bf_set(r, a);
return bf_add_epsilon(r, r, e, a->sign, prec, flags);
}
}
return bf_ziv_rounding(r, a, prec, flags, bf_asin_internal, (void *)FALSE);
}
int bf_acos(bf_t *r, const bf_t *a, limb_t prec, bf_flags_t flags)
{
bf_context_t *s = r->ctx;
bf_t T_s, *T = &T_s;
int res;
if (a->len == 0) {
if (a->expn == BF_EXP_NAN) {
bf_set_nan(r);
return 0;
} else if (a->expn == BF_EXP_INF) {
bf_set_nan(r);
return BF_ST_INVALID_OP;
} else {
bf_const_pi(r, prec, flags);
bf_mul_2exp(r, -1, BF_PREC_INF, BF_RNDZ);
return BF_ST_INEXACT;
}
}
bf_init(s, T);
bf_set_ui(T, 1);
res = bf_cmpu(a, T);
bf_delete(T);
if (res > 0) {
bf_set_nan(r);
return BF_ST_INVALID_OP;
} else if (res == 0 && a->sign == 0) {
bf_set_zero(r, 0);
return 0;
}
return bf_ziv_rounding(r, a, prec, flags, bf_asin_internal, (void *)TRUE);
}
/***************************************************************/
/* decimal floating point numbers */
#ifdef USE_BF_DEC
#define adddq(r1, r0, a1, a0) \
do { \
limb_t __t = r0; \
r0 += (a0); \
r1 += (a1) + (r0 < __t); \
} while (0)
#define subdq(r1, r0, a1, a0) \
do { \
limb_t __t = r0; \
r0 -= (a0); \
r1 -= (a1) + (r0 > __t); \
} while (0)
#if LIMB_BITS == 64
/* Note: we assume __int128 is available */
#define muldq(r1, r0, a, b) \
do { \
unsigned __int128 __t; \
__t = (unsigned __int128)(a) * (unsigned __int128)(b); \
r0 = __t; \
r1 = __t >> 64; \
} while (0)
#define divdq(q, r, a1, a0, b) \
do { \
unsigned __int128 __t; \
limb_t __b = (b); \
__t = ((unsigned __int128)(a1) << 64) | (a0); \
q = __t / __b; \
r = __t % __b; \
} while (0)
#else
#define muldq(r1, r0, a, b) \
do { \
uint64_t __t; \
__t = (uint64_t)(a) * (uint64_t)(b); \
r0 = __t; \
r1 = __t >> 32; \
} while (0)
#define divdq(q, r, a1, a0, b) \
do { \
uint64_t __t; \
limb_t __b = (b); \
__t = ((uint64_t)(a1) << 32) | (a0); \
q = __t / __b; \
r = __t % __b; \
} while (0)
#endif /* LIMB_BITS != 64 */
static inline __maybe_unused limb_t shrd(limb_t low, limb_t high, long shift)
{
if (shift != 0)
low = (low >> shift) | (high << (LIMB_BITS - shift));
return low;
}
static inline __maybe_unused limb_t shld(limb_t a1, limb_t a0, long shift)
{
if (shift != 0)
return (a1 << shift) | (a0 >> (LIMB_BITS - shift));
else
return a1;
}
#if LIMB_DIGITS == 19
/* WARNING: hardcoded for b = 1e19. It is assumed that:
0 <= a1 < 2^63 */
#define divdq_base(q, r, a1, a0)\
do {\
uint64_t __a0, __a1, __t0, __t1, __b = BF_DEC_BASE; \
__a0 = a0;\
__a1 = a1;\
__t0 = __a1;\
__t0 = shld(__t0, __a0, 1);\
muldq(q, __t1, __t0, UINT64_C(17014118346046923173)); \
muldq(__t1, __t0, q, __b);\
subdq(__a1, __a0, __t1, __t0);\
subdq(__a1, __a0, 1, __b * 2); \
__t0 = (slimb_t)__a1 >> 1; \
q += 2 + __t0;\
adddq(__a1, __a0, 0, __b & __t0);\
q += __a1; \
__a0 += __b & __a1; \
r = __a0;\
} while(0)
#elif LIMB_DIGITS == 9
/* WARNING: hardcoded for b = 1e9. It is assumed that:
0 <= a1 < 2^29 */
#define divdq_base(q, r, a1, a0)\
do {\
uint32_t __t0, __t1, __b = BF_DEC_BASE; \
__t0 = a1;\
__t1 = a0;\
__t0 = (__t0 << 3) | (__t1 >> (32 - 3)); \
muldq(q, __t1, __t0, 2305843009U);\
r = a0 - q * __b;\
__t1 = (r >= __b);\
q += __t1;\
if (__t1)\
r -= __b;\
} while(0)
#endif
/* fast integer division by a fixed constant */
typedef struct FastDivData {
limb_t m1; /* multiplier */
int8_t shift1;
int8_t shift2;
} FastDivData;
/* From "Division by Invariant Integers using Multiplication" by
Torborn Granlund and Peter L. Montgomery */
/* d must be != 0 */
static inline __maybe_unused void fast_udiv_init(FastDivData *s, limb_t d)
{
int l;
limb_t q, r, m1;
if (d == 1)
l = 0;
else
l = 64 - clz64(d - 1);
divdq(q, r, ((limb_t)1 << l) - d, 0, d);
(void)r;
m1 = q + 1;
// printf("d=%lu l=%d m1=0x%016lx\n", d, l, m1);
s->m1 = m1;
s->shift1 = l;
if (s->shift1 > 1)
s->shift1 = 1;
s->shift2 = l - 1;
if (s->shift2 < 0)
s->shift2 = 0;
}
static inline limb_t fast_udiv(limb_t a, const FastDivData *s)
{
limb_t t0, t1;
muldq(t1, t0, s->m1, a);
t0 = (a - t1) >> s->shift1;
return (t1 + t0) >> s->shift2;
}
/* contains 10^i */
const limb_t mp_pow_dec[LIMB_DIGITS + 1] = {
1U,
10U,
100U,
1000U,
10000U,
100000U,
1000000U,
10000000U,
100000000U,
1000000000U,
#if LIMB_BITS == 64
10000000000U,
100000000000U,
1000000000000U,
10000000000000U,
100000000000000U,
1000000000000000U,
10000000000000000U,
100000000000000000U,
1000000000000000000U,
10000000000000000000U,
#endif
};
/* precomputed from fast_udiv_init(10^i) */
static const FastDivData mp_pow_div[LIMB_DIGITS + 1] = {
#if LIMB_BITS == 32
{ 0x00000001, 0, 0 },
{ 0x9999999a, 1, 3 },
{ 0x47ae147b, 1, 6 },
{ 0x0624dd30, 1, 9 },
{ 0xa36e2eb2, 1, 13 },
{ 0x4f8b588f, 1, 16 },
{ 0x0c6f7a0c, 1, 19 },
{ 0xad7f29ac, 1, 23 },
{ 0x5798ee24, 1, 26 },
{ 0x12e0be83, 1, 29 },
#else
{ 0x0000000000000001, 0, 0 },
{ 0x999999999999999a, 1, 3 },
{ 0x47ae147ae147ae15, 1, 6 },
{ 0x0624dd2f1a9fbe77, 1, 9 },
{ 0xa36e2eb1c432ca58, 1, 13 },
{ 0x4f8b588e368f0847, 1, 16 },
{ 0x0c6f7a0b5ed8d36c, 1, 19 },
{ 0xad7f29abcaf48579, 1, 23 },
{ 0x5798ee2308c39dfa, 1, 26 },
{ 0x12e0be826d694b2f, 1, 29 },
{ 0xb7cdfd9d7bdbab7e, 1, 33 },
{ 0x5fd7fe17964955fe, 1, 36 },
{ 0x19799812dea11198, 1, 39 },
{ 0xc25c268497681c27, 1, 43 },
{ 0x6849b86a12b9b01f, 1, 46 },
{ 0x203af9ee756159b3, 1, 49 },
{ 0xcd2b297d889bc2b7, 1, 53 },
{ 0x70ef54646d496893, 1, 56 },
{ 0x2725dd1d243aba0f, 1, 59 },
{ 0xd83c94fb6d2ac34d, 1, 63 },
#endif
};
/* divide by 10^shift with 0 <= shift <= LIMB_DIGITS */
static inline limb_t fast_shr_dec(limb_t a, int shift)
{
return fast_udiv(a, &mp_pow_div[shift]);
}
/* division and remainder by 10^shift */
#define fast_shr_rem_dec(q, r, a, shift) q = fast_shr_dec(a, shift), r = a - q * mp_pow_dec[shift]
limb_t mp_add_dec(limb_t *res, const limb_t *op1, const limb_t *op2,
mp_size_t n, limb_t carry)
{
limb_t base = BF_DEC_BASE;
mp_size_t i;
limb_t k, a, v;
k=carry;
for(i=0;i<n;i++) {
/* XXX: reuse the trick in add_mod */
v = op1[i];
a = v + op2[i] + k - base;
k = a <= v;
if (!k)
a += base;
res[i]=a;
}
return k;
}
limb_t mp_add_ui_dec(limb_t *tab, limb_t b, mp_size_t n)
{
limb_t base = BF_DEC_BASE;
mp_size_t i;
limb_t k, a, v;
k=b;
for(i=0;i<n;i++) {
v = tab[i];
a = v + k - base;
k = a <= v;
if (!k)
a += base;
tab[i] = a;
if (k == 0)
break;
}
return k;
}
limb_t mp_sub_dec(limb_t *res, const limb_t *op1, const limb_t *op2,
mp_size_t n, limb_t carry)
{
limb_t base = BF_DEC_BASE;
mp_size_t i;
limb_t k, v, a;
k=carry;
for(i=0;i<n;i++) {
v = op1[i];
a = v - op2[i] - k;
k = a > v;
if (k)
a += base;
res[i] = a;
}
return k;
}
limb_t mp_sub_ui_dec(limb_t *tab, limb_t b, mp_size_t n)
{
limb_t base = BF_DEC_BASE;
mp_size_t i;
limb_t k, v, a;
k=b;
for(i=0;i<n;i++) {
v = tab[i];
a = v - k;
k = a > v;
if (k)
a += base;
tab[i]=a;
if (k == 0)
break;
}
return k;
}
/* taba[] = taba[] * b + l. 0 <= b, l <= base - 1. Return the high carry */
limb_t mp_mul1_dec(limb_t *tabr, const limb_t *taba, mp_size_t n,
limb_t b, limb_t l)
{
mp_size_t i;
limb_t t0, t1, r;
for(i = 0; i < n; i++) {
muldq(t1, t0, taba[i], b);
adddq(t1, t0, 0, l);
divdq_base(l, r, t1, t0);
tabr[i] = r;
}
return l;
}
/* tabr[] += taba[] * b. 0 <= b <= base - 1. Return the value to add
to the high word */
limb_t mp_add_mul1_dec(limb_t *tabr, const limb_t *taba, mp_size_t n,
limb_t b)
{
mp_size_t i;
limb_t l, t0, t1, r;
l = 0;
for(i = 0; i < n; i++) {
muldq(t1, t0, taba[i], b);
adddq(t1, t0, 0, l);
adddq(t1, t0, 0, tabr[i]);
divdq_base(l, r, t1, t0);
tabr[i] = r;
}
return l;
}
/* tabr[] -= taba[] * b. 0 <= b <= base - 1. Return the value to
substract to the high word. */
limb_t mp_sub_mul1_dec(limb_t *tabr, const limb_t *taba, mp_size_t n,
limb_t b)
{
limb_t base = BF_DEC_BASE;
mp_size_t i;
limb_t l, t0, t1, r, a, v, c;
/* XXX: optimize */
l = 0;
for(i = 0; i < n; i++) {
muldq(t1, t0, taba[i], b);
adddq(t1, t0, 0, l);
divdq_base(l, r, t1, t0);
v = tabr[i];
a = v - r;
c = a > v;
if (c)
a += base;
gitextract_q0zhqzu1/ ├── .gitattributes ├── .gitignore ├── LICENSE ├── README.md ├── bridge.c ├── bridge.h ├── cutils.c ├── cutils.h ├── examples/ │ └── main.go ├── go.mod ├── go.sum ├── libbf.c ├── libbf.h ├── libregexp-opcode.h ├── libregexp.c ├── libregexp.h ├── libunicode-table.h ├── libunicode.c ├── libunicode.h ├── list.h ├── quickjs-atom.h ├── quickjs-opcode.h ├── quickjs.c ├── quickjs.go ├── quickjs.h ├── quickjs_test.go └── version.h
Showing preview only (209K chars total). Download the full file or copy to clipboard to get everything.
SYMBOL INDEX (2200 symbols across 17 files)
FILE: bridge.c
function JSValue (line 3) | JSValue InvokeProxy(JSContext *ctx, JSValueConst this_val, int argc, JSV...
FILE: bridge.h
function JSValue (line 6) | static JSValue JS_NewNull() { return JS_NULL; }
function JSValue (line 7) | static JSValue JS_NewUndefined() { return JS_UNDEFINED; }
function JSValue (line 8) | static JSValue JS_NewUninitialized() { return JS_UNINITIALIZED; }
function JSValue (line 10) | static JSValue ThrowSyntaxError(JSContext *ctx, const char *fmt) { retur...
function JSValue (line 11) | static JSValue ThrowTypeError(JSContext *ctx, const char *fmt) { return ...
function JSValue (line 12) | static JSValue ThrowReferenceError(JSContext *ctx, const char *fmt) { re...
function JSValue (line 13) | static JSValue ThrowRangeError(JSContext *ctx, const char *fmt) { return...
function JSValue (line 14) | static JSValue ThrowInternalError(JSContext *ctx, const char *fmt) { ret...
FILE: cutils.c
function pstrcpy (line 32) | void pstrcpy(char *buf, int buf_size, const char *str)
function strstart (line 59) | int strstart(const char *str, const char *val, const char **ptr)
function has_suffix (line 75) | int has_suffix(const char *str, const char *suffix)
function dbuf_init2 (line 89) | void dbuf_init2(DynBuf *s, void *opaque, DynBufReallocFunc *realloc_func)
function dbuf_init (line 98) | void dbuf_init(DynBuf *s)
function dbuf_realloc (line 104) | int dbuf_realloc(DynBuf *s, size_t new_size)
function dbuf_write (line 125) | int dbuf_write(DynBuf *s, size_t offset, const uint8_t *data, size_t len)
function dbuf_put (line 137) | int dbuf_put(DynBuf *s, const uint8_t *data, size_t len)
function dbuf_put_self (line 148) | int dbuf_put_self(DynBuf *s, size_t offset, size_t len)
function dbuf_putc (line 159) | int dbuf_putc(DynBuf *s, uint8_t c)
function dbuf_putstr (line 164) | int dbuf_putstr(DynBuf *s, const char *str)
function dbuf_printf (line 169) | int __attribute__((format(printf, 2, 3))) dbuf_printf(DynBuf *s,
function dbuf_free (line 194) | void dbuf_free(DynBuf *s)
function unicode_to_utf8 (line 206) | int unicode_to_utf8(uint8_t *buf, unsigned int c)
function unicode_from_utf8 (line 251) | int unicode_from_utf8(const uint8_t *p, int max_len, const uint8_t **pp)
function rqsort_cmp2 (line 302) | static int rqsort_cmp2(const void *p1, const void *p2)
function rqsort (line 308) | void rqsort(void *base, size_t nmemb, size_t size,
function exchange_bytes (line 324) | static void exchange_bytes(void *a, void *b, size_t size) {
function exchange_one_byte (line 335) | static void exchange_one_byte(void *a, void *b, size_t size) {
function exchange_int16s (line 343) | static void exchange_int16s(void *a, void *b, size_t size) {
function exchange_one_int16 (line 354) | static void exchange_one_int16(void *a, void *b, size_t size) {
function exchange_int32s (line 362) | static void exchange_int32s(void *a, void *b, size_t size) {
function exchange_one_int32 (line 373) | static void exchange_one_int32(void *a, void *b, size_t size) {
function exchange_int64s (line 381) | static void exchange_int64s(void *a, void *b, size_t size) {
function exchange_one_int64 (line 392) | static void exchange_one_int64(void *a, void *b, size_t size) {
function exchange_int128s (line 400) | static void exchange_int128s(void *a, void *b, size_t size) {
function exchange_one_int128 (line 414) | static void exchange_one_int128(void *a, void *b, size_t size) {
function exchange_f (line 425) | static inline exchange_f exchange_func(const void *base, size_t size) {
function heapsortx (line 459) | static void heapsortx(void *base, size_t nmemb, size_t size, cmp_f cmp, ...
function rqsort (line 501) | void rqsort(void *base, size_t nmemb, size_t size, cmp_f cmp, void *opaque)
FILE: cutils.h
type BOOL (line 52) | typedef int BOOL;
function max_int (line 66) | static inline int max_int(int a, int b)
function min_int (line 74) | static inline int min_int(int a, int b)
function max_uint32 (line 82) | static inline uint32_t max_uint32(uint32_t a, uint32_t b)
function min_uint32 (line 90) | static inline uint32_t min_uint32(uint32_t a, uint32_t b)
function max_int64 (line 98) | static inline int64_t max_int64(int64_t a, int64_t b)
function min_int64 (line 106) | static inline int64_t min_int64(int64_t a, int64_t b)
function clz32 (line 115) | static inline int clz32(unsigned int a)
function clz64 (line 121) | static inline int clz64(uint64_t a)
function ctz32 (line 127) | static inline int ctz32(unsigned int a)
function ctz64 (line 133) | static inline int ctz64(uint64_t a)
type packed_u64 (line 138) | struct __attribute__((packed)) packed_u64 {
type packed_u32 (line 142) | struct __attribute__((packed)) packed_u32 {
type packed_u16 (line 146) | struct __attribute__((packed)) packed_u16 {
function get_u64 (line 150) | static inline uint64_t get_u64(const uint8_t *tab)
function get_i64 (line 155) | static inline int64_t get_i64(const uint8_t *tab)
function put_u64 (line 160) | static inline void put_u64(uint8_t *tab, uint64_t val)
function get_u32 (line 165) | static inline uint32_t get_u32(const uint8_t *tab)
function get_i32 (line 170) | static inline int32_t get_i32(const uint8_t *tab)
function put_u32 (line 175) | static inline void put_u32(uint8_t *tab, uint32_t val)
function get_u16 (line 180) | static inline uint32_t get_u16(const uint8_t *tab)
function get_i16 (line 185) | static inline int32_t get_i16(const uint8_t *tab)
function put_u16 (line 190) | static inline void put_u16(uint8_t *tab, uint16_t val)
function get_u8 (line 195) | static inline uint32_t get_u8(const uint8_t *tab)
function get_i8 (line 200) | static inline int32_t get_i8(const uint8_t *tab)
function put_u8 (line 205) | static inline void put_u8(uint8_t *tab, uint8_t val)
function bswap16 (line 210) | static inline uint16_t bswap16(uint16_t x)
function bswap32 (line 215) | static inline uint32_t bswap32(uint32_t v)
function bswap64 (line 221) | static inline uint64_t bswap64(uint64_t v)
type DynBuf (line 236) | typedef struct DynBuf {
function dbuf_put_u16 (line 253) | static inline int dbuf_put_u16(DynBuf *s, uint16_t val)
function dbuf_put_u32 (line 257) | static inline int dbuf_put_u32(DynBuf *s, uint32_t val)
function dbuf_put_u64 (line 261) | static inline int dbuf_put_u64(DynBuf *s, uint64_t val)
function BOOL (line 268) | static inline BOOL dbuf_error(DynBuf *s) {
function dbuf_set_error (line 271) | static inline void dbuf_set_error(DynBuf *s)
function from_hex (line 281) | static inline int from_hex(int c)
FILE: examples/main.go
function check (line 11) | func check(err error) {
function main (line 22) | func main() {
FILE: libbf.c
type mp_size_t (line 72) | typedef intptr_t mp_size_t;
function clz (line 94) | static inline int clz(limb_t a)
function ctz (line 107) | static inline int ctz(limb_t a)
function ceil_log2 (line 120) | static inline int ceil_log2(limb_t a)
function slimb_t (line 129) | static inline slimb_t ceil_div(slimb_t a, slimb_t b)
function slimb_t (line 138) | static inline slimb_t floor_div(slimb_t a, slimb_t b)
function limb_t (line 148) | static inline limb_t smod(slimb_t a, slimb_t b)
function slimb_t (line 157) | static inline slimb_t sat_add(slimb_t a, slimb_t b)
function bf_context_init (line 171) | void bf_context_init(bf_context_t *s, bf_realloc_func_t *realloc_func,
function bf_context_end (line 179) | void bf_context_end(bf_context_t *s)
function bf_init (line 184) | void bf_init(bf_context_t *s, bf_t *r)
function bf_resize (line 194) | int bf_resize(bf_t *r, limb_t len)
function bf_set_ui (line 209) | int bf_set_ui(bf_t *r, uint64_t a)
function bf_set_si (line 250) | int bf_set_si(bf_t *r, int64_t a)
function bf_set_nan (line 263) | void bf_set_nan(bf_t *r)
function bf_set_zero (line 270) | void bf_set_zero(bf_t *r, int is_neg)
function bf_set_inf (line 277) | void bf_set_inf(bf_t *r, int is_neg)
function bf_set (line 285) | int bf_set(bf_t *r, const bf_t *a)
function bf_move (line 300) | void bf_move(bf_t *r, bf_t *a)
function limb_t (line 309) | static limb_t get_limbz(const bf_t *a, limb_t idx)
function limb_t (line 318) | static inline limb_t get_bits(const limb_t *tab, limb_t len, slimb_t pos)
function limb_t (line 341) | static inline limb_t get_bit(const limb_t *tab, limb_t len, slimb_t pos)
function limb_t (line 350) | static inline limb_t limb_mask(int start, int last)
function limb_t (line 362) | static limb_t mp_scan_nz(const limb_t *tab, mp_size_t n)
function limb_t (line 373) | static inline limb_t scan_bit_nz(const bf_t *r, slimb_t bit_pos)
function bf_get_rnd_add (line 395) | static int bf_get_rnd_add(int *pret, const bf_t *r, limb_t l,
function bf_set_overflow (line 448) | static int bf_set_overflow(bf_t *r, int sign, limb_t prec, bf_flags_t fl...
function __bf_round (line 484) | static int __bf_round(bf_t *r, limb_t prec1, bf_flags_t flags, limb_t l,
function bf_normalize_and_round (line 592) | int bf_normalize_and_round(bf_t *r, limb_t prec1, bf_flags_t flags)
function bf_can_round (line 631) | int bf_can_round(const bf_t *a, slimb_t prec, bf_rnd_t rnd_mode, slimb_t k)
function bf_round (line 667) | int bf_round(bf_t *r, limb_t prec, bf_flags_t flags)
function __maybe_unused (line 675) | static __maybe_unused void dump_limbs(const char *str, const limb_t *tab...
function mp_print_str (line 685) | void mp_print_str(const char *str, const limb_t *tab, limb_t n)
function __maybe_unused (line 697) | static __maybe_unused void mp_print_str_h(const char *str,
function bf_print_str (line 712) | void bf_print_str(const char *str, const bf_t *a)
function bf_cmpu (line 738) | int bf_cmpu(const bf_t *a, const bf_t *b)
function bf_cmp_full (line 764) | int bf_cmp_full(const bf_t *a, const bf_t *b)
function bf_cmp (line 788) | int bf_cmp(const bf_t *a, const bf_t *b)
function limb_t (line 816) | static limb_t count_cancelled_bits(const bf_t *a, const bf_t *b)
function bf_add_internal (line 868) | static int bf_add_internal(bf_t *r, const bf_t *a, const bf_t *b, limb_t...
function __bf_add (line 1012) | static int __bf_add(bf_t *r, const bf_t *a, const bf_t *b, limb_t prec,
function __bf_sub (line 1018) | static int __bf_sub(bf_t *r, const bf_t *a, const bf_t *b, limb_t prec,
function limb_t (line 1024) | limb_t mp_add(limb_t *res, const limb_t *op1, const limb_t *op2,
function limb_t (line 1042) | limb_t mp_add_ui(limb_t *tab, limb_t b, size_t n)
function limb_t (line 1058) | limb_t mp_sub(limb_t *res, const limb_t *op1, const limb_t *op2,
function limb_t (line 1077) | static limb_t mp_neg(limb_t *res, const limb_t *op2, mp_size_t n, limb_t...
function limb_t (line 1094) | limb_t mp_sub_ui(limb_t *tab, limb_t b, mp_size_t n)
function limb_t (line 1113) | static limb_t mp_shr(limb_t *tab_r, const limb_t *tab, mp_size_t n,
function limb_t (line 1130) | static limb_t mp_mul1(limb_t *tabr, const limb_t *taba, limb_t n,
function limb_t (line 1145) | static limb_t mp_add_mul1(limb_t *tabr, const limb_t *taba, limb_t n,
function mp_mul_basecase (line 1161) | static void mp_mul_basecase(limb_t *result,
function mp_mul (line 1176) | int mp_mul(bf_context_t *s, limb_t *result,
function limb_t (line 1198) | static limb_t mp_sub_mul1(limb_t *tabr, const limb_t *taba, limb_t n,
function limb_t (line 1214) | static inline limb_t udiv1norm_init(limb_t d)
function limb_t (line 1224) | static inline limb_t udiv1norm(limb_t *pr, limb_t a1, limb_t a0,
function limb_t (line 1245) | static limb_t mp_div1norm(limb_t *tabr, const limb_t *taba, limb_t n,
function mp_divnorm (line 1275) | static int mp_divnorm(bf_context_t *s, limb_t *tabq, limb_t *taba, limb_...
function mp_recip (line 1351) | int mp_recip(bf_context_t *s, limb_t *tabr, const limb_t *taba, limb_t n)
function mp_cmp (line 1415) | static int mp_cmp(const limb_t *taba, const limb_t *tabb, mp_size_t n)
function mp_divnorm_large (line 1433) | static int mp_divnorm_large(bf_context_t *s,
function bf_mul (line 1524) | int bf_mul(bf_t *r, const bf_t *a, const bf_t *b, limb_t prec,
function bf_mul_2exp (line 1606) | int bf_mul_2exp(bf_t *r, slimb_t e, limb_t prec, bf_flags_t flags)
function slimb_t (line 1620) | slimb_t bf_get_exp_min(const bf_t *a)
function bf_tdivremu (line 1638) | static void bf_tdivremu(bf_t *q, bf_t *r,
function __bf_div (line 1652) | static int __bf_div(bf_t *r, const bf_t *a, const bf_t *b, limb_t prec,
function bf_divrem (line 1732) | int bf_divrem(bf_t *q, bf_t *r, const bf_t *a, const bf_t *b,
function bf_rem (line 1826) | int bf_rem(bf_t *r, const bf_t *a, const bf_t *b, limb_t prec,
function bf_get_limb (line 1838) | static inline int bf_get_limb(slimb_t *pres, const bf_t *a, int flags)
function bf_remquo (line 1847) | int bf_remquo(slimb_t *pq, bf_t *r, const bf_t *a, const bf_t *b, limb_t...
function __maybe_unused (line 1860) | static __maybe_unused inline limb_t mul_mod(limb_t a, limb_t b, limb_t m)
function limb_t (line 1868) | static limb_t mp_mod1(const limb_t *tab, limb_t n, limb_t m, limb_t r)
function limb_t (line 1887) | static limb_t mp_sqrtrem1(limb_t *pr, limb_t a)
function limb_t (line 1931) | limb_t bf_isqrt(limb_t a)
function limb_t (line 1944) | static limb_t mp_sqrtrem2(limb_t *tabs, limb_t *taba)
function mp_sqrtrem_rec (line 1976) | static int mp_sqrtrem_rec(bf_context_t *s, limb_t *tabs, limb_t *taba, l...
function mp_sqrtrem (line 2050) | int mp_sqrtrem(bf_context_t *s, limb_t *tabs, limb_t *taba, limb_t n)
function bf_sqrtrem (line 2073) | int bf_sqrtrem(bf_t *r, bf_t *rem1, const bf_t *a)
function bf_sqrt (line 2126) | int bf_sqrt(bf_t *r, const bf_t *a, limb_t prec, bf_flags_t flags)
function no_inline (line 2190) | static no_inline int bf_op2(bf_t *r, const bf_t *a, const bf_t *b, limb_...
function bf_add (line 2206) | int bf_add(bf_t *r, const bf_t *a, const bf_t *b, limb_t prec,
function bf_sub (line 2212) | int bf_sub(bf_t *r, const bf_t *a, const bf_t *b, limb_t prec,
function bf_div (line 2218) | int bf_div(bf_t *r, const bf_t *a, const bf_t *b, limb_t prec,
function bf_mul_ui (line 2224) | int bf_mul_ui(bf_t *r, const bf_t *a, uint64_t b1, limb_t prec,
function bf_mul_si (line 2236) | int bf_mul_si(bf_t *r, const bf_t *a, int64_t b1, limb_t prec,
function bf_add_si (line 2248) | int bf_add_si(bf_t *r, const bf_t *a, int64_t b1, limb_t prec,
function bf_pow_ui (line 2261) | static int bf_pow_ui(bf_t *r, const bf_t *a, limb_t b, limb_t prec,
function bf_pow_ui_ui (line 2279) | static int bf_pow_ui_ui(bf_t *r, limb_t a1, limb_t b,
function bf_rint (line 2299) | int bf_rint(bf_t *r, int rnd_mode)
function limb_t (line 2309) | static inline limb_t bf_logic_op1(limb_t a, limb_t b, int op)
function bf_logic_op (line 2322) | static int bf_logic_op(bf_t *r, const bf_t *a1, const bf_t *b1, int op)
function bf_logic_or (line 2409) | int bf_logic_or(bf_t *r, const bf_t *a, const bf_t *b)
function bf_logic_xor (line 2415) | int bf_logic_xor(bf_t *r, const bf_t *a, const bf_t *b)
function bf_logic_and (line 2421) | int bf_logic_and(bf_t *r, const bf_t *a, const bf_t *b)
type Float64Union (line 2428) | typedef union {
function bf_get_float64 (line 2433) | int bf_get_float64(const bf_t *a, double *pres, bf_rnd_t rnd_mode)
function bf_set_float64 (line 2482) | int bf_set_float64(bf_t *a, double d)
function bf_get_int32 (line 2533) | int bf_get_int32(int *pres, const bf_t *a, int flags)
function bf_get_int64 (line 2577) | int bf_get_int64(int64_t *pres, const bf_t *a, int flags)
function bf_get_uint64 (line 2638) | int bf_get_uint64(uint64_t *pres, const bf_t *a)
function limb_t (line 2680) | static limb_t get_limb_radix(int radix)
function bf_integer_from_radix_rec (line 2693) | static int bf_integer_from_radix_rec(bf_t *r, const limb_t *tab,
function bf_integer_from_radix (line 2732) | static int bf_integer_from_radix(bf_t *r, const limb_t *tab,
function bf_mul_pow_radix (line 2756) | int bf_mul_pow_radix(bf_t *r, const bf_t *T, limb_t radix,
function to_digit (line 2820) | static inline int to_digit(int c)
function bf_add_limb (line 2834) | static int bf_add_limb(bf_t *a, slimb_t *ppos, limb_t v)
function bf_tolower (line 2855) | static int bf_tolower(int c)
function strcasestart (line 2862) | static int strcasestart(const char *str, const char *val, const char **ptr)
function bf_atof_internal (line 2878) | static int bf_atof_internal(bf_t *r, slimb_t *pexponent,
function bf_atof2 (line 3137) | int bf_atof2(bf_t *r, slimb_t *pexponent,
function bf_atof (line 3145) | int bf_atof(bf_t *r, const char *str, const char **pnext, int radix,
function slimb_t (line 3315) | slimb_t bf_mul_log2_radix(slimb_t a1, unsigned int radix, int is_inv,
function bf_integer_to_radix_rec (line 3373) | static int bf_integer_to_radix_rec(bf_t *pow_tab,
function bf_integer_to_radix (line 3459) | static int bf_integer_to_radix(bf_t *r, const bf_t *a, limb_t radixl)
function bf_convert_to_radix (line 3487) | static int bf_convert_to_radix(bf_t *r, slimb_t *pE,
function limb_to_a (line 3570) | static void limb_to_a(char *buf, limb_t n, unsigned int radix, int len)
function limb_to_a2 (line 3595) | static void limb_to_a2(char *buf, limb_t n, unsigned int radix_bits, int...
function output_digits (line 3616) | static void output_digits(DynBuf *s, const bf_t *a1, int radix, limb_t n...
function bf_const_log2_rec (line 4004) | static void bf_const_log2_rec(bf_t *T, bf_t *P, bf_t *Q, limb_t n1,
function bf_const_log2_internal (line 4043) | static void bf_const_log2_internal(bf_t *T, limb_t prec)
function chud_bs (line 4066) | static void chud_bs(bf_t *P, bf_t *Q, bf_t *G, int64_t a, int64_t b, int...
function bf_const_pi_internal (line 4124) | static void bf_const_pi_internal(bf_t *Q, limb_t prec)
function bf_const_get (line 4152) | static int bf_const_get(bf_t *T, limb_t prec, bf_flags_t flags,
function bf_const_free (line 4181) | static void bf_const_free(BFConstCache *c)
function bf_const_log2 (line 4187) | int bf_const_log2(bf_t *T, limb_t prec, bf_flags_t flags)
function bf_const_pi_signed (line 4194) | static int bf_const_pi_signed(bf_t *T, int sign, limb_t prec, bf_flags_t...
function bf_const_pi (line 4201) | int bf_const_pi(bf_t *T, limb_t prec, bf_flags_t flags)
function bf_clear_cache (line 4206) | void bf_clear_cache(bf_context_t *s)
function bf_ziv_rounding (line 4220) | static int bf_ziv_rounding(bf_t *r, const bf_t *a,
function bf_add_epsilon (line 4263) | static int bf_add_epsilon(bf_t *r, const bf_t *a, slimb_t e, int e_sign,
function bf_exp_internal (line 4280) | static int bf_exp_internal(bf_t *r, const bf_t *a, limb_t prec, void *op...
function check_exp_underflow_overflow (line 4350) | static int check_exp_underflow_overflow(bf_context_t *s, bf_t *r,
function bf_exp (line 4400) | int bf_exp(bf_t *r, const bf_t *a, limb_t prec, bf_flags_t flags)
function bf_log_internal (line 4431) | static int bf_log_internal(bf_t *r, const bf_t *a, limb_t prec, void *op...
function bf_log (line 4530) | int bf_log(bf_t *r, const bf_t *a, limb_t prec, bf_flags_t flags)
function bf_pow_generic (line 4570) | static int bf_pow_generic(bf_t *r, const bf_t *x, limb_t prec, void *opa...
function bf_pow_int (line 4591) | static int bf_pow_int(bf_t *r, const bf_t *x, limb_t prec, void *opaque)
function BOOL (line 4618) | static BOOL check_exact_power2n(bf_t *r, const bf_t *x, slimb_t n)
function bf_pow (line 4656) | int bf_pow(bf_t *r, const bf_t *x, const bf_t *y, limb_t prec, bf_flags_...
function bf_sqrt_sin (line 4827) | static void bf_sqrt_sin(bf_t *r, const bf_t *x, limb_t prec1)
function bf_sincos (line 4841) | static int bf_sincos(bf_t *s, bf_t *c, const bf_t *a, limb_t prec)
function bf_cos_internal (line 4938) | static int bf_cos_internal(bf_t *r, const bf_t *a, limb_t prec, void *op...
function bf_cos (line 4943) | int bf_cos(bf_t *r, const bf_t *a, limb_t prec, bf_flags_t flags)
function bf_sin_internal (line 4972) | static int bf_sin_internal(bf_t *r, const bf_t *a, limb_t prec, void *op...
function bf_sin (line 4977) | int bf_sin(bf_t *r, const bf_t *a, limb_t prec, bf_flags_t flags)
function bf_tan_internal (line 5006) | static int bf_tan_internal(bf_t *r, const bf_t *a, limb_t prec, void *op...
function bf_tan (line 5021) | int bf_tan(bf_t *r, const bf_t *a, limb_t prec, bf_flags_t flags)
function bf_atan_internal (line 5053) | static int bf_atan_internal(bf_t *r, const bf_t *a, limb_t prec,
function bf_atan (line 5139) | int bf_atan(bf_t *r, const bf_t *a, limb_t prec, bf_flags_t flags)
function bf_atan2_internal (line 5185) | static int bf_atan2_internal(bf_t *r, const bf_t *y, limb_t prec, void *...
function bf_atan2 (line 5223) | int bf_atan2(bf_t *r, const bf_t *y, const bf_t *x,
function bf_asin_internal (line 5229) | static int bf_asin_internal(bf_t *r, const bf_t *a, limb_t prec, void *o...
function bf_asin (line 5260) | int bf_asin(bf_t *r, const bf_t *a, limb_t prec, bf_flags_t flags)
function bf_acos (line 5301) | int bf_acos(bf_t *r, const bf_t *a, limb_t prec, bf_flags_t flags)
function __maybe_unused (line 5395) | static inline __maybe_unused limb_t shrd(limb_t low, limb_t high, long s...
function __maybe_unused (line 5402) | static inline __maybe_unused limb_t shld(limb_t a1, limb_t a0, long shift)
type FastDivData (line 5455) | typedef struct FastDivData {
function __maybe_unused (line 5464) | static inline __maybe_unused void fast_udiv_init(FastDivData *s, limb_t d)
function limb_t (line 5485) | static inline limb_t fast_udiv(limb_t a, const FastDivData *s)
function limb_t (line 5557) | static inline limb_t fast_shr_dec(limb_t a, int shift)
function limb_t (line 5565) | limb_t mp_add_dec(limb_t *res, const limb_t *op1, const limb_t *op2,
function limb_t (line 5585) | limb_t mp_add_ui_dec(limb_t *tab, limb_t b, mp_size_t n)
function limb_t (line 5605) | limb_t mp_sub_dec(limb_t *res, const limb_t *op1, const limb_t *op2,
function limb_t (line 5624) | limb_t mp_sub_ui_dec(limb_t *tab, limb_t b, mp_size_t n)
function limb_t (line 5645) | limb_t mp_mul1_dec(limb_t *tabr, const limb_t *taba, mp_size_t n,
function limb_t (line 5662) | limb_t mp_add_mul1_dec(limb_t *tabr, const limb_t *taba, mp_size_t n,
function limb_t (line 5681) | limb_t mp_sub_mul1_dec(limb_t *tabr, const limb_t *taba, mp_size_t n,
function mp_mul_basecase_dec (line 5707) | void mp_mul_basecase_dec(limb_t *result,
function limb_t (line 5724) | limb_t mp_div1_dec(limb_t *tabr, const limb_t *taba, mp_size_t na,
function __maybe_unused (line 5787) | static __maybe_unused void mp_print_str_dec(const char *str,
function __maybe_unused (line 5800) | static __maybe_unused void mp_print_str_h_dec(const char *str,
function mp_div_dec (line 5831) | static int mp_div_dec(bf_context_t *s, limb_t *tabq,
function limb_t (line 5937) | static limb_t mp_shr_dec(limb_t *tab_r, const limb_t *tab, mp_size_t n,
function limb_t (line 5955) | static limb_t mp_shl_dec(limb_t *tab_r, const limb_t *tab, mp_size_t n,
function limb_t (line 5972) | static limb_t mp_sqrtrem2_dec(limb_t *tabs, limb_t *taba)
function limb_t (line 5997) | static limb_t mp_sqrtrem_rec_dec(limb_t *tabs, limb_t *taba, limb_t n,
function mp_sqrtrem_dec (line 6063) | int mp_sqrtrem_dec(bf_context_t *s, limb_t *tabs, limb_t *taba, limb_t n)
function clz_dec (line 6083) | static int clz_dec(limb_t a)
function bfdec_print_str (line 6270) | void bfdec_print_str(const char *str, const bfdec_t *a)
function limb_t (line 6295) | static inline limb_t scan_digit_nz(const bfdec_t *r, slimb_t bit_pos)
function limb_t (line 6318) | static limb_t get_digit(const limb_t *tab, limb_t len, slimb_t pos)
function limb_t (line 6330) | static limb_t get_digits(const limb_t *tab, limb_t len, slimb_t pos)
function bfdec_get_rnd_add (line 6358) | static int bfdec_get_rnd_add(int *pret, const bfdec_t *r, limb_t l,
function __bfdec_round (line 6419) | static int __bfdec_round(bfdec_t *r, limb_t prec1, bf_flags_t flags, lim...
function bfdec_round (line 6519) | int bfdec_round(bfdec_t *r, limb_t prec, bf_flags_t flags)
function bfdec_normalize_and_round (line 6527) | int bfdec_normalize_and_round(bfdec_t *r, limb_t prec1, bf_flags_t flags)
function bfdec_set_ui (line 6556) | int bfdec_set_ui(bfdec_t *r, uint64_t v)
function bfdec_set_si (line 6588) | int bfdec_set_si(bfdec_t *r, int64_t v)
function bfdec_add_internal (line 6600) | static int bfdec_add_internal(bfdec_t *r, const bfdec_t *a, const bfdec_...
function __bfdec_add (line 6715) | static int __bfdec_add(bfdec_t *r, const bfdec_t *a, const bfdec_t *b, l...
function __bfdec_sub (line 6721) | static int __bfdec_sub(bfdec_t *r, const bfdec_t *a, const bfdec_t *b, l...
function bfdec_add (line 6727) | int bfdec_add(bfdec_t *r, const bfdec_t *a, const bfdec_t *b, limb_t prec,
function bfdec_sub (line 6734) | int bfdec_sub(bfdec_t *r, const bfdec_t *a, const bfdec_t *b, limb_t prec,
function bfdec_mul (line 6741) | int bfdec_mul(bfdec_t *r, const bfdec_t *a, const bfdec_t *b, limb_t prec,
function bfdec_mul_si (line 6801) | int bfdec_mul_si(bfdec_t *r, const bfdec_t *a, int64_t b1, limb_t prec,
function bfdec_add_si (line 6813) | int bfdec_add_si(bfdec_t *r, const bfdec_t *a, int64_t b1, limb_t prec,
function __bfdec_div (line 6826) | static int __bfdec_div(bfdec_t *r, const bfdec_t *a, const bfdec_t *b,
function bfdec_div (line 6919) | int bfdec_div(bfdec_t *r, const bfdec_t *a, const bfdec_t *b, limb_t prec,
function bfdec_tdivremu (line 6928) | static void bfdec_tdivremu(bf_context_t *s, bfdec_t *q, bfdec_t *r,
function bfdec_divrem (line 6949) | int bfdec_divrem(bfdec_t *q, bfdec_t *r, const bfdec_t *a, const bfdec_t...
function bfdec_rem (line 7054) | int bfdec_rem(bfdec_t *r, const bfdec_t *a, const bfdec_t *b, limb_t prec,
function bfdec_rint (line 7067) | int bfdec_rint(bfdec_t *r, int rnd_mode)
function bfdec_sqrt (line 7072) | int bfdec_sqrt(bfdec_t *r, const bfdec_t *a, limb_t prec, bf_flags_t flags)
function bfdec_get_int32 (line 7156) | int bfdec_get_int32(int *pres, const bfdec_t *a)
function bfdec_pow_ui (line 7204) | int bfdec_pow_ui(bfdec_t *r, const bfdec_t *a, limb_t b)
function bfdec_atof (line 7226) | int bfdec_atof(bfdec_t *r, const char *str, const char **pnext,
function put_bits (line 7241) | static inline void put_bits(limb_t *tab, limb_t len, slimb_t pos, limb_t...
type NTTLimb (line 7260) | typedef double NTTLimb;
type limb_t (line 7286) | typedef limb_t NTTLimb;
type BFNTTState (line 7345) | typedef struct BFNTTState {
function limb_t (line 7368) | static inline limb_t add_mod(limb_t a, limb_t b, limb_t m)
function limb_t (line 7378) | static inline limb_t sub_mod(limb_t a, limb_t b, limb_t m)
function limb_t (line 7390) | static inline limb_t mod_fast(dlimb_t r,
function limb_t (line 7410) | static inline limb_t mul_mod_fast(limb_t a, limb_t b,
function limb_t (line 7418) | static inline limb_t init_mul_mod_fast(limb_t m)
function limb_t (line 7429) | static inline limb_t mul_mod_fast2(limb_t a, limb_t b,
function limb_t (line 7444) | static inline limb_t mul_mod_fast3(limb_t a, limb_t b,
function limb_t (line 7454) | static inline limb_t init_mul_mod_fast2(limb_t b, limb_t m)
function limb_t (line 7461) | static inline limb_t ntt_limb_to_int(NTTLimb a, limb_t m)
function NTTLimb (line 7472) | static inline NTTLimb int_to_ntt_limb(limb_t a, limb_t m)
function NTTLimb (line 7477) | static inline NTTLimb int_to_ntt_limb2(limb_t a, limb_t m)
function __m256d (line 7485) | static inline __m256d ntt_mod1(__m256d r, __m256d m)
function __m256d (line 7491) | static inline __m256d ntt_mod(__m256d r, __m256d mf, __m256d m2f)
function __m256d (line 7497) | static inline __m256d ntt_mul_mod(__m256d a, __m256d b, __m256d mf,
function bf_aligned_free (line 7523) | static void bf_aligned_free(bf_context_t *s, void *ptr)
function ntt_free (line 7535) | static void ntt_free(BFNTTState *s, void *ptr)
function no_inline (line 7540) | static no_inline int ntt_fft(BFNTTState *s,
function ntt_vec_mul (line 7651) | static void ntt_vec_mul(BFNTTState *s,
function no_inline (line 7673) | static no_inline void mul_trig(NTTLimb *buf,
function ntt_free (line 7704) | static void ntt_free(BFNTTState *s, void *ptr)
function limb_t (line 7709) | static inline limb_t ntt_limb_to_int(NTTLimb a, limb_t m)
function NTTLimb (line 7716) | static inline NTTLimb int_to_ntt_limb(slimb_t a, limb_t m)
function no_inline (line 7721) | static no_inline int ntt_fft(BFNTTState *s, NTTLimb *out_buf, NTTLimb *i...
function ntt_vec_mul (line 7780) | static void ntt_vec_mul(BFNTTState *s,
function no_inline (line 7803) | static no_inline void mul_trig(NTTLimb *buf,
function no_inline (line 7818) | static no_inline NTTLimb *get_trig(BFNTTState *s,
function fft_clear_cache (line 7855) | void fft_clear_cache(bf_context_t *s1)
function ntt_fft_partial (line 7882) | static int ntt_fft_partial(BFNTTState *s, NTTLimb *buf1,
function ntt_conv (line 7940) | static int ntt_conv(BFNTTState *s, NTTLimb *buf1, NTTLimb *buf2,
function no_inline (line 7973) | static no_inline void limb_to_ntt(BFNTTState *s,
type VecUnion (line 8037) | typedef union {
function no_inline (line 8042) | static no_inline void ntt_to_limb(BFNTTState *s, limb_t *tabr, limb_t r_...
function no_inline (line 8146) | static no_inline void ntt_to_limb(BFNTTState *s, limb_t *tabr, limb_t r_...
function ntt_static_init (line 8246) | static int ntt_static_init(bf_context_t *s1)
function bf_get_fft_size (line 8308) | int bf_get_fft_size(int *pdpl, int *pnb_mods, limb_t len)
function no_inline (line 8358) | static no_inline int fft_mul(bf_context_t *s1,
function bf_get_fft_size (line 8461) | int bf_get_fft_size(int *pdpl, int *pnb_mods, limb_t len)
FILE: libbf.h
type __int128 (line 39) | typedef __int128 int128_t;
type uint128_t (line 40) | typedef unsigned __int128 uint128_t;
type slimb_t (line 41) | typedef int64_t slimb_t;
type limb_t (line 42) | typedef uint64_t limb_t;
type uint128_t (line 43) | typedef uint128_t dlimb_t;
type slimb_t (line 52) | typedef int32_t slimb_t;
type limb_t (line 53) | typedef uint32_t limb_t;
type dlimb_t (line 54) | typedef uint64_t dlimb_t;
type bf_t (line 91) | typedef struct {
type bfdec_t (line 99) | typedef struct {
type bf_rnd_t (line 108) | typedef enum {
type bf_flags_t (line 135) | typedef uint32_t bf_flags_t;
type BFConstCache (line 139) | typedef struct {
type bf_context_t (line 144) | typedef struct bf_context_t {
function bf_get_exp_bits (line 152) | static inline int bf_get_exp_bits(bf_flags_t flags)
function bf_flags_t (line 162) | static inline bf_flags_t bf_set_exp_bits(int n)
function slimb_t (line 178) | static inline slimb_t bf_max(slimb_t a, slimb_t b)
function slimb_t (line 186) | static inline slimb_t bf_min(slimb_t a, slimb_t b)
function bf_free (line 211) | static inline void bf_free(bf_context_t *s, void *ptr)
function bf_delete (line 220) | static inline void bf_delete(bf_t *r)
function bf_neg (line 229) | static inline void bf_neg(bf_t *r)
function bf_is_finite (line 234) | static inline int bf_is_finite(const bf_t *a)
function bf_is_nan (line 239) | static inline int bf_is_nan(const bf_t *a)
function bf_is_zero (line 244) | static inline int bf_is_zero(const bf_t *a)
function bf_memcpy (line 249) | static inline void bf_memcpy(bf_t *r, const bf_t *a)
function bf_cmp_eq (line 267) | static inline int bf_cmp_eq(const bf_t *a, const bf_t *b)
function bf_cmp_le (line 272) | static inline int bf_cmp_le(const bf_t *a, const bf_t *b)
function bf_cmp_lt (line 277) | static inline int bf_cmp_lt(const bf_t *a, const bf_t *b)
function bfdec_init (line 418) | static inline void bfdec_init(bf_context_t *s, bfdec_t *r)
function bfdec_delete (line 422) | static inline void bfdec_delete(bfdec_t *r)
function bfdec_neg (line 427) | static inline void bfdec_neg(bfdec_t *r)
function bfdec_is_finite (line 432) | static inline int bfdec_is_finite(const bfdec_t *a)
function bfdec_is_nan (line 437) | static inline int bfdec_is_nan(const bfdec_t *a)
function bfdec_is_zero (line 442) | static inline int bfdec_is_zero(const bfdec_t *a)
function bfdec_memcpy (line 447) | static inline void bfdec_memcpy(bfdec_t *r, const bfdec_t *a)
function bfdec_set_nan (line 455) | static inline void bfdec_set_nan(bfdec_t *r)
function bfdec_set_zero (line 459) | static inline void bfdec_set_zero(bfdec_t *r, int is_neg)
function bfdec_set_inf (line 463) | static inline void bfdec_set_inf(bfdec_t *r, int is_neg)
function bfdec_set (line 467) | static inline int bfdec_set(bfdec_t *r, const bfdec_t *a)
function bfdec_move (line 471) | static inline void bfdec_move(bfdec_t *r, bfdec_t *a)
function bfdec_cmpu (line 475) | static inline int bfdec_cmpu(const bfdec_t *a, const bfdec_t *b)
function bfdec_cmp_full (line 479) | static inline int bfdec_cmp_full(const bfdec_t *a, const bfdec_t *b)
function bfdec_cmp (line 483) | static inline int bfdec_cmp(const bfdec_t *a, const bfdec_t *b)
function bfdec_cmp_eq (line 487) | static inline int bfdec_cmp_eq(const bfdec_t *a, const bfdec_t *b)
function bfdec_cmp_le (line 491) | static inline int bfdec_cmp_le(const bfdec_t *a, const bfdec_t *b)
function bfdec_cmp_lt (line 495) | static inline int bfdec_cmp_lt(const bfdec_t *a, const bfdec_t *b)
function bfdec_resize (line 529) | static inline int bfdec_resize(bfdec_t *r, limb_t len)
FILE: libregexp.c
type REParseState (line 66) | typedef struct {
type REOpCode (line 86) | typedef struct {
function is_digit (line 109) | static inline int is_digit(int c) {
function dbuf_insert (line 114) | static int dbuf_insert(DynBuf *s, int pos, int len)
function lre_canonicalize (line 124) | static uint32_t lre_canonicalize(uint32_t c, BOOL is_utf16)
function BOOL (line 173) | BOOL lre_is_space(int c)
type CharRangeEnum (line 209) | typedef enum {
function cr_init_char_range (line 224) | static int cr_init_char_range(REParseState *s, CharRange *cr, uint32_t c)
function cr_canonicalize (line 248) | static int cr_canonicalize(CharRange *cr)
function __maybe_unused (line 274) | static __maybe_unused void lre_dump_bytecode(const uint8_t *buf,
function re_emit_op (line 394) | static void re_emit_op(REParseState *s, int op)
function re_emit_op_u32 (line 400) | static int re_emit_op_u32(REParseState *s, int op, uint32_t val)
function re_emit_goto (line 409) | static int re_emit_goto(REParseState *s, int op, uint32_t val)
function re_emit_op_u8 (line 418) | static void re_emit_op_u8(REParseState *s, int op, uint32_t val)
function re_emit_op_u16 (line 424) | static void re_emit_op_u16(REParseState *s, int op, uint32_t val)
function re_parse_error (line 430) | static int __attribute__((format(printf, 2, 3))) re_parse_error(REParseS...
function re_parse_out_of_memory (line 439) | static int re_parse_out_of_memory(REParseState *s)
function parse_digits (line 446) | static int parse_digits(const uint8_t **pp, BOOL allow_overflow)
function re_parse_expect (line 471) | static int re_parse_expect(REParseState *s, const uint8_t **pp, int c)
function lre_parse_escape (line 492) | int lre_parse_escape(const uint8_t **pp, int allow_utf16)
function BOOL (line 604) | static BOOL is_unicode_char(int c)
function parse_unicode_property (line 612) | static int parse_unicode_property(REParseState *s, CharRange *cr,
function get_class_atom (line 710) | static int get_class_atom(REParseState *s, CharRange *cr,
function re_emit_range (line 820) | static int re_emit_range(REParseState *s, const CharRange *cr)
function re_parse_char_class (line 858) | static int re_parse_char_class(REParseState *s, const uint8_t **pp)
function re_check_advance (line 949) | static int re_check_advance(const uint8_t *bc_buf, int bc_buf_len)
function re_is_simple_quantifier (line 1033) | static int re_is_simple_quantifier(const uint8_t *bc_buf, int bc_buf_len)
function re_parse_group_name (line 1073) | static int re_parse_group_name(char *buf, int buf_size,
function re_parse_captures (line 1124) | static int re_parse_captures(REParseState *s, int *phas_named_captures,
function re_count_captures (line 1171) | static int re_count_captures(REParseState *s)
function BOOL (line 1180) | static BOOL re_has_named_captures(REParseState *s)
function find_group_name (line 1187) | static int find_group_name(REParseState *s, const char *name)
function re_parse_term (line 1209) | static int re_parse_term(REParseState *s, BOOL is_backward_dir)
function re_parse_alternative (line 1696) | static int re_parse_alternative(REParseState *s, BOOL is_backward_dir)
function re_parse_disjunction (line 1730) | static int re_parse_disjunction(REParseState *s, BOOL is_backward_dir)
function compute_stack_size (line 1762) | static int compute_stack_size(const uint8_t *bc_buf, int bc_buf_len)
function BOOL (line 1900) | static BOOL is_line_terminator(uint32_t c)
function BOOL (line 1905) | static BOOL is_word_char(uint32_t c)
type StackInt (line 2003) | typedef uintptr_t StackInt;
type REExecStateEnum (line 2005) | typedef enum {
type REExecState (line 2012) | typedef struct REExecState {
type REExecContext (line 2021) | typedef struct {
function push_state (line 2039) | static int push_state(REExecContext *s,
function lre_exec_backtrack (line 2078) | static intptr_t lre_exec_backtrack(REExecContext *s, uint8_t **capture,
function lre_exec (line 2488) | int lre_exec(uint8_t **capture,
function lre_get_capture_count (line 2526) | int lre_get_capture_count(const uint8_t *bc_buf)
function lre_get_flags (line 2531) | int lre_get_flags(const uint8_t *bc_buf)
function BOOL (line 2538) | BOOL lre_check_stack_overflow(void *opaque, size_t alloca_size)
function main (line 2548) | int main(int argc, char **argv)
FILE: libregexp.h
function lre_js_is_ident_first (line 62) | static inline int lre_js_is_ident_first(int c)
function lre_js_is_ident_next (line 75) | static inline int lre_js_is_ident_next(int c)
FILE: libunicode-table.h
type UnicodeGCEnum (line 2199) | typedef enum {
type UnicodeScriptEnum (line 2759) | typedef enum {
type UnicodePropertyEnum (line 4132) | typedef enum {
FILE: libunicode.c
function lre_case_conv (line 56) | int lre_case_conv(uint32_t *res, uint32_t c, int conv_type)
function get_le24 (line 160) | static uint32_t get_le24(const uint8_t *ptr)
function get_index_pos (line 172) | static int get_index_pos(uint32_t *pcode, uint32_t c,
function BOOL (line 205) | static BOOL lre_is_in_table(uint32_t c, const uint8_t *table,
function BOOL (line 240) | BOOL lre_is_cased(uint32_t c)
function BOOL (line 265) | BOOL lre_is_case_ignorable(uint32_t c)
function __maybe_unused (line 274) | static __maybe_unused void cr_dump(CharRange *cr)
function cr_init (line 286) | void cr_init(CharRange *cr, void *mem_opaque, DynBufReallocFunc *realloc...
function cr_free (line 294) | void cr_free(CharRange *cr)
function cr_realloc (line 299) | int cr_realloc(CharRange *cr, int size)
function cr_copy (line 316) | int cr_copy(CharRange *cr, const CharRange *cr1)
function cr_compress (line 326) | static void cr_compress(CharRange *cr)
function cr_op (line 355) | int cr_op(CharRange *cr, const uint32_t *a_pt, int a_len,
function cr_union1 (line 407) | int cr_union1(CharRange *cr, const uint32_t *b_pt, int b_len)
function cr_invert (line 419) | int cr_invert(CharRange *cr)
function BOOL (line 435) | BOOL lre_is_id_start(uint32_t c)
function BOOL (line 442) | BOOL lre_is_id_continue(uint32_t c)
type DecompTypeEnum (line 452) | typedef enum {
function unicode_get_short_code (line 490) | static uint32_t unicode_get_short_code(uint32_t c)
function unicode_get_lower_simple (line 502) | static uint32_t unicode_get_lower_simple(uint32_t c)
function unicode_get16 (line 511) | static uint16_t unicode_get16(const uint8_t *p)
function unicode_decomp_entry (line 516) | static int unicode_decomp_entry(uint32_t *res, uint32_t c,
function unicode_decomp_char (line 639) | static int unicode_decomp_char(uint32_t *res, uint32_t c, BOOL is_compat1)
function unicode_compose_pair (line 668) | static int unicode_compose_pair(uint32_t c0, uint32_t c1)
function unicode_get_cc (line 704) | static int unicode_get_cc(uint32_t c)
function sort_cc (line 755) | static void sort_cc(int *buf, int len)
function to_nfd_rec (line 791) | static void to_nfd_rec(DynBuf *dbuf,
function compose_pair (line 820) | static int compose_pair(uint32_t c0, uint32_t c1)
function unicode_normalize (line 835) | int unicode_normalize(uint32_t **pdst, const uint32_t *src, int src_len,
function unicode_find_name (line 910) | static int unicode_find_name(const char *name_table, const char *name)
function unicode_script (line 939) | int unicode_script(CharRange *cr,
function unicode_general_category1 (line 1059) | static int unicode_general_category1(CharRange *cr, uint32_t gc_mask)
function unicode_prop1 (line 1111) | static int unicode_prop1(CharRange *cr, int prop_idx)
function unicode_case1 (line 1159) | static int unicode_case1(CharRange *cr, int case_mask)
type PropOPEnum (line 1222) | typedef enum {
function unicode_prop_ops (line 1235) | static int unicode_prop_ops(CharRange *cr, ...)
function unicode_general_category (line 1323) | int unicode_general_category(CharRange *cr, const char *gc_name)
function unicode_prop (line 1342) | int unicode_prop(CharRange *cr, const char *prop_name)
FILE: libunicode.h
type UnicodeNormalizationEnum (line 36) | typedef enum {
type CharRange (line 49) | typedef struct {
type CharRangeOpEnum (line 57) | typedef enum {
function cr_add_point (line 68) | static inline int cr_add_point(CharRange *cr, uint32_t v)
function cr_add_interval (line 78) | static inline int cr_add_interval(CharRange *cr, uint32_t c1, uint32_t c2)
function cr_union_interval (line 91) | static inline int cr_union_interval(CharRange *cr, uint32_t c1, uint32_t...
FILE: list.h
type list_head (line 31) | struct list_head {
function init_list_head (line 42) | static inline void init_list_head(struct list_head *head)
function __list_add (line 49) | static inline void __list_add(struct list_head *el,
function list_add (line 59) | static inline void list_add(struct list_head *el, struct list_head *head)
function list_add_tail (line 65) | static inline void list_add_tail(struct list_head *el, struct list_head ...
function list_del (line 70) | static inline void list_del(struct list_head *el)
function list_empty (line 81) | static inline int list_empty(struct list_head *el)
FILE: quickjs.c
type JSErrorEnum (line 189) | typedef enum JSErrorEnum {
type JSShape (line 208) | typedef struct JSShape JSShape;
type JSString (line 209) | typedef struct JSString JSString;
type JSAtomStruct (line 210) | typedef struct JSString JSAtomStruct;
type JSGCPhaseEnum (line 212) | typedef enum {
type OPCodeEnum (line 218) | typedef enum OPCodeEnum OPCodeEnum;
type JSNumericOperations (line 223) | typedef struct {
type JSRuntime (line 240) | struct JSRuntime {
type JSClass (line 309) | struct JSClass {
type JSStackFrame (line 323) | typedef struct JSStackFrame {
type JSGCObjectTypeEnum (line 338) | typedef enum {
type JSGCObjectHeader (line 350) | struct JSGCObjectHeader {
type JSVarRef (line 359) | typedef struct JSVarRef {
type JSFloatEnv (line 382) | typedef struct JSFloatEnv {
type JSBigFloat (line 390) | typedef struct JSBigFloat {
type JSBigDecimal (line 395) | typedef struct JSBigDecimal {
type JSAutoInitIDEnum (line 401) | typedef enum {
type JSContext (line 411) | struct JSContext {
type JSFloat64Union (line 460) | typedef union JSFloat64Union {
type JSAtomKindEnum (line 478) | typedef enum {
type JSString (line 486) | struct JSString {
type JSClosureVar (line 505) | typedef struct JSClosureVar {
type JSVarScope (line 518) | typedef struct JSVarScope {
type JSVarKindEnum (line 523) | typedef enum {
type JSVarDef (line 537) | typedef struct JSVarDef {
type JSFunctionKindEnum (line 561) | typedef enum JSFunctionKindEnum {
type JSFunctionBytecode (line 568) | typedef struct JSFunctionBytecode {
type JSBoundFunction (line 609) | typedef struct JSBoundFunction {
type JSIteratorKindEnum (line 616) | typedef enum JSIteratorKindEnum {
type JSForInIterator (line 622) | typedef struct JSForInIterator {
type JSRegExp (line 629) | typedef struct JSRegExp {
type JSProxyData (line 634) | typedef struct JSProxyData {
type JSArrayBuffer (line 641) | typedef struct JSArrayBuffer {
type JSTypedArray (line 651) | typedef struct JSTypedArray {
type JSAsyncFunctionState (line 659) | typedef struct JSAsyncFunctionState {
type JSAsyncFunctionData (line 668) | typedef struct JSAsyncFunctionData {
type JSOverloadableOperatorEnum (line 675) | typedef enum {
type JSBinaryOperatorDefEntry (line 703) | typedef struct {
type JSBinaryOperatorDef (line 708) | typedef struct {
type JSOperatorSetData (line 713) | typedef struct {
type JSReqModuleEntry (line 722) | typedef struct JSReqModuleEntry {
type JSExportTypeEnum (line 727) | typedef enum JSExportTypeEnum {
type JSExportEntry (line 732) | typedef struct JSExportEntry {
type JSStarExportEntry (line 746) | typedef struct JSStarExportEntry {
type JSImportEntry (line 750) | typedef struct JSImportEntry {
type JSModuleDef (line 756) | struct JSModuleDef {
type JSJobEntry (line 792) | typedef struct JSJobEntry {
type JSProperty (line 800) | typedef struct JSProperty {
type JSShapeProperty (line 822) | typedef struct JSShapeProperty {
type JSShape (line 828) | struct JSShape {
type JSObject (line 849) | struct JSObject {
type OPCodeFormat (line 950) | typedef enum OPCodeFormat {
type JSStrictEqModeEnum (line 1087) | typedef enum JSStrictEqModeEnum {
function bf_t (line 1105) | static inline bf_t *JS_GetBigFloat(JSValueConst val)
function bfdec_t (line 1111) | static inline bfdec_t *JS_GetBigDecimal(JSValueConst val)
function bf_t (line 1117) | static inline bf_t *JS_GetBigInt(JSValueConst val)
function js_trigger_gc (line 1242) | static void js_trigger_gc(JSRuntime *rt, size_t size)
function js_malloc_usable_size_unknown (line 1262) | static size_t js_malloc_usable_size_unknown(const void *ptr)
function js_free_rt (line 1272) | void js_free_rt(JSRuntime *rt, void *ptr)
function js_malloc_usable_size_rt (line 1282) | size_t js_malloc_usable_size_rt(JSRuntime *rt, const void *ptr)
function js_free (line 1329) | void js_free(JSContext *ctx, void *ptr)
function js_malloc_usable_size (line 1362) | size_t js_malloc_usable_size(JSContext *ctx, const void *ptr)
function no_inline (line 1384) | static no_inline int js_realloc_array(JSContext *ctx, void **parray,
function js_resize_array (line 1402) | static inline int js_resize_array(JSContext *ctx, void **parray, int ele...
function js_dbuf_init (line 1411) | static inline void js_dbuf_init(JSContext *ctx, DynBuf *s)
function is_digit (line 1416) | static inline int is_digit(int c) {
type JSClassShortDef (line 1420) | typedef struct JSClassShortDef {
function init_class_range (line 1480) | static int init_class_range(JSRuntime *rt, JSClassShortDef const *tab,
function JSValue (line 1498) | static JSValue JS_ThrowUnsupportedOperation(JSContext *ctx)
function JSValue (line 1503) | static JSValue invalid_to_string(JSContext *ctx, JSValueConst val)
function JSValue (line 1508) | static JSValue invalid_from_string(JSContext *ctx, const char *buf,
function invalid_unary_arith (line 1514) | static int invalid_unary_arith(JSContext *ctx,
function invalid_binary_arith (line 1522) | static int invalid_binary_arith(JSContext *ctx, OPCodeEnum op,
function JSValue (line 1531) | static JSValue invalid_mul_pow10_to_float64(JSContext *ctx, const bf_t *a,
function invalid_mul_pow10 (line 1537) | static int invalid_mul_pow10(JSContext *ctx, JSValue *sp)
function set_dummy_numeric_ops (line 1543) | static void set_dummy_numeric_ops(JSNumericOperations *ops)
function BOOL (line 1562) | static inline BOOL js_check_stack_overflow(JSRuntime *rt, size_t alloca_...
function BOOL (line 1573) | static inline BOOL js_check_stack_overflow(JSRuntime *rt, size_t alloca_...
function JSRuntime (line 1581) | JSRuntime *JS_NewRuntime2(const JSMallocFunctions *mf, void *opaque)
function JS_SetRuntimeOpaque (line 1652) | void JS_SetRuntimeOpaque(JSRuntime *rt, void *opaque)
function js_def_malloc_usable_size (line 1658) | static inline size_t js_def_malloc_usable_size(void *ptr)
function js_def_free (line 1693) | static void js_def_free(JSMallocState *s, void *ptr)
function JSRuntime (line 1748) | JSRuntime *JS_NewRuntime(void)
function JS_SetMemoryLimit (line 1753) | void JS_SetMemoryLimit(JSRuntime *rt, size_t limit)
function JS_SetGCThreshold (line 1759) | void JS_SetGCThreshold(JSRuntime *rt, size_t gc_threshold)
function JS_SetInterruptHandler (line 1768) | void JS_SetInterruptHandler(JSRuntime *rt, JSInterruptHandler *cb, void ...
function JS_SetCanBlock (line 1774) | void JS_SetCanBlock(JSRuntime *rt, BOOL can_block)
function JS_SetSharedArrayBufferFunctions (line 1779) | void JS_SetSharedArrayBufferFunctions(JSRuntime *rt,
function JS_EnqueueJob (line 1786) | int JS_EnqueueJob(JSContext *ctx, JSJobFunc *job_func,
function BOOL (line 1806) | BOOL JS_IsJobPending(JSRuntime *rt)
function JS_ExecutePendingJob (line 1813) | int JS_ExecutePendingJob(JSRuntime *rt, JSContext **pctx)
function atom_get_free (line 1842) | static inline uint32_t atom_get_free(const JSAtomStruct *p)
function BOOL (line 1847) | static inline BOOL atom_is_free(const JSAtomStruct *p)
function JSAtomStruct (line 1852) | static inline JSAtomStruct *atom_set_free(uint32_t v)
function JSString (line 1858) | static JSString *js_alloc_string_rt(JSRuntime *rt, int max_len, int is_w...
function JSString (line 1876) | static JSString *js_alloc_string(JSContext *ctx, int max_len, int is_wid...
function js_free_string (line 1888) | static inline void js_free_string(JSRuntime *rt, JSString *str)
function JS_SetRuntimeInfo (line 1902) | void JS_SetRuntimeInfo(JSRuntime *rt, const char *s)
function JS_FreeRuntime (line 1908) | void JS_FreeRuntime(JSRuntime *rt)
function JSContext (line 2096) | JSContext *JS_NewContextRaw(JSRuntime *rt)
function JSContext (line 2131) | JSContext *JS_NewContext(JSRuntime *rt)
function JS_SetContextOpaque (line 2160) | void JS_SetContextOpaque(JSContext *ctx, void *opaque)
function set_value (line 2167) | static inline void set_value(JSContext *ctx, JSValue *pval, JSValue new_...
function JS_SetClassProto (line 2175) | void JS_SetClassProto(JSContext *ctx, JSClassID class_id, JSValue obj)
function JSValue (line 2182) | JSValue JS_GetClassProto(JSContext *ctx, JSClassID class_id)
type JSFreeModuleEnum (line 2189) | typedef enum JSFreeModuleEnum {
function js_free_modules (line 2196) | static void js_free_modules(JSContext *ctx, JSFreeModuleEnum flag)
function JSContext (line 2209) | JSContext *JS_DupContext(JSContext *ctx)
function JS_MarkContext (line 2216) | static void JS_MarkContext(JSRuntime *rt, JSContext *ctx,
function JS_FreeContext (line 2254) | void JS_FreeContext(JSContext *ctx)
function JSRuntime (line 2321) | JSRuntime *JS_GetRuntime(JSContext *ctx)
function JS_SetMaxStackSize (line 2326) | void JS_SetMaxStackSize(JSRuntime *rt, size_t stack_size)
function BOOL (line 2331) | static inline BOOL is_strict_mode(JSContext *ctx)
function BOOL (line 2338) | static inline BOOL is_math_mode(JSContext *ctx)
function BOOL (line 2354) | static inline BOOL __JS_AtomIsConst(JSAtom v)
function BOOL (line 2363) | static inline BOOL __JS_AtomIsTaggedInt(JSAtom v)
function JSAtom (line 2368) | static inline JSAtom __JS_AtomFromUInt32(uint32_t v)
function __JS_AtomToUInt32 (line 2373) | static inline uint32_t __JS_AtomToUInt32(JSAtom atom)
function is_num (line 2378) | static inline int is_num(int c)
function BOOL (line 2384) | static inline BOOL is_num_string(uint32_t *pval, const JSString *p)
function hash_string8 (line 2425) | static inline uint32_t hash_string8(const uint8_t *str, size_t len, uint...
function hash_string16 (line 2434) | static inline uint32_t hash_string16(const uint16_t *str,
function hash_string (line 2444) | static uint32_t hash_string(const JSString *str, uint32_t h)
function __maybe_unused (line 2453) | static __maybe_unused void JS_DumpString(JSRuntime *rt,
function __maybe_unused (line 2485) | static __maybe_unused void JS_DumpAtoms(JSRuntime *rt)
function JS_ResizeAtomHash (line 2520) | static int JS_ResizeAtomHash(JSRuntime *rt, int new_hash_size)
function JS_InitAtoms (line 2550) | static int JS_InitAtoms(JSRuntime *rt)
function JSAtom (line 2579) | static JSAtom JS_DupAtomRT(JSRuntime *rt, JSAtom v)
function JSAtom (line 2590) | JSAtom JS_DupAtom(JSContext *ctx, JSAtom v)
function JSAtomKindEnum (line 2603) | static JSAtomKindEnum JS_AtomGetKind(JSContext *ctx, JSAtom v)
function BOOL (line 2631) | static BOOL JS_AtomIsString(JSContext *ctx, JSAtom v)
function JSAtom (line 2636) | static JSAtom js_get_atom_index(JSRuntime *rt, JSAtomStruct *p)
function JSAtom (line 2655) | static JSAtom __JS_NewAtom(JSRuntime *rt, JSString *str, int atom_type)
function JSAtom (line 2811) | static JSAtom __JS_NewAtomInit(JSRuntime *rt, const char *str, int len,
function JSAtom (line 2823) | static JSAtom __JS_FindAtom(JSRuntime *rt, const char *str, size_t len,
function JS_FreeAtomStruct (line 2849) | static void JS_FreeAtomStruct(JSRuntime *rt, JSAtomStruct *p)
function __JS_FreeAtom (line 2892) | static void __JS_FreeAtom(JSRuntime *rt, uint32_t i)
function JSAtom (line 2903) | static JSAtom JS_NewAtomStr(JSContext *ctx, JSString *p)
function JSAtom (line 2917) | JSAtom JS_NewAtomLen(JSContext *ctx, const char *str, size_t len)
function JSAtom (line 2932) | JSAtom JS_NewAtom(JSContext *ctx, const char *str)
function JSAtom (line 2937) | JSAtom JS_NewAtomUInt32(JSContext *ctx, uint32_t n)
function JSAtom (line 2953) | static JSAtom JS_NewAtomInt64(JSContext *ctx, int64_t n)
function JSValue (line 2970) | static JSValue JS_NewSymbol(JSContext *ctx, JSString *p, int atom_type)
function JSValue (line 2981) | static JSValue JS_NewSymbolFromAtom(JSContext *ctx, JSAtom descr,
function JSValue (line 3051) | static JSValue __JS_AtomToValue(JSContext *ctx, JSAtom atom, BOOL force_...
function JSValue (line 3078) | JSValue JS_AtomToValue(JSContext *ctx, JSAtom atom)
function JSValue (line 3083) | JSValue JS_AtomToString(JSContext *ctx, JSAtom atom)
function BOOL (line 3090) | static BOOL JS_AtomIsArrayIndex(JSContext *ctx, uint32_t *pval, JSAtom a...
function JSValue (line 3116) | static JSValue JS_AtomIsNumericIndex1(JSContext *ctx, JSAtom atom)
function JS_AtomIsNumericIndex (line 3198) | static int JS_AtomIsNumericIndex(JSContext *ctx, JSAtom atom)
function JS_FreeAtom (line 3210) | void JS_FreeAtom(JSContext *ctx, JSAtom v)
function JS_FreeAtomRT (line 3216) | void JS_FreeAtomRT(JSRuntime *rt, JSAtom v)
function BOOL (line 3223) | static BOOL JS_AtomSymbolHasDescription(JSContext *ctx, JSAtom v)
function __maybe_unused (line 3238) | static __maybe_unused void print_atom(JSContext *ctx, JSAtom atom)
function JSAtom (line 3291) | static JSAtom js_atom_concat_str(JSContext *ctx, JSAtom name, const char...
function JSAtom (line 3323) | static JSAtom js_atom_concat_num(JSContext *ctx, JSAtom name, uint32_t n)
function BOOL (line 3330) | static inline BOOL JS_IsEmptyString(JSValueConst v)
function JSClassID (line 3338) | JSClassID JS_NewClassID(JSClassID *pclass_id)
function BOOL (line 3350) | BOOL JS_IsRegisteredClass(JSRuntime *rt, JSClassID class_id)
function JS_NewClass1 (line 3358) | static int JS_NewClass1(JSRuntime *rt, JSClassID class_id,
function JS_NewClass (line 3405) | int JS_NewClass(JSRuntime *rt, JSClassID class_id, const JSClassDef *cla...
function JSValue (line 3422) | static JSValue js_new_string8(JSContext *ctx, const uint8_t *buf, int len)
function JSValue (line 3437) | static JSValue js_new_string16(JSContext *ctx, const uint16_t *buf, int ...
function JSValue (line 3447) | static JSValue js_new_string_char(JSContext *ctx, uint16_t c)
function JSValue (line 3458) | static JSValue js_sub_string(JSContext *ctx, JSString *p, int start, int...
type StringBuffer (line 3487) | typedef struct StringBuffer {
function string_buffer_init2 (line 3500) | static int string_buffer_init2(JSContext *ctx, StringBuffer *s, int size,
function string_buffer_init (line 3520) | static inline int string_buffer_init(JSContext *ctx, StringBuffer *s, in...
function string_buffer_free (line 3525) | static void string_buffer_free(StringBuffer *s)
function string_buffer_set_error (line 3531) | static int string_buffer_set_error(StringBuffer *s)
function no_inline (line 3540) | static no_inline int string_buffer_widen(StringBuffer *s, int size)
function no_inline (line 3562) | static no_inline int string_buffer_realloc(StringBuffer *s, int new_len,...
function no_inline (line 3589) | static no_inline int string_buffer_putc_slow(StringBuffer *s, uint32_t c)
function string_buffer_putc8 (line 3608) | static int string_buffer_putc8(StringBuffer *s, uint32_t c)
function string_buffer_putc16 (line 3623) | static int string_buffer_putc16(StringBuffer *s, uint32_t c)
function string_buffer_putc (line 3638) | static int string_buffer_putc(StringBuffer *s, uint32_t c)
function string_get (line 3650) | static int string_get(const JSString *p, int idx) {
function string_getc (line 3654) | static int string_getc(const JSString *p, int *pidx)
function string_buffer_write8 (line 3674) | static int string_buffer_write8(StringBuffer *s, const uint8_t *p, int len)
function string_buffer_write16 (line 3694) | static int string_buffer_write16(StringBuffer *s, const uint16_t *p, int...
function string_buffer_puts8 (line 3721) | static int string_buffer_puts8(StringBuffer *s, const char *str)
function string_buffer_concat (line 3726) | static int string_buffer_concat(StringBuffer *s, const JSString *p,
function string_buffer_concat_value (line 3737) | static int string_buffer_concat_value(StringBuffer *s, JSValueConst v)
function string_buffer_concat_value_free (line 3760) | static int string_buffer_concat_value_free(StringBuffer *s, JSValue v)
function string_buffer_fill (line 3781) | static int string_buffer_fill(StringBuffer *s, int c, int count)
function JSValue (line 3795) | static JSValue string_buffer_end(StringBuffer *s)
function JSValue (line 3828) | JSValue JS_NewStringLen(JSContext *ctx, const char *buf, size_t buf_len)
function JSValue (line 3888) | static JSValue JS_ConcatString3(JSContext *ctx, const char *str1,
function JSValue (line 3919) | JSValue JS_NewString(JSContext *ctx, const char *str)
function JSValue (line 3924) | JSValue JS_NewAtomString(JSContext *ctx, const char *str)
function JS_FreeCString (line 4034) | void JS_FreeCString(JSContext *ctx, const char *ptr)
function memcmp16_8 (line 4044) | static int memcmp16_8(const uint16_t *src1, const uint8_t *src2, int len)
function memcmp16 (line 4055) | static int memcmp16(const uint16_t *src1, const uint16_t *src2, int len)
function js_string_memcmp (line 4066) | static int js_string_memcmp(const JSString *p1, const JSString *p2, int ...
function js_string_compare (line 4085) | static int js_string_compare(JSContext *ctx,
function copy_str16 (line 4102) | static void copy_str16(uint16_t *dst, const JSString *p, int offset, int...
function JSValue (line 4115) | static JSValue JS_ConcatString1(JSContext *ctx,
function JSValue (line 4142) | static JSValue JS_ConcatString(JSContext *ctx, JSValue op1, JSValue op2)
function get_shape_size (line 4191) | static inline size_t get_shape_size(size_t hash_size, size_t prop_size)
function JSShape (line 4197) | static inline JSShape *get_shape_from_alloc(void *sh_alloc, size_t hash_...
function JSShapeProperty (line 4207) | static inline JSShapeProperty *get_shape_prop(JSShape *sh)
function init_shape_hash (line 4212) | static int init_shape_hash(JSRuntime *rt)
function shape_hash (line 4225) | static uint32_t shape_hash(uint32_t h, uint32_t val)
function get_shape_hash (line 4231) | static uint32_t get_shape_hash(uint32_t h, int hash_bits)
function shape_initial_hash (line 4236) | static uint32_t shape_initial_hash(JSObject *proto)
function resize_shape_hash (line 4245) | static int resize_shape_hash(JSRuntime *rt, int new_shape_hash_bits)
function js_shape_hash_link (line 4271) | static void js_shape_hash_link(JSRuntime *rt, JSShape *sh)
function js_shape_hash_unlink (line 4280) | static void js_shape_hash_unlink(JSRuntime *rt, JSShape *sh)
function no_inline (line 4294) | static no_inline JSShape *js_new_shape2(JSContext *ctx, JSObject *proto,
function JSShape (line 4330) | static JSShape *js_new_shape(JSContext *ctx, JSObject *proto)
function JSShape (line 4338) | static JSShape *js_clone_shape(JSContext *ctx, JSShape *sh1)
function JSShape (line 4366) | static JSShape *js_dup_shape(JSShape *sh)
function js_free_shape0 (line 4372) | static void js_free_shape0(JSRuntime *rt, JSShape *sh)
function js_free_shape (line 4392) | static void js_free_shape(JSRuntime *rt, JSShape *sh)
function js_free_shape_null (line 4399) | static void js_free_shape_null(JSRuntime *rt, JSShape *sh)
function no_inline (line 4406) | static no_inline int resize_properties(JSContext *ctx, JSShape **psh,
function compact_properties (line 4473) | static int compact_properties(JSContext *ctx, JSObject *p)
function add_shape_property (line 4540) | static int add_shape_property(JSContext *ctx, JSShape **psh,
function JSShape (line 4586) | static JSShape *find_hashed_shape_proto(JSRuntime *rt, JSObject *proto)
function JSShape (line 4605) | static JSShape *find_hashed_shape_prop(JSRuntime *rt, JSShape *sh,
function __maybe_unused (line 4636) | static __maybe_unused void JS_DumpShape(JSRuntime *rt, int i, JSShape *sh)
function __maybe_unused (line 4652) | static __maybe_unused void JS_DumpShapes(JSRuntime *rt)
function JSValue (line 4681) | static JSValue JS_NewObjectFromShape(JSContext *ctx, JSShape *sh, JSClas...
function JSObject (line 4773) | static JSObject *get_proto_obj(JSValueConst proto_val)
function JSValue (line 4782) | JSValue JS_NewObjectProtoClass(JSContext *ctx, JSValueConst proto_val,
function JSValue (line 4801) | static JSValue JS_GetObjectData(JSContext *ctx, JSValueConst obj)
function JS_SetObjectData (line 4825) | static int JS_SetObjectData(JSContext *ctx, JSValueConst obj, JSValue val)
function JSValue (line 4853) | JSValue JS_NewObjectClass(JSContext *ctx, int class_id)
function JSValue (line 4858) | JSValue JS_NewObjectProto(JSContext *ctx, JSValueConst proto)
function JSValue (line 4863) | JSValue JS_NewArray(JSContext *ctx)
function JSValue (line 4869) | JSValue JS_NewObject(JSContext *ctx)
function js_function_set_properties (line 4875) | static void js_function_set_properties(JSContext *ctx, JSValueConst func...
function BOOL (line 4885) | static BOOL js_class_has_bytecode(JSClassID class_id)
function JSFunctionBytecode (line 4894) | static JSFunctionBytecode *JS_GetFunctionBytecode(JSValueConst val)
function js_method_set_home_object (line 4905) | static void js_method_set_home_object(JSContext *ctx, JSValueConst func_...
function JSValue (line 4930) | static JSValue js_get_function_name(JSContext *ctx, JSAtom name)
function js_method_set_properties (line 4945) | static int js_method_set_properties(JSContext *ctx, JSValueConst func_obj,
function JSValue (line 4966) | static JSValue JS_NewCFunction3(JSContext *ctx, JSCFunction *func,
function JSValue (line 4997) | JSValue JS_NewCFunction2(JSContext *ctx, JSCFunction *func,
type JSCFunctionDataRecord (line 5005) | typedef struct JSCFunctionDataRecord {
function js_c_function_data_finalizer (line 5013) | static void js_c_function_data_finalizer(JSRuntime *rt, JSValue val)
function js_c_function_data_mark (line 5026) | static void js_c_function_data_mark(JSRuntime *rt, JSValueConst val,
function JSValue (line 5039) | static JSValue js_c_function_data_call(JSContext *ctx, JSValueConst func...
function JSValue (line 5061) | JSValue JS_NewCFunctionData(JSContext *ctx, JSCFunctionData *func,
function JSContext (line 5090) | static JSContext *js_autoinit_get_realm(JSProperty *pr)
function JSAutoInitIDEnum (line 5095) | static JSAutoInitIDEnum js_autoinit_get_id(JSProperty *pr)
function js_autoinit_free (line 5100) | static void js_autoinit_free(JSRuntime *rt, JSProperty *pr)
function js_autoinit_mark (line 5105) | static void js_autoinit_mark(JSRuntime *rt, JSProperty *pr,
function free_property (line 5111) | static void free_property(JSRuntime *rt, JSProperty *pr, int prop_flags)
function force_inline (line 5129) | static force_inline JSShapeProperty *find_own_property1(JSObject *p,
function force_inline (line 5149) | static force_inline JSShapeProperty *find_own_property(JSProperty **ppr,
function set_cycle_flag (line 5174) | static void set_cycle_flag(JSContext *ctx, JSValueConst obj)
function free_var_ref (line 5178) | static void free_var_ref(JSRuntime *rt, JSVarRef *var_ref)
function js_array_finalizer (line 5194) | static void js_array_finalizer(JSRuntime *rt, JSValue val)
function js_array_mark (line 5205) | static void js_array_mark(JSRuntime *rt, JSValueConst val,
function js_object_data_finalizer (line 5216) | static void js_object_data_finalizer(JSRuntime *rt, JSValue val)
function js_object_data_mark (line 5223) | static void js_object_data_mark(JSRuntime *rt, JSValueConst val,
function js_c_function_finalizer (line 5230) | static void js_c_function_finalizer(JSRuntime *rt, JSValue val)
function js_c_function_mark (line 5238) | static void js_c_function_mark(JSRuntime *rt, JSValueConst val,
function js_bytecode_function_finalizer (line 5247) | static void js_bytecode_function_finalizer(JSRuntime *rt, JSValue val)
function js_bytecode_function_mark (line 5270) | static void js_bytecode_function_mark(JSRuntime *rt, JSValueConst val,
function js_bound_function_finalizer (line 5297) | static void js_bound_function_finalizer(JSRuntime *rt, JSValue val)
function js_bound_function_mark (line 5311) | static void js_bound_function_mark(JSRuntime *rt, JSValueConst val,
function js_for_in_iterator_finalizer (line 5324) | static void js_for_in_iterator_finalizer(JSRuntime *rt, JSValue val)
function js_for_in_iterator_mark (line 5332) | static void js_for_in_iterator_mark(JSRuntime *rt, JSValueConst val,
function free_object (line 5340) | static void free_object(JSRuntime *rt, JSObject *p)
function free_gc_object (line 5387) | static void free_gc_object(JSRuntime *rt, JSGCObjectHeader *gp)
function free_zero_refcount (line 5401) | static void free_zero_refcount(JSRuntime *rt)
function __JS_FreeValueRT (line 5419) | void __JS_FreeValueRT(JSRuntime *rt, JSValue v)
function __JS_FreeValue (line 5494) | void __JS_FreeValue(JSContext *ctx, JSValue v)
function add_gc_object (line 5501) | static void add_gc_object(JSRuntime *rt, JSGCObjectHeader *h,
function remove_gc_object (line 5509) | static void remove_gc_object(JSGCObjectHeader *h)
function JS_MarkValue (line 5514) | void JS_MarkValue(JSRuntime *rt, JSValueConst val, JS_MarkFunc *mark_func)
function mark_children (line 5528) | static void mark_children(JSRuntime *rt, JSGCObjectHeader *gp,
function gc_decref_child (line 5623) | static void gc_decref_child(JSRuntime *rt, JSGCObjectHeader *p)
function gc_decref (line 5633) | static void gc_decref(JSRuntime *rt)
function gc_scan_incref_child (line 5655) | static void gc_scan_incref_child(JSRuntime *rt, JSGCObjectHeader *p)
function gc_scan_incref_child2 (line 5667) | static void gc_scan_incref_child2(JSRuntime *rt, JSGCObjectHeader *p)
function gc_scan (line 5672) | static void gc_scan(JSRuntime *rt)
function gc_free_cycles (line 5692) | static void gc_free_cycles(JSRuntime *rt)
function JS_RunGC (line 5741) | void JS_RunGC(JSRuntime *rt)
function BOOL (line 5757) | BOOL JS_IsLiveObject(JSRuntime *rt, JSValueConst obj)
type JSMemoryUsage_helper (line 5768) | typedef struct JSMemoryUsage_helper {
function compute_jsstring_size (line 5781) | static void compute_jsstring_size(JSString *str, JSMemoryUsage_helper *hp)
function compute_bytecode_size (line 5791) | static void compute_bytecode_size(JSFunctionBytecode *b, JSMemoryUsage_h...
function compute_value_size (line 5830) | static void compute_value_size(JSValueConst val, JSMemoryUsage_helper *hp)
function JS_ComputeMemoryUsage (line 5846) | void JS_ComputeMemoryUsage(JSRuntime *rt, JSMemoryUsage *s)
function JS_DumpMemoryUsage (line 6136) | void JS_DumpMemoryUsage(FILE *fp, const JSMemoryUsage *s, JSRuntime *rt)
function JSValue (line 6265) | JSValue JS_GetGlobalObject(JSContext *ctx)
function JSValue (line 6271) | JSValue JS_Throw(JSContext *ctx, JSValue obj)
function JSValue (line 6280) | JSValue JS_GetException(JSContext *ctx)
function dbuf_put_leb128 (line 6289) | static void dbuf_put_leb128(DynBuf *s, uint32_t v)
function dbuf_put_sleb128 (line 6304) | static void dbuf_put_sleb128(DynBuf *s, int32_t v1)
function get_leb128 (line 6310) | static int get_leb128(uint32_t *pval, const uint8_t *buf,
function get_sleb128 (line 6330) | static int get_sleb128(int32_t *pval, const uint8_t *buf,
function find_line_num (line 6344) | static int find_line_num(JSContext *ctx, JSFunctionBytecode *b,
function build_backtrace (line 6417) | static void build_backtrace(JSContext *ctx, JSValueConst error_obj,
function BOOL (line 6496) | static BOOL is_backtrace_needed(JSContext *ctx, JSValueConst obj)
function JSValue (line 6509) | JSValue JS_NewError(JSContext *ctx)
function JSValue (line 6514) | static JSValue JS_ThrowError2(JSContext *ctx, JSErrorEnum error_num,
function JSValue (line 6538) | static JSValue JS_ThrowError(JSContext *ctx, JSErrorEnum error_num,
function JSValue (line 6552) | JSValue __attribute__((format(printf, 2, 3))) JS_ThrowSyntaxError(JSCont...
function JSValue (line 6563) | JSValue __attribute__((format(printf, 2, 3))) JS_ThrowTypeError(JSContex...
function JS_ThrowTypeErrorOrFalse (line 6574) | static int __attribute__((format(printf, 3, 4))) JS_ThrowTypeErrorOrFals...
function JSValue (line 6590) | static JSValue __attribute__((format(printf, 3, 4))) __JS_ThrowTypeError...
function JSValue (line 6598) | static JSValue __attribute__((format(printf, 3, 4))) __JS_ThrowSyntaxErr...
function JS_ThrowTypeErrorReadOnly (line 6610) | static int JS_ThrowTypeErrorReadOnly(JSContext *ctx, int flags, JSAtom a...
function JSValue (line 6621) | JSValue __attribute__((format(printf, 2, 3))) JS_ThrowReferenceError(JSC...
function JSValue (line 6632) | JSValue __attribute__((format(printf, 2, 3))) JS_ThrowRangeError(JSConte...
function JSValue (line 6643) | JSValue __attribute__((format(printf, 2, 3))) JS_ThrowInternalError(JSCo...
function JSValue (line 6654) | JSValue JS_ThrowOutOfMemory(JSContext *ctx)
function JSValue (line 6665) | static JSValue JS_ThrowStackOverflow(JSContext *ctx)
function JSValue (line 6670) | static JSValue JS_ThrowTypeErrorNotAnObject(JSContext *ctx)
function JSValue (line 6675) | static JSValue JS_ThrowTypeErrorNotASymbol(JSContext *ctx)
function JSValue (line 6680) | static JSValue JS_ThrowReferenceErrorNotDefined(JSContext *ctx, JSAtom n...
function JSValue (line 6687) | static JSValue JS_ThrowReferenceErrorUninitialized(JSContext *ctx, JSAto...
function JSValue (line 6695) | static JSValue JS_ThrowTypeErrorInvalidClass(JSContext *ctx, int class_id)
function __js_poll_interrupts (line 6703) | int __js_poll_interrupts(JSContext *ctx)
function __exception (line 6718) | static inline __exception int js_poll_interrupts(JSContext *ctx)
function JS_SetPrototypeInternal (line 6728) | static int JS_SetPrototypeInternal(JSContext *ctx, JSValueConst obj,
function JS_SetPrototype (line 6799) | int JS_SetPrototype(JSContext *ctx, JSValueConst obj, JSValueConst proto...
function JSValueConst (line 6805) | static JSValueConst JS_GetPrototypePrimitive(JSContext *ctx, JSValueCons...
function JSValue (line 6843) | JSValue JS_GetPrototype(JSContext *ctx, JSValueConst obj)
function JSValue (line 6864) | static JSValue JS_GetPrototypeFree(JSContext *ctx, JSValue obj)
function JS_OrdinaryIsInstanceOf (line 6873) | static int JS_OrdinaryIsInstanceOf(JSContext *ctx, JSValueConst val,
function JS_IsInstanceOf (line 6947) | int JS_IsInstanceOf(JSContext *ctx, JSValueConst val, JSValueConst obj)
function JS_AutoInitProperty (line 6979) | static int JS_AutoInitProperty(JSContext *ctx, JSObject *p, JSAtom prop,
function JSValue (line 6992) | JSValue JS_GetPropertyInternal(JSContext *ctx, JSValueConst obj,
function JSValue (line 7141) | static JSValue JS_ThrowTypeErrorPrivateNotFound(JSContext *ctx, JSAtom a...
function JS_DefinePrivateField (line 7149) | static int JS_DefinePrivateField(JSContext *ctx, JSValueConst obj,
function JSValue (line 7184) | static JSValue JS_GetPrivateField(JSContext *ctx, JSValueConst obj,
function JS_SetPrivateField (line 7207) | static int JS_SetPrivateField(JSContext *ctx, JSValueConst obj,
function JS_AddBrand (line 7237) | static int JS_AddBrand(JSContext *ctx, JSValueConst obj, JSValueConst ho...
function JS_CheckBrand (line 7281) | static int JS_CheckBrand(JSContext *ctx, JSValueConst obj, JSValueConst ...
function num_keys_cmp (line 7322) | static int num_keys_cmp(const void *p1, const void *p2, void *opaque)
function js_free_prop_enum (line 7341) | static void js_free_prop_enum(JSContext *ctx, JSPropertyEnum *tab, uint3...
function JS_GetOwnPropertyNamesInternal (line 7353) | static int __exception JS_GetOwnPropertyNamesInternal(JSContext *ctx,
function JS_GetOwnPropertyNames (line 7555) | int JS_GetOwnPropertyNames(JSContext *ctx, JSPropertyEnum **ptab,
function JS_GetOwnPropertyInternal (line 7569) | static int JS_GetOwnPropertyInternal(JSContext *ctx, JSPropertyDescripto...
function JS_GetOwnProperty (line 7662) | int JS_GetOwnProperty(JSContext *ctx, JSPropertyDescriptor *desc,
function JS_IsExtensible (line 7673) | int JS_IsExtensible(JSContext *ctx, JSValueConst obj)
function JS_PreventExtensions (line 7687) | int JS_PreventExtensions(JSContext *ctx, JSValueConst obj)
function JS_HasProperty (line 7701) | int JS_HasProperty(JSContext *ctx, JSValueConst obj, JSAtom prop)
function JSAtom (line 7746) | static JSAtom js_symbol_to_atom(JSContext *ctx, JSValue val)
function JSAtom (line 7753) | JSAtom JS_ValueToAtom(JSContext *ctx, JSValueConst val)
function JSValue (line 7779) | static JSValue JS_GetPropertyValue(JSContext *ctx, JSValueConst this_obj,
function JSValue (line 7837) | JSValue JS_GetPropertyUint32(JSContext *ctx, JSValueConst this_obj,
function JS_TryGetPropertyInt64 (line 7848) | static int JS_TryGetPropertyInt64(JSContext *ctx, JSValueConst obj, int6...
function JSValue (line 7879) | static JSValue JS_GetPropertyInt64(JSContext *ctx, JSValueConst obj, int...
function JSValue (line 7897) | JSValue JS_GetPropertyStr(JSContext *ctx, JSValueConst this_obj,
function JSProperty (line 7910) | static JSProperty *add_property(JSContext *ctx,
function convert_fast_array_to_array (line 7953) | int convert_fast_array_to_array(JSContext *ctx,
function delete_property (line 7987) | static int delete_property(JSContext *ctx, JSObject *p, JSAtom atom)
function call_setter (line 8073) | static int call_setter(JSContext *ctx, JSObject *setter,
function set_array_length (line 8099) | static int set_array_length(JSContext *ctx, JSObject *p, JSProperty *prop,
function add_fast_array_element (line 8186) | static int add_fast_array_element(JSContext *ctx, JSObject *p,
function js_free_desc (line 8225) | static void js_free_desc(JSContext *ctx, JSPropertyDescriptor *desc)
function JS_SetPropertyGeneric (line 8233) | static int JS_SetPropertyGeneric(JSContext *ctx,
function JS_SetPropertyInternal (line 8327) | int JS_SetPropertyInternal(JSContext *ctx, JSValueConst this_obj,
function JS_SetPropertyValue (line 8554) | static int JS_SetPropertyValue(JSContext *ctx, JSValueConst this_obj,
function JS_SetPropertyUint32 (line 8690) | int JS_SetPropertyUint32(JSContext *ctx, JSValueConst this_obj,
function JS_SetPropertyInt64 (line 8697) | int JS_SetPropertyInt64(JSContext *ctx, JSValueConst this_obj,
function JS_SetPropertyStr (line 8718) | int JS_SetPropertyStr(JSContext *ctx, JSValueConst this_obj,
function get_prop_flags (line 8733) | static int get_prop_flags(int flags, int def_flags)
function JS_CreateProperty (line 8740) | static int JS_CreateProperty(JSContext *ctx, JSObject *p,
function BOOL (line 8853) | static BOOL check_define_prop_flags(int prop_flags, int flags)
function js_shape_prepare_update (line 8885) | static int js_shape_prepare_update(JSContext *ctx, JSObject *p,
function js_update_property_flags (line 8912) | static int js_update_property_flags(JSContext *ctx, JSObject *p,
function JS_DefineProperty (line 8933) | int JS_DefineProperty(JSContext *ctx, JSValueConst this_obj,
function JS_DefineAutoInitProperty (line 9194) | static int JS_DefineAutoInitProperty(JSContext *ctx, JSValueConst this_obj,
function JS_DefinePropertyValue (line 9225) | int JS_DefinePropertyValue(JSContext *ctx, JSValueConst this_obj,
function JS_DefinePropertyValueValue (line 9235) | int JS_DefinePropertyValueValue(JSContext *ctx, JSValueConst this_obj,
function JS_DefinePropertyValueUint32 (line 9251) | int JS_DefinePropertyValueUint32(JSContext *ctx, JSValueConst this_obj,
function JS_DefinePropertyValueInt64 (line 9258) | int JS_DefinePropertyValueInt64(JSContext *ctx, JSValueConst this_obj,
function JS_DefinePropertyValueStr (line 9265) | int JS_DefinePropertyValueStr(JSContext *ctx, JSValueConst this_obj,
function JS_DefinePropertyGetSet (line 9277) | int JS_DefinePropertyGetSet(JSContext *ctx, JSValueConst this_obj,
function JS_CreateDataPropertyUint32 (line 9290) | static int JS_CreateDataPropertyUint32(JSContext *ctx, JSValueConst this...
function BOOL (line 9300) | static BOOL js_object_has_name(JSContext *ctx, JSValueConst obj)
function JS_DefineObjectName (line 9319) | static int JS_DefineObjectName(JSContext *ctx, JSValueConst obj,
function JS_DefineObjectNameComputed (line 9331) | static int JS_DefineObjectNameComputed(JSContext *ctx, JSValueConst obj,
function JSValue (line 9354) | static JSValue JS_ThrowSyntaxErrorVarRedeclaration(JSContext *ctx, JSAto...
function JS_CheckDefineGlobalVar (line 9361) | static int JS_CheckDefineGlobalVar(JSContext *ctx, JSAtom prop, int flags)
function JS_DefineGlobalVar (line 9403) | static int JS_DefineGlobalVar(JSContext *ctx, JSAtom prop, int def_flags)
function JS_DefineGlobalFunction (line 9436) | static int JS_DefineGlobalFunction(JSContext *ctx, JSAtom prop,
function JSValue (line 9457) | static JSValue JS_GetGlobalVar(JSContext *ctx, JSAtom prop,
function JS_GetGlobalVarRef (line 9478) | static int JS_GetGlobalVarRef(JSContext *ctx, JSAtom prop, JSValue *sp)
function JS_CheckGlobalVar (line 9515) | static int JS_CheckGlobalVar(JSContext *ctx, JSAtom prop)
function JS_SetGlobalVar (line 9538) | static int JS_SetGlobalVar(JSContext *ctx, JSAtom prop, JSValue val,
function JS_DeleteProperty (line 9575) | int JS_DeleteProperty(JSContext *ctx, JSValueConst obj, JSAtom prop, int...
function JS_DeletePropertyInt64 (line 9597) | int JS_DeletePropertyInt64(JSContext *ctx, JSValueConst obj, int64_t idx...
function BOOL (line 9614) | BOOL JS_IsFunction(JSContext *ctx, JSValueConst val)
function BOOL (line 9630) | BOOL JS_IsCFunction(JSContext *ctx, JSValueConst val, JSCFunction *func,...
function BOOL (line 9642) | BOOL JS_IsConstructor(JSContext *ctx, JSValueConst val)
function BOOL (line 9651) | BOOL JS_SetConstructorBit(JSContext *ctx, JSValueConst func_obj, BOOL val)
function BOOL (line 9661) | BOOL JS_IsError(JSContext *ctx, JSValueConst val)
function BOOL (line 9671) | BOOL JS_IsUncatchableError(JSContext *ctx, JSValueConst val)
function JS_SetUncatchableError (line 9680) | void JS_SetUncatchableError(JSContext *ctx, JSValueConst val, BOOL flag)
function JS_ResetUncatchableError (line 9690) | void JS_ResetUncatchableError(JSContext *ctx)
function JS_SetOpaque (line 9695) | void JS_SetOpaque(JSValue obj, void *opaque)
function JSValue (line 9731) | static JSValue JS_ToPrimitiveFree(JSContext *ctx, JSValue val, int hint)
function JSValue (line 9805) | static JSValue JS_ToPrimitive(JSContext *ctx, JSValueConst val, int hint)
function JS_ToBoolFree (line 9810) | static int JS_ToBoolFree(JSContext *ctx, JSValue val)
function JS_ToBool (line 9858) | int JS_ToBool(JSContext *ctx, JSValueConst val)
function skip_spaces (line 9863) | static int skip_spaces(const char *pc)
function to_digit (line 9885) | static inline int to_digit(int c)
function js_strtod (line 9898) | static double js_strtod(const char *p, int radix, BOOL is_float)
function JSValue (line 9968) | static JSValue js_string_to_bigint(JSContext *ctx, const char *buf,
function JSValue (line 9987) | static JSValue js_string_to_bigfloat(JSContext *ctx, const char *buf,
function JSValue (line 10013) | static JSValue js_string_to_bigdecimal(JSContext *ctx, const char *buf,
function JSValue (line 10041) | static JSValue js_atof(JSContext *ctx, const char *str, const char **pp,
function JSValue (line 10278) | static JSValue js_atof(JSContext *ctx, const char *str, const char **pp,
type JSToNumberHintEnum (line 10285) | typedef enum JSToNumberHintEnum {
function JSValue (line 10290) | static JSValue JS_ToNumberHintFree(JSContext *ctx, JSValue val,
function JSValue (line 10378) | static JSValue JS_ToNumberFree(JSContext *ctx, JSValue val)
function JSValue (line 10383) | static JSValue JS_ToNumericFree(JSContext *ctx, JSValue val)
function JSValue (line 10388) | static JSValue JS_ToNumeric(JSContext *ctx, JSValueConst val)
function __exception (line 10393) | static __exception int __JS_ToFloat64Free(JSContext *ctx, double *pres,
function JS_ToFloat64Free (line 10432) | static inline int JS_ToFloat64Free(JSContext *ctx, double *pres, JSValue...
function JS_ToFloat64 (line 10448) | int JS_ToFloat64(JSContext *ctx, double *pres, JSValueConst val)
function JSValue (line 10453) | static JSValue JS_ToNumber(JSContext *ctx, JSValueConst val)
function __maybe_unused (line 10459) | static __maybe_unused JSValue JS_ToIntegerFree(JSContext *ctx, JSValue val)
function JS_ToInt32SatFree (line 10523) | static int JS_ToInt32SatFree(JSContext *ctx, int *pres, JSValue val)
function JS_ToInt32Sat (line 10576) | int JS_ToInt32Sat(JSContext *ctx, int *pres, JSValueConst val)
function JS_ToInt32Clamp (line 10581) | int JS_ToInt32Clamp(JSContext *ctx, int *pres, JSValueConst val,
function JS_ToInt64SatFree (line 10598) | static int JS_ToInt64SatFree(JSContext *ctx, int64_t *pres, JSValue val)
function JS_ToInt64Sat (line 10648) | int JS_ToInt64Sat(JSContext *ctx, int64_t *pres, JSValueConst val)
function JS_ToInt64Clamp (line 10653) | int JS_ToInt64Clamp(JSContext *ctx, int64_t *pres, JSValueConst val,
function JS_ToInt64Free (line 10670) | static int JS_ToInt64Free(JSContext *ctx, int64_t *pres, JSValue val)
function JS_ToInt64 (line 10730) | int JS_ToInt64(JSContext *ctx, int64_t *pres, JSValueConst val)
function JS_ToInt64Ext (line 10735) | int JS_ToInt64Ext(JSContext *ctx, int64_t *pres, JSValueConst val)
function JS_ToInt32Free (line 10744) | static int JS_ToInt32Free(JSContext *ctx, int32_t *pres, JSValue val)
function JS_ToInt32 (line 10805) | int JS_ToInt32(JSContext *ctx, int32_t *pres, JSValueConst val)
function JS_ToUint32Free (line 10810) | static inline int JS_ToUint32Free(JSContext *ctx, uint32_t *pres, JSValu...
function JS_ToUint8ClampFree (line 10815) | static int JS_ToUint8ClampFree(JSContext *ctx, int32_t *pres, JSValue val)
function __exception (line 10874) | static __exception int JS_ToArrayLengthFree(JSContext *ctx, uint32_t *plen,
function BOOL (line 10935) | static BOOL is_safe_integer(double d)
function JS_ToIndex (line 10941) | int JS_ToIndex(JSContext *ctx, uint64_t *plen, JSValueConst val)
function __exception (line 10957) | static __exception int JS_ToLengthFree(JSContext *ctx, int64_t *plen,
function JS_NumberIsInteger (line 10966) | static int JS_NumberIsInteger(JSContext *ctx, JSValueConst val)
function BOOL (line 10976) | static BOOL JS_NumberIsNegativeOrMinusZero(JSContext *ctx, JSValueConst ...
function JSValue (line 11021) | static JSValue js_bigint_to_string1(JSContext *ctx, JSValueConst val, in...
function JSValue (line 11045) | static JSValue js_bigint_to_string(JSContext *ctx, JSValueConst val)
function JSValue (line 11050) | static JSValue js_ftoa(JSContext *ctx, JSValueConst val1, int radix,
function JSValue (line 11104) | static JSValue js_bigfloat_to_string(JSContext *ctx, JSValueConst val)
function JSValue (line 11109) | static JSValue js_bigdecimal_to_string1(JSContext *ctx, JSValueConst val,
function JSValue (line 11130) | static JSValue js_bigdecimal_to_string(JSContext *ctx, JSValueConst val)
function js_ecvt1 (line 11165) | static void js_ecvt1(double d, int n_digits, int *decpt, int *sign, char...
function js_ecvt (line 11188) | static int js_ecvt(double d, int n_digits, int *decpt, int *sign, char *...
function js_fcvt1 (line 11248) | static int js_fcvt1(char *buf, int buf_size, double d, int n_digits,
function js_fcvt (line 11261) | static void js_fcvt(char *buf, int buf_size, double d, int n_digits)
function js_dtoa1 (line 11307) | static void js_dtoa1(char *buf, double d, int radix, int n_digits, int f...
function JSValue (line 11396) | static JSValue js_dtoa(JSContext *ctx,
function JSValue (line 11404) | JSValue JS_ToStringInternal(JSContext *ctx, JSValueConst val, BOOL is_To...
function JSValue (line 11465) | JSValue JS_ToString(JSContext *ctx, JSValueConst val)
function JSValue (line 11470) | static JSValue JS_ToStringFree(JSContext *ctx, JSValue val)
function JSValue (line 11478) | static JSValue JS_ToLocaleStringFree(JSContext *ctx, JSValue val)
function JSValue (line 11485) | JSValue JS_ToPropertyKey(JSContext *ctx, JSValueConst val)
function JSValue (line 11490) | static JSValue JS_ToStringCheckObject(JSContext *ctx, JSValueConst val)
function JSValue (line 11498) | static JSValue JS_ToQuotedString(JSContext *ctx, JSValueConst val1)
function __maybe_unused (line 11565) | static __maybe_unused void JS_DumpObjectHeader(JSRuntime *rt)
function __maybe_unused (line 11572) | static __maybe_unused void JS_DumpObject(JSRuntime *rt, JSObject *p)
function __maybe_unused (line 11666) | static __maybe_unused void JS_DumpGCObject(JSRuntime *rt, JSGCObjectHead...
function __maybe_unused (line 11698) | static __maybe_unused void JS_DumpValueShort(JSRuntime *rt,
function __maybe_unused (line 11803) | static __maybe_unused void JS_DumpValue(JSContext *ctx,
function __maybe_unused (line 11809) | static __maybe_unused void JS_PrintValue(JSContext *ctx,
function JS_IsArray (line 11819) | int JS_IsArray(JSContext *ctx, JSValueConst val)
function js_pow (line 11833) | static double js_pow(double a, double b)
function JSValue (line 11845) | JSValue JS_NewBigInt64_1(JSContext *ctx, int64_t v)
function JSValue (line 11860) | JSValue JS_NewBigInt64(JSContext *ctx, int64_t v)
function JSValue (line 11870) | JSValue JS_NewBigUint64(JSContext *ctx, uint64_t v)
function bf_t (line 11892) | static bf_t *JS_ToBigFloat(JSContext *ctx, bf_t *buf, JSValueConst val)
function bfdec_t (line 11933) | static bfdec_t *JS_ToBigDecimal(JSContext *ctx, JSValueConst val)
function JSValue (line 11954) | static JSValue JS_StringToBigInt(JSContext *ctx, JSValue val)
function JSValue (line 11985) | static JSValue JS_StringToBigIntErr(JSContext *ctx, JSValue val)
function bf_t (line 11995) | static bf_t *JS_ToBigIntFree(JSContext *ctx, bf_t *buf, JSValue val)
function bf_t (line 12063) | static bf_t *JS_ToBigInt(JSContext *ctx, bf_t *buf, JSValueConst val)
function __maybe_unused (line 12068) | static __maybe_unused JSValue JS_ToBigIntValueFree(JSContext *ctx, JSVal...
function JS_FreeBigInt (line 12097) | static void JS_FreeBigInt(JSContext *ctx, bf_t *a, bf_t *buf)
function JS_ToBigInt64Free (line 12109) | static int JS_ToBigInt64Free(JSContext *ctx, int64_t *pres, JSValue val)
function JS_ToBigInt64 (line 12123) | int JS_ToBigInt64(JSContext *ctx, int64_t *pres, JSValueConst val)
function JSBigFloat (line 12128) | static JSBigFloat *js_new_bf(JSContext *ctx)
function JSValue (line 12139) | static JSValue JS_NewBigFloat(JSContext *ctx)
function JSValue (line 12150) | static JSValue JS_NewBigDecimal(JSContext *ctx)
function JSValue (line 12161) | static JSValue JS_NewBigInt(JSContext *ctx)
function JSValue (line 12172) | static JSValue JS_CompactBigInt1(JSContext *ctx, JSValue val,
function JSValue (line 12197) | static JSValue JS_CompactBigInt(JSContext *ctx, JSValue val)
function get_ovop_from_opcode (line 12226) | static int get_ovop_from_opcode(OPCodeEnum op)
function JSObject (line 12276) | static JSObject *find_binary_op(JSBinaryOperatorDef *def,
function __exception (line 12292) | static __exception int js_call_binary_op_fallback(JSContext *ctx,
function __exception (line 12421) | static __exception int js_call_binary_op_simple(JSContext *ctx,
function __exception (line 12478) | static __exception int js_call_unary_op_fallback(JSContext *ctx,
function JSValue (line 12525) | static JSValue throw_bf_exception(JSContext *ctx, int status)
function js_unary_arith_bigint (line 12540) | static int js_unary_arith_bigint(JSContext *ctx,
function js_unary_arith_bigfloat (line 12592) | static int js_unary_arith_bigfloat(JSContext *ctx,
function js_unary_arith_bigdecimal (line 12641) | static int js_unary_arith_bigdecimal(JSContext *ctx,
function js_unary_arith_slow (line 12688) | int js_unary_arith_slow(JSContext *ctx,
function __exception (line 12786) | static __exception int js_post_inc_slow(JSContext *ctx,
function no_inline (line 12803) | static no_inline int js_not_slow(JSContext *ctx, JSValue *sp)
function js_binary_arith_bigfloat (line 12838) | static int js_binary_arith_bigfloat(JSContext *ctx, OPCodeEnum op,
function js_binary_arith_bigint (line 12899) | static int js_binary_arith_bigint(JSContext *ctx, OPCodeEnum op,
function js_bfdec_pow (line 13055) | static int js_bfdec_pow(bfdec_t *r, const bfdec_t *a, const bfdec_t *b)
function js_binary_arith_bigdecimal (line 13081) | static int js_binary_arith_bigdecimal(JSContext *ctx, OPCodeEnum op,
function js_binary_arith_slow (line 13141) | int js_binary_arith_slow(JSContext *ctx, JSValue *sp,
function js_add_slow (line 13305) | int js_add_slow(JSContext *ctx, JSValue *sp)
function js_binary_logic_slow (line 13419) | int js_binary_logic_slow(JSContext *ctx,
function js_compare_bigfloat (line 13514) | static int js_compare_bigfloat(JSContext *ctx, OPCodeEnum op,
function js_compare_bigdecimal (line 13560) | static int js_compare_bigdecimal(JSContext *ctx, OPCodeEnum op,
function no_inline (line 13606) | static no_inline int js_relational_slow(JSContext *ctx, JSValue *sp,
function BOOL (line 13756) | static BOOL tag_is_number(uint32_t tag)
function js_eq_slow (line 13763) | int js_eq_slow(JSContext *ctx, JSValue *sp,
function no_inline (line 13912) | static no_inline int js_shr_slow(JSContext *ctx, JSValue *sp)
function JSValue (line 13950) | static JSValue js_mul_pow10_to_float64(JSContext *ctx, const bf_t *a,
function no_inline (line 13970) | static no_inline int js_mul_pow10(JSContext *ctx, JSValue *sp)
function JSValue (line 14009) | static JSValue JS_ThrowUnsupportedBigint(JSContext *ctx)
function JSValue (line 14014) | JSValue JS_NewBigInt64(JSContext *ctx, int64_t v)
function JSValue (line 14019) | JSValue JS_NewBigUint64(JSContext *ctx, uint64_t v)
function JS_ToBigInt64 (line 14024) | int JS_ToBigInt64(JSContext *ctx, int64_t *pres, JSValueConst val)
function js_unary_arith_slow (line 14031) | int js_unary_arith_slow(JSContext *ctx,
function __exception (line 14063) | static __exception int js_post_inc_slow(JSContext *ctx,
function js_binary_arith_slow (line 14080) | int js_binary_arith_slow(JSContext *ctx, JSValue *sp,
function js_add_slow (line 14122) | int js_add_slow(JSContext *ctx, JSValue *sp)
function js_binary_logic_slow (line 14170) | int js_binary_logic_slow(JSContext *ctx,
function no_inline (line 14212) | static no_inline int js_not_slow(JSContext *ctx, JSValue *sp)
function no_inline (line 14224) | static no_inline int js_relational_slow(JSContext *ctx, JSValue *sp,
function js_eq_slow (line 14297) | int js_eq_slow(JSContext *ctx, JSValue *sp,
function no_inline (line 14364) | static no_inline int js_shr_slow(JSContext *ctx, JSValue *sp)
function BOOL (line 14389) | static BOOL js_strict_eq2(JSContext *ctx, JSValue op1, JSValue op2,
function BOOL (line 14547) | static BOOL js_strict_eq(JSContext *ctx, JSValue op1, JSValue op2)
function BOOL (line 14552) | static BOOL js_same_value(JSContext *ctx, JSValueConst op1, JSValueConst...
function BOOL (line 14559) | static BOOL js_same_value_zero(JSContext *ctx, JSValueConst op1, JSValue...
function no_inline (line 14566) | static no_inline int js_strict_eq_slow(JSContext *ctx, JSValue *sp,
function __exception (line 14575) | static __exception int js_operator_in(JSContext *ctx, JSValue *sp)
function __exception (line 14601) | static __exception int js_has_unscopable(JSContext *ctx, JSValueConst obj,
function __exception (line 14619) | static __exception int js_operator_instanceof(JSContext *ctx, JSValue *sp)
function __exception (line 14635) | static __exception int js_operator_typeof(JSContext *ctx, JSValue op1)
function __exception (line 14686) | static __exception int js_operator_delete(JSContext *ctx, JSValue *sp)
function JSValue (line 14707) | static JSValue js_throw_type_error(JSContext *ctx, JSValueConst this_val,
function JSValue (line 14716) | static JSValue js_function_proto_caller(JSContext *ctx, JSValueConst thi...
function JSValue (line 14726) | static JSValue js_function_proto_fileName(JSContext *ctx,
function JSValue (line 14736) | static JSValue js_function_proto_lineNumber(JSContext *ctx,
function js_arguments_define_own_property (line 14746) | static int js_arguments_define_own_property(JSContext *ctx,
function JSValue (line 14769) | static JSValue js_build_arguments(JSContext *ctx, int argc, JSValueConst...
function JSValue (line 14816) | static JSValue js_build_mapped_arguments(JSContext *ctx, int argc,
function JSValue (line 14871) | static JSValue js_build_rest(JSContext *ctx, int first, int argc, JSValu...
function JSValue (line 14891) | static JSValue build_for_in_iterator(JSContext *ctx, JSValue obj)
function __exception (line 14995) | static __exception int js_for_in_start(JSContext *ctx, JSValue *sp)
function __exception (line 15004) | static __exception int js_for_in_next(JSContext *ctx, JSValue *sp)
function JSValue (line 15056) | static JSValue JS_GetIterator2(JSContext *ctx, JSValueConst obj,
function JSValue (line 15071) | static JSValue JS_GetIterator(JSContext *ctx, JSValueConst obj, BOOL is_...
function JSValue (line 15106) | static JSValue JS_IteratorNext2(JSContext *ctx, JSValueConst enum_obj,
function JSValue (line 15146) | static JSValue JS_IteratorNext(JSContext *ctx, JSValueConst enum_obj,
function JS_IteratorClose (line 15178) | static int JS_IteratorClose(JSContext *ctx, JSValueConst enum_obj,
function __exception (line 15218) | static __exception int js_for_of_start(JSContext *ctx, JSValue *sp,
function __exception (line 15236) | static __exception int js_for_of_next(JSContext *ctx, JSValue *sp, int o...
function __exception (line 15259) | static __exception int js_for_await_of_next(JSContext *ctx, JSValue *sp)
function JSValue (line 15269) | static JSValue JS_IteratorGetCompleteValue(JSContext *ctx, JSValueConst ...
function __exception (line 15288) | static __exception int js_iterator_get_value_done(JSContext *ctx, JSValu...
function JSValue (line 15306) | static JSValue js_create_iterator_result(JSContext *ctx,
function BOOL (line 15336) | static BOOL js_is_fast_array(JSContext *ctx, JSValueConst obj)
function BOOL (line 15349) | static BOOL js_get_fast_array(JSContext *ctx, JSValueConst obj,
function __exception (line 15364) | static __exception int js_append_enumerate(JSContext *ctx, JSValue *sp)
function __exception (line 15446) | static __exception int JS_CopyDataProperties(JSContext *ctx,
function JSValueConst (line 15500) | static JSValueConst JS_GetActiveFunction(JSContext *ctx)
function JSVarRef (line 15505) | static JSVarRef *get_var_ref(JSContext *ctx, JSStackFrame *sf,
function JSValue (line 15535) | static JSValue js_closure2(JSContext *ctx, JSValue func_obj,
function js_instantiate_prototype (line 15575) | static int js_instantiate_prototype(JSContext *ctx, JSObject *p, JSAtom ...
function JSValue (line 15601) | static JSValue js_closure(JSContext *ctx, JSValue bfunc,
function js_op_define_class (line 15658) | static int js_op_define_class(JSContext *ctx, JSValue *sp,
function close_var_refs (line 15753) | static void close_var_refs(JSRuntime *rt, JSStackFrame *sf)
function close_lexical_var (line 15773) | static void close_lexical_var(JSContext *ctx, JSStackFrame *sf, int idx,...
function JSValue (line 15795) | static JSValue js_call_c_function(JSContext *ctx, JSValueConst func_obj,
function JSValue (line 15934) | static JSValue js_call_bound_function(JSContext *ctx, JSValueConst func_...
type OPSpecialObjectEnum (line 15968) | typedef enum {
function SWITCH (line 16108) | SWITCH(pc) {
function CASE (line 16203) | CASE(OP_special_object):
function CASE (line 16249) | CASE(OP_rest):
function CASE (line 16315) | CASE(OP_perm3): /* obj a b -> a obj b (213) */
function CASE (line 16323) | CASE(OP_rot3l): /* x a b -> a b x (231) */
function CASE (line 16332) | CASE(OP_rot4l): /* x a b c -> a b c x */
function CASE (line 16342) | CASE(OP_rot5l): /* x a b c d -> a b c d x */
function CASE (line 16353) | CASE(OP_rot3r): /* a b x -> x a b (312) */
function CASE (line 16362) | CASE(OP_perm4): /* obj prop a b -> a obj prop b */
function CASE (line 16371) | CASE(OP_perm5): /* this obj prop a b -> a this obj prop b */
function CASE (line 16381) | CASE(OP_swap): /* a b -> b a */
function CASE (line 16389) | CASE(OP_swap2): /* a b c d -> c d a b */
function CASE (line 16401) | CASE(OP_fclosure):
function CASE (line 16411) | CASE(OP_call0):
function CASE (line 16499) | CASE(OP_apply):
function CASE (line 16535) | CASE(OP_check_ctor):
function CASE (line 16584) | CASE(OP_eval):
function CASE (line 16613) | CASE(OP_apply_eval):
function CASE (line 16646) | CASE(OP_regexp):
function CASE (line 16654) | CASE(OP_get_super):
function CASE (line 16665) | CASE(OP_import):
function CASE (line 16676) | CASE(OP_check_var):
function CASE (line 16720) | CASE(OP_put_var_strict):
function CASE (line 16739) | CASE(OP_check_define_var):
function CASE (line 16750) | CASE(OP_define_var):
function CASE (line 16761) | CASE(OP_define_func):
function CASE (line 16775) | CASE(OP_get_loc):
function CASE (line 16784) | CASE(OP_put_loc):
function CASE (line 16793) | CASE(OP_set_loc):
function CASE (line 16801) | CASE(OP_get_arg):
function CASE (line 16810) | CASE(OP_put_arg):
function CASE (line 16819) | CASE(OP_set_arg):
function CASE (line 16871) | CASE(OP_get_var_ref):
function CASE (line 16882) | CASE(OP_put_var_ref):
function CASE (line 16891) | CASE(OP_set_var_ref):
function CASE (line 16899) | CASE(OP_get_var_ref_check):
function CASE (line 16914) | CASE(OP_put_var_ref_check):
function CASE (line 16927) | CASE(OP_put_var_ref_check_init):
function CASE (line 16940) | CASE(OP_set_loc_uninitialized):
function CASE (line 16948) | CASE(OP_get_loc_check):
function CASE (line 16961) | CASE(OP_put_loc_check):
function CASE (line 16974) | CASE(OP_put_loc_check_init):
function CASE (line 16987) | CASE(OP_close_loc):
function CASE (line 17028) | CASE(OP_make_var_ref):
function CASE (line 17057) | CASE(OP_if_true):
function CASE (line 17077) | CASE(OP_if_false):
function CASE (line 17098) | CASE(OP_if_true8):
function CASE (line 17118) | CASE(OP_if_false8):
function CASE (line 17139) | CASE(OP_catch):
function CASE (line 17148) | CASE(OP_gosub):
function CASE (line 17158) | CASE(OP_ret):
function CASE (line 17191) | CASE(OP_for_of_next):
function CASE (line 17229) | CASE(OP_iterator_close_return):
function CASE (line 17252) | CASE(OP_async_iterator_close):
function CASE (line 17282) | CASE(OP_async_iterator_next):
function CASE (line 17295) | CASE(OP_async_iterator_get):
function CASE (line 17326) | CASE(OP_lnot):
function CASE (line 17341) | CASE(OP_get_field):
function CASE (line 17356) | CASE(OP_get_field2):
function CASE (line 17370) | CASE(OP_put_field):
function CASE (line 17386) | CASE(OP_private_symbol):
function CASE (line 17400) | CASE(OP_get_private_field):
function CASE (line 17414) | CASE(OP_put_private_field):
function CASE (line 17426) | CASE(OP_define_private_field):
function CASE (line 17437) | CASE(OP_define_field):
function CASE (line 17452) | CASE(OP_set_name):
function CASE (line 17464) | CASE(OP_set_name_computed):
function CASE (line 17472) | CASE(OP_set_proto):
function CASE (line 17487) | CASE(OP_define_method):
function CASE (line 17547) | CASE(OP_define_class):
function CASE (line 17607) | CASE(OP_get_super_value):
function CASE (line 17626) | CASE(OP_put_array_el):
function CASE (line 17638) | CASE(OP_put_ref_value):
function CASE (line 17661) | CASE(OP_put_super_value):
function CASE (line 17685) | CASE(OP_define_array_el):
function CASE (line 17696) | CASE(OP_append): /* array pos enumobj -- array pos */
function CASE (line 17704) | CASE(OP_copy_data_properties): /* target source excludeList */
function CASE (line 17720) | CASE(OP_add):
function CASE (line 17744) | CASE(OP_add_loc):
function CASE (line 17790) | CASE(OP_sub):
function CASE (line 17811) | CASE(OP_mul):
function CASE (line 17853) | CASE(OP_div):
function CASE (line 17873) | CASE(OP_math_mod):
function CASE (line 17902) | CASE(OP_plus):
function CASE (line 17915) | CASE(OP_neg):
function CASE (line 17945) | CASE(OP_inc):
function CASE (line 17962) | CASE(OP_dec):
function CASE (line 17985) | CASE(OP_inc_loc):
function CASE (line 18006) | CASE(OP_dec_loc):
function CASE (line 18027) | CASE(OP_not):
function CASE (line 18040) | CASE(OP_shl):
function CASE (line 18077) | CASE(OP_shr):
function CASE (line 18098) | CASE(OP_sar):
function CASE (line 18129) | CASE(OP_and):
function CASE (line 18146) | CASE(OP_or):
function CASE (line 18163) | CASE(OP_xor):
function CASE (line 18225) | CASE(OP_typeof):
function CASE (line 18241) | CASE(OP_delete_var):
function CASE (line 18266) | CASE(OP_to_propkey):
function CASE (line 18313) | CASE(OP_with_get_var):
function CASE (line 18400) | CASE(OP_yield_star):
function JSValue (line 18505) | JSValue JS_Call(JSContext *ctx, JSValueConst func_obj, JSValueConst this...
function JSValue (line 18512) | static JSValue JS_CallFree(JSContext *ctx, JSValue func_obj, JSValueCons...
function JSContext (line 18523) | static JSContext *JS_GetFunctionRealm(JSContext *ctx, JSValueConst func_...
function JSValue (line 18571) | static JSValue js_create_from_ctor(JSContext *ctx, JSValueConst ctor,
function JSValue (line 18597) | static JSValue JS_CallConstructorInternal(JSContext *ctx,
function JSValue (line 18645) | JSValue JS_CallConstructor2(JSContext *ctx, JSValueConst func_obj,
function JSValue (line 18654) | JSValue JS_CallConstructor(JSContext *ctx, JSValueConst func_obj,
function JSValue (line 18662) | JSValue JS_Invoke(JSContext *ctx, JSValueConst this_val, JSAtom atom,
function JSValue (line 18672) | static JSValue JS_InvokeFree(JSContext *ctx, JSValue this_val, JSAtom atom,
function __exception (line 18681) | static __exception int async_func_init(JSContext *ctx, JSAsyncFunctionSt...
function async_func_mark (line 18715) | static void async_func_mark(JSRuntime *rt, JSAsyncFunctionState *s,
function async_func_free (line 18734) | static void async_func_free(JSRuntime *rt, JSAsyncFunctionState *s)
function JSValue (line 18756) | static JSValue async_func_resume(JSContext *ctx, JSAsyncFunctionState *s)
type JSGeneratorStateEnum (line 18772) | typedef enum JSGeneratorStateEnum {
type JSGeneratorData (line 18780) | typedef struct JSGeneratorData {
function free_generator_stack_rt (line 18785) | static void free_generator_stack_rt(JSRuntime *rt, JSGeneratorData *s)
function js_generator_finalizer (line 18793) | static void js_generator_finalizer(JSRuntime *rt, JSValue obj)
function free_generator_stack (line 18803) | static void free_generator_stack(JSContext *ctx, JSGeneratorData *s)
function js_generator_mark (line 18808) | static void js_generator_mark(JSRuntime *rt, JSValueConst val,
function JSValue (line 18824) | static JSValue js_generator_next(JSContext *ctx, JSValueConst this_val,
function JSValue (line 18985) | static JSValue js_generator_function_call(JSContext *ctx, JSValueConst f...
function js_async_function_terminate (line 19021) | static void js_async_function_terminate(JSRuntime *rt, JSAsyncFunctionDa...
function js_async_function_free0 (line 19029) | static void js_async_function_free0(JSRuntime *rt, JSAsyncFunctionData *s)
function js_async_function_free (line 19038) | static void js_async_function_free(JSRuntime *rt, JSAsyncFunctionData *s)
function js_async_function_resolve_finalizer (line 19045) | static void js_async_function_resolve_finalizer(JSRuntime *rt, JSValue val)
function js_async_function_resolve_mark (line 19054) | static void js_async_function_resolve_mark(JSRuntime *rt, JSValueConst val,
function js_async_function_resolve_create (line 19064) | static int js_async_function_resolve_create(JSContext *ctx,
function js_async_function_resume (line 19087) | static void js_async_function_resume(JSContext *ctx, JSAsyncFunctionData...
function JSValue (line 19144) | static JSValue js_async_function_resolve_call(JSContext *ctx,
function JSValue (line 19170) | static JSValue js_async_function_call(JSContext *ctx, JSValueConst func_...
type JSAsyncGeneratorStateEnum (line 19207) | typedef enum JSAsyncGeneratorStateEnum {
type JSAsyncGeneratorRequest (line 19216) | typedef struct JSAsyncGeneratorRequest {
type JSAsyncGeneratorData (line 19226) | typedef struct JSAsyncGeneratorData {
function js_async_generator_free (line 19233) | static void js_async_generator_free(JSRuntime *rt,
function js_async_generator_finalizer (line 19254) | static void js_async_generator_finalizer(JSRuntime *rt, JSValue obj)
function js_async_generator_mark (line 19263) | static void js_async_generator_mark(JSRuntime *rt, JSValueConst val,
function js_async_generator_resolve_function_create (line 19289) | static int js_async_generator_resolve_function_create(JSContext *ctx,
function js_async_generator_await (line 19310) | static int js_async_generator_await(JSContext *ctx,
function js_async_generator_resolve_or_reject (line 19345) | static void js_async_generator_resolve_or_reject(JSContext *ctx,
function js_async_generator_resolve (line 19365) | static void js_async_generator_resolve(JSContext *ctx,
function js_async_generator_reject (line 19377) | static void js_async_generator_reject(JSContext *ctx,
function js_async_generator_complete (line 19384) | static void js_async_generator_complete(JSContext *ctx,
function js_async_generator_completed_return (line 19393) | static int js_async_generator_completed_return(JSContext *ctx,
function js_async_generator_resume_next (line 19422) | static void js_async_generator_resume_next(JSContext *ctx,
function JSValue (line 19520) | static JSValue js_async_generator_resolve_function(JSContext *ctx,
function JSValue (line 19557) | static JSValue js_async_generator_next(JSContext *ctx, JSValueConst this...
function JSValue (line 19600) | static JSValue js_async_generator_function_call(JSContext *ctx, JSValueC...
type BlockEnv (line 19748) | typedef struct BlockEnv {
type JSHoistedDef (line 19759) | typedef struct JSHoistedDef {
type RelocEntry (line 19769) | typedef struct RelocEntry {
type JumpSlot (line 19775) | typedef struct JumpSlot {
type LabelSlot (line 19782) | typedef struct LabelSlot {
type LineNumberSlot (line 19790) | typedef struct LineNumberSlot {
type JSParseFunctionEnum (line 19795) | typedef enum JSParseFunctionEnum {
type JSParseExportEnum (line 19807) | typedef enum JSParseExportEnum {
type JSFunctionDef (line 19813) | typedef struct JSFunctionDef {
type JSToken (line 19919) | typedef struct JSToken {
type JSParseState (line 19946) | typedef struct JSParseState {
type JSOpCode (line 19964) | typedef struct JSOpCode {
function free_token (line 20002) | static void free_token(JSParseState *s, JSToken *token)
function dump_token (line 20028) | static void __attribute((unused)) dump_token(JSParseState *s,
function js_parse_error (line 20089) | int __attribute__((format(printf, 2, 3))) js_parse_error(JSParseState *s...
function js_parse_expect (line 20106) | static int js_parse_expect(JSParseState *s, int tok)
function js_parse_expect_semi (line 20115) | static int js_parse_expect_semi(JSParseState *s)
function js_parse_error_reserved_identifier (line 20127) | static int js_parse_error_reserved_identifier(JSParseState *s)
function __exception (line 20135) | static __exception int js_parse_template_part(JSParseState *s, const uin...
function __exception (line 20196) | static __exception int js_parse_string(JSParseState *s, int sep,
function BOOL (line 20328) | static inline BOOL token_is_pseudo_keyword(JSParseState *s, JSAtom atom) {
function __exception (line 20333) | static __exception int js_parse_regexp(JSParseState *s)
function __exception (line 20431) | static __exception int ident_realloc(JSContext *ctx, char **pbuf, size_t...
function JSAtom (line 20459) | static JSAtom parse_ident(JSParseState *s, const uint8_t **pp,
function __exception (line 20507) | static __exception int next_token(JSParseState *s)
function JSAtom (line 20993) | static JSAtom json_parse_ident(JSParseState *s, const uint8_t **pp, int c)
function __exception (line 21026) | static __exception int json_next_token(JSParseState *s)
function simple_next_token (line 21209) | static int simple_next_token(const uint8_t **pp, BOOL no_line_terminator)
function peek_token (line 21285) | static int peek_token(JSParseState *s, BOOL no_line_terminator)
function BOOL (line 21297) | BOOL JS_DetectModule(const char *input, size_t input_len)
function get_prev_opcode (line 21312) | static inline int get_prev_opcode(JSFunctionDef *fd) {
function BOOL (line 21319) | static BOOL js_is_live_code(JSParseState *s) {
function emit_u8 (line 21340) | static void emit_u8(JSParseState *s, uint8_t val)
function emit_u16 (line 21345) | static void emit_u16(JSParseState *s, uint16_t val)
function emit_u32 (line 21350) | static void emit_u32(JSParseState *s, uint32_t val)
function emit_op (line 21355) | static void emit_op(JSParseState *s, uint8_t val)
function emit_atom (line 21372) | static void emit_atom(JSParseState *s, JSAtom name)
function update_label (line 21377) | static int update_label(JSFunctionDef *s, int label, int delta)
function new_label_fd (line 21388) | static int new_label_fd(JSFunctionDef *fd, int label)
function new_label (line 21408) | static int new_label(JSParseState *s)
function emit_label (line 21414) | static int emit_label(JSParseState *s, int label)
function emit_goto (line 21427) | static int emit_goto(JSParseState *s, int opcode, int label)
function cpool_add (line 21441) | static int cpool_add(JSParseState *s, JSValue val)
function __exception (line 21452) | static __exception int emit_push_const(JSParseState *s, JSValueConst val,
function find_arg (line 21479) | static int find_arg(JSContext *ctx, JSFunctionDef *fd, JSAtom name)
function find_var (line 21489) | static int find_var(JSContext *ctx, JSFunctionDef *fd, JSAtom name)
function BOOL (line 21501) | static BOOL is_child_scope(JSContext *ctx, JSFunctionDef *fd,
function find_var_in_child_scope (line 21513) | static int find_var_in_child_scope(JSContext *ctx, JSFunctionDef *fd,
function JSHoistedDef (line 21529) | static JSHoistedDef *find_hoisted_def(JSFunctionDef *fd, JSAtom name)
function JSHoistedDef (line 21541) | static JSHoistedDef *find_lexical_hoisted_def(JSFunctionDef *fd, JSAtom ...
function find_lexical_decl (line 21550) | static int find_lexical_decl(JSContext *ctx, JSFunctionDef *fd, JSAtom n...
function push_scope (line 21569) | static int push_scope(JSParseState *s) {
function get_first_lexical_var (line 21604) | static int get_first_lexical_var(JSFunctionDef *fd, int scope)
function pop_scope (line 21615) | static void pop_scope(JSParseState *s) {
function close_scopes (line 21627) | static void close_scopes(JSParseState *s, int scope, int scope_stop)
function add_var (line 21637) | static int add_var(JSContext *ctx, JSFunctionDef *fd, JSAtom name)
function add_scope_var (line 21655) | static int add_scope_var(JSContext *ctx, JSFunctionDef *fd, JSAtom name,
function add_func_var (line 21670) | static int add_func_var(JSContext *ctx, JSFunctionDef *fd, JSAtom name)
function add_arguments_var (line 21682) | static int add_arguments_var(JSContext *ctx, JSFunctionDef *fd, JSAtom n...
function add_arg (line 21691) | static int add_arg(JSContext *ctx, JSFunctionDef *fd, JSAtom name)
function JSHoistedDef (line 21711) | static JSHoistedDef *add_hoisted_def(JSContext *ctx,
type JSVarDefEnum (line 21735) | typedef enum {
function define_var (line 21745) | static int define_var(JSParseState *s, JSFunctionDef *fd, JSAtom name,
function add_private_class_field (line 21873) | static int add_private_class_field(JSParseState *s, JSFunctionDef *fd,
function seal_template_obj (line 21916) | static int seal_template_obj(JSContext *ctx, JSValueConst obj)
function __exception (line 21932) | static __exception int js_parse_template(JSParseState *s, int call, int ...
function BOOL (line 22054) | static BOOL token_is_ident(int tok)
function js_parse_property_name (line 22063) | static int __exception js_parse_property_name(JSParseState *s,
type JSParsePos (line 22189) | typedef struct JSParsePos {
function js_parse_get_pos (line 22196) | static int js_parse_get_pos(JSParseState *s, JSParsePos *sp)
function __exception (line 22205) | static __exception int js_parse_seek_token(JSParseState *s, const JSPars...
function BOOL (line 22215) | static BOOL is_regexp_allowed(int tok)
function js_parse_skip_parens_token (line 22243) | static int js_parse_skip_parens_token(JSParseState *s, int *pbits, BOOL ...
function set_object_name (line 22357) | static void set_object_name(JSParseState *s, JSAtom name)
function set_object_name_computed (line 22385) | static void set_object_name_computed(JSParseState *s)
function __exception (line 22406) | static __exception int js_parse_object_literal(JSParseState *s)
function __exception (line 22524) | static __exception int js_parse_class_default_ctor(JSParseState *s,
function find_private_class_field (line 22558) | static int find_private_class_field(JSContext *ctx, JSFunctionDef *fd,
function emit_class_field_init (line 22576) | static void emit_class_field_init(JSParseState *s)
function JSAtom (line 22602) | static JSAtom get_private_setter_name(JSContext *ctx, JSAtom name)
type ClassFieldsDef (line 22607) | typedef struct {
function __exception (line 22614) | static __exception int emit_class_init_start(JSParseState *s,
function __exception (line 22647) | static __exception int add_brand(JSParseState *s, ClassFieldsDef *cf)
function emit_class_init_end (line 22663) | static void emit_class_init_end(JSParseState *s, ClassFieldsDef *cf)
function __exception (line 22679) | static __exception int js_parse_class(JSParseState *s, BOOL is_class_expr,
function __exception (line 23125) | static __exception int js_parse_array_literal(JSParseState *s)
function BOOL (line 23252) | static BOOL has_with_scope(JSFunctionDef *s, int scope_level)
type JSLValue (line 23271) | typedef struct JSLValue {
function __exception (line 23280) | static __exception int get_lvalue(JSParseState *s, int *popcode, int *ps...
function put_lvalue (line 23406) | static void put_lvalue(JSParseState *s, int opcode, int scope,
function put_lvalue_nokeep (line 23455) | static void put_lvalue_nokeep(JSParseState *s, int opcode, int scope,
function __exception (line 23492) | static __exception int js_parse_expr_paren(JSParseState *s)
function js_unsupported_keyword (line 23503) | static int js_unsupported_keyword(JSParseState *s, JSAtom atom)
function __exception (line 23510) | static __exception int js_define_var(JSParseState *s, JSAtom name, int tok)
function js_emit_spread_code (line 23547) | static void js_emit_spread_code(JSParseState *s, int depth)
function js_parse_check_duplicate_parameter (line 23573) | static int js_parse_check_duplicate_parameter(JSParseState *s, JSAtom name)
function JSAtom (line 23592) | static JSAtom js_parse_destructuring_var(JSParseState *s, int tok, int i...
function js_parse_destructuring_element (line 23614) | static int js_parse_destructuring_element(JSParseState *s, int tok, int ...
type FuncCallType (line 24026) | typedef enum FuncCallType {
function optional_chain_test (line 24033) | static void optional_chain_test(JSParseState *s, int *poptional_chaining...
function __exception (line 24050) | static __exception int js_parse_postfix_expr(JSParseState *s, BOOL accep...
function __exception (line 24679) | static __exception int js_parse_delete(JSParseState *s)
function __exception (line 24739) | static __exception int js_parse_unary(JSParseState *s, int exponentiatio...
function __exception (line 24884) | static __exception int js_parse_expr_binary(JSParseState *s, int level,
function __exception (line 25029) | static __exception int js_parse_logical_and_or(JSParseState *s, int op,
function __exception (line 25070) | static __exception int js_parse_coalesce_expr(JSParseState *s, BOOL in_a...
function __exception (line 25097) | static __exception int js_parse_cond_expr(JSParseState *s, BOOL in_accep...
function __exception (line 25127) | static __exception int js_parse_assign_expr(JSParseState *s, BOOL in_acc...
function __exception (line 25307) | static __exception int js_parse_expr2(JSParseState *s, BOOL in_accepted)
function __exception (line 25331) | static __exception int js_parse_expr(JSParseState *s)
function push_break_entry (line 25336) | static void push_break_entry(JSFunctionDef *fd, BlockEnv *be,
function pop_break_entry (line 25352) | static void pop_break_entry(JSFunctionDef *fd)
function __exception (line 25359) | static __exception int emit_break(JSParseState *s, JSAtom name, int is_c...
function emit_return (line 25408) | static void emit_return(JSParseState *s, BOOL hasval)
function __exception (line 25498) | static __exception int js_parse_statement(JSParseState *s)
function __exception (line 25503) | static __exception int js_parse_block(JSParseState *s)
function __exception (line 25522) | static __exception int js_parse_var(JSParseState *s, BOOL in_accepted, i...
function BOOL (line 25616) | static BOOL is_label(JSParseState *s)
function is_let (line 25623) | static int is_let(JSParseState *s, int decl_mask)
function __exception (line 25673) | static __exception int js_parse_for_in_of(JSParseState *s, int label_name,
function set_eval_ret_undefined (line 25906) | static void set_eval_ret_undefined(JSParseState *s)
function __exception (line 25915) | static __exception int js_parse_statement_or_decl(JSParseState *s,
function JSModuleDef (line 26640) | static JSModuleDef *js_new_module_def(JSContext *ctx, JSAtom name)
function js_mark_module_def (line 26658) | static void js_mark_module_def(JSRuntime *rt, JSModuleDef *m,
function js_free_module_def (line 26677) | static void js_free_module_def(JSContext *ctx, JSModuleDef *m)
function add_req_module_entry (line 26714) | static int add_req_module_entry(JSContext *ctx, JSModuleDef *m,
function JSExportEntry (line 26738) | static JSExportEntry *find_export_entry(JSContext *ctx, JSModuleDef *m,
function JSExportEntry (line 26751) | static JSExportEntry *add_export_entry2(JSContext *ctx,
function JSExportEntry (line 26782) | static JSExportEntry *add_export_entry(JSParseState *s, JSModuleDef *m,
function add_star_export_entry (line 26790) | static int add_star_export_entry(JSContext *ctx, JSModuleDef *m,
function JSModuleDef (line 26806) | JSModuleDef *JS_NewCModule(JSContext *ctx, const char *name_str,
function JS_AddModuleExport (line 26819) | int JS_AddModuleExport(JSContext *ctx, JSModuleDef *m, const char *expor...
function JS_SetModuleExport (line 26835) | int JS_SetModuleExport(JSContext *ctx, JSModuleDef *m, const char *expor...
function JS_SetModuleLoaderFunc (line 26854) | void JS_SetModuleLoaderFunc(JSRuntime *rt,
function JSModuleDef (line 26921) | static JSModuleDef *js_find_loaded_module(JSContext *ctx, JSAtom name)
function JSModuleDef (line 26936) | static JSModuleDef *js_host_resolve_imported_module(JSContext *ctx,
type JSResolveEntry (line 26996) | typedef struct JSResolveEntry {
type JSResolveState (line 27001) | typedef struct JSResolveState {
function find_resolve_entry (line 27007) | static int find_resolve_entry(JSResolveState *s,
function add_resolve_entry (line 27019) | static int add_resolve_entry(JSContext *ctx, JSResolveState *s,
type JSResolveResultEnum (line 27034) | typedef enum JSResolveResultEnum {
function JSResolveResultEnum (line 27042) | static JSResolveResultEnum js_resolve_export1(JSContext *ctx,
function JSResolveResultEnum (line 27119) | static JSResolveResultEnum js_resolve_export(JSContext *ctx,
function js_resolve_export_throw_error (line 27142) | static void js_resolve_export_throw_error(JSContext *ctx,
type ExportedNameEntryEnum (line 27171) | typedef enum {
type ExportedNameEntry (line 27177) | typedef struct ExportedNameEntry {
type GetExportNamesState (line 27187) | typedef struct GetExportNamesState {
function find_exported_name (line 27197) | static int find_exported_name(GetExportNamesState *s, JSAtom name)
function __exception (line 27207) | static __exception int get_exported_names(JSContext *ctx,
function js_module_ns_has (line 27257) | static int js_module_ns_has(JSContext *ctx, JSValueConst obj, JSAtom atom)
function exported_names_cmp (line 27266) | static int exported_names_cmp(const void *p1, const void *p2, void *opaque)
function js_module_ns_autoinit (line 27291) | static int js_module_ns_autoinit(JSContext *ctx, JSObject *p, JSAtom atom,
function JSValue (line 27306) | static JSValue js_build_module_ns(JSContext *ctx, JSModuleDef *m)
function JSValue (line 27409) | static JSValue js_get_module_ns(JSContext *ctx, JSModuleDef *m)
function js_resolve_module (line 27422) | static int js_resolve_module(JSContext *ctx, JSModuleDef *m)
function JSVarRef (line 27452) | static JSVarRef *js_create_module_var(JSContext *ctx, BOOL is_lexical)
function js_create_module_bytecode_function (line 27470) | static int js_create_module_bytecode_function(JSContext *ctx, JSModuleDe...
function js_create_module_function (line 27522) | static int js_create_module_function(JSContext *ctx, JSModuleDef *m)
function js_instantiate_module (line 27564) | static int js_instantiate_module(JSContext *ctx, JSModuleDef *m)
function JSAtom (line 27716) | static JSAtom js_get_script_or_module_name(JSContext *ctx)
function JSAtom (line 27735) | JSAtom JS_GetModuleName(JSContext *ctx, JSModuleDef *m)
function JSValue (line 27740) | JSValue JS_GetImportMeta(JSContext *ctx, JSModuleDef *m)
function JSValue (line 27754) | static JSValue js_import_meta(JSContext *ctx)
function JSValue (line 27774) | static JSValue js_dynamic_import_job(JSContext *ctx,
function JSValue (line 27840) | static JSValue js_dynamic_import(JSContext *ctx, JSValueConst specifier)
function JSValue (line 27875) | static JSValue js_evaluate_module(JSContext *ctx, JSModuleDef *m)
function __exception (line 27929) | static __exception JSAtom js_parse_from_clause(JSParseState *s)
function __exception (line 27952) | static __exception int js_parse_export(JSParseState *s)
function add_import (line 28120) | static int add_import(JSParseState *s, JSModuleDef *m,
function __exception (line 28155) | static __exception int js_parse_import(JSParseState *s)
function __exception (line 28270) | static __exception int js_parse_source_element(JSParseState *s)
function JSFunctionDef (line 28298) | static JSFunctionDef *js_new_function_def(JSContext *ctx,
function free_bytecode_atoms (line 28356) | static void free_bytecode_atoms(JSRuntime *rt,
function js_free_function_def (line 28389) | static void js_free_function_def(JSContext *ctx, JSFunctionDef *fd)
function print_lines (line 28459) | static void print_lines(const char *source, int line, int line1) {
function dump_byte_code (line 28475) | static void dump_byte_code(JSContext *ctx, int pass,
function __maybe_unused (line 28745) | static __maybe_unused void dump_pc2line(JSContext *ctx, const uint8_t *b...
function __maybe_unused (line 28790) | static __maybe_unused void js_dump_function_bytecode(JSContext *ctx, JSF...
function add_closure_var (line 28866) | static int add_closure_var(JSContext *ctx, JSFunctionDef *s,
function find_closure_var (line 28895) | static int find_closure_var(JSContext *ctx, JSFunctionDef *s,
function get_closure_var2 (line 28910) | static int get_closure_var2(JSContext *ctx, JSFunctionDef *s,
function get_closure_var (line 28936) | static int get_closure_var(JSContext *ctx, JSFunctionDef *s,
function get_with_scope_opcode (line 28947) | static int get_with_scope_opcode(int op)
function BOOL (line 28955) | static BOOL can_opt_put_ref_value(const uint8_t *bc_buf, int pos)
function BOOL (line 28965) | static BOOL can_opt_put_global_ref_value(const uint8_t *bc_buf, int pos)
function optimize_scope_make_ref (line 28975) | static int optimize_scope_make_ref(JSContext *ctx, JSFunctionDef *s,
function optimize_scope_make_global_ref (line 29019) | static int optimize_scope_make_global_ref(JSContext *ctx, JSFunctionDef *s,
function add_var_this (line 29086) | static int add_var_this(JSContext *ctx, JSFunctionDef *fd)
function resolve_pseudo_var (line 29099) | static int resolve_pseudo_var(JSContext *ctx, JSFunctionDef *s,
function resolve_scope_var (line 29131) | static int resolve_scope_var(JSContext *ctx, JSFunctionDef *s,
function find_private_class_field_all (line 29589) | static int find_private_class_field_all(JSContext *ctx, JSFunctionDef *fd,
function get_loc_or_ref (line 29603) | static void get_loc_or_ref(DynBuf *bc, BOOL is_ref, int idx)
function resolve_scope_private_field1 (line 29614) | static int resolve_scope_private_field1(JSContext *ctx,
function resolve_scope_private_field (line 29676) | static int resolve_scope_private_field(JSContext *ctx, JSFunctionDef *s,
function mark_eval_captured_variables (line 29771) | static void mark_eval_captured_variables(JSContext *ctx, JSFunctionDef *s,
function add_eval_variables (line 29784) | static void add_eval_variables(JSContext *ctx, JSFunctionDef *s)
function __exception (line 29895) | static __exception int add_closure_variables(JSContext *ctx, JSFunctionD...
type CodeContext (line 29965) | typedef struct CodeContext {
function BOOL (line 29981) | static BOOL code_match(CodeContext *s, int pos, ...)
function instantiate_hoisted_definitions (line 30105) | static void instantiate_hoisted_definitions(JSContext *ctx, JSFunctionDe...
function skip_dead_code (line 30207) | static int skip_dead_code(JSFunctionDef *s, const uint8_t *bc_buf, int b...
function get_label_pos (line 30257) | static int get_label_pos(JSFunctionDef *s, int label)
function __exception (line 30282) | static __exception int resolve_variables(JSContext *ctx, JSFunctionDef *s)
function add_pc2line_info (line 30637) | static void add_pc2line_info(JSFunctionDef *s, uint32_t pc, int line_num)
function compute_pc2line_info (line 30651) | static void compute_pc2line_info(JSFunctionDef *s)
function RelocEntry (line 30689) | static RelocEntry *add_reloc(JSContext *ctx, LabelSlot *ls, uint32_t add...
function BOOL (line 30702) | static BOOL code_has_label(CodeContext *s, int pos, int label)
function find_jump_target (line 30730) | static int find_jump_target(JSFunctionDef *s, int label, int *pop, int *...
function push_short_int (line 30770) | static void push_short_int(DynBuf *bc_out, int val)
function put_short_code (line 30792) | static void put_short_code(DynBuf *bc_out, int op, int idx)
function __exception (line 30851) | static __exception int resolve_labels(JSContext *ctx, JSFunctionDef *s)
type StackSizeState (line 31736) | typedef struct StackSizeState {
function __exception (line 31741) | static __exception int compute_stack_size_rec(JSContext *ctx,
function __exception (line 31884) | static __exception int compute_stack_size(JSContext *ctx,
function add_module_variables (line 31905) | static int add_module_variables(JSContext *ctx, JSFunctionDef *fd)
function JSValue (line 31942) | static JSValue js_create_function(JSContext *ctx, JSFunctionDef *fd)
function free_function_bytecode (line 32163) | static void free_function_bytecode(JSRuntime *rt, JSFunctionBytecode *b)
function __exception (line 32206) | static __exception int js_parse_directives(JSParseState *s)
function js_parse_function_check_names (line 32302) | static int js_parse_function_check_names(JSParseState *s, JSFunctionDef ...
function JSFunctionDef (line 32352) | static JSFunctionDef *js_parse_function_class_fields_init(JSParseState *s)
function __exception (line 32379) | static __exception int js_parse_function_decl2(JSParseState *s,
function __exception (line 32870) | static __exception int js_parse_function_decl(JSParseState *s,
function __exception (line 32882) | static __exception int js_parse_program(JSParseState *s)
function js_parse_init (line 32922) | static void js_parse_init(JSContext *ctx, JSParseState *s,
function JSValue (line 32936) | static JSValue JS_EvalFunctionInternal(JSContext *ctx, JSValue fun_obj,
function JSValue (line 32969) | JSValue JS_EvalFunction(JSContext *ctx, JSValue fun_obj)
function skip_shebang (line 32974) | static void skip_shebang(JSParseState *s)
function JSValue (line 33000) | static JSValue __JS_EvalInternal(JSContext *ctx, JSValueConst this_obj,
function JSValue (line 33110) | static JSValue JS_EvalInternal(JSContext *ctx, JSValueConst this_obj,
function JSValue (line 33121) | static JSValue JS_EvalObject(JSContext *ctx, JSValueConst this_obj,
function JSValue (line 33139) | JSValue JS_Eval(JSContext *ctx, const char *input, size_t input_len,
function JS_ResolveModule (line 33152) | int JS_ResolveModule(JSContext *ctx, JSValueConst obj)
type JSObjectListEntry (line 33167) | typedef struct {
type JSObjectList (line 33173) | typedef struct {
function js_object_list_init (line 33181) | static void js_object_list_init(JSObjectList *s)
function js_object_list_get_hash (line 33186) | static uint32_t js_object_list_get_hash(JSObject *p, uint32_t hash_size)
function js_object_list_resize_hash (line 33191) | static int js_object_list_resize_hash(JSContext *ctx, JSObjectList *s,
function js_object_list_add (line 33218) | static int js_object_list_add(JSContext *ctx, JSObjectList *s, JSObject ...
function js_object_list_find (line 33243) | static int js_object_list_find(JSContext *ctx, JSObjectList *s, JSObject...
function js_object_list_end (line 33262) | static void js_object_list_end(JSContext *ctx, JSObjectList *s)
type BCTagEnum (line 33271) | typedef enum BCTagEnum {
type BCWriterState (line 33307) | typedef struct BCWriterState {
function bc_put_u8 (line 33354) | static void bc_put_u8(BCWriterState *s, uint8_t v)
function bc_put_u16 (line 33359) | static void bc_put_u16(BCWriterState *s, uint16_t v)
function __maybe_unused (line 33366) | static __maybe_unused void bc_put_u32(BCWriterState *s, uint32_t v)
function bc_put_u64 (line 33373) | static void bc_put_u64(BCWriterState *s, uint64_t v)
function bc_put_leb128 (line 33380) | static void bc_put_leb128(BCWriterState *s, uint32_t v)
function bc_put_sleb128 (line 33385) | static void bc_put_sleb128(BCWriterState *s, int32_t v)
function bc_set_flags (line 33390) | static void bc_set_flags(uint32_t *pflags, int *pidx, uint32_t val, int n)
function bc_atom_to_idx (line 33396) | static int bc_atom_to_idx(BCWriterState *s, uint32_t *pres, JSAtom atom)
function bc_put_atom (line 33436) | static int bc_put_atom(BCWriterState *s, JSAtom atom)
function bc_byte_swap (line 33451) | static void bc_byte_swap(uint8_t *bc_buf, int bc_len)
function JS_WriteFunctionBytecode (line 33511) | static int JS_WriteFunctionBytecode(BCWriterState *s,
function JS_WriteString (line 33557) | static void JS_WriteString(BCWriterState *s, JSString *p)
function JS_WriteBigNum (line 33570) | static int JS_WriteBigNum(BCWriterState *s, JSValueConst obj)
function JS_WriteFunctionTag (line 33708) | static int JS_WriteFunctionTag(BCWriterState *s, JSValueConst obj)
function JS_WriteModule (line 33792) | static int JS_WriteModule(BCWriterState *s, JSValueConst obj)
function JS_WriteArray (line 33840) | static int JS_WriteArray(BCWriterState *s, JSValueConst obj)
function JS_WriteObjectTag (line 33883) | static int JS_WriteObjectTag(BCWriterState *s, JSValueConst obj)
function JS_WriteTypedArray (line 33922) | static int JS_WriteTypedArray(BCWriterState *s, JSValueConst obj)
function JS_WriteArrayBuffer (line 33936) | static int JS_WriteArrayBuffer(BCWriterState *s, JSValueConst obj)
function JS_WriteSharedArrayBuffer (line 33950) | static int JS_WriteSharedArrayBuffer(BCWriterState *s, JSValueConst obj)
function JS_WriteObjectRec (line 33966) | static int JS_WriteObjectRec(BCWriterState *s, JSValueConst obj)
function JS_WriteObjectAtoms (line 34104) | static int JS_WriteObjectAtoms(BCWriterState *s)
type BCReaderState (line 34195) | typedef struct BCReaderState {
function bc_read_trace (line 34218) | static void __attribute__((format(printf, 2, 3))) bc_read_trace(BCReader...
function bc_read_error_end (line 34252) | static int bc_read_error_end(BCReaderState *s)
function bc_get_u8 (line 34260) | static int bc_get_u8(BCReaderState *s, uint8_t *pval)
function bc_get_u16 (line 34270) | static int bc_get_u16(BCReaderState *s, uint16_t *pval)
function __maybe_unused (line 34281) | static __maybe_unused int bc_get_u32(BCReaderState *s, uint32_t *pval)
function bc_get_u64 (line 34292) | static int bc_get_u64(BCReaderState *s, uint64_t *pval)
function bc_get_leb128 (line 34303) | static int bc_get_leb128(BCReaderState *s, uint32_t *pval)
function bc_get_sleb128 (line 34313) | static int bc_get_sleb128(BCReaderState *s, int32_t *pval)
function bc_get_leb128_int (line 34324) | static int bc_get_leb128_int(BCReaderState *s, int *pval)
function bc_get_leb128_u16 (line 34329) | static int bc_get_leb128_u16(BCReaderState *s, uint16_t *pval)
function bc_get_buf (line 34340) | static int bc_get_buf(BCReaderState *s, uint8_t *buf, uint32_t buf_len)
function bc_idx_to_atom (line 34351) | static int bc_idx_to_atom(BCReaderState *s, JSAtom *patom, uint32_t idx)
function bc_get_atom (line 34373) | static int bc_get_atom(BCReaderState *s, JSAtom *patom)
function JSString (line 34386) | static JSString *JS_ReadString(BCReaderState *s)
function bc_get_flags (line 34419) | static uint32_t bc_get_flags(uint32_t flags, int *pidx, int n)
function JS_ReadFunctionBytecode (line 34428) | static int JS_ReadFunctionBytecode(BCReaderState *s, JSFunctionBytecode *b,
function JSValue (line 34484) | static JSValue JS_ReadBigNum(BCReaderState *s, int tag)
function BC_add_object_ref1 (line 34619) | static int BC_add_object_ref1(BCReaderState *s, JSObject *p)
function BC_add_object_ref (line 34631) | static int BC_add_object_ref(BCReaderState *s, JSValueConst obj)
function JSValue (line 34636) | static JSValue JS_ReadFunctionTag(BCReaderState *s)
function JSValue (line 34820) | static JSValue JS_ReadModule(BCReaderState *s)
function JSValue (line 34921) | static JSValue JS_ReadObjectTag(BCReaderState *s)
function JSValue (line 34957) | static JSValue JS_ReadArray(BCReaderState *s, int tag)
function JSValue (line 35002) | static JSValue JS_ReadTypedArray(BCReaderState *s)
function JSValue (line 35049) | static JSValue JS_ReadArrayBuffer(BCReaderState *s)
function JSValue (line 35073) | static JSValue JS_ReadSharedArrayBuffer(BCReaderState *s)
function JSValue (line 35101) | static JSValue JS_ReadDate(BCReaderState *s)
function JSValue (line 35127) | static JSValue JS_ReadObjectValue(BCReaderState *s)
function JSValue (line 35148) | static JSValue JS_ReadObjectRec(BCReaderState *s)
function JS_ReadObjectAtoms (line 35265) | static int JS_ReadObjectAtoms(BCReaderState *s)
function bc_reader_free (line 35306) | static void bc_reader_free(BCReaderState *s)
function JSValue (line 35318) | JSValue JS_ReadObject(JSContext *ctx, const uint8_t *buf, size_t buf_len,
function check_function (line 35359) | static int check_function(JSContext *ctx, JSValueConst obj)
function check_exception_free (line 35367) | static int check_exception_free(JSContext *ctx, JSValue obj)
function JSAtom (line 35373) | static JSAtom find_atom(JSContext *ctx, const char *name)
function JS_InstantiateFunctionListItem (line 35396) | static int JS_InstantiateFunctionListItem(JSContext *ctx, JSObject *p,
function JS_SetPropertyFunctionList (line 35486) | void JS_SetPropertyFunctionList(JSContext *ctx, JSValueConst obj,
function JS_AddModuleExportList (line 35523) | int JS_AddModuleExportList(JSContext *ctx, JSModuleDef *m,
function JS_SetModuleExportList (line 35534) | int JS_SetModuleExportList(JSContext *ctx, JSModuleDef *m,
function JS_SetConstructor2 (line 35573) | static void JS_SetConstructor2(JSContext *ctx,
function JS_SetConstructor (line 35587) | void JS_SetConstructor(JSContext *ctx, JSValueConst func_obj,
function JS_NewGlobalCConstructor2 (line 35594) | static void JS_NewGlobalCConstructor2(JSContext *ctx,
function JSValueConst (line 35606) | static JSValueConst JS_NewGlobalCConstructor(JSContext *ctx, const char ...
function JSValueConst (line 35616) | static JSValueConst JS_NewGlobalCConstructorOnly(JSContext *ctx, const c...
function JSValue (line 35626) | static JSValue js_global_eval(JSContext *ctx, JSValueConst this_val,
function JSValue (line 35632) | static JSValue js_global_isNaN(JSContext *ctx, JSValueConst this_val,
function JSValue (line 35643) | static JSValue js_global_isFinite(JSContext *ctx, JSValueConst this_val,
function JSValue (line 35656) | static JSValue JS_ToObject(JSContext *ctx, JSValueConst val)
function JSValue (line 35704) | static JSValue JS_ToObjectFree(JSContext *ctx, JSValue val)
function js_obj_to_desc (line 35711) | static int js_obj_to_desc(JSContext *ctx, JSPropertyDescriptor *d,
function __exception (line 35790) | static __exception int JS_DefinePropertyDesc(JSContext *ctx, JSValueCons...
function __exception (line 35806) | static __exception int JS_ObjectDefineProperties(JSContext *ctx,
function JSValue (line 35844) | static JSValue js_object_constructor(JSContext *ctx, JSValueConst new_ta...
function JSValue (line 35867) | static JSValue js_object_create(JSContext *ctx, JSValueConst this_val,
function JSValue (line 35889) | static JSValue js_object_getPrototypeOf(JSContext *ctx, JSValueConst thi...
function JSValue (line 35905) | static JSValue js_object_setPrototypeOf(JSContext *ctx, JSValueConst thi...
function JSValue (line 35916) | static JSValue js_object_defineProperty(JSContext *ctx, JSValueConst thi...
function JSValue (line 35946) | static JSValue js_object_defineProperties(JSContext *ctx, JSValueConst t...
function JSValue (line 35959) | static JSValue js_object___defineGetter__(JSContext *ctx, JSValueConst t...
function JSValue (line 36005) | static JSValue js_object_getOwnPropertyDescriptor(JSContext *ctx, JSValu...
function JSValue (line 36069) | static JSValue js_object_getOwnPropertyDescriptors(JSContext *ctx, JSVal...
function JSValue (line 36120) | static JSValue JS_GetOwnPropertyNames2(JSContext *ctx, JSValueConst obj1,
function JSValue (line 36199) | static JSValue js_object_getOwnPropertyNames(JSContext *ctx, JSValueCons...
function JSValue (line 36206) | static JSValue js_object_getOwnPropertySymbols(JSContext *ctx, JSValueCo...
function JSValue (line 36213) | static JSValue js_object_keys(JSContext *ctx, JSValueConst this_val,
function JSValue (line 36220) | static JSValue js_object_isExtensible(JSContext *ctx, JSValueConst this_...
function JSValue (line 36240) | static JSValue js_object_preventExtensions(JSContext *ctx, JSValueConst ...
function JSValue (line 36265) | static JSValue js_object_hasOwnProperty(JSContext *ctx, JSValueConst thi...
function JSValue (line 36291) | static JSValue js_object_valueOf(JSContext *ctx, JSValueConst this_val,
function JSValue (line 36297) | static JSValue js_object_toString(JSContext *ctx, JSValueConst this_val,
function JSValue (line 36352) | static JSValue js_object_toLocaleString(JSContext *ctx, JSValueConst thi...
function JSValue (line 36358) | static JSValue js_object_assign(JSContext *ctx, JSValueConst this_val,
function JSValue (line 36386) | static JSValue js_object_seal(JSContext *ctx, JSValueConst this_val,
function JSValue (line 36437) | static JSValue js_object_isSealed(JSContext *ctx, JSValueConst this_val,
function JSValue (line 36483) | static JSValue js_object_fromEntries(JSContext *ctx, JSValueConst this_val,
function JSValue (line 36553) | static JSValue js_object___setOwnProperty(JSContext *ctx, JSValueConst t...
function JSValue (line 36566) | static JSValue js_object___toObject(JSContext *ctx, JSValueConst this_val,
function JSValue (line 36572) | static JSValue js_object___toPrimitive(JSContext *ctx, JSValueConst this...
function JSValue (line 36585) | static JSValue js_object___getClass(JSContext *ctx, JSValueConst this_val,
function JSValue (line 36606) | static JSValue js_object_is(JSContext *ctx, JSValueConst this_val,
function JSValue (line 36613) | static JSValue js_object___getObjectData(JSContext *ctx, JSValueConst th...
function JSValue (line 36619) | static JSValue js_object___setObjectData(JSContext *ctx, JSValueConst th...
function JSValue (line 36627) | static JSValue js_object___toPropertyKey(JSContext *ctx, JSValueConst th...
function JSValue (line 36633) | static JSValue js_object___isObject(JSContext *ctx, JSValueConst this_val,
function JSValue (line 36639) | static JSValue js_object___isSameValueZero(JSContext *ctx, JSValueConst ...
function JSValue (line 36645) | static JSValue js_object___isConstructor(JSContext *ctx, JSValueConst th...
function JSValue (line 36652) | static JSValue JS_SpeciesConstructor(JSContext *ctx, JSValueConst obj,
function JSValue (line 36682) | static JSValue js_object___speciesConstructor(JSContext *ctx, JSValueCon...
function JSValue (line 36689) | static JSValue js_object_get___proto__(JSContext *ctx, JSValueConst this...
function JSValue (line 36701) | static JSValue js_object_set___proto__(JSContext *ctx, JSValueConst this...
function JSValue (line 36714) | static JSValue js_object_isPrototypeOf(JSContext *ctx, JSValueConst this...
function JSValue (line 36754) | static JSValue js_object_propertyIsEnumerable(JSContext *ctx, JSValueCon...
function JSValue (line 36785) | static JSValue js_object___lookupGetter__(JSContext *ctx, JSValueConst t...
function JSValue (line 36881) | static JSValue js_function_proto(JSContext *ctx, JSValueConst this_val,
function JSValue (line 36888) | static JSValue js_function_constructor(JSContext *ctx, JSValueConst new_...
function __exception (line 36958) | static __exception int js_get_length32(JSContext *ctx, uint32_t *pres,
function __exception (line 36970) | static __exception int js_get_length64(JSContext *ctx, int64_t *pres,
function free_arg_list (line 36982) | static void free_arg_list(JSContext *ctx, JSValue *tab, uint32_t len)
function JSValue (line 36992) | static JSValue *build_arg_list(JSContext *ctx, uint32_t *plen,
function JSValue (line 37030) | static JSValue js_function_apply(JSContext *ctx, JSValueConst this_val,
function JSValue (line 37057) | static JSValue js_function_call(JSContext *ctx, JSValueConst this_val,
function JSValue (line 37067) | static JSValue js_function_bind(JSContext *ctx, JSValueConst this_val,
function JSValue (line 37124) | static JSValue js_function_toString(JSContext *ctx, JSValueConst this_val,
function JSValue (line 37168) | static JSValue js_function_hasInstance(JSContext *ctx, JSValueConst this...
function JSValue (line 37191) | static JSValue iterator_to_array(JSContext *ctx, JSValueConst items)
function JSValue (line 37229) | static JSValue js_error_constructor(JSContext *ctx, JSValueConst new_tar...
function JSValue (line 37289) | static JSValue js_error_toString(JSContext *ctx, JSValueConst this_val,
function JSValue (line 37327) | static JSValue js_aggregate_error_constructor(JSContext *ctx,
function JS_CopySubArray (line 37344) | static int JS_CopySubArray(JSContext *ctx,
function JSValue (line 37379) | static JSValue js_array_constructor(JSContext *ctx, JSValueConst new_tar...
function JSValue (line 37406) | static JSValue js_array_from(JSContext *ctx, JSValueConst this_val,
function JSValue (line 37519) | static JSValue js_array_of(JSContext *ctx, JSValueConst this_val,
function JSValue (line 37547) | static JSValue js_array_isArray(JSContext *ctx, JSValueConst this_val,
function JSValue (line 37558) | static JSValue js_get_this(JSContext *ctx,
function JSValue (line 37564) | static JSValue JS_ArraySpeciesCreate(JSContext *ctx, JSValueConst obj,
function JS_isConcatSpreadable (line 37617) | static int JS_isConcatSpreadable(JSContext *ctx, JSValueConst obj)
function JSValue (line 37631) | static JSValue js_array_concat(JSContext *ctx, JSValueConst this_val,
function JSValue (line 37710) | static JSValue js_array_every(JSContext *ctx, JSValueConst this_val,
function JSValue (line 37858) | static JSValue js_array_reduce(JSContext *ctx, JSValueConst this_val,
function JSValue (line 37935) | static JSValue js_array_fill(JSContext *ctx, JSValueConst this_val,
function JSValue (line 37971) | static JSValue js_array_includes(JSContext *ctx, JSValueConst this_val,
function JSValue (line 38020) | static JSValue js_array_indexOf(JSContext *ctx, JSValueConst this_val,
function JSValue (line 38069) | static JSValue js_array_lastIndexOf(JSContext *ctx, JSValueConst this_val,
function JSValue (line 38108) | static JSValue js_array_find(JSContext *ctx, JSValueConst this_val,
function JSValue (line 38170) | static JSValue js_array_toString(JSContext *ctx, JSValueConst this_val,
function JSValue (line 38193) | static JSValue js_array_join(JSContext *ctx, JSValueConst this_val,
function JSValue (line 38250) | static JSValue js_array_pop(JSContext *ctx, JSValueConst this_val,
function JSValue (line 38303) | static JSValue js_array_push(JSContext *ctx, JSValueConst this_val,
function JSValue (line 38340) | static JSValue js_array_reverse(JSContext *ctx, JSValueConst this_val,
function JSValue (line 38409) | static JSValue js_array_slice(JSContext *ctx, JSValueConst this_val,
function JSValue (line 38516) | static JSValue js_array_copyWithin(JSContext *ctx, JSValueConst this_val,
function JS_FlattenIntoArray (line 38551) | static int64_t JS_FlattenIntoArray(JSContext *ctx, JSValueConst target,
function JSValue (line 38608) | static JSValue js_array_flatten(JSContext *ctx, JSValueConst this_val,
type ValueSlot (line 38654) | typedef struct ValueSlot {
type array_sort_context (line 38660) | struct array_sort_context {
function js_array_cmp_generic (line 38667) | static int js_array_cmp_generic(const void *a, const void *b, void *opaq...
function JSValue (line 38728) | static JSValue js_array_sort(JSContext *ctx, JSValueConst this_val,
type JSArrayIteratorData (line 38814) | typedef struct JSArrayIteratorData {
function js_array_iterator_finalizer (line 38820) | static void js_array_iterator_finalizer(JSRuntime *rt, JSValue val)
function js_array_iterator_mark (line 38830) | static void js_array_iterator_mark(JSRuntime *rt, JSValueConst val,
function JSValue (line 38840) | static JSValue js_create_array(JSContext *ctx, int len, JSValueConst *tab)
function JSValue (line 38857) | static JSValue js_create_array_iterator(JSContext *ctx, JSValueConst thi...
function JSValue (line 38894) | static JSValue js_array_iterator_next(JSContext *ctx, JSValueConst this_...
function JSValue (line 38955) | static JSValue js_iterator_proto_iterator(JSContext *ctx, JSValueConst t...
function JSValue (line 39007) | static JSValue js_number_constructor(JSContext *ctx, JSValueConst new_ta...
function JSValue (line 39053) | static JSValue js_number___toInteger(JSContext *ctx, JSValueConst this_val,
function JSValue (line 39059) | static JSValue js_number___toLength(JSContext *ctx, JSValueConst this_val,
function JSValue (line 39069) | static JSValue js_number_isNaN(JSContext *ctx, JSValueConst this_val,
function JSValue (line 39077) | static JSValue js_number_isFinite(JSContext *ctx, JSValueConst this_val,
function JSValue (line 39085) | static JSValue js_number_isInteger(JSContext *ctx, JSValueConst this_val,
function JSValue (line 39096) | static JSValue js_number_isSafeInteger(JSContext *ctx, JSValueConst this...
function JSValue (line 39127) | static JSValue js_thisNumberValue(JSContext *ctx, JSValueConst this_val)
function JSValue (line 39142) | static JSValue js_number_valueOf(JSContext *ctx, JSValueConst this_val,
function js_get_radix (line 39148) | static int js_get_radix(JSContext *ctx, JSValueConst val)
function JSValue (line 39160) | static JSValue js_number_toString(JSContext *ctx, JSValueConst this_val,
function JSValue (line 39185) | static JSValue js_number_toFixed(JSContext *ctx, JSValueConst this_val,
function JSValue (line 39208) | static JSValue js_number_toExponential(JSContext *ctx, JSValueConst this...
function JSValue (line 39237) | static JSValue js_number_toPrecision(JSContext *ctx, JSValueConst this_val,
function JSValue (line 39271) | static JSValue js_parseInt(JSContext *ctx, JSValueConst this_val,
function JSValue (line 39297) | static JSValue js_parseFloat(JSContext *ctx, JSValueConst this_val,
function JSValue (line 39314) | static JSValue js_boolean_constructor(JSContext *ctx, JSValueConst new_t...
function JSValue (line 39329) | static JSValue js_thisBooleanValue(JSContext *ctx, JSValueConst this_val)
function JSValue (line 39344) | static JSValue js_boolean_toString(JSContext *ctx, JSValueConst this_val,
function JSValue (line 39354) | static JSValue js_boolean_valueOf(JSContext *ctx, JSValueConst this_val,
function js_string_get_own_property (line 39367) | static int js_string_get_own_property(JSContext *ctx,
function js_string_obj_get_length (line 39399) | static uint32_t js_string_obj_get_length(JSContext *ctx,
function js_string_get_own_property_names (line 39415) | static int js_string_get_own_property_names(JSContext *ctx,
function js_string_define_own_property (line 39439) | static int js_string_define_own_property(JSContext *ctx,
function js_string_delete_property (line 39479) | static int js_string_delete_property(JSContext *ctx,
function JSValue (line 39500) | static JSValue js_string_constructor(JSContext *ctx, JSValueConst new_ta...
function JSValue (line 39530) | static JSValue js_thisStringValue(JSContext *ctx, JSValueConst this_val)
function JSValue (line 39545) | static JSValue js_string_fromCharCode(JSContext *ctx, JSValueConst this_...
function JSValue (line 39563) | static JSValue js_string_fromCodePoint(JSContext *ctx, JSValueConst this...
function JSValue (line 39597) | static JSValue js_string_raw(JSContext *ctx, JSValueConst this_val,
function JSValue (line 39638) | JSValue js_string_codePointRange(JSContext *ctx, JSValueConst this_val,
function JSValue (line 39665) | static JSValue js_string___isSpace(JSContext *ctx, JSValueConst this_val,
function JSValue (line 39675) | static JSValue js_string_charCodeAt(JSContext *ctx, JSValueConst this_val,
function JSValue (line 39703) | static JSValue js_string_charAt(JSContext *ctx, JSValueConst this_val,
function JSValue (line 39731) | static JSValue js_string_codePointAt(JSContext *ctx, JSValueConst this_val,
function JSValue (line 39756) | static JSValue js_string_concat(JSContext *ctx, JSValueConst this_val,
function string_cmp (line 39774) | static int string_cmp(JSString *p1, JSString *p2, int x1, int x2, int len)
function string_indexof_char (line 39784) | static int string_indexof_char(JSString *p, int c, int from)
function string_indexof (line 39804) | static int string_indexof(JSString *p1, JSString *p2, int from)
function string_advance_index (line 39820) | static int64_t string_advance_index(JSString *p, int64_t index, BOOL uni...
function JSValue (line 39832) | static JSValue js_string_indexOf(JSContext *ctx, JSValueConst this_val,
function JSValue (line 39900) | static JSValue js_string_includes(JSContext *ctx, JSValueConst this_val,
function check_regexp_g_flag (line 39964) | static int check_regexp_g_flag(JSContext *ctx, JSValueConst regexp)
function JSValue (line 39993) | static JSValue js_string_match(JSContext *ctx, JSValueConst this_val,
function JSValue (line 40043) | static JSValue js_string___GetSubstitution(JSContext *ctx, JSValueConst ...
function JSValue (line 40149) | static JSValue js_string_replace(JSContext *ctx, JSValueConst this_val,
function JSValue (line 40262) | static JSValue js_string_split(JSContext *ctx, JSValueConst this_val,
function JSValue (line 40352) | static JSValue js_string_substring(JSContext *ctx, JSValueConst this_val,
function JSValue (line 40386) | static JSValue js_string_substr(JSContext *ctx, JSValueConst this_val,
function JSValue (line 40414) | static JSValue js_string_slice(JSContext *ctx, JSValueConst this_val,
function JSValue (line 40442) | static JSValue js_string_pad(JSContext *ctx, JSValueConst this_val,
function JSValue (line 40513) | static JSValue js_string_repeat(JSContext *ctx, JSValueConst this_val,
function JSValue (line 40557) | static JSValue js_string_trim(JSContext *ctx, JSValueConst this_val,
function JSValue (line 40583) | static JSValue js_string___quote(JSContext *ctx, JSValueConst this_val,
function string_prevc (line 40590) | static int string_prevc(JSString *p, int *pidx)
function BOOL (line 40614) | static BOOL test_final_sigma(JSString *p, int sigma_pos)
function JSValue (line 40642) | static JSValue js_string_localeCompare(JSContext *ctx, JSValueConst this...
function JSValue (line 40662) | static JSValue js_string_toLowerCase(JSContext *ctx, JSValueConst this_val,
function JS_ToUTF32String (line 40703) | static int JS_ToUTF32String(JSContext *ctx, uint32_t **pbuf, JSValueCons...
function JSValue (line 40731) | static JSValue JS_NewUTF32String(JSContext *ctx, const uint32_t *buf, in...
function JSValue (line 40747) | static JSValue js_string_normalize(JSContext *ctx, JSValueConst this_val,
function JSValue (line 40807) | static JSValue js_string_toString(JSContext *ctx, JSValueConst this_val,
function JSValue (line 40814) | static JSValue js_string___toStringCheckObject(JSContext *ctx, JSValueCo...
function JSValue (line 40820) | static JSValue js_string___toString(JSContext *ctx, JSValueConst this_val,
function JSValue (line 40826) | static JSValue js_string___advanceStringIndex(JSContext *ctx, JSValueConst
function JSValue (line 40856) | static JSValue js_string_iterator_next(JSContext *ctx, JSValueConst this...
function JSValue (line 40909) | static JSValue js_string_CreateHTML(JSContext *ctx, JSValueConst this_val,
function JS_AddIntrinsicStringNormalize (line 41038) | void JS_AddIntrinsicStringNormalize(JSContext *ctx)
function js_fmin (line 41049) | static double js_fmin(double a, double b)
function js_fmax (line 41063) | static double js_fmax(double a, double b)
function JSValue (line 41076) | static JSValue js_math_min_max(JSContext *ctx, JSValueConst this_val,
function js_math_sign (line 41129) | static double js_math_sign(double a)
function js_math_round (line 41139) | static double js_math_round(double a)
function JSValue (line 41167) | static JSValue js_math_hypot(JSContext *ctx, JSValueConst this_val,
function js_math_fround (line 41191) | static double js_math_fround(double a)
function JSValue (line 41196) | static JSValue js_math_imul(JSContext *ctx, JSValueConst this_val,
function JSValue (line 41209) | static JSValue js_math_clz32(JSContext *ctx, JSValueConst this_val,
function xorshift64star (line 41224) | static uint64_t xorshift64star(uint64_t *pstate)
function js_random_init (line 41235) | static void js_random_init(JSContext *ctx)
function JSValue (line 41245) | static JSValue js_math_random(JSContext *ctx, JSValueConst this_val,
function JSValue (line 41314) | static JSValue js___date_now(JSContext *ctx, JSValueConst this_val,
function JSValue (line 41326) | static JSValue js___date_clock(JSContext *ctx, JSValueConst this_val,
function getTimezoneOffset (line 41338) | static int getTimezoneOffset(int64_t time) {
function JSValue (line 41374) | static JSValue js___date_getTimezoneOffset(JSContext *ctx, JSValueConst ...
function JSValue (line 41387) | static JSValue js_get_prototype_from_ctor(JSContext *ctx, JSValueConst c...
function JSValue (line 41402) | static JSValue js___date_create(JSContext *ctx, JSValueConst this_val,
function js_regexp_finalizer (line 41419) | static void js_regexp_finalizer(JSRuntime *rt, JSValue val)
function JSValue (line 41428) | static JSValue js_compile_regexp(JSContext *ctx, JSValueConst pattern,
function JSValue (line 41496) | static JSValue js_regexp_constructor_internal(JSContext *ctx, JSValueCon...
function JSRegExp (line 41525) | static JSRegExp *js_get_regexp(JSContext *ctx, JSValueConst obj, BOOL th...
function js_is_regexp (line 41539) | static int js_is_regexp(JSContext *ctx, JSValueConst obj)
function JSValue (line 41553) | static JSValue js_regexp_constructor(JSContext *ctx, JSValueConst new_ta...
function JSValue (line 41631) | static JSValue js_regexp_compile(JSContext *ctx, JSValueConst this_val,
function JSValue (line 41676) | static JSValue js_regexp_get___source(JSContext *ctx, JSValueConst this_...
function JSValue (line 41684) | static JSValue js_regexp_get___flags(JSContext *ctx, JSValueConst this_val)
function JSValue (line 41696) | static JSValue js_regexp_get_source(JSContext *ctx, JSValueConst this_val)
function JSValue (line 41762) | static JSValue js_regexp_get_flag(JSContext *ctx, JSValueConst this_val,...
function JSValue (line 41782) | static JSValue js_regexp_get_flags(JSContext *ctx, JSValueConst this_val)
function JSValue (line 41826) | static JSValue js_regexp_toString(JSContext *ctx, JSValueConst this_val,
function BOOL (line 41851) | BOOL lre_check_stack_overflow(void *opaque, size_t alloca_size)
function JSValue (line 41864) | static JSValue js_regexp_exec(JSContext *ctx, JSValueConst this_val,
function JSValue (line 41994) | static JSValue JS_RegExpDelete(JSContext *ctx, JSValueConst this_val, JS...
function JSValue (line 42089) | static JSValue JS_RegExpExec(JSContext *ctx, JSValueConst r, JSValueCons...
function JSValue (line 42111) | static JSValue js_regexp___RegExpExec(JSContext *ctx, JSValueConst this_...
function JSValue (line 42116) | static JSValue js_regexp___RegExpDelete(JSContext *ctx, JSValueConst thi...
function JSValue (line 42123) | static JSValue js_regexp_test(JSContext *ctx, JSValueConst this_val,
function JSValue (line 42137) | static JSValue js_regexp_Symbol_match(JSContext *ctx, JSValueConst this_...
type JSRegExpStringIteratorData (line 42213) | typedef struct JSRegExpStringIteratorData {
function js_regexp_string_iterator_finalizer (line 42221) | static void js_regexp_string_iterator_finalizer(JSRuntime *rt, JSValue val)
function js_regexp_string_iterator_mark (line 42232) | static void js_regexp_string_iterator_mark(JSRuntime *rt, JSValueConst val,
function JSValue (line 42243) | static JSValue js_regexp_string_iterator_next(JSContext *ctx,
function JSValue (line 42297) | static JSValue js_regexp_Symbol_matchAll(JSContext *ctx, JSValueConst th...
type ValueBuffer (line 42363) | typedef struct ValueBuffer {
function value_buffer_init (line 42372) | static int value_buffer_init(JSContext *ctx, ValueBuffer *b)
function value_buffer_free (line 42382) | static void value_buffer_free(ValueBuffer *b)
function value_buffer_append (line 42392) | static int value_buffer_append(ValueBuffer *b, JSValue val)
function js_is_standard_regexp (line 42423) | static int js_is_standard_regexp(JSContext *ctx, JSValueConst rx)
function JSValue (line 42445) | static JSValue js_regexp_Symbol_replace(JSContext *ctx, JSValueConst thi...
function JSValue (line 42626) | static JSValue js_regexp_Symbol_search(JSContext *ctx, JSValueConst this...
function JSValue (line 42682) | static JSValue js_regexp_Symbol_split(JSContext *ctx, JSValueConst this_...
function JS_AddIntrinsicRegExpCompiler (line 42840) | void JS_AddIntrinsicRegExpCompiler(JSContext *ctx)
function JS_AddIntrinsicRegExp (line 42845) | void JS_AddIntrinsicRegExp(JSContext *ctx)
function json_parse_expect (line 42868) | static int json_parse_expect(JSParseState *s, int tok)
function JSValue (line 42877) | static JSValue json_parse_value(JSParseState *s)
function JSValue (line 43004) | JSValue JS_ParseJSON2(JSContext *ctx, const char *buf, size_t buf_len,
function JSValue (line 43028) | JSValue JS_ParseJSON(JSContext *ctx, const char *buf, size_t buf_len,
function JSValue (line 43034) | static JSValue internalize_json_property(JSContext *ctx, JSValueConst ho...
function JSValue (line 43103) | static JSValue js_json_parse(JSContext *ctx, JSValueConst this_val,
type JSONStringifyContext (line 43137) | typedef struct JSONStringifyContext {
function JSValue (line 43146) | static JSValue JS_ToQuotedStringFree(JSContext *ctx, JSValue val) {
function JSValue (line 43152) | static JSValue js_json_check(JSContext *ctx, JSONStringifyContext *jsc,
function js_json_to_str (line 43215) | static int js_json_to_str(JSContext *ctx, JSONStringifyContext *jsc,
function JSValue (line 43410) | JSValue JS_JSONStringify(JSContext *ctx, JSValueConst obj,
function JSValue (line 43544) | static JSValue js_json_stringify(JSContext *ctx, JSValueConst this_val,
function JS_AddIntrinsicJSON (line 43561) | void JS_AddIntrinsicJSON(JSContext *ctx)
function JSValue (line 43569) | static JSValue js_reflect_apply(JSContext *ctx, JSValueConst this_val,
function JSValue (line 43575) | static JSValue js_reflect_construct(JSContext *ctx, JSValueConst this_val,
function JSValue (line 43599) | static JSValue js_reflect_deleteProperty(JSContext *ctx, JSValueConst th...
function JSValue (line 43620) | static JSValue js_reflect_get(JSContext *ctx, JSValueConst this_val,
function JSValue (line 43643) | static JSValue js_reflect_has(JSContext *ctx, JSValueConst this_val,
function JSValue (line 43665) | static JSValue js_reflect_set(JSContext *ctx, JSValueConst this_val,
function JSValue (line 43693) | static JSValue js_reflect_setPrototypeOf(JSContext *ctx, JSValueConst th...
function JSValue (line 43704) | static JSValue js_reflect_ownKeys(JSContext *ctx, JSValueConst this_val,
function js_proxy_finalizer (line 43736) | static void js_proxy_finalizer(JSRuntime *rt, JSValue val)
function js_proxy_mark (line 43746) | static void js_proxy_mark(JSRuntime *rt, JSValueConst val,
function JSValue (line 43756) | static JSValue JS_ThrowTypeErrorRevokedProxy(JSContext *ctx)
function JSProxyData (line 43761) | static JSProxyData *get_proxy_method(JSContext *ctx, JSValue *pmethod,
function JSValue (line 43787) | static JSValue js_proxy_getPrototypeOf(JSContext *ctx, JSValueConst obj)
function js_proxy_setPrototypeOf (line 43828) | static int js_proxy_setPrototypeOf(JSContext *ctx, JSValueConst obj,
function js_proxy_isExtensible (line 43873) | static int js_proxy_isExtensible(JSContext *ctx, JSValueConst obj)
function js_proxy_preventExtensions (line 43899) | static int js_proxy_preventExtensions(JSContext *ctx, JSValueConst obj)
function js_proxy_has (line 43927) | static int js_proxy_has(JSContext *ctx, JSValueConst obj, JSAtom atom)
function JSValue (line 43971) | static JSValue js_proxy_get(JSContext *ctx, JSValueConst obj, JSAtom atom,
function js_proxy_set (line 44019) | static int js_proxy_set(JSContext *ctx, JSValueConst obj, JSAtom atom,
function JSValue (line 44077) | static JSValue js_create_desc(JSContext *ctx, JSValueConst val,
function js_proxy_get_own_property (line 44115) | static int js_proxy_get_own_property(JSContext *ctx, JSPropertyDescripto...
function js_proxy_define_own_property (line 44212) | static int js_proxy_define_own_property(JSContext *ctx, JSValueConst obj,
function js_proxy_delete_property (line 44312) | static int js_proxy_delete_property(JSContext *ctx, JSValueConst obj,
function find_prop_key (line 44364) | static int find_prop_key(const JSPropertyEnum *tab, int n, JSAtom atom)
function js_proxy_get_own_property_names (line 44374) | static int js_proxy_get_own_property_names(JSContext *ctx,
function JSValue (line 44492) | static JSValue js_proxy_call_constructor(JSContext *ctx, JSValueConst fu...
function JSValue (line 44526) | static JSValue js_proxy_call(JSContext *ctx, JSValueConst func_obj,
function js_proxy_isArray (line 44561) | static int js_proxy_isArray(JSContext *ctx, JSValueConst obj)
function JSValue (line 44583) | static JSValue js_proxy_constructor(JSContext *ctx, JSValueConst this_val,
function JSValue (line 44613) | static JSValue js_proxy_revoke(JSContext *ctx, JSValueConst this_val,
function JSValue (line 44628) | static JSValue js_proxy_revoke_constructor(JSContext *ctx,
function JSValue (line 44634) | static JSValue js_proxy_revocable(JSContext *ctx, JSValueConst this_val,
function JS_AddIntrinsicProxy (line 44666) | void JS_AddIntrinsicProxy(JSContext *ctx)
function JSValue (line 44689) | static JSValue js_symbol_constructor(JSContext *ctx, JSValueConst new_ta...
function JSValue (line 44708) | static JSValue js_thisSymbolValue(JSContext *ctx, JSValueConst this_val)
function JSValue (line 44723) | static JSValue js_symbol_toString(JSContext *ctx, JSValueConst this_val,
function JSValue (line 44736) | static JSValue js_symbol_valueOf(JSContext *ctx, JSValueConst this_val,
function JSValue (line 44742) | static JSValue js_symbol_get_description(JSContext *ctx, JSValueConst th...
function JSValue (line 44769) | static JSValue js_symbol_for(JSContext *ctx, JSValueConst this_val,
function JSValue (line 44780) | static JSValue js_symbol_keyFor(JSContext *ctx, JSValueConst this_val,
type JSMapRecord (line 44800) | typedef struct JSMapRecord {
type JSMapState (line 44811) | typedef struct JSMapState {
function JSValue (line 44824) | static JSValue js_map_constructor(JSContext *ctx, JSValueConst new_target,
function JSValueConst (line 44935) | static JSValueConst map_normalize_key(JSContext *ctx, JSValueConst key)
function map_hash_key (line 44946) | static uint32_t map_hash_key(JSContext *ctx, JSValueConst key)
function JSMapRecord (line 44984) | static JSMapRecord *map_find_record(JSContext *ctx, JSMapState *s,
function map_hash_resize (line 44999) | static void map_hash_resize(JSContext *ctx, JSMapState *s)
function JSMapRecord (line 45032) | static JSMapRecord *map_add_record(JSContext *ctx, JSMapState *s,
function delete_weak_ref (line 45067) | static void delete_weak_ref(JSRuntime *rt, JSMapRecord *mr)
function map_delete_record (line 45084) | static void map_delete_record(JSRuntime *rt, JSMapState *s, JSMapRecord ...
function map_decref_record (line 45107) | static void map_decref_record(JSRuntime *rt, JSMapRecord *mr)
function reset_weak_ref (line 45117) | static void reset_weak_ref(JSRuntime *rt, JSObject *p)
function JSValue (line 45143) | static JSValue js_map_set(JSContext *ctx, JSValueConst this_val,
function JSValue (line 45171) | static JSValue js_map_get(JSContext *ctx, JSValueConst this_val,
function JSValue (line 45188) | static JSValue js_map_has(JSContext *ctx, JSValueConst this_val,
function JSValue (line 45202) | static JSValue js_map_delete(JSContext *ctx, JSValueConst this_val,
function JSValue (line 45219) | static JSValue js_map_clear(JSContext *ctx, JSValueConst this_val,
function JSValue (line 45235) | static JSValue js_map_get_size(JSContext *ctx, JSValueConst this_val, in...
function JSValue (line 45243) | static JSValue js_map_forEach(JSContext *ctx, JSValueConst this_val,
function js_map_finalizer (line 45291) | static void js_map_finalizer(JSRuntime *rt, JSValue val)
function js_map_mark (line 45319) | static void js_map_mark(JSRuntime *rt, JSValueConst val, JS_MarkFunc *ma...
type JSMapIteratorData (line 45339) | typedef struct JSMapIteratorData {
function js_map_iterator_finalizer (line 45345) | static void js_map_iterator_finalizer(JSRuntime *rt, JSValue val)
function js_map_iterator_mark (line 45363) | static void js_map_iterator_mark(JSRuntime *rt, JSValueConst val,
function JSValue (line 45375) | static JSValue js_create_map_iterator(JSContext *ctx, JSValueConst this_...
function JSValue (line 45405) | static JSValue js_map_iterator_next(JSContext *ctx, JSValueConst this_val,
function JS_AddIntrinsicMapSet (line 45546) | void JS_AddIntrinsicMapSet(JSContext *ctx)
type JSPromiseStateEnum (line 45591) | typedef enum JSPromiseStateEnum {
type JSPromiseData (line 45597) | typedef struct JSPromiseData {
type JSPromiseFunctionDataResolved (line 45605) | typedef struct JSPromiseFunctionDataResolved {
type JSPromiseFunctionData (line 45610) | typedef struct JSPromiseFunctionData {
type JSPromiseReactionData (line 45615) | typedef struct JSPromiseReactionData {
function promise_reaction_data_free (line 45624) | static void promise_reaction_data_free(JSRuntime *rt,
function JSValue (line 45633) | static JSValue promise_reaction_job(JSContext *ctx, int argc,
function JS_SetHostPromiseRejectionTracker (line 45675) | void JS_SetHostPromiseRejectionTracker(JSRuntime *rt,
function fulfill_or_reject_promise (line 45683) | static void fulfill_or_reject_promise(JSContext *ctx, JSValueConst promise,
function reject_promise (line 45725) | static void reject_promise(JSContext *ctx, JSValueConst promise,
function JSValue (line 45731) | static JSValue js_promise_resolve_thenable_job(JSContext *ctx,
function js_promise_resolve_function_free_resolved (line 45757) | static void js_promise_resolve_function_free_resolved(JSRuntime *rt,
function js_create_resolving_functions (line 45765) | static int js_create_resolving_functions(JSContext *ctx,
function js_promise_resolve_function_finalizer (line 45807) | static void js_promise_resolve_function_finalizer(JSRuntime *rt, JSValue...
function js_promise_resolve_function_mark (line 45817) | static void js_promise_resolve_function_mark(JSRuntime *rt, JSValueConst...
function JSValue (line 45826) | static JSValue js_promise_resolve_function_call(JSContext *ctx,
function js_promise_finalizer (line 45879) | static void js_promise_finalizer(JSRuntime *rt, JSValue val)
function js_promise_mark (line 45898) | static void js_promise_mark(JSRuntime *rt, JSValueConst val,
function JSValue (line 45919) | static JSValue js_promise_constructor(JSContext *ctx, JSValueConst new_t...
function JSValue (line 45967) | static JSValue js_promise_executor(JSContext *ctx,
function JSValue (line 45982) | static JSValue js_promise_executor_new(JSContext *ctx)
function JSValue (line 45992) | static JSValue js_new_promise_capability(JSContext *ctx,
function JSValue (line 46028) | JSValue JS_NewPromiseCapability(JSContext *ctx, JSValue *resolving_funcs)
function JSValue (line 46033) | static JSValue js_promise_resolve(JSContext *ctx, JSValueConst this_val,
function JSValue (line 46067) | static JSValue js_promise___newPromiseCapability(JSContext *ctx,
function __exception (line 46093) | static __exception int remainingElementsCount_add(JSContext *ctx,
function JSValue (line 46116) | static JSValue js_promise_all_resolve_element(JSContext *ctx,
function JSValue (line 46187) | static JSValue js_promise_all(JSContext *ctx, JSValueConst this_val,
function JSValue (line 46332) | static JSValue js_promise_race(JSContext *ctx, JSValueConst this_val,
function __exception (line 46401) | static __exception int perform_promise_then(JSContext *ctx,
function JSValue (line 46456) | static JSValue js_promise_then(JSContext *ctx, JSValueConst this_val,
function JSValue (line 46485) | static JSValue js_promise_catch(JSContext *ctx, JSValueConst this_val,
function JSValue (line 46494) | static JSValue js_promise_finally_value_thunk(JSContext *ctx, JSValueCon...
function JSValue (line 46501) | static JSValue js_promise_finally_thrower(JSContext *ctx, JSValueConst t...
function JSValue (line 46508) | static JSValue js_promise_then_finally_func(JSContext *ctx, JSValueConst...
function JSValue (line 46550) | static JSValue js_promise_finally(JSContext *ctx, JSValueConst this_val,
function JSValue (line 46608) | static JSValue js_async_from_sync_iterator_unwrap(JSContext *ctx,
function JSValue (line 46617) | static JSValue js_async_from_sync_iterator_unwrap_func_create(JSContext ...
type JSAsyncFromSyncIteratorData (line 46635) | typedef struct JSAsyncFromSyncIteratorData {
function js_async_from_sync_iterator_finalizer (line 46640) | static void js_async_from_sync_iterator_finalizer(JSRuntime *rt, JSValue...
function js_async_from_sync_iterator_mark (line 46651) | static void js_async_from_sync_iterator_mark(JSRuntime *rt, JSValueConst...
function JSValue (line 46662) | static JSValue JS_CreateAsyncFromSyncIterator(JSContext *ctx,
function JSValue (line 46688) | static JSValue js_async_from_sync_iterator_next(JSContext *ctx, JSValueC...
function JS_AddIntrinsicPromise (line 46826) | void JS_AddIntrinsicPromise(JSContext *ctx)
function string_get_hex (line 46913) | static int string_get_hex(JSString *p, int k, int n) {
function isURIReserved (line 46923) | static int isURIReserved(int c) {
function js_throw_URIError (line 46927) | static int __attribute__((format(printf, 2, 3))) js_throw_URIError(JSCon...
function hex_decode (line 46937) | static int hex_decode(JSContext *ctx, JSString *p, int k) {
function JSValue (line 46948) | static JSValue js_global_decodeURI(JSContext *ctx, JSValueConst this_val,
function isUnescaped (line 47025) | static int isUnescaped(int c) {
function isURIUnescaped (line 47035) | static int isURIUnescaped(int c, int isComponent) {
function encodeURI_hex (line 47044) | static int encodeURI_hex(StringBuffer *b, int c) {
function JSValue (line 47060) | static JSValue js_global_encodeURI(JSContext *ctx, JSValueConst this_val,
function JSValue (line 47125) | static JSValue js_global_escape(JSContext *ctx, JSValueConst this_val,
function JSValue (line 47151) | static JSValue js_global_unescape(JSContext *ctx, JSValueConst this_val,
function math_mod (line 47213) | static int64_t math_mod(int64_t a, int64_t b) {
function floor_div (line 47219) | static int64_t floor_div(int64_t a, int64_t b) {
function __exception (line 47228) | static __exception int JS_ThisTimeValue(JSContext *ctx, double *valp, JS...
function JSValue (line 47239) | static JSValue JS_SetThisTimeValue(JSContext *ctx, JSValueConst this_val...
function days_from_year (line 47252) | static int64_t days_from_year(int64_t y) {
function days_in_year (line 47257) | static int64_t days_in_year(int64_t y) {
function year_from_days (line 47262) | static int64_t year_from_days(int64_t *days) {
function __exception (line 47288) | static __exception int get_date_fields(JSContext *ctx, JSValueConst obj,
function time_clip (line 47341) | static double time_clip(double t) {
function set_date_fields (line 47348) | static double set_date_fields(int64_t fields[], int is_local) {
function JSValue (line 47370) | static JSValue get_date_field(JSContext *ctx, JSValueConst this_val,
function JSValue (line 47391) | static JSValue set_date_field(JSContext *ctx, JSValueConst this_val,
function JSValue (line 47432) | static JSValue get_date_string(JSContext *ctx, JSValueConst this_val,
function date_now (line 47539) | static int64_t date_now(void) {
function JSValue (line 47545) | static JSValue js_date_constructor(JSContext *ctx, JSValueConst new_target,
function JSValue (line 47621) | static JSValue js_Date_UTC(JSContext *ctx, JSValueConst this_val,
function string_skip_spaces (line 47646) | static void string_skip_spaces(JSString *sp, int *pp) {
function string_skip_non_spaces (line 47651) | static void string_skip_non_spaces(JSString *sp, int *pp) {
function string_get_field (line 47657) | static int string_get_field(JSString *sp, int *pp, int64_t *pval) {
function string_get_digits (line 47683) | static int string_get_digits(JSString *sp, int *pp, int n, int64_t *pval) {
function string_get_signed_field (line 47702) | static int string_get_signed_field(JSString *sp, int *pp, int64_t *pval) {
function find_abbrev (line 47718) | static int find_abbrev(JSString *sp, int p, const char *list, int count) {
function string_get_month (line 47734) | static int string_get_month(JSString *sp, int *pp, int64_t *pval) {
function JSValue (line 47747) | static JSValue js_Date_parse(JSContext *ctx, JSValueConst this_val,
function JSValue (line 47873) | static JSValue js_Date_now(JSContext *ctx, JSValueConst this_val,
function JSValue (line 47880) | static JSValue js_date_Symbol_toPrimitive(JSContext *ctx, JSValueConst t...
function JSValue (line 47914) | static JSValue js_date_getTimezoneOffset(JSContext *ctx, JSValueConst th...
function JSValue (line 47928) | static JSValue js_date_getTime(JSContext *ctx, JSValueConst this_val,
function JSValue (line 47939) | static JSValue js_date_setTime(JSContext *ctx, JSValueConst this_val,
function JSValue (line 47950) | static JSValue js_date_setYear(JSContext *ctx, JSValueConst this_val,
function JSValue (line 47969) | static JSValue js_date_toJSON(JSContext *ctx, JSValueConst this_val,
function JS_AddIntrinsicDate (line 48063) | void JS_AddIntrinsicDate(JSContext *ctx)
function JS_AddIntrinsicEval (line 48078) | void JS_AddIntrinsicEval(JSContext *ctx)
function js_operator_set_finalizer (line 48087) | static void js_operator_set_finalizer(JSRuntime *rt, JSValue val)
function js_operator_set_mark (line 48118) | static void js_operator_set_mark(JSRuntime *rt, JSValueConst val,
function JSValue (line 48152) | static JSValue js_operators_create_internal(JSContext *ctx,
function JSValue (line 48258) | static JSValue js_operators_create(JSContext *ctx, JSValueConst this_val,
function JSValue (line 48264) | static JSValue js_operators_updateBigIntOperators(JSContext *ctx, JSValu...
function js_operators_set_default (line 48307) | static int js_operators_set_default(JSContext *ctx, JSValueConst obj)
function JSValue (line 48322) | static JSValue js_dummy_operators_ctor(JSContext *ctx, JSValueConst new_...
function JSValue (line 48328) | static JSValue js_global_operators(JSContext *ctx, JSValueConst this_val,
function JS_AddIntrinsicOperators (line 48362) | void JS_AddIntrinsicOperators(JSContext *ctx)
function JSValue (line 48385) | static JSValue JS_ToBigIntCtorFree(JSContext *ctx, JSValue val)
function JSValue (line 48455) | static JSValue js_bigint_constructor(JSContext *ctx,
function JSValue (line 48462) | static JSValue js_thisBigIntValue(JSContext *ctx, JSValueConst this_val)
function JSValue (line 48477) | static JSValue js_bigint_toString(JSContext *ctx, JSValueConst this_val,
function JSValue (line 48502) | static JSValue js_bigint_valueOf(JSContext *ctx, JSValueConst this_val,
function JSValue (line 48508) | static JSValue js_bigint_div(JSContext *ctx,
function JSValue (line 48559) | static JSValue js_bigint_sqrt(JSContext *ctx,
function JSValue (line 48604) | static JSValue js_bigint_op1(JSContext *ctx,
function JSValue (line 48637) | static JSValue js_bigint_asUintN(JSContext *ctx,
function JS_AddIntrinsicBigInt (line 48701) | void JS_AddIntrinsicBigInt(JSContext *ctx)
function JSValue (line 48725) | static JSValue js_thisBigFloatValue(JSContext *ctx, JSValueConst this_val)
function JSValue (line 48740) | static JSValue js_bigfloat_toString(JSContext *ctx, JSValueConst this_val,
function JSValue (line 48765) | static JSValue js_bigfloat_valueOf(JSContext *ctx, JSValueConst this_val,
function bigfloat_get_rnd_mode (line 48771) | static int bigfloat_get_rnd_mode(JSContext *ctx, JSValueConst val)
function JSValue (line 48783) | static JSValue js_bigfloat_toFixed(JSContext *ctx, JSValueConst this_val,
function BOOL (line 48820) | static BOOL js_bigfloat_is_finite(JSContext *ctx, JSValueConst val)
function JSValue (line 48840) | static JSValue js_bigfloat_toExponential(JSContext *ctx, JSValueConst th...
function JSValue (line 48884) | static JSValue js_bigfloat_toPrecision(JSContext *ctx, JSValueConst this...
function JSValue (line 48935) | static JSValue js_bigfloat_constructor(JSContext *ctx,
function JSValue (line 49045) | static JSValue js_bigfloat_get_const(JSContext *ctx,
function JSValue (line 49092) | static JSValue js_bigfloat_parseFloat(JSContext *ctx, JSValueConst this_...
function JSValue (line 49130) | static JSValue js_bigfloat_isFinite(JSContext *ctx, JSValueConst this_val,
function JSValue (line 49142) | static JSValue js_bigfloat_isNaN(JSContext *ctx, JSValueConst this_val,
function JSValue (line 49182) | static JSValue js_bigfloat_fop(JSContext *ctx, JSValueConst this_val,
function JSValue (line 49276) | static JSValue js_bigfloat_fop2(JSContext *ctx, JSValueConst this_val,
function JSValue (line 49385) | static JSValue js_float_env_constructor(JSContext *ctx,
function js_float_env_finalizer (line 49424) | static void js_float_env_finalizer(JSRuntime *rt, JSValue val)
function JSValue (line 49430) | static JSValue js_float_env_get_prec(JSContext *ctx, JSValueConst this_val)
function JSValue (line 49435) | static JSValue js_float_env_get_expBits(JSContext *ctx, JSValueConst thi...
function JSValue (line 49440) | static JSValue js_float_env_setPrec(JSContext *ctx,
function JSValue (line 49484) | static JSValue js_float_env_proto_get_status(JSContext *ctx, JSValueCons...
function JSValue (line 49504) | static JSValue js_float_env_proto_set_status(JSContext *ctx, JSValueCons...
function JSValue (line 49547) | static JSValue js_float_env_clearStatus(JSContext *ctx,
function JS_AddIntrinsicBigFloat (line 49597) | void JS_AddIntrinsicBigFloat(JSContext *ctx)
function JSValue (line 49634) | static JSValue JS_ToBigDecimalFree(JSContext *ctx, JSValue val,
function JSValue (line 49730) | static JSValue js_bigdecimal_constructor(JSContext *ctx,
function JSValue (line 49748) | static JSValue js_thisBigDecimalValue(JSContext *ctx, JSValueConst this_...
function JSValue (line 49763) | static JSValue js_bigdecimal_toString(JSContext *ctx, JSValueConst this_...
function JSValue (line 49774) | static JSValue js_bigdecimal_valueOf(JSContext *ctx, JSValueConst this_val,
function js_bigdecimal_get_rnd_mode (line 49780) | static int js_bigdecimal_get_rnd_mode(JSContext *ctx, JSValueConst obj)
type BigDecimalEnv (line 49813) | typedef struct {
function js_bigdecimal_get_env (line 49818) | static int js_bigdecimal_get_env(JSContext *ctx, BigDecimalEnv *fe,
function JSValue (line 49880) | static JSValue js_bigdecimal_fop(JSContext *ctx, JSValueConst this_val,
function JSValue (line 49969) | static JSValue js_bigdecimal_toFixed(JSContext *ctx, JSValueConst this_val,
function JSValue (line 49999) | static JSValue js_bigdecimal_toExponential(JSContext *ctx, JSValueConst ...
function JSValue (line 50035) | static JSValue js_bigdecimal_toPrecision(JSContext *ctx, JSValueConst th...
function JS_AddIntrinsicBigDecimal (line 50087) | void JS_AddIntrinsicBigDecimal(JSContext *ctx)
function JS_EnableBignumExt (line 50109) | void JS_EnableBignumExt(JSContext *ctx, BOOL enable)
function JS_AddIntrinsicBasicObjects (line 50124) | static void JS_AddIntrinsicBasicObjects(JSContext *ctx)
function JS_AddIntrinsicBaseObjects (line 50178) | void JS_AddIntrinsicBaseObjects(JSContext *ctx)
function JSValue (line 50385) | static JSValue js_array_buffer_constructor3(JSContext *ctx,
function js_array_buffer_free (line 50444) | static void js_array_buffer_free(JSRuntime *rt, void *opaque, void *ptr)
function JSValue (line 50449) | static JSValue js_array_buffer_constructor2(JSContext *ctx,
function JSValue (line 50458) | static JSValue js_array_buffer_constructor1(JSContext *ctx,
function JSValue (line 50466) | JSValue JS_NewArrayBuffer(JSContext *ctx, uint8_t *buf, size_t len,
function JSValue (line 50476) | JSValue JS_NewArrayBufferCopy(JSContext *ctx, const uint8_t *buf, size_t...
function JSValue (line 50485) | static JSValue js_array_buffer_constructor(JSContext *ctx,
function JSValue (line 50495) | static JSValue js_shared_array_buffer_constructor(JSContext *ctx,
function js_array_buffer_finalizer (line 50507) | static void js_array_buffer_finalizer(JSRuntime *rt, JSValue val)
function JSValue (line 50526) | static JSValue js_array_buffer_isView(JSContext *ctx,
function JSValue (line 50548) | static JSValue JS_ThrowTypeErrorDetachedArrayBuffer(JSContext *ctx)
function JSValue (line 50553) | static JSValue js_array_buffer_get_byteLength(JSContext *ctx,
function JS_DetachArrayBuffer (line 50565) | void JS_DetachArrayBuffer(JSContext *ctx, JSValueConst obj)
function JSArrayBuffer (line 50593) | static JSArrayBuffer *js_get_array_buffer(JSContext *ctx, JSValueConst obj)
function JSValue (line 50626) | static JSValue js_array_buffer_slice(JSContext *ctx,
function JSObject (line 50710) | static JSObject *get_typed_array(JSContext *ctx,
function BOOL (line 50733) | static BOOL typed_array_is_detached(JSContext *ctx, JSObject *p)
function typed_array_get_length (line 50744) | static uint32_t typed_array_get_length(JSContext *ctx, JSObject *p)
function validate_typed_array (line 50751) | static int validate_typed_array(JSContext *ctx, JSValueConst this_val)
function JSValue (line 50764) | static JSValue js_typed_array_get_length(JSContext *ctx,
function JSValue (line 50774) | static JSValue js_typed_array_get_buffer(JSContext *ctx,
function JSValue (line 50786) | static JSValue js_typed_array_get_byteLength(JSContext *ctx,
function JSValue (line 50806) | static JSValue js_typed_array_get_byteOffset(JSContext *ctx,
function JSValue (line 50829) | JSValue JS_GetTypedArrayBuffer(JSContext *ctx, JSValueConst obj,
function JSValue (line 50852) | static JSValue js_typed_array_get_toStringTag(JSContext *ctx,
function JSValue (line 50865) | static JSValue js_typed_array_set_internal(JSContext *ctx,
function JSValue (line 50943) | static JSValue js_typed_array_set(JSContext *ctx,
function JSValue (line 50954) | static JSValue js_create_typed_array_iterator(JSContext *ctx, JSValueCon...
function js_typed_array_get_length_internal (line 50963) | static int js_typed_array_get_length_internal(JSContext *ctx,
function JSValue (line 50979) | static JSValue js_typed_array___getLength(JSContext *ctx,
function JSValue (line 50997) | static JSValue js_typed_array_create(JSContext *ctx, JSValueConst ctor,
function JSValue (line 51026) | static JSValue js_typed_array___create(JSContext *ctx,
function JSValue (line 51034) | static JSValue js_typed_array___speciesCreate(JSContext *ctx,
function JSValue (line 51061) | static JSValue js_typed_array_from(JSContext *ctx, JSValueConst this_val,
function JSValue (line 51154) | static JSValue js_typed_array_of(JSContext *ctx, JSValueConst this_val,
function JSValue (line 51175) | static JSValue js_typed_array_copyWithin(JSContext *ctx, JSValueConst th...
function JSValue (line 51210) | static JSValue js_typed_array_fill(JSContext *ctx, JSValueConst this_val,
function JSValue (line 51300) | static JSValue js_typed_array_find(JSContext *ctx, JSValueConst this_val,
function JSValue (line 51356) | static JSValue js_typed_array_indexOf(JSContext *ctx, JSValueConst this_...
function JSValue (line 51593) | static JSValue js_typed_array_join(JSContext *ctx, JSValueConst this_val,
function JSValue (line 51649) | static JSValue js_typed_array_reverse(JSContext *ctx, JSValueConst this_...
function JSValue (line 51712) | static JSValue js_typed_array_slice(JSContext *ctx, JSValueConst this_val,
function JSValue (line 51775) | static JSValue js_typed_array_subarray(JSContext *ctx, JSValueConst this...
function js_cmp_doubles (line 51819) | static int js_cmp_doubles(double x, double y)
function js_TA_cmp_int8 (line 51830) | static int js_TA_cmp_int8(const void *a, const void *b, void *opaque) {
function js_TA_cmp_uint8 (line 51834) | static int js_TA_cmp_uint8(const void *a, const void *b, void *opaque) {
function js_TA_cmp_int16 (line 51838) | static int js_TA_cmp_int16(const void *a, const void *b, void *opaque) {
function js_TA_cmp_uint16 (line 51842) | static int js_TA_cmp_uint16(const void *a, const void *b, void *opaque) {
function js_TA_cmp_int32 (line 51846) | static int js_TA_cmp_int32(const void *a, const void *b, void *opaque) {
function js_TA_cmp_uint32 (line 51852) | static int js_TA_cmp_uint32(const void *a, const void *b, void *opaque) {
function js_TA_cmp_int64 (line 51859) | static int js_TA_cmp_int64(const void *a, const void *b, void *opaque) {
function js_TA_cmp_uint64 (line 51865) | static int js_TA_cmp_uint64(const void *a, const void *b, void *opaque) {
function js_TA_cmp_float32 (line 51872) | static int js_TA_cmp_float32(const void *a, const void *b, void *opaque) {
function js_TA_cmp_float64 (line 51876) | static int js_TA_cmp_float64(const void *a, const void *b, void *opaque) {
function JSValue (line 51880) | static JSValue js_TA_get_int8(JSContext *ctx, const void *a) {
function JSValue (line 51884) | static JSValue js_TA_get_uint8(JSContext *ctx, const void *a) {
function JSValue (line 51888) | static JSValue js_TA_get_int16(JSContext *ctx, const void *a) {
function JSValue (line 51892) | static JSValue js_TA_get_uint16(JSContext *ctx, const void *a) {
function JSValue (line 51896) | static JSValue js_TA_get_int32(JSContext *ctx, const void *a) {
function JSValue (line 51900) | static JSValue js_TA_get_uint32(JSContext *ctx, const void *a) {
function JSValue (line 51905) | static JSValue js_TA_get_int64(JSContext *ctx, const void *a) {
function JSValue (line 51909) | static JSValue js_TA_get_uint64(JSContext *ctx, const void *a) {
function JSValue (line 51914) | static JSValue js_TA_get_float32(JSContext *ctx, const void *a) {
function JSValue (line 51918) | static JSValue js_TA_get_float64(JSContext *ctx, const void *a) {
type TA_sort_context (line 51922) | struct TA_sort_context {
function js_TA_cmp_generic (line 51932) | static int js_TA_cmp_generic(const void *a, const void *b, void *opaque) {
function JSValue (line 51979) | static JSValue js_typed_array_sort(JSContext *ctx, JSValueConst this_val,
function JSValue (line 52157) | static JSValue js_typed_array_base_constructor(JSContext *ctx,
function typed_array_init (line 52165) | static int typed_array_init(JSContext *ctx, JSValueConst obj,
function JSValue (line 52194) | static JSValue js_array_from_iterator(JSContext *ctx, uint32_t *plen,
function JSValue (line 52235) | static JSValue js_typed_array_constructor_obj(JSContext *ctx,
function JSValue (line 52288) | static JSValue js_typed_array_constructor_ta(JSContext *ctx,
function JSValue (line 52355) | static JSValue js_typed_array_constructor(JSContext *ctx,
function js_typed_array_finalizer (line 52423) | static void js_typed_array_finalizer(JSRuntime *rt, JSValue val)
function js_typed_array_mark (line 52438) | static void js_typed_array_mark(JSRuntime *rt, JSValueConst val,
function JSValue (line 52448) | static JSValue js_dataview_constructor(JSContext *ctx,
function JSValue (line 52507) | static JSValue js_dataview_getValue(JSContext *ctx,
function JSValue (line 52610) | static JSValue js_dataview_setValue(JSContext *ctx,
type AtomicsOpEnum (line 52739) | typedef enum AtomicsOpEnum {
function JSValue (line 52817) | static JSValue js_atomics_op(JSContext *ctx,
function JSValue (line 52987) | static JSValue js_atomics_store(JSContext *ctx,
function JSValue (line 53044) | static JSValue js_atomics_isLockFree(JSContext *ctx,
type JSAtomicsWaiter (line 53059) | typedef struct JSAtomicsWaiter {
type list_head (line 53067) | struct list_head
function JSValue (line 53070) | static JSValue js_atomics_wait(JSContext *ctx,
function JSValue (line 53155) | static JSValue js_atomics_notify(JSContext *ctx,
function JS_AddIntrinsicAtomics (line 53222) | void JS_AddIntrinsicAtomics(JSContext *ctx)
function JS_AddIntrinsicTypedArrays (line 53230) | void JS_AddIntrinsicTypedArrays(JSContext *ctx)
FILE: quickjs.go
type Runtime (line 23) | type Runtime struct
method RunGC (line 33) | func (r Runtime) RunGC() { C.JS_RunGC(r.ref) }
method Free (line 35) | func (r Runtime) Free() { C.JS_FreeRuntime(r.ref) }
method NewContext (line 37) | func (r Runtime) NewContext() *Context {
method ExecutePendingJob (line 48) | func (r Runtime) ExecutePendingJob() (Context, error) {
function NewRuntime (line 27) | func NewRuntime() Runtime {
type Function (line 62) | type Function
type funcEntry (line 64) | type funcEntry struct
function init (line 74) | func init() { C.JS_NewClassID(&funcPtrClassID) }
function storeFuncPtr (line 76) | func storeFuncPtr(v funcEntry) int64 {
function restoreFuncPtr (line 84) | func restoreFuncPtr(ptr int64) funcEntry {
function proxy (line 97) | func proxy(ctx *C.JSContext, thisVal C.JSValueConst, argc C.int, argv *C...
type Context (line 116) | type Context struct
method Free (line 122) | func (ctx *Context) Free() {
method Function (line 133) | func (ctx *Context) Function(fn Function) Value {
method Null (line 155) | func (ctx *Context) Null() Value {
method Undefined (line 159) | func (ctx *Context) Undefined() Value {
method Uninitialized (line 163) | func (ctx *Context) Uninitialized() Value {
method Error (line 167) | func (ctx *Context) Error(err error) Value {
method Bool (line 173) | func (ctx *Context) Bool(b bool) Value {
method Int32 (line 181) | func (ctx *Context) Int32(v int32) Value {
method Int64 (line 185) | func (ctx *Context) Int64(v int64) Value {
method Uint32 (line 189) | func (ctx *Context) Uint32(v uint32) Value {
method BigUint64 (line 193) | func (ctx *Context) BigUint64(v uint64) Value {
method Float64 (line 197) | func (ctx *Context) Float64(v float64) Value {
method String (line 201) | func (ctx *Context) String(v string) Value {
method Atom (line 207) | func (ctx *Context) Atom(v string) Atom {
method eval (line 213) | func (ctx *Context) eval(code string) Value { return ctx.evalFile(code...
method evalFile (line 215) | func (ctx *Context) evalFile(code, filename string) Value {
method Eval (line 225) | func (ctx *Context) Eval(code string) (Value, error) { return ctx.Eval...
method EvalFile (line 227) | func (ctx *Context) EvalFile(code, filename string) (Value, error) {
method Globals (line 235) | func (ctx *Context) Globals() Value {
method Throw (line 245) | func (ctx *Context) Throw(v Value) Value {
method ThrowError (line 249) | func (ctx *Context) ThrowError(err error) Value { return ctx.Throw(ctx...
method ThrowSyntaxError (line 251) | func (ctx *Context) ThrowSyntaxError(format string, args ...interface{...
method ThrowTypeError (line 258) | func (ctx *Context) ThrowTypeError(format string, args ...interface{})...
method ThrowReferenceError (line 265) | func (ctx *Context) ThrowReferenceError(format string, args ...interfa...
method ThrowRangeError (line 272) | func (ctx *Context) ThrowRangeError(format string, args ...interface{}...
method ThrowInternalError (line 279) | func (ctx *Context) ThrowInternalError(format string, args ...interfac...
method Exception (line 286) | func (ctx *Context) Exception() error {
method Object (line 292) | func (ctx *Context) Object() Value {
method Array (line 296) | func (ctx *Context) Array() Value {
type Atom (line 300) | type Atom struct
method Free (line 305) | func (a Atom) Free() { C.JS_FreeAtom(a.ctx.ref, a.ref) }
method String (line 307) | func (a Atom) String() string {
method Value (line 313) | func (a Atom) Value() Value {
type Value (line 317) | type Value struct
method Free (line 322) | func (v Value) Free() { C.JS_FreeValue(v.ctx.ref, v.ref) }
method Context (line 324) | func (v Value) Context() *Context { return v.ctx }
method Bool (line 326) | func (v Value) Bool() bool { return C.JS_ToBool(v.ctx.ref, v.ref) == 1 }
method String (line 328) | func (v Value) String() string {
method Int64 (line 334) | func (v Value) Int64() int64 {
method Int32 (li
Condensed preview — 27 files, each showing path, character count, and a content snippet. Download the .json file or copy for the full structured content (2,545K chars).
[
{
"path": ".gitattributes",
"chars": 127,
"preview": "# Set the default behavior, in case people don't have core.autocrlf set\n* text=auto\n\n# Require Unix line endings\n* text "
},
{
"path": ".gitignore",
"chars": 6,
"preview": ".idea/"
},
{
"path": "LICENSE",
"chars": 1169,
"preview": "MIT License\n\nCopyright (c) 2020 Kenta Iwasaki <kenta@lithdew.net>\nCopyright (c) 2017-2020 Fabrice Bellard\nCopyright (c) "
},
{
"path": "README.md",
"chars": 8258,
"preview": "# quickjs\n\n[](LICENSE)\n[ {\n\t r"
},
{
"path": "bridge.h",
"chars": 881,
"preview": "#include \"stdlib.h\"\n#include \"quickjs.h\"\n\nextern JSValue InvokeProxy(JSContext *ctx, JSValueConst this_val, int argc, JS"
},
{
"path": "cutils.c",
"chars": 16925,
"preview": "/*\n * C utilities\n * \n * Copyright (c) 2017 Fabrice Bellard\n * Copyright (c) 2018 Charlie Gordon\n *\n * Permission is her"
},
{
"path": "cutils.h",
"chars": 7403,
"preview": "/*\n * C utilities\n * \n * Copyright (c) 2017 Fabrice Bellard\n * Copyright (c) 2018 Charlie Gordon\n *\n * Permission is her"
},
{
"path": "examples/main.go",
"chars": 2657,
"preview": "package main\n\nimport (\n\t\"errors\"\n\t\"flag\"\n\t\"fmt\"\n\t\"github.com/lithdew/quickjs\"\n\t\"strings\"\n)\n\nfunc check(err error) {\n\tif "
},
{
"path": "go.mod",
"chars": 87,
"preview": "module github.com/lithdew/quickjs\n\ngo 1.14\n\nrequire github.com/stretchr/testify v1.6.1\n"
},
{
"path": "go.sum",
"chars": 1104,
"preview": "github.com/davecgh/go-spew v1.1.0 h1:ZDRjVQ15GmhC3fiQ8ni8+OwkZQO4DARzQgrnXU1Liz8=\ngithub.com/davecgh/go-spew v1.1.0/go.m"
},
{
"path": "libbf.c",
"chars": 240925,
"preview": "/*\n * Tiny arbitrary precision floating point library\n * \n * Copyright (c) 2017-2020 Fabrice Bellard\n *\n * Permission is"
},
{
"path": "libbf.h",
"chars": 17843,
"preview": "/*\n * Tiny arbitrary precision floating point library\n * \n * Copyright (c) 2017-2020 Fabrice Bellard\n *\n * Permission is"
},
{
"path": "libregexp-opcode.h",
"chars": 2236,
"preview": "/*\n * Regular Expression Engine\n * \n * Copyright (c) 2017-2018 Fabrice Bellard\n *\n * Permission is hereby granted, free "
},
{
"path": "libregexp.c",
"chars": 83683,
"preview": "/*\n * Regular Expression Engine\n * \n * Copyright (c) 2017-2018 Fabrice Bellard\n *\n * Permission is hereby granted, free "
},
{
"path": "libregexp.h",
"chars": 3129,
"preview": "/*\n * Regular Expression Engine\n * \n * Copyright (c) 2017-2018 Fabrice Bellard\n *\n * Permission is hereby granted, free "
},
{
"path": "libunicode-table.h",
"chars": 211895,
"preview": "/* Compressed unicode tables */\n/* Automatically generated file - do not edit */\n\n#include <stdint.h>\n\nstatic const uint"
},
{
"path": "libunicode.c",
"chars": 46403,
"preview": "/*\n * Unicode utilities\n * \n * Copyright (c) 2017-2018 Fabrice Bellard\n *\n * Permission is hereby granted, free of charg"
},
{
"path": "libunicode.h",
"chars": 3751,
"preview": "/*\n * Unicode utilities\n * \n * Copyright (c) 2017-2018 Fabrice Bellard\n *\n * Permission is hereby granted, free of charg"
},
{
"path": "list.h",
"chars": 3119,
"preview": "/*\n * Linux klist like system\n * \n * Copyright (c) 2016-2017 Fabrice Bellard\n *\n * Permission is hereby granted, free of"
},
{
"path": "quickjs-atom.h",
"chars": 7886,
"preview": "/*\n * QuickJS atom definitions\n * \n * Copyright (c) 2017-2018 Fabrice Bellard\n * Copyright (c) 2017-2018 Charlie Gordon\n"
},
{
"path": "quickjs-opcode.h",
"chars": 15331,
"preview": "/*\n * QuickJS opcode definitions\n * \n * Copyright (c) 2017-2018 Fabrice Bellard\n * Copyright (c) 2017-2018 Charlie Gordo"
},
{
"path": "quickjs.c",
"chars": 1730660,
"preview": "/*\n * QuickJS Javascript Engine\n * \n * Copyright (c) 2017-2020 Fabrice Bellard\n * Copyright (c) 2017-2020 Charlie Gordon"
},
{
"path": "quickjs.go",
"chars": 12256,
"preview": "package quickjs\n\nimport (\n\t\"errors\"\n\t\"fmt\"\n\t\"io\"\n\t\"math/big\"\n\t\"sync\"\n\t\"sync/atomic\"\n\t\"unsafe\"\n)\n\n/*\n#cgo CFLAGS: -D_GNU_"
},
{
"path": "quickjs.h",
"chars": 40574,
"preview": "/*\n * QuickJS Javascript Engine\n *\n * Copyright (c) 2017-2020 Fabrice Bellard\n * Copyright (c) 2017-2020 Charlie Gordon\n"
},
{
"path": "quickjs_test.go",
"chars": 3658,
"preview": "package quickjs\n\nimport (\n\t\"errors\"\n\t\"fmt\"\n\t\"github.com/stretchr/testify/require\"\n\tstdruntime \"runtime\"\n\t\"sync\"\n\t\"testin"
},
{
"path": "version.h",
"chars": 95,
"preview": "#ifndef _GUARD_H_PORT_H_\n#define _GUARD_H_PORT_H_\n\n#define CONFIG_VERSION \"2020-07-05\"\n\n#endif\n"
}
]
About this extraction
This page contains the full source code of the lithdew/quickjs GitHub repository, extracted and formatted as plain text for AI agents and large language models (LLMs). The extraction includes 27 files (2.3 MB), approximately 616.6k tokens, and a symbol index with 2200 extracted functions, classes, methods, constants, and types. Use this with OpenClaw, Claude, ChatGPT, Cursor, Windsurf, or any other AI tool that accepts text input. You can copy the full output to your clipboard or download it as a .txt file.
Extracted by GitExtract — free GitHub repo to text converter for AI. Built by Nikandr Surkov.