Blue v7 Legend
word: compile call jmp  execute call jmp  addr label asmtime runtime 
num: write 00  push 00 
postpone: call jmp call jmp label asmtime runtime 00 00 

x86_64/Linux/cmd/blue/blue.bl

shadow
Blue v7 in Blue v7.

Blue is a single-pass bytecode interpreter for a `colorForth` dialect. It has
no separate macro syntax and any word can be called at assemble time. Inspired
by `fasmg`, when using Blue you start with a clean slate and the output is
completely driven by the input.

Blue has no built in words. Starting from the provided colors you dsl yourself
an artisinal binary. Blue programs typically go from green numbers (machine
code) to higher level words which are used as macros, commands and variables
via assemble-time execution.

WIP: lots of green numbers were used to bootstrap, will be factoring.

Blocks:

  1. x86_64/lib/blue/basis.bo
  2. x86_64/lib/blue/enc.bo
  3. lib/blue/defs.bo
  4. x86_64/lib/blue/defs.bo
  5. x86_64/Linux/lib/defs.bo
  6. x86_64/lib/blue/kernel.bo
  7. x86_64/lib/blue/dst.bo
  8. x86_64/lib/blue/init.bo
  9. x86_64/lib/blue/cf.bo
  10. x86_64/lib/blue/ease.bo
  11. x86_64/Linux/lib/sys.bo
  12. lib/blue/res.bo
  13. x86_64/lib/elf/hdr.bo
  14. lib/blue/magic.bo
  15. x86_64/lib/blue/basis.bo
  16. x86_64/lib/blue/kernel.bo
  17. x86_64/lib/blue/dst.bo
  18. x86_64/lib/blue/rt.bo
  19. x86_64/lib/blue/ops.bo
  20. lib/blue/opa.bo
  21. lib/blue/vars.bo
  22. x86_64/lib/blue/entry.bo
  23. lib/blue/fin.bo
  24. lib/elf/fin.res.bo

x86_64/lib/blue/basis.bo

shadow
`basis` defines the words needed to begin encoding x86_64 machine code. After 
this file we escape the need to hand jit words with only green numbers.

The machine code here is tightly coupled to the registers used by Blue v7.
; C3 C3 >ds 49 0089 08C08349 ; ds>2 08E88349 49 088B ds> 08E88349 49 008B ; 
| ds>2 48 C809 >ds << ds>2 48 E0D3 >ds ,1 ds> AA ;  
[top]

x86_64/lib/blue/enc.bo

rex.b 41 ; rex.w 48 ; rex.wb 49 ; rex.rw 4C ; 
/0 C0 | /r 03 << | 
/0, /0 ,1 /r, /r ,1 /r0, /r /0 ,1 

add 01 /r0, sub 29 /r0, xor 31 /r0, 
mov 89 /r0, mov# B8 | ,1 []mov 89 /r, []mov1 88 /r, 
push 50 | ,1 pop 58 | ,1 
stosq rex.w stosd AB ; stosw AB66 ; stosb AA ; 
syscall 050F ; axchg 90 | ,1 
[top]

lib/blue/defs.bo

dsz 1000 ; dstsz srcsz 2000 ; 
[top]

x86_64/lib/blue/defs.bo

a ds  rax/r8 00 ; b  rcx 01 ; c srce  rdx/r10 02 ; last  rbx 03 ; 
dstb  r12 04 ; ops  r13 05 ; src  rsi 06 ; dst  rdi 07 ; 
[top]

x86_64/Linux/lib/defs.bo

org 00400000 ; stdin 00 ; stdout 01 ; 
sys# a sys1 dst sys2 src sys3 c 
[top]

x86_64/lib/blue/kernel.bo

dup ds> >ds >ds swap ds>2 rex.w b axchg 2>ds >ds rex.w a b mov >ds 

+ ds>2 rex.w a b add >ds - ds>2 rex.w a b sub >ds 
, ds> stosq ; ,4 ds> stosd ; ,2 ds> stosw ; 
! ds>2 rex.w b a []mov ; !4 ds>2 b a []mov ; !1 ds>2 rex.w b a []mov1 ; 
[top]

x86_64/lib/blue/dst.bo

$ rex.w a dst mov >ds $^ rex.rw a dstb mov >ds 
$* $ ~ $^ - 00400000 + $^! rex.wb dstb dst mov ; 
[top]

x86_64/lib/blue/init.bo

ds! rex.b ds mov# ,4 dst! 8B 253C ,4 dstb! rex.wb dstb swap mov 
last! 8B 251C ,4 ops! rex.b ops mov# ,4 
srce! rex.wb srce swap mov 
[top]

