org.erights.e.elang.smallcaps
Class SmallcapsEncoder

java.lang.Object
  |
  +--org.erights.e.elang.smallcaps.SmallcapsEncoder
All Implemented Interfaces:
SmallcapsEmitter, SmallcapsOps

public class SmallcapsEncoder
extends Object
implements SmallcapsOps, SmallcapsEmitter

Untamed: A code generator that just emits Smallcaps instructions directly.

Author:
Mark S. Miller, Darius Bacon

Field Summary
private  byte[] myBuf
          Encoded bytes in reverse order.
private  int myCodeSize
           
private  int myMaxHandlers
           
private  int myMaxOperands
           
private  int myNumHandlers
           
private  int myNumOperands
           
 
Fields inherited from interface org.erights.e.elang.smallcaps.SmallcapsOps
ADDR_FRAME, ADDR_FRAME_SLOT, ADDR_LITERAL, ADDR_LOCAL, ADDR_LOCAL_SLOT, ADDR_OUTER_SLOT, OP_ASSIGN, OP_BIND, OP_BIND_SLOT, OP_BRANCH, OP_CALL, OP_CALL_ONLY, OP_CDR_PATT, OP_CHAR, OP_DUP, OP_EJECTOR, OP_EJECTOR_ONLY, OP_END_HANDLER, OP_FALSE, OP_FLOAT64, OP_JUMP, OP_LIST_PATT, OP_NEG_INT, OP_NOUN, OP_NULL, OP_OBJECT, OP_POP, OP_RETURN, OP_ROT, OP_SCOPE, OP_SEND, OP_SEND_ONLY, OP_SLOT, OP_STRING, OP_SWAP, OP_TRUE, OP_TRY, OP_TWINE, OP_UNWIND, OP_WHOLE_NUM
 
Constructor Summary
(package private) SmallcapsEncoder()
           
 
Method Summary
 void associateSourceLocation(int lowLabel, int highLabel, SourceSpan span)
          Enabled:
(package private)  byte[] copyBytes()
           
 void emitAssign(int addressingMode, int index)
          Enabled:
 void emitBind(int addressingMode, int index, boolean slot)
          Enabled:
 void emitBranch()
          Enabled:
 void emitCall(String verb, int arity, boolean only)
          Enabled:
 void emitCdrPatt(int n)
          Enabled:
 void emitChar(char chr)
          Enabled:
 void emitContourTop()
          Enabled:
 void emitDup()
          Enabled:
 void emitEjector(int label)
          Enabled:
 void emitEjectorOnly(int label)
          Enabled:
 void emitEndHandler()
          Enabled:
 void emitFalse()
          Enabled:
 void emitFloat64(double float64)
          Enabled:
 void emitInteger(BigInteger num)
          Enabled:
private  void emitInvoke(int opcode, String verb, int arity, int pushed)
           
 void emitJump(int label)
          Enabled:
 void emitListPatt(int n)
          Enabled:
 void emitLiteral(Object obj)
          Enabled:
 void emitNoun(int addressingMode, int index, boolean slot)
          Enabled:
 void emitNull()
          Enabled:
 void emitObject(String docComment, String optFQN, EExpr[] auditors, EScript eScript)
          Enabled:
 void emitPop()
          Enabled:
 void emitRot()
          Enabled:
 void emitScope()
          Enabled:
 void emitSend(String verb, int arity, boolean only)
          Enabled:
 void emitString(String str)
          Enabled:
 void emitSwap()
          Enabled:
 void emitTrue()
          Enabled:
 void emitTry(int label)
          Enabled:
 void emitUnwind(int label)
          Enabled:
 int getLabel()
          Enabled: Return a value representing the current position in the code buffer.
(package private) static int numDocBytes(BigInteger wholeNum)
          How many bytes are needed to represent the whole number wholeNum in Waterken Doc ExtensionNumber format?
private  void writeByte(int byt)
           
(package private)  void writeBytes(byte[] bytes)
           
(package private)  void writeChar(char c)
          Writes out a unicode character as a high-order byte followed by a low order byte.
(package private)  void writeFloat64(double float64)
          Writes out a float64 as 8 bytes according to Double.doubleToLongBits(double), written out most significant byte first.
(package private)  void writeOpcode(int opcode, int deltaOperands, int deltaHandlers)
           
(package private)  void writeUTF(String str)
          Writes out a String of Unicode characters in UTF-8.
(package private)  void writeWholeNum(BigInteger wholeNum)
          Encodes a whole number (a non-negative integer) using the Waterken Doc ExtensionNumber format, written using just enough bytes.
(package private)  void writeWholeNum(BigInteger wholeNum, int numBytes)
          Encodes a whole number (a non-negative integer) using the Waterken Doc ExtensionNumber format, zero-extended to fit into numBytes bytes.
(package private)  void writeWholeNum(int wholeNum)
          Just like writeWholeNum(BigInteger), but when the argument already fits in a Java int.
(package private)  void writeWholeNum(int wholeNum, int numBytes)
          Just like writeWholeNum(BigInteger, int), but when the argument already fits in a Java int.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

myBuf

private byte[] myBuf
Encoded bytes in reverse order.


myCodeSize

private int myCodeSize

myNumOperands

private int myNumOperands

myMaxOperands

private int myMaxOperands

myNumHandlers

private int myNumHandlers

myMaxHandlers

private int myMaxHandlers
Constructor Detail

SmallcapsEncoder

SmallcapsEncoder()
Method Detail

associateSourceLocation

public void associateSourceLocation(int lowLabel,
                                    int highLabel,
                                    SourceSpan span)
Enabled:

Specified by:
associateSourceLocation in interface SmallcapsEmitter

getLabel

