/* TCC runtime library. Parts of this code are (c) 2002 Fabrice Bellard Copyright (C) 1987, 1988, 1992, 1994, 1995 Free Software Foundation, Inc. This file is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 2, or (at your option) any later version. In addition to the permissions in the GNU General Public License, the Free Software Foundation gives you unlimited permission to link the compiled version of this file into combinations with other programs, and to distribute those combinations without any restriction coming from the use of this file. (The General Public License restrictions do apply in other respects; for example, they cover modification of the file, and distribution when not linked into a combine executable.) This file is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with this program; see the file COPYING. If not, write to the Free Software Foundation, 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */ #define W_TYPE_SIZE 32 #define BITS_PER_UNIT 8 typedef int Wtype; typedef unsigned int UWtype; typedef unsigned int USItype; typedef long long DWtype; typedef unsigned long long UDWtype; struct DWstruct { Wtype low, high; }; typedef union { struct DWstruct s; DWtype ll; } DWunion; typedef long double XFtype; #define WORD_SIZE (sizeof (Wtype) * BITS_PER_UNIT) #define HIGH_WORD_COEFF (((UDWtype) 1) << WORD_SIZE) /* the following deal with IEEE single-precision numbers */ #define EXCESS 126 #define SIGNBIT 0x80000000 #define HIDDEN (1 << 23) #define SIGN(fp) ((fp) & SIGNBIT) #define EXP(fp) (((fp) >> 23) & 0xFF) #define MANT(fp) (((fp) & 0x7FFFFF) | HIDDEN) #define PACK(s,e,m) ((s) | ((e) << 23) | (m)) /* the following deal with IEEE double-precision numbers */ #define EXCESSD 1022 #define HIDDEND (1 << 20) #define EXPD(fp) (((fp.l.upper) >> 20) & 0x7FF) #define SIGND(fp) ((fp.l.upper) & SIGNBIT) #define MANTD(fp) (((((fp.l.upper) & 0xFFFFF) | HIDDEND) << 10) | \ (fp.l.lower >> 22)) #define HIDDEND_LL ((long long)1 << 52) #define MANTD_LL(fp) ((fp.ll & (HIDDEND_LL-1)) | HIDDEND_LL) #define PACKD_LL(s,e,m) (((long long)((s)+((e)<<20))<<32)|(m)) /* the following deal with x86 long double-precision numbers */ #define EXCESSLD 16382 #define EXPLD(fp) (fp.l.upper & 0x7fff) #define SIGNLD(fp) ((fp.l.upper) & 0x8000) /* only for x86 */ union ldouble_long { long double ld; struct { unsigned long long lower; unsigned short upper; } l; }; union double_long { double d; #if 1 struct { unsigned int lower; int upper; } l; #else struct { int upper; unsigned int lower; } l; #endif long long ll; }; union float_long { float f; unsigned int l; }; /* XXX: we don't support several builtin supports for now */ #if !defined __x86_64__ && !defined __arm__ /* XXX: use gcc/tcc intrinsic ? */ #if defined __i386__ #define sub_ddmmss(sh, sl, ah, al, bh, bl) \ __asm__ ("subl %5,%1\n\tsbbl %3,%0" \ : "=r" ((USItype) (sh)), \ "=&r" ((USItype) (sl)) \ : "0" ((USItype) (ah)), \ "g" ((USItype) (bh)), \ "1" ((USItype) (al)), \ "g" ((USItype) (bl))) #define umul_ppmm(w1, w0, u, v) \ __asm__ ("mull %3" \ : "=a" ((USItype) (w0)), \ "=d" ((USItype) (w1)) \ : "%0" ((USItype) (u)), \ "rm" ((USItype) (v))) #define udiv_qrnnd(q, r, n1, n0, dv) \ __asm__ ("divl %4" \ : "=a" ((USItype) (q)), \ "=d" ((USItype) (r)) \ : "0" ((USItype) (n0)), \ "1" ((USItype) (n1)), \ "rm" ((USItype) (dv))) #define count_leading_zeros(count, x) \ do { \ USItype __cbtmp; \ __asm__ ("bsrl %1,%0" \ : "=r" (__cbtmp) : "rm" ((USItype) (x))); \ (count) = __cbtmp ^ 31; \ } while (0) #else #error unsupported CPU type #endif /* most of this code is taken from libgcc2.c from gcc */ static UDWtype __udivmoddi4 (UDWtype n, UDWtype d, UDWtype *rp) { DWunion ww; DWunion nn, dd; DWunion rr; UWtype d0, d1, n0, n1, n2; UWtype q0, q1; UWtype b, bm; nn.ll = n; dd.ll = d; d0 = dd.s.low; d1 = dd.s.high; n0 = nn.s.low; n1 = nn.s.high; #if !defined(UDIV_NEEDS_NORMALIZATION) if (d1 == 0) { if (d0 > n1) { /* 0q = nn / 0D */ udiv_qrnnd (q0, n0, n1, n0, d0); q1 = 0; /* Remainder in n0. */ } else { /* qq = NN / 0d */ if (d0 == 0) d0 = 1 / d0; /* Divide intentionally by zero. */ udiv_qrnnd (q1, n1, 0, n1, d0); udiv_qrnnd (q0, n0, n1, n0, d0); /* Remainder in n0. */ } if (rp != 0) { rr.s.low = n0; rr.s.high = 0; *rp = rr.ll; } } #else /* UDIV_NEEDS_NORMALIZATION */ if (d1 == 0) { if (d0 > n1) { /* 0q = nn / 0D */ count_leading_zeros (bm, d0); i
## - `FormData` for the JavaScript target: https://developer.mozilla.org/en-US/docs/Web/API/FormData
when not defined(js):
{.fatal: "Module jsformdata is designed to be used with the JavaScript backend.".}
type FormData* = ref object of JsRoot ## FormData API.
func newFormData*(): FormData {.importjs: "new FormData()".}
func add*(self: FormData; name: cstring; value: SomeNumber | bool | cstring) {.importjs: "#.append(#, #)".}
## https://developer.mozilla.org/en-US/docs/Web/API/FormData/append
## Duplicate keys are