<?xml version='1.0' encoding='UTF-8'?><rss xmlns:atom='http://www.w3.org/2005/Atom' xmlns:openSearch='http://a9.com/-/spec/opensearchrss/1.0/' version='2.0'><channel><atom:id>tag:blogger.com,1999:blog-5061189310503801533</atom:id><lastBuildDate>Sat, 08 Mar 2008 03:37:07 +0000</lastBuildDate><title>Erlang for .NET</title><description/><link>http://erlangdotnet.net/</link><managingEditor>Kappuccino Kid</managingEditor><generator>Blogger</generator><openSearch:totalResults>4</openSearch:totalResults><openSearch:startIndex>1</openSearch:startIndex><openSearch:itemsPerPage>25</openSearch:itemsPerPage><item><guid isPermaLink='false'>tag:blogger.com,1999:blog-5061189310503801533.post-1926041268912245132</guid><pubDate>Sat, 22 Sep 2007 21:46:00 +0000</pubDate><atom:updated>2007-09-23T19:45:07.399-07:00</atom:updated><title>Why Compile Erlang for the CLR?</title><description>Erlang for the CLR? Why do such a crazy thing?&lt;br /&gt;&lt;ul&gt;&lt;li&gt;The .NET ecosystem lacks a concurrent programming language. C#, Visual Basic and so on have limited language support for concurrency (basically providing the equivalent of Java's &lt;span style="font-style: italic;"&gt;synchronized.&lt;/span&gt;) Erlang would ideally fill this gap.&lt;/li&gt;&lt;li&gt;Windows programmers expect multi-language interoperation, to be able to readily consume common Windows APIs and frameworks, and to be able to integrate with Windows applications. The CLR is the substrate that enables all of these scenarios. Incidentally, a lot of the .NET and Win32 libraries and frameworks complement the common Erlang libraries. (&lt;a href="http://windowsclient.net/"&gt;UI libraries,&lt;/a&gt; for example.)&lt;br /&gt;&lt;/li&gt;&lt;li&gt;The CLR has a security model for dynamically-loaded code called &lt;a href="http://msdn2.microsoft.com/en-us/library/930b76w0%28vs.80%29.aspx"&gt;Code Access Security&lt;/a&gt; (CAS.) CAS provides metadata for dynamically-loaded code to declare the permissions it requires, APIs for loading code with specific sets of permissions and for demanding permissions dynamically, and security policy management tools. Erlang's security system is much simpler: permissions are associated with entire Erlang virtual machines ('nodes') which can either be completely trusted, or not trusted at all. Bringing CAS to Erlang would make secure, distributed programming in Erlang first class.&lt;/li&gt;&lt;li&gt;Erlang occupies an interesting spot: It is dynamic, functional, and concurrent. That is new territory on the CLR.&lt;br /&gt;&lt;/li&gt;&lt;li&gt;The CLR runs on servers, the Windows client, and &lt;a href="http://silverlight.net/"&gt;in browsers.&lt;/a&gt; That is new territory for Erlang.&lt;/li&gt;&lt;/ul&gt;</description><link>http://erlangdotnet.net/2007/09/why-compile-erlang-for-clr.html</link><author>Kappuccino Kid</author></item><item><guid isPermaLink='false'>tag:blogger.com,1999:blog-5061189310503801533.post-1089885530019630382</guid><pubDate>Thu, 20 Sep 2007 05:35:00 +0000</pubDate><atom:updated>2007-09-21T00:29:52.976-07:00</atom:updated><title>Inside BEAM, the Erlang Virtual Machine</title><description>&lt;div&gt;OTP R11B-5 includes more than one million lines of Erlang. The kernel and standard library are about a third of these lines. The emulator, BEAM, is around 200,000 lines of C.&lt;/div&gt;&lt;div&gt;&lt;br /&gt;&lt;/div&gt;&lt;div&gt;BEAM's C &lt;span class="Apple-style-span" style="font-style: italic;"&gt;main&lt;/span&gt; functions are platform-specific and live in &lt;span class="Apple-style-span" style="font-style: italic; "&gt;erts/emulator/sys/unix, win32,&lt;/span&gt; and so on. (Windows actually has two &lt;span class="Apple-style-span" style="font-style: italic; "&gt;mains:&lt;/span&gt; a simple one similar to the Unix entrypoints in &lt;span class="Apple-style-span" style="font-style: italic; "&gt;erl_main.c,&lt;/span&gt; and a more complex one in &lt;span class="Apple-style-span" style="font-style: italic; "&gt;erl_main_sae.c&lt;/span&gt; which is used in bootstrapping the toolchain.) The conventional &lt;span class="Apple-style-span" style="font-style: italic; "&gt;mains&lt;/span&gt; immediately call &lt;span class="Apple-style-span" style="font-style: italic; "&gt;erl_start&lt;/span&gt; which processes command line arguments, copies &lt;span class="Apple-style-span" style="font-style: italic; "&gt;argv&lt;/span&gt; into a list of strings, creates a process and runs &lt;span class="Apple-style-span" style="font-style: italic; "&gt;otp_ring0&lt;/span&gt; with the argument list. &lt;span class="Apple-style-span" style="font-style: italic;"&gt;otp_ring0&lt;/span&gt; looks up and runs &lt;span class="Apple-style-span" style="font-style: italic; "&gt;init:boot/1.&lt;/span&gt; There is more initialization after this, but from &lt;span class="Apple-style-span" style="font-style: italic; "&gt;otp_ring0&lt;/span&gt; on, apart from some built-in functions, Erlang is implemented in Erlang. &lt;/div&gt;&lt;div&gt;&lt;br /&gt;&lt;/div&gt;&lt;div&gt;In practice, the Erlang compiler (another 30,000 lines of Erlang) compiles Erlang to BEAM bytecodes. When &lt;span class="Apple-style-span" style="font-style: italic;"&gt;erl_start&lt;/span&gt; runs &lt;span class="Apple-style-span" style="font-style: italic;"&gt;otp_ring0&lt;/span&gt; and so on, it is loading BEAM binaries generated by the Erlang compiler earlier. The BEAM instruction set is register-based and has 130 instructions. These include instructions for arithmetic, comparsions and boolean logic; manipulating strings, tuples and lists; stack and heap allocation and freeing; type tests for Erlang primitives (numbers, lists, process IDs, references, and so on);  jumps, structured exception handling, and calls and returns; sending messages and reading from the process' mailbox; waiting and timeouts; and so on. The instructions are listed in &lt;span class="Apple-style-span" style="font-style: italic;"&gt;lib/compiler/src/beam_opcodes.erl.&lt;/span&gt; In BEAM, &lt;span class="Apple-style-span" style="font-style: italic;"&gt;erts/emulator/beam/ops.tab&lt;/span&gt; contains rewrite rules that map typed BEAM instructions into emulator internals. A Perl script (&lt;span class="Apple-style-span" style="font-style: italic;"&gt;beam_makeops&lt;/span&gt;) translates this file into C code (mostly macros.)&lt;/div&gt;&lt;div&gt;&lt;br /&gt;&lt;/div&gt;&lt;div&gt;Some Erlang built-in function (BIFs) calls are translated into an extended instruction set not generated by the compiler. For example, the BIF &lt;span class="Apple-style-span" style="font-style: italic;"&gt;erlang:self/3&lt;/span&gt; is rewritten as a single 'self' instruction. Other BIF linkage is via a set of instructions for calling BIFs of varying arities. &lt;span class="Apple-style-span" style="font-style: italic;"&gt;erts/emulator/beam/bif.tab&lt;/span&gt; maps BIF labels into C externs. For example, calls to the BIF &lt;span class="Apple-style-span" style="font-style: italic;"&gt;erlang:spawn/3&lt;/span&gt; boil down to a call to &lt;span class="Apple-style-span" style="font-style: italic;"&gt;spawn_3&lt;/span&gt; (found in &lt;span class="Apple-style-span" style="font-style: italic;"&gt;erts/emulator/bif.c&lt;/span&gt;),&lt;span class="Apple-style-span" style="font-style: italic;"&gt; &lt;/span&gt;which in turn thunks to &lt;span class="Apple-style-span" style="font-style: italic;"&gt;erl_create_process.&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span class="Apple-style-span" style="font-style: italic;"&gt;&lt;br /&gt;&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span class="Apple-style-span" style="font-style: italic;"&gt;&lt;span class="Apple-style-span" style="font-style: normal; "&gt;Incidentally, processes are not related to threads or operating system processes. Instead, BEAM maintains queues of processes that are scheduled to run. There is one queue per priority level.&lt;/span&gt; &lt;span class="Apple-style-span" style="font-style: normal;"&gt;Schedulers&lt;/span&gt;&lt;span class="Apple-style-span" style="font-style: normal;"&gt; pick processes from the queues and run them. Processes maintain their registers and a pointer to the next instruction to execute.&lt;/span&gt;&lt;br /&gt;&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span class="Apple-style-span" style="font-style: italic;"&gt;&lt;br /&gt;&lt;/span&gt;&lt;/div&gt;&lt;div&gt;The garbage collector, in &lt;span class="Apple-style-span" style="font-style: italic;"&gt;erts/emulator/beam/erl_gc.c,&lt;/span&gt; is a mark-and-sweep copying collector. The most interesting thing about the BEAM garbage collector is that the garbage collected heaps are per-process. BEAM can do this because Erlang processes communicate explicitly via messages, and not via mutating shared memory. The CLR, in contrast, divides heaps into generations protected by write barriers and does incremental collection to avoid having to garbage collect all of a program's heap at the same time. This extra complexity is part of the price of using a shared heap to communicate between threads in the CLR.&lt;/div&gt;</description><link>http://erlangdotnet.net/2007/09/inside-beam-erlang-virtual-machine.html</link><author>Kappuccino Kid</author></item><item><guid isPermaLink='false'>tag:blogger.com,1999:blog-5061189310503801533.post-4006162902308669532</guid><pubDate>Wed, 19 Sep 2007 08:00:00 +0000</pubDate><atom:updated>2007-09-19T02:32:14.237-07:00</atom:updated><title>Stranger Bedfellows: Erlang and the Dynamic Language Runtime</title><description>The &lt;a href="http://msdn.microsoft.com/msdnmag/issues/07/10/CLRInsideOut/default.aspx"&gt;Dynamic Language Runtime&lt;/a&gt; (DLR) sprung from &lt;a href="http://www.codeplex.com/IronPython"&gt;IronPython&lt;/a&gt; internals and will provide the integration point between the CLR and dynamic languages (Python, Ruby, JavaScript and others) and define interoperation between components in different dynamic languages. The former includes abstract syntax for dynamic languages, a member resolution cache, and call-site thunks that cache method resolution. The member resolution cache is purged when a type is introduced or a type's representation changes. The call-site thunks can be strongly typed (at least, for up to six arguments); 'object' acts as a type wildcard the binding of which determines cache validity.&lt;br /&gt;&lt;br /&gt;Is the DLR relevant to Erlang? Erlang is untyped, but crucially symbol resolution is straightforward and static, unlike Ruby/Python/etc. member resolution. The DLR is probably useful around the edges, for example in CLR interoperability, where DLR dynamic sites could cache the result of Reflection look-ups on plain old CLR objects, which must presumably appear to Erlang programs as processes (or Erlang must be heavily bastardized.) Erlang .NET's internals will probably more closely resemble F#--pattern matching and tuples--than any DLR language.</description><link>http://erlangdotnet.net/2007/09/stranger-bedfellows-erlang-and-dynamic.html</link><author>Kappuccino Kid</author></item><item><guid isPermaLink='false'>tag:blogger.com,1999:blog-5061189310503801533.post-5873311748513688559</guid><pubDate>Tue, 18 Sep 2007 07:56:00 +0000</pubDate><atom:updated>2007-09-18T01:03:19.034-07:00</atom:updated><title>Erlang and .NET: Strange bedfellows?</title><description>There are a few challenges in implementing Erlang for .NET:&lt;div&gt;&lt;ol id=""&gt;&lt;li&gt;Erlang is dynamic, functional, concurrent and distributed. The original languages on the CLR were static, object-oriented, not especially concurrent (there are limited language primitives for per-thread locks) and not distributed (there is a deprecated &lt;a href="http://java.sun.com/javase/technologies/core/basic/rmi/"&gt;RMI&lt;/a&gt; remote-stub mechanism, &lt;a href="http://msdn2.microsoft.com/en-us/library/kwdt6w2k.aspx"&gt;Remoting&lt;/a&gt;; and a few &lt;a href="http://msdn.microsoft.com/wcf/"&gt;web services libraries.&lt;/a&gt;) However there have been some bold attempts at dynamic languages (&lt;a href="http://www.codeplex.com/Wiki/View.aspx?ProjectName=IronPython"&gt;IronPython,&lt;/a&gt; &lt;a href="http://plas2003.fit.qut.edu.au/Ruby.NET/"&gt;Gardens Point Ruby&lt;/a&gt;) and functional languages (&lt;a href="http://research.microsoft.com/fsharp"&gt;F#&lt;/a&gt;.)&lt;/li&gt;&lt;li&gt;Erlang processes are cheap. In the CLR, processes are expensive (a CLR thread reserves 1 MB of stack space!) In fact, reliable, fast concurrent programming on Windows with the CLR is &lt;a href="http://www.bluebytesoftware.com/"&gt;downright difficult.&lt;/a&gt; Objects are about the cheapest interesting thing in the CLR, so I guess Erlang processes map to objects.&lt;/li&gt;&lt;li&gt;Although the core Erlang language is small, it isn't set down formally. The implementation is the definition, which is one of the problems that derailed a &lt;a href="http://research.microsoft.com/Collaboration/University/Europe/events/Workshop/Rotor/wshop-JGough.ppt"&gt;Perl implementation for .NET.&lt;/a&gt; For a working definition, Erlang's bytecode format might be a good starting point, however there have been many of those, and like Erlang itself, the meaning of the bytecodes aren't written down either. The current incarnation ('BEAM') is embodied in about 100,000 lines of C code.&lt;/li&gt;&lt;li&gt;Because there is no shared memory between processes, Erlang's garbage collector can collect per-process. This means even naive stop-the-world garbage collection is highly concurrent in a global sense because of Erlang programs' heavy use of processes. For short-lived processes, the default heap is small enough for per-process memory management to work effectively as an area-based allocator. This limits the benefit of using the CLR's excellent generational garbage collector, because there is no way to hint the CLR that memory will be scoped to a particular process (although arguably short-lived processes should fit into gen-0 heap.)&lt;/li&gt;&lt;li&gt;Erlang has C and Java interoperation, but C and Java aren't .NET (the former supported reasonably well with P/Invoke, and the latter with an object model like .NET's, yet not quite.) More difficult than just calling .NET libraries from Erlang, .NET developers typically need a language to produce static constructs to have something to call, which could be difficult given Erlang's baroque syntax and dynamic nature. .NET has little-known terms for various aspects of interoperation (CTS and CLS producer/consumer) and even these don't cover many common scenarios (such as .NET generics.) Nonetheless, the CLR is leveraging Metcalfe's law for heterogenous components, and Erlang should be another exponent in that equation.&lt;/li&gt;&lt;li&gt;Erlang for the CLR should have syntax highlighting, IntelliSense, and debugger integration with Visual Studio.&lt;/li&gt;&lt;li&gt;The Erlang community is relatively small, and disjoint to the Microsoft developer community, and likely not interested in Erlang for the CLR.&lt;/li&gt;&lt;/ol&gt;&lt;div&gt;There are, however, some consoling things:&lt;/div&gt;&lt;div&gt;&lt;ol id=""&gt;&lt;li&gt;The CLR has an excellent JIT, and Erlang has not been exposed to an excellent JIT. Because Erlang is essentially a dynamic language, I would have dismissed this--surely Erlang has more to gain from a better garbage collector than a JIT? But anecdotally (from a CLR architect) IronPython's solid performance is due to both the JIT and the GC.&lt;/li&gt;&lt;li&gt;Erlang libraries are mostly implemented in Erlang, and not C. This means porting the relatively small Erlang runtime system should give immediate access to OTP, Mnesia, and other big Erlang libraries.&lt;/li&gt;&lt;li&gt;The CLR supports asynchronous IO with thread pools and &lt;a href="http://msdn2.microsoft.com/en-us/library/system.iasyncresult.aspx"&gt;IAsyncResult.&lt;/a&gt; The lack of asynchronous IO was one of the factors making Erlang implementations on the JVM impractical--Erlang's thread scheduler is built around asynchronous IO, and the JVM's wasn't. (Since Java 1.5, &lt;a href="https://java.sun.com/j2se/1.5.0/docs/api/java/util/concurrent/package-summary.html"&gt;java.util.concurrent&lt;/a&gt; has been addressing this issue though.)&lt;/li&gt;&lt;li&gt;Erlang's dynamism is relatively constrained. For example, Erlang's &lt;a href="http://wiki.trapexit.org/index.php/String_Eval"&gt;eval&lt;/a&gt; takes a list of bindings for the evaluator, as opposed to JavaScript's eval which can access variables in the callee's scope.&lt;/li&gt;&lt;/ol&gt;&lt;/div&gt;&lt;/div&gt;</description><link>http://erlangdotnet.net/2007/09/erlang-and-net-strange-bedfellows.html</link><author>Kappuccino Kid</author></item></channel></rss>