added sys.time, sys.random, sys.srandom.
removed test-bi.sh wrote a simple bigint test program into test-bi.hcl
This commit is contained in:
parent
9045220ef8
commit
2d9f5b51ad
@ -99,6 +99,8 @@ libhcl_la_LIBADD += -lhcl-dic
|
||||
libhcl_la_DEPENDENCIES += $(abs_builddir)/../mod/libhcl-dic.la
|
||||
libhcl_la_LIBADD += -lhcl-str
|
||||
libhcl_la_DEPENDENCIES += $(abs_builddir)/../mod/libhcl-str.la
|
||||
libhcl_la_LIBADD += -lhcl-sys
|
||||
libhcl_la_DEPENDENCIES += $(abs_builddir)/../mod/libhcl-sys.la
|
||||
endif
|
||||
|
||||
bin_PROGRAMS = hcl
|
||||
|
@ -94,10 +94,11 @@ host_triplet = @host@
|
||||
@MACOSX_TRUE@@WIN32_FALSE@am__append_4 = -DHCL_DEFAULT_PFMODPOSTFIX=\".dylib\"
|
||||
@MACOSX_FALSE@@WIN32_FALSE@am__append_5 = -DHCL_DEFAULT_PFMODPOSTFIX=\".so\"
|
||||
@ENABLE_STATIC_MODULE_TRUE@am__append_6 = -lhcl-arr -lhcl-dic \
|
||||
@ENABLE_STATIC_MODULE_TRUE@ -lhcl-str
|
||||
@ENABLE_STATIC_MODULE_TRUE@ -lhcl-str -lhcl-sys
|
||||
@ENABLE_STATIC_MODULE_TRUE@am__append_7 = $(abs_builddir)/../mod/libhcl-arr.la \
|
||||
@ENABLE_STATIC_MODULE_TRUE@ $(abs_builddir)/../mod/libhcl-dic.la \
|
||||
@ENABLE_STATIC_MODULE_TRUE@ $(abs_builddir)/../mod/libhcl-str.la
|
||||
@ENABLE_STATIC_MODULE_TRUE@ $(abs_builddir)/../mod/libhcl-str.la \
|
||||
@ENABLE_STATIC_MODULE_TRUE@ $(abs_builddir)/../mod/libhcl-sys.la
|
||||
bin_PROGRAMS = hcl$(EXEEXT) $(am__EXEEXT_1)
|
||||
@ENABLE_HCLEX_TRUE@am__append_8 = libhclex.la
|
||||
@ENABLE_HCLEX_TRUE@am__append_9 = hcl-c.h hcl-s.h hcl-tmr.h hcl-xutl.h hcl-json.h
|
||||
@ -425,7 +426,6 @@ pdfdir = @pdfdir@
|
||||
prefix = @prefix@
|
||||
program_transform_name = @program_transform_name@
|
||||
psdir = @psdir@
|
||||
runstatedir = @runstatedir@
|
||||
sbindir = @sbindir@
|
||||
sharedstatedir = @sharedstatedir@
|
||||
srcdir = @srcdir@
|
||||
|
@ -396,7 +396,7 @@ int hcl_inttooow (hcl_t* hcl, hcl_oop_t x, hcl_oow_t* w)
|
||||
}
|
||||
}
|
||||
|
||||
if (is_bigint(hcl, x)) return bigint_to_oow (hcl, x, w);
|
||||
if (is_bigint(hcl, x)) return bigint_to_oow(hcl, x, w);
|
||||
|
||||
hcl_seterrbfmt (hcl, HCL_EINVAL, "parameter not integer - %O", x);
|
||||
return 0; /* not convertable - too big, too small, or not integer */
|
||||
|
@ -513,6 +513,7 @@ void hcl_freemem (hcl_t* hcl, void* ptr)
|
||||
#include "../mod/_arr.h"
|
||||
#include "../mod/_dic.h"
|
||||
#include "../mod/_str.h"
|
||||
#include "../mod/_sys.h"
|
||||
|
||||
static struct
|
||||
{
|
||||
@ -523,7 +524,8 @@ static_modtab[] =
|
||||
{
|
||||
{ "arr", hcl_mod_arr },
|
||||
{ "dic", hcl_mod_dic },
|
||||
{ "str", hcl_mod_str }
|
||||
{ "str", hcl_mod_str },
|
||||
{ "sys", hcl_mod_sys }
|
||||
};
|
||||
#endif
|
||||
|
||||
|
@ -1174,7 +1174,7 @@ count++;
|
||||
|
||||
code_offset = hcl_getbclen(hcl);
|
||||
|
||||
/*hcl_proutbfmt (hcl, 0, "\n");*/
|
||||
if (verbose) hcl_proutbfmt (hcl, 0, "\n"); /* flush the output buffer by hcl_print above */
|
||||
if (hcl_compile(hcl, obj) <= -1)
|
||||
{
|
||||
if (hcl->errnum == HCL_ESYNERR)
|
||||
|
@ -22,6 +22,7 @@ noinst_LTLIBRARIES =
|
||||
noinst_LTLIBRARIES += libhcl-arr.la
|
||||
noinst_LTLIBRARIES += libhcl-dic.la
|
||||
noinst_LTLIBRARIES += libhcl-str.la
|
||||
noinst_LTLIBRARIES += libhcl-sys.la
|
||||
|
||||
else
|
||||
|
||||
@ -37,6 +38,7 @@ pkgmodexec_LTLIBRARIES =
|
||||
pkgmodexec_LTLIBRARIES += libhcl-arr.la
|
||||
pkgmodexec_LTLIBRARIES += libhcl-dic.la
|
||||
pkgmodexec_LTLIBRARIES += libhcl-str.la
|
||||
pkgmodexec_LTLIBRARIES += libhcl-sys.la
|
||||
|
||||
endif
|
||||
|
||||
@ -54,3 +56,8 @@ libhcl_str_la_SOURCES = str.c _str.h
|
||||
libhcl_str_la_CPPFLAGS = $(CPPFLAGS_COMMON)
|
||||
libhcl_str_la_LDFLAGS = $(LDFLAGS_COMMON)
|
||||
libhcl_str_la_LIBADD = $(LIBADD_COMMON)
|
||||
|
||||
libhcl_sys_la_SOURCES = sys.c _sys.h
|
||||
libhcl_sys_la_CPPFLAGS = $(CPPFLAGS_COMMON)
|
||||
libhcl_sys_la_LDFLAGS = $(LDFLAGS_COMMON)
|
||||
libhcl_sys_la_LIBADD = $(LIBADD_COMMON)
|
||||
|
@ -164,6 +164,15 @@ libhcl_str_la_LINK = $(LIBTOOL) $(AM_V_lt) --tag=CC $(AM_LIBTOOLFLAGS) \
|
||||
@ENABLE_STATIC_MODULE_FALSE@am_libhcl_str_la_rpath = -rpath \
|
||||
@ENABLE_STATIC_MODULE_FALSE@ $(pkgmodexecdir)
|
||||
@ENABLE_STATIC_MODULE_TRUE@am_libhcl_str_la_rpath =
|
||||
libhcl_sys_la_DEPENDENCIES = $(am__DEPENDENCIES_1)
|
||||
am_libhcl_sys_la_OBJECTS = libhcl_sys_la-sys.lo
|
||||
libhcl_sys_la_OBJECTS = $(am_libhcl_sys_la_OBJECTS)
|
||||
libhcl_sys_la_LINK = $(LIBTOOL) $(AM_V_lt) --tag=CC $(AM_LIBTOOLFLAGS) \
|
||||
$(LIBTOOLFLAGS) --mode=link $(CCLD) $(AM_CFLAGS) $(CFLAGS) \
|
||||
$(libhcl_sys_la_LDFLAGS) $(LDFLAGS) -o $@
|
||||
@ENABLE_STATIC_MODULE_FALSE@am_libhcl_sys_la_rpath = -rpath \
|
||||
@ENABLE_STATIC_MODULE_FALSE@ $(pkgmodexecdir)
|
||||
@ENABLE_STATIC_MODULE_TRUE@am_libhcl_sys_la_rpath =
|
||||
AM_V_P = $(am__v_P_@AM_V@)
|
||||
am__v_P_ = $(am__v_P_@AM_DEFAULT_V@)
|
||||
am__v_P_0 = false
|
||||
@ -199,9 +208,9 @@ am__v_CCLD_ = $(am__v_CCLD_@AM_DEFAULT_V@)
|
||||
am__v_CCLD_0 = @echo " CCLD " $@;
|
||||
am__v_CCLD_1 =
|
||||
SOURCES = $(libhcl_arr_la_SOURCES) $(libhcl_dic_la_SOURCES) \
|
||||
$(libhcl_str_la_SOURCES)
|
||||
$(libhcl_str_la_SOURCES) $(libhcl_sys_la_SOURCES)
|
||||
DIST_SOURCES = $(libhcl_arr_la_SOURCES) $(libhcl_dic_la_SOURCES) \
|
||||
$(libhcl_str_la_SOURCES)
|
||||
$(libhcl_str_la_SOURCES) $(libhcl_sys_la_SOURCES)
|
||||
am__can_run_installinfo = \
|
||||
case $$AM_UPDATE_INFO_DIR in \
|
||||
n|no|NO) false;; \
|
||||
@ -372,7 +381,6 @@ pdfdir = @pdfdir@
|
||||
prefix = @prefix@
|
||||
program_transform_name = @program_transform_name@
|
||||
psdir = @psdir@
|
||||
runstatedir = @runstatedir@
|
||||
sbindir = @sbindir@
|
||||
sharedstatedir = @sharedstatedir@
|
||||
srcdir = @srcdir@
|
||||
@ -402,10 +410,12 @@ CPPFLAGS_COMMON = \
|
||||
@ENABLE_STATIC_MODULE_FALSE@LIBADD_COMMON = -lhcl
|
||||
@ENABLE_STATIC_MODULE_TRUE@LIBADD_COMMON =
|
||||
@ENABLE_STATIC_MODULE_TRUE@noinst_LTLIBRARIES = libhcl-arr.la \
|
||||
@ENABLE_STATIC_MODULE_TRUE@ libhcl-dic.la libhcl-str.la
|
||||
@ENABLE_STATIC_MODULE_TRUE@ libhcl-dic.la libhcl-str.la \
|
||||
@ENABLE_STATIC_MODULE_TRUE@ libhcl-sys.la
|
||||
@ENABLE_STATIC_MODULE_FALSE@pkgmodexecdir = $(libdir)
|
||||
@ENABLE_STATIC_MODULE_FALSE@pkgmodexec_LTLIBRARIES = libhcl-arr.la \
|
||||
@ENABLE_STATIC_MODULE_FALSE@ libhcl-dic.la libhcl-str.la
|
||||
@ENABLE_STATIC_MODULE_FALSE@ libhcl-dic.la libhcl-str.la \
|
||||
@ENABLE_STATIC_MODULE_FALSE@ libhcl-sys.la
|
||||
libhcl_arr_la_SOURCES = arr.c _arr.h
|
||||
libhcl_arr_la_CPPFLAGS = $(CPPFLAGS_COMMON)
|
||||
libhcl_arr_la_LDFLAGS = $(LDFLAGS_COMMON)
|
||||
@ -418,6 +428,10 @@ libhcl_str_la_SOURCES = str.c _str.h
|
||||
libhcl_str_la_CPPFLAGS = $(CPPFLAGS_COMMON)
|
||||
libhcl_str_la_LDFLAGS = $(LDFLAGS_COMMON)
|
||||
libhcl_str_la_LIBADD = $(LIBADD_COMMON)
|
||||
libhcl_sys_la_SOURCES = sys.c _sys.h
|
||||
libhcl_sys_la_CPPFLAGS = $(CPPFLAGS_COMMON)
|
||||
libhcl_sys_la_LDFLAGS = $(LDFLAGS_COMMON)
|
||||
libhcl_sys_la_LIBADD = $(LIBADD_COMMON)
|
||||
all: all-am
|
||||
|
||||
.SUFFIXES:
|
||||
@ -507,6 +521,9 @@ libhcl-dic.la: $(libhcl_dic_la_OBJECTS) $(libhcl_dic_la_DEPENDENCIES) $(EXTRA_li
|
||||
libhcl-str.la: $(libhcl_str_la_OBJECTS) $(libhcl_str_la_DEPENDENCIES) $(EXTRA_libhcl_str_la_DEPENDENCIES)
|
||||
$(AM_V_CCLD)$(libhcl_str_la_LINK) $(am_libhcl_str_la_rpath) $(libhcl_str_la_OBJECTS) $(libhcl_str_la_LIBADD) $(LIBS)
|
||||
|
||||
libhcl-sys.la: $(libhcl_sys_la_OBJECTS) $(libhcl_sys_la_DEPENDENCIES) $(EXTRA_libhcl_sys_la_DEPENDENCIES)
|
||||
$(AM_V_CCLD)$(libhcl_sys_la_LINK) $(am_libhcl_sys_la_rpath) $(libhcl_sys_la_OBJECTS) $(libhcl_sys_la_LIBADD) $(LIBS)
|
||||
|
||||
mostlyclean-compile:
|
||||
-rm -f *.$(OBJEXT)
|
||||
|
||||
@ -516,6 +533,7 @@ distclean-compile:
|
||||
@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/libhcl_arr_la-arr.Plo@am__quote@
|
||||
@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/libhcl_dic_la-dic.Plo@am__quote@
|
||||
@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/libhcl_str_la-str.Plo@am__quote@
|
||||
@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/libhcl_sys_la-sys.Plo@am__quote@
|
||||
|
||||
.c.o:
|
||||
@am__fastdepCC_TRUE@ $(AM_V_CC)depbase=`echo $@ | sed 's|[^/]*$$|$(DEPDIR)/&|;s|\.o$$||'`;\
|
||||
@ -562,6 +580,13 @@ libhcl_str_la-str.lo: str.c
|
||||
@AMDEP_TRUE@@am__fastdepCC_FALSE@ DEPDIR=$(DEPDIR) $(CCDEPMODE) $(depcomp) @AMDEPBACKSLASH@
|
||||
@am__fastdepCC_FALSE@ $(AM_V_CC@am__nodep@)$(LIBTOOL) $(AM_V_lt) --tag=CC $(AM_LIBTOOLFLAGS) $(LIBTOOLFLAGS) --mode=compile $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(libhcl_str_la_CPPFLAGS) $(CPPFLAGS) $(AM_CFLAGS) $(CFLAGS) -c -o libhcl_str_la-str.lo `test -f 'str.c' || echo '$(srcdir)/'`str.c
|
||||
|
||||
libhcl_sys_la-sys.lo: sys.c
|
||||
@am__fastdepCC_TRUE@ $(AM_V_CC)$(LIBTOOL) $(AM_V_lt) --tag=CC $(AM_LIBTOOLFLAGS) $(LIBTOOLFLAGS) --mode=compile $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(libhcl_sys_la_CPPFLAGS) $(CPPFLAGS) $(AM_CFLAGS) $(CFLAGS) -MT libhcl_sys_la-sys.lo -MD -MP -MF $(DEPDIR)/libhcl_sys_la-sys.Tpo -c -o libhcl_sys_la-sys.lo `test -f 'sys.c' || echo '$(srcdir)/'`sys.c
|
||||
@am__fastdepCC_TRUE@ $(AM_V_at)$(am__mv) $(DEPDIR)/libhcl_sys_la-sys.Tpo $(DEPDIR)/libhcl_sys_la-sys.Plo
|
||||
@AMDEP_TRUE@@am__fastdepCC_FALSE@ $(AM_V_CC)source='sys.c' object='libhcl_sys_la-sys.lo' libtool=yes @AMDEPBACKSLASH@
|
||||
@AMDEP_TRUE@@am__fastdepCC_FALSE@ DEPDIR=$(DEPDIR) $(CCDEPMODE) $(depcomp) @AMDEPBACKSLASH@
|
||||
@am__fastdepCC_FALSE@ $(AM_V_CC@am__nodep@)$(LIBTOOL) $(AM_V_lt) --tag=CC $(AM_LIBTOOLFLAGS) $(LIBTOOLFLAGS) --mode=compile $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(libhcl_sys_la_CPPFLAGS) $(CPPFLAGS) $(AM_CFLAGS) $(CFLAGS) -c -o libhcl_sys_la-sys.lo `test -f 'sys.c' || echo '$(srcdir)/'`sys.c
|
||||
|
||||
mostlyclean-libtool:
|
||||
-rm -f *.lo
|
||||
|
||||
|
43
mod/_sys.h
Normal file
43
mod/_sys.h
Normal file
@ -0,0 +1,43 @@
|
||||
/*
|
||||
* $Id$
|
||||
*
|
||||
Copyright (c) 2016-2018 Chung, Hyung-Hwan. All rights reserved.
|
||||
|
||||
Redistribution and use in source and binary forms, with or without
|
||||
modification, are permitted provided that the following conditions
|
||||
are met:
|
||||
1. Redistributions of source code must retain the above copyright
|
||||
notice, this list of conditions and the following disclaimer.
|
||||
2. Redistributions in binary form must reproduce the above copyright
|
||||
notice, this list of conditions and the following disclaimer in the
|
||||
documentation and/or other materials provided with the distribution.
|
||||
|
||||
THIS SOFTWARE IS PROVIDED BY THE AUTHOR "AS IS" AND ANY EXPRESS OR
|
||||
IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
|
||||
OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
|
||||
IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
|
||||
INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
|
||||
NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
|
||||
DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
|
||||
THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
||||
(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
|
||||
THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*/
|
||||
|
||||
#ifndef _HCL_MOD_SYS_H_
|
||||
#define _HCL_MOD_SYS_H_
|
||||
|
||||
#include <hcl.h>
|
||||
|
||||
#if defined(__cplusplus)
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
HCL_EXPORT int hcl_mod_sys (hcl_t* hcl, hcl_mod_t* mod);
|
||||
|
||||
#if defined(__cplusplus)
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif
|
||||
|
93
mod/sys.c
Normal file
93
mod/sys.c
Normal file
@ -0,0 +1,93 @@
|
||||
/*
|
||||
* $Id$
|
||||
*
|
||||
Copyright (c) 2016-2018 Chung, Hyung-Hwan. All rights reserved.
|
||||
|
||||
Redistribution and use in source and binary forms, with or without
|
||||
modification, are permitted provided that the following conditions
|
||||
are met:
|
||||
1. Redistributions of source code must retain the above copyright
|
||||
notice, this list of conditions and the following disclaimer.
|
||||
2. Redistributions in binary form must reproduce the above copyright
|
||||
notice, this list of conditions and the following disclaimer in the
|
||||
documentation and/or other materials provided with the distribution.
|
||||
|
||||
THIS SOFTWARE IS PROVIDED BY THE AUTHOR "AS IS" AND ANY EXPRESS OR
|
||||
IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
|
||||
OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
|
||||
IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
|
||||
INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
|
||||
NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
|
||||
DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
|
||||
THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
||||
(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
|
||||
THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*/
|
||||
|
||||
|
||||
#include "_sys.h"
|
||||
#include <stdlib.h>
|
||||
|
||||
static hcl_pfrc_t pf_sys_time (hcl_t* hcl, hcl_mod_t* mod, hcl_ooi_t nargs)
|
||||
{
|
||||
hcl_ntime_t now;
|
||||
hcl_oop_t tv;
|
||||
hcl->vmprim.gettime(hcl, &now);
|
||||
tv = hcl_oowtoint(hcl, now.sec);
|
||||
if (!tv) return HCL_PF_FAILURE;
|
||||
HCL_STACK_SETRET (hcl, nargs, tv);
|
||||
return HCL_PF_SUCCESS;
|
||||
}
|
||||
|
||||
static hcl_pfrc_t pf_sys_srandom (hcl_t* hcl, hcl_mod_t* mod, hcl_ooi_t nargs)
|
||||
{
|
||||
hcl_oop_t seed;
|
||||
hcl_oow_t seedw;
|
||||
|
||||
seed = HCL_STACK_GETARG(hcl, nargs, 0);
|
||||
if (hcl_inttooow(hcl, seed, &seedw) == 0)
|
||||
{
|
||||
const hcl_ooch_t* orgmsg = hcl_backuperrmsg(hcl);
|
||||
hcl_seterrbfmt (hcl, HCL_EINVAL, "unacceptiable seed - %O - %js", seed, orgmsg);
|
||||
return HCL_PF_FAILURE;
|
||||
}
|
||||
|
||||
srandom (seedw);
|
||||
HCL_STACK_SETRET (hcl, nargs, hcl->_nil);
|
||||
return HCL_PF_SUCCESS;
|
||||
}
|
||||
|
||||
static hcl_pfrc_t pf_sys_random (hcl_t* hcl, hcl_mod_t* mod, hcl_ooi_t nargs)
|
||||
{
|
||||
long int r = random();
|
||||
hcl_ooi_t rv = (hcl_ooi_t)(r % HCL_SMOOI_MAX);
|
||||
HCL_STACK_SETRET (hcl, nargs, HCL_SMOOI_TO_OOP(rv));
|
||||
return HCL_PF_SUCCESS;
|
||||
}
|
||||
|
||||
static hcl_pfinfo_t pfinfos[] =
|
||||
{
|
||||
/*{ { 'V','A','R','\0' }, { HCL_PFBASE_VAR, HCL_NULL, 0, 0 } },*/
|
||||
{ { 'r','a','n','d','o','m','\0' }, { HCL_PFBASE_FUNC, pf_sys_random, 0, 0 } },
|
||||
{ { 's','r','a','n','d','o','m','\0' }, { HCL_PFBASE_FUNC, pf_sys_srandom, 1, 1 } },
|
||||
{ { 't','i','m','e','\0' }, { HCL_PFBASE_FUNC, pf_sys_time, 0, 0 } }
|
||||
};
|
||||
|
||||
/* ------------------------------------------------------------------------ */
|
||||
|
||||
static hcl_pfbase_t* query (hcl_t* hcl, hcl_mod_t* mod, const hcl_ooch_t* name, hcl_oow_t namelen)
|
||||
{
|
||||
return hcl_findpfbase(hcl, pfinfos, HCL_COUNTOF(pfinfos), name, namelen);
|
||||
}
|
||||
|
||||
static void unload (hcl_t* hcl, hcl_mod_t* mod)
|
||||
{
|
||||
}
|
||||
|
||||
int hcl_mod_sys (hcl_t* hcl, hcl_mod_t* mod)
|
||||
{
|
||||
mod->query = query;
|
||||
mod->unload = unload;
|
||||
mod->ctx = HCL_NULL;
|
||||
return 0;
|
||||
}
|
36
t/test-bi.hcl
Normal file
36
t/test-bi.hcl
Normal file
@ -0,0 +1,36 @@
|
||||
## test big integer operations
|
||||
## hcl --log /dev/null,warn+ test-bi.hcl
|
||||
|
||||
(sys.srandom (sys.time))
|
||||
(set count 0)
|
||||
(while true
|
||||
(printf "%O\r" count)
|
||||
(set count (+ count 1))
|
||||
|
||||
(set limit (rem (sys.random) 30))
|
||||
(set dividend (sys.random))
|
||||
(set i 1)
|
||||
(while (< i limit)
|
||||
(set dividend (bit-or (bit-shift dividend 30) (sys.random)))
|
||||
(set i (+ i 1))
|
||||
)
|
||||
|
||||
(set limit (rem (sys.random) 30))
|
||||
(set divisor (sys.random))
|
||||
(set i 1)
|
||||
(while (< i limit)
|
||||
(set divisor (bit-or (bit-shift divisor 30) (sys.random)))
|
||||
(set i (+ i 1))
|
||||
)
|
||||
|
||||
(set quotient (/ dividend divisor))
|
||||
(set remainder (rem dividend divisor))
|
||||
(set derived_dividend (+ (* quotient divisor) remainder))
|
||||
|
||||
(if (/= dividend derived_dividend)
|
||||
(printf ">> dividend %O\n>> divisor %O\n>> quotient %O\n>> remainder %O\n>> derived_dividend %O\n"
|
||||
dividend divisor quotient remainder derived_dividend)
|
||||
(break)
|
||||
)
|
||||
)
|
||||
(printf "\n")
|
35
t/test-bi.sh
35
t/test-bi.sh
@ -1,35 +0,0 @@
|
||||
count=0
|
||||
while true
|
||||
do
|
||||
/bin/echo -n -e "$count\r"
|
||||
count=$(($count + 1))
|
||||
|
||||
a=`openssl rand -hex 1 | tr '[a-z]' '[A-Z]'`
|
||||
a=$(echo -e "(printf \"%O\" #x$a)" | ~/xxx/bin/hcl --log /dev/null /dev/stdin)
|
||||
[ "$a" = "0" ] && a=1
|
||||
a=`openssl rand -hex $a | tr '[a-z]' '[A-Z]'`
|
||||
|
||||
|
||||
b=`openssl rand -hex 1 | tr '[a-z]' '[A-Z]'`
|
||||
b=$(echo -e "(printf \"%O\" #x$b)" | ~/xxx/bin/hcl --log /dev/null /dev/stdin)
|
||||
[ "$b" = "0" ] && b=1
|
||||
b=`openssl rand -hex $b | tr '[a-z]' '[A-Z]'`
|
||||
|
||||
a=$(echo -e "(printf \"%O\" #x$a)" | ~/xxx/bin/hcl --log /dev/null /dev/stdin)
|
||||
b=$(echo -e "(printf \"%O\" #x$b)" | ~/xxx/bin/hcl --log /dev/null /dev/stdin)
|
||||
[ "$b" = "0" ] && b=1
|
||||
|
||||
q=$(echo -e "(printf \"%O\" (/ $a $b))" | ~/xxx/bin/hcl --log /dev/null /dev/stdin)
|
||||
r=$(echo -e "(printf \"%O\" (rem $a $b))" | ~/xxx/bin/hcl --log /dev/null /dev/stdin)
|
||||
a1=$(echo -e "(printf \"%O\" (+ (* $q $b) $r))" | ~/xxx/bin/hcl --log /dev/null /dev/stdin)
|
||||
|
||||
if [ "$a" != "$a1" ]
|
||||
then
|
||||
echo "a=>$a"
|
||||
echo "b=>$b"
|
||||
echo "q=>$q"
|
||||
echo "r=>$r"
|
||||
echo "a1=>$a1"
|
||||
break
|
||||
fi
|
||||
done
|
Loading…
Reference in New Issue
Block a user