Commit 11d8cf7c authored by Guy Watson's avatar Guy Watson
Browse files

Add for loop ast structure generation

parent 8a20c80a
......@@ -32,6 +32,7 @@
xsmith
xsmith/racr-convenience
racr
racket/class
racket/pretty
racket/string
racket/match
......@@ -51,7 +52,7 @@
[LiteralInt Expr ([v = (random 10000)])
#:prop choice-weight 3]
[Noop Expr ([e : Expr])]
[Binop Expr ()
[Binop Expr () ;; use l and r here
#:prop choice-weight 30 ;; default is 10
#:prop may-be-generated #f]
[Equal Binop ([l : Expr] [r : Expr])]
......@@ -94,12 +95,6 @@
[then : Expr])]
[Block Expr ([e : Expr])]
[Loop Expr ([e : Expr])]
[ForLoop Expr ([loopvar : GlobalSet] ;; This will be the inital value set before entering the loop
;; Rendering for this node is restricted: it will not produce
;; a value for use by children
[iter : GlobalSet]) ;; this iter is controlled by 'fresh', and will produce an
;; expression for the result of the loop
#:prop choice-weight 100]
[Branch Expr ([val : Expr]
[targetnode]
[targetindex]) ;; a number depth
......@@ -138,6 +133,15 @@
[expr : Expr])
#:prop reference-info (write name #:unifies val)
#:prop choice-weight 4]
;; Idiomatic Generation
[ForLoop Expr ([loopvar : GlobalSet] ;; This will be the inital value set before entering the loop
;; Rendering for this node is restricted: it will not produce
;; a value for use by children
[loop : Loop]) ;; this iter is controlled by 'fresh', and will produce an
;; expression for the result of the loop
#:prop choice-weight 10000]
)
(add-prop
......@@ -150,44 +154,46 @@
[LocalGet (hash 'index (choose-local-target (current-hole)))]
[LocalSet (hash 'index (choose-local-target (current-hole)))]
[LocalTee (hash 'index (choose-local-target (current-hole)))]
#;[GlobalSet (λ (d)
(let* ([type (hash-ref d 'type [(fresh-type-variable)])]
[binders (ast-child 'globals (top-ancestor-node (current-hole)))]
[fresh-node (make-fresh-node 'GlobalDeclaration
(hash 'type type))])
(begin
(append binders (make-fresh-node 'GlobalDeclaration
(hash 'type type)))
(hash 'type type
'name (ast-child 'name fresh-node)))))]
#;[GlobalGet (hash 'name (fresh-var-name "$global_"))]
#;[GlobalSet (hash 'name (fresh-var-name "$global_"))]
;; implement these with the upcoming custom name changes
[ForLoop (let* ([proto-loopvar (make-fresh-node 'GlobalSet
;;todo Implement these with the upcoming custom name changes
;; The problem here is that I can't seem to make-fresh-node inside of fresh
[ForLoop (let* ([_ (printf "Started fresh for loop\n")]
[loopvar-name (binding-name (send this xsmith_get-reference-for-child! int #t))]
[proto-loopvar (make-fresh-node 'GlobalSet
(hash 'val (make-fresh-node 'LiteralInt)
'expr (make-fresh-node 'LiteralInt)))]
[global-name (ast-child 'name proto-loopvar)]
[global-get (make-fresh-node 'GlobalGet
(hash 'name global-name))]
'name loopvar-name
'expr (make-fresh-node 'LiteralInt)))] ;;dummy leaf node
[_ (printf (format "Chose loopvar name: ~a\n" loopvar-name))]
[zero (make-fresh-node 'LiteralInt
(hash 'v 0))]
[one (make-fresh-node 'LiteralInt
(hash 'v 1))]
[iteration (make-fresh-node ('Subtraction
(hash 'l global-get
'r one)))]
[comparison (make-fresh-node 'LessThanOrEqualSigned
(hash 'l zero
'r global-get))]
[loopvar-get1 (make-fresh-node 'GlobalGet
(hash 'name loopvar-name))]
[loopvar-get2 (make-fresh-node 'GlobalGet
(hash 'name loopvar-name))]
[subtraction (make-fresh-node 'Subtraction
(hash 'l loopvar-get1
'r one))]
[comparison (make-fresh-node 'GreaterThanSigned
(hash 'l loopvar-get2
'r zero))]
[branch (make-fresh-node 'BranchIf
(hash 'cond comparison))])
(hash 'cond comparison
'targetindex 0))] ;; Target the loop in order to loop
;; 'val is the loop body
[proto-loop (make-fresh-node 'GlobalSet
(hash 'val subtraction
'name loopvar-name
'expr branch))]
[_ (printf "Finished fresh for loop\n")])
(hash 'loopvar proto-loopvar
'iter (make-fresh-node 'GlobalSet
(hash 'val iteration
'name global-name
'expr branch))))]
'loop (make-fresh-node 'Loop
(hash 'expr proto-loop))))]
)
(add-att-rule
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment