1
0
mirror of https://github.com/janet-lang/janet synced 2025-02-22 11:10:02 +00:00
janet/examples/sysir/samples.janet

51 lines
992 B
Plaintext
Raw Normal View History

2024-06-11 19:37:11 -05:00
(use ./frontend)
2024-06-14 16:57:32 -05:00
(def square
'(defn square:int [num:int]
(return (* 1 num num))))
2024-06-14 16:57:32 -05:00
2024-06-11 19:37:11 -05:00
(def simple
2024-06-14 16:57:32 -05:00
'(defn simple:int [x:int]
2024-06-11 19:37:11 -05:00
(def xyz:int (+ 1 2 3))
2024-09-29 07:13:27 -05:00
(return (* x 2 x))))
2024-06-11 19:37:11 -05:00
(def myprog
2024-06-12 18:28:05 -05:00
'(defn myprog:int []
2024-06-11 19:37:11 -05:00
(def xyz:int (+ 1 2 3))
(def abc:int (* 4 5 6))
(def x:boolean (= xyz 5))
2024-06-11 19:37:11 -05:00
(var i:int 0)
(while (< i 10)
(set i (+ 1 i))
2024-06-11 19:37:11 -05:00
(printf "i = %d\n" i))
(printf "hello, world!\n%d\n" (the int (if x abc xyz)))
#(return (* abc xyz))))
(return (the int (simple (* abc xyz))))))
2024-06-11 19:37:11 -05:00
(def doloop
'(defn doloop [x:int y:int]
(var i:int x)
(while (< i y)
(set i (the int (+ 1 i)))
(printf "i = %d\n" (the int i)))
2024-06-12 18:28:05 -05:00
(myprog)
2024-06-11 19:37:11 -05:00
(return x)))
(def main-fn
'(defn _start:void []
2024-06-16 13:37:25 -07:00
#(syscall 1 1 "Hello, world!\n" 14)
2024-06-11 19:37:11 -05:00
(doloop 10 20)
(exit (the int 0))
(return)))
####
(compile1 square)
(compile1 simple)
(compile1 myprog)
(compile1 doloop)
(compile1 main-fn)
2024-06-11 19:37:11 -05:00
#(dump)
(dumpc)
#(dumpx64)