Skip to content

Core 0.3.5

Latest

Choose a tag to compare

@zweiler1 zweiler1 released this 29 May 21:39
· 101 commits to main since this release
80f6b1a

TLDR

use Core.print

def main():
	i32[] arr = i32[6](0);
	for (i, elem) in arr:
		elem = i32(i);

	arr.[3, 4] = arr.[4, 3];

	for (i, elem) in arr:
		print($"arr[{i}] = {elem}\n");
arr[0] = 0
arr[1] = 1
arr[2] = 2
arr[3] = 4
arr[4] = 3
arr[5] = 5
  • Added persistent local variables
use Core.print

def counter() -> i32:
	persistent i32 c = 0;
	i32 val = c;
	c++;
	return val;

def main():
	fn<() -> i32> c = ::counter;
	print($"c() = {c()}\n");
	print($"c() = {c()}\n");
	print($"c() = {c()}\n");

	print($"counter() = {counter()}\n");
	print($"counter() = {counter()}\n");
c() = 0
c() = 1
c() = 2
counter() = 0
counter() = 0
  • Added enttiy-defined functions, added ability to reference them and call them through callables
use Core.print

data MyData:
	i32 x;
	i32 y;
	i32 z;
	MyData(x, y, z);

entity MyEntity:
	data: MyData d;
	MyEntity(d);

	def print():
		print($"d.(x, y, z) = ({d.x}, {d.y}, {d.z})\n");
	
def main():
	e := MyEntity(MyData(10, 20, 30));
	e.print();

	MyEntity.print(e);
	fn<mut MyEntity> p = MyEntity::print;
	p(e);
d.(x, y, z) = (10, 20, 30)
d.(x, y, z) = (10, 20, 30)
d.(x, y, z) = (10, 20, 30)
  • Added ability to define functions without a body in func modules
  • Added links
  • Added func modules as instances
  • Added ability to links to target entity functions
  • Made entities DIMA-managed
use Core.print

func IMovement:
	def move();
	def move_by(i32x2 diff);


data DPlayer:
	i32x2 pos;
	i32x2 dir;
	DPlayer(pos, dir);

func FPlayer requires(DPlayer d):
	def move():
		print($"Player moved from {d.pos} to ");
		d.pos += d.dir;
		print($"{d.pos}\n");

	def move_by(i32x2 diff):
		print($"Player moved by {diff} from {d.pos} to ");
		d.pos += diff;
		print($"{d.pos}\n");

entity Player:
	data: DPlayer;
	func: IMovement, FPlayer;
	link:
		IMovement::move -> FPlayer::move,
		IMovement::move_by -> FPlayer::move_by;
	Player(DPlayer);


data DComputer:
	i32x2 pos;
	i32x2 dir;
	i32 speed;
	DComputer(pos, dir, speed);

entity Computer:
	data: DComputer d;
	func: IMovement;
	link:
		IMovement::move -> Computer::move,
		IMovement::move_by -> Computer::move_by;
	Computer(d);

	def move():
		print($"Computer moved from {d.pos} to ");
		d.pos += d.dir * d.speed;
		print($"{d.pos}\n");

	def move_by(i32x2 diff):
		print($"Computer moved by {diff} from {d.pos} to ");
		d.pos += diff;
		print($"{d.pos}\n");


def apply_movement(mut IMovement m):
	m.move();
	m.move_by(i32x2(3, 3));

def main():
	p := Player(DPlayer(i32x2(10, 20), i32x2(3, 2)));
	IMovement m = p;
	apply_movement(m);

	if true:
		c := Computer(DComputer(i32x2(20, 10), i32x2(-3, -2), 2));
		m = c;
	apply_movement(m);
Player moved from (10, 20) to (13, 22)
Player moved by (3, 3) from (13, 22) to (16, 25)
Computer moved from (20, 10) to (14, 6)
Computer moved by (3, 3) from (14, 6) to (17, 9)
  • Added ability to throw anonymous errors
use Core.print

def crash(i32 v):
    switch v:
        0: throw error.Crash("Custom Message");
        1: throw error.CrashOther;
        else: throw error.CrashLast("LAST");

def print_crash(i32 v):
    crash(v) catch err:
        print($"{err}: \"{err.message}\"\n");

