tomlokhorst / language-cil

Manipulating Common Intermediate Language AST in Haskell
Other
20 stars 8 forks source link

Move labels from OpCode to MethodDecl #8

Closed dmcclean closed 13 years ago

dmcclean commented 13 years ago

The following CIL is legal but inexpressible in the current Syntax.hs

a:
b:
    ldc.i4.0
c:

Multiple labels can precede the same instruction, and labels can even come at the very end after all instructions (uselessly, but its grammatically allowed and ILASM accepts and ignores it).

As a result, I think we should eliminate the Instr type entirely, change the Instr constructor in MethodDecl to wrap an OpCode (maybe it should be renamed to OpCode as well?) instead of an Instr, and add a Label constructor to MethodDecl, so that MethodDecl looks like this:

-- | Method declarations, i.e. the body of a method.
data MethodDecl
  = Directive Directive
  | OpCode OpCode
  | Label Label
  | Comment String
  deriving Show

Being able to place multiple labels before the same instruction vastly simplifies composing various code generators.

tomlokhorst commented 13 years ago

Agreed, never liked that Instr type anyway.

I have some time, I can make the change right now.

tomlokhorst commented 13 years ago

I've made this change in the branch no-instr. This is a breaking change, as any code that uses the label builder function now no longer works.

This branch can be merged with master for the 0.3 release of language-cil, along with any other breaking changes. I first want to release 0.2.2 which contains just additional functionality (like unaligned).

tomlokhorst commented 13 years ago

I've released 0.2.2 to Hackage. The no-instr branch has been merged with master.