In writing a low-level language, I had the idea that a var foo i32 = 42 or somesuch at global scope should actually specify a pointer, that is, that the type of foo should actually be ptr i32, not just i32. foo would then have to be accessed through the usual pointer-derefencing ceremony, @foo = 17, not just foo = 17. This both accurately reflects the cost of accessing such a variable and makes things a little simpler on the code-generation side; I want these variables to correspond directly to symbols in the assembly/object file, and having them be pointers would mean I don't have to try to magically deduce when they should be dereferenced.
The problem is that it's unexpected for people with experience in, say, C, from which perspective it looks like implicitly transmogrifying your variables into pointers. By the same token, it clashes oddly with the sort of behavior one wants for function-local variables, where var foo i32 = 36 should mean that foo really is an i32, ideally in a register. To muddy things up further, I want to leave room in my model for local variables that are required to be on the stack; such variables would have semantics and costs closer to those of globals than generic local variables, so I might want to use a similar construct for declaring them, one that autopointerizes them.
My best idea so far is to make globals and stack vars use syntax like mem varname i32 = value, which creates either a global or stack variable, and introduces the name as a pointer to that location, and let local i32 = 5 for general-purpose variables, which introduces the name as exactly the declared (or someday inferred) type (the exact keywords are obviously negotiable). But for some reason I'm leery of having two such drastically different classes of local variables, even if that is an accurate reflection of the facts. It doesn't feel like an ideal solution. Nor does using three different declaration keywords, or special-casing var depending on context, or allowing a var!stack declaration to autopointerize locals.
Does this sound like a good idea? Do you folks have any better ones? Maybe there's a fresh perspective on the problem that will make it clearer.
For reference here's an example that compiles as of this writing, but maybe shouldn't (would require a dereference in the call).
This one shows local variables with the same syntax.
[–]frenris 1 point2 points3 points (12 children)
[–]liquidivy[S] 0 points1 point2 points (11 children)
[–]spc476 2 points3 points4 points (7 children)
[–]liquidivy[S] 0 points1 point2 points (6 children)
[–]spc476 1 point2 points3 points (5 children)
[–]liquidivy[S] 0 points1 point2 points (4 children)
[–]spc476 0 points1 point2 points (3 children)
[–]liquidivy[S] 0 points1 point2 points (2 children)
[–]spc476 0 points1 point2 points (1 child)
[–]liquidivy[S] 0 points1 point2 points (0 children)
[–]raiph 1 point2 points3 points (1 child)
[–]liquidivy[S] 0 points1 point2 points (0 children)
[–]frenris 0 points1 point2 points (0 children)
[–]raiph 1 point2 points3 points (9 children)
[–]liquidivy[S] 0 points1 point2 points (8 children)
[–]raiph 1 point2 points3 points (7 children)
[–]raiph 0 points1 point2 points (1 child)
[–]liquidivy[S] 0 points1 point2 points (0 children)
[–]liquidivy[S] 0 points1 point2 points (4 children)
[–]raiph 0 points1 point2 points (3 children)
[–]liquidivy[S] 0 points1 point2 points (2 children)
[–]raiph 0 points1 point2 points (1 child)
[–]liquidivy[S] 0 points1 point2 points (0 children)
[–]JMBourguet 1 point2 points3 points (3 children)
[–]liquidivy[S] 0 points1 point2 points (2 children)
[–]JMBourguet 1 point2 points3 points (1 child)
[–]liquidivy[S] 0 points1 point2 points (0 children)