Updated cast syntax in code samples.

This commit is contained in:
Christoffer Lerno
2021-05-18 17:23:27 +02:00
parent 216467cbf8
commit fc31c15914
50 changed files with 113 additions and 2770 deletions

View File

@@ -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;
}

View File

@@ -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--)
{

View File

@@ -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;
}

View File

@@ -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 */

View File

@@ -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.");
}

View File

@@ -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));
}
/**

View File

@@ -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 */

View File

@@ -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:

View File

@@ -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

View File

@@ -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

View File

@@ -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);
}
}

View File

@@ -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++)
{

View File

@@ -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) {

View File

@@ -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)

View File

@@ -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)

View File

@@ -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;

View File

@@ -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)