diff --git a/resources/examples/base64.c3 b/resources/examples/base64.c3 index 3efbf4edc..bfc0dc0c7 100644 --- a/resources/examples/base64.c3 +++ b/resources/examples/base64.c3 @@ -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; } diff --git a/resources/examples/gameoflife.c3 b/resources/examples/gameoflife.c3 index 7748f1a76..a83b87a5f 100644 --- a/resources/examples/gameoflife.c3 +++ b/resources/examples/gameoflife.c3 @@ -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--) { diff --git a/resources/examples/hash.c3 b/resources/examples/hash.c3 index db42be07d..49919ae2f 100644 --- a/resources/examples/hash.c3 +++ b/resources/examples/hash.c3 @@ -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; } diff --git a/resources/examples/notworking/acornvm/avm_array.c3 b/resources/examples/notworking/acornvm/avm_array.c3 index 488d7f8af..859531864 100644 --- a/resources/examples/notworking/acornvm/avm_array.c3 +++ b/resources/examples/notworking/acornvm/avm_array.c3 @@ -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 */ diff --git a/resources/examples/notworking/acornvm/avm_memory.c3 b/resources/examples/notworking/acornvm/avm_memory.c3 index ac363d12a..15242f731 100644 --- a/resources/examples/notworking/acornvm/avm_memory.c3 +++ b/resources/examples/notworking/acornvm/avm_memory.c3 @@ -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."); } diff --git a/resources/examples/notworking/acornvm/avm_stack.c3 b/resources/examples/notworking/acornvm/avm_stack.c3 index cf5a0bc73..7124d5be7 100644 --- a/resources/examples/notworking/acornvm/avm_stack.c3 +++ b/resources/examples/notworking/acornvm/avm_stack.c3 @@ -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)); } /** diff --git a/resources/examples/notworking/acornvm/lexer.c3 b/resources/examples/notworking/acornvm/lexer.c3 index 654a0030e..0168ca1f3 100644 --- a/resources/examples/notworking/acornvm/lexer.c3 +++ b/resources/examples/notworking/acornvm/lexer.c3 @@ -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 */ diff --git a/resources/examples/notworking/acornvm/main.c3 b/resources/examples/notworking/acornvm/main.c3 index 330d8e252..21f8479cc 100644 --- a/resources/examples/notworking/acornvm/main.c3 +++ b/resources/examples/notworking/acornvm/main.c3 @@ -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: diff --git a/resources/examples/notworking/acornvm/symbol.c3 b/resources/examples/notworking/acornvm/symbol.c3 index 4d96581f9..4d64c7819 100644 --- a/resources/examples/notworking/acornvm/symbol.c3 +++ b/resources/examples/notworking/acornvm/symbol.c3 @@ -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 diff --git a/resources/examples/notworking/acornvm/value.c3 b/resources/examples/notworking/acornvm/value.c3 index 97f91b580..b43bd4815 100644 --- a/resources/examples/notworking/acornvm/value.c3 +++ b/resources/examples/notworking/acornvm/value.c3 @@ -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 diff --git a/resources/examples/notworking/acornvm/vm.c3 b/resources/examples/notworking/acornvm/vm.c3 index 71c92442f..86e8bdc71 100644 --- a/resources/examples/notworking/acornvm/vm.c3 +++ b/resources/examples/notworking/acornvm/vm.c3 @@ -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); } } diff --git a/resources/examples/notworking/binarydigits.c3 b/resources/examples/notworking/binarydigits.c3 index 01d9fdab8..ca1ec8a5c 100644 --- a/resources/examples/notworking/binarydigits.c3 +++ b/resources/examples/notworking/binarydigits.c3 @@ -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++) { diff --git a/resources/examples/notworking/functions.c3 b/resources/examples/notworking/functions.c3 index a1408f6cf..3ba1a7cf8 100644 --- a/resources/examples/notworking/functions.c3 +++ b/resources/examples/notworking/functions.c3 @@ -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) { diff --git a/resources/examples/notworking/globals.c3 b/resources/examples/notworking/globals.c3 index 18f32a47b..884ded3e5 100644 --- a/resources/examples/notworking/globals.c3 +++ b/resources/examples/notworking/globals.c3 @@ -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) diff --git a/resources/examples/notworking/toml_parser_c2.c3 b/resources/examples/notworking/toml_parser_c2.c3 index e78b9a014..902b340f0 100644 --- a/resources/examples/notworking/toml_parser_c2.c3 +++ b/resources/examples/notworking/toml_parser_c2.c3 @@ -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) diff --git a/resources/examples/notworking/toml_tokenizer_c2.c3 b/resources/examples/notworking/toml_tokenizer_c2.c3 index ed5f5ffdc..a35656691 100644 --- a/resources/examples/notworking/toml_tokenizer_c2.c3 +++ b/resources/examples/notworking/toml_tokenizer_c2.c3 @@ -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; diff --git a/resources/examples/notworking/window.c3 b/resources/examples/notworking/window.c3 index 820e8f110..d6f028d22 100644 --- a/resources/examples/notworking/window.c3 +++ b/resources/examples/notworking/window.c3 @@ -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) diff --git a/resources/lib/std/io.c3 b/resources/lib/std/io.c3 index 407de038c..a8d6db1ac 100644 --- a/resources/lib/std/io.c3 +++ b/resources/lib/std/io.c3 @@ -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) diff --git a/resources/lib/std/math.c3 b/resources/lib/std/math.c3 index c23957a0f..cd560f3d0 100644 --- a/resources/lib/std/math.c3 +++ b/resources/lib/std/math.c3 @@ -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); diff --git a/resources/lib/std/mem.c3 b/resources/lib/std/mem.c3 index eeee4e926..885cb977c 100644 --- a/resources/lib/std/mem.c3 +++ b/resources/lib/std/mem.c3 @@ -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 { diff --git a/resources/testfragments/comparisons.c3 b/resources/testfragments/comparisons.c3 index 711b6aa45..9356036e6 100644 --- a/resources/testfragments/comparisons.c3 +++ b/resources/testfragments/comparisons.c3 @@ -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"); diff --git a/resources/testfragments/compiletest.c3 b/resources/testfragments/compiletest.c3 index f7dd9d023..a39232ba3 100644 --- a/resources/testfragments/compiletest.c3 +++ b/resources/testfragments/compiletest.c3 @@ -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; } diff --git a/resources/testfragments/conversion.c3 b/resources/testfragments/conversion.c3 deleted file mode 100644 index ed8468d02..000000000 --- a/resources/testfragments/conversion.c3 +++ /dev/null @@ -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; -} \ No newline at end of file diff --git a/resources/testfragments/sdl2.c3 b/resources/testfragments/sdl2.c3 index 6730e8b70..e13a338ea 100644 --- a/resources/testfragments/sdl2.c3 +++ b/resources/testfragments/sdl2.c3 @@ -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); diff --git a/resources/testfragments/super_simple.c3 b/resources/testfragments/super_simple.c3 deleted file mode 100644 index a54371e92..000000000 --- a/resources/testfragments/super_simple.c3 +++ /dev/null @@ -1,1699 +0,0 @@ -module bar; -import baz; -import gen; - -typedef int as Bob; - - - - -/* -func void testVararg(int foo, ... args) -{ - @args.start(); - int i = @args.next(i, int); - @args.end(); -}*/ - -/* -macro namespaceFor(ns; void(int i) $body) -{ - for (usize i = 0; i < ns.avail; i++) - { - @$body(i); - } -} - -macro usize nameHashFn(char *strp, usize strl) -{ - usize hash = 5381; - for (usize i = 0; i < strl; i++) - { - hash = ((hash << 5) + hash) ^ cast(strp[i] as usize); - } - return hash; -} - -macro INode *nodesGet(nodes as index) -{ - return cast(node + 1 as INode**)[index]; -} - -macro lexReturnPuncTok!(tok as skip as implicit lex, implicit srcp) -{ - lex.toktype = tok; - lex.tokp = srcp; - lex.srcp = srcp + skip; - return; -} -*/ -func int! testThrow4(int x) -{ - return x > 4 ? TestErr1! : TestErr2!; -} - -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 -} - -$if (false) { - -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 -} - -} - - - - - -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 testIf() -{ - - int a = 0; - int b = 1; - if (a, b) - { - printf("Yes!\n"); - } - if (int x = 0, int y = 2) - { - printf("Yes: %d/%d\n", x, y); - } - if (int x = 2, int y = 0) - { - printf("No: %d/%d\n", x, y); - } - int! z = 67; - - try (int j = z, int k = z + 1) - { - printf("Check: %d %d\n", j, k); - } - try (z) - { - printf("Show :%d", z); - } -} - - -func void testPointer() -{ - int i = 0; - int *x = &i; - int y = x[2]; - *x; -} -func void testUnion() -{ - int wdw = 123; - cast(wdw as long); - wdw = 222; - 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 }; - - - SimpleUnion y = s = { 2 }; - double yval = SimpleUnion{ f = 3.333 }.f; - printf("Union y: %d\n", y.a); - printf("Union simple: %f\n", yval); -} - -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 switchTest() -{ - - switch FOO: (cast(1 as int)) - { - case 1: - printf("1\n"); - next FOO:3; - case 2: - printf("2\n"); - next 4; - case 3: - printf("3\n"); - next 2; - case 4: - printf("4\n"); - } -} - -func int jumptest() -{ - - do LABELX: - { - if (0) break LABELX; - printf("Hello\n"); - }; - do LABELX: - { - if (1) break LABELX; - return 1; - } while(1); - do LABELX: - { - if (1) continue LABELX; - return 1; - } while(0); - - return 2; -} -/* -func int! borok() -{ - return 1; -}*/ - - - - -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("Testing:\n"); - printf("a = %d, b = %d (2), 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), cast(sinit.z2 as int)); - if (sinit.a != 1) printf("ERROR a\n"); - if (sinit.b != 2) printf("ERROR b\n"); - if (sinit.d != 3.0) printf("ERROR d\n"); - if (sinit.z1 != 1) printf("ERROR z1\n"); - snoinit.b = 1; - snoinit.a = 100; - snoinit.d = 3.0; - snoinit.c = 2.0; - snoinit.z1 = 1; - snoinit.z2 = 2; - printf("b = %d (1), d = %f (3.0), z1 = %d (1)\n", snoinit.b, snoinit.d, snoinit.z1); - if (snoinit.b != 1) printf("ERROR b\n"); - if (snoinit.d != 3.0) printf("ERROR d\n"); - if (snoinit.z1 != 1) printf("ERROR z1\n"); -} - -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 = AnonStruct { a = 1 }; - // Foo { a = 1 } - foo.b2 = 123; - return foo; -} - -func void testAnonStruct2() -{ - sendAnonStruct(); -} - - -func void testAnonStruct() -{ - - AnonStruct s = { b2 = 3, b1 = 7, xx.b = 1 }; - AnonStruct foo; - - if (s.a != 0) printf("Error s.a\n"); - if (s.x != 0) printf("Error s.x\n"); - if (s.xx.b != 1) printf("Error s.xx.b = %d\n", s.xx.b); - if (s.xx.c != 0) printf("Error s.xx.c\n"); - if (s.b1 != 7) printf("Error s.b1\n"); - if (s.c1 != 0) printf("Error s.c1\n"); - if (s.b2 != 3) printf("Error s.b2\n"); - if (s.c2 != 3) printf("Error s.c2\n"); - - s.xx.b = 100; - s.xx.c = 99; - s.b1 = 3; - s.b2 = 5; - s.c2 = 7; - - if (s.a != 0) printf("Error s.a\n"); - if (s.x != 0) printf("Error s.x\n"); - if (s.xx.b != 100) printf("Error s.xx.b = %d\n", s.xx.b); - if (s.xx.c != 99) printf("Error s.xx.c\n"); - if (s.b1 != 3) printf("Error s.b1\n"); - if (s.c1 != 0) printf("Error s.c1\n"); - if (s.b2 != 7) printf("Error s.b2\n"); - if (s.c2 != 7) printf("Error s.c2\n"); - - s = { xx = { c = 2 }}; - - if (s.a != 0) printf("Error s.a\n"); - if (s.x != 0) printf("Error s.x\n"); - if (s.xx.b != 0) printf("Error s.xx.b = %d\n", s.xx.b); - if (s.xx.c != 2) printf("Error s.xx.c\n"); - if (s.b1 != 0) printf("Error s.b1\n"); - if (s.c1 != 0) printf("Error s.c1\n"); - if (s.b2 != 0) printf("Error s.b2\n"); - if (s.c2 != 0) printf("Error s.c2\n"); - - s.xx.c = 3; - s.x = 1212; - s.a = 29183; - s = AnonStruct { xx = { c = 2 }}; - - if (s.a != 0) printf("Error s.a\n"); - if (s.x != 0) printf("Error s.x\n"); - if (s.xx.b != 0) printf("Error s.xx.b = %d\n", s.xx.b); - if (s.xx.c != 2) printf("Error s.xx.c\n"); - if (s.b1 != 0) printf("Error s.b1\n"); - if (s.c1 != 0) printf("Error s.c1\n"); - if (s.b2 != 0) printf("Error s.b2\n"); - if (s.c2 != 0) printf("Error s.c2\n"); - - s = sendAnonStruct(); - - if (s.a != 1) printf("Error s.a\n"); - if (s.x != 0) printf("Error s.x\n"); - if (s.xx.b != 0) printf("Error s.xx.b = %d\n", s.xx.b); - if (s.xx.c != 0) printf("Error s.xx.c\n"); - if (s.b1 != 0) printf("Error s.b1\n"); - if (s.c1 != 0) printf("Error s.c1\n"); - if (s.b2 != 123) printf("Error s.b2\n"); - if (s.c2 != 123) printf("Error s.c2\n"); - -} -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; - - - 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 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 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) -{ - - - do LABELD: - { - x += 10; - defer printf("XXX"); - if (x < 100) break LABELD; - defer printf("EODfe"); - }; - { - defer printf("Defer says hello!\n"); - x--; - } - 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); -} - -int foofei = 3; - -func int testReturnDefer() -{ - int i = 0; - foofei++; - i++; - defer ++i; - return i; -} - -struct WithArray -{ - int[4] x; -} - -error TestErr1; -error TestErr2; - -func void testErr1() -{ - -} - -struct Feok -{ - long a; - long b; - long c; -} - -error FooErr -{ - int x; - int y; -} - -func int! testThrow1() -{ - return TestErr1!; -} - - -func int frob(int i) -{ - return i * i; -} - - -func void show() -{ - int! num = 3; - num = frob(num + 1); - printf("Num: %d\n", num); -} -func void! testAllErrors() -{ - - printf("Try test all\n"); - int! i = 7; - int*! iptr = &i; - int* xd = iptr!!; - printf("%d\n", *xd); - int**! iptrptr = &iptr; - catch (err = iptrptr) - { - printf("Unexpected error!\n"); - } - catch (i = **iptrptr) - { - printf("Unexpected error!\n"); - } - bool! hej = (i + 1); - try (hej) - { - printf("Was clean!\n"); - } - i = TestErr1!; - hej = (i + 1); - catch (hej) printf("Not clean!\n"); - i = 2938; - try(i) printf("Fine? %d\n", i); - catch(i) printf("Not fine\n"); - try (int j = i) - { - printf("Gotcha %d\n", j); - } - int hupp = 3; - iptr = &hupp; - iptr = TestErr1!; - catch (err = *iptr) - { - printf("Expected error!\n"); - } - - i = 2; - Feok z; - z.a = 1; - Feok! x = z; - int! j; - j = i; - j = TestErr1!; - FooErr fex = FooErr { 1, 3 }; - fex.x = 2; - printf("Fex: %d\n", fex.x); - error test33 = fex; - FooErr fex2 = cast(test33 as FooErr); - printf("Fex2: %d\n", fex.x); - TestErr1 eok = TestErr1{}; - error e = eok; - catch (err = x) - { - printf("Error!\n"); - } - catch (err = j) - { - case FooErr: - printf("FooErr\n"); - case TestErr1: - printf("TestErr1\n"); - default: - printf("Default error!\n"); - } - printf("No error!\n"); - int! flow = 1; - catch (flow) return; - int xy = flow; - - catch (err = i) return; - if (i > 0) - { - printf("Ok!\n"); - } - i = TestErr1!; -/* Error if (i > 0) - { - printf("Not ok!\n"); - }*/ - -} - - - - - -func int! testThrow6(int x) -{ - if (x > 4) return TestErr1!; - return TestErr2!; -} - - -func int! testThrow(int x) -{ - throwsDone.times++; - if (x < 0) return TestErr1!; - return x * x; -} -func int! oekt() -{ - int z = testThrow(-1) else return 1; - printf("Skipped.\n"); - int! x = testThrow(-3); - catch (err = x) - { -// printf("An error %p\n" as cast(err as usize)); - return err!; - } - return x; -} -func int! testThrowAny(int x) -{ - if (x < 0) return TestErr1!; - return x * x; -} -func void testErrorBug() -{ - printf("Test error multi\n"); - printf("Will call\n"); - catch(oekt()) - { - case TestErr1: - printf("Expected particular error.\n"); - default: - error foo = TestErr2{}; - //printf("Not expected %p != %p\n" as cast(e as usize) as cast(foo as usize)); - printf("Unexpected any error error.\n"); - } - printf("End\n"); -} -func void testErrorMulti() -{ - defer printf("End defer\n"); - int! z; - printf("Test error multi\n"); - { - defer printf("Defer\n"); - printf("Will call\n"); - z = oekt(); - printf("Got here\n"); - } - catch (e = z) - { - case TestErr1: - printf("Expected particular error.\n"); - default: - error foo = TestErr1{}; -// printf("Not expected %p != %p\n" as cast(e as usize) as cast(foo as usize)); - printf("Unexpected any error error.\n"); - } - printf("End\n"); -} - -func void! throwAOrB(int i) -{ - printf("AB\n"); - defer printf("A-Err\n"); - if (i == 1) return TestErr1!; - printf("B\n"); - defer printf("B-Err\n"); - if (i == 2) return TestErr2!; - printf("None\n"); -} - -struct ThrowsDone -{ - long x; - long y; - long z; - int times; -} -ThrowsDone throwsDone; - -func void testErrors() -{ - - printf("Throws: %d\n", throwsDone.times); - - int x = testThrow(20) else 1; - printf("Value was %d, expected 400.\n", x); - - printf("Throws: %d\n", throwsDone.times); - - x = testThrow(-1) else 20; - printf("Value was %d, expected 20.\n", x); - - printf("Throws: %d\n", throwsDone.times); - - printf("Begin\n"); - int! y = testThrow(-1); - - try (y) - { - printf("Value was %d, expected 9.\n", y); - printf("Didn't expect this one.\n"); - } - catch(y) - { - printf("Expected this catch.\n"); - } - - y = testThrow(-1); - catch (y) - { - printf("Particular error.\n"); - } - testErrorMulti(); - - catch (throwAOrB(1)) - { - case TestErr1: - printf("A1\n"); - case TestErr2: - printf("A2\n"); - } - catch (throwAOrB(2)) - { - case TestErr1: - printf("B1\n"); - case TestErr2: - printf("B2\n"); - } - printf("Throws: %d\n", throwsDone.times); - printf("End of errors\n"); -} - -macro void arrayCallMacro($x) -{ - printf("Array call: %d, %d\n", $x[0], $x[1]); -} - -typedef func int(int) as IntInt; - -func int funcTest(int i) -{ - return i * i; -} - -func void testFuncPointer() -{ - IntInt bobd = &funcTest; - int x = bobd(2); - printf("Func test: %d\n", x); - printf("Func test: %d\n", bobd(100)); -} - -func void arrayCall(int[2] x) @inline @weak @align(16) @cname("Foo") -{ - printf("Array call: %d, %d\n", x[0], x[1]); -} -func void testArray() -{ - int[4] zebra = { [2] = 1 }; - int[4] deok = { 1, 5, 9, 16 }; - int[] sa = &deok; - int* sp = sa; - WithArray boo; - boo.x[0] = 2; - printf("boo.x[0] = %d\n", boo.x[0]); - printf("boo.x[2] = %d\n", boo.x[2]); - printf("sa[2] = %d\n", sa[2]); - printf("sa[3] = %d\n", sa[3]); - deok[2] = 100; - sa[1] = 999; - printf("sa[2] = %d\n", sa[2]); - printf("sp[2] = %d\n", sp[2]); - printf("deok[1] = %d\n", deok[1]); - int[2] two = { 142, 2 }; - arrayCall(two); - //@arrayCallMacro(two); - 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; - defer printf("-JUMPDEFER-"); - switch (int boo = 2) - { - case 0: - printf("\n0\n"); - case 2: - defer printf("*CaseDefer*"); - printf("-Case2-"); - default: - break; - } - defer printf("7"); - printf("6"); -} - -func void testType() -{ - printf("Test type\n"); - typeid x = WithArray.typeid; - int y = 0; - Teob b; - typeid structSize = typeof(b); -} - -struct Big -{ - long x; - long y; - long z; -} -func Big testStructReturn() -{ - return Big { 1, 2, 3}; -} - -func void testExprBlock() -{ - printf("ExprBlock\n"); - int x = ({ - int y = 1; - for (int i = 0; i < 100; i++) - { - printf("%d\n", i); - if (y % 3 == 0 && y % 2 == 0) return y; - y++; - } - return 100; - }); - printf("Was %d\n", x); -} - -typedef func int(int) as Blorb; - -func int eokf(int x) -{ - return x * x + 1; -} - -func void Big.init(Big* big) -{ - big.x = 1; - big.y = 2; - big.z = 3; -} -func void Big.mult(Big* big, int x) -{ - big.x *= x; - big.y *= x; - big.z *= x; -} - -struct Bork -{ - Big x; - Big y; -} -func void testMethodFunctions() -{ - Big b; - b.init(); - printf("%d %d %d\n", b.x, b.y, b.z); - b.mult(3); - printf("%d %d %d\n", b.x, b.y, b.z); - Bork x; - x.x.init(); - x.x.mult(4); - printf("%d %d %d\n", x.x.x, x.x.y, x.x.z); -} - -enum TestEnumSize : ushort -{ - BLURB -} - -enum TestEnumSizeDefault -{ - BLURB -} - -struct TestStructSize -{ - char x; - long y; -} - -struct TestStructInt -{ - int a; - int b; - int c; -} - -union TestUnionSize -{ - short a; - int b; - char[5] c; -} -func void testTypeValues() -{ - printf("Enum size: %d = 2\n", TestEnumSize.sizeof); - printf("Enum size: %d = 4\n", TestEnumSizeDefault.sizeof); - printf("Struct size: %d = 12\n", TestStructInt.sizeof); - printf("Struct size: %d = 16\n", TestStructSize.sizeof); - printf("Union size: %d = 5\n", TestUnionSize.sizeof); -} - -func int testTypeofHelp() -{ - return 2; -} - -func void testTypeof() -{ - typeid y = typeof(1 + testTypeofHelp()); -} - -macro void printMessage($x) -{ - for (int i = 0; i < $x; i++) - { - printf("print message! %d\n", i); - } - $x = $x + 1; -} - -func void testMacros() -{ - int i = 3; - @printMessage(i); - printf("i: %d\n", i); -} - -/* -const char[] LUT_ENC = { - 'A', 'B', 'C', 'D', 'E', 'F', 'G', 'H', - 'I', 'J', 'K', 'L', 'M', 'N', 'O', 'P', - 'Q', 'R', 'S', 'T', 'U', 'V', 'W', 'X', - 'Y', 'Z', 'a', 'b', 'c', 'd', 'e', 'f', - 'g', 'h', 'i', 'j', 'k', 'l', 'm', 'n', - 'o', 'p', 'q', 'r', 's', 't', 'u', 'v', - 'w', 'x', 'y', 'z', '0', '1', '2', '3', - '4', '5', '6', '7', '8', '9', '+', '/', -}; -*/ -//const byte ERR = 0xFF; - -/* -const byte[256] LUT_DEC = { - // '+', ',', '-', '.', '/', '0', '1', '2' - 62, ERR, ERR, ERR, 63, 52, 53, 54, - // '3', '4', '5', '6', '7', '8', '9', ':' - 55, 56, 57, 58, 59, 60, 61, ERR, - // ';', '<', '=', '>', '?', '@', 'A', 'B' - ERR, ERR, ERR, ERR, ERR, ERR, 0, 1, - // 'C', 'D', 'E', 'F', 'G', 'H', 'I', 'J' - 2, 3, 4, 5, 6, 7, 8, 9, - // 'K', 'L', 'M', 'N', 'O', 'P', 'Q', 'R' - 10, 11, 12, 13, 14, 15, 16, 17, - // 'S', 'T', 'U', 'V', 'W', 'X', 'Y', 'Z' - 18, 19, 20, 21, 22, 23, 24, 25, - // '[', '\', ']', '^', '_', '`', 'a', 'b' - ERR, ERR, ERR, ERR, ERR, ERR, 26, 27, - // 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j' - 28, 29, 30, 31, 32, 33, 34, 35, - // 'k', 'l', 'm', 'n', 'o', 'p', 'q', 'r' - 36, 37, 38, 39, 40, 41, 42, 43, - // 's', 't', 'u', 'v', 'w', 'x', 'y', 'z' - 44, 45, 46, 47, 48, 49, 50, 51, -}; -*/ -/* -const char PAD = '='; -const char FIRST = '+'; -const char LAST = 'z'; -*/ -public error InvalidCharacterError; - -/* -public func void encode(byte[] infile, char[] *out) -{ - int j = 0; - - for (int i = 0; i < i.len; i++); - { - switch (i % 3) - { - case 0: - out[j++] = LUT_ENC[(infile[i] >> 2) & 0x3F]; - case 1: - out[j++] = LUT_ENC[(infile[i-1] & 0x3) << 4 + ((infile[i] >> 4) & 0xF)]; - case 2: - out[j++] = LUT_ENC[(infile[i-1] & 0xF) << 2 + ((infile[i] >> 6) & 0x3)]; - out[j++] = LUT_ENC[infile[i] & 0x3F]; - } - i++; - } - - // move back - int last = infile.len - 1; - - // check the last and add padding - switch (last % 3) - { - case 0: - out[j++] = LUT_ENC[(infile[last] & 0x3) << 4]; - out[j++] = PAD; - out[j++] = PAD; - case 1: - out[j++] = LUT_ENC[(infile[last] & 0xF) << 2]; - out[j++] = PAD; - } -} - -public func int! decode(char[] infile, byte[] out) -{ - int j = 0; - - for (int i = 0; i < len; i++) - { - char value = infile[i]; - - if (value == PAD) return j; - - if (value < FIRST || infile[i] > LAST) return InvalidCharacterError!; - byte c = LUT_DEC[infile[i] - FIRST]; - if (c == ERR) return InvalidCharacterError!; - - switch (i % 4) - { - case 0: - out[j] = c << 2; - case 1: - out[j++] += (c >> 4) & 0x3; - // if not last char with padding - if (i < (len - 3) || infile[len - 2] != PAD) - { - out[j] = (c & 0xF) << 4; - } - case 2: - out[j++] += (c >> 2) & 0xF; - if (i < (len -2) || infile[len -1] != PAD) - { - out[j] = (c & 0x3) << 6; - } - case 3: - out[j++] += c; - } - } - return j; -} -*/ - -func int main(int x) -{ - if (x < 0) printf("Hello\n"); - if (x - < 0) printf("Hello\n"); - - int[6] feok2 = { 1, 8, 100, 293, 23982, 34}; - int[] feok = &feok2; - int[] flok = feok2[3..6]; - int[] flak = flok[1..2]; - printf("HEllo\n"); - printf("Feok: %d\n", feok[0]); - printf("Feok: %d\n", feok[1]); - printf("Len: %d\n", feok.len); - printf("Len: %d\n", feok2.len); - printf("Len: %d\n", flok.len); - printf("Flok: %d\n", flok[0]); - printf("Flak: %d\n", flak[0]); - printf("Len: %d\n", flak.len); - feok2[1..^2] = 0xAA; - printf("Flok[0]: %d\n", flok[0]); - printf("Flok[1]: %d\n", flok[1]); - printf("Flok[2]: %d\n", flok[2]); - printf("Feok[0]: %d\n", feok[0]); - printf("Feok[1]: %d\n", feok[1]); - printf("Feok[2]: %d\n", feok[2]); - for (int ef = 0; ef < 6; ef++) - { - printf("feok2[%d] = %d\n", ef, feok2[ef]); - } - baz::runBaz(); - show(); - testMacros(); - testTypeof(); - testAllErrors(); - //testErrorBug(); - //testErrors(); - testDefault(y = 99); - testPointers(2, 3); - testDefer(); - testArray(); - testAnonStruct(); - testSimpleStruct(0); - testUnion(); - testType(); - testExprBlock(); - testFuncPointer(); - testMethodFunctions(); - testTypeValues(); - int efd = 9; - - uint fefoek = 1; - testIf(); - 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, int ko = 0, ok = 2; ok + ko < 10; ok++, ko++) - { - printf(":okko"); - } - printf("\n"); - int ok = 0; - while (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; - - do 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) continue JUMP; - break JUMP; - } while (1); - - return 1; -} - -func void teeeest() -{ - long z = 3; - (1 ? (z < 1 ? 2 : 1) : 3) == 3; - (1 ?: (z ?: 7)) == 4; - (1 ?: (3 ?: 7)) == 4; -} -func void test2(int* x, int y, 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; - 2 << g; - 3 >> 4; - 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; -} - -func void testBreak() -{ - - defer printf("ALL TESTS DONE\n"); - int i = 0; - int j = 0; - while (j < 2) - { - defer printf("Defer while %d\n", j); - break; - defer printf("Exit\n"); - } - do - { - defer printf("Defer do %d\n", j); - break; - defer printf("Exit\n"); - } while (j < 2); - - for (j = 0; j < 2; j++) - { - defer printf("Defer for %d\n", j); - break; - defer printf("Exit\n"); - } - - while (j < 2) - { - defer printf("Defer while %d\n", j); - j++; - continue; - defer printf("Exit\n"); - printf("ERROR\n"); - } - do - { - defer printf("Defer do %d\n", j); - j++; - continue; - defer printf("Exit\n"); - printf("ERROR\n"); - } while (j < 2); - - for (j = 0; j < 2; j++) - { - defer printf("Defer for %d\n", j); - continue; - defer printf("Exit\n"); - printf("ERROR\n"); - } - - if FOO: (i == 0) - { - printf("Enter if\n"); - i++; - defer("EXIT_FOO\n"); - while BAZ: (1) - { - defer("EXIT_BAZ\n"); - if BAR: (i > 0) break FOO; - } - printf("WRONG\n"); - } - printf("Test done\n"); - - while (i < 10) - { - i++; - if (i % 2 == 0) continue; - printf("%d\n", i); - if (i > 6) break; - } - - i = 0; - j = 0; - while FOO: (i < 10) - { - i++; - j = 0; - while (j < 3) - { - j++; - printf("%d, %d\n", i, j); - if ((i + j) % 3 == 0) continue FOO; - if (i + j > 8) break FOO; - } - } - i = 0; - do - { - i++; - if (i % 2 == 0) continue; - printf("%d\n", i); - if (i > 6) break; - } while (i < 10); - - i = 0; - do FOO: - { - i++; - j = 0; - while (j < 3) - { - j++; - printf("%d, %d\n", i, j); - if ((i + j) % 3 == 0) continue FOO; - if (i + j > 8) break FOO; - } - } while (i < 10); - - i = 0; - switch (i) - { - case 0: - printf("case0\n"); - break; - printf("ERROR\n"); - case 1: - printf("ERROR\n"); - } - - printf("TestFor\n"); - for (i = 0; i < 15; i++) - { - for (j = 0; j < 3; j++) - { - printf("%d, %d\n", i, j); - if ((i + j) % 3 == 0) continue; - if (i + j > 8) break; - } - } - - printf("TestFor2\n"); - for FOO: (i = 0; i < 12; i++) - { - for (j = 0; j < 3; j++) - { - printf("%d, %d\n", i, j); - if ((i + j) % 3 == 0) continue FOO; - if (i + j > 8) break FOO; - } - } - printf("Test1\n"); - i = 0; - switch FOO: (i) - { - case 0: - defer printf("Test1DeferOuter\n"); - while (1) - { - printf("case0\n"); - defer printf("Test1DeferInner\n"); - break FOO; - } - printf("ERROR\n"); - case 1: - printf("ERROR\n"); - } - printf("Test2\n"); - switch FOO: (i) - { - case 0: - printf("case0\n"); - defer printf("Test2DeferNext\n"); - next; - case 1: - defer printf("Test2DeferCase\n"); - printf("case1\n"); - } - printf("Test3\n"); - switch FOO: (i) - { - case 0: - defer printf("Test3DeferNext\n"); - printf("case0\n"); - next 2; - case 1: - defer printf("Test3DeferErr\n"); - printf("case1\n"); - case 2: - defer printf("Test3DeferCase\n"); - printf("case2\n"); - } - printf("Test4\n"); - switch FOO: (i) - { - case 0: - printf("case0\n"); - defer printf("OuterDefer\n"); - switch (i) - { - case 0: - printf("Inner\n"); - defer printf("InnerDefer\n"); - next FOO:2; - case 2: - printf("ERROR\n"); - } - next 1; - case 1: - printf("case1\n"); - case 2: - defer printf("Case2Defer\n"); - printf("case2\n"); - } - printf("Test5\n"); - switch FOO: (i) - { - case 0: - defer printf("DEFER\n"); - printf("case0\n"); - switch (i) - { - case 0: - printf("Inner\n"); - defer printf("DEFERINNER\n"); - int k = 1; - next FOO: k; - case 2: - printf("ERROR\n"); - } - next 1; - case 1: - printf("case1\n"); - case 2: - printf("case2\n"); - } - - i = 0; - switch FOO: (i) - { - case 0: - printf("0: %d\n", i); - i++; - next i; - case 1: - i += 2; - defer printf("DEFER1\n"); - printf("1: %d\n", i); - next i; - case 2: - printf("2: END\n", i); - case 3: - i--; - printf("3: %d\n", i); - next i; - default: - printf("WAAAIT\n"); - } -} \ No newline at end of file diff --git a/resources/testfragments/super_simple2.c3 b/resources/testfragments/super_simple2.c3 deleted file mode 100644 index 52a0471bc..000000000 --- a/resources/testfragments/super_simple2.c3 +++ /dev/null @@ -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() -{ - -} \ No newline at end of file diff --git a/resources/testfragments/super_simple3.c3 b/resources/testfragments/super_simple3.c3 deleted file mode 100644 index 1a82e2221..000000000 --- a/resources/testfragments/super_simple3.c3 +++ /dev/null @@ -1,6 +0,0 @@ -module gen (Type); -/* -struct BobaFett -{ - Type x; -}*/ \ No newline at end of file diff --git a/resources/testfragments/testscrap.c3 b/resources/testfragments/testscrap.c3 deleted file mode 100644 index 29fb777ba..000000000 --- a/resources/testfragments/testscrap.c3 +++ /dev/null @@ -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; -} - diff --git a/test/test_suite/cast/cast_struct.c3 b/test/test_suite/cast/cast_struct.c3 index 9089a6c10..594a1cce0 100644 --- a/test/test_suite/cast/cast_struct.c3 +++ b/test/test_suite/cast/cast_struct.c3 @@ -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); } diff --git a/test/test_suite/cast/cast_struct_fails.c3 b/test/test_suite/cast/cast_struct_fails.c3 index b03eb13fc..d6114b65b 100644 --- a/test/test_suite/cast/cast_struct_fails.c3 +++ b/test/test_suite/cast/cast_struct_fails.c3 @@ -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' } diff --git a/test/test_suite/constants/constants.c3t b/test/test_suite/constants/constants.c3t index 49dc6a3f7..79826ad6f 100644 --- a/test/test_suite/constants/constants.c3t +++ b/test/test_suite/constants/constants.c3t @@ -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() diff --git a/test/test_suite/distinct/distinct_struct.c3 b/test/test_suite/distinct/distinct_struct.c3 index 0b045896a..64d617365 100644 --- a/test/test_suite/distinct/distinct_struct.c3 +++ b/test/test_suite/distinct/distinct_struct.c3 @@ -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 }; diff --git a/test/test_suite/distinct/distinct_union.c3 b/test/test_suite/distinct/distinct_union.c3 index 95f210af6..b430a824c 100644 --- a/test/test_suite/distinct/distinct_union.c3 +++ b/test/test_suite/distinct/distinct_union.c3 @@ -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 }; diff --git a/test/test_suite/distinct/test_ops_on_int.c3 b/test/test_suite/distinct/test_ops_on_int.c3 index b6b52a90f..b5e60b6a4 100644 --- a/test/test_suite/distinct/test_ops_on_int.c3 +++ b/test/test_suite/distinct/test_ops_on_int.c3 @@ -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); } diff --git a/test/test_suite/distinct/test_ops_on_struct.c3 b/test/test_suite/distinct/test_ops_on_struct.c3 index 3908fc55d..94fd66590 100644 --- a/test/test_suite/distinct/test_ops_on_struct.c3 +++ b/test/test_suite/distinct/test_ops_on_struct.c3 @@ -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 } }; } \ No newline at end of file diff --git a/test/test_suite/examples/gameoflife.c3 b/test/test_suite/examples/gameoflife.c3 index 913ba4373..c0e7b7c68 100644 --- a/test/test_suite/examples/gameoflife.c3 +++ b/test/test_suite/examples/gameoflife.c3 @@ -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++) diff --git a/test/test_suite/expressions/casts/cast_const.c3 b/test/test_suite/expressions/casts/cast_const.c3 index 67baa5007..a85552f24 100644 --- a/test/test_suite/expressions/casts/cast_const.c3 +++ b/test/test_suite/expressions/casts/cast_const.c3 @@ -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' } diff --git a/test/test_suite/expressions/casts/cast_enum_to_various.c3 b/test/test_suite/expressions/casts/cast_enum_to_various.c3 index d98cca7dc..93622baf2 100644 --- a/test/test_suite/expressions/casts/cast_enum_to_various.c3 +++ b/test/test_suite/expressions/casts/cast_enum_to_various.c3 @@ -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' } diff --git a/test/test_suite/expressions/casts/cast_expr.c3t b/test/test_suite/expressions/casts/cast_expr.c3t index a33cc9887..01f49855f 100644 --- a/test/test_suite/expressions/casts/cast_expr.c3t +++ b/test/test_suite/expressions/casts/cast_expr.c3t @@ -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; } diff --git a/test/test_suite/expressions/casts/cast_func_to_various.c3 b/test/test_suite/expressions/casts/cast_func_to_various.c3 index 3fbdbbca6..c02c80412 100644 --- a/test/test_suite/expressions/casts/cast_func_to_various.c3 +++ b/test/test_suite/expressions/casts/cast_func_to_various.c3 @@ -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'. } diff --git a/test/test_suite/expressions/casts/cast_to_nonscalar.c3 b/test/test_suite/expressions/casts/cast_to_nonscalar.c3 index 153debd1a..619409fca 100644 --- a/test/test_suite/expressions/casts/cast_to_nonscalar.c3 +++ b/test/test_suite/expressions/casts/cast_to_nonscalar.c3 @@ -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' } diff --git a/test/test_suite/expressions/casts/cast_unknown.c3 b/test/test_suite/expressions/casts/cast_unknown.c3 index 8bd195879..218aa2ab5 100644 --- a/test/test_suite/expressions/casts/cast_unknown.c3 +++ b/test/test_suite/expressions/casts/cast_unknown.c3 @@ -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. } diff --git a/test/test_suite/expressions/casts/explicit_cast.c3 b/test/test_suite/expressions/casts/explicit_cast.c3 index 1bcd25d1b..c43db992f 100644 --- a/test/test_suite/expressions/casts/explicit_cast.c3 +++ b/test/test_suite/expressions/casts/explicit_cast.c3 @@ -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'. } \ No newline at end of file diff --git a/test/test_suite/expressions/pointer_conv_error.c3 b/test/test_suite/expressions/pointer_conv_error.c3 index 2e825d59d..0e1681dec 100644 --- a/test/test_suite/expressions/pointer_conv_error.c3 +++ b/test/test_suite/expressions/pointer_conv_error.c3 @@ -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*'. } diff --git a/test/test_suite/functions/assorted_tests.c3t b/test/test_suite/functions/assorted_tests.c3t index ecf1b4f37..b78c619f3 100644 --- a/test/test_suite/functions/assorted_tests.c3t +++ b/test/test_suite/functions/assorted_tests.c3t @@ -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 diff --git a/test/test_suite/functions/double_return.c3t b/test/test_suite/functions/double_return.c3t index 6d158e208..fae952c56 100644 --- a/test/test_suite/functions/double_return.c3t +++ b/test/test_suite/functions/double_return.c3t @@ -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 diff --git a/test/test_suite/macros/generic_common.c3 b/test/test_suite/macros/generic_common.c3 index f776b790b..caaeaa3fa 100644 --- a/test/test_suite/macros/generic_common.c3 +++ b/test/test_suite/macros/generic_common.c3 @@ -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; } diff --git a/test/test_suite/statements/foreach_common.c3t b/test/test_suite/statements/foreach_common.c3t index 9cebccda6..93b6cb5ae 100644 --- a/test/test_suite/statements/foreach_common.c3t +++ b/test/test_suite/statements/foreach_common.c3t @@ -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) { diff --git a/test/test_suite/types/enum_inference.c3 b/test/test_suite/types/enum_inference.c3 index 7e1804bc0..35212eb9d 100644 --- a/test/test_suite/types/enum_inference.c3 +++ b/test/test_suite/types/enum_inference.c3 @@ -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: diff --git a/test/test_suite/union/union_member_voidcast.c3 b/test/test_suite/union/union_member_voidcast.c3 index 4d2866085..cd2e20022 100644 --- a/test/test_suite/union/union_member_voidcast.c3 +++ b/test/test_suite/union/union_member_voidcast.c3 @@ -8,6 +8,6 @@ union Xu func Xu foo() { Xu a; - a.b = cast(123 as void*); + a.b = (void*)(123); return a; } \ No newline at end of file