module: dfmc-modeling Copyright: Original Code is Copyright (c) 1995-2004 Functional Objects, Inc. All rights reserved. License: Functional Objects Library Public License Version 1.0 Dual-license: GNU Lesser General Public License Warranty: Distributed WITHOUT WARRANTY OF ANY KIND define constant $max-signature-size = 256; define constant $max-default-signature-size = 16; define constant $max-mini-default-signature-size = 2; define function source-constructor-for-$signature-types (types-name, size) let types = ^make(, size: size); // initialization is completed in compute-signature at which // the definition is available let types-form-name = make-variable-name-fragment(types-name); #{ define constant ?types-form-name = ?types; } end function; define class () constant slot signature-type-vector-type-name :: , required-init-keyword: type-name:; constant slot signature-type-vector-definition-name :: , required-init-keyword: definition-name:; constant slot signature-type-vector-size :: , required-init-keyword: size:; end class; define function fill-model-objects (stv :: ) local method safe-dylan-value (name) block () dylan-value(name) exception () dylan-value(#"") end block end method; let type-name = signature-type-vector-type-name(stv); let defn-name = signature-type-vector-definition-name(stv); let types = dylan-value(defn-name); let type = safe-dylan-value(type-name); fill!(types, type); // HACK: SHOULDN'T BE NECESSARY types.model-definition := types.model-creator end function; define function ensure-signature-type-vector-initialized (x :: ) unless (x[0]) for (stv in $signature-type-vectors) fill-model-objects(stv); end for; end unless; x end function; define function compute-signature-type-vector-definition-name (type-name :: ) => (definition-name :: ) as(, format-to-string("$signature-%s-types", type-name)) end function; define macro signature-type-vector-table-definer { define signature-type-vector-table ?table-name:name = { ?entries } } => { define constant ?table-name :: = make(
); begin let the-table = ?table-name; ?entries end; } entries: { } => { } { ?:name => ?size:expression, ... } => { the-table[ ?#"name" ] := make(, type-name: ?#"name", definition-name: compute-signature-type-vector-definition-name(?#"name"), size: ?size); ... } end macro signature-type-vector-table-definer; define signature-type-vector-table $signature-type-vectors = { // MOST-USED DRM CLASS => $max-signature-size, // OFT-USED DRM CLASSES => $max-default-signature-size, => $max-default-signature-size, => $max-default-signature-size, => $max-default-signature-size, => $max-default-signature-size, => $max-default-signature-size, => $max-default-signature-size, => $max-default-signature-size, => $max-default-signature-size, => $max-default-signature-size, => $max-default-signature-size, => $max-default-signature-size, => $max-default-signature-size, => $max-default-signature-size, => $max-default-signature-size, // REST OF DRM CLASSES => $max-mini-default-signature-size, => $max-mini-default-signature-size, => $max-mini-default-signature-size, => $max-mini-default-signature-size, => $max-mini-default-signature-size, => $max-mini-default-signature-size, => $max-mini-default-signature-size, => $max-mini-default-signature-size, => $max-mini-default-signature-size, => $max-mini-default-signature-size, => $max-mini-default-signature-size, => $max-mini-default-signature-size, => $max-mini-default-signature-size, => $max-mini-default-signature-size, => $max-mini-default-signature-size, => $max-mini-default-signature-size, => $max-mini-default-signature-size, => $max-mini-default-signature-size,
=> $max-mini-default-signature-size, => $max-mini-default-signature-size, => $max-mini-default-signature-size, => $max-mini-default-signature-size, => $max-mini-default-signature-size, => $max-mini-default-signature-size, => $max-mini-default-signature-size, => $max-mini-default-signature-size, => $max-mini-default-signature-size, => $max-mini-default-signature-size, => $max-mini-default-signature-size, => $max-mini-default-signature-size, => $max-mini-default-signature-size, => $max-mini-default-signature-size, => $max-mini-default-signature-size, => $max-mini-default-signature-size, => $max-mini-default-signature-size, => $max-mini-default-signature-size, => $max-mini-default-signature-size, => $max-mini-default-signature-size, // => $max-mini-default-signature-size, // DYLAN EXTENSIONS => $max-mini-default-signature-size, => $max-mini-default-signature-size, => $max-mini-default-signature-size, => $max-mini-default-signature-size, => $max-mini-default-signature-size, => $max-mini-default-signature-size, => $max-mini-default-signature-size, => $max-mini-default-signature-size, => $max-mini-default-signature-size, => $max-mini-default-signature-size, => $max-mini-default-signature-size, => $max-mini-default-signature-size, => $max-mini-default-signature-size, => $max-mini-default-signature-size, => $max-mini-default-signature-size, => $max-mini-default-signature-size, => $max-mini-default-signature-size, => $max-mini-default-signature-size, => $max-mini-default-signature-size, => $max-mini-default-signature-size, => $max-mini-default-signature-size, => $max-mini-default-signature-size, => $max-mini-default-signature-size, => $max-mini-default-signature-size, => $max-mini-default-signature-size, => $max-mini-default-signature-size }; define constant $basic-object-types-name = signature-type-vector-definition-name ($signature-type-vectors[#""]); for (sig-type-vec in $signature-type-vectors) do-define-core-unadorned-definition (signature-type-vector-definition-name(sig-type-vec), curry(source-constructor-for-$signature-types, signature-type-vector-definition-name(sig-type-vec), signature-type-vector-size(sig-type-vec))); end for; define inline function ^signature-default-types-if-computed () let binding = dylan-binding($basic-object-types-name); untracked-binding-model-object-if-computed(binding) end function; define inline function ^signature-default-types () dylan-value($basic-object-types-name); end function; define inline function ^signature-default-rest-value () dylan-value(#"") end function; define method as-sig-types (x :: ) => (types :: ) as-sig-types(as(, x)) end method; define method as-sig-types (x :: ) => (types :: ) let sig-size = size(x); if (sig-size > 0 & ^instance?(x[0], dylan-value(#""))) let type-name = as(, ^debug-name(x[0])); let sig-type-vec :: false-or() = element($signature-type-vectors, type-name, default: #f); if (sig-type-vec & sig-size <= signature-type-vector-size(sig-type-vec)) let type = dylan-value(type-name); if (every?(curry(\==, type), x)) let types-name = signature-type-vector-definition-name(sig-type-vec); ensure-signature-type-vector-initialized(dylan-value(types-name)) else immutable-model(x) end if else immutable-model(x) end if else immutable-model(x) end if end method; //// //// SIGNATURE //// define primary &class () &slot signature-properties :: , init-keyword: properties:, init-value: 0; runtime-constant &slot signature-required :: , required-init-keyword: required:; end &class; define primary &class () end &class; define function compute-signature-definition-name (type-name :: , rest-value? :: , size :: ) => (definition-name :: ) as(, format-to-string ("$signature-%s-%s-rest-value-%d", type-name, if (rest-value?) "object" else "no" end, size)) end function; define constant $object-no-rest-value-signature-definition-names :: = make(, size: $max-default-signature-size); define constant $object-object-rest-value-signature-definition-names :: = make(, size: $max-default-signature-size); define function source-constructor-for-$object-signature (sig-name, rest-value?, size) let sig = ^make(<&object-signature>, number-required: size, required: #[], rest-value?: rest-value?, default-values?: #t); // initialization is completed in compute-signature at which // the definition is available let sig-form-name = make-variable-name-fragment(sig-name); #{ define constant ?sig-form-name = ?sig; } end function; define function object-signature-definition-names (rest-value? :: ) => (res :: ) if (rest-value?) $object-object-rest-value-signature-definition-names; else $object-no-rest-value-signature-definition-names; end if end function; define function object-signature-definition-name (rest-value? :: , size :: ) object-signature-definition-names(rest-value?)[size] end function; define function object-signature-definition-name-setter (name, rest-value? :: , size :: ) object-signature-definition-names(rest-value?)[size] := name end function; define function lookup-object-signature (number-required :: , rest-value?, rest-value) => (res :: false-or(<&object-signature>)) let object-sig-types = ^signature-default-types(); let sig-name = object-signature-definition-name(rest-value?, number-required); let sig = dylan-value(sig-name); unless (^signature-required(sig) == object-sig-types) for (rest-value? in #[#t, #f]) for (number-required from 0 below $max-default-signature-size) let sig-name = object-signature-definition-name(rest-value?, number-required); let sig = dylan-value(sig-name); ^signature-required(sig) := object-sig-types; end for; end for; end unless; sig end function; for (rest-value? in #[#t, #f]) for (size from 0 below $max-default-signature-size) let definition-name = compute-signature-definition-name(#"", rest-value?, size); object-signature-definition-name(rest-value?, size) := definition-name; do-define-core-unadorned-definition (definition-name, curry(source-constructor-for-$object-signature, definition-name, rest-value?, size)) end for; end for; define method ^signature-values (sig :: <&signature>) => (res :: ) if (^signature-default-values?(sig)) ^signature-default-types() else #[] end if end method; define &class () runtime-constant &slot signature-values :: , required-init-keyword: values:; end &class; define method ^signature-rest-value (sig :: <&signature>) => (res) ^signature-rest-value?(sig) & ^signature-default-rest-value() end method; define &class () runtime-constant &slot signature-rest-value, // :: &false-or(<&type>) required-init-keyword: rest-value:; end &class; define &class (, ) end &class; define &class (, ) end &class; define &class (, ) end &class; define primary &class () runtime-constant &slot signature-keys :: , required-init-keyword: keys:; runtime-constant &slot signature-key-types :: , required-init-keyword: key-types:; end &class; define method ^signature-keys (sig :: <&signature>) #[] end method; define &class (, ) end &class; define &class (, ) end &class; define &class (, ) end &class; define method ^signature-number-keys (sig :: <&keyword-signature>) => (result :: ) size(^signature-keys(sig)) end method ^signature-number-keys; define method ^make (class == <&signature>, #rest all-keys, #key number-required, required, key?, values, rest-value?, rest-value, number-values, rest?, next?, sealed-domain?, #all-keys) => (res :: <&signature>) let default-values? = every?(curry(\==, dylan-value(#"")), values); let default-rest-value? = ~rest-value | rest-value == dylan-value(#""); if (~key? & default-values? & default-rest-value?) let (sig-default-types, sig-default-types-computed?) = ^signature-default-types-if-computed(); if (sig-default-types-computed? & required == sig-default-types & number-required < $max-default-signature-size & ~rest? & ~next? & ~sealed-domain? & number-values = 0 & (~rest-value? | default-rest-value?)) lookup-object-signature(number-required, rest-value?, rest-value) else apply(next-method, <&signature>, default-values?: default-values?, all-keys) end if else apply(^make, if (key?) if (default-values?) if (default-rest-value?) <&keyword-signature> else <&keyword-signature+rest-value> end if else if (default-rest-value?) <&keyword-signature+values> else <&keyword-signature+values+rest-value> end if end if else if (default-values?) <&signature+rest-value> else if (default-rest-value?) <&signature+values> else <&signature+values+rest-value> end if end if end if, default-values?: default-values?, all-keys) end if; end method; /* define inline method ^pack-signature-properties (#rest all-keys, #key, #all-keys) apply(compute-initial-packed-slot, 0, make(<&signature>, required: #()), all-keys); end method; */ define method ^pack-signature-properties (#rest all-keys, #key, #all-keys) // HACK: WASTEFUL --- PICK SMALLEST CONCRETE CLASS let sig = apply(^make, <&signature+values>, required: #[], values: #[], all-keys); // apply(initialize-packed-slots, sig, all-keys); ^signature-properties(sig) end method; define method ^initialize (sig :: <&signature>, #rest all-keys, #key properties, next?, sealed-domain?, default-values?, #all-keys) next-method(); if (properties) ^signature-next?(sig) := next?; ^signature-sealed-domain?(sig) := sealed-domain?; ^signature-default-values?(sig) := default-values?; else apply(initialize-packed-slots, sig, all-keys) end if; end method; define leaf packed-slots ^signature-properties (<&signature>, ) field slot ^signature-number-required = 0, field-size: 8, init-keyword: number-required:; field slot ^signature-number-values = 0, field-size: 8, init-keyword: number-values:; boolean slot ^signature-key? = #f, init-keyword: key?:; boolean slot ^signature-all-keys? = #f, init-keyword: all-keys?:; boolean slot ^signature-rest? = #f, init-keyword: rest?:; boolean slot ^signature-rest-value? = #f, init-keyword: rest-value?:; boolean slot ^signature-next? = #f, init-keyword: next?:; boolean slot ^signature-default-values? = #f, init-keyword: default-values?:; boolean slot ^signature-sealed-domain? = #f, init-keyword: sealed-domain?:; boolean slot ^signature-complete? = #t, init-keyword: complete?:; end packed-slots; ignore(^signature-next?); ignore(^signature-complete?); define method ^signature-optionals? (sig :: <&signature>) => (result :: ) ^signature-key?(sig) | ^signature-rest?(sig) end method ^signature-optionals?; define method ^signature-number-keys (sig :: <&signature>) => (result :: ) 0 end method ^signature-number-keys; // , // , // , // , // , // , // , // , // , // , // , // , // , // , // , // , // , // , // , // , // , // , // , // , // , // , // , // , // , // , // , // , // , // , // , // , // , // , // , // , // , // , // , // , // , // , // , // , // , // , // , // , // , // , // , // , // , // , // , // , // , // , // , // , // , // , // , // , // , // , // , // , // , // , // , // , // , // , // , // , // , // , // , // , // , // , // , // , // , // , // , // , // , // , // , // , // , // , // , // , // , // , // , // , // , // , // , // , // , // , // , // , // , // , // , // , // , // , // , // , // , // , // , // , // , // , // , // , // , // , // , // , // , // , // , // , // , // , // , // , // , // , // , // , // , // , // , // , // , // , // , // , // , // , // , // , // , // , // , // , // , // , // , // , // , // , // , // , // , // , // , // , // , // , // , // , // , // , // , // , // , // , // , // , // , // , // , // , // , // , // , // , // , // , // , // , // , // , // , // , // , // , // , // , // , // , // , // , // , // , // , // , // , // , // , // , // , // , // , // , // , // , // , // , // , // , // , // , // , // , // , // , // , // , // , // , // , // , // , // , // , // , // , // , // , // , // , // , // , // , // , //
, // , // , // , // , // , // , // , // , // , // , // , // , // , // , // , // , // , // , // , // , // , // , // , // , // , // , // , // , // , // // // , // , // , // , // , // , // , // , // , // , // , // , // , // , // , // , // , // , // , // , // , // , // , // , // , // , // , // , // , // , // , // , // , // , // , // , // , // , // , // , // , // , // , // , // , // , // , // , // , // , // , // , // , // , // , // , // , // , // , // , // , // , // , // , // , // , // , // , // , // , // , // , // , // , // , // , // , // , // , // , // , // , // , // , // , // , // , // , // , // , // , // , // , // , // , // , // , // , // , // , // , // , // , // , // , // , // , // , // , // , // , // , // , // , // , // , // , // , // , // , // , // , // , // , // , // , // , // , // , // , // , // , // , // , // , // , // , // , // , // , // , // , // , // , // , // , // , // , // , // , // , // , // , // , // , // , // , // , // , // , // , // , // , // , // , // , // , // , // , // , // , // , // , // , // , // , // , // , // , // , // , // , // , // , // , // , // , // , // , // , // , // , // , // , // , // , // , // , // , // , // , // , // , // , // , // , // , // , // , // , // , // , // , // , // , // , // , // , // , // , // , // , // , // , // , // , // , // , // , // , // , // , // , // , // , // , // , // , // , // , // , // , // , // , // , // , // , // , // , // , // , //
, // , // , // , // , // , // , // , // , // , // , // , // , // , // , // , // , // , // , // , // , // , // , // , // , // , // , // , // , // , // // // , // , // , // , // , // , // , // , // , // , // ; // , // , // , // , // , // , // , // // , // , // , // , // , // , // , // , // , // , // , // , // , // , // , // , // , // , //
, // , // , // , // , // , // , // , // , // , // , // , // , // , // , // , // , // , // , // , // , // // , // ; // , // , // , // , // , // , // , // , // , // , // , // , // , // , // , // , // , // , // , // , // , // , // , // , // , // , // , // , // , // , // , // , // , // , // , // ; // , // ; // , // , // ,