File: test403.thp

package info (click to toggle)
theme-d 7.2.4-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 21,036 kB
  • sloc: lisp: 9,625; sh: 5,321; makefile: 715; ansic: 477
file content (83 lines) | stat: -rw-r--r-- 2,593 bytes parent folder | download | duplicates (2)
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
;; -*-theme-d-*-

;; Copyright (C) 2016 Tommi Höynälänmaa
;; Distributed under GNU General Public License version 3,
;; see file doc/GPL-3.

;; Expected results: translation and running OK


(define-proper-program (tests test403)

  (import (standard-library core)
	  (standard-library list-utilities)
	  (standard-library object-string-conversion)
	  (standard-library console-io))

  (define-param-logical-type :hash-proc (%key)
    (:procedure (%key <integer>) <integer> pure))

  (define-param-logical-type :assoc-proc (%key %value)
    (:procedure (%key (:alist %key %value)) (:maybe (:pair %key %value))
		pure))

  (define-param-class :hash-table
    (parameters %key %value)
    (fields
     (v (:maybe (:mutable-vector (:alist %key %value))) public module null)
     (proc-hash (:maybe (:hash-proc %key)) public module null)
     (proc-assoc (:maybe (:assoc-proc %key %value)) public module null)))

  (define-param-virtual-method initialize (%key %value)
		       (((ht (:hash-table %key %value))
			 (i-size <integer>)
			 (proc-hash (:hash-proc %key))
			 (proc-assoc (:assoc-proc %key %value)))
			<none>
			nonpure)
    (console-display-string "initialize (:hash-table ...)\n")
    (field-set! ht 'v (make-mutable-vector (:alist %key %value) i-size null))
    (field-set! ht 'proc-hash proc-hash)
    (field-set! ht 'proc-assoc proc-assoc))

  (define-param-class :logged-hash-table
    (parameters %key %value)
    (superclass (:hash-table %key %value)))

  (define my-hash
    (:hash-proc <symbol>)
    (unchecked-prim-proc hashv (<symbol> <integer>) <integer> pure))

  (define-simple-proc my-assoc (((s-key <symbol>)
				 (al (:alist <symbol> <string>)))
				(:maybe (:pair <symbol> <string>))
				pure)
    (assoc-objects s-key al null))

  (define-param-virtual-method initialize (%key %value)
		       (((ht (:logged-hash-table %key %value))
			 (i-size <integer>)
			 (proc-hash (:hash-proc %key))
			 (proc-assoc (:assoc-proc %key %value)))
			<none>
			nonpure)
    (console-display-string "initialize (:logged-hash-table ...)\n")
    ((generic-proc-dispatch-without-result
      initialize
      ((:hash-table %key %value)
       <integer>
       (:hash-proc %key)
       (:assoc-proc %key %value))
      ())
     ht i-size proc-hash proc-assoc))

  (define-main-proc (() <none> nonpure)
    (let ((ht
	   (let ((ht1 (create (:logged-hash-table <symbol> <string>))))
	     (initialize ht1 100 my-hash my-assoc)
	     ht1)))
      (console-display-line
       (mutable-vector-ref
	(cast (:mutable-vector (:alist <symbol> <string>))
	      (field-ref ht 'v))
	1)))))