1. Compilation to Javascript

Something I have been wanting to try with Phix is compiling it to javascript, however I am struggling with even the first little baby-steps.

One of the better ones seems to me to be Pyjs, at least in terms of examples.

Does anyone have any suggestions for me, such as/specifically this bit of Phix/OE should be translated to this bit of (working) javascript?

Alternatively, just some (simple/working) javascript that you'd love to be able to do in Phix/OE.

Pete

new topic     » topic index » view message » categorize

2. Re: Compilation to Javascript

[OT] Hi Pete,

Can't help you out on this topic, but am willing to do translations into dutch of anything you might like to be translated.

Regards,

Antoine

new topic     » goto parent     » topic index » view message » categorize

3. Re: Compilation to Javascript

petelomax said...

Something I have been wanting to try with Phix is compiling it to javascript, however I am struggling with even the first little baby-steps.

One of the better ones seems to me to be Pyjs, at least in terms of examples.

Does anyone have any suggestions for me, such as/specifically this bit of Phix/OE should be translated to this bit of (working) javascript?

Alternatively, just some (simple/working) javascript that you'd love to be able to do in Phix/OE.

Neat! I'd be very interested to help.

Potential approaches, in order of increasing difficulty:

  • Euphoria-to-JavaScript translator (a la the existing translator)
  • Euphoria interpreter written in JavaScript
  • Euphoria-to-WebAssembly compiler (possibly via LLVM)

