/******************************************************************************/ /* */ /* genprelude.rex - Generate rvm-prelude.mjs: the R-code of the prelude */ /* ==================================================================== */ /* */ /* Usage: rexx genprelude.rex ../prelude.orx.rcode > rvm-prelude.mjs */ /* rexx genprelude.rex ../prelude-streams.orx.rcode */ /* PRELUDE_STREAMS_RCODE > rvm-prelude-streams.mjs */ /* */ /* The prelude (../prelude.orx, made by ../makeprelude.rex) is compiled by */ /* the RVM of ooRexx (rvm -l prelude.orx > prelude.orx.rcode, its cache); */ /* this writes that R-code as a JS module, for the JS RVM (Node and the */ /* browser alike). Its PROGRAM is REXX, the name of the package. */ /* */ /* 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 const . If file = "" Then Do Say "Usage: rexx genprelude.rex ../prelude.orx.rcode > rvm-prelude.mjs" Say " rexx genprelude.rex ../prelude-streams.orx.rcode PRELUDE_STREAMS_RCODE" - "> rvm-prelude-streams.mjs" Exit 1 End If const == "" Then const = "PRELUDE_RCODE" lines = CharIn( file, 1, Chars( file ) )~makeArray Call Stream file, "C", "Close" If lines~items < 3 | Word( lines[1], 1 ) \== "RCODE" Then Do .Error~lineOut( file "is not R-code." ) Exit 1 End source = FileSpec( "Name", file ) source = Left( source, Length( source ) - Length( ".rcode" ) ) -- The license of what it comes from: the prelude, ooRexx's (CPL). If const == "PRELUDE_RCODE" Then Parse Value "rvm-prelude.mjs CoreClasses.orx" With out origin Else Parse Value "rvm-prelude-streams.mjs StreamClasses.orx" With out origin Do h Over CPLHeader( out "- the R-code of" source "for the RVM of JavaScript," - "generated by genprelude.rex. It comes from" origin "of the ooRexx" - "interpreter, and is therefore distributed under the Common Public" - "License v1.0, not under the Apache License 2.0 that covers the rest of" - "the RVM (see NOTICE)." ) Say h End Say "// Generated by genprelude.rex from" source "-- DO NOT EDIT." Say "export const" const "= [" Do l Over lines If Word( l, 1 ) == "PROGRAM" Then l = 'PROGRAM "REXX"' Say " "JS( l )"," End Say '].join("\n");' Exit 0 JS: Procedure Parse Arg s out = '"' Do i = 1 To Length( s ) c = SubStr( s, i, 1 ) Select When c == '"' Then out = out'\"' When c == '\' Then out = out'\\' When c << " " | c >> "~" Then out = out"\u00"Lower( C2X( c ) ) Otherwise out = out || c End End Return out'"' -- A comment box of 80 columns: the CPL header of a file generated from what -- comes from ooRexx ('intro' says what the file is and where it comes from). ::Routine CPLHeader Use Strict Arg intro out = .Array~new bar = "/"Copies( "*", 78 )"/" blank = "/*"Copies( " ", 76 )"*/" out~append( bar ); out~append( blank ) Call Box out, intro out~append( blank ) Call Box out, "This file is part of the RVM, the Rexx Virtual Machine" out~append( blank ) Call Box out, "Copyright (c) 1995, 2004 IBM Corporation. All rights reserved." Call Box out, "Copyright (c) 2005-2026 Rexx Language Association. All rights reserved." Call Box out, "Copyright (c) 2026 Josep Maria Blasco " out~append( blank ) Call Box out, "This program and the accompanying materials are made available under" - "the terms of the Common Public License v1.0 which accompanies this" - "distribution. A copy is also available at the following address:" - "https://www.oorexx.org/license.html" out~append( blank ) Call Box out, "DO NOT EDIT DIRECTLY -- ALL CHANGES WILL BE LOST" out~append( blank ); out~append( bar ) Return out -- The text in lines of the box (74 columns of text). ::Routine Box Use Strict Arg out, text line = "" Do w Over Space( text )~makeArray( " " ) If line == "" Then cand = w Else cand = line w If Length( cand ) > 74 Then Do out~append( "/* "Left( line, 74 )" */" ) line = w End Else line = cand End If line \== "" Then out~append( "/* "Left( line, 74 )" */" )