mirror of
https://github.com/c3lang/c3c.git
synced 2026-02-27 12:01:16 +00:00
Complete transition to fn. Introduce global/threadlocal
This commit is contained in:
committed by
Christoffer Lerno
parent
e2621617f1
commit
b52b42d4da
@@ -246,11 +246,11 @@ contexts [] {
|
||||
decls : context
|
||||
{
|
||||
: pattern {
|
||||
regex \= (func\s+)($${__SCOPE})?($${__USERTYPE})?($${__BUILTIN_TYPE})?(\s+$${__IDENT})
|
||||
regex \= (fn\s+)($${__SCOPE})?($${__USERTYPE})?($${__BUILTIN_TYPE})?(\s+$${__IDENT})
|
||||
styles [] = .declare, .text, .text, .type, .type_builtin, .function_decl;
|
||||
}
|
||||
: pattern {
|
||||
regex \= (func\s+)($${__SCOPE})?($${__USERTYPE})?($${__BUILTIN_TYPE})?(\s+$${__IDENT})
|
||||
regex \= (fn\s+)($${__SCOPE})?($${__USERTYPE})?($${__BUILTIN_TYPE})?(\s+$${__IDENT})
|
||||
styles [] = .declare, .text, .text, .type, .type_builtin, .function_decl;
|
||||
}
|
||||
: pattern {
|
||||
@@ -289,7 +289,7 @@ main : context {
|
||||
|
||||
: include "top_level";
|
||||
: pattern {
|
||||
regex \= (define|extern|if|module|import|func|struct|while|do|return|union|errtype)
|
||||
regex \= (define|extern|if|module|import|fn|struct|while|do|return|union|errtype)
|
||||
styles [] = .keyword;
|
||||
}
|
||||
|
||||
|
||||
@@ -18,7 +18,7 @@ color normal "\(|\)"
|
||||
color green "\<(virtual|anyerr|void|bool|quad|double|float|long|ulong|int|uint|short|ushort|ichar|char|isize|usize|iptr|uptr|iptrdiff|uptrdiff|half)\>"
|
||||
|
||||
# Keywords
|
||||
color yellow "\<(alias|as|asm|assert|attribute|break|case|catch|const|continue|default|defer|define|do|else|enum|extern|errtype|false|for|foreach|func|generic|if|import|interface|macro|module|nextcase|null|private|return|static|struct|switch|true|try|typeid|typeof|union|while|var|volatile|yield)\>"
|
||||
color yellow "\<(alias|as|asm|assert|attribute|break|case|catch|const|continue|default|defer|define|do|else|enum|extern|errtype|false|for|foreach|fn|generic|if|import|interface|macro|module|nextcase|null|private|return|static|struct|switch|true|try|typeid|typeof|union|while|var|volatile|yield)\>"
|
||||
|
||||
# $ Statements
|
||||
color brightyellow "\$\<(assert|case|default|elif|else|endif|endswitch|for|if|switch|unreachable)\>"
|
||||
|
||||
@@ -42,7 +42,7 @@ const char PAD = '=';
|
||||
const char FIRST = '+';
|
||||
const char LAST = 'z';
|
||||
|
||||
func void encode(char[] in, char *out)
|
||||
fn void encode(char[] in, char *out)
|
||||
{
|
||||
int j = 0;
|
||||
char c = LUT_ENC[1];
|
||||
@@ -76,7 +76,7 @@ func void encode(char[] in, char *out)
|
||||
}
|
||||
|
||||
|
||||
func int! decode(char[] in, char* out, int* invalid_char_index = null)
|
||||
fn int! decode(char[] in, char* out, int* invalid_char_index = null)
|
||||
{
|
||||
int j = 0;
|
||||
|
||||
@@ -118,9 +118,9 @@ func int! decode(char[] in, char* out, int* invalid_char_index = null)
|
||||
return j;
|
||||
}
|
||||
|
||||
extern func void printf(char *fmt, ...);
|
||||
extern fn void printf(char *fmt, ...);
|
||||
|
||||
func void main()
|
||||
fn void main()
|
||||
{
|
||||
char *helloworld = "Hello World\n";
|
||||
char[1000] buffer;
|
||||
|
||||
@@ -7,9 +7,9 @@ macro int factorial($n)
|
||||
$endif;
|
||||
}
|
||||
|
||||
extern func void printf(char *fmt, ...);
|
||||
extern fn void printf(char *fmt, ...);
|
||||
|
||||
func void main()
|
||||
fn void main()
|
||||
{
|
||||
int x = @factorial(12);
|
||||
printf("12! = %d\n", x);
|
||||
|
||||
@@ -8,7 +8,7 @@ macro int max(int a, int b)
|
||||
return a > b ? a : b;
|
||||
}
|
||||
|
||||
func int fannkuchredux(int n)
|
||||
fn int fannkuchredux(int n)
|
||||
{
|
||||
int* perm = @array::make(int, n);
|
||||
int* perm1 = @array::make(int, n);
|
||||
@@ -72,7 +72,7 @@ func int fannkuchredux(int n)
|
||||
return 0;
|
||||
}
|
||||
|
||||
func int main(int argc, char** argv)
|
||||
fn int main(int argc, char** argv)
|
||||
{
|
||||
int n = argc > 1 ? libc::atoi(argv[1]) : 7;
|
||||
libc::printf("Pfannkuchen(%d) = %d\n", n, fannkuchredux(n));
|
||||
|
||||
@@ -6,15 +6,15 @@ const IA = 3877;
|
||||
const IC = 29573;
|
||||
const SEED = 42;
|
||||
|
||||
uint seed = SEED;
|
||||
global uint seed = SEED;
|
||||
|
||||
func float fasta_rand(float max)
|
||||
fn float fasta_rand(float max)
|
||||
{
|
||||
seed = (seed * IA + IC) % IM;
|
||||
return max * seed / IM;
|
||||
}
|
||||
|
||||
private char[] alu =
|
||||
private global char[] alu =
|
||||
"GGCCGGGCGCGGTGGCTCACGCCTGTAATCCCAGCACTTTGG"
|
||||
"GAGGCCGAGGCGGGCGGATCACCTGAGGTCAGGAGTTCGAGA"
|
||||
"CCAGCCTGGCCAACATGGTGAAACCCCGTCTCTACTAAAAAT"
|
||||
@@ -24,8 +24,8 @@ private char[] alu =
|
||||
"AGCCTGGGCGACAGAGCGAGACTCCGTCTCAAAAA";
|
||||
|
||||
|
||||
char[] iub = "acgtBDHKMNRSVWY";
|
||||
double[] iub_p = {
|
||||
global char[] iub = "acgtBDHKMNRSVWY";
|
||||
global double[] iub_p = {
|
||||
0.27,
|
||||
0.12,
|
||||
0.12,
|
||||
@@ -42,8 +42,8 @@ double[] iub_p = {
|
||||
0.02,
|
||||
0.02 };
|
||||
|
||||
char[] homosapiens = "acgt";
|
||||
double[] homosapiens_p = {
|
||||
global char[] homosapiens = "acgt";
|
||||
global double[] homosapiens_p = {
|
||||
0.3029549426680,
|
||||
0.1979883004921,
|
||||
0.1975473066391,
|
||||
@@ -53,7 +53,7 @@ double[] homosapiens_p = {
|
||||
const LINELEN = 60;
|
||||
|
||||
// slowest character-at-a-time output
|
||||
func void repeat_fasta(char[] seq, int n)
|
||||
fn void repeat_fasta(char[] seq, int n)
|
||||
{
|
||||
usize len = seq.len;
|
||||
int i = void;
|
||||
@@ -65,7 +65,7 @@ func void repeat_fasta(char[] seq, int n)
|
||||
if (i % LINELEN != 0) libc::putchar('\n');
|
||||
}
|
||||
|
||||
func void random_fasta(char[] symb, double[] probability, int n)
|
||||
fn void random_fasta(char[] symb, double[] probability, int n)
|
||||
{
|
||||
assert(symb.len == probability.len);
|
||||
int len = probability.len;
|
||||
@@ -86,7 +86,7 @@ func void random_fasta(char[] symb, double[] probability, int n)
|
||||
if (i % LINELEN != 0) libc::putchar('\n');
|
||||
}
|
||||
|
||||
func void main(int argc, char **argv)
|
||||
fn void main(int argc, char **argv)
|
||||
{
|
||||
int n = 1000;
|
||||
if (argc > 1) n = libc::atoi(argv[1]);
|
||||
|
||||
@@ -1,12 +1,12 @@
|
||||
module game_of_life;
|
||||
|
||||
extern func void printf(char *fmt, ...);
|
||||
extern func int atoi(char *val);
|
||||
extern fn void printf(char *fmt, ...);
|
||||
extern fn int atoi(char *val);
|
||||
extern void *__stdoutp;
|
||||
extern func void fflush(void *std);
|
||||
extern func int rand();
|
||||
extern func void* malloc(usize size);
|
||||
extern func void usleep(int time);
|
||||
extern fn void fflush(void *std);
|
||||
extern fn int rand();
|
||||
extern fn void* malloc(usize size);
|
||||
extern fn void usleep(int time);
|
||||
|
||||
|
||||
struct GameBoard
|
||||
@@ -17,7 +17,7 @@ struct GameBoard
|
||||
char* temp;
|
||||
}
|
||||
|
||||
func void GameBoard.show(GameBoard *board)
|
||||
fn void GameBoard.show(GameBoard *board)
|
||||
{
|
||||
|
||||
printf("\e[H");
|
||||
@@ -34,7 +34,7 @@ func void GameBoard.show(GameBoard *board)
|
||||
fflush(__stdoutp);
|
||||
}
|
||||
|
||||
func void GameBoard.evolve(GameBoard *board)
|
||||
fn void GameBoard.evolve(GameBoard *board)
|
||||
{
|
||||
for (int y = 0; y < board.h; y++)
|
||||
{
|
||||
@@ -61,7 +61,7 @@ func void GameBoard.evolve(GameBoard *board)
|
||||
}
|
||||
|
||||
|
||||
func int main(int c, char** v)
|
||||
fn int main(int c, char** v)
|
||||
{
|
||||
int w = 0;
|
||||
int h = 0;
|
||||
|
||||
@@ -5,7 +5,7 @@ import libc;
|
||||
// The code below should not be considered *correct*
|
||||
// They are merely done to illustrate the language syntax.
|
||||
|
||||
func void main()
|
||||
fn void main()
|
||||
{
|
||||
char[] y = "Hello World!";
|
||||
libc::printf("Adler32 of %s is %x, expected 1c49043e\n", (char*)(y), adler32(y));
|
||||
@@ -17,7 +17,7 @@ func void main()
|
||||
libc::printf("FNV64a of %s is %llx, expected 8c0ec8d1fb9e6e32\n", (char*)(y), fnv64a(y));
|
||||
}
|
||||
|
||||
func uint adler32(char[] data)
|
||||
fn uint adler32(char[] data)
|
||||
{
|
||||
const uint ADLER_CONST = 65521;
|
||||
uint a = 1;
|
||||
@@ -30,7 +30,7 @@ func uint adler32(char[] data)
|
||||
return (b << 16) | a;
|
||||
}
|
||||
|
||||
func uint crc32(char[] data)
|
||||
fn uint crc32(char[] data)
|
||||
{
|
||||
uint result = ~(uint)(0);
|
||||
foreach (char x : data)
|
||||
@@ -40,7 +40,7 @@ func uint crc32(char[] data)
|
||||
return ~result;
|
||||
}
|
||||
|
||||
func ulong crc64(char[] data)
|
||||
fn ulong crc64(char[] data)
|
||||
{
|
||||
ulong result = (ulong)(0);
|
||||
foreach (char x : data)
|
||||
@@ -51,7 +51,7 @@ func ulong crc64(char[] data)
|
||||
}
|
||||
|
||||
|
||||
func uint fnv32(char[] data)
|
||||
fn uint fnv32(char[] data)
|
||||
{
|
||||
uint h = 0x811c9dc5;
|
||||
foreach (char x : data)
|
||||
@@ -61,7 +61,7 @@ func uint fnv32(char[] data)
|
||||
return h;
|
||||
}
|
||||
|
||||
func ulong fnv64(char[] data)
|
||||
fn ulong fnv64(char[] data)
|
||||
{
|
||||
ulong h = 0xcbf29ce484222325;
|
||||
foreach (char x : data)
|
||||
@@ -71,7 +71,7 @@ func ulong fnv64(char[] data)
|
||||
return h;
|
||||
}
|
||||
|
||||
func uint fnv32a(char[] data)
|
||||
fn uint fnv32a(char[] data)
|
||||
{
|
||||
uint h = 0x811c9dc5;
|
||||
foreach (char x : data)
|
||||
@@ -81,7 +81,7 @@ func uint fnv32a(char[] data)
|
||||
return h;
|
||||
}
|
||||
|
||||
func ulong fnv64a(char[] data)
|
||||
fn ulong fnv64a(char[] data)
|
||||
{
|
||||
ulong h = 0xcbf29ce484222325;
|
||||
foreach (char x : data)
|
||||
|
||||
@@ -1,10 +1,10 @@
|
||||
module mandelbrot;
|
||||
|
||||
extern func int atoi(char *s);
|
||||
extern func int printf(char *s, ...);
|
||||
extern func void putchar(int c);
|
||||
extern fn int atoi(char *s);
|
||||
extern fn int printf(char *s, ...);
|
||||
extern fn void putchar(int c);
|
||||
|
||||
func void main(int argc, char **argv)
|
||||
fn void main(int argc, char **argv)
|
||||
{
|
||||
int w = atoi(argv[1]);
|
||||
int h = w;
|
||||
|
||||
@@ -13,7 +13,7 @@ struct Planet
|
||||
double mass;
|
||||
}
|
||||
|
||||
func void advance(Planet[] bodies) @noinline
|
||||
fn void advance(Planet[] bodies) @noinline
|
||||
{
|
||||
usize nbodies = bodies.len;
|
||||
foreach (i, Planet* &b : bodies)
|
||||
@@ -42,7 +42,7 @@ func void advance(Planet[] bodies) @noinline
|
||||
}
|
||||
}
|
||||
|
||||
func double energy(Planet[] bodies)
|
||||
fn double energy(Planet[] bodies)
|
||||
{
|
||||
double e;
|
||||
usize nbodies = bodies.len;
|
||||
@@ -63,7 +63,7 @@ func double energy(Planet[] bodies)
|
||||
return e;
|
||||
}
|
||||
|
||||
func void offset_momentum(Planet[] bodies)
|
||||
fn void offset_momentum(Planet[] bodies)
|
||||
{
|
||||
double px;
|
||||
double py;
|
||||
@@ -128,7 +128,7 @@ Planet[*] planet_bodies = {
|
||||
*
|
||||
* When all advances done, rescale bodies back to obtain correct energy.
|
||||
*/
|
||||
func void scale_bodies(Planet[] bodies, double scale)
|
||||
fn void scale_bodies(Planet[] bodies, double scale)
|
||||
{
|
||||
foreach (&b : bodies)
|
||||
{
|
||||
@@ -139,11 +139,11 @@ func void scale_bodies(Planet[] bodies, double scale)
|
||||
}
|
||||
}
|
||||
|
||||
extern func int atoi(char *s);
|
||||
extern func int printf(char *s, ...);
|
||||
extern func double sqrt(double);
|
||||
extern fn int atoi(char *s);
|
||||
extern fn int printf(char *s, ...);
|
||||
extern fn double sqrt(double);
|
||||
|
||||
func int main(int argc, char ** argv)
|
||||
fn int main(int argc, char ** argv)
|
||||
{
|
||||
int n = atoi(argv[1]);
|
||||
|
||||
|
||||
@@ -10,7 +10,7 @@ module acorn::arr;
|
||||
|
||||
|
||||
/* Return a new Array, allocating len slots for Values. */
|
||||
func Value new(Value th, Value *dest, Value type, AuintIdx len)
|
||||
fn Value new(Value th, Value *dest, Value type, AuintIdx len)
|
||||
{
|
||||
// Create an array object
|
||||
ArrInfo* val = (ArrInfo*)(mem::new(th as ArrEnc as sizeof(ArrInfo));
|
||||
@@ -24,7 +24,7 @@ func Value new(Value th, Value *dest, Value type, AuintIdx len)
|
||||
}
|
||||
|
||||
/* Return a new Array as allocating len slots for Values. */
|
||||
func Value newClosure(Value *th, Value *dest, Value type, AuintIdx len)
|
||||
fn Value newClosure(Value *th, Value *dest, Value type, AuintIdx len)
|
||||
{
|
||||
// Create an array object
|
||||
ArrInfo* val = (sizeof(ArrInfo), ArrInfo*)(mem::new(th as ArrEnc);
|
||||
@@ -38,25 +38,25 @@ func Value newClosure(Value *th, Value *dest, Value type, AuintIdx len)
|
||||
}
|
||||
|
||||
/* Return 1 if the value is an Array as otherwise 0 */
|
||||
func int Value.isArr(Value* val)
|
||||
fn int Value.isArr(Value* val)
|
||||
{
|
||||
return val.isEnc(ArrEnc);
|
||||
}
|
||||
|
||||
/* Return 1 if the value is an Array, otherwise 0 */
|
||||
func int Value.isClosure(Value* val)
|
||||
fn int Value.isClosure(Value* val)
|
||||
{
|
||||
return val.isEnc(ArrEnc) && arr_info(val)->flags1 & TypeClo;
|
||||
}
|
||||
|
||||
private func ArrInfo.fill(ArrInfo* a, AuintIdx start, AuintIdx end, Value value) @inline
|
||||
private fn ArrInfo.fill(ArrInfo* a, AuintIdx start, AuintIdx end, Value value) @inline
|
||||
{
|
||||
for (AuintIdx i = start; i < end; i++) a.arr[i] = value;
|
||||
}
|
||||
|
||||
/* Ensure array has room for len Values, allocating memory as needed.
|
||||
* Allocated space will not shrink. Changes nothing about array's contents. */
|
||||
func void makeRoom(Value th, Value arr, AuintIdx len)
|
||||
fn void makeRoom(Value th, Value arr, AuintIdx len)
|
||||
{
|
||||
ArrInfo* a = arr_info(arr);
|
||||
if (len > a.avail)
|
||||
@@ -71,7 +71,7 @@ func void makeRoom(Value th, Value arr, AuintIdx len)
|
||||
* Set the number of elements in the array, growing it if needed.
|
||||
* If less than current number array size, array is not shrunk.
|
||||
*/
|
||||
func void setSize(Value th, Value arr, AuintIdx len)
|
||||
fn void setSize(Value th, Value arr, AuintIdx len)
|
||||
{
|
||||
ArrInfo* a = arr_info(arr);
|
||||
AuintIdx size = arr_size(arr);
|
||||
@@ -84,7 +84,7 @@ func void setSize(Value th, Value arr, AuintIdx len)
|
||||
* or expanding as needed. Growth space is initialized to aNull.
|
||||
* @require val.isArr()
|
||||
*/
|
||||
func void forceSize(Value th, Value val, AuintIdx len)
|
||||
fn void forceSize(Value th, Value val, AuintIdx len)
|
||||
{
|
||||
ArrInfo *arr = arr_info(val);
|
||||
|
||||
@@ -105,7 +105,7 @@ func void forceSize(Value th, Value val, AuintIdx len)
|
||||
* Retrieve the value in array at specified position.
|
||||
* @require arr.isArr()
|
||||
*/
|
||||
func Value get(Value th, Value arr, AuintIdx pos)
|
||||
fn Value get(Value th, Value arr, AuintIdx pos)
|
||||
{
|
||||
ArrInfo* a = arr_info(arr);
|
||||
return pos >= a.size ? aNull : a.arr[pos];
|
||||
@@ -116,7 +116,7 @@ func Value get(Value th, Value arr, AuintIdx pos)
|
||||
* This can expand the size of the array.
|
||||
* @require arr.isArr()
|
||||
*/
|
||||
func void set(Value th, Value arr, AuintIdx pos, Value val)
|
||||
fn void set(Value th, Value arr, AuintIdx pos, Value val)
|
||||
{
|
||||
ArrInfo* a = arr_info(arr);
|
||||
|
||||
@@ -135,7 +135,7 @@ func void set(Value th, Value arr, AuintIdx pos, Value val)
|
||||
* Append val to the end of the array (increasing array's size).
|
||||
* @require arr.isArr()
|
||||
*/
|
||||
func void add(Value th, Value arr, Value val)
|
||||
fn void add(Value th, Value arr, Value val)
|
||||
{
|
||||
ArrInfo *a = arr_info(arr);
|
||||
AuintIdx sz = arr_size(arr);
|
||||
@@ -154,7 +154,7 @@ func void add(Value th, Value arr, Value val)
|
||||
* This can expand the size of the array.
|
||||
* @require arr.isArr()
|
||||
*/
|
||||
func void repeat(Value th, Value arr, AuintIdx pos, AuintIdx n, Value val)
|
||||
fn void repeat(Value th, Value arr, AuintIdx pos, AuintIdx n, Value val)
|
||||
{
|
||||
ArrInfo* a = arr_info(arr);
|
||||
|
||||
@@ -177,7 +177,7 @@ func void repeat(Value th, Value arr, AuintIdx pos, AuintIdx n, Value val)
|
||||
* All values after these are preserved, essentially shrinking the array.
|
||||
* @require arr.isArr()
|
||||
*/
|
||||
func void del(Value th, Value arr, AuintIdx pos, AuintIdx n)
|
||||
fn void del(Value th, Value arr, AuintIdx pos, AuintIdx n)
|
||||
{
|
||||
ArrInfo *a = arr_info(arr);
|
||||
|
||||
@@ -200,7 +200,7 @@ func void del(Value th, Value arr, AuintIdx pos, AuintIdx n)
|
||||
* Insert n copies of val into the array starting at pos, expanding the array's size.
|
||||
* @require arr.isArr()
|
||||
*/
|
||||
func void ins(Value th, Value arr, AuintIdx pos, AuintIdx n, Value val)
|
||||
fn void ins(Value th, Value arr, AuintIdx pos, AuintIdx n, Value val)
|
||||
{
|
||||
ArrInfo *a = arr_info(arr);
|
||||
|
||||
@@ -223,7 +223,7 @@ func void ins(Value th, Value arr, AuintIdx pos, AuintIdx n, Value val)
|
||||
* This can increase or decrease the size of the array. arr and arr2 may be the same array.
|
||||
* @require arr.isArr()
|
||||
*/
|
||||
func void sub(Value th, Value arr, AuintIdx pos, AuintIdx n, Value arr2, AuintIdx pos2, AuintIdx n2)
|
||||
fn void sub(Value th, Value arr, AuintIdx pos, AuintIdx n, Value arr2, AuintIdx pos2, AuintIdx n2)
|
||||
{
|
||||
ArrInfo *a = arr_info(arr);
|
||||
|
||||
@@ -250,7 +250,7 @@ func void sub(Value th, Value arr, AuintIdx pos, AuintIdx n, Value arr2, AuintId
|
||||
}
|
||||
|
||||
/* Serialize an array's contents to indented text */
|
||||
func void serialize(Value th, Value str, int indent, Value arr)
|
||||
fn void serialize(Value th, Value str, int indent, Value arr)
|
||||
{
|
||||
// TODO
|
||||
ArrInfo *a = arr_info(arr);
|
||||
|
||||
@@ -12,7 +12,7 @@ module acorn::mem;
|
||||
* - If ptr==NULL, it allocates a new uninitialized memory block
|
||||
* - Otherwise it changes the size of the memory block (and may move its location)
|
||||
* It returns the location of the new block or NULL (if freed). */
|
||||
func void* gcrealloc(Value th, void *block, Auint osize, Auint nsize)
|
||||
fn void* gcrealloc(Value th, void *block, Auint osize, Auint nsize)
|
||||
{
|
||||
// Check consistency of block and osize (both must be null or specified)
|
||||
Auint realosize = block ? osize : 0;
|
||||
@@ -51,7 +51,7 @@ func void* gcrealloc(Value th, void *block, Auint osize, Auint nsize)
|
||||
return newblock;
|
||||
}
|
||||
|
||||
func void* gcreallocv(Value th, void* block, Auint osize, Auint nsize, Auint esize)
|
||||
fn void* gcreallocv(Value th, void* block, Auint osize, Auint nsize, Auint esize)
|
||||
{
|
||||
// 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
|
||||
@@ -68,7 +68,7 @@ func void* gcreallocv(Value th, void* block, Auint osize, Auint nsize, Auint esi
|
||||
* - Otherwise it changes the size of the memory block (and may move its location)
|
||||
* It returns the location of the new block or NULL (if freed).
|
||||
**/
|
||||
func void* frealloc(void* block, Auint size)
|
||||
fn void* frealloc(void* block, Auint size)
|
||||
{
|
||||
if (!size)
|
||||
{
|
||||
@@ -113,7 +113,7 @@ MemInfo* new(Value th as int enc, Auint sz)
|
||||
* Create a new pointer object (with given encoding and size).
|
||||
* Caller must add itself to its own private list
|
||||
*/
|
||||
func MemInfo* newnolink(Value th, int enc, Auint sz)
|
||||
fn MemInfo* newnolink(Value th, int enc, Auint sz)
|
||||
{
|
||||
// Perform garbage collection before a memory allocation
|
||||
$if (defined(AVM_GCHARDMEMTEST))
|
||||
@@ -134,7 +134,7 @@ func MemInfo* newnolink(Value th, int enc, Auint sz)
|
||||
}
|
||||
|
||||
/* double size of vector array, up to limits */
|
||||
func void growaux_(Value th, void *block, AuintIdx *size, AuintIdx size_elems, AuintIdx limit)
|
||||
fn void growaux_(Value th, void *block, AuintIdx *size, AuintIdx size_elems, AuintIdx limit)
|
||||
{
|
||||
void* newblock;
|
||||
AuintIdx newsize = void;
|
||||
|
||||
@@ -25,7 +25,7 @@ import acorn::sym;
|
||||
***************************************/
|
||||
|
||||
/** Size of the method's stack area: base to top */
|
||||
func AintIdx stkSz(Value th) @inline
|
||||
fn AintIdx stkSz(Value th) @inline
|
||||
{
|
||||
return th(th).stk_top - th(th).curmethod.begin;
|
||||
}
|
||||
@@ -35,7 +35,7 @@ func AintIdx stkSz(Value th) @inline
|
||||
|
||||
/** Point to current method's stack value at position i.
|
||||
* For a method: i=0 is self, i=1 is first parameter, etc. */
|
||||
func void Value.at(Value* th, AintIdx i) @inline
|
||||
fn void Value.at(Value* th, AintIdx i) @inline
|
||||
{
|
||||
@assert_exp(i >= 0 && i < stkSz(th), "invalid stack index");
|
||||
return &th(*th).curmethod.begin[i];
|
||||
@@ -47,20 +47,20 @@ func void Value.at(Value* th, AintIdx i) @inline
|
||||
|
||||
/* Retrieve the stack value at the index. Be sure 0<= idx < top.
|
||||
* Good for getting method's parameters: 0=self, 1=parm 1, etc. */
|
||||
func Value Value.getLocal(Value *th, AintIdx idx)
|
||||
fn Value Value.getLocal(Value *th, AintIdx idx)
|
||||
{
|
||||
return *th.at(idx);
|
||||
}
|
||||
|
||||
/* Put the value on the stack at the designated position. Be sure 0<= idx < top. */
|
||||
func void Value.setLocal(Value th, AintIdx idx, Value val)
|
||||
fn void Value.setLocal(Value th, AintIdx idx, Value val)
|
||||
{
|
||||
*th.at(idx) = val;
|
||||
mem::markChk(th, th, val);
|
||||
}
|
||||
|
||||
/* Copy the stack value at fromidx into toidx */
|
||||
func void Value.copyLocal(Value* th, AintIdx toidx, AintIdx fromidx)
|
||||
fn void Value.copyLocal(Value* th, AintIdx toidx, AintIdx fromidx)
|
||||
{
|
||||
*th.at(toidx) = *th.at(fromidx);
|
||||
}
|
||||
@@ -69,7 +69,7 @@ func void Value.copyLocal(Value* th, AintIdx toidx, AintIdx fromidx)
|
||||
* Remove the value at index (shifting down all values above it to top)
|
||||
* @require stkSz(th) > 0
|
||||
*/
|
||||
func void Value.deleteLocal(Value* th, AintIdx idx)
|
||||
fn void Value.deleteLocal(Value* th, AintIdx idx)
|
||||
{
|
||||
Value* p = th.at(idx);
|
||||
memmove(p, p + 1, sizeof(Value)*(stkSz(th) - idx - 1));
|
||||
@@ -80,7 +80,7 @@ func void Value.deleteLocal(Value* th, AintIdx idx)
|
||||
* Insert the popped value into index (shifting up all values above it)
|
||||
* @require stkSz(th) > 0
|
||||
*/
|
||||
func void Value.insertLocal(Value *th, AintIdx idx)
|
||||
fn void Value.insertLocal(Value *th, AintIdx idx)
|
||||
{
|
||||
Value *p = th.at(idx);
|
||||
Value val = *(th(*th).stk_top - 1);
|
||||
@@ -94,7 +94,7 @@ func void Value.insertLocal(Value *th, AintIdx idx)
|
||||
***************************************/
|
||||
|
||||
/* Push a value on the stack's top */
|
||||
func Value Value.pushValue(Value* th, Value val)
|
||||
fn Value Value.pushValue(Value* th, Value val)
|
||||
{
|
||||
stkCanIncTop(th); /* Check if there is room */
|
||||
*th(*th).stk_top++ = val;
|
||||
@@ -103,14 +103,14 @@ func Value Value.pushValue(Value* th, Value val)
|
||||
}
|
||||
|
||||
/* Push and return the corresponding Symbol value for a 0-terminated c-string */
|
||||
func Value Value.pushSym(Value* th, string str)
|
||||
fn Value Value.pushSym(Value* th, string str)
|
||||
{
|
||||
stkCanIncTop(th); /* Check if there is room */
|
||||
return sym::newSym(*th, th(*th).stk_top++, str);
|
||||
}
|
||||
|
||||
/* Push and return the corresponding Symbol value for a byte sequence of specified length */
|
||||
func Value Value.pushSyml(Value th, string str)
|
||||
fn Value Value.pushSyml(Value th, string str)
|
||||
{
|
||||
stkCanIncTop(th); /* Check if there is room */
|
||||
return sym::newSym(*th, th(*th).stk_top++, str);
|
||||
@@ -319,7 +319,7 @@ void popSetActProp(Value th, AintIdx selfidx, const char *mbrnm) {
|
||||
}
|
||||
|
||||
/* Push a copy of a stack's value at index onto the stack's top */
|
||||
func Value Value.pushLocal(Value* th, AintIdx idx)
|
||||
fn Value Value.pushLocal(Value* th, AintIdx idx)
|
||||
{
|
||||
stkCanIncTop(th); /* Check if there is room */
|
||||
return *th(*th).stk_top++ = th.getLocal(idx);
|
||||
@@ -329,7 +329,7 @@ func Value Value.pushLocal(Value* th, AintIdx idx)
|
||||
* Pop a value off the top of the stack
|
||||
* @require stkSz(th) > 0
|
||||
*/
|
||||
func Value Value.popValue()
|
||||
fn Value Value.popValue()
|
||||
{
|
||||
return *--th(*th).stk_top;
|
||||
}
|
||||
@@ -338,7 +338,7 @@ func Value Value.popValue()
|
||||
* Pops the top value and writes it at idx. Often used to set return value
|
||||
* @require stkSz(th) > 0, idx >= 0, idx < stkSz(th) - 1
|
||||
*/
|
||||
func void Value.popLocal(Value* th, AintIdx idx)
|
||||
fn void Value.popLocal(Value* th, AintIdx idx)
|
||||
{
|
||||
th.setLocal(idx, *(th(*th).stk_top - 1));
|
||||
// Pop after value is safely in Global
|
||||
@@ -349,7 +349,7 @@ func void Value.popLocal(Value* th, AintIdx idx)
|
||||
* Retrieve the stack value at the index from top. Be sure 0<= idx < top.
|
||||
* @require idx >= 0, idx < stkSz(th)
|
||||
*/
|
||||
func Value Value.getFromTop(Value* th, AintIdx idx)
|
||||
fn Value Value.getFromTop(Value* th, AintIdx idx)
|
||||
{
|
||||
return *th.at(stkSz(th) - idx - 1);
|
||||
}
|
||||
@@ -357,7 +357,7 @@ func Value Value.getFromTop(Value* th, AintIdx idx)
|
||||
/**
|
||||
* Return number of values on the current method's stack
|
||||
*/
|
||||
func AuintIdx Value.getTop(Value* th)
|
||||
fn AuintIdx Value.getTop(Value* th)
|
||||
{
|
||||
return (AuintIdx)(stkSz(th));
|
||||
}
|
||||
@@ -367,7 +367,7 @@ func AuintIdx Value.getTop(Value* th)
|
||||
* This can shrink the stack or grow it (padding with 'null's).
|
||||
* A negative index removes that number of values off the top.
|
||||
*/
|
||||
func void Value.setTop(Value* th as AintIdx idx)
|
||||
fn void Value.setTop(Value* th as AintIdx idx)
|
||||
{
|
||||
// TODO
|
||||
Value *base = th(*th).curmethod.begin;
|
||||
@@ -395,7 +395,7 @@ func void Value.setTop(Value* th as AintIdx idx)
|
||||
* Push and return the symbolically-named global variable's value
|
||||
* @require vm(*th).global.isTbl()
|
||||
**/
|
||||
func Value Value.pushGloVar(Value* th, string var)
|
||||
fn Value Value.pushGloVar(Value* th, string var)
|
||||
{
|
||||
// Check if there is room
|
||||
stkCanIncTop(th);
|
||||
@@ -408,7 +408,7 @@ func Value Value.pushGloVar(Value* th, string var)
|
||||
* Alter the symbolically-named global variable to have the value popped off the local stack
|
||||
* @require stkSz(th) > 0, vm(th).global.isTbl()
|
||||
**/
|
||||
func void Value.popGloVar(Value* th, string var)
|
||||
fn void Value.popGloVar(Value* th, string var)
|
||||
{
|
||||
// Check if there is room
|
||||
stkCanIncTop(th);
|
||||
@@ -428,7 +428,7 @@ Value pushGlobal(Value th)
|
||||
* Internal function to re-allocate stack's size
|
||||
* @require newsize <= STACK_MAXSIZE || newsize == STACK_ERRORSIZE
|
||||
**/
|
||||
func void realloc(Value th, int newsize)
|
||||
fn void realloc(Value th, int newsize)
|
||||
{
|
||||
// Incremental GC before memory allocation events
|
||||
mem::gccheck(th);
|
||||
|
||||
@@ -11,7 +11,7 @@ module acorn::lex;
|
||||
/**
|
||||
* Crude algorithm for determining if character is a Unicode letter
|
||||
*/
|
||||
func bool isualpha(Auchar c) @inline
|
||||
fn bool isualpha(Auchar c) @inline
|
||||
{
|
||||
return c > 0xA0 || isalpha(c);
|
||||
}
|
||||
@@ -20,7 +20,7 @@ func bool isualpha(Auchar c) @inline
|
||||
/**
|
||||
* Algorithm for determining if character is a digit 0-9
|
||||
*/
|
||||
func bool isudigit(Auchar c) @inline
|
||||
fn bool isudigit(Auchar c) @inline
|
||||
{
|
||||
return c >= '0' && c <= '9';
|
||||
}
|
||||
@@ -28,7 +28,7 @@ func bool isudigit(Auchar c) @inline
|
||||
/**
|
||||
* Return a new LexInfo value, lexer context for a source program
|
||||
*/
|
||||
func Value new(Value th, Value *dest, Value src, Value url)
|
||||
fn Value new(Value th, Value *dest, Value src, Value url)
|
||||
{
|
||||
LexInfo *lex;
|
||||
|
||||
@@ -60,7 +60,7 @@ func Value new(Value th, Value *dest, Value src, Value url)
|
||||
}
|
||||
|
||||
/** Return the current unicode character whose UTF-8 bytes start at lex->bytepos */
|
||||
func Auchar LexInfo.thischar(LexInfo* lex)
|
||||
fn Auchar LexInfo.thischar(LexInfo* lex)
|
||||
{
|
||||
byte *src = &toStr(lex.source)[lex.bytepos];
|
||||
int nbytes;
|
||||
@@ -83,7 +83,7 @@ func Auchar LexInfo.thischar(LexInfo* lex)
|
||||
}
|
||||
|
||||
/** Return the current unicode character whose UTF-8 bytes start at lex->bytepos */
|
||||
func Auchar LexInfo.nextchar(LexInfo* lex)
|
||||
fn Auchar LexInfo.nextchar(LexInfo* lex)
|
||||
{
|
||||
const char *src = &toStr(lex->source)[lex->bytepos];
|
||||
int nbytes;
|
||||
@@ -114,7 +114,7 @@ func Auchar LexInfo.nextchar(LexInfo* lex)
|
||||
}
|
||||
|
||||
/** Skip lex->bytepos past the unicode character whose UTF-8 bytes start at lex->bytepos */
|
||||
func void LexInfo.skipchar(LexInfo* lex)
|
||||
fn void LexInfo.skipchar(LexInfo* lex)
|
||||
{
|
||||
const char *src = &toStr(lex->source)[lex->bytepos];
|
||||
int nbytes;
|
||||
@@ -137,7 +137,7 @@ func void LexInfo.skipchar(LexInfo* lex)
|
||||
|
||||
/** Scan past non-tokenized white space.
|
||||
* Handle line indentation and continuation */
|
||||
func bool LexInfo.scanWhite(LexInfo *lex)
|
||||
fn bool LexInfo.scanWhite(LexInfo *lex)
|
||||
{
|
||||
Value th = lex.th; // for vmlit
|
||||
|
||||
@@ -628,7 +628,7 @@ bool lexScanOp(LexInfo *lex) {
|
||||
}
|
||||
|
||||
/* Get the next token */
|
||||
func void LexInfo.getNextToken(LexInfo *lex)
|
||||
fn void LexInfo.getNextToken(LexInfo *lex)
|
||||
{
|
||||
|
||||
// Scan until we find a token
|
||||
|
||||
@@ -2,7 +2,7 @@ module acornvm::compiler;
|
||||
|
||||
|
||||
/* Return a new CompInfo value, compiler state for an Acorn method */
|
||||
func Value new_compiler(Value th, Value *dest, Value src, Value url)
|
||||
fn Value new_compiler(Value th, Value *dest, Value src, Value url)
|
||||
{
|
||||
CompInfo *comp;
|
||||
|
||||
@@ -53,7 +53,7 @@ func Value new_compiler(Value th, Value *dest, Value src, Value url)
|
||||
- pgmsrc: CompInfo or Text string containing the program source
|
||||
- baseurl: a symbol or null
|
||||
It returns the compiled byte-code method. */
|
||||
func int acn_newmethod(Value th)
|
||||
fn int acn_newmethod(Value th)
|
||||
{
|
||||
// Retrieve pgmsrc and baseurl from parameters
|
||||
Value pgmsrc as baseurl;
|
||||
|
||||
@@ -29,7 +29,7 @@ int genAddUrlLit(CompInfo *comp, Value val) {
|
||||
}
|
||||
|
||||
/* Add a method literal and return its index */
|
||||
func int CompInfo.genAddMethodLit(CompInfo *comp, Value val)
|
||||
fn int CompInfo.genAddMethodLit(CompInfo *comp, Value val)
|
||||
{
|
||||
BMethodInfo* f = comp.method;
|
||||
mem_growvector(comp->th, f->lits, f->nbrlits, f->litsz, Value, INT_MAX);
|
||||
@@ -50,7 +50,7 @@ int findBlockVar(Value th, Value locvars, Value varnm)
|
||||
}
|
||||
|
||||
/* Look for local variable. Returns idx if found, -1 otherwise. */
|
||||
func int CompInfo.findLocalVar(CompInfo *comp, Value varnm) throws SearchError
|
||||
fn int CompInfo.findLocalVar(CompInfo *comp, Value varnm) throws SearchError
|
||||
{
|
||||
assert(varnm.isSym());
|
||||
|
||||
@@ -72,7 +72,7 @@ func int CompInfo.findLocalVar(CompInfo *comp, Value varnm) throws SearchError
|
||||
}
|
||||
|
||||
/* Look for closure variable. Returns idx if found, -1 otherwise. */
|
||||
func int CompInfo.findClosureVar(CompInfo *comp, Value varnm)
|
||||
fn int CompInfo.findClosureVar(CompInfo *comp, Value varnm)
|
||||
{
|
||||
assert(varnm.isSym());
|
||||
|
||||
@@ -112,7 +112,7 @@ void CompInfo.declareLocal(CompInfo *comp, Value varnm)
|
||||
|
||||
/** Create and return new Closure AST segment
|
||||
Modifies comp->clovarseg and -> newcloseg */
|
||||
func Value parseNewClo(CompInfo* comp, Value astseg)
|
||||
fn Value parseNewClo(CompInfo* comp, Value astseg)
|
||||
{
|
||||
Value th = comp->th;
|
||||
// ('Closure', clovars, ('callprop', Closure, New, getmethod, setmethod))
|
||||
@@ -289,7 +289,7 @@ void parseValue(CompInfo* comp, Value astseg)
|
||||
}
|
||||
|
||||
/** Add a list of parameters to a AST propseg */
|
||||
func void CompInfo.parseParams(CompInfo* comp, Value propseg, const char *closeparen)
|
||||
fn void CompInfo.parseParams(CompInfo* comp, Value propseg, const char *closeparen)
|
||||
{
|
||||
bool saveforcelocal = comp->forcelocal;
|
||||
comp->forcelocal = false;
|
||||
@@ -434,7 +434,7 @@ void parsePrefixExp(CompInfo* comp, Value astseg) {
|
||||
}
|
||||
|
||||
/** Parse the '**' operator */
|
||||
func void CompInfo.parsePowerExp(CompInfo* comp, Value astseg)
|
||||
fn void CompInfo.parsePowerExp(CompInfo* comp, Value astseg)
|
||||
{
|
||||
Value th = comp.th;
|
||||
comp.parsePrefixExp(astseg);
|
||||
@@ -448,7 +448,7 @@ func void CompInfo.parsePowerExp(CompInfo* comp, Value astseg)
|
||||
}
|
||||
|
||||
/** Parse the '*', '/' or '%' binary operator */
|
||||
func void CompInfo.parseMultDivExp(CompInfo* comp inline, Value astseg)
|
||||
fn void CompInfo.parseMultDivExp(CompInfo* comp inline, Value astseg)
|
||||
{
|
||||
Value th = comp.th;
|
||||
parsePowerExp(astseg);
|
||||
@@ -461,7 +461,7 @@ func void CompInfo.parseMultDivExp(CompInfo* comp inline, Value astseg)
|
||||
}
|
||||
|
||||
/** Parse the '+' or '-' binary operator */
|
||||
func void CompInfo.parseAddSubExp(CompInfo* comp, Value astseg)
|
||||
fn void CompInfo.parseAddSubExp(CompInfo* comp, Value astseg)
|
||||
{
|
||||
Value th = comp.th;
|
||||
comp.parseMultDivExp(astseg);
|
||||
@@ -474,7 +474,7 @@ func void CompInfo.parseAddSubExp(CompInfo* comp, Value astseg)
|
||||
}
|
||||
|
||||
/** Parse the range .. constructor operator */
|
||||
func void CompInfo.parseRangeExp(CompInfo* comp, Value astseg)
|
||||
fn void CompInfo.parseRangeExp(CompInfo* comp, Value astseg)
|
||||
{
|
||||
Value th = comp.th;
|
||||
comp.parseAddSubExp(astseg);
|
||||
@@ -494,7 +494,7 @@ func void CompInfo.parseRangeExp(CompInfo* comp, Value astseg)
|
||||
}
|
||||
|
||||
/** Parse the comparison operators */
|
||||
func void CompInfo.parseCompExp(CompInfo* comp, Value astseg) {
|
||||
fn void CompInfo.parseCompExp(CompInfo* comp, Value astseg) {
|
||||
Value th = comp.th;
|
||||
comp.parseRangeExp(astseg);
|
||||
Value op = comp.lex->token;
|
||||
@@ -514,7 +514,7 @@ func void CompInfo.parseCompExp(CompInfo* comp, Value astseg) {
|
||||
}
|
||||
|
||||
/* Parse 'not' conditional logic operator */
|
||||
func void CompInfo.parseNotExp(CompInfo* comp, Value astseg)
|
||||
fn void CompInfo.parseNotExp(CompInfo* comp, Value astseg)
|
||||
{
|
||||
Value th = comp.th;
|
||||
bool takenot = false;
|
||||
@@ -530,13 +530,13 @@ func void CompInfo.parseNotExp(CompInfo* comp, Value astseg)
|
||||
}
|
||||
}
|
||||
|
||||
func bool CompInfo.matchNext(CompInfo *comp, string s) @inline
|
||||
fn bool CompInfo.matchNext(CompInfo *comp, string s) @inline
|
||||
{
|
||||
return comp.lex.matchNext(s);
|
||||
}
|
||||
|
||||
/* Parse 'and' conditional logic operator */
|
||||
func void CompInfo.parseAndExp(CompInfo* comp, Value astseg)
|
||||
fn void CompInfo.parseAndExp(CompInfo* comp, Value astseg)
|
||||
{
|
||||
Value th = comp.th;
|
||||
comp.parseNotExp(astseg);
|
||||
|
||||
@@ -16,19 +16,19 @@ import acorn::arr;
|
||||
* **********************/
|
||||
|
||||
/** Append a value to AST segment - growing as needed */
|
||||
func void addValue(Value th, Value astseg, Value val) @inline
|
||||
fn void addValue(Value th, Value astseg, Value val) @inline
|
||||
{
|
||||
arr::add(th, astseg, val);
|
||||
}
|
||||
|
||||
/** Get a value within the AST segment */
|
||||
func Value get(Value th, Value astseg, AuintIdx idx) @inline
|
||||
fn Value get(Value th, Value astseg, AuintIdx idx) @inline
|
||||
{
|
||||
return arr::get(th, astseg, idx);
|
||||
}
|
||||
|
||||
/** Set a value within the AST segment */
|
||||
func void set(Value th, Value astseg, AuintIdx idx, Value val)
|
||||
fn void set(Value th, Value astseg, AuintIdx idx, Value val)
|
||||
{
|
||||
arr::set(th, astseg, idx, val);
|
||||
}
|
||||
@@ -123,7 +123,7 @@ void popNew(Value th, Value oldseg, Value newseg)
|
||||
}
|
||||
|
||||
/** Return true if ast segment can be assigned a value: variable or settable property/method */
|
||||
func bool isLval(Value th, Value astseg)
|
||||
fn bool isLval(Value th, Value astseg)
|
||||
{
|
||||
if (!astseg.isArr()) return false;
|
||||
Value op = get(th, astseg, 0);
|
||||
|
||||
@@ -8,7 +8,7 @@ macro @hash_binmod(s, size)
|
||||
}
|
||||
|
||||
/** Resize the symbol table */
|
||||
func void resizeTable(Value th as Auint newsize)
|
||||
fn void resizeTable(Value th as Auint newsize)
|
||||
{
|
||||
SymTable* sym_tbl = &vm(th)->sym_table;
|
||||
Auint i;
|
||||
@@ -48,7 +48,7 @@ func void resizeTable(Value th as Auint newsize)
|
||||
}
|
||||
|
||||
/** Initialize the symbol table that hash indexes all symbols */
|
||||
func void init(Value th)
|
||||
fn void init(Value th)
|
||||
{
|
||||
SymTable* sym_tbl = &vm(th).sym_table;
|
||||
sym_tbl.nbrAvail = 0;
|
||||
@@ -67,7 +67,7 @@ void free(Value th)
|
||||
|
||||
/* If symbol exists in symbol table, reuse it. Otherwise, add it.
|
||||
Anchor (store) symbol value in dest and return it. */
|
||||
func Value newSym(Value th, Value* dest, string str, AuintIdx len)
|
||||
fn Value newSym(Value th, Value* dest, string str, AuintIdx len)
|
||||
{
|
||||
SymInfo* sym;
|
||||
SymTable* sym_tbl = &vm(th)->sym_table;
|
||||
@@ -101,7 +101,7 @@ func Value newSym(Value th, Value* dest, string str, AuintIdx len)
|
||||
}
|
||||
|
||||
/* Return 1 if the value is a Symbol, otherwise 0 */
|
||||
func int Value.isSym(Value *sym) @inline
|
||||
fn int Value.isSym(Value *sym) @inline
|
||||
{
|
||||
return sym.isEnc(SymEnc);
|
||||
}
|
||||
@@ -120,7 +120,7 @@ int isGlobal(Value sym)
|
||||
* This can be used to sequentially iterate through the symbol table.
|
||||
* Results may be inaccurate if the symbol table is changed during iteration.
|
||||
*/
|
||||
func Value next(Value th, Value key)
|
||||
fn Value next(Value th, Value key)
|
||||
{
|
||||
SymTable *sym_tbl = &th(th)->vm->sym_table;
|
||||
SymInfo *sym;
|
||||
|
||||
@@ -48,7 +48,7 @@ typedef void* as distinct Value
|
||||
/** Prototype for a C method callable by the VM.
|
||||
It is passed the thread, through which it obtains parameters via the data stack.
|
||||
When done, it returns how many return values it has placed on the stack. */
|
||||
typedef func int(Value) as AcMethodp;
|
||||
typedef fn int(Value) as AcMethodp;
|
||||
|
||||
/** Quick, exact equivalence check between two values ('===')
|
||||
* Great for null, false, true, integers and symbols.
|
||||
@@ -73,7 +73,7 @@ const int VAL_MASK = 0x3;
|
||||
const int VAL_SHIFT = 2;
|
||||
|
||||
|
||||
func bool Value.isEnc(Value *value, EncType type) @inline
|
||||
fn bool Value.isEnc(Value *value, EncType type) @inline
|
||||
{
|
||||
return value.isPtr() && @cast(value as MemInfo*).enctyp == type;
|
||||
}
|
||||
@@ -93,7 +93,7 @@ macro isType(v, ValBits e)
|
||||
|
||||
|
||||
/** Is v an Integer? */
|
||||
func bool Value.isInt(Value *v)
|
||||
fn bool Value.isInt(Value *v)
|
||||
{
|
||||
return @isType(*v as INT);
|
||||
}
|
||||
@@ -116,7 +116,7 @@ macro toAint(v)
|
||||
// Float value functions
|
||||
|
||||
/** Is v a Float? */
|
||||
func Value.isFloat(Value *v)
|
||||
fn Value.isFloat(Value *v)
|
||||
{
|
||||
return @isType(*v as FLOAT);
|
||||
}
|
||||
@@ -157,7 +157,7 @@ macro aTrue()
|
||||
* Is value null?
|
||||
* @require value != null
|
||||
*/
|
||||
func bool Value.isNull(Value *value) @inline
|
||||
fn bool Value.isNull(Value *value) @inline
|
||||
{
|
||||
return *v == aNull;
|
||||
}
|
||||
@@ -166,7 +166,7 @@ func bool Value.isNull(Value *value) @inline
|
||||
* Is value false or null?
|
||||
* @require value != null
|
||||
*/
|
||||
func bool Value.isFalse(Value *value) @inline
|
||||
fn bool Value.isFalse(Value *value) @inline
|
||||
{
|
||||
return *v == aFalse || *v == aNull;
|
||||
}
|
||||
@@ -174,7 +174,7 @@ func bool Value.isFalse(Value *value) @inline
|
||||
/**
|
||||
* Is value true or false?
|
||||
*/
|
||||
func bool Value.isBool(Value *value) @inline
|
||||
fn bool Value.isBool(Value *value) @inline
|
||||
{
|
||||
return *v >= aFalse;
|
||||
}
|
||||
@@ -183,7 +183,7 @@ func bool Value.isBool(Value *value) @inline
|
||||
// Pointer functions.
|
||||
|
||||
/** Is value a pointer? */
|
||||
func bool Value.isPtr(Value *value) @inline
|
||||
fn bool Value.isPtr(Value *value) @inline
|
||||
{
|
||||
return @isType(*v as POINTER);
|
||||
}
|
||||
|
||||
@@ -255,7 +255,7 @@ macro memcpy_Auint(i, val)
|
||||
* - The main thread is started up, initializing its global namespace.
|
||||
* - All core types are progressively loaded, establishing the default types for
|
||||
* each encoding. This includes the resource types and Acorn compiler. */
|
||||
func Value new(void)
|
||||
fn Value new(void)
|
||||
{
|
||||
logInfo(AVM_RELEASE " started.");
|
||||
|
||||
@@ -352,7 +352,7 @@ float vmEndTimer(int64_t starttime)
|
||||
}
|
||||
$else
|
||||
{
|
||||
func int64_t vmStartTimer()
|
||||
fn int64_t vmStartTimer()
|
||||
{
|
||||
TimeVal start;
|
||||
start.gettimeofday();
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
module binarydigits;
|
||||
|
||||
func int main()
|
||||
fn int main()
|
||||
{
|
||||
fot (int i = 0; i < 20; i++)
|
||||
{
|
||||
@@ -8,7 +8,7 @@ func int main()
|
||||
}
|
||||
}
|
||||
|
||||
func string bin(int x)
|
||||
fn string bin(int x)
|
||||
{
|
||||
int bits = (x == 0) ? 1 : log10((double)(x)) / log10(2);
|
||||
string ret = str.make_repeat('0' as bits);
|
||||
|
||||
@@ -4,7 +4,7 @@ module globals;
|
||||
const string CLICK_ME = "Click Me";
|
||||
var uint counter = 0;
|
||||
|
||||
func void clickedme(GtkButton *o, void *d)
|
||||
fn void clickedme(GtkButton *o, void *d)
|
||||
{
|
||||
(GtkLabel*)(d).set_text(string.format("You clicked me %d times", ++counter));
|
||||
}
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
import curl;
|
||||
|
||||
func int main(void)
|
||||
fn int main(void)
|
||||
{
|
||||
Curl curl;
|
||||
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
module levenshtein;
|
||||
|
||||
func int levenshtein(String s, String t)
|
||||
fn int levenshtein(String s, String t)
|
||||
{
|
||||
// if either string is empty, difference is inserting all chars
|
||||
// from the other
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
module madlibs;
|
||||
import regex, stdio;
|
||||
|
||||
func void main()
|
||||
fn void main()
|
||||
{
|
||||
println("Enter a story template, terminated by an empty line:");
|
||||
String story = "";
|
||||
|
||||
@@ -15,13 +15,13 @@ public struct Map
|
||||
uint mod;
|
||||
}
|
||||
|
||||
public func Map* Map.init(Map *map)
|
||||
public fn Map* Map.init(Map *map)
|
||||
{
|
||||
*map = { };
|
||||
return map;
|
||||
}
|
||||
|
||||
public func Type* Map.valueForKey(Map *map, Key key)
|
||||
public fn Type* Map.valueForKey(Map *map, Key key)
|
||||
{
|
||||
if (!map.map) return nil;
|
||||
usize hash = key.hash();
|
||||
@@ -36,7 +36,7 @@ public func Type* Map.valueForKey(Map *map, Key key)
|
||||
return nil;
|
||||
}
|
||||
|
||||
public func Type *Map.setValueForKey(Map *map, Key key, Type *value)
|
||||
public fn Type *Map.setValueForKey(Map *map, Key key, Type *value)
|
||||
{
|
||||
if (!map.map)
|
||||
{
|
||||
@@ -71,12 +71,12 @@ public func Type *Map.setValueForKey(Map *map, Key key, Type *value)
|
||||
}
|
||||
}
|
||||
|
||||
public func usize Map.size(Vector *vector)
|
||||
public fn usize Map.size(Vector *vector)
|
||||
{
|
||||
return vector.array.size;
|
||||
}
|
||||
|
||||
public func void Map.removeLast(Vector *vector)
|
||||
public fn void Map.removeLast(Vector *vector)
|
||||
{
|
||||
vector.array.pop();
|
||||
}
|
||||
|
||||
@@ -13,7 +13,7 @@ public macro retry(#function, int retries = 3)
|
||||
return e!;
|
||||
}
|
||||
|
||||
func void main()
|
||||
fn void main()
|
||||
{
|
||||
int! result = @retry(eventually_succeed());
|
||||
}
|
||||
@@ -18,7 +18,7 @@ const uint MaxDepth = 8;
|
||||
|
||||
$if (DEBUG_NODES):
|
||||
|
||||
func void Blocks.dump(Blocks* b)
|
||||
fn void Blocks.dump(Blocks* b)
|
||||
{
|
||||
printf("Nodes (%u/%u) (%u bytes)\n", b.nodeCount, b.maxNodes, b.nodeCount * sizeof(Node));
|
||||
for (uint i = 0; i < b.nodeCount; i++)
|
||||
@@ -82,7 +82,7 @@ $endif;
|
||||
/**
|
||||
* @ensure const(a), const(b)
|
||||
*/
|
||||
func bool same(char* a, char* b)
|
||||
fn bool same(char* a, char* b)
|
||||
{
|
||||
uint i = 0;
|
||||
while (a[i] == b[i])
|
||||
@@ -110,7 +110,7 @@ struct Parser
|
||||
/**
|
||||
* @ensure const(input)
|
||||
*/
|
||||
func void! Parser.parse(Parser* p, char* input, char* diagMsg, Blocks* blocks)
|
||||
fn void! Parser.parse(Parser* p, char* input, char* diagMsg, Blocks* blocks)
|
||||
{
|
||||
p.tokenizer.init(input);
|
||||
p.tok.init();
|
||||
@@ -127,7 +127,7 @@ func void! Parser.parse(Parser* p, char* input, char* diagMsg, Blocks* blocks)
|
||||
try p.parseTopLevel();
|
||||
}
|
||||
|
||||
func void! Parser.parseTopLevel(Parser* p)
|
||||
fn void! Parser.parseTopLevel(Parser* p)
|
||||
{
|
||||
// key = value
|
||||
// | [[array]]
|
||||
@@ -149,22 +149,22 @@ func void! Parser.parseTopLevel(Parser* p)
|
||||
}
|
||||
}
|
||||
|
||||
func uint getRawValue(uint raw) @(inline)
|
||||
fn uint getRawValue(uint raw) @(inline)
|
||||
{
|
||||
return raw & ~RawValueMask;
|
||||
}
|
||||
|
||||
func ValueType getRawType(uint raw) @(inline)
|
||||
fn ValueType getRawType(uint raw) @(inline)
|
||||
{
|
||||
return (ValueType)((raw >> ValueTypeOffset) & 0x3);
|
||||
}
|
||||
|
||||
func uint addType(uint raw, ValueType t) @(inline)
|
||||
fn uint addType(uint raw, ValueType t) @(inline)
|
||||
{
|
||||
return raw | (t << ValueTypeOffset);
|
||||
}
|
||||
|
||||
func void! Parser.parseKeyValue(Parser* p)
|
||||
fn void! Parser.parseKeyValue(Parser* p)
|
||||
{
|
||||
//printf("parseKeyValue()\n");
|
||||
char[MaxText] key;
|
||||
@@ -187,7 +187,7 @@ func void! Parser.parseKeyValue(Parser* p)
|
||||
p.lastChild[p.numParents] = node;
|
||||
}
|
||||
|
||||
func void! Parser.parseTable(Parser* p)
|
||||
fn void! Parser.parseTable(Parser* p)
|
||||
{
|
||||
//printf("parseTable()\n");
|
||||
try p.consumeToken();
|
||||
@@ -211,7 +211,7 @@ func void! Parser.parseTable(Parser* p)
|
||||
p.expectAndConsume(TokenKind.Rbrace);
|
||||
}
|
||||
|
||||
func void Parser.parseTableArray(Parser* p)
|
||||
fn void Parser.parseTableArray(Parser* p)
|
||||
{
|
||||
//printf("parseTableArray()\n");
|
||||
p.consumeToken();
|
||||
@@ -234,7 +234,7 @@ func void Parser.parseTableArray(Parser* p)
|
||||
p.expectAndConsume(TokenKind.Rbrace2);
|
||||
}
|
||||
|
||||
func u32 Parser.parseValue(Parser* p) {
|
||||
fn u32 Parser.parseValue(Parser* p) {
|
||||
//printf("parseValue()\n");
|
||||
u32 value = 0;
|
||||
switch (p.tok.kind) {
|
||||
@@ -266,7 +266,7 @@ func u32 Parser.parseValue(Parser* p) {
|
||||
return value;
|
||||
}
|
||||
|
||||
func u32 Parser.parseArrayValues(Parser* p) {
|
||||
fn u32 Parser.parseArrayValues(Parser* p) {
|
||||
//printf("parseArrayValues()\n");
|
||||
p.consumeToken();
|
||||
u32 value = p.parseValue() | ValueIsArray;
|
||||
@@ -280,7 +280,7 @@ func u32 Parser.parseArrayValues(Parser* p) {
|
||||
return value;
|
||||
}
|
||||
|
||||
func u32 Parser.addTable(Parser* p, const char* name, u32 depth, bool isTop, NodeKind kind) {
|
||||
fn u32 Parser.addTable(Parser* p, const char* name, u32 depth, bool isTop, NodeKind kind) {
|
||||
//printf("addTable %s\n", name);
|
||||
Blocks* blocks = p.blocks;
|
||||
if (!isTop && p.numParents > depth && same(blocks.getName(p.parents[depth]), name)) {
|
||||
@@ -342,18 +342,18 @@ func u32 Parser.addTable(Parser* p, const char* name, u32 depth, bool isTop, Nod
|
||||
return 0;
|
||||
}
|
||||
|
||||
func Location! Parser.consumeToken(Parser* p)
|
||||
fn Location! Parser.consumeToken(Parser* p)
|
||||
{
|
||||
Location prev = p.tok.loc;
|
||||
try p.tokenizer.lex(&p.tok);
|
||||
return prev;
|
||||
}
|
||||
|
||||
func Token* Parser.nextToken(Parser* p) {
|
||||
fn Token* Parser.nextToken(Parser* p) {
|
||||
return p.tokenizer.lookahead();
|
||||
}
|
||||
|
||||
func void! Parser.expectAndConsume(Parser* p, TokenKind k) {
|
||||
fn void! Parser.expectAndConsume(Parser* p, TokenKind k) {
|
||||
if (p.tok.isNot(k))
|
||||
{
|
||||
sprintf(p.errorMsg, "expected '%s' at %s", token2str(k), p.tok.loc.str());
|
||||
@@ -362,7 +362,7 @@ func void! Parser.expectAndConsume(Parser* p, TokenKind k) {
|
||||
try p.consumeToken();
|
||||
}
|
||||
|
||||
func void Parser.expect(Parser* p, TokenKind k)
|
||||
fn void Parser.expect(Parser* p, TokenKind k)
|
||||
{
|
||||
if (p.tok.isNot(k))
|
||||
{
|
||||
@@ -379,7 +379,7 @@ public struct TomlReader @opaque
|
||||
Blocks* blocks;
|
||||
}
|
||||
|
||||
public func TomlReader* new_toml()
|
||||
public fn TomlReader* new_toml()
|
||||
{
|
||||
TomlReader* r = @malloc(TomlReader);
|
||||
r.blocks = @malloc(Blocks);
|
||||
@@ -387,21 +387,21 @@ public func TomlReader* new_toml()
|
||||
return r;
|
||||
}
|
||||
|
||||
public func void TomlReader.destroy(TomlReader* r)
|
||||
public fn void TomlReader.destroy(TomlReader* r)
|
||||
{
|
||||
r.blocks.destroy();
|
||||
free(r.blocks);
|
||||
free(r);
|
||||
}
|
||||
|
||||
public func const char* TomlReader.getMsg(const TomlReader* r)
|
||||
public fn const char* TomlReader.getMsg(const TomlReader* r)
|
||||
{
|
||||
return r.message;
|
||||
}
|
||||
|
||||
error EmptyFileError;
|
||||
|
||||
public func void! TomlReader.parse(TomlReader* r, string filename)
|
||||
public fn void! TomlReader.parse(TomlReader* r, string filename)
|
||||
{
|
||||
Reader file;
|
||||
|
||||
@@ -427,7 +427,7 @@ $endif
|
||||
// --------------------------------------------------------------
|
||||
// Getters+iters
|
||||
|
||||
func const Node* Reader.findNode(const Reader* r, const char* key)
|
||||
fn const Node* Reader.findNode(const Reader* r, const char* key)
|
||||
{
|
||||
char[MaxText] name;
|
||||
const char* cp = key;
|
||||
@@ -459,7 +459,7 @@ func const Node* Reader.findNode(const Reader* r, const char* key)
|
||||
return nil;
|
||||
}
|
||||
|
||||
public func const char* Reader.getValue(const Reader* r, const char* key) {
|
||||
public fn const char* Reader.getValue(const Reader* r, const char* key) {
|
||||
const Node* node = r.findNode(key);
|
||||
if (!node) return nil;
|
||||
if (getKind(node.nameOffset) != NodeKind.Value) return nil;
|
||||
@@ -468,7 +468,7 @@ public func const char* Reader.getValue(const Reader* r, const char* key) {
|
||||
return &r.blocks.values[getRawValue(node.rawValue)];
|
||||
}
|
||||
|
||||
public func bool Reader.getNumber(const Reader* r, const char* key, u32* result) {
|
||||
public fn bool Reader.getNumber(const Reader* r, const char* key, u32* result) {
|
||||
const Node* node = r.findNode(key);
|
||||
if (!node) return false;
|
||||
if (getKind(node.nameOffset) != NodeKind.Value) return false;
|
||||
@@ -478,7 +478,7 @@ public func bool Reader.getNumber(const Reader* r, const char* key, u32* result)
|
||||
return true;
|
||||
}
|
||||
|
||||
public func bool Reader.getBool(const Reader* r, const char* key, bool* result) {
|
||||
public fn bool Reader.getBool(const Reader* r, const char* key, bool* result) {
|
||||
const Node* node = r.findNode(key);
|
||||
if (!node) return false;
|
||||
if (getKind(node.nameOffset) != NodeKind.Value) return false;
|
||||
@@ -493,18 +493,18 @@ public type NodeIter struct {
|
||||
const Node* node;
|
||||
}
|
||||
|
||||
public func bool NodeIter.done(const NodeIter* i) {
|
||||
public fn bool NodeIter.done(const NodeIter* i) {
|
||||
return i.node == nil;
|
||||
}
|
||||
|
||||
public func void NodeIter.next(NodeIter* i) {
|
||||
public fn void NodeIter.next(NodeIter* i) {
|
||||
if (i.node == nil) return;
|
||||
u32 next = i.node.nextNode;
|
||||
if (next == 0) i.node = nil;
|
||||
else i.node = &i.blocks.nodes[next];
|
||||
}
|
||||
|
||||
public func const char* NodeIter.getValue(const NodeIter* i, const char* key) {
|
||||
public fn const char* NodeIter.getValue(const NodeIter* i, const char* key) {
|
||||
const Node* child = i.blocks.findNode(key, i.node);
|
||||
if (!child) return nil;
|
||||
if (getKind(child.nameOffset) != NodeKind.Value) return nil;
|
||||
@@ -513,7 +513,7 @@ public func const char* NodeIter.getValue(const NodeIter* i, const char* key) {
|
||||
return &i.blocks.values[getRawValue(child.rawValue)];
|
||||
}
|
||||
|
||||
public func bool NodeIter.getNumber(const NodeIter* i, const char* key, u32* result) {
|
||||
public fn bool NodeIter.getNumber(const NodeIter* i, const char* key, u32* result) {
|
||||
const Node* child = i.blocks.findNode(key, i.node);
|
||||
if (!child) return false;
|
||||
if (getKind(child.nameOffset) != NodeKind.Value) return false;
|
||||
@@ -523,7 +523,7 @@ public func bool NodeIter.getNumber(const NodeIter* i, const char* key, u32* res
|
||||
return true;
|
||||
}
|
||||
|
||||
public func bool NodeIter.getBool(const NodeIter* i, const char* key, bool* result) {
|
||||
public fn bool NodeIter.getBool(const NodeIter* i, const char* key, bool* result) {
|
||||
const Node* child = i.blocks.findNode(key, i.node);
|
||||
if (!child) return false;
|
||||
if (getKind(child.nameOffset) != NodeKind.Value) return false;
|
||||
@@ -533,7 +533,7 @@ public func bool NodeIter.getBool(const NodeIter* i, const char* key, bool* resu
|
||||
return true;
|
||||
}
|
||||
|
||||
public func NodeIter Reader.getNodeIter(const Reader* r, const char* key) {
|
||||
public fn NodeIter Reader.getNodeIter(const Reader* r, const char* key) {
|
||||
const Node* node = r.findNode(key);
|
||||
if (node && getKind(node.nameOffset) == NodeKind.TableArray) {
|
||||
node = &r.blocks.nodes[node.child];
|
||||
@@ -548,26 +548,26 @@ public type ValueIter struct {
|
||||
bool isArray;
|
||||
}
|
||||
|
||||
func ValueIter ValueIter.create(const char* values, bool isArray) {
|
||||
fn ValueIter ValueIter.create(const char* values, bool isArray) {
|
||||
ValueIter iter = { values, isArray }
|
||||
return iter;
|
||||
}
|
||||
|
||||
public func bool ValueIter.done(const ValueIter* i) {
|
||||
public fn bool ValueIter.done(const ValueIter* i) {
|
||||
return i.values[0] == 0;
|
||||
}
|
||||
|
||||
public func void ValueIter.next(ValueIter* i) {
|
||||
public fn void ValueIter.next(ValueIter* i) {
|
||||
if (i.values[0] == 0) return;
|
||||
while (i.values[0] != 0) i.values++;
|
||||
if (i.isArray) i.values++; // skip 0-terminator
|
||||
}
|
||||
|
||||
public func const char* ValueIter.getValue(const ValueIter* i) {
|
||||
public fn const char* ValueIter.getValue(const ValueIter* i) {
|
||||
return i.values;
|
||||
}
|
||||
|
||||
public func ValueIter Reader.getValueIter(const Reader* r, const char* key) {
|
||||
public fn ValueIter Reader.getValueIter(const Reader* r, const char* key) {
|
||||
const Node* node = r.findNode(key);
|
||||
if (node) {
|
||||
switch (getKind(node.nameOffset)) {
|
||||
@@ -608,7 +608,7 @@ const u32 ValueIsArray = (1 << 31);
|
||||
const u32 ValueTypeOffset = 29;
|
||||
const u32 RawValueMask = (0x7 << 29);
|
||||
|
||||
func const char* type2str(ValueType t) {
|
||||
fn const char* type2str(ValueType t) {
|
||||
switch (t) {
|
||||
case ValueType.Text: return "T";
|
||||
case ValueType.Number: return "N";
|
||||
@@ -643,7 +643,7 @@ public type Blocks struct {
|
||||
u32 valuesSize;
|
||||
} @(opaque)
|
||||
|
||||
func void Blocks.init(Blocks* b) {
|
||||
fn void Blocks.init(Blocks* b) {
|
||||
memset(b, 0, sizeof(Blocks));
|
||||
b.nodes = calloc(MaxNodes, sizeof(Node));
|
||||
|
||||
@@ -662,13 +662,13 @@ func void Blocks.init(Blocks* b) {
|
||||
memset(b.namesCache, 0, sizeof(u32)*NamesCacheSize);
|
||||
}
|
||||
|
||||
func void Blocks.destroy(Blocks* b) {
|
||||
fn void Blocks.destroy(Blocks* b) {
|
||||
free(b.values);
|
||||
free(b.names);
|
||||
free(b.nodes);
|
||||
}
|
||||
|
||||
func u32 Blocks.searchNameCache(Blocks* b, const char* name) {
|
||||
fn u32 Blocks.searchNameCache(Blocks* b, const char* name) {
|
||||
for (u32 i=0; i<NamesCacheSize; ++i) {
|
||||
u32 off = b.namesCache[i];
|
||||
if (off && same(&b.names[off], name)) return off;
|
||||
@@ -676,12 +676,12 @@ func u32 Blocks.searchNameCache(Blocks* b, const char* name) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
func const char* Blocks.getName(const Blocks* b, const Node* node) {
|
||||
fn const char* Blocks.getName(const Blocks* b, const Node* node) {
|
||||
return &b.names[getValue(node.nameOffset)];
|
||||
}
|
||||
|
||||
|
||||
func u32 Blocks.addNode(Blocks* b, const char* name, NodeKind k) {
|
||||
fn u32 Blocks.addNode(Blocks* b, const char* name, NodeKind k) {
|
||||
if (b.nodeCount == MaxNodes) {
|
||||
// TODO jmp?
|
||||
printf("node limit reached\n");
|
||||
@@ -712,7 +712,7 @@ func u32 Blocks.addNode(Blocks* b, const char* name, NodeKind k) {
|
||||
return off;
|
||||
}
|
||||
|
||||
func u32 Blocks.addValue(Blocks* b, const char* value) {
|
||||
fn u32 Blocks.addValue(Blocks* b, const char* value) {
|
||||
if (value[0] == 0) return 0;
|
||||
u32 off = b.valuesOffset;
|
||||
u32 len = cast<u32>(strlen(value)) + 1;
|
||||
@@ -721,12 +721,12 @@ func u32 Blocks.addValue(Blocks* b, const char* value) {
|
||||
return off;
|
||||
}
|
||||
|
||||
func void Blocks.addNull(Blocks* b) {
|
||||
fn void Blocks.addNull(Blocks* b) {
|
||||
b.values[b.valuesOffset] = 0;
|
||||
b.valuesOffset++;
|
||||
}
|
||||
|
||||
func Node* Blocks.findNode(const Blocks* b, const char* name, const Node* parent) {
|
||||
fn Node* Blocks.findNode(const Blocks* b, const char* name, const Node* parent) {
|
||||
if (b.nodeCount == 0) return nil;
|
||||
Node* node = &b.nodes[0];
|
||||
if (parent) {
|
||||
@@ -746,14 +746,14 @@ func Node* Blocks.findNode(const Blocks* b, const char* name, const Node* parent
|
||||
|
||||
const u32 NodeKindOffset = 29;
|
||||
|
||||
func u32 addKind(u32 value, NodeKind k) @(inline) {
|
||||
fn u32 addKind(u32 value, NodeKind k) @(inline) {
|
||||
return value | (k << NodeKindOffset);
|
||||
}
|
||||
|
||||
func NodeKind getKind(u32 value) @(inline) {
|
||||
fn NodeKind getKind(u32 value) @(inline) {
|
||||
return cast<NodeKind>(value >> NodeKindOffset);
|
||||
}
|
||||
|
||||
func u32 getValue(u32 value) @(inline) {
|
||||
fn u32 getValue(u32 value) @(inline) {
|
||||
return value & ~(0x7 << NodeKindOffset);
|
||||
}
|
||||
|
||||
@@ -25,13 +25,13 @@ enum TokenKind : char (String name)
|
||||
ERROR("error"),
|
||||
}
|
||||
|
||||
func void Location.init(Location* l, uint line = 0, uint col = 0)
|
||||
fn void Location.init(Location* l, uint line = 0, uint col = 0)
|
||||
{
|
||||
l.line = line;
|
||||
l.column = col;
|
||||
}
|
||||
|
||||
func string Location.str(Location* l)
|
||||
fn string Location.str(Location* l)
|
||||
{
|
||||
static char[32] msg;
|
||||
sprintf(msg, "line %u:%u", l.line, l.column);
|
||||
@@ -50,7 +50,7 @@ struct Token
|
||||
}
|
||||
}
|
||||
|
||||
func void Token.init(Token* t)
|
||||
fn void Token.init(Token* t)
|
||||
{
|
||||
t.loc.init(0, 0);
|
||||
t.kind = TokenKind.EOF;
|
||||
@@ -58,28 +58,28 @@ func void Token.init(Token* t)
|
||||
t.number = 0;
|
||||
}
|
||||
|
||||
func void Token.clear(Token* t)
|
||||
fn void Token.clear(Token* t)
|
||||
{
|
||||
t.text = nil;
|
||||
t.number = 0;
|
||||
}
|
||||
|
||||
func void Token.setLocation(Token* t, Location l)
|
||||
fn void Token.setLocation(Token* t, Location l)
|
||||
{
|
||||
t.loc = l;
|
||||
}
|
||||
|
||||
func bool Token.is(Token* t, TokenKind k)
|
||||
fn bool Token.is(Token* t, TokenKind k)
|
||||
{
|
||||
return t.kind == k;
|
||||
}
|
||||
|
||||
func bool Token.isNot(Token* t, TokenKind k)
|
||||
fn bool Token.isNot(Token* t, TokenKind k)
|
||||
{
|
||||
return t.kind != k;
|
||||
}
|
||||
|
||||
func string Token.getName(Token* t)
|
||||
fn string Token.getName(Token* t)
|
||||
{
|
||||
return t.kind.name;
|
||||
}
|
||||
@@ -94,7 +94,7 @@ struct Tokenizer
|
||||
bool haveNext;
|
||||
}
|
||||
|
||||
func void Tokenizer.init(Tokenizer* t, char* input)
|
||||
fn void Tokenizer.init(Tokenizer* t, char* input)
|
||||
{
|
||||
t.dataStart = input;
|
||||
t.current = input;
|
||||
@@ -109,7 +109,7 @@ error LexError
|
||||
string error_message;
|
||||
}
|
||||
|
||||
func void! Tokenizer.lex(Tokenizer* t, Token* result)
|
||||
fn void! Tokenizer.lex(Tokenizer* t, Token* result)
|
||||
{
|
||||
if (t.haveNext)
|
||||
{
|
||||
@@ -221,7 +221,7 @@ func void! Tokenizer.lex(Tokenizer* t, Token* result)
|
||||
}
|
||||
}
|
||||
|
||||
func Token*! Tokenizer.lookahead(Tokenizer* t)
|
||||
fn Token*! Tokenizer.lookahead(Tokenizer* t)
|
||||
{
|
||||
if (!t.haveNext)
|
||||
{
|
||||
@@ -231,13 +231,13 @@ func Token*! Tokenizer.lookahead(Tokenizer* t)
|
||||
return &t.nextToken;
|
||||
}
|
||||
|
||||
func void Tokenizer.advance(Tokenizer* t, uint amount)
|
||||
fn void Tokenizer.advance(Tokenizer* t, uint amount)
|
||||
{
|
||||
t.loc.column += amount;
|
||||
t.current += amount;
|
||||
}
|
||||
|
||||
func void Tokenizer.parseComment(Tokenizer* t)
|
||||
fn void Tokenizer.parseComment(Tokenizer* t)
|
||||
{
|
||||
while (1)
|
||||
{
|
||||
@@ -258,7 +258,7 @@ func void Tokenizer.parseComment(Tokenizer* t)
|
||||
}
|
||||
}
|
||||
|
||||
func void Tokenizer.parseText(Tokenizer* t, Token* result)
|
||||
fn void Tokenizer.parseText(Tokenizer* t, Token* result)
|
||||
{
|
||||
// TODO handle literal strings ' .. ' -> no escaping
|
||||
// TODO handle escape chars for normal strings " .. \" \r \n "
|
||||
@@ -277,7 +277,7 @@ func void Tokenizer.parseText(Tokenizer* t, Token* result)
|
||||
t.advance(1);
|
||||
}
|
||||
|
||||
func void! Tokenizer.parseMultiText(Tokenizer* t, Token* result)
|
||||
fn void! Tokenizer.parseMultiText(Tokenizer* t, Token* result)
|
||||
{
|
||||
t.advance(3);
|
||||
if (t.current[0] == '\n')
|
||||
@@ -317,7 +317,7 @@ func void! Tokenizer.parseMultiText(Tokenizer* t, Token* result)
|
||||
t.advance(3);
|
||||
}
|
||||
|
||||
func void Tokenizer.parseNumber(Tokenizer* t, Token* result)
|
||||
fn void Tokenizer.parseNumber(Tokenizer* t, Token* result)
|
||||
{
|
||||
// TODO handle prefix +/-
|
||||
// handle hexadecimal/ocal/binary number
|
||||
@@ -333,7 +333,7 @@ func void Tokenizer.parseNumber(Tokenizer* t, Token* result)
|
||||
}
|
||||
}
|
||||
|
||||
func bool isKeyChar(u8 c)
|
||||
fn bool isKeyChar(u8 c)
|
||||
{
|
||||
if (c >= 128) return true;
|
||||
if (isalpha(c)) return true;
|
||||
@@ -342,7 +342,7 @@ func bool isKeyChar(u8 c)
|
||||
return false;
|
||||
}
|
||||
|
||||
func void Tokenizer.parseKey(Tokenizer* t, Token* result)
|
||||
fn void Tokenizer.parseKey(Tokenizer* t, Token* result)
|
||||
{
|
||||
char* start = t.current;
|
||||
while (t.current[0] && isKeyChar((char)(t.current[0]))) t.current++;
|
||||
|
||||
@@ -5,42 +5,42 @@ public struct Vector
|
||||
Type[] array;
|
||||
}
|
||||
|
||||
public func void Vector.init()
|
||||
public fn void Vector.init()
|
||||
{
|
||||
array = nil;
|
||||
}
|
||||
|
||||
public func void Vector.add(Vector *vector, Type type)
|
||||
public fn void Vector.add(Vector *vector, Type type)
|
||||
{
|
||||
vector.array += type;
|
||||
}
|
||||
|
||||
public func usize Vector.size(Vector *vector)
|
||||
public fn usize Vector.size(Vector *vector)
|
||||
{
|
||||
return vector.array.size;
|
||||
}
|
||||
|
||||
public func void Vector.removeLast(Vector *vector)
|
||||
public fn void Vector.removeLast(Vector *vector)
|
||||
{
|
||||
vector.array.pop();
|
||||
}
|
||||
|
||||
public func void Vector.removefirst(Vector *vector)
|
||||
public fn void Vector.removefirst(Vector *vector)
|
||||
{
|
||||
vector.array.removeAt(0);
|
||||
}
|
||||
|
||||
public func void Type *Vector.first(Vector *vector)
|
||||
public fn void Type *Vector.first(Vector *vector)
|
||||
{
|
||||
return &vector.array.first;
|
||||
}
|
||||
|
||||
public func void Type *Vector.last(Vector *vector)
|
||||
public fn void Type *Vector.last(Vector *vector)
|
||||
{
|
||||
return &vector.array.last();
|
||||
}
|
||||
|
||||
public func bool Vector.empty(Vector *vector)
|
||||
public fn bool Vector.empty(Vector *vector)
|
||||
{
|
||||
return !vector.array.size;
|
||||
}
|
||||
|
||||
@@ -3,8 +3,8 @@ import std::math;
|
||||
|
||||
interface Geometry
|
||||
{
|
||||
func double area();
|
||||
func double perim();
|
||||
fn double area();
|
||||
fn double perim();
|
||||
}
|
||||
|
||||
struct Rect
|
||||
@@ -17,32 +17,32 @@ struct Circle
|
||||
double radius;
|
||||
}
|
||||
|
||||
func double Rect.area(Rect *r)
|
||||
fn double Rect.area(Rect *r)
|
||||
{
|
||||
return r.width * r.height;
|
||||
}
|
||||
|
||||
func double Rect.perim(Rect *r)
|
||||
fn double Rect.perim(Rect *r)
|
||||
{
|
||||
return 2 * r.width + 2 * r.height;
|
||||
}
|
||||
|
||||
func double Circle.area(Circle *c)
|
||||
fn double Circle.area(Circle *c)
|
||||
{
|
||||
return math::PI * c.radius * c.radius
|
||||
}
|
||||
|
||||
func double Circle.perim(Circle *c)
|
||||
fn double Circle.perim(Circle *c)
|
||||
{
|
||||
return math::PI * c.radius * 2;
|
||||
}
|
||||
|
||||
func void measure(virtual Geometry g)
|
||||
fn void measure(virtual Geometry g)
|
||||
{
|
||||
printf("area: %f, perimeter: %f\n", g.area(), g.perim());
|
||||
}
|
||||
|
||||
func void main()
|
||||
fn void main()
|
||||
{
|
||||
Rect r = { 3, 4 };
|
||||
Circle c = { 5 };
|
||||
|
||||
@@ -3,7 +3,7 @@ import gtk;
|
||||
const string CLICK_ME = "Click Me";
|
||||
uint counter = 0;
|
||||
|
||||
func void clickedme(GtkButton *o, void *d)
|
||||
fn void clickedme(GtkButton *o, void *d)
|
||||
{
|
||||
(GtkLabel*)(d).set_text(string.format("You clicked me %d times", ++counter));
|
||||
}
|
||||
|
||||
@@ -2,18 +2,18 @@ module spectralnorm;
|
||||
import std::mem;
|
||||
import std::array;
|
||||
|
||||
extern func int atoi(char *s);
|
||||
extern func int printf(char *s, ...);
|
||||
extern func double sqrt(double);
|
||||
extern fn int atoi(char *s);
|
||||
extern fn int printf(char *s, ...);
|
||||
extern fn double sqrt(double);
|
||||
|
||||
double[] temparr;
|
||||
|
||||
func double eval_A(int i, int j)
|
||||
fn double eval_A(int i, int j)
|
||||
{
|
||||
return 1.0 / ((i + j) * (i + j + 1) / 2 + i + 1);
|
||||
}
|
||||
|
||||
func void eval_A_times_u(double[] u, double[] au)
|
||||
fn void eval_A_times_u(double[] u, double[] au)
|
||||
{
|
||||
foreach (i, &val : au)
|
||||
{
|
||||
@@ -25,7 +25,7 @@ func void eval_A_times_u(double[] u, double[] au)
|
||||
}
|
||||
}
|
||||
|
||||
func void eval_At_times_u(double[] u, double[] au)
|
||||
fn void eval_At_times_u(double[] u, double[] au)
|
||||
{
|
||||
foreach (i, &val : au)
|
||||
{
|
||||
@@ -37,13 +37,13 @@ func void eval_At_times_u(double[] u, double[] au)
|
||||
}
|
||||
}
|
||||
|
||||
func void eval_AtA_times_u(double[] u, double[] atau) @noinline
|
||||
fn void eval_AtA_times_u(double[] u, double[] atau) @noinline
|
||||
{
|
||||
eval_A_times_u(u, temparr);
|
||||
eval_At_times_u(temparr, atau);
|
||||
}
|
||||
|
||||
func int main(int argc, char **argv)
|
||||
fn int main(int argc, char **argv)
|
||||
{
|
||||
int n = (argc == 2) ? atoi(argv[1]) : 2000;
|
||||
temparr = @array::make(double, n);
|
||||
|
||||
@@ -56,7 +56,7 @@ void comment(void);
|
||||
"void" { count(); return(VOID); }
|
||||
"volatile" { count(); return(VOLATILE); }
|
||||
"while" { count(); return(WHILE); }
|
||||
"func" { count(); return(FUNC); }
|
||||
"fn" { count(); return(FUNC); }
|
||||
"nil" { count(); return(NIL); }
|
||||
"next" { count(); return(NEXT); }
|
||||
"in" { count(); return(IN); }
|
||||
|
||||
@@ -8,18 +8,18 @@ struct Adler32
|
||||
uint b;
|
||||
}
|
||||
|
||||
func void Adler32.init(Adler32 *this)
|
||||
fn void Adler32.init(Adler32 *this)
|
||||
{
|
||||
*this = { 1, 0 };
|
||||
}
|
||||
|
||||
func void Adler32.updatec(Adler32* this, char c)
|
||||
fn void Adler32.updatec(Adler32* this, char c)
|
||||
{
|
||||
this.a = (this.a + c) % ADLER_CONST;
|
||||
this.b = (this.b + this.a) % ADLER_CONST;
|
||||
}
|
||||
|
||||
func void Adler32.update(Adler32* this, char[] data)
|
||||
fn void Adler32.update(Adler32* this, char[] data)
|
||||
{
|
||||
uint a = this.a;
|
||||
uint b = this.b;
|
||||
@@ -31,12 +31,12 @@ func void Adler32.update(Adler32* this, char[] data)
|
||||
*this = { a, b };
|
||||
}
|
||||
|
||||
func uint Adler32.final(Adler32* this)
|
||||
fn uint Adler32.final(Adler32* this)
|
||||
{
|
||||
return (this.b << 16) | this.a;
|
||||
}
|
||||
|
||||
func uint encode(char[] data)
|
||||
fn uint encode(char[] data)
|
||||
{
|
||||
uint a = 1;
|
||||
uint b = 0;
|
||||
|
||||
@@ -5,17 +5,17 @@ struct Crc32
|
||||
uint result;
|
||||
}
|
||||
|
||||
func void Crc32.init(Crc32* this, uint seed = 0)
|
||||
fn void Crc32.init(Crc32* this, uint seed = 0)
|
||||
{
|
||||
this.result = ~seed;
|
||||
}
|
||||
|
||||
func void Crc32.updatec(Crc32* this, char c)
|
||||
fn void Crc32.updatec(Crc32* this, char c)
|
||||
{
|
||||
this.result = (this.result >> 8) ^ CRC32_TABLE[(this.result ^ c) & 0xFF];
|
||||
}
|
||||
|
||||
func void Crc32.update(Crc32* this, char[] data)
|
||||
fn void Crc32.update(Crc32* this, char[] data)
|
||||
{
|
||||
uint result = this.result;
|
||||
foreach (char x : data)
|
||||
@@ -25,12 +25,12 @@ func void Crc32.update(Crc32* this, char[] data)
|
||||
this.result = result;
|
||||
}
|
||||
|
||||
func uint Crc32.final(Crc32* this)
|
||||
fn uint Crc32.final(Crc32* this)
|
||||
{
|
||||
return ~this.result;
|
||||
}
|
||||
|
||||
func uint encode(char[] data)
|
||||
fn uint encode(char[] data)
|
||||
{
|
||||
uint result = ~(uint)(0);
|
||||
foreach (char x : data)
|
||||
|
||||
@@ -5,17 +5,17 @@ struct Crc64
|
||||
ulong result;
|
||||
}
|
||||
|
||||
func void Crc64.init(Crc64* this, uint seed = 0)
|
||||
fn void Crc64.init(Crc64* this, uint seed = 0)
|
||||
{
|
||||
this.result = seed;
|
||||
}
|
||||
|
||||
func void Crc64.updatec(Crc64* this, char c)
|
||||
fn void Crc64.updatec(Crc64* this, char c)
|
||||
{
|
||||
this.result = (this.result << 8) ^ CRC64_TABLE[(char)((this.result >> 56) ^ c)];
|
||||
}
|
||||
|
||||
func void Crc64.update(Crc64* this, char[] data)
|
||||
fn void Crc64.update(Crc64* this, char[] data)
|
||||
{
|
||||
ulong result = this.result;
|
||||
foreach (char x : data)
|
||||
@@ -25,12 +25,12 @@ func void Crc64.update(Crc64* this, char[] data)
|
||||
this.result = result;
|
||||
}
|
||||
|
||||
func ulong Crc64.final(Crc64* this)
|
||||
fn ulong Crc64.final(Crc64* this)
|
||||
{
|
||||
return this.result;
|
||||
}
|
||||
|
||||
func ulong encode(char[] data)
|
||||
fn ulong encode(char[] data)
|
||||
{
|
||||
ulong result = (ulong)(0);
|
||||
foreach (char x : data)
|
||||
|
||||
@@ -29,18 +29,18 @@ struct File
|
||||
void *file;
|
||||
}
|
||||
|
||||
extern func int _puts(char* message) @extname("puts");
|
||||
extern func int printf(char* message, ...);
|
||||
extern func int _putchar(char c) @extname("putchar");
|
||||
extern fn int _puts(char* message) @extname("puts");
|
||||
extern fn int printf(char* message, ...);
|
||||
extern fn int _putchar(char c) @extname("putchar");
|
||||
|
||||
extern File *__stdinp;
|
||||
|
||||
func int putchar(char c) @inline
|
||||
fn int putchar(char c) @inline
|
||||
{
|
||||
return _putchar(c);
|
||||
}
|
||||
|
||||
func int print(char *message)
|
||||
fn int print(char *message)
|
||||
{
|
||||
char* pointer = message;
|
||||
while (*pointer != '\0')
|
||||
@@ -51,13 +51,13 @@ func int print(char *message)
|
||||
return 1;
|
||||
}
|
||||
|
||||
func int println(char *message = "") @inline
|
||||
fn int println(char *message = "") @inline
|
||||
{
|
||||
return _puts(message);
|
||||
}
|
||||
|
||||
|
||||
func void! File.open(File* file, char[] filename, char[] mode)
|
||||
fn void! File.open(File* file, char[] filename, char[] mode)
|
||||
{
|
||||
char* filename_copy = mem::talloc(filename.len + 1)!!;
|
||||
|
||||
|
||||
@@ -15,12 +15,12 @@ struct LinkedList
|
||||
Node *last;
|
||||
}
|
||||
|
||||
func void LinkedList.push(LinkedList *list, Type value)
|
||||
fn void LinkedList.push(LinkedList *list, Type value)
|
||||
{
|
||||
list.linkLast(value);
|
||||
}
|
||||
|
||||
private func void LinkedList.linkFirst(LinkedList *list, Type value)
|
||||
private fn void LinkedList.linkFirst(LinkedList *list, Type value)
|
||||
{
|
||||
Node *first = list.first;
|
||||
Node *new_node = @mem::malloc(Node);
|
||||
@@ -37,7 +37,7 @@ private func void LinkedList.linkFirst(LinkedList *list, Type value)
|
||||
list.size++;
|
||||
}
|
||||
|
||||
private func void LinkedList.linkLast(LinkedList *list, Type value)
|
||||
private fn void LinkedList.linkLast(LinkedList *list, Type value)
|
||||
{
|
||||
Node *last = list.last;
|
||||
Node *new_node = mem::alloc($sizeof(Node));
|
||||
@@ -54,7 +54,7 @@ private func void LinkedList.linkLast(LinkedList *list, Type value)
|
||||
list.size++;
|
||||
}
|
||||
|
||||
func void LinkedList.free(LinkedList *list)
|
||||
fn void LinkedList.free(LinkedList *list)
|
||||
{
|
||||
for (Node* node = list.first; node != null;)
|
||||
{
|
||||
@@ -67,12 +67,12 @@ func void LinkedList.free(LinkedList *list)
|
||||
list.size = 0;
|
||||
}
|
||||
|
||||
func usize LinkedList.len(LinkedList* list) @inline
|
||||
fn usize LinkedList.len(LinkedList* list) @inline
|
||||
{
|
||||
return list.size;
|
||||
}
|
||||
|
||||
func Type LinkedList.get(LinkedList* list, usize index)
|
||||
fn Type LinkedList.get(LinkedList* list, usize index)
|
||||
{
|
||||
Node* node = list.first;
|
||||
while (index--)
|
||||
@@ -84,7 +84,7 @@ func Type LinkedList.get(LinkedList* list, usize index)
|
||||
/**
|
||||
* @require succ != null
|
||||
**/
|
||||
private func void LinkedList.linkBefore(LinkedList *list, Node *succ, Type value)
|
||||
private fn void LinkedList.linkBefore(LinkedList *list, Node *succ, Type value)
|
||||
{
|
||||
Node* pred = succ.prev;
|
||||
Node* new_node = @mem::malloc(Node);
|
||||
@@ -104,7 +104,7 @@ private func void LinkedList.linkBefore(LinkedList *list, Node *succ, Type value
|
||||
/**
|
||||
* @require f == list.first && f != null
|
||||
**/
|
||||
private func void unlinkFirst(LinkedList* list, Node* f)
|
||||
private fn void unlinkFirst(LinkedList* list, Node* f)
|
||||
{
|
||||
Node* next = f.next;
|
||||
mem::free(f);
|
||||
@@ -123,7 +123,7 @@ private func void unlinkFirst(LinkedList* list, Node* f)
|
||||
/**
|
||||
* @require l == list.last && l != null
|
||||
**/
|
||||
private func void LinkedList.unlinkLast(LinkedList *list, Node* l)
|
||||
private fn void LinkedList.unlinkLast(LinkedList *list, Node* l)
|
||||
{
|
||||
Node* prev = l.prev;
|
||||
list.last = prev;
|
||||
@@ -142,7 +142,7 @@ private func void LinkedList.unlinkLast(LinkedList *list, Node* l)
|
||||
/**
|
||||
* @require x != null
|
||||
**/
|
||||
private func void LinkedList.unlink(LinkedList* list, Node* x)
|
||||
private fn void LinkedList.unlink(LinkedList* list, Node* x)
|
||||
{
|
||||
Node* next = x.next;
|
||||
Node* prev = x.prev;
|
||||
|
||||
@@ -8,7 +8,7 @@ struct List
|
||||
Type *entries;
|
||||
}
|
||||
|
||||
private func void List.ensureCapacity(List *list) @inline
|
||||
private fn void List.ensureCapacity(List *list) @inline
|
||||
{
|
||||
if (list.capacity == list.size)
|
||||
{
|
||||
@@ -17,12 +17,12 @@ private func void List.ensureCapacity(List *list) @inline
|
||||
}
|
||||
}
|
||||
|
||||
func void List.push(List *list, Type element) @inline
|
||||
fn void List.push(List *list, Type element) @inline
|
||||
{
|
||||
list.append(element);
|
||||
}
|
||||
|
||||
func void List.append(List *list, Type element)
|
||||
fn void List.append(List *list, Type element)
|
||||
{
|
||||
list.ensureCapacity();
|
||||
list.entries[list.size++] = element;
|
||||
@@ -31,7 +31,7 @@ func void List.append(List *list, Type element)
|
||||
/**
|
||||
* @require list.size > 0
|
||||
*/
|
||||
func Type List.pop(List *list)
|
||||
fn Type List.pop(List *list)
|
||||
{
|
||||
return list.entries[--list.size];
|
||||
}
|
||||
@@ -39,14 +39,14 @@ func Type List.pop(List *list)
|
||||
/**
|
||||
* @require list.size > 0
|
||||
*/
|
||||
func Type List.popFirst(List *list)
|
||||
fn Type List.popFirst(List *list)
|
||||
{
|
||||
Type value = list.entries[0];
|
||||
list.removeAt(0);
|
||||
return value;
|
||||
}
|
||||
|
||||
func void List.removeAt(List *list, usize index)
|
||||
fn void List.removeAt(List *list, usize index)
|
||||
{
|
||||
for (usize i = index + 1; i < list.size; i++)
|
||||
{
|
||||
@@ -55,12 +55,12 @@ func void List.removeAt(List *list, usize index)
|
||||
list.size--;
|
||||
}
|
||||
|
||||
func void List.pushFront(List *list, Type type) @inline
|
||||
fn void List.pushFront(List *list, Type type) @inline
|
||||
{
|
||||
list.insertAt(0, type);
|
||||
}
|
||||
|
||||
func void List.insertAt(List *list, usize index, Type type)
|
||||
fn void List.insertAt(List *list, usize index, Type type)
|
||||
{
|
||||
list.ensureCapacity();
|
||||
for (usize i = list.size; i > index; i--)
|
||||
@@ -71,42 +71,42 @@ func void List.insertAt(List *list, usize index, Type type)
|
||||
list.entries[index] = type;
|
||||
}
|
||||
|
||||
func void List.removeLast(List *list)
|
||||
fn void List.removeLast(List *list)
|
||||
{
|
||||
list.size--;
|
||||
}
|
||||
|
||||
func void List.removeFirst(List *list)
|
||||
fn void List.removeFirst(List *list)
|
||||
{
|
||||
list.removeAt(0);
|
||||
}
|
||||
|
||||
func Type* List.first(List *list)
|
||||
fn Type* List.first(List *list)
|
||||
{
|
||||
return list.size ? &list.entries[0] : null;
|
||||
}
|
||||
|
||||
func Type* List.last(List *list)
|
||||
fn Type* List.last(List *list)
|
||||
{
|
||||
return list.size ? &list.entries[list.size - 1] : null;
|
||||
}
|
||||
|
||||
func bool List.isEmpty(List *list)
|
||||
fn bool List.isEmpty(List *list)
|
||||
{
|
||||
return list.size;
|
||||
}
|
||||
|
||||
func usize List.len(List *list)
|
||||
fn usize List.len(List *list)
|
||||
{
|
||||
return list.size;
|
||||
}
|
||||
|
||||
func Type List.get(List *list, usize index)
|
||||
fn Type List.get(List *list, usize index)
|
||||
{
|
||||
return list.entries[index];
|
||||
}
|
||||
|
||||
func void List.free(List *list)
|
||||
fn void List.free(List *list)
|
||||
{
|
||||
mem::free(list.entries);
|
||||
list.capacity = 0;
|
||||
|
||||
@@ -1,9 +1,9 @@
|
||||
module std::mem;
|
||||
|
||||
extern func void* _malloc(usize bytes) @extname("malloc");
|
||||
extern func void* _realloc(void* ptr, usize bytes) @extname("realloc");
|
||||
extern func void* _calloc(usize bytes, usize elements) @extname("calloc");
|
||||
extern func void _free(void* ptr) @extname("free");
|
||||
extern fn void* _malloc(usize bytes) @extname("malloc");
|
||||
extern fn void* _realloc(void* ptr, usize bytes) @extname("realloc");
|
||||
extern fn void* _calloc(usize bytes, usize elements) @extname("calloc");
|
||||
extern fn void _free(void* ptr) @extname("free");
|
||||
|
||||
macro volatile_load(&x)
|
||||
{
|
||||
@@ -27,7 +27,7 @@ errtype AllocationFailure
|
||||
OUT_OF_MEMORY
|
||||
}
|
||||
|
||||
define AllocatorFunction = func void!(void *data, void** pointer, usize bytes, usize alignment, AllocationKind kind);
|
||||
define AllocatorFunction = fn void!(void *data, void** pointer, usize bytes, usize alignment, AllocationKind kind);
|
||||
|
||||
struct Allocator
|
||||
{
|
||||
@@ -35,12 +35,12 @@ struct Allocator
|
||||
void *data;
|
||||
}
|
||||
|
||||
func void copy(char* dst, char* src, usize size)
|
||||
fn void copy(char* dst, char* src, usize size)
|
||||
{
|
||||
for (usize i = 0; i < size; i++) dst[i] = src[i];
|
||||
}
|
||||
|
||||
func void! system_malloc_function(void *unused, void** pointer, usize bytes, usize alignment, AllocationKind kind) @inline
|
||||
fn void! system_malloc_function(void *unused, void** pointer, usize bytes, usize alignment, AllocationKind kind) @inline
|
||||
{
|
||||
switch (kind)
|
||||
{
|
||||
@@ -72,7 +72,7 @@ struct SlotAllocator
|
||||
usize current_page;
|
||||
}
|
||||
|
||||
func void*! SlotAllocator.alloc(SlotAllocator *allocator, usize size)
|
||||
fn void*! SlotAllocator.alloc(SlotAllocator *allocator, usize size)
|
||||
{
|
||||
void* active_page = (char*)(allocator.pages) + allocator.current_page * allocator.page_size;
|
||||
void** page_pointer = (void**)(active_page);
|
||||
@@ -101,7 +101,7 @@ struct RingAllocator
|
||||
}
|
||||
|
||||
|
||||
func void* RingAllocator.alloc(RingAllocator *allocator, usize size)
|
||||
fn void* RingAllocator.alloc(RingAllocator *allocator, usize size)
|
||||
{
|
||||
if (size > allocator.size) return null;
|
||||
// Wraparound? If so, start at the beginning.
|
||||
@@ -115,7 +115,7 @@ func void* RingAllocator.alloc(RingAllocator *allocator, usize size)
|
||||
return data;
|
||||
}
|
||||
|
||||
func void* RingAllocator.realloc(RingAllocator *allocator, void* ptr, usize size)
|
||||
fn void* RingAllocator.realloc(RingAllocator *allocator, void* ptr, usize size)
|
||||
{
|
||||
if (size > allocator.size) return null;
|
||||
assert(allocator.data >= ptr && ptr < allocator.data + size, "Realloc on other allocator.");
|
||||
@@ -159,22 +159,22 @@ macro malloc($Type)
|
||||
return ($Type*)(mem::alloc($sizeof($Type)));
|
||||
}
|
||||
|
||||
func void* alloc(usize size, usize count = 1) @inline
|
||||
fn void* alloc(usize size, usize count = 1) @inline
|
||||
{
|
||||
return _malloc(size * count);
|
||||
}
|
||||
|
||||
func void* calloc(usize size, usize elements = 1) @inline
|
||||
fn void* calloc(usize size, usize elements = 1) @inline
|
||||
{
|
||||
return _calloc(size, elements);
|
||||
}
|
||||
|
||||
func void* realloc(void *ptr, usize size) @inline
|
||||
fn void* realloc(void *ptr, usize size) @inline
|
||||
{
|
||||
return _realloc(ptr, size);
|
||||
}
|
||||
|
||||
func void free(void* ptr) @inline
|
||||
fn void free(void* ptr) @inline
|
||||
{
|
||||
_free(ptr);
|
||||
}
|
||||
@@ -194,7 +194,7 @@ SlotAllocator default_allocator = {
|
||||
.current_page = 0,
|
||||
};
|
||||
|
||||
func void*! talloc(usize size)
|
||||
fn void*! talloc(usize size)
|
||||
{
|
||||
return default_allocator.alloc(size);
|
||||
}
|
||||
@@ -1,9 +1,9 @@
|
||||
module antiprime;
|
||||
import std::io;
|
||||
|
||||
extern func int printf(char* message, ...);
|
||||
extern fn int printf(char* message, ...);
|
||||
|
||||
func int countDivisors(int n)
|
||||
fn int countDivisors(int n)
|
||||
{
|
||||
if (n < 2) return 1;
|
||||
int count = 2;
|
||||
@@ -14,7 +14,7 @@ func int countDivisors(int n)
|
||||
return count;
|
||||
}
|
||||
|
||||
func int main()
|
||||
fn int main()
|
||||
{
|
||||
int maxDiv;
|
||||
int count;
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
import std::io;
|
||||
|
||||
func int main()
|
||||
fn int main()
|
||||
{
|
||||
io::println("Hello world");
|
||||
return 0;
|
||||
|
||||
@@ -13,7 +13,7 @@ public struct BigInt @opaque
|
||||
char sign;
|
||||
}
|
||||
|
||||
public func void BigInt.init(BigInt* bigInt)
|
||||
public fn void BigInt.init(BigInt* bigInt)
|
||||
{
|
||||
bigInt.number = malloc(1);
|
||||
bigInt.number[0] = 0;
|
||||
@@ -21,7 +21,7 @@ public func void BigInt.init(BigInt* bigInt)
|
||||
bigInt.sign = 1;
|
||||
}
|
||||
|
||||
public func void BigInt.initFromString(BigInt* bigInt, char* str)
|
||||
public fn void BigInt.initFromString(BigInt* bigInt, char* str)
|
||||
{
|
||||
uint size = strlen(str);
|
||||
bigInt.sign = 1;
|
||||
@@ -46,7 +46,7 @@ public func void BigInt.initFromString(BigInt* bigInt, char* str)
|
||||
bigInt.length = size;
|
||||
}
|
||||
|
||||
public func void BigInt.copyTo(BigInt* source, BigInt* target)
|
||||
public fn void BigInt.copyTo(BigInt* source, BigInt* target)
|
||||
{
|
||||
target.number = realloc(target.number, source.length);
|
||||
target.sign = source.sign;
|
||||
@@ -54,12 +54,12 @@ public func void BigInt.copyTo(BigInt* source, BigInt* target)
|
||||
for (uint i = 0; i < target.length; i++) target.number[i] = source.number[i];
|
||||
}
|
||||
|
||||
public func void BigInt.destroy(BigInt* bigInt)
|
||||
public fn void BigInt.destroy(BigInt* bigInt)
|
||||
{
|
||||
free(bigInt.number);
|
||||
}
|
||||
|
||||
func void BigInt.addIgnoreSign(BigInt* a, BigInt* b, BigInt* result)
|
||||
fn void BigInt.addIgnoreSign(BigInt* a, BigInt* b, BigInt* result)
|
||||
{
|
||||
uint length = @max(a.length, b.length) + 1;
|
||||
byte* res = malloc(length);
|
||||
@@ -98,7 +98,7 @@ func void BigInt.addIgnoreSign(BigInt* a, BigInt* b, BigInt* result)
|
||||
result.length = length;
|
||||
}
|
||||
|
||||
public func void BigInt.getMaxVal(BigInt* bigInt, uint* pos, int* val)
|
||||
public fn void BigInt.getMaxVal(BigInt* bigInt, uint* pos, int* val)
|
||||
{
|
||||
for (uint i = bigInt.length; i > 0; i++)
|
||||
{
|
||||
@@ -113,7 +113,7 @@ public func void BigInt.getMaxVal(BigInt* bigInt, uint* pos, int* val)
|
||||
*val = 0;
|
||||
}
|
||||
|
||||
public func char BigInt.compare(BigInt* a, BigInt* b)
|
||||
public fn char BigInt.compare(BigInt* a, BigInt* b)
|
||||
{
|
||||
if (a.sign != b.sign) return a.sign;
|
||||
byte aMax;
|
||||
@@ -130,7 +130,7 @@ public func char BigInt.compare(BigInt* a, BigInt* b)
|
||||
return 0;
|
||||
}
|
||||
|
||||
public func char BigInt.compareNoSign(BigInt* a, BigInt* b)
|
||||
public fn char BigInt.compareNoSign(BigInt* a, BigInt* b)
|
||||
{
|
||||
byte aMax;
|
||||
uint aMaxPos;
|
||||
@@ -146,7 +146,7 @@ public func char BigInt.compareNoSign(BigInt* a, BigInt* b)
|
||||
return 0;
|
||||
}
|
||||
|
||||
func void BigInt.subIgnoreSign(BigInt* a, BigInt* b, BigInt* result)
|
||||
fn void BigInt.subIgnoreSign(BigInt* a, BigInt* b, BigInt* result)
|
||||
{
|
||||
uint length = @max(a.length, b.length);
|
||||
byte* res = malloc(length);
|
||||
@@ -187,7 +187,7 @@ func void BigInt.subIgnoreSign(BigInt* a, BigInt* b, BigInt* result)
|
||||
result.length = length;
|
||||
}
|
||||
|
||||
public func void BigInt.add(BigInt* a, BigInt* b, BigInt* result)
|
||||
public fn void BigInt.add(BigInt* a, BigInt* b, BigInt* result)
|
||||
{
|
||||
if (a.sign == b.sign)
|
||||
{
|
||||
@@ -205,7 +205,7 @@ public func void BigInt.add(BigInt* a, BigInt* b, BigInt* result)
|
||||
}
|
||||
}
|
||||
|
||||
public func char* BigInt.toCharArray(BigInt* bigInt)
|
||||
public fn char* BigInt.toCharArray(BigInt* bigInt)
|
||||
{
|
||||
uint charLen = bigInt.length + 1 + (bigInt.sign < 0 ? 1 : 0);
|
||||
byte* out = malloc(charLen);
|
||||
@@ -227,7 +227,7 @@ public func char* BigInt.toCharArray(BigInt* bigInt)
|
||||
return out;
|
||||
}
|
||||
|
||||
public func void BigInt.print(BigInt* bigInt)
|
||||
public fn void BigInt.print(BigInt* bigInt)
|
||||
{
|
||||
char* chars = bigInt.toCharArray();
|
||||
puts(chars);
|
||||
@@ -244,7 +244,7 @@ public func void BigInt.fprint(BigInt* bigInt, FILE* file)
|
||||
}*/
|
||||
|
||||
|
||||
public func int main(int size, char** args)
|
||||
public fn int main(int size, char** args)
|
||||
{
|
||||
BigInt minus2;
|
||||
BigInt minus1;
|
||||
|
||||
@@ -6,7 +6,7 @@ struct Pixmap
|
||||
int bpp;
|
||||
}
|
||||
|
||||
func void readpgm(char* name, Pixmap* p)
|
||||
fn void readpgm(char* name, Pixmap* p)
|
||||
{
|
||||
/* ... */
|
||||
pnm_readpaminit(fp, &inpam);
|
||||
@@ -28,7 +28,7 @@ func void readpgm(char* name, Pixmap* p)
|
||||
}
|
||||
}
|
||||
|
||||
func void getComm(uint len, char* src)
|
||||
fn void getComm(uint len, char* src)
|
||||
{
|
||||
uint size;
|
||||
size = len - 2;
|
||||
@@ -36,7 +36,7 @@ func void getComm(uint len, char* src)
|
||||
memcpy(comm, src, size);
|
||||
}
|
||||
|
||||
func uint* decode_fh(uint* p, SvcFh* fhp)
|
||||
fn uint* decode_fh(uint* p, SvcFh* fhp)
|
||||
{
|
||||
int size;
|
||||
fh_init(fhp, NFS3_FHSIZE);
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
module comparisons;
|
||||
|
||||
func void test_signed()
|
||||
fn void test_signed()
|
||||
{
|
||||
int a = 0;
|
||||
int b = 1;
|
||||
@@ -14,7 +14,7 @@ func void test_signed()
|
||||
|
||||
}
|
||||
|
||||
func void test_unsigned()
|
||||
fn void test_unsigned()
|
||||
{
|
||||
uint a = 0;
|
||||
uint b = 1;
|
||||
@@ -28,9 +28,9 @@ func void test_unsigned()
|
||||
|
||||
}
|
||||
|
||||
extern func void printf(char *s);
|
||||
extern fn void printf(char *s);
|
||||
|
||||
func void test_signedunsigned()
|
||||
fn void test_signedunsigned()
|
||||
{
|
||||
char a = 0 - 1;
|
||||
byte b = (byte)(a);
|
||||
@@ -100,7 +100,7 @@ func void test_signedunsigned()
|
||||
|
||||
}
|
||||
|
||||
func void test_unsignedsigned()
|
||||
fn void test_unsignedsigned()
|
||||
{
|
||||
int b = -1;
|
||||
uint a = (uint)(b);
|
||||
@@ -170,7 +170,7 @@ func void test_unsignedsigned()
|
||||
|
||||
}
|
||||
|
||||
func void main()
|
||||
fn void main()
|
||||
{
|
||||
test_signedunsigned();
|
||||
test_unsignedsigned();
|
||||
|
||||
@@ -13,7 +13,7 @@ public struct BigInt @opaque
|
||||
char sign;
|
||||
}
|
||||
|
||||
public func void BigInt.init(BigInt& bigInt)
|
||||
public fn void BigInt.init(BigInt& bigInt)
|
||||
{
|
||||
bigInt.number = malloc(1);
|
||||
bigInt.number[0] = 0;
|
||||
@@ -21,7 +21,7 @@ public func void BigInt.init(BigInt& bigInt)
|
||||
bigInt.sign = 1;
|
||||
}
|
||||
|
||||
public func void BigInt.initFromString(BigInt& bigInt, char& str)
|
||||
public fn void BigInt.initFromString(BigInt& bigInt, char& str)
|
||||
{
|
||||
uint size = strlen(str);
|
||||
bigInt.sign = 1;
|
||||
@@ -46,14 +46,14 @@ public func void BigInt.initFromString(BigInt& bigInt, char& str)
|
||||
bigInt.length = size;
|
||||
}
|
||||
|
||||
public func BigInt& BigInt.newFromString(char& str)
|
||||
public fn BigInt& BigInt.newFromString(char& str)
|
||||
{
|
||||
BigInt& bigInt = malloc(sizeof(BigInt));
|
||||
bigInt.initFromString(str);
|
||||
return bigInt;
|
||||
}
|
||||
|
||||
public func void BigInt.copyTo(BigInt& source, BigInt& target)
|
||||
public fn void BigInt.copyTo(BigInt& source, BigInt& target)
|
||||
{
|
||||
target.number = realloc(target.number, source.length);
|
||||
target.sign = source.sign;
|
||||
@@ -61,12 +61,12 @@ public func void BigInt.copyTo(BigInt& source, BigInt& target)
|
||||
for (uint i = 0; i < target.length; i++) target.number[i] = source.number[i];
|
||||
}
|
||||
|
||||
public func void BigInt.destroy(BigInt& bigInt)
|
||||
public fn void BigInt.destroy(BigInt& bigInt)
|
||||
{
|
||||
free(bigInt.number);
|
||||
}
|
||||
|
||||
func void BigInt.addIgnoreSign(BigInt& a, BigInt& b, BigInt& result)
|
||||
fn void BigInt.addIgnoreSign(BigInt& a, BigInt& b, BigInt& result)
|
||||
{
|
||||
uint length = @max(a.length, b.length) + 1;
|
||||
byte* res = malloc(length);
|
||||
@@ -105,7 +105,7 @@ func void BigInt.addIgnoreSign(BigInt& a, BigInt& b, BigInt& result)
|
||||
result.length = length;
|
||||
}
|
||||
|
||||
public func void BigInt.getMaxVal(BigInt &bigInt, uint& pos, int& val)
|
||||
public fn void BigInt.getMaxVal(BigInt &bigInt, uint& pos, int& val)
|
||||
{
|
||||
for (uint i = bigInt.length; i > 0; i++)
|
||||
{
|
||||
@@ -120,7 +120,7 @@ public func void BigInt.getMaxVal(BigInt &bigInt, uint& pos, int& val)
|
||||
*val = 0;
|
||||
}
|
||||
|
||||
public func char BigInt.compare(BigInt& a, BigInt& b)
|
||||
public fn char BigInt.compare(BigInt& a, BigInt& b)
|
||||
{
|
||||
if (a.sign != b.sign) return a.sign;
|
||||
byte aMax;
|
||||
@@ -137,7 +137,7 @@ public func char BigInt.compare(BigInt& a, BigInt& b)
|
||||
return 0;
|
||||
}
|
||||
|
||||
public func char BigInt.compareNoSign(BigInt& a, BigInt& b)
|
||||
public fn char BigInt.compareNoSign(BigInt& a, BigInt& b)
|
||||
{
|
||||
byte aMax;
|
||||
uint aMaxPos;
|
||||
@@ -153,7 +153,7 @@ public func char BigInt.compareNoSign(BigInt& a, BigInt& b)
|
||||
return 0;
|
||||
}
|
||||
|
||||
func void BigInt.subIgnoreSign(BigInt& a, BigInt& b, BigInt& result)
|
||||
fn void BigInt.subIgnoreSign(BigInt& a, BigInt& b, BigInt& result)
|
||||
{
|
||||
uint length = @max(a.length, b.length);
|
||||
byte& res = malloc(length);
|
||||
@@ -194,7 +194,7 @@ func void BigInt.subIgnoreSign(BigInt& a, BigInt& b, BigInt& result)
|
||||
result.length = length;
|
||||
}
|
||||
|
||||
public func void BigInt.add(BigInt& a, BigInt& b, BigInt& result)
|
||||
public fn void BigInt.add(BigInt& a, BigInt& b, BigInt& result)
|
||||
{
|
||||
if (a.sign == b.sign)
|
||||
{
|
||||
@@ -212,7 +212,7 @@ public func void BigInt.add(BigInt& a, BigInt& b, BigInt& result)
|
||||
}
|
||||
}
|
||||
|
||||
public func char* BigInt.toCharArray(BigInt* bigInt)
|
||||
public fn char* BigInt.toCharArray(BigInt* bigInt)
|
||||
{
|
||||
uint charLen = bigInt.length + 1 + (bigInt.sign < 0 ? 1 : 0);
|
||||
byte* out = malloc(charLen);
|
||||
@@ -234,7 +234,7 @@ public func char* BigInt.toCharArray(BigInt* bigInt)
|
||||
return out;
|
||||
}
|
||||
|
||||
public func void BigInt.print(BigInt& bigInt)
|
||||
public fn void BigInt.print(BigInt& bigInt)
|
||||
{
|
||||
char* chars = bigInt.toCharArray();
|
||||
puts(chars);
|
||||
@@ -251,7 +251,7 @@ public func void BigInt.fprint(BigInt* bigInt, FILE* file)
|
||||
}*/
|
||||
|
||||
|
||||
public func int main(int size, char*& args)
|
||||
public fn int main(int size, char*& args)
|
||||
{
|
||||
BigInt minus2;
|
||||
BigInt minus1;
|
||||
|
||||
@@ -5,7 +5,7 @@ int bob = 'HELO';
|
||||
|
||||
typedef Foo* as Bob;
|
||||
|
||||
func void testdefer(int x)
|
||||
fn void testdefer(int x)
|
||||
{
|
||||
defer printf("A");
|
||||
defer
|
||||
@@ -67,7 +67,7 @@ struct Simple
|
||||
int i;
|
||||
double j;
|
||||
}
|
||||
func int boo()
|
||||
fn int boo()
|
||||
{
|
||||
Zed zfe;
|
||||
Simple s = { 1 };
|
||||
@@ -148,11 +148,11 @@ func int boo()
|
||||
return 1;
|
||||
}
|
||||
|
||||
func int helo(int i)
|
||||
fn int helo(int i)
|
||||
{
|
||||
return i + 1;
|
||||
}
|
||||
func void while_test()
|
||||
fn void while_test()
|
||||
{
|
||||
|
||||
int a = 10;
|
||||
@@ -164,7 +164,7 @@ func void while_test()
|
||||
}
|
||||
}
|
||||
|
||||
func void test()
|
||||
fn void test()
|
||||
{
|
||||
int a = 10;
|
||||
while (1)
|
||||
@@ -183,7 +183,7 @@ func void test()
|
||||
return;
|
||||
}
|
||||
|
||||
func void main()
|
||||
fn void main()
|
||||
{
|
||||
helo(2);
|
||||
printf("Helo\n");
|
||||
|
||||
@@ -1,8 +1,8 @@
|
||||
module demo1;
|
||||
|
||||
// Use C functions directly.
|
||||
extern func int printf(char *, ...);
|
||||
extern func void puts(char *);
|
||||
extern fn int printf(char *, ...);
|
||||
extern fn void puts(char *);
|
||||
|
||||
struct Foo
|
||||
{
|
||||
@@ -10,7 +10,7 @@ struct Foo
|
||||
int b;
|
||||
}
|
||||
|
||||
func Foo createFoo(int a, int b = 10)
|
||||
fn Foo createFoo(int a, int b = 10)
|
||||
{
|
||||
// Compound initializer
|
||||
return Foo({a, b});
|
||||
@@ -23,7 +23,7 @@ struct Bar
|
||||
}
|
||||
|
||||
|
||||
func void testStruct()
|
||||
fn void testStruct()
|
||||
{
|
||||
// Default arguments
|
||||
Foo foo = createFoo(100);
|
||||
@@ -47,17 +47,17 @@ func void testStruct()
|
||||
|
||||
}
|
||||
|
||||
func int Bar.add(Bar* b)
|
||||
fn int Bar.add(Bar* b)
|
||||
{
|
||||
return b.x + b.y;
|
||||
}
|
||||
|
||||
func int Foo.mult(Foo* f)
|
||||
fn int Foo.mult(Foo* f)
|
||||
{
|
||||
return f.a * f.b;
|
||||
}
|
||||
|
||||
func void printArray(int[] array)
|
||||
fn void printArray(int[] array)
|
||||
{
|
||||
printf("[");
|
||||
foreach (i, a : array)
|
||||
@@ -69,7 +69,7 @@ func void printArray(int[] array)
|
||||
}
|
||||
|
||||
|
||||
func void testArrays()
|
||||
fn void testArrays()
|
||||
{
|
||||
int[5] x = { [0] = 100, [1..2] = 4 };
|
||||
puts("Testing arrays---");
|
||||
@@ -118,7 +118,7 @@ func void testArrays()
|
||||
printf("Pointer to array: %p\nPointer to slice: %p\nPointer to first element of slice: %p\n", z, &y, &y[0]);
|
||||
}
|
||||
|
||||
func void testExpressionBlocks()
|
||||
fn void testExpressionBlocks()
|
||||
{
|
||||
int x = {|
|
||||
int j = 0;
|
||||
@@ -144,7 +144,7 @@ func void testExpressionBlocks()
|
||||
}
|
||||
}
|
||||
|
||||
func void main()
|
||||
fn void main()
|
||||
{
|
||||
testStruct();
|
||||
testArrays();
|
||||
|
||||
@@ -11,7 +11,7 @@ struct Foo
|
||||
|
||||
//define bar::blub(Foo, 1) as fooblub;
|
||||
|
||||
public func void main()
|
||||
public fn void main()
|
||||
{
|
||||
Foo f = { 3, 4 };
|
||||
//Foo g = fooblub(&f);
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
module bar(Type, i);
|
||||
|
||||
public func Type blub(Type type)
|
||||
public fn Type blub(Type type)
|
||||
{
|
||||
type.x = i;
|
||||
return type;
|
||||
|
||||
@@ -1,8 +1,8 @@
|
||||
module helloworld;
|
||||
|
||||
extern func void printf(char *str, ...);
|
||||
extern fn void printf(char *str, ...);
|
||||
|
||||
func void main()
|
||||
fn void main()
|
||||
{
|
||||
printf("Hello World!\n");
|
||||
}
|
||||
@@ -11,7 +11,7 @@ struct Boo
|
||||
};
|
||||
}
|
||||
|
||||
func void test()
|
||||
fn void test()
|
||||
{
|
||||
int i = 0;
|
||||
i++;
|
||||
|
||||
@@ -68,7 +68,7 @@ error Errors
|
||||
OTHER_ERROR
|
||||
}
|
||||
|
||||
func Foom test(int a)
|
||||
fn Foom test(int a)
|
||||
{
|
||||
while (int x = 0, int y = 3; int y = foo())
|
||||
{
|
||||
@@ -85,7 +85,7 @@ func Foom test(int a)
|
||||
return 1 + 2;
|
||||
}
|
||||
|
||||
func boo::Bar zab::Baz.sd(die::Eij i) throws Zab // , sij:Zig
|
||||
fn boo::Bar zab::Baz.sd(die::Eij i) throws Zab // , sij:Zig
|
||||
{
|
||||
float a = 0, b = 3, double c = 1, d;
|
||||
int i = 0;
|
||||
@@ -111,20 +111,20 @@ generic boor2(i)
|
||||
|
||||
$if ($e > 0)
|
||||
{
|
||||
func void foo() {}
|
||||
fn void foo() {}
|
||||
}
|
||||
$elif ($e < 0)
|
||||
{
|
||||
func void foo() { printf("HELO"); }
|
||||
fn void foo() { printf("HELO"); }
|
||||
}
|
||||
$else
|
||||
{
|
||||
func void foo() { printf("OLEH"); }
|
||||
fn void foo() { printf("OLEH"); }
|
||||
}
|
||||
|
||||
$if ($e > 0)
|
||||
{
|
||||
func void foo() {}
|
||||
fn void foo() {}
|
||||
}
|
||||
|
||||
$if ($b > 0)
|
||||
@@ -151,7 +151,7 @@ generic boofer2(i, g, eok)
|
||||
|
||||
|
||||
|
||||
func void hello() throws Errors
|
||||
fn void hello() throws Errors
|
||||
{
|
||||
int i, j;
|
||||
throw FOO;
|
||||
@@ -229,11 +229,11 @@ func void hello() throws Errors
|
||||
}
|
||||
|
||||
typedef Foo* as Bar;
|
||||
typedef func void(int, Foo*) as Zoo;
|
||||
typedef fn void(int, Foo*) as Zoo;
|
||||
|
||||
|
||||
|
||||
func void test2()
|
||||
fn void test2()
|
||||
{
|
||||
return;
|
||||
}
|
||||
@@ -26,11 +26,11 @@ void* gWindow = null;
|
||||
void* gScreenSurface = null;
|
||||
|
||||
|
||||
extern func int init(uint flags) @extname("SDL_Init");
|
||||
extern func int initSubSystem(uint flags) @extname("SDL_InitSubSystem");
|
||||
extern func void quitSubSystem(uint flags) @extname("SDL_QuitSubSystem");
|
||||
extern func uint wasInit(uint flags) @extname("SDL_WasInit");
|
||||
extern func void quit() @extname("SDL_Quit");
|
||||
extern fn int init(uint flags) @extname("SDL_Init");
|
||||
extern fn int initSubSystem(uint flags) @extname("SDL_InitSubSystem");
|
||||
extern fn void quitSubSystem(uint flags) @extname("SDL_QuitSubSystem");
|
||||
extern fn uint wasInit(uint flags) @extname("SDL_WasInit");
|
||||
extern fn void quit() @extname("SDL_Quit");
|
||||
|
||||
enum SDLWindowFlags : c_int
|
||||
{
|
||||
@@ -59,13 +59,13 @@ enum SDLWindowFlags : c_int
|
||||
VULKAN = 0x10000000 /**< window usable for Vulkan surface */
|
||||
}
|
||||
|
||||
extern func void* createWindow(char *title, uint x, uint y, int w, int h, uint flags) @extname("SDL_CreateWindow");
|
||||
extern func void* getWindowSurface(void *window) @extname("SDL_GetWindowSurface");
|
||||
extern fn void* createWindow(char *title, uint x, uint y, int w, int h, uint flags) @extname("SDL_CreateWindow");
|
||||
extern fn void* getWindowSurface(void *window) @extname("SDL_GetWindowSurface");
|
||||
const uint WINDOWPOS_UNDEFINED_MASK = 0x1FFF0000;
|
||||
extern func int exit(int code);
|
||||
extern func int printf(char *mess, ...);
|
||||
extern fn int exit(int code);
|
||||
extern fn int printf(char *mess, ...);
|
||||
|
||||
func bool initX()
|
||||
fn bool initX()
|
||||
{
|
||||
//Initialization flag
|
||||
bool success = true;
|
||||
@@ -86,7 +86,7 @@ func bool initX()
|
||||
}
|
||||
|
||||
|
||||
func void close()
|
||||
fn void close()
|
||||
{
|
||||
//Destroy window
|
||||
// SDL_DestroyWindow( gWindow );
|
||||
@@ -96,8 +96,8 @@ func void close()
|
||||
quit();
|
||||
}
|
||||
|
||||
extern func int pollEvent(SDL_Event *event) @extname("SDL_PollEvent");
|
||||
extern func int updateWindowSurface(void *window) @extname("SDL_UpdateWindowSurface");
|
||||
extern fn int pollEvent(SDL_Event *event) @extname("SDL_PollEvent");
|
||||
extern fn int updateWindowSurface(void *window) @extname("SDL_UpdateWindowSurface");
|
||||
|
||||
enum SDLEventType : uint
|
||||
{
|
||||
@@ -223,7 +223,7 @@ union SDL_Event
|
||||
|
||||
const uint SDL_QUIT = 0x100;
|
||||
|
||||
func int main(int argc, char** args)
|
||||
fn int main(int argc, char** args)
|
||||
{
|
||||
initX();
|
||||
//Main loop flag
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
import std::io;
|
||||
|
||||
extern func int printf(char* message, ...);
|
||||
extern fn int printf(char* message, ...);
|
||||
|
||||
macro void swap(&a, &b)
|
||||
{
|
||||
@@ -9,7 +9,7 @@ macro void swap(&a, &b)
|
||||
b = temp;
|
||||
}
|
||||
|
||||
func void main()
|
||||
fn void main()
|
||||
{
|
||||
int x = 1;
|
||||
int y = 2;
|
||||
|
||||
@@ -1,10 +1,10 @@
|
||||
module foo;
|
||||
|
||||
extern func void printf(char *hello, ...);
|
||||
extern fn void printf(char *hello, ...);
|
||||
|
||||
error MyError;
|
||||
error YourError;
|
||||
func void main()
|
||||
fn void main()
|
||||
{
|
||||
int! i = 1;
|
||||
catch (i)
|
||||
|
||||
@@ -1,19 +1,19 @@
|
||||
|
||||
extern func void printf(char* message, ...);
|
||||
extern fn void printf(char* message, ...);
|
||||
|
||||
public func void defer1() {}
|
||||
public func void defer2() {}
|
||||
public func void defer3() {}
|
||||
public func void defer4() {}
|
||||
public func void defer5() {}
|
||||
public func void defer6() {}
|
||||
public func void defer7() {}
|
||||
public func void defer8() {}
|
||||
public func void defer9() {}
|
||||
public func void defer10() {}
|
||||
public func void defer11() {}
|
||||
public fn void defer1() {}
|
||||
public fn void defer2() {}
|
||||
public fn void defer3() {}
|
||||
public fn void defer4() {}
|
||||
public fn void defer5() {}
|
||||
public fn void defer6() {}
|
||||
public fn void defer7() {}
|
||||
public fn void defer8() {}
|
||||
public fn void defer9() {}
|
||||
public fn void defer10() {}
|
||||
public fn void defer11() {}
|
||||
|
||||
public func int main(int argc)
|
||||
public fn int main(int argc)
|
||||
{
|
||||
int a = 0;
|
||||
{
|
||||
|
||||
@@ -10,7 +10,7 @@ struct String
|
||||
char* ptr;
|
||||
}
|
||||
|
||||
func void String.init(String *s, char[] c)
|
||||
fn void String.init(String *s, char[] c)
|
||||
{
|
||||
s.capacity = c.len + 16;
|
||||
s.ptr = mem::_malloc(s.capacity);
|
||||
@@ -18,7 +18,7 @@ func void String.init(String *s, char[] c)
|
||||
mem::copy(s.ptr, (char*)(c), c.len);
|
||||
}
|
||||
|
||||
func char* String.zstr(String *s)
|
||||
fn char* String.zstr(String *s)
|
||||
{
|
||||
char* c = mem::_malloc(s.len + 1);
|
||||
mem::copy(c, s.ptr, s.len);
|
||||
@@ -26,7 +26,7 @@ func char* String.zstr(String *s)
|
||||
return c;
|
||||
}
|
||||
|
||||
func void String.appendc(String *s, char c)
|
||||
fn void String.appendc(String *s, char c)
|
||||
{
|
||||
if (s.capacity == s.len)
|
||||
{
|
||||
@@ -38,7 +38,7 @@ func void String.appendc(String *s, char c)
|
||||
s.ptr[s.len++] = c;
|
||||
}
|
||||
|
||||
func void String.append(String *s, char[] other_string)
|
||||
fn void String.append(String *s, char[] other_string)
|
||||
{
|
||||
if (s.capacity < s.len + other_string.len)
|
||||
{
|
||||
@@ -55,7 +55,7 @@ func void String.append(String *s, char[] other_string)
|
||||
s.len += other_string.len;
|
||||
}
|
||||
|
||||
func void String.concat(String *s, String* other_string)
|
||||
fn void String.concat(String *s, String* other_string)
|
||||
{
|
||||
if (s.capacity < s.len + other_string.len)
|
||||
{
|
||||
@@ -72,7 +72,7 @@ func void String.concat(String *s, String* other_string)
|
||||
s.len += other_string.len;
|
||||
}
|
||||
|
||||
func void main()
|
||||
fn void main()
|
||||
{
|
||||
String s;
|
||||
s.init("Hello");
|
||||
|
||||
@@ -2,7 +2,7 @@ module topologicalsort;
|
||||
import std::mem;
|
||||
import std::array;
|
||||
|
||||
extern func void printf(char* x, ...);
|
||||
extern fn void printf(char* x, ...);
|
||||
|
||||
struct InputPair
|
||||
{
|
||||
@@ -23,7 +23,7 @@ struct TopoList
|
||||
}
|
||||
|
||||
|
||||
func void sort(InputPair[] pairs, uint elements)
|
||||
fn void sort(InputPair[] pairs, uint elements)
|
||||
{
|
||||
InputPair[] result = @array::make(InputPair, pairs.len);
|
||||
TopoList* top = @array::make(TopoList, elements);
|
||||
@@ -70,7 +70,7 @@ func void sort(InputPair[] pairs, uint elements)
|
||||
}
|
||||
}
|
||||
|
||||
func void main()
|
||||
fn void main()
|
||||
{
|
||||
InputPair[10] pairs = {
|
||||
{ 9, 2 },
|
||||
|
||||
@@ -3,7 +3,7 @@ module bar;
|
||||
import baz::foo;
|
||||
import testbaz::zab;
|
||||
|
||||
func void test()
|
||||
fn void test()
|
||||
{
|
||||
Foo x;
|
||||
baz::foo::test();
|
||||
|
||||
@@ -7,14 +7,14 @@ struct Foo
|
||||
int a;
|
||||
}
|
||||
|
||||
extern func void printf(char *hello);
|
||||
extern fn void printf(char *hello);
|
||||
|
||||
private func void ofke()
|
||||
private fn void ofke()
|
||||
{}
|
||||
|
||||
private func void exple() {}
|
||||
private fn void exple() {}
|
||||
|
||||
func void test()
|
||||
fn void test()
|
||||
{
|
||||
printf("Hello from baz::foo::test()!\n");
|
||||
}
|
||||
@@ -1,9 +1,9 @@
|
||||
module hello_world;
|
||||
import bar;
|
||||
|
||||
extern func void printf(char *hello);
|
||||
extern fn void printf(char *hello);
|
||||
|
||||
func int main(int x)
|
||||
fn int main(int x)
|
||||
{
|
||||
printf("Hello World!\n");
|
||||
bar::test();
|
||||
|
||||
@@ -365,6 +365,7 @@ typedef struct VarDecl_
|
||||
bool unwrap : 1;
|
||||
bool vararg : 1;
|
||||
bool is_static : 1;
|
||||
bool is_threadglobal : 1;
|
||||
TypeInfo *type_info;
|
||||
union
|
||||
{
|
||||
|
||||
@@ -442,6 +442,7 @@ typedef enum
|
||||
TOKEN_FN,
|
||||
TOKEN_FUNC,
|
||||
TOKEN_GENERIC,
|
||||
TOKEN_GLOBAL,
|
||||
TOKEN_IF,
|
||||
TOKEN_IMPORT,
|
||||
TOKEN_MACRO,
|
||||
|
||||
@@ -363,6 +363,8 @@ void llvm_emit_global_variable_init(GenContext *c, Decl *decl)
|
||||
// TODO fix name
|
||||
LLVMValueRef old = decl->backend_ref;
|
||||
decl->backend_ref = LLVMAddGlobal(c->module, LLVMTypeOf(init_value), decl->extname ? decl->extname : decl->external_name);
|
||||
bool thread_local = !decl->var.is_threadglobal && decl->var.kind != VARDECL_CONST;
|
||||
LLVMSetThreadLocal(decl->backend_ref, thread_local);
|
||||
if (decl->section)
|
||||
{
|
||||
LLVMSetSection(decl->backend_ref, decl->section);
|
||||
@@ -373,6 +375,7 @@ void llvm_emit_global_variable_init(GenContext *c, Decl *decl)
|
||||
if (failable_ref)
|
||||
{
|
||||
llvm_set_alignment(failable_ref, type_alloca_alignment(type_anyerr));
|
||||
LLVMSetThreadLocal(failable_ref, thread_local);
|
||||
}
|
||||
if (init_expr && IS_FAILABLE(init_expr) && init_expr->expr_kind == EXPR_FAILABLE)
|
||||
{
|
||||
|
||||
@@ -73,16 +73,13 @@ void recover_top_level(Context *context)
|
||||
switch (context->tok.type)
|
||||
{
|
||||
case TOKEN_PRIVATE:
|
||||
case TOKEN_STRUCT:
|
||||
case TOKEN_IMPORT:
|
||||
case TOKEN_UNION:
|
||||
case TOKEN_EXTERN:
|
||||
case TOKEN_ENUM:
|
||||
case TOKEN_GENERIC:
|
||||
case TOKEN_ATTRIBUTE:
|
||||
case TOKEN_DEFINE:
|
||||
case TOKEN_ERRTYPE:
|
||||
case TOKEN_BITSTRUCT:
|
||||
return;
|
||||
case TOKEN_IDENT: // Incr arrays only
|
||||
case TOKEN_CONST:
|
||||
@@ -95,6 +92,9 @@ void recover_top_level(Context *context)
|
||||
case TOKEN_CT_SWITCH:
|
||||
case TOKEN_FUNC:
|
||||
case TOKEN_FN:
|
||||
case TOKEN_STRUCT:
|
||||
case TOKEN_UNION:
|
||||
case TOKEN_BITSTRUCT:
|
||||
case TYPELIKE_TOKENS:
|
||||
// Only recover if this is in the first col.
|
||||
if (TOKLOC(context->tok)->col == 1) return;
|
||||
@@ -805,7 +805,8 @@ Decl *parse_decl(Context *context)
|
||||
return parse_const_declaration(context, VISIBLE_LOCAL);
|
||||
}
|
||||
|
||||
bool is_static = try_consume(context, TOKEN_STATIC);
|
||||
bool is_threadglobal = try_consume(context, TOKEN_GLOBAL);
|
||||
bool is_static = !is_threadglobal && try_consume(context, TOKEN_STATIC);
|
||||
|
||||
ASSIGN_TYPE_ELSE(TypeInfo *type, parse_failable_type(context), poisoned_decl);
|
||||
|
||||
@@ -815,7 +816,8 @@ Decl *parse_decl(Context *context)
|
||||
SEMA_ERROR(decl, "You cannot use unwrap with a failable variable.");
|
||||
return poisoned_decl;
|
||||
}
|
||||
decl->var.is_static = is_static;
|
||||
decl->var.is_static = is_static || is_threadglobal;
|
||||
decl->var.is_threadglobal = is_threadglobal;
|
||||
return decl;
|
||||
}
|
||||
|
||||
@@ -1009,9 +1011,9 @@ bool parse_attributes(Context *context, Attr ***attributes_ref)
|
||||
|
||||
/**
|
||||
* global_declaration
|
||||
* : failable_type IDENT ';'
|
||||
* | failable_type IDENT '=' expression ';'
|
||||
* | failable_type func_definition
|
||||
* : global? failable_type IDENT ';'
|
||||
* | global? failable_type IDENT '=' expression ';'
|
||||
* | global? failable_type func_definition
|
||||
* ;
|
||||
*
|
||||
* @param visibility
|
||||
@@ -1019,10 +1021,14 @@ bool parse_attributes(Context *context, Attr ***attributes_ref)
|
||||
*/
|
||||
static inline Decl *parse_global_declaration(Context *context, Visibility visibility)
|
||||
{
|
||||
bool thread_global = try_consume(context, TOKEN_GLOBAL);
|
||||
|
||||
ASSIGN_TYPE_ELSE(TypeInfo *type, parse_failable_type(context), poisoned_decl);
|
||||
|
||||
Decl *decl = decl_new_var(context->tok.id, type, VARDECL_GLOBAL, visibility);
|
||||
|
||||
decl->var.is_threadglobal = thread_global;
|
||||
|
||||
if (TOKEN_IS(TOKEN_CONST_IDENT))
|
||||
{
|
||||
SEMA_TOKEN_ERROR(context->tok, "This looks like a constant variable, did you forget 'const'?");
|
||||
@@ -2360,6 +2366,7 @@ Decl *parse_top_level_statement(Context *context)
|
||||
case TOKEN_IMPORT:
|
||||
SEMA_TOKEN_ERROR(context->tok, "Imports are only allowed directly after the module declaration.");
|
||||
return poisoned_decl;
|
||||
case TOKEN_GLOBAL:
|
||||
case TYPELIKE_TOKENS:
|
||||
{
|
||||
ASSIGN_DECL_ELSE(decl, parse_global_declaration(context, visibility), poisoned_decl);
|
||||
|
||||
@@ -800,6 +800,7 @@ Ast *parse_stmt(Context *context)
|
||||
return parse_decl_or_expr_stmt(context);
|
||||
case TOKEN_VAR:
|
||||
return parse_var_stmt(context);
|
||||
case TOKEN_GLOBAL: // Global means declaration!
|
||||
case TOKEN_STATIC: // Static means declaration!
|
||||
case TOKEN_CONST: // Const means declaration!
|
||||
return parse_declaration_stmt(context);
|
||||
|
||||
@@ -1847,6 +1847,7 @@ static bool sema_analyse_body_expansion(Context *context, Expr *call)
|
||||
assert(macro);
|
||||
assert(macro->macro_decl.block_parameter.index);
|
||||
|
||||
// TODO handle named arguments
|
||||
ExprCall *call_expr = &call->call_expr;
|
||||
if (vec_size(call_expr->body_arguments))
|
||||
{
|
||||
|
||||
@@ -236,6 +236,8 @@ const char *token_type_to_string(TokenType type)
|
||||
return "func";
|
||||
case TOKEN_GENERIC:
|
||||
return "generic";
|
||||
case TOKEN_GLOBAL:
|
||||
return "global";
|
||||
case TOKEN_IF:
|
||||
return "if";
|
||||
case TOKEN_IMPORT:
|
||||
|
||||
@@ -7,9 +7,9 @@ struct Test
|
||||
|
||||
Test foo = {};
|
||||
|
||||
extern func void blorg(Test t);
|
||||
extern fn void blorg(Test t);
|
||||
|
||||
func Test creator()
|
||||
fn Test creator()
|
||||
{
|
||||
blorg(Test{});
|
||||
return Test{};
|
||||
|
||||
@@ -8,9 +8,9 @@ struct Test
|
||||
|
||||
Test foo = {};
|
||||
|
||||
extern func void blorg(Test t);
|
||||
extern fn void blorg(Test t);
|
||||
|
||||
func Test creator()
|
||||
fn Test creator()
|
||||
{
|
||||
blorg(Test{});
|
||||
return Test{};
|
||||
|
||||
@@ -8,9 +8,9 @@ struct Test
|
||||
|
||||
Test foo = {};
|
||||
|
||||
extern func void blorg(Test t);
|
||||
extern fn void blorg(Test t);
|
||||
|
||||
func Test creator()
|
||||
fn Test creator()
|
||||
{
|
||||
blorg(Test{});
|
||||
return Test{};
|
||||
|
||||
@@ -8,9 +8,9 @@ struct Large
|
||||
void*[8] pointers;
|
||||
}
|
||||
|
||||
extern func void pass_large(Large large);
|
||||
extern fn void pass_large(Large large);
|
||||
|
||||
func void example()
|
||||
fn void example()
|
||||
{
|
||||
Large l = {};
|
||||
pass_large(l);
|
||||
|
||||
@@ -8,10 +8,10 @@ struct Abc {
|
||||
long e;
|
||||
}
|
||||
|
||||
extern func Abc foo1();
|
||||
extern func Abc foo2();
|
||||
extern fn Abc foo1();
|
||||
extern fn Abc foo2();
|
||||
|
||||
func void bar() {
|
||||
fn void bar() {
|
||||
Abc dummy1 = foo1();
|
||||
Abc dummy2 = foo2();
|
||||
}
|
||||
|
||||
@@ -7,9 +7,9 @@ union Foo
|
||||
long a;
|
||||
char[12] b;
|
||||
}
|
||||
extern func void hello2(Foo f);
|
||||
extern fn void hello2(Foo f);
|
||||
|
||||
func void hello(Foo f)
|
||||
fn void hello(Foo f)
|
||||
{
|
||||
hello2(f);
|
||||
}
|
||||
|
||||
@@ -5,12 +5,12 @@ struct Vector2 {
|
||||
float x;
|
||||
float y;
|
||||
}
|
||||
extern func Vector2 vector2_zero() { return Vector2 {}; }
|
||||
extern func Vector2 vector2_one() { return Vector2 {}; }
|
||||
extern func Vector2 vector2_add(Vector2 v1, Vector2 v2) { return Vector2 {}; }
|
||||
extern func Vector2 vector2_add_value(Vector2 v, float add) { return Vector2 {}; }
|
||||
extern func Vector2 vector2_subtract(Vector2 v1, Vector2 v2) { return Vector2 {}; }
|
||||
extern func Vector2 vector2_subtract_value(Vector2 v, float sub) { return Vector2 {}; }
|
||||
extern fn Vector2 vector2_zero() { return Vector2 {}; }
|
||||
extern fn Vector2 vector2_one() { return Vector2 {}; }
|
||||
extern fn Vector2 vector2_add(Vector2 v1, Vector2 v2) { return Vector2 {}; }
|
||||
extern fn Vector2 vector2_add_value(Vector2 v, float add) { return Vector2 {}; }
|
||||
extern fn Vector2 vector2_subtract(Vector2 v1, Vector2 v2) { return Vector2 {}; }
|
||||
extern fn Vector2 vector2_subtract_value(Vector2 v, float sub) { return Vector2 {}; }
|
||||
|
||||
// #expect: abi.ll
|
||||
%Vector2 = type { float, float }
|
||||
|
||||
@@ -5,12 +5,12 @@ struct Vector2 {
|
||||
float x;
|
||||
float y;
|
||||
}
|
||||
extern func Vector2 vector2_zero() { return Vector2 {}; }
|
||||
extern func Vector2 vector2_one() { return Vector2 {}; }
|
||||
extern func Vector2 vector2_add(Vector2 v1, Vector2 v2) { return Vector2 {}; }
|
||||
extern func Vector2 vector2_add_value(Vector2 v, float add) { return Vector2 {}; }
|
||||
extern func Vector2 vector2_subtract(Vector2 v1, Vector2 v2) { return Vector2 {}; }
|
||||
extern func Vector2 vector2_subtract_value(Vector2 v, float sub) { return Vector2 {}; }
|
||||
extern fn Vector2 vector2_zero() { return Vector2 {}; }
|
||||
extern fn Vector2 vector2_one() { return Vector2 {}; }
|
||||
extern fn Vector2 vector2_add(Vector2 v1, Vector2 v2) { return Vector2 {}; }
|
||||
extern fn Vector2 vector2_add_value(Vector2 v, float add) { return Vector2 {}; }
|
||||
extern fn Vector2 vector2_subtract(Vector2 v1, Vector2 v2) { return Vector2 {}; }
|
||||
extern fn Vector2 vector2_subtract_value(Vector2 v, float sub) { return Vector2 {}; }
|
||||
|
||||
// #expect: abi.ll
|
||||
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
module array_casts;
|
||||
|
||||
|
||||
func void test()
|
||||
fn void test()
|
||||
{
|
||||
int[3] x;
|
||||
int *y = &x;
|
||||
|
||||
@@ -1,11 +1,11 @@
|
||||
|
||||
func void test()
|
||||
fn void test()
|
||||
{
|
||||
int[3] x;
|
||||
double *y = &x; // #error: 'int[3]*' to 'double*
|
||||
}
|
||||
|
||||
func void test2()
|
||||
fn void test2()
|
||||
{
|
||||
int[3] x;
|
||||
double[] z = &x; // #error: 'int[3]*' into 'double[]'
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
// #target: x64-darwin
|
||||
module array_literal;
|
||||
|
||||
func double test(uint x)
|
||||
fn double test(uint x)
|
||||
{
|
||||
double[30] student_t = { 0.0 , 12.706 , 4.303 , 3.182 , 2.776 , 2.571 ,
|
||||
2.447 , 2.365 , 2.306 , 2.262 , 2.228 ,
|
||||
|
||||
@@ -6,7 +6,7 @@ struct Foo
|
||||
int x, y;
|
||||
}
|
||||
|
||||
private Foo[10] array;
|
||||
private global Foo[10] array;
|
||||
|
||||
// #expect: test.ll
|
||||
|
||||
|
||||
@@ -8,7 +8,7 @@ struct Connection
|
||||
long length;
|
||||
}
|
||||
|
||||
private Connection[3] link
|
||||
private global Connection[3] link
|
||||
= { {1, "link1", 10},
|
||||
{2, "link2", 20},
|
||||
{3, "link3", 30} };
|
||||
|
||||
@@ -8,7 +8,7 @@ int[B] c2; // #error: Expected an integer size.
|
||||
int non_constant = 10;
|
||||
int[non_constant] b; // #error: Expected a constant value as
|
||||
|
||||
func int foo()
|
||||
fn int foo()
|
||||
{
|
||||
return 10;
|
||||
}
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
func void test()
|
||||
fn void test()
|
||||
{
|
||||
int[3] x = { 1, 2, 3 };
|
||||
int[] z = &x;
|
||||
|
||||
@@ -1,11 +1,11 @@
|
||||
// #target: x64-windows
|
||||
|
||||
func int foo()
|
||||
fn int foo()
|
||||
{
|
||||
return 1;
|
||||
}
|
||||
|
||||
func void test()
|
||||
fn void test()
|
||||
{
|
||||
int x = foo();
|
||||
int y = foo();
|
||||
|
||||
@@ -1,19 +1,19 @@
|
||||
int x = 3;
|
||||
|
||||
func void test()
|
||||
fn void test()
|
||||
{
|
||||
$assert(x == 3); // #error: Compile time evaluation requires a compile time constant value.
|
||||
}
|
||||
|
||||
func void test2()
|
||||
fn void test2()
|
||||
{
|
||||
int i = 0;
|
||||
$assert(1);
|
||||
$assert(i == 0); // #error: Compile time evaluation requires a compile time constant value.
|
||||
}
|
||||
|
||||
func int foo();
|
||||
func void test3()
|
||||
fn int foo();
|
||||
fn void test3()
|
||||
{
|
||||
int i = 0;
|
||||
$assert(foo() == 0); // #error: Compile time evaluation requires a compile time constant value.
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
|
||||
const int FOO = 2;
|
||||
|
||||
func void test()
|
||||
fn void test()
|
||||
{
|
||||
$assert(FOO == 2, "Bad");
|
||||
$assert(FOO == 0, "Good"); // #error: Compile time assert - Good
|
||||
|
||||
@@ -1,10 +1,10 @@
|
||||
|
||||
func int foo()
|
||||
fn int foo()
|
||||
{
|
||||
return 1;
|
||||
}
|
||||
|
||||
func void test()
|
||||
fn void test()
|
||||
{
|
||||
int x = foo();
|
||||
if (x > 0) return;
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
module test;
|
||||
|
||||
func int foo()
|
||||
fn int foo()
|
||||
{
|
||||
int x = 0;
|
||||
int y;
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
func void test()
|
||||
fn void test()
|
||||
{
|
||||
for (int a @align(16) @align(16) = 0 ; a < 10; a++) // #error: Repeat of attribute 'align'
|
||||
{
|
||||
|
||||
@@ -1,11 +1,11 @@
|
||||
struct Foo { int a; }
|
||||
|
||||
func void test4()
|
||||
fn void test4()
|
||||
{
|
||||
int x = (int)(32);
|
||||
}
|
||||
|
||||
func void test5()
|
||||
fn void test5()
|
||||
{
|
||||
Foo x = (Foo)(Foo{32});
|
||||
}
|
||||
@@ -1,11 +1,11 @@
|
||||
struct Foo { int a; }
|
||||
|
||||
func void test2()
|
||||
fn void test2()
|
||||
{
|
||||
int x = int{ 32 }; // #error: 'int' cannot use compound literal initialization, did you intend to use a cast
|
||||
}
|
||||
|
||||
func void test3()
|
||||
fn void test3()
|
||||
{
|
||||
int x = int(32); // #error: A type cannot be followed by (), if you intended a cast, use (type)(expression)
|
||||
}
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
|
||||
struct Foo { int a; }
|
||||
|
||||
func void test1()
|
||||
fn void test1()
|
||||
{
|
||||
Foo({ 32 });
|
||||
(Foo)({ 32 }); // #error: Unexpected start of a block '{' here. If you intended a compound literal
|
||||
|
||||
@@ -22,7 +22,7 @@ struct BazTwo
|
||||
int e;
|
||||
}
|
||||
|
||||
func void test()
|
||||
fn void test()
|
||||
{
|
||||
Foo x;
|
||||
Bar y = (Bar)(x);
|
||||
|
||||
@@ -22,12 +22,12 @@ struct BazTwo
|
||||
int e;
|
||||
}
|
||||
|
||||
func void test1()
|
||||
fn void test1()
|
||||
{
|
||||
Foo x;
|
||||
Bar z = (Baz)(x); // #error: cast 'Foo' to 'Baz'
|
||||
}
|
||||
func void test2()
|
||||
fn void test2()
|
||||
{
|
||||
Baz x;
|
||||
BazTwo z = (BazTwo)(x); // #error: cast 'Baz' to 'BazTwo'
|
||||
|
||||
@@ -3,7 +3,7 @@ errtype MyErr
|
||||
FOO
|
||||
}
|
||||
|
||||
func void test()
|
||||
fn void test()
|
||||
{
|
||||
int! x;
|
||||
int! d = ($typeof(MyErr.FOO!))(x); // #error: Casting to a failable type is not allowed
|
||||
|
||||
@@ -7,7 +7,7 @@ module comments;
|
||||
Multiline span style
|
||||
*/
|
||||
|
||||
func void test()
|
||||
fn void test()
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -2,12 +2,12 @@
|
||||
module test;
|
||||
|
||||
|
||||
int*[] blurp = { &ptr, &ptr, (&ptr + 1), &ptr - 1, (int*)((iptr)(&ptr) - 4) };
|
||||
int* c = (int*)((iptr)(&ptr) - 4);
|
||||
int* c2 = (int*)((iptr)(&ptr) + 4);
|
||||
int* c3 = (int*)(4 + (iptr)(&ptr));
|
||||
iptr ff = (iptr)(&ptr);
|
||||
int ptr = 0;
|
||||
global int*[] blurp = { &ptr, &ptr, (&ptr + 1), &ptr - 1, (int*)((iptr)(&ptr) - 4) };
|
||||
global int* c = (int*)((iptr)(&ptr) - 4);
|
||||
global int* c2 = (int*)((iptr)(&ptr) + 4);
|
||||
global int* c3 = (int*)(4 + (iptr)(&ptr));
|
||||
global iptr ff = (iptr)(&ptr);
|
||||
global int ptr = 0;
|
||||
|
||||
// #expect: test.ll
|
||||
|
||||
|
||||
@@ -4,7 +4,7 @@ $else:
|
||||
$elif (0):
|
||||
$elif (0):
|
||||
$else:
|
||||
int x = 1;
|
||||
global int x = 1;
|
||||
$endif;
|
||||
$endif;
|
||||
|
||||
@@ -18,7 +18,7 @@ $endif;
|
||||
|
||||
$if (1):
|
||||
$assert(true);
|
||||
int d = 5;
|
||||
global int d = 5;
|
||||
$elif (0):
|
||||
$assert(false);
|
||||
$else:
|
||||
@@ -29,7 +29,7 @@ $if (0):
|
||||
$assert(true);
|
||||
$elif (1):
|
||||
$assert(true);
|
||||
int c = 5;
|
||||
global int c = 5;
|
||||
$else:
|
||||
$assert(false);
|
||||
$endif;
|
||||
@@ -38,7 +38,7 @@ $if (0):
|
||||
$assert(true);
|
||||
$elif (1):
|
||||
$assert(true);
|
||||
int b = 4;
|
||||
global int b = 4;
|
||||
$elif (0):
|
||||
$assert(false);
|
||||
$else:
|
||||
@@ -51,7 +51,7 @@ $elif (0):
|
||||
$assert(false);
|
||||
$elif (1):
|
||||
$assert(true);
|
||||
int a = 3;
|
||||
global int a = 3;
|
||||
$else:
|
||||
$assert(false);
|
||||
$endif;
|
||||
|
||||
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user