Changeset 12862


Ignore:
Timestamp:
08/05/10 20:20:18 (12 years ago)
Author:
ehuelsmann
Message:

Implement serialization for SOURCE-FILE-ATTRIBUTE,
LINE-NUMBERS-ATTRIBUTE and LOCAL-VARIABLES-ATTRIBUTE.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • branches/generic-class-file/abcl/src/org/armedbear/lisp/jvm-class-file.lisp

    r12861 r12862  
    10221022
    10231023
    1024 ;; ### Can't be used yet: no serialization
    10251024(defstruct (source-file-attribute (:conc-name source-)
    10261025                                  (:include attribute
    1027                                             (name "SourceFile")))
     1026                                            (name "SourceFile")
     1027                                            (finalizer #'finalize-source-file)
     1028                                            (writer #'write-source-file)))
    10281029  "An attribute of the class file indicating which source file
    10291030it was compiled from."
    10301031  filename)
    10311032
    1032 ;; ### Can't be used yet: no serialization
    1033 (defstruct (line-numbers-attribute (:include attribute
    1034                                              (name "LineNumberTable")))
     1033(defun finalize-source-file (source-file code class)
     1034  (declare (ignorable code class))
     1035  (setf (source-filename source-file)
     1036        (pool-add-utf8 (class-file-constants class)
     1037                       (source-filename source-file))))
     1038
     1039(defun write-source-file (source-file stream)
     1040  (write-u2 (source-filename source-file) stream))
     1041
     1042
     1043
     1044(defstruct (line-numbers-attribute
     1045             (:conc-name line-numbers-)
     1046             (:include attribute
     1047                       (name "LineNumberTable")
     1048                       (finalizer #'finalize-line-numbers)
     1049                       (writer #'write-line-numbers)))
    10351050  "An attribute of `code-attribute', containing a mapping of offsets
    10361051within the code section to the line numbers in the source file."
    1037   line-numbers ;; a list of line-number structures, in reverse order
     1052  table ;; a list of line-number structures, in reverse order
    10381053  )
    10391054
     
    10421057  line)
    10431058
    1044 ;; ### Can't be used yet: no serialization
    1045 (defstruct (local-variables-attribute (:conc-name local-var-)
    1046                                       (:include attribute
    1047                                                 (name "LocalVariableTable")))
     1059(defun finalize-line-numbers (line-numbers code class)
     1060  (declare (ignorable code class))
     1061  (dolist (line-number (line-numbers-table line-numbers))
     1062    (setf (line-number-start-pc line-number)
     1063          (code-label-offset code (line-number-start-pc line-number)))))
     1064
     1065(defun write-line-numbers (line-numbers stream)
     1066  (write-u2 (length (line-numbers-table line-numbers)) stream)
     1067  (dolist (line-number (reverse (line-numbers-table line-numbers)))
     1068    (write-u2 (line-number-start-pc line-number) stream)
     1069    (write-u2 (line-number-line line-number) stream)))
     1070
     1071
     1072
     1073(defstruct (local-variables-attribute
     1074             (:conc-name local-var-)
     1075             (:include attribute
     1076                       (name "LocalVariableTable")
     1077                       (finalizer #'finalize-local-variables)
     1078                       (writer #'write-local-variables)))
    10481079  "An attribute of the `code-attribute', containing a table of local variable
    10491080names, their type and their scope of validity."
    1050   locals ;; a list of local-variable structures, in reverse order
     1081  table ;; a list of local-variable structures, in reverse order
    10511082  )
    10521083
    10531084(defstruct (local-variable (:conc-name local-))
    10541085  start-pc  ;; a label, before finalization
    1055   length
     1086  length    ;; a label (at the ending position) before finalization
    10561087  name
    10571088  descriptor
    10581089  index ;; The index of the variable inside the block of locals
    10591090  )
     1091
     1092(defun finalize-local-variables (local-variables code class)
     1093  (dolist (local-variable (local-var-table local-variables))
     1094    (setf (local-start-pc local-variable)
     1095          (code-label-offset code (local-start-pc local-variable))
     1096          (local-length local-variable)
     1097          ;; calculate 'length' from the distance between 2 labels
     1098          (- (code-label-offset code (local-length local-variable))
     1099             (local-start-pc local-variable))
     1100          (local-name local-variable)
     1101          (pool-add-utf8 (class-file-constants class)
     1102                         (local-name local-variable))
     1103          (local-descriptor local-variable)
     1104          (pool-add-utf8 (class-file-constants class)
     1105                         (local-descriptor local-variable)))))
     1106
     1107(defun write-local-variables (local-variables stream)
     1108  (write-u2 (length (local-var-table local-variables)) stream)
     1109  (dolist (local-variable (reverse (local-var-table local-variables)))
     1110    (write-u2 (local-start-pc local-variable) stream)
     1111    (write-u2 (local-length local-variable) stream)
     1112    (write-u2 (local-name local-variable) stream)
     1113    (write-u2 (local-descriptor local-variable) stream)
     1114    (write-u2 (local-index local-variable) stream)))
    10601115
    10611116#|
Note: See TracChangeset for help on using the changeset viewer.