I have been interested in programming, and computers since I was about 12. At first it was batch programming. Then I found a better language contained inside MS Word for Windows, called "Visual Basic For Applications"(VBA). Sure it was fairly simple, but it was a better language than batch programming. Soon after I learned that I found out about a programming language called Perl. I realized quickly that it could easily do almost everything that VBA could do, and there was something that VBA could not easily do that Perl could easily do, Regular Expression.
Now I realize that some people don't like the way that Perl5 looks, but I think most of that will all but disappear when Perl6 gets fully implemented.
I also liked digging into the heart of systems, be it hardware or software, so I wanted to learn more about how real machine-coded programs were developed. Well since C/C++ is the language that is used most for this, I started to learn about how to program in that language. It didn't take me long to realize just how complicated a language it had become since it was created, near the end of the 60's (I think). I wasn't even born until 1982.
I don't remember how I found out about "D", but it certainly seems to be a step in the right direction when compared to C/C++. Since I had learned Perl before I learned "D", I kept trying to do programming idioms that I have become familiar to doing in Perl.
When I read about Perl6, and how it was going to be designed. I decided that I wanted to try creating a programming language that was low level like C, but had some of the useful features from Perl and "D".
I hope that this turns out to be useful enough, that it could be used for Operating System programming, as well as be a fairly easy programming language to learn.
Tuesday, January 17, 2006
data revisited
Ok I admit it I don't know an easy way to specify a data format easily. So for now at least forget all about "data".
Plus it's possible it could be done through a macro (Perl6 macro).
Plus it's possible it could be done through a macro (Perl6 macro).
Sunday, January 01, 2006
"data" Structures
Please note the following is just a starting point of the design process.
alias D_Static_Array(char,3) to char[3];
alias D_Static_Array(char,3,4) to char[3][4];
# this will catch all char[3] char[3][4]
# brings out the aliases from inside of the data template
import D_Static_Array( 'char', / char [ \[ $d := (\d+) \] ]+ / );
# this will catch all static array types
import D_Static_Array( / [ \[ (\d+) \] ]+ / );
# please note that increasing the value of .length at runtime
# won't allocate more memory it will just make the program think it
# has more data to work with. So it wouldn't be a good idea to do
# that in most cases.
data D_Static_Array(type $ident,uint $size = 0){
}
data D_Static_Array($ident,@sizes){
}
this is what it would do
# array of four arrays of 3 char each.
D_Static_Array(char,3,4)
{
}
alias D_Static_Array(char,3) to char[3];
alias D_Static_Array(char,3,4) to char[3][4];
# this will catch all char[3] char[3][4]
# brings out the aliases from inside of the data template
import D_Static_Array( 'char', / char [ \[ $d := (\d+) \] ]+ / );
# this will catch all static array types
import D_Static_Array( /
# please note that increasing the value of .length at runtime
# won't allocate more memory it will just make the program think it
# has more data to work with. So it wouldn't be a good idea to do
# that in most cases.
data D_Static_Array(type $ident,uint $size = 0){
# uint{0} refers to a uint starting at byte offset 0
# readonly means that only this and anything
# that subclasses this can change it (could also be spelled "r").
readonly uint{0} .length = $size;
# you could also spell ".length" as "->length" if you prefer Perl5
# that would mean you would have to rename all instances of ".length".
# the reason you can do this is because all you need is a word boundary
# to be created between the "data" and ".length"
# ".data" will grow and shrink depending on what
# the value of ".length" is at the time you ask for it
# because of the bind ":=" in the definition.
# This also won't allow you to change the length of ".data"
# outside of this class because ".data.length" is bound to ".length".
rw $ident[ _ := .length ]{.length.sizeof} .data;
# this is for retrieving the value at $index
INDEX(uint $index){
uint $pos = $index * $ident.sizeof + length.sizeof;
return $ident[$pos];
}
# this is for determining out of bounds errors
SIZE{
# the size grows and shrink depending on
return (.length + .length.sizeof) * $ident.sizeof;
# or
return (uint{0} + uint.sizeof) * $ident.sizeof;
}
}
data D_Static_Array($ident,@sizes){
# note this "data" will keep another variable around
# to know how long the array ".length" is.
readonly uint[@sizes.length]{0} .length = @sizes;
# note the bind goes recursively through mult because
# it is a keyword.
uint .data_size := mult( @{.length} );
# ".data_size" needs to be bound because the variable it depends
# on can be changed, and there should be a way to propogate it on
# to ".data", it is not enforced, but highly recommended.
readwrite $ident[ _ := .data_size ]{ _ := .length.sizeof } .data;
INDEX( ){
}
SIZE{
return .length.sizeof + .data_size;
}
}
this is what it would do
# array of four arrays of 3 char each.
D_Static_Array(char,3,4)
{
.length = [4,3];
.data = [char,char,char, char,char,char, char,char,char, char,char,char];
}
Subscribe to:
Posts (Atom)