Changeset 12861
- Timestamp:
- 08/05/10 19:16:22 (13 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
branches/generic-class-file/abcl/src/org/armedbear/lisp/jvm-class-file.lisp
r12856 r12861 280 280 (:include constant 281 281 (tag 7))) 282 "Structure holding information on a 'class' type item in the constant pool." 282 283 name-index) 283 284 … … 286 287 (tag index class-index name/type-index)) 287 288 (:include constant)) 289 "Structure holding information on a member reference type item 290 (a field, method or interface method reference) in the constant pool." 288 291 class-index 289 292 name/type-index) … … 308 311 (:include constant 309 312 (tag 8))) 313 "Structure holding information on a 'string' type item in the constant pool." 310 314 value-index) 311 315 … … 313 317 %make-constant-float/int (tag index value)) 314 318 (:include constant)) 319 "Structure holding information on a 'float' or 'integer' type item 320 in the constant pool." 315 321 value) 316 322 … … 327 333 %make-constant-double/long (tag index value)) 328 334 (:include constant)) 335 "Structure holding information on a 'double' or 'long' type item 336 in the constant pool." 329 337 value) 330 338 … … 344 352 (:include constant 345 353 (tag 12))) 354 "Structure holding information on a 'name-and-type' type item in the 355 constant pool; this type of element is used by 'member-ref' type items." 346 356 name-index 347 357 descriptor-index) … … 350 360 (:include constant 351 361 (tag 1))) 362 "Structure holding information on a 'utf8' type item in the constant pool; 363 364 This type of item is used for text representation of identifiers 365 and string contents." 352 366 value) 353 367 … … 489 503 (defstruct (class-file (:constructor 490 504 !make-class-file (class superclass access-flags))) 505 "Holds the components of a class file." 491 506 (constants (make-pool)) 492 507 access-flags 493 508 class 494 509 superclass 510 ;; support for implementing interfaces not yet available 495 511 ;; interfaces 496 512 fields … … 690 706 691 707 (defstruct (field (:constructor %make-field)) 692 " "708 "Holds information on the properties of fields in the class(-file)." 693 709 access-flags 694 710 name … … 697 713 698 714 (defun !make-field (name type &key (flags '(:public))) 699 715 "Creates a field for addition to a class file." 700 716 (%make-field :access-flags flags 701 717 :name name … … 703 719 704 720 (defun field-add-attribute (field attribute) 721 "Adds an attribute to a field." 705 722 (push attribute (field-attributes field))) 706 723 707 724 (defun field-attribute (field name) 725 "Retrieves an attribute named `name' of `field'. 726 727 Returns NIL if the attribute isn't found." 708 728 (find name (field-attributes field) 709 729 :test #'string= :key #'attribute-name)) 710 730 711 731 (defun finalize-field (field class) 732 "Prepares `field' for serialization." 712 733 (let ((pool (class-file-constants class))) 713 734 (setf (field-access-flags field) … … 720 741 721 742 (defun !write-field (field stream) 743 "Writes classfile representation of `field' to `stream'." 722 744 (write-u2 (field-access-flags field) stream) 723 745 (write-u2 (field-name field) stream) … … 727 749 728 750 (defstruct (method (:constructor %!make-method)) 751 "Holds information on the properties of methods in the class(-file)." 729 752 access-flags 730 753 name … … 748 771 749 772 (defun !make-method (name return args &key (flags '(:public))) 773 "Creates a method for addition to a class file." 750 774 (%!make-method :descriptor (cons return args) 751 775 :access-flags flags … … 776 800 777 801 (defun method-attribute (method name) 802 "Returns the first attribute of `method' with `name'." 778 803 (find name (method-attributes method) 779 804 :test #'string= :key #'attribute-name)) … … 781 806 782 807 (defun finalize-method (method class) 808 "Prepares `method' for serialization." 783 809 (let ((pool (class-file-constants class))) 784 810 (setf (method-access-flags method) … … 792 818 793 819 (defun !write-method (method stream) 820 "Write class file representation of `method' to `stream'." 794 821 (write-u2 (method-access-flags method) stream) 795 822 (write-u2 (method-name method) stream) … … 799 826 800 827 (defstruct attribute 828 "Parent attribute structure to be included into other attributes, mainly 829 to define common fields. 830 831 Having common fields allows common driver code for 832 finalizing and serializing attributes." 801 833 name 802 834 … … 807 839 808 840 (defun finalize-attributes (attributes att class) 841 "Prepare `attributes' (a list) of attribute `att' list for serialization." 809 842 (dolist (attribute attributes) 810 843 ;; assure header: make sure 'name' is in the pool … … 816 849 817 850 (defun write-attributes (attributes stream) 851 "Writes the `attributes' to `stream'." 818 852 (write-u2 (length attributes) stream) 819 853 (dolist (attribute attributes) … … 835 869 (writer #'!write-code)) 836 870 (:constructor %make-code-attribute)) 871 "The attribute containing the actual JVM byte code; 872 an attribute of a method." 837 873 max-stack 838 874 max-locals … … 851 887 852 888 (defun code-label-offset (code label) 889 "Retrieves the `label' offset within a `code' attribute after the 890 attribute has been finalized." 853 891 (cdr (assoc label (code-labels code)))) 854 892 855 893 (defun (setf code-label-offset) (offset code label) 894 "Sets the `label' offset within a `code' attribute after the attribute 895 has been finalized." 856 896 (setf (code-labels code) 857 897 (acons label offset (code-labels code)))) 858 898 859 860 861 899 (defun !finalize-code (code parent class) 900 "Prepares the `code' attribute for serialization, within method `parent'." 862 901 (declare (ignore parent)) 863 902 (let ((c (resolve-instructions (coerce (reverse (code-code code)) 'vector)))) … … 885 924 886 925 (defun !write-code (code stream) 926 "Writes the attribute `code' to `stream'." 887 927 (sys::%format t "max-stack: ~a~%" (code-max-stack code)) 888 928 (write-u2 (code-max-stack code) stream) … … 918 958 919 959 (defun code-attribute (code name) 960 "Returns an attribute of `code' identified by `name'." 920 961 (find name (code-attributes code) 921 962 :test #'string= :key #'attribute-name)) … … 923 964 924 965 (defun code-add-exception-handler (code start end handler type) 966 "Adds an exception handler to `code' protecting the region from 967 labels `start' to `end' (inclusive) from exception `type' - where 968 a value of NIL indicates all types. Upon an exception of the given 969 type, control is transferred to label `handler'." 925 970 (push (make-exception :start-pc start 926 971 :end-pc end … … 930 975 931 976 (defstruct exception 977 "Exception handler information. 978 979 After finalization, the fields contain offsets instead of labels." 932 980 start-pc ;; label target 933 981 end-pc ;; label target … … 974 1022 975 1023 1024 ;; ### Can't be used yet: no serialization 976 1025 (defstruct (source-file-attribute (:conc-name source-) 977 1026 (:include attribute 978 1027 (name "SourceFile"))) 1028 "An attribute of the class file indicating which source file 1029 it was compiled from." 979 1030 filename) 980 1031 1032 ;; ### Can't be used yet: no serialization 981 1033 (defstruct (line-numbers-attribute (:include attribute 982 1034 (name "LineNumberTable"))) 983 line-numbers) 1035 "An attribute of `code-attribute', containing a mapping of offsets 1036 within the code section to the line numbers in the source file." 1037 line-numbers ;; a list of line-number structures, in reverse order 1038 ) 984 1039 985 1040 (defstruct line-number 986 start-pc 1041 start-pc ;; a label, before finalization 987 1042 line) 988 1043 1044 ;; ### Can't be used yet: no serialization 989 1045 (defstruct (local-variables-attribute (:conc-name local-var-) 990 1046 (:include attribute 991 1047 (name "LocalVariableTable"))) 992 locals) 1048 "An attribute of the `code-attribute', containing a table of local variable 1049 names, their type and their scope of validity." 1050 locals ;; a list of local-variable structures, in reverse order 1051 ) 993 1052 994 1053 (defstruct (local-variable (:conc-name local-)) 995 start-pc 1054 start-pc ;; a label, before finalization 996 1055 length 997 1056 name 998 1057 descriptor 999 index) 1058 index ;; The index of the variable inside the block of locals 1059 ) 1000 1060 1001 1061 #|
Note: See TracChangeset
for help on using the changeset viewer.