Language Design: Basis
Language Design: Basis
Since there seems to be a lot of interest in systems programming in languages other than C or C++ in the OS forum I thought I'd start up a thread for one of the three most common ideas: a Basic derivative (the others, a member of the Lisp family and an object-oriented language similar to SmallTalk, will have separate threads). I have given this putative language the tenative name 'Basis', short for 'BASIC for Systems'.
To start things off, we need to know what people want in the language, and to consider which of those 'wish list items' is practical for the sort of low-level language we want. Does anyone have anything to start with?
Also, is there a specific dialect (Qbasic, VB, PowerBuilder, etc.) that you wish to base the design on, or any compromises between dialects? Keep in mind that only a very minimal subset will be possible, and that there will, of necessity, be some considerable changes and additions; In effect, this will be a new dialect in and of itself. If anyone can find any reference material on ANSI Minimal Basic, it could prove useful as a starting point.
To start things off, we need to know what people want in the language, and to consider which of those 'wish list items' is practical for the sort of low-level language we want. Does anyone have anything to start with?
Also, is there a specific dialect (Qbasic, VB, PowerBuilder, etc.) that you wish to base the design on, or any compromises between dialects? Keep in mind that only a very minimal subset will be possible, and that there will, of necessity, be some considerable changes and additions; In effect, this will be a new dialect in and of itself. If anyone can find any reference material on ANSI Minimal Basic, it could prove useful as a starting point.
Re:Language Design: Basis
Still being of the BASIC-origin camp, I would like to see this . As for suggestions:
I would like to see it start off with QBASIC (or QuickBasic) for starters. Then, some major changes to the usage of the language, but absolutely none to the scripture (the way in which operands interact etc). This would be making it lots easier to use separate files for one project, preferably without headers (just all-compile them). Still, not sure whether leaving out headers is a good thing...
Suggestion for this: INCLUDE "filename.bas", possibly with a user-specified project root, so you could do an INCLUDE "\STANDARD\MATH.BAS" or something similar.
Much easier access to both assembly language and pointer-like things. People scour at pointers because you can make mistakes with them. There's a lot of different ways to do harm with a knife, but without a knife you would lose a lot of elementary functionality. Answer, keep the knife (and, in my opinion, the pointers).
Assembly now requires handcoding it, converting it to machine code (manually or with nasm + hexeditor), putting it in the source, changing it to bytecode again and using some weird hack to jump to it. Make this easier with some form of
structure
And finally, lots (and I mean LOTS, variable offset indication, manually relocating functions, auto-alignment of things, stuff like that) of control over the build process plus the final stuff.
If I may suggest one very plain thing, a number of default files that are delivered along called REALLIB for realmode functions, and a number of functions for protected mode that are present nearly identical in each OS (set page table entry, set GDT entry, clear interrupt line, stuff like that).
HTH, Candy (from his brand-new cable connection! with a blistering downstream of 64kbit/s! )
I would like to see it start off with QBASIC (or QuickBasic) for starters. Then, some major changes to the usage of the language, but absolutely none to the scripture (the way in which operands interact etc). This would be making it lots easier to use separate files for one project, preferably without headers (just all-compile them). Still, not sure whether leaving out headers is a good thing...
Suggestion for this: INCLUDE "filename.bas", possibly with a user-specified project root, so you could do an INCLUDE "\STANDARD\MATH.BAS" or something similar.
Much easier access to both assembly language and pointer-like things. People scour at pointers because you can make mistakes with them. There's a lot of different ways to do harm with a knife, but without a knife you would lose a lot of elementary functionality. Answer, keep the knife (and, in my opinion, the pointers).
Assembly now requires handcoding it, converting it to machine code (manually or with nasm + hexeditor), putting it in the source, changing it to bytecode again and using some weird hack to jump to it. Make this easier with some form of
Code: Select all
ASM eax=variable1, ebx=var2, edi=count
...
END ASM var3=edx, var4=edi
And finally, lots (and I mean LOTS, variable offset indication, manually relocating functions, auto-alignment of things, stuff like that) of control over the build process plus the final stuff.
If I may suggest one very plain thing, a number of default files that are delivered along called REALLIB for realmode functions, and a number of functions for protected mode that are present nearly identical in each OS (set page table entry, set GDT entry, clear interrupt line, stuff like that).
HTH, Candy (from his brand-new cable connection! with a blistering downstream of 64kbit/s! )
Re:Language Design: Basis
Out of those three I prefer qbasic the most. (I'm not ashamed that I know basic ;D)
Re:Language Design: Basis
Can we have something a bit clever than just including text line C does? Something like Pascal units or .Net assemblies, please? That is, you compile MATH.BAS into some clever format which describes not only the functions and variables it contains, but also the constants, types, etc.Candy wrote: Suggestion for this: INCLUDE "filename.bas", possibly with a user-specified project root, so you could do an INCLUDE "\STANDARD\MATH.BAS" or something similar.
Remember, this language is like BASIC . If you want to be able to shoot yourself in the foot, program in C. If you want to be able to write safe code in a less powerful language, program in this language. Adding an inline assembler is a good idea, but I think pointers should be kept out of the language.Much easier access to both assembly language and pointer-like things. People scour at pointers because you can make mistakes with them.
Although an equivalent of C++'s references would be handy. You could say:
Code: Select all
DIM i AS INTEGER
DIM REFERENCE j AS INTEGER
SET j = i
j = 42
PRINT i ' prints 42
Congratulations!HTH, Candy (from his brand-new cable connection! with a blistering downstream of 64kbit/s! )
Re:Language Design: Basis
That's ok with me... but, if we're going to make some more intelligent include, why not make it some sort of import? Something similar to pointing it to some source file to import all function definitions, constants etc. that are publicly visible?Tim Robinson wrote: Can we have something a bit clever than just including text line C does? Something like Pascal units or .Net assemblies, please? That is, you compile MATH.BAS into some clever format which describes not only the functions and variables it contains, but also the constants, types, etc.
How would I return a pointer with malloc or new or anything of memory management stuff if I can't make a pointer?Remember, this language is like BASIC . If you want to be able to shoot yourself in the foot, program in C. If you want to be able to write safe code in a less powerful language, program in this language. Adding an inline assembler is a good idea, but I think pointers should be kept out of the language.
That might be an idea... Still, I would like pointers.Although an equivalent of C++'s references would be handy. You could say:This might be similar to VB's object types.Code: Select all
DIM i AS INTEGER DIM REFERENCE j AS INTEGER SET j = i j = 42 PRINT i ' prints 42
For setting static references, something like
Code: Select all
SET ADDRESS OF j = i
Re:Language Design: Basis
BASIC has DIM to allocate memory. IIRC Visual Basic 6 lets you create new objects, something like:Candy wrote:How would I return a pointer with malloc or new or anything of memory management stuff if I can't make a pointer?
Code: Select all
Set newForm = New Form1
Code: Select all
SET i = NEW INTEGER ' like VB6
' or
SET i = DIM AS INTEGER ' allocate a new integer
SET i = DIM(100) AS INTEGER ' allocate an array of integers
OK, but is that different from my syntax?For setting static references, something likethat might do the trick?Code: Select all
SET ADDRESS OF j = i
Re:Language Design: Basis
DIM is a function based on the OS. Do away with DIM, or make it redefinable (having my obvious preference).Tim Robinson wrote: BASIC has DIM to allocate memory. IIRC Visual Basic 6 lets you create new objects, something like:We could have a memory-allocating function return a reference:Code: Select all
Set newForm = New Form1
Code: Select all
SET i = NEW INTEGER ' like VB6 ' or SET i = DIM AS INTEGER ' allocate a new integer SET i = DIM(100) AS INTEGER ' allocate an array of integers
Some sort of UNDIM would also be nice, similar to freeing memory.
And, if I may, change the syntax of dim to a function called DIM returning the new place for some address or something.
It does not add another set of variables to the language. That alone would make it worth it to me, it does away with all the pointer, reference, dereference **** and make it as clear as setting the location of a variable to something else. That might also solve the problem with making the memory manager.OK, but is that different from my syntax?For setting static references, something likethat might do the trick?Code: Select all
SET ADDRESS OF j = i
Re:Language Design: Basis
OK. Should you be able to write the implementation of DIM without resorting to assembly or C?Candy wrote: DIM is a function based on the OS. Do away with DIM, or make it redefinable (having my obvious preference).
Some sort of UNDIM would also be nice, similar to freeing memory.
And, if I may, change the syntax of dim to a function called DIM returning the new place for some address or something.
I think we're talking about the same thing.It does not add another set of variables to the language. That alone would make it worth it to me, it does away with all the pointer, reference, dereference **** and make it as clear as setting the location of a variable to something else. That might also solve the problem with making the memory manager.
I proposed a new SET statement, separate from LET:
From what I understand from your post, SET ADDRESS OF would do the same thing as SET in this listing. Note I shortened REFERENCE to REF this time -- and I prefer SET on its own to SET ADDRESS OF -- because it's more in keeping with the rest of the syntax. Long words are nice, but that's more like SQL than BASIC. ([me=Tim Robinson]avoids temptation to start a new thread describing an SQL clone )[/me]DIM i as INTEGER
DIM REF j AS INTEGER
LET i = 1 ' assign value 1 to i
LET j = 2 ' crash! j doesn't refer to anything
SET j = i ' make j refer to i
LET j = 3 ' assign value 3 to variable referred to by j, i.e. i
Re:Language Design: Basis
Add elseif's.
I prefer this:
instead of this:
I think elseif's help keep the code alot cleaner as compared to stuffing tons of if's into the else's.
I prefer this:
Code: Select all
if (code) {
}
elseif (code2) {
}
else {
}
Code: Select all
if (code) {
}
else {
if (code2) {
}
else {
}
}
Re:Language Design: Basis
Um, if you add a space in the middle of the elseif in your first listing, you'd get valid C or C++ code. No need for all the { }.
Re:Language Design: Basis
Don't see why not? You can control a list from within basic, just like within C. You should be able to make it just as simple.Tim Robinson wrote:OK. Should you be able to write the implementation of DIM without resorting to assembly or C?Candy wrote: DIM is a function based on the OS. Do away with DIM, or make it redefinable (having my obvious preference).
Some sort of UNDIM would also be nice, similar to freeing memory.
And, if I may, change the syntax of dim to a function called DIM returning the new place for some address or something.
Didn't notice the S instead of the L Sorry bout that.I think we're talking about the same thing.It does not add another set of variables to the language. That alone would make it worth it to me, it does away with all the pointer, reference, dereference **** and make it as clear as setting the location of a variable to something else. That might also solve the problem with making the memory manager.
I proposed a new SET statement, separate from LET:DIM i as INTEGER
DIM REF j AS INTEGER
LET i = 1 ' assign value 1 to i
LET j = 2 ' crash! j doesn't refer to anything
SET j = i ' make j refer to i
LET j = 3 ' assign value 3 to variable referred to by j, i.e. i
ok, but you miss the point. You want to explicitly use references. Isn't it an idea to not make them explicit but implicit, like
Code: Select all
DIM a, b AS INTEGER
LET a = 1
SET b = a
LET b = 2
' a = 2 too
Re:Language Design: Basis
I'm sorry, maybe I'm just stupid but what exactly are you trying to do? Create a low-level language with basic-like syntax?
Re:Language Design: Basis
That was only meant as an example, not how the syntax should look.Tim Robinson wrote: Um, if you add a space in the middle of the elseif in your first listing, you'd get valid C or C++ code. No need for all the { }.
Re:Language Design: Basis
Mmmm... evil, I like it . So you add the ability to say, "when I ask for this variable, give me this one instead". Then dynamic allocation means assigning making a variable point to some block of memory.Candy wrote:in order to let the basis-users not mess with reference types? Still... wondering how you'd do a memory manager even with this... You would have to have a variable (or pointer, whatever you like most) to the space, and return that as the place for the info. I would still opt for the pointers...
Re the implementation of DIM. You'd need some advanced l33t feature to let you take a pointer from the OS and turn it into a reference. This would let you treat a block returned from the OS's virtual memory allocation function as an array of bytes.
Re:Language Design: Basis
Exactly. One of the FAQs on the OS-Development forum is whether you can use some Basic or another for kernel programming. This is an attempt to find an answer to it aside from simply, 'no'.kyle wrote: I'm sorry, maybe I'm just stupid but what exactly are you trying to do? Create a low-level language with basic-like syntax?