Closed adam-mcdaniel closed 4 years ago
The only thing left to decide is whether or not the standard library should be included by default. What do you think, @kevinramharak? Right now, this PR does not include it by default. See the examples for how it works.
I would say it depends on the target audience. Some languages include the stdlib by default because of convenience and because it is usually expected by novice programmers. I like the idea of having both flags and stdlib being optional. It gives more control on what the resulting code is going to be. The convenience part is easily fixed with good error reporting. For example if print
is a stdlib function and a program calls it without stdlib being included the error reporter can be smart enough to ask if they meant to include the stdlib.
Hmmm. Adding error messages for std functions would be a pretty difficult task, depending on the level of obscurity of the function. Maybe we could add have you included the standard library?
error messages for common functions like putstrln
, but not for EVERY function like fmod
or sqrt
. I feel like that's an acceptable compromise: new users get the error messages for the functions that they will surely first be exposed to, and more experienced users automatically know why something like std::DateTime
is not defined, for example.
I think its fairly easy or am i missing something? If there is a spec for stdlib all those function names should be known right, it might not be the most elegant way but if the called function does not exist and if its name is present in a static array of strings representing those names then a helpful hint can be shown. It doesn't have to be implemented like this and theres no hurry. I just think having good error reporting is a good compiler feature.
It would be easy in the sense that it would be simple, but not in the sense that it would be a small amount of code. It would involve checking against an array of identifiers constituting all the STD symbols, like you said. It definitely could be done, but I think that a comprehensive standard library spec should be written before we consider adding error reporting about the standard library this way.
Oh definitly. I was just trying to provide an alternative to the con of having the stdlib not included by default
This PR implements the
no_std
andstd
flags, which explicitly dismiss the standard library and explicitly require the standard library, respectively. By default, the standard library is not required, just like C. When there are conflicting requirements (when thestd
andno_std
flags are both present) a compiler error is emitted.Additionally, this PR changes the structure of the
target
directory in the crate, and slightly changes theTarget
trait itself. TheTarget
trait previously hadprelude
andpostlude
methods; these methods have been renamed tocore_prelude
andcore_postlude
. These methods ONLY emit code implementing the 14 core VM instructions. Thats it.A new
Target
method, thestd
method, returns the code implementing standard library foreign functions, such asprn
,prc
,prs
, andgetch
. It is likely that as the standard library grows, these will adopt different names.When the standard library is required, the
std.ok
andcore.ok
files are pasted at the end of the user's code. If the standard library is not required, then justcore.ok
is pasted at the end of the user's code.