Skip to content

Commit

Permalink
Add a readme
Browse files Browse the repository at this point in the history
  • Loading branch information
radare committed Apr 11, 2024
1 parent d38d25c commit 4803ea0
Show file tree
Hide file tree
Showing 2 changed files with 39 additions and 0 deletions.
26 changes: 26 additions & 0 deletions zforth/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
# zForth for radare2

zforth is a minimalistic implementation of Forth that aims to be easy
to embed, simple and portable.

This plugin exposes the forth interpreter to be used with radare2.

Enter the zforth repl.

```
$ r2 -c '#!zforth' -
```

## Simple programs

```
1 3 + . 10 0 sys ( 10 0 sys is the same as printing \n char to stdout )
```

## Using the r2cmd syscall

```
s" ?E Hello World " r2cmd tell nl
```


13 changes: 13 additions & 0 deletions zforth/core.zf
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,19 @@
: nl 10 0 sys ; ( new line )
: drop2 drop drop ;

: place over over >r >r char+ swap chars cmove r> r> c! ;

: append ( a1 n2 a2 --)
over over \ duplicate target and count
>r >r \ save them on the return stack
count chars + \ calculate offset target
swap chars move \ now move the source string
r> r> \ get target and count
dup >r \ duplicate target and save one
c@ + \ calculate new count
r> c! \ get address and store
;


( dictionary access. These are shortcuts through the primitive operations are !!, @@ and ,, )

Expand Down

0 comments on commit 4803ea0

Please sign in to comment.