public int getLabel()
Enabled: Return a value representing the current position in the code buffer. This is *not* an address; it's an opaque value used as an argument to emitJump(), etc.

Specified by:
getLabel in interface SmallcapsEmitter

emitContourTop

public void emitContourTop()
Enabled:

Specified by:
emitContourTop in interface SmallcapsEmitter

emitDup

public void emitDup()
Enabled:

Specified by:
emitDup in interface SmallcapsEmitter

emitPop

public void emitPop()
Enabled:

Specified by:
emitPop in interface SmallcapsEmitter

emitSwap

public void emitSwap()
Enabled:

Specified by:
emitSwap in interface SmallcapsEmitter

emitRot

public void emitRot()
Enabled:

Specified by:
emitRot in interface SmallcapsEmitter

emitJump

public void emitJump(int label)
Enabled:

Specified by:
emitJump in interface SmallcapsEmitter

emitBranch

public void emitBranch()
Enabled:

Specified by:
emitBranch in interface SmallcapsEmitter

emitCall

public void emitCall(String verb,
                     int arity,
                     boolean only)
Enabled:

Specified by:
emitCall in interface SmallcapsEmitter

emitSend

public void emitSend(String verb,
                     int arity,
                     boolean only)
Enabled:

Specified by:
emitSend in interface SmallcapsEmitter

emitInvoke

private void emitInvoke(int opcode,
                        String verb,
                        int arity,
                        int pushed)

emitEjectorOnly

public void emitEjectorOnly(int label)
Enabled:

Specified by:
emitEjectorOnly in interface SmallcapsEmitter

emitEjector

public void emitEjector(int label)
Enabled:

Specified by:
emitEjector in interface SmallcapsEmitter

emitTry

public void emitTry(int label)
Enabled:

Specified by:
emitTry in interface SmallcapsEmitter

emitUnwind

public void emitUnwind(int label)
Enabled:

Specified by:
emitUnwind in interface SmallcapsEmitter

emitEndHandler

public void emitEndHandler()
Enabled:

Specified by:
emitEndHandler in interface SmallcapsEmitter

emitInteger

public void emitInteger(BigInteger num)
Enabled:

Specified by:
emitInteger in interface SmallcapsEmitter

emitFloat64

public void emitFloat64(double float64)
Enabled:

Specified by:
emitFloat64 in interface SmallcapsEmitter

emitChar

public void emitChar(char chr)
Enabled:

Specified by:
emitChar in interface SmallcapsEmitter

emitString

public void emitString(String str)
Enabled:

Specified by:
emitString in interface SmallcapsEmitter

emitTrue

public void emitTrue()
Enabled:

Specified by:
emitTrue in interface SmallcapsEmitter

emitFalse

public void emitFalse()
Enabled:

Specified by:
emitFalse in interface SmallcapsEmitter

emitNull

public void emitNull()
Enabled:

Specified by:
emitNull in interface SmallcapsEmitter

emitLiteral

public void emitLiteral(Object obj)
Enabled:

Specified by:
emitLiteral in interface SmallcapsEmitter

emitScope

public void emitScope()
Enabled:

Specified by:
emitScope in interface SmallcapsEmitter

emitObject

public void emitObject(String docComment,
                       String optFQN,
                       EExpr[] auditors,
                       EScript eScript)
Enabled:

Specified by:
emitObject in interface SmallcapsEmitter

emitListPatt

public void emitListPatt(int n)
Enabled:

Specified by:
emitListPatt in interface SmallcapsEmitter

emitCdrPatt

public void emitCdrPatt(int n)
Enabled:

Specified by:
emitCdrPatt in interface SmallcapsEmitter

emitNoun

public void emitNoun(int addressingMode,
                     int index,
                     boolean slot)
Enabled:

Specified by:
emitNoun in interface SmallcapsEmitter

emitAssign

public void emitAssign(int addressingMode,
                       int index)
Enabled:

Specified by:
emitAssign in interface SmallcapsEmitter

emitBind

public void emitBind(int addressingMode,
                     int index,
                     boolean slot)
Enabled:

Specified by:
emitBind in interface SmallcapsEmitter

copyBytes

byte[] copyBytes()

writeByte

private void writeByte(int byt)

writeOpcode

void writeOpcode(int opcode,
                 int deltaOperands,
                 int deltaHandlers)

writeBytes

void writeBytes(byte[] bytes)

numDocBytes

static int numDocBytes(BigInteger wholeNum)
How many bytes are needed to represent the whole number wholeNum in Waterken Doc ExtensionNumber format?


writeWholeNum

void writeWholeNum(BigInteger wholeNum)
Encodes a whole number (a non-negative integer) using the Waterken Doc ExtensionNumber format, written using just enough bytes.


writeWholeNum

void writeWholeNum(BigInteger wholeNum,
                   int numBytes)
Encodes a whole number (a non-negative integer) using the Waterken Doc ExtensionNumber format, zero-extended to fit into numBytes bytes.

numBytes must be large enough, and therefore must be >= 1 even if wholeNum == 0. By "zero extended", we mean extended with leading 0x80 bytes, in keeping with the ExtensionNumber format.


writeWholeNum

void writeWholeNum(int wholeNum)
Just like writeWholeNum(BigInteger), but when the argument already fits in a Java int.


writeWholeNum

void writeWholeNum(int wholeNum,
                   int numBytes)
Just like writeWholeNum(BigInteger, int), but when the argument already fits in a Java int.


writeUTF

void writeUTF(String str)
Writes out a String of Unicode characters in UTF-8.


writeChar

void writeChar(char c)
Writes out a unicode character as a high-order byte followed by a low order byte.


writeFloat64

void writeFloat64(double float64)
Writes out a float64 as 8 bytes according to Double.doubleToLongBits(double), written out most significant byte first.



comments?