via http://twitter.com/programmingjoy Javascript as Compiler Target: Clamato, GWT Smalltalk, Python, Scheme http://www.infoq.com/news/2009/09/javascript-compilation-target (require moby/stub/world) (define WIDTH 320) (define HEIGHT 480) (define (render w) (place-image (text "Hello World" 10 "Black") 20 20 (empty-scene WIDTH HEIGHT))) (big-bang WIDTH HEIGHT 10 0) (on-redraw render)
After a few minutes of poking around, I was able to compile this to Java and then run it on the Android Emulator:
Example: sum of first 4 integers.
sum = 0;
for (i = 1; i <= 4; ++i)
sum += i*i;
can be translated to
sum = 0;
i = 1;
loop:
if (i == 5) goto end;;
sum = sum + i;
i = i + 1;
goto loop;
end:
can be translated to
; sum in R16
; i in R17
; R18,R19 used for temporary values
LDI R16, 0
LDI R17, 1
LDI R18, 5
SUB R18, R17
BRBS 1, 22
ADD R16, R17
LDI R19, 1
ADD R17, R19
JMP 2
SLEEP