1
0
mirror of https://github.com/janet-lang/janet synced 2025-01-10 15:40:30 +00:00
janet/examples/sysir/samples.janet

54 lines
1.1 KiB
Plaintext
Raw Normal View History

2024-06-12 00:37:11 +00:00
(use ./frontend)
2024-06-14 21:57:32 +00:00
(def square
'(defn square:int [num:int]
(return (* num num))))
2024-06-12 00:37:11 +00:00
(def simple
2024-06-14 21:57:32 +00:00
'(defn simple:int [x:int]
2024-06-12 00:37:11 +00:00
(def xyz:int (+ 1 2 3))
2024-06-14 21:57:32 +00:00
(return (the int (* x 2 x)))))
2024-06-12 00:37:11 +00:00
(def myprog
2024-06-12 23:28:05 +00:00
'(defn myprog:int []
2024-06-12 00:37:11 +00:00
(def xyz:int (+ 1 2 3))
(def abc:int (* 4 5 6))
2024-06-12 23:28:05 +00:00
(def x:boolean (= (the int 5) xyz))
2024-06-12 00:37:11 +00:00
(var i:int 0)
2024-06-12 23:28:05 +00:00
(while (< i (the int 10))
(set i (the int (+ 1 i)))
2024-06-12 00:37:11 +00: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-12 00:37:11 +00: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 23:28:05 +00:00
(myprog)
2024-06-12 00:37:11 +00:00
(return x)))
(def main-fn
2024-06-16 20:37:25 +00:00
'(defn WinMain:void []
#(syscall 1 1 "Hello, world!\n" 14)
2024-06-12 00:37:11 +00:00
(doloop 10 20)
(exit (the int 0))
(return)))
####
2024-06-14 21:57:32 +00:00
#(compile1 square)
(compile1 simple)
2024-06-12 23:28:05 +00:00
(compile1 myprog)
2024-06-12 00:37:11 +00:00
(compile1 doloop)
(compile1 main-fn)
#(dump)
#(dumpc)
(dumpx64)
# Run with
# janet examples/sysir/scratch.janet > temp.nasm && nasm -felf64 temp.nasm -l temp.lst && ld temp.o && ./a.out