def main():
    print_crash(0);
    print_crash(1);
    print_crash(2);
error.18151480153507458904.Crash: "Custom Message"
error.18151480153507458904.CrashOther: ""
error.18151480153507458904.CrashLast: "LAST"
  • Added support for the catch keyword to be used as a binary operator to linearize calls:
use Core.print

error MyError:
	VAL1, VAL2, VAL3;

def foo(bool crash) -> i32:
	if crash:
		throw MyError.VAL1("foo failed");
	return 42;

def bar(bool crash) -> i32 {MyError}:
	if crash:
		throw MyError.VAL2("bar failed");
	return 69;

def main():
	i32 x = foo(false);
	print($"x = {x}\n");
	x = foo(true) catch 20;
	print($"x = {x}\n");

	i32 y = bar(false);
	print($"y = {y}\n");
	y = foo(true) catch 20;
	print($"y = {y}\n");

	i32 z = foo(false) + bar(false);
	print($"z = {z}\n");
	z = foo(true) catch 10 + bar(true) catch 30;
	print($"z = {z}\n");
x = 42
x = 20
y = 69
y = 20
z = 111
z = 40
  • Added the i8xN, u16xN, i16xN, u32xN and u64xN multi-type variations, now all primitive integer and floating point types have multi-type variations too
  • Added ability to cast multi-types between one another:
use Core.print

def main():
	i32x2 v1 = (10, 20);
	print($"v1 = {v1}\n");
	i32x2 v2 = i32x2(f32x2(v1) * 1.3);
	print($"v2 = {v2}\n");
v1 = (10, 20)
v2 = (13, 26)
  • Added ability to cast groups to strings:
use Core.print

def get_values() -> (i32, i32):
	return (69, 240);

def main():
	print($"get_values() = {get_values()}\n");
get_values() = (69, 240)
  • Fixed a lot of bugs, across the board, as usual

