GithubHelp home page GithubHelp logo

gregorytravis / hen-opengl Goto Github PK

View Code? Open in Web Editor NEW
1.0 2.0 0.0 372 KB

Hen: dynamically typed, pure functional language with pattern-matching and monadic IO

C 88.58% Scheme 10.25% Perl 1.17%

hen-opengl's Introduction

Hen: dynamically typed, pure functional language with pattern-matching and monadic IO

Hen is a dynamically typed, pure functional language with pattern-matching and monadic IO. It includes an FFI generator and examples OpenGL programs.

It uses S-expression syntax, and is implemented as a lazy lambda graph reducer.

The sample program is a port of an OpenGL sample FBO program that renders a cube, and then maps the cube rendering onto the faces of another cube.

  (import
   (ffi "GLee.h")
   (ffi "<OpenGL/gl.h>")
   (ffi "<GLUT/glut.h>")
   (ffi "<OpenGL/glext.h>")
   (ffi "<OpenGL/glu.h>")
   (ffi "ref.c")
   (ffi "cvt.c")
   (link "GLee.c")
   (link "shew.impl.c")
   (framework "GLUT")
   (framework "OpenGL")
   (framework "CoreFoundation"))

  (fun (idle)
       (doo
        ;_ (shew 'idle-callback)
        _ (glutPostRedisplay)))

  (fun (reshape w h)
       (doo
        _ (shew ($ 'reshape-callback w h))
        _ (glViewport 0 0 w h)
        _ (glMatrixMode _GL_PROJECTION)
        _ (glLoadIdentity)
        wf (int-to-float w)
        hf (int-to-float h)
        _ (gluPerspective 80.0 ((/ wf) hf) 1.0 5000.0);
        _ (glMatrixMode _GL_MODELVIEW)
        _ (glLoadIdentity)))

   (fun (keyboard key x y)
       (doo
        ;; TODO exit when ESC is pressed, as follows:
        ;;       glDeleteFramebuffersEXT(1, &fbo);
        ;;       glDeleteRenderbuffersEXT(1, &depthBuffer);
        ;;       glDeleteTextures(1,&img);
        _ (shew ($ key x y))))

The import/ffi declarations trigger a script to generate the FFI stubs. I generate a C program that includes the libraries of interest:

  #include "GLee.h"
  #include "OpenGL/gl.h"
  #include "GLUT/glut.h"
  #include "OpenGL/glext.h"
  #include "OpenGL/glu.h"

I run GCC on this, but instead of compiling, I have it dump the enormous code tree:

  @1      namespace_decl   name: @2       srcp: <built-in>:0      
                           dcls: @3      
  @2      identifier_node  strg: ::       lngt: 2       
  @3      function_decl    name: @4       type: @5       srcp: glut.h:617    
                           chan: @6       C              args: @7      
                           undefined      extern        
  @4      identifier_node  strg: glutGameModeGet         lngt: 15      
  @5      function_type    size: @8       algn: 8        retn: @9      
                           prms: @10     
  @6      function_decl    name: @11      type: @12      srcp: glut.h:616    
                           chan: @13      C              undefined     
                           extern        
  @7      parm_decl        name: @14      type: @15      srcp: glut.h:617    
                           argt: @15      size: @16      algn: 32      
                           used: 0       
  @8      integer_cst      type: @17      low : 8       
  @9      integer_type     name: @18      size: @16      algn: 32      
                           prec: 32       min : @19      max : @20     
  @10     tree_list        valu: @15      chan: @21     
  @11     identifier_node  strg: glutLeaveGameMode       lngt: 17      
  @12     function_type    size: @8       algn: 8        retn: @22     
                           prms: @21     

Which I then parse to get the types of all of the functions. I can then generate stub code, in my language:

  ;; In hen
  (fun (glutSolidTetrahedron) (Command 'glutSolidTetrahedron ($)))

and on the C side:

  // in C
  node* foreign_glutSolidTetrahedron(node* arg498) {
    node* here499 = arg498;
    A(isnil(here499));
    glutSolidTetrahedron();
    return Nil;
  }

The hen stuff is translated to C, and everything is compiled together into an exe that produces the attached screenshot.

Note: gcc no longer supports the feature that provides this dump.

hen-opengl's People

Contributors

gregorytravis avatar

Stargazers

 avatar

Watchers

James Cloos avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.