Skip to content

Commit

Permalink
Add strat arg to makefile
Browse files Browse the repository at this point in the history
  • Loading branch information
bsaleil committed Jun 1, 2017
1 parent 5f07fe4 commit a89eaab
Show file tree
Hide file tree
Showing 3 changed files with 126 additions and 3 deletions.
10 changes: 7 additions & 3 deletions Makefile
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
GSC_FLAGS= -prelude "(declare (not safe))"
CONFIG_FILE= config-release.scm
LC_STRAT=strat1.scm

all: config types.o1 analyses.o1 float.o1 utils.o1 main.o1 native.o1 mem.o1 codegen.o1 ast.o1 core.o1 expand.o1 ctx.o1 lib
cp lazy-comp.template lazy-comp
Expand All @@ -11,15 +12,18 @@ debug: GSC_FLAGS= -debug
debug: CONFIG_FILE= config-debug.scm
debug: all

.PHONY: lib config
dummy:
@:

.PHONY: lib config dummy
lib:
gsi ./build-lib

config:
cp $(CONFIG_FILE) config.scm

types.o1: types.scm
gsc $(GSC_FLAGS) -o $@ $<
types.o1: $(and $(LC_STRAT),dummy)
gsc $(GSC_FLAGS) -o $@ $(LC_STRAT)

ctx.o1: ctx.scm
gsc $(GSC_FLAGS) -o $@ $<
Expand Down
File renamed without changes.
119 changes: 119 additions & 0 deletions strat2.scm
Original file line number Diff line number Diff line change
@@ -0,0 +1,119 @@
;;---------------------------------------------------------------------------
;;
;; Copyright (c) 2015, Baptiste Saleil. All rights reserved.
;;
;; Redistribution and use in source and binary forms, with or without
;; modification, are permitted provided that the following conditions are
;; met:
;; 1. Redistributions of source code must retain the above copyright
;; notice, this list of conditions and the following disclaimer.
;; 2. Redistributions in binary form must reproduce the above copyright
;; notice, this list of conditions and the following disclaimer in the
;; documentation and/or other materials provided with the distribution.
;; 3. The name of the author may not be used to endorse or promote
;; products derived from this software without specific prior written
;; permission.
;;
;; THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESS OR IMPLIED
;; WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
;; MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN
;; NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
;; INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
;; NOT LIMITED TO PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
;; DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
;; THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
;; (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
;; THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
;;
;;---------------------------------------------------------------------------

;; This is the most simple strategy
;; Generate lazy-code objects with given contexts until hard limit is reached
;; Then fallback to a generic version

(define opt-max-versions #f)
(define lazy-code-entry? #f)

(define lco_versions (make-table test: eq?))
(define lco_generic (make-table test: eq?))

;;------------------------------------------------------------------------------
;; PUBLIC

(define (lazy-code-versions lco)
(let ((versions (table-ref lco_versions lco #f)))
(or versions
(let ((versions (make-table)))
(table-set! lco_versions lco versions)
versions))))

(define (lazy-code-nb-versions lazy-code)
(table-length (lazy-code-versions lazy-code)))

(define (lazy-code-nb-real-versions lazy-code)
(count (table->list (lazy-code-versions lazy-code)) cddr))

;;------------------------------------------------------------------------------
;; PRIVATE

(define (lazy-code-generic lco)
(table-ref lco_generic lco #f))

(define (lazy-code-generic-set! lco ctx version)
(table-set! lco_generic lco (cons ctx version)))

(define (get-version lazy-code ctx)
(let* ((key (if (lazy-code-entry? lazy-code)
ctx;(ctx-stack ctx)
ctx))
(versions (lazy-code-versions lazy-code))
(version (table-ref versions key #f)))
(and version (car version))))

(define (put-version lazy-code ctx version real-version?)
(let ((key (if (lazy-code-entry? lazy-code)
ctx;(ctx-stack ctx)
ctx))
(versions (lazy-code-versions lazy-code)))
(table-set! versions key (cons version real-version?))))

(define (limit-reached? lco)
(and opt-max-versions
(let ((nb-versions (lazy-code-nb-real-versions lco)))
(>= nb-versions opt-max-versions))))

(define (strat-get-version lco ctx)

;; CASE 1: a version exists for this ctx, use it
(define (case-use-version version)
(list version ctx (lambda (r) r)))

;; CASE 2: no version for this ctx, and limit is not reached
;; then generate a new version
(define (case-gen-version)
(list #f ctx (lambda (label) (put-version lco ctx label #t))))

;; CASE 3: no version for this ctx, limit reached, generic exists
;; then use the generic version
(define (case-use-generic generic)
(let ((callback (lambda (label-merge) (put-version lco ctx label-merge #f))))
(list (cdr generic) (car generic) callback)))

;; CASE 4: no version for this ctx, limit reached, generic does not exist
;; then generate the generic version
(define (case-gen-generic)
(let* ((gctx (ctx-generic ctx))
(callback (lambda (label-merge label-version)
(put-version lco ctx label-merge #f)
(lazy-code-generic-set! lco gctx label-version))))
(list #f gctx callback)))

(let ((version (get-version lco ctx)))
(if version
(case-use-version version) ;; CASE 1
(if (not (limit-reached? lco))
(case-gen-version) ;; CASE 2
(let ((generic (lazy-code-generic lco)))
(if generic
(case-use-generic generic) ;; CASE 3
(case-gen-generic))))))) ;; CASE 4

0 comments on commit a89eaab

Please sign in to comment.