Difference between revisions of "Yhc/Javascript"

From HaskellWiki
< Yhc
Jump to navigation Jump to search
(More table)
m (Link to nhc98)
Line 2: Line 2:
 
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.
 
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|nhc98]] in attempt to convert its internal PosLambda constructs into Javascript expressions. After some initial success, the project was switched to use the [[Yhc/API/Core|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.
+
The project was started as an experimental patch to [[Implementations#nhc98|nhc98]] in attempt to convert its internal PosLambda constructs into Javascript expressions. After some initial success, the project was switched to use the [[Yhc/API/Core|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.
 
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.

Revision as of 14:44, 7 November 2006

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.

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.

Users Guide

<to be written>

Inner Workings

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

Javascript Objects

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

Javascript Object Types and Their Methods and Properties
Member/
Constructor
Prop
Meth
Constr
HSCons HSEOL HSFun HSDly HSData Description Arguments
HSCons C *         Builds a list CONS cell head:
head element
tail:
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:
arity of the function known by the compiler
body:
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

Examples and Demos


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