diff --git a/CHANGELOG.md b/CHANGELOG.md index 52c9688f..6fea27fa 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -15,6 +15,7 @@ - Qualified name now use `\` separator instead of `.` - The `float` type is renamed to `double` (https://github.com/buzz-language/buzz/issues/311) - Enum type is declared between `<>` rather than `()` +- `const` keyword is renamed to `final` (https://github.com/buzz-language/buzz/issues/318) ## Added - Object can have `const` properties (https://github.com/buzz-language/buzz/issues/13). A object with only `const` properties is considered itself `const`. Although we don't do anything yet with that concept. https://github.com/buzz-language/buzz/issues/114 is the objective but it requires being able to build objects and instances at compile time which is not yet possible. diff --git a/examples/2048.buzz b/examples/2048.buzz index dbb288a3..534c2008 100644 --- a/examples/2048.buzz +++ b/examples/2048.buzz @@ -48,7 +48,7 @@ object Game { invalidMove: bool = false, static fun init(size: int = 4, goal: int = 2048) > Game { - const game = Game{ + final game = Game{ size, goal }; @@ -76,13 +76,13 @@ object Game { // Add new tile at a random free sp fun addNewTile() > void { - const free = this.freeSpots(); + final free = this.freeSpots(); if (free.len() == 0) { return; } - const spot = free[std\random(min: 0, max: free.len() - 1)]; + final spot = free[std\random(min: 0, max: free.len() - 1)]; this.board[spot.x][spot.y] = if (std\random(min: 0, max: 9) == 0) 4 else @@ -158,7 +158,7 @@ object Game { foreach (x in 0..this.size) { foreach (y in 0..this.size) { - const pair = Pair{ + final pair = Pair{ srcX = x, srcY = y, srcValue = this.board[x][y], @@ -227,7 +227,7 @@ object Game { fun move() > bool { io\stdout.write("(wasd to move, q to quit, r to restart)\n> ") catch void; - const command = io\stdin.read(1) catch void; + final command = io\stdin.read(1) catch void; if (command == "q") { os\exit(0); @@ -294,7 +294,7 @@ object Game { } fun main(_: [str]) > void { - const game = Game.init(); + final game = Game.init(); game.addNewTile(); game.render(); diff --git a/examples/brownian-tree.buzz b/examples/brownian-tree.buzz index 2dcee781..5ada4549 100644 --- a/examples/brownian-tree.buzz +++ b/examples/brownian-tree.buzz @@ -29,11 +29,11 @@ fun setParticle(canvas: [[bool]]) > obj{ x: int, y: int } { fun iterate(canvas: [[bool]], numParticles: int) { foreach (_ in 0..numParticles) { - const pos = setParticle(canvas); + final pos = setParticle(canvas); while (true) { - const dx = std\random(min: 0, max: 5) - 3; - const dy = std\random(min: 0, max: 5) - 3; + final dx = std\random(min: 0, max: 5) - 3; + final dy = std\random(min: 0, max: 5) - 3; if (pos.x + dx >= 0 and pos.x + dx < canvas.len() and pos.y + dy >= 0 and pos.y + dy < canvas[0].len()) { if (canvas[pos.x + dx][pos.y + dy]) { @@ -72,9 +72,9 @@ fun draw(canvas: [[bool]], renderer: Renderer) > void !> SDLError { } fun main(_: [str]) > void !> SDLError { - const sizeX = 200; - const sizeY = 200; - const numParticles = 16000; + final sizeX = 200; + final sizeY = 200; + final numParticles = 16000; var canvas: [[bool]] = []; foreach (i in 0..sizeX) { diff --git a/examples/fibonacci.buzz b/examples/fibonacci.buzz index 2ce91310..b0234243 100644 --- a/examples/fibonacci.buzz +++ b/examples/fibonacci.buzz @@ -14,7 +14,7 @@ fun fibonacci(n: int) > void *> int? { } fun main(args: [str]) > void { - const N = std\parseInt(args[?0] ?? "10") ?? 10; + final N = std\parseInt(args[?0] ?? "10") ?? 10; foreach (n in &fibonacci(N)) { std\print("{n}"); diff --git a/examples/fizzbuzz.buzz b/examples/fizzbuzz.buzz index 0219b9fb..3c001eb1 100644 --- a/examples/fizzbuzz.buzz +++ b/examples/fizzbuzz.buzz @@ -3,8 +3,8 @@ namespace examples\fizzbuzz; import "std"; fun fizzBuzz(n: int) > str { - const fizz = n % 3 == 0; - const buzz = n % 5 == 0; + final fizz = n % 3 == 0; + final buzz = n % 5 == 0; if (fizz and buzz) { return "FizzBuzz"; @@ -18,7 +18,7 @@ fun fizzBuzz(n: int) > str { } fun main(args: [str]) > void { - const limit = std\parseInt(args[?0] ?? "10") ?? 10; + final limit = std\parseInt(args[?0] ?? "10") ?? 10; foreach (n in 0..limit) { std\print("{n}: {fizzBuzz(n)}"); diff --git a/examples/game-of-life.buzz b/examples/game-of-life.buzz index 229a5a36..48d72781 100644 --- a/examples/game-of-life.buzz +++ b/examples/game-of-life.buzz @@ -39,8 +39,8 @@ object World { var cells = []; for (y: int = 0; y < this.height; y = y + 1) { for (x: int = 0; x < this.width; x = x + 1) { - const coordinate = y * this.width + x; - const liveNeighbors = this.neighbors(x: x, y: y); + final coordinate = y * this.width + x; + final liveNeighbors = this.neighbors(x: x, y: y); cells.append(liveNeighbors == 3 or (this.cells[coordinate] and liveNeighbors == 2)); } @@ -64,8 +64,8 @@ object World { } fun draw(renderer: Renderer) > void !> SDLError { - const cellWidth = 800 / this.width; - const cellHeight = 600 / this.height; + final cellWidth = 800 / this.width; + final cellHeight = 600 / this.height; for (y: int = 0; y < this.height; y = y + 1) { for (x: int = 0; x < this.width; x = x + 1) { @@ -154,8 +154,8 @@ fun main(args: [str]) > void !> SDLError { height: 600, ); - const width = if (args.len() > 0) std\parseInt(args[0]) else null; - const height = if (args.len() > 1) std\parseInt(args[1]) else null; + final width = if (args.len() > 0) std\parseInt(args[0]) else null; + final height = if (args.len() > 1) std\parseInt(args[1]) else null; var world = World.init( width: width ?? 10, diff --git a/examples/sdl-wrapped.buzz b/examples/sdl-wrapped.buzz index fc5ff666..e146fecb 100644 --- a/examples/sdl-wrapped.buzz +++ b/examples/sdl-wrapped.buzz @@ -294,7 +294,7 @@ export object Renderer { width: int, height: int ) > Texture !> SDLError { - const texture = SDL_CreateTexture( + final texture = SDL_CreateTexture( this.renderer, format: std\toDouble(format.value), access: access.value, @@ -314,7 +314,7 @@ export object Renderer { } fun setRenderTarget(texture: Texture?) > void !> SDLError { - const result = SDL_SetRenderTarget( + final result = SDL_SetRenderTarget( this.renderer, texture: texture?.texture ); @@ -327,7 +327,7 @@ export object Renderer { } fun setRenderDrawColor(color: Color) > void !> SDLError { - const result = SDL_SetRenderDrawColor( + final result = SDL_SetRenderDrawColor( this.renderer, r: color.red, g: color.green, @@ -343,7 +343,7 @@ export object Renderer { } fun fillRect(rect: Rect) > void !> SDLError { - const result = SDL_RenderFillRect( + final result = SDL_RenderFillRect( this.renderer, rect: SDL_Rect{ x = rect.x, @@ -361,7 +361,7 @@ export object Renderer { } fun drawPoint(x: int, y: int) > void !> SDLError { - const result = SDL_RenderDrawPoint( + final result = SDL_RenderDrawPoint( this.renderer, x, y, ); @@ -374,7 +374,7 @@ export object Renderer { } fun renderCopy(texture: Texture, srcRect: Rect? = null, dstRect: Rect? = null) > void !> SDLError { - const result = SDL_RenderCopy( + final result = SDL_RenderCopy( this.renderer, texture: texture.texture, srcrect: if (srcRect -> rect) @@ -427,7 +427,7 @@ export object Window { windowFlags = windowFlags | flag.value; } - const window = SDL_CreateWindow( + final window = SDL_CreateWindow( ffi\cstr(name), x, y, @@ -456,7 +456,7 @@ export object Window { rendererFlags = rendererFlags | flag.value; } - const renderer = SDL_CreateRenderer( + final renderer = SDL_CreateRenderer( this.window, index: index, flags: std\toDouble(rendererFlags), diff --git a/examples/sdl.buzz b/examples/sdl.buzz index d1fae7e8..a41b7ed2 100644 --- a/examples/sdl.buzz +++ b/examples/sdl.buzz @@ -2,21 +2,21 @@ import "examples/sdl-wrapped" as _; // buzz -L/path/to/SDL2.dylib/so/dll examples/sdl.buzz fun main(_: [str]) > int !> SDLError { - const sdl = SDL.init([Subsystem.Video]); + final sdl = SDL.init([Subsystem.Video]); - const window = Window.init( + final window = Window.init( "SDL FFI test", width: 800, height: 600, flags: [WindowFlag.OpenGL, WindowFlag.AllowHighDPI], ); - const renderer = window.createRenderer( + final renderer = window.createRenderer( index: -1, flags: [RendererFlag.Accelerated, RendererFlag.TargetTexture], ); - const texture = renderer.createTexture( + final texture = renderer.createTexture( format: PixelFormat.RGBA8888, access: TextureAccess.Target, width: 800, diff --git a/examples/sqlite.buzz b/examples/sqlite.buzz index 207f7937..469fbfb8 100644 --- a/examples/sqlite.buzz +++ b/examples/sqlite.buzz @@ -45,7 +45,7 @@ enum ResultCode { Empty = 16, // Internal use only Schema = 17, // The database schema changed TooBig = 18, // String or BLOB exceeds size limit - Constraint = 19, // Abort due to constraint violation + Constraint = 19, // Abort due to finalraint violation Mismatch = 20, // Data type mismatch Misuse = 21, // Library used incorrectly NoLfs = 22, // Uses OS features not supported on host @@ -156,7 +156,7 @@ export object Statement { std\print("Executing query `{this.query}`"); var code: ResultCode = ResultCode.Ok; - const rows = [<[Boxed]>]; + final rows = [<[Boxed]>]; while (code != ResultCode.Done) { code = ResultCode(sqlite3_step(this.stmt)) ?? ResultCode.Error; if (code != ResultCode.Ok and code != ResultCode.Row and code != ResultCode.Done) { @@ -170,10 +170,10 @@ export object Statement { break; } - const columnCount = sqlite3_column_count(this.stmt); + final columnCount = sqlite3_column_count(this.stmt); var row = []; for (i: int = 0; i < columnCount; i = i + 1) { - const columnType = Type(sqlite3_column_type(this.stmt, col: i)) ?? Type.Null; + final columnType = Type(sqlite3_column_type(this.stmt, col: i)) ?? Type.Null; if (columnType == Type.Integer) { row.append( @@ -196,7 +196,7 @@ export object Statement { } } - const boxedRow = (Boxed.init(row) catch void).listValue(); + final boxedRow = (Boxed.init(row) catch void).listValue(); rows.append(boxedRow); _ = yield boxedRow; @@ -222,10 +222,10 @@ export object Database { } fun prepareRaw(query: str) > Statement !> SQLiteError { - const buffer = buffer\Buffer.init(); + final buffer = buffer\Buffer.init(); buffer.writeUserData(std\toUd(0)) catch void; - const code = ResultCode( + final code = ResultCode( sqlite3_prepare_v2( db: this.db, zSql: ffi\cstr(query), @@ -251,7 +251,7 @@ export object Database { export object SQLite { static fun init() > SQLite !> SQLiteError { - const code = ResultCode(sqlite3_initialize()) ?? ResultCode.Error; + final code = ResultCode(sqlite3_initialize()) ?? ResultCode.Error; if (code != ResultCode.Ok) { throw SQLiteError{ code = code, @@ -276,10 +276,10 @@ export object SQLite { cFlags = cFlags | flag.value; } - const buffer = buffer\Buffer.init(); + final buffer = buffer\Buffer.init(); buffer.writeUserData(std\toUd(0)) catch void; - const code = ResultCode( + final code = ResultCode( sqlite3_open_v2( filename: ffi\cstr(filename), ppDb: buffer.ptr(), @@ -304,11 +304,11 @@ export object SQLite { } test "Testing sqlite" { - const sqlite = SQLite.init(); + final sqlite = SQLite.init(); - const database = sqlite.open("./test.db", flags: [OpenFlag.ReadWrite, OpenFlag.Create]); + final database = sqlite.open("./test.db", flags: [OpenFlag.ReadWrite, OpenFlag.Create]); - const statement = database.prepareRaw(` + final statement = database.prepareRaw(` CREATE TABLE IF NOT EXISTS test ( name TEXT NOT NULL ) @@ -323,7 +323,7 @@ test "Testing sqlite" { .execute(database); } - const select = Query{} + final select = Query{} .select([ "rowid", "name" ]) .@"from"("test") .prepare(database); diff --git a/examples/voronoi-diagram.buzz b/examples/voronoi-diagram.buzz index fadd5c94..fc195dfa 100644 --- a/examples/voronoi-diagram.buzz +++ b/examples/voronoi-diagram.buzz @@ -40,7 +40,7 @@ fun generateVoronoi(renderer: Renderer, width: int, height: int, numCells: int) var dmin = hypot(x: width - 1, y: height - 1); var j = -1; foreach (i in 0..numCells) { - const d = hypot(x: nx[i] - x, y: ny[i] - y); + final d = hypot(x: nx[i] - x, y: ny[i] - y); if (d < dmin) { dmin = d; j = i; @@ -67,9 +67,9 @@ fun generateVoronoi(renderer: Renderer, width: int, height: int, numCells: int) } fun main(_: [str]) > void !> SDLError { - const width = 400; - const height = 400; - const numCells = 50; + final width = 400; + final height = 400; + final numCells = 50; var sdl = SDL.init([Subsystem.Video]); diff --git a/src/Ast.zig b/src/Ast.zig index 7cc29081..cafe173c 100644 --- a/src/Ast.zig +++ b/src/Ast.zig @@ -602,7 +602,7 @@ pub const NamedVariable = struct { value: ?Node.Index, slot: Slot, slot_type: SlotType, - slot_constant: bool, + slot_final: bool, }; pub const ObjectDeclaration = struct { @@ -698,7 +698,7 @@ pub const VarDeclaration = struct { name: TokenIndex, value: ?Node.Index, type: ?Node.Index, - constant: bool, + final: bool, slot: Slot, slot_type: SlotType, }; diff --git a/src/Chunk.zig b/src/Chunk.zig index 59dcacac..a3090ccf 100644 --- a/src/Chunk.zig +++ b/src/Chunk.zig @@ -166,6 +166,7 @@ pub fn HashMap(V: type) type { allocator: std.mem.Allocator, /// AST ast: Ast, +// TODO: merge `code` and `lines` in a multiarray /// List of opcodes to execute code: std.ArrayListUnmanaged(u32), /// List of locations diff --git a/src/Codegen.zig b/src/Codegen.zig index 472a8bcc..a0077c02 100644 --- a/src/Codegen.zig +++ b/src/Codegen.zig @@ -1546,11 +1546,11 @@ fn generateDot(self: *Self, node: Ast.Node.Index, breaks: ?*Breaks) Error!?*obj. field_name, }, ); - } else if (field.?.constant) { + } else if (field.?.final) { self.reporter.reportErrorFmt( .constant_property, self.ast.tokens.get(locations[value]), - "`{s}` is constant", + "`{s}` is final", .{ field_name, }, diff --git a/src/Parser.zig b/src/Parser.zig index bf122f32..cbc460d5 100644 --- a/src/Parser.zig +++ b/src/Parser.zig @@ -199,7 +199,7 @@ pub const Local = struct { type_def: *obj.ObjTypeDef, depth: i32, is_captured: bool, - constant: bool, + final: bool, referenced: bool = false, pub fn isReferenced(self: Local, ast: Ast) bool { @@ -221,7 +221,7 @@ pub const Global = struct { initialized: bool = false, exported: bool = false, hidden: bool = false, - constant: bool, + final: bool, referenced: bool = false, pub fn isReferenced(self: Global, ast: Ast) bool { @@ -500,7 +500,7 @@ const rules = [_]ParseRule{ .{ .prefix = null, .infix = null, .precedence = .None }, // Test .{ .prefix = null, .infix = null, .precedence = .None }, // Import .{ .prefix = null, .infix = null, .precedence = .None }, // Export - .{ .prefix = null, .infix = null, .precedence = .None }, // Const + .{ .prefix = null, .infix = null, .precedence = .None }, // Final .{ .prefix = null, .infix = null, .precedence = .None }, // Static .{ .prefix = blockExpression, .infix = null, .precedence = .None }, // From .{ .prefix = null, .infix = null, .precedence = .None }, // As @@ -802,7 +802,7 @@ fn synchronize(self: *Self) !void { .Enum, .Test, .Fun, - .Const, + .Final, .If, .While, .Do, @@ -1333,11 +1333,11 @@ fn declaration(self: *Self) Error!?Ast.Node.Index { try self.enumDeclaration() else if ((try self.match(.Fun)) or (global_scope and try self.match(.Extern))) try self.funDeclaration() - else if ((try self.match(.Const)) or + else if ((try self.match(.Final)) or (try self.match(.Var) or (self.check(.Identifier) and std.mem.eql(u8, "_", self.ast.tokens.items(.lexeme)[self.current_token.?])))) variable: { - const constant = self.current_token.? > 0 and self.ast.tokens.items(.tag)[self.current_token.? - 1] == .Const; + const final = self.current_token.? > 0 and self.ast.tokens.items(.tag)[self.current_token.? - 1] == .Final; try self.consume(.Identifier, "Expected identifier"); const identifier = self.current_token.? - 1; @@ -1347,7 +1347,7 @@ fn declaration(self: *Self) Error!?Ast.Node.Index { identifier, null, .Semicolon, - constant, + final, true, false, ); @@ -1360,7 +1360,7 @@ fn declaration(self: *Self) Error!?Ast.Node.Index { identifier, try self.simpleType(simpleTypeFromToken(token).?), .Semicolon, - constant, + final, true, false, ); @@ -1373,7 +1373,7 @@ fn declaration(self: *Self) Error!?Ast.Node.Index { identifier, try self.parseFiberType(null), .Semicolon, - constant, + final, true, false, ) @@ -1382,7 +1382,7 @@ fn declaration(self: *Self) Error!?Ast.Node.Index { identifier, try self.parseObjType(null), .Semicolon, - constant, + final, true, false, ) @@ -1391,7 +1391,7 @@ fn declaration(self: *Self) Error!?Ast.Node.Index { identifier, try self.parseListType(null), .Semicolon, - constant, + final, true, false, ) @@ -1400,7 +1400,7 @@ fn declaration(self: *Self) Error!?Ast.Node.Index { identifier, try self.parseMapType(null), .Semicolon, - constant, + final, true, false, ) @@ -1409,14 +1409,14 @@ fn declaration(self: *Self) Error!?Ast.Node.Index { identifier, try self.parseFunctionType(null), .Semicolon, - constant, + final, true, false, ) else if (try self.match(.Identifier)) { break :variable try self.userVarDeclaration( identifier, - constant, + final, ); } @@ -1505,7 +1505,7 @@ fn statement(self: *Self, hanging: bool, loop_scope: ?LoopScope) !?Ast.Node.Inde return try self.expressionStatement(hanging); } -fn addLocal(self: *Self, name: Ast.TokenIndex, local_type: *obj.ObjTypeDef, constant: bool) Error!usize { +fn addLocal(self: *Self, name: Ast.TokenIndex, local_type: *obj.ObjTypeDef, final: bool) Error!usize { if (self.current.?.local_count == 255) { self.reportError(.locals_count, "Too many local variables in scope."); return 0; @@ -1517,7 +1517,7 @@ fn addLocal(self: *Self, name: Ast.TokenIndex, local_type: *obj.ObjTypeDef, cons .depth = -1, .is_captured = false, .type_def = local_type, - .constant = constant, + .final = final, // Extern and abstract function arguments are considered referenced .referenced = function_type == .Extern or function_type == .Abstract, }; @@ -1527,7 +1527,7 @@ fn addLocal(self: *Self, name: Ast.TokenIndex, local_type: *obj.ObjTypeDef, cons return self.current.?.local_count - 1; } -fn addGlobal(self: *Self, name: Ast.TokenIndex, global_type: *obj.ObjTypeDef, constant: bool) Error!usize { +fn addGlobal(self: *Self, name: Ast.TokenIndex, global_type: *obj.ObjTypeDef, final: bool) Error!usize { const lexemes = self.ast.tokens.items(.lexeme); // Search for an existing placeholder global with the same name for (self.globals.items, 0..) |*global, index| { @@ -1538,7 +1538,7 @@ fn addGlobal(self: *Self, name: Ast.TokenIndex, global_type: *obj.ObjTypeDef, co global.exported = self.exporting; if (global_type.def_type != .Placeholder) { - try self.resolvePlaceholder(global.type_def, global_type, constant); + try self.resolvePlaceholder(global.type_def, global_type, final); } return index; @@ -1561,7 +1561,7 @@ fn addGlobal(self: *Self, name: Ast.TokenIndex, global_type: *obj.ObjTypeDef, co .{ .name = qualified_name.items, .type_def = global_type, - .constant = constant, + .final = final, .exported = self.exporting, }, ); @@ -1661,7 +1661,7 @@ fn resolvePlaceholderWithRelation( self: *Self, child: *obj.ObjTypeDef, resolved_type: *obj.ObjTypeDef, - constant: bool, + final: bool, relation: obj.PlaceholderDef.PlaceholderRelation, ) Error!void { const child_placeholder = child.resolved_type.?.Placeholder; @@ -1906,7 +1906,7 @@ fn resolvePlaceholderWithRelation( try self.resolvePlaceholder( child, field.type_def, - field.constant, + field.final, ); } else { self.reportErrorFmt( @@ -1928,7 +1928,7 @@ fn resolvePlaceholderWithRelation( try self.resolvePlaceholder( child, field.type_def, - field.constant, + field.final, ); } else { self.reportErrorFmt( @@ -2024,11 +2024,11 @@ fn resolvePlaceholderWithRelation( } }, .Assignment => { - if (constant) { + if (final) { self.reporter.reportErrorAt( - .constant, + .final, self.ast.tokens.get(child_placeholder.where), - "Is constant.", + "Is final.", ); return; } @@ -2045,7 +2045,7 @@ fn resolvePlaceholderWithRelation( // When we encounter the missing declaration we replace it with the resolved type. // We then follow the chain of placeholders to see if their assumptions were correct. // If not we raise a compile error. -pub fn resolvePlaceholder(self: *Self, placeholder: *obj.ObjTypeDef, resolved_type: *obj.ObjTypeDef, constant: bool) Error!void { +pub fn resolvePlaceholder(self: *Self, placeholder: *obj.ObjTypeDef, resolved_type: *obj.ObjTypeDef, final: bool) Error!void { std.debug.assert(placeholder.def_type == .Placeholder); if (BuildOptions.debug_placeholders) { @@ -2080,7 +2080,7 @@ pub fn resolvePlaceholder(self: *Self, placeholder: *obj.ObjTypeDef, resolved_ty try self.resolvePlaceholderWithRelation( resolved_type, parent, - constant, + final, resolved_type.resolved_type.?.Placeholder.parent_relation.?, ); } @@ -2128,7 +2128,7 @@ pub fn resolvePlaceholder(self: *Self, placeholder: *obj.ObjTypeDef, resolved_ty try self.resolvePlaceholderWithRelation( child, placeholder, - constant, + final, child.resolved_type.?.Placeholder.parent_relation.?, ); } @@ -2182,7 +2182,7 @@ fn resolveUpvalue(self: *Self, frame: *Frame, name: Ast.TokenIndex) Error!?usize return null; } -fn declareVariable(self: *Self, variable_type: *obj.ObjTypeDef, name: Ast.TokenIndex, constant: bool, check_name: bool) Error!usize { +fn declareVariable(self: *Self, variable_type: *obj.ObjTypeDef, name: Ast.TokenIndex, final: bool, check_name: bool) Error!usize { const lexemes = self.ast.tokens.items(.lexeme); const name_lexeme = lexemes[name]; @@ -2215,7 +2215,7 @@ fn declareVariable(self: *Self, variable_type: *obj.ObjTypeDef, name: Ast.TokenI } } - return try self.addLocal(name, variable_type, constant); + return try self.addLocal(name, variable_type, final); } else { if (check_name) { // Check a global with the same name doesn't exists @@ -2245,7 +2245,7 @@ fn declareVariable(self: *Self, variable_type: *obj.ObjTypeDef, name: Ast.TokenI ); } - try self.resolvePlaceholder(global.type_def, variable_type, constant); + try self.resolvePlaceholder(global.type_def, variable_type, final); } global.referenced = true; @@ -2258,7 +2258,7 @@ fn declareVariable(self: *Self, variable_type: *obj.ObjTypeDef, name: Ast.TokenI } } - return try self.addGlobal(name, variable_type, constant); + return try self.addGlobal(name, variable_type, final); } } @@ -2266,7 +2266,7 @@ fn parseVariable( self: *Self, identifier: ?Ast.TokenIndex, variable_type: *obj.ObjTypeDef, - constant: bool, + final: bool, error_message: []const u8, ) !usize { if (identifier == null) { @@ -2276,7 +2276,7 @@ fn parseVariable( return try self.declareVariable( variable_type, identifier orelse self.current_token.? - 1, - constant, + final, true, ); } @@ -3057,7 +3057,7 @@ fn parseObjType(self: *Self, generic_types: ?std.AutoArrayHashMap(*obj.ObjString var obj_is_not_tuple = false; var property_idx: usize = 0; while (!self.check(.RightBrace) and !self.check(.Eof)) : (property_idx += 1) { - const constant = try self.match(.Const); + const final = try self.match(.Final); const is_tuple = !(try self.match(.Identifier)); const property_name = if (!is_tuple) @@ -3121,7 +3121,7 @@ fn parseObjType(self: *Self, generic_types: ?std.AutoArrayHashMap(*obj.ObjString .name = property_name_lexeme, .type_def = self.ast.nodes.items(.type_def)[property_type].?, .location = self.ast.tokens.get(property_name), - .constant = constant, + .final = final, .static = false, .method = false, .has_default = false, @@ -4051,7 +4051,7 @@ fn anonymousObjectInit(self: *Self, _: bool) Error!Ast.Node.Index { .location = self.ast.tokens.get(property_name), .static = false, .method = false, - .constant = false, + .final = false, .has_default = false, .index = property_idx, }, @@ -4102,7 +4102,7 @@ fn anonymousObjectInit(self: *Self, _: bool) Error!Ast.Node.Index { .location = self.ast.tokens.get(property_name), .static = false, .method = false, - .constant = false, + .final = false, .has_default = false, .index = property_idx, }, @@ -4501,7 +4501,7 @@ fn dot(self: *Self, can_assign: bool, callee: Ast.Node.Index) Error!Ast.Node.Ind property_type; // If its a field or placeholder, we can assign to it - // TODO: here get info that field is constant or not + // TODO: here get info that field is final or not var components = self.ast.nodes.items(.components); if (can_assign and try self.match(.Equal)) { components[dot_node].Dot.member_kind = .Value; @@ -5077,18 +5077,18 @@ fn namedVariable(self: *Self, name: []const Ast.TokenIndex, can_assign: bool) Er var var_def: ?*obj.ObjTypeDef = null; var slot: usize = undefined; var slot_type: Ast.SlotType = undefined; - var slot_constant = false; + var slot_final = false; if (name.len == 1) { if (try self.resolveLocal(self.current.?, name[0])) |uslot| { var_def = self.current.?.locals[uslot].type_def; slot = uslot; slot_type = .Local; - slot_constant = self.current.?.locals[uslot].constant; + slot_final = self.current.?.locals[uslot].final; } else if (try self.resolveUpvalue(self.current.?, name[0])) |uslot| { var_def = self.current.?.enclosing.?.locals[self.current.?.upvalues[uslot].index].type_def; slot = uslot; slot_type = .UpValue; - slot_constant = self.current.?.enclosing.?.locals[self.current.?.upvalues[uslot].index].constant; + slot_final = self.current.?.enclosing.?.locals[self.current.?.upvalues[uslot].index].final; } } @@ -5099,7 +5099,7 @@ fn namedVariable(self: *Self, name: []const Ast.TokenIndex, can_assign: bool) Er var_def = global.type_def; slot = uslot; slot_type = .Global; - slot_constant = global.constant; + slot_final = global.final; if (global.imported_from != null and self.script_imports.get(global.imported_from.?) != null) { const imported_from = global.imported_from.?; @@ -5134,8 +5134,8 @@ fn namedVariable(self: *Self, name: []const Ast.TokenIndex, can_assign: bool) Er else null; - if (value != null and slot_constant) { - self.reportError(.constant, "Can't assign to constant variable"); + if (value != null and slot_final) { + self.reportError(.final, "Can't assign to final variable"); } return try self.ast.appendNode( @@ -5150,7 +5150,7 @@ fn namedVariable(self: *Self, name: []const Ast.TokenIndex, can_assign: bool) Er .value = value, .slot = @intCast(slot), .slot_type = slot_type, - .slot_constant = slot_constant, + .slot_final = slot_final, }, }, }, @@ -5366,7 +5366,7 @@ fn function( const slot = try self.parseVariable( identifier, argument_type, - true, // function arguments are constant + true, // function arguments are final "Expected argument name", ); @@ -6518,7 +6518,7 @@ fn objectDeclaration(self: *Self) Error!Ast.Node.Index { .{ .name = method_name, .type_def = method_type_def.?, - .constant = true, + .final = true, .static = static, .location = self.ast.tokens.get(method_token), .method = true, @@ -6540,7 +6540,7 @@ fn objectDeclaration(self: *Self) Error!Ast.Node.Index { try fields.put(method_name, {}); try properties_type.put(method_name, self.ast.nodes.items(.type_def)[method_node].?); } else { - const constant = try self.match(.Const); + const final = try self.match(.Final); try self.consume(.Identifier, "Expected property name."); const property_token = self.current_token.? - 1; @@ -6627,7 +6627,7 @@ fn objectDeclaration(self: *Self) Error!Ast.Node.Index { .{ .name = property_name.lexeme, .type_def = self.ast.nodes.items(.type_def)[property_type].?, - .constant = constant, + .final = final, .static = static, .location = property_name, .method = false, @@ -6670,7 +6670,7 @@ fn objectDeclaration(self: *Self) Error!Ast.Node.Index { const slot = try self.declareVariable( &object_type, // Should resolve object_name_tokenect_placeholder and be discarded object_name_token, - true, // Object is always constant + true, // Object is always final true, ); @@ -6814,7 +6814,7 @@ fn protocolDeclaration(self: *Self) Error!Ast.Node.Index { const slot = try self.declareVariable( &protocol_type, // Should resolve protocol_placeholder and be discarded protocol_name, - true, // Protocol is always constant + true, // Protocol is always final true, ); @@ -7047,7 +7047,7 @@ fn varDeclaration( identifier: ?Ast.TokenIndex, parsed_type: ?Ast.Node.Index, terminator: DeclarationTerminator, - constant: bool, + final: bool, should_assign: bool, type_provided_later: bool, ) Error!Ast.Node.Index { @@ -7062,7 +7062,7 @@ fn varDeclaration( const slot: usize = try self.parseVariable( identifier, var_type, - constant, + final, "Expected variable name.", ); @@ -7142,7 +7142,7 @@ fn varDeclaration( .name = name, .value = value, .type = parsed_type, - .constant = constant, + .final = final, .slot = @intCast(slot), .slot_type = if (self.current.?.scope_depth > 0) .Local else .Global, }, @@ -7152,9 +7152,9 @@ fn varDeclaration( } // Same as varDeclaration but does not parse anything (useful when we need to declare a variable that need to exists but is not exposed to the user) -fn implicitVarDeclaration(self: *Self, name: Ast.TokenIndex, parsed_type: *obj.ObjTypeDef, constant: bool) Error!Ast.Node.Index { +fn implicitVarDeclaration(self: *Self, name: Ast.TokenIndex, parsed_type: *obj.ObjTypeDef, final: bool) Error!Ast.Node.Index { const var_type = try parsed_type.toInstance(self.gc.allocator, &self.gc.type_registry); - const slot = try self.declareVariable(var_type, name, constant, true); + const slot = try self.declareVariable(var_type, name, final, true); self.markInitialized(); return try self.ast.appendNode( @@ -7168,7 +7168,7 @@ fn implicitVarDeclaration(self: *Self, name: Ast.TokenIndex, parsed_type: *obj.O .name = name, .value = null, .type = null, - .constant = constant, + .final = final, .slot = @intCast(slot), .slot_type = if (self.current.?.scope_depth > 0) .Local else .Global, }, @@ -7216,7 +7216,7 @@ fn testStatement(self: *Self) Error!Ast.Node.Index { .name = name_token, .value = function_node, .type = self.ast.nodes.items(.components)[function_node].Function.function_signature, - .constant = true, + .final = true, .slot = @intCast(slot), .slot_type = .Global, }, @@ -8025,7 +8025,7 @@ fn zdefStatement(self: *Self) Error!Ast.Node.Index { } // FIXME: this is almost the same as parseUserType! -fn userVarDeclaration(self: *Self, identifier: Ast.TokenIndex, constant: bool) Error!Ast.Node.Index { +fn userVarDeclaration(self: *Self, identifier: Ast.TokenIndex, final: bool) Error!Ast.Node.Index { const start_location = self.current_token.? - 1; var var_type: ?*obj.ObjTypeDef = null; @@ -8171,7 +8171,7 @@ fn userVarDeclaration(self: *Self, identifier: Ast.TokenIndex, constant: bool) E identifier, user_type_node, .Semicolon, - constant, + final, true, false, ); @@ -8724,7 +8724,7 @@ fn tryStatement(self: *Self) Error!Ast.Node.Index { _ = try self.parseVariable( identifier, self.ast.nodes.items(.type_def)[type_def].?, - true, // function arguments are constant + true, // function arguments are final "Expected error identifier", ); diff --git a/src/Reporter.zig b/src/Reporter.zig index 4294d562..d1fdccb4 100644 --- a/src/Reporter.zig +++ b/src/Reporter.zig @@ -34,7 +34,7 @@ pub const Error = enum(u8) { comparison_operand_type = 12, compile = 13, constant_default = 14, - constant = 15, + final = 15, do_condition_type = 16, enum_argument = 17, enum_case_type = 18, @@ -174,7 +174,8 @@ pub const ReportItem = struct { pub const SortContext = struct {}; pub fn lessThan(_: SortContext, lhs: ReportItem, rhs: ReportItem) bool { - return lhs.location.line < rhs.location.line or (lhs.location.line == rhs.location.line and lhs.location.column < rhs.location.column); + return lhs.location.line < rhs.location.line or + (lhs.location.line == rhs.location.line and lhs.location.column < rhs.location.column); } }; diff --git a/src/Scanner.zig b/src/Scanner.zig index 1e4432f5..a87a5ac8 100644 --- a/src/Scanner.zig +++ b/src/Scanner.zig @@ -662,7 +662,7 @@ pub fn highlight(self: *Self, out: anytype, true_color: bool) void { .ForEach, .Break, .Continue, - .Const, + .Final, .Fun, .In, .Str, diff --git a/src/Token.zig b/src/Token.zig index 0f3665e5..013dc865 100644 --- a/src/Token.zig +++ b/src/Token.zig @@ -151,7 +151,7 @@ pub const Type = enum { Test, // test Import, // import Export, // export - Const, // const + Final, // final Static, // static From, // from As, // as @@ -187,7 +187,7 @@ pub const keywords = std.StaticStringMap(Type).initComptime( .{ "bool", .Bool }, .{ "break", .Break }, .{ "catch", .Catch }, - .{ "const", .Const }, + .{ "final", .Final }, .{ "continue", .Continue }, .{ "do", .Do }, .{ "else", .Else }, diff --git a/src/buzz_api.zig b/src/buzz_api.zig index fdc34acc..f620f207 100644 --- a/src/buzz_api.zig +++ b/src/buzz_api.zig @@ -241,7 +241,7 @@ fn valueDump(value: Value, vm: *VM, seen: *std.AutoHashMap(*_obj.Obj, void), dep "{s}{s}{s}: {s}", .{ if (field.static) "static" else "", - if (field.constant) "const" else "", + if (field.final) "final" else "", field.name, field_type_str.items, }, diff --git a/src/disassembler.zig b/src/disassembler.zig index eae2fbf8..6f098d23 100644 --- a/src/disassembler.zig +++ b/src/disassembler.zig @@ -590,7 +590,7 @@ pub const DumpState = struct { " {s}{s}{s}: {s}", .{ if (kv.value_ptr.*.static) "static " else "", - if (kv.value_ptr.*.constant) "const " else "", + if (kv.value_ptr.*.final) "final " else "", kv.key_ptr.*, field_type_str.items, }, diff --git a/src/lib/buffer.buzz b/src/lib/buffer.buzz index ecd3a784..9ff95680 100644 --- a/src/lib/buffer.buzz +++ b/src/lib/buffer.buzz @@ -75,7 +75,7 @@ export object Buffer { } static fun fromStr(string: str) > Buffer { - const buffer = Buffer.init(); + final buffer = Buffer.init(); // We're sure we did not read this buffer before buffer.write(string) catch void; diff --git a/src/lib/http.buzz b/src/lib/http.buzz index d9a2e9c6..ca7a9259 100644 --- a/src/lib/http.buzz +++ b/src/lib/http.buzz @@ -76,7 +76,7 @@ extern fun HttpRequestRead(request: ud) > Response !> HttpError; /// @private extern fun HttpRequestDeinit(request: ud) > void; -const {int: str} reasons = { +final {int: str} reasons = { 100: "Continue", 101: "Switching Protocols", 102: "Processing", @@ -224,7 +224,7 @@ export object Request { if (this.request -> request) { HttpRequestWait(request); - const response = HttpRequestRead(request); + final response = HttpRequestRead(request); // - we don't need the request anymore // - also this allows to properly reuse the Request object diff --git a/src/lib/io.buzz b/src/lib/io.buzz index 59e5b956..8d04e486 100644 --- a/src/lib/io.buzz +++ b/src/lib/io.buzz @@ -86,11 +86,11 @@ export object File { } /// stdin -export const stdin = File{ fd = getStdIn() }; +export final stdin = File{ fd = getStdIn() }; /// stdout -export const stdout = File{ fd = getStdOut() }; +export final stdout = File{ fd = getStdOut() }; /// stderr -export const stderr = File{ fd = getStdErr() }; +export final stderr = File{ fd = getStdErr() }; /// Run a buzz file /// @param filename path to buzz file diff --git a/src/lib/math.buzz b/src/lib/math.buzz index 753a7d17..a4c0cd33 100644 --- a/src/lib/math.buzz +++ b/src/lib/math.buzz @@ -20,8 +20,8 @@ extern fun bzceil(n: double) > int; /// @return cos of n extern fun bzcos(n: double) > double; -/// π constant -const pi: double = 3.1415926535898; +/// π +final pi: double = 3.1415926535898; /// Convert radian to degree fun deg(n: double) > double { diff --git a/src/lib/serialize.buzz b/src/lib/serialize.buzz index a6f391ae..6b5de07a 100644 --- a/src/lib/serialize.buzz +++ b/src/lib/serialize.buzz @@ -154,7 +154,7 @@ object JsonParser { fun skipWhitespaces() > void { while (true) { - const char = this.peek(); + final char = this.peek(); if (char == " " or char == "\r" or char == "\t" or char == "\n") { _ = this.advance(); @@ -171,8 +171,8 @@ object JsonParser { throw JsonParseError{ message = "Could not parse JSON: end of string" }; } - const char = this.advance() ?? ""; - const byte = char.byte(0); + final char = this.advance() ?? ""; + final byte = char.byte(0); if (char == "[") { return this.array(); } else if (char == "\{") { @@ -230,7 +230,7 @@ object JsonParser { } this.consume("\""); - const key = this.string(); + final key = this.string(); this.skipWhitespaces(); @@ -324,7 +324,7 @@ export fun jsonEncode(data: Boxed) > str !> CircularReference, NotSerializable { return "{doubleing}"; } else if (data.map() -> map) { var json = "\{"; - const size = map.size(); + final size = map.size(); var count = 0; foreach (key, value in map) { json = json + "\"{key}\":{jsonEncode(value)}"; @@ -339,7 +339,7 @@ export fun jsonEncode(data: Boxed) > str !> CircularReference, NotSerializable { } else if (data.list() -> list) { var json = "["; - const len = list.len(); + final len = list.len(); foreach (i, value in list) { json = json + jsonEncode(value); diff --git a/src/lib/testing.buzz b/src/lib/testing.buzz index fffd7b59..877898d8 100644 --- a/src/lib/testing.buzz +++ b/src/lib/testing.buzz @@ -146,7 +146,7 @@ export object Tester { afterAll(this); } - const failed = this.failedTests(); + final failed = this.failedTests(); io\stdout.write("\n") catch void; diff --git a/src/obj.zig b/src/obj.zig index 4f82f608..25a40bde 100644 --- a/src/obj.zig +++ b/src/obj.zig @@ -1708,7 +1708,7 @@ pub const ObjObject = struct { pub const Field = struct { name: []const u8, type_def: *ObjTypeDef, - constant: bool, + final: bool, method: bool, static: bool, location: Token, @@ -1719,7 +1719,7 @@ pub const ObjObject = struct { pub fn eql(self: Field, other: Field) bool { return std.mem.eql(u8, self.name, other.name) and self.type_def.eql(other.type_def) and - self.constant == other.constant and + self.final == other.final and self.method == other.method and self.static == other.static and self.has_default == other.has_default; @@ -1805,7 +1805,7 @@ pub const ObjObject = struct { .{ .name = original_field.name, .type_def = original_field.type_def, - .constant = original_field.constant, + .final = original_field.final, .method = original_field.method, .static = original_field.static, .location = original_field.location, @@ -3529,7 +3529,7 @@ pub const ObjMap = struct { .{ .name = "key", .type_def = generic_key_type, - .constant = false, + .final = false, .method = false, .static = false, .has_default = false, @@ -3542,7 +3542,7 @@ pub const ObjMap = struct { .{ .name = "value", .type_def = generic_value_type, - .constant = false, + .final = false, .method = false, .static = false, .has_default = false, @@ -4197,7 +4197,7 @@ pub const ObjTypeDef = struct { kv.key_ptr.*, .{ .name = kv.value_ptr.*.name, - .constant = kv.value_ptr.*.constant, + .final = kv.value_ptr.*.final, .static = kv.value_ptr.*.static, .location = kv.value_ptr.*.location, .method = kv.value_ptr.*.method, diff --git a/src/vm.zig b/src/vm.zig index d3750f0a..d3870652 100644 --- a/src/vm.zig +++ b/src/vm.zig @@ -490,10 +490,7 @@ pub const VM = struct { .resolved_type = .{ .List = ObjList.ListDef.init( self.gc.allocator, - try self.gc.allocateObject( - ObjTypeDef, - ObjTypeDef{ .def_type = .String }, - ), + self.gc.type_registry.str_type, ), }, }, @@ -621,7 +618,7 @@ pub const VM = struct { } fn readPreviousInstruction(self: *Self) ?u32 { - const current_frame: *CallFrame = self.currentFrame().?; + const current_frame = self.currentFrame().?; if (current_frame.ip > 0) { return current_frame.closure.function.chunk.code.items[current_frame.ip - 1]; @@ -1012,7 +1009,7 @@ pub const VM = struct { const from = @as(u8, @intCast(arg)); const to = self.readByte(); - const temp: Value = (self.current_fiber.stack_top - to - 1)[0]; + const temp = (self.current_fiber.stack_top - to - 1)[0]; (self.current_fiber.stack_top - to - 1)[0] = (self.current_fiber.stack_top - from - 1)[0]; (self.current_fiber.stack_top - from - 1)[0] = temp; diff --git a/tests/001-basic-types.buzz b/tests/001-basic-types.buzz index 7ce0991e..e50fc115 100644 --- a/tests/001-basic-types.buzz +++ b/tests/001-basic-types.buzz @@ -1,40 +1,40 @@ import "std"; test "Basic types" { - const _: str = "hello world"; - const _: double = 3.14; - const _: int = 3; - const _: bool = true; + final _: str = "hello world"; + final _: double = 3.14; + final _: int = 3; + final _: bool = true; } test "Underscore on number literals" { - const a: int = 100_000; + final a: int = 100_000; std\assert(a == 100000, message: "Could use an underscore on an int"); - const b = 3.1_4; + final b = 3.1_4; std\assert(b == 3.14, message: "Could use an underscore on a double"); - const bin = 0b1_0001; + final bin = 0b1_0001; std\assert(bin == 17, message: "Clould use an underscore on a binary int"); - const h = 0xF_FFF; + final h = 0xF_FFF; std\assert(h == 65535, message: "Clould use an underscore on a hex int"); } test "Char literal" { - const char = 'A'; + final char = 'A'; std\assert(char == 65, message: "Could use char literal"); - const quote = '\''; + final quote = '\''; std\assert(quote == 39, message: "Could escape ' in char literal"); - const slash = '\\'; + final slash = '\\'; std\assert(slash == 92, message: "Could escape \\ in char literal"); } diff --git a/tests/002-operators.buzz b/tests/002-operators.buzz index ba8b58ff..4117002d 100644 --- a/tests/002-operators.buzz +++ b/tests/002-operators.buzz @@ -28,9 +28,9 @@ test "Unary operators (constant folded)" { } test "Unary operators" { - const a = 12; - const b = false; - const c = 15; + final a = 12; + final b = false; + final c = 15; std\assert(-a < 0, message: "negate operator"); std\assert(!b, message: "not operator"); diff --git a/tests/003-control-flow.buzz b/tests/003-control-flow.buzz index 13968663..be92b05a 100644 --- a/tests/003-control-flow.buzz +++ b/tests/003-control-flow.buzz @@ -54,7 +54,7 @@ test "do-until statement" { std\assert(i == 0, message: "do until"); } -const ahead = "wat"; +final ahead = "wat"; // object Ahead { // str name = "joe", diff --git a/tests/004-lists.buzz b/tests/004-lists.buzz index 5886bbd7..eda6be6a 100644 --- a/tests/004-lists.buzz +++ b/tests/004-lists.buzz @@ -1,18 +1,18 @@ import "std"; test "Lists" { - const list = [1, 2, 3, 4]; + final list = [1, 2, 3, 4]; std\assert(list.len() == 4, message: "len"); - const strList = ["hello", "world"]; + final strList = ["hello", "world"]; std\assert(strList[0] == "hello", message: "subscript"); // A lone list expression - const _ = ["hello", "world"]; - const _ = [["hello"], ["world"]]; + final _ = ["hello", "world"]; + final _ = [["hello"], ["world"]]; - const nestedList = [["hello"], ["world"]]; + final nestedList = [["hello"], ["world"]]; std\assert(nestedList[0][0] == "hello", message: "nested list"); @@ -22,7 +22,7 @@ test "Lists" { strList.append("dojo"); std\assert(strList[strList.len() - 1] == "dojo", message: "append to list"); - const removed = strList.remove(1); + final removed = strList.remove(1); std\assert(strList.len() == 2, message: "removed element form list"); std\assert(strList[0] == "hello" and strList[1] == "dojo", message: "item were properly shifted"); std\assert(removed == "yolo", message: "removed element has the correct value"); @@ -31,8 +31,8 @@ test "Lists" { } test "list.sub" { - const list = [1, 2, 3, 4]; - const sub = list.sub(1, len: 2); + final list = [1, 2, 3, 4]; + final sub = list.sub(1, len: 2); std\assert(sub.len() == 2 and sub[0] == 2 and sub[1] == 3, message: "list.sub"); } @@ -50,8 +50,8 @@ test "list concat" { } test "list.clone" { - const list = [1, 2, 3]; - const copy = list.clone(); + final list = [1, 2, 3]; + final copy = list.clone(); std\assert(list.len() == copy.len(), message: "Could clone list"); foreach (i, el in copy) { @@ -60,21 +60,21 @@ test "list.clone" { } test "empty list type inferring" { - const list = []; + final list = []; std\assert(typeof list == <[any]>); - const slist: [str] = []; + final slist: [str] = []; std\assert(typeof slist == <[str]>); } test "list.fill" { - const list = (0..3).toList().fill(42); + final list = (0..3).toList().fill(42); std\assert(list[0] == 42 and list[1] == 42 and list[2] == 42); - const another = (0..10).toList().fill(42, start: 2, len: 3); + final another = (0..10).toList().fill(42, start: 2, len: 3); std\assert(another[2] == 42 and another[3] == 42 and another[4] == 42 and another[1] != 42 and another[5] != 42); } diff --git a/tests/005-maps.buzz b/tests/005-maps.buzz index bef1ec9b..307d819d 100644 --- a/tests/005-maps.buzz +++ b/tests/005-maps.buzz @@ -1,12 +1,12 @@ import "std"; test "Maps" { - const map = { + final map = { "hello": 1, "bye": 2, }; - const _ = {1: true, 2: false}; + final _ = {1: true, 2: false}; std\assert(map["bye"] is int?, message: "yeah"); @@ -19,7 +19,7 @@ test "Maps" { } test "map merge" { - const map = {"one": 1, "two": 22} + {"three": 3, "two": 2}; + final map = {"one": 1, "two": 22} + {"three": 3, "two": 2}; std\assert(map["two"] == 2, message: "map merge"); std\assert(map.size() == 3, message: "map merge"); @@ -36,48 +36,48 @@ test "map.values" { } test "map.diff" { - const first = { + final first = { "one": 1, "two": 2, "three": 3, }; - const second = { + final second = { "two": 22, "three": 33, "four": 4, }; - const diff = first.diff(second); + final diff = first.diff(second); std\assert(diff.size() == 1 and diff["one"] != null, message: "Could use map.diff"); } test "map.intersect" { - const first = { + final first = { "one": 1, "two": 2, "five": 5, }; - const second = { + final second = { "two": 22, "three": 33, "four": 4, }; - const intersect = first.intersect(second); + final intersect = first.intersect(second); std\assert(intersect.size() == 1 and intersect["two"] != null, message: "Could use map.intersect"); } test "map.clone" { - const first = { + final first = { "one": 1, "two": 2, "five": 5, }; - const copy = first.clone(); + final copy = first.clone(); std\assert(copy.size() == first.size(), message: "Could clone map"); foreach (key, value in copy) { @@ -86,11 +86,11 @@ test "map.clone" { } test "empty map type inferring" { - const map = {}; + final map = {}; std\assert(typeof map == <{any: any}>); - const smap: {str: int} = {}; + final smap: {str: int} = {}; std\assert(typeof smap == <{str: int}>); } diff --git a/tests/006-enums.buzz b/tests/006-enums.buzz index 38b522de..d6a026c9 100644 --- a/tests/006-enums.buzz +++ b/tests/006-enums.buzz @@ -34,11 +34,11 @@ test "Enums" { std\assert(NaturalEnum.zero.value == 0, message: "natural enum"); - const myCase = NaturalEnum.two; + final myCase = NaturalEnum.two; std\assert(myCase.value == 2, message: "enum instance"); - const fromValue = NaturalEnum(0); + final fromValue = NaturalEnum(0); std\assert(fromValue != null, message: "Could get enum instance from value"); std\assert(fromValue?.value == 0, message: "Could get correct enum instance from value"); } diff --git a/tests/007-objects.buzz b/tests/007-objects.buzz index 1063579b..457b23a4 100644 --- a/tests/007-objects.buzz +++ b/tests/007-objects.buzz @@ -11,7 +11,7 @@ object First { } test "Objects" { - const first = First { + final first = First { name = "John", }; @@ -38,7 +38,7 @@ object Second { } test "Object with static fields" { - const second = Second.init(); + final second = Second.init(); std\assert(second.id == Second.nextId, message: "could use static fields"); } diff --git a/tests/009-gc.buzz b/tests/009-gc.buzz index 2bce546c..42b2c44d 100644 --- a/tests/009-gc.buzz +++ b/tests/009-gc.buzz @@ -13,14 +13,14 @@ object Kill { test "GC, collecting unreferenced objects" { var i = 0; - const _ = Kill{}; // Should be kept longer + final _ = Kill{}; // Should be kept longer while (i < 1000) { - const _ = Kill{ yo = i }; // Should be collected since not referenced anywhere + final _ = Kill{ yo = i }; // Should be collected since not referenced anywhere i = i + 1; } - const before = gc\allocated(); + final before = gc\allocated(); gc\collect(); diff --git a/tests/011-list-map-properties.buzz b/tests/011-list-map-properties.buzz index 8dc3c369..8cdd313b 100644 --- a/tests/011-list-map-properties.buzz +++ b/tests/011-list-map-properties.buzz @@ -6,7 +6,7 @@ object Hey { } test "List and Map as Object properties" { - const hey = Hey{ + final hey = Hey{ ages = [, 1, 2, 3], names = { , diff --git a/tests/012-lambda.buzz b/tests/012-lambda.buzz index 2caa6feb..c6184246 100644 --- a/tests/012-lambda.buzz +++ b/tests/012-lambda.buzz @@ -1,7 +1,7 @@ import "std"; test "Lambda/Anonymous functions" { - const mul: fun (n: int) > int = fun (n: int) > int => n * 2; + final mul: fun (n: int) > int = fun (n: int) > int => n * 2; std\assert(mul(1) == 2, message: "called a lambda function"); } diff --git a/tests/013-import-export.buzz b/tests/013-import-export.buzz index 9bd1a643..49794308 100644 --- a/tests/013-import-export.buzz +++ b/tests/013-import-export.buzz @@ -1,9 +1,9 @@ import "tests/utils/testing" as testing; -const mine = 42; +final mine = 42; test "Using a function coming from an import" { - const me = testing\PrefixMe{}; + final me = testing\PrefixMe{}; testing\assert(me.name == "Joe", message: "prefixed global works as type"); testing\assert(testing\hey("world") == mine, message: "unexported symbol is reachable"); testing\assert(true, message: "yeah!"); diff --git a/tests/015-interpolation.buzz b/tests/015-interpolation.buzz index 0c0e8e68..c9037d39 100644 --- a/tests/015-interpolation.buzz +++ b/tests/015-interpolation.buzz @@ -5,8 +5,8 @@ test "Escape sequences" { } test "String interpolation" { - const name = "joe"; - const age = 12; + final name = "joe"; + final age = 12; std\assert( "{"$"} hello {name} i'm {age} years old {3+4}" diff --git a/tests/016-optionals.buzz b/tests/016-optionals.buzz index e4bd0911..386bfa11 100644 --- a/tests/016-optionals.buzz +++ b/tests/016-optionals.buzz @@ -4,13 +4,13 @@ test "Optional force unwrapping with `!`" { // Note: trying to force unwrap a null value raises an uncatchable error // Dart allows to catch an null unwrap but swift doesn't // I think it's saner for it to not be catchable but to provides safe way to unwrap it - const hello: str? = "hello world"; + final hello: str? = "hello world"; std\assert(hello! == "hello world", message: "Could force unwrap an optional"); } test "Optional graceful unwrapping with `?`" { - const optList: [int]? = [1, 2, 3]; + final optList: [int]? = [1, 2, 3]; std\assert(optList?.len() == 3, message: "could unwrap optList"); } @@ -20,25 +20,25 @@ object Me { } test "Optional chaining" { - const me: Me? = Me{ + final me: Me? = Me{ list = [1, 2, 3], }; std\assert(me?.list?.len() == 3, message: "chaining optionals work"); - const you: Me? = null; + final you: Me? = null; std\assert(you?.list?.len() == null, message: "chaining optionals work"); } test "Null coalescing operator" { - const hello: str? = null; + final hello: str? = null; std\assert(hello ?? "world" == "world", message: "null coalescing"); } test "Unwrap map subscript" { - const map = { + final map = { "yo": "lo", "mo": "jo", }; @@ -51,7 +51,7 @@ object You { } test "Field access on map subscript" { - const map = { + final map = { "yo": You{} }; diff --git a/tests/018-foreach.buzz b/tests/018-foreach.buzz index c33b2445..f01410fe 100644 --- a/tests/018-foreach.buzz +++ b/tests/018-foreach.buzz @@ -1,7 +1,7 @@ import "std"; test "foreach on list" { - const list = [1, 2, 3]; + final list = [1, 2, 3]; var sum = 0; foreach (item in list) { @@ -12,14 +12,14 @@ test "foreach on list" { } test "list.next" { - const list = [1, 2, 3]; + final list = [1, 2, 3]; std\assert(list.next(null) == 0, message: "calling next native"); std\assert(list.next(0) == 1, message: "calling next native"); } test "foreach on map" { - const map = { + final map = { "one": 1, "two": 2, "three": 3 diff --git a/tests/021-upvalues.buzz b/tests/021-upvalues.buzz index 3f031cc0..04b480ee 100644 --- a/tests/021-upvalues.buzz +++ b/tests/021-upvalues.buzz @@ -1,8 +1,8 @@ import "std"; fun upvals() > fun () { - const upvalue = 12; - const up = "up"; + final upvalue = 12; + final up = "up"; return fun () > void => std\print("{upvalue} {up}"); } diff --git a/tests/025-fs.buzz b/tests/025-fs.buzz index 3af8da63..91ee8916 100644 --- a/tests/025-fs.buzz +++ b/tests/025-fs.buzz @@ -23,7 +23,7 @@ test "ls" { } } - const anotherRandomLocal = "bye there!"; + final anotherRandomLocal = "bye there!"; std\assert(anotherRandomLocal == "bye there!", message: "foreach break is wrong"); diff --git a/tests/030-str.buzz b/tests/030-str.buzz index 25ca7f2f..2b13b04b 100644 --- a/tests/030-str.buzz +++ b/tests/030-str.buzz @@ -18,7 +18,7 @@ test "str.indexOf" { } test "str.split" { - const splits = "one,two,three".split(","); + final splits = "one,two,three".split(","); std\assert(splits[0] == "one" and splits[1] == "two" and splits[2] == "three", message: "str.split"); } diff --git a/tests/031-json.buzz b/tests/031-json.buzz index 1cc420fc..20682b75 100644 --- a/tests/031-json.buzz +++ b/tests/031-json.buzz @@ -2,7 +2,7 @@ import "std"; import "serialize"; test "Json.encode" { - const data = { + final data = { "hello": "world", "bye": 42, }; @@ -21,7 +21,7 @@ test "Json.decode" { } test "Boxed.q" { - const data = { + final data = { "submap": { , "subsubmap": { diff --git a/tests/032-debug.buzz b/tests/032-debug.buzz index 21e36510..29a7f9ce 100644 --- a/tests/032-debug.buzz +++ b/tests/032-debug.buzz @@ -45,14 +45,14 @@ object MyObject { } test "dump" { - const list = [1, 2, 3, 4]; - const map = { + final list = [1, 2, 3, 4]; + final map = { "one": 1, "two": 2, "three": 3, }; - const instance = MyObject{ + final instance = MyObject{ name = "joe", age = 35, data = Data{ diff --git a/tests/033-invoke.buzz b/tests/033-invoke.buzz index 74eee434..a4b41d13 100644 --- a/tests/033-invoke.buzz +++ b/tests/033-invoke.buzz @@ -10,7 +10,7 @@ object A { } test "Chained invoke" { - const a = A{ + final a = A{ list = [ A{ list = [ A{ list = [] } ] diff --git a/tests/034-scope.buzz b/tests/034-scope.buzz index dd9c85f8..20652841 100644 --- a/tests/034-scope.buzz +++ b/tests/034-scope.buzz @@ -1,15 +1,15 @@ import "std"; test "locals inside a foreach" { - const hello = ""; + final hello = ""; foreach (_ in "hello world") { - const new = "yo"; - const old = "lo"; + final new = "yo"; + final old = "lo"; foreach (_ in "goodbye world") { - const newnew = "yoyo"; - const oldold = "lolo"; + final newnew = "yoyo"; + final oldold = "lolo"; std\assert(new == "yo", message: "locals are ok"); std\assert(old == "lo", message: "locals are ok"); @@ -21,8 +21,8 @@ test "locals inside a foreach" { } for (i: int = 0; i < 3; i = i + 1) { - const new = "yo"; - const old = "lo"; + final new = "yo"; + final old = "lo"; std\assert(new == "yo", message: "locals are ok"); std\assert(old == "lo", message: "locals are ok"); diff --git a/tests/035-const-expr.buzz b/tests/035-const-expr.buzz index 5d2d78b5..aea2a92f 100644 --- a/tests/035-const-expr.buzz +++ b/tests/035-const-expr.buzz @@ -19,8 +19,8 @@ test "Constant expression" { hello(); hello(); - const a = A{}; - const b = A{}; + final a = A{}; + final b = A{}; std\assert(a.list != b.list, message: "object default value were cloned"); std\assert(a.map != b.map, message: "object default value were cloned"); diff --git a/tests/036-pattern.buzz b/tests/036-pattern.buzz index 9484c193..505952c7 100644 --- a/tests/036-pattern.buzz +++ b/tests/036-pattern.buzz @@ -1,9 +1,9 @@ import "std"; test "pattern.match" { - const pattern = $"hello ([a-z]+)"; + final pattern = $"hello ([a-z]+)"; - const results = pattern.match("All i want to say is hello joe! hello mundo!"); + final results = pattern.match("All i want to say is hello joe! hello mundo!"); std\assert(results?.len() == 2, message: "1 match and 1 capture"); std\assert(results![0] == "hello joe", message: "first is match"); @@ -11,9 +11,9 @@ test "pattern.match" { } test "pattern.matchAll" { - const pattern = $"hello ([a-z]+)"; + final pattern = $"hello ([a-z]+)"; - const results = pattern.matchAll("All i want to say is hello joe!\nhello mundo!\nAnd hello neighbor..."); + final results = pattern.matchAll("All i want to say is hello joe!\nhello mundo!\nAnd hello neighbor..."); std\assert(results?.len() == 3, message: "found 3 matches"); std\assert(results![2].len() == 2, message: "1 match and 1 capture"); @@ -21,7 +21,7 @@ test "pattern.matchAll" { } test "Escaped pattern delimiter" { - const pattern = $"hello \" world"; + final pattern = $"hello \" world"; std\assert("{pattern}" == "hello \" world", message: "delimiter was properly escaped"); } diff --git a/tests/038-fibers.buzz b/tests/038-fibers.buzz index 3550dd2f..cc74228b 100644 --- a/tests/038-fibers.buzz +++ b/tests/038-fibers.buzz @@ -2,7 +2,7 @@ import "std"; test "fiber" { // Async call, creates a new fiber, yield type must be nullable because resume will return null when nothing yielded - const counter = &count(10); + final counter = &count(10); // A fiber is over when a OP_RETURN as been executed var sum = 0; @@ -42,7 +42,7 @@ fun fail() > bool !> str { } fun caughFiberFail() > bool !> str { - const fiber = &fail(); + final fiber = &fail(); return resolve fiber; } @@ -52,15 +52,15 @@ test "Throw inside a fiber" { } fun closedUpvalue() > fun () > str { - const upvalue = "joe"; + final upvalue = "joe"; return fun () > str => "hello {upvalue}"; } test "Opened upvalue in fiber" { - const upvalue = "world"; + final upvalue = "world"; - const fiberFn = fun () > str => "hello {upvalue}"; + final fiberFn = fun () > str => "hello {upvalue}"; std\assert(resolve &fiberFn() == "hello world", message: "Fiber could use an opened upvalue"); } @@ -70,7 +70,7 @@ test "Closed upvalue in fiber" { } test "Wrapping call inside complex expressions" { - const map = { + final map = { "hello": fun () > str => "hello world", }; diff --git a/tests/039-buffer.buzz b/tests/039-buffer.buzz index 0119a0b3..b053243c 100644 --- a/tests/039-buffer.buzz +++ b/tests/039-buffer.buzz @@ -9,7 +9,7 @@ test "Reading and writing in a buffer" { buffer.writeDouble(1238.324); buffer.writeBoolean(true); - const expected = [ + final expected = [ 11, 0, 0, 0, // "hello world".len() 104, 101, 108, 108, 111, 32, 119, 111, 114, 108, 100, // "hello world" 158, 239, 167, 198, 75, 89, 147, 64, // 1238.324 @@ -21,7 +21,7 @@ test "Reading and writing in a buffer" { std\assert(buffer.len() == expected.len(), message: "wrote expected number of bytes"); - const len = buffer.readInt() ?? -1; + final len = buffer.readInt() ?? -1; std\assert(len == 11, message: "could read number"); std\assert(buffer.read(len) == "hello world", message: "could read n bytes"); diff --git a/tests/041-iterator.buzz b/tests/041-iterator.buzz index ea20072d..bb2013a8 100644 --- a/tests/041-iterator.buzz +++ b/tests/041-iterator.buzz @@ -14,7 +14,7 @@ fun fibonacci(n: int) > void *> int? { } test "finobacci generator" { - const suite = [0, 1, 1, 2, 3, 5, 8, 13, 21, 34]; + final suite = [0, 1, 1, 2, 3, 5, 8, 13, 21, 34]; var i = 0; foreach (n in &fibonacci(10)) { std\assert(suite[i] == n, message: "could iterate over fiber"); diff --git a/tests/042-anonymous-objects.buzz b/tests/042-anonymous-objects.buzz index ceb17c68..32f00330 100644 --- a/tests/042-anonymous-objects.buzz +++ b/tests/042-anonymous-objects.buzz @@ -8,7 +8,7 @@ fun getInfo() > obj{ name: str, age: int } { } test "Anonymous objects" { - const info = getInfo(); + final info = getInfo(); // Two anonymous type matches _: obj{ name: str, age: int } = info; @@ -17,10 +17,10 @@ test "Anonymous objects" { } test "Named variable init" { - const name = "Joe"; - const age = 42; + final name = "Joe"; + final age = 42; - const person = .{ name, age }; + final person = .{ name, age }; std\assert(person.name == "Joe" and person.age == 42); } @@ -32,7 +32,7 @@ fun getPayload::(data: T) > obj{ data: T } { } test "Anonymous object with generics" { - const payload = getPayload::(42); + final payload = getPayload::(42); std\assert(payload.data == 42, message: "Could use anonymous object with generic"); } diff --git a/tests/044-break-continue.buzz b/tests/044-break-continue.buzz index dd18d329..beccc0f7 100644 --- a/tests/044-break-continue.buzz +++ b/tests/044-break-continue.buzz @@ -10,7 +10,7 @@ test "continue properly jumps and closes scope" { } } - const anotherRandomLocal = "bye there"; + final anotherRandomLocal = "bye there"; std\assert(anotherRandomLocal == "bye there", message: "continue properly closed revelant scopes"); } @@ -26,7 +26,7 @@ test "break properly jumps and closes scope" { _ = "after break"; } - const anotherRandomLocal = "bye there"; + final anotherRandomLocal = "bye there"; std\assert(anotherRandomLocal == "bye there", message: "break properly closed revelant scopes"); } diff --git a/tests/046-try-catch.buzz b/tests/046-try-catch.buzz index d85683c1..fe6b3fe6 100644 --- a/tests/046-try-catch.buzz +++ b/tests/046-try-catch.buzz @@ -49,7 +49,7 @@ test "Try catch" { std\assert(false, message: "unreachable"); } - const afterLocal = "bye"; + final afterLocal = "bye"; std\assert(setme == "yes", message: "error was handled and code continues"); diff --git a/tests/047-if-arrow.buzz b/tests/047-if-arrow.buzz index 1169b84f..73dc6e2e 100644 --- a/tests/047-if-arrow.buzz +++ b/tests/047-if-arrow.buzz @@ -1,8 +1,8 @@ import "std"; test "If arrow" { - const opt: int? = null; - const optS: str? = "hello"; + final opt: int? = null; + final optS: str? = "hello"; if (opt -> _) { std\assert(false, message: "unreachable"); diff --git a/tests/048-generics.buzz b/tests/048-generics.buzz index aeb28f9f..f028343e 100644 --- a/tests/048-generics.buzz +++ b/tests/048-generics.buzz @@ -13,7 +13,7 @@ fun extractList::(data: obj{ list: [T] }) > [T] { } test "Generic within anonymous object" { - const list = [1, 2, 3]; + final list = [1, 2, 3]; std\assert(extractList::(.{ list = list }) == list, message: "could use generic within anonymous object"); } @@ -23,7 +23,7 @@ fun countMap::(map: {K: V}) > int { } test "Multiple generic types" { - const map = { + final map = { "one": 1, "two": 2, "three": 3, @@ -37,7 +37,7 @@ fun extractMap::(data: obj{ map: {K: V} }) > {K: V} { } test "Generic within anonymous object and map" { - const map = { + final map = { "one": 1, "two": 2, "three": 3, @@ -51,8 +51,8 @@ fun countShuffleGenerics::() > fun (a: [A], b: [B]) > int { } test "Generic in lambda function definition" { - const a = ["one", "two", "three"]; - const b = [1, 2, 3]; + final a = ["one", "two", "three"]; + final b = [1, 2, 3]; std\assert(countShuffleGenerics::()(a, b: b) == 6, message: "could use generic in lambda function definition"); } @@ -72,7 +72,7 @@ fun fiber::(data: [T]) > void *> T? { } test "Generic with fibers" { - const f = &fiber::([1, 2, 3]); + final f = &fiber::([1, 2, 3]); var sum = 0; while (!f.over()) { diff --git a/tests/049-multiline-strings.buzz b/tests/049-multiline-strings.buzz index 355355f5..e5a12608 100644 --- a/tests/049-multiline-strings.buzz +++ b/tests/049-multiline-strings.buzz @@ -2,7 +2,7 @@ import "std"; import "serialize"; test "Multiline strings" { - const multi = `\{ + final multi = `\{ "some": "json", "yes": {3 + 12}, {` @@ -10,7 +10,7 @@ test "Multiline strings" { `} }`; - const json = serialize\jsonDecode(multi); + final json = serialize\jsonDecode(multi); std\assert(json.q(["yes"]).integer() == 15, message: "multiline string is valid"); std\assert(json.q(["another"]).string() == "one", message: "multiline string is valid"); diff --git a/tests/050-protocols.buzz b/tests/050-protocols.buzz index d5304f2b..9adfbb91 100644 --- a/tests/050-protocols.buzz +++ b/tests/050-protocols.buzz @@ -34,17 +34,17 @@ object(Nameable) Pet { } test "Protocols" { - const joe = Person{ + final joe = Person{ name = "Joe", age = 25, }; - const bob = Person{ + final bob = Person{ name = "Bob", age = 56, }; - const bandit = Pet{ + final bandit = Pet{ name = "bandit", }; @@ -53,8 +53,8 @@ test "Protocols" { var nameable: Nameable = bandit; nameable = joe; - const nameables: [Nameable] = [bandit, joe]; - const newNames = ["Chili", "Nick"]; + final nameables: [Nameable] = [bandit, joe]; + final newNames = ["Chili", "Nick"]; foreach (i, item in nameables) { item.rename(newNames[i]); } @@ -62,14 +62,14 @@ test "Protocols" { std\assert(bandit.name == "Chili", message: "could call protocol method"); std\assert(joe.name == "Nick", message: "could call protocol method"); - const map: {Nameable: bool} = { + final map: {Nameable: bool} = { bandit: true, joe: false, }; std\assert(map[joe] == false, message: "could hold protocol as map key"); - const mapValue: {str: Nameable} = { + final mapValue: {str: Nameable} = { "bandit": bandit, "joe": joe, }; diff --git a/tests/051-functional.buzz b/tests/051-functional.buzz index 6105bc01..fe1d4b54 100644 --- a/tests/051-functional.buzz +++ b/tests/051-functional.buzz @@ -1,7 +1,7 @@ import "std"; test "list.forEach" { - const data = [1, 2, 3, 4]; + final data = [1, 2, 3, 4]; var sum = 0; data.forEach(fun (_: int, element: int) > void { @@ -12,23 +12,23 @@ test "list.forEach" { } test "list.map" { - const data = [1, 2, 3, 4]; + final data = [1, 2, 3, 4]; - const mapped = data.map::(fun (_: int, element: int) => "{element}"); + final mapped = data.map::(fun (_: int, element: int) => "{element}"); std\assert(mapped.join(", ") == "1, 2, 3, 4", message: "could use map"); } test "list.filter" { - const data = [1, 2, 3, 4]; + final data = [1, 2, 3, 4]; - const odd = data.filter(fun (_: int, element: int) => element % 2 != 0); + final odd = data.filter(fun (_: int, element: int) => element % 2 != 0); std\assert(odd.join(", ") == "1, 3", message: "could use filter"); } test "list.reduce" { - const data = [1, 2, 3, 4]; + final data = [1, 2, 3, 4]; var sum = data.reduce::( fun (_: int, element: int, accumulator: int) => accumulator + element, @@ -39,7 +39,7 @@ test "list.reduce" { } test "list.sort" { - const data = [10, 3, 12, 0, 1, -3]; + final data = [10, 3, 12, 0, 1, -3]; _ = data.sort(fun (left: int, right: int) => left < right); @@ -49,7 +49,7 @@ test "list.sort" { } test "map.forEach" { - const map = { + final map = { "five": 5, "two": 2, "one": 1, @@ -65,14 +65,14 @@ test "map.forEach" { } test "map.map" { - const map = { + final map = { "five": 5, "two": 2, "one": 1, "three": 3, }; - const inverted = map.map::( + final inverted = map.map::( fun (key: str, value: int) => .{ key = value, value = key }, ); @@ -82,14 +82,14 @@ test "map.map" { } test "map.filter" { - const map = { + final map = { "five": 5, "two": 2, "one": 1, "three": 3, }; - const filtered = map.filter( + final filtered = map.filter( fun (_: str, value: int) => value % 2 != 0 ); @@ -97,7 +97,7 @@ test "map.filter" { } test "map.reduce" { - const map = { + final map = { "five": 5, "two": 2, "one": 1, @@ -113,7 +113,7 @@ test "map.reduce" { } test "map.sort" { - const map = { + final map = { "five": 5, "two": 2, "one": 1, @@ -125,7 +125,7 @@ test "map.sort" { fun (lhs: str, rhs: str) => map[lhs]! < map[rhs]! ); - const ordered = [ "one", "two", "three", "five" ]; + final ordered = [ "one", "two", "three", "five" ]; var i = 0; foreach (key in map.keys()) { std\assert(ordered[i] == key, message: "Could sort map"); diff --git a/tests/052-inline-if.buzz b/tests/052-inline-if.buzz index 98f30dbe..6450eb86 100644 --- a/tests/052-inline-if.buzz +++ b/tests/052-inline-if.buzz @@ -11,9 +11,9 @@ test "ternary" { } test "multiple branches" { - const value = 12; + final value = 12; - const expr = if (value == 14) + final expr = if (value == 14) "hello" else if (value == 12) "yolo" @@ -24,7 +24,7 @@ test "multiple branches" { } test "inline if in expression" { - const value = 12; + final value = 12; std\assert( (if (value == 14) diff --git a/tests/053-range.buzz b/tests/053-range.buzz index 10211b1e..a00fb030 100644 --- a/tests/053-range.buzz +++ b/tests/053-range.buzz @@ -1,14 +1,14 @@ import "std"; test "Range" { - const limit = 10; - const range = 0..limit; + final limit = 10; + final range = 0..limit; std\assert(range == 0..10, message: "Could compare ranges"); std\assert(range.low() == 0, message: "Could get low limit of range"); std\assert(range.high() == 10, message: "Could get high limit of range"); - const list = range.toList(); + final list = range.toList(); std\assert(list.len() == 10, message: "Could create list from range"); var sum = 0; @@ -21,14 +21,14 @@ test "Range" { } test "Inverted range" { - const limit = 0; - const range = 10..limit; + final limit = 0; + final range = 10..limit; std\assert((0..10).invert() == range, message: "Could invert range"); std\assert(range.low() == 10, message: "Could get low limit of range"); std\assert(range.high() == 0, message: "Could get high limit of range"); - const list = range.toList(); + final list = range.toList(); std\assert(list.len() == 10, message: "Could create list from inverted range"); var sum = 0; diff --git a/tests/057-any.buzz b/tests/057-any.buzz index 9ba32683..26e3611e 100644 --- a/tests/057-any.buzz +++ b/tests/057-any.buzz @@ -1,7 +1,7 @@ import "std"; test "any" { - const anything: any = "hello"; + final anything: any = "hello"; std\assert(anything is str, message: "can manipulate any typed value"); @@ -18,10 +18,10 @@ test "any placeholder" { } } -const placeholder: any = "hello"; +final placeholder: any = "hello"; test "as?" { - const anything: any = 12; + final anything: any = 12; std\assert((anything as? int) == 12, message: "as?"); @@ -29,7 +29,7 @@ test "as?" { } test "list of any" { - const list = [ 1, true, 12.4, "hello" ]; + final list = [ 1, true, 12.4, "hello" ]; foreach (element in list) { std\print("{element}"); @@ -37,7 +37,7 @@ test "list of any" { } test "map of any" { - const map: {str: any} = { + final map: {str: any} = { "hello": true, "world": "one", }; @@ -46,7 +46,7 @@ test "map of any" { std\print("{key}: {element}"); } - const map2: {any: str} = { + final map2: {any: str} = { "hello": "true", true: "one", }; @@ -55,7 +55,7 @@ test "map of any" { std\print("{key}: {element}"); } - const map3: {any: any} = { + final map3: {any: any} = { "hello": 1, true: "one", }; diff --git a/tests/058-ffi.buzz b/tests/058-ffi.buzz index dcf5949a..a7e6a757 100644 --- a/tests/058-ffi.buzz +++ b/tests/058-ffi.buzz @@ -32,10 +32,10 @@ test "pointer with Buffer" { std\assert(true, message: "Using bad buzz type triggers error"); } - const i32align = ffi\alignOf("i32"); - const len = buffer.len(align: i32align); + final i32align = ffi\alignOf("i32"); + final len = buffer.len(align: i32align); std\assert(len == buffer.len() / 4, message: "Len align"); - const total = sum(buffer.ptr(), len: len); + final total = sum(buffer.ptr(), len: len); std\assert(total == 12, message: "Could call FFI function with pointer argument"); @@ -49,7 +49,7 @@ test "pointer with Buffer" { std\assert(readTotal == total, message: "Could read from pointer"); - const subTotal = sum(buffer.ptr(1, align: i32align), len: len - 1); + final subTotal = sum(buffer.ptr(1, align: i32align), len: len - 1); std\assert(subTotal == 11, message: "Could get ptr at offset"); } @@ -66,7 +66,7 @@ zdef("tests/utils/libforeign", ` `); test "struct" { - const data = Data{ + final data = Data{ msg = ffi\cstr("bye world"), id = 123, value = 42.0, @@ -87,7 +87,7 @@ test "struct" { } test "write/read struct in buffer" { - const data = Data{ + final data = Data{ msg = ffi\cstr("bye world"), id = 123, value = 42.0, @@ -99,7 +99,7 @@ test "write/read struct in buffer" { std\assert(buffer.toString().len() == ffi\sizeOfStruct(Data), message: "Could write struct to buffer"); - const read = buffer.readStruct::(Data); + final read = buffer.readStruct::(Data); std\assert( read.msg == data.msg and read.id == data.id, @@ -125,7 +125,7 @@ zdef("tests/utils/libforeign", ` `); test "union" { - const misc = Misc{ + final misc = Misc{ data = Data{ id = 123, msg = ffi\cstr("hello world"), diff --git a/tests/059-types-as-value.buzz b/tests/059-types-as-value.buzz index 5cca19f6..1b134b84 100644 --- a/tests/059-types-as-value.buzz +++ b/tests/059-types-as-value.buzz @@ -13,9 +13,9 @@ fun dumpType(myType: type) > void { protocol C {} test "Types as value" { - const _ = ; - const another = ; - const again = ; + final _ = ; + final another = ; + final again = ; std\assert(another == again, message: "Can compare type values"); } diff --git a/tests/060-free-identifiers.buzz b/tests/060-free-identifiers.buzz index 339e0142..961111b1 100644 --- a/tests/060-free-identifiers.buzz +++ b/tests/060-free-identifiers.buzz @@ -1,7 +1,7 @@ import "std"; test "Free identifiers" { - const @"non-standard-identifier" = "hello world"; + final @"non-standard-identifier" = "hello world"; std\assert(@"non-standard-identifier" == "hello world", message: "Could use non-standard identifiers"); } @@ -11,7 +11,7 @@ object A { } test "Free identifier as object field" { - const a = A{ + final a = A{ @"type" = "Hello", }; diff --git a/tests/061-utf8.buzz b/tests/061-utf8.buzz index 485596f6..d67ec91c 100644 --- a/tests/061-utf8.buzz +++ b/tests/061-utf8.buzz @@ -1,15 +1,15 @@ import "std"; test "utf8" { - const msg = "hello 🔥 buzz !"; + final msg = "hello 🔥 buzz !"; std\assert(msg.utf8Len() == 14, message: "Could get length of utf8 string"); std\assert(msg.utf8Valid(), message: "Could validate utf8 string"); - const invalid = "hello \232 world!"; + final invalid = "hello \232 world!"; std\assert(!invalid.utf8Valid(), message: "Could not validate invalid utf8 string"); - const codepoints = "I'm 🦇-man so 🔥 !".utf8Codepoints(); + final codepoints = "I'm 🦇-man so 🔥 !".utf8Codepoints(); std\assert(codepoints[4] == "🦇", message: "Could get utf8 string codepoints"); } diff --git a/tests/063-nullable-default.buzz b/tests/063-nullable-default.buzz index d53051d0..b3224b2e 100644 --- a/tests/063-nullable-default.buzz +++ b/tests/063-nullable-default.buzz @@ -6,7 +6,7 @@ object Person { } test "Nullable object field has a default value at null" { - const person = Person{ + final person = Person{ name = "Joe" }; diff --git a/tests/065-inferred-var-type.buzz b/tests/065-inferred-var-type.buzz index 40e720c5..862b210e 100644 --- a/tests/065-inferred-var-type.buzz +++ b/tests/065-inferred-var-type.buzz @@ -5,7 +5,7 @@ object Person { } var integer = 42; -const doubleing = 42.42; +final doubleing = 42.42; test "Inferring variable declaration type" { std\assert(integer is int, message: "Could infer global variable declaration type"); @@ -15,7 +15,7 @@ test "Inferring variable declaration type" { std\assert(string is str, message: "Could infer variable declaration type"); - const person = Person{}; + final person = Person{}; std\assert(person is Person, message: "Could infer constant declaration type"); } diff --git a/tests/068-testing.buzz b/tests/068-testing.buzz index f8e5d166..855ca6ea 100644 --- a/tests/068-testing.buzz +++ b/tests/068-testing.buzz @@ -1,7 +1,7 @@ import "testing" as _; test "Test std lib" { - const t = Tester.init( + final t = Tester.init( beforeAll: fun (t: Tester) { t.assert(true); }, diff --git a/tests/071-tail-call.buzz b/tests/071-tail-call.buzz index 3a652aba..b856d9be 100644 --- a/tests/071-tail-call.buzz +++ b/tests/071-tail-call.buzz @@ -38,7 +38,7 @@ object Tail { } test "dot tail call" { - const result = Tail{ + final result = Tail{ a = 5, b = 2, }.tail(3); diff --git a/tests/073-tuples.buzz b/tests/073-tuples.buzz index b943ddf7..eef8c021 100644 --- a/tests/073-tuples.buzz +++ b/tests/073-tuples.buzz @@ -9,19 +9,19 @@ fun pack(names: [str]) > obj{ :str, :str, :str } { } test "Tuples" { - const tuple = .{ "joe", "doe" }; + final tuple = .{ "joe", "doe" }; std\assert(tuple.@"0" == "joe" and tuple.@"1" == "doe"); - const name = "Joe"; - const age = 42; + final name = "Joe"; + final age = 42; // Forced tuple - const another = .{ (name), (age) }; + final another = .{ (name), (age) }; std\assert(another.@"0" == "Joe" and another.@"1" == 42); - const names = pack(["Joe", "John", "James"]); + final names = pack(["Joe", "John", "James"]); std\assert(names.@"0" == "Joe" and names.@"1" == "John"); } diff --git a/tests/bench/003-nbody.buzz b/tests/bench/003-nbody.buzz index 9c23b980..6492e37e 100644 --- a/tests/bench/003-nbody.buzz +++ b/tests/bench/003-nbody.buzz @@ -1,9 +1,9 @@ import "std"; import "math"; -const double pi = 3.141592653589793; -const double solarMass = 4.0 * pi * pi; -const double daysPerYear = 365.24; +final double pi = 3.141592653589793; +final double solarMass = 4.0 * pi * pi; +final double daysPerYear = 365.24; object Body { double x, diff --git a/tests/bench/005-k-nucleoide.buzz b/tests/bench/005-k-nucleoide.buzz index 624b6e9d..55e7c27d 100644 --- a/tests/bench/005-k-nucleoide.buzz +++ b/tests/bench/005-k-nucleoide.buzz @@ -31,7 +31,7 @@ fun kfrequency(str sequence, {str: int} frequency, int k, int frame) > void { } fun count(str sequence, str fragment) > void { - const int k = fragment.len(); + final int k = fragment.len(); {str: int} frequency = {}; for (int frame = 0; frame < k; frame = frame + 1) { kfrequency(sequence, frequency: frequency, k: k, frame: frame); diff --git a/tests/bench/006-fasta.buzz b/tests/bench/006-fasta.buzz index 16dafb1c..fd984011 100644 --- a/tests/bench/006-fasta.buzz +++ b/tests/bench/006-fasta.buzz @@ -2,11 +2,11 @@ import "std"; import "math"; import "buffer" as _; -const double IM = 139968.0; -const double IA = 3877.0; -const double IC = 29573.0; -const int lineLength = 60; -const int bufferSize = (lineLength + 1) * 1024; +final double IM = 139968.0; +final double IA = 3877.0; +final double IC = 29573.0; +final int lineLength = 60; +final int bufferSize = (lineLength + 1) * 1024; fun makeRepeatFasta(str id, str desc, str s, int nchars) > void { std\print(">{id} {desc}"); @@ -57,7 +57,7 @@ object Frequency { } fun selectRandomIntoBuffer(Buffer buffer, int initialBufferIndex, int nRandom) > int !> OutOfBoundError, WriteWhileReadingError { - const int len = this.probs.len(); + final int len = this.probs.len(); var bufferIndex = initialBufferIndex; for (int rIndex = 0; rIndex < nRandom; rIndex = rIndex + 1) { @@ -107,7 +107,7 @@ fun makeRandomFasta(str id, str desc, Frequency fpf, int initialNchars) > void ! std\print(buffer\toString().sub(0, len: bufferIndex)); } -const str alu = "GGCCGGGCGCGGTGGCTCACGCCTGTAATCCCAGCACTTTGG" +final str alu = "GGCCGGGCGCGGTGGCTCACGCCTGTAATCCCAGCACTTTGG" + "GAGGCCGAGGCGGGCGGATCACCTGAGGTCAGGAGTTCGAGA" + "CCAGCCTGGCCAACATGGTGAAACCCCGTCTCTACTAAAAAT" + "ACAAAAATTAGCCGGGCGTGGTGGCGCGCGCCTGTAATCCCA" @@ -125,7 +125,7 @@ fun main([str] args) > void !> any { Buffer iubChars = Buffer.init(); iubChars.write("acgtBDHKMNRSVWY"); - const Frequency iub = Frequency.init( + final Frequency iub = Frequency.init( chars: iubChars, probs: [ 0.27, 0.12, 0.12, 0.27, 0.02, 0.02, 0.02, 0.02, 0.02, 0.02, 0.02, 0.02, 0.02, 0.02, 0.02 ], last: 42.0, @@ -135,7 +135,7 @@ fun main([str] args) > void !> any { Buffer homoSapiensChars = Buffer.init(); homoSapiensChars.write("acgt"); - const Frequency homoSapiens = Frequency.init( + final Frequency homoSapiens = Frequency.init( chars: homoSapiensChars, probs: [ 0.3029549426680, 0.1979883004921, 0.1975473066391, 0.3015094502008 ], last: iub.last, diff --git a/tests/bench/009-grid.buzz b/tests/bench/009-grid.buzz index 3ffa2ada..e868c032 100644 --- a/tests/bench/009-grid.buzz +++ b/tests/bench/009-grid.buzz @@ -1,8 +1,8 @@ import "std"; fun main([str] args) > void { - const int width = (if (args.len() > 0) std\parseInt(args[0]) else 80) ?? 80; - const int height = (if (args.len() > 1) std\parseInt(args[1]) else 60) ?? 60; + final int width = (if (args.len() > 0) std\parseInt(args[0]) else 80) ?? 80; + final int height = (if (args.len() > 1) std\parseInt(args[1]) else 60) ?? 60; var cells = []; diff --git a/tests/bench/010-ackermann.buzz b/tests/bench/010-ackermann.buzz index 99bc3c7e..812ba43c 100644 --- a/tests/bench/010-ackermann.buzz +++ b/tests/bench/010-ackermann.buzz @@ -1,8 +1,8 @@ import "std"; fun main([str] args) > void { - const m = (if (args.len() > 0) std\parseInt(args[0]) else null) ?? 3; - const n = (if (args.len() > 1) std\parseInt(args[1]) else null) ?? 8; + final m = (if (args.len() > 0) std\parseInt(args[0]) else null) ?? 3; + final n = (if (args.len() > 1) std\parseInt(args[1]) else null) ?? 8; std\print("result: {ack(m, n)}"); } diff --git a/tests/bench/011-bubble-sort.buzz b/tests/bench/011-bubble-sort.buzz index e9283e42..a5e8c669 100644 --- a/tests/bench/011-bubble-sort.buzz +++ b/tests/bench/011-bubble-sort.buzz @@ -1,7 +1,7 @@ import "std"; fun main([str] args) > void { - const max = (if (args.len() > 0) std\parseInt(args[0]) else null) ?? 750; + final max = (if (args.len() > 0) std\parseInt(args[0]) else null) ?? 750; var list = init(max); @@ -14,8 +14,8 @@ fun main([str] args) > void { fun init(int max) > [int] { [int] list = []; - const f = max - 13; - const h = ((max - 117) * (max - 13)) / max; + final f = max - 13; + final h = ((max - 117) * (max - 13)) / max; for (int i = 0; i < max; i = i + 1) { list.append((f * i) % h - (h / 2)); @@ -25,11 +25,11 @@ fun init(int max) > [int] { } fun bubblesort([int] list) > void { - const len = list.len(); + final len = list.len(); for (int i = 0; i < len - 1; i = i + 1) { for (int j = 0; j < len - 1; j = j + 1) { if (list[j] > list[j + 1]) { - const tmp = list[j]; + final tmp = list[j]; list[j] = list[j + 1]; list[j + 1] = tmp; } diff --git a/tests/compile_errors/001-const.buzz b/tests/compile_errors/001-const.buzz index c75d45bd..9a98da25 100644 --- a/tests/compile_errors/001-const.buzz +++ b/tests/compile_errors/001-const.buzz @@ -1,13 +1,13 @@ -// Can't assign to constant variable +// Can't assign to final variable import "std"; -test "`const` variable" { - const yo = "yo"; +test "`final` variable" { + final yo = "yo"; yo = "no way"; } -// function arguments are `const` +// function arguments are `final` fun illegal(yo: str) > void { yo = "no way"; } diff --git a/tests/compile_errors/004-not-callable.buzz b/tests/compile_errors/004-not-callable.buzz index 4112cbad..f8e4490c 100644 --- a/tests/compile_errors/004-not-callable.buzz +++ b/tests/compile_errors/004-not-callable.buzz @@ -1,5 +1,5 @@ // Can't be called test "Can't be called" { - const yo = 12; + final yo = 12; yo("mo"); } diff --git a/tests/compile_errors/006-deep-yield.buzz b/tests/compile_errors/006-deep-yield.buzz index 25e24db7..ea7c9b47 100644 --- a/tests/compile_errors/006-deep-yield.buzz +++ b/tests/compile_errors/006-deep-yield.buzz @@ -10,6 +10,6 @@ fun two() > void { } test "Deep yield" { - const fiber = &two(); + final fiber = &two(); std\print(resume fiber ?? "nope"); } diff --git a/tests/compile_errors/015-bad-pattern.buzz b/tests/compile_errors/015-bad-pattern.buzz index bd05be1f..d999a648 100644 --- a/tests/compile_errors/015-bad-pattern.buzz +++ b/tests/compile_errors/015-bad-pattern.buzz @@ -2,5 +2,5 @@ import "std"; test "bad pattern" { - const bad = $"bad\pattern"; + final bad = $"bad\pattern"; } diff --git a/tests/compile_errors/016-unused-local.buzz b/tests/compile_errors/016-unused-local.buzz index 5a8a7bce..c15f6f83 100644 --- a/tests/compile_errors/016-unused-local.buzz +++ b/tests/compile_errors/016-unused-local.buzz @@ -10,5 +10,5 @@ test "discarded value" { "forgot me?"; - const unused = 42; + final unused = 42; } diff --git a/tests/compile_errors/021-fiber-error-location.buzz b/tests/compile_errors/021-fiber-error-location.buzz index 9f0f25e6..3c5e3fb6 100644 --- a/tests/compile_errors/021-fiber-error-location.buzz +++ b/tests/compile_errors/021-fiber-error-location.buzz @@ -13,7 +13,7 @@ fun count(n: int) > str *> int? { } fun run() > void { - const counter = &count(10); + final counter = &count(10); var sum = 0; while (!counter.over()) { diff --git a/tests/compile_errors/022-var-decl-without-value.buzz b/tests/compile_errors/022-var-decl-without-value.buzz index 8377db78..c3c6e81b 100644 --- a/tests/compile_errors/022-var-decl-without-value.buzz +++ b/tests/compile_errors/022-var-decl-without-value.buzz @@ -1,4 +1,4 @@ // Expected variable initial value test "Var decl without a value" { - const canidothis: str; + final canidothis: str; } diff --git a/tests/compile_errors/030-const-objects.buzz b/tests/compile_errors/030-const-objects.buzz index 6105ef77..9ac08cc6 100644 --- a/tests/compile_errors/030-const-objects.buzz +++ b/tests/compile_errors/030-const-objects.buzz @@ -1,16 +1,16 @@ -// `age` is constant +// `age` is final object Constant { - const name: str, - const age: int, + final name: str, + final age: int, } object PartiallyConstant { - const name: str, + final name: str, age: int, } test "Constant object" { - const constant = Constant{ + final constant = Constant{ name = "Joe", age = 35, }; diff --git a/tests/manual/001-cli-args.buzz b/tests/manual/001-cli-args.buzz index d9353990..b3205db2 100644 --- a/tests/manual/001-cli-args.buzz +++ b/tests/manual/001-cli-args.buzz @@ -1,7 +1,7 @@ import "std"; -fun main([str] args) > void { - foreach (int index, str arg in args) { +fun main(args: [str]) > void { + foreach (index, arg in args) { std\print("{index}: {arg}"); } } \ No newline at end of file diff --git a/tests/manual/002-error.buzz b/tests/manual/002-error.buzz index 8cd17f75..cf780fc8 100644 --- a/tests/manual/002-error.buzz +++ b/tests/manual/002-error.buzz @@ -1,3 +1,3 @@ -fun main([str] _) > void { +fun main(_: [str]) > void { throw "wat!"; } \ No newline at end of file diff --git a/tests/manual/003-io.buzz b/tests/manual/003-io.buzz index d79d5d3d..5bef5c9c 100644 --- a/tests/manual/003-io.buzz +++ b/tests/manual/003-io.buzz @@ -2,7 +2,7 @@ import "std"; import "io"; test "Read stdin" { - for (str? line = ""; line != null; line = io\stdin.readLine()) { + for (line: str? = ""; line != null; line = io\stdin.readLine()) { std\print("= {line}"); io\stdout.write("> "); } diff --git a/tests/manual/006-http-client.buzz b/tests/manual/006-http-client.buzz index 5e0ce868..a2ebd536 100644 --- a/tests/manual/006-http-client.buzz +++ b/tests/manual/006-http-client.buzz @@ -3,10 +3,10 @@ import "debug"; import "errors"; import "serialize"; -fun main([str] _) > void !> any { - const client = http\Client.init(); +fun main(_: [str]) > void !> any { + final client = http\Client.init(); - const request = http\Request{ + final request = http\Request{ method = http\Method.GET, headers = { "accept": "*/*", @@ -15,8 +15,8 @@ fun main([str] _) > void !> any { uri = "https://catfact.ninja/fact", }; - const response = client.send(request); - const fact = serialize\jsonDecode(response.body ?? "null").q(["fact"]).stringValue(); + final response = client.send(request); + final fact = serialize\jsonDecode(response.body ?? "null").q(["fact"]).stringValue(); debug\dump(fact); } \ No newline at end of file diff --git a/tests/utils/testing.buzz b/tests/utils/testing.buzz index ec5c5adc..20f1b0ad 100644 --- a/tests/utils/testing.buzz +++ b/tests/utils/testing.buzz @@ -2,14 +2,14 @@ namespace testing; import "std" as std; -const unexported = 42; +final unexported = 42; fun hey(message: str) > int { std\print(message); return unexported; } -const ignore = "ignore me!"; +final ignore = "ignore me!"; object PrefixMe { name: str = "Joe",