monsonite / SIMPL

Serial Interpreted Microcontroller Programming Language
GNU General Public License v3.0
24 stars 4 forks source link

Feature request: Support conditionals #1

Open JamesNewton opened 4 years ago

JamesNewton commented 4 years ago

If you could add support for conditional execution, then the system could react to inputs. For example, if you support =, >, < and use ? as IF and . as THEN, something like 2dl1ds128>?2dh. would set pin 2 low, then do an adc reading from pin 1 and if it's more than 128 it would set pin 2 high. Handy, no?

monsonite commented 4 years ago

Hi James,

Thank you for your suggestion.

I toyed briefly with conditional code execution, where a phrase of code contained within brackets, would be executed only if there was 1 left on the stack or skipped if there was 0 on the stack.

It's a few years since I have looked at this - so I will have to refresh my memory and get back to you.

I have a lot more documentation to do on SIMPL, I previously had been interested in making the kernel as small as possible, with the aim of extending it with further words - rather like the way a Forth is generally constructed.

I also have been distracted by TTL computers - and have been following the Gigatron project - where an Apple 1 can be emulated, running 6502 code - executed on a TTL cpu consisting of just 930 basic logic gates, a ROM and a RAM.

It is my intention to implement the SIMPL on the Gigatron - running in the 16-bit virtual machine that it implements.

Right now I am renovating an old garden shed - to turn it into a garden cabin - and taking advantage of the exceptional weather, here in the UK, and opportunity of excess free time - I have available this year.

I will follow through your example and se if there is a reletively simple way to implement the IF-THEN construct.

regards

Ken

On Tue, 12 May 2020 at 18:20, JamesNewton notifications@github.com wrote:

If you could add support for conditional execution, then the system could react to inputs. For example, if you support =, >, < and use ? as IF and . as THEN, something like 2dl1ds128>?2dh. would set pin 2 low, then do an adc reading from pin 1 and if it's more than 128 it would set pin 2 high. Handy, no?

— You are receiving this because you are subscribed to this thread. Reply to this email directly, view it on GitHub https://github.com/monsonite/SIMPL/issues/1, or unsubscribe https://github.com/notifications/unsubscribe-auth/AAFZIP6KL6ZMBQVRKYFHKDTRRGAOZANCNFSM4M7AR7EQ .

sturem commented 3 years ago

Use 0 or 1 on left on the stack from < > or = as the parameter for a {...} loop, which will cause the code inside to be either skipped or executed exactly once.

No if-else but ! could invert the test (or does that flip all the bits, not just toggle 1 & 0 / true-false? in which case you may need to mask the loop arg to only the lsb)


Note however that loops are not nested, hence could not contain that type of 0/1{...} if-then conditional: there is only 1 loop counter, k; and the { start-loop scanner skips only until the first } not until a balanced } matching any {...} nesting; similarly, only one saved ch buf pointer to use at end-of-loop.

(not intended as a criticism, just food for thought: SIMPL is amazingly simple and compact!)

monsonite commented 3 years ago

Sturem,

That is exactly what is intended. Any operation that leaves 0 or 1 on the stack will result in the loop being skipped or executed once.

This could be as the result of reading the state of an input pin. If the pin is high the block of code is executed.

monsonite commented 3 years ago

I must advise that the code has moved on a bit since last year, as a result of several external influences.

One of these is "STABLE" a similar character based language by Sandor Schneider of Budapest

http://www.w3group.de/stable.html

STABLE provided me a better means of implementing and managing a stack structure, and these features are currently being incorporated into SIMPL.

C source is here http://www.w3group.de/stable.c

monsonite commented 3 years ago

(not intended as a criticism, just food for thought: SIMPL is amazingly simple and compact!)

Yes, SIMPL was always intended to be the minimum needed to have an interactive session with a microcontroller. Not so much as a complete programming language, but a very lightweight tool to check that the fundamentals are all working.

I have been somewhat distracted this year by the idea of a minimum gate count cpu (<1000 gates) which is natively programmed in SIMPL code. i.e. human readable SIMPL code forms the machine language of the cpu.

sturem commented 3 years ago

human readable SIMPL code forms the machine language of the cpu

Now that's an interesting idea....

monsonite commented 3 years ago

Stuart,

The 7-bit ascii character from the source code is directly jammed into the Program Counter so that it provides a jump to a block of code that executes the primitive instruction.

If you have a "+" in the source code, it causes a jump to the 16-bit add routine.

There's a lot of simulation work to do yet, but I think it could be a valid technique for minimal hardware.