Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Docs #7

Open
wants to merge 18 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 0 additions & 3 deletions .gitignore

This file was deleted.

47 changes: 0 additions & 47 deletions Makefile

This file was deleted.

74 changes: 0 additions & 74 deletions doc-engine.frt

This file was deleted.

14 changes: 0 additions & 14 deletions documentation.frt

This file was deleted.

File renamed without changes.
30 changes: 30 additions & 0 deletions forthress/Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
# ------------------------------------------------
# Forthress, a Forth dialect
#
# Author: igorjirkov@gmail.com
# Date : 15-10-2016
#
# ------------------------------------------------

ASM = nasm
FLAGS = -felf64 -g -Isrc/
LINKER = ld

all: bin/forthress

bin/forthress: obj/forthress.o obj/util.o
mkdir -p bin
ld -o bin/forthress obj/forthress.o obj/util.o

obj/forthress.o: src/forthress.asm src/macro.inc src/words.inc src/util.inc
mkdir -p obj
$(ASM) $(FLAGS) src/forthress.asm -o obj/forthress.o

obj/util.o: src/util.inc src/util.asm
mkdir -p obj
$(ASM) $(FLAGS) src/util.asm -o obj/util.o
clean:
rm -rf build obj

.PHONY: clean

20 changes: 10 additions & 10 deletions README.md → forthress/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -33,12 +33,12 @@ Programming: C, Assembly, and Program Execution on Intel x86-64 Architecture"](h
* `dup` ( a -- a a )
* `rot` ( a b c -- b c a )
* Arithmetic:
* `+` ( x y-- [ x + y ] )
* `*` ( x y-- [ x * y ] )
* `/` ( x y-- [ x / y ] )
* `%` ( x y-- [ x mod y ] )
* `-` ( x y-- [x - y] )
* `<` ( x y-- [x < y] )
* `+` ( y x -- [ x + y ] )
* `*` ( y x -- [ x * y ] )
* `/` ( y x -- [ x / y ] )
* `%` ( y x -- [ x mod y ] )
* `-` ( y x -- [x - y] )
* `<` ( y x -- [x < y] )
* Logic:
* `not` ( a -- a' )
a' = 0 if a != 0
Expand Down Expand Up @@ -142,12 +142,12 @@ Prints a certain amount of characters from string.
( addr -- value )
Fetch value from memory.
* `!`
( val addr -- )
( addr val -- )
Store value by address.
* `c!`
( char addr -- )
* `!c`
( addr char -- )
Store one byte by address.
* `c@`
* `@c`
( addr -- char )
Read one byte starting at addr.
* `,`
Expand Down
File renamed without changes.
114 changes: 114 additions & 0 deletions forthress/documentation.frt
Original file line number Diff line number Diff line change
@@ -0,0 +1,114 @@
' dup g"
( a - a a )
Duplicate the cell on top of the stack.
" doc-word

' drop g"
( a -- )
Drop the topmost element of the stack.
" doc-word

' swap g"
( a b -- b a )
Swap two topmost elements of the stack.
" doc-word

' 2over g"
( a b c -- a b c a )
Copy third element from the top of the stack to the top of the stack.
" doc-word

' 2drop g"
( a b -- )
Drop 2 elements from the top of the stack.
" doc-word

' ( g"
Start a comment. Reads from input stream until ) symbol.
" doc-word

' readc g"
Read char from input stream.
" doc-word

' readc@ g"
Read char from an open fd.
" doc-word

' sys-write g"
Perform write syscall.
" doc-word

' sys-read g"
Perform read syscall.
" doc-word

' sys-write-no g"
Constant used in sys-write.
" doc-word

' sys-read-no g"
Constant used in sys-read.
" doc-word

' loop g"
End of do ... loop block. do loop block reads limit and index from the top of the stack and repeats block of code between do and loop (limit - index) times.
" doc-word

' do g"
Begin of do ... loop block. do loop block reads limit and index from the top of the stack and repeats block of code between do and loop (limit - index) times.
" doc-word

' endfor g"
End of for ... endfor block. Similar to do ... loop block, but will perform at least once if index is more than limit.
" doc-word

' for g"
Begin of for ... endfor block. Similar to do ... loop block, but will perform at least once if index is more than limit.
" doc-word

' until g"
End of repeat ... until block. At the end of each iteration, checks number at the top of the stack? If it is 0, then remove it and start the loop again; if not zero, then remove it and exit the loop.
" doc-word

' repeat g"
Begin of repeat ... until block. At the end of each iteration, checks number at the top of the stack? If it is 0, then remove it and start the loop again; if not zero, then remove it and exit the loop.
" doc-word

' endif g"
Exit if ... then block.
" doc-word

' then g"
End of if ... then block.
" doc-word

' else g"
Used indide if ... then block. Perform the body if the top of the stack is zero.
" doc-word

' if g"
Begin of if ... then block. Perform the body if the top of the stack is non-zero.
" doc-word

' again g"
Performs unconditional branch to the previous begin block.
" doc-word

' begin g"
Begin of begin ... again block.
" doc-word

' allot g"
Accept the number of bytes to allocate in the global data area.
" doc-word

' KB g"
( a -- a * 1024)
Multiply the topmost element of the stack by 1024.
" doc-word

' MB g"
( a -- a * 1048576)
Multiply the topmost element of the stack by 1024 twice.
" doc-word
6 changes: 6 additions & 0 deletions fib.frt → forthress/fib.frt
Original file line number Diff line number Diff line change
Expand Up @@ -26,3 +26,9 @@ _______

then ;

: prime ;

: perfect-sq ;



File renamed without changes.
File renamed without changes.
4 changes: 2 additions & 2 deletions managed-string.frt → forthress/managed-string.frt
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,10 @@ mtype string mend

1 string >meta-is-value !

: string-show ." Str: " QUOTE emit prints QUOTE emit ." \"" ;
: string-show ." Str: " QUOTE prints QUOTE ." \"" ;
' string-show string >meta-printer !


: m" ' h" execute compiling if
' dup , ' string , ' manage ,
else dup string manage then ; IMMEDIATE
else dup string manage then ;
File renamed without changes.
30 changes: 30 additions & 0 deletions forthress/part1/collatz_sequence.frt
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
: is_even 2 % not ;

: inc 1 + ;

: collatz
dup 1 < if drop ." Illegal argument. Number must be positive integer"
else
dup >r
repeat
dup 1 > if
dup is_even if
dup 2 /
else
dup 3 * inc
then
else 1
then
dup 1 = until
then
r>
; IMMEDIATE

: print_collatz
>r
repeat
dup . ." "
r@ =
until
cr r> drop
;
Loading