6502.org Forum  Projects  Code  Documents  Tools  Forum
It is currently Mon May 13, 2024 10:57 pm

All times are UTC




Post new topic Reply to topic  [ 1 post ] 
Author Message
 Post subject: My Really Loopy Idea
PostPosted: Wed Oct 02, 2019 8:06 pm 
Offline

Joined: Wed Jan 08, 2014 3:31 pm
Posts: 575
What if Forth was written using Scheme S expressions? The result is a weird language that's kinda like Forth, but also a bit like Scheme. Hence why I am posting this in the Forth sub-forum. It would look like the code below, and be Forth from an alternate universe:
Code:
(define factorial
  (lambda
  (if (= dup 0) 1
      (* dup (factorial (- dup 1))))))

So to make this crazy idea a reality I've been building a toy cross compiler written in Python that generates 6502 assembly. The language syntax uses Scheme S expressions, a data, and a return address stack. Here's my repo: https://github.com/Martin-H1/TinyComp

The compiler will translate the code above into assembler like this:
Code:
factorial:
.scope
        `dup
        `pushi 0
        jsr equals16
.scope
        bne _else
        `pushi 1
        bra _endif
_else:
        `dup
        `dup
        `pushi 1
        jsr sub16
        jsr factorial
        jsr mul16
_endif:
.scend

        rts
.scend


This code assumes the use of the Ophis assembler and my page zero stack macros, and 16 bit math functions. This is also in the really early stages and my never go anywhere. But I figured people here might be interested in the concept.


Top
 Profile  
Reply with quote  
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 1 post ] 

All times are UTC


Who is online

Users browsing this forum: No registered users and 2 guests


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Search for:
Jump to: