Skip to content

Commit d6008d0

Browse files
committed
Misc fixes to the C_MODE + refactors
1 parent 4aee0c1 commit d6008d0

File tree

8 files changed

+195
-147
lines changed

8 files changed

+195
-147
lines changed

bin/autotest.rs

Lines changed: 64 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,55 @@
11
#!/usr/bin/env -S cargo +nightly -Zscript
22
use core::str;
33
use std::collections::HashSet;
4-
4+
#[macro_export]
5+
macro_rules! config {
6+
($name:ident,bool,$default:expr) => {
7+
pub static $name: std::sync::LazyLock<bool> = std::sync::LazyLock::new(|| {
8+
std::env::vars()
9+
.find_map(|(key, value)| {
10+
if key == stringify!($name) {
11+
Some(value)
12+
} else {
13+
None
14+
}
15+
})
16+
.map(|value| match value.as_ref() {
17+
"0" | "false" | "False" | "FALSE" => false,
18+
"1" | "true" | "True" | "TRUE" => true,
19+
_ => panic!(
20+
"Boolean enviroment variable {} has invalid value {}",
21+
stringify!($name),
22+
value
23+
),
24+
})
25+
.unwrap_or($default)
26+
});
27+
};
28+
($name:ident,bool,$default:expr,$comment:literal) => {
29+
#[doc = $comment]
30+
pub static $name: std::sync::LazyLock<bool> = std::sync::LazyLock::new(|| {
31+
std::env::vars()
32+
.find_map(|(key, value)| {
33+
if key == stringify!($name) {
34+
Some(value)
35+
} else {
36+
None
37+
}
38+
})
39+
.map(|value| match value.as_ref() {
40+
"0" | "false" | "False" | "FALSE" => false,
41+
"1" | "true" | "True" | "TRUE" => true,
42+
_ => panic!(
43+
"Boolean enviroment variable {} has invalid value {}",
44+
stringify!($name),
45+
value
46+
),
47+
})
48+
.unwrap_or($default)
49+
});
50+
};
51+
}
52+
config!(C_MODE, bool, false);
553
fn main() {
654
let exec_path = std::env::args().nth(1).unwrap();
755
let mut ok: HashSet<String> = HashSet::default();
@@ -14,7 +62,10 @@ fn main() {
1462
cmd.arg("-k");
1563
cmd.arg(&timeout);
1664
cmd.arg(&timeout);
17-
cmd.arg("dotnet");
65+
if !*C_MODE {
66+
cmd.arg("dotnet");
67+
}
68+
1869
cmd.arg(exec_path.clone());
1970
if shuffles > 0 {
2071
cmd.arg("--shuffle");
@@ -81,10 +132,17 @@ fn main() {
81132
println!("{faliure}");
82133
}
83134
println!("COMMAND:");
84-
let mut cmd = std::process::Command::new("dotnet");
85-
cmd.arg(exec_path.clone());
86-
cmd.args(broken.iter().flat_map(|arg| ["--skip", arg]));
87-
println!("{cmd:?}");
135+
if *C_MODE {
136+
let mut cmd = std::process::Command::new(exec_path.clone());
137+
138+
cmd.args(broken.iter().flat_map(|arg| ["--skip", arg]));
139+
println!("{cmd:?}");
140+
} else {
141+
let mut cmd = std::process::Command::new("dotnet");
142+
cmd.arg(exec_path.clone());
143+
cmd.args(broken.iter().flat_map(|arg| ["--skip", arg]));
144+
println!("{cmd:?}");
145+
}
88146
println!(
89147
"\nsearch result: ok:{ok}, failures:{failures} broken:{broken}",
90148
ok = ok.len(),

cilly/src/v2/c_exporter/c_header.h

Lines changed: 52 additions & 90 deletions
Original file line numberDiff line numberDiff line change
@@ -6,37 +6,26 @@
66
#include <string.h>
77
#include <math.h>
88
#include <mm_malloc.h>
9+
10+
#include <alloca.h>
11+
912
/*
1013
#include <unistd.h>
1114
#include <sys/uio.h>
1215
#include <poll.h>
1316
#include <sched.h>
1417
#include "threads.h"*/
15-
#ifdef __STDC_VERSION__
16-
17-
#else
18-
#error "C version too old(< C99), and unsuported"
18+
#ifndef __SIZEOF_INT128__
19+
#define __int128 long long
1920
#endif
20-
2121
#define eprintf(...) fprintf(stderr, __VA_ARGS__)
22-
union System_Collections_IDictionary
23-
{
24-
};
25-
union System_Collections_IDictionaryEnumerator
26-
{
27-
};
28-
union System_Collections_DictionaryEntry
29-
{
30-
};
31-
union System_String
32-
{
33-
};
22+
3423
int execvp(void *file, void *argv);
3524
#define System_Runtime_InteropServices_Marshal_AllocHGlobali4is(size) malloc(size)
3625
#define System_Runtime_InteropServices_Marshal_AllocHGlobalisis(size) malloc(size)
3726
#define System_Runtime_InteropServices_Marshal_ReAllocHGlobalisisis(ptr, new_size) realloc(ptr, new_size)
3827
#define System_Runtime_InteropServices_Marshal_FreeHGlobalisv(ptr) free(ptr)
39-
#define System_Collections_ICollection_get_Count14System_Runtime30System_Collections_IDictionaryi4(dict) 0
28+
4029
#define System_Runtime_InteropServices_NativeMemory_AlignedAllocususpv(size, align) aligned_alloc(align, size)
4130
#define System_Runtime_InteropServices_NativeMemory_AlignedFreepvv free
4231
void *System_Runtime_InteropServices_NativeMemory_AlignedReallocpvususpv(void *ptr, uintptr_t size, uintptr_t align)
@@ -47,17 +36,12 @@ void *System_Runtime_InteropServices_NativeMemory_AlignedReallocpvususpv(void *p
4736
return new_buff;
4837
}
4938

50-
#define System_Collections_IEnumerator_MoveNext14System_Runtime40System_Collections_IDictionaryEnumeratorb(arg) false
51-
5239
#define System_UInt128_op_Additionu16u16u16(lhs, rhs) (lhs + rhs)
5340
#define System_Int128_op_Additioni16i16i16(lhs, rhs) (__int128)((unsigned __int128)lhs + (unsigned __int128)rhs)
5441

5542
#define System_UInt128_op_Subtractionu16u16u16(lhs, rhs) (lhs - rhs)
5643
#define System_Int128_op_Subtractioni16i16i16(lhs, rhs) (__int128)((unsigned __int128)lhs - (unsigned __int128)rhs)
5744

58-
#define System_UInt128_op_Equalityu16u16b(lhs, rhs) (lhs == rhs)
59-
#define System_Int128_op_Equalityi16i16b(lhs, rhs) (lhs == rhs)
60-
6145
#define System_Int128_op_LessThani16i16b(lhs, rhs) (lhs < rhs)
6246
#define System_UInt128_op_LessThanu16u16b(lhs, rhs) (lhs < rhs)
6347

@@ -158,8 +142,8 @@ void *System_Runtime_InteropServices_NativeMemory_AlignedReallocpvususpv(void *p
158142
#define System_Buffers_Binary_BinaryPrimitives_ReverseEndiannessi4i4(val) (int32_t) __builtin_bswap32((uint32_t)val)
159143
#define System_Buffers_Binary_BinaryPrimitives_ReverseEndiannessu2u2 __builtin_bswap16
160144
#define System_Buffers_Binary_BinaryPrimitives_ReverseEndiannessi2i2(val) (int16_t) __builtin_bswap16((uint16_t)val)
161-
// Assumes a 64 bit OS.
162-
#define System_Buffers_Binary_BinaryPrimitives_ReverseEndiannessisis(val) (intptr_t) __builtin_bswap64((ulong)val)
145+
/*Assumes a 64 bit OS.*/
146+
#define System_Buffers_Binary_BinaryPrimitives_ReverseEndiannessisis(val) (intptr_t) __builtin_bswap64((uint64_t)val)
163147
#define System_Buffers_Binary_BinaryPrimitives_ReverseEndiannessusus __builtin_bswap64
164148

165149
#define System_Numerics_BitOperations_TrailingZeroCountusi4(val) (int32_t) __builtin_ctzl((uint64_t)val)
@@ -172,51 +156,27 @@ int32_t System_Numerics_BitOperations_LeadingZeroCountusi4(uintptr_t val) { retu
172156
#define System_Numerics_BitOperations_PopCountu4i4(val) __builtin_popcountl((uint32_t)val)
173157
#define System_Numerics_BitOperations_PopCountu8i4(val) __builtin_popcountl((uint64_t)val)
174158

175-
union System_Collections_IDictionary System_Environment_GetEnvironmentVariables14System_Runtime30System_Collections_IDictionary()
176-
{
177-
union System_Collections_IDictionary res;
178-
return res;
179-
};
180-
union System_Collections_IDictionaryEnumerator System_Collections_IDictionary_GetEnumerator14System_Runtime30System_Collections_IDictionary14System_Runtime40System_Collections_IDictionaryEnumerator(union System_Collections_IDictionary dict)
181-
{
182-
union System_Collections_IDictionaryEnumerator res;
183-
return res;
184-
}
185-
union System_Collections_DictionaryEntry System_Collections_IEnumerator_get_Current14System_Runtime40System_Collections_IDictionaryEnumeratoro(union System_Collections_IDictionaryEnumerator dict)
186-
{
187-
union System_Collections_DictionaryEntry res;
188-
return res;
189-
}
190-
union System_String System_String_Concat_()
191-
{
192-
union System_String res;
193-
return res;
194-
}
195-
const char *System_Runtime_InteropServices_Marshal_StringToCoTaskMemUTF8sis(union System_String str)
196-
{
197-
char *res = (char *)malloc(1);
198-
res[0] = '\0';
199-
return res;
200-
}
201-
void System_Console_WriteLineu8v(ulong arg)
159+
#define System_Console_WriteLinestv(msg) printf("%s", msg)
160+
#define System_String_Concatststst(a, b) a b
161+
#define System_String_Concatstststst(a, b, c) a b c
162+
#define System_String_Concatststststst(a, b, c, d) a b c d
163+
void System_Console_WriteLineu8v(uint64_t arg)
202164
{
203165
printf("%lu\n", arg);
204166
}
205-
void System_Console_WriteLinei8v(long arg)
167+
void System_Console_WriteLinei8v(int64_t arg)
206168
{
207169
printf("%ld\n", arg);
208170
}
209-
void System_Console_WriteLineu4v(uint arg)
171+
void System_Console_WriteLineu4v(uint32_t arg)
210172
{
211173
printf("%u\n", arg);
212174
}
213-
void System_Console_WriteLinei4v(int arg)
175+
void System_Console_WriteLinei4v(int32_t arg)
214176
{
215177
printf("%u\n", arg);
216178
}
217179

218-
#define System_String_Concatooos(...) System_String_Concat_()
219-
220180
#define System_UIntPtr_get_MaxValueus() UINTPTR_MAX
221181
#define System_UIntPtr_get_MinValueus() ((uintptr_t)0)
222182

@@ -279,16 +239,36 @@ float System_Single_FusedMultiplyAddf4f4f4f4(float left, float right, float adde
279239
float System_Single_CopySignf4f4f4(float mag, float sign)
280240
{
281241
if (sign > 0)
282-
return fabs(mag);
242+
{
243+
if (mag > 0)
244+
return mag;
245+
else
246+
return -mag;
247+
}
283248
else
284-
return -fabs(mag);
249+
{
250+
if (mag > 0)
251+
return -mag;
252+
else
253+
return mag;
254+
}
285255
}
286256
double System_Double_CopySignf8f8f8(double mag, double sign)
287257
{
288258
if (sign > 0)
289-
return fabs(mag);
259+
{
260+
if (mag > 0)
261+
return mag;
262+
else
263+
return -mag;
264+
}
290265
else
291-
return -fabs(mag);
266+
{
267+
if (mag > 0)
268+
return -mag;
269+
else
270+
return mag;
271+
}
292272
}
293273
float System_MathF_Truncatef4f4(float val)
294274
{
@@ -316,7 +296,7 @@ double fabsf64(double val);
316296
typedef struct TSWData
317297
{
318298
void *start_routine;
319-
void *arg
299+
void *arg;
320300
} TSWData;
321301
void _tcctor();
322302
void *thread_start_wrapper(TSWData *data)
@@ -367,36 +347,18 @@ float System_Single_Log10f4f4(float input)
367347
abort();
368348
return 0.0f;
369349
}
370-
float System_Math_Floorf8f8(float input)
371-
{
372-
fprintf(stderr, "Can't System_Math_Floorf8f8 yet.\n");
373-
abort();
374-
return 0.0f;
375-
}
376-
double System_Math_Sqrtf8f8(double input)
377-
{
378-
fprintf(stderr, "Can't System_Math_Sqrtf8f8 yet.\n");
379-
abort();
380-
return 0.0f;
381-
}
350+
#define System_Math_Floorf8f8(input) floor(input)
351+
#define System_Math_Sqrtf8f8(input) sqrt(input)
352+
382353
double System_Double_Log10f8f8(double input)
383354
{
384355
fprintf(stderr, "Can't System_Double_Log10f8f8 yet.\n");
385356
abort();
386357
return 0.0f;
387358
}
388-
double System_Math_Ceilingf8f8(double input)
389-
{
390-
fprintf(stderr, "Can't System_Math_Ceilingf8f8 yet.\n");
391-
abort();
392-
return 0.0f;
393-
}
394-
double System_Math_Truncatef8f8(double input)
395-
{
396-
fprintf(stderr, "Can't System_Math_Truncatef8f8 yet.\n");
397-
abort();
398-
return 0.0f;
399-
}
359+
#define System_Math_Ceilingf8f8(input) celi(input)
360+
#define System_Math_Truncatef8f8(input) trunc(input)
361+
400362
uint32_t System_UInt32_RotateRightu4i4u4(uint32_t val, int32_t ammount)
401363
{
402364
fprintf(stderr, "Can't System_UInt32_RotateRightu4i4u4 yet.\n");
@@ -418,7 +380,7 @@ uint32_t System_Threading_Interlocked_CompareExchangeru4u4u4u4(uint32_t *addr, u
418380
}
419381
else
420382
{
421-
// On failure, value is written to comparand.
383+
/* On failure, value is written to comparand. */
422384
return comparand;
423385
}
424386
}
@@ -431,7 +393,7 @@ uint64_t System_Threading_Interlocked_CompareExchangeru8u8u8u8(uint64_t *addr, u
431393
}
432394
else
433395
{
434-
// On failure, value is written to comparand.
396+
/* On failure, value is written to comparand. */
435397
return comparand;
436398
}
437399
}
@@ -444,7 +406,7 @@ uintptr_t System_Threading_Interlocked_CompareExchangerusususus(uintptr_t *addr,
444406
}
445407
else
446408
{
447-
// On failure, value is written to comparand.
409+
/* On failure, value is written to comparand. */
448410
return comparand;
449411
}
450412
}
@@ -457,7 +419,7 @@ intptr_t System_Threading_Interlocked_CompareExchangerisisisis(intptr_t *addr, i
457419
}
458420
else
459421
{
460-
// On failure, value is written to comparand.
422+
/* On failure, value is written to comparand. */
461423
return comparand;
462424
}
463425
}

0 commit comments

Comments
 (0)