luv

Workshop wiki

frontier.lisp

luvcraft/frontier.lisp

system luvcraft/frontier · 96 definitions · on GitHub

Inspectable frontier programs over packed, domain-addressed work, and the compiler which closes one program over bound fields into a scalar loop.

Two languages meet here. The frontier language owns work-generating effects: pop a site, expose its relations, read and commit fields, admit another site, count evidence. The arithmetic language owns pure value laws: transfer, admission tests, and priorities, quantity-checked against the fields they read. A frontier-program-definition is the open, redefinable source; a frontier-realization is one compilation of it over particular field bindings, retaining the checked expressions, the emitted form, and the compiled function. #53Q1II

in-package#:luvcraft.frontier

------------------------------------------------------------------------ Program definitions

defunfrontier-word-p
formname

Whether form is the frontier language word name, in any package.

Programs and bindings are written in their client packages, so the language recognizes its few reserved words by name rather than by symbol identity.

and
symbolpform
form
not
keywordpform
string=formname
defclassfrontier-field-role
name:initarg:name:readerfrontier-field-role-name
relaxed-p:initarg:relaxed-p:initformnil:readerfrontier-field-role-relaxed-p
memo-p:initarg:memo-p:initformnil:readerfrontier-field-role-memo-p
invalidated-p:initarg:invalidated-p:initformnil:readerfrontier-field-role-invalidated-p
source-form:initarg:source-form:readerfrontier-field-role-source-form
:documentation

One field a program reads or writes by role name. RELAXED-P marks the best-known-value field of a monotone program; MEMO-P marks the visited identity of a discover-once program; INVALIDATED-P marks the field an invalidation program clears, whose source value is the level a cleared site had. Storage is bound at realization.

defclassfrontier-relation-predicate
name:initarg:name:readerfrontier-relation-predicate-name
kind:initarg:kind:readerfrontier-relation-predicate-kind
argument:initarg:argument:initformnil:readerfrontier-relation-predicate-argument
source-form:initarg:source-form:readerfrontier-relation-predicate-source-form
:documentation

A raw truth value about the relation being exposed: (DIRECTION= constant) or CROSSING. Predicates enter arithmetic laws as unchecked flags.

defclassfrontier-program-definition
name:initarg:name:readerfrontier-program-definition-name
family:initarg:family:readerfrontier-program-definition-family
frontier-layout:initarg:frontier-layout:readerfrontier-program-definition-frontier-layout
neighborhood:initarg:neighborhood:readerfrontier-program-definition-neighborhood
fields:initarg:fields:initformnil:readerfrontier-program-definition-fields
constants:initarg:constants:initformnil:readerfrontier-program-definition-constants
predicates:initarg:predicates:initformnil:readerfrontier-program-definition-predicates
transfer:initarg:transfer:initformnil:readerfrontier-program-definition-transfer
admission:initarg:admission:initformnil:readerfrontier-program-definition-admission
priority:initarg:priority:initformnil:readerfrontier-program-definition-priority
retain-admissions-p:initarg:retain-admissions-p:initformnil:readerfrontier-program-definition-retain-admissions-p
source-form:initarg:source-form:readerfrontier-program-definition-source-form
revision:initform
gensym"FRONTIER-PROGRAM-"
:readerfrontier-program-definition-revision
:documentation

One live semantic account of frontier-shaped materialization work. #X7Q90E

The definition names the dynamic family, physical frontier layout, and neighborhood at an aggregate boundary, and states its local law: field roles, realization constants, relation predicates, and the arithmetic TRANSFER, ADMISSION, and PRIORITY forms over them. Concrete methods on EXECUTE-FRONTIER-PROGRAM lower that account by hand; compile-frontier-program lowers it mechanically over bound fields.

defgenericfrontier-program-definition-for
name
:documentation

Return the live frontier program definition named by name.

defmethodfrontier-program-definition-for
name
declare
ignorename
nil
defunparse-frontier-field-role
form
destructuring-bind
name&keyrelaxedmemoinvalidated
if
conspform
form
listform
check-typenamesymbol
make-instance'frontier-field-role:namename:relaxed-prelaxed:memo-pmemo:invalidated-pinvalidated:source-formform
defunparse-frontier-relation-predicate
form
destructuring-bindform
check-typenamesymbol
cond
make-instance'frontier-relation-predicate:namename:kind:crossing:source-formform
make-instance'frontier-relation-predicate:namename:kind:direction=:argument:source-formform
t
error"Unknown frontier relation predicate ~S."form
defunmake-frontier-program-definition
name&keyfamilyfrontier-layoutneighborhoodfieldsconstantspredicatestransferadmissionpriorityretain-admissionssource-form
let
definition
make-instance'frontier-program-definition:namename:familyfamily:frontier-layoutfrontier-layout:neighborhoodneighborhood:fields:constantsconstants:predicates:transfertransfer:admissionadmission:prioritypriority:retain-admissions-pretain-admissions:source-formsource-form
definition
defmacrodefine-frontier-program
name&restoptions&keyfamilyfrontier-layoutneighborhoodfieldsconstantspredicatestransferadmissionpriorityretain-admissions

Define an inspectable frontier program at one EQL-specialized name.

declare
ignorefamilyfrontier-layoutneighborhoodfieldsconstantspredicatestransferadmissionpriorityretain-admissions
let
query
gensym"PROGRAM-NAME"
source-form`
`
progn
defmethodfrontier-program-definition-for
,query
eql',name
declare
ignore,query
load-time-value
make-frontier-program-definition',name,@
loopfor
keyvalue
onoptionsby#'cddrappend
listkey`',value
:source-form
',source-form
',name
defgenericnote-frontier-program-redefinition
name
:documentation

Notify retained realizations that program name changed.

defmethodnote-frontier-program-redefinition
name
declare
ignorename
nil
defunfrontier-program-relaxed-field
find-if#'frontier-field-role-relaxed-p
frontier-program-definition-fieldsdefinition
defunfrontier-program-memo-field
find-if#'frontier-field-role-memo-p
frontier-program-definition-fieldsdefinition
defunfrontier-program-invalidated-field
find-if#'frontier-field-role-invalidated-p
frontier-program-definition-fieldsdefinition

Families are the semantic dynamics of #DURBKN. Each family knows which roles a program must declare and what its default admission, commit, and priority laws are. A definition is checked against its family at definition time so a wrong program fails before any realization.

defgenericfrontier-family-check-definition
:documentation

Signal an error unless definition is well formed for family.

defmethodfrontier-family-check-definition
error"Unknown frontier program family ~S in ~S."family
frontier-program-definition-namedefinition
defmethodfrontier-family-check-definition
family
eql:monotone-max-fixpoint
definition
declare
ignorefamily
unless
=1
count-if#'frontier-field-role-relaxed-p
frontier-program-definition-fieldsdefinition
error"A monotone program needs exactly one :RELAXED field: ~S"
frontier-program-definition-namedefinition
unless
frontier-program-definition-transferdefinition
error"A monotone program needs a :TRANSFER law: ~S"
frontier-program-definition-namedefinition
defmethodfrontier-family-check-definition
family
eql:invalidation
definition
declare
ignorefamily
unless
=1
count-if#'frontier-field-role-invalidated-p
frontier-program-definition-fieldsdefinition
error"An invalidation program needs exactly one :INVALIDATED field: ~S"
frontier-program-definition-namedefinition
unless
frontier-program-definition-admissiondefinition
error"An invalidation program needs an :ADMISSION (dependency) test: ~S"
frontier-program-definition-namedefinition
defmethodfrontier-family-check-definition
family
eql:discover-once
definition
declare
ignorefamily
unless
=1
count-if#'frontier-field-role-memo-p
frontier-program-definition-fieldsdefinition
error"A discover-once program needs exactly one :MEMO field: ~S"
frontier-program-definition-namedefinition
unless
frontier-program-definition-admissiondefinition
error"A discover-once program needs an :ADMISSION test: ~S"
frontier-program-definition-namedefinition

------------------------------------------------------------------------ Packed frontier storage and execution evidence

records:define-columnar-bufferfrontier-site-buffer
materializationnil:typet:clear-on-removet
offset0:type
unsigned-byte32
defclassbucket-frontier
maximum-priority:initarg:maximum-priority:readerbucket-frontier-maximum-priority
priority-meaning:initarg:priority-meaning:initformnil:readerbucket-frontier-priority-meaning
buckets:initarg:buckets:readerbucket-frontier-buckets
current-priority:initform-1:accessorbucket-frontier-current-priority
count:initform0:accessorbucket-frontier-count
pushes:initform0:accessorbucket-frontier-pushes
pops:initform0:accessorbucket-frontier-pops
peak-count:initform0:accessorbucket-frontier-peak-count
:documentation

A finite highest-priority-first frontier of packed materialization sites.

Each bucket is a generated columnar buffer of aggregate identity plus dense offset. PRIORITY-MEANING retains the field or client declaration which gives the otherwise raw bucket number its meaning.

defunmake-bucket-frontier
&keymaximum-prioritypriority-meaning
initial-capacity256
check-typemaximum-priority
integer0#.most-positive-fixnum
check-typeinitial-capacity
integer0#.most-positive-fixnum
let
buckets
make-array
1+maximum-priority
dotimes
priority
lengthbuckets
setf
arefbucketspriority
make-frontier-site-buffer:capacityinitial-capacity
make-instance'bucket-frontier:maximum-prioritymaximum-priority:priority-meaningpriority-meaning:bucketsbuckets
defunbucket-frontier-empty-p
frontier
zerop
bucket-frontier-countfrontier
defunbucket-frontier-push
frontiermaterializationoffsetpriority

Admit one MATERIALIZATION/OFFSET site at finite priority.

check-typeoffset
unsigned-byte32
let
maximum-priority
bucket-frontier-maximum-priorityfrontier

A runtime-constructed `(INTEGER 0 ,maximum-priority) type specifier conses once per admission. Spell the same open-protocol check as primitive predicates so the packed frontier remains allocation-free.

unless
and
integerppriority
<=0prioritymaximum-priority
error"Frontier priority ~S is outside 0..~D."prioritymaximum-priority
frontier-site-buffer-push
aref
bucket-frontier-bucketsfrontier
priority
materializationoffset
incf
bucket-frontier-countfrontier
incf
bucket-frontier-pushesfrontier
setf
bucket-frontier-current-priorityfrontier
maxpriority
bucket-frontier-current-priorityfrontier
bucket-frontier-peak-countfrontier
max
bucket-frontier-countfrontier
bucket-frontier-peak-countfrontier
frontier
defunbucket-frontier-pop
frontier

Return MATERIALIZATION, OFFSET, PRIORITY, and PRESENT-P for the next site.

when
return-frombucket-frontier-pop
valuesnilnilnilnil
let*
priority
bucket-frontier-current-priorityfrontier
bucket
aref
bucket-frontier-bucketsfrontier
priority
multiple-value-bind
materializationoffsetpresent-p
frontier-site-buffer-popbucket
unlesspresent-p
error"Frontier count disagrees with priority bucket ~D."priority
decf
bucket-frontier-countfrontier
incf
bucket-frontier-popsfrontier
when
zerop
frontier-site-buffer-lengthbucket
loopforcandidatedownfrom
1-priority
to0when
plusp
frontier-site-buffer-length
aref
bucket-frontier-bucketsfrontier
candidate
do
setf
bucket-frontier-current-priorityfrontier
candidate
finally
setf
bucket-frontier-current-priorityfrontier
-1
valuesmaterializationoffsetpriorityt
defclassfrontier-execution
program:initarg:program:readerfrontier-execution-program
input:initarg:input:readerfrontier-execution-input
frontier:initarg:frontier:readerfrontier-execution-frontier
visits:initform0:accessorfrontier-execution-visits
relations:initform0:accessorfrontier-execution-relations
admissions:initform0:accessorfrontier-execution-admissions
crossings:initform0:accessorfrontier-execution-crossings
unavailable:initform0:accessorfrontier-execution-unavailable
emissions:initform0:accessorfrontier-execution-emissions
admitted-sites:initarg:admitted-sites:initformnil:readerfrontier-execution-admitted-sites
:documentation

Inspectable semantic work evidence from one frontier execution.

ADMITTED-SITES is a packed frontier-site-buffer of every admitted site when the program retains admissions, so a discover-once execution can hand its component to the client without a cons per member, and an invalidation execution its cleared set. EMISSIONS counts sites handed to a companion frontier, such as the surviving sources an invalidation discovers.

defunmake-frontier-execution
programinputfrontier&keyretain-admissions
make-instance'frontier-execution:program
orprogram
:inputinput:frontierfrontier:admitted-sites
andretain-admissions
make-frontier-site-buffer:capacity64
defunadmit-frontier-site
executionmaterializationoffsetpriority

Record one admitted relation and push its destination site.

incf
frontier-execution-admissionsexecution
bucket-frontier-push
frontier-execution-frontierexecution
materializationoffsetpriority
defmacrodo-voxel-frontier-relations
sourcesource-offsetprioritytargettarget-offsetdirectiondestinationcrossingavailabilityfrontierwindowdomaindirections&keyexecutionresult
&bodybody

Drain FRONTIER and execute body once for every spatial relation it exposes.

source is a retained aggregate materialization and SOURCE-OFFSET is its dense site identity. TARGET is the local source or a materialization selected by WINDOW at a crossing. DESTINATION has dynamic extent. The client body owns admission, transfer, mutation, and unavailable-neighbor semantics; the macro keeps traversal and value lifetimes visible to the compiler. This is the manually staged lowering which compile-frontier-program now generates. #X7Q90E

let
present-p
gensym"PRESENT-P"
local
gensym"LOCAL"
resolved
gensym"RESOLVED"
execution-value
gensym"EXECUTION"
`
let
,execution-value,execution
loopuntildo
multiple-value-bind
,source,source-offset,priority,present-p
declare
ignore,present-p
let
,local
chunk-domain-local-coordinate,domain,source-offset
declare
dynamic-extent,local
when,execution-value
incf
frontier-execution-visits,execution-value
do-chunk-window-neighbors
,target-offset,destination,crossing,direction,resolved,availability,window,domain,local,directions
when,execution-value
incf
frontier-execution-relations,execution-value
when,crossing
incf
frontier-execution-crossings,execution-value
when
eq,availability:unavailable
incf
frontier-execution-unavailable,execution-value
let
,target
ecase,availability
:local,source
:available,resolved
:unavailablenil
,@body
finally
return,result

------------------------------------------------------------------------ Field bindings: how one program role reaches physical storage

defclassfrontier-field-binding
name:initarg:name:readerfrontier-field-binding-name
declaration:initarg:declaration:initformnil:readerfrontier-field-binding-declaration
lanes:initarg:lanes:initformnil:readerfrontier-field-binding-lanes
read-template:initarg:read:readerfrontier-field-binding-read-template
write-template:initarg:write:initformnil:readerfrontier-field-binding-write-template
lazy-p:initarg:lazy:initformnil:readerfrontier-field-binding-lazy-p
:documentation

One program field role bound to storage reachable from a materialization.

declaration is the represented-value declaration (often a voxel field definition) giving the field its quantity and Lisp representation. LANES are (NAME FORM &key type): storage borrowed once per materialization, where FORM mentions the template variable MATERIALIZATION. READ and WRITE are forms over lane names, MATERIALIZATION, OFFSET, WINDOW, and (for WRITE) VALUE. A LAZY binding is read where the law mentions it rather than once up front, so a short-circuiting admission can skip an expensive probe. Templates are ordinary inspectable data; the compiler substitutes them into the emitted loop.

defunmake-frontier-field-binding
name&keydeclarationlanesreadwritelazy
check-typenamesymbol
make-instance'frontier-field-binding:namename:declarationdeclaration:laneslanes:readread:writewrite:lazylazy
defgenericfrontier-declaration-maximum-value
:documentation

Return the finite integer maximum a declaration's legal values allow.

defmethodfrontier-declaration-maximum-value
let
legal
luvcraft.world.fields:voxel-field-definition-legal-value-typedeclaration
and
consplegal
eq
firstlegal
'integer
integerp
thirdlegal
thirdlegal

------------------------------------------------------------------------ Realizations

defclassfrontier-realization
definition:initarg:definition:readerfrontier-realization-definition
revision:initarg:revision:readerfrontier-realization-revision
bindings:initarg:bindings:readerfrontier-realization-bindings
site-domain:initarg:site-domain:readerfrontier-realization-site-domain
maximum-priority:initarg:maximum-priority:readerfrontier-realization-maximum-priority
priority-meaning:initarg:priority-meaning:readerfrontier-realization-priority-meaning
transfer:initarg:transfer:readerfrontier-realization-transfer
admission:initarg:admission:readerfrontier-realization-admission
priority:initarg:priority:readerfrontier-realization-priority
drain-form:initarg:drain-form:readerfrontier-realization-drain-form
admit-form:initarg:admit-form:readerfrontier-realization-admit-form
relate-form:initarg:relate-form:readerfrontier-realization-relate-form
drain-function:initarg:drain-function:readerfrontier-realization-drain-function
admit-function:initarg:admit-function:readerfrontier-realization-admit-function
relate-function:initarg:relate-function:readerfrontier-realization-relate-function
:documentation

One program compiled over bound fields into closed scalar Lisp.

TRANSFER, ADMISSION, and PRIORITY are the checked arithmetic expression graphs; DRAIN-FORM and ADMIT-FORM are the emitted lambda forms; the two functions are their compiled realizations. ADMIT-FUNCTION seeds one site through the same admission and commit law as a relation, or is NIL when the law needs a source. RELATE-FUNCTION exposes one relation from a virtual source whose field values are supplied as arguments, so a boundary such as open sky is the program's own transfer law rather than client arithmetic. #53Q1II #581ZQP

defmethodprint-object
stream
print-unreadable-object
realizationstream:typet
formatstream"~S over ~{~S~^ ~}"
frontier-program-definition-name
frontier-realization-definitionrealization
mapcar#'frontier-field-binding-name
frontier-realization-bindingsrealization
defunfrontier-realization-current-p
realization

Whether realization still reflects its program's live definition.

let
live
frontier-program-definition-for
frontier-program-definition-name
frontier-realization-definitionrealization
andlive
eq
frontier-program-definition-revisionlive
frontier-realization-revisionrealization
defunmake-realization-frontier
realization&key
initial-capacity256

Make the packed frontier the realization's layout requires.

make-bucket-frontier:maximum-priority
frontier-realization-maximum-priorityrealization
:priority-meaning
frontier-realization-priority-meaningrealization
:initial-capacityinitial-capacity
defunmake-realization-execution
realizationinputfrontier
make-frontier-execution
frontier-realization-definitionrealization
inputfrontier:retain-admissions
frontier-program-definition-retain-admissions-p
frontier-realization-definitionrealization
defundrain-frontier-realization
realizationwindowfrontierexecution&restarguments

Run the compiled program until frontier is empty; return execution.

arguments are the program's constants as keywords. A program whose family hands sites to a companion frontier, such as invalidation's surviving sources, takes that frontier as the first argument before the keywords.

apply
frontier-realization-drain-functionrealization
windowfrontierexecutionarguments
defunadmit-frontier-realization-site
realizationwindowfrontierexecutionmaterializationoffsetvalue&restconstants

Seed one site through the program's admission and commit law.

For a monotone program value joins the relaxed field; for a discover-once program value is ignored. Return whether the site was admitted.

let
admit
frontier-realization-admit-functionrealization
unlessadmit
error"~S cannot admit a site without a source."realization
applyadmitwindowfrontierexecutionmaterializationoffsetvalueconstants
defunschedule-frontier-realization-site
realizationfrontierexecutionmaterializationoffsetpriority

Push MATERIALIZATION/OFFSET at priority for reconsideration, without law.

This is the frontier word for a site whose value already stands but whose relations must be exposed again, such as a resident chunk's face when a neighbour arrives. It is not an admission and is not retained.

declare
ignorerealizationexecution
bucket-frontier-pushfrontiermaterializationoffsetpriority
defunrelate-frontier-realization-site
realizationwindowfrontierexecutionmaterializationoffsetdirection&restarguments

Expose one relation into MATERIALIZATION/OFFSET from a virtual source.

arguments supply the program's constants and, keyed by role name, the source field values the transfer reads; direction is the relation's direction as seen from that source. The target is tested, committed, and admitted by the same law as an ordinary relation. Return whether it was admitted. #581ZQP

apply
frontier-realization-relate-functionrealization
windowfrontierexecutionmaterializationoffsetdirectionarguments

------------------------------------------------------------------------ The compiler

Template variables. Binding authors write these symbols; the compiler substitutes the emitted loop's own variables for them.

defparameter*frontier-template-variables*'
materializationoffsetvalue
defvar*frontier-compilation-fields*nil"Alist of field role name to quantity specification while parsing laws."
defclassfrontier-lowered-field
binding:initarg:binding:readerlowered-field-binding
source-parameter:initarg:source-parameter:readerlowered-field-source-parameter
target-parameter:initarg:target-parameter:readerlowered-field-target-parameter
source-lanes:initarg:source-lanes:readerlowered-field-source-lanes
target-lanes:initarg:target-lanes:readerlowered-field-target-lanes
source-variable:initarg:source-variable:readerlowered-field-source-variable
target-variable:initarg:target-variable:readerlowered-field-target-variable
:documentation

Compiler bookkeeping for one bound field role.

defunfrontier-role-symbol
namerole
make-symbol
formatnil"~A/~A"namerole
defunmake-frontier-parameter
namespecification
make-instance'lang:arithmetic-parameter:namename:quantity-specificationspecification:source-formname
lang:define-arithmetic-operatoras-field-quantity"Assert that a raw or foreign value is measured in a program field's quantity."
defmethodlang:parse-arithmetic-operator-call
operator
formenvironment
declare
ignoreoperator
destructuring-bind
namefield-nameoperand-form
form
declare
ignorename
let*
entry
specification
cdrentry
operand
lang:parse-arithmetic-expressionoperand-formenvironment
unlessentry
error'lang:arithmetic-language-error:formform:reason:unknown-frontier-field:detailsfield-name
unlessspecification
error'lang:arithmetic-language-error:formform:reason:field-has-no-quantity:detailsfield-name
when
setfoperand
make-instance'lang:arithmetic-representation:operandoperand:source-formform
make-instance'lang:arithmetic-quantity-assumption:operandoperand:quantity-specificationspecification:source-formform
defunrewrite-frontier-field-references
formfields

Replace (FIELD ROLE) reads with the compiler's role symbols.

flet
lowered-for
name
findnamefields:key
lambda
lowered
frontier-field-binding-name
lowered-field-bindinglowered
cond
atomform
form
frontier-word-p
firstform
"AS-FIELD-QUANTITY"
list*'as-field-quantity
secondform
mapcar
lambda
subform
cddrform
and
symbolp
firstform
=
lengthform
2
lowered-for
firstform
let
lowered
lowered-for
firstform
if
lang:arithmetic-object-name
lowered-field-source-parameterlowered
lang:arithmetic-object-name
lowered-field-target-parameterlowered
t
mapcar
lambda
subform
form
defunexpression-reference-targets
expression

Every arithmetic reference target reachable from expression.

let
seen
make-hash-table:test#'eq
targetsnil
labels
visit
expression
unless
gethashexpressionseen
setf
gethashexpressionseen
t
when
pushnew
lang:arithmetic-reference-targetexpression
targets
visitexpression
targets
defunsubstitute-template
templatesubstitutions

Substitute substitutions (name . form) into template, matching by name.

cond
consptemplate
cons
substitute-template
cartemplate
substitutions
substitute-template
cdrtemplate
substitutions
and
symbolptemplate
template
not
keywordptemplate
let
entry
assoctemplatesubstitutions:test
lambda
formkey
frontier-word-pform
symbol-namekey
ifentry
cdrentry
template
ttemplate
defunlane-let-bindings
bindinglanes-alistmaterialization-variable
loopfor
lane-nameform
in
frontier-field-binding-lanesbinding
collect`
,
cdr
assoclane-namelanes-alist
,
substitute-templateform`
materialization.,materialization-variable
defunlane-type-declarations
bindinglanes-alist
loopfor
lane-namenil.options
in
frontier-field-binding-lanesbinding
fortype=
getfoptions:type
whentypecollect`
type,type,
cdr
assoclane-namelanes-alist
defunrole-materialization-variable
role
ecaserole
:source'source
:target'target
defunfield-read-form
loweredroleoffset-variable
let*
binding
lowered-field-bindinglowered
lanes
ecaserole
:source
lowered-field-source-laneslowered
:target
lowered-field-target-laneslowered
substitute-template
frontier-field-binding-read-templatebinding
appendlanes`
offset.,offset-variable
materialization.,
window.window
defunfield-write-form
loweredoffset-variablevalue-form
let*
binding
lowered-field-bindinglowered
template
frontier-field-binding-write-templatebinding
unlesstemplate
error"Field ~S has no write template but the program commits to it."
frontier-field-binding-namebinding
substitute-templatetemplate
append
lowered-field-target-laneslowered
`
offset.,offset-variable
value.,value-form
materialization.target
window.window
defclassfrontier-compilation
definition:initarg:definition:readercompilation-definition
fields:initarg:fields:readercompilation-fields
constants:initarg:constants:readercompilation-constants
predicates:initarg:predicates:readercompilation-predicates
environment:initarg:environment:accessorcompilation-environment
transfer:initformnil:accessorcompilation-transfer
admission:initformnil:accessorcompilation-admission
priority:initformnil:accessorcompilation-priority
site-domain:initarg:site-domain:readercompilation-site-domain
:documentation

