Reputation: 31
I am attempting to (one step at a time) build my own copy of Forth to run on Mac OS X.
I currently have a version of Forth running on Apache and localhost in PHP, Ruby, and Python.
I want to make a version of Forth in C that will create a native executable version of Forth that can make its own native executable files of any compiled Forth code. Sorry about the semi-recursive sentence. My goal is to start in C and end up with my own Forth compiler (no longer running in any C code).
My starting point is to attempt to get a minimal test program to run as a binary executable for Terminal. Once I can understand what the existing C compiler is doing, I can modify its methods for my own purposes.
I created a small "hello world" program in C and ended up with an executable file of 8,497 bytes, which consisted mostly of 0x00 arrays (presumably buffers). My guess is that the entire stdio library was included.
Next, I created the smallest possible C program I could think of (other than a completely null program -- I wanted to be able to find my code in the resulting hex):
int main(void)
{
char testitem;
testitem = 'A';
return -1;
}
That should have given me the barest possible overhead with the storage of the ASCII A and the return value of all ones being easy to find.
Instead, I ended up with a file of 4,313 bytes. There were four locations with the 0x41 (ASCII 'A'), but none were part of a MOV immediate byte instruction. Presumably the 0x41 was stored as constant data and loaded with a different MOV instruction.
Again there were a lot of 0x00 arrays (3,731 bytes, or all but 402 bytes). Presumably there is some kind of header data in the object file (which does run correctly in Terminal and does signal -1) and who knows what else.
At the moment I am not concerned with having an application bundle -- running in Terminal is my short term goal. Once I have this first step working, I can move on to a full application.
Any suggestions on how to determine what I need to have in the object file for it to correctly work as a Terminal tool?
Upvotes: 3
Views: 2805
Reputation: 1561
This turns out to be a common challenge. You might want to check following links that provide rather in-depth information:
Upvotes: 6