Compiler addPrototype: #Compiler derivedFrom: {ReadStream}. "Takes incoming source and turns it into IR (trees). The Parser is a processing Stream for incoming characters, via its own Lexer. The Compiler then acts as a Stream protocol wrapping the IRGenerator's functionality." Compiler Compiler addSlot: #parser valued: Syntax Parser clone. Compiler Compiler addSlot: #buffer valued: ExtensibleArray newEmpty. Compiler Compiler addSlot: #generator. Compiler Compiler addSlot: #context valued: lobby. "The root namespace context for compilation. Not yet used." c@(Compiler Compiler traits) on: s [ c parser: (c parser newOn: s). c buffer: c buffer newEmpty. c generator: c generator newEmpty. c ]. c@(Compiler Compiler traits) source "The character input source." [ c parser lexer stream ]. c@(Compiler Compiler traits) source: s "The character input source." [ c parser lexer stream: s ]. c@(Compiler Compiler traits) open [ c parser open ]. c@(Compiler Compiler traits) close [ c parser close ]. c@(Compiler Compiler traits) peek [ c buffer isEmpty ifTrue: [c buffer addLast: c next]. c buffer first ]. c@(Compiler Compiler traits) next "Returns the next top-level generated Node from the Stream." [| node | c buffer isEmpty ifTrue: [node: c parser next. c generator generate: node] ifFalse: [c buffer removeFirst] ]. c@(Compiler Compiler traits) atEnd [ c buffer isEmpty and: [c parser atEnd] ]. c@(Compiler Compiler traits) compile "Compiles the contents of the buffer." [ c buffer do: [| :each | each] ].