dschmenk / PLASMA

Proto Language AsSeMbler for All (formerly Apple)
MIT License
189 stars 26 forks source link

PLASMA compiler: constants can be defined in a function but have global scope #59

Closed ZornsLemma closed 1 year ago

ZornsLemma commented 4 years ago

I'm not sure if this is a bug or not but it seems a little counter-intuitive so I thought I'd mention it.

If I modify test.pla as follows:

diff --git a/src/samplesrc/test.pla b/src/samplesrc/test.pla
index 73a29eb..0408e9e 100755
--- a/src/samplesrc/test.pla
+++ b/src/samplesrc/test.pla
@@ -36,6 +36,7 @@ word ptr
 // Define functions.
 //
 def tens(start)#0
+  const range = 99
   word i, pptr

   i = start

and compile it, I get an error in a later function which uses range as an argument name:

$ ./plasm -AMOW  < samplesrc/test.pla > samplesrc/test.a

<stdin>   60: def nums(range)#0
                       ^
Error: const/local name conflict

I found this by trying to use const to define a local constant inside a function and it broke compilation of another function. I'd suggest const should either be disallowed inside a function, or the constants defined in this way should be local to that function.

PS I hope raising these issues doesn't seem like I'm complaining, I'm updating the Acorn port to ALPHA1 and doing some general tweaking. ALPHA1 generally looks great!

dschmenk commented 4 years ago

Ha! No complaining! Thanks for bringing these issues up. But I'll admit that error-checking is my least favorite code to write ;-)

dschmenk commented 1 year ago

I've taken the easy way out and made local constant declarations an error.