rename dir lib -> example

because it is not quite lib yet, but an example dump definitely
This commit is contained in:
2025-06-14 12:40:15 +03:00
parent 6e59e523d4
commit f309f83dbb
2 changed files with 0 additions and 0 deletions

36
example/list.seh Normal file
View File

@@ -0,0 +1,36 @@
(template (list-T (T))
(struct list-T
((T value)
((* list-T) next))))
(template (make-list-T (T) is-public?)
(,@(if is-public? '(pub) '()) fn (* list-T) make-list-T ()
(var (* list-T) list (cast (* list-T) (malloc (sizeof list-T))))
(= (-> list next) NULL)
list))
(template (add-value-list-T (T) is-public?)
(,@(if is-public? '(pub) '()) fn void add-value-list-T ((list-T *list) (T value))
(while (!= (-> list next) NULL)
(= list (-> list next)))
(= (-> list next) (make-list-T))
(= (-> list value) value)))
(template (length-list-T (T) is-public?)
(,@(if is-public? '(pub) '()) fn size-t length-list-T ((list-T *list))
(var size-t n 0)
(while (!= (-> list next) NULL)
(= list (-> list next))
(++ n))
n))
(template (is-empty-list-T (T) is-public?)
(,@(if is-public? '(pub) '()) fn bool is-empty-list-T ((list-T *list))
(== (-> list next) NULL)))
(template (list-for-each (what-do list-var elt-var))
(var int elt-var (-> list-var value))
(while (!= (-> list-var next) NULL)
what-do
(= list-var (-> list-var next))
(= elt-var (-> list-var value))))

36
example/test-list.sex Normal file
View File

@@ -0,0 +1,36 @@
(include stdlib.h)
(include stddef.h)
(include stdbool.h)
(include stdio.h)
(load "list.seh")
(struct foo
((float a)
(int b)
((const char *) c)))
,(list-T '(int))
,(make-list-T '(int) #f)
,(add-value-list-T '(int) #f)
,(length-list-T '(int) #f)
,(is-empty-list-T '(int) #f)
(extern fn void puk ((int a) (float b)))
(fn bool bar () false)
(pub fn void baz () true)
(extern var int i)
(var int j)
(pub var int k)
(pub fn int main ()
(var (* list-int) l (make-list-int))
(printf "Size of the list: %zu\n" (length-list-int l))
(add-value-list-int l 3)
(add-value-list-int l 4)
(printf "Size of the list: %zu\n" (length-list-int l))
,(list-for-each '((printf "%d " v) l v))
(printf "\n")
0)