Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8599443
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 12, 20262026-06-12T01:23:57+00:00 2026-06-12T01:23:57+00:00

I have a small programming language I’ve been designing, and I want a relatively

  • 0

I have a small programming language I’ve been designing, and I want a relatively easy backend option for it. C stands out as a relatively decent option for all the usual reasons (such as “I can’t follow good advice” and “I don’t know assembly”), plus more importantly the fact that there’s not very much in my language that can’t easily be expressed in C (it’s more about the type checker, no GC or heavy-duty runtime to accommodate) – except one thing: optimised tail calls.

It’s not a deal breaker: I don’t really need it, as the language has looping constructs, but it’s supposed to be functional too, so TCO seems like a valuable thing to put in if possible. Trampoline or lazy-thunk solutions would work, but appear (from the literature, I have not profiled yet, and anyway don’t have any usage information) to have a noticeable effect on performance. Don’t want the implementation to discourage users from expressing a problem in a valid way.

This question leaves me thinking it ought to be possible to create a relatively simple platform-specific “tailcall” block, to replace “return” and force the behaviour that I want. But, not being familiar enough with x86, I don’t know how to control C’s automatic stack manipulation, where I ought to be aiming the jump, etc. (It looks to me like it extends the stack after the start of a function… so I need to either shrink the stack before the tailcall, which would be a bit unnecessary, or somehow aim a jump at the start of the target’s body after the stack manipulation, which sounds pretty much impossible edit: for a statically-unknown target ..?)

So:

  • can this be done?
  • can it be done safely?
  • is it at all sensible?

I should repeat that I am aware that it is possible to implement tail call elimination that works in C (that is, of my high-level language, not of C), I just want to add a compiler-and-platform-specific optimisation, to help it be be more or less indistinguishable from the “real thing”. And I mainly want to use C because I’m very confident with it, whereas I’ve never used LLVM and have only the barest reading-knowledge of x86, so I was hoping to skip that step and get output working. I know I will have to learn both properly in the future at some point, but …

(i.e. I’m asking this because the idea is stuck in my head and it bugs me that there might be a Better Way To Do It(tm), not because I need the solution to get a working backend.)

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-12T01:23:58+00:00Added an answer on June 12, 2026 at 1:23 am

    can this be done?

    Yes.

    can it be done safely?

    Yes.

    is it at all sensible?

    No. gcc already does TCO for you and additionally supports computed goto, so there’s absolutely no reason to do this.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

i have made a small opengl program using the d programming language. what i
I have been reading Wikipedia's article on K programming language and this is what
I have recently been reading up on the D programming language, and am interested
I have been working through the tutorial at http://bkiers.blogspot.de/2011/03/creating-your-own-programming-language.html . In short, a small
I'm learning JavaFX and this is just a small programming question. I have 3
I am just new to programming in Unix and have a small issue that
I have just started programming and have made a few small applications in C
I'm working on a small programming language for the Microsoft DLR, and having a
I've been developing an interpreter in C++ for my (esoteric, if you want) programming
I have recently started learning Ruby, as my first programming language. I feel comfortable

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.