Re:Show HN: A small virtual machine written in C
by spatulon on Monday August 04, 2014 @06:05AM
(#8130995)
This is a technique I first came across in the code for lcc, as described in David R. Hanson's book "A Retargetable C Compiler: Design and Implementation".
https://sites.google.com/site/lccretargetablecompiler/
The code in that book feels pretty dated in a lot of places, but this was a neat trick. Every piece of information related to a token is defined in one place:
https://github.com/drh/lcc/blob/master/src/token.h
Then here's how it's used:
Re:Show HN: A small virtual machine written in C
by tekknolagi on Monday August 04, 2014 @02:16AM
(#8130585)
Definitely interesting — I shall take a look! Feel free to make a pull request if you're game.
Re:Show HN: A small virtual machine written in C
by axman6 on Monday August 04, 2014 @02:25AM
(#8130612)
If I had time and a job where I got to code I would, but it'll be a few days before I have time.
Re:Show HN: A small virtual machine written in C
by tekknolagi on Monday August 04, 2014 @02:44AM
(#8130646)
Quick question. Is that code you've given ok to use in the project? I just realized that I added and pushed without asking.
GPL?
Re:Show HN: A small virtual machine written in C
by axman6 on Monday August 04, 2014 @03:18AM
(#8130695)
The binop stuff you can certainly use freely, the X macro stuff is quite well known so I guess that it's also fine to use. I certainly won't be claiming any copyright on the code I shared =)
My personal preference for licensing is one of the BSD or MIT licenses, I'd rather see things of mine used to makie the world a better place than force people to share what they've done with it.
Re:Show HN: A small virtual machine written in C
by tekknolagi on Monday August 04, 2014 @03:21AM
(#8130701)
Thanks :) Having some weird pasting issues with a macro for POP expansion. http://i.imgur.com/4HiltgI.png
Edit: Just kidding. That was dumb.
Re:Show HN: A small virtual machine written in C
by zura on Monday August 04, 2014 @09:29AM
(#8131617)
Btw, I remember there was a law stating that the code less than 10(?) lines is not copyright-able, no?
Re:Show HN: A small virtual machine written in C
by IgorPartola on Monday August 04, 2014 @02:26PM
(#8133258)
My first reaction was to say "it should be based on the number of CPU/GPU/*PU instructions". But then, there are things like this: http://www.norvig.com/spell-correct.html. I wonder how much actual new-ness you can pack into, say, 100 instructions on a modern CPU.
Re:Show HN: A small virtual machine written in C
by voidlogic on Monday August 04, 2014 @01:10PM
(#8132802)
That would be a a silly rule, for better or worse 10 lines of Haskell might perform the computation of 500 line of Java (even if they took you the same amount of time to write.. heh).
Re:Show HN: A small virtual machine written in C
by zura on Monday August 04, 2014 @02:17PM
(#8133202)
Well, maybe they made this rule in days when COBOL was in hype? ;)
Re:Show HN: A small virtual machine written in C
by tekknolagi on Monday August 04, 2014 @02:03PM
(#8133127)
Or, say, Befunge...
Re:Show HN: A small virtual machine written in C
by Alupis on Monday August 04, 2014 @05:29PM
(#8134132)
Wrong -- Google lost the first of the Android/Java battles to Oracle for 9 lines of "copy/pasted" range check code.[1][2][3]
[1] https://news.ycombinator.com/item?id=3951575
[2] https://news.ycombinator.com/item?id=3951480
[3] http://www.theverge.com/android/2012/5/9/3010404/judge-denie...
Re:Show HN: A small virtual machine written in C
by tekknolagi on Monday August 04, 2014 @02:27AM
(#8130616)
Ah, I feel you — no problem! I do really love the binop macro.
[1] https://github.com/tekknolagi/carp/blob/master/src/carp_inst...
[2] http://www.embedded.com/design/programming-languages-and-too... and the following parts