/******************************************************************************/ /* */ /* makeprelude.rex - The prelude of the RVM, from ooRexx's CoreClasses.orx */ /* ======================================================================= */ /* */ /* The RVM's prelude is ooRexx's own CoreClasses.orx (the Rexx part of the */ /* REXX package: Collection and its mixins, the methods written in Rexx of */ /* Supplier, Set, Bag and Relation, CircularQueue, the comparators, ...), */ /* cut so that every line keeps its number (an error in a method of the */ /* prelude is reported at the line ooRexx reports): the lines of its prolog */ /* that call StreamClasses.orx and PlatformObjects.orx become blank lines. */ /* The rest of the prolog runs when the RVM loads the prelude; what the */ /* prolog does not do (the inherits of the primitive classes, the class */ /* methods of String) the RVM does itself (RVM.World~bootstrap). Every class */ /* is kept. RexxQueue's LINEIN becomes UNGUARDED (ooRexx's rexx_linein_queue */ /* turns the guard off while it waits). After the last line comes */ /* prelude-rvm.orx, the RVM's own part. */ /* */ /* Usage: rexx makeprelude.rex CoreClasses.orx > prelude.orx */ /* rexx makeprelude.rex StreamClasses.orx streams > prelude-streams.orx */ /* */ /* The second: ooRexx's StreamClasses.orx (Stream and its mixins, */ /* StreamSupplier, File), cut the same way, a program of its own (its lines */ /* keep their numbers too) that the RVM loads after the prelude; its prolog */ /* becomes blank lines, and its public classes are the REXX package's (as */ /* its prolog makes them in ooRexx). */ /* */ /* Both outputs keep the copyright and licence box of their source (CPL), */ /* with a line for the modifications and a sentence naming the source after */ /* the IBM and RexxLA lines; to keep the line numbers, the blank lines at the */ /* top and the bottom of the box make room for them (see */ /* doc/19-licensing.md). */ /* */ /* This file is part of the RVM, the Rexx Virtual Machine */ /* [See https://rexx.epbcn.com/rexx-parser/] */ /* */ /* Copyright (c) 2026 Josep Maria Blasco */ /* */ /* License: Apache License 2.0 (https://www.apache.org/licenses/LICENSE-2.0) */ /* */ /******************************************************************************/ Parse Arg file part If file = "" Then Do Say "Usage: rexx makeprelude.rex CoreClasses.orx > prelude.orx" Say " rexx makeprelude.rex StreamClasses.orx streams > prelude-streams.orx" Exit 1 End streams = ( part == "streams" ) -- The classes to leave out (blank lines): none, every class is kept. dropped = "" -- The prolog of CoreClasses stays (RVM.World~ensurePrelude runs it), but -- for the lines that call the other files (StreamClasses.orx is a program -- of its own, prelude-streams.orx; PlatformObjects.orx is RexxQueue); -- that of StreamClasses goes. lines = .Array~new Call Stream file, "C", "Open Read" Do While Lines( file ) > 0 lines~append( LineIn( file ) ) End Call Stream file, "C", "Close" Call MarkBox lines, FileSpec( "Name", file ) keep = \ streams -- the prolog stays (CoreClasses) seenDirective = .False header = streams -- StreamClasses' copyright box stays Do i = 1 To lines~items line = lines[i] If header Then Do If Left( Strip( line ), 2 ) == "/*" Then Do Say line Iterate End header = .False End Parse Upper Var line word1 name . If Left( word1, 2 ) == "::" Then Do -- A class starts: kept unless it is one of those left out. Other -- directives (the floating methods, the methods of a class) go with -- what comes before them. If word1 == "::CLASS" Then Do name = Strip( Strip( name ), "B", '"' ) name = Strip( name, "B", "'" ) keep = WordPos( name, dropped ) == 0 End Else If word1 == "::METHOD", \ seenDirective Then keep = .True seenDirective = .True End If keep, \ seenDirective, Pos( ".orx'", line ) > 0 Then line = "" -- RexxQueue's LINEIN waits with no guard (SetGuardOff in ooRexx). If keep, Pos( "rexx_linein_queue", line ) > 0 Then line = "::METHOD linein UNGUARDED EXTERNAL 'LIBRARY REXX rexx_linein_queue'" If keep Then Say line Else Say "" End If streams Then Exit 0 -- The RVM's part, next to this file: after the last line of CoreClasses. Parse Source . . me own = Left( me, LastPos( .File~separator, me ) )"prelude-rvm.orx" Call Stream own, "C", "Open Read" Do While Lines( own ) > 0 Say LineIn( own ) End Call Stream own, "C", "Close" Exit 0 /******************************************************************************/ /* MarkBox: in the leading copyright box of LINES, add after the RexxLA line */ /* the copyright of the modifications and a sentence naming SOURCE, and take */ /* out as many blank box lines (the one after the top rule, the one before */ /* the bottom rule, then others from the bottom up) so that every line after */ /* the box keeps its number. */ /******************************************************************************/ MarkBox: Procedure Use Arg lines, source last = 0 Do i = 1 To lines~items While Left( Strip( lines[i] ), 2 ) == "/*" last = i End at = 0 Do i = 1 To last If Pos( "Copyright", lines[i] ) > 0, - Pos( "Rexx Language Association", lines[i] ) > 0 Then at = i End If at == 0 Then Return added = .Array~of( - "Modifications Copyright (c) 2026 Josep Maria Blasco", - "Derived from ooRexx's" source "and modified for the RVM." ) Do j = added~items To 1 By -1 lines~insert( "/*" Left( added[j], 74 ) "*/", at ) End last += added~items owed = added~items blank = "/*" || Copies( " ", 76 ) || "*/" If owed > 0, lines[2] == blank Then Do lines~delete( 2 ) last -= 1 owed -= 1 End Do i = last - 1 To 2 By -1 While owed > 0 If lines[i] == blank Then Do lines~delete( i ) owed -= 1 End End Return