Coder Social home page Coder Social logo

quickforth's Introduction

QuickForth

A simple forth dialect prototype with its VM, just for experimental purpose.

* You can continue to extend the function of this VM if you will.

Can only be used under Linux X86-64.

Compile

make  # the binary will be compiled into the "build" folder.

Modes

  • REPL:
➜  Forthress git:(master) ✗ ./build/vm
> 1
> 2
> +
> .S
3
> exit
  • Interpreter:
➜  Forthress git:(master) ✗ ./build/vm forth_discr.fth
-8

Concepts

  • Native Word:

Word provided by the VM.

  • Colon Word:

Word constituted by a series of Native Words (need docol to control the flow).

Format: prologue: xt_docol, epilogue: xt_ret;

  • Control Flow:

Execution Sequences (Native Words):

+------+    +------+ 
| word | -> | word | ...
+------+    +------+
    ^           ^
    w           pc

Execution Sequences (Colon Words):

+------+    +------+ 
| word | -> | word | ...
+------+    +------+
    |           ^
    |           pc (saved in rstack)
+------+    +------+     |
| word | -> | word | ... |
+------+    +------+     | 
    ^           ^        |
    w           pc (new position) 

Architecture

  • Word:
|---------------------->  header (exclude private word)  <---------------------|
+---------------------+----------------+-----------------+---------------------+
| next word addr (dq) | label (string) | (reserved byte) | implementation addr |
+---------------------+----------------+-----------------+---------------------+
  • Dictionary:
 (head)                               (tail)             (.bss)
+------+    +------+     +------+    +------+    +--------------------+
| word | -> | word | ... | word | -> | word | -> | dynamic_colon_stub | -> (dynamic words)
+------+    +------+     +------+    +------+    +--------------------+
                                                     
    +--------------------+        +-------------------------------------+
... | dynamic_colon_stub | ... => | next effective address (dq) | words | ... 
    +--------------------+        +-------------------------------------+
                                                  |--------------|--------^
  • Opcode (For inner interpreter, saving the operation and immediates of each dynamic colon word):
+----------------+-------------------+
| opcode (qword) | immediate (qword) |
+----------------+-------------------+

quickforth's People

Contributors

becavalier avatar

Stargazers

 avatar  avatar  avatar  avatar

Watchers

 avatar  avatar

Forkers

dfischer

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.