Working state for one compile-frontier-program call.

defuncompilation-lowered-field
compilationname
or
findname
compilation-fieldscompilation
:key
lambda
lowered
frontier-field-binding-name
lowered-field-bindinglowered
error"Program ~S has no field ~S."
frontier-program-definition-name
compilation-definitioncompilation
name
defuncompilation-relaxed-field
compilation
let
role
frontier-program-relaxed-field
compilation-definitioncompilation
androle
compilation-lowered-fieldcompilation
frontier-field-role-namerole
defuncompilation-invalidated-field
compilation
let
role
frontier-program-invalidated-field
compilation-definitioncompilation
androle
compilation-lowered-fieldcompilation
frontier-field-role-namerole
defuncompilation-memo-field
compilation
let
role
frontier-program-memo-field
compilation-definitioncompilation
androle
compilation-lowered-fieldcompilation
frontier-field-role-namerole
defunparse-frontier-law
compilationform

Parse one arithmetic law of the program in the compilation environment.

andform
let
*frontier-compilation-fields*
mapcar
lambda
lowered
cons
frontier-field-binding-name
lowered-field-bindinglowered
compilation-fieldscompilation
lang:parse-arithmetic-expression
rewrite-frontier-field-referencesform
compilation-fieldscompilation
compilation-environmentcompilation
defunensure-law-fits-field
expressionloweredwhat

