Monthly Archives: May 2012

AjGenesis Code Generation in .NET, Javascript and Ruby, All the Gates are Open

Usually, I get up early in the morning. Today, I got up a bit earlier, with some ideas about how to implement a simple template engine for my personal project, AjGenesis in Ruby. Then, I put my hands at work, and 3 hours later I had a solution, built using TDD (I made frequent commits, so you can see the progress of development in the GitHub Log).

The result at my GitHub account:

Initially, I planned to use one of the template engines already available in Ruby, like Haml. But I decided to write my own implementation. Past week, I wrote AjGenesis in Javascript/NodeJs, see:

In that project, I separated the template engine in another package:

In this way, I designed the template format to be similar to the original templates in classic AjGenesis.

I reuse the Javascript template engine in another new project (code kata of the past weekend):

a simple MVC implementation over NodeJs/Express.

So, now you have three projects:

Classical AjGenesis code generation, implemented in .NET (see examples folder)
AjGenesis in Javascript/Node, with SimpleTpl template engine, with interpolated Javascript expressions, and embedded Javascript commands (see samples folder)
AjGenesis in Ruby, with a similar internal template engine, with interpolated Ruby expressions, and embedded Ruby commands (see samples folder)

AjGenesis in Javascript was published to npm (node package manager) as beta.

AjGenesis in Ruby is still not a gem: work in progress.

REMEMBER: all these projects GENERATES the text artifacts YOU WANT to generate. There are not limited to a technology, platform or programming languages.

It’s really interesting to see how simple ideas can be reimplemented in dynamic languages. Next steps: more samples, ruby gem, node package, and web site implementing code generation as a service (ASP.NET implementation commented in my old post). (see AjGenesis: Basis of Its Implementation).

Pending implementation languages: Python, maybe Java.

