/******************************************************************************/ /* */ /* gendata.rex - generate rvm-data.mjs */ /* ===================================== */ /* */ /* The tables the JS RVM takes from ooRexx and from the Rexx Parser: the */ /* error texts, the secondary messages, and the argument signatures of the */ /* built-in functions. */ /* */ /* Usage: REXX_PATH=.../bin rexx gendata.rex > rvm-data.mjs */ /* */ /* What it makes comes from ooRexx's messages, and is under the Common Public */ /* License v1.0 (it says so in its header: CPLHeader); this generator is */ /* under the Apache License 2.0. */ /* */ /* 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) */ /* */ /******************************************************************************/ .environment~Options.CMS = 0 .environment~Options.Unicode = 0 .environment~Options.Experimental = 0 Call LoadBIFInfo -- Its messages are ooRexx's (CPL): the file is. Do h Over CPLHeader( "rvm-data.mjs - the tables the RVM of JavaScript takes" - "from ooRexx and from the Rexx Parser, generated by gendata.rex: the texts" - "of the error messages (ooRexx's ERRORTEXT, the main ones and the" - "secondary ones) and the argument signatures of the built-in" - "functions. The messages come from the ooRexx interpreter, and the file" - "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 gendata.rex -- DO NOT EDIT." Say "export const ERROR_TEXT = {" Do i = 0 To 99 t = ErrorText( i ) If t \== "" Then Say " " i":" JS( t )"," End Say "};" Say "export const SECONDARY = {" -- The secondary messages, from the ERRORTEXT of the interpreter that runs -- this: every code from 0.1 to 99.999 that has one (ERRORTEXT is "" for -- the others). The key has the minor in three digits ("30.001"); ERRORTEXT -- writes the inserts "&n", and secondaryText (errors.mjs) reads "". sec = .StringTable~new Do major = 0 To 99 Do minor = 1 To 999 t = ErrorText( major"."minor ) If t == "" Then Iterate Do n = 9 To 1 By -1 t = t~changeStr( "&"n, "<"n":>" ) End sec[ major"."Right( minor, 3, 0 ) ] = t End End Do k Over sec~allIndexes~sort Say " " JS( k )":" JS( sec[k] )"," End Say "};" Say "export const BIF_INFO = {" info = .Parser.BIFInfo Do k Over info~allIndexes~sort d = info[k] If d~maxArgs == .Nil Then Iterate types = "" Do t Over d~argType types = types JS( t )"," End Say " "k": { min:" d~minArgs", max:" JS( d~maxArgs )", types: [" types "] }," End Say "};" -- The messages of the interpreter by number, as REXXUTIL's SysGetMessage -- finds them (RexxGetErrorMessageByNumber), with their &1 to &9. From -- the host's own SysGetMessage (Unix), which gives them back when the -- substitutions are themselves. Say "export const MESSAGES = {" If RxFuncQuery( "SysGetMessage" ) == 0 Then Do i = 1 To 1999 t = SysGetMessage( i, , "&1", "&2", "&3", "&4", "&5", "&6", "&7", "&8", "&9" ) If t \== "Error: Message not found" Then Say " " i":" JS( t )"," End Say "};" 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'"' ::Requires "parser/BIFs.cls" -- 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 )" */" )