Charles Pegge
04-03-2011, 08:10
Proposed New OxygenSyntax
OOP is renowned for being clunky & long-winded. But this compact syntax will I hope make objects really easy to build:
Note the single line type definitions and the constructor prototype. Simple methods can also be done on a single line. :)
Oxygen source code
type vector single x,y,z
type color single r,g,b,a
class body
vector position,size,orientation,velocity,spin
color ambient,diffuse,specular
single density
method mass() as single {return density * size.x * size.y * size.z}
method constructor ( single* x,y,z) { size=>x,y,z : density=1 }
method destructor () {}
end class
new body rock 1,2,3
'putfile "t.txt", recordof rock
print "mass of rock is " rock.mass
del rock
Internally the structure is flattened out snd the compiler sees it like this:
$$ 383 383 383 383 383 384 384 384 $$
mass 0 4 9 9 A , single
constructor 4 4 9 9 A #single#single#single@a1a1a1 sys
destructor 8 4 9 9 A , sys
/
position 0 12 1 9 A , vector
position.x 0 4 1 9 A , single
position.y 4 4 1 9 A , single
position.z 8 4 1 9 A , single
size 12 12 1 9 A , vector
size.x 12 4 1 9 A , single
size.y 16 4 1 9 A , single
size.z 20 4 1 9 A , single
orientation 24 12 1 9 A , vector
orientation.x 24 4 1 9 A , single
orientation.y 28 4 1 9 A , single
orientation.z 32 4 1 9 A , single
velocity 36 12 1 9 A , vector
velocity.x 36 4 1 9 A , single
velocity.y 40 4 1 9 A , single
velocity.z 44 4 1 9 A , single
spin 48 12 1 9 A , vector
spin.x 48 4 1 9 A , single
spin.y 52 4 1 9 A , single
spin.z 56 4 1 9 A , single
ambient 60 16 1 9 A , color
ambient.r 60 4 1 9 A , single
ambient.g 64 4 1 9 A , single
ambient.b 68 4 1 9 A , single
ambient.a 72 4 1 9 A , single
diffuse 76 16 1 9 A , color
diffuse.r 76 4 1 9 A , single
diffuse.g 80 4 1 9 A , single
diffuse.b 84 4 1 9 A , single
diffuse.a 88 4 1 9 A , single
specular 92 16 1 9 A , color
specular.r 92 4 1 9 A , single
specular.g 96 4 1 9 A , single
specular.b 100 4 1 9 A , single
specular.a 104 4 1 9 A , single
density 108 4 1 9 A , single
Charles
OOP is renowned for being clunky & long-winded. But this compact syntax will I hope make objects really easy to build:
Note the single line type definitions and the constructor prototype. Simple methods can also be done on a single line. :)
Oxygen source code
type vector single x,y,z
type color single r,g,b,a
class body
vector position,size,orientation,velocity,spin
color ambient,diffuse,specular
single density
method mass() as single {return density * size.x * size.y * size.z}
method constructor ( single* x,y,z) { size=>x,y,z : density=1 }
method destructor () {}
end class
new body rock 1,2,3
'putfile "t.txt", recordof rock
print "mass of rock is " rock.mass
del rock
Internally the structure is flattened out snd the compiler sees it like this:
$$ 383 383 383 383 383 384 384 384 $$
mass 0 4 9 9 A , single
constructor 4 4 9 9 A #single#single#single@a1a1a1 sys
destructor 8 4 9 9 A , sys
/
position 0 12 1 9 A , vector
position.x 0 4 1 9 A , single
position.y 4 4 1 9 A , single
position.z 8 4 1 9 A , single
size 12 12 1 9 A , vector
size.x 12 4 1 9 A , single
size.y 16 4 1 9 A , single
size.z 20 4 1 9 A , single
orientation 24 12 1 9 A , vector
orientation.x 24 4 1 9 A , single
orientation.y 28 4 1 9 A , single
orientation.z 32 4 1 9 A , single
velocity 36 12 1 9 A , vector
velocity.x 36 4 1 9 A , single
velocity.y 40 4 1 9 A , single
velocity.z 44 4 1 9 A , single
spin 48 12 1 9 A , vector
spin.x 48 4 1 9 A , single
spin.y 52 4 1 9 A , single
spin.z 56 4 1 9 A , single
ambient 60 16 1 9 A , color
ambient.r 60 4 1 9 A , single
ambient.g 64 4 1 9 A , single
ambient.b 68 4 1 9 A , single
ambient.a 72 4 1 9 A , single
diffuse 76 16 1 9 A , color
diffuse.r 76 4 1 9 A , single
diffuse.g 80 4 1 9 A , single
diffuse.b 84 4 1 9 A , single
diffuse.a 88 4 1 9 A , single
specular 92 16 1 9 A , color
specular.r 92 4 1 9 A , single
specular.g 96 4 1 9 A , single
specular.b 100 4 1 9 A , single
specular.a 104 4 1 9 A , single
density 108 4 1 9 A , single
Charles