tsoding / porth

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

Supporting Intrinsic `LOAD` and `STORE` 64 bit values #51

Closed zrthxn closed 2 years ago

zrthxn commented 2 years ago

I was interested in contributing to this, so I figured I should ask how you're thinking this should be implemented. Mainly, should the size of the value to be read be an input (like 8, 16, 32, 64 bit) OR should it just have intrinsic support for 64 bit values and then have standard library macros provide support for other sizes?

If its only 64 bit then it can probably just be done with

pop rax
xor rbx, rbx
mov rbx, [rax] ;; Instead of mov bl, [rax]
push rbx
zrthxn commented 2 years ago

So for now I've tested with just 64 bit LOAD and STORE. The operators are rather unimaginative, ,64 and .64

// Test 1000...0001 (64 bit)
mem 1 63 shl 
1 + .64
mem ,64 print

// Test UINT64_MAX
mem 18446744073709551615 .64 
mem ,64 print
rexim commented 2 years ago

@zrthxn this looks good for now. In the future I plan to approach the size of load/store slightly differently, but for now it's alright.

zrthxn commented 2 years ago

@rexim Do you want to use different operators...? Maybe .64 and ,64 aren't the best

rexim commented 2 years ago

@zrthxn nah, .64 and ,64 are alright. I don't really care much about specific names since they always can be changed later while we are in active development phase and nothing is stabilized yet.

zrthxn commented 2 years ago

Okay then #54 is waiting approval :)