tsoding / porth

It's like Forth but in Python
629 stars 50 forks source link

Macro naming convension for porth.porth #130

Open mjdr opened 2 years ago

mjdr commented 2 years ago

Right now macros in porth.porth refer to addresses of corresponding objects And they de referenced as needed

Proposal:

Template for names of addresses:

&{name}

So, macros that gets value of single cell object can be implemented like this:

macro {name}
  &{name} @64
end

And for writing single cell values, like this (not sure about syntax):

macro ={name}
  &{name} !64
end

With #129 this code

macro push-op // type operand -- 
  ops-count @64 sizeof(Op) * ops +
  dup Op.operand rot swap !64
  Op.type !64
  ops-count inc64
end

transforms into this

macro push-op // type operand -- 
  ops-count &ops[]
  dup Op.operand rot swap !64
  Op.type !64
  &ops-count inc64
end

A lot more readable