x86_64/lib/blue/cf.bo

_1 $ stosb then dup $ swap - 01 - swap !1 
char? 80A8 75 _1 flag? 7410C1F6 _1 pp? 7408C1F6 _1 
srce? rex.rw D639 7C _1 
[top]

x86_64/lib/blue/ease.bo

callop 41 00D554FF ; =0 dup xor 
src>a AD48 ; src1>a a =0 AC ; 
[top]

x86_64/Linux/lib/sys.bo

bye a =0 exit sys1 a mov sys# mov# 0000003C syscall 
read sys1 mov# ,4 8B 2534 ,4 sys3 mov# ,4 sys# =0 syscall 
write sys1 mov# ,4 ds> sys2 a mov ds> sys3 a mov sys# mov# 00000001 syscall 
[top]

lib/blue/res.bo

resmsz dsz dstsz + srcsz + 
[top]

x86_64/lib/elf/hdr.bo

elfhdrs $^! 
	03010102464C457F 	0000000000000000 
	00000001003E0002 entry 	0000000000400078 
	0000000000000040 	0000000000000000 
	0038004000000000 	0000000000400001 
	0000000700000001 	0000000000000000 
	0000000000400000 	0000000000400000 
elfbsz 	0000000000000000 elfmsz 0000000000000000 
	0000000000001000 
[top]

lib/blue/magic.bo

0000000765756C62 
[top]

x86_64/lib/blue/basis.bo

shadow
`basis` defines the words needed to begin encoding x86_64 machine code. After 
this file we escape the need to hand jit words with only green numbers.

The machine code here is tightly coupled to the registers used by Blue v7.
; C3 C3 >ds 49 0089 08C08349 ; ds>2 08E88349 49 088B ds> 08E88349 49 008B ; 
| ds>2 48 C809 >ds << ds>2 48 E0D3 >ds ,1 ds> AA ;  
[top]

x86_64/lib/blue/kernel.bo

dup ds> >ds >ds swap ds>2 rex.w b axchg 2>ds >ds rex.w a b mov >ds 

+ ds>2 rex.w a b add >ds - ds>2 rex.w a b sub >ds 
, ds> stosq ; ,4 ds> stosd ; ,2 ds> stosw ; 
! ds>2 rex.w b a []mov ; !4 ds>2 b a []mov ; !1 ds>2 rex.w b a []mov1 ; 
[top]

x86_64/lib/blue/dst.bo

$ rex.w a dst mov >ds $^ rex.rw a dstb mov >ds 
$* $ ~ $^ - 00400000 + $^! rex.wb dstb dst mov ; 
[top]

x86_64/lib/blue/rt.bo

find last push 
rex.w 83 EB 10 
rex.w 3B 03 
75 F7 
rex.w 8B 43 08 last pop ; 
postpone a push 
B0 B9 stosb 89 C8 stosd 
66 B8 B848 
stosw a pop stosq 
a mov# 0055FF41 
C1 E2 1B 
D009 stosd ; 
[top]

x86_64/lib/blue/ops.bo

gw find a push 
B0 E8 
flag? C0FE then 
stosb a pop 
rex.w a dst sub 
rex.w 83 E8 04 
stosd ; 
bw find F6 C1 10 74 02 FF E0 FF D0 ; 
rw rex.w last a []mov 
rex.w 89 7B 08 
rex.w 83 C3 10 ; 
mw find flag? >ds ~ then 
bn >ds 
gn 80 E1 70 C0 E9 04 FE C1 
rex.w dst a []mov 
rex.w dst b add ; 
[top]

lib/blue/opa.bo

opa gw , bw , rw , mw , gn , bn , 
[top]

lib/blue/vars.bo

_dict 00000000 _dst 00000000 _src 00000000 
[top]

x86_64/lib/blue/entry.bo

$* entry ! 
init srcsz _src stdin read a dup src add srce! 
_dst dst! dst dstb! _dict last! org ds! opa ops! 

interp srce? $ $^ - $^ stdout write bye then 
src1>a char? interp then 
b a mov c a mov 83 E2 07 
A8 08 
src>a 
74 0A postpone interp 
callop interp 
[top]

lib/blue/fin.bo

$* dup _dict !4 dsz + dup _dst !4 dstsz + _src !4 
[top]

lib/elf/fin.res.bo

$ $^ - dup elfbsz ! resmsz + elfmsz ! 
[top]

Blue, v7