Tuesday, July 31, 2012

krayola

Copperbox revision 2821.

Added a stroked polygon drawing doodle.

There is a lot to attend to when using OpenGL to draw 2D. I'm almost surprised Processing uses OpenGL as its basis for drawing but perhaps there wasn't much choice at the end of the nineties. Actually I'm not sure there is much choice now as OpenVG seems like a white elephant.

Monday, July 30, 2012

krayola

Copperbox revision 2820.

I've added my first OpenGL in C doodle.

It's a bit of a mea culpa, but I've never actually written any OpenGL of my own. I've compiled and not compiled (due to makefile frustrations) various examples and I've got four of the Addison Wesley books, the first I got something like 14 years ago; but I've never worked anything out for myself. It's time to start.

Sunday, July 29, 2012

wumpus-expr

Copperbox revision 2819.

I've added function definition and application to the TopLevel syntax layer. This means you can now embed functions "properly" [*] in Wumpus-Expr, although you can't compile them yet as the translator needs extending.

[*] Properly embedding functions in Wumpus-Expr means they are defined as-is in the target language rather than inlined into a huge expression. This is important as Wumpus-Expr has function definitions specifically to reduce code size.

Saturday, July 28, 2012

OpenGL version number

Here's a program to print the OpenGL version to the console:

#include <GL/gl.h>
#include <GL/glut.h>

#include <stdio.h>

static GLint window;

int main( int argc, char* argv[] )
{

  char *gl_vers;
  

  glutInit(&argc, argv);
  glutInitDisplayMode( GLUT_SINGLE | GLUT_RGB );
  glutInitWindowSize(500, 500);
  window = glutCreateWindow( "Need a window to get the version.");

  gl_vers = (char *) glGetString(GL_VERSION);

  fprintf(stdout, "GL version:\n");

  if (gl_vers != NULL)
    fprintf(stdout, "%s\n", gl_vers);

  return 0;
}

Apparently my GL version under MinGW is 1.1.0 - disappointingly old skool!

Thursday, July 26, 2012

wumpus-expr

Copperbox revision 2818.

Work on the phantom typed top level. Adding phantom constructors and operators for most of the constructors of the Expr datatype - only application and return are outstanding. Return is probably unnecessary, application needs some thought as it is n-ary in Wumpus-Expr unlike Haskell where it is binary.


Sunday, July 22, 2012

wumpus-expr

Copperbox revision 2817.

Initial work on a phantom typed top level layer. The work is a bit wacky as it hides monadic code in newtype wrappers to give it type signatures that look pure (nothing unsafe though). Although I haven't tested it yet, I think it improves the design in Ochre which tried to do similar.

wumpus-expr

Copperbox revision 2816.

Following the experiments with the CPS-mon code, I've made the expression language in Wumpus-Expr monadic.

As Wumpus-Expr doesn't have a lambda form, I only have (>>) monadic sequence and not (>>=) monadic bind. Maybe this will be a problem, maybe it won't - I'll have to work out the consequences.

Off-topic - I've been looking at SDL for graphics and simple user-interfaces, hence no commits the last two days. SDL is interesting but very low-level - it would need a lot of work to functionalize it.

Thursday, July 19, 2012

cps-mon

Copperbox revision 2815.

I've finished the CPS transformation and added pretty printers for the source and target languages.


Wednesday, July 18, 2012

cps-mon

Copperbox revision 2814.

Work on implementing the CPS transformation presented in "How to CPS Transform a Monad" by Annette Bieniusa and Peter Thiemann.

I'm a bit concerned that Wumpus-Expr allows effects in the wrong places - i.e. the heads of let expressions - that will cause problems for the translation from K Normal form to PostScript or JavaScript; so, I'm looking at the expression language in the above paper for guidance as to properly integrating monadic effects.

Tuesday, July 17, 2012

wumpus-expr

Copperbox revision 2813.

I've re-implemented constant folding. The code isn't significantly neater but it is more complete.

Monday, July 16, 2012

wumpus-expr

Copperbox revision 2812.

I've changed the K Normal form representation to make constant folding inside If expressions easier. Currently the actual constant folding code is stubbed out, tomorrow's work is to re-implement it and see if it is easier...

Sunday, July 15, 2012

wumpus-expr

Copperbox revision 2811.

I've extended the interpreter to handle fundefs and funcalls.

Effects in the expression language have been left unchanged, I was thinking Blank Canvas wrapped updates to the graphics state in a local function as per the Reader monad - this isn't the case. While this behaviour would be desirable for Wumpus-Expr it would introduce a risk of entombing graphics state updates in a chain of gsave / grestore that is too deep for PostScript.

wumpus-expr

Copperbox revision 2810.

More work on the interpreter, excepting function defs it now evaluates the expression datatype and produces a bounding box.

As the expression datatype has unrestrained effects there is a lot of potential for the interpreter to be wrong. I think an alternative direction might be to change the expression type so it is more operational like Andy Gill's Blank Canvas. This would make it easier to trust the interpreter. The potential downside is that this makes the embedded language less like PostScript / JavaScript.


