Shop OBEX P1 Docs P2 Docs Learn Events
Mince Interpreter for the Propeller -- Forth wins — Parallax Forums

Mince Interpreter for the Propeller -- Forth wins

David BetzDavid Betz Posts: 14,516
edited 2014-02-09 04:49 in Propeller 1
I have just finished my first attempt ant providing an interactive infix language for the Propeller that has decent performance. I took a simple Basic interpreter that I wrote a while back and added a PASM VM to improve its runtime performance. I then added an interactive mode so it itsn't necessary to type "run" every time you want to test some code. My intent had been to replace the Basic-like syntax with C-like syntax mainly because it is more terse and easier to type interactively. I got all of this running on the Macintosh using Xcode and on the Propeller using PropGCC. Unfortunately, the resulting system is too large to fit in hub memory even compiled with the CMM memory model. It does fit comfortably on a board like the C3 that has a SPI flash chip and can use the XMMC memory model but not many people are willing to supply the extra chip to use the XMM modes.

The code is in GitHub if anyone is interested. I didn't do the conversion to C-like syntax yet because I figured that the requirement for external memory would probably mean there would be little interest in this. Also, the name "Mince" stands for "Mince Is Not C Exactly". It's one of those recursive acronyms that were popular a while back (like Gnu is Not Unix for GNU).

https://github.com/dbetz/mince

So, for now anyway Forth wins. It is the only interactive environment for the Propeller that can run without any external memory. Actually, there are others like FemtoBasic and the embedded Basic that Bean created but Mince is quite a bit faster than those and probably nearly as fast as Spin.

Here is a sample run. Toward the end you can see the interactive mode.
ebasic 0.003
load test.bas
Loading 'test.bas'
OK
list
10  def fact(n)
20    if n < 2 then
30      return n
40    else
50      return fact(n-1) * n
60    end if
70  end def
80  a = 2
90  b = 10
100  for x=a to b
110    print x, fact(x)
120  next x
OK
run
2	2
3	6
4	24
5	120
6	720
7	5040
8	40320
9	362880
10	3628800
OK
print a
2
print fact(10)
3628800
«13

