Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

I64 implementation #465

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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")
Expand Down Expand Up @@ -157,7 +158,7 @@ endif()
if(BUILD_TESTING)

find_program(
HAXE_COMPILER
HAXE_COMPILERs
RealyUniqueName marked this conversation as resolved.
Show resolved Hide resolved
haxe
)

Expand Down
2 changes: 1 addition & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
107 changes: 107 additions & 0 deletions src/std/num.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,107 @@
#include <hl.h>
#include <limits.h>
#include <inttypes.h>

// 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 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);
12 changes: 10 additions & 2 deletions src/std/ucs2.c
Original file line number Diff line number Diff line change
Expand Up @@ -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++;
Expand Down Expand Up @@ -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;
Expand Down