refactor label handling into AsyncEmbeddedScript

This commit is contained in:
2021-12-21 20:43:10 -07:00
parent 322fc20743
commit 5d7620e409
3 changed files with 48 additions and 43 deletions

View File

@@ -4,36 +4,19 @@
(collectBlocks preload (#when (StringTools.contains kissFile className) (cc)))
(collectBlocks cleanup (#when (StringTools.contains kissFile className) (cc)))
(prop :Map<String,Int> labelsByName (new Map))
(prop :Array<Int> labels [])
(defMacroVar _labelNames [])
(defMacroVar _labelLines [])
(defReaderMacro "LABEL " [stream]
(_labelNames.push (stream.expect "label name" ->(stream.takeLine)))
(_labelLines.push (- .line (stream.position) 1))
`(cc))
(defMacro end []
(let [labelSetters
(for [label idx] (zipThrow _labelNames _labelLines)
`{
(dictSet labelsByName ,label ,idx)
(labels.push ,idx)
})]
`{
(method doPreload [:Void->Void cc]
(set isLoading true)
(collectedBlocks preload)
(set isLoading false)
,@labelSetters
(cc))
(method doCleanup []
(director.cleanup)
(set lastInstructionPointer -2)
(collectedBlocks cleanup))
(doCleanup)
}))
`{
(method doPreload [:Void->Void cc]
(set isLoading true)
(collectedBlocks preload)
(set isLoading false)
(cc))
(method doCleanup []
(director.cleanup)
(set lastInstructionPointer -2)
(collectedBlocks cleanup))
(doCleanup)
})
(defReaderMacro &bof "" [stream] `(#when (StringTools.contains kissFile className) (doPreload cc)))
(defReaderMacro &eof "" [stream] `(#when (StringTools.contains kissFile className) (end)))