Changelog

  • Updated Flint's build system to Zig 0.16 (commit)
  • Implemented day 7 of AOC 2025 in Flint (commit)
  • Implemented part 1 of day 8 of AOC 2025 (commit)
  • Added parsing support for grouped array accesses (commit)
  • Added code generation support for grouped array accesses (commit)
  • Added parsing support for grouped array assignments (commit)
  • Added code generation support for grouped array assignments (commit)
  • Added ability that grouped array accesses / assignments also work on strings (commit)
  • Added parsing support for the persistent local variable storage modifier (commit)
  • Added counting of persistent local variable count for functions and setting persistent local IDs for declarations (commit)
  • Added codegen support for persistent locals (commit)
  • Added ability to declare data accessors' identifiers of entity data (commit)
  • Added parsing support for free-floating entity functions, Added ability to do instance-calls on entity-functions (commit)
  • Added ability to use data defined inside the entity within the free-floating entity functions (commit)
  • Added ability to reference entity-functions as callables (commit)
  • Added ability to call entity functions directly through EntityType.call(...) (commit)
  • Added ability to define functions in func modules with no body, they will be required to be linked to concrete functions of other func modules at entity-composition time (commit)
  • Added ability to parse links defined in entites (commit)
  • Completely reworked how links are handled in Flint. Removed the entire idea of the CTDT and instead created a new class, the EntityDispatchGraph, responsible to resolve all links (and hooks in the future) of entity definitions, simplifying the func-interface-instance runtime story by a lot (commit)
  • Improved debug output of all links, printed the actual name-representation of the linked functions instead of just their IDs, which are not human-readable (commit)
  • Added support to call linked functions of entities through interface instances (commit)
  • Made entities DIMA-managed. Made func-modules as instances freeable since they now retain / release their captured entity (commit)
  • Added ability to throw anonymous errors in functions (commit)
  • Added support for the use of the catch keyword as a binary operation to linearize function calls (commit)
  • Added the i8xN, u16xN, i16xN, u32xN and u64xN multi-type variations (commit)
  • Added ability to cast multi-types between one another (commit)
  • Added ability to cast groups to strings if all elements of the group are castable to a string as well (commit)
  • Added the --no-fip flag to the debug build of the compiler to be able to better diagnose non-fip related problems with programs utilizing FIP (commit)
  • Added free.callable function to free persistent locals when the callable is freed (commit)
  • Added the clone.callable function to be able to clone callables (commit)
  • Added missing types to LSP completion data (commit)
  • Added detection of error case if declarations of freeable values don't have an initializer (commit)
  • Added ErrExprCallOfVirtualFunction error (commit)
  • Added ErrDefEntityUnresolvedVirtual error (commit)
  • Added ErrDefEntityLinkNameMismatch error (commit)
  • Added ErrDefEntityLinkSignatureMismatch error (commit)
  • Added ability to links to target entity functions (commit)
  • Updated the generate_clone_value function. It was still generating the code based on the old design of func-module instances (commit)
  • Refactored the EnttiyDispatchGraph to not use function IDs but the raw pointers to the function nodes, as the IDs of the functions change once their bodies are fully parsed, leading to code-generation problems (commit)
  • Fixed bug where an unary operator followed by a binary operation inside another expression, like an array access, would crash the parser (commit)
  • Fixed bug where tokens which start with a given pattern continuously would not be matched to end with said pattern continuously, but if they start with it then they also end with it. Otherwise tokens_end_with_continuous would assert that the tokens are at least one token larger than the pattern to match for, but they could match exactly still. (commit)
  • Fixed bug where accessing a field of a data in an array through a array access as the base expression would crash the compiler (commit)
  • Fixed codegen bug where cloning arrays would not do the final assignment of the cloned array (commit)
  • Fixed bug where enhanced for loops iterating over data would have the wrong type in their GEP calculation for the next iterable element (it took the size of the data instead of the size of a pointer), Fixed the same problem in the create_arr and fill_arr function calls when dealing with arrays of data (commit)
  • Fixed bug where flint.free function would pass wrong pointer to dima.release when an array of data is freed (commit)
  • Fixed bug where arrays were not freed in the flint.free function, they were leaked entirely (commit)
  • Fixed memory leak of complex assignments where the to-assigned value was never freed (commit)
  • Fixed memory leak when assigning complex values inside an array (commit)
  • Fixed construction order issue when extending other entities (commit)
  • Fixed bug where data passed to the entity initializer was not cloned in but simply stored, leading to multiple entities pointing to the same underlying data (commit)
  • Fixed bug where the get_id function would crash if the function does not have a scope (commit)
  • Fixed regression where parsing multiple return values would not work at all (commit)
  • Fixed regression where specifically declared error sets of a function were not parsable any more (commit)
  • Fixed resolving of func-module defined and entity-defined functions coming from other files (commit)
  • Fixed bug where persistent local variables were freed on end-of-scope too, just like regular local variables (commit)
  • Fixed incorrect alignment / offset calculations for callable and interface call parameter storing (commit)
  • Fixed bug where non-freeable persistent local variables were tried to be freed (commit)
  • Fixed bug where the persistent local checks prevented test functions from compiling (commit)
  • Fixed alignment issues when calculating the parameter offsets of callables and interface calls (commit)
  • Fixed use-after-free bug in DIMA::generate_allocate_function in the case of reallocations (commit)
  • Fixed incorrect pointer comparisons in needs_relocation branch of the DIMA::generate_release_function code generation leading to a completely dysfunctional dima.release function if this code path is hit (commit)
  • Fixed incorrect multiplication for calculation of new dima head size as the block part is N pointers to the blocks, not N blocks directly (the head was allocated way too large) (commit)
  • Fixed bug where func-module instance calls parameters would overwrite the implicit parameters set by the dispatch setup function (commit)
  • Fixed bug where argument cleanup of calls had incorrect alignment of the parameters (commit)
  • Fixed hard-crash when parsing empty files (commit)
  • Fixed bug where values normally not passed by reference, e.g. tuples or func-instances, were not able to be passed to the fill_arr function by pointer (commit)
  • Fixed bug where values assigned to arrays which were not already pointers would crash the codegen, similar to the bug fixed in 7d8f5c4 (commit)
  • Fixed incorrect assignment codegen of optional values (commit)
  • Fixed mistake where type.second.first was used instead of expr->getType()->isPointerTy() leading to incorrect code generation for array filling and array assignments in certain cases (AOC Day 6 and 8 did not compile) (commit)

Full Changelog: v0.3.4-core...v0.3.5-core