开发者

How to work WebSharper translator?

Could anyone explain how to work WebSharper translator in conjunction with the F#? Is it translate F# code to JS itself or using F# compiler for it?

In second case, what F# compiler are doing when finds [] attribute in source? Does compiler generate functions in any case and in run开发者_Go百科time construct JS as reflection from compiled bytecode or there something other?


I develop WebSharper. Good question!

Roughly the compilation looks like this:

a.dll: a.fs b.fs c.fs
    fsc ...

a.dll.js: a.dll
    WebSharper.exe ..

When functions are annotated with [<JavaScript>], which is an alias for [<ReflectedDefinition>], the F# compiler does not only compile these functions to .NET IL, but also stores the representation of their syntax in the DLL metadata. This representation has type Quotations.Expr and can be recovered by reflection. Have a look at Quotations.DerivedPatterns.MethodWithReflectedDefinition.

WebSharper is therefore a source to source translator, and it is pretty direct (preserves lambdas, for example). In WebSharper 2.0 we have an intermediate Scheme-like language, but that is only there to help optimize the generated code.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