Repository navigation
Flag v0.2.0
This release makes the language more stable and adds two new features: function values and pass.
New
- Function values: the name of a function is a value, with the type
func(i32) -> bool. They go in variables, fields, arrays and arguments, and they are called like any function. There are no closures pass, a statement that does nothing, for a block that has to be empty- A generic alias works in a parameter (
func get(x: Opt[$T])), and$Talso comes from inside a function type sort(items, before)sorts with your own order andfind(items, fits)finds the first element that a function accepts{k: v}fills any type that hasput, not only maps- An array can be sliced directly,
values[0:2]
Faster
x[i]on lists, slices and text, andforover arrays, lists and slices, are written by the compiler instead of calling the library. A loop that walks a list by index or withforruns about 7 times faster, and the compiler checks its own code in two thirds of the time- The IL that goes to QBE is smaller: no empty blocks, no jumps to the next line
Changed
- The keywords of the language cannot be used as names anymore
- A union always holds a real tag. Memory that you zero yourself is
nullfor a union that hasnull, and it's not a value for a union that doesn't (a variable, a field or a literal still starts as its first member) - In an assignment the right side runs first, so
l[0] = grow(l)ands += "x" + sdo what they say - A statement that only makes a value (
x == 2) and a variable that keeps an error nobody reads are errors privin a file without a module hides the name from the other files, and the helpers of the library areprivnowasdoesn't turn a value into a union or a union into another of the same size- An operator between two numbers of one type cannot be declared,
==and<must returnbool, andoperator +=is only the one that prints atwith an integer index cannot be declared for lists, slices, arrays and text, noriterfor lists, slices and arrays, andat(list, i)is gone: a pointer to an element isptr(list[i])- Code can nest about 150 blocks deep, and a chain of
elifor of one operator can have about 300 parts. More than that is an error now, where 0.1.0 crashed a bit further on - A type with parameters cannot have a block of fields inside, and
a.Typeneedsuse a - Several things that compiled by accident are errors: a function declared twice, a constant and a function with one name,
x := [],0x_ff,1e5e3, a call that returns nothing used as a value (also on the right ofiferror:x := load() iferror stop()), assigning to a slice or to an element of a temporary,defer x := 1, variants of an enum at different indentations - The counter of a
forover a range with literal ends is not passed as a pointer on its own, writeptr(i). A function that changed it made the loop index an array out of bounds without a check - A
privfunction that fits a call wins over the ones that are notpriv, so a function of yours with the name of a helper of the library no longer replaces it - A
&strgiven to C as acstris never grown: when it has no room for the zero it goes as a temporary copy. Growing it left the other copies of that text pointing to freed memory - The slice of an
array[u8, N]is a&slice[u8], it was text - A module of the library is the file of its name,
use jsonloadslib/json.flg - The signature of a C function is checked where it is declared, and a fat pointer cannot be a parameter of one
- When two overloads tie, the one that takes its arguments through a shape like
&slice[$T]wins over a bare$T json.parsetakes exactly JSON,fs.walkdoesn't follow links to folders, and several messages of runtime errors say more (slice 4:2 is out of bounds, length 6)
Fixed
- More than a hundred bugs: the compiler crashing or hanging on code it didn't expect, programs reading the wrong member of a union,
deferand loops losing track of what a variable holds, text appended to itself, constants that name a field, wrong results infs,json,osand the printing of floats, and many messages that pointed at the wrong place or didn't say what was wrong - On macOS, a function with more than 32 KiB of locals could store a 64-bit number as 32 bits. It was a bug of QBE for Apple ARM64, and it made
-memorynever end on a struct bigger than 4096 bytes - The memory checker: it reports the memory of a
&ring, the free of a temporary and the real place of a free, and it no longer invents warnings in functions with many allocations
What may still surprise you is in Rough edges.