WIP hollyoo movie method readermacros
This commit is contained in:
@@ -1,8 +1,13 @@
|
|||||||
|
// When this file is loaded, all expressions in (preload <...>) will be collected. When (end) is called, they will
|
||||||
|
// be injected into a method called (doPreload).
|
||||||
|
// This allows assets to be declared in Hollywoo files where they first appear, but still loaded before execution starts.
|
||||||
(collectBlocks preload (cc))
|
(collectBlocks preload (cc))
|
||||||
|
|
||||||
|
// TODO could make an &eof style of reader macro, and have (end) read automatically at the end of any Hollywoo file.
|
||||||
(defMacro end []
|
(defMacro end []
|
||||||
`(method doPreload [:Void->Void cc]
|
`(method doPreload [:Void->Void cc]
|
||||||
(set isLoading true)
|
(set isLoading true)
|
||||||
(collectedBlocks preload)
|
(collectedBlocks preload)
|
||||||
(set isLoading false)
|
(set isLoading false)
|
||||||
(cc)))
|
(cc)))
|
||||||
|
// TODO also &bof could call (doPreload)
|
||||||
|
@@ -37,7 +37,32 @@
|
|||||||
|
|
||||||
(super))
|
(super))
|
||||||
|
|
||||||
(method :Void delay [sec :Continuation cc]
|
// Some real magic happens here. This macro defines a method, AND a reader macro
|
||||||
|
// for calling it with cc passed automatically if cc is an argument.
|
||||||
|
|
||||||
|
(defMacro hollywooMethod [nameAndType argList &body body]
|
||||||
|
(let [&mut ccIndex -1
|
||||||
|
args (expList argList)
|
||||||
|
numArgs args.length
|
||||||
|
methodName (symbolNameValue nameAndType true)
|
||||||
|
readerMacroStart "$(.toUpperCase methodName) "]
|
||||||
|
(doFor [idx arg] (enumerate args)
|
||||||
|
(exprCase arg
|
||||||
|
(:Continuation cc
|
||||||
|
(set ccIndex idx))
|
||||||
|
(_)))
|
||||||
|
`{
|
||||||
|
(defReaderMacro ,readerMacroStart [stream]
|
||||||
|
(ReaderExp.CallExp
|
||||||
|
(ReaderExp.Symbol methodName)
|
||||||
|
(for i (range numArgs)
|
||||||
|
(if (= i ccIndex)
|
||||||
|
(ReaderExp.Symbol "cc")
|
||||||
|
(read)))))
|
||||||
|
(method ,nameAndType ,argList ,@body)
|
||||||
|
}))
|
||||||
|
|
||||||
|
(hollywooMethod :Void delay [sec :Continuation cc]
|
||||||
(case delayHandling
|
(case delayHandling
|
||||||
(Auto
|
(Auto
|
||||||
(Timer.delay cc (* 1000 sec)))
|
(Timer.delay cc (* 1000 sec)))
|
||||||
|
Reference in New Issue
Block a user