Page 1 of 1

Why REXX does not need to be compiled?

Posted: Wed Aug 18, 2021 6:41 pm
by Geetu
Hi,

I have started working with REXX. I am reading about it more and learned that it's true that scripting languages don't require compilation and so does REXX. But how does a computer understand a program then:: I mean is not it a first step to convert the program to some kind of machine code to become understandable to machines?

Re: Why REXX does not need to be compiled?

Posted: Wed Aug 18, 2021 9:49 pm
by Robert Sample
is not it a first step to convert the program to some kind of machine code to become understandable to machines
Not necessarily -- research interpreters and p-code machines. REXX is generally an interpreted language, although (for z/OS at least) there is a REXX compiler available.

Re: Why REXX does not need to be compiled?

Posted: Fri Aug 20, 2021 6:15 pm
by Geetu
Thanks Robert. I read the article on p-code machines at https://en.wikipedia.org/wiki/P-code_machine though I am still trying to understand it.

Re: Why REXX does not need to be compiled?

Posted: Fri Aug 20, 2021 7:42 pm
by Robert Sample
Programs are either compiled or interpreted. Compiled programs can run quickly (and often are optimized for the hardware) but the cost is that changes to the source have to be recompiled which introduces a delay. Interpreted programs can be changed very quickly since the code is read when the program is executed but the cost is that interpreted programs run MUCH slower than compiled programs -- usually a minimum of one order of magnitude slower; it is not unusual for them to run 2 orders of magnitude slower. Optimization also tends to be problematic for interpreted programs since the final machine code isn't known until the program is executing. Also, compiled programs are closely tied to the hardware since they are using the machine's instructions; interpreted programs don't need the machine's instructions until the code is being executed.

Bytecode (p-code) is an attempt to combine these approaches. An ideal p-code machine is conceived and programs are compiled into p-code; for any given platform a p-code translator converts the p-code into machine code. This preserves code portability since the p-code will be the same for all platforms.

Re: Why REXX does not need to be compiled?

Posted: Mon Sep 13, 2021 11:03 pm
by Geetu
Thanks Robert. That's a great a explanation. I read it 3 times.

I have another question, does that mean all the languages which are called compiled languages are actually generating p-code, to make them platform independent?

Re: Why REXX does not need to be compiled?

Posted: Tue Sep 14, 2021 4:34 am
by Robert Sample
Actually bytecode (or p-code) is much more recent than mainframes (I think it dates to the late 1970's but I don't have any specific references to its age) whereas the IBM S/360 and its COBOL compiler dates back to 1964. COBOL and FORTRAN, both extensively used in the 1960's and early to mid 1970's, compiled to the machine instructions and still do -- you can use the LIST option of COBOL to generate in the compile listing the pseudo-assembler code generated by the compiler. That code will match the opcodes and instructions you learn in an IBM Assembler class.

You have to look at the language specification (and sometimes the implementation) to determine if it compiles to p-code or not. Java compiles to p-code and I'm not sure if it is possible to use it any other way. Wikipedia has an article on bytecode and lists a number of languages that compile to p-code.

There are other options, of course. GnuCOBOL (formerly OpenCOBOL) translates COBOL into C and then compiles the C code; I don't think it uses bytecode but I've never delved that deep into what it does. Their Wikipedia article says that the C code is compiled into machine code.

Re: Why REXX does not need to be compiled?

Posted: Sun Oct 10, 2021 9:08 am
by Geetu
Robert Sample wrote: Tue Sep 14, 2021 4:34 am Actually bytecode (or p-code) is much more recent than mainframes (I think it dates to the late 1970's but I don't have any specific references to its age) whereas the IBM S/360 and its COBOL compiler dates back to 1964. COBOL and FORTRAN, both extensively used in the 1960's and early to mid 1970's, compiled to the machine instructions and still do -- you can use the LIST option of COBOL to generate in the compile listing the pseudo-assembler code generated by the compiler. That code will match the opcodes and instructions you learn in an IBM Assembler class.

You have to look at the language specification (and sometimes the implementation) to determine if it compiles to p-code or not. Java compiles to p-code and I'm not sure if it is possible to use it any other way. Wikipedia has an article on bytecode and lists a number of languages that compile to p-code.

There are other options, of course. GnuCOBOL (formerly OpenCOBOL) translates COBOL into C and then compiles the C code; I don't think it uses bytecode but I've never delved that deep into what it does. Their Wikipedia article says that the C code is compiled into machine code.
Thank you Robert, this did help.