From 63437fbefa29685f99f38c696a60b8a5dc815b16 Mon Sep 17 00:00:00 2001 From: dvanhorn Date: Mon, 2 Dec 2024 15:02:17 +0000 Subject: [PATCH 1/6] crook --- dodger/parse.rkt | 1 - dupe/parse.rkt | 1 - evildoer/parse.rkt | 1 - extort/parse.rkt | 1 - fraud/parse.rkt | 26 ++++++++++++++++---------- hoax/parse.rkt | 26 ++++++++++++++++---------- hustle/parse.rkt | 26 ++++++++++++++++---------- iniquity/parse.rkt | 10 +++++----- jig/parse.rkt | 9 +++++---- knock/parse.rkt | 9 +++++---- loot/parse.rkt | 9 +++++---- 11 files changed, 68 insertions(+), 51 deletions(-) diff --git a/dodger/parse.rkt b/dodger/parse.rkt index 72ee294..e3f9506 100644 --- a/dodger/parse.rkt +++ b/dodger/parse.rkt @@ -21,7 +21,6 @@ [_ (error "parse error" s)])] [_ (error "parse error" s)])) - ;; Any -> Boolean (define (datum? x) (or (exact-integer? x) diff --git a/dupe/parse.rkt b/dupe/parse.rkt index 439aec7..972117c 100644 --- a/dupe/parse.rkt +++ b/dupe/parse.rkt @@ -21,7 +21,6 @@ [_ (error "parse error" s)])] [_ (error "parse error" s)])) - ;; Any -> Boolean (define (datum? x) (or (exact-integer? x) diff --git a/evildoer/parse.rkt b/evildoer/parse.rkt index 5d14abb..04e552a 100644 --- a/evildoer/parse.rkt +++ b/evildoer/parse.rkt @@ -31,7 +31,6 @@ [_ (error "parse error" s)])] [_ (error "parse error" s)])) - ;; Any -> Boolean (define (datum? x) (or (exact-integer? x) diff --git a/extort/parse.rkt b/extort/parse.rkt index 5d14abb..04e552a 100644 --- a/extort/parse.rkt +++ b/extort/parse.rkt @@ -31,7 +31,6 @@ [_ (error "parse error" s)])] [_ (error "parse error" s)])) - ;; Any -> Boolean (define (datum? x) (or (exact-integer? x) diff --git a/fraud/parse.rkt b/fraud/parse.rkt index 3dd7a53..0823008 100644 --- a/fraud/parse.rkt +++ b/fraud/parse.rkt @@ -2,20 +2,23 @@ (provide parse parse-closed) (require "ast.rkt") -;; S-Expr -> Expr +;; s:S-Expr -> e:ClosedExpr +;; Parse s into (a potentially open) expr e (define (parse s) (match (parse/acc s '() '()) [(list _ e) e])) -;; S-Expr -> ClosedExpr +;; s:S-Expr -> e:ClosedExpr +;; Parse s into closed expr e; signal an error when e is open (define (parse-closed s) (match (parse/acc s '() '()) [(list '() e) e] [(list fvs e) (error "unbound identifiers" fvs)])) -;; S-Expr [Listof Id] [Listof Id] -> (list [Listof Id] Expr) -;; Parse s into expr and list of free variables -;; assuming bvs are bound, fvs are free +;; s:S-Expr bvs:[Listof Id] fvs:[Listof Id] +;; -> (list fvs-e:[Listof Id] e:Expr) +;; Parse s into expr e and list of free variables fvs-e, +;; assuming variables in bvs are bound and fvs are free. (define (parse/acc s bvs fvs) (define (rec s bvs fvs) (match s @@ -50,7 +53,10 @@ [_ (error "parse error" s)])) (rec s bvs fvs)) -;; S-Expr [Listof Id] [Listof Id] -> (list [Listof Id] [Listof Expr]) +;; s:S-Expr bvs:[Listof Id] fvs:[Listof Id] +;; -> (list fvs-e:[Listof Id] es:[Listof Expr]) +;; Parse s into a list of expr es and list of free variables fvs-e, +;; assuming variables in bvs are bound and fvs are free. (define (parse-es/acc s bvs fvs) (match s ['() (list fvs '())] @@ -62,10 +68,10 @@ (list fvs (cons e es))])])] [_ (error "parse error")])) -;; [Listof Any] -> (Any -> Boolean) -(define (not-in m) - (λ (x) (not (memq x m)))) - +;; xs:[Listof Any] -> p:(x:Any -> Boolean) +;; Produce a predicate p for things not in xs +(define (not-in xs) + (λ (x) (not (memq x xs)))) ;; Any -> Boolean (define (datum? x) diff --git a/hoax/parse.rkt b/hoax/parse.rkt index 21824a4..e6250f1 100644 --- a/hoax/parse.rkt +++ b/hoax/parse.rkt @@ -2,20 +2,23 @@ (provide parse parse-closed) (require "ast.rkt") -;; S-Expr -> Expr +;; s:S-Expr -> e:ClosedExpr +;; Parse s into (a potentially open) expr e (define (parse s) (match (parse/acc s '() '()) [(list _ e) e])) -;; S-Expr -> ClosedExpr +;; s:S-Expr -> e:ClosedExpr +;; Parse s into closed expr e; signal an error when e is open (define (parse-closed s) (match (parse/acc s '() '()) [(list '() e) e] [(list fvs e) (error "unbound identifiers" fvs)])) -;; S-Expr [Listof Id] [Listof Id] -> (list [Listof Id] Expr) -;; Parse s into expr and list of free variables -;; assuming bvs are bound, fvs are free +;; s:S-Expr bvs:[Listof Id] fvs:[Listof Id] +;; -> (list fvs-e:[Listof Id] e:Expr) +;; Parse s into expr e and list of free variables fvs-e, +;; assuming variables in bvs are bound and fvs are free. (define (parse/acc s bvs fvs) (define (rec s bvs fvs) (match s @@ -53,7 +56,10 @@ [_ (error "parse error" s)])) (rec s bvs fvs)) -;; S-Expr [Listof Id] [Listof Id] -> (list [Listof Id] [Listof Expr]) +;; s:S-Expr bvs:[Listof Id] fvs:[Listof Id] +;; -> (list fvs-e:[Listof Id] es:[Listof Expr]) +;; Parse s into a list of expr es and list of free variables fvs-e, +;; assuming variables in bvs are bound and fvs are free. (define (parse-es/acc s bvs fvs) (match s ['() (list fvs '())] @@ -65,10 +71,10 @@ (list fvs (cons e es))])])] [_ (error "parse error")])) -;; [Listof Any] -> (Any -> Boolean) -(define (not-in m) - (λ (x) (not (memq x m)))) - +;; xs:[Listof Any] -> p:(x:Any -> Boolean) +;; Produce a predicate p for things not in xs +(define (not-in xs) + (λ (x) (not (memq x xs)))) ;; Any -> Boolean (define (datum? x) diff --git a/hustle/parse.rkt b/hustle/parse.rkt index 6cb3f0a..e307fea 100644 --- a/hustle/parse.rkt +++ b/hustle/parse.rkt @@ -2,20 +2,23 @@ (provide parse parse-closed) (require "ast.rkt") -;; S-Expr -> Expr +;; s:S-Expr -> e:ClosedExpr +;; Parse s into (a potentially open) expr e (define (parse s) (match (parse/acc s '() '()) [(list _ e) e])) -;; S-Expr -> ClosedExpr +;; s:S-Expr -> e:ClosedExpr +;; Parse s into closed expr e; signal an error when e is open (define (parse-closed s) (match (parse/acc s '() '()) [(list '() e) e] [(list fvs e) (error "unbound identifiers" fvs)])) -;; S-Expr [Listof Id] [Listof Id] -> (list [Listof Id] Expr) -;; Parse s into expr and list of free variables -;; assuming bvs are bound, fvs are free +;; s:S-Expr bvs:[Listof Id] fvs:[Listof Id] +;; -> (list fvs-e:[Listof Id] e:Expr) +;; Parse s into expr e and list of free variables fvs-e, +;; assuming variables in bvs are bound and fvs are free. (define (parse/acc s bvs fvs) (define (rec s bvs fvs) (match s @@ -52,7 +55,10 @@ [_ (error "parse error" s)])) (rec s bvs fvs)) -;; S-Expr [Listof Id] [Listof Id] -> (list [Listof Id] [Listof Expr]) +;; s:S-Expr bvs:[Listof Id] fvs:[Listof Id] +;; -> (list fvs-e:[Listof Id] es:[Listof Expr]) +;; Parse s into a list of expr es and list of free variables fvs-e, +;; assuming variables in bvs are bound and fvs are free. (define (parse-es/acc s bvs fvs) (match s ['() (list fvs '())] @@ -64,10 +70,10 @@ (list fvs (cons e es))])])] [_ (error "parse error")])) -;; [Listof Any] -> (Any -> Boolean) -(define (not-in m) - (λ (x) (not (memq x m)))) - +;; xs:[Listof Any] -> p:(x:Any -> Boolean) +;; Produce a predicate p for things not in xs +(define (not-in xs) + (λ (x) (not (memq x xs)))) ;; Any -> Boolean (define (datum? x) diff --git a/iniquity/parse.rkt b/iniquity/parse.rkt index defc49c..a3e4e87 100644 --- a/iniquity/parse.rkt +++ b/iniquity/parse.rkt @@ -68,7 +68,6 @@ [(list ys gs (Prog ds e)) (list ys gs (Prog (cons d ds) e))])])])) - ;; S-Expr [Listof Id] [Listof Id] [Listof Id] [Listof Id] -> (list [Listof Id] [Listof Id] Defn) ;; s: definition shaped s-expr to be parsed ;; fs: defined function names @@ -163,16 +162,17 @@ (list ys gs (cons e es))])])] [_ (error "parse error")])) +;; [Listof Any] -> Boolean (define (distinct? xs) (not (check-duplicates xs))) -;; [Listof Any] -> (Any -> Boolean) -(define (not-in m) - (λ (x) (not (memq x m)))) +;; xs:[Listof Any] -> p:(x:Any -> Boolean) +;; Produce a predicate p for things not in xs +(define (not-in xs) + (λ (x) (not (memq x xs)))) (define (in m) (λ (x) (memq x m))) - ;; Any -> Boolean (define (datum? x) (or (exact-integer? x) diff --git a/jig/parse.rkt b/jig/parse.rkt index 721b1b8..522aa92 100644 --- a/jig/parse.rkt +++ b/jig/parse.rkt @@ -163,16 +163,17 @@ (list ys gs (cons e es))])])] [_ (error "parse error")])) +;; [Listof Any] -> Boolean (define (distinct? xs) (not (check-duplicates xs))) -;; [Listof Any] -> (Any -> Boolean) -(define (not-in m) - (λ (x) (not (memq x m)))) +;; xs:[Listof Any] -> p:(x:Any -> Boolean) +;; Produce a predicate p for things not in xs +(define (not-in xs) + (λ (x) (not (memq x xs)))) (define (in m) (λ (x) (memq x m))) - ;; Any -> Boolean (define (datum? x) (or (exact-integer? x) diff --git a/knock/parse.rkt b/knock/parse.rkt index 7c33d8b..6e714b1 100644 --- a/knock/parse.rkt +++ b/knock/parse.rkt @@ -231,16 +231,17 @@ [_ (error "parse pattern error")])) (rec s xs ys gs)) +;; [Listof Any] -> Boolean (define (distinct? xs) (not (check-duplicates xs))) -;; [Listof Any] -> (Any -> Boolean) -(define (not-in m) - (λ (x) (not (memq x m)))) +;; xs:[Listof Any] -> p:(x:Any -> Boolean) +;; Produce a predicate p for things not in xs +(define (not-in xs) + (λ (x) (not (memq x xs)))) (define (in m) (λ (x) (memq x m))) - ;; Any -> Boolean (define (datum? x) (or (exact-integer? x) diff --git a/loot/parse.rkt b/loot/parse.rkt index 651a052..113085f 100644 --- a/loot/parse.rkt +++ b/loot/parse.rkt @@ -222,16 +222,17 @@ [_ (error "parse pattern error")])) (rec s xs ys)) +;; [Listof Any] -> Boolean (define (distinct? xs) (not (check-duplicates xs))) -;; [Listof Any] -> (Any -> Boolean) -(define (not-in m) - (λ (x) (not (memq x m)))) +;; xs:[Listof Any] -> p:(x:Any -> Boolean) +;; Produce a predicate p for things not in xs +(define (not-in xs) + (λ (x) (not (memq x xs)))) (define (in m) (λ (x) (memq x m))) - ;; Any -> Boolean (define (datum? x) (or (exact-integer? x) From 5ab8df0cc867fb09c6507f009d0a8cac12677bfa Mon Sep 17 00:00:00 2001 From: David Van Horn Date: Sat, 23 Nov 2024 22:58:17 -0500 Subject: [PATCH 2/6] A random expression generator for Dodger. --- dodger/random.rkt | 42 ++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 42 insertions(+) create mode 100644 dodger/random.rkt diff --git a/dodger/random.rkt b/dodger/random.rkt new file mode 100644 index 0000000..d0936e3 --- /dev/null +++ b/dodger/random.rkt @@ -0,0 +1,42 @@ +#lang racket +(provide random-expr random-well-defined-expr) +(require "parse.rkt") + +;; Randomly generate an expression +;; Note: this will often generate programs with type errors +(define (random-expr) + (parse (contract-random-generate expr/c))) + +(define (random-well-defined-expr) + (parse (contract-random-generate expr-good/c))) + +(define op1/c + (one-of/c 'add1 'sub1 'zero? 'char? 'integer->char 'char->integer)) + +(define expr/c + (flat-rec-contract e + boolean? + char? + (integer-in #f #f) + (list/c op1/c e) + (list/c 'if e e e))) + +(define expr-good/c + (flat-murec-contract + ([e-int (integer-in #f #f) + (list/c 'add1 e-int) + (list/c 'sub1 e-int) + (list/c 'char->integer e-char) + (list/c 'if e-any e-int e-int)] + [e-char char? + (list/c 'integer->char e-codepoint) + (list/c 'if e-any e-char e-char)] + [e-bool boolean? + (list/c 'char? e-any) + (list/c 'zero? e-int) + (list/c 'if e-any e-bool e-bool)] + [e-codepoint (integer-in 0 #xD7FF) + (integer-in #xE000 #x10FFFF)] + [e-any e-int e-char e-bool + (list/c 'if e-any e-any e-any)]) + e-any)) From c9e147c4cef15c349c8ef5362641056b21801232 Mon Sep 17 00:00:00 2001 From: David Van Horn Date: Sat, 23 Nov 2024 23:34:35 -0500 Subject: [PATCH 3/6] A random expression generator for Evildoer. --- evildoer/random.rkt | 73 +++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 73 insertions(+) create mode 100644 evildoer/random.rkt diff --git a/evildoer/random.rkt b/evildoer/random.rkt new file mode 100644 index 0000000..b6443e5 --- /dev/null +++ b/evildoer/random.rkt @@ -0,0 +1,73 @@ +#lang racket +(provide random-expr random-well-defined-expr) +(require "parse.rkt") + +;; Randomly generate an expression +;; Note: this will often generate programs with type errors +(define (random-expr) + (parse (contract-random-generate expr/c))) + +(define (random-well-defined-expr) + (parse (contract-random-generate expr-good/c))) + +(define op0/c + (one-of/c 'read-byte 'peek-byte 'void)) + +(define op1/c + (one-of/c 'add1 'sub1 'zero? 'char? 'integer->char 'char->integer + 'write-byte 'eof-object?)) + +(define expr/c + (flat-rec-contract e + boolean? + char? + 'eof + (integer-in #f #f) + (list/c op0/c) + (list/c op1/c e) + (list/c 'if e e e) + (list/c 'begin e e))) + +(define expr-good/c + (flat-murec-contract + ([e-int e-byte + (integer-in #f #f) + (list/c 'add1 e-int) + (list/c 'sub1 e-int) + (list/c 'char->integer e-char) + (list/c 'if e-any e-int e-int) + (list/c 'begin e-any e-int)] + [e-byte (integer-in 0 255) + (list/c 'if + (list/c 'eof-object? (list/c 'peek-byte)) + e-byte + (list/c 'read-byte)) + (list/c 'if + (list/c 'eof-object? (list/c 'peek-byte)) + e-byte + (list/c 'peek-byte)) + (list/c 'if e-any e-byte e-byte) + (list/c 'begin e-any e-byte)] + [e-char char? + (list/c 'integer->char e-codepoint) + (list/c 'if e-any e-char e-char) + (list/c 'begin e-any e-char)] + [e-bool boolean? + (list/c 'char? e-any) + (list/c 'zero? e-int) + (list/c 'eof-object? e-any) + (list/c 'if e-any e-bool e-bool) + (list/c 'begin e-any e-bool)] + [e-codepoint (integer-in 0 #xD7FF) + (integer-in #xE000 #x10FFFF) + (list/c 'if e-any e-codepoint e-codepoint) + (list/c 'begin e-any e-codepoint)] + [e-void (list/c 'void) + (list/c 'write-byte e-byte) + (list/c 'if e-any e-void e-void) + (list/c 'begin e-any e-void)] + [e-any e-int e-byte e-char e-bool e-codepoint e-void + 'eof + (list/c 'if e-any e-any e-any) + (list/c 'begin e-any e-any)]) + e-any)) From 167e539cbae88f89ac46ecb6a198f1318a14c4ce Mon Sep 17 00:00:00 2001 From: David Van Horn Date: Mon, 2 Dec 2024 10:18:05 -0500 Subject: [PATCH 4/6] Remove alloc-str in Hustle. --- hustle/heap.rkt | 7 +------ 1 file changed, 1 insertion(+), 6 deletions(-) diff --git a/hustle/heap.rkt b/hustle/heap.rkt index 0b3fd95..0f7eb34 100644 --- a/hustle/heap.rkt +++ b/hustle/heap.rkt @@ -1,5 +1,5 @@ #lang racket -(provide alloc-box alloc-cons alloc-str heap-ref heap-set) +(provide alloc-box alloc-cons heap-ref heap-set) ;; Value* Heap -> Answer* (define (alloc-box v h) @@ -11,11 +11,6 @@ (cons (cons v2 (cons v1 h)) (list 'cons (length h)))) -;; String Heap -> Answer* -(define (alloc-str s h) - (cons (append (reverse (string->list s)) (list (string-length s)) h) - (list 'str (length h)))) - ;; Heap Address -> Value* (define (heap-ref h a) (list-ref h (- (length h) (add1 a)))) From 4eb7c236a821a70abbcfc9bdaf804ecafa60b425 Mon Sep 17 00:00:00 2001 From: David Van Horn Date: Mon, 2 Dec 2024 15:14:00 -0500 Subject: [PATCH 5/6] File needed for notes. --- evildoer/gcd.c | 12 ++++++++++++ 1 file changed, 12 insertions(+) create mode 100644 evildoer/gcd.c diff --git a/evildoer/gcd.c b/evildoer/gcd.c new file mode 100644 index 0000000..9f81af5 --- /dev/null +++ b/evildoer/gcd.c @@ -0,0 +1,12 @@ +#include + +int64_t gcd(int64_t a, int64_t b) { + int remainder = a % b; + + if (remainder == 0) { + return b; + } + + return gcd(b, remainder); +} + From f39930f7ce5e4b5509fa36a51e85df4c6a90235d Mon Sep 17 00:00:00 2001 From: David Van Horn Date: Mon, 2 Dec 2024 15:24:01 -0500 Subject: [PATCH 6/6] Copy of Evildoer random expr generator for Evildoer. --- extort/random.rkt | 77 ++++++++++++++++++++++++++++++++++++++++------- 1 file changed, 66 insertions(+), 11 deletions(-) diff --git a/extort/random.rkt b/extort/random.rkt index e2b7a7b..b6443e5 100644 --- a/extort/random.rkt +++ b/extort/random.rkt @@ -1,18 +1,73 @@ #lang racket -(provide random-expr) +(provide random-expr random-well-defined-expr) (require "parse.rkt") ;; Randomly generate an expression ;; Note: this will often generate programs with type errors (define (random-expr) - (parse - (contract-random-generate - (flat-rec-contract e - #t - #f - (integer-in #f #f) - (list/c 'add1 e) - (list/c 'sub1 e) - (list/c 'zero? e) - (list/c 'if e e e))))) + (parse (contract-random-generate expr/c))) +(define (random-well-defined-expr) + (parse (contract-random-generate expr-good/c))) + +(define op0/c + (one-of/c 'read-byte 'peek-byte 'void)) + +(define op1/c + (one-of/c 'add1 'sub1 'zero? 'char? 'integer->char 'char->integer + 'write-byte 'eof-object?)) + +(define expr/c + (flat-rec-contract e + boolean? + char? + 'eof + (integer-in #f #f) + (list/c op0/c) + (list/c op1/c e) + (list/c 'if e e e) + (list/c 'begin e e))) + +(define expr-good/c + (flat-murec-contract + ([e-int e-byte + (integer-in #f #f) + (list/c 'add1 e-int) + (list/c 'sub1 e-int) + (list/c 'char->integer e-char) + (list/c 'if e-any e-int e-int) + (list/c 'begin e-any e-int)] + [e-byte (integer-in 0 255) + (list/c 'if + (list/c 'eof-object? (list/c 'peek-byte)) + e-byte + (list/c 'read-byte)) + (list/c 'if + (list/c 'eof-object? (list/c 'peek-byte)) + e-byte + (list/c 'peek-byte)) + (list/c 'if e-any e-byte e-byte) + (list/c 'begin e-any e-byte)] + [e-char char? + (list/c 'integer->char e-codepoint) + (list/c 'if e-any e-char e-char) + (list/c 'begin e-any e-char)] + [e-bool boolean? + (list/c 'char? e-any) + (list/c 'zero? e-int) + (list/c 'eof-object? e-any) + (list/c 'if e-any e-bool e-bool) + (list/c 'begin e-any e-bool)] + [e-codepoint (integer-in 0 #xD7FF) + (integer-in #xE000 #x10FFFF) + (list/c 'if e-any e-codepoint e-codepoint) + (list/c 'begin e-any e-codepoint)] + [e-void (list/c 'void) + (list/c 'write-byte e-byte) + (list/c 'if e-any e-void e-void) + (list/c 'begin e-any e-void)] + [e-any e-int e-byte e-char e-bool e-codepoint e-void + 'eof + (list/c 'if e-any e-any e-any) + (list/c 'begin e-any e-any)]) + e-any))