-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathui.scm
115 lines (102 loc) · 5.02 KB
/
ui.scm
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
#!r6rs
; This program and the accompanying materials are made available under the
; terms of the MIT license (X11 license) which accompanies this distribution.
; Author: R. Schöne
(library
(mquat ui)
(export cim hw req obj clauses-met? deploy-on use-next-impl
display-part display-ast)
(import (rnrs) (racr core) (racr testing)
(mquat constants) (mquat ast) (mquat basic-ag))
(define (name-or-type n) (if (ast-has-child? 'name n) (->name n) (ast-node-type n)))
(define (clauses-to-list loc)
(fold-left
(lambda (result clause)
(let ([returnType (->name (=real (->ReturnType clause)))]
[evalValue (=eval clause)]
[compName (comp->rev-string (->comparator clause))])
(cons
(if (ast-subtype? clause 'ProvClause) (list returnType compName evalValue)
(list returnType 'on (name-or-type (<<- (=real (->ReturnType clause))))
compName evalValue 'currently: (=actual-value clause)))
result)))
(list) loc))
; [Debugging] returns a list of the components, implementations and modes
; Form: (compI ((implI1 deployedon-I1 (mode-to-use-I1 ((propName min|max actual-value) ... ))) ...) ...)
(define (cim ast)
(letrec
([C (lambda (comp) (list (->name comp) (I (->* (->Impl* comp)))))]
[M (lambda (mode) (list (->name mode) (clauses-to-list (->* (->Clause* mode)))))]
[I (lambda (loi) ; [l]ist [o]f [i]mpls
(if (null? loi) (list)
(let* ([impl (car loi)]
[name (->name impl)])
(cons
(list
(=req-comp-map impl)
(if (=selected? impl) (string-append "*" name) name)
(if (=deployed-on impl) (->name (=deployed-on impl)) #f)
(if (=selected? impl) (M (=mode-to-use impl)) #f))
(I (cdr loi))))))])
(fold-left
(lambda (result comp) (cons (C comp) result))
(list)
(->* (->Comp* (->SWRoot ast))))))
; [Debugging] Returns a list of hardware resources along with their provided properties
; Form: (res1-type res1-name ((provClause1a-name -comp->string -actualValue) ... (res1-subresources ... )) ... )
(define (hw ast)
(letrec
([R (lambda (lor) ; [l]ist [o]f [r]esources
(if (null? lor) (list)
(let ([subs (R (->* (->SubResources (car lor))))]
[rest (R (cdr lor))])
(cons
(list
(->name (=type (car lor))) ; resource type name
(->name (car lor)) ; resource name
(clauses-to-list (->* (->ProvClause* (car lor))))) ; list of clauses
(if (null? subs) rest (cons subs rest))))))])
(R (->* (->SubResources (->HWRoot ast))))))
; [Debugging] Returns a list of the request
; Form: (((metaparam1-name -value) ... ) ((constraint1-name -comp->string -requiredValue) ... ) objective)
(define (req ast)
(letrec
([MP
(lambda (lomp) ; [l]ist [o]f [m]eta[p]arameter
(if (null? lomp) (list)
(cons (list (->name (car lomp)) (->value (car lomp)))
(MP (cdr lomp)))))])
(let* ([r (<=request ast)]
[o (->objective r)])
(list
(MP (->* (->MetaParameter* r))) ; metaparams
(clauses-to-list (->* (->Constraints r))) ; constraints
(if o (->name o) "default"))))) ; objective
;; Shortcuts
(define (clauses-met? ast) (att-value 'clauses-met? ast))
(define (obj ast) (=objective-val ast))
; Given a component (or an impl) and a resource, change deployed-on of the selected impl
; of the given component (or the given impl) to the given resource, returning the old resource
(define (deploy-on x new-pe) (rewrite-terminal 'deployedon (if (ast-subtype? x 'Comp) (=selected-impl x) x) (->name new-pe)))
(define (use-next-impl comp)
(let* ([former-impl (=selected-impl comp)]
[former-index (ast-child-index former-impl)]
[num-impls (ast-num-children (->Impl* comp))]
[former-deployed (=deployed-on former-impl)]
[new-index (+ (mod former-index num-impls) 1)]
[new-impl (ast-sibling new-index former-impl)]
[first-new-mode (car (->* (->Mode* new-impl)))])
(rewrite-terminal 'deployedon former-impl #f)
(rewrite-terminal 'selectedmode former-impl #f)
(rewrite-terminal 'selectedimpl comp (->name new-impl))
(rewrite-terminal 'deployedon new-impl (->name former-deployed))
(rewrite-terminal 'selectedmode new-impl (->name first-new-mode)) ; use first mode
new-impl))
(define (display-part node . attributes)
(define (print name) (cons name (lambda (v) v)))
; (define printer (list)); (print 'eval)))
(define printer (map (lambda (att) (print att)) (car attributes)))
; (display (car attributes)) (newline)
; (display (list 'remote-unit 'remote-container)) (newline)
(print-ast node printer (current-output-port)))
(define (display-ast ast . attributes) (display-part ast attributes)))