aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMITSUNARI Shigeo <herumi@nifty.com>2017-11-27 21:11:44 +0800
committerMITSUNARI Shigeo <herumi@nifty.com>2017-11-27 21:11:44 +0800
commit97b4208ce18bbe00aa74b55e50fc8d07cd14a1c4 (patch)
treed37675745bb7f4607f3481ef3f15e885a72c2b6f
parent6dfc9d153a652aa0ee2884dc2052f480b957816c (diff)
downloadtangerine-mcl-97b4208ce18bbe00aa74b55e50fc8d07cd14a1c4.tar.gz
tangerine-mcl-97b4208ce18bbe00aa74b55e50fc8d07cd14a1c4.tar.zst
tangerine-mcl-97b4208ce18bbe00aa74b55e50fc8d07cd14a1c4.zip
[js] remove exported-mcl.json ; add setInt32 for JS
-rw-r--r--Makefile7
-rw-r--r--ffi/js/pre-mcl.js5
-rw-r--r--include/mcl/bn.h2
-rw-r--r--src/bn_c_impl.hpp9
4 files changed, 17 insertions, 6 deletions
diff --git a/Makefile b/Makefile
index 7d97c39..31bca3f 100644
--- a/Makefile
+++ b/Makefile
@@ -209,10 +209,6 @@ test: $(TEST_EXE)
@sh -ec 'for i in $(TEST_EXE); do $$i|grep "ctest:name"; done' > result.txt
@grep -v "ng=0, exception=0" result.txt; if [ $$? -eq 1 ]; then echo "all unit tests succeed"; else exit 1; fi
-MCL_JSON=docs/demo/exported-mcl.json
-$(MCL_JSON): include/mcl/bn.h
- python ffi/js/export-functions.py -json $^ > $(MCL_JSON)
-
EMCC_OPT=-I./include -I./src -I../cybozulib/include
EMCC_OPT+=-O3 -DNDEBUG -DMCLBN_FP_UNIT_SIZE=4 -DMCL_MAX_BIT_SIZE=256 -DMCLSHE_WIN_SIZE=8
EMCC_OPT+=-s WASM=1 -s DISABLE_EXCEPTION_CATCHING=0 -s NO_EXIT_RUNTIME=1
@@ -228,10 +224,9 @@ docs/demo/she_c.js: $(JS_DEP)
emcc -o $@ src/fp.cpp src/she_c256.cpp $(EMCC_OPT) --pre-js ffi/js/pre.js
cp docs/demo/she.js ../she-wasm/
-../mcl-wasm/mcl_c.js: src/fp.cpp src/bn_c256.cpp $(MCL_JSON)
+../mcl-wasm/mcl_c.js: src/fp.cpp src/bn_c256.cpp
emcc -o $@ src/fp.cpp src/bn_c256.cpp $(EMCC_OPT) --pre-js ffi/js/pre-mcl.js
cp docs/demo/mcl.js ../mcl-wasm/
- cp $(MCL_JSON) ../mcl-wasm/
demo:
$(MAKE) docs/demo/she_c.js
diff --git a/ffi/js/pre-mcl.js b/ffi/js/pre-mcl.js
new file mode 100644
index 0000000..ebc93e5
--- /dev/null
+++ b/ffi/js/pre-mcl.js
@@ -0,0 +1,5 @@
+if (typeof __dirname === 'string') {
+ var Module = {}
+ Module.wasmBinaryFile = __dirname + '/mcl_c.wasm'
+}
+
diff --git a/include/mcl/bn.h b/include/mcl/bn.h
index f57aa34..5aee94c 100644
--- a/include/mcl/bn.h
+++ b/include/mcl/bn.h
@@ -131,6 +131,7 @@ MCLBN_DLL_API void mclBnFr_clear(mclBnFr *x);
// set x to y
MCLBN_DLL_API void mclBnFr_setInt(mclBnFr *y, int64_t x);
+MCLBN_DLL_API void mclBnFr_setInt32(mclBnFr *y, int x);
/*
ioMode
@@ -235,6 +236,7 @@ MCLBN_DLL_API void mclBnG2_mulCT(mclBnG2 *z, const mclBnG2 *x, const mclBnFr *y)
MCLBN_DLL_API void mclBnGT_clear(mclBnGT *x);
// set x to y
MCLBN_DLL_API void mclBnGT_setInt(mclBnGT *y, int64_t x);
+MCLBN_DLL_API void mclBnGT_setInt32(mclBnGT *y, int x);
// return 0 if success
MCLBN_DLL_API int mclBnGT_setStr(mclBnGT *x, const char *buf, size_t bufSize, int ioMode);
diff --git a/src/bn_c_impl.hpp b/src/bn_c_impl.hpp
index 2f6d90d..fee1576 100644
--- a/src/bn_c_impl.hpp
+++ b/src/bn_c_impl.hpp
@@ -174,6 +174,10 @@ void mclBnFr_setInt(mclBnFr *y, int64_t x)
{
*cast(y) = x;
}
+void mclBnFr_setInt32(mclBnFr *y, int x)
+{
+ *cast(y) = x;
+}
int mclBnFr_setStr(mclBnFr *x, const char *buf, size_t bufSize, int ioMode)
{
@@ -425,6 +429,11 @@ void mclBnGT_setInt(mclBnGT *y, int64_t x)
cast(y)->clear();
*(cast(y)->getFp0()) = x;
}
+void mclBnGT_setInt32(mclBnGT *y, int x)
+{
+ cast(y)->clear();
+ *(cast(y)->getFp0()) = x;
+}
int mclBnGT_setStr(mclBnGT *x, const char *buf, size_t bufSize, int ioMode)
{
mmit/accounts/abi/numbers.go?id=aa5b29e2f291322991ceab231267d19b19af72a2'>aa5b29e2f
fe45210c5
dec8bba9d
















fe45210c5
aa5b29e2f
0f9539e1e
aa5b29e2f
5f7826270
aa5b29e2f

aa5b29e2f


aa5b29e2f




1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
                                         
                                                
  
                                                                                  



                                                                              
                                                                             
                                                                 
                                                               


                                                                           
                                                                                  
 





                  
                                                
                                                     

 
     
















                                                     
 
 
                                                    
                              
                                                    

 


                                                                                                  




                                                                                                     
// Copyright 2015 The go-ethereum Authors
// This file is part of the go-ethereum library.
//
// The go-ethereum library is free software: you can redistribute it and/or modify
// it under the terms of the GNU Lesser General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// The go-ethereum library 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 Lesser General Public License for more details.
//
// You should have received a copy of the GNU Lesser General Public License
// along with the go-ethereum library. If not, see <http://www.gnu.org/licenses/>.

package abi

import (
    "math/big"
    "reflect"

    "github.com/ethereum/go-ethereum/common"
    "github.com/ethereum/go-ethereum/common/math"
)

var (
    big_t      = reflect.TypeOf(&big.Int{})
    derefbig_t = reflect.TypeOf(big.Int{})
    uint8_t    = reflect.TypeOf(uint8(0))
    uint16_t   = reflect.TypeOf(uint16(0))
    uint32_t   = reflect.TypeOf(uint32(0))
    uint64_t   = reflect.TypeOf(uint64(0))
    int_t      = reflect.TypeOf(int(0))
    int8_t     = reflect.TypeOf(int8(0))
    int16_t    = reflect.TypeOf(int16(0))
    int32_t    = reflect.TypeOf(int32(0))
    int64_t    = reflect.TypeOf(int64(0))
    address_t  = reflect.TypeOf(common.Address{})
    int_ts     = reflect.TypeOf([]int(nil))
    int8_ts    = reflect.TypeOf([]int8(nil))
    int16_ts   = reflect.TypeOf([]int16(nil))
    int32_ts   = reflect.TypeOf([]int32(nil))
    int64_ts   = reflect.TypeOf([]int64(nil))
)

// U256 converts a big Int into a 256bit EVM number.
func U256(n *big.Int) []byte {
    return math.PaddedBigBytes(math.U256(n), 32)
}

// checks whether the given reflect value is signed. This also works for slices with a number type
func isSigned(v reflect.Value) bool {
    switch v.Type() {
    case int_ts, int8_ts, int16_ts, int32_ts, int64_ts, int_t, int8_t, int16_t, int32_t, int64_t:
        return true
    }
    return false
}