Comments

  • Bill HenningBill Henning Posts: 6,445
    edited 2014-02-07 10:13
    Nice work David!

    Did you benchmark the runtime against Forth, C version in various LMM modes, and ebasic?

    It might be nice to see the performance deltas for the various languages.
    David Betz wrote: »
    I have just finished my first attempt ant providing an interactive infix language for the Propeller that has decent performance. I took a simple Basic interpreter that I wrote a while back and added a PASM VM to improve its runtime performance. I then added an interactive mode so it itsn't necessary to type "run" every time you want to test some code. My intent had been to replace the Basic-like syntax with C-like syntax mainly because it is more terse and easier to type interactively. I got all of this running on the Macintosh using Xcode and on the Propeller using PropGCC. Unfortunately, the resulting system is too large to fit in hub memory even compiled with the CMM memory model. It does fit comfortably on a board like the C3 that has a SPI flash chip and can use the XMMC memory model but not many people are willing to supply the extra chip to use the XMM modes.

    The code is in GitHub if anyone is interested. I didn't do the conversion to C-like syntax yet because I figured that the requirement for external memory would probably mean there would be little interest in this. Also, the name "Mince" stands for "Mince Is Not C Exactly". It's one of those recursive acronyms that were popular a while back (like Gnu is Not Unix for GNU).

    https://github.com/dbetz/mince

    So, for now anyway Forth wins. It is the only interactive environment for the Propeller that can run without any external memory. Actually, there are others like FemtoBasic and the embedded Basic that Bean created but Mince is quite a bit faster than those and probably nearly as fast as Spin.

    Here is a sample run. Toward the end you can see the interactive mode.
    ebasic 0.003
    load test.bas
    Loading 'test.bas'
    OK
    list
    10  def fact(n)
    20    if n < 2 then
    30      return n
    40    else
    50      return fact(n-1) * n
    60    end if
    70  end def
    80  a = 2
    90  b = 10
    100  for x=a to b
    110    print x, fact(x)
    120  next x
    OK
    run
    2	2
    3	6
    4	24
    5	120
    6	720
    7	5040
    8	40320
    9	362880
    10	3628800
    OK
    print a
    2
    print fact(10)
    3628800
    
  • David BetzDavid Betz Posts: 14,516
    edited 2014-02-07 10:21
    Nice work David!

    Did you benchmark the runtime against Forth, C version in various LMM modes, and ebasic?

    It might be nice to see the performance deltas for the various languages.
    ebasic3/mince will not fit in LMM mode. It will barely fit in CMM mode if you leave out the filesystem support. It really needs external memory to be practical. I guess the least chip-intensive platform for it would be a Propeller board with a 128K EEPROM but the EEPROM cache driver is rather slow so the performance might not be that good. The good news is that the external memory is only used for the editor and compiler. At runtime it runs entirely out of hub memory with a PASM VM.
  • jazzedjazzed Posts: 11,803
    edited 2014-02-07 10:25
    Hmm. So I should leave the propeller community forever now because forth is the only viable language?
  • Bill HenningBill Henning Posts: 6,445
    edited 2014-02-07 10:26
    I still think it is a nice idea - add a cheap SPI flash, develop on board. Heck, uSD based caching XMM could be used for the compiler/editor!

    Sorry, I guess I was not clear... I was curious about the run times for benchmarks; it would be nice to start building a database for P1 / P2 languages.
    David Betz wrote: »
    ebasic3/mince will not fit in LMM mode. It will barely fit in CMM mode if you leave out the filesystem support. It really needs external memory to be practical. I guess the least chip-intensive platform for it would be a Propeller board with a 128K EEPROM but the EEPROM cache driver is rather slow so the performance might not be that good. The good news is that the external memory is only used for the editor and compiler. At runtime it runs entirely out of hub memory with a PASM VM.
  • David BetzDavid Betz Posts: 14,516
    edited 2014-02-07 10:27
    jazzed wrote: »
    Hmm. So I should leave the propeller community forever now because forth is the only viable language?
    No, it's not the only viable language but it might be the best choice if you absolutely need a fast interactive language. I'm sure someone can do better than I did though.
  • David BetzDavid Betz Posts: 14,516
    edited 2014-02-07 10:29
    I still think it is a nice idea - add a cheap SPI flash, develop on board. Heck, uSD based caching XMM could be used for the compiler/editor!

    Sorry, I guess I was not clear... I was curious about the run times for benchmarks; it would be nice to start building a database for P1 / P2 languages.
    No, you were clear. I just misread your post. Sorry.

    I assume you're kidding about building a database of P1 / P2 languages. There's already that huge list of languages that mostly contains languages that run under CP/M. :-)
  • Bill HenningBill Henning Posts: 6,445
    edited 2014-02-07 10:44
    I meant benchmarks for the languages :)

    All languages will run way faster on the P2 than P1, it might help P2 sales.
    David Betz wrote: »
    No, you were clear. I just misread your post. Sorry.

    I assume you're kidding about building a database of P1 / P2 languages. There's already that huge list of languages that mostly contains languages that run under CP/M. :-)
  • David BetzDavid Betz Posts: 14,516
    edited 2014-02-07 10:46
    I meant benchmarks for the languages :)

    All languages will run way faster on the P2 than P1, it might help P2 sales.
    I would hope they would run faster. It's been how many years since the P1 was introduced? :-)
  • jazzedjazzed Posts: 11,803
    edited 2014-02-07 12:03
    Mince should have no problem running from a 64KB EEPROM by removing the SD filesystem. I've done this easily with a version of ebasic.

    Since the code runs in a VM, run-time performance would be the same as if Mince were running in HUB RAM. Compiling will be a little slower of course. There should also be lots of room left in the EEPROM for storing a user program.

    Don't give up David. You have a viable solution started. All you need to do is finish with reasonable features.
  • David BetzDavid Betz Posts: 14,516
    edited 2014-02-07 12:05
    jazzed wrote: »
    Mince should have no problem running from a 64KB EEPROM by removing the SD filesystem. I've done this easily with a version of ebasic.

    Since the code runs in a VM, run-time performance would be the same as if Mince were running in HUB RAM. Compiling will be a little slower of course. There should also be lots of room left in the EEPROM for storing a user program.

    Don't give up David. You have a viable solution started. All you need to do is finish with reasonable features.
    Yes, it will fit with the filesystem disabled. And yes, I could implement LOAD and SAVE to a simple EEPROM filesystem that might fit in the remaining space of a 64K EEPROM. It would be tight though.
  • Bill HenningBill Henning Posts: 6,445
    edited 2014-02-07 12:08
    There is a 24LC1024 that may help you - and I agree with Steve, don't give up.

    The more languages for the prop, the likelier it is that every user will find something that fits them best!

    If the Prop won't boot on a 24LC1024, there is another one that behaves like two 24LC512's in one package... I think 25LC1024?
    David Betz wrote: »
    Yes, it will fit with the filesystem disabled. And yes, I could implement LOAD and SAVE to a simple EEPROM filesystem that might fit in the remaining space of a 64K EEPROM. It would be tight though.
  • David BetzDavid Betz Posts: 14,516
    edited 2014-02-07 12:11
    There is a 24LC1024 that may help you - and I agree with Steve, don't give up.

    The more languages for the prop, the likelier it is that every user will find something that fits them best!

    If the Prop won't boot on a 24LC1024, there is another one that behaves like two 24LC512's in one package... I think 25LC1024?
    Doesn't the Hydra use a 128K EEPROM? I think it uses the 24LC1024. In any case, I have a few of those I can try using to replace the 64K EEPROM on a Quickstart board.
  • jmgjmg Posts: 15,173
    edited 2014-02-07 13:08
    David Betz wrote: »

    Here is a sample run. Toward the end you can see the interactive mode.
    ebasic 0.003
    load test.bas
    Loading 'test.bas'
    OK
    list
    10  def fact(n)
    20    if n < 2 then
    30      return n
    40    else
    50      return fact(n-1) * n
    60    end if
    70  end def
    80  a = 2
    90  b = 10
    100  for x=a to b
    110    print x, fact(x)
    120  next x
    OK
    run
    2	2
    3	6
    4	24
    5	120
    6	720
    7	5040
    8	40320
    9	362880
    10	3628800
    OK
    print a
    2
    print fact(10)
    3628800
    

    Nice example.

    Is it easy to add a time-stamp to each result line ?
  • David BetzDavid Betz Posts: 14,516
    edited 2014-02-07 13:22
    jmg wrote: »
    Nice example.

    Is it easy to add a time-stamp to each result line ?
    Yes but it wouldn't be that informative. I guess I should try running fibo instead of people are really interested in performance numbers.
  • jmgjmg Posts: 15,173
    edited 2014-02-07 13:32
    David Betz wrote: »
    Yes but it wouldn't be that informative.

    ? To me, time taken is always informative :)

    Especially when I see the words "Interpreter", as then any code-speed becomes a much larger unknown.
  • David BetzDavid Betz Posts: 14,516
    edited 2014-02-07 13:50
    jmg wrote: »
    ? To me, time taken is always informative :)

    Especially when I see the words "Interpreter", as then any code-speed becomes a much larger unknown.
    I think the printing speed dominates the loop I presented above. The fibo example is more compute intensive.
  • Heater.Heater. Posts: 21,230
    edited 2014-02-07 14:57
    Is it possible that people would stop inventing new programming languages?

    I know it's an interesting endeavour but it really confuses the world.

    @David Betz, Are you the same David Betz that created XLisp?

    If so you have a lot to answer for:)

    If not, I make my apologies.
  • David BetzDavid Betz Posts: 14,516
    edited 2014-02-07 15:06
    Heater. wrote: »
    Is it possible that people would stop inventing new programming languages?
    No, because it's fun as you suggested. Also, I did this in an attempt to show that an infix language could be interactive not just Forth and would fit on the Propeller. Unfortunately, I failed at that. It doesn't fit on a Propeller without using external memory.
    I know it's an interesting endeavour but it really confuses the world.
    Not really because mostly everyone ignores the new languages.
    @David Betz, Are you the same David Betz that created XLisp?
    Yes, that's me.
    If so you have a lot to answer for:)
    What would that be?
    If not, I make my apologies.
    No need for any apologies. :-)
  • Heater.Heater. Posts: 21,230
    edited 2014-02-07 15:36
    David,

    I am no programming language designer, and I admire your efforts.

    It just seemed to me for a long time that if you want a really small interpreted, interactive "high level" language then you have to engineer its syntax to be as simple as possible. Complex parsing costs code space. Never mind the semantics. As far as I can tell Forth like, backwards, syntaxes are the simplest and hence can be made in the least code space.

    As I said above I admire your effort to prove this thesis wrong.
    Not really because mostly everyone ignores the new languages.
    I really hope that is true today. Having had to learn a new language for pretty much every project I have taken part in during my career I do wonder: ALGOL, BASIC, Coral, PL/M, C, C++, Python, JavaScript, PHP, Spin ...

    It has not stopped. The young kids today have Ruby, Go, Dart....

    Please make it stop!
    What would that be?
    Sorry, I was a bit hard there.

    I just happened to put 2 and 2 together the other day and start googling for David Betz the xlisp guy.

    As far as I can tell from finding various forum posts and such xlisp attracted a lot of enthusiastic followers. They need you.
  • David BetzDavid Betz Posts: 14,516
    edited 2014-02-07 15:48
    Heater. wrote: »
    David,

    I am no programming language designer, and I admire your efforts.

    It just seemed to me for a long time that if you want a really small interpreted, interactive "high level" language then you have to engineer its syntax to be as simple as possible. Complex parsing costs code space. Never mind the semantics. As far as I can tell Forth like, backwards, syntaxes are the simplest and hence can be made in the least code space.
    Why stop with Forth then? Steve is always mentioning the BrainF*ck language. It is more concise than Forth and is probably Turing complete. An interactive version of that should probably replace Forth by that measure. What I was trying to address is the fact that there are many people who believe that postfix languages are difficult to work with. An alternative doesn't have to be quite as small or maybe even quite as fast. It just needs to be small enough and fast enough.
    As I said above I admire your effort to prove this thesis wrong.
    As it turns out, I was wrong. The ebasic3/mince system does fit in CMM with the SD card LOAD/SAVE commands disabled. It would probably be possible to add EEPROM LOAD/SAVE commands and still fit in hub memory using CMM. So, if I were to follow through with that, I guess I have succeeded. Also, my plan to migrate to C-like syntax was at least an attempt to use a standard syntax. It might be possible to be a strict subset of C so that Mince programs could be compiled and run by a normal C compiler. The reverse would obviously not be possible though so maybe being similar to C has limited value. However, the more terse syntax will be easier to type interactively so it might still be useful.
    I really hope that is true today. Having had to learn a new language for pretty much every project I have taken part in during my career I do wonder: ALGOL, BASIC, Coral, PL/M, C, C++, Python, JavaScript, PHP, Spin ...

    It has not stopped. The young kids today have Ruby, Go, Dart....

    Please make it stop!
    That was my first reaction to learning that the Propeller had to be programmed in Spin. Why another language?
    Sorry, I was a bit hard there.

    I just happened to put 2 and 2 together the other day and start googling for David Betz the xlisp guy.

    As far as I can tell from finding various forum posts and such xlisp attracted a lot of enthusiastic followers. They need you.
    I'm still not sure what you're saying. Are you saying that creating xlisp was bad? In fact, I wrote xlisp before Common Lisp existed or at least before I knew about it. At the time there were lots of different Lisp systems around and none were completely compatible with the others. For a while xlisp was actually used in the MIT introductory programming class that taught Scheme using the book Structure and Interpretation of Computer Programs. It wasn't the main language used. That was MIT C-Scheme. It was used by some students who wanted to do their homework at home since MIT C-Scheme did not run on personal computers at the time. Also, are you suggesting that I should disappear from here and go support all of those enthusiastic xlisp users? I'm not sure why you're being so hostile.
  • potatoheadpotatohead Posts: 10,261
    edited 2014-02-07 16:05
    I don't believe Heater is being hostile, and I would really like to see you stay here with us David. I enjoy your contributions, like this one, very much.

    Having seen this, I really think a discussion about Forth and a postfix alternative would be of value, but start lower. Like what infix (do I have that right?) syntax can fit into a COG kernel and build out from there. We may be surprised at the result of that conversation. Something I have been thinking hard about since you started the discussion.
  • Heater.Heater. Posts: 21,230
    edited 2014-02-07 16:18
    David,

    No, I am not suggesting you disappear from here. Please don't.

    I don't mean to be hostile. Actually I'm fascinated by programming language design.

    On the one hand it's an exercise in engineering, what can we actually do to make programming easier for "normal" humans who don't want to talk to their machines in binary op codes. A compiler/interpreter has to be buildable, it has to fit the machines resources, it has to be fast enough.

    On the other hand it is seems to be very cultural. For example infix is good postfix is bad. Languages like VB gain traction, but Lisp and Scheme do not.

    I have to have snooze and think about your other points.
  • David BetzDavid Betz Posts: 14,516
    edited 2014-02-07 18:54
    Heater. wrote: »
    On the other hand it is seems to be very cultural. For example infix is good postfix is bad. Languages like VB gain traction, but Lisp and Scheme do not.
    I'm certainly not saying that postfix is bad. I have a number of HP calculators and like playing with RPL and have wanted to find the time to learn more about Forth but am making slow progress. I even spent some time playing with PostScript. I'm just saying that there seem to be many more people who are comfortable with infix languages than postfix languages.
  • mindrobotsmindrobots Posts: 6,506
    edited 2014-02-07 19:14
    Maybe because infix is more similar to many natural languages:

    Noun/object verb noun/object

    than postfix languages:

    Noun/object noun/object verb verb

    ??
  • jazzedjazzed Posts: 11,803
    edited 2014-02-07 20:11
    mindrobots wrote: »
    Maybe because infix is more similar to many natural languages:

    Noun/object verb noun/object

    than postfix languages:

    Noun/object noun/object verb verb

    ??
    That's the way it is in the USA at least.

    It's also how little kids learn math - please don't confuse them.
  • David BetzDavid Betz Posts: 14,516
    edited 2014-02-07 20:11
    mindrobots wrote: »
    Maybe because infix is more similar to many natural languages:

    Noun/object verb noun/object

    than postfix languages:

    Noun/object noun/object verb verb

    ??
    I think it's because that is the way we were taught to do it in math class.
  • David BetzDavid Betz Posts: 14,516
    edited 2014-02-07 20:11
    Here are the Fibo results for ebasic3/mince running on a C3:
    fibo(0) = 0 (0ms) (2688 ticks)
    fibo(1) = 1 (0ms) (2688 ticks)
    fibo(2) = 1 (0ms) (6016 ticks)
    fibo(3) = 2 (0ms) (9344 ticks)
    fibo(4) = 3 (0ms) (16000 ticks)
    fibo(5) = 5 (0ms) (25984 ticks)
    fibo(6) = 8 (0ms) (42624 ticks)
    fibo(7) = 13 (0ms) (69248 ticks)
    fibo(8) = 21 (1ms) (112512 ticks)
    fibo(9) = 34 (2ms) (182400 ticks)
    fibo(10) = 55 (3ms) (295552 ticks)
    fibo(11) = 89 (5ms) (478592 ticks)
    fibo(12) = 144 (9ms) (774784 ticks)
    fibo(13) = 233 (15ms) (1254016 ticks)
    fibo(14) = 377 (25ms) (2029440 ticks)
    fibo(15) = 610 (41ms) (3284096 ticks)
    fibo(16) = 987 (66ms) (5314176 ticks)
    fibo(17) = 1597 (107ms) (8598912 ticks)
    fibo(18) = 2584 (173ms) (13913728 ticks)
    fibo(19) = 4181 (281ms) (22513280 ticks)
    fibo(20) = 6765 (455ms) (36427648 ticks)
    fibo(21) = 10946 (736ms) (58941568 ticks)
    fibo(22) = 17711 (1192ms) (95369856 ticks)
    fibo(23) = 28657 (1928ms) (154312064 ticks)
    fibo(24) = 46368 (3121ms) (249682560 ticks)
    fibo(25) = 75025 (5049ms) (403995264 ticks)
    fibo(26) = 121393 (8170ms) (653678464 ticks)
    
    And here is the code:
    def fibo(n)
      if n < 2 then
        return n
      else
        return fibo(n - 1) + fibo(n - 2)
      end if
    end def
    
    for n = 0 to 26
      print "fibo("; n; ") = ";
      startTime = cnt
      result = fibo(n)
      endTime = cnt
      rawTime = endTime - startTime
      executionTime = rawTime / (clkfreq / 1000)
      print result; " ("; executionTime; "ms) ("; rawTime; " ticks)"
    next n
    
  • jonesjones Posts: 281
    edited 2014-02-07 20:52
    If the Prop won't boot on a 24LC1024, there is another one that behaves like two 24LC512's in one package... I think 25LC1024?
    It will. I used a 24LC1024 in a Prop1 design and it worked fine.
  • Peter JakackiPeter Jakacki Posts: 10,193
    edited 2014-02-07 21:31
    David Betz wrote: »
    Here are the Fibo results for ebasic3/mince running on a C3:

    I don't go in for benchmarks as I look at performance as a whole and there are a lot of things that benchmarks don't reveal or hide. Anyhows, I wrote a quick fibo and tried it out and it turns out it takes a whopping 192ms / loop. But when I compare that to an ARM Forth that had far more assembler code for the kernel and of course fast access to main memory, as well as a faster clock speed (15ns cycle time vs 50ns) the ARM Forth was still only just over 3 times faster.

    Thought you might like the figure as a comparison.

    EDIT: !!! Whoops, wrong benchmark, that was a sieve of eratosthenes.
  • KeithEKeithE Posts: 957
    edited 2014-02-07 22:04
    Another one for heater - http://www.ifarchive.org/if-archive/articles/byte87_betz.html

    I remember playing around with this a couple of decades ago ;-)
Sign In or Register to comment.