mirror of
https://github.com/carp-lang/Carp.git
synced 2024-10-26 13:51:50 +03:00
Moved safe int functions into their own file that's not automatically loaded.
This commit is contained in:
parent
a6f0db8675
commit
4c8b661bdc
@ -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
7
core/SafeInt.carp
Normal 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))
|
||||
)
|
@ -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
6
core/carp_safe_int.h
Normal 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); }
|
@ -1,4 +1,5 @@
|
||||
(load "Test.carp")
|
||||
(load "SafeInt.carp")
|
||||
|
||||
(use-all Bool Int Long Test)
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user