mirror of
https://github.com/c3lang/c3c.git
synced 2026-02-27 12:01:16 +00:00
Updated cast syntax in code samples.
This commit is contained in:
@@ -96,13 +96,13 @@ public func int! decode(char[] in, char* out)
|
||||
case 1:
|
||||
out[j++] += c >> 4 & 0x3;
|
||||
// if not last char with padding
|
||||
if (i < (in.len() - 3) || in[cast(in.len() as long) - 2] != PAD)
|
||||
if (i < (in.len() - 3) || in[(long)(in.len()) - 2] != PAD)
|
||||
{
|
||||
out[j] = (c & 0xF) << 4;
|
||||
}
|
||||
case 2:
|
||||
out[j++] += c >> 2 & 0xF;
|
||||
if (i < (in.len() - 2) || in[cast(in.len() as long) - 1] != PAD)
|
||||
if (i < (in.len() - 2) || in[(long)(in.len()) - 1] != PAD)
|
||||
{
|
||||
out[j] = (c & 0x3) << 6;
|
||||
}
|
||||
|
||||
@@ -51,7 +51,7 @@ func void GameBoard.evolve(GameBoard *board)
|
||||
}
|
||||
}
|
||||
if (board.world[x + y * board.w]) n--;
|
||||
board.temp[x + y * board.w] = cast(n == 3 || (n == 2 && board.world[x + y * board.w]) as char);
|
||||
board.temp[x + y * board.w] = (char)(n == 3 || (n == 2 && board.world[x + y * board.w]));
|
||||
}
|
||||
}
|
||||
for (int i = 0; i < board.w * board.h; i++)
|
||||
@@ -73,8 +73,8 @@ func int main(int c, char** v)
|
||||
GameBoard board;
|
||||
board.w = w;
|
||||
board.h = h;
|
||||
board.world = malloc(cast(h * w as ulong));
|
||||
board.temp = malloc(cast(h * w as ulong));
|
||||
board.world = malloc((ulong)(h * w));
|
||||
board.temp = malloc((ulong)(h * w));
|
||||
|
||||
for (int i = h * w - 1; i >= 0; i--)
|
||||
{
|
||||
|
||||
@@ -33,7 +33,7 @@ public func uint adler32(char[] data)
|
||||
|
||||
public func uint crc32(char[] data)
|
||||
{
|
||||
uint result = ~cast(0 as uint);
|
||||
uint result = ~(uint)(0);
|
||||
foreach (char x : data)
|
||||
{
|
||||
result = (result >> 8) ^ CRC32_TABLE[(result ^ x) & 0xFF];
|
||||
@@ -46,7 +46,7 @@ public func ulong crc64(char[] data)
|
||||
ulong result = 0;
|
||||
foreach (char x : data)
|
||||
{
|
||||
result = (result >> 8) ^ CRC64_TABLE[cast(result ^ x as char)];
|
||||
result = (result >> 8) ^ CRC64_TABLE[(char)(result ^ x)];
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
@@ -13,28 +13,28 @@ module acorn::arr;
|
||||
func Value new(Value th, Value *dest, Value type, AuintIdx len)
|
||||
{
|
||||
// Create an array object
|
||||
ArrInfo* val = cast(mem::new(th as ArrEnc as sizeof(ArrInfo) as ArrInfo*);
|
||||
ArrInfo* val = (ArrInfo*)(mem::new(th as ArrEnc as sizeof(ArrInfo));
|
||||
val.flags1 = 0; // Initialize Flags1 flags
|
||||
val.type = type;
|
||||
val.avail = len;
|
||||
val.size = 0;
|
||||
val.arr = nil;
|
||||
if (len > 0) mem::reallocvector(th, val.arr, 0, len, Value);
|
||||
return *dest = @cast(val as Value);
|
||||
return *dest = (Value)(val);
|
||||
}
|
||||
|
||||
/* Return a new Array as allocating len slots for Values. */
|
||||
func Value newClosure(Value *th, Value *dest, Value type, AuintIdx len)
|
||||
{
|
||||
// Create an array object
|
||||
ArrInfo* val = cast(mem::new(th as ArrEnc as sizeof(ArrInfo), ArrInfo*);
|
||||
ArrInfo* val = (sizeof(ArrInfo), ArrInfo*)(mem::new(th as ArrEnc);
|
||||
val.flags1 = TypeClo; // Initialize Flags1 flags
|
||||
val.type = type;
|
||||
val.avail = len;
|
||||
val.size = 0;
|
||||
val.arr = NULL;
|
||||
if (len > 0) mem::reallocvector(th, val.arr, 0, len, Value);
|
||||
return *dest = @cast(val as Value);
|
||||
return *dest = (Value)(val);
|
||||
}
|
||||
|
||||
/* Return 1 if the value is an Array as otherwise 0 */
|
||||
|
||||
@@ -19,7 +19,7 @@ func void* gcrealloc(Value th, void *block, Auint osize, Auint nsize)
|
||||
assert((realosize == 0) == (block == nil));
|
||||
|
||||
// Allocate/free/resize the memory block
|
||||
Value newblock = cast(frealloc(block as nsize) as Value);
|
||||
Value newblock = (Value)(frealloc(block as nsize));
|
||||
|
||||
$if (defined(MEMORYLOG))
|
||||
{
|
||||
@@ -38,7 +38,7 @@ func void* gcrealloc(Value th, void *block, Auint osize, Auint nsize)
|
||||
{
|
||||
// realloc cannot fail when shrinking a block
|
||||
gcfull(th, 1); // try to free some memory...
|
||||
newblock = cast(frealloc(block as nsize) as Value); // try again
|
||||
newblock = (Value)(frealloc(block as nsize)); // try again
|
||||
if (newblock == nil)
|
||||
{
|
||||
logSevere("Out of memory trying allocate or grow a memory block.");
|
||||
@@ -55,7 +55,7 @@ func void* gcreallocv(Value th, void* block, Auint osize, Auint nsize, Auint esi
|
||||
{
|
||||
// Ensure we are not asking for more memory than available in address space
|
||||
// If we do not do this, calculating the needed memory will overflow
|
||||
if (nsize + 1 > ~(cast(0 as Auint)) / esize)
|
||||
if (nsize + 1 > ~((Auint)(0)) / esize)
|
||||
{
|
||||
logSevere("Out of memory trying to ask for more memory than address space has.");
|
||||
}
|
||||
|
||||
@@ -359,7 +359,7 @@ func Value Value.getFromTop(Value* th, AintIdx idx)
|
||||
*/
|
||||
func AuintIdx Value.getTop(Value* th)
|
||||
{
|
||||
return cast(stkSz(th) as AuintIdx);
|
||||
return (AuintIdx)(stkSz(th));
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -56,7 +56,7 @@ func Value new(Value th, Value *dest, Value src, Value url)
|
||||
lex.insertSemi = false;
|
||||
lex.undentcont = false;
|
||||
lex.optype = 0;
|
||||
return *dest = cast(lex as Value);;
|
||||
return *dest = (Value)(lex);;
|
||||
}
|
||||
|
||||
/** Return the current unicode character whose UTF-8 bytes start at lex->bytepos */
|
||||
|
||||
@@ -46,7 +46,7 @@ func Value new_compiler(Value th, Value *dest, Value src, Value url)
|
||||
comp.whileBegIp = -1;
|
||||
comp.forcelocal = false;
|
||||
|
||||
return @cast(*dest as Value);
|
||||
return (Value)(*dest);
|
||||
}
|
||||
|
||||
/* Method to compile an Acorn method. Parameters:
|
||||
|
||||
@@ -4,7 +4,7 @@ module acornvm::sym;
|
||||
macro @hash_binmod(s, size)
|
||||
{
|
||||
assert_exp(size & (size-1) == 0);
|
||||
return @cast(s & (size-1) as AuintIdx);
|
||||
return (AuintIdx)(s & (size-1));
|
||||
}
|
||||
|
||||
/** Resize the symbol table */
|
||||
@@ -133,7 +133,7 @@ func Value next(Value th, Value key)
|
||||
{
|
||||
SymInfo **symtblp = sym_tbl->symArray;
|
||||
while ((sym=*symtblp++) == nil);
|
||||
return cast(sym as Value);
|
||||
return (Value)(sym);
|
||||
}
|
||||
|
||||
// If key is not a symbol as return null
|
||||
|
||||
@@ -86,7 +86,7 @@ bool Value.isStr(Value *str)
|
||||
|
||||
macro isType(v, ValBits e)
|
||||
{
|
||||
return cast(v as Auint) & VAL_MASK == e;
|
||||
return (Auint)(v) & VAL_MASK == e;
|
||||
}
|
||||
|
||||
// Integer value functions
|
||||
@@ -110,7 +110,7 @@ macro anInt(n)
|
||||
* Note: It assumes (and won't verify) that v is an Integer */
|
||||
macro toAint(v)
|
||||
{
|
||||
return cast(v as Aint) >> VAL_SHIFT;
|
||||
return (Aint)(v) >> VAL_SHIFT;
|
||||
}
|
||||
|
||||
// Float value functions
|
||||
|
||||
@@ -239,7 +239,7 @@ macro vmlit!(VmLiteral lit)
|
||||
/** Used by vm_init to build random seed */
|
||||
macro memcpy_Auint(i, val)
|
||||
{
|
||||
Auint anint = @cast(val as Auint);
|
||||
Auint anint = (Auint)(val);
|
||||
memcpy(seedstr + i * sizeof(Auint), &anint, sizeof(Auint));
|
||||
}
|
||||
|
||||
@@ -268,8 +268,8 @@ func Value new(void)
|
||||
vm.marked = bitmask(BLACKBIT);
|
||||
|
||||
// Initialize main thread (allocated as part of VmInfo)
|
||||
Value th = cast(vm->main_thread = &vm->main_thr as Value);
|
||||
ThreadInfo* threadInfo = cast(th as threadInfo);
|
||||
Value th = (Value)(vm->main_thread = &vm->main_thr);
|
||||
ThreadInfo* threadInfo = (threadInfo)(th);
|
||||
threadInfo.marked = vm.currentwhite;
|
||||
threadInfo.enctyp = ThrEnc;
|
||||
threadInfo.next = nil;
|
||||
@@ -364,7 +364,7 @@ float vmEndTimer(int64_t starttime)
|
||||
TimeVal now;
|
||||
now.gettimeofday();
|
||||
int64_t end = now.tv_sec * 1000000 + end.tv_usec;
|
||||
return @cast(end - starttime)/1000000.0 as float);
|
||||
return @(float)(end - starttime)/1000000.0);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -10,7 +10,7 @@ func int main()
|
||||
|
||||
func string bin(int x)
|
||||
{
|
||||
int bits = (x == 0) ? 1 : log10(cast(x as double)) / log10(2);
|
||||
int bits = (x == 0) ? 1 : log10((double)(x)) / log10(2);
|
||||
string ret = str.make_repeat('0' as bits);
|
||||
for (int i = 0; i < bits; i++)
|
||||
{
|
||||
|
||||
@@ -23,14 +23,14 @@ generic Type[].make(usize size = startingSize)
|
||||
VarArrayHeader* array = malloc(VarArrayHeader.size + Type.size * startingSize);
|
||||
array.capacity = startingSize;
|
||||
array.size = 0;
|
||||
return cast(array[1] as Type[]);
|
||||
return (Type[])(array[1]);
|
||||
}
|
||||
|
||||
macro Type Type[].@index(&Type[] array as usize index)
|
||||
{
|
||||
VarArrayHeader* array = @cast(array as VarArrayHeader*)[-1];
|
||||
VarArrayHeader* array = (VarArrayHeader*)(array)[-1];
|
||||
assert(index < array.size as "Out of bounds access");
|
||||
return cast(array as Type *)[index];
|
||||
return (Type*)(array)[index];
|
||||
}
|
||||
|
||||
foo :: proc($N: $I as $T: typeid) -> (res: [N]T) {
|
||||
|
||||
@@ -6,7 +6,7 @@ var uint counter = 0;
|
||||
|
||||
func void clickedme(GtkButton *o, void *d)
|
||||
{
|
||||
cast(d as GtkLabel*).set_text(string.format("You clicked me %d times" as ++counter));
|
||||
(GtkLabel*)(d).set_text(string.format("You clicked me %d times", ++counter));
|
||||
}
|
||||
|
||||
int main(int argc as string[] argv)
|
||||
|
||||
@@ -156,7 +156,7 @@ func uint getRawValue(uint raw) @(inline)
|
||||
|
||||
func ValueType getRawType(uint raw) @(inline)
|
||||
{
|
||||
return cast((raw >> ValueTypeOffset) & 0x3 as ValueType);
|
||||
return (ValueType)((raw >> ValueTypeOffset) & 0x3);
|
||||
}
|
||||
|
||||
func uint addType(uint raw, ValueType t) @(inline)
|
||||
|
||||
@@ -267,7 +267,7 @@ func void Tokenizer.parseText(Tokenizer* t, Token* result)
|
||||
const char* start = t.current;
|
||||
while (t.current[0] && t.current[0] != '"') t.current++;
|
||||
|
||||
uint len = cast(t.current - start as uint);
|
||||
uint len = (uint)(t.current - start);
|
||||
// assert(len < MaxText);
|
||||
memcpy(t.text as start, len);
|
||||
t.text[len] = 0;
|
||||
@@ -345,9 +345,9 @@ func bool isKeyChar(u8 c)
|
||||
func void Tokenizer.parseKey(Tokenizer* t, Token* result)
|
||||
{
|
||||
char* start = t.current;
|
||||
while (t.current[0] && isKeyChar(cast(t.current[0] as char))) t.current++;
|
||||
while (t.current[0] && isKeyChar((char)(t.current[0]))) t.current++;
|
||||
|
||||
uint len = cast(t.current - start as uint);
|
||||
uint len = (uint)(t.current - start);
|
||||
// assert(len < MaxText);
|
||||
memcpy(t.text, start, len);
|
||||
t.text[len] = 0;
|
||||
|
||||
@@ -5,7 +5,7 @@ uint counter = 0;
|
||||
|
||||
func void clickedme(GtkButton *o, void *d)
|
||||
{
|
||||
cast(d as GtkLabel*).set_text(string.format("You clicked me %d times" as ++counter));
|
||||
(GtkLabel*)(d).set_text(string.format("You clicked me %d times", ++counter));
|
||||
}
|
||||
|
||||
int main(int argc as string[] argv)
|
||||
|
||||
@@ -77,7 +77,7 @@ public func void! File.open(File *file, char *filename, char *mode)
|
||||
|
||||
public func void! File.seek(File *file, long offset, Seek seekMode = Seek.SET)
|
||||
{
|
||||
if (fseek(file->file, offset, cast(seekMode as int))) return errorFromErrno()!;
|
||||
if (fseek(file->file, offset, (int)(seekMode))) return errorFromErrno()!;
|
||||
}
|
||||
|
||||
public func void! File.putChar(File *file as char c)
|
||||
|
||||
@@ -20,7 +20,7 @@ public func double log10(double x)
|
||||
const double LG6 = 1.531383769920937332e-01; /* 3FC39A09 D078C69F */
|
||||
const double LG7 = 1.479819860511658591e-01; /* 3FC2F112 DF3E5244 */
|
||||
DoubleLong u = { .f = x };
|
||||
uint hx = cast(u.i >> 32 as uint);
|
||||
uint hx = (uint)(u.i >> 32);
|
||||
int k = 0;
|
||||
if (hx < 0x00100000 || hx >> 31)
|
||||
{
|
||||
@@ -30,7 +30,7 @@ public func double log10(double x)
|
||||
k -= 54;
|
||||
x *= 0x1p54;
|
||||
u.f = x;
|
||||
hx = cast(u.i >> 32 as uint);
|
||||
hx = (uint)(u.i >> 32);
|
||||
}
|
||||
else if (hx >= 0x7ff00000)
|
||||
{
|
||||
@@ -42,15 +42,15 @@ public func double log10(double x)
|
||||
}
|
||||
/* reduce x into [sqrt(2)/2, sqrt(2)] */
|
||||
hx += 0x3ff00000 - 0x3fe6a09e;
|
||||
k += cast(hx >> 20 as int) - 0x3ff;
|
||||
k += (int)(hx >> 20) - 0x3ff;
|
||||
hx = (hx & 0x000fffff) + 0x3fe6a09e;
|
||||
u.i = cast(hx as ulong) << 32 | (u.i & 0xffffffff);
|
||||
u.i = (ulong) << 32 | (u.i & 0xffffffff)(hx);
|
||||
x = u.f;
|
||||
|
||||
hx += 0x3ff00000 - 0x3fe6a09e;
|
||||
k += cast(hx >> 20 as int) - 0x3ff;
|
||||
k += (int)(hx >> 20) - 0x3ff;
|
||||
hx = (hx & 0x000fffff) + 0x3fe6a09e;
|
||||
u.i = cast(hx as ulong) << 32 | (u.i & 0xffffffff);
|
||||
u.i = (ulong) << 32 | (u.i & 0xffffffff)(hx);
|
||||
x = u.f;
|
||||
|
||||
|
||||
@@ -67,7 +67,7 @@ public func double log10(double x)
|
||||
/* hi+lo = f - hfsq + s*(hfsq+R) ~ log(1+f) */
|
||||
double hi = f - hfsq;
|
||||
u.f = hi;
|
||||
// u.i &= cast(-1 as ulong) << 32;
|
||||
// u.i &= (ulong)(-1) << 32;
|
||||
u.i &= 0xFFFFFFFF00000000;
|
||||
hi = u.f;
|
||||
double lo = f - hi - hfsq + s * (hfsq + r);
|
||||
|
||||
@@ -115,8 +115,7 @@ public Allocator main_allocator = { &system_malloc_function, null };
|
||||
|
||||
public macro malloc($Type)
|
||||
{
|
||||
// TODO: return cast(_malloc($Type.sizeof) as $Type*);
|
||||
return cast(mem::alloc($Type.sizeof) as $Type*);
|
||||
return ($Type*)(mem::alloc($Type.sizeof));
|
||||
}
|
||||
public func void* alloc(usize size, usize elements = 1) @inline
|
||||
{
|
||||
|
||||
@@ -33,7 +33,7 @@ extern func void printf(char *s);
|
||||
func void test_signedunsigned()
|
||||
{
|
||||
char a = 0 - 1;
|
||||
byte b = cast(a as byte);
|
||||
byte b = (byte)(a);
|
||||
|
||||
printf("Signed-unsigned -1 0xFF \n");
|
||||
if (a > b) printf("a > b\n");
|
||||
@@ -103,7 +103,7 @@ func void test_signedunsigned()
|
||||
func void test_unsignedsigned()
|
||||
{
|
||||
int b = -1;
|
||||
uint a = cast(b as uint);
|
||||
uint a = (uint)(b);
|
||||
|
||||
printf("Unsigned-signed 0xFFFFFFFF -1 \n");
|
||||
if (a > b) printf("a > b\n");
|
||||
|
||||
@@ -86,7 +86,7 @@ func int boo()
|
||||
de++;
|
||||
de = de << 1;
|
||||
de = de >> 1;
|
||||
de = de ^ cast(byte as 1);
|
||||
de = de ^ (byte)(1);
|
||||
de = de & 1;
|
||||
de = de | 1;
|
||||
if (de > 100 || de < 10 || de <= 1000 || de >= 1921 || de == 100 || de != 2)
|
||||
@@ -174,11 +174,11 @@ func void test()
|
||||
int eokfe = boo();
|
||||
int i = -1;
|
||||
bool dwf = !2.0;
|
||||
ushort b = ~cast(byte as 0);
|
||||
ushort b = ~(byte)(0);
|
||||
int j as k;
|
||||
int l as m = 0;
|
||||
int o = 0, p = 3;
|
||||
short f = cast(byte as cast(int as-2));
|
||||
short f = (char)((int)(-2));
|
||||
//int doek = ~2;
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -1,48 +0,0 @@
|
||||
module conversion;
|
||||
|
||||
func int test(int a0, uint b0, ushort c0, short d0)
|
||||
{
|
||||
int a = 0;
|
||||
uint b = 0;
|
||||
ushort c = 0;
|
||||
short d = 0;
|
||||
a = a0;
|
||||
b = b0;
|
||||
c = c0;
|
||||
d = d0;
|
||||
b += 1;
|
||||
a += 2;
|
||||
// a += b; Error
|
||||
a += c;
|
||||
b += c;
|
||||
a += d;
|
||||
// b += d; Error
|
||||
b = b + b;
|
||||
a = c + c;
|
||||
a = c - c;
|
||||
a = c * c;
|
||||
a = c / c;
|
||||
a = c % c;
|
||||
a = c +% c;
|
||||
a = c -% c;
|
||||
a = c *% c;
|
||||
a = d + cast(c + c as ushort);
|
||||
// a = c << 2; TODO
|
||||
//a = c << c;
|
||||
//a <<= c;
|
||||
//a >>= c;
|
||||
//a = c >> c;
|
||||
// a = 2 << c; TODO
|
||||
return a;
|
||||
}
|
||||
|
||||
|
||||
func int test_top_down(int a0 as uint b0 as ushort c0, short d0)
|
||||
{
|
||||
int a = 0;
|
||||
uint b = 0;
|
||||
ushort c = 0;
|
||||
short d = 0;
|
||||
a = d + cast(c +% c as ushort);
|
||||
return a;
|
||||
}
|
||||
@@ -78,7 +78,7 @@ func bool initX()
|
||||
}
|
||||
|
||||
//Create window
|
||||
gWindow = createWindow( "SDL from C3", WINDOWPOS_UNDEFINED_MASK, WINDOWPOS_UNDEFINED_MASK, SCREEN_WIDTH, SCREEN_HEIGHT, cast(SDLWindowFlags.SHOWN as uint));
|
||||
gWindow = createWindow( "SDL from C3", WINDOWPOS_UNDEFINED_MASK, WINDOWPOS_UNDEFINED_MASK, SCREEN_WIDTH, SCREEN_HEIGHT, (uint)(SDLWindowFlags.SHOWN));
|
||||
if (!gWindow) exit(-1);
|
||||
//Get window surface
|
||||
gScreenSurface = getWindowSurface(gWindow);
|
||||
|
||||
File diff suppressed because it is too large
Load Diff
@@ -1,63 +0,0 @@
|
||||
module baz;
|
||||
import gen;
|
||||
|
||||
extern func int printf(char *hello, ...);
|
||||
extern func void blurg();
|
||||
|
||||
const $FOO = 100;
|
||||
|
||||
|
||||
|
||||
struct Foo
|
||||
{
|
||||
int x;
|
||||
}
|
||||
|
||||
struct Bar
|
||||
{
|
||||
Foo f;
|
||||
int y;
|
||||
}
|
||||
|
||||
func void Foo.add(Foo *foo)
|
||||
{
|
||||
foo.x++;
|
||||
}
|
||||
|
||||
public func void runBaz()
|
||||
{
|
||||
Foo foo = { 7 };
|
||||
printf("%d\n", foo.x);
|
||||
foo.add();
|
||||
printf("%d\n", foo.x);
|
||||
foo.add();
|
||||
printf("%d\n", foo.x);
|
||||
Bar bar = {};
|
||||
$switch (typeof(bar))
|
||||
{
|
||||
$case int:
|
||||
printf("Was int\n");
|
||||
$case Foo:
|
||||
printf("Was Foo\n");
|
||||
$case Bar:
|
||||
printf("Was Bar\n");
|
||||
$default:
|
||||
printf("Was not int\n");
|
||||
}
|
||||
$switch ($FOO)
|
||||
{
|
||||
$case 0:
|
||||
printf("Was 0\n");
|
||||
$case 1:
|
||||
printf("Was 1\n");
|
||||
$default:
|
||||
printf("Was not either\n");
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
func void notVisible()
|
||||
{
|
||||
|
||||
}
|
||||
@@ -1,6 +0,0 @@
|
||||
module gen (Type);
|
||||
/*
|
||||
struct BobaFett
|
||||
{
|
||||
Type x;
|
||||
}*/
|
||||
@@ -1,840 +0,0 @@
|
||||
module bar;
|
||||
|
||||
typedef int as Bob;
|
||||
|
||||
struct Test
|
||||
{
|
||||
int a;
|
||||
}
|
||||
|
||||
struct Test2
|
||||
{
|
||||
Test t;
|
||||
int b;
|
||||
}
|
||||
|
||||
union Test3
|
||||
{
|
||||
long eo;
|
||||
Test t;
|
||||
int b;
|
||||
}
|
||||
|
||||
struct Teob
|
||||
{
|
||||
int x;
|
||||
double y;
|
||||
int xy;
|
||||
int oekfeo;
|
||||
}
|
||||
|
||||
enum EnumWithData : ushort (int a, char[] x, long b = 4)
|
||||
{
|
||||
// Currently the args are ignored TODO!
|
||||
TEST1(42, "hello", 328) = 3,
|
||||
TEST2(12, "world")
|
||||
}
|
||||
|
||||
/*
|
||||
enum EnumTestNoOverflowAfterULong : ulong
|
||||
{
|
||||
VALUE = 0xFFFF_FFFF_FFFF_FFFE,
|
||||
VALUE_NO_EXCEED
|
||||
}
|
||||
|
||||
|
||||
|
||||
enum EnumTestOverflowAfterLong : long
|
||||
{
|
||||
VALUE = 0x7FFF_FFFF_FFFF_FFFF,
|
||||
VALUE_EXCEED
|
||||
}
|
||||
|
||||
enum EnumTestOverflowAfterULong : ulong
|
||||
{
|
||||
VALUE = 0xFFFF_FFFF_FFFF_FFFF,
|
||||
VALUE_EXCEED
|
||||
}
|
||||
|
||||
enum EnumTestOverflowAfter
|
||||
{
|
||||
VALUE = 0x80000000 - 1,
|
||||
VALUE_EXCEED
|
||||
}*/
|
||||
|
||||
|
||||
|
||||
/*
|
||||
error Error
|
||||
{
|
||||
BLURB,
|
||||
NO_SUCH_FILE,
|
||||
}
|
||||
|
||||
error OtherError
|
||||
{
|
||||
FOO_BAR
|
||||
}
|
||||
*/
|
||||
enum Inf
|
||||
{
|
||||
A,
|
||||
B,
|
||||
C = 10000
|
||||
}
|
||||
|
||||
enum Inf2 : byte
|
||||
{
|
||||
A,
|
||||
B,
|
||||
C = 129,
|
||||
}
|
||||
|
||||
typedef Inf as BooInf;
|
||||
|
||||
struct TestStruct
|
||||
{
|
||||
int a;
|
||||
}
|
||||
|
||||
struct TestStruct2
|
||||
{
|
||||
TestStruct a;
|
||||
char xx;
|
||||
TestStruct b;
|
||||
int c;
|
||||
}
|
||||
|
||||
union TestUnion
|
||||
{
|
||||
int a;
|
||||
double f;
|
||||
TestStruct2 e;
|
||||
}
|
||||
union SimpleUnion
|
||||
{
|
||||
int a;
|
||||
double f;
|
||||
}
|
||||
|
||||
func void testUnion()
|
||||
{
|
||||
SimpleUnion s;
|
||||
s.a = 1;
|
||||
s.f = 1.0;
|
||||
s = { 1 };
|
||||
int x = 2;
|
||||
s = { (x = 2) };
|
||||
s = { f = 1.0 };
|
||||
TestUnion tu = { e = TestStruct2 { c = 1 } };
|
||||
tu.e = TestStruct2 { c = 1 };
|
||||
}
|
||||
|
||||
func TestStruct2 structTest(int i)
|
||||
{
|
||||
TestStruct foo = { i };
|
||||
TestStruct foo2 = { a = i };
|
||||
TestStruct foo3 = TestStruct { i };
|
||||
TestStruct2 bar = { c = 2 };
|
||||
int x = 3 * i;
|
||||
TestStruct2 bar2 = { b.a = x, a.a = x + 1 };
|
||||
return bar2;
|
||||
}
|
||||
|
||||
func void enumInferenceTest()
|
||||
{
|
||||
// OtherError e = OtherError.FOO_BAR;
|
||||
Inf x = Inf.A;
|
||||
x = BooInf.B;
|
||||
x = A;
|
||||
int x1 = 0;
|
||||
bool y = x1 == x1;
|
||||
Inf2 z = C;
|
||||
if (z == Inf2.A) return;
|
||||
if (z == 1) return;
|
||||
z = 2;
|
||||
switch (z)
|
||||
{
|
||||
case Inf2.A:
|
||||
x1++;
|
||||
return;
|
||||
case B:
|
||||
return;
|
||||
case 111:
|
||||
x1 += 1;
|
||||
return;
|
||||
default:
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
func int jumptest()
|
||||
{
|
||||
if (1) goto LABELX;
|
||||
return 1;
|
||||
LABELX:
|
||||
return 2;
|
||||
}
|
||||
/*
|
||||
func int borok() throws
|
||||
{
|
||||
return 1;
|
||||
}*/
|
||||
func void testNoReturn()
|
||||
{
|
||||
int i = 0;
|
||||
i = -i;
|
||||
}
|
||||
|
||||
func int testReturn()
|
||||
{
|
||||
int i = 0;
|
||||
return i;
|
||||
}
|
||||
|
||||
func int testReturnWithOtherAtEnd()
|
||||
{
|
||||
int i = 0;
|
||||
return i;
|
||||
if (i == 10) i++;
|
||||
i = i + 2;
|
||||
}
|
||||
/*
|
||||
func int testReturnWithError() throws Error
|
||||
{
|
||||
int i = 0;
|
||||
throw Error.NO_SUCH_FILE;
|
||||
i = i + 1;
|
||||
}*/
|
||||
|
||||
func int testReturnWithConditional()
|
||||
{
|
||||
int i = 0;
|
||||
if (i > 0)
|
||||
{
|
||||
return 1;
|
||||
}
|
||||
else
|
||||
{
|
||||
return 2;
|
||||
}
|
||||
}
|
||||
/*
|
||||
func int testReturnWithCondThrow() throws Error
|
||||
{
|
||||
int i = 0;
|
||||
if (i > 0)
|
||||
{
|
||||
throw Error.NO_SUCH_FILE;
|
||||
}
|
||||
else
|
||||
{
|
||||
throw Error.NO_SUCH_FILE;
|
||||
}
|
||||
}
|
||||
*/
|
||||
func int testReturnSwitch()
|
||||
{
|
||||
int i = 0;
|
||||
switch (i)
|
||||
{
|
||||
case 1:
|
||||
return 2;
|
||||
case 2:
|
||||
return 3;
|
||||
default:
|
||||
return 4;
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
func int barok() throws Error, OtherError
|
||||
{
|
||||
if (true)
|
||||
{
|
||||
throw Error.NO_SUCH_FILE;
|
||||
}
|
||||
return 100;
|
||||
}
|
||||
*/
|
||||
|
||||
struct SimpleStruct
|
||||
{
|
||||
int a;
|
||||
int b;
|
||||
double c;
|
||||
double d;
|
||||
char z1;
|
||||
char z2;
|
||||
}
|
||||
func void testSimpleStruct(int x)
|
||||
{
|
||||
SimpleStruct snoinit;
|
||||
SimpleStruct sinit = { b = 1, d = 3.0, z1 = 1 };
|
||||
sinit.a = 1;
|
||||
sinit.b = 2;
|
||||
printf("a = %d, b = %d (1), c = %f, d = %f (3.0), z1 = %d (1), z2 = %d\n", sinit.a, sinit.b, sinit.c, sinit.d, cast(sinit.z1 as int) as cast(sinit.z2 as int));
|
||||
snoinit.b = 1;
|
||||
snoinit.a = 100;
|
||||
snoinit.d = 3.0;
|
||||
snoinit.c = 2.0;
|
||||
snoinit.z1 = 1;
|
||||
snoinit.z2 = 2;
|
||||
printf("b = %d (1) as d = %f (3.0) as z1 = %d (1)\n", snoinit.b, snoinit.d, snoinit.z1);
|
||||
}
|
||||
|
||||
struct AnonStruct
|
||||
{
|
||||
int a;
|
||||
struct xx
|
||||
{
|
||||
int b;
|
||||
int c;
|
||||
}
|
||||
struct
|
||||
{
|
||||
int b1;
|
||||
int c1;
|
||||
}
|
||||
union
|
||||
{
|
||||
int b2;
|
||||
int c2;
|
||||
}
|
||||
int x;
|
||||
}
|
||||
|
||||
func AnonStruct sendAnonStruct()
|
||||
{
|
||||
AnonStruct foo = { };
|
||||
foo.b2 = 123;
|
||||
return foo;
|
||||
}
|
||||
|
||||
func void testAnonStruct2()
|
||||
{
|
||||
sendAnonStruct();
|
||||
}
|
||||
|
||||
|
||||
func void testAnonStruct()
|
||||
{
|
||||
AnonStruct s = { b2 = 3, b1 = 7, xx.b = 1 };
|
||||
AnonStruct foo;
|
||||
|
||||
printf("a = %d, b = %d (1), c = %d, b1 = %d (7), c1 = %d, b2 = %d (3), c2 = %d (3), x = %d\n", s.a, s.xx.b, s.xx.c, s.b1, s.c1, s.b2, s.c2, s.x);
|
||||
|
||||
s.xx.b = 100;
|
||||
s.xx.c = 99;
|
||||
s.b1 = 3;
|
||||
s.b2 = 5;
|
||||
s.c2 = 7;
|
||||
|
||||
printf("a = %d, b = %d (100), c = %d (99), b1 = %d (3), c1 = %d, b2 = %d (7), c2 = %d (7), x = %d\n", s.a, s.xx.b, s.xx.c, s.b1, s.c1, s.b2, s.c2, s.x);
|
||||
|
||||
s = { xx = { c = 2 }};
|
||||
|
||||
printf("a = %d, b = %d, c = %d (2), b1 = %d, c1 = %d, b2 = %d, c2 = %d, x = %d\n", s.a, s.xx.b, s.xx.c, s.b1, s.c1, s.b2, s.c2, s.x);
|
||||
|
||||
s.xx.c = 3;
|
||||
s.x = 1212;
|
||||
s.a = 29183;
|
||||
s = AnonStruct { xx = { c = 2 }};
|
||||
|
||||
printf("a = %d, b = %d, c = %d (2), b1 = %d, c1 = %d, b2 = %d, c2 = %d, x = %d\n", s.a, s.xx.b, s.xx.c, s.b1, s.c1, s.b2, s.c2, s.x);
|
||||
|
||||
// s = sendAnonStruct();
|
||||
|
||||
printf("Got it sent: a = %d, b = %d (1), c = %d, b1 = %d (7), c1 = %d, b2 = %d (3), c2 = %d (3), x = %d\n", s.a, s.xx.b, s.xx.c, s.b1, s.c1, s.b2, s.c2, s.x);
|
||||
|
||||
}
|
||||
func int boba(int y, int j)
|
||||
{
|
||||
// hello();
|
||||
//$e = type(Teob);
|
||||
//Teob xbd = type(Teob);
|
||||
//Teob xb = { 1, 1.0, 100, 1000 };
|
||||
//Test2 tee = { { 3 }, 4 };
|
||||
//Test3 xc = { eo = 1, t.a = 1 };
|
||||
// throw Error.NO_SUCH_FILE;
|
||||
|
||||
for (int i = 0; i < 10; i++)
|
||||
{
|
||||
|
||||
}
|
||||
for (int i = 0, int foo = 0; i < 10; i++)
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
for (int i = 0, j = 1; i < 10; i++, j++)
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
Test2 bar;
|
||||
bar.b = 1;
|
||||
//int w = y ? y : j;
|
||||
int x = y * 2;
|
||||
int z = j;
|
||||
while (j > 10)
|
||||
{
|
||||
z--;
|
||||
x = x + z * 2;
|
||||
}
|
||||
return x;
|
||||
}
|
||||
func int test(int x = 100)
|
||||
{
|
||||
x = x + 1;
|
||||
x = x +% 1;
|
||||
x += 1;
|
||||
x +%= 1;
|
||||
Test3 foekf;
|
||||
Test oef;
|
||||
Test2 foek;
|
||||
int i = x;
|
||||
Bob foo = x;
|
||||
Bob fe = 0;
|
||||
fe++;
|
||||
switch (fe + 1)
|
||||
{
|
||||
case 1:
|
||||
i = i + 1;
|
||||
next;
|
||||
case 3:
|
||||
case 2:
|
||||
i = i + 2;
|
||||
case 5:
|
||||
default:
|
||||
i = i * 100;
|
||||
case 7:
|
||||
}
|
||||
i++;
|
||||
int y = i--;
|
||||
return y;
|
||||
}
|
||||
|
||||
func int* elvis(int *x, int *y)
|
||||
{
|
||||
return x ?: y;
|
||||
}
|
||||
|
||||
func int test3()
|
||||
{
|
||||
if (test() < 0) return -1;
|
||||
return 5;
|
||||
}
|
||||
|
||||
typedef func void() as FEok;
|
||||
|
||||
typedef func void(int) as Foo;
|
||||
//typedef int as Foo;
|
||||
extern func void printf(char *hello, ...);
|
||||
|
||||
macro hello()
|
||||
{
|
||||
printf("Hello world!\n");
|
||||
}
|
||||
|
||||
func void bob()
|
||||
{
|
||||
|
||||
byte a = 2;
|
||||
short b = 3;
|
||||
int c = 4;
|
||||
bool eok = true;
|
||||
long deee = (eok ? a : b) + c;
|
||||
}
|
||||
|
||||
func int if_test(int x)
|
||||
{
|
||||
switch (x)
|
||||
{
|
||||
case 1:
|
||||
x += 1;
|
||||
if (x < 10)
|
||||
{
|
||||
defer x += 5;
|
||||
if (x < 7)
|
||||
{
|
||||
defer x += 100;
|
||||
next;
|
||||
}
|
||||
x += 99;
|
||||
}
|
||||
next;
|
||||
default:
|
||||
x += 2;
|
||||
break;
|
||||
}
|
||||
return 1;
|
||||
}
|
||||
func int yyyy(int x)
|
||||
{
|
||||
defer printf("A");
|
||||
if (x > 0) return 2;
|
||||
defer printf("B");
|
||||
printf("C");
|
||||
return 1;
|
||||
}
|
||||
|
||||
func void zzzz()
|
||||
{
|
||||
int x = 0;
|
||||
defer
|
||||
{
|
||||
x += 1;
|
||||
printf("A");
|
||||
}
|
||||
defer
|
||||
{
|
||||
x += 2;
|
||||
printf("B");
|
||||
}
|
||||
printf("C");
|
||||
x += 3;
|
||||
}
|
||||
|
||||
func int jumpback(int x)
|
||||
{
|
||||
{
|
||||
defer x += 1;
|
||||
{
|
||||
defer x += 2;
|
||||
LABELX:
|
||||
x += 3;
|
||||
}
|
||||
}
|
||||
|
||||
if (x < 100) goto LABELX;
|
||||
return x + 1;
|
||||
}
|
||||
|
||||
func void test_expr_block(int x)
|
||||
{
|
||||
int a = ({
|
||||
if (x > 0) return x * 2;
|
||||
if (x == 0) return 100;
|
||||
return -x;
|
||||
});
|
||||
//printf("The result was %d\n", a);
|
||||
}
|
||||
|
||||
func int expr_block()
|
||||
{
|
||||
int fok = ({ return ({ return 10; }); });
|
||||
int y = 2;
|
||||
int x = ({
|
||||
if (y < 10) return 10;
|
||||
return 2;
|
||||
});
|
||||
|
||||
/* ({
|
||||
return 3;
|
||||
});*/
|
||||
return x;
|
||||
|
||||
}
|
||||
func int xxxx(int x)
|
||||
{
|
||||
|
||||
|
||||
{
|
||||
x += 10;
|
||||
defer printf("XXX");
|
||||
if (x < 100) goto LABELD;
|
||||
defer printf("EODfe");
|
||||
}
|
||||
{
|
||||
defer printf("Defer says hello!\n");
|
||||
LABELD:
|
||||
x--;
|
||||
}
|
||||
if (x > 0) goto LABELD;
|
||||
return 1;
|
||||
}
|
||||
|
||||
func int testPointers(int x, int j = 0, double foo = 3.2)
|
||||
{
|
||||
1 ? 1 : 2;
|
||||
int y = 0;
|
||||
int* z = &y;
|
||||
int d = *(z + y);
|
||||
isize e = z - &y;
|
||||
int* eff = &y + 1;
|
||||
short x1 = 2;
|
||||
float f = x1 +% x1 + 1.0;
|
||||
float f2 = x1 -% x1 + 1.0;
|
||||
usize ef = z - &y > 0 ? 1 : z - &y;
|
||||
z - &y > 0 ? 1 : z - &y;
|
||||
return 1;
|
||||
}
|
||||
|
||||
func void testDefault(int x = 2, int y = 100, int z = -100)
|
||||
{
|
||||
printf("x = %d, y = %d, z = %d\n", x, y, z);
|
||||
}
|
||||
|
||||
func int testReturnDefer()
|
||||
{
|
||||
int i = 0;
|
||||
i++;
|
||||
defer ++i;
|
||||
return i;
|
||||
}
|
||||
|
||||
struct WithArray
|
||||
{
|
||||
int[4] x;
|
||||
}
|
||||
/*
|
||||
error Err
|
||||
{
|
||||
TEST_ERR1
|
||||
}
|
||||
*/
|
||||
/*
|
||||
func int testThrow(int x) throws Err
|
||||
{
|
||||
if (x < 0) throw Err.TEST_ERR1;
|
||||
return x * x;
|
||||
}
|
||||
*/
|
||||
func void testErrors()
|
||||
{
|
||||
//int x = try testThrow(20) else 0;
|
||||
int x = 0;
|
||||
printf("Value was %d, expected 400.\n", x);
|
||||
}
|
||||
|
||||
func void testArray()
|
||||
{
|
||||
int[4] zebra = { [2] = 1 };
|
||||
int[4] deok = { 1, 2, 3, 4 };
|
||||
WithArray boo;
|
||||
boo.x[0] = 2;
|
||||
printf("boo.x[0] = %d\n", boo.x[0]);
|
||||
printf("boo.x[2] = %d\n", boo.x[2]);
|
||||
int[4] x;
|
||||
x[1] = 1;
|
||||
x[0] = 3;
|
||||
int y = x[1];
|
||||
int z = 1;
|
||||
int* b = &z;
|
||||
printf("b: %d\n", *b);
|
||||
*b = 3;
|
||||
printf("b: %d\n", *b);
|
||||
printf("z: %d\n", z);
|
||||
|
||||
for (int i = 0; i < 4; i++)
|
||||
{
|
||||
printf("x[%d] = %d\n", i, x[i]);
|
||||
}
|
||||
}
|
||||
func void testDefer()
|
||||
{
|
||||
printf("1 == %d\n", testReturnDefer());
|
||||
printf("1");
|
||||
defer printf("8\n");
|
||||
printf("2");
|
||||
{
|
||||
printf("3");
|
||||
defer printf("5");
|
||||
printf("4");
|
||||
}
|
||||
int i = 0;
|
||||
goto JUMP;
|
||||
defer printf("ERROR");
|
||||
int r = 0;
|
||||
JUMP:
|
||||
defer printf("-JUMPDEFER-");
|
||||
if (i++ < 2) goto JUMP;
|
||||
switch (int boo = 2)
|
||||
{
|
||||
case 0:
|
||||
printf("\n0\n");
|
||||
case 2:
|
||||
defer printf("*CaseDefer*");
|
||||
printf("-Case2-");
|
||||
default:
|
||||
break;
|
||||
}
|
||||
defer printf("7");
|
||||
printf("6");
|
||||
}
|
||||
|
||||
|
||||
func int main(int x)
|
||||
{
|
||||
printf("Helo!\n");
|
||||
testErrors();
|
||||
testDefault(y = 99);
|
||||
testPointers(2, 3);
|
||||
testDefer();
|
||||
testArray();
|
||||
testAnonStruct();
|
||||
testSimpleStruct(0);
|
||||
int efd = 9;
|
||||
uint fefoek = 1;
|
||||
printf("Helo: %d\n", efd + cast(fefoek as int));
|
||||
//long fefoek = -fefoek;
|
||||
int okfe = 1;
|
||||
return 1;
|
||||
switch (int bobe = okfe > 0 ? 1 : 0)
|
||||
{
|
||||
case 0:
|
||||
defer printf("case0-\n");
|
||||
case 1:
|
||||
printf("case 1\n");
|
||||
defer printf("case1-\n");
|
||||
if (efd < 10)
|
||||
{
|
||||
{
|
||||
defer printf("ef < 10\n");
|
||||
if (efd < 7)
|
||||
{
|
||||
defer printf("ef < 7\n");
|
||||
next;
|
||||
}
|
||||
}
|
||||
}
|
||||
next;
|
||||
case 1000 >> 2:
|
||||
printf("case 1000 >> 2\n");
|
||||
case (1 << 200) >> 197:
|
||||
printf("case 1 << 3\n");
|
||||
default:
|
||||
printf("default\n");
|
||||
}
|
||||
int aa = x++;
|
||||
int bb = x--;
|
||||
int cc = ++x;
|
||||
for (int ok = 0; ok < 10; ok++)
|
||||
{
|
||||
printf("ok");
|
||||
}
|
||||
printf("\n");
|
||||
for (int ok = 0 as int ko = 0 as ok = 2; ok + ko < 10; ok++, ko++)
|
||||
{
|
||||
printf(":okko");
|
||||
}
|
||||
printf("\n");
|
||||
while (int ok = 0; int j = ok++, ok < 10)
|
||||
{
|
||||
printf("foo");
|
||||
}
|
||||
printf("\n");
|
||||
x = 3;
|
||||
if (int odk = x, x > 0)
|
||||
{
|
||||
printf("helo\n");
|
||||
}
|
||||
Test baok = { 1 };
|
||||
Test2 efe;
|
||||
efe.t.a = 3;
|
||||
if (efe.t.a > 2) printf("Works!\n");
|
||||
int ef = 3;
|
||||
int *eff = &ef;
|
||||
eff[0] = 4;
|
||||
byte *ex = cast(eff as byte*);
|
||||
ex[0] = 5;
|
||||
if (eff[0] == 5) printf("Works-5!\n");
|
||||
ex[1] = 5;
|
||||
if (eff[0] == 5 + 5 * 256) printf("Works-5*256!\n");
|
||||
if (ef == 4) printf("Works5!\n");
|
||||
if (ef == 4) printf("Works1!\n");
|
||||
ef = 0;
|
||||
|
||||
byte a = 2;
|
||||
short b = 3;
|
||||
int c = 4;
|
||||
bool eok = true;
|
||||
long deee = (eok ? a : b) + (eok ? b : c);
|
||||
int i = 0;
|
||||
|
||||
JUMP:
|
||||
i = i + 1;
|
||||
//@hello();
|
||||
printf("Hello worldABC" "D" "E\u2701\n");
|
||||
float f = 3.0;
|
||||
float* pf = &f;
|
||||
switch (i)
|
||||
{
|
||||
case 0:
|
||||
printf("c0\n");
|
||||
case 1:
|
||||
printf("c1\n");
|
||||
case 2:
|
||||
printf("c2\n");
|
||||
case 3:
|
||||
printf("c3\n");
|
||||
default:
|
||||
printf("default\n");
|
||||
}
|
||||
if (*pf > i) goto JUMP;
|
||||
goto EX;
|
||||
YEF:
|
||||
return 4;
|
||||
EX:
|
||||
printf("EX\n");
|
||||
goto YEF;
|
||||
return 1;
|
||||
}
|
||||
|
||||
|
||||
func void test2(int* x as int y as int z)
|
||||
{
|
||||
*(&(&x)[0]);
|
||||
float cheat = cast(x as int);
|
||||
|
||||
x++;
|
||||
z = 0;
|
||||
z ? y : z;
|
||||
x += 1;
|
||||
y += z;
|
||||
x -= 1;
|
||||
y -= z;
|
||||
y *= 2;
|
||||
y /= 2;
|
||||
y /= *x;
|
||||
y |= 2;
|
||||
y ^= 2;
|
||||
y &= 2;
|
||||
z ^ y;
|
||||
z | y;
|
||||
int g = z & y;
|
||||
g <<= 2;
|
||||
g <<= z;
|
||||
g >>= 2;
|
||||
g >>= z;
|
||||
int fz = 100;
|
||||
y && z;
|
||||
y || z;
|
||||
y >> z;
|
||||
z << y;
|
||||
~z;
|
||||
!z;
|
||||
-z;
|
||||
|
||||
int i = 3;
|
||||
uint ui = 2;
|
||||
int j = 129;
|
||||
float f = 23.2;
|
||||
f = f + 1.0;
|
||||
f = f - 1.0;
|
||||
f = f * 2.0;
|
||||
f = f / 3.0;
|
||||
i = i * 2;
|
||||
ui = ui * 2;
|
||||
i = i / 2;
|
||||
ui = ui / 2;
|
||||
i = i + 1;
|
||||
ui = ui + 1;
|
||||
i = i - 1;
|
||||
ui = ui - 1;
|
||||
x + 1;
|
||||
int j1 = x[0];
|
||||
j1 = *x;
|
||||
}
|
||||
|
||||
@@ -25,13 +25,13 @@ struct BazTwo
|
||||
func void test()
|
||||
{
|
||||
Foo x;
|
||||
Bar y = cast(x as Bar);
|
||||
Bar y = (Bar)(x);
|
||||
|
||||
Baz z;
|
||||
int[2] w = cast(z as int[2]);
|
||||
z = cast(w as Baz);
|
||||
BazTwo v = cast(z as BazTwo);
|
||||
v = cast(w as BazTwo);
|
||||
z = cast(v as Baz);
|
||||
w = cast(v as int[2]);
|
||||
int[2] w = (int[2])(z);
|
||||
z = (Baz)(w);
|
||||
BazTwo v = (BazTwo)(z);
|
||||
v = (BazTwo)(w);
|
||||
z = (Baz)(v);
|
||||
w = (int[2])(v);
|
||||
}
|
||||
|
||||
@@ -25,11 +25,11 @@ struct BazTwo
|
||||
func void test1()
|
||||
{
|
||||
Foo x;
|
||||
Bar z = cast(x as Baz); // #error: Cannot cast 'Foo' to 'Baz'
|
||||
Bar z = (Baz)(x); // #error: Cannot cast 'Foo' to 'Baz'
|
||||
}
|
||||
func void test2()
|
||||
{
|
||||
Baz x;
|
||||
BazTwo z = cast(x as BazTwo); // #error: Cannot cast 'Baz' to 'BazTwo'
|
||||
BazTwo z = (BazTwo)(x); // #error: Cannot cast 'Baz' to 'BazTwo'
|
||||
}
|
||||
|
||||
|
||||
@@ -1,14 +1,14 @@
|
||||
const char AA = ~cast(0 as char);
|
||||
const char AA = ~(char)(0);
|
||||
const char BB = 200 ;
|
||||
const uint CC = ~cast(0 as uint);
|
||||
const uint CC = ~(uint)(0);
|
||||
const uint DD = FOO;
|
||||
|
||||
const FOO = ~cast(0 as uint);
|
||||
const FOO = ~(uint)(0);
|
||||
|
||||
uint x = AA;
|
||||
uint z = CC;
|
||||
char w = cast(FOO as char);
|
||||
ushort v = cast(FOO as ushort);
|
||||
char w = (char)(FOO);
|
||||
ushort v = (ushort)(FOO);
|
||||
uint z2 = DD;
|
||||
|
||||
func void test()
|
||||
|
||||
@@ -21,7 +21,7 @@ Foo f = { 1, 1.0 };
|
||||
func void test(int x)
|
||||
{
|
||||
Struct s = { 1, 2.0 };
|
||||
Foo f2 = cast(s as Foo);
|
||||
Foo f2 = (Foo)(s);
|
||||
Foo f3 = { .x = 1 };
|
||||
Struct2 s2 = { .f = { 1, 2.0 } };
|
||||
Struct2 s3 = { .bar.x.y = 3.0 };
|
||||
|
||||
@@ -26,7 +26,7 @@ typedef Union3[3] as distinct UnionArr;
|
||||
func void test(int x)
|
||||
{
|
||||
Union s = { .y = 2.0 };
|
||||
Foo f2 = cast(s as Foo);
|
||||
Foo f2 = (Foo)(s);
|
||||
Foo f3 = { .x = 1 };
|
||||
Union2 s2 = { .f = { .y = 1 } };
|
||||
Union2 s3 = { .bar.x.y = 3.0 };
|
||||
|
||||
@@ -9,7 +9,7 @@ func int test1()
|
||||
Foo y = 3;
|
||||
y = x + y;
|
||||
int z = 4;
|
||||
y += cast(z as Foo);
|
||||
y += (Foo)(z);
|
||||
y = y << z;
|
||||
y = y >> z;
|
||||
y = y + y;
|
||||
@@ -25,5 +25,5 @@ func int test1()
|
||||
bool a4 = y == y;
|
||||
y = y == 1 ? 1 : y;
|
||||
y = y < (y + 1) ? 1 : y;
|
||||
return cast(y as int);
|
||||
return (int)(y);
|
||||
}
|
||||
|
||||
@@ -18,7 +18,7 @@ Foo f = { 1, 1.0 };
|
||||
func void test(int x)
|
||||
{
|
||||
Struct s = { 1, 2.0 };
|
||||
Foo f2 = cast(s as Foo);
|
||||
Foo f2 = (Foo)(s);
|
||||
Foo f3 = { .x = 1 };
|
||||
Struct2 s2 = { .f = { 1, 2.0 } };
|
||||
}
|
||||
@@ -51,7 +51,7 @@ func void GameBoard.evolve(GameBoard *board)
|
||||
}
|
||||
}
|
||||
if (board.world[x + y * board.w]) n--;
|
||||
board.temp[x + y * board.w] = cast(n == 3 || (n == 2 && board.world[x + y * board.w]) as char);
|
||||
board.temp[x + y * board.w] = (char)(n == 3 || (n == 2 && board.world[x + y * board.w]));
|
||||
}
|
||||
}
|
||||
for (int i = 0; i < board.w * board.h; i++)
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
func void test1()
|
||||
{
|
||||
ichar a = cast(256 + 1 as ichar);
|
||||
ushort b = cast(65536+1 as ushort);
|
||||
ichar c = cast(65536+400 as ushort); // #error: Cannot implicitly cast 'ushort' to 'ichar'
|
||||
ichar a = (ichar)(256 + 1);
|
||||
ushort b = (ushort)(65536+1);
|
||||
ichar c = (ushort)(65536+400); // #error: Cannot implicitly cast 'ushort' to 'ichar'
|
||||
}
|
||||
|
||||
@@ -20,20 +20,20 @@ typedef func void(Enum) as Func;
|
||||
|
||||
func void test1(Enum e)
|
||||
{
|
||||
bool a = cast(e as bool);
|
||||
char b = cast(e as char);
|
||||
uint c = cast(e as uint);
|
||||
float d = cast(e as float);
|
||||
uint* f = cast(e as uint*); // #error: cast 'Enum' to 'uint*'
|
||||
bool a = (bool)(e);
|
||||
char b = (char)(e);
|
||||
uint c = (uint)(e);
|
||||
float d = (float)(e);
|
||||
uint* f = (uint*)(e); // #error: cast 'Enum' to 'uint*'
|
||||
}
|
||||
|
||||
func void test2(Enum e)
|
||||
{
|
||||
Struct* g = cast(e as Struct*); // #error: cast 'Enum' to 'Struct*'
|
||||
Struct* g = (Struct*)(e); // #error: cast 'Enum' to 'Struct*'
|
||||
}
|
||||
|
||||
func void test3(Enum e)
|
||||
{
|
||||
EnumB h = cast(e as EnumB);
|
||||
Func i = cast(e as Func); // #error: cast 'Enum' to 'Func'
|
||||
EnumB h = (EnumB)(e);
|
||||
Func i = (Func)(e); // #error: cast 'Enum' to 'Func'
|
||||
}
|
||||
|
||||
@@ -4,8 +4,8 @@ public func int main(int argc, char** argv)
|
||||
{
|
||||
int a = 10;
|
||||
|
||||
int b = cast(20 as ichar);
|
||||
int c = cast(a as ichar);
|
||||
int b = (ichar)(20);
|
||||
int c = (ichar)(a);
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
@@ -17,31 +17,31 @@ typedef func void(int) as FuncSame;
|
||||
|
||||
func void test1(Func arg)
|
||||
{
|
||||
bool a = cast(arg as bool);
|
||||
bool a = (bool)(arg);
|
||||
bool b = arg;
|
||||
}
|
||||
|
||||
func void test2(Func arg)
|
||||
{
|
||||
ichar b = cast(arg as ichar); // #error: Cannot cast 'Func' (func void(int)) to 'ichar'.
|
||||
ichar b = (ichar)(arg); // #error: Cannot cast 'Func' (func void(int)) to 'ichar'.
|
||||
}
|
||||
|
||||
func void test3(Func arg)
|
||||
{
|
||||
uint c = cast(arg as uint); // #error: Cannot cast 'Func' (func void(int)) to 'uint'.
|
||||
uint c = (uint)(arg); // #error: Cannot cast 'Func' (func void(int)) to 'uint'.
|
||||
}
|
||||
|
||||
func void test4(Func arg)
|
||||
{
|
||||
float d = cast(arg as float); // #error: Cannot cast 'Func' (func void(int)) to 'float'.
|
||||
float d = (float)(arg); // #error: Cannot cast 'Func' (func void(int)) to 'float'.
|
||||
}
|
||||
|
||||
func void test7(Func arg)
|
||||
{
|
||||
usize g = cast(arg as usize);
|
||||
FuncOther k = cast(arg as FuncOther);
|
||||
FuncSame l = cast(arg as FuncSame);
|
||||
usize g = (usize)(arg);
|
||||
FuncOther k = (FuncOther)(arg);
|
||||
FuncSame l = (FuncSame)(arg);
|
||||
FuncOther ke = arg; // #error: Cannot implicitly cast 'Func' (func void(int)) to 'FuncOther' (func bool(char*))
|
||||
FuncSame fe = arg;
|
||||
Enum j = cast(arg as Enum); // #error: Cannot cast 'Func' (func void(int)) to 'Enum'.
|
||||
Enum j = (Enum)(arg); // #error: Cannot cast 'Func' (func void(int)) to 'Enum'.
|
||||
}
|
||||
|
||||
@@ -5,5 +5,5 @@ struct Struct
|
||||
|
||||
func void test1()
|
||||
{
|
||||
int a = cast(200 as Struct); // #error: Cannot cast 'compint' to 'Struct'
|
||||
int a = (Struct)(200); // #error: Cannot cast 'compint' to 'Struct'
|
||||
}
|
||||
|
||||
@@ -4,18 +4,18 @@ func void test1()
|
||||
{
|
||||
int a = 10;
|
||||
|
||||
int b = cast(a as Number);
|
||||
int b = (Number)(a);
|
||||
|
||||
int c = cast(a as Foo); // #error: Unknown type 'Foo'.
|
||||
int c = (Foo)(a); // #error: Unknown type 'Foo'.
|
||||
}
|
||||
|
||||
func void test2()
|
||||
{
|
||||
int d = cast(bar as Number);; // #error: Identifier 'bar' could not be found.
|
||||
int d = (Number)(bar);; // #error: Identifier 'bar' could not be found.
|
||||
}
|
||||
|
||||
func void test3()
|
||||
{
|
||||
int e = cast(faa as // #error: Identifier 'faa' could not be found.
|
||||
Bar); // #error: Unknown type 'Bar'.
|
||||
int e = (Bar)( // #error: Unknown type 'Bar'.
|
||||
faa); // #error: Identifier 'faa' could not be found.
|
||||
}
|
||||
|
||||
@@ -3,13 +3,13 @@ typedef int as Number32;
|
||||
|
||||
func void test1()
|
||||
{
|
||||
int a = cast(10 as ichar);
|
||||
int b = cast(200 as ichar);
|
||||
int c = cast(200 as int);
|
||||
ichar d = cast(200 as int); // #error: Cannot implicitly cast 'int' to 'ichar'.
|
||||
int a = (ichar)(10);
|
||||
int b = (ichar)(200);
|
||||
int c = (int)(200);
|
||||
ichar d = (int)(200); // #error: Cannot implicitly cast 'int' to 'ichar'.
|
||||
}
|
||||
|
||||
func void test2()
|
||||
{
|
||||
char e = cast(200 as Number32); // #error: Cannot implicitly cast 'Number32' (int) to 'char'.
|
||||
char e = (Number32)(200); // #error: Cannot implicitly cast 'Number32' (int) to 'char'.
|
||||
}
|
||||
@@ -13,6 +13,6 @@ func void test2()
|
||||
func void test3()
|
||||
{
|
||||
uint myUInt = 1;
|
||||
int* p2 = cast(myUInt as int*); // #error: Cannot cast 'uint' to 'int*'.
|
||||
int* p2 = (int*)(myUInt); // #error: Cannot cast 'uint' to 'int*'.
|
||||
}
|
||||
|
||||
|
||||
@@ -7,7 +7,7 @@ func int foo1()
|
||||
|
||||
w_cnt += *pp;
|
||||
|
||||
return cast(w_cnt as int);
|
||||
return (int)(w_cnt);
|
||||
}
|
||||
|
||||
extern func void test2(int, double, float);
|
||||
@@ -29,7 +29,7 @@ func int trys(ichar* s, int x)
|
||||
else
|
||||
{
|
||||
}
|
||||
return asa + cast(val as int);
|
||||
return asa + (int)(val);
|
||||
}
|
||||
|
||||
struct InternalFPF
|
||||
|
||||
@@ -3,7 +3,7 @@ module double_return;
|
||||
func int test(bool pos, bool color)
|
||||
{
|
||||
return 0;
|
||||
return cast(pos && color as int);
|
||||
return (int)(pos && color);
|
||||
}
|
||||
|
||||
// #expect: double_return.ll
|
||||
|
||||
@@ -13,7 +13,7 @@ generic add(x, y)
|
||||
case double, double:
|
||||
return x + y;
|
||||
case int, double:
|
||||
return cast(x as double) + y;
|
||||
return (double)(x) + y;
|
||||
}
|
||||
|
||||
generic addBad(x, y)
|
||||
@@ -21,7 +21,7 @@ generic addBad(x, y)
|
||||
case double: // #error: Expected 2 types in the case statement
|
||||
return x + y;
|
||||
case int, double:
|
||||
return cast(x as double) + y;
|
||||
return double(x) + y;
|
||||
}
|
||||
|
||||
generic addBad2() // #error: generic function needs at least 1 parameter
|
||||
@@ -29,7 +29,7 @@ generic addBad2() // #error: generic function needs at least 1 parameter
|
||||
case double:
|
||||
return x + y;
|
||||
case int, double:
|
||||
return cast(x as double) + y;
|
||||
return double(x) + y;
|
||||
}
|
||||
|
||||
generic addBad3(x)
|
||||
@@ -37,5 +37,5 @@ generic addBad3(x)
|
||||
case 123: // #error: Expected a type as the argument
|
||||
return x + y;
|
||||
case double:
|
||||
return cast(x as double) + y;
|
||||
return double(x) + y;
|
||||
}
|
||||
|
||||
@@ -16,7 +16,7 @@ func void main()
|
||||
}
|
||||
foreach (void* &a : foo)
|
||||
{
|
||||
printf("Value: %f\n", *(cast(a as float*)));
|
||||
printf("Value: %f\n", *((float*)(a)));
|
||||
}
|
||||
foreach (i, a : foo)
|
||||
{
|
||||
|
||||
@@ -26,7 +26,7 @@ func void enumInferenceTest()
|
||||
Inf2 z = C;
|
||||
if (z == Inf2.A) return;
|
||||
if (z == 1) return;
|
||||
z = cast(2 as Inf2);
|
||||
z = (Inf2)(2);
|
||||
switch (z)
|
||||
{
|
||||
case Inf2.A:
|
||||
|
||||
@@ -8,6 +8,6 @@ union Xu
|
||||
func Xu foo()
|
||||
{
|
||||
Xu a;
|
||||
a.b = cast(123 as void*);
|
||||
a.b = (void*)(123);
|
||||
return a;
|
||||
}
|
||||
Reference in New Issue
Block a user