Be nice to each other. Flame wars and rants are not welcomed. Please also put some effort into your post, this isn't Quora.  This subreddit is not

ProgrammingLanguages

submited by
Style Pass
2023-03-17 17:00:04

Be nice to each other. Flame wars and rants are not welcomed. Please also put some effort into your post, this isn't Quora.

This subreddit is not the right place to ask questions such as "What language should I use for X", "what language should I learn", "what's your favourite language" and similar questions. Such questions should be posted in /r/AskProgramming or /r/LearnProgramming.

I have made a compiler for a stack machine in Idris. It uses dependent types so it should be safe. It can be seen here: https://github.com/marouan-itu/IdrisCompiler/blob/main/IdrCompVect.idr

I think the main problem with stack machines is the fact that they access only the top two stack elements for arithmetic operations. This could have caused problems if I didn't use dependent types to make my compiler safe, because then I could have attempted to add one number which would cause run time problems. They say the following on this website: Stack Computers: 3.2 A GENERIC STACK MACHINE (cmu.edu)

"One of the problems associated with pure stack machines is that they are able to access only the top two stack elements for arithmetic operations. Therefore, some overhead instructions must be spent on preparing operands to be consumed by other operations. Of course, it should be said that some register-based machines also spend a large number instructions doing register-to-register moves to prepare for operations, so the question of which approach is better becomes complicated."

Leave a Comment
Related Posts