Require expression's quantity to be interpretable as lowered's field.

let
field-specification
when
andexpressionfield-specification
let
derived
and
lang:arithmetic-expression-quantity-specificationexpression
unlessderived
error"The ~A law ~S has no quantity but field ~S is measured in ~S."what
frontier-field-binding-name
lowered-field-bindinglowered
field-specification
handler-case
math:interpret-quantity-specificationderivedfield-specification
math:quantity-operation-error
condition
error"The ~A law ~S yields ~S, which is not the ~S field's ~S: ~A"whatderived
frontier-field-binding-name
lowered-field-bindinglowered
field-specificationcondition
defunlower-law
compilationexpressionlowering-environment
declare
ignorecompilation
defgenericfrontier-family-law-forms
familycompilationcandidate-variablelowering-environment&keyseed-p
:documentation

Return (VALUES TEST-FORM COMMIT-FORMS PRIORITY-FORM OTHERWISE-FORMS) for one exposed target under family, given the lowering environment of bound field values. candidate-variable names the transfer result for monotone families, or the supplied value when seed-p says the target is being seeded rather than reached through a relation. OTHERWISE-FORMS run when the test fails, for families with a secondary effect. #FE0O5R

defmethodfrontier-family-law-forms
family
eql:monotone-max-fixpoint
compilationcandidatelowering-environment&keyseed-p
declare
ignorefamilyseed-p
let*
relaxed
current
lowered-field-target-variablerelaxed
admission
compilation-admissioncompilation
priority
compilation-prioritycompilation
values
ifadmission`
and
>,candidate,current
,
lower-lawcompilationadmissionlowering-environment
`
>,candidate,current
list
field-write-formrelaxed'target-offsetcandidate
ifpriority
lower-lawcompilationprioritylowering-environment
candidate
defmethodfrontier-family-law-forms
family
eql:discover-once
compilationcandidatelowering-environment&keyseed-p
declare
ignorefamilycandidateseed-p
let*
memo
visited
lowered-field-target-variablememo
priority
compilation-prioritycompilation
values`
and
not,visited
,
lower-lawcompilation
compilation-admissioncompilation
lowering-environment
list
field-write-formmemo'target-offsett
ifpriority
lower-lawcompilationprioritylowering-environment
0
defmethodfrontier-family-law-forms
family
eql:invalidation
compilationcandidatelowering-environment&keyseed-p

Clear a dependent target and re-admit it at the level it had; hand an independent lit target to the companion frontier as a surviving source.

The invalidated field's source value is the popped priority: the level the cleared source had. A seed clears the site unconditionally and admits it at the supplied value.

declare
ignorefamily
let*
invalidated
current
lowered-field-target-variableinvalidated
ifseed-p
valuest
list
field-write-forminvalidated'target-offset0
candidatenil
values`
and
plusp,current
,
lower-lawcompilation
compilation-admissioncompilation
lowering-environment
list
field-write-forminvalidated'target-offset0
current`
when
plusp,current
survivetargettarget-offset,current
defgenericfrontier-family-companion-p
family
:documentation

Whether family's drain hands sites to a second, companion frontier.

defmethodfrontier-family-companion-p
family
declare
ignorefamily
nil
defmethodfrontier-family-companion-p
family
eql:invalidation
declare
ignorefamily
t
defunfrontier-directions-form
let
neighborhood
frontier-program-definition-neighborhooddefinition
cond
eqneighborhood:voxel-face-relations
'*voxel-face-directions*
and
conspneighborhood
eq
firstneighborhood
:voxel-relations
member
secondneighborhood
frontier-program-definition-constantsdefinition
secondneighborhood
t
error"Unknown frontier neighborhood ~S."neighborhood
defunfrontier-layout-maximum-priority
definitionrelaxed-binding

The finite bucket range: from the relaxed or invalidated field's legal values.

let
layout
frontier-program-definition-frontier-layoutdefinition
cond
eqlayout:brightest-first-buckets
or
andrelaxed-binding
frontier-declaration-maximum-value
frontier-field-binding-declarationrelaxed-binding
error"~S needs a finite legal-value maximum on its relaxed field."layout
eqlayout:lifo-stack
0
and
consplayout
eq
firstlayout
:buckets
t
error"Unknown frontier layout ~S."layout
defunpredicate-form
predicate
ecase
frontier-relation-predicate-kindpredicate
:crossing'
andcrossingt
:direction=`
eqdirection,
frontier-relation-predicate-argumentpredicate
defuncompile-frontier-program
program&keybindingssite-domain
compilet