Potential challenges to overcome:

  • Euphoria types and builtins (via native JS classes?)
  • Rebuilding the standard library in JavaScript
  • Navigating the DOM in the browsers (it's very object oriented)

-Greg

new topic     » goto parent     » topic index » view message » categorize

4. Re: Compilation to Javascript

One thing I have belatedly realised is that one of my favorite sites is probably the best place to go, and in fact I've just added another Javascript to Phix translation, plasma effect. Not a great deal of commonality, though.

Also, the lack of any JavaScript entries in 7Guis suggests I may be expecting too much... I am now thinking that at the very least you would need both a lib.e and a lib.js, a whole new library developed from scratch, in parallel, and not just for a UI but also all the builtins.

new topic     » goto parent     » topic index » view message » categorize

5. Re: Compilation to Javascript

Shamelessy copied from Pete's entry

 
include euallegro.ew 
 
--adjust these for experimentation 
integer width = 300,  
        height = 300 
 
atom buffer 
object ret 
 
-------------------------------------------------------------- 
--module initialisations 
-------------------------------------------------------------- 
ret = allegro_init() 
ret = install_timer() 
ret = install_keyboard() 
 
set_color_depth(32) 
--ret = set_gfx_mode(GFX_AUTODETECT_FULLSCREEN, 1024,768, 0, 0) 
ret = set_gfx_mode(GFX_AUTODETECT_WINDOWED,width, height, 0, 0) 
 
if ret = -1 then 
    --switch to a safe mode instead 
    ret = set_gfx_mode(GFX_SAFE, 640, 480, 0, 0) 
end if 
 
buffer = create_bitmap(width, height) 
clear_bitmap(buffer) 
 
------------------------------------------------------------ 
procedure dot(atom m, atom n, integer color = -1) 
------------------------------------------------------------ 
if color = -1 then 
    color = makecol(255,255,255) 
end if 
 
putpixel(buffer, floor(m), floor(n), color) 
 
end procedure 
 
------------------------------------------------------------ 
sequence plasma 
integer pw = 0, ph = 0 
procedure createPlasma(integer w, h) 
--direct copy 
------------------------------------------------------------ 
    plasma = repeat(repeat(0,w),h) 
    for y=1 to h do 
        for x=1 to w do 
            atom v = sin(x/16) 
            v += sin(y/8) 
            v += sin((x+y)/16) 
            v += sin(sqrt(x*x + y*y)/8) 
            v += 4 -- shift range from -4 .. 4 to 0 .. 8 
            v /= 8 -- bring range down to 0 .. 1 
            plasma[y][x] = v 
        end for 
    end for 
    pw = w 
    ph = h 
end procedure 
 
------------------------------------------------------------ 
atom hueShift = 0 
procedure drawPlasma(integer w, h) 
------------------------------------------------------------ 
    hueShift = remainder(hueShift + 0.02,1) 
    sequence rgb3 = repeat(repeat(0,w*h),3) 
    integer cx = 1 
    for y=1 to h do 
        for x=1 to w do 
            atom hue = hueShift + remainder(plasma[y][x],1) 
            integer i = floor(hue * 6) 
            atom t = 255, 
                 f = (hue * 6 - i)*t, 
                 q = t - f,  
                 r, g, b 
            switch mod(i,6) do 
                case 0: r = t; g = f; b = 0 
                case 1: r = q; g = t; b = 0 
                case 2: r = 0; g = t; b = f 
                case 3: r = 0; g = q; b = t 
                case 4: r = f; g = 0; b = t 
                case 5: r = t; g = 0; b = q 
            end switch 
            rgb3[1][cx] = r 
            rgb3[2][cx] = g 
            rgb3[3][cx] = b 
            cx += 1 
             
            --at this point put the coloured dot in the buffer 
            --would have been easier with a 2 dimensional sequence 
            --although should be actually able to skip rgb sequence 
            dot(x,y, makecol(floor(r),floor(g),floor(b))) 
            --max tension! 
            --blit(buffer, screen,  0, 0, 0, 0, SCREEN_W, SCREEN_H) 
        end for 
    end for 
    --this is the bit that draws to the screen 
    --cdCanvasPutImageRectRGB(cddbuffer, w, h, rgb3, 0, 0, 0, 0, 0, 0, 0, 0)  
     
    --for the impatient 
    blit(buffer, screen,  0, 0, 0, 0, SCREEN_W, SCREEN_H) 
end procedure 
 
 
------------------------------------------------------------ 
procedure main() 
------------------------------------------------------------ 
createPlasma(width, height) 
drawPlasma(width, height) 
 
--press any key to exit  
clear_keybuf() 
while 1 do 
    hueShift += 0.002 
    createPlasma(width, height) 
    drawPlasma(width, height) 
     
    if keypressed() then 
        exit 
    end if 
end while 
 
end procedure 
main() 

Cheers

Chris

new topic     » goto parent     » topic index » view message » categorize

6. Re: Compilation to Javascript

I, likewise, originally used cdCanvasPixel(), but changing it to cdCanvasPutImageRectRGB() made it much smoother/faster.

One thing I might suggest is removing the requirement to copy dlls into system32/syswow64: pGUI has win32 and win64 subdirectories and sets dll_path before invoking iup_open_dll() [so it can be done].
Of course, besides running straight out of the box for the developer, that would make shipping a completed game much easier too.

Pete

new topic     » goto parent     » topic index » view message » categorize

7. Re: Compilation to Javascript

I've just done a quick web app as part of a job application: http://phix.x10.mx/mint.html

Fairly spartan, but (imo) packs a fair amount of functionality for just 89 lines of html/javascript.
Typing in a filter rebuilds the table instantly, the table can be sorted on any column, and clicking on an entry shows the details.

Pete

new topic     » goto parent     » topic index » view message » categorize

8. Re: Compilation to Javascript

petelomax said...

part of a job application

I'm definitely interested! Tell me more, please!

petelomax said...

Fairly spartan, but (imo) packs a fair amount of functionality for just 89 lines of html/javascript.

Was this translated from Phix at some point? It looks very neat (human-written).

new topic     » goto parent     » topic index » view message » categorize

9. Re: Compilation to Javascript

jimcbrown said...

I'm definitely interested! Tell me more, please!

Oh, it was just a random pre-interview test: build a web app that responds to input (exact words were "think typeahead"), list some things and allow them to be clicked on. At the time I felt rather pleased with it, but now I'm beginning to imagine it may well be viewed with some disdain (no design patterns, no class hierarchy, no MVC, no separation of concerns, no dependency injection or inversion, no SQL or noSQL, no unit tests, no blah blah blah...)

jimcbrown said...

Was this translated from Phix at some point? It looks very neat (human-written).

Ah, no, it was hand-written. I really should have said that I was posting it here, more as something that might possibly succumb to a lib.js/lib.e attack, but there is no Phix version as yet.

Pete

new topic     » goto parent     » topic index » view message » categorize

10. Re: Compilation to Javascript

petelomax said...
jimcbrown said...

I'm definitely interested! Tell me more, please!

Oh, it was just a random pre-interview test:

Which company was it and where are they based? What kind of role was it (front-end, javascript developer, etc)?

petelomax said...

At the time I felt rather pleased with it, but now I'm beginning to imagine it may well be viewed with some disdain (no design patterns, no class hierarchy, no MVC, no separation of concerns, no dependency injection or inversion, no SQL or noSQL, no unit tests, no blah blah blah...)

Considering how simple it was, some of that would be over-kill. KISS?

new topic     » goto parent     » topic index » view message » categorize

11. Re: Compilation to Javascript

jimcbrown said...

Which company was it and where are they based? What kind of role was it (front-end, javascript developer, etc)?

Mintdigital in central London. The role sounds very varied.

new topic     » goto parent     » topic index » view message » categorize

12. Re: Compilation to Javascript

petelomax said...
jimcbrown said...

Which company was it and where are they based? What kind of role was it (front-end, javascript developer, etc)?

Mintdigital in central London. The role sounds very varied.

Ah, brilliant.

At first I thought this was a cryptocurrency-type company - and sure enough, there's a different, unrelated company with a very similar name ( https://blog.digitalmint.io/ ).

But https://mintdigital.com/blog/2 appears to be an all-around consulting agency with a focus in software tech: https://www.facebook.com/MintDigitalAgency

There's a good history here: http://weare10.mintdigital.com/

Break a leg!

new topic     » goto parent     » topic index » view message » categorize

13. Re: Compilation to Javascript

This has some promise: https://www.codeproject.com/Articles/1254389/Procedural-Smiles-Animating-SVG-with-Pure-JavaScript

new topic     » goto parent     » topic index » view message » categorize

14. Re: Compilation to Javascript

This also has some promise: https://www.codeproject.com/Articles/345888/How-to-write-a-simple-interpreter-in-JavaScript
as does this: http://lisperator.net/pltut/ (but it does all get a bit too lisp-y for my tastes)

new topic     » goto parent     » topic index » view message » categorize

Search



Quick Links

User menu

Not signed in.

Misc Menu