Design and source of IINT

If you have any questions, remarks, ... if you need help... its here...

Design and source of IINT

Postby Will.Rubin » 16 Dec 2014 17:04

Oforth looks to have some interesting ideas. Where can I see more about the inner interpreter, how internal stacks are handled, threading method, native method implementation, etc?
Posts: 10
Joined: 16 Dec 2014 17:00

Re: Design and source of IINT

Postby Franck » 16 Dec 2014 19:24


Yes I think I will post Oforth inner interpreter sources when it will reach a a good stability (when oforth will reach V1.0.0, I think).

1) Internal stacks :

Oforth differs from some Forth implementation about internal stacks :
- Most Forth implementations use thread stack as data stack. Oforth uses thread stack as Return Stack. Each call to function or method is converted to a call on the thread stack (return is a true ret instruction, not a jmp).

- Data stack is allocated on the heap when a task is created, and is removed when the task ends. Task switch on a thread does not copy the data stack, only the RS.

2) Native methods implementation :
Most are written in C (some are written in ASM, like polymorphism).
Because RS is mapped to thread stack, native calls are similar to oforth calls (native code can call oforth code and oforth code can call native call).

3) Threading method
Oforth creates workers (OS Thread) when needed.

A thread has a linked list of running tasks.

Thread main method is an infinite loop :
- If its running tasks list is not empty, it removes the first task and run it until task is waiting, is dead or if a yield is necessary.
- If its running tasks list is empty, it searches for the next task scheduled on its scheduler and adds it to its running tasks list.
- If nothing to do, the thread just yields and restart the loop.

A task is always handled by the same thread (for garbage collector optimization).

Resources have waiting tasks. When a task is waiting for a resource, it is no more visible by its thread. When a task stops waiting, it is added to its thread running tasks list.

A thread is never killed. If the scheduler attached to the thread is garbaged, the thread is detached and its state becomes IDLE, which means it is available for a new scheduler or for the default scheduler.

Best regards,
Posts: 163
Joined: 29 Oct 2014 19:01

Re: Design and source of IINT

Postby Franck » 08 Feb 2016 23:32

With V0.9.23, you can see Oforth theading method into asm.of and prelude.of files.

Oforth generates native code on the flow while immediate words are performed.

For instance, in Oforth, dup, drop, over, ... are ... immediate words that generate asm code.

More native methods will be translated to Oforth code in later versions.

Posts: 163
Joined: 29 Oct 2014 19:01

Return to General

Who is online

Users browsing this forum: No registered users and 1 guest