What exactly is the difference here between your define-opcode macro and Racket’s define-struct form? For example, simply doing (define-struct A2 result left right relop) would generate make-A2, A2? A2-result, A2-left, etc.
What you describe is certainly possible, but I don’t think it’s currently clear why exactly you’d prefer your solution over just using the struct built-in. Could you elaborate on the differences between your domain-specific approach and the Racket form? > On Apr 13, 2015, at 08:11, Nils Van Geele <nils.vge...@gmail.com> wrote: > > Hey all, > > Bit of context: I'm writing a compiler for a course and decided to use > Racket. I'm translating an AST to three address code-like instructions. > Because I do not want to manually write a great deal of boilerplate code for > each opcode, I figured I could use macros. > > I have a struct `instruction' that holds the argument registers/options, > result register, and the opcode. Using the macro I have in mind, I could for > instance generate all boilerplate for the A2 opcode (A = B binop C): > > (define-opcode A2 > (result #t) > (arg left) > (arg right) > (arg relop)) > > This would create the functions: > - (make-A2 left right relop result), which creates a new instance of the > instruction struct > - (A2? obj), which checks if obj is an instruction struct and the opcode > maches A2 > - (A2-left obj) and so on, all accessor functions > > In an opcode constructor such as make-A2, result is always the last argument, > and all other arguments are in the order in which they are defined. > > I already managed to write a much more simple version, which can be used as > follows: > > (define-opcode A2 #t 3) > > Which will just generate functions like make-A2, A2-arg1, A2-arg2, and so on. > However, I prefer the version with (result ...) and (arg ...), but I just > can't figure out how to write a macro for it, given that there must be only > one occurence of (result ...) and zero or more occurences of (arg ...). > > I hope someone will be able to help me or point me to some similar macros for > inspiration! > > Greetings, > Nils Van Geele. > > -- > You received this message because you are subscribed to the Google Groups > "Racket Users" group. > To unsubscribe from this group and stop receiving emails from it, send an > email to racket-users+unsubscr...@googlegroups.com. > For more options, visit https://groups.google.com/d/optout. -- You received this message because you are subscribed to the Google Groups "Racket Users" group. To unsubscribe from this group and stop receiving emails from it, send an email to racket-users+unsubscr...@googlegroups.com. For more options, visit https://groups.google.com/d/optout.