~cmpitg/tim-judge/redesign-0.1

« back to all changes in this revision

Viewing changes to src/conf-data-structures.lisp

  • Committer: Dương "Yang" ヤン Hà Nguyễn
  • Date: 2011-05-13 03:11:57 UTC
  • Revision ID: cmpitg@gmail.com-20110513031157-og00e31n375lt9p7
Cleaning up

Show diffs side-by-side

added added

removed removed

Lines of Context:
9
9
 
10
10
(in-package #:tim-judge)
11
11
 
12
 
(defparameter *languages-compilers*
13
 
  '(:python "cpython"
14
 
    :c      "gcc"
15
 
    :c++    "g++"
16
 
    :go     "6g"
17
 
    :pascal "fpc"))
18
 
 
19
 
(defparameter *languages-interpreters*
20
 
  '(:python "python"))
21
 
 
22
 
(defparameter *languages-extensions*
23
 
  '(:python "py"
24
 
    :c      "c"
25
 
    :c++    "cpp"
26
 
    :pascal "pas"
27
 
    :go     "go"))
28
 
 
29
 
(defparameter *test-extensions*
30
 
  '(:input "in"
31
 
    :output "out"
32
 
    :answer "ans"))
33
 
 
34
 
(defun make-accessor (slot-name)
35
 
  "Make accessor from slot-name for class generating."
36
 
  (intern (concatenate 'string
37
 
                       "CONF-"
38
 
                       (string-upcase (string slot-name)))))
39
 
 
40
 
(defun make-initarg (slot-name)
41
 
  "Make initarg from slot-name for class generating"
42
 
  (intern (string slot-name) "KEYWORD"))
43
 
 
44
 
(defun make-class-from-structure (s
45
 
                                  &optional (class-name 'judge-config))
46
 
  "Generate a class from a convenient user-defined variable."
47
 
  (eval `(defclass ,class-name ()
48
 
           ,(loop
49
 
               for slot in s
50
 
               collect
51
 
               (let* ((slot-name (nth 0 slot))
52
 
                      (slot-init-value (nth 1 slot)))
53
 
                 (list slot-name
54
 
                       :accessor (make-accessor slot-name)
55
 
                       :initarg  (make-initarg slot-name)
56
 
                       :initform slot-init-value))))))
57
 
 
58
12
(defun make-dump-string (class-structure)
59
13
  (format nil "~{~{~a~*~}: ~~15a~~%~}" class-structure))
60
 
 
61
 
(defun get-slot-value (slot-name obj)
62
 
  (eval `(funcall #',(intern (concatenate 'string "CONF-"
63
 
                                          (symbol-name slot-name))) ,obj)))
64
 
 
65
 
(defun make-dump-parameters (class-structure class-object)
66
 
  (loop
67
 
     for slot in class-structure
68
 
     collect (get-slot-value (first slot) class-object)))
69
 
 
70
 
(defun dump-class (obj class-structure &optional (stream *standard-output*))
71
 
  (apply #'format stream (make-dump-string class-structure)
72
 
         (make-dump-parameters class-structure obj)))