Archive for the ‘NQP’ Category

nq-nqp: Lessons Learned

Tuesday, May 4th, 2010

NQ-NQP’s Status:

  • A fairly well defined grammar for parsing nqp exists. It generates AST nodes for most of the grammar, but not all of the grammar.
    • In the future, it would be useful for AST optimizations, like constant folding
  • Code generation supports integers and subs, but it does not yet support other data types like floats, strings, bools, or anything else like regular expressions.
    • Built in basic types should eventually include:
      • Packages
      • Subs
      • Classes
      • Roles
      • Arrays
      • Hashes
      • Ints
      • Nums
      • Strings
      • Bools
  • Execution of code generated works.
    • Debugging is surprisingly easy with the gdb, but I will have to see how hard it is in the future. I know that if I start working with a JIT it becomes increasingly difficult to view whats being run on the processor.
  • A limited number of binary ops, like add and subtract are working.
  • The VM supports method calls, but the code does not currently generate code properly.

Lessons learned:

  • LLVM is neat but advanced and complicated
  • Grammars are fun, we should do more of those
    • Having a way of defining a grammar is difficult though currently, in C there is yacc/bison but that is a bit limited compared to other systems.
  • Grammars are hard, parsing is not easy
    • Tokenizers and Lexers are difficult if you want to contextually call things based off of where they should be in your grammar
  • Focusing on construction a real “Compiler” is probably a mistake. Start small, an ast that you can walk and execute each step of the way is better for learning than building a code generation system. Code generation is useful but hard, and can be deferred until later.

Things I would do different if I could start over:

  • Focus on the grammar, and making an executable AST rather than translating the AST into code.
  • If there was a VM out there I could link to for a runtime, I have not found an easy to use one. It would be nice to have because then I could of focused more on other parts of the language, but VM support is not that hard, just lots of typing.

Small Update for Scoping

Saturday, April 10th, 2010

I now have lexical and dynamic scopes fully implemented in my runtime support, and I know how I will be using them once I have code generation completed. Package scope seems like it shouldn’t be to difficult to figure out, now that I have lexical’s working. (more…)

Runtime Support for nq-nqp

Monday, April 5th, 2010

So, I have a fairly complete parser and AST for my compiler. I think its an appropriate time to start looking at runtime support and how some of the runtime properties of the language will work.

Here is a rough diagram of the relation between objects instances, their containers, and their lexical values:

For garbage collection for now I am simply going to use Boehm GC [1], it should do for now, till I can look into GC a bit more.

The meta model seems pretty solid, granted its from the perl 6 spec. The current nqp-rx doesn’t have its own meta model. It uses parrot’s meta model directly. So, this has lead me to an issue, since I can’t be consistant with nqp, since I don’t want to implement all of parrot. So, instead I am going to steal the MOP (Meta Object Protocol) from perl 6.

Dispatch is going to be interesting. I’d like to implement multi-dispatch, but maybe not just yet. I have been thinking about it, for now I will probably start with single dispatch, and build up to multi-dispatch later.

Here is a sequence diagram of how I think I could accomplish multi-dispatch, sorta. I still need to flush out some of my ideas for how to do this right.

Foot Notes:
1# http://www.hpl.hp.com/personal/Hans_Boehm/gc/

Not Quite – NQP, Goals and Objectives

Monday, March 1st, 2010

Since NQ-NQP is primarily a learning project, which hopefully I can evolve into an alternative NQP runtime, I’d like the outline my current goals and objecties. Writing out the grammar and lexer are two of my immediate objectives. I’d like to see if I can write out a grammar and lexer for the Regular Expression library built into NQP, or at least parts of it. Currently, NQP is self hosted in parrot, meaning if you want to extend NQP, you can use NQP to do that. After I finish with all the basics, I’d like to look into some way of doing that. Maybe a basic bootstrap using my work I have done so far, and a full NQP implementation written in my bootstrap sub language of nqp. (more…)