Close program over field bindings and emit its scalar realization.

site-domain is a form over MATERIALIZATION yielding the chunk domain that gives a site's dense offset spatial meaning. Each field role of the program must have one frontier-field-binding. The laws are parsed and quantity checked against the bound fields, lowered with scalar arithmetic, and spliced into one closed loop over raw buckets and lanes. With compile NIL the forms are emitted but not compiled, for inspection. #53Q1II #T2G95K #716UN6

let*
definition
if
symbolpprogram
or
error"No frontier program named ~S."program
program
roles
frontier-program-definition-fieldsdefinition
constants
frontier-program-definition-constantsdefinition
fields
mapcar
lambda
role
let*
name
frontier-field-role-namerole
binding
or
findnamebindings:key#'frontier-field-binding-name
error"Program ~S field ~S is unbound."
frontier-program-definition-namedefinition
name
flet
lanes
which
loopfor
lane-name
in
frontier-field-binding-lanesbinding
collect
conslane-name
make-symbol
formatnil"~A/~A/~A"whichnamelane-name
make-instance'frontier-lowered-field:bindingbinding:source-parameter:target-parameter:source-lanes
lanes'source
:target-lanes
lanes'target
:source-variable:target-variable
roles
predicates
frontier-program-definition-predicatesdefinition
constant-parameters
mapcar
lambda
name
constants
predicate-parameters
mapcar
lambda
predicate
make-frontier-parameter
frontier-relation-predicate-namepredicate
nil
predicates
environment
append
loopforloweredinfieldscollect
cons
lang:arithmetic-object-name
lowered-field-source-parameterlowered
lowered-field-source-parameterlowered
collect
cons
lang:arithmetic-object-name
lowered-field-target-parameterlowered
lowered-field-target-parameterlowered
mapcar
lambda
parameter
cons
lang:arithmetic-object-nameparameter
parameter
appendconstant-parameterspredicate-parameters
compilation
make-instance'frontier-compilation:definitiondefinition:fieldsfields:constantsconstant-parameters:predicatespredicate-parameters:environmentenvironment:site-domainsite-domain
unlesssite-domain
error"COMPILE-FRONTIER-PROGRAM needs a :SITE-DOMAIN template."
dolist
loweredfields
let
role
find
frontier-field-binding-name
lowered-field-bindinglowered
roles:key#'frontier-field-role-name
when
and
frontier-field-binding-lazy-p
lowered-field-bindinglowered
or
frontier-field-role-relaxed-prole
frontier-field-role-memo-prole
error"The ~S field is relaxed or a memo and cannot be bound lazily."
frontier-field-role-namerole
dolist
predicatepredicates
when
and
eq
frontier-relation-predicate-kindpredicate
:direction=
not
member
frontier-relation-predicate-argumentpredicate
constants
error"Predicate ~S names ~S, which is not a program constant."
frontier-relation-predicate-namepredicate
frontier-relation-predicate-argumentpredicate

Parse and check the laws.

setf
compilation-transfercompilation
parse-frontier-lawcompilation
frontier-program-definition-transferdefinition
compilation-admissioncompilation
parse-frontier-lawcompilation
frontier-program-definition-admissiondefinition
compilation-prioritycompilation
parse-frontier-lawcompilation
frontier-program-definition-prioritydefinition
let
relaxed
whenrelaxed
ensure-law-fits-field
compilation-transfercompilation
relaxed"transfer"
ensure-law-fits-field
compilation-prioritycompilation
relaxed"priority"
let*
relaxed-binding
andrelaxed
lowered-field-bindingrelaxed
maximum-priority
drain-form
admit-form
relate-form
make-instance'frontier-realization:definitiondefinition:revision
frontier-program-definition-revisiondefinition
:bindingsbindings:site-domainsite-domain:maximum-prioritymaximum-priority:priority-meaning
andrelaxed-binding
frontier-field-binding-declarationrelaxed-binding
:transfer
compilation-transfercompilation
:admission
compilation-admissioncompilation
:priority
compilation-prioritycompilation
:drain-formdrain-form:admit-formadmit-form:relate-formrelate-form:drain-function
andcompile
compilenildrain-form
:admit-function
andcompileadmit-form
compileniladmit-form
:relate-function
andcompilerelate-form
compilenilrelate-form

Emission. The generated loop is deliberately plain: raw bucket vectors and counters are bound once at entry and written back at exit; the source site's lanes and field values are bound once per pop; the popped site is validated once and its six relations are primitive fixnum steps (do-chunk-site-neighbors, #FGT96H); a target's lanes are the source's own for a local step and are borrowed from the crossing materialization otherwise. Nothing per relation is generic, checked twice, or allocated.

defuncompilation-lowering-environment
compilation&key
source-pt

Map every arithmetic parameter to the emitted form holding its value.

Eager fields are read once into a variable; lazy fields lower to their read form wherever the law mentions them.

append
loopforloweredin
compilation-fieldscompilation
forlazy=
frontier-field-binding-lazy-p
lowered-field-bindinglowered
whensource-pcollect
cons
lowered-field-source-parameterlowered
iflazy
field-read-formlowered:source'source-offset
lowered-field-source-variablelowered
collect
cons
lowered-field-target-parameterlowered
iflazy
field-read-formlowered:target'target-offset
lowered-field-target-variablelowered
mapcar
lambda
parameter
consparameter
lang:arithmetic-object-nameparameter
compilation-constantscompilation
whensource-p
mapcar
lambda
parameter
consparameter
lang:arithmetic-object-nameparameter
compilation-predicatescompilation
defuncompilation-referenced-parameters
compilation
let
targetsnil
dolist
expression
list
compilation-transfercompilation
compilation-admissioncompilation
compilation-prioritycompilation
whenexpression
setftargets
uniontargets
targets
defunfield-value-bindings
compilationroleoffset-variablereferenced

