From 85093de7415e9410dc5917f8ef6ac489b8198b42 Mon Sep 17 00:00:00 2001 From: Tom Harley Date: Mon, 28 Oct 2019 22:25:54 +0000 Subject: Add struct type definitions Struct-like types can now be created using the `type` builtin. This creates a constructor function as well as a function for accessing each of the struct's properties. LLVM's type checking makes using these structs a little awkward: they currently cannot be returned by any functions (except the constructor). The aim is to box everything, so that functions can return values they don't know much about. --- simple.int | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) (limited to 'simple.int') diff --git a/simple.int b/simple.int index fe34eab..d06bbcc 100644 --- a/simple.int +++ b/simple.int @@ -1,3 +1,5 @@ -[def (INT fact) [(INT n)] [if n [* n [fact [- n 1]]] 1]] +[type test [(INT x) (INT y)]] +[def (INT testest) [] [test.y [test 3 4]]] +[def (INT fact) [(INT n)] [if [- n 1] [* n [fact [- n 1]]] 1]] [def (INT double) [(INT x)] [* 2 x]] -[def (INT main) [] [debug_int [fact 10]]] +[def (INT main) [] [debug_int [fact [debug_int [testest]]]]] -- cgit v1.2.1