Skip to content

Commit 35411c7

Browse files
committed
Add system-type primitive.
1 parent 9865752 commit 35411c7

7 files changed

Lines changed: 21 additions & 9 deletions

File tree

langs/outlaw/Makefile

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ objs = \
2020
string.o \
2121
io.o \
2222
error.o \
23+
os.o \
2324
stdlib.o
2425

2526
default: runtime.o

langs/outlaw/a86/printer.rkt

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -18,15 +18,15 @@
1818

1919
;; Label -> String
2020
(define label-symbol->string
21-
(match (system-type 'os)
21+
(match (system-type)
2222
['macosx
2323
(λ (s) (string-append "_" (symbol->string s)))]
2424
[_ symbol->string]))
2525

2626
;; Label -> String
2727
;; prefix with _ for Mac
2828
(define label-symbol->string/rel
29-
(match (system-type 'os)
29+
(match (system-type)
3030
['macosx
3131
(λ (s) (string-append "_" (symbol->string s)))]
3232
[_
@@ -76,7 +76,7 @@
7676
(define (external-label-shared? x)
7777
(and (label? x)
7878
(current-shared?)
79-
(eq? 'unix (system-type 'os))
79+
(eq? 'unix (system-type))
8080
(memq x (unbox external-labels))))
8181

8282
(define (mov->string a1 a2)

langs/outlaw/compile-ops.rkt

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,11 @@
1212
(unpad-stack))]
1313
['current-input-port ; hack, doesn't actually exist
1414
(seq (Mov rax val-void))]
15+
['system-type
16+
(seq (pad-stack)
17+
(Call 'system_type)
18+
(Sal rax int-shift)
19+
(unpad-stack))]
1520

1621
;; Op1
1722
['add1

langs/outlaw/compile.rkt

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -102,7 +102,8 @@
102102
open_input_file
103103
read_byte_port
104104
peek_byte_port
105-
is_char_alphabetic)))
105+
is_char_alphabetic
106+
system_type)))
106107

107108
(define cons-function
108109
(let ((code (gensym 'cons_code))

langs/outlaw/parse.rkt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -322,6 +322,7 @@
322322
(define op0
323323
'(read-byte void read-char peek-char
324324
current-input-port ; hack, doesn't actually exist
325+
system-type
325326
))
326327

327328
(define op1

langs/outlaw/stdlib.rkt

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
remove-duplicates remq* remove* remove
1010
andmap vector list->vector boolean? substring
1111
odd?
12-
system-type ;; hard-coded
12+
system-type
1313
not
1414
findf
1515
read-line
@@ -299,10 +299,13 @@
299299
(define (odd? x)
300300
(= (remainder x 2) 1))
301301

302-
;; FIXME: hard-coded system type
303-
(define (system-type _)
304-
'unix)
305-
; 'macosx)
302+
(define (system-type)
303+
;; the primitive system type returns 1 for mac, 0 otherwise;
304+
;; the fall through case is for when %system-type is implemented in Racket
305+
(match (%system-type)
306+
[1 'macosx]
307+
[0 'unix]
308+
[x x]))
306309

307310
(define (not x)
308311
(if x #f #t))

langs/outlaw/test/test-runner.rkt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -601,6 +601,7 @@
601601
(check-equal? (run '(let ((x 1)) x x)) 1)
602602
(check-equal? (run '(let ((x 1)) x x x)) 1)
603603
(check-equal? (run '(match 1 [1 2 3])) 3)
604+
(check-equal? (run '(system-type)) (system-type))
604605
)
605606

606607

0 commit comments

Comments
 (0)