Skip to content
This repository was archived by the owner on Nov 11, 2021. It is now read-only.
Open
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
19 changes: 17 additions & 2 deletions porth.porth
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,21 @@ macro sim-stack sim-stack-count 8 + end
macro ops-count sim-stack SIM_STACK_CAP 8 * + end
macro ops ops-count 8 + end

//Pushes &base[index] on top of the stack
macro &[] // index base element_size -- element_address
rot * +
end

//Pushes Op &base[index] on top of the stack
macro &[Op] // index base -- element_address
sizeof(Op) &[]
end

//Pushes Op &ops[index] on top of the stack
macro &ops[] // index -- element_address
ops &[Op]
end

macro sim-stack-push // u64 --
if sim-stack-count @64 SIM_STACK_CAP >= do
here eputs ": ERROR: data stack overflow in simulation mode" eputs 1 exit
Expand Down Expand Up @@ -57,7 +72,7 @@ macro putd // u64 --
end

macro push-op // type operand --
ops-count @64 sizeof(Op) * ops +
ops-count @64 &ops[]
dup Op.operand rot swap !64
Op.type !64
ops-count inc64
Expand All @@ -66,7 +81,7 @@ end
macro dump-ops // --
0 while dup ops-count @64 < do
// ptr ptr
dup sizeof(Op) * ops +
dup &ops[]
"Type: " puts dup Op.type @64 print
"Operand: " puts Op.operand @64 print
"----------\n" puts
Expand Down