HGL - a graphics language

Pages: 12
Velnias75 (27)
I refactored the assignment operator. The first implementation was everything than clever, saving in the compiled binary a reference and a serial id of the type only. Next the binary parser had to collect the next type from the input stream and assign it to the variable.

The new assignment operator can handle arbitrary complex expressions including references. The compiler parses and evaluates out all scalar types line floats, ints and vectors and now leaves a prepared RPN stack for evaluation on runtime in the interpreter.

So, this stack is now more than just the object the old implementation hold. Therefore it doesn't need this references anymore, because the compiler takes care in the stream the full RPN stack or even only the single scalar object are next to the variable to assign, the interpreter just needs to know, that the next tokens are to assign.

Short: the reference and the serial id of the "to assign" type can get removed out of the compiled binary.
I can let them in too and ignore them, but that way the binary will blow more and more, and this I want to avaoid before version 1.0.
Velnias75 (27)
Just a small update to keep the thread alive.

I just finished with the assignment operator. Now following is possible for the 4 basic arithmetics and for points, vectors and float values:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
// ...
procedures {
	proc moveAPolygonLineED {
		[ offset ] // expected parameter(s); only one here
		{} // constructor (empty, but required)

		// add and assign 'offset' parameter to @aPolygon.d.p2
		@aPolygon.d.p2 = #aPolygon.d.p2 + #offset;
	}
}
// ...
main {
	// call the procedure defined above with a vector, to move y-coord down
	@moveAPolygonLineED((0, 90 + 10));
	render(); // finally render the picture
}
//... 


The rest is almost the same like in the example I posted before. I just changed aPolygon.d.p2 to -54.

The next release will be after I implemented expressions like that:
@aPolygon.d.p2 = (#aPolygon.d.p2 + (1 + 2 * 10) + -sin(#offset)) * sin(7+83) + (#aPolygon.d.p1);
as well as implementing all operators for all object types.

EDIT: while the above code works very well, there is a problem left with operator precedence, i.e. @aPolygon.d.p2 = #aPolygon.d.p2 + #offset * 5; causes problems. I get the right RPN order from the compiler, but I have an error evaluating it in the interpreter :-/
Last edited on
Registered users can post here. Sign in or register to post.
Pages: 12