mirror of
https://github.com/janet-lang/janet
synced 2025-01-26 15:16:51 +00:00
ea332ff81e
We need to create abstractions around more of the backend to properly test and experiment with things, even if the frontend is not final.
68 lines
1.1 KiB
Plaintext
68 lines
1.1 KiB
Plaintext
(use ./frontend)
|
|
|
|
(defstruct vec3
|
|
a float
|
|
b float
|
|
c float)
|
|
|
|
(defunion myunion
|
|
a float
|
|
b double
|
|
c long)
|
|
|
|
(defarray myvec float 4)
|
|
|
|
(defn-external printf:int [fmt:pointer x:int]) # TODO varargs
|
|
|
|
(defn-external exit:void [x:int])
|
|
|
|
(defsys square:int
|
|
[num:int]
|
|
(return (* 1 num num)))
|
|
|
|
(defsys simple:int [x:int]
|
|
(def xyz:int (+ 1 2 3))
|
|
(return (* x 2 x)))
|
|
|
|
(defsys myprog:int []
|
|
(def xyz:int (+ 1 2 3))
|
|
(def abc:int (* 4 5 6))
|
|
(def x:boolean (= xyz 5))
|
|
(var i:int 0)
|
|
(while (< i 10)
|
|
(set i (+ 1 i))
|
|
(printf "i = %d\n" i))
|
|
(printf "hello, world!\n%d\n" (if x abc xyz))
|
|
(return (simple (* abc xyz))))
|
|
|
|
(defsys doloop [x:int y:int]
|
|
(var i:int x)
|
|
(while (< i y)
|
|
(set i (the int (+ 1 i)))
|
|
(printf "i = %d\n" i))
|
|
(myprog)
|
|
(return x))
|
|
|
|
(defsys _start:void []
|
|
#(syscall 1 1 "Hello, world!\n" 14)
|
|
(doloop 10 20)
|
|
(exit (the int 0))
|
|
(return))
|
|
|
|
(defsys test_inttypes:ulong []
|
|
(def x:ulong 123:u)
|
|
(return (+ x x)))
|
|
|
|
(defsys test_arrays:myvec [a:myvec b:myvec]
|
|
(return (+ a b)))
|
|
|
|
(defsys make_array:myvec []
|
|
(def vec:myvec 0)
|
|
(return vec))
|
|
|
|
####
|
|
|
|
#(dump)
|
|
(dumpc)
|
|
#(dumpx64)
|