7 ms·
T3X – a minimal procedural language
- megapatch 9y agoThe Mandelbrot example has implementation problems. The check for a point being outside the set is implemented totally wrong, even the comment (which is not even consistent with the code) is wrong. Not judging the language itself, but that is not really convincing.
- nils-m-holm 9y agoFor being "totally wrong" it draws a pretty nice Mandelbrot set! That being said: yes there are problems with the comments. It's code I have written decades ago and just copy-pasted now. Will fix! Thanks!
- sigjuice 9y agoLooks cool, but what is FreeBSD-specific about it? Shouldn't a compiler just be reading and writing files?
- JdeBP 9y agoCompiled executables are, by their very natures, usually specific to operating systems. This minimal compiler outputs one specific executable file format, hardwiring a specific platform and instruction set architecture in that executable file format's header.
- sigjuice 9y agoYes, I know that about executables, but I guess compiler-related subtleties are lost on me. I will clearly benefit from reading the book I just bought.
- oddity 9y agoIt generates FreeBSD executables directly. >The compiler translates from T3X9 directly to FreeBSD-386-ELF. It does not require any assembler, linker, or other additional programs. I suspect that it can be ported to other 32-bit ELF Unixes in about half an hour.
- sitkack 9y agoWebAssembly port would be fun.
- penpapersw 9y agoVery cool! I love minimalistic languages. How is this able to omit basic type information? Is everything just an int? > "It is a statement rather than a production tool." What's the statement supposed to be?
- lowtolerance 9y ago"I made a minimal procedural language"
- nils-m-holm 9y ago>How is this able to omit basic type information? Is everything just an int? Data is untyped and operators are typed. So in X+Y, X and Y are integers, in X::Y, X is a byte vector and Y is an integer, and in Y[X], X is an integer and Y is a vector (and the types of its element again depend on the operators applied to them). Note that not all combinations of data and operators make sense. E.g., "foo"*[1,2,3] is a valid expression, but probably will not deliver any meaningful result. I'll leave the interpretation of the statement to you! ;)
- stcredzero 9y agoIt's hard to say what a minimal procedural language is. There are ISAs with a single instruction: https://en.wikipedia.org/wiki/One_instruction_set_computer https://en.wikipedia.org/wiki/One_instruction_set_computer This looks like it's a MISC: https://en.wikipedia.org/wiki/Minimal_instruction_set_computer https://en.wikipedia.org/wiki/Minimal_instruction_set_comput... I've also invented something like this: NISC. (Or {}ISC) Null Instruction Set Computer. You can arbitrarily reduce the die size for implementations of this architecture, as well as scale the clock speed arbitrarily. It also revolutionizes cooling.
- oddity 9y agoI don't think the description as minimal was intended in any formal way. It's informally minimal in the sense that it features less complexity than more well known languages like C or Fortran. A formal notion of a minimal language/machine gets messy anyway and is of limited utility even in a purely academic context, as far as I know.
- stcredzero 9y agoMy NISC ISA is minimal in a comedic context.
- zoren 9y agoI don't think it was intended in the formal sense either. But "minimalistic" or "small" would probably be more suitable.
- simcop2387 9y agoSomeone else invented something similar, https://en.wikipedia.org/wiki/Zero_instruction_set_computer https://en.wikipedia.org/wiki/Zero_instruction_set_computer it's kind of insane how little you need to do computation.
- nickpsecurity 9y agoYou got me excited then eye rolling with the NISC reference. The author showing up would've been interesting. https://en.wikipedia.org/wiki/No_instruction_set_computing https://en.wikipedia.org/wiki/No_instruction_set_computing
- bluetomcat 9y agoI have a very similar project (not a compiler but an interpreter for a small, integer-only imperative language): https://github.com/bbu/simple-interpreter https://github.com/bbu/simple-interpreter Unlike this recursive-descent parser, my minimalistic language uses a table-driven shift-reduce parser which is entirely contained in the C code. Both the lexer and the parser can be extended very easily in order to accommodate new tokens and new syntactic forms.
- nils-m-holm 9y agoT3X9 also uses a table-driven operator-precedence (LR) parser for most binary operators.
- bluetomcat 9y agoKudos for the bootstrapping ability and for the highly skillfully made ELF and code generation. I wouldn't be able to do that :-)
- nils-m-holm 9y agoThanks! Decades of experience! :)
- i336_ 9y agoWhat might you recommend to someone who wants to to learn more about these subjects? For example, http://www.muppetlabs.com/~breadbox/software/tiny/teensy.html http://www.muppetlabs.com/~breadbox/software/tiny/teensy.htm... is extremely interesting, but a lot of it is over my head. I guess at the end of the day there's no real alternative to "just dive into the source code for a while" with these sorts of things - hence the importance of having "decades of experience" under your belt - but I'm curious if there's anywhere in particular that you might recommend as a startpoint.
- nils-m-holm 9y ago
- T3RMINATED 9y agotake this garbage behind a shed and shoot it. Do us a favor.
- deleted 9y ago[deleted]
- b1gtuna 9y agoCool, looks like I have something to read this weekend. I am glad their e-book caters towards people with little comp-sci / compiler design background.
- b1gtuna 9y agoIs the author of T3X reputable? I am about to drop $20 for the ebook, but I just want to be sure he has good basis on the subject.
- sigjuice 9y agoThe author is unknown to me (and I am nobody!). FWIW, I just bought the book and quickly read through the chapter on bootstrapping. IMHO, it is really well written.
- b1gtuna 9y agoTy for your input. Getting a copy :)
- nils-m-holm 9y agoIt is, of course, a bit of an oxymoron to answer this question myself but, FWIW, I have been writing compilers since the 1990's, both as a hobby and as a job. I have written compilers for lots of different processors and virtual machines with varying key aspects, like compilation speed, memory footprint, executable size, etc. Check out my home page (http://t3x.org http://t3x.org), there compilers for many different languages, from mainstream to pretty exotic. There are also excerpts from many of my books and even the full texts of some of the older ones.
- register 9y agoWhat about your other book "Lightweight Compiler Techniques? Could you put an excerpt online?
- nils-m-holm 9y agoOh, yes, the homepage needs some reorganization! For now, you can download the full text of "Lightweight Compiler Techniques" here: http://www.bcl.hamilton.ie/~nmh/t3x.org/zzz/lightweight-compiler-techniques.zip http://www.bcl.hamilton.ie/~nmh/t3x.org/zzz/lightweight-comp... Enjoy!
- nickpsecurity 9y agoPeople who want a simple language like old days should check out Edison language and system. It's like BCPL minimalism meets Wirth's Oberon: http://brinch-hansen.net/papers/1981b.pdf http://brinch-hansen.net/papers/1981b.pdf He did lots of interesting stuff including a race-free language for concurrency: http://brinch-hansen.net/papers/ http://brinch-hansen.net/papers/
- bmh100 9y agoI mean this earnestly (no snark): why should I care about T3X? I know that I'm missing the obvious reasons.
- nils-m-holm 9y agoAs bootload said, it's a learning tool. You can also use it to bootstrap something more high-level than assembly language in very little time. I have even written real-life programs in T3X for a while, but I wouldn't recommend it unless you are fascinated by the beauty of typeless languages!
- bmh100 9y agoWhat could it teach? Compiler design? Imperative language design? By "bootstrapping", are you referring to building a higher-level language that compiles to T3X?
- nils-m-holm 9y agoIt can teach the most fundamental basics of procedural language design and compiler construction: how to implement selection, loops, and functions/procedures as well as scanning, parsing, and code generation. By bootstrapping, I'm referring to building a T3X9 compiler for a new target platform and than using that to create something more interesting. You can start the process by re-implementing the compiler or by re-targeting it.
- bmh100 9y agoWould studying it be helpful if I wanted to create a static analysis application on top of an existing procedural language?
- nils-m-holm 9y agoStatic analysis involves things like partial evaluation, dataflow analysis, and type inference. None of this is covered in the T3X book.