LET* bindings and declarations reading the role values the laws need.

let
bindingsnil
needednil
dolist
lowered
compilation-fieldscompilation
let*
parameter
ecaserole
:source
lowered-field-source-parameterlowered
:target
lowered-field-target-parameterlowered
variable
ecaserole
:source
lowered-field-source-variablelowered
:target
lowered-field-target-variablelowered
binding
lowered-field-bindinglowered
implied
and
eqrole:target
or
frontier-field-role-relaxed-p
find
frontier-field-binding-namebinding
frontier-program-definition-fields
compilation-definitioncompilation
:key#'frontier-field-role-name
frontier-field-role-memo-p
find
frontier-field-binding-namebinding
frontier-program-definition-fields
compilation-definitioncompilation
:key#'frontier-field-role-name
frontier-field-role-invalidated-p
find
frontier-field-binding-namebinding
frontier-program-definition-fields
compilation-definitioncompilation
:key#'frontier-field-role-name
when
orimplied
memberparameterreferenced
pushloweredneeded
unless
frontier-field-binding-lazy-pbinding
push`
,variable,
if
and
eqrole:source
eqlowered

A cleared source's value is the level it had,

which is the priority it was admitted at.

'source-priority
field-read-formloweredroleoffset-variable
bindings
values
nreversebindings
nreversedeclarations
nreverseneeded
defunemit-target-law
compilationcandidate-formlowering-environment&keyadmit-formseed-p

Emit the test, commits, and admission for one exposed target site.

let
candidate
make-symbol"CANDIDATE"
multiple-value-bind
testcommitspriorityotherwise
frontier-family-law-forms
frontier-program-definition-family
compilation-definitioncompilation
compilationcandidatelowering-environment:seed-pseed-p
let
body
ifotherwise`
if,test
progn,@commits,
funcalladmit-formpriority
progn,@otherwise
`
when,test,@commits,
funcalladmit-formpriority
ifcandidate-form`
let
,candidate,candidate-form
,body
body
defuncounter-write-back-forms
`
setf
bucket-frontier-countfrontier
count
bucket-frontier-current-priorityfrontier
current-priority
bucket-frontier-pushesfrontier
pushes
bucket-frontier-popsfrontier
pops
bucket-frontier-peak-countfrontier
peak-count
incf
frontier-execution-visitsexecution
visits
incf
frontier-execution-relationsexecution
relations
incf
frontier-execution-admissionsexecution
admissions
incf
frontier-execution-crossingsexecution
crossings
incf
frontier-execution-unavailableexecution
unavailable
defuncompanion-parameters
compilation
and
frontier-family-companion-p
frontier-program-definition-family
compilation-definitioncompilation
'
companion
defuncompanion-bindings
compilation
and`
companion-buckets
bucket-frontier-bucketscompanion
companion-count
bucket-frontier-countcompanion
companion-current-priority
bucket-frontier-current-prioritycompanion
companion-pushes
bucket-frontier-pushescompanion
companion-peak-count
bucket-frontier-peak-countcompanion
emissions0
defuncompanion-declarations
compilation
and`
typesimple-vectorcompanion-buckets
typefixnumcompanion-countcompanion-current-prioritycompanion-pushescompanion-peak-countemissions
defuncompanion-flets
compilation
and`
survive
materializationoffsetpriority
declare
typefixnumoffsetpriority
frontier-site-buffer-push
svrefcompanion-bucketspriority
materializationoffset
incfcompanion-count
incfcompanion-pushes
incfemissions
when
>prioritycompanion-current-priority
setfcompanion-current-prioritypriority
when
>companion-countcompanion-peak-count
setfcompanion-peak-countcompanion-count
defuncompanion-write-back-forms
compilation
and`
setf
bucket-frontier-countcompanion
companion-count
bucket-frontier-current-prioritycompanion
companion-current-priority
bucket-frontier-pushescompanion
companion-pushes
bucket-frontier-peak-countcompanion
companion-peak-count
incf
frontier-execution-emissionsexecution
emissions
defunraw-frontier-bindings
`
buckets
bucket-frontier-bucketsfrontier
count
bucket-frontier-countfrontier
current-priority
bucket-frontier-current-priorityfrontier
pushes
bucket-frontier-pushesfrontier
pops
bucket-frontier-popsfrontier
peak-count
bucket-frontier-peak-countfrontier
admitted-sites
frontier-execution-admitted-sitesexecution
visits0
relations0
admissions0
crossings0
unavailable0
defunraw-frontier-declarations
`
declare
typesimple-vectorbuckets
typefixnumcountcurrent-prioritypushespopspeak-countvisitsrelationsadmissionscrossingsunavailable
ignorableadmitted-sites
defunadmit-flet
`
admit
materializationoffsetpriority
declare
typefixnumoffsetpriority
frontier-site-buffer-push
svrefbucketspriority
materializationoffset
whenadmitted-sites
frontier-site-buffer-pushadmitted-sitesmaterializationoffset
incfcount
incfpushes
incfadmissions
when
>prioritycurrent-priority
setfcurrent-prioritypriority
when
>countpeak-count
setfpeak-countcount
defunemit-frontier-drain-form
compilation
let*
definition
compilation-definitioncompilation
constants
mapcar#'lang:arithmetic-object-name
compilation-constantscompilation
transfer
compilation-transfercompilation
candidate-form
andtransfer
lower-lawcompilationtransferlowering
multiple-value-bind
source-valuessource-declarationssource-needed
field-value-bindingscompilation:source'source-offsetreferenced
multiple-value-bind
target-valuestarget-declarationstarget-needed
field-value-bindingscompilation:target'target-offsetreferenced

A local step's target lanes are the source's own, so every lane a target reads is also borrowed at the source.

