Re: machine code vs. byte codes

"Steven D. Majewski" <sdm7g@elvis.med.virginia.edu>
3 Apr 1999 21:55:37 -0500

          From comp.compilers

Related articles
machine code vs. byte codes jamess1@wwnet.com (Mark) (1999-03-28)
Re: machine code vs. byte codes ftu@fi.ruu.nl (1999-04-01)
Re: machine code vs. byte codes sdm7g@elvis.med.virginia.edu (Steven D. Majewski) (1999-04-03)
| List of all articles for this month |
From: "Steven D. Majewski" <sdm7g@elvis.med.virginia.edu>
Newsgroups: comp.compilers
Date: 3 Apr 1999 21:55:37 -0500
Organization: University of Virginia
References: 99-03-111 99-04-006
Keywords: code, performance

>> I'm working a compiler that compiles a very simple C-like language.
>> For the most part the source code will be compiled to byte codes and
>> interpreted, however certain parts can be compiled to machine code.
>
>In that case you can mix byte code and machine code. Just use one byte
>code to escape to inline machine code where appropriate. When the
>inline code returns to the byte code interpreter it must inform the
>interpreter of the new byte code Instruction Pointer. This can be
>implemented by a Jump SubRoutine back to the interpreter at the end of
>the inline code. The return address of the JSR will identify the new
>IP.


Another more flexible mechanism, which is what Forth uses, is the
inverse of having an escape (to native code) code:
  Forth WORDS have a Code Field Address and a Parameter Field Address.
  The CFA points to the code used to interpret the PFA.
  For words defined in forth, the Parameter Field contains the
        compiled threaded code and the CFA points to the threaded code
        interpreter.
  For either built-in primitives or words defined in assembler lang.,
        the CFA points to the Parameter Field, which containing
        machine code, is 'self-interpreting'.


  This mechanism is extensible: Forth had a proto Object-Oriented
      mechanism with the BUILDS/DOES pair, which defines a data
      structure and defines a function -- often an accessor function -
      to 'DO' the structure. The WORD defined by BUILDS is the
      generator for new objects, and the word defined by DOES is the
      function that gets executed by those objects. This is the high-level
      version of setting the CFA & PFA .




I've seen some new interest in this sort of mechanism due to the
ubiquity of JAVA VMs: This is one way to link language implementations
that have their own Virtual Machines interpreters and byte-code, like
Python and Lisp for example, with compiled Java code and native code
compilers.




---| Steven D. Majewski (804-982-0831) <sdm7g@Virginia.EDU> |---
---| Department of Molecular Physiology and Biological Physics |---
---| University of Virginia Health Sciences Center |---
---| P.O. Box 10011 Charlottesville, VA 22906-0011 |---





Post a followup to this message

Return to the comp.compilers page.
Search the comp.compilers archives again.