;;; -*- mode: Lisp; Syntax: Common-Lisp; -*- ;;; ;;; Copyright (c) 2009 by the authors. ;;; ;;; See LICENCE for details. (in-package :hu.dwim.excosy) ;;;;;; ;;; object api (def (interface e) is-object? ((thing t)) boolean "Returns true iff THING is an object.") (def (interface e) is-immediate-object? ((instance object)) boolean "Returns true iff INSTANCE is an immediate object.") (def (interface e) object-type ((instance object)) object "Returns the type of INSTANCE that is shared between the instances of type.") (def (interface e) object-identity ((instance object)) integer "Returns the unique identity of INSTANCE as an integer. Returns the tagged bit representation for immediates and the tagged memory location for allocated objects.") (def (interface e) object-memory-location ((instance object)) (or null integer) "Returns the memory location of INSTANCE as a pointer into memory. Returns NIL if INSTANCE is an immediate.") (def (interface e) object-allocation-size ((instance object)) (or null integer) "Returns the memory allocation size of INSTANCE measured in bytes. Returns NIL if INSTANCE is an immediate.") (def (interface e) object-lisp-value ((instance object)) t "Returns the lisp value that is equivalent with the one represented by INSTANCE. Returns NIL if INSTANCE is not an immediate.") (def (interface e) read-object ((input t)) object "Reads an INSTANCE from the character sequence available from INPUT.") (def (interface e) print-object ((instance object) (output t)) (values) "Prints a character sequence representation of OBJECT into OUTPUT.") ;;;;;; ;;; type api (def (interface e) is-type? ((thing t)) boolean "Returns true iff THING is a type.") (def (interface e) is-immediate-type? ((type-instance type)) boolean "Returns true iff TYPE-INSTANCE is an immediate type.") (def (interface e) is-instance-of-type? ((object-instance object) (type-instance type)) boolean "Returns true iff OBJECT-INSTANCE is an instance of TYPE-INSTANCE.") (def (interface e) allocate-object ((type-instance type) (lisp-value t)) object "Allocates a fresh instance of TYPE-INSTANCE initialized to LISP-VALUE.") (def (interface e) type-allocation-size ((type-instance type)) integer "Returns the memory allocation size of instances of TYPE-INSTANCE measured in bytes. Returns NIL if instances of TYPE-INSTANCE are immediates.") (def (interface e) read-type-instance ((input t)) special-form "TODO") (def (interface e) print-type-instance ((instance object) (output t)) (values) "TODO") ;;;;;; ;;; special form api (def (interface e) is-special-form? ((thing t)) boolean "Returns true iff THING is a special form.") (def (interface e) read-special-form ((input t)) special-form "TODO") (def (interface e) print-special-form ((special-form special-form) (output t)) (values) "TODO") (def (interface e) interpret-special-form ((special-form special-form)) object "TODO") ;;;;;; ;;; object implementation (def class* object () ((type :type object) (identity :type integer) (memory-location :type (or null integer)) (allocation-size :type (or null integer)) (lisp-value :type t)) (:documentation "Represents a runtime value in the virtual machine.")) (def function is-object? (thing) (typep thing 'object)) (def function is-immediate-object? (instance) (null (allocation-size-of instance))) (def function object-type (instance) (type-of instance)) (def function object-identity (instance) (identity-of instance)) (def function object-memory-location (instance) (memory-location-of instance)) (def function object-allocation-size (instance) (allocation-size-of instance)) (def function object-lisp-value (instance) (lisp-value-of instance)) (def function read-object (input) ) (def function print-object (instance output) ) ;;;;;; ;;; type implementation (def class* type () ((name :type string) (immediate :type boolean) (tag-bits :type integer) (allocation-size :type (or null integer)) (allocator-function :type symbol) (reader-function :type symbol) (printer-function :type symbol) (interpreter-function :type symbol))) (def function is-type? (thing) (typep thing 'type)) (def function is-immediate-type? (type) (null (memory-allocator-of type))) (def function is-instance-of-type? (type instance) (eq type (type-of instance))) (def function allocate-object (type lisp-value) (funcall (allocator-function-of type) type lisp-value)) (def function type-allocation-size (type) ) ;;;;;; ;;; built-in types (def function make-no-value-type () (make-instance 'type :name "no-value" :immediate #t :allocation-size nil)) (def function make-no-meaningful-value-type () (make-instance 'type :name "no-meaningful-value" :immediate #t :allocation-size nil)) (def function make-boolean-type () (make-instance 'type :name "boolean" :immediate #t :allocation-size nil)) (def function make-tagged-integer-type () (make-instance 'type :name "tagged-integer" :immediate #t :allocation-size nil)) (def function make-native-integer-type () (make-instance 'type :name "native-integer" :immediate #t :allocation-size nil)) (def function make-big-integer-type () (make-instance 'type :name "big-integer" :immediate #f :allocation-size ???)) (def function make-null-type () (make-instance 'type :name "null" :immediate #t :allocation-size nil)) (def function make-cons-type () (make-instance 'type :name "cons" :immediate #f :allocation-size (* 2 +word-size+???))) (def function make-ascii-character-type () (make-instance 'type :name "ascii-character" :immediate #t :allocation-size 1)) (def function make-unicode-character-type () (make-instance 'type :name "single-byte-character" :immediate #t :allocation-size 4)) ;;;;;; ;;; special form implementation (def class* special-form () ())