Moved safe int functions into their own file that's not automatically loaded.

This commit is contained in:
Erik Svedäng 2018-03-06 16:44:07 +01:00
parent a6f0db8675
commit 4c8b661bdc
5 changed files with 15 additions and 12 deletions

View File

@ -18,12 +18,7 @@
(register bit-not (λ [Int] Int))
(register inc (λ [Int] Int))
(register dec (λ [Int] Int))
(register copy (λ [&Int] Int)) ;; TODO: Should not be needed when refs to value types are auto-converted to non-refs.
(not-on-windows
(register safe-add (λ [Int Int (Ref Int)] Bool))
(register safe-sub (λ [Int Int (Ref Int)] Bool))
(register safe-mul (λ [Int Int (Ref Int)] Bool)))
(register copy (λ [&Int] Int))
(register abs (λ [Int] Int))

7
core/SafeInt.carp Normal file
View File

@ -0,0 +1,7 @@
(system-include "carp_safe_int.h")
(defmodule Int
(register safe-add (λ [Int Int (Ref Int)] Bool))
(register safe-sub (λ [Int Int (Ref Int)] Bool))
(register safe-mul (λ [Int Int (Ref Int)] Bool))
)

View File

@ -5,11 +5,6 @@ int Int__PLUS_(int x, int y) { return x + y; }
int Int__MINUS_(int x, int y) { return x - y; }
int Int__MUL_(int x, int y) { return x * y; }
int Int__DIV_(int x, int y) { return x / y; }
#ifndef _WIN32
bool Int_safe_MINUS_add(int x, int y, int* res) { return __builtin_sadd_overflow(x, y, res); }
bool Int_safe_MINUS_sub(int x, int y, int* res) { return __builtin_ssub_overflow(x, y, res); }
bool Int_safe_MINUS_mul(int x, int y, int* res) { return __builtin_smul_overflow(x, y, res); }
#endif
bool Int__EQ_(int x, int y) { return x == y; }
bool Int__DIV__EQ_(int x, int y) { return x != y; }
bool Int__LT_(int x, int y) { return x < y; }
@ -34,4 +29,3 @@ int Int_mod(int x, int divider) {
bool Int_mask(int a, int b) {
return a & b;
}

6
core/carp_safe_int.h Normal file
View File

@ -0,0 +1,6 @@
#include <math.h>
#include <stdbool.h>
bool Int_safe_MINUS_add(int x, int y, int* res) { return __builtin_sadd_overflow(x, y, res); }
bool Int_safe_MINUS_sub(int x, int y, int* res) { return __builtin_ssub_overflow(x, y, res); }
bool Int_safe_MINUS_mul(int x, int y, int* res) { return __builtin_smul_overflow(x, y, res); }

View File

@ -1,4 +1,5 @@
(load "Test.carp")
(load "SafeInt.carp")
(use-all Bool Int Long Test)