From 05350f1888d28ae08105ed278e80b6de790c3e30 Mon Sep 17 00:00:00 2001 From: Aleksandr Kuzmenko Date: Mon, 9 Aug 2021 18:36:34 +0300 Subject: [PATCH 1/3] I64 --- CMakeLists.txt | 3 +- Makefile | 2 +- src/std/num.c | 114 +++++++++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 117 insertions(+), 2 deletions(-) create mode 100644 src/std/num.c diff --git a/CMakeLists.txt b/CMakeLists.txt index 01c00142e..0b72fe4dc 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -79,6 +79,7 @@ file(GLOB std_srcs src/std/ucs2.c src/std/thread.c src/std/process.c + src/std/num.c ) if(CMAKE_SYSTEM_NAME MATCHES "Darwin") @@ -157,7 +158,7 @@ endif() if(BUILD_TESTING) find_program( - HAXE_COMPILER + HAXE_COMPILERs haxe ) diff --git a/Makefile b/Makefile index 50dfb4d27..28de81d19 100644 --- a/Makefile +++ b/Makefile @@ -27,7 +27,7 @@ RUNTIME = src/gc.o STD = src/std/array.o src/std/buffer.o src/std/bytes.o src/std/cast.o src/std/date.o src/std/error.o src/std/debug.o \ src/std/file.o src/std/fun.o src/std/maps.o src/std/math.o src/std/obj.o src/std/random.o src/std/regexp.o \ src/std/socket.o src/std/string.o src/std/sys.o src/std/types.o src/std/ucs2.o src/std/thread.o src/std/process.o \ - src/std/track.o + src/std/track.o src/std/num.o HL = src/code.o src/jit.o src/main.o src/module.o src/debugger.o src/profile.o diff --git a/src/std/num.c b/src/std/num.c new file mode 100644 index 000000000..9d1fa2eb0 --- /dev/null +++ b/src/std/num.c @@ -0,0 +1,114 @@ +#include +#include +#include + +// I64 + +HL_PRIM int64 hl_num_i64_of_int( int i ) { + return i; +} +DEFINE_PRIM(_I64, num_i64_of_int, _I32); + +HL_PRIM int64 hl_num_i64_max() { + return LLONG_MAX; +} +DEFINE_PRIM(_I64, num_i64_max, _NO_ARG); + +HL_PRIM int64 hl_num_i64_min() { + return LLONG_MIN; +} +DEFINE_PRIM(_I64, num_i64_min, _NO_ARG); + +HL_PRIM int64 hl_num_i64_of_string( vstring *s ) { + if( !s ) + hl_null_access(); + return strtoll(hl_to_utf8(s->bytes), NULL, 10); +} +DEFINE_PRIM(_I64, num_i64_of_string, _STRING); + +HL_PRIM vbyte *hl_num_i64_to_bytes( int64 i ) { + char buf[20]; + int length = sprintf(buf, "%lld", i); + return hl_copy_bytes((vbyte *)buf, length); +} +DEFINE_PRIM(_BYTES, num_i64_to_bytes, _I64); + +HL_PRIM int64 hl_num_i64_add( int64 a, int64 b ) { + return a + b; +} +DEFINE_PRIM(_I64, num_i64_add, _I64 _I64); + +HL_PRIM int64 hl_num_i64_sub( int64 a, int64 b ) { + return a - b; +} +DEFINE_PRIM(_I64, num_i64_sub, _I64 _I64); + +HL_PRIM int64 hl_num_i64_mul( int64 a, int64 b ) { + return a * b; +} +DEFINE_PRIM(_I64, num_i64_mul, _I64 _I64); + +HL_PRIM int64 hl_num_i64_mod( int64 a, int64 b ) { + return a % b; +} +DEFINE_PRIM(_I64, num_i64_mod, _I64 _I64); + +HL_PRIM int64 hl_num_i64_div( int64 a, int64 b ) { + return a / b; +} +DEFINE_PRIM(_I64, num_i64_div, _I64 _I64); + +HL_PRIM int64 hl_num_i64_logand( int64 a, int64 b ) { + return a & b; +} +DEFINE_PRIM(_I64, num_i64_logand, _I64 _I64); + +HL_PRIM int64 hl_num_i64_logor( int64 a, int64 b ) { + return a | b; +} +DEFINE_PRIM(_I64, num_i64_logor, _I64 _I64); + +HL_PRIM int64 hl_num_i64_logxor( int64 a, int64 b ) { + return a ^ b; +} +DEFINE_PRIM(_I64, num_i64_logxor, _I64 _I64); + +HL_PRIM int64 hl_num_i64_shift_left( int64 a, int b ) { + return a << b; +} +DEFINE_PRIM(_I64, num_i64_shift_left, _I64 _I32); + +HL_PRIM int64 hl_num_i64_shift_right( int64 a, int b ) { + return a >> b; +} +DEFINE_PRIM(_I64, num_i64_shift_right, _I64 _I32); + +HL_PRIM int64 hl_num_i64_lognot( int64 a ) { + return ~a; +} +DEFINE_PRIM(_I64, num_i64_lognot, _I64); + +HL_PRIM bool hl_num_i64_eq( int64 a, int64 b ) { + return a == b; +} +DEFINE_PRIM(_BOOL, num_i64_eq, _I64 _I64); + +HL_PRIM bool hl_num_i64_lt( int64 a, int64 b ) { + return a < b; +} +DEFINE_PRIM(_BOOL, num_i64_lt, _I64 _I64); + +HL_PRIM bool hl_num_i64_gt( int64 a, int64 b ) { + return a > b; +} +DEFINE_PRIM(_BOOL, num_i64_gt, _I64 _I64); + +HL_PRIM bool hl_num_i64_lte( int64 a, int64 b ) { + return a <= b; +} +DEFINE_PRIM(_BOOL, num_i64_lte, _I64 _I64); + +HL_PRIM bool hl_num_i64_gte( int64 a, int64 b ) { + return a >= b; +} +DEFINE_PRIM(_BOOL, num_i64_gte, _I64 _I64); \ No newline at end of file From d93ef7baf34affdfd565aaef18c33f6535830caa Mon Sep 17 00:00:00 2001 From: Aleksandr Kuzmenko Date: Mon, 9 Aug 2021 18:57:52 +0300 Subject: [PATCH 2/3] handle long long in ucs2.uvszprintf --- src/std/num.c | 7 ------- src/std/ucs2.c | 12 ++++++++++-- 2 files changed, 10 insertions(+), 9 deletions(-) diff --git a/src/std/num.c b/src/std/num.c index 9d1fa2eb0..33805b645 100644 --- a/src/std/num.c +++ b/src/std/num.c @@ -26,13 +26,6 @@ HL_PRIM int64 hl_num_i64_of_string( vstring *s ) { } DEFINE_PRIM(_I64, num_i64_of_string, _STRING); -HL_PRIM vbyte *hl_num_i64_to_bytes( int64 i ) { - char buf[20]; - int length = sprintf(buf, "%lld", i); - return hl_copy_bytes((vbyte *)buf, length); -} -DEFINE_PRIM(_BYTES, num_i64_to_bytes, _I64); - HL_PRIM int64 hl_num_i64_add( int64 a, int64 b ) { return a + b; } diff --git a/src/std/ucs2.c b/src/std/ucs2.c index b009801dc..d34667231 100644 --- a/src/std/ucs2.c +++ b/src/std/ucs2.c @@ -105,7 +105,7 @@ int utoi( const uchar *str, uchar **end ) { int ucmp( const uchar *a, const uchar *b ) { while(true) { - int d = (unsigned)*a - (unsigned)*b; + int d = (unsigned)*a - (unsigned)*b; if( d ) return d; if( !*a ) return 0; a++; @@ -202,7 +202,15 @@ HL_PRIM int uvszprintf( uchar *out, int out_size, const uchar *fmt, va_list argl switch( c ) { case 'd': cfmt[i++] = 0; - size = sprintf(tmp,cfmt,va_arg(arglist,int)); + if( cfmt[i - 3] == 'l') { + if( cfmt[i - 4] == 'l' ) { + size = sprintf(tmp,cfmt,va_arg(arglist,long long)); + } else { + size = sprintf(tmp,cfmt,va_arg(arglist,long)); + } + } else { + size = sprintf(tmp,cfmt,va_arg(arglist,int)); + } goto sprintf_add; case 'f': cfmt[i++] = 0; From 1f1e2b0cf07abcef65e1d4f609751214e2ed209b Mon Sep 17 00:00:00 2001 From: Aleksandr Kuzmenko Date: Mon, 9 Aug 2021 20:34:01 +0300 Subject: [PATCH 3/3] typo --- CMakeLists.txt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 0b72fe4dc..88a3109ad 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -158,7 +158,7 @@ endif() if(BUILD_TESTING) find_program( - HAXE_COMPILERs + HAXE_COMPILER haxe )