Skip to content

Commit

Permalink
Updating Read to Parse Flonums and Fixing Flonum Compilation (#67)
Browse files Browse the repository at this point in the history
* Update compile.rkt

* Update ast.rkt

* Update printer.rkt

* Update read.rkt

* Add files via upload
  • Loading branch information
WChung43 authored Mar 23, 2021
1 parent d53d0c4 commit 3cd156f
Show file tree
Hide file tree
Showing 5 changed files with 26 additions and 25 deletions.
4 changes: 2 additions & 2 deletions a86/ast.rkt
Original file line number Diff line number Diff line change
Expand Up @@ -189,7 +189,7 @@
(instruct Cqo () check:none)
(instruct Addsd (dst src) check:xarith)
(instruct Subsd (dst src) check:xarith)
(instruct Movapd (dst src) check:xsrc-xdest)
(instruct Movsd (dst src) check:xsrc-xdest)
(instruct Offset (r i) check:offset)
(instruct Extern (x) check:label-symbol)

Expand Down Expand Up @@ -245,7 +245,7 @@
(Comment? x)
(Addsd? x)
(Subsd? x)
(Movapd? x)
(Movsd? x)
)
)

Expand Down
4 changes: 2 additions & 2 deletions a86/printer.rkt
Original file line number Diff line number Diff line change
Expand Up @@ -160,8 +160,8 @@
(arg->string a1) ", "
(arg->string a2))]

[(Movapd a1 a2)
(string-append tab "movapd "
[(Movsd a1 a2)
(string-append tab "movsd "
(arg->string a1) ", "
(arg->string a2))]

Expand Down
8 changes: 4 additions & 4 deletions villain/compile.rkt
Original file line number Diff line number Diff line change
Expand Up @@ -1206,9 +1206,9 @@
(assert-flonum rax c)
(Xor rax type-flonum)
(Xor r8 type-flonum)
(Movapd xmm0 (Offset r8 0))
(Movsd xmm0 (Offset r8 0))
(Addsd xmm0 (Offset rax 0))
(Movapd (Offset rbx 0) xmm0)
(Movsd (Offset rbx 0) xmm0)
(Mov rax rbx)
(Or rax type-flonum)
(Add rbx 8)
Expand All @@ -1221,9 +1221,9 @@
(Xor rax type-flonum)

(Xor r8 type-flonum)
(Movapd xmm0 (Offset r8 0))
(Movsd xmm0 (Offset r8 0))
(Subsd xmm0 (Offset rax 0))
(Movapd (Offset rbx 0) xmm0)
(Movsd (Offset rbx 0) xmm0)
(Mov rax rbx)
(Or rax type-flonum)
(Add rbx 8)
Expand Down
33 changes: 16 additions & 17 deletions villain/read.rkt
Original file line number Diff line number Diff line change
Expand Up @@ -258,21 +258,21 @@
(check-equal? (pn "-123") -123)
(check-equal? (pn "+123") 123)
; removed frac
;(check-equal? (pn "5.") 5.0)
;(check-equal? (pn ".5") 0.5)
;(check-equal? (pn ".5 ") 0.5)
;(check-equal? (pn "+.5") 0.5)
;(check-equal? (pn "-.5") -0.5)
;(check-equal? (pn "+1.5") 1.5)
;(check-equal? (pn "-1.5") -1.5)
;(check-equal? (pn "+.5") 0.5)
;(check-equal? (pn "-.") '-.)
;(check-equal? (pn "+.") '+.)
;(check-equal? (pn "+.x") '+.x)
(check-equal? (pn "5.") 5.0)
(check-equal? (pn ".5") 0.5)
(check-equal? (pn ".5 ") 0.5)
(check-equal? (pn "+.5") 0.5)
(check-equal? (pn "-.5") -0.5)
(check-equal? (pn "+1.5") 1.5)
(check-equal? (pn "-1.5") -1.5)
(check-equal? (pn "+.5") 0.5)
(check-equal? (pn "-.") '-.)
(check-equal? (pn "+.") '+.)
(check-equal? (pn "+.x") '+.x)
(check-equal? (pn "+x") '+x)
(check-equal? (pn "-x") '-x)
; removed frac
;(check-equal? (pn ".x") '.x)
(check-equal? (pn ".x") '.x)
(check-equal? (pn "1..") '1..)
(check-equal? (pn "1.1.") '1.1.)
(check-pred err? (pn ".")))
Expand Down Expand Up @@ -310,8 +310,6 @@
p)]))

(define (make-frac signed? whole frac)
(unimplemented "frac")
#; ;; unimplemented because we don't have fractions in the run-time
(match* (whole frac)
[('() '()) (chars->symbol (list #\. signed?))]
[(_ _)
Expand All @@ -320,10 +318,10 @@
[#\- (- (frac->number whole frac))]
[_ (frac->number whole frac)]))]))

#;; removed frac

(define (frac->number whole frac)
(+ (char-digits->number whole)
(/ (char-digits->number frac)
(+ (char-digit10s->number whole)
(/ (char-digit10s->number frac)
(expt 10 (length frac)))))

(define (make-whole signed? ds)
Expand All @@ -332,6 +330,7 @@
[_ (char-digit10s->number ds)]))



;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;; Line comment

Expand Down
2 changes: 2 additions & 0 deletions villain/test/test-programs/villain/float.rkt
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
#lang racket (require racket/flonum)
(if (fl<= (fl+ 7.5 17.2) (fl- 17.5 6.5)) (fl= 5.5 5.5) (fl+ 2.25 2.555555))

0 comments on commit 3cd156f

Please sign in to comment.