Personal tools


From HaskellWiki

< Yhc(Difference between revisions)
Jump to: navigation, search
m (Link to nhc98)
(More table)

Revision as of 15:01, 7 November 2006


1 Brief Overview

An experimental sub-project, Yhc Core to Javascript Converter (ycr2js), is aimed to create a tool that generates Javascript out of a binary Yhc core file.

The project was started as an experimental patch to nhc98 in attempt to convert its internal PosLambda constructs into Javascript expressions. After some initial success, the project was switched to use the Yhc Core as the source for transformation. Recently, with a great amount of help from the Yhc Team, the project has been integrated into the main Yhc source tree and is moving towards closer integration with the compiler.

Ability to convert an arbitrary Haskell source into Javascript makes it possible to execute Haskell programs in a Web browser. This, in turn, allows for development of both client and server sides of an Internet application entirely in Haskell.

Server side solutions in Haskell have been around for a while, such as HAppS -- Haskell Application Server, Haskell Server Pages, and others. For the client side, HSPClientSide has been recently introduced, which is a close analog to ycr2js. HSPClientSide provides a domain-specific language to define the client side Web page structure (static HTML and Javascript). On the contrary, ycr2js helps convert any compilable Haskell source into Javascript.

2 Principles of Operation

The Yhc compiler generally produces a binary bytecode file (usually named with .hbc extension) for each Haskell module compiled. These bytecode files are to be interpreted by yhi, a command-line bytecode interpreter.

The compiler is also capable of producing a binary core file (usually named with .ycr extension), and also its human-readable representation for each Haskell module compiled. The internal structure of core is based on significantly simplified nhc98's PosLambda constructs (Yhc is derived from nhc98 code). Core consists of definitions for compiled Haskell functions and data objects.

The feature of core linking was added recently to Yhc. This allows for merging core files from several modules together, removing functions that are not used (similar to static linking performed by a traditional Unix or Windows executable linker). The resulting file (usually named with .yca extension) has the same format as per-module core files.

Binary core files may be read back into computer memory using the Yhc Core API functions.

The ycr2js program reads the binary core file specified (.yca or .ycr), and performs conversion of Haskell functions compiled into Core to their Javascript representation storing the generated Javascript code in a file. Resulting Javascript may be embedded on a (X)HTML page to be loaded into a Web browser.

3 Users Guide

<to be written>

4 Inner Workings

In this section, internal structure of Javascript objects and runtime support algorithms is reviewed.

4.1 Javascript Objects

The table below summarizes types of Javascript objects used in the ycr2jsgenerated Javascript code.

Javascript Object Types and Their Methods and Properties
HSCons HSEOL HSFun HSDly HSData Description/Arguments
HSCons C *         Builds a list CONS cell head:
head element
remainder of the list
HSEOL C   *       Final element of a list or an empty list  
HSFun C     *     Creates a function thunk with no arguments applied to name:
function name to be used for debugging/exception tracing
arity of the function known by the compiler
expression to apply to function's arguments and evaluate
HSDly C       *   A special object to wrap around a saturated function call thunk:
saturated function call that is a HSFun object with number of arguments applied to (_a) equal to the function arity (_x); evaluation of this thunk will be delayed until it is applied to an argument which would have oversaturated the call in the absence of HSDly
HSData C         * Builds a data object other than a CONS cell or an Empty List con:
constructor name (with non-alphanumeric characters replaced with underscored character codes)
a Javascript Array containing contructor arguments
_r P * * * * * Boolean: true when a thunk may be evaluated.
  • true in HSFun when the call is saturated (_a.length == _x)
  • Always true in HSDly
  • Always false in HSCons, HSEOL, HSData

5 Examples and Demos

--DimitryGolubovsky 19:02, 6 November 2006 (UTC)