Skip to content

Commit

Permalink
Bignums (#65)
Browse files Browse the repository at this point in the history
* initial GMP attempt (does not work)

* bignums should be compiling

* bignums compile for real

* sign represented in length word sign

* fixed representation, added tests, add unloading

* fix interp.rkt

* added functionality for more primitives

* clean up redundancy, use mpz import

* finish prim1, with tests

* fix library externs

* addition, plus tests

* subtraction, plus tests

* clean up bignums.c

* updated all integer comparisons

* fixed interp for quotient and remainder, add bignum functionality
  • Loading branch information
vyasgupta authored Mar 30, 2021
1 parent 3cd156f commit ae4b588
Show file tree
Hide file tree
Showing 16 changed files with 947 additions and 124 deletions.
13 changes: 12 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,17 @@ Code emitted by the compiler depends upon the following libraries:
$ makepkg -si
```

* [`GMP`](https://gmplib.org/)

To install this library, you can download and compile the source code from this [`website`](https://gmplib.org/). Following unzipping, below are the instructions to install GMP in a Unix-like environment.

```console
$ cd gmp-6.2.1 (or whatever release)
$ ./configure
$ make
$ make check
$ make install
```
## Reference

- [standard libraries](stdlibs.md)
- [standard libraries](stdlibs.md)
2 changes: 1 addition & 1 deletion a86/interp.rkt
Original file line number Diff line number Diff line change
Expand Up @@ -169,7 +169,7 @@
""
"-z defs "))
(unless (parameterize ((current-error-port err-port))
(system (format "gcc ~a-v -shared ~a ~a -o ~a -lunistring -lm"
(system (format "gcc ~a-v -shared ~a ~a -o ~a -lunistring -lm -lgmp"
-z-defs-maybe
t.o objs t.so)))
(define err-msg
Expand Down
5 changes: 4 additions & 1 deletion villain/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ objs = \
io.o \
symbol.o \
str.o \
bignums.o \
wrap.o \
utf8.o

Expand All @@ -29,12 +30,13 @@ char.o: villain.h utf8.h char.h
io.o: runtime.h villain.h utf8.h
symbol.o: str.h types.h villain.h
str.o: types.h villain.h
bignums.o: villain.h types.h

%.run: %.o
@ racket -t formdps.rkt -m make $@

%.run2: %.o runtime.o
gcc runtime.o $(shell cat modulefiles) $< -o $@ $(libs) # -lm
gcc runtime.o $(shell cat modulefiles) $< -o $@ $(libs) -lgmp # -lm
@ racket -t formdps.rkt -m mv $@
rm -f formdps $(shell cat modulefiles) modulefiles
find . -name "*.s" -not -name libraries-lmdefs.s -delete
Expand Down Expand Up @@ -74,6 +76,7 @@ clean:
-not -name "symbol.o" \
-not -name "str.o" \
-not -name "wrap.o" \
-not -name "bignums.o" \
-not -name "utf8.o" -delete \
-or -name "*.s" -not -name \
"libraries-lmdefs.s" -delete \
Expand Down
2 changes: 2 additions & 0 deletions villain/ast.rkt
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
;; | (Int Integer)
;; | (Bool Boolean)
;; | (Char Character)
;; | (Bignum Bignum)
;; | (Flonum f)
;; | (String String)
;; | (Vec (Listof Expr))
Expand Down Expand Up @@ -76,6 +77,7 @@
(struct Char (c) #:prefab)
(struct Flonum (f) #:prefab)
(struct String (s) #:prefab)
(struct Bignum (i) #:prefab)
(struct Symbol (s) #:prefab)
(struct Prim0 (p) #:prefab)
(struct Prim1 (p e) #:prefab)
Expand Down
Loading

0 comments on commit ae4b588

Please sign in to comment.