(Original photo from:

Keep tuned!

Angel “Java” Lopez

Compilers: Links, News And Resources (3)

Previous Post
Next Post

More links about compiler implementations, ideas, interpreters, and programming languages:

Pharo Opal Compiler

Microsoft’s Roslyn: Reinventing the compiler as we know it

Roslyn CTP Now Available

Why Clojure Doesn’t Need Invokedynamic (Unless You Want It to be More Awesome)

C#5 and Meta-Programming

Roslyn: Compiler as a Service, not a black-box anymore!!.aspx

Project Roslyn or Compiler-as-a-Service. Bringing flexibility of dynamic languages to C#

Microsoft previews Compiler-as-a-Service software

O# (managed Objective-C) Compiler (requires .NET 4)

Microsoft previews Compiler-as-a-Service software

GNU Objective-C runtime features

An Introduction to Objective-C for .NET Programmers

Opa – a unified approach to web programming
Opa is a new open source language that lets you write an app and compile it to a JavaScript application on the client, complete with server-side support including a database.

Clojure, JVM 7 support (invokedynamic)

RES – An Open Cobol To Java Translato

Making Ruby Fast: The Rubinius JIT
by @dseminara

Introducing ClojureScript
by @stuartsierra

ClojureScript Rationale
by @stuarthalloway

Compiling Clojure to Javascript pt. 1 of n
by @fogus

Scala comes to .Net
Miguel Garcia, part of the Scala group at EPFL, has been striving to make the Scala productivity available to .Net developers too. In a project funded by Microsoft, he has now reached a major milestone in delivering that capability.

List of languages that compile to JS

Ferret: An Experimental Clojure Compiler

Precompile your MVC Razor views using RazorGenerator

Razor Generator

My Links

Keep tuned!

Angel “Java” Lopez

Compilers: Links, News And Resources (2)

Previous Post
Next Post

More links about compiler implementations, ideas and technologies:

jitasm is C++ library for runtime code generation of x86/x64. You can write the code like a inline assembler.

Compiling Scala to LLVM

Groovy Goodness: Add AST Transformations Transparently to Scripts
With Groovy 1.8 we can add compilation customizers when for example we want to run a Groovy script from our application code.

Jabaco is a simple programming language with a Visual Basic like syntax. Jabaco enables you to create powerful software for all Java supported operating systems.

How To Write a Console Application in PowerShell with Add-Type

Type inference
Type inference refers to the automatic deduction of the type of an expression in a programming language. If some, but not all, type annotations are already present it is referred to as type reconstruction.

LLVM Language Reference Manual

Example of how to use ANTLR+StringTemplate with LLVM to build a compiler.

Implementing the virtual method pattern in C#, Part Two

The goal of XMLVM is to offer a flexible and extensible cross-compiler toolchain. Instead of cross-compiling on a source code level, XMLVM cross-compiles byte code instructions from Sun Microsystem’s virtual machine and Microsoft’s Common Language Runtime.

Engineering a Compiler, 2nd Edition

Implementing Smalltalk’s Non-Local Returns in JavaScript

Smalltalk Classes in JavaScript

A Linux Compiler Deathmatch: GCC, LLVM, DragonEgg, Open64, Etc…

Pharen: Lisp -> PHP
Pharen is a compiler that takes a Lisp-like language and turns it into PHP code. This combines Lisp’s advantages of uniform syntax and homoiconicity (among others) and PHP’s advantage of…being everywhere.

clojurejs — a Clojure (subset) to Javascript translator

timcameronryan / mug
A self-hosted JavaScript compiler for the JVM. Written in CoffeeScript

Mono’s C# Compiler as a Service on Windows.

Smalltalk in small talks: The Setup
Smalltalk in Java

Xbase interactive programming environment
One of the exciting new features of the upcoming Xtext 2.0 is the integration of the general purpose expression language Xbase.

Compiler in Clojure
The Clojure compiler is currently a large Java class. Writing it in Clojure will produce many benefits

jarpiain / cljc
A clojure port of the clojure compiler

Inside Razor – Part 3 – Templates

My Links

More links about interpreters, compilers and programming languages are coming.

Keep tuned!

Angel “Java” Lopez

Compilers: Links, News and Resources (1)

Next Post

Since the late seventies, I am a programming language geek. I remember my first contact with COBOL, Fortran, Algol/W, assembly language for mainframes and BCPL. In recent years, I was studying new languages implementations, in the form of interpreter, virtual machine and compilers. This is part of the links I found interesting in the last years.

It parses .NET assemblies and generates unmanaged C++ code that can be compiled on any standard C++ compiler.

Mono CSharp Compiler
The Mono C# compiler is considered feature complete for C# 1.0, C# 2.0, C# 3.0 and C# 4.0 (ECMA).

Bytecode 2011

Write A Template Compiler For Erlang

alvaroc1 / s2js
Scala to Javascript compiler

Clojure Faster than Machine Code?


On FaceBook’s Thrift semantics, code generation, and OCaml



Introduction to GOLD Parser


Irony – .NET Language Implementation Kit
Irony is a development kit for implementing languages on .NET platform. Unlike most existing yacc/lex-style solutions Irony does not employ any scanner or parser code generation from grammar specifications written in a specialized meta-language. In Irony the target language grammar is coded directly in c# using operator overloading to express grammar constructs.

Interpreter and Compiler

Compiling .NET code on-the-fly

Dynamic Creation of Assemblies/Apps

NScript – A script host for C#/VB.NET/JScript.NET
NScript is a tool similar to WScript except that it allows scripts to be written in .NET languages such as C#, VB.NET and JScript.NET. NScript automatically compiles the code into an assembly in memory and executes the assembly.

CodeDom Assistant
Generating CodeDom Code By Parsing C# or VB

Building .NET Assemblies Dynamically

A Simple Compiler for the Common Language Runtime
An end-to-end example of a bottom up LALR(1) compiler for a fictitious language targeting the Common Language Runtime

Clojure COmpilation
Ahead-of-time Compilation and Class Generation

he Lisp Before the End of My Lifetime

Hydrating Objects With Expression Trees – Part I

Mastering Expression Trees With .NET Reflector

Dumping Objects Using Expression Trees

Solving the Expression Problem with OOP

C# compiler as a service

Chicken is an implementation of the Scheme programming language that can compile Scheme programs to C code as well as interpret them.

Steel Bank Common Lisp
Steel Bank Common Lisp (SBCL) is a high performance Common Lisp compiler

Scheme2Js is a Scheme to JavaScript compiler

Comparing SPUR to PyPy

SPUR: A Trace-Based JIT Compiler for CIL

chandlerkent / HKCD
MiniJava compiler for RHIT compilers course (CSSE 404)

Google Closure Compiler Advanced mode

free pascal
Free Pascal (aka FPK Pascal) is a 32 and 64 bit professional Pascal compiler.

VMKit: a substrate for virtual machines
The VMKit project is a framework for building virtual machines. It uses LLVM for compiling and optimizing high-level languages to machine code, and MMTk to manage memory.

Hello from a libc-free world! (Part 1)

My Links

Parallel Programming: Links, News And Resources (2)

Previous Post
Next Post

More links about this interesting topic. I think parallel programming is the way to explore new algorithms, specially in artificial intelligence and distributed computing.

Dryad – Microsoft Research

Ville Tuulos on Big Data and Map/Reduce in Erlang and Python with Disco
Ville Tuulos talks about Disco, the Map/Reduce framework for Python and Erlang, real-world data mining with Python, the advantages of Erlang for distributed and fault tolerant software, and more.

ICSE 2011: Danny Dig – Retrofitting Parallelism into a Sequential World
Dr. Danny Dig is a Principal Investigator at the Universal Parallel Computing Research Center (UPCRC Illinois). UPCRC’s stated mission is to make parallel programming synonymous with programming.

Patterns for Parallel Programming: Understanding and Applying Parallel Patterns with the .NET Framework 4
A document providing an in-depth tour of implementing a variety of parallel patterns using the .NET Framework 4.

Haskell: First results from GHC’s new garbage collector
For a number of months now, we have been designing and developing a new garbage collector for GHC, with the primary goal of improving scaling on multicores.

Actor-based Programming
Jamie Ridgway explains what actors are, why we need them, what they are helpful for, the languages built around this programming paradigm, along with some demos showing actor-based apps.

Functional Programming eXchange 2011: Simon Peyton Jones on Managing parallelism: embrace diversity, but control side effects
If you want to program a parallel computer, it obviously makes sense to start with a computational paradigm in which parallelism is the default (ie functional programming), rather than one in which computation is based on sequential flow of control (the imperative paradigm). And yet, and yet … functional programmers have been singing this tune since the 1980s, but do not yet rule the world.

Articles on Parallel Programming with the .NET Framework 4
A set of articles that provide information on parallel programming with the .NET Framework 4.

Dynamic parallel async requests in MVC
Thanks to AsyncControllers, it’s quite easy to make several asynchronous requests in parallel to different web services, and have MVC gather the results.

Groovy Parallel Systems
The GPars framework offers Java developers intuitive and safe ways to handle Java or Groovy tasks concurrently. Leveraging the enormous flexibility of the Groovy programing language and building on proven Java technologies, we aim to make concurrent programming for multi-core hardware intuitive, robust and enjoyable.

InfoQ: Parallel Programming Patterns: Data Parallelism
Ralph Johnson presents several data parallelism patterns, including related Java, C# and C++ libraries from Intel and Microsoft, comparing it with other forms of parallelism such as actor programming.

Task Parallel Library: 5 of n – CodeProject
A look into using the Task Parallel Library.

Mired in code: Easy parallel processing in Clojure
For those not familiar with it, the eight queens problem is to place eight queens on a chess board such that none of them are attacking each other. Since queens attack in eight directions, this means that none of them are in the same row or column, and that none of them share a diagonal. It’s interesting, but not incredibly difficult, to do this.

W. Daniel Hillis
William Daniel “Danny” Hillis (born September 25, 1956, in Baltimore, Maryland) is an American inventor, entrepreneur, and author. He co-founded Thinking Machines Corporation, a company that developed the Connection Machine, a parallel supercomputer designed by Hillis at MIT. He is also co-founder of the Long Now Foundation, Applied Minds, Metaweb, and author of The Pattern on the Stone: The Simple Ideas That Make Computers Work.

Scala Team Wins ERC Grant | The Scala Programming Language
The Scala research group at EPFL is excited to announce that they have won a 5 year European Research Grant of over 2.3 million Euros to tackle the “Popular Parallel Programming” challenge. This means that the Scala team will nearly double in size to pursue a truly promising way for industry to harness the parallel processing power of the ever increasing number of cores available on each chip.

Organizing Functional Code for Parallel Execution; or, foldl and foldr Considered Slightly Harmful
Guy L. Steele, Jr.; Sun Microsystems
International Conference on Functional Programming (ICFP)
Edinburgh 2009

InfoQ: How to Think about Parallel Programming: Not!
Guy L. Steele Jr. believes that it should not be the programmer’s job to think about parallelism, but languages should provide ways to transparently run tasks in parallel. This requires a new approach in building languages supporting algorithms built on independence and build-and-conquer principles rather than on linear decomposition of problems.

Parallel Programming with .NET
All about Async/Await, System.Threading.Tasks, System.Collections.Concurrent, System.Linq, and more…

await anything;
One of the very cool things about the new await keyword in C# and Visual Basic is that it’s pattern based.  It works great with Task and Task<TResult>, and awaiting those two types will represent the vast majority of uses, but they’re by no means the only types that can be awaited.  The languages support awaiting any instance that exposes the right method (either instance method or extension method): GetAwaiter.

Professional Parallel Programming with C#: Master Parallel Extensions with .NET 4 (Wrox Programmer to Programmer)

No Callbacks Required: StratifiedJS Returns Sequential Programming to Javascript
Javascript is fundamentally single threaded, no parallel threads in sight. Asynchronous programming is necessary for any task that might block; Javascript programming usually involves creating and passing around a lot of callbacks, essentially forcing the developer to manually translate sequential code into continuation passing style.

Parallelism: In the Cloud, Cluster and Client
Software and digital experience is now becoming ubiquitous in our lives. Software is everywhere – it is stocking supermarket shelves, delivering electricity and water to our homes, storing our personal information in computers around the world, running nuclear plants and even controlling doomsday weapons! Moreover, with the popularity of the Internet and mobile devices, and with the advances in graphical and natural user interfaces, the creative human minds and the innovative companies are making the digital age more personal, social and indispensible.
This is leading to three fundamental trends in the world today:
Data explosion – the phenomenal growth of raw digital data
Demand for computational power for transforming raw data into meaningful information
Exponential growth in the number of users getting on to the digital super highway

My Links

More links are coming.

Keep tuned!

Angel “Java” Lopez

Metaprogramming: Links, news and resources (1)

As a programming language fan and writer of many interpreters, I’m interested in metaprogramming. Some links I found useful:

Metaprogramming is the writing of computer programs that write or manipulate other programs (or themselves) as their data, or that do part of the work at compile time that would otherwise be done at runtime. In some cases, this allows programmers to minimize the number of lines of code to express a solution (hence reducing development time), or it gives programs greater flexibility to efficiently handle new situations without recompilation.

magarciaEPFL / MethodHandleUtils
JVM: Composing MethodHandles at runtime like AST nodes
Runtime metaprogramming via java.lang.invoke.MethodHandle

Ruby Metaprogramming: Declaratively Adding Methods to a Class

dlitvakb / MetaBuilder
A Ruby MetaProgramming Excercise

Adding Properties to Ruby Metaprogramatically

Ruby: More About Methods

Calling Methods Dynamically

Ruby dynamic method calling

celluloid / celluloid
Actor-based concurrent object framework for Ruby

MetaProgramming – Extending Ruby for Fun and Profit

Three implicit contexts in Ruby
Yehuda Katz wrote an article about self and metaclass. In the article he said that Person.instance_eval assigns Person’s metaclass to self for a class Person. But this is obviously wrong.
Ruby always has three implicit contexts: self), so called `klass’ and the constant definition point.

Metaprogramming in Ruby: It’s All About the Self

class << self idiom in Ruby


Default Ruby accessor method?
method_missing; it gets called whenever an undefined method is used

A Logic Meta-Programming Approach
to Support the Co-Evolution of
Object-Oriented Design and Implementation

Meta-level Programming with CodA

C#5 and Meta-Programming

Metaprogramming in .NET

Whole Platform
the Whole Platform provides an Eclipse-based Language Workbench for developing new languages, manipulating them using domain notations and transforming them using a generative model driven approach.

Code Generation on the JVM: Writing Code that Writes Code

Rascal – Meta Programming Language
Rascal is a domain specific language for source code analysis and manipulation a.k.a. meta-programming.

Write A Template Compiler For Erlang
Implementing the Django Template Language in Erlang

Groovy: Best Practices Developed From Distributed Polyglot Programming

The Magnificent Seven
creating a Lisp variant in seven forms

The calculator language tutorial

The art of metaprogramming, Part 1: Introduction to metaprogramming
One of the most under-used programming techniques is writing programs that generate programs or program parts. Learn why metaprogramming is necessary and look at some of the components of metaprogramming (textual macro languages, specialized code generators). See how to build a code generator and get a closer look at language-sensitive macro programming in Scheme.

Through the Looking Glass Darkly
The classic approach to reflection in object-oriented programming languages originates with Smalltalk, and is used in most class based languages that support reflection: define a reflective API on Objec
nother approach is used in many scripting languages. The language constructs themselves introduce code on the fly, modifying the program as they are executed.
The third approach is that of mirrors, and originates in Self. Mirrors have been used in class based systems such as Strongtalk, and even in the Java world. JDI, the Java Debugger Interface, is a mirror based reflective API. Here, the reflective operations are separated into distinct objects called mirrors.

Mirrors: Design Principles for Meta-level Facilities of Object-Oriented Programming Languages

Metaprogramming: Ruby vs. Javascript

Metaprogramming in Ruby

A Basic YAML Config Module For Ruby

Categories, the homemade object system


Why? Language Archaeology … and Metaprogramming

Metaclasses Demystified
The word “metaclass” often strikes fear into the hearts of Python programmers. This article explores metaclasses in an approachable way, in order to take the mystery out of metaclasses, and enable you to leverage metaprogramming techniques to solve real problems.

Dupping Our Way Out of Instance Eval

In this RubyFringe talk, Reginald Braithwaite shows how to write Ruby that reads, writes, and rewrites Ruby. The demos include extending the Ruby language with conditional expressions, new forms of evaluation such as call-by-name and call-by-need, and more.

Smalltalk magritte-metamodel
Magritte is a fully dynamic meta-description framework that helps to solve those problems, while keeping the full power to the programmer in all aspects.

My Links

More links about DLSs, programming languages, and metaprogramming are coming.

Keep tuned!

Angel “Java” Lopez