Skip to content

Instantly share code, notes, and snippets.

View crcx's full-sized avatar

Charles Childers crcx

View GitHub Profile
@crcx
crcx / Words.txt
Last active April 25, 2017 14:50
Retro, as of 2017.04.25
This is a reference to the words and their
usage. It includes stack comments, a brief
description, and some examples.
-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-
-
nm-o
@crcx
crcx / see.forth
Created April 23, 2017 04:26
see.forth
# See: a Better Disassembler
````
{{
````
The decompiler is an important tool in the process of debugging and gaining insight into code.
Output will be structured like this:
6.30
clear lf onscreen-lines ' copy$ place count " ?negate ?dup ;code bytes c, :code codeX here pop push stack: array pick chars char+ cells cell+ align allot pad char-size cell-size -- ++ +! on off \ (
7.6
.version version# $, ." " st0 | zt-free zt-make words >pad clear del tab space cr << 0; fill alias execute ' 2swap 2over cells cell+ align allot pad /mod octal binary decimal hex 2drop 2dup over tuck -rot rot constant variable, variable here mod / - negate * + c! c@ ! @ not >> xor or and nip dup drop swap base h0 last cmove reset parse type . macro forth : compile ] (create) create 3, 2, 1, , eval >number find mfind syscall bye key emit
8.2.5
edit v new include load w r blocks use \f \ ia i s e el eb x d n p (line) block (block) offset #blks blk home clear ? version .s words zt | ( exit ui octal binary decimal hex u. . cr space ." { s" $, " >pad pad place move fill ;loc loc: list devector is alias :: allot -! +! constant variable: variable create literal, create: execute 0; later 2dup tuck over -rot rot
@crcx
crcx / mime.types.forth
Created April 21, 2017 12:22
Mime Types
:get-mime-type (s-s)
[ $. s:index-of ] sip +
'.ez [ 'application/andrew-inset ] s:case
'.anx [ 'application/annodex ] s:case
'.atomcat [ 'application/atomcat+xml ] s:case
'.atomsrv [ 'application/atomserv+xml ] s:case
'.atom [ 'application/atom+xml ] s:case
'.lin [ 'application/bbolin ] s:case
'.cu [ 'application/cu-seeme ] s:case
'.davmount [ 'application/davmount+xml ] s:case
RETRO: An Overview
-----------------------------------------------------
RETRO is a Forth, but it's far from traditional takes
on the language. This document attempts to describe
the basics of the language, contrasting with standard
Forth.
-----------------------------------------------------
General Structure
@crcx
crcx / s_with_format.forth
Last active April 17, 2017 17:09
constructing a string from parts on the stack
````
{{
:char (c-)
$n [ ASCII:LF buffer:add ] case
$t [ ASCII:HT buffer:add ] case
buffer:add ;
:string (a-a)
repeat fetch-next 0; buffer:add again ;
@crcx
crcx / as.forth
Created April 17, 2017 15:31
runtime assembler for retro12
# AS
Assembler for Nga
This is an assembler for the Nga virtual machine that Retro runs on. It's intended to make it possible to develop tighter code than the standard Retro compiler can generate.
Nga allows for packing up to four instructions per cell. This is limited by a single aspect, which is that instructions that modify the IP prevent later instructions from executing. So you can't pack anything after a jump, call, or conditional return.
As a reference, here's the Nga instruction set:
@crcx
crcx / bad.forth
Created April 15, 2017 15:44
Byte Addressing in Retro
{{
:mask #255 and ;
:next #8 shift ;
:unpack (n-dcba)
dup mask swap next
dup mask swap next
dup mask swap next
'abcd 'dcba reorder ;
---reveal---
:bad:fetch (a-n)
crc@debian:~/scratch$ gforth p
in file included from *OS command line*:-1
p:3: Undefined word
: >>>anonymous-pointer<<< here cell allot ;
Backtrace:
$7F6883F90A68 throw
$7F6883FA6C68 no.extensions
$7F6883F943A0 compiler-notfound1
crc@debian:~/scratch$
{{
'Needle d:create
#501 allot
:in-namespace? (s-sf)
d:name #0 &Needle s:length s:substr &Needle s:eq? ;
:extract-name (s-s)
d:name &Needle s:length + ;
---reveal---
:words<in-namespace> (s-)
&Needle over s:length n:inc copy