commit 4f85f32d72d2a1c6b2463aff934ab49e1da94b92 parent c1a5309b05c504d7c3913826e097c5f1ddd0d73a Author: Brian Swetland <swetland@frotz.net> Date: Sat, 14 Oct 2023 00:35:43 -0700 compiler0: func -> fn Diffstat:
30 files changed, 62 insertions(+), 62 deletions(-)
diff --git a/compiler0.c b/compiler0.c @@ -129,12 +129,12 @@ struct Ctx { Scope global; String *idn_if; // identifier strings + String *idn_fn; String *idn_for; String *idn_var; String *idn_nil; String *idn_new; String *idn_case; - String *idn_func; String *idn_else; String *idn_enum; String *idn_true; @@ -301,12 +301,12 @@ void ctx_init() { // pre-intern keywords ctx.idn_if = string_make("if", 2); + ctx.idn_fn = string_make("fn", 2); ctx.idn_for = string_make("for", 3); ctx.idn_var = string_make("var", 3); ctx.idn_nil = string_make("nil", 3); ctx.idn_new = string_make("new", 3); ctx.idn_case = string_make("case", 4); - ctx.idn_func = string_make("func", 4); ctx.idn_else = string_make("else", 4); ctx.idn_enum = string_make("enum", 4); ctx.idn_true = string_make("true", 4); @@ -501,7 +501,7 @@ enum { tSEMI, tCOLON, tDOT, tCOMMA, tNOT, tAND, tOR, tBANG, tASSIGN, tINC, tDEC, // Keywords - tNEW, tFUNC, tSTRUCT, tVAR, tENUM, + tNEW, tFN, tSTRUCT, tVAR, tENUM, tIF, tELSE, tWHILE, tBREAK, tCONTINUE, tRETURN, tFOR, tSWITCH, tCASE, @@ -520,7 +520,7 @@ const char *tnames[] = { "*=", "/=", "%=", "&=", "<<=", ">>=", "", "", ";", ":", ".", ",", "~", "&&", "||", "!", "=", "++", "--", - "new", "func", "struct", "var", "enum", + "new", "fn", "struct", "var", "enum", "if", "else", "while", "break", "continue", "return", "for", "switch", "case", @@ -653,6 +653,7 @@ token_t scan_keyword(u32 len) { if (len == 2) { if (idn == ctx.idn_if) { return tIF; }; + if (idn == ctx.idn_fn) { return tFN; } } else if (len == 3) { if (idn == ctx.idn_for) { return tFOR; } if (idn == ctx.idn_var) { return tVAR; } @@ -660,7 +661,6 @@ token_t scan_keyword(u32 len) { if (idn == ctx.idn_new) { return tNEW; } } else if (len == 4) { if (idn == ctx.idn_case) { return tCASE; } - if (idn == ctx.idn_func) { return tFUNC; } if (idn == ctx.idn_else) { return tELSE; } if (idn == ctx.idn_enum) { return tENUM; } if (idn == ctx.idn_true) { return tTRUE; } @@ -1150,7 +1150,7 @@ Type *parse_type(bool fwd_ref_ok) { } else if (ctx.tok == tOBRACK) { // array-of next(); return parse_array_type(); - } else if (ctx.tok == tFUNC) { + } else if (ctx.tok == tFN) { error("func types not supported"); //next(); //return parse_func_type(); @@ -1505,7 +1505,7 @@ void parse_program() { String *name = parse_name("struct name"); parse_struct_type(name); require(tSEMI); - } else if (ctx.tok == tFUNC) { + } else if (ctx.tok == tFN) { next(); parse_function(); } else if (ctx.tok == tVAR) { diff --git a/demo/echo.spl b/demo/echo.spl @@ -1,5 +1,5 @@ -func start() i32 { +fn start() i32 { while 1 { var ch i32 = readc(0); if ch < 0 { break; } diff --git a/demo/hello.spl b/demo/hello.spl @@ -1,5 +1,5 @@ -func start() i32 { +fn start() i32 { writes(1, "Hello, World\n"); return 0; } diff --git a/test/1000-return-42.spl b/test/1000-return-42.spl @@ -1,3 +1,3 @@ -func start() i32 { +fn start() i32 { return 42; } diff --git a/test/1010-func-call.spl b/test/1010-func-call.spl @@ -1,7 +1,7 @@ -func add(a i32, b i32) i32 { +fn add(a i32, b i32) i32 { return a + b; } -func start() i32 { +fn start() i32 { return add(20, 22); } diff --git a/test/1011-func-call-forward.spl b/test/1011-func-call-forward.spl @@ -1,8 +1,8 @@ -func start() i32 { +fn start() i32 { return add(20, 22); } -func add(a i32, b i32) i32 { +fn add(a i32, b i32) i32 { return a + b; } diff --git a/test/1012-func-call-builtin.spl b/test/1012-func-call-builtin.spl @@ -1,4 +1,4 @@ -func start() i32 { +fn start() i32 { _hexout_(0x10203040); _hexout_(0xcafef00d); _hexout_(-1); diff --git a/test/1020-math-1.spl b/test/1020-math-1.spl @@ -1,9 +1,9 @@ -func print(n i32) { +fn print(n i32) { _hexout_(n); } -func test(v2 i32, v5 i32, v31 i32, v128000 i32) { +fn test(v2 i32, v5 i32, v31 i32, v128000 i32) { // quick check hex and bin consts print(0xFFD23137); print(0b10001000110100000101000010100001); @@ -16,7 +16,7 @@ func test(v2 i32, v5 i32, v31 i32, v128000 i32) { print(-v128000); } -func start() i32 { +fn start() i32 { test(2, 5, 31, 128000); return 0; } diff --git a/test/1021-numbers.spl b/test/1021-numbers.spl @@ -1,5 +1,5 @@ -func start() i32 { +fn start() i32 { _hexout_(4294967295); // maxu32 _hexout_(2147483648); // highbit _hexout_(0xffffffff); // maxu32 diff --git a/test/1024-xorshift32.spl b/test/1024-xorshift32.spl @@ -3,14 +3,14 @@ var state i32 = 0xd3f56332; -func xorshift32() i32 { +fn xorshift32() i32 { state = state ^ (state << 13); state = state ^ ((state >> 17) & 0x7FFF); state = state ^ (state << 5); return state; } -func start() i32 { +fn start() i32 { var n i32 = 0; while (n < 64) { _hexout_(xorshift32()); diff --git a/test/1025-fibonacci.spl b/test/1025-fibonacci.spl @@ -1,5 +1,5 @@ -func fib(n i32) i32 { +fn fib(n i32) i32 { if (n < 2) { return n; } else { @@ -7,7 +7,7 @@ func fib(n i32) i32 { } } -func start() i32 { +fn start() i32 { var n i32 = 0; while n < 24 { _hexout_(fib(n)); diff --git a/test/1026-fib-iter.spl b/test/1026-fib-iter.spl @@ -1,5 +1,5 @@ -func fib(n i32) i32 { +fn fib(n i32) i32 { var a i32 = 0; var b i32 = 1; var z i32 = 0; @@ -13,7 +13,7 @@ func fib(n i32) i32 { return a; } -func start() i32 { +fn start() i32 { var n i32 = 0; while n < 24 { _hexout_(fib(n)); diff --git a/test/1030-flow-control.spl b/test/1030-flow-control.spl @@ -1,8 +1,8 @@ -func hex(n i32) { +fn hex(n i32) { _hexout_(n); } -func count(n i32) { +fn count(n i32) { while (n > 0) { hex(n); if (n == 3) { @@ -12,7 +12,7 @@ func count(n i32) { } } -func count_even(n i32) { +fn count_even(n i32) { while (n > 0) { n--; if ((n & 1) == 1) { @@ -22,7 +22,7 @@ func count_even(n i32) { } } -func start() i32 { +fn start() i32 { if (true) { hex(0x10101010); } else { diff --git a/test/1031-logical-and-or.spl b/test/1031-logical-and-or.spl @@ -1,18 +1,18 @@ -func is_three(n i32) i32 { +fn is_three(n i32) i32 { _hexout_(0x333); return n == 3; } -func is_six(n i32) i32 { +fn is_six(n i32) i32 { _hexout_(0x666); return n == 6; } -func is_nine(n i32) i32 { +fn is_nine(n i32) i32 { _hexout_(0x999); return n == 9; } -func or_test2(n i32) { +fn or_test2(n i32) { if (is_three(n) || is_six(n) || is_nine(n)) { _hexout_(n | 0x1100); } else { @@ -20,14 +20,14 @@ func or_test2(n i32) { } } -func or_test(n i32) { +fn or_test(n i32) { if (n == 3 || n == 6 || n == 9) { _hexout_(n | 0x100); } else { _hexout_(n | 0x200); } } -func and_test(n i32) { +fn and_test(n i32) { if ((n & 1 == 1) && (n & 2 == 2) && (n < 8)) { _hexout_(n | 0x300); } else { @@ -35,7 +35,7 @@ func and_test(n i32) { } } -func start() i32 { +fn start() i32 { var n i32 = 0; while n < 10 { or_test(n); diff --git a/test/1040-structs.spl b/test/1040-structs.spl @@ -9,12 +9,12 @@ struct Line { end Point, }; -func add(a Point, b Point) { +fn add(a Point, b Point) { a.x = a.x + b.x; a.y = a.y + b.y; } -func print(p Point) { +fn print(p Point) { _hexout_(p.x); _hexout_(p.y); } @@ -29,7 +29,7 @@ var line Line = { // var p2 struct { x i32, y i32, } = { x: 7, y: 6 }; -func start() i32 { +fn start() i32 { _hexout_(p0.x); _hexout_(p0.y); p0.x = 123; diff --git a/test/1041-arrays.spl b/test/1041-arrays.spl @@ -4,7 +4,7 @@ var numbers [8]u8 = { 1, 2, 4, 8, 16, 32, 64, 128 }; var data [8]u8 = { 0x10, 0x20, 0x30, 0x40, 0x50, 0x60, 0x70, 0x80 }; -func dump(x [8]u8) { +fn dump(x [8]u8) { var n i32 = 0; while (n < 8) { _hexout_(x[n]); @@ -12,7 +12,7 @@ func dump(x [8]u8) { } } -func start() i32 { +fn start() i32 { var n i32 = 0; var m i32 = 0; while (n < 8) { diff --git a/test/1042-arrays2.spl b/test/1042-arrays2.spl @@ -1,7 +1,7 @@ var data [8]u8; -func start() i32 { +fn start() i32 { var n i32 = 0; while n < 8 { data[n] = n << 4; diff --git a/test/1043-str.spl b/test/1043-str.spl @@ -1,7 +1,7 @@ var hello str = "Hello"; -func strlen(x str) i32 { +fn strlen(x str) i32 { var n i32 = 0; while x[n] != 0 { n++; @@ -9,7 +9,7 @@ func strlen(x str) i32 { return n; } -func dump(x str, xlen i32) { +fn dump(x str, xlen i32) { var n i32 = 0; while n < xlen { _hexout_(x[n]); @@ -19,7 +19,7 @@ func dump(x str, xlen i32) { var strtab [5]str = { "aaa", "bbb", "xxx", "ddd", "eee" }; -func start() i32 { +fn start() i32 { dump(hello, strlen(hello)); var n i32 = 0; strtab[2] = "ccc"; diff --git a/test/1045-list.spl b/test/1045-list.spl @@ -4,11 +4,11 @@ struct Node { value i32, }; -func print(node Node) { +fn print(node Node) { _hexout_(node.value); } -func start() i32 { +fn start() i32 { var node Node = new(Node); node.value = 42; print(node); diff --git a/test/1050-enums.spl b/test/1050-enums.spl @@ -5,7 +5,7 @@ enum { ZERO, ONE, TWO, }; enum { A = 5, B = 6, C = 0x10000000, D = 0x10000001, E = 50 + 50, F = ONE * TWO, }; -func start() i32 { +fn start() i32 { _hexout_(ZERO); _hexout_(ONE); _hexout_(TWO); diff --git a/test/2000-err-decl-mismatch-type.spl b/test/2000-err-decl-mismatch-type.spl @@ -1,6 +1,6 @@ -func hello(a i32, b i32) bool; +fn hello(a i32, b i32) bool; -func hello(a i32, b bool) bool { +fn hello(a i32, b bool) bool { return false; } diff --git a/test/2001-err-decl-mismatch-return.spl b/test/2001-err-decl-mismatch-return.spl @@ -1,5 +1,5 @@ -func hello(a i32, b i32) bool; +fn hello(a i32, b i32) bool; -func hello(a i32, b i32) { +fn hello(a i32, b i32) { } diff --git a/test/2002-err-decl-mismatch-count.spl b/test/2002-err-decl-mismatch-count.spl @@ -1,6 +1,6 @@ -func hello(a i32, b i32) bool; +fn hello(a i32, b i32) bool; -func hello(a i32, b i32, c i32) bool { +fn hello(a i32, b i32, c i32) bool { return false; } diff --git a/test/2003-err-decl-mismatch-array.spl b/test/2003-err-decl-mismatch-array.spl @@ -1,8 +1,8 @@ -func a1a1a1(aaa [17]i32) { +fn a1a1a1(aaa [17]i32) { } -func bad() { +fn bad() { var z [10]i32; a1a1a1(z); } diff --git a/test/2011-err-array-oob-const.spl b/test/2011-err-array-oob-const.spl @@ -1,6 +1,6 @@ var blarg [256]byte; -func bad() { +fn bad() { var n i32 = blarg[256]; } diff --git a/test/2020-err-u32-overflow.spl b/test/2020-err-u32-overflow.spl @@ -1,3 +1,3 @@ -func start() i32 { +fn start() i32 { return 4294967296; } diff --git a/test/2021-err-u32-hex-overflow.spl b/test/2021-err-u32-hex-overflow.spl @@ -1,3 +1,3 @@ -func start() i32 { +fn start() i32 { return 0x123456789; } diff --git a/test/2022-err-u32-bin-overflow.spl b/test/2022-err-u32-bin-overflow.spl @@ -1,3 +1,3 @@ -func start() i32 { +fn start() i32 { return 0b100010001000100010001000100010001; } diff --git a/test/2030-err-bad-break.spl b/test/2030-err-bad-break.spl @@ -1,4 +1,4 @@ -func nogood() { +fn nogood() { break; } diff --git a/test/2031-err-bad-continue.spl b/test/2031-err-bad-continue.spl @@ -1,4 +1,4 @@ -func fail() { +fn fail() { continue; }