diff --git a/LICENSE b/LICENSE new file mode 100644 index 0000000..47e8959 --- /dev/null +++ b/LICENSE @@ -0,0 +1,21 @@ +MIT License + +Copyright (c) 2022 Stefan Heller + +Permission is hereby granted, free of charge, to any person obtaining a copy +of this software and associated documentation files (the "Software"), to deal +in the Software without restriction, including without limitation the rights +to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +copies of the Software, and to permit persons to whom the Software is +furnished to do so, subject to the following conditions: + +The above copyright notice and this permission notice shall be included in all +copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE +SOFTWARE. diff --git a/lang/compile.rkt b/lang/compile.rkt index ad85246..9728ddb 100644 --- a/lang/compile.rkt +++ b/lang/compile.rkt @@ -208,6 +208,7 @@ ['- (Sub (assert-integer e1) (assert-integer e2))] ['* (runtime-int->bits (Mul (runtime-bits->int (assert-integer e1)) (runtime-bits->int(assert-integer e2))))] ['/ (runtime-int->bits (Div (runtime-bits->int (assert-integer e1)) (runtime-bits->int(assert-integer e2))))] + ['% (Rem (assert-integer e1) (assert-integer e2))] ['or (Or e1 e2)] ['and (And e1 e2)] ['xor (Xor e1 e2)] diff --git a/lang/parse.rkt b/lang/parse.rkt index eac5a98..15aeeac 100644 --- a/lang/parse.rkt +++ b/lang/parse.rkt @@ -73,7 +73,7 @@ box unbox empty? cons? box? car cdr vector? vector-length string? string-length)) (define op2 - '(+ - < = * / << >> and or xor cons eq? make-vector vector-ref make-string string-ref)) + '(+ - < = * / << >> % and or xor cons eq? make-vector vector-ref make-string string-ref)) (define op3 '(vector-set!)) diff --git a/package-lock.json b/package-lock.json index ccc1685..b0b3516 100644 --- a/package-lock.json +++ b/package-lock.json @@ -10,7 +10,7 @@ "license": "ISC", "dependencies": { "express": "^4.17.3", - "node-fetch": "^3.2.3" + "node-fetch": "^3.2.10" } }, "node_modules/accepts": { @@ -373,9 +373,9 @@ } }, "node_modules/node-fetch": { - "version": "3.2.3", - "resolved": "https://registry.npmjs.org/node-fetch/-/node-fetch-3.2.3.tgz", - "integrity": "sha512-AXP18u4pidSZ1xYXRDPY/8jdv3RAozIt/WLNR/MBGZAz+xjtlr90RvCnsvHQRiXyWliZF/CpytExp32UU67/SA==", + "version": "3.2.10", + "resolved": "https://registry.npmjs.org/node-fetch/-/node-fetch-3.2.10.tgz", + "integrity": "sha512-MhuzNwdURnZ1Cp4XTazr69K0BTizsBroX7Zx3UgDSVcZYKF/6p0CBe4EUb/hLqmzVhl0UpYfgRljQ4yxE+iCxA==", "dependencies": { "data-uri-to-buffer": "^4.0.0", "fetch-blob": "^3.1.4", @@ -850,9 +850,9 @@ "integrity": "sha512-/jKZoMpw0F8GRwl4/eLROPA3cfcXtLApP0QzLmUT/HuPCZWyB7IY9ZrMeKw2O/nFIqPQB3PVM9aYm0F312AXDQ==" }, "node-fetch": { - "version": "3.2.3", - "resolved": "https://registry.npmjs.org/node-fetch/-/node-fetch-3.2.3.tgz", - "integrity": "sha512-AXP18u4pidSZ1xYXRDPY/8jdv3RAozIt/WLNR/MBGZAz+xjtlr90RvCnsvHQRiXyWliZF/CpytExp32UU67/SA==", + "version": "3.2.10", + "resolved": "https://registry.npmjs.org/node-fetch/-/node-fetch-3.2.10.tgz", + "integrity": "sha512-MhuzNwdURnZ1Cp4XTazr69K0BTizsBroX7Zx3UgDSVcZYKF/6p0CBe4EUb/hLqmzVhl0UpYfgRljQ4yxE+iCxA==", "requires": { "data-uri-to-buffer": "^4.0.0", "fetch-blob": "^3.1.4", diff --git a/package.json b/package.json index cfb413f..13c3764 100644 --- a/package.json +++ b/package.json @@ -18,7 +18,7 @@ "homepage": "https://github.com/stefanhts/430_finalproj#readme", "dependencies": { "express": "^4.17.3", - "node-fetch": "^3.2.3" + "node-fetch": "^3.2.10" }, "module": "true" } diff --git a/tests/arithmetic/1.wkt b/tests/arithmetic/1.wkt new file mode 100644 index 0000000..46fde05 --- /dev/null +++ b/tests/arithmetic/1.wkt @@ -0,0 +1,2 @@ +#lang wacket +(% 10 3) \ No newline at end of file diff --git a/wat/ast.rkt b/wat/ast.rkt index dd909b0..478f82d 100644 --- a/wat/ast.rkt +++ b/wat/ast.rkt @@ -61,6 +61,8 @@ ;; Convenience for adding 64 bit integers. (struct Sub (i1 i2) #:prefab) +(struct Rem (i1 i2) #:prefab) + (struct Mul (i1 i2) #:prefab) (struct Div (i1 i2) #:prefab) diff --git a/wat/printer.rkt b/wat/printer.rkt index 448a6c3..8268864 100644 --- a/wat/printer.rkt +++ b/wat/printer.rkt @@ -231,6 +231,7 @@ [(Sub i1 i2) (list "i64.sub" (seq i1 i2))] [(Mul i1 i2) (list "i64.mul" (seq i1 i2))] [(Div i1 i2) (list "i64.div_s" (seq i1 i2))] + [(Rem i1 i2) (list "i64.rem_s" (seq i1 i2))] [(And i1 i2) (list "i64.and" (seq i1 i2))] [(Or i1 i2) (list "i64.or" (seq i1 i2))] [(Xor i1 i2) (list "i64.xor" (seq i1 i2))]