Difference between revisions of "Yhc/API/Bytecode"

From HaskellWiki
< Yhc‎ | API
Jump to navigation Jump to search
 
 
(One intermediate revision by the same user not shown)
Line 1: Line 1:
  +
{{Yhc}}
   
 
On the step towards a full API for the whole compiler, an API for just the bytecode first will probably be desirable.
 
On the step towards a full API for the whole compiler, an API for just the bytecode first will probably be desirable.
Line 6: Line 7:
 
== Module ==
 
== Module ==
   
 
data Module = Module {objects :: [Object]}
{{{
 
#!syntax haskell
 
data Module = Module {objects :: [Object]}
 
   
data PackageVer = PackageVer {version :: [Int], name :: String}
+
data PackageVer = PackageVer {version :: [Int], name :: String}
data ModuleName = ModuleName PackageVer {name :: String}
+
data ModuleName = ModuleName PackageVer {name :: String}
data Import = Import ModuleName {name :: String, arity :: Int}
+
data Import = Import ModuleName {name :: String, arity :: Int}
data Export = Export {name :: String, obj :: Object, arity :: Int}
+
data Export = Export {name :: String, obj :: Object, arity :: Int}
   
data Object = Function Arity ConstTable HufByteCode
+
data Object = Function Arity ConstTable HufByteCode
| Constructor Arity TagNo
+
| Constructor Arity TagNo
   
type ConstTable = [Const]
+
type ConstTable = [Const]
   
type HufByteCode = [HufBC]
+
type HufByteCode = [HufBC]
}}}
 
   
 
== Bytecode ==
 
== Bytecode ==
Line 27: Line 25:
 
There are tree types of bytecode representation:
 
There are tree types of bytecode representation:
   
 
data GraphNode = ...
{{{
 
 
data LabeledJumps = ...
#!syntax haskell
 
data GraphNode = ...
 
data LabeledJumps = ...
 
}}}
 
   
 
Then there are the api's
 
Then there are the api's
{{{
 
#!syntax haskell
 
instance Show GraphNode
 
instance Show ByteCode
 
instance Show ByteCodeHuf
 
instance Show ...
 
   
graphToByteCode :: GraphNode -> ByteCode
+
instance Show GraphNode
byteCodeToGraph :: ByteCode -> GraphNode
+
instance Show ByteCode
byteCodeCompress :: ByteCode -> ByteCodeHuf
+
instance Show ByteCodeHuf
 
instance Show ...
byteCodeInflate :: ByteCodeHuf -> ByteCode
 
  +
  +
graphToByteCode :: GraphNode -> ByteCode
  +
byteCodeToGraph :: ByteCode -> GraphNode
  +
byteCodeCompress :: ByteCode -> ByteCodeHuf
 
byteCodeInflate :: ByteCodeHuf -> ByteCode
   
writeModule :: Module -> FilePath -> IO ()
+
writeModule :: Module -> FilePath -> IO ()
readModule :: FilePath -> IO Module
+
readModule :: FilePath -> IO Module
   
-- do memory and zapping analysis
+
-- do memory and zapping analysis
memAnalysis :: a -> a
+
memAnalysis :: a -> a
   
-- peep hole optimisations
+
-- peep hole optimisations
peephole :: a -> a
+
peephole :: a -> a
}}}
 

Latest revision as of 23:36, 15 January 2006

Part of Yhc

(Download)

On the step towards a full API for the whole compiler, an API for just the bytecode first will probably be desirable.

There are two entirely separate lumps in this, the raw bytecode, and the wrappers that make a module file.

Module

data Module = Module {objects :: [Object]}
data PackageVer = PackageVer {version :: [Int], name :: String}
data ModuleName = ModuleName PackageVer {name :: String}
data Import = Import ModuleName {name :: String, arity :: Int}
data Export = Export {name :: String, obj :: Object, arity :: Int}
data Object = Function Arity ConstTable HufByteCode
            | Constructor Arity TagNo
type ConstTable = [Const]
type HufByteCode = [HufBC]

Bytecode

There are tree types of bytecode representation:

data GraphNode = ...
data LabeledJumps = ...

Then there are the api's

instance Show GraphNode
instance Show ByteCode
instance Show ByteCodeHuf
instance Show ...

graphToByteCode :: GraphNode -> ByteCode
byteCodeToGraph :: ByteCode -> GraphNode
byteCodeCompress :: ByteCode -> ByteCodeHuf
byteCodeInflate :: ByteCodeHuf -> ByteCode
writeModule :: Module -> FilePath -> IO ()
readModule :: FilePath -> IO Module
-- do memory and zapping analysis
memAnalysis :: a -> a
-- peep hole optimisations
peephole :: a -> a