setfsource-needed
remove-if-not
lambda
lowered
or
memberloweredsource-needed
memberloweredtarget-needed
compilation-fieldscompilation
`
lambda
windowfrontierexecution,@&key,@constants
declare
ignorablewindow,@constants
let*
,@,@
directions,directions
,
declare,@
flet
declare
inlineadmit
loop
when
zeropcount
let
bucket
svrefbucketscurrent-priority
source-prioritycurrent-priority
declare
typefixnumsource-priority
ignorablesource-priority
multiple-value-bind
sourcesource-offsetpresent-p
frontier-site-buffer-popbucket
declare
typefixnumsource-offset
unlesspresent-p
error"Frontier count disagrees with priority bucket ~D."current-priority
decfcount
incfpops
when
zerop
frontier-site-buffer-lengthbucket
setfcurrent-priority
loopforcandidatedownfrom
1-current-priority
to0when
plusp
frontier-site-buffer-length
svrefbucketscandidate
returncandidatefinally
incfvisits
let*
source-domain,
substitute-template
compilation-site-domaincompilation
'
materialization.source
,@
loopforloweredinsource-neededappend
lane-let-bindings
lowered-field-bindinglowered
lowered-field-source-laneslowered
'source
,@source-values
declare,@
loopforloweredinsource-neededappend
lane-type-declarations
lowered-field-bindinglowered
lowered-field-source-laneslowered
,@source-declarations
do-chunk-site-neighbors
target-offsetcrossingdirectionmaterializationavailabilitywindowsource-domainsource-offsetdirections
incfrelations
whencrossing
incfcrossings
if
eqavailability:unavailable
incfunavailable
let*
target
ifcrossingmaterializationsource
,@
loopforloweredintarget-neededappend
loopfor
lane.target-variable
in
lowered-field-target-laneslowered
forsource-variable=
cdr
assoclane
lowered-field-source-laneslowered
forform=
second
assoclane
frontier-field-binding-lanes
lowered-field-bindinglowered
collect`
,target-variable
ifcrossing,
substitute-templateform'
materialization.target
,source-variable
,@
loopforpredicatein
frontier-program-definition-predicatesdefinition
collect`
,
frontier-relation-predicate-namepredicate
,
,@target-values
declare,@
loopforloweredintarget-neededappend
lane-type-declarations
lowered-field-bindinglowered
lowered-field-target-laneslowered
,@target-declarations
ignorabletarget,@
mapcar#'frontier-relation-predicate-name
frontier-program-definition-predicatesdefinition
,
emit-target-lawcompilationcandidate-formlowering:admit-form
lambda
priority
`
admittargettarget-offset,priority
,@,@execution
defunemit-frontier-admit-form
compilation

Emit the seed entry point, or NIL when the law needs a source or relation.

let*
constants
mapcar#'lang:arithmetic-object-name
compilation-constantscompilation
referenced
let
targetsnil
dolist
expression
list
compilation-admissioncompilation
compilation-prioritycompilation
targets
whenexpression
setftargets
uniontargets
relaxed
source-parameters
append
mapcar#'lowered-field-source-parameter
compilation-fieldscompilation
compilation-predicatescompilation
law-expressions
list
compilation-admissioncompilation
compilation-prioritycompilation
when
and
not
eq
frontier-program-definition-family
compilation-definitioncompilation
:invalidation
some
lambda
expression
andexpression
intersectionsource-parameters
law-expressions
multiple-value-bind
target-valuestarget-declarationstarget-needed
field-value-bindingscompilation:target'target-offsetreferenced
`
lambda
windowfrontierexecutionmaterializationtarget-offsetvalue&key,@constants
declare
ignorablewindowvalue,@constants
typefixnumtarget-offset
let*
,@
targetmaterialization
,@
loopforloweredintarget-neededappend
lane-let-bindings
lowered-field-bindinglowered
lowered-field-target-laneslowered
'target
,@target-values
admitted-pnil
,
declare,@
loopforloweredintarget-neededappend
lane-type-declarations
lowered-field-bindinglowered
lowered-field-target-laneslowered
,@target-declarations
flet
declare
inlineadmit
,
emit-target-lawcompilation
and'value
compilation-lowering-environmentcompilation:source-pnil
:seed-pt:admit-form
lambda
priority
`
progn
admittargettarget-offset,priority
setfadmitted-pt
,@admitted-p
defunemit-frontier-relate-form
compilation

Emit the virtual-source relation entry point.

The source role's field values arrive as keyword arguments named by role, the relation direction as an argument, and the crossing predicate is true: a virtual source is by definition outside the target's materialization.

let*
definition
compilation-definitioncompilation
constants
mapcar#'lang:arithmetic-object-name
compilation-constantscompilation
transfer
compilation-transfercompilation
candidate-form
andtransfer
lower-lawcompilationtransferlowering
source-fields
remove-if-not
lambda
lowered
member
lowered-field-source-parameterlowered
referenced
compilation-fieldscompilation
source-arguments
mapcar
lambda
lowered
frontier-field-binding-name
lowered-field-bindinglowered
source-fields
multiple-value-bind
target-valuestarget-declarationstarget-needed
field-value-bindingscompilation:target'target-offsetreferenced
`
lambda
windowfrontierexecutionmaterializationtarget-offsetdirection&key,@constants,@source-arguments
declare
ignorablewindowdirection,@constants
typefixnumtarget-offset
let*
,@
targetmaterialization
,@
loopforloweredinsource-fieldsforargumentinsource-argumentscollect`
,
lowered-field-source-variablelowered
,argument
,@
loopforloweredintarget-neededappend
lane-let-bindings
lowered-field-bindinglowered
lowered-field-target-laneslowered
'target
,@
loopforpredicatein
frontier-program-definition-predicatesdefinition
collect`
,
frontier-relation-predicate-namepredicate
,
ecase
frontier-relation-predicate-kindpredicate
:crossingt
:direction=
,@target-values
admitted-pnil
,
declare,@
loopforloweredinsource-fieldsfortype=
frontier-field-binding-representation-type
lowered-field-bindinglowered
whentypecollect`
type,type,
lowered-field-source-variablelowered
,@
loopforloweredintarget-neededappend
lane-type-declarations
lowered-field-bindinglowered
lowered-field-target-laneslowered
,@target-declarations
ignorable,@
mapcar#'frontier-relation-predicate-name
frontier-program-definition-predicatesdefinition
flet
declare
inlineadmit
,
emit-target-lawcompilationcandidate-formlowering:admit-form
lambda
priority
`
progn
admittargettarget-offset,priority
setfadmitted-pt
,@admitted-p