14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
..
42
43
44
45
46
47
48
49
50
|
; (@ … ) introduces a block of Scheme code that
; is evaluated in the program's environment, but
; whose value is silently ignored. this makes it
; good for defining globals you intend to use
; later in the program with (* … ) or (= … )
; blocks - see the paragraph below
(define (sayl str)
`(add-> total (call write 1
; the return value of a scheme expression will
; be evaluated just like any other expression
; and transformed into C code, so we can rely
; on existing syntax instead of haven't to
; generate raw strings of C
,(string-append str "\\n")
,(+ 1 (string-length str))))))
(decl sayhello ((ptr char) → int))
(def (total size_t) 0)
(def (main int (argc int) (argv (array (ptr char))))
(ret (call sayhello "dumbass")))
(def (sayhello int (name (ptr char)))
(* sayl "hello…")
; a list prefixed with * indicates that it
; should be evaluated as a scheme expression
; and its result then processed, instead of
; being processed directly like (call) or
................................................................................
; (def). scheme expressions may be inserted
; anywhere a normal sexpc expression can. or
; we could instead write (= (sayl "hello…"))
; to accomplish the same effect; (= … ) is
; really just shorthand for (* begin … )
(call write 1 name (call strlen name))
(ret total)
)
|
|
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
..
45
46
47
48
49
50
51
52
53
54
55
56
|
; (@ … ) introduces a block of Scheme code that
; is evaluated in the program's environment, but
; whose value is silently ignored. this makes it
; good for defining globals you intend to use
; later in the program with (* … ) or (= … )
; blocks - see the paragraph below
(define (sayl str)
`(add-> total (call write 1
; the return value of a scheme expression will
; be evaluated just like any other expression
; and transformed into C code, so we can rely
; on existing syntax instead of haven't to
; generate raw strings of C
,(string-append str "\\n")
,(+ 1 (string-length str))))))
(decl sayhello ((ptr char) → int))
(decl usage (() => ()))
(def (total size_t) 0)
(def (main int (argc int) (argv (array (ptr char))))
(def (voidptr (ptr ())) (cast (ptr ()) argv))
(cond ((neq argc 2) (call usage))
(else (call sayhello (idx argv 1)))))
(def (sayhello int (name (ptr char)))
(* sayl "hello…")
; a list prefixed with * indicates that it
; should be evaluated as a scheme expression
; and its result then processed, instead of
; being processed directly like (call) or
................................................................................
; (def). scheme expressions may be inserted
; anywhere a normal sexpc expression can. or
; we could instead write (= (sayl "hello…"))
; to accomplish the same effect; (= … ) is
; really just shorthand for (* begin … )
(call write 1 name (call strlen name))
(ret total))
(def (usage void ())
(* sayl "usage: example <name>"))
|