Saturday, July 14, 2012

wumpus-expr

Copperbox revision 2809.

More work on the interpreter module, the code is a long way from being complete...

I've changed the Program type to have a main function an auxiliary definitions - it should have been defined like this from the beginning as a program must always have a main.

Friday, July 13, 2012

wumpus-expr

Copperbox revision 2808.

Initial work on a interpreter for programs in Wumpus-Expr. The interpreter should produce the bounding box that a drawing (Wumpus program) inhabits.

The code so far is the initial thoughts - already I've seen that the monad is not sufficient and needs at least a Reader and probably a Writer.

Thursday, July 12, 2012

wumpus-expr

Copperbox revision 2807.

I've changed VarIds to accommodate immutable prim names (for functions or built ins). This makes the alpha renaming code more stable as it won't change function names.

Wednesday, July 11, 2012

wumpus-expr

Copperbox revision 2806.

I've added a PostScript symbol constructor to the expression type. Although I don't think PostScript has symbols a la Lisp, it does have opaque defs for font names - this is the use-case that the symbols will model.

Otherwise, I've come a bit unstuck with alpha renaming and VarId's. The current code represents function names with a PrimId that is oblivious to alpha renaming, but the expression syntax doesn't allow me to access a PrimId when it is needed for application.

Tuesday, July 10, 2012

wumpus-expr

Copperbox revision 2805.

Some work (not much) on the K-normal form to JavaScript translation.

A realization I had whilst committing is that I think I'll need different translators for procs and functions - procs have effects (writing output commands) and can only return Unit, functions should be pure. There's a caveat to this that generating PostScript will be easier if I can live with just procs and no functions...





Monday, July 9, 2012

wumpus-expr

Copperbox revision 2804.

I've extended the JavaScript output syntax and pretty printer to accommodate more of the constructions in the input language.

Side note - I've now managed a contiguous month of "a commit a day", it might be the first time I've achieved this since I've been contracting (some of the commits like today's have been pretty trivial, but I'll let that slide). Unfortunately all my projects are now pending design work - this is something I can't seem to fit in on a work night, so "a commit a day" might end here.

Also I'm not going to buy Max MSP at the moment, so although my work rate is set to drop the work will continue in Haskell. I may buy Max MSP in the autumn.

Sunday, July 8, 2012

wumpus-expr

Copperbox revision 2803.

Initial work on PostScript generation. So far, the work has been on the AST and pretty printing, I haven't looked a translation from K normal form, however the AST is a bit more worked out than the JavaScript AST.

Saturday, July 7, 2012

wumpus-expr

Copperbox revision 2802.

I've implemented a trivial and incomplete translation of the knormal form representation into JavaScript - only two expression cases are handled Command and Seq others cause a pattern match failure.

Friday, July 6, 2012

pretty-expr-hpj

Copperbox revision 2801.

Work on the C99 and JavaScript expression pretty printers. I've now implemented all the operators except for the mixfix (distfix?) ones like array access and conditional expressions. Currently, these can't be encoded in pretty-epxr-hpj which only handles prefix, postfix and binary expressions.


Thursday, July 5, 2012

wumpus-expr

Copperbox revision 2800.

I've moved the JavaScript expression pretty printer into pretty-expr-hpj - a better place for it.

Wednesday, July 4, 2012

wumpus-expr

Copperbox revision 2799.

Initial work on the syntax tree and pretty printer for the JavaScript backend.

Tuesday, July 3, 2012

wumpus-expr

Copperbox revision 2798.

I've changed the exports of the optimization functions so they work on programs rather than expressions.

I hope "compilation" of Wumpus-Expr should be fairly easy as the language is first-order rather than higher order. A program is just a list of function definitions.

Monday, July 2, 2012

wumpus-expr

Copperbox revision 2797.

I've added more output commands.

Canvas appears to take many of its command from PostScript, the biggest difference seems to be with the graphic state update commands - line size and end appear as good as the same, but dash pattern and colours are different enough to cause problems. I'll have to think about how to handle them.

Sunday, July 1, 2012

wumpus-expr

Copperbox revision 2796.

Started on wumpus-expr - this is an experimental project that aims to support function definition in the generated PostScript or HTML canvas + JavaScript.

Allowing limited function / procedure definition in the target language is the only way to avoid code size explosion in the output from Wumpus. If wumpus-expr is a success, it will form the backend for WumpusLite.

The initial code has taken the K Normal Form compiler from Ochre and changed the syntax to suit graphics generation rather than Csound instruments.


Blog Archive

About Me

My photo
Disambiguating biog as there are a few Stephen Tetley's in the world. I'm neither a cage fighter or yachtsman. I studied Fine Art in the nineties (foundation Bradford 1992, degree Cheltenham 1992 - 95) then Computing part-time at Leeds Met graduating in 2003. I'm the Stephen Tetley on Haskell Cafe and Stackoverflow.