geartrain \
glinfo \
gloss \
+ glslnoise.c \
gltestperf \
glutfx \
isosurf \
* simple per-pixel lighting.\r
*\r
* Michal Krol\r
- * 14 February 2006
+ * 17 February 2006
*\r
* Based on the original demo by:
* Brian Paul
* 17 April 2003
- */
+ */\r
+\r
+#ifdef WIN32\r
+#include <windows.h>\r
+#endif
#include <stdio.h>
-#include <stdlib.h>
+#include <stdlib.h>\r
+#include <GL/gl.h>
#include <GL/glut.h>\r
+#include <GL/glext.h>\r
+\r
+#ifdef WIN32\r
+#define GETPROCADDRESS wglGetProcAddress\r
+#else\r
+#define GETPROCADDRESS glutGetProcAddress\r
+#endif\r
static GLfloat diffuse[4] = { 0.5f, 0.5f, 1.0f, 1.0f };
static GLfloat specular[4] = { 0.8f, 0.8f, 0.8f, 1.0f };
\r
/* XXX source from uniform diffuse */\r
" vec4 diffuse;\n"\r
- " diffuse.xy = vec2 (0.5);\n"\r
- " diffuse.zw = vec2 (1.0);\n"\r
+ " diffuse = vec4 (0.5, 0.5, 1.0, 1.0);\n"\r
\r
/* XXX source from uniform specular */\r
" vec4 specular;\n"\r
- " specular.xyz = vec3 (0.8);\n"\r
- " specular.w = 1.0;\n"\r
+ " specular = vec4 (0.8, 0.8, 0.8, 1.0);\n"\r
\r
- " // Compute normalized light direction\n"\r
- " vec4 lightDir;\n"\r
- " lightDir = lightPos / length (lightPos);\n"\r
- " // Compute normalized normal\n"\r
- " vec4 normal;\n"\r
- " normal = gl_TexCoord[0] / length (gl_TexCoord[0]);\n"\r
" // Compute dot product of light direction and normal vector\n"\r
" float dotProd;\n"\r
- " dotProd = clamp (dot (lightDir.xyz, normal.xyz), 0.0, 1.0);\n"\r
+ " dotProd = clamp (dot (normalize (lightPos).xyz, normalize (gl_TexCoord[0]).xyz), 0.0, 1.0);\n"\r
" // Compute diffuse and specular contributions\n"\r
" gl_FragColor = diffuse * dotProd + specular * pow (dotProd, 20.0);\n"\r
"}\n"
static const char *vertShaderText =
"void main () {\n"\r
" gl_Position = gl_ModelViewProjectionMatrix * gl_Vertex;\n"\r
- " gl_TexCoord[0].xyz = gl_NormalMatrix * gl_Normal;\n"\r
- " gl_TexCoord[0].w = 1.0;\n"\r
+ " gl_TexCoord[0] = vec4 (gl_NormalMatrix * gl_Normal, 1.0);\n"\r
\r
/* XXX source from uniform lightPos */\r
" gl_TexCoord[1] = gl_MultiTexCoord0;\n"\r
exit(1);\r
}
- glCreateShaderObjectARB = (PFNGLCREATESHADEROBJECTARBPROC) glutGetProcAddress ("glCreateShaderObjectARB");\r
- glShaderSourceARB = (PFNGLSHADERSOURCEARBPROC) glutGetProcAddress ("glShaderSourceARB");\r
- glCompileShaderARB = (PFNGLCOMPILESHADERARBPROC) glutGetProcAddress ("glCompileShaderARB");\r
- glCreateProgramObjectARB = (PFNGLCREATEPROGRAMOBJECTARBPROC) glutGetProcAddress ("glCreateProgramObjectARB");\r
- glAttachObjectARB = (PFNGLATTACHOBJECTARBPROC) glutGetProcAddress ("glAttachObjectARB");\r
- glLinkProgramARB = (PFNGLLINKPROGRAMARBPROC) glutGetProcAddress ("glLinkProgramARB");\r
- glUseProgramObjectARB = (PFNGLUSEPROGRAMOBJECTARBPROC) glutGetProcAddress ("glUseProgramObjectARB");\r
+ glCreateShaderObjectARB = (PFNGLCREATESHADEROBJECTARBPROC) GETPROCADDRESS ("glCreateShaderObjectARB");\r
+ glShaderSourceARB = (PFNGLSHADERSOURCEARBPROC) GETPROCADDRESS ("glShaderSourceARB");\r
+ glCompileShaderARB = (PFNGLCOMPILESHADERARBPROC) GETPROCADDRESS ("glCompileShaderARB");\r
+ glCreateProgramObjectARB = (PFNGLCREATEPROGRAMOBJECTARBPROC) GETPROCADDRESS ("glCreateProgramObjectARB");\r
+ glAttachObjectARB = (PFNGLATTACHOBJECTARBPROC) GETPROCADDRESS ("glAttachObjectARB");\r
+ glLinkProgramARB = (PFNGLLINKPROGRAMARBPROC) GETPROCADDRESS ("glLinkProgramARB");\r
+ glUseProgramObjectARB = (PFNGLUSEPROGRAMOBJECTARBPROC) GETPROCADDRESS ("glUseProgramObjectARB");\r
\r
fragShader = glCreateShaderObjectARB (GL_FRAGMENT_SHADER_ARB);\r
glShaderSourceARB (fragShader, 1, &fragShaderText, NULL);\r
--- /dev/null
+/*
+ * GLSL noise demo.
+ *\r
+ * Michal Krol\r
+ * 17 February 2006
+ *\r
+ * Based on the original demo by:
+ * Stefan Gustavson (stegu@itn.liu.se) 2004, 2005
+ */\r
+\r
+#ifdef WIN32\r
+#include <windows.h>\r
+#endif
+
+#include <stdio.h>
+#include <stdlib.h>
+#include <GL/gl.h>\r
+#include <GL/glut.h>\r
+#include <GL/glext.h>\r
+\r
+#ifdef WIN32\r
+#define GETPROCADDRESS wglGetProcAddress\r
+#else\r
+#define GETPROCADDRESS glutGetProcAddress\r
+#endif\r
+
+static GLhandleARB fragShader;
+static GLhandleARB vertShader;\r
+static GLhandleARB program;\r
+\r
+static GLfloat u_time = 0.0f;\r
+
+static PFNGLCREATESHADEROBJECTARBPROC glCreateShaderObjectARB = NULL;\r
+static PFNGLSHADERSOURCEARBPROC glShaderSourceARB = NULL;\r
+static PFNGLCOMPILESHADERARBPROC glCompileShaderARB = NULL;\r
+static PFNGLCREATEPROGRAMOBJECTARBPROC glCreateProgramObjectARB = NULL;\r
+static PFNGLATTACHOBJECTARBPROC glAttachObjectARB = NULL;\r
+static PFNGLLINKPROGRAMARBPROC glLinkProgramARB = NULL;\r
+static PFNGLUSEPROGRAMOBJECTARBPROC glUseProgramObjectARB = NULL;
+
+static void Redisplay (void)
+{
+ glClear (GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);\r
+\r
+ /* XXX source from uniform time */\r
+ glTexCoord1f (u_time);
+
+ glPushMatrix ();
+ glutSolidSphere (2.0, 20, 10);\r
+ glPopMatrix ();
+
+ glutSwapBuffers();
+}
+
+static void Idle (void)
+{\r
+ u_time += 0.1f;
+ glutPostRedisplay ();
+}
+
+static void Reshape (int width, int height)
+{
+ glViewport (0, 0, width, height);
+ glMatrixMode (GL_PROJECTION);
+ glLoadIdentity ();
+ glFrustum (-1.0, 1.0, -1.0, 1.0, 5.0, 25.0);
+ glMatrixMode (GL_MODELVIEW);
+ glLoadIdentity ();
+ glTranslatef (0.0f, 0.0f, -15.0f);
+}
+
+static void Key (unsigned char key, int x, int y)
+{
+ (void) x;
+ (void) y;\r
+
+ switch (key)\r
+ {
+ case 27:
+ exit(0);
+ break;
+ }
+ glutPostRedisplay ();
+}
+
+static void Init (void)
+{
+ static const char *fragShaderText =
+ "void main () {\n"\r
+\r
+ /* XXX source from uniform time */\r
+ " float time;\n"\r
+ " time = gl_TexCoord[1].x;\n"\r
+\r
+ " vec4 v;\n"\r
+ " v = vec4 (4.0 * gl_TexCoord[0].xyz, 0.5 * time);\n"\r
+ " gl_FragColor = gl_Color * vec4 ((0.5 + 0.5 * vec3 (noise1 (v))), 1.0);\n"\r
+ "}\n"
+ ;
+ static const char *vertShaderText =
+ "void main () {\n"\r
+ " gl_Position = gl_ModelViewProjectionMatrix * gl_Vertex;\n"\r
+ " gl_TexCoord[0] = gl_Vertex;\n"\r
+ " gl_FrontColor = gl_Color;\n"\r
+\r
+ /* XXX source from uniform time */\r
+ " gl_TexCoord[1] = gl_MultiTexCoord0;\n"\r
+ "}\n"
+ ;
+\r
+ if (!glutExtensionSupported ("GL_ARB_fragment_shader"))\r
+ {
+ printf ("Sorry, this demo requires GL_ARB_fragment_shader\n");
+ exit(1);
+ }\r
+ if (!glutExtensionSupported ("GL_ARB_shader_objects"))\r
+ {\r
+ printf ("Sorry, this demo requires GL_ARB_shader_objects\n");\r
+ exit(1);\r
+ }\r
+ if (!glutExtensionSupported ("GL_ARB_shading_language_100"))\r
+ {\r
+ printf ("Sorry, this demo requires GL_ARB_shading_language_100\n");\r
+ exit(1);\r
+ }\r
+ if (!glutExtensionSupported ("GL_ARB_vertex_shader"))\r
+ {\r
+ printf ("Sorry, this demo requires GL_ARB_vertex_shader\n");\r
+ exit(1);\r
+ }
+
+ glCreateShaderObjectARB = (PFNGLCREATESHADEROBJECTARBPROC) wglGetProcAddress ("glCreateShaderObjectARB");\r
+ glShaderSourceARB = (PFNGLSHADERSOURCEARBPROC) wglGetProcAddress ("glShaderSourceARB");\r
+ glCompileShaderARB = (PFNGLCOMPILESHADERARBPROC) wglGetProcAddress ("glCompileShaderARB");\r
+ glCreateProgramObjectARB = (PFNGLCREATEPROGRAMOBJECTARBPROC) wglGetProcAddress ("glCreateProgramObjectARB");\r
+ glAttachObjectARB = (PFNGLATTACHOBJECTARBPROC) wglGetProcAddress ("glAttachObjectARB");\r
+ glLinkProgramARB = (PFNGLLINKPROGRAMARBPROC) wglGetProcAddress ("glLinkProgramARB");\r
+ glUseProgramObjectARB = (PFNGLUSEPROGRAMOBJECTARBPROC) wglGetProcAddress ("glUseProgramObjectARB");\r
+\r
+ fragShader = glCreateShaderObjectARB (GL_FRAGMENT_SHADER_ARB);\r
+ glShaderSourceARB (fragShader, 1, &fragShaderText, NULL);\r
+ glCompileShaderARB (fragShader);
+\r
+ vertShader = glCreateShaderObjectARB (GL_VERTEX_SHADER_ARB);\r
+ glShaderSourceARB (vertShader, 1, &vertShaderText, NULL);\r
+ glCompileShaderARB (vertShader);\r
+\r
+ program = glCreateProgramObjectARB ();\r
+ glAttachObjectARB (program, fragShader);\r
+ glAttachObjectARB (program, vertShader);\r
+ glLinkProgramARB (program);\r
+ glUseProgramObjectARB (program);\r
+
+ glClearColor (0.0f, 0.1f, 0.3f, 1.0f);\r
+ glEnable (GL_CULL_FACE);
+ glEnable (GL_DEPTH_TEST);
+
+ printf ("GL_RENDERER = %s\n", (const char *) glGetString (GL_RENDERER));
+}
+
+int main (int argc, char *argv[])
+{
+ glutInit (&argc, argv);
+ glutInitWindowPosition ( 0, 0);
+ glutInitWindowSize (200, 200);
+ glutInitDisplayMode (GLUT_RGB | GLUT_DOUBLE | GLUT_DEPTH);
+ glutCreateWindow (argv[0]);
+ glutReshapeFunc (Reshape);
+ glutKeyboardFunc (Key);
+ glutDisplayFunc (Redisplay);
+ glutIdleFunc (Idle);
+ Init ();
+ glutMainLoop ();
+ return 0;
+}
+\r
{\r
GLubyte *data;\r
\r
- data = get_address_of (vs, name) + index * size;\r
+ data = get_address_of (vs, name);\r
if (data == NULL)\r
return 0;\r
if (write)\r
- _mesa_memcpy (data, val, size);\r
+ _mesa_memcpy (data + index * size, val, size);\r
else\r
- _mesa_memcpy (val, data, size);\r
+ _mesa_memcpy (val, data + index * size, size);\r
return 1;\r
}\r
\r
{\r
GLubyte *data;\r
\r
- data = get_address_of_f (fs, name) + index * size;\r
+ data = get_address_of_f (fs, name);\r
if (data == NULL)\r
return 0;\r
if (write)\r
- _mesa_memcpy (data, val, size);\r
+ _mesa_memcpy (data + index * size, val, size);\r
else\r
- _mesa_memcpy (val, data, size);\r
+ _mesa_memcpy (val, data + index * size, size);\r
return 1;\r
}\r
\r
slang_function *f;\r
slang_assembly_file_restore_point point;\r
slang_machine mach;\r
- slang_assembly_local_info info;\r
- slang_assembly_name_space space;\r
slang_assemble_ctx A;\r
\r
f = &unit->functions.functions[i];\r
slang_assembly_file_restore_point_save (unit->assembly, &point);\r
mach = *unit->machine;\r
mach.ip = unit->assembly->count;\r
- info.ret_size = 0;\r
- info.addr_tmp = 0;\r
- info.swizzle_tmp = 4;\r
- slang_assembly_file_push_label (unit->assembly, slang_asm_local_alloc, 20);\r
- slang_assembly_file_push_label (unit->assembly, slang_asm_enter, 20);\r
- space.funcs = &unit->functions;\r
- space.structs = &unit->structs;\r
- space.vars = &unit->globals;\r
+\r
A.file = unit->assembly;\r
A.mach = unit->machine;\r
A.atoms = unit->atom_pool;\r
- A.space = space;\r
+ A.space.funcs = &unit->functions;\r
+ A.space.structs = &unit->structs;\r
+ A.space.vars = &unit->globals;\r
+ slang_assembly_file_push_label (unit->assembly, slang_asm_local_alloc, 20);\r
+ slang_assembly_file_push_label (unit->assembly, slang_asm_enter, 20);\r
_slang_assemble_function_call (&A, f, NULL, 0, GL_FALSE);\r
slang_assembly_file_push (unit->assembly, slang_asm_exit);\r
+\r
_slang_execute2 (unit->assembly, &mach);\r
slang_assembly_file_restore_point_load (unit->assembly, &point);\r
_mesa_memcpy (unit->machine->mem, mach.mem, SLANG_MACHINE_MEMORY_SIZE * sizeof (slang_machine_slot));\r
slang_function *f;\r
slang_assembly_file_restore_point point;\r
slang_machine mach;\r
- slang_assembly_local_info info;\r
- slang_assembly_name_space space;\r
slang_assemble_ctx A;\r
\r
f = &unit->functions.functions[i];\r
mach = *unit->machine;\r
mach.ip = unit->assembly->count;\r
mach.kill = 0;\r
- info.ret_size = 0;\r
- info.addr_tmp = 0;\r
- info.swizzle_tmp = 4;\r
- slang_assembly_file_push_label (unit->assembly, slang_asm_local_alloc, 20);\r
- slang_assembly_file_push_label (unit->assembly, slang_asm_enter, 20);\r
- space.funcs = &unit->functions;\r
- space.structs = &unit->structs;\r
- space.vars = &unit->globals;\r
+\r
A.file = unit->assembly;\r
A.mach = unit->machine;\r
A.atoms = unit->atom_pool;\r
- A.space = space;\r
+ A.space.funcs = &unit->functions;\r
+ A.space.structs = &unit->structs;\r
+ A.space.vars = &unit->globals;\r
+ slang_assembly_file_push_label (unit->assembly, slang_asm_local_alloc, 20);\r
+ slang_assembly_file_push_label (unit->assembly, slang_asm_enter, 20);\r
_slang_assemble_function_call (&A, f, NULL, 0, GL_FALSE);\r
slang_assembly_file_push (unit->assembly, slang_asm_exit);\r
+\r
_slang_execute2 (unit->assembly, &mach);\r
slang_assembly_file_restore_point_load (unit->assembly, &point);\r
_mesa_memcpy (unit->machine->mem, mach.mem, SLANG_MACHINE_MEMORY_SIZE * sizeof (slang_machine_slot));\r
// TODO:
// - implement texture1D, texture2D, texture3D, textureCube,
// - implement shadow1D, shadow2D,
-// - implement noise1, noise2, noise3, noise4,
//
//
\r
float atan (float y, float x) {\r
float z;\r
- z = atan (y / x);
+ z = atan (y / x);
if (x < 0.0)\r
- {\r
- if (y < 0.0)\r
- return z - 3.141593;\r
- return z + 3.141593;\r
- }\r
- return z;
+ {\r
+ if (y < 0.0)\r
+ return z - 3.141593;\r
+ return z + 3.141593;\r
+ }\r
+ return z;
}\r
vec2 atan (vec2 u, vec2 v) {
}\r
vec2 abs (vec2 v) {\r
- vec2 u;\r
- u.x = abs (v.x);\r
- u.y = abs (v.y);
+ vec2 u;\r
+ u.x = abs (v.x);\r
+ u.y = abs (v.y);
return u;
}\r
vec3 abs (vec3 v) {
vec3 u;\r
- u.x = abs (v.x);\r
- u.y = abs (v.y);\r
- u.z = abs (v.z);\r
+ u.x = abs (v.x);\r
+ u.y = abs (v.y);\r
+ u.z = abs (v.z);\r
return u;
}\r
vec4 abs (vec4 v) {
vec4 u;\r
- u.x = abs (v.x);\r
- u.y = abs (v.y);\r
- u.z = abs (v.z);\r
- u.w = abs (v.w);\r
+ u.x = abs (v.x);\r
+ u.y = abs (v.y);\r
+ u.z = abs (v.z);\r
+ u.w = abs (v.w);\r
return u;
}
vec2 sign (vec2 v) {
vec2 u;\r
- u.x = sign (v.x);\r
- u.y = sign (v.y);\r
+ u.x = sign (v.x);\r
+ u.y = sign (v.y);\r
return u;
}\r
vec3 sign (vec3 v) {
vec3 u;\r
- u.x = sign (v.x);\r
- u.y = sign (v.y);\r
- u.z = sign (v.z);\r
+ u.x = sign (v.x);\r
+ u.y = sign (v.y);\r
+ u.z = sign (v.z);\r
return u;
}\r
vec4 sign (vec4 v) {
vec4 u;\r
- u.x = sign (v.x);\r
- u.y = sign (v.y);\r
- u.z = sign (v.z);\r
- u.w = sign (v.w);\r
+ u.x = sign (v.x);\r
+ u.y = sign (v.y);\r
+ u.z = sign (v.z);\r
+ u.w = sign (v.w);\r
return u;
}
float floor (float x) {\r
float y;\r
- __asm float_floor y, x;\r
- return y;\r
+ __asm float_floor y, x;\r
+ return y;\r
}\r
\r
vec2 floor (vec2 v) {\r
vec2 u;\r
- u.x = floor (v.x);\r
- u.y = floor (v.y);\r
+ u.x = floor (v.x);\r
+ u.y = floor (v.y);\r
return u;\r
}\r
\r
vec3 floor (vec3 v) {\r
vec3 u;\r
- u.x = floor (v.x);\r
- u.y = floor (v.y);\r
- u.z = floor (v.z);\r
+ u.x = floor (v.x);\r
+ u.y = floor (v.y);\r
+ u.z = floor (v.z);\r
return u;\r
}\r
\r
vec4 floor (vec4 v) {\r
vec4 u;\r
- u.x = floor (v.x);\r
- u.y = floor (v.y);\r
- u.z = floor (v.z);\r
- u.w = floor (v.w);\r
+ u.x = floor (v.x);\r
+ u.y = floor (v.y);\r
+ u.z = floor (v.z);\r
+ u.w = floor (v.w);\r
return u;\r
}\r
\r
float ceil (float x) {\r
float y;\r
- __asm float_ceil y, x;\r
- return y;\r
+ __asm float_ceil y, x;\r
+ return y;\r
}\r
\r
vec2 ceil (vec2 v) {\r
vec2 u;\r
- u.x = ceil (v.x);\r
- u.y = ceil (v.y);\r
+ u.x = ceil (v.x);\r
+ u.y = ceil (v.y);\r
return u;\r
}\r
\r
vec3 ceil (vec3 v) {\r
vec3 u;\r
- u.x = ceil (v.x);\r
- u.y = ceil (v.y);\r
- u.z = ceil (v.z);\r
+ u.x = ceil (v.x);\r
+ u.y = ceil (v.y);\r
+ u.z = ceil (v.z);\r
return u;\r
}\r
\r
vec4 ceil (vec4 v) {\r
vec4 u;\r
- u.x = ceil (v.x);\r
- u.y = ceil (v.y);\r
- u.z = ceil (v.z);\r
- u.w = ceil (v.w);\r
+ u.x = ceil (v.x);\r
+ u.y = ceil (v.y);\r
+ u.z = ceil (v.z);\r
+ u.w = ceil (v.w);\r
return u;\r
}
\r
vec2 min (vec2 v, vec2 u) {\r
vec2 t;\r
- t.x = min (v.x, u.x);\r
- t.y = min (v.y, u.y);\r
- return t;\r
+ t.x = min (v.x, u.x);\r
+ t.y = min (v.y, u.y);\r
+ return t;\r
}\r
\r
vec3 min (vec3 v, vec3 u) {\r
vec3 t;\r
- t.x = min (v.x, u.x);\r
- t.y = min (v.y, u.y);\r
- t.z = min (v.z, u.z);\r
- return t;\r
+ t.x = min (v.x, u.x);\r
+ t.y = min (v.y, u.y);\r
+ t.z = min (v.z, u.z);\r
+ return t;\r
}\r
\r
vec4 min (vec4 v, vec4 u) {\r
vec4 t;\r
- t.x = min (v.x, u.x);\r
- t.y = min (v.y, u.y);\r
- t.z = min (v.z, u.z);\r
- t.w = min (v.w, u.w);\r
- return t;\r
+ t.x = min (v.x, u.x);\r
+ t.y = min (v.y, u.y);\r
+ t.z = min (v.z, u.z);\r
+ t.w = min (v.w, u.w);\r
+ return t;\r
}\r
\r
vec2 min (vec2 v, float y) {
vec2 max (vec2 v, vec2 u) {\r
vec2 t;\r
- t.x = max (v.x, u.x);\r
- t.y = max (v.y, u.y);\r
- return t;\r
+ t.x = max (v.x, u.x);\r
+ t.y = max (v.y, u.y);\r
+ return t;\r
}\r
\r
vec3 max (vec3 v, vec3 u) {\r
vec3 t;\r
- t.x = max (v.x, u.x);\r
- t.y = max (v.y, u.y);\r
- t.z = max (v.z, u.z);\r
- return t;\r
+ t.x = max (v.x, u.x);\r
+ t.y = max (v.y, u.y);\r
+ t.z = max (v.z, u.z);\r
+ return t;\r
}\r
\r
vec4 max (vec4 v, vec4 u) {\r
vec4 t;\r
- t.x = max (v.x, u.x);\r
- t.y = max (v.y, u.y);\r
- t.z = max (v.z, u.z);\r
- t.w = max (v.w, u.w);\r
- return t;\r
+ t.x = max (v.x, u.x);\r
+ t.y = max (v.y, u.y);\r
+ t.z = max (v.z, u.z);\r
+ t.w = max (v.w, u.w);\r
+ return t;\r
}\r
\r
vec2 max (vec2 v, float y) {
vec2 step (vec2 edge, vec2 v) {\r
vec2 u;\r
- u.x = step (edge.x, v.x);\r
- u.y = step (edge.y, v.y);\r
- return u;\r
+ u.x = step (edge.x, v.x);\r
+ u.y = step (edge.y, v.y);\r
+ return u;\r
}\r
\r
vec3 step (vec3 edge, vec3 v) {\r
vec3 u;\r
- u.x = step (edge.x, v.x);\r
- u.y = step (edge.y, v.y);\r
- u.z = step (edge.z, v.z);\r
- return u;\r
+ u.x = step (edge.x, v.x);\r
+ u.y = step (edge.y, v.y);\r
+ u.z = step (edge.z, v.z);\r
+ return u;\r
}\r
\r
vec4 step (vec4 edge, vec4 v) {\r
vec4 u;\r
- u.x = step (edge.x, v.x);\r
- u.y = step (edge.y, v.y);\r
- u.z = step (edge.z, v.z);\r
- u.w = step (edge.w, v.w);\r
- return u;\r
+ u.x = step (edge.x, v.x);\r
+ u.y = step (edge.y, v.y);\r
+ u.z = step (edge.z, v.z);\r
+ u.w = step (edge.w, v.w);\r
+ return u;\r
}\r
\r
vec2 step (float edge, vec2 v) {
float smoothstep (float edge0, float edge1, float x) {
float t;\r
- t = clamp ((x - edge0) / (edge1 - edge0), 0.0, 1.0);
+ t = clamp ((x - edge0) / (edge1 - edge0), 0.0, 1.0);
return t * t * (3.0 - 2.0 * t);
}\r
vec2 smoothstep (vec2 edge0, vec2 edge1, vec2 v) {\r
vec2 u;\r
- u.x = smoothstep (edge0.x, edge1.x, v.x);\r
- u.y = smoothstep (edge0.y, edge1.y, v.y);\r
- return u;\r
+ u.x = smoothstep (edge0.x, edge1.x, v.x);\r
+ u.y = smoothstep (edge0.y, edge1.y, v.y);\r
+ return u;\r
}\r
\r
vec3 smoothstep (vec3 edge0, vec3 edge1, vec3 v) {\r
vec3 u;\r
- u.x = smoothstep (edge0.x, edge1.x, v.x);\r
- u.y = smoothstep (edge0.y, edge1.y, v.y);\r
- u.z = smoothstep (edge0.z, edge1.z, v.z);\r
- return u;\r
+ u.x = smoothstep (edge0.x, edge1.x, v.x);\r
+ u.y = smoothstep (edge0.y, edge1.y, v.y);\r
+ u.z = smoothstep (edge0.z, edge1.z, v.z);\r
+ return u;\r
}\r
\r
vec4 smoothstep (vec4 edge0, vec4 edge1, vec4 v) {\r
vec4 u;\r
- u.x = smoothstep (edge0.x, edge1.x, v.x);\r
- u.y = smoothstep (edge0.y, edge1.y, v.y);\r
- u.z = smoothstep (edge0.z, edge1.z, v.z);\r
- u.w = smoothstep (edge0.w, edge1.w, v.w);\r
- return u;\r
+ u.x = smoothstep (edge0.x, edge1.x, v.x);\r
+ u.y = smoothstep (edge0.y, edge1.y, v.y);\r
+ u.z = smoothstep (edge0.z, edge1.z, v.z);\r
+ u.w = smoothstep (edge0.w, edge1.w, v.w);\r
+ return u;\r
}\r
\r
vec2 smoothstep (float edge0, float edge1, vec2 v) {
vec2 u;\r
- u.x = smoothstep (edge0, edge1, v.x);\r
- u.y = smoothstep (edge0, edge1, v.y);\r
- return u;
+ u.x = smoothstep (edge0, edge1, v.x);\r
+ u.y = smoothstep (edge0, edge1, v.y);\r
+ return u;
}\r
vec3 smoothstep (float edge0, float edge1, vec3 v) {
vec3 u;\r
- u.x = smoothstep (edge0, edge1, v.x);\r
- u.y = smoothstep (edge0, edge1, v.y);\r
- u.z = smoothstep (edge0, edge1, v.z);\r
- return u;
+ u.x = smoothstep (edge0, edge1, v.x);\r
+ u.y = smoothstep (edge0, edge1, v.y);\r
+ u.z = smoothstep (edge0, edge1, v.z);\r
+ return u;
}\r
vec4 smoothstep (float edge0, float edge1, vec4 v) {
vec4 u;\r
- u.x = smoothstep (edge0, edge1, v.x);\r
- u.y = smoothstep (edge0, edge1, v.y);\r
- u.z = smoothstep (edge0, edge1, v.z);\r
- u.w = smoothstep (edge0, edge1, v.w);\r
- return u;
+ u.x = smoothstep (edge0, edge1, v.x);\r
+ u.y = smoothstep (edge0, edge1, v.y);\r
+ u.z = smoothstep (edge0, edge1, v.z);\r
+ u.w = smoothstep (edge0, edge1, v.w);\r
+ return u;
}\r
//
float refract (float I, float N, float eta) {
float k;\r
- k = 1.0 - eta * eta * (1.0 - dot (N, I) * dot (N, I));
+ k = 1.0 - eta * eta * (1.0 - dot (N, I) * dot (N, I));
if (k < 0.0)
return 0.0;
return eta * I - (eta * dot (N, I) + sqrt (k)) * N;
vec2 refract (vec2 I, vec2 N, float eta) {
float k;\r
- k = 1.0 - eta * eta * (1.0 - dot (N, I) * dot (N, I));\r
+ k = 1.0 - eta * eta * (1.0 - dot (N, I) * dot (N, I));\r
if (k < 0.0)\r
return 0.0;\r
return eta * I - (eta * dot (N, I) + sqrt (k)) * N;
vec3 refract (vec3 I, vec3 N, float eta) {
float k;\r
- k = 1.0 - eta * eta * (1.0 - dot (N, I) * dot (N, I));\r
+ k = 1.0 - eta * eta * (1.0 - dot (N, I) * dot (N, I));\r
if (k < 0.0)\r
return 0.0;\r
return eta * I - (eta * dot (N, I) + sqrt (k)) * N;
vec4 refract (vec4 I, vec4 N, float eta) {
float k;\r
- k = 1.0 - eta * eta * (1.0 - dot (N, I) * dot (N, I));\r
+ k = 1.0 - eta * eta * (1.0 - dot (N, I) * dot (N, I));\r
if (k < 0.0)\r
return 0.0;\r
return eta * I - (eta * dot (N, I) + sqrt (k)) * N;
//
bvec2 lessThan (vec2 v, vec2 u) {\r
- bvec2 b;\r
- b.x = v.x < u.x;\r
- b.y = v.y < u.y;\r
- return b;
+ bvec2 b;\r
+ b.x = v.x < u.x;\r
+ b.y = v.y < u.y;\r
+ return b;
}\r
bvec3 lessThan (vec3 v, vec3 u) {
bvec3 b;\r
- b.x = v.x < u.x;\r
- b.y = v.y < u.y;\r
- b.z = v.z < u.z;\r
- return b;
+ b.x = v.x < u.x;\r
+ b.y = v.y < u.y;\r
+ b.z = v.z < u.z;\r
+ return b;
}\r
bvec4 lessThan (vec4 v, vec4 u) {
bvec4 b;\r
- b.x = v.x < u.x;\r
- b.y = v.y < u.y;\r
- b.z = v.z < u.z;\r
- b.w = v.w < u.w;\r
- return b;
+ b.x = v.x < u.x;\r
+ b.y = v.y < u.y;\r
+ b.z = v.z < u.z;\r
+ b.w = v.w < u.w;\r
+ return b;
}\r
bvec2 lessThan (ivec2 v, ivec2 u) {
bvec2 b;\r
- b.x = v.x < u.x;\r
- b.y = v.y < u.y;\r
- return b;
+ b.x = v.x < u.x;\r
+ b.y = v.y < u.y;\r
+ return b;
}\r
bvec3 lessThan (ivec3 v, ivec3 u) {
bvec3 b;\r
- b.x = v.x < u.x;\r
- b.y = v.y < u.y;\r
- b.z = v.z < u.z;\r
- return b;
+ b.x = v.x < u.x;\r
+ b.y = v.y < u.y;\r
+ b.z = v.z < u.z;\r
+ return b;
}\r
bvec4 lessThan (ivec4 v, ivec4 u) {
bvec4 b;\r
- b.x = v.x < u.x;\r
- b.y = v.y < u.y;\r
- b.z = v.z < u.z;\r
- b.w = v.w < u.w;\r
- return b;
+ b.x = v.x < u.x;\r
+ b.y = v.y < u.y;\r
+ b.z = v.z < u.z;\r
+ b.w = v.w < u.w;\r
+ return b;
}
bvec2 lessThanEqual (vec2 v, vec2 u) {
bvec2 b;\r
- b.x = v.x <= u.x;\r
- b.y = v.y <= u.y;\r
- return b;
+ b.x = v.x <= u.x;\r
+ b.y = v.y <= u.y;\r
+ return b;
}\r
bvec3 lessThanEqual (vec3 v, vec3 u) {
bvec3 b;\r
- b.x = v.x <= u.x;\r
- b.y = v.y <= u.y;\r
- b.z = v.z <= u.z;\r
- return b;
+ b.x = v.x <= u.x;\r
+ b.y = v.y <= u.y;\r
+ b.z = v.z <= u.z;\r
+ return b;
}\r
bvec4 lessThanEqual (vec4 v, vec4 u) {
bvec4 b;\r
- b.x = v.x <= u.x;\r
- b.y = v.y <= u.y;\r
- b.z = v.z <= u.z;\r
- b.w = v.w <= u.w;\r
- return b;
+ b.x = v.x <= u.x;\r
+ b.y = v.y <= u.y;\r
+ b.z = v.z <= u.z;\r
+ b.w = v.w <= u.w;\r
+ return b;
}\r
bvec2 lessThanEqual (ivec2 v, ivec2 u) {
bvec2 b;\r
- b.x = v.x <= u.x;\r
- b.y = v.y <= u.y;\r
- return b;
+ b.x = v.x <= u.x;\r
+ b.y = v.y <= u.y;\r
+ return b;
}\r
bvec3 lessThanEqual (ivec3 v, ivec3 u) {
bvec3 b;\r
- b.x = v.x <= u.x;\r
- b.y = v.y <= u.y;\r
- b.z = v.z <= u.z;\r
- return b;
+ b.x = v.x <= u.x;\r
+ b.y = v.y <= u.y;\r
+ b.z = v.z <= u.z;\r
+ return b;
}\r
bvec4 lessThanEqual (ivec4 v, ivec4 u) {
bvec4 b;\r
- b.x = v.x <= u.x;\r
- b.y = v.y <= u.y;\r
- b.z = v.z <= u.z;\r
- b.w = v.w <= u.w;\r
- return b;
+ b.x = v.x <= u.x;\r
+ b.y = v.y <= u.y;\r
+ b.z = v.z <= u.z;\r
+ b.w = v.w <= u.w;\r
+ return b;
}
bvec2 greaterThan (vec2 v, vec2 u) {
bvec2 b;\r
- b.x = v.x > u.x;\r
- b.y = v.y > u.y;\r
- return b;
+ b.x = v.x > u.x;\r
+ b.y = v.y > u.y;\r
+ return b;
}\r
bvec3 greaterThan (vec3 v, vec3 u) {
bvec3 b;\r
- b.x = v.x > u.x;\r
- b.y = v.y > u.y;\r
- b.z = v.z > u.z;\r
- return b;
+ b.x = v.x > u.x;\r
+ b.y = v.y > u.y;\r
+ b.z = v.z > u.z;\r
+ return b;
}\r
bvec4 greaterThan (vec4 v, vec4 u) {
bvec4 b;\r
- b.x = v.x > u.x;\r
- b.y = v.y > u.y;\r
- b.z = v.z > u.z;\r
- b.w = v.w > u.w;\r
- return b;
+ b.x = v.x > u.x;\r
+ b.y = v.y > u.y;\r
+ b.z = v.z > u.z;\r
+ b.w = v.w > u.w;\r
+ return b;
}\r
bvec2 greaterThan (ivec2 v, ivec2 u) {
bvec2 b;\r
- b.x = v.x > u.x;\r
- b.y = v.y > u.y;\r
- return b;
+ b.x = v.x > u.x;\r
+ b.y = v.y > u.y;\r
+ return b;
}\r
bvec3 greaterThan (ivec3 v, ivec3 u) {
bvec3 b;\r
- b.x = v.x > u.x;\r
- b.y = v.y > u.y;\r
- b.z = v.z > u.z;\r
- return b;
+ b.x = v.x > u.x;\r
+ b.y = v.y > u.y;\r
+ b.z = v.z > u.z;\r
+ return b;
}\r
bvec4 greaterThan (ivec4 v, ivec4 u) {
bvec4 b;\r
- b.x = v.x > u.x;\r
- b.y = v.y > u.y;\r
- b.z = v.z > u.z;\r
- b.w = v.w > u.w;\r
- return b;
+ b.x = v.x > u.x;\r
+ b.y = v.y > u.y;\r
+ b.z = v.z > u.z;\r
+ b.w = v.w > u.w;\r
+ return b;
}
bvec2 greaterThanEqual (vec2 v, vec2 u) {
bvec2 b;\r
- b.x = v.x >= u.x;\r
- b.y = v.y >= u.y;\r
- return b;
+ b.x = v.x >= u.x;\r
+ b.y = v.y >= u.y;\r
+ return b;
}\r
bvec3 greaterThanEqual (vec3 v, vec3 u) {
bvec3 b;\r
- b.x = v.x >= u.x;\r
- b.y = v.y >= u.y;\r
- b.z = v.z >= u.z;\r
- return b;
+ b.x = v.x >= u.x;\r
+ b.y = v.y >= u.y;\r
+ b.z = v.z >= u.z;\r
+ return b;
}\r
bvec4 greaterThanEqual (vec4 v, vec4 u) {
bvec4 b;\r
- b.x = v.x >= u.x;\r
- b.y = v.y >= u.y;\r
- b.z = v.z >= u.z;\r
- b.w = v.w >= u.w;\r
- return b;
+ b.x = v.x >= u.x;\r
+ b.y = v.y >= u.y;\r
+ b.z = v.z >= u.z;\r
+ b.w = v.w >= u.w;\r
+ return b;
}\r
bvec2 greaterThanEqual (ivec2 v, ivec2 u) {
bvec2 b;\r
- b.x = v.x >= u.x;\r
- b.y = v.y >= u.y;\r
- return b;
+ b.x = v.x >= u.x;\r
+ b.y = v.y >= u.y;\r
+ return b;
}\r
bvec3 greaterThanEqual (ivec3 v, ivec3 u) {
bvec3 b;\r
- b.x = v.x >= u.x;\r
- b.y = v.y >= u.y;\r
- b.z = v.z >= u.z;\r
- return b;
+ b.x = v.x >= u.x;\r
+ b.y = v.y >= u.y;\r
+ b.z = v.z >= u.z;\r
+ return b;
}\r
bvec4 greaterThanEqual (ivec4 v, ivec4 u) {
bvec4 b;\r
- b.x = v.x >= u.x;\r
- b.y = v.y >= u.y;\r
- b.z = v.z >= u.z;\r
- b.w = v.w >= u.w;\r
- return b;
+ b.x = v.x >= u.x;\r
+ b.y = v.y >= u.y;\r
+ b.z = v.z >= u.z;\r
+ b.w = v.w >= u.w;\r
+ return b;
}
bvec2 equal (vec2 v, vec2 u) {
bvec2 b;\r
- b.x = v.x == u.x;\r
- b.y = v.y == u.y;\r
- return b;
+ b.x = v.x == u.x;\r
+ b.y = v.y == u.y;\r
+ return b;
}\r
bvec3 equal (vec3 v, vec3 u) {
bvec3 b;\r
- b.x = v.x == u.x;\r
- b.y = v.y == u.y;\r
- b.z = v.z == u.z;\r
- return b;
+ b.x = v.x == u.x;\r
+ b.y = v.y == u.y;\r
+ b.z = v.z == u.z;\r
+ return b;
}\r
bvec4 equal (vec4 v, vec4 u) {
bvec4 b;\r
- b.x = v.x == u.x;\r
- b.y = v.y == u.y;\r
- b.z = v.z == u.z;\r
- b.w = v.w == u.w;\r
- return b;
+ b.x = v.x == u.x;\r
+ b.y = v.y == u.y;\r
+ b.z = v.z == u.z;\r
+ b.w = v.w == u.w;\r
+ return b;
}\r
bvec2 equal (ivec2 v, ivec2 u) {
bvec2 b;\r
- b.x = v.x == u.x;\r
- b.y = v.y == u.y;\r
- return b;
+ b.x = v.x == u.x;\r
+ b.y = v.y == u.y;\r
+ return b;
}\r
bvec3 equal (ivec3 v, ivec3 u) {
bvec3 b;\r
- b.x = v.x == u.x;\r
- b.y = v.y == u.y;\r
- b.z = v.z == u.z;\r
- return b;
+ b.x = v.x == u.x;\r
+ b.y = v.y == u.y;\r
+ b.z = v.z == u.z;\r
+ return b;
}\r
bvec4 equal (ivec4 v, ivec4 u) {
bvec4 b;\r
- b.x = v.x == u.x;\r
- b.y = v.y == u.y;\r
- b.z = v.z == u.z;\r
- b.w = v.w == u.w;\r
- return b;
+ b.x = v.x == u.x;\r
+ b.y = v.y == u.y;\r
+ b.z = v.z == u.z;\r
+ b.w = v.w == u.w;\r
+ return b;
}
bvec2 notEqual (vec2 v, vec2 u) {
bvec2 b;\r
- b.x = v.x != u.x;\r
- b.y = v.y != u.y;\r
- return b;
+ b.x = v.x != u.x;\r
+ b.y = v.y != u.y;\r
+ return b;
}\r
bvec3 notEqual (vec3 v, vec3 u) {
bvec3 b;\r
- b.x = v.x != u.x;\r
- b.y = v.y != u.y;\r
- b.z = v.z != u.z;\r
- return b;
+ b.x = v.x != u.x;\r
+ b.y = v.y != u.y;\r
+ b.z = v.z != u.z;\r
+ return b;
}\r
bvec4 notEqual (vec4 v, vec4 u) {
bvec4 b;\r
- b.x = v.x != u.x;\r
- b.y = v.y != u.y;\r
- b.z = v.z != u.z;\r
- b.w = v.w != u.w;\r
- return b;
+ b.x = v.x != u.x;\r
+ b.y = v.y != u.y;\r
+ b.z = v.z != u.z;\r
+ b.w = v.w != u.w;\r
+ return b;
}\r
bvec2 notEqual (ivec2 v, ivec2 u) {
bvec2 b;\r
- b.x = v.x != u.x;\r
- b.y = v.y != u.y;\r
- return b;
+ b.x = v.x != u.x;\r
+ b.y = v.y != u.y;\r
+ return b;
}\r
bvec3 notEqual (ivec3 v, ivec3 u) {
bvec3 b;\r
- b.x = v.x != u.x;\r
- b.y = v.y != u.y;\r
- b.z = v.z != u.z;\r
- return b;
+ b.x = v.x != u.x;\r
+ b.y = v.y != u.y;\r
+ b.z = v.z != u.z;\r
+ return b;
}\r
bvec4 notEqual (ivec4 v, ivec4 u) {
bvec4 b;\r
- b.x = v.x != u.x;\r
- b.y = v.y != u.y;\r
- b.z = v.z != u.z;\r
- b.w = v.w != u.w;\r
- return b;
+ b.x = v.x != u.x;\r
+ b.y = v.y != u.y;\r
+ b.z = v.z != u.z;\r
+ b.w = v.w != u.w;\r
+ return b;
}
bool any (bvec2 v) {
}
bvec2 not (bvec2 v) {\r
- bvec2 u;\r
- u.x = !v.x;\r
- u.y = !v.y;
+ bvec2 u;\r
+ u.x = !v.x;\r
+ u.y = !v.y;
return u;
}\r
bvec3 not (bvec3 v) {
bvec3 u;\r
- u.x = !v.x;\r
- u.y = !v.y;\r
- u.z = !v.z;\r
+ u.x = !v.x;\r
+ u.y = !v.y;\r
+ u.z = !v.z;\r
return u;
}\r
bvec4 not (bvec4 v) {
bvec4 u;\r
- u.x = !v.x;\r
- u.y = !v.y;\r
- u.z = !v.z;\r
- u.w = !v.w;\r
+ u.x = !v.x;\r
+ u.y = !v.y;\r
+ u.z = !v.z;\r
+ u.w = !v.w;\r
return u;
}
}
//
-// 8.9 Noise Functions
+// 8.9 Noise Functions\r
+//\r
+// AUTHOR: Stefan Gustavson (stegu@itn.liu.se), Nov 26, 2005
//
float noise1 (float x) {\r
- // XXX:
- return 0.0;
+ float a;\r
+ __asm float_noise1 a, x;\r
+ return a;
}
float noise1 (vec2 x) {\r
- // XXX:
- return 0.0;
+ float a;\r
+ __asm float_noise2 a, x;\r
+ return a;
}
float noise1 (vec3 x) {\r
- // XXX:
- return 0.0;
+ float a;\r
+ __asm float_noise3 a, x;\r
+ return a;
}
float noise1 (vec4 x) {\r
- // XXX:
- return 0.0;
+ float a;\r
+ __asm float_noise4 a, x;\r
+ return a;
}
vec2 noise2 (float x) {\r
- // XXX:
- return vec2 (0.0);
+ vec2 u;\r
+ u.x = noise1 (x);\r
+ u.y = noise1 (x + 19.34);\r
+ return u;
}
vec2 noise2 (vec2 x) {\r
- // XXX:
- return vec2 (0.0);
+ vec2 u;\r
+ u.x = noise1 (x);\r
+ u.y = noise1 (x + vec2 (19.34, 7.66));\r
+ return u;
}
vec2 noise2 (vec3 x) {\r
- // XXX:
- return vec2 (0.0);
+ vec2 u;\r
+ u.x = noise1 (x);\r
+ u.y = noise1 (x + vec3 (19.34, 7.66, 3.23));\r
+ return u;
}
vec2 noise2 (vec4 x) {\r
- // XXX:
- return vec2 (0.0);
+ vec2 u;\r
+ u.x = noise1 (x);\r
+ u.y = noise1 (x + vec4 (19.34, 7.66, 3.23, 2.77));\r
+ return u;
}
vec3 noise3 (float x) {\r
- // XXX:
- return vec3 (0.0);
+ vec3 u;\r
+ u.x = noise1 (x);\r
+ u.y = noise1 (x + 19.34);\r
+ u.z = noise1 (x + 5.47);\r
+ return u;
}
vec3 noise3 (vec2 x) {\r
- // XXX:
- return vec3 (0.0);
+ vec3 u;\r
+ u.x = noise1 (x);\r
+ u.y = noise1 (x + vec2 (19.34, 7.66));\r
+ u.z = noise1 (x + vec2 (5.47, 17.85));\r
+ return u;
}
vec3 noise3 (vec3 x) {\r
- // XXX:
- return vec3 (0.0);
+ vec3 u;\r
+ u.x = noise1 (x);\r
+ u.y = noise1 (x + vec3 (19.34, 7.66, 3.23));\r
+ u.z = noise1 (x + vec3 (5.47, 17.85, 11.04));\r
+ return u;
}
vec3 noise3 (vec4 x) {\r
- // XXX:
- return vec3 (0.0);
+ vec3 u;\r
+ u.x = noise1 (x);\r
+ u.y = noise1 (x + vec4 (19.34, 7.66, 3.23, 2.77));\r
+ u.z = noise1 (x + vec4 (5.47, 17.85, 11.04, 13.19));\r
+ return u;
}
vec4 noise4 (float x) {\r
- // XXX:
- return vec4 (0.0);
+ vec4 u;\r
+ u.x = noise1 (x);\r
+ u.y = noise1 (x + 19.34);\r
+ u.z = noise1 (x + 5.47);\r
+ u.w = noise1 (x + 23.54);\r
+ return u;
}
vec4 noise4 (vec2 x) {\r
- // XXX:
- return vec4 (0.0);
+ vec4 u;\r
+ u.x = noise1 (x);\r
+ u.y = noise1 (x + vec2 (19.34, 7.66));\r
+ u.z = noise1 (x + vec2 (5.47, 17.85));\r
+ u.w = noise1 (x + vec2 (23.54, 29.11));\r
+ return u;
}
vec4 noise4 (vec3 x) {\r
- // XXX:
- return vec4 (0.0);
+ vec4 u;\r
+ u.x = noise1 (x);\r
+ u.y = noise1 (x + vec3 (19.34, 7.66, 3.23));\r
+ u.z = noise1 (x + vec3 (5.47, 17.85, 11.04));\r
+ u.w = noise1 (x + vec3 (23.54, 29.11, 31.91));\r
+ return u;
}
vec4 noise4 (vec4 x) {\r
- // XXX:
- return vec4 (0.0);
+ vec4 u;\r
+ u.x = noise1 (x);\r
+ u.y = noise1 (x + vec4 (19.34, 7.66, 3.23, 2.77));\r
+ u.z = noise1 (x + vec4 (5.47, 17.85, 11.04, 13.19));\r
+ u.w = noise1 (x + vec4 (23.54, 29.11, 31.91, 37.48));\r
+ return u;
}
\r
111,114,100,0,59,115,0,18,99,111,111,114,100,0,59,113,0,49,20,0,9,18,117,0,59,116,0,18,99,111,111,\r
114,100,0,59,116,0,18,99,111,111,114,100,0,59,113,0,49,20,0,9,18,117,0,59,112,0,18,99,111,111,114,\r
100,0,59,112,0,18,99,111,111,114,100,0,59,113,0,49,20,0,8,58,115,104,97,100,111,119,50,68,0,18,115,\r
-97,109,112,108,101,114,0,0,18,117,0,0,0,0,0,1,0,9,0,110,111,105,115,101,49,0,1,0,0,9,120,0,0,0,1,8,\r
-17,48,0,48,0,0,0,0,1,0,9,0,110,111,105,115,101,49,0,1,0,0,10,120,0,0,0,1,8,17,48,0,48,0,0,0,0,1,0,\r
-9,0,110,111,105,115,101,49,0,1,0,0,11,120,0,0,0,1,8,17,48,0,48,0,0,0,0,1,0,9,0,110,111,105,115,101,\r
-49,0,1,0,0,12,120,0,0,0,1,8,17,48,0,48,0,0,0,0,1,0,10,0,110,111,105,115,101,50,0,1,0,0,9,120,0,0,0,\r
-1,8,58,118,101,99,50,0,17,48,0,48,0,0,0,0,0,0,1,0,10,0,110,111,105,115,101,50,0,1,0,0,10,120,0,0,0,\r
-1,8,58,118,101,99,50,0,17,48,0,48,0,0,0,0,0,0,1,0,10,0,110,111,105,115,101,50,0,1,0,0,11,120,0,0,0,\r
-1,8,58,118,101,99,50,0,17,48,0,48,0,0,0,0,0,0,1,0,10,0,110,111,105,115,101,50,0,1,0,0,12,120,0,0,0,\r
-1,8,58,118,101,99,50,0,17,48,0,48,0,0,0,0,0,0,1,0,11,0,110,111,105,115,101,51,0,1,0,0,9,120,0,0,0,\r
-1,8,58,118,101,99,51,0,17,48,0,48,0,0,0,0,0,0,1,0,11,0,110,111,105,115,101,51,0,1,0,0,10,120,0,0,0,\r
-1,8,58,118,101,99,51,0,17,48,0,48,0,0,0,0,0,0,1,0,11,0,110,111,105,115,101,51,0,1,0,0,11,120,0,0,0,\r
-1,8,58,118,101,99,51,0,17,48,0,48,0,0,0,0,0,0,1,0,11,0,110,111,105,115,101,51,0,1,0,0,12,120,0,0,0,\r
-1,8,58,118,101,99,51,0,17,48,0,48,0,0,0,0,0,0,1,0,12,0,110,111,105,115,101,52,0,1,0,0,9,120,0,0,0,\r
-1,8,58,118,101,99,52,0,17,48,0,48,0,0,0,0,0,0,1,0,12,0,110,111,105,115,101,52,0,1,0,0,10,120,0,0,0,\r
-1,8,58,118,101,99,52,0,17,48,0,48,0,0,0,0,0,0,1,0,12,0,110,111,105,115,101,52,0,1,0,0,11,120,0,0,0,\r
-1,8,58,118,101,99,52,0,17,48,0,48,0,0,0,0,0,0,1,0,12,0,110,111,105,115,101,52,0,1,0,0,12,120,0,0,0,\r
-1,8,58,118,101,99,52,0,17,48,0,48,0,0,0,0,0,0,0\r
+97,109,112,108,101,114,0,0,18,117,0,0,0,0,0,1,0,9,0,110,111,105,115,101,49,0,1,0,0,9,120,0,0,0,1,3,\r
+2,0,9,1,97,0,0,0,4,102,108,111,97,116,95,110,111,105,115,101,49,0,18,97,0,0,18,120,0,0,0,8,18,97,0,\r
+0,0,1,0,9,0,110,111,105,115,101,49,0,1,0,0,10,120,0,0,0,1,3,2,0,9,1,97,0,0,0,4,102,108,111,97,116,\r
+95,110,111,105,115,101,50,0,18,97,0,0,18,120,0,0,0,8,18,97,0,0,0,1,0,9,0,110,111,105,115,101,49,0,\r
+1,0,0,11,120,0,0,0,1,3,2,0,9,1,97,0,0,0,4,102,108,111,97,116,95,110,111,105,115,101,51,0,18,97,0,0,\r
+18,120,0,0,0,8,18,97,0,0,0,1,0,9,0,110,111,105,115,101,49,0,1,0,0,12,120,0,0,0,1,3,2,0,9,1,97,0,0,\r
+0,4,102,108,111,97,116,95,110,111,105,115,101,52,0,18,97,0,0,18,120,0,0,0,8,18,97,0,0,0,1,0,10,0,\r
+110,111,105,115,101,50,0,1,0,0,9,120,0,0,0,1,3,2,0,10,1,117,0,0,0,9,18,117,0,59,120,0,58,110,111,\r
+105,115,101,49,0,18,120,0,0,0,20,0,9,18,117,0,59,121,0,58,110,111,105,115,101,49,0,18,120,0,17,49,\r
+57,0,51,52,0,0,46,0,0,20,0,8,18,117,0,0,0,1,0,10,0,110,111,105,115,101,50,0,1,0,0,10,120,0,0,0,1,3,\r
+2,0,10,1,117,0,0,0,9,18,117,0,59,120,0,58,110,111,105,115,101,49,0,18,120,0,0,0,20,0,9,18,117,0,59,\r
+121,0,58,110,111,105,115,101,49,0,18,120,0,58,118,101,99,50,0,17,49,57,0,51,52,0,0,0,17,55,0,54,54,\r
+0,0,0,0,46,0,0,20,0,8,18,117,0,0,0,1,0,10,0,110,111,105,115,101,50,0,1,0,0,11,120,0,0,0,1,3,2,0,10,\r
+1,117,0,0,0,9,18,117,0,59,120,0,58,110,111,105,115,101,49,0,18,120,0,0,0,20,0,9,18,117,0,59,121,0,\r
+58,110,111,105,115,101,49,0,18,120,0,58,118,101,99,51,0,17,49,57,0,51,52,0,0,0,17,55,0,54,54,0,0,0,\r
+17,51,0,50,51,0,0,0,0,46,0,0,20,0,8,18,117,0,0,0,1,0,10,0,110,111,105,115,101,50,0,1,0,0,12,120,0,\r
+0,0,1,3,2,0,10,1,117,0,0,0,9,18,117,0,59,120,0,58,110,111,105,115,101,49,0,18,120,0,0,0,20,0,9,18,\r
+117,0,59,121,0,58,110,111,105,115,101,49,0,18,120,0,58,118,101,99,52,0,17,49,57,0,51,52,0,0,0,17,\r
+55,0,54,54,0,0,0,17,51,0,50,51,0,0,0,17,50,0,55,55,0,0,0,0,46,0,0,20,0,8,18,117,0,0,0,1,0,11,0,110,\r
+111,105,115,101,51,0,1,0,0,9,120,0,0,0,1,3,2,0,11,1,117,0,0,0,9,18,117,0,59,120,0,58,110,111,105,\r
+115,101,49,0,18,120,0,0,0,20,0,9,18,117,0,59,121,0,58,110,111,105,115,101,49,0,18,120,0,17,49,57,0,\r
+51,52,0,0,46,0,0,20,0,9,18,117,0,59,122,0,58,110,111,105,115,101,49,0,18,120,0,17,53,0,52,55,0,0,\r
+46,0,0,20,0,8,18,117,0,0,0,1,0,11,0,110,111,105,115,101,51,0,1,0,0,10,120,0,0,0,1,3,2,0,11,1,117,0,\r
+0,0,9,18,117,0,59,120,0,58,110,111,105,115,101,49,0,18,120,0,0,0,20,0,9,18,117,0,59,121,0,58,110,\r
+111,105,115,101,49,0,18,120,0,58,118,101,99,50,0,17,49,57,0,51,52,0,0,0,17,55,0,54,54,0,0,0,0,46,0,\r
+0,20,0,9,18,117,0,59,122,0,58,110,111,105,115,101,49,0,18,120,0,58,118,101,99,50,0,17,53,0,52,55,0,\r
+0,0,17,49,55,0,56,53,0,0,0,0,46,0,0,20,0,8,18,117,0,0,0,1,0,11,0,110,111,105,115,101,51,0,1,0,0,11,\r
+120,0,0,0,1,3,2,0,11,1,117,0,0,0,9,18,117,0,59,120,0,58,110,111,105,115,101,49,0,18,120,0,0,0,20,0,\r
+9,18,117,0,59,121,0,58,110,111,105,115,101,49,0,18,120,0,58,118,101,99,51,0,17,49,57,0,51,52,0,0,0,\r
+17,55,0,54,54,0,0,0,17,51,0,50,51,0,0,0,0,46,0,0,20,0,9,18,117,0,59,122,0,58,110,111,105,115,101,\r
+49,0,18,120,0,58,118,101,99,51,0,17,53,0,52,55,0,0,0,17,49,55,0,56,53,0,0,0,17,49,49,0,48,52,0,0,0,\r
+0,46,0,0,20,0,8,18,117,0,0,0,1,0,11,0,110,111,105,115,101,51,0,1,0,0,12,120,0,0,0,1,3,2,0,11,1,117,\r
+0,0,0,9,18,117,0,59,120,0,58,110,111,105,115,101,49,0,18,120,0,0,0,20,0,9,18,117,0,59,121,0,58,110,\r
+111,105,115,101,49,0,18,120,0,58,118,101,99,52,0,17,49,57,0,51,52,0,0,0,17,55,0,54,54,0,0,0,17,51,\r
+0,50,51,0,0,0,17,50,0,55,55,0,0,0,0,46,0,0,20,0,9,18,117,0,59,122,0,58,110,111,105,115,101,49,0,18,\r
+120,0,58,118,101,99,52,0,17,53,0,52,55,0,0,0,17,49,55,0,56,53,0,0,0,17,49,49,0,48,52,0,0,0,17,49,\r
+51,0,49,57,0,0,0,0,46,0,0,20,0,8,18,117,0,0,0,1,0,12,0,110,111,105,115,101,52,0,1,0,0,9,120,0,0,0,\r
+1,3,2,0,12,1,117,0,0,0,9,18,117,0,59,120,0,58,110,111,105,115,101,49,0,18,120,0,0,0,20,0,9,18,117,\r
+0,59,121,0,58,110,111,105,115,101,49,0,18,120,0,17,49,57,0,51,52,0,0,46,0,0,20,0,9,18,117,0,59,122,\r
+0,58,110,111,105,115,101,49,0,18,120,0,17,53,0,52,55,0,0,46,0,0,20,0,9,18,117,0,59,119,0,58,110,\r
+111,105,115,101,49,0,18,120,0,17,50,51,0,53,52,0,0,46,0,0,20,0,8,18,117,0,0,0,1,0,12,0,110,111,105,\r
+115,101,52,0,1,0,0,10,120,0,0,0,1,3,2,0,12,1,117,0,0,0,9,18,117,0,59,120,0,58,110,111,105,115,101,\r
+49,0,18,120,0,0,0,20,0,9,18,117,0,59,121,0,58,110,111,105,115,101,49,0,18,120,0,58,118,101,99,50,0,\r
+17,49,57,0,51,52,0,0,0,17,55,0,54,54,0,0,0,0,46,0,0,20,0,9,18,117,0,59,122,0,58,110,111,105,115,\r
+101,49,0,18,120,0,58,118,101,99,50,0,17,53,0,52,55,0,0,0,17,49,55,0,56,53,0,0,0,0,46,0,0,20,0,9,18,\r
+117,0,59,119,0,58,110,111,105,115,101,49,0,18,120,0,58,118,101,99,50,0,17,50,51,0,53,52,0,0,0,17,\r
+50,57,0,49,49,0,0,0,0,46,0,0,20,0,8,18,117,0,0,0,1,0,12,0,110,111,105,115,101,52,0,1,0,0,11,120,0,\r
+0,0,1,3,2,0,12,1,117,0,0,0,9,18,117,0,59,120,0,58,110,111,105,115,101,49,0,18,120,0,0,0,20,0,9,18,\r
+117,0,59,121,0,58,110,111,105,115,101,49,0,18,120,0,58,118,101,99,51,0,17,49,57,0,51,52,0,0,0,17,\r
+55,0,54,54,0,0,0,17,51,0,50,51,0,0,0,0,46,0,0,20,0,9,18,117,0,59,122,0,58,110,111,105,115,101,49,0,\r
+18,120,0,58,118,101,99,51,0,17,53,0,52,55,0,0,0,17,49,55,0,56,53,0,0,0,17,49,49,0,48,52,0,0,0,0,46,\r
+0,0,20,0,9,18,117,0,59,119,0,58,110,111,105,115,101,49,0,18,120,0,58,118,101,99,51,0,17,50,51,0,53,\r
+52,0,0,0,17,50,57,0,49,49,0,0,0,17,51,49,0,57,49,0,0,0,0,46,0,0,20,0,8,18,117,0,0,0,1,0,12,0,110,\r
+111,105,115,101,52,0,1,0,0,12,120,0,0,0,1,3,2,0,12,1,117,0,0,0,9,18,117,0,59,120,0,58,110,111,105,\r
+115,101,49,0,18,120,0,0,0,20,0,9,18,117,0,59,121,0,58,110,111,105,115,101,49,0,18,120,0,58,118,101,\r
+99,52,0,17,49,57,0,51,52,0,0,0,17,55,0,54,54,0,0,0,17,51,0,50,51,0,0,0,17,50,0,55,55,0,0,0,0,46,0,\r
+0,20,0,9,18,117,0,59,122,0,58,110,111,105,115,101,49,0,18,120,0,58,118,101,99,52,0,17,53,0,52,55,0,\r
+0,0,17,49,55,0,56,53,0,0,0,17,49,49,0,48,52,0,0,0,17,49,51,0,49,57,0,0,0,0,46,0,0,20,0,9,18,117,0,\r
+59,119,0,58,110,111,105,115,101,49,0,18,120,0,58,118,101,99,52,0,17,50,51,0,53,52,0,0,0,17,50,57,0,\r
+49,49,0,0,0,17,51,49,0,57,49,0,0,0,17,51,55,0,52,56,0,0,0,0,46,0,0,20,0,8,18,117,0,0,0,0\r
#include "imports.h"\r
#include "slang_utility.h"\r
#include "slang_assemble.h"\r
-/*#include "slang_compile.h"*/\r
#include "slang_storage.h"\r
-/*#include "slang_assemble_constructor.h"*/\r
#include "slang_assemble_typeinfo.h"\r
#include "slang_assemble_conditional.h"\r
#include "slang_assemble_assignment.h"\r
\r
/* slang_assembly */\r
\r
-static int slang_assembly_construct (slang_assembly *assem)\r
+static GLboolean slang_assembly_construct (slang_assembly *assem)\r
{\r
assem->type = slang_asm_none;\r
- return 1;\r
+ return GL_TRUE;\r
}\r
\r
-static void slang_assembly_destruct (slang_assembly *assem)\r
+static GLvoid slang_assembly_destruct (slang_assembly *assem)\r
{\r
}\r
\r
/* slang_assembly_file */\r
\r
-int slang_assembly_file_construct (slang_assembly_file *file)\r
+GLboolean slang_assembly_file_construct (slang_assembly_file *file)\r
{\r
file->code = NULL;\r
file->count = 0;\r
file->capacity = 0;\r
- return 1;\r
+ return GL_TRUE;\r
}\r
\r
-void slang_assembly_file_destruct (slang_assembly_file *file)\r
+GLvoid slang_assembly_file_destruct (slang_assembly_file *file)\r
{\r
- unsigned int i;\r
+ GLuint i;\r
\r
for (i = 0; i < file->count; i++)\r
slang_assembly_destruct (&file->code[i]);\r
slang_alloc_free (file->code);\r
}\r
\r
-static int push_new (slang_assembly_file *file)\r
+static GLboolean push_new (slang_assembly_file *file)\r
{\r
if (file->count == file->capacity)\r
{\r
- unsigned int n;\r
+ GLuint n;\r
\r
if (file->capacity == 0)\r
n = 256;\r
file->code = (slang_assembly *) slang_alloc_realloc (file->code,\r
file->capacity * sizeof (slang_assembly), n * sizeof (slang_assembly));\r
if (file->code == NULL)\r
- return 0;\r
+ return GL_FALSE;\r
file->capacity = n;\r
}\r
if (!slang_assembly_construct (&file->code[file->count]))\r
- return 0;\r
+ return GL_FALSE;\r
file->count++;\r
- return 1;\r
+ return GL_TRUE;\r
}\r
\r
-static int push_gen (slang_assembly_file *file, slang_assembly_type type, GLfloat literal,\r
+static GLboolean push_gen (slang_assembly_file *file, slang_assembly_type type, GLfloat literal,\r
GLuint label, GLuint size)\r
{\r
slang_assembly *assem;\r
\r
if (!push_new (file))\r
- return 0;\r
+ return GL_FALSE;\r
assem = &file->code[file->count - 1];\r
assem->type = type;\r
assem->literal = literal;\r
assem->param[0] = label;\r
assem->param[1] = size;\r
- return 1;\r
+ return GL_TRUE;\r
}\r
\r
-int slang_assembly_file_push (slang_assembly_file *file, slang_assembly_type type)\r
+GLboolean slang_assembly_file_push (slang_assembly_file *file, slang_assembly_type type)\r
{\r
return push_gen (file, type, (GLfloat) 0, 0, 0);\r
}\r
\r
-int slang_assembly_file_push_label (slang_assembly_file *file, slang_assembly_type type,\r
+GLboolean slang_assembly_file_push_label (slang_assembly_file *file, slang_assembly_type type,\r
GLuint label)\r
{\r
return push_gen (file, type, (GLfloat) 0, label, 0);\r
}\r
\r
-int slang_assembly_file_push_label2 (slang_assembly_file *file, slang_assembly_type type,\r
+GLboolean slang_assembly_file_push_label2 (slang_assembly_file *file, slang_assembly_type type,\r
GLuint label1, GLuint label2)\r
{\r
return push_gen (file, type, (GLfloat) 0, label1, label2);\r
}\r
\r
-int slang_assembly_file_push_literal (slang_assembly_file *file, slang_assembly_type type,\r
+GLboolean slang_assembly_file_push_literal (slang_assembly_file *file, slang_assembly_type type,\r
GLfloat literal)\r
{\r
return push_gen (file, type, literal, 0, 0);\r
\r
/* slang_assembly_file_restore_point */\r
\r
-int slang_assembly_file_restore_point_save (slang_assembly_file *file,\r
+GLboolean slang_assembly_file_restore_point_save (slang_assembly_file *file,\r
slang_assembly_file_restore_point *point)\r
{\r
point->count = file->count;\r
- return 1;\r
+ return GL_TRUE;\r
}\r
\r
-int slang_assembly_file_restore_point_load (slang_assembly_file *file,\r
+GLboolean slang_assembly_file_restore_point_load (slang_assembly_file *file,\r
slang_assembly_file_restore_point *point)\r
{\r
- unsigned int i;\r
+ GLuint i;\r
\r
for (i = point->count; i < file->count; i++)\r
slang_assembly_destruct (&file->code[i]);\r
file->count = point->count;\r
- return 1;\r
+ return GL_TRUE;\r
}\r
\r
/* utility functions */\r
\r
-static int sizeof_variable (slang_type_specifier *spec, slang_type_qualifier qual,\r
- slang_operation *array_size, slang_assembly_name_space *space, unsigned int *size,\r
- slang_machine *mach, slang_assembly_file *pfile, slang_atom_pool *atoms)\r
+static GLboolean sizeof_variable (slang_assemble_ctx *A, slang_type_specifier *spec,\r
+ slang_type_qualifier qual, slang_operation *array_size, GLuint *size)\r
{\r
slang_storage_aggregate agg;\r
\r
/* calculate the size of the variable's aggregate */\r
if (!slang_storage_aggregate_construct (&agg))\r
- return 0;\r
- if (!_slang_aggregate_variable (&agg, spec, array_size, space->funcs, space->structs,\r
- space->vars, mach, pfile, atoms))\r
+ return GL_FALSE;\r
+ if (!_slang_aggregate_variable (&agg, spec, array_size, A->space.funcs, A->space.structs,\r
+ A->space.vars, A->mach, A->file, A->atoms))\r
{\r
slang_storage_aggregate_destruct (&agg);\r
- return 0;\r
+ return GL_FALSE;\r
}\r
*size += _slang_sizeof_aggregate (&agg);\r
slang_storage_aggregate_destruct (&agg);\r
/* for reference variables consider the additional address overhead */\r
if (qual == slang_qual_out || qual == slang_qual_inout)\r
*size += 4;\r
- return 1;\r
+\r
+ return GL_TRUE;\r
}\r
\r
-static int sizeof_variable2 (slang_variable *var, slang_assembly_name_space *space,\r
- unsigned int *size, slang_machine *mach, slang_assembly_file *pfile, slang_atom_pool *atoms)\r
+static GLboolean sizeof_variable2 (slang_assemble_ctx *A, slang_variable *var, GLuint *size)\r
{\r
var->address = *size;\r
if (var->type.qualifier == slang_qual_out || var->type.qualifier == slang_qual_inout)\r
var->address += 4;\r
- return sizeof_variable (&var->type.specifier, var->type.qualifier, var->array_size, space,\r
- size, mach, pfile, atoms);\r
+ return sizeof_variable (A, &var->type.specifier, var->type.qualifier, var->array_size, size);\r
}\r
\r
-static int sizeof_variables (slang_variable_scope *vars, unsigned int start, unsigned int stop,\r
- slang_assembly_name_space *space, unsigned int *size, slang_machine *mach,\r
- slang_assembly_file *pfile, slang_atom_pool *atoms)\r
+static GLboolean sizeof_variables (slang_assemble_ctx *A, slang_variable_scope *vars, GLuint start,\r
+ GLuint stop, GLuint *size)\r
{\r
- unsigned int i;\r
+ GLuint i;\r
\r
for (i = start; i < stop; i++)\r
- if (!sizeof_variable2 (&vars->variables[i], space, size, mach, pfile, atoms))\r
- return 0;\r
- return 1;\r
+ if (!sizeof_variable2 (A, &vars->variables[i], size))\r
+ return GL_FALSE;\r
+ return GL_TRUE;\r
}\r
\r
-static int collect_locals (slang_operation *op, slang_assembly_name_space *space,\r
- unsigned int *size, slang_machine *mach, slang_assembly_file *pfile, slang_atom_pool *atoms)\r
+static GLboolean collect_locals (slang_assemble_ctx *A, slang_operation *op, GLuint *size)\r
{\r
- unsigned int i;\r
+ GLuint i;\r
\r
- if (!sizeof_variables (op->locals, 0, op->locals->num_variables, space, size, mach, pfile,\r
- atoms))\r
- return 0;\r
+ if (!sizeof_variables (A, op->locals, 0, op->locals->num_variables, size))\r
+ return GL_FALSE;\r
for (i = 0; i < op->num_children; i++)\r
- if (!collect_locals (&op->children[i], space, size, mach, pfile, atoms))\r
- return 0;\r
- return 1;\r
+ if (!collect_locals (A, &op->children[i], size))\r
+ return GL_FALSE;\r
+ return GL_TRUE;\r
}\r
\r
/* _slang_locate_function() */\r
\r
slang_function *_slang_locate_function (slang_function_scope *funcs, slang_atom a_name,\r
- slang_operation *params, unsigned int num_params, slang_assembly_name_space *space,\r
+ slang_operation *params, GLuint num_params, slang_assembly_name_space *space,\r
slang_atom_pool *atoms)\r
{\r
- unsigned int i;\r
+ GLuint i;\r
\r
for (i = 0; i < funcs->num_functions; i++)\r
{\r
- unsigned int j;\r
+ GLuint j;\r
slang_function *f = &funcs->functions[i];\r
\r
if (a_name != f->header.a_name)\r
slang_assembly_typeinfo ti;\r
\r
if (!slang_assembly_typeinfo_construct (&ti))\r
- return 0;\r
+ return NULL;\r
if (!_slang_typeof_operation (¶ms[j], space, &ti, atoms))\r
{\r
slang_assembly_typeinfo_destruct (&ti);\r
- return 0;\r
+ return NULL;\r
}\r
if (!slang_type_specifier_equal (&ti.spec, &f->parameters->variables[j].type.specifier))\r
{\r
\r
/* _slang_assemble_function() */\r
\r
-int _slang_assemble_function (slang_assemble_ctx *A, slang_function *fun)\r
+GLboolean _slang_assemble_function (slang_assemble_ctx *A, slang_function *fun)\r
{\r
- unsigned int param_size, local_size;\r
- unsigned int skip, cleanup;\r
+ GLuint param_size, local_size;\r
+ GLuint skip, cleanup;\r
\r
fun->address = A->file->count;\r
\r
fun->fixups.table = (GLuint *) slang_alloc_realloc (fun->fixups.table,\r
fun->fixups.count * sizeof (GLuint), (fun->fixups.count + 1) * sizeof (GLuint));\r
if (fun->fixups.table == NULL)\r
- return 0;\r
+ return GL_FALSE;\r
fun->fixups.table[fun->fixups.count] = fun->address;\r
fun->fixups.count++;\r
if (!PUSH (A->file, slang_asm_jump))\r
- return 0;\r
- return 1;\r
+ return GL_FALSE;\r
+ return GL_TRUE;\r
}\r
else\r
{\r
/* calculate return value size */\r
param_size = 0;\r
if (fun->header.type.specifier.type != slang_spec_void)\r
- if (!sizeof_variable (&fun->header.type.specifier, slang_qual_none, NULL, &A->space,\r
- ¶m_size, A->mach, A->file, A->atoms))\r
- return 0;\r
+ if (!sizeof_variable (A, &fun->header.type.specifier, slang_qual_none, NULL, ¶m_size))\r
+ return GL_FALSE;\r
A->local.ret_size = param_size;\r
\r
/* calculate formal parameter list size */\r
- if (!sizeof_variables (fun->parameters, 0, fun->param_count, &A->space, ¶m_size, A->mach, A->file,\r
- A->atoms))\r
- return 0;\r
+ if (!sizeof_variables (A, fun->parameters, 0, fun->param_count, ¶m_size))\r
+ return GL_FALSE;\r
\r
/* calculate local variables size - take into account the four-byte return address and\r
* temporaries for various tasks (4 for addr and 16 for swizzle temporaries).\r
A->local.addr_tmp = param_size + 4;\r
A->local.swizzle_tmp = param_size + 4 + 4;\r
local_size = param_size + 4 + 4 + 16;\r
- if (!sizeof_variables (fun->parameters, fun->param_count, fun->parameters->num_variables, &A->space,\r
- &local_size, A->mach, A->file, A->atoms))\r
- return 0;\r
- if (!collect_locals (fun->body, &A->space, &local_size, A->mach, A->file, A->atoms))\r
- return 0;\r
+ if (!sizeof_variables (A, fun->parameters, fun->param_count, fun->parameters->num_variables,\r
+ &local_size))\r
+ return GL_FALSE;\r
+ if (!collect_locals (A, fun->body, &local_size))\r
+ return GL_FALSE;\r
\r
/* allocate local variable storage */\r
if (!PLAB (A->file, slang_asm_local_alloc, local_size - param_size - 4))\r
- return 0;\r
+ return GL_FALSE;\r
\r
/* mark a new frame for function variable storage */\r
if (!PLAB (A->file, slang_asm_enter, local_size))\r
- return 0;\r
+ return GL_FALSE;\r
\r
/* jump directly to the actual code */\r
skip = A->file->count;\r
if (!push_new (A->file))\r
- return 0;\r
+ return GL_FALSE;\r
A->file->code[skip].type = slang_asm_jump;\r
\r
/* all "return" statements will be directed here */\r
A->flow.function_end = A->file->count;\r
cleanup = A->file->count;\r
if (!push_new (A->file))\r
- return 0;\r
+ return GL_FALSE;\r
A->file->code[cleanup].type = slang_asm_jump;\r
\r
/* execute the function body */\r
A->file->code[skip].param[0] = A->file->count;\r
- if (!_slang_assemble_operation_ (A, fun->body, slang_ref_freelance))\r
- return 0;\r
+ if (!_slang_assemble_operation_ (A, fun->body, /*slang_ref_freelance*/slang_ref_forbid))\r
+ return GL_FALSE;\r
\r
/* this is the end of the function - restore the old function frame */\r
A->file->code[cleanup].param[0] = A->file->count;\r
if (!PUSH (A->file, slang_asm_leave))\r
- return 0;\r
+ return GL_FALSE;\r
\r
/* free local variable storage */\r
if (!PLAB (A->file, slang_asm_local_free, local_size - param_size - 4))\r
- return 0;\r
+ return GL_FALSE;\r
\r
/* return from the function */\r
if (!PUSH (A->file, slang_asm_return))\r
- return 0;\r
- return 1;\r
-}\r
+ return GL_FALSE;\r
\r
-int _slang_cleanup_stack (slang_assembly_file *file, slang_operation *op, int ref,\r
- slang_assembly_name_space *space, struct slang_machine_ *mach, slang_atom_pool *atoms)\r
-{\r
- slang_assemble_ctx A;\r
-\r
- A.file = file;\r
- A.mach = mach;\r
- A.atoms = atoms;\r
- A.space = *space;\r
- return _slang_cleanup_stack_ (&A, op);\r
+ return GL_TRUE;\r
}\r
\r
-int _slang_cleanup_stack_ (slang_assemble_ctx *A, slang_operation *op)\r
+GLboolean _slang_cleanup_stack_ (slang_assemble_ctx *A, slang_operation *op)\r
{\r
slang_assembly_typeinfo ti;\r
- unsigned int size = 0;\r
+ GLuint size = 0;\r
\r
/* get type info of the operation and calculate its size */\r
if (!slang_assembly_typeinfo_construct (&ti))\r
- return 0;\r
+ return GL_FALSE;\r
if (!_slang_typeof_operation (op, &A->space, &ti, A->atoms))\r
{\r
slang_assembly_typeinfo_destruct (&ti);\r
- return 0;\r
+ return GL_FALSE;\r
}\r
- if (A->ref == slang_ref_force)\r
- size = 4;\r
- else if (ti.spec.type != slang_spec_void)\r
- if (!sizeof_variable (&ti.spec, slang_qual_none, NULL, &A->space, &size, A->mach, A->file, A->atoms))\r
+ if (ti.spec.type != slang_spec_void)\r
+ if (A->ref == slang_ref_force)\r
+ size = 4;\r
+ else if (!sizeof_variable (A, &ti.spec, slang_qual_none, NULL, &size))\r
{\r
slang_assembly_typeinfo_destruct (&ti);\r
- return 0;\r
+ return GL_FALSE;\r
}\r
slang_assembly_typeinfo_destruct (&ti);\r
\r
if (size != 0)\r
{\r
if (!PLAB (A->file, slang_asm_local_free, size))\r
- return 0;\r
+ return GL_FALSE;\r
}\r
- return 1;\r
+\r
+ return GL_TRUE;\r
}\r
\r
/* _slang_assemble_operation() */\r
\r
-static int dereference_aggregate (slang_assembly_file *file, const slang_storage_aggregate *agg,\r
- unsigned int *size, slang_assembly_local_info *info, slang_swizzle *swz, int is_swizzled)\r
+static GLboolean dereference_aggregate (slang_assemble_ctx *A, const slang_storage_aggregate *agg,\r
+ GLuint *size, slang_swizzle *swz, GLboolean is_swizzled)\r
{\r
- unsigned int i;\r
+ GLuint i;\r
\r
for (i = agg->count; i > 0; i--)\r
{\r
const slang_storage_array *arr = &agg->arrays[i - 1];\r
- unsigned int j;\r
+ GLuint j;\r
\r
for (j = arr->length; j > 0; j--)\r
{\r
if (arr->type == slang_stor_aggregate)\r
{\r
- if (!dereference_aggregate (file, arr->aggregate, size, info, swz, is_swizzled))\r
- return 0;\r
+ if (!dereference_aggregate (A, arr->aggregate, size, swz, is_swizzled))\r
+ return GL_FALSE;\r
}\r
else\r
{\r
- unsigned int src_offset;\r
+ GLuint src_offset;\r
slang_assembly_type ty;\r
\r
*size -= 4;\r
}\r
\r
/* dereference data slot of a basic type */\r
- if (!PLAB2 (file, slang_asm_local_addr, info->addr_tmp, 4))\r
- return 0;\r
- if (!PUSH (file, slang_asm_addr_deref))\r
- return 0;\r
- if (!PLAB (file, slang_asm_addr_push, src_offset))\r
- return 0;\r
- if (!PUSH (file, slang_asm_addr_add))\r
- return 0;\r
+ if (!PLAB2 (A->file, slang_asm_local_addr, A->local.addr_tmp, 4))\r
+ return GL_FALSE;\r
+ if (!PUSH (A->file, slang_asm_addr_deref))\r
+ return GL_FALSE;\r
+ if (!PLAB (A->file, slang_asm_addr_push, src_offset))\r
+ return GL_FALSE;\r
+ if (!PUSH (A->file, slang_asm_addr_add))\r
+ return GL_FALSE;\r
\r
switch (arr->type)\r
{\r
_mesa_problem(NULL, "Unexpected arr->type in dereference_aggregate");\r
ty = slang_asm_none;\r
}\r
- if (!PUSH (file, ty))\r
- return 0;\r
+ if (!PUSH (A->file, ty))\r
+ return GL_FALSE;\r
}\r
}\r
}\r
- return 1;\r
+\r
+ return GL_TRUE;\r
}\r
\r
-int _slang_dereference (slang_assembly_file *file, slang_operation *op,\r
- slang_assembly_name_space *space, slang_assembly_local_info *info, slang_machine *mach,\r
- slang_atom_pool *atoms)\r
+GLboolean _slang_dereference (slang_assemble_ctx *A, slang_operation *op)\r
{\r
slang_assembly_typeinfo ti;\r
- int result;\r
+ GLboolean result = GL_FALSE;\r
slang_storage_aggregate agg;\r
- unsigned int size;\r
+ GLuint size;\r
\r
/* get type information of the given operation */\r
if (!slang_assembly_typeinfo_construct (&ti))\r
- return 0;\r
- if (!_slang_typeof_operation (op, space, &ti, atoms))\r
- {\r
- slang_assembly_typeinfo_destruct (&ti);\r
- return 0;\r
- }\r
+ return GL_FALSE;\r
+ if (!_slang_typeof_operation (op, &A->space, &ti, A->atoms))\r
+ goto end1;\r
\r
/* construct aggregate from the type info */\r
if (!slang_storage_aggregate_construct (&agg))\r
- {\r
- slang_assembly_typeinfo_destruct (&ti);\r
- return 0;\r
- }\r
- if (!_slang_aggregate_variable (&agg, &ti.spec, ti.array_size, space->funcs, space->structs,\r
- space->vars, mach, file, atoms))\r
- {\r
- slang_storage_aggregate_destruct (&agg);\r
- slang_assembly_typeinfo_destruct (&ti);\r
- return 0;\r
- }\r
+ goto end1;\r
+ if (!_slang_aggregate_variable (&agg, &ti.spec, ti.array_size, A->space.funcs, A->space.structs,\r
+ A->space.vars, A->mach, A->file, A->atoms))\r
+ goto end;\r
\r
/* dereference the resulting aggregate */\r
size = _slang_sizeof_aggregate (&agg);\r
- result = dereference_aggregate (file, &agg, &size, info, &ti.swz, ti.is_swizzled);\r
+ result = dereference_aggregate (A, &agg, &size, &ti.swz, ti.is_swizzled);\r
\r
+end:\r
slang_storage_aggregate_destruct (&agg);\r
+end1:\r
slang_assembly_typeinfo_destruct (&ti);\r
return result;\r
}\r
\r
-int _slang_assemble_function_call (slang_assemble_ctx *A, slang_function *fun,\r
+GLboolean _slang_assemble_function_call (slang_assemble_ctx *A, slang_function *fun,\r
slang_operation *params, GLuint param_count, GLboolean assignment)\r
{\r
- unsigned int i;\r
- slang_assembly_stack_info p_stk[64];\r
+ GLuint i;\r
+ slang_swizzle p_swz[64];\r
+ slang_ref_type p_ref[64];\r
\r
/* TODO: fix this, allocate dynamically */\r
if (param_count > 64)\r
- return 0;\r
+ return GL_FALSE;\r
\r
/* make room for the return value, if any */\r
if (fun->header.type.specifier.type != slang_spec_void)\r
{\r
- unsigned int ret_size = 0;\r
+ GLuint ret_size = 0;\r
\r
- if (!sizeof_variable (&fun->header.type.specifier, slang_qual_none, NULL, &A->space,\r
- &ret_size, A->mach, A->file, A->atoms))\r
- return 0;\r
+ if (!sizeof_variable (A, &fun->header.type.specifier, slang_qual_none, NULL, &ret_size))\r
+ return GL_FALSE;\r
if (!PLAB (A->file, slang_asm_local_alloc, ret_size))\r
- return 0;\r
+ return GL_FALSE;\r
}\r
\r
/* push the actual parameters on the stack */\r
fun->parameters->variables[i].type.qualifier == slang_qual_out)\r
{\r
if (!PLAB2 (A->file, slang_asm_local_addr, A->local.addr_tmp, 4))\r
- return 0;\r
+ return GL_FALSE;\r
/* TODO: optimize the "out" parameter case */\r
if (!_slang_assemble_operation_ (A, ¶ms[i], slang_ref_force))\r
- return 0;\r
- p_stk[i] = A->swz;\r
+ return GL_FALSE;\r
+ p_swz[i] = A->swz;\r
+ p_ref[i] = A->ref;\r
if (!PUSH (A->file, slang_asm_addr_copy))\r
- return 0;\r
+ return GL_FALSE;\r
if (!PUSH (A->file, slang_asm_addr_deref))\r
- return 0;\r
+ return GL_FALSE;\r
if (i == 0 && assignment)\r
{\r
/* duplicate the resulting address */\r
if (!PLAB2 (A->file, slang_asm_local_addr, A->local.addr_tmp, 4))\r
- return 0;\r
+ return GL_FALSE;\r
if (!PUSH (A->file, slang_asm_addr_deref))\r
- return 0;\r
+ return GL_FALSE;\r
}\r
- if (!_slang_dereference (A->file, ¶ms[i], &A->space, &A->local, A->mach, A->atoms))\r
- return 0;\r
+ if (!_slang_dereference (A, ¶ms[i]))\r
+ return GL_FALSE;\r
}\r
else\r
{\r
if (!_slang_assemble_operation_ (A, ¶ms[i], slang_ref_forbid))\r
- return 0;\r
- p_stk[i] = A->swz;\r
+ return GL_FALSE;\r
+ p_swz[i] = A->swz;\r
+ p_ref[i] = A->ref;\r
}\r
}\r
\r
/* call the function */\r
if (!PLAB (A->file, slang_asm_call, fun->address))\r
- return 0;\r
+ return GL_FALSE;\r
\r
/* pop the parameters from the stack */\r
for (i = param_count; i > 0; i--)\r
{\r
- unsigned int j = i - 1;\r
+ GLuint j = i - 1;\r
\r
+ A->swz = p_swz[j];\r
+ A->ref = p_ref[j];\r
if (fun->parameters->variables[j].type.qualifier == slang_qual_inout ||\r
fun->parameters->variables[j].type.qualifier == slang_qual_out)\r
{\r
/* for output parameter copy the contents of the formal parameter\r
* back to the original actual parameter */\r
- A->swz = p_stk[j];\r
if (!_slang_assemble_assignment (A, ¶ms[j]))\r
- return 0;\r
+ return GL_FALSE;\r
/* pop the actual parameter's address */\r
if (!PLAB (A->file, slang_asm_local_free, 4))\r
- return 0;\r
+ return GL_FALSE;\r
}\r
else\r
{\r
/* pop the value of the parameter */\r
if (!_slang_cleanup_stack_ (A, ¶ms[j]))\r
- return 0;\r
+ return GL_FALSE;\r
}\r
}\r
\r
- return 1;\r
+ return GL_TRUE;\r
}\r
\r
-int _slang_assemble_function_call_name (slang_assemble_ctx *A, const char *name,\r
+GLboolean _slang_assemble_function_call_name (slang_assemble_ctx *A, const char *name,\r
slang_operation *params, GLuint param_count, GLboolean assignment)\r
{\r
slang_atom atom;\r
\r
atom = slang_atom_pool_atom (A->atoms, name);\r
if (atom == SLANG_ATOM_NULL)\r
- return 0;\r
+ return GL_FALSE;\r
fun = _slang_locate_function (A->space.funcs, atom, params, param_count, &A->space, A->atoms);\r
if (fun == NULL)\r
- return 0;\r
+ return GL_FALSE;\r
return _slang_assemble_function_call (A, fun, params, param_count, assignment);\r
}\r
\r
-static int assemble_function_call_name_dummyint (slang_assemble_ctx *A, const char *name,\r
+static GLboolean assemble_function_call_name_dummyint (slang_assemble_ctx *A, const char *name,\r
slang_operation *params)\r
{\r
slang_operation p[2];\r
- int result;\r
+ GLboolean result;\r
\r
p[0] = params[0];\r
if (!slang_operation_construct (&p[1]))\r
- return 0;\r
+ return GL_FALSE;\r
p[1].type = slang_oper_literal_int;\r
result = _slang_assemble_function_call_name (A, name, p, 2, GL_FALSE);\r
slang_operation_destruct (&p[1]);\r
{ "float_log2", slang_asm_float_log2, slang_asm_float_copy },\r
{ "float_floor", slang_asm_float_floor, slang_asm_float_copy },\r
{ "float_ceil", slang_asm_float_ceil, slang_asm_float_copy },\r
+ { "float_noise1", slang_asm_float_noise1, slang_asm_float_copy },\r
+ { "float_noise2", slang_asm_float_noise2, slang_asm_float_copy },\r
+ { "float_noise3", slang_asm_float_noise3, slang_asm_float_copy },\r
+ { "float_noise4", slang_asm_float_noise4, slang_asm_float_copy },\r
{ "int_to_float", slang_asm_int_to_float, slang_asm_float_copy },\r
/* mesa-specific extensions */\r
{ "float_print", slang_asm_float_deref, slang_asm_float_print },\r
{ NULL, slang_asm_none, slang_asm_none }\r
};\r
\r
-static int call_asm_instruction (slang_assembly_file *file, slang_atom a_name, slang_atom_pool *atoms)\r
+static GLboolean call_asm_instruction (slang_assemble_ctx *A, slang_atom a_name)\r
{\r
const char *id;\r
- unsigned int i;\r
+ GLuint i;\r
\r
- id = slang_atom_pool_id (atoms, a_name);\r
+ id = slang_atom_pool_id (A->atoms, a_name);\r
\r
for (i = 0; inst[i].name != NULL; i++)\r
if (slang_string_compare (id, inst[i].name) == 0)\r
break;\r
if (inst[i].name == NULL)\r
- return 0;\r
+ return GL_FALSE;\r
\r
- if (!PLAB2 (file, inst[i].code1, 4, 0))\r
- return 0;\r
+ if (!PLAB2 (A->file, inst[i].code1, 4, 0))\r
+ return GL_FALSE;\r
if (inst[i].code2 != slang_asm_none)\r
- if (!PLAB2 (file, inst[i].code2, 4, 0))\r
- return 0;\r
+ if (!PLAB2 (A->file, inst[i].code2, 4, 0))\r
+ return GL_FALSE;\r
\r
/* clean-up the stack from the remaining dst address */\r
- if (!PLAB (file, slang_asm_local_free, 4))\r
- return 0;\r
+ if (!PLAB (A->file, slang_asm_local_free, 4))\r
+ return GL_FALSE;\r
\r
- return 1;\r
+ return GL_TRUE;\r
}\r
\r
-static int equality_aggregate (slang_assembly_file *file, const slang_storage_aggregate *agg,\r
- unsigned int *index, unsigned int size, slang_assembly_local_info *info, unsigned int z_label)\r
+static GLboolean equality_aggregate (slang_assemble_ctx *A, const slang_storage_aggregate *agg,\r
+ GLuint *index, GLuint size, GLuint z_label)\r
{\r
- unsigned int i;\r
+ GLuint i;\r
\r
for (i = 0; i < agg->count; i++)\r
{\r
const slang_storage_array *arr = &agg->arrays[i];\r
- unsigned int j;\r
+ GLuint j;\r
\r
for (j = 0; j < arr->length; j++)\r
{\r
if (arr->type == slang_stor_aggregate)\r
{\r
- if (!equality_aggregate (file, arr->aggregate, index, size, info, z_label))\r
- return 0;\r
+ if (!equality_aggregate (A, arr->aggregate, index, size, z_label))\r
+ return GL_FALSE;\r
}\r
else\r
{\r
- if (!PLAB2 (file, slang_asm_float_equal_int, size + *index, *index))\r
- return 0;\r
+ if (!PLAB2 (A->file, slang_asm_float_equal_int, size + *index, *index))\r
+ return GL_FALSE;\r
*index += 4;\r
- if (!PLAB (file, slang_asm_jump_if_zero, z_label))\r
- return 0;\r
+ if (!PLAB (A->file, slang_asm_jump_if_zero, z_label))\r
+ return GL_FALSE;\r
}\r
}\r
}\r
- return 1;\r
+\r
+ return GL_TRUE;\r
}\r
\r
-static int equality (slang_assembly_file *file, slang_operation *op,\r
- slang_assembly_name_space *space, slang_assembly_local_info *info, int equal,\r
- slang_machine *mach, slang_atom_pool *atoms)\r
+static GLboolean equality (slang_assemble_ctx *A, slang_operation *op, GLboolean equal)\r
{\r
slang_assembly_typeinfo ti;\r
- int result = 0;\r
+ GLboolean result = GL_FALSE;\r
slang_storage_aggregate agg;\r
- unsigned int index, size;\r
- unsigned int skip_jump, true_label, true_jump, false_label, false_jump;\r
+ GLuint index, size;\r
+ GLuint skip_jump, true_label, true_jump, false_label, false_jump;\r
\r
/* get type of operation */\r
if (!slang_assembly_typeinfo_construct (&ti))\r
- return 0;\r
- if (!_slang_typeof_operation (op, space, &ti, atoms))\r
+ return GL_FALSE;\r
+ if (!_slang_typeof_operation (op, &A->space, &ti, A->atoms))\r
goto end1;\r
\r
/* convert it to an aggregate */\r
if (!slang_storage_aggregate_construct (&agg))\r
goto end1;\r
- if (!_slang_aggregate_variable (&agg, &ti.spec, NULL, space->funcs, space->structs,\r
- space->vars, mach, file, atoms))\r
+ if (!_slang_aggregate_variable (&agg, &ti.spec, NULL, A->space.funcs, A->space.structs,\r
+ A->space.vars, A->mach, A->file, A->atoms))\r
goto end;\r
\r
/* compute the size of the agregate - there are two such aggregates on the stack */\r
size = _slang_sizeof_aggregate (&agg);\r
\r
/* jump to the actual data-comparison code */\r
- skip_jump = file->count;\r
- if (!PUSH (file, slang_asm_jump))\r
+ skip_jump = A->file->count;\r
+ if (!PUSH (A->file, slang_asm_jump))\r
goto end;\r
\r
/* pop off the stack the compared data and push 1 */\r
- true_label = file->count;\r
- if (!PLAB (file, slang_asm_local_free, size * 2))\r
+ true_label = A->file->count;\r
+ if (!PLAB (A->file, slang_asm_local_free, size * 2))\r
goto end;\r
- if (!PLIT (file, slang_asm_bool_push, (GLfloat) 1))\r
+ if (!PLIT (A->file, slang_asm_bool_push, (GLfloat) 1))\r
goto end;\r
- true_jump = file->count;\r
- if (!PUSH (file, slang_asm_jump))\r
+ true_jump = A->file->count;\r
+ if (!PUSH (A->file, slang_asm_jump))\r
goto end;\r
\r
- false_label = file->count;\r
- if (!PLAB (file, slang_asm_local_free, size * 2))\r
+ false_label = A->file->count;\r
+ if (!PLAB (A->file, slang_asm_local_free, size * 2))\r
goto end;\r
- if (!PLIT (file, slang_asm_bool_push, (GLfloat) 0))\r
+ if (!PLIT (A->file, slang_asm_bool_push, (GLfloat) 0))\r
goto end;\r
- false_jump = file->count;\r
- if (!PUSH (file, slang_asm_jump))\r
+ false_jump = A->file->count;\r
+ if (!PUSH (A->file, slang_asm_jump))\r
goto end;\r
\r
- file->code[skip_jump].param[0] = file->count;\r
+ A->file->code[skip_jump].param[0] = A->file->count;\r
\r
/* compare the data on stack, it will eventually jump either to true or false label */\r
index = 0;\r
- if (!equality_aggregate (file, &agg, &index, size, info, equal ? false_label : true_label))\r
+ if (!equality_aggregate (A, &agg, &index, size, equal ? false_label : true_label))\r
goto end;\r
- if (!PLAB (file, slang_asm_jump, equal ? true_label : false_label))\r
+ if (!PLAB (A->file, slang_asm_jump, equal ? true_label : false_label))\r
goto end;\r
\r
- file->code[true_jump].param[0] = file->count;\r
- file->code[false_jump].param[0] = file->count;\r
+ A->file->code[true_jump].param[0] = A->file->count;\r
+ A->file->code[false_jump].param[0] = A->file->count;\r
\r
- result = 1;\r
+ result = GL_TRUE;\r
end:\r
slang_storage_aggregate_destruct (&agg);\r
end1:\r
return result;\r
}\r
\r
-static int handle_subscript (slang_assembly_typeinfo *tie, slang_assembly_typeinfo *tia,\r
- slang_assembly_file *file, slang_operation *op, int reference, slang_assembly_flow_control *flow,\r
- slang_assembly_name_space *space, slang_assembly_local_info *info, slang_machine *mach,\r
- slang_atom_pool *atoms)\r
+static GLboolean handle_subscript (slang_assemble_ctx *A, slang_assembly_typeinfo *tie,\r
+ slang_assembly_typeinfo *tia, slang_operation *op, slang_ref_type ref)\r
{\r
- unsigned int asize = 0, esize = 0;\r
- slang_assembly_stack_info _stk;\r
+ GLuint asize = 0, esize = 0;\r
\r
/* get type info of the master expression (matrix, vector or an array */\r
- if (!_slang_typeof_operation (&op->children[0], space, tia, atoms))\r
- return 0;\r
- if (!sizeof_variable (&tia->spec, slang_qual_none, tia->array_size, space, &asize, mach, file,\r
- atoms))\r
- return 0;\r
+ if (!_slang_typeof_operation (&op->children[0], &A->space, tia, A->atoms))\r
+ return GL_FALSE;\r
+ if (!sizeof_variable (A, &tia->spec, slang_qual_none, tia->array_size, &asize))\r
+ return GL_FALSE;\r
\r
/* get type info of the result (matrix column, vector row or array element) */\r
- if (!_slang_typeof_operation (op, space, tie, atoms))\r
- return 0;\r
- if (!sizeof_variable (&tie->spec, slang_qual_none, NULL, space, &esize, mach, file, atoms))\r
- return 0;\r
+ if (!_slang_typeof_operation (op, &A->space, tie, A->atoms))\r
+ return GL_FALSE;\r
+ if (!sizeof_variable (A, &tie->spec, slang_qual_none, NULL, &esize))\r
+ return GL_FALSE;\r
\r
/* assemble the master expression */\r
- if (!_slang_assemble_operation (file, &op->children[0], reference, flow, space, info, &_stk,\r
- mach, atoms))\r
- return 0;\r
- /* ignre the _stk */\r
+ if (!_slang_assemble_operation_ (A, &op->children[0], ref))\r
+ return GL_FALSE;\r
\r
/* when indexing an l-value swizzle, push the swizzle_tmp */\r
- if (reference && tia->is_swizzled)\r
- {\r
- if (!PLAB2 (file, slang_asm_local_addr, info->swizzle_tmp, 16))\r
- return 0;\r
- }\r
+ if (ref == slang_ref_force && tia->is_swizzled)\r
+ if (!PLAB2 (A->file, slang_asm_local_addr, A->local.swizzle_tmp, 16))\r
+ return GL_FALSE;\r
\r
/* assemble the subscript expression */\r
- if (!_slang_assemble_operation (file, &op->children[1], 0, flow, space, info, &_stk, mach, atoms))\r
- return 0;\r
- /* ignore the _stk */\r
+ if (!_slang_assemble_operation_ (A, &op->children[1], slang_ref_forbid))\r
+ return GL_FALSE;\r
\r
- if (reference && tia->is_swizzled)\r
+ if (ref == slang_ref_force && tia->is_swizzled)\r
{\r
- unsigned int i;\r
+ GLuint i;\r
\r
/* copy the swizzle indexes to the swizzle_tmp */\r
for (i = 0; i < tia->swz.num_components; i++)\r
{\r
- if (!PLAB2 (file, slang_asm_local_addr, info->swizzle_tmp, 16))\r
- return 0;\r
- if (!PLAB (file, slang_asm_addr_push, i * 4))\r
- return 0;\r
- if (!PUSH (file, slang_asm_addr_add))\r
- return 0;\r
- if (!PLAB (file, slang_asm_addr_push, tia->swz.swizzle[i]))\r
- return 0;\r
- if (!PUSH (file, slang_asm_addr_copy))\r
- return 0;\r
- if (!PLAB (file, slang_asm_local_free, 4))\r
- return 0;\r
+ if (!PLAB2 (A->file, slang_asm_local_addr, A->local.swizzle_tmp, 16))\r
+ return GL_FALSE;\r
+ if (!PLAB (A->file, slang_asm_addr_push, i * 4))\r
+ return GL_FALSE;\r
+ if (!PUSH (A->file, slang_asm_addr_add))\r
+ return GL_FALSE;\r
+ if (!PLAB (A->file, slang_asm_addr_push, tia->swz.swizzle[i]))\r
+ return GL_FALSE;\r
+ if (!PUSH (A->file, slang_asm_addr_copy))\r
+ return GL_FALSE;\r
+ if (!PLAB (A->file, slang_asm_local_free, 4))\r
+ return GL_FALSE;\r
}\r
\r
/* offset the pushed swizzle_tmp address and dereference it */\r
- if (!PUSH (file, slang_asm_int_to_addr))\r
- return 0;\r
- if (!PLAB (file, slang_asm_addr_push, 4))\r
- return 0;\r
- if (!PUSH (file, slang_asm_addr_multiply))\r
- return 0;\r
- if (!PUSH (file, slang_asm_addr_add))\r
- return 0;\r
- if (!PUSH (file, slang_asm_addr_deref))\r
- return 0;\r
+ if (!PUSH (A->file, slang_asm_int_to_addr))\r
+ return GL_FALSE;\r
+ if (!PLAB (A->file, slang_asm_addr_push, 4))\r
+ return GL_FALSE;\r
+ if (!PUSH (A->file, slang_asm_addr_multiply))\r
+ return GL_FALSE;\r
+ if (!PUSH (A->file, slang_asm_addr_add))\r
+ return GL_FALSE;\r
+ if (!PUSH (A->file, slang_asm_addr_deref))\r
+ return GL_FALSE;\r
}\r
else\r
{\r
/* convert the integer subscript to a relative address */\r
- if (!PUSH (file, slang_asm_int_to_addr))\r
- return 0;\r
+ if (!PUSH (A->file, slang_asm_int_to_addr))\r
+ return GL_FALSE;\r
}\r
\r
- if (!PLAB (file, slang_asm_addr_push, esize))\r
- return 0;\r
- if (!PUSH (file, slang_asm_addr_multiply))\r
- return 0;\r
+ if (!PLAB (A->file, slang_asm_addr_push, esize))\r
+ return GL_FALSE;\r
+ if (!PUSH (A->file, slang_asm_addr_multiply))\r
+ return GL_FALSE;\r
\r
- if (reference)\r
+ if (ref == slang_ref_force)\r
{\r
/* offset the base address with the relative address */\r
- if (!PUSH (file, slang_asm_addr_add))\r
- return 0;\r
+ if (!PUSH (A->file, slang_asm_addr_add))\r
+ return GL_FALSE;\r
}\r
else\r
{\r
- unsigned int i;\r
+ GLuint i;\r
\r
/* move the selected element to the beginning of the master expression */\r
for (i = 0; i < esize; i += 4)\r
- if (!PLAB2 (file, slang_asm_float_move, asize - esize + i + 4, i + 4))\r
- return 0;\r
- if (!PLAB (file, slang_asm_local_free, 4))\r
- return 0;\r
+ if (!PLAB2 (A->file, slang_asm_float_move, asize - esize + i + 4, i + 4))\r
+ return GL_FALSE;\r
+ if (!PLAB (A->file, slang_asm_local_free, 4))\r
+ return GL_FALSE;\r
\r
/* free the rest of the master expression */\r
- if (!PLAB (file, slang_asm_local_free, asize - esize))\r
- return 0;\r
+ if (!PLAB (A->file, slang_asm_local_free, asize - esize))\r
+ return GL_FALSE;\r
}\r
- return 1;\r
+\r
+ return GL_TRUE;\r
}\r
\r
-static int handle_field (slang_assembly_typeinfo *tia, slang_assembly_typeinfo *tib,\r
- slang_assembly_file *file, slang_operation *op, int reference, slang_assembly_flow_control *flow,\r
- slang_assembly_name_space *space, slang_assembly_local_info *info, slang_assembly_stack_info *stk,\r
- slang_machine *mach, slang_atom_pool *atoms)\r
+static GLboolean handle_field (slang_assemble_ctx *A, slang_assembly_typeinfo *tia,\r
+ slang_assembly_typeinfo *tib, slang_operation *op, slang_ref_type ref)\r
{\r
- slang_assembly_stack_info _stk;\r
-\r
/* get type info of the result (field or swizzle) */\r
- if (!_slang_typeof_operation (op, space, tia, atoms))\r
- return 0;\r
+ if (!_slang_typeof_operation (op, &A->space, tia, A->atoms))\r
+ return GL_FALSE;\r
\r
/* get type info of the master expression being accessed (struct or vector) */\r
- if (!_slang_typeof_operation (&op->children[0], space, tib, atoms))\r
- return 0;\r
+ if (!_slang_typeof_operation (&op->children[0], &A->space, tib, A->atoms))\r
+ return GL_FALSE;\r
\r
/* if swizzling a vector in-place, the swizzle temporary is needed */\r
- if (!reference && tia->is_swizzled)\r
- if (!PLAB2 (file, slang_asm_local_addr, info->swizzle_tmp, 16))\r
- return 0;\r
+ if (ref == slang_ref_forbid && tia->is_swizzled)\r
+ if (!PLAB2 (A->file, slang_asm_local_addr, A->local.swizzle_tmp, 16))\r
+ return GL_FALSE;\r
\r
/* assemble the master expression */\r
- if (!_slang_assemble_operation (file, &op->children[0], reference, flow, space, info, &_stk,\r
- mach, atoms))\r
- return 0;\r
- /* ignore _stk.swizzle - we'll have it in tia->swz */\r
+ if (!_slang_assemble_operation_ (A, &op->children[0], ref))\r
+ return GL_FALSE;\r
\r
/* assemble the field expression */\r
if (tia->is_swizzled)\r
{\r
- if (reference)\r
+ if (ref == slang_ref_force)\r
{\r
#if 0\r
if (tia->swz.num_components == 1)\r
/* two or more vector components are being referenced - the so-called write mask\r
* must be passed to the upper operations and applied when assigning value\r
* to this swizzle */\r
- stk->swizzle = tia->swz;\r
+ A->swz = tia->swz;\r
}\r
}\r
else\r
{\r
/* swizzle the vector in-place using the swizzle temporary */\r
- if (!_slang_assemble_constructor_from_swizzle (file, &tia->swz, &tia->spec, &tib->spec,\r
- info))\r
- return 0;\r
+ if (!_slang_assemble_constructor_from_swizzle (A, &tia->swz, &tia->spec, &tib->spec))\r
+ return GL_FALSE;\r
}\r
}\r
else\r
\r
field = &tib->spec._struct->fields->variables[i];\r
if (!slang_storage_aggregate_construct (&agg))\r
- return 0;\r
+ return GL_FALSE;\r
if (!_slang_aggregate_variable (&agg, &field->type.specifier, field->array_size,\r
- space->funcs, space->structs, space->vars, mach, file, atoms))\r
+ A->space.funcs, A->space.structs, A->space.vars, A->mach, A->file, A->atoms))\r
{\r
slang_storage_aggregate_destruct (&agg);\r
- return 0;\r
+ return GL_FALSE;\r
}\r
size = _slang_sizeof_aggregate (&agg);\r
slang_storage_aggregate_destruct (&agg);\r
field_offset += size;\r
}\r
\r
- if (!PLAB (file, slang_asm_addr_push, field_offset))\r
- return 0;\r
+ if (!PLAB (A->file, slang_asm_addr_push, field_offset))\r
+ return GL_FALSE;\r
\r
- if (reference)\r
+ if (ref == slang_ref_force)\r
{\r
- if (!PUSH (file, slang_asm_addr_add))\r
- return 0;\r
+ if (!PUSH (A->file, slang_asm_addr_add))\r
+ return GL_FALSE;\r
}\r
else\r
{\r
- unsigned int i;\r
+ GLuint i;\r
\r
/* move the selected element to the beginning of the master expression */\r
for (i = 0; i < field_size; i += 4)\r
- if (!PLAB2 (file, slang_asm_float_move, struct_size - field_size + i + 4, i + 4))\r
- return 0;\r
- if (!PLAB (file, slang_asm_local_free, 4))\r
- return 0;\r
+ if (!PLAB2 (A->file, slang_asm_float_move, struct_size - field_size + i + 4, i + 4))\r
+ return GL_FALSE;\r
+ if (!PLAB (A->file, slang_asm_local_free, 4))\r
+ return GL_FALSE;\r
\r
/* free the rest of the master expression */\r
- if (!PLAB (file, slang_asm_local_free, struct_size - field_size))\r
- return 0;\r
+ if (!PLAB (A->file, slang_asm_local_free, struct_size - field_size))\r
+ return GL_FALSE;\r
}\r
}\r
- return 1;\r
-}\r
\r
-int _slang_assemble_operation (slang_assembly_file *file, struct slang_operation_ *op, int reference,\r
- slang_assembly_flow_control *flow, slang_assembly_name_space *space, slang_assembly_local_info *info,\r
- slang_assembly_stack_info *stk, struct slang_machine_ *mach, slang_atom_pool *atoms)\r
-{\r
- slang_assemble_ctx A;\r
-\r
- A.file = file;\r
- A.mach = mach;\r
- A.atoms = atoms;\r
- A.space = *space;\r
- A.flow = *flow;\r
- A.local = *info;\r
- if (!_slang_assemble_operation_ (&A, op, reference ? slang_ref_force : slang_ref_forbid))\r
- return 0;\r
- *stk = A.swz;\r
- return 1;\r
+ return GL_TRUE;\r
}\r
\r
-int _slang_assemble_operation_ (slang_assemble_ctx *A, slang_operation *op, slang_ref_type ref)\r
+GLboolean _slang_assemble_operation_ (slang_assemble_ctx *A, slang_operation *op, slang_ref_type ref)\r
{\r
- unsigned int assem;\r
- slang_assembly_stack_info swz;\r
+ GLuint assem;\r
\r
assem = A->file->count;\r
if (!push_new (A->file))\r
- return 0;\r
-\r
-if (ref == slang_ref_freelance)\r
-ref = slang_ref_forbid;\r
+ return GL_FALSE;\r
\r
/* set default results */\r
- A->ref = (ref == slang_ref_freelance) ? slang_ref_force : ref;\r
- swz.swizzle.num_components = 0;\r
+ A->ref = /*(ref == slang_ref_freelance) ? slang_ref_force : */ref;\r
+ A->swz.num_components = 0;\r
\r
switch (op->type)\r
{\r
case slang_oper_block_no_new_scope:\r
case slang_oper_block_new_scope:\r
{\r
- unsigned int i;\r
+ GLuint i;\r
\r
for (i = 0; i < op->num_children; i++)\r
{\r
- if (!_slang_assemble_operation_ (A, &op->children[i], slang_ref_freelance))\r
- return 0;\r
+ if (!_slang_assemble_operation_ (A, &op->children[i], slang_ref_forbid/*slang_ref_freelance*/))\r
+ return GL_FALSE;\r
if (!_slang_cleanup_stack_ (A, &op->children[i]))\r
- return 0;\r
+ return GL_FALSE;\r
}\r
}\r
break;\r
case slang_oper_variable_decl:\r
{\r
- unsigned int i;\r
+ GLuint i;\r
\r
for (i = 0; i < op->num_children; i++)\r
{\r
break;\r
case slang_oper_asm:\r
{\r
- unsigned int i;\r
+ GLuint i;\r
\r
if (!_slang_assemble_operation_ (A, &op->children[0], slang_ref_force))\r
- return 0;\r
+ return GL_FALSE;\r
for (i = 1; i < op->num_children; i++)\r
if (!_slang_assemble_operation_ (A, &op->children[i], slang_ref_forbid))\r
- return 0;\r
- if (!call_asm_instruction (A->file, op->a_id, A->atoms))\r
- return 0;\r
+ return GL_FALSE;\r
+ if (!call_asm_instruction (A, op->a_id))\r
+ return GL_FALSE;\r
}\r
break;\r
case slang_oper_break:\r
case slang_oper_discard:\r
A->file->code[assem].type = slang_asm_discard;\r
if (!PUSH (A->file, slang_asm_exit))\r
- return 0;\r
+ return GL_FALSE;\r
break;\r
case slang_oper_return:\r
if (A->local.ret_size != 0)\r
{\r
/* push the result's address */\r
if (!PLAB2 (A->file, slang_asm_local_addr, 0, A->local.ret_size))\r
- return 0;\r
+ return GL_FALSE;\r
if (!_slang_assemble_operation_ (A, &op->children[0], slang_ref_forbid))\r
- return 0;\r
+ return GL_FALSE;\r
\r
- A->swz.swizzle.num_components = 0;\r
+ A->swz.num_components = 0;\r
/* assign the operation to the function result (it was reserved on the stack) */\r
if (!_slang_assemble_assignment (A, op->children))\r
- return 0;\r
+ return GL_FALSE;\r
\r
if (!PLAB (A->file, slang_asm_local_free, 4))\r
- return 0;\r
+ return GL_FALSE;\r
}\r
if (!PLAB (A->file, slang_asm_jump, A->flow.function_end))\r
- return 0;\r
+ return GL_FALSE;\r
break;\r
case slang_oper_expression:\r
if (ref == slang_ref_force)\r
- return 0;\r
+ return GL_FALSE;\r
if (!_slang_assemble_operation_ (A, &op->children[0], ref))\r
- return 0;\r
+ return GL_FALSE;\r
break;\r
case slang_oper_if:\r
- if (!_slang_assemble_if (A->file, op, &A->flow, &A->space, &A->local, A->mach, A->atoms))\r
- return 0;\r
+ if (!_slang_assemble_if (A, op))\r
+ return GL_FALSE;\r
break;\r
case slang_oper_while:\r
- if (!_slang_assemble_while (A->file, op, &A->flow, &A->space, &A->local, A->mach, A->atoms))\r
- return 0;\r
+ if (!_slang_assemble_while (A, op))\r
+ return GL_FALSE;\r
break;\r
case slang_oper_do:\r
- if (!_slang_assemble_do (A->file, op, &A->flow, &A->space, &A->local, A->mach, A->atoms))\r
- return 0;\r
+ if (!_slang_assemble_do (A, op))\r
+ return GL_FALSE;\r
break;\r
case slang_oper_for:\r
- if (!_slang_assemble_for (A->file, op, &A->flow, &A->space, &A->local, A->mach, A->atoms))\r
- return 0;\r
+ if (!_slang_assemble_for (A, op))\r
+ return GL_FALSE;\r
break;\r
case slang_oper_void:\r
break;\r
case slang_oper_literal_bool:\r
if (ref == slang_ref_force)\r
- return 0;\r
+ return GL_FALSE;\r
A->file->code[assem].type = slang_asm_bool_push;\r
A->file->code[assem].literal = op->literal;\r
A->ref = slang_ref_forbid;\r
break;\r
case slang_oper_literal_int:\r
if (ref == slang_ref_force)\r
- return 0;\r
+ return GL_FALSE;\r
A->file->code[assem].type = slang_asm_int_push;\r
A->file->code[assem].literal = op->literal;\r
A->ref = slang_ref_forbid;\r
break;\r
case slang_oper_literal_float:\r
if (ref == slang_ref_force)\r
- return 0;\r
+ return GL_FALSE;\r
A->file->code[assem].type = slang_asm_float_push;\r
A->file->code[assem].literal = op->literal;\r
A->ref = slang_ref_forbid;\r
case slang_oper_identifier:\r
{\r
slang_variable *var;\r
- unsigned int size;\r
+ GLuint size;\r
\r
/* find the variable and calculate its size */\r
- var = _slang_locate_variable (op->locals, op->a_id, 1);\r
+ var = _slang_locate_variable (op->locals, op->a_id, GL_TRUE);\r
if (var == NULL)\r
- return 0;\r
+ return GL_FALSE;\r
size = 0;\r
- if (!sizeof_variable (&var->type.specifier, slang_qual_none, var->array_size, &A->space,\r
- &size, A->mach, A->file, A->atoms))\r
- return 0;\r
+ if (!sizeof_variable (A, &var->type.specifier, slang_qual_none, var->array_size, &size))\r
+ return GL_FALSE;\r
\r
/* prepare stack for dereferencing */\r
if (ref == slang_ref_forbid)\r
if (!PLAB2 (A->file, slang_asm_local_addr, A->local.addr_tmp, 4))\r
- return 0;\r
+ return GL_FALSE;\r
\r
/* push the variable's address */\r
if (var->global)\r
{\r
if (!PLAB (A->file, slang_asm_addr_push, var->address))\r
- return 0;\r
+ return GL_FALSE;\r
}\r
else\r
{\r
if (!PLAB2 (A->file, slang_asm_local_addr, var->address, size))\r
- return 0;\r
+ return GL_FALSE;\r
}\r
\r
/* perform the dereference */\r
if (ref == slang_ref_forbid)\r
{\r
if (!PUSH (A->file, slang_asm_addr_copy))\r
- return 0;\r
+ return GL_FALSE;\r
if (!PLAB (A->file, slang_asm_local_free, 4))\r
- return 0;\r
- if (!_slang_dereference (A->file, op, &A->space, &A->local, A->mach, A->atoms))\r
- return 0;\r
+ return GL_FALSE;\r
+ if (!_slang_dereference (A, op))\r
+ return GL_FALSE;\r
}\r
}\r
break;\r
case slang_oper_sequence:\r
if (ref == slang_ref_force)\r
- return 0;\r
- if (!_slang_assemble_operation_ (A, &op->children[0], slang_ref_freelance))\r
- return 0;\r
+ return GL_FALSE;\r
+ if (!_slang_assemble_operation_ (A, &op->children[0], slang_ref_forbid/*slang_ref_freelance*/))\r
+ return GL_FALSE;\r
if (!_slang_cleanup_stack_ (A, &op->children[0]))\r
- return 0;\r
+ return GL_FALSE;\r
if (!_slang_assemble_operation_ (A, &op->children[1], slang_ref_forbid))\r
- return 0;\r
+ return GL_FALSE;\r
A->ref = slang_ref_forbid;\r
break;\r
case slang_oper_assign:\r
if (!_slang_assemble_assign (A, op, "=", ref))\r
- return 0;\r
+ return GL_FALSE;\r
break;\r
case slang_oper_addassign:\r
if (!_slang_assemble_assign (A, op, "+=", ref))\r
- return 0;\r
+ return GL_FALSE;\r
break;\r
case slang_oper_subassign:\r
if (!_slang_assemble_assign (A, op, "-=", ref))\r
- return 0;\r
+ return GL_FALSE;\r
break;\r
case slang_oper_mulassign:\r
if (!_slang_assemble_assign (A, op, "*=", ref))\r
- return 0;\r
+ return GL_FALSE;\r
break;\r
/*case slang_oper_modassign:*/\r
/*case slang_oper_lshassign:*/\r
/*case slang_oper_andassign:*/\r
case slang_oper_divassign:\r
if (!_slang_assemble_assign (A, op, "/=", ref))\r
- return 0;\r
+ return GL_FALSE;\r
break;\r
case slang_oper_select:\r
- if (!_slang_assemble_select (A->file, op, &A->flow, &A->space, &A->local, A->mach, A->atoms))\r
- return 0;\r
+ if (!_slang_assemble_select (A, op))\r
+ return GL_FALSE;\r
A->ref = slang_ref_forbid;\r
break;\r
case slang_oper_logicalor:\r
- if (!_slang_assemble_logicalor (A->file, op, &A->flow, &A->space, &A->local, A->mach, A->atoms))\r
- return 0;\r
+ if (!_slang_assemble_logicalor (A, op))\r
+ return GL_FALSE;\r
A->ref = slang_ref_forbid;\r
break;\r
case slang_oper_logicaland:\r
- if (!_slang_assemble_logicaland (A->file, op, &A->flow, &A->space, &A->local, A->mach, A->atoms))\r
- return 0;\r
+ if (!_slang_assemble_logicaland (A, op))\r
+ return GL_FALSE;\r
A->ref = slang_ref_forbid;\r
break;\r
case slang_oper_logicalxor:\r
if (!_slang_assemble_function_call_name (A, "^^", op->children, 2, GL_FALSE))\r
- return 0;\r
+ return GL_FALSE;\r
A->ref = slang_ref_forbid;\r
break;\r
/*case slang_oper_bitor:*/\r
/*case slang_oper_bitand:*/\r
case slang_oper_less:\r
if (!_slang_assemble_function_call_name (A, "<", op->children, 2, GL_FALSE))\r
- return 0;\r
+ return GL_FALSE;\r
A->ref = slang_ref_forbid;\r
break;\r
case slang_oper_greater:\r
if (!_slang_assemble_function_call_name (A, ">", op->children, 2, GL_FALSE))\r
- return 0;\r
+ return GL_FALSE;\r
A->ref = slang_ref_forbid;\r
break;\r
case slang_oper_lessequal:\r
if (!_slang_assemble_function_call_name (A, "<=", op->children, 2, GL_FALSE))\r
- return 0;\r
+ return GL_FALSE;\r
A->ref = slang_ref_forbid;\r
break;\r
case slang_oper_greaterequal:\r
if (!_slang_assemble_function_call_name (A, ">=", op->children, 2, GL_FALSE))\r
- return 0;\r
+ return GL_FALSE;\r
A->ref = slang_ref_forbid;\r
break;\r
/*case slang_oper_lshift:*/\r
/*case slang_oper_rshift:*/\r
case slang_oper_add:\r
if (!_slang_assemble_function_call_name (A, "+", op->children, 2, GL_FALSE))\r
- return 0;\r
+ return GL_FALSE;\r
A->ref = slang_ref_forbid;\r
break;\r
case slang_oper_subtract:\r
if (!_slang_assemble_function_call_name (A, "-", op->children, 2, GL_FALSE))\r
- return 0;\r
+ return GL_FALSE;\r
A->ref = slang_ref_forbid;\r
break;\r
case slang_oper_multiply:\r
if (!_slang_assemble_function_call_name (A, "*", op->children, 2, GL_FALSE))\r
- return 0;\r
+ return GL_FALSE;\r
A->ref = slang_ref_forbid;\r
break;\r
/*case slang_oper_modulus:*/\r
case slang_oper_divide:\r
if (!_slang_assemble_function_call_name (A, "/", op->children, 2, GL_FALSE))\r
- return 0;\r
+ return GL_FALSE;\r
A->ref = slang_ref_forbid;\r
break;\r
case slang_oper_equal:\r
if (!_slang_assemble_operation_ (A, &op->children[0], slang_ref_forbid))\r
- return 0;\r
+ return GL_FALSE;\r
if (!_slang_assemble_operation_ (A, &op->children[1], slang_ref_forbid))\r
- return 0;\r
- if (!equality (A->file, op->children, &A->space, &A->local, 1, A->mach, A->atoms))\r
- return 0;\r
+ return GL_FALSE;\r
+ if (!equality (A, op->children, GL_TRUE))\r
+ return GL_FALSE;\r
A->ref = slang_ref_forbid;\r
break;\r
case slang_oper_notequal:\r
if (!_slang_assemble_operation_ (A, &op->children[0], slang_ref_forbid))\r
- return 0;\r
+ return GL_FALSE;\r
if (!_slang_assemble_operation_ (A, &op->children[1], slang_ref_forbid))\r
- return 0;\r
- if (!equality (A->file, op->children, &A->space, &A->local, 0, A->mach, A->atoms))\r
- return 0;\r
+ return GL_FALSE;\r
+ if (!equality (A, op->children, GL_FALSE))\r
+ return GL_FALSE;\r
A->ref = slang_ref_forbid;\r
break;\r
case slang_oper_preincrement:\r
if (!_slang_assemble_assign (A, op, "++", ref))\r
- return 0;\r
+ return GL_FALSE;\r
break;\r
case slang_oper_predecrement:\r
if (!_slang_assemble_assign (A, op, "--", ref))\r
- return 0;\r
+ return GL_FALSE;\r
break;\r
case slang_oper_plus:\r
- if (!_slang_dereference (A->file, op, &A->space, &A->local, A->mach, A->atoms))\r
- return 0;\r
+ if (!_slang_dereference (A, op))\r
+ return GL_FALSE;\r
A->ref = slang_ref_forbid;\r
break;\r
case slang_oper_minus:\r
if (!_slang_assemble_function_call_name (A, "-", op->children, 1, GL_FALSE))\r
- return 0;\r
+ return GL_FALSE;\r
A->ref = slang_ref_forbid;\r
break;\r
/*case slang_oper_complement:*/\r
case slang_oper_not:\r
if (!_slang_assemble_function_call_name (A, "!", op->children, 1, GL_FALSE))\r
- return 0;\r
+ return GL_FALSE;\r
A->ref = slang_ref_forbid;\r
break;\r
case slang_oper_subscript:\r
slang_assembly_typeinfo ti_arr, ti_elem;\r
\r
if (!slang_assembly_typeinfo_construct (&ti_arr))\r
- return 0;\r
+ return GL_FALSE;\r
if (!slang_assembly_typeinfo_construct (&ti_elem))\r
{\r
slang_assembly_typeinfo_destruct (&ti_arr);\r
- return 0;\r
+ return GL_FALSE;\r
}\r
- if (!handle_subscript (&ti_elem, &ti_arr, A->file, op, ref != slang_ref_forbid, &A->flow, &A->space, &A->local,\r
- A->mach, A->atoms))\r
+ if (!handle_subscript (A, &ti_elem, &ti_arr, op, ref))\r
{\r
slang_assembly_typeinfo_destruct (&ti_arr);\r
slang_assembly_typeinfo_destruct (&ti_elem);\r
- return 0;\r
+ return GL_FALSE;\r
}\r
slang_assembly_typeinfo_destruct (&ti_arr);\r
slang_assembly_typeinfo_destruct (&ti_elem);\r
&A->space, A->atoms);\r
if (fun == NULL)\r
{\r
-/* if (!_slang_assemble_constructor (file, op, flow, space, info, mach))\r
-*/ return 0;\r
+ if (!_slang_assemble_constructor (A, op))\r
+ return GL_FALSE;\r
}\r
else\r
{\r
if (!_slang_assemble_function_call (A, fun, op->children, op->num_children, GL_FALSE))\r
- return 0;\r
+ return GL_FALSE;\r
}\r
A->ref = slang_ref_forbid;\r
}\r
slang_assembly_typeinfo ti_after, ti_before;\r
\r
if (!slang_assembly_typeinfo_construct (&ti_after))\r
- return 0;\r
+ return GL_FALSE;\r
if (!slang_assembly_typeinfo_construct (&ti_before))\r
{\r
slang_assembly_typeinfo_destruct (&ti_after);\r
- return 0;\r
+ return GL_FALSE;\r
}\r
- if (!handle_field (&ti_after, &ti_before, A->file, op, ref != slang_ref_forbid, &A->flow, &A->space, &A->local, &swz,\r
- A->mach, A->atoms))\r
+ if (!handle_field (A, &ti_after, &ti_before, op, ref))\r
{\r
slang_assembly_typeinfo_destruct (&ti_after);\r
slang_assembly_typeinfo_destruct (&ti_before);\r
- return 0;\r
+ return GL_FALSE;\r
}\r
slang_assembly_typeinfo_destruct (&ti_after);\r
slang_assembly_typeinfo_destruct (&ti_before);\r
break;\r
case slang_oper_postincrement:\r
if (!assemble_function_call_name_dummyint (A, "++", op->children))\r
- return 0;\r
+ return GL_FALSE;\r
A->ref = slang_ref_forbid;\r
break;\r
case slang_oper_postdecrement:\r
if (!assemble_function_call_name_dummyint (A, "--", op->children))\r
- return 0;\r
+ return GL_FALSE;\r
A->ref = slang_ref_forbid;\r
break;\r
default:\r
- return 0;\r
+ return GL_FALSE;\r
}\r
\r
- A->swz = swz;\r
-\r
- return 1;\r
+ return GL_TRUE;\r
}\r
\r
slang_asm_float_log2,\r
slang_asm_float_floor,\r
slang_asm_float_ceil,\r
+ slang_asm_float_noise1,\r
+ slang_asm_float_noise2,\r
+ slang_asm_float_noise3,\r
+ slang_asm_float_noise4,\r
slang_asm_int_copy,\r
slang_asm_int_move,\r
slang_asm_int_push,\r
typedef struct slang_assembly_file_\r
{\r
slang_assembly *code;\r
- unsigned int count;\r
- unsigned int capacity;\r
+ GLuint count;\r
+ GLuint capacity;\r
} slang_assembly_file;\r
\r
-int slang_assembly_file_construct (slang_assembly_file *);\r
-void slang_assembly_file_destruct (slang_assembly_file *);\r
-int slang_assembly_file_push (slang_assembly_file *, slang_assembly_type);\r
-int slang_assembly_file_push_label (slang_assembly_file *, slang_assembly_type, GLuint);\r
-int slang_assembly_file_push_label2 (slang_assembly_file *, slang_assembly_type, GLuint, GLuint);\r
-int slang_assembly_file_push_literal (slang_assembly_file *, slang_assembly_type, GLfloat);\r
+GLboolean slang_assembly_file_construct (slang_assembly_file *);\r
+GLvoid slang_assembly_file_destruct (slang_assembly_file *);\r
+GLboolean slang_assembly_file_push (slang_assembly_file *, slang_assembly_type);\r
+GLboolean slang_assembly_file_push_label (slang_assembly_file *, slang_assembly_type, GLuint);\r
+GLboolean slang_assembly_file_push_label2 (slang_assembly_file *, slang_assembly_type, GLuint, GLuint);\r
+GLboolean slang_assembly_file_push_literal (slang_assembly_file *, slang_assembly_type, GLfloat);\r
\r
typedef struct slang_assembly_file_restore_point_\r
{\r
- unsigned int count;\r
+ GLuint count;\r
} slang_assembly_file_restore_point;\r
\r
-int slang_assembly_file_restore_point_save (slang_assembly_file *,\r
+GLboolean slang_assembly_file_restore_point_save (slang_assembly_file *,\r
slang_assembly_file_restore_point *);\r
-int slang_assembly_file_restore_point_load (slang_assembly_file *,\r
+GLboolean slang_assembly_file_restore_point_load (slang_assembly_file *,\r
slang_assembly_file_restore_point *);\r
\r
typedef struct slang_assembly_flow_control_\r
{\r
- unsigned int loop_start; /* for "continue" statement */\r
- unsigned int loop_end; /* for "break" statement */\r
- unsigned int function_end; /* for "return" statement */\r
+ GLuint loop_start; /* for "continue" statement */\r
+ GLuint loop_end; /* for "break" statement */\r
+ GLuint function_end; /* for "return" statement */\r
} slang_assembly_flow_control;\r
\r
typedef struct slang_assembly_local_info_\r
{\r
- unsigned int ret_size;\r
- unsigned int addr_tmp;\r
- unsigned int swizzle_tmp;\r
+ GLuint ret_size;\r
+ GLuint addr_tmp;\r
+ GLuint swizzle_tmp;\r
} slang_assembly_local_info;\r
\r
typedef enum\r
{\r
slang_ref_force,\r
- slang_ref_forbid,\r
- slang_ref_freelance\r
+ slang_ref_forbid/*,\r
+ slang_ref_freelance*/\r
} slang_ref_type;\r
\r
/*\r
- holds a complete information about vector swizzle - the <swizzle> array contains\r
- vector component sources indices, where 0 is "x", 1 is "y", ...\r
- example: "xwz" --> { 3, { 0, 3, 2, n/u } }\r
-*/\r
+ * Holds a complete information about vector swizzle - the <swizzle> array contains\r
+ * vector component source indices, where 0 is "x", 1 is "y", 2 is "z" and 3 is "w".\r
+ * Example: "xwz" --> { 3, { 0, 3, 2, not used } }.\r
+ */\r
typedef struct slang_swizzle_\r
{\r
- unsigned int num_components;\r
- unsigned int swizzle[4];\r
+ GLuint num_components;\r
+ GLuint swizzle[4];\r
} slang_swizzle;\r
\r
-typedef struct slang_assembly_stack_info_\r
-{\r
- slang_swizzle swizzle;\r
-} slang_assembly_stack_info;\r
-\r
typedef struct slang_assembly_name_space_\r
{\r
struct slang_function_scope_ *funcs;\r
slang_assembly_flow_control flow;\r
slang_assembly_local_info local;\r
slang_ref_type ref;\r
- slang_assembly_stack_info swz;\r
+ slang_swizzle swz;\r
} slang_assemble_ctx;\r
\r
slang_function *_slang_locate_function (slang_function_scope *funcs, slang_atom a_name,\r
- slang_operation *params, unsigned int num_params, slang_assembly_name_space *space,\r
+ slang_operation *params, GLuint num_params, slang_assembly_name_space *space,\r
slang_atom_pool *);\r
\r
-int _slang_assemble_function (slang_assemble_ctx *, struct slang_function_ *);\r
+GLboolean _slang_assemble_function (slang_assemble_ctx *, struct slang_function_ *);\r
\r
-int _slang_cleanup_stack (slang_assembly_file *, slang_operation *, int ref,\r
- slang_assembly_name_space *, struct slang_machine_ *, slang_atom_pool *);\r
-int _slang_cleanup_stack_ (slang_assemble_ctx *, slang_operation *);\r
+GLboolean _slang_cleanup_stack_ (slang_assemble_ctx *, slang_operation *);\r
\r
-int _slang_dereference (slang_assembly_file *, slang_operation *, slang_assembly_name_space *,\r
- slang_assembly_local_info *, struct slang_machine_ *, slang_atom_pool *);\r
+GLboolean _slang_dereference (slang_assemble_ctx *, slang_operation *);\r
\r
-int _slang_assemble_function_call (slang_assemble_ctx *, slang_function *,\r
- slang_operation *, GLuint, GLboolean);\r
+GLboolean _slang_assemble_function_call (slang_assemble_ctx *, slang_function *, slang_operation *,\r
+ GLuint, GLboolean);\r
\r
-int _slang_assemble_function_call_name (slang_assemble_ctx *, const char *,\r
- slang_operation *, GLuint, GLboolean);\r
+GLboolean _slang_assemble_function_call_name (slang_assemble_ctx *, const char *, slang_operation *,\r
+ GLuint, GLboolean);\r
\r
-int _slang_assemble_operation (slang_assembly_file *, struct slang_operation_ *, int reference,\r
- slang_assembly_flow_control *, slang_assembly_name_space *, slang_assembly_local_info *,\r
- slang_assembly_stack_info *, struct slang_machine_ *, slang_atom_pool *);\r
-int _slang_assemble_operation_ (slang_assemble_ctx *, struct slang_operation_ *, slang_ref_type);\r
+GLboolean _slang_assemble_operation_ (slang_assemble_ctx *, struct slang_operation_ *, slang_ref_type);\r
\r
#ifdef __cplusplus\r
}\r
#include "slang_execute.h"\r
\r
/*\r
- _slang_assemble_assignment()\r
-\r
- copies values on the stack (<component 0> to <component N-1>) to a memory\r
- location pointed by <addr of variable>;\r
-\r
- in:\r
- +------------------+\r
- | addr of variable |\r
- +------------------+\r
- | component N-1 |\r
- | ... |\r
- | component 0 |\r
- +------------------+\r
-\r
- out:\r
- +------------------+\r
- | addr of variable |\r
- +------------------+\r
-*/\r
-\r
-static int assign_aggregate (slang_assembly_file *file, const slang_storage_aggregate *agg,\r
- unsigned int *index, unsigned int size, slang_assembly_local_info *info,\r
- slang_assembly_stack_info *stk)\r
+ * _slang_assemble_assignment()\r
+ *\r
+ * Copies values on the stack (<component 0> to <component N-1>) to a memory\r
+ * location pointed by <addr of variable>.\r
+ *\r
+ * in:\r
+ * +------------------+\r
+ * | addr of variable |\r
+ * +------------------+\r
+ * | component N-1 |\r
+ * | ... |\r
+ * | component 0 |\r
+ * +------------------+\r
+ *\r
+ * out:\r
+ * +------------------+\r
+ * | addr of variable |\r
+ * +------------------+\r
+ */\r
+\r
+static GLboolean assign_aggregate (slang_assemble_ctx *A, const slang_storage_aggregate *agg,\r
+ GLuint *index, GLuint size)\r
{\r
- unsigned int i;\r
+ GLuint i;\r
\r
for (i = 0; i < agg->count; i++)\r
{\r
const slang_storage_array *arr = &agg->arrays[i];\r
- unsigned int j;\r
+ GLuint j;\r
\r
for (j = 0; j < arr->length; j++)\r
{\r
if (arr->type == slang_stor_aggregate)\r
{\r
- if (!assign_aggregate (file, arr->aggregate, index, size, info, stk))\r
- return 0;\r
+ if (!assign_aggregate (A, arr->aggregate, index, size))\r
+ return GL_FALSE;\r
}\r
else\r
{\r
- unsigned int dst_addr_loc, dst_offset;\r
+ GLuint dst_addr_loc, dst_offset;\r
slang_assembly_type ty;\r
\r
/* calculate the distance from top of the stack to the destination address */\r
dst_addr_loc = size - *index;\r
\r
/* calculate the offset within destination variable to write */\r
- if (stk->swizzle.num_components != 0)\r
+ if (A->swz.num_components != 0)\r
{\r
/* swizzle the index to get the actual offset */\r
- dst_offset = stk->swizzle.swizzle[*index / 4] * 4;\r
+ dst_offset = A->swz.swizzle[*index / 4] * 4;\r
}\r
else\r
{\r
ty = slang_asm_float_copy;\r
break;\r
default:\r
- _mesa_problem(NULL, "Unexpected arr->type in assign_aggregate");\r
- ty = slang_asm_none;\r
break;\r
}\r
- if (!slang_assembly_file_push_label2 (file, ty, dst_addr_loc, dst_offset))\r
- return 0;\r
+ if (!slang_assembly_file_push_label2 (A->file, ty, dst_addr_loc, dst_offset))\r
+ return GL_FALSE;\r
+\r
*index += 4;\r
}\r
}\r
}\r
- return 1;\r
+\r
+ return GL_TRUE;\r
}\r
\r
-int _slang_assemble_assignment (slang_assemble_ctx *A, slang_operation *op)\r
+GLboolean _slang_assemble_assignment (slang_assemble_ctx *A, slang_operation *op)\r
{\r
slang_assembly_typeinfo ti;\r
- int result;\r
+ GLboolean result = GL_FALSE;\r
slang_storage_aggregate agg;\r
- unsigned int index, size;\r
+ GLuint index, size;\r
\r
if (!slang_assembly_typeinfo_construct (&ti))\r
- return 0;\r
+ return GL_FALSE;\r
if (!_slang_typeof_operation (op, &A->space, &ti, A->atoms))\r
- {\r
- slang_assembly_typeinfo_destruct (&ti);\r
- return 0;\r
- }\r
+ goto end1;\r
\r
if (!slang_storage_aggregate_construct (&agg))\r
- {\r
- slang_assembly_typeinfo_destruct (&ti);\r
- return 0;\r
- }\r
+ goto end1;\r
if (!_slang_aggregate_variable (&agg, &ti.spec, NULL, A->space.funcs, A->space.structs,\r
A->space.vars, A->mach, A->file, A->atoms))\r
- {\r
- slang_storage_aggregate_destruct (&agg);\r
- slang_assembly_typeinfo_destruct (&ti);\r
- return 0;\r
- }\r
+ goto end;\r
\r
index = 0;\r
size = _slang_sizeof_aggregate (&agg);\r
- result = assign_aggregate (A->file, &agg, &index, size, &A->local, &A->swz);\r
+ result = assign_aggregate (A, &agg, &index, size);\r
\r
+end1:\r
slang_storage_aggregate_destruct (&agg);\r
+end:\r
slang_assembly_typeinfo_destruct (&ti);\r
return result;\r
}\r
\r
/*\r
- _slang_assemble_assign()\r
-\r
- performs unary (pre ++ and --) or binary (=, +=, -=, *=, /=) assignment on the operation's\r
- children\r
-*/\r
+ * _slang_assemble_assign()\r
+ *\r
+ * Performs unary (pre ++ and --) or binary (=, +=, -=, *=, /=) assignment on the operation's\r
+ * children.\r
+ */\r
\r
-int _slang_assemble_assign (slang_assemble_ctx *A, slang_operation *op, const char *oper,\r
+GLboolean _slang_assemble_assign (slang_assemble_ctx *A, slang_operation *op, const char *oper,\r
slang_ref_type ref)\r
{\r
- slang_assembly_stack_info stk;\r
+ slang_swizzle swz;\r
\r
if (ref == slang_ref_forbid)\r
{\r
if (!slang_assembly_file_push_label2 (A->file, slang_asm_local_addr, A->local.addr_tmp, 4))\r
- return 0;\r
+ return GL_FALSE;\r
}\r
\r
if (slang_string_compare ("=", oper) == 0)\r
{\r
if (!_slang_assemble_operation_ (A, &op->children[0], slang_ref_force))\r
- return 0;\r
- stk = A->swz;\r
+ return GL_FALSE;\r
+ swz = A->swz;\r
if (!_slang_assemble_operation_ (A, &op->children[1], slang_ref_forbid))\r
- return 0;\r
- A->swz = stk;\r
+ return GL_FALSE;\r
+ A->swz = swz;\r
if (!_slang_assemble_assignment (A, op->children))\r
- return 0;\r
+ return GL_FALSE;\r
}\r
else\r
{\r
if (!_slang_assemble_function_call_name (A, oper, op->children, op->num_children, GL_TRUE))\r
- return 0;\r
+ return GL_FALSE;\r
}\r
\r
if (ref == slang_ref_forbid)\r
{\r
if (!slang_assembly_file_push (A->file, slang_asm_addr_copy))\r
- return 0;\r
+ return GL_FALSE;\r
if (!slang_assembly_file_push_label (A->file, slang_asm_local_free, 4))\r
- return 0;\r
- if (!_slang_dereference (A->file, op->children, &A->space, &A->local, A->mach, A->atoms))\r
- return 0;\r
+ return GL_FALSE;\r
+ if (!_slang_dereference (A, op->children))\r
+ return GL_FALSE;\r
}\r
\r
- return 1;\r
+ return GL_TRUE;\r
}\r
\r
extern "C" {\r
#endif\r
\r
-int _slang_assemble_assignment (slang_assemble_ctx *, slang_operation *);\r
+GLboolean _slang_assemble_assignment (slang_assemble_ctx *, slang_operation *);\r
\r
-int _slang_assemble_assign (slang_assemble_ctx *, slang_operation *, const char *, slang_ref_type);\r
+GLboolean _slang_assemble_assign (slang_assemble_ctx *, slang_operation *, const char *,\r
+ slang_ref_type);\r
\r
#ifdef __cplusplus\r
}\r
#include "slang_assemble.h"\r
#include "slang_execute.h"\r
\r
-/* _slang_assemble_logicaland() */\r
+/*\r
+ * _slang_assemble_logicaland()\r
+ *\r
+ * and:\r
+ * <left-expression>\r
+ * jumpz zero\r
+ * <right-expression>\r
+ * jump end\r
+ * zero:\r
+ * push 0\r
+ * end:\r
+ */\r
\r
-int _slang_assemble_logicaland (slang_assembly_file *file, slang_operation *op,\r
- slang_assembly_flow_control *flow, slang_assembly_name_space *space,\r
- slang_assembly_local_info *info, slang_machine *mach, slang_atom_pool *atoms)\r
+GLboolean _slang_assemble_logicaland (slang_assemble_ctx *A, slang_operation *op)\r
{\r
- /*\r
- and:\r
- <left-expression>\r
- jumpz zero\r
- <right-expression>\r
- jump end\r
- zero:\r
- push 0\r
- end:\r
- */\r
-\r
- unsigned int zero_jump, end_jump;\r
- slang_assembly_stack_info stk;\r
+ GLuint zero_jump, end_jump;\r
\r
/* evaluate left expression */\r
- if (!_slang_assemble_operation (file, &op->children[0], 0, flow, space, info, &stk, mach, atoms))\r
- return 0;\r
- /* TODO: inspect stk */\r
+ if (!_slang_assemble_operation_ (A, &op->children[0], slang_ref_forbid))\r
+ return GL_FALSE;\r
\r
/* jump to pushing 0 if not true */\r
- zero_jump = file->count;\r
- if (!slang_assembly_file_push (file, slang_asm_jump_if_zero))\r
- return 0;\r
+ zero_jump = A->file->count;\r
+ if (!slang_assembly_file_push (A->file, slang_asm_jump_if_zero))\r
+ return GL_FALSE;\r
\r
/* evaluate right expression */\r
- if (!_slang_assemble_operation (file, &op->children[1], 0, flow, space, info, &stk, mach, atoms))\r
- return 0;\r
- /* TODO: inspect stk */\r
+ if (!_slang_assemble_operation_ (A, &op->children[1], slang_ref_forbid))\r
+ return GL_FALSE;\r
\r
/* jump to the end of the expression */\r
- end_jump = file->count;\r
- if (!slang_assembly_file_push (file, slang_asm_jump))\r
- return 0;\r
+ end_jump = A->file->count;\r
+ if (!slang_assembly_file_push (A->file, slang_asm_jump))\r
+ return GL_FALSE;\r
\r
/* push 0 on stack */\r
- file->code[zero_jump].param[0] = file->count;\r
- if (!slang_assembly_file_push_literal (file, slang_asm_bool_push, (GLfloat) 0))\r
- return 0;\r
+ A->file->code[zero_jump].param[0] = A->file->count;\r
+ if (!slang_assembly_file_push_literal (A->file, slang_asm_bool_push, (GLfloat) 0))\r
+ return GL_FALSE;\r
\r
/* the end of the expression */\r
- file->code[end_jump].param[0] = file->count;\r
+ A->file->code[end_jump].param[0] = A->file->count;\r
\r
- return 1;\r
+ return GL_TRUE;\r
}\r
\r
-/* _slang_assemble_logicalor() */\r
+/*\r
+ * _slang_assemble_logicalor()\r
+ *\r
+ * or:\r
+ * <left-expression>\r
+ * jumpz right\r
+ * push 1\r
+ * jump end\r
+ * right:\r
+ * <right-expression>\r
+ * end:\r
+ */\r
\r
-int _slang_assemble_logicalor (slang_assembly_file *file, slang_operation *op,\r
- slang_assembly_flow_control *flow, slang_assembly_name_space *space,\r
- slang_assembly_local_info *info, slang_machine *mach, slang_atom_pool *atoms)\r
+GLboolean _slang_assemble_logicalor (slang_assemble_ctx *A, slang_operation *op)\r
{\r
- /*\r
- or:\r
- <left-expression>\r
- jumpz right\r
- push 1\r
- jump end\r
- right:\r
- <right-expression>\r
- end:\r
- */\r
-\r
- unsigned int right_jump, end_jump;\r
- slang_assembly_stack_info stk;\r
+ GLuint right_jump, end_jump;\r
\r
/* evaluate left expression */\r
- if (!_slang_assemble_operation (file, &op->children[0], 0, flow, space, info, &stk, mach, atoms))\r
- return 0;\r
- /* TODO: inspect stk */\r
+ if (!_slang_assemble_operation_ (A, &op->children[0], slang_ref_forbid))\r
+ return GL_FALSE;\r
\r
/* jump to evaluation of right expression if not true */\r
- right_jump = file->count;\r
- if (!slang_assembly_file_push (file, slang_asm_jump_if_zero))\r
- return 0;\r
+ right_jump = A->file->count;\r
+ if (!slang_assembly_file_push (A->file, slang_asm_jump_if_zero))\r
+ return GL_FALSE;\r
\r
/* push 1 on stack */\r
- if (!slang_assembly_file_push_literal (file, slang_asm_bool_push, (GLfloat) 1))\r
- return 0;\r
+ if (!slang_assembly_file_push_literal (A->file, slang_asm_bool_push, (GLfloat) 1))\r
+ return GL_FALSE;\r
\r
/* jump to the end of the expression */\r
- end_jump = file->count;\r
- if (!slang_assembly_file_push (file, slang_asm_jump))\r
- return 0;\r
+ end_jump = A->file->count;\r
+ if (!slang_assembly_file_push (A->file, slang_asm_jump))\r
+ return GL_FALSE;\r
\r
/* evaluate right expression */\r
- file->code[right_jump].param[0] = file->count;\r
- if (!_slang_assemble_operation (file, &op->children[1], 0, flow, space, info, &stk, mach, atoms))\r
- return 0;\r
- /* TODO: inspect stk */\r
+ A->file->code[right_jump].param[0] = A->file->count;\r
+ if (!_slang_assemble_operation_ (A, &op->children[1], slang_ref_forbid))\r
+ return GL_FALSE;\r
\r
/* the end of the expression */\r
- file->code[end_jump].param[0] = file->count;\r
+ A->file->code[end_jump].param[0] = A->file->count;\r
\r
- return 1;\r
+ return GL_TRUE;\r
}\r
\r
-/* _slang_assemble_select() */\r
+/*\r
+ * _slang_assemble_select()\r
+ *\r
+ * select:\r
+ * <condition-expression>\r
+ * jumpz false\r
+ * <true-expression>\r
+ * jump end\r
+ * false:\r
+ * <false-expression>\r
+ * end:\r
+ */\r
\r
-int _slang_assemble_select (slang_assembly_file *file, slang_operation *op,\r
- slang_assembly_flow_control *flow, slang_assembly_name_space *space,\r
- slang_assembly_local_info *info, slang_machine *mach, slang_atom_pool *atoms)\r
+GLboolean _slang_assemble_select (slang_assemble_ctx *A, slang_operation *op)\r
{\r
- /*\r
- select:\r
- <condition-expression>\r
- jumpz false\r
- <true-expression>\r
- jump end\r
- false:\r
- <false-expression>\r
- end:\r
- */\r
-\r
- unsigned int cond_jump, end_jump;\r
- slang_assembly_stack_info stk;\r
+ GLuint cond_jump, end_jump;\r
\r
/* execute condition expression */\r
- if (!_slang_assemble_operation (file, &op->children[0], 0, flow, space, info, &stk, mach, atoms))\r
- return 0;\r
- /* TODO: inspect stk */\r
+ if (!_slang_assemble_operation_ (A, &op->children[0], slang_ref_forbid))\r
+ return GL_FALSE;\r
\r
/* jump to false expression if not true */\r
- cond_jump = file->count;\r
- if (!slang_assembly_file_push (file, slang_asm_jump_if_zero))\r
- return 0;\r
+ cond_jump = A->file->count;\r
+ if (!slang_assembly_file_push (A->file, slang_asm_jump_if_zero))\r
+ return GL_FALSE;\r
\r
/* execute true expression */\r
- if (!_slang_assemble_operation (file, &op->children[1], 0, flow, space, info, &stk, mach, atoms))\r
- return 0;\r
- /* TODO: inspect stk */\r
+ if (!_slang_assemble_operation_ (A, &op->children[1], slang_ref_forbid))\r
+ return GL_FALSE;\r
\r
/* jump to the end of the expression */\r
- end_jump = file->count;\r
- if (!slang_assembly_file_push (file, slang_asm_jump))\r
- return 0;\r
+ end_jump = A->file->count;\r
+ if (!slang_assembly_file_push (A->file, slang_asm_jump))\r
+ return GL_FALSE;\r
\r
/* resolve false point */\r
- file->code[cond_jump].param[0] = file->count;\r
+ A->file->code[cond_jump].param[0] = A->file->count;\r
\r
/* execute false expression */\r
- if (!_slang_assemble_operation (file, &op->children[2], 0, flow, space, info, &stk, mach, atoms))\r
- return 0;\r
- /* TODO: inspect stk */\r
+ if (!_slang_assemble_operation_ (A, &op->children[2], slang_ref_forbid))\r
+ return GL_FALSE;\r
\r
/* resolve the end of the expression */\r
- file->code[end_jump].param[0] = file->count;\r
+ A->file->code[end_jump].param[0] = A->file->count;\r
\r
- return 1;\r
+ return GL_TRUE;\r
}\r
\r
-/* _slang_assemble_for() */\r
+/*\r
+ * _slang_assemble_for()\r
+ *\r
+ * for:\r
+ * <init-statement>\r
+ * jump start\r
+ * break:\r
+ * jump end\r
+ * continue:\r
+ * <loop-increment>\r
+ * start:\r
+ * <condition-statement>\r
+ * jumpz end\r
+ * <loop-body>\r
+ * jump continue\r
+ * end:\r
+ */\r
\r
-int _slang_assemble_for (slang_assembly_file *file, slang_operation *op,\r
- slang_assembly_flow_control *flow, slang_assembly_name_space *space,\r
- slang_assembly_local_info *info, slang_machine *mach, slang_atom_pool *atoms)\r
+GLboolean _slang_assemble_for (slang_assemble_ctx *A, slang_operation *op)\r
{\r
- /*\r
- for:\r
- <init-statement>\r
- jump start\r
- break:\r
- jump end\r
- continue:\r
- <loop-increment>\r
- start:\r
- <condition-statement>\r
- jumpz end\r
- <loop-body>\r
- jump continue\r
- end:\r
- */\r
-\r
- unsigned int start_jump, end_jump, cond_jump;\r
- unsigned int break_label, cont_label;\r
- slang_assembly_flow_control loop_flow = *flow;\r
- slang_assembly_stack_info stk;\r
+ GLuint start_jump, end_jump, cond_jump;\r
+ GLuint break_label, cont_label;\r
+ slang_assembly_flow_control save_flow = A->flow;\r
\r
/* execute initialization statement */\r
- if (!_slang_assemble_operation (file, &op->children[0], 0, flow, space, info, &stk, mach, atoms))\r
- return 0;\r
- /* TODO: pass-in stk to cleanup */\r
- if (!_slang_cleanup_stack (file, &op->children[0], 0, space, mach, atoms))\r
- return 0;\r
+ if (!_slang_assemble_operation_ (A, &op->children[0], slang_ref_forbid/*slang_ref_freelance*/))\r
+ return GL_FALSE;\r
+ if (!_slang_cleanup_stack_ (A, &op->children[0]))\r
+ return GL_FALSE;\r
\r
/* skip the "go to the end of the loop" and loop-increment statements */\r
- start_jump = file->count;\r
- if (!slang_assembly_file_push (file, slang_asm_jump))\r
- return 0;\r
+ start_jump = A->file->count;\r
+ if (!slang_assembly_file_push (A->file, slang_asm_jump))\r
+ return GL_FALSE;\r
\r
/* go to the end of the loop - break statements are directed here */\r
- break_label = file->count;\r
- end_jump = file->count;\r
- if (!slang_assembly_file_push (file, slang_asm_jump))\r
- return 0;\r
+ break_label = A->file->count;\r
+ end_jump = A->file->count;\r
+ if (!slang_assembly_file_push (A->file, slang_asm_jump))\r
+ return GL_FALSE;\r
\r
/* resolve the beginning of the loop - continue statements are directed here */\r
- cont_label = file->count;\r
+ cont_label = A->file->count;\r
\r
/* execute loop-increment statement */\r
- if (!_slang_assemble_operation (file, &op->children[2], 0, flow, space, info, &stk, mach, atoms))\r
- return 0;\r
- /* TODO: pass-in stk to cleanup */\r
- if (!_slang_cleanup_stack (file, &op->children[2], 0, space, mach, atoms))\r
- return 0;\r
+ if (!_slang_assemble_operation_ (A, &op->children[2], slang_ref_forbid/*slang_ref_freelance*/))\r
+ return GL_FALSE;\r
+ if (!_slang_cleanup_stack_ (A, &op->children[2]))\r
+ return GL_FALSE;\r
\r
/* resolve the condition point */\r
- file->code[start_jump].param[0] = file->count;\r
+ A->file->code[start_jump].param[0] = A->file->count;\r
\r
/* execute condition statement */\r
- if (!_slang_assemble_operation (file, &op->children[1], 0, flow, space, info, &stk, mach, atoms))\r
- return 0;\r
- /* TODO: inspect stk */\r
+ if (!_slang_assemble_operation_ (A, &op->children[1], slang_ref_forbid))\r
+ return GL_FALSE;\r
\r
/* jump to the end of the loop if not true */\r
- cond_jump = file->count;\r
- if (!slang_assembly_file_push (file, slang_asm_jump_if_zero))\r
- return 0;\r
+ cond_jump = A->file->count;\r
+ if (!slang_assembly_file_push (A->file, slang_asm_jump_if_zero))\r
+ return GL_FALSE;\r
\r
/* execute loop body */\r
- loop_flow.loop_start = cont_label;\r
- loop_flow.loop_end = break_label;\r
- if (!_slang_assemble_operation (file, &op->children[3], 0, &loop_flow, space, info, &stk, mach, atoms))\r
- return 0;\r
- /* TODO: pass-in stk to cleanup */\r
- if (!_slang_cleanup_stack (file, &op->children[3], 0, space, mach, atoms))\r
- return 0;\r
+ A->flow.loop_start = cont_label;\r
+ A->flow.loop_end = break_label;\r
+ if (!_slang_assemble_operation_ (A, &op->children[3], slang_ref_forbid/*slang_ref_freelance*/))\r
+ return GL_FALSE;\r
+ if (!_slang_cleanup_stack_ (A, &op->children[3]))\r
+ return GL_FALSE;\r
+ A->flow = save_flow;\r
\r
/* go to the beginning of the loop */\r
- if (!slang_assembly_file_push_label (file, slang_asm_jump, cont_label))\r
- return 0;\r
+ if (!slang_assembly_file_push_label (A->file, slang_asm_jump, cont_label))\r
+ return GL_FALSE;\r
\r
/* resolve the end of the loop */\r
- file->code[end_jump].param[0] = file->count;\r
- file->code[cond_jump].param[0] = file->count;\r
+ A->file->code[end_jump].param[0] = A->file->count;\r
+ A->file->code[cond_jump].param[0] = A->file->count;\r
\r
- return 1;\r
+ return GL_TRUE;\r
}\r
\r
-/* _slang_assemble_do() */\r
+/*\r
+ * _slang_assemble_do()\r
+ *\r
+ * do:\r
+ * jump start\r
+ * break:\r
+ * jump end\r
+ * continue:\r
+ * jump condition\r
+ * start:\r
+ * <loop-body>\r
+ * condition:\r
+ * <condition-statement>\r
+ * jumpz end\r
+ * jump start\r
+ * end:\r
+ */\r
\r
-int _slang_assemble_do (slang_assembly_file *file, slang_operation *op,\r
- slang_assembly_flow_control *flow, slang_assembly_name_space *space,\r
- slang_assembly_local_info *info, slang_machine *mach, slang_atom_pool *atoms)\r
+GLboolean _slang_assemble_do (slang_assemble_ctx *A, slang_operation *op)\r
{\r
- /*\r
- do:\r
- jump start\r
- break:\r
- jump end\r
- continue:\r
- jump condition\r
- start:\r
- <loop-body>\r
- condition:\r
- <condition-statement>\r
- jumpz end\r
- jump start\r
- end:\r
- */\r
-\r
- unsigned int skip_jump, end_jump, cont_jump, cond_jump;\r
- unsigned int break_label, cont_label;\r
- slang_assembly_flow_control loop_flow = *flow;\r
- slang_assembly_stack_info stk;\r
+ GLuint skip_jump, end_jump, cont_jump, cond_jump;\r
+ GLuint break_label, cont_label;\r
+ slang_assembly_flow_control save_flow = A->flow;\r
\r
/* skip the "go to the end of the loop" and "go to condition" statements */\r
- skip_jump = file->count;\r
- if (!slang_assembly_file_push (file, slang_asm_jump))\r
- return 0;\r
+ skip_jump = A->file->count;\r
+ if (!slang_assembly_file_push (A->file, slang_asm_jump))\r
+ return GL_FALSE;\r
\r
/* go to the end of the loop - break statements are directed here */\r
- break_label = file->count;\r
- end_jump = file->count;\r
- if (!slang_assembly_file_push (file, slang_asm_jump))\r
- return 0;\r
+ break_label = A->file->count;\r
+ end_jump = A->file->count;\r
+ if (!slang_assembly_file_push (A->file, slang_asm_jump))\r
+ return GL_FALSE;\r
\r
/* go to condition - continue statements are directed here */\r
- cont_label = file->count;\r
- cont_jump = file->count;\r
- if (!slang_assembly_file_push (file, slang_asm_jump))\r
- return 0;\r
+ cont_label = A->file->count;\r
+ cont_jump = A->file->count;\r
+ if (!slang_assembly_file_push (A->file, slang_asm_jump))\r
+ return GL_FALSE;\r
\r
/* resolve the beginning of the loop */\r
- file->code[skip_jump].param[0] = file->count;\r
+ A->file->code[skip_jump].param[0] = A->file->count;\r
\r
/* execute loop body */\r
- loop_flow.loop_start = cont_label;\r
- loop_flow.loop_end = break_label;\r
- if (!_slang_assemble_operation (file, &op->children[0], 0, &loop_flow, space, info, &stk, mach, atoms))\r
- return 0;\r
- /* TODO: pass-in stk to cleanup */\r
- if (!_slang_cleanup_stack (file, &op->children[0], 0, space, mach, atoms))\r
- return 0;\r
+ A->flow.loop_start = cont_label;\r
+ A->flow.loop_end = break_label;\r
+ if (!_slang_assemble_operation_ (A, &op->children[0], slang_ref_forbid/*slang_ref_freelance*/))\r
+ return GL_FALSE;\r
+ if (!_slang_cleanup_stack_ (A, &op->children[0]))\r
+ return GL_FALSE;\r
+ A->flow = save_flow;\r
\r
/* resolve condition point */\r
- file->code[cont_jump].param[0] = file->count;\r
+ A->file->code[cont_jump].param[0] = A->file->count;\r
\r
/* execute condition statement */\r
- if (!_slang_assemble_operation (file, &op->children[1], 0, flow, space, info, &stk, mach, atoms))\r
- return 0;\r
- /* TODO: pass-in stk to cleanup */\r
+ if (!_slang_assemble_operation_ (A, &op->children[1], slang_ref_forbid))\r
+ return GL_FALSE;\r
\r
/* jump to the end of the loop if not true */\r
- cond_jump = file->count;\r
- if (!slang_assembly_file_push (file, slang_asm_jump_if_zero))\r
- return 0;\r
+ cond_jump = A->file->count;\r
+ if (!slang_assembly_file_push (A->file, slang_asm_jump_if_zero))\r
+ return GL_FALSE;\r
\r
/* jump to the beginning of the loop */\r
- if (!slang_assembly_file_push_label (file, slang_asm_jump, file->code[skip_jump].param[0]))\r
- return 0;\r
+ if (!slang_assembly_file_push_label (A->file, slang_asm_jump, A->file->code[skip_jump].param[0]))\r
+ return GL_FALSE;\r
\r
/* resolve the end of the loop */\r
- file->code[end_jump].param[0] = file->count;\r
- file->code[cond_jump].param[0] = file->count;\r
+ A->file->code[end_jump].param[0] = A->file->count;\r
+ A->file->code[cond_jump].param[0] = A->file->count;\r
\r
- return 1;\r
+ return GL_TRUE;\r
}\r
\r
-/* _slang_assemble_while() */\r
+/*\r
+ * _slang_assemble_while()\r
+ *\r
+ * while:\r
+ * jump continue\r
+ * break:\r
+ * jump end\r
+ * continue:\r
+ * <condition-statement>\r
+ * jumpz end\r
+ * <loop-body>\r
+ * jump continue\r
+ * end:\r
+ */\r
\r
-int _slang_assemble_while (slang_assembly_file *file, slang_operation *op,\r
- slang_assembly_flow_control *flow, slang_assembly_name_space *space,\r
- slang_assembly_local_info *info, slang_machine *mach, slang_atom_pool *atoms)\r
+GLboolean _slang_assemble_while (slang_assemble_ctx *A, slang_operation *op)\r
{\r
- /*\r
- while:\r
- jump continue\r
- break:\r
- jump end\r
- continue:\r
- <condition-statement>\r
- jumpz end\r
- <loop-body>\r
- jump continue\r
- end:\r
- */\r
-\r
- unsigned int skip_jump, end_jump, cond_jump;\r
- unsigned int break_label;\r
- slang_assembly_flow_control loop_flow = *flow;\r
- slang_assembly_stack_info stk;\r
+ GLuint skip_jump, end_jump, cond_jump;\r
+ GLuint break_label;\r
+ slang_assembly_flow_control save_flow = A->flow;\r
\r
/* skip the "go to the end of the loop" statement */\r
- skip_jump = file->count;\r
- if (!slang_assembly_file_push (file, slang_asm_jump))\r
- return 0;\r
+ skip_jump = A->file->count;\r
+ if (!slang_assembly_file_push (A->file, slang_asm_jump))\r
+ return GL_FALSE;\r
\r
/* go to the end of the loop - break statements are directed here */\r
- break_label = file->count;\r
- end_jump = file->count;\r
- if (!slang_assembly_file_push (file, slang_asm_jump))\r
- return 0;\r
+ break_label = A->file->count;\r
+ end_jump = A->file->count;\r
+ if (!slang_assembly_file_push (A->file, slang_asm_jump))\r
+ return GL_FALSE;\r
\r
/* resolve the beginning of the loop - continue statements are directed here */\r
- file->code[skip_jump].param[0] = file->count;\r
+ A->file->code[skip_jump].param[0] = A->file->count;\r
\r
/* execute condition statement */\r
- if (!_slang_assemble_operation (file, &op->children[0], 0, flow, space, info, &stk, mach, atoms))\r
- return 0;\r
- /* TODO: pass-in stk to cleanup */\r
+ if (!_slang_assemble_operation_ (A, &op->children[0], slang_ref_forbid))\r
+ return GL_FALSE;\r
\r
/* jump to the end of the loop if not true */\r
- cond_jump = file->count;\r
- if (!slang_assembly_file_push (file, slang_asm_jump_if_zero))\r
- return 0;\r
+ cond_jump = A->file->count;\r
+ if (!slang_assembly_file_push (A->file, slang_asm_jump_if_zero))\r
+ return GL_FALSE;\r
\r
/* execute loop body */\r
- loop_flow.loop_start = file->code[skip_jump].param[0];\r
- loop_flow.loop_end = break_label;\r
- if (!_slang_assemble_operation (file, &op->children[1], 0, &loop_flow, space, info, &stk, mach, atoms))\r
- return 0;\r
- /* TODO: pass-in stk to cleanup */\r
- if (!_slang_cleanup_stack (file, &op->children[1], 0, space, mach, atoms))\r
- return 0;\r
+ A->flow.loop_start = A->file->code[skip_jump].param[0];\r
+ A->flow.loop_end = break_label;\r
+ if (!_slang_assemble_operation_ (A, &op->children[1], slang_ref_forbid/*slang_ref_freelance*/))\r
+ return GL_FALSE;\r
+ if (!_slang_cleanup_stack_ (A, &op->children[1]))\r
+ return GL_FALSE;\r
+ A->flow = save_flow;\r
\r
/* jump to the beginning of the loop */\r
- if (!slang_assembly_file_push_label (file, slang_asm_jump, file->code[skip_jump].param[0]))\r
- return 0;\r
+ if (!slang_assembly_file_push_label (A->file, slang_asm_jump, A->file->code[skip_jump].param[0]))\r
+ return GL_FALSE;\r
\r
/* resolve the end of the loop */\r
- file->code[end_jump].param[0] = file->count;\r
- file->code[cond_jump].param[0] = file->count;\r
+ A->file->code[end_jump].param[0] = A->file->count;\r
+ A->file->code[cond_jump].param[0] = A->file->count;\r
\r
- return 1;\r
+ return GL_TRUE;\r
}\r
\r
-/* _slang_assemble_if() */\r
+/*\r
+ * _slang_assemble_if()\r
+ *\r
+ * if:\r
+ * <condition-statement>\r
+ * jumpz else\r
+ * <true-statement>\r
+ * jump end\r
+ * else:\r
+ * <false-statement>\r
+ * end:\r
+ */\r
\r
-int _slang_assemble_if (slang_assembly_file *file, slang_operation *op,\r
- slang_assembly_flow_control *flow, slang_assembly_name_space *space,\r
- slang_assembly_local_info *info, slang_machine *mach, slang_atom_pool *atoms)\r
+GLboolean _slang_assemble_if (slang_assemble_ctx *A, slang_operation *op)\r
{\r
- /*\r
- if:\r
- <condition-statement>\r
- jumpz else\r
- <true-statement>\r
- jump end\r
- else:\r
- <false-statement>\r
- end:\r
- */\r
-\r
- unsigned int cond_jump, else_jump;\r
- slang_assembly_stack_info stk;\r
+ GLuint cond_jump, else_jump;\r
\r
/* execute condition statement */\r
- if (!_slang_assemble_operation (file, &op->children[0], 0, flow, space, info, &stk, mach, atoms))\r
- return 0;\r
- /* TODO: pass-in stk to cleanup */\r
+ if (!_slang_assemble_operation_ (A, &op->children[0], slang_ref_forbid))\r
+ return GL_FALSE;\r
\r
/* jump to false-statement if not true */\r
- cond_jump = file->count;\r
- if (!slang_assembly_file_push (file, slang_asm_jump_if_zero))\r
- return 0;\r
+ cond_jump = A->file->count;\r
+ if (!slang_assembly_file_push (A->file, slang_asm_jump_if_zero))\r
+ return GL_FALSE;\r
\r
/* execute true-statement */\r
- if (!_slang_assemble_operation (file, &op->children[1], 0, flow, space, info, &stk, mach, atoms))\r
- return 0;\r
- /* TODO: pass-in stk to cleanup */\r
- if (!_slang_cleanup_stack (file, &op->children[1], 0, space, mach, atoms))\r
- return 0;\r
+ if (!_slang_assemble_operation_ (A, &op->children[1], slang_ref_forbid/*slang_ref_freelance*/))\r
+ return GL_FALSE;\r
+ if (!_slang_cleanup_stack_ (A, &op->children[1]))\r
+ return GL_FALSE;\r
\r
/* skip if-false statement */\r
- else_jump = file->count;\r
- if (!slang_assembly_file_push (file, slang_asm_jump))\r
- return 0;\r
+ else_jump = A->file->count;\r
+ if (!slang_assembly_file_push (A->file, slang_asm_jump))\r
+ return GL_FALSE;\r
\r
/* resolve start of false-statement */\r
- file->code[cond_jump].param[0] = file->count;\r
+ A->file->code[cond_jump].param[0] = A->file->count;\r
\r
/* execute false-statement */\r
- if (!_slang_assemble_operation (file, &op->children[2], 0, flow, space, info, &stk, mach, atoms))\r
- return 0;\r
- /* TODO: pass-in stk to cleanup */\r
- if (!_slang_cleanup_stack (file, &op->children[2], 0, space, mach, atoms))\r
- return 0;\r
+ if (!_slang_assemble_operation_ (A, &op->children[2], slang_ref_forbid/*slang_ref_freelance*/))\r
+ return GL_FALSE;\r
+ if (!_slang_cleanup_stack_ (A, &op->children[2]))\r
+ return GL_FALSE;\r
\r
/* resolve end of if-false statement */\r
- file->code[else_jump].param[0] = file->count;\r
+ A->file->code[else_jump].param[0] = A->file->count;\r
\r
- return 1;\r
+ return GL_TRUE;\r
}\r
\r
extern "C" {\r
#endif\r
\r
-int _slang_assemble_logicaland (slang_assembly_file *file, slang_operation *op,\r
- slang_assembly_flow_control *flow, slang_assembly_name_space *space,\r
- slang_assembly_local_info *info, struct slang_machine_ *, slang_atom_pool *);\r
+GLboolean _slang_assemble_logicaland (slang_assemble_ctx *, slang_operation *);\r
\r
-int _slang_assemble_logicalor (slang_assembly_file *file, slang_operation *op,\r
- slang_assembly_flow_control *flow, slang_assembly_name_space *space,\r
- slang_assembly_local_info *info, struct slang_machine_ *, slang_atom_pool *);\r
+GLboolean _slang_assemble_logicalor (slang_assemble_ctx *, slang_operation *);\r
\r
-int _slang_assemble_select (slang_assembly_file *file, slang_operation *op,\r
- slang_assembly_flow_control *flow, slang_assembly_name_space *space,\r
- slang_assembly_local_info *info, struct slang_machine_ *, slang_atom_pool *);\r
+GLboolean _slang_assemble_select (slang_assemble_ctx *, slang_operation *);\r
\r
-int _slang_assemble_for (slang_assembly_file *file, slang_operation *op,\r
- slang_assembly_flow_control *flow, slang_assembly_name_space *space,\r
- slang_assembly_local_info *info, struct slang_machine_ *, slang_atom_pool *);\r
+GLboolean _slang_assemble_for (slang_assemble_ctx *, slang_operation *);\r
\r
-int _slang_assemble_do (slang_assembly_file *file, slang_operation *op,\r
- slang_assembly_flow_control *flow, slang_assembly_name_space *space,\r
- slang_assembly_local_info *info, struct slang_machine_ *, slang_atom_pool *);\r
+GLboolean _slang_assemble_do (slang_assemble_ctx *, slang_operation *);\r
\r
-int _slang_assemble_while (slang_assembly_file *file, slang_operation *op,\r
- slang_assembly_flow_control *flow, slang_assembly_name_space *space,\r
- slang_assembly_local_info *info, struct slang_machine_ *, slang_atom_pool *);\r
+GLboolean _slang_assemble_while (slang_assemble_ctx *, slang_operation *);\r
\r
-int _slang_assemble_if (slang_assembly_file *file, slang_operation *op,\r
- slang_assembly_flow_control *flow, slang_assembly_name_space *space,\r
- slang_assembly_local_info *info, struct slang_machine_ *, slang_atom_pool *);\r
+GLboolean _slang_assemble_if (slang_assemble_ctx *, slang_operation *);\r
\r
#ifdef __cplusplus\r
}\r
\r
/* _slang_is_swizzle() */\r
\r
-int _slang_is_swizzle (const char *field, unsigned int rows, slang_swizzle *swz)\r
+GLboolean _slang_is_swizzle (const char *field, GLuint rows, slang_swizzle *swz)\r
{\r
- unsigned int i;\r
- int xyzw = 0, rgba = 0, stpq = 0;\r
+ GLuint i;\r
+ GLboolean xyzw = GL_FALSE, rgba = GL_FALSE, stpq = GL_FALSE;\r
\r
/* the swizzle can be at most 4-component long */\r
swz->num_components = slang_string_length (field);\r
if (swz->num_components > 4)\r
- return 0;\r
+ return GL_FALSE;\r
\r
for (i = 0; i < swz->num_components; i++)\r
{\r
case 'y':\r
case 'z':\r
case 'w':\r
- xyzw = 1;\r
+ xyzw = GL_TRUE;\r
break;\r
case 'r':\r
case 'g':\r
case 'b':\r
case 'a':\r
- rgba = 1;\r
+ rgba = GL_TRUE;\r
break;\r
case 's':\r
case 't':\r
case 'p':\r
case 'q':\r
- stpq = 1;\r
+ stpq = GL_TRUE;\r
break;\r
default:\r
- return 0;\r
+ return GL_FALSE;\r
}\r
\r
/* collect swizzle component */\r
\r
/* check if the component is valid for given vector's row count */\r
if (rows <= swz->swizzle[i])\r
- return 0;\r
+ return GL_FALSE;\r
}\r
\r
/* only one swizzle group can be used */\r
if ((xyzw && rgba) || (xyzw && stpq) || (rgba && stpq))\r
- return 0;\r
+ return GL_FALSE;\r
\r
- return 1;\r
+ return GL_TRUE;\r
}\r
\r
/* _slang_is_swizzle_mask() */\r
\r
-int _slang_is_swizzle_mask (const slang_swizzle *swz, unsigned int rows)\r
+GLboolean _slang_is_swizzle_mask (const slang_swizzle *swz, GLuint rows)\r
{\r
- unsigned int i, c = 0;\r
+ GLuint i, c = 0;\r
\r
/* the swizzle may not be longer than the vector dim */\r
if (swz->num_components > rows)\r
- return 0;\r
+ return GL_FALSE;\r
\r
/* the swizzle components cannot be duplicated */\r
for (i = 0; i < swz->num_components; i++)\r
{\r
if ((c & (1 << swz->swizzle[i])) != 0)\r
- return 0;\r
+ return GL_FALSE;\r
c |= 1 << swz->swizzle[i];\r
}\r
- return 1;\r
+\r
+ return GL_TRUE;\r
}\r
\r
/* _slang_multiply_swizzles() */\r
\r
-void _slang_multiply_swizzles (slang_swizzle *dst, const slang_swizzle *left,\r
+GLvoid _slang_multiply_swizzles (slang_swizzle *dst, const slang_swizzle *left,\r
const slang_swizzle *right)\r
{\r
- unsigned int i;\r
+ GLuint i;\r
\r
dst->num_components = right->num_components;\r
for (i = 0; i < right->num_components; i++)\r
}\r
\r
/* _slang_assemble_constructor() */\r
-#if 0\r
-static int constructor_aggregate (slang_assembly_file *file, const slang_storage_aggregate *flat,\r
- unsigned int *index, slang_operation *op, unsigned int size, slang_assembly_flow_control *flow,\r
- slang_assembly_name_space *space, slang_assembly_local_info *info)\r
+\r
+static GLboolean constructor_aggregate (slang_assemble_ctx *A, const slang_storage_aggregate *flat,\r
+ GLuint *index, slang_operation *op, GLuint size)\r
{\r
slang_assembly_typeinfo ti;\r
- int result;\r
+ GLboolean result = GL_FALSE;\r
slang_storage_aggregate agg, flat_agg;\r
- slang_assembly_stack_info stk;\r
- unsigned int i;\r
+ GLuint i;\r
\r
- slang_assembly_typeinfo_construct (&ti);\r
- if (!(result = _slang_typeof_operation (op, space, &ti)))\r
+ if (!slang_assembly_typeinfo_construct (&ti))\r
+ return GL_FALSE;\r
+ if (!_slang_typeof_operation (op, &A->space, &ti, A->atoms))\r
goto end1;\r
\r
- slang_storage_aggregate_construct (&agg);\r
- if (!(result = _slang_aggregate_variable (&agg, &ti.spec, NULL, space->funcs, space->structs,\r
- space->vars)))\r
+ if (!slang_storage_aggregate_construct (&agg))\r
+ goto end1;\r
+ if (!_slang_aggregate_variable (&agg, &ti.spec, NULL, A->space.funcs, A->space.structs,\r
+ A->space.vars, A->mach, A->file, A->atoms))\r
goto end2;\r
\r
- slang_storage_aggregate_construct (&flat_agg);\r
- if (!(result = _slang_flatten_aggregate (&flat_agg, &agg)))\r
+ if (!slang_storage_aggregate_construct (&flat_agg))\r
+ goto end2;\r
+ if (!_slang_flatten_aggregate (&flat_agg, &agg))\r
goto end;\r
\r
- if (!(result = _slang_assemble_operation (file, op, 0, flow, space, info, &stk)))\r
+ if (!_slang_assemble_operation_ (A, op, slang_ref_forbid))\r
goto end;\r
\r
for (i = 0; i < flat_agg.count; i++)\r
{\r
- const slang_storage_array *arr1 = flat_agg.arrays + i;\r
- const slang_storage_array *arr2 = flat->arrays + *index;\r
+ const slang_storage_array *arr1 = &flat_agg.arrays[i];\r
+ const slang_storage_array *arr2 = &flat->arrays[*index];\r
\r
if (arr1->type != arr2->type)\r
{\r
/* TODO: watch the index, if it reaches the size, pop off the stack subsequent values */\r
}\r
\r
- result = 1;\r
+ result = GL_TRUE;\r
end:\r
slang_storage_aggregate_destruct (&flat_agg);\r
end2:\r
slang_assembly_typeinfo_destruct (&ti);\r
return result;\r
}\r
-#endif\r
-\r
-/* XXX: general swizzle! */\r
\r
-#if 0\r
-int _slang_assemble_constructor (slang_assembly_file *file, slang_operation *op,\r
- slang_assembly_flow_control *flow, slang_assembly_name_space *space,\r
- slang_assembly_local_info *info, struct slang_machine_ *pmach)\r
+GLboolean _slang_assemble_constructor (slang_assemble_ctx *A, slang_operation *op)\r
{\r
slang_assembly_typeinfo ti;\r
- int result;\r
+ GLboolean result = GL_FALSE;\r
slang_storage_aggregate agg, flat;\r
- unsigned int size, index, i;\r
+ GLuint size, index, i;\r
\r
+ /* get typeinfo of the constructor (the result of constructor expression) */\r
if (!slang_assembly_typeinfo_construct (&ti))\r
- return 0;\r
- if (!(result = _slang_typeof_operation (op, space, &ti)))\r
+ return GL_FALSE;\r
+ if (!_slang_typeof_operation (op, &A->space, &ti, A->atoms))\r
goto end1;\r
\r
- if (!(result = slang_storage_aggregate_construct (&agg)))\r
+ /* create an aggregate of the constructor */\r
+ if (!slang_storage_aggregate_construct (&agg))\r
goto end1;\r
- if (!(result = _slang_aggregate_variable (&agg, &ti.spec, NULL, space->funcs, space->structs,\r
- space->vars, pmach, file)))\r
+ if (!_slang_aggregate_variable (&agg, &ti.spec, NULL, A->space.funcs, A->space.structs,\r
+ A->space.vars, A->mach, A->file, A->atoms))\r
goto end2;\r
\r
+ /* calculate size of the constructor */\r
size = _slang_sizeof_aggregate (&agg);\r
\r
- if (!(result = slang_storage_aggregate_construct (&flat)))\r
+ /* flatten the constructor */\r
+ if (!slang_storage_aggregate_construct (&flat))\r
goto end2;\r
- if (!(result = _slang_flatten_aggregate (&flat, &agg)))\r
+ if (!_slang_flatten_aggregate (&flat, &agg))\r
goto end;\r
\r
+ /* XXX: The children operations are traversed in a reversed order, so it poses a\r
+ * problem when there is more data than the constructor needs. We must fix it! */\r
+\r
+ /* traverse the children that form the constructor expression */\r
index = 0;\r
- for (i = 0; i < op->num_children; i++)\r
+ for (i = op->num_children; i > 0; i--)\r
{\r
- if (!(result = constructor_aggregate (file, &flat, &index, op->children + i, size, flow,\r
- space, info)))\r
+ if (!constructor_aggregate (A, &flat, &index, &op->children[i - 1], size))\r
goto end;\r
/* TODO: watch the index, if it reaches the size, raise an error */\r
}\r
\r
- result = 1;\r
+ result = GL_TRUE;\r
end:\r
slang_storage_aggregate_destruct (&flat);\r
end2:\r
slang_assembly_typeinfo_destruct (&ti);\r
return result;\r
}\r
-#endif\r
\r
/* _slang_assemble_constructor_from_swizzle() */\r
\r
-int _slang_assemble_constructor_from_swizzle (slang_assembly_file *file, const slang_swizzle *swz,\r
- slang_type_specifier *spec, slang_type_specifier *master_spec, slang_assembly_local_info *info)\r
+GLboolean _slang_assemble_constructor_from_swizzle (slang_assemble_ctx *A, const slang_swizzle *swz,\r
+ slang_type_specifier *spec, slang_type_specifier *master_spec)\r
{\r
- unsigned int master_rows, i;\r
+ GLuint master_rows, i;\r
\r
master_rows = _slang_type_dim (master_spec->type);\r
for (i = 0; i < master_rows; i++)\r
switch (_slang_type_base (master_spec->type))\r
{\r
case slang_spec_bool:\r
- if (!slang_assembly_file_push_label2 (file, slang_asm_bool_copy,\r
+ if (!slang_assembly_file_push_label2 (A->file, slang_asm_bool_copy,\r
(master_rows - i) * 4, i * 4))\r
- return 0;\r
+ return GL_FALSE;\r
break;\r
case slang_spec_int:\r
- if (!slang_assembly_file_push_label2 (file, slang_asm_int_copy,\r
+ if (!slang_assembly_file_push_label2 (A->file, slang_asm_int_copy,\r
(master_rows - i) * 4, i * 4))\r
- return 0;\r
+ return GL_FALSE;\r
break;\r
case slang_spec_float:\r
- if (!slang_assembly_file_push_label2 (file, slang_asm_float_copy,\r
+ if (!slang_assembly_file_push_label2 (A->file, slang_asm_float_copy,\r
(master_rows - i) * 4, i * 4))\r
- return 0;\r
+ return GL_FALSE;\r
break;\r
default:\r
break;\r
}\r
}\r
- if (!slang_assembly_file_push_label (file, slang_asm_local_free, 4))\r
- return 0;\r
+ if (!slang_assembly_file_push_label (A->file, slang_asm_local_free, 4))\r
+ return GL_FALSE;\r
for (i = swz->num_components; i > 0; i--)\r
{\r
- unsigned int n = i - 1;\r
-\r
- if (!slang_assembly_file_push_label2 (file, slang_asm_local_addr, info->swizzle_tmp, 16))\r
- return 0;\r
- if (!slang_assembly_file_push_label (file, slang_asm_addr_push, swz->swizzle[n] * 4))\r
- return 0;\r
- if (!slang_assembly_file_push (file, slang_asm_addr_add))\r
- return 0;\r
+ GLuint n = i - 1;\r
+\r
+ if (!slang_assembly_file_push_label2 (A->file, slang_asm_local_addr, A->local.swizzle_tmp, 16))\r
+ return GL_FALSE;\r
+ if (!slang_assembly_file_push_label (A->file, slang_asm_addr_push, swz->swizzle[n] * 4))\r
+ return GL_FALSE;\r
+ if (!slang_assembly_file_push (A->file, slang_asm_addr_add))\r
+ return GL_FALSE;\r
switch (_slang_type_base (master_spec->type))\r
{\r
case slang_spec_bool:\r
- if (!slang_assembly_file_push (file, slang_asm_bool_deref))\r
- return 0;\r
+ if (!slang_assembly_file_push (A->file, slang_asm_bool_deref))\r
+ return GL_FALSE;\r
break;\r
case slang_spec_int:\r
- if (!slang_assembly_file_push (file, slang_asm_int_deref))\r
- return 0;\r
+ if (!slang_assembly_file_push (A->file, slang_asm_int_deref))\r
+ return GL_FALSE;\r
break;\r
case slang_spec_float:\r
- if (!slang_assembly_file_push (file, slang_asm_float_deref))\r
- return 0;\r
+ if (!slang_assembly_file_push (A->file, slang_asm_float_deref))\r
+ return GL_FALSE;\r
break;\r
default:\r
break;\r
}\r
}\r
- return 1;\r
+\r
+ return GL_TRUE;\r
}\r
\r
#endif\r
\r
/*\r
- checks if a field selector is a general swizzle (an r-value swizzle with replicated\r
- components or an l-value swizzle mask) for a vector\r
- returns 1 if this is the case, <swz> is filled with swizzle information\r
- returns 0 otherwise\r
-*/\r
-int _slang_is_swizzle (const char *field, unsigned int rows, slang_swizzle *swz);\r
+ * Checks if a field selector is a general swizzle (an r-value swizzle with replicated\r
+ * components or an l-value swizzle mask) for a vector.\r
+ * Returns GL_TRUE if this is the case, <swz> is filled with swizzle information.\r
+ * Returns GL_FALSE otherwise.\r
+ */\r
+GLboolean _slang_is_swizzle (const char *field, GLuint rows, slang_swizzle *swz);\r
\r
/*\r
- checks if a general swizzle is an l-value swizzle - these swizzles do not have\r
- duplicated fields and they are specified in order\r
- returns 1 if this is a swizzle mask\r
- returns 0 otherwise\r
-*/\r
-int _slang_is_swizzle_mask (const slang_swizzle *swz, unsigned int rows);\r
+ * Checks if a general swizzle is an l-value swizzle - these swizzles do not have\r
+ * duplicated fields.\r
+ * Returns GL_TRUE if this is a swizzle mask.\r
+ * Returns GL_FALSE otherwise\r
+ */\r
+GLboolean _slang_is_swizzle_mask (const slang_swizzle *swz, GLuint rows);\r
\r
/*\r
- combines two swizzles to form single swizzle\r
- example: "wzyx.yx" --> "zw"\r
-*/\r
-void _slang_multiply_swizzles (slang_swizzle *, const slang_swizzle *, const slang_swizzle *);\r
+ * Combines (multiplies) two swizzles to form single swizzle.\r
+ * Example: "vec.wzyx.yx" --> "vec.zw".\r
+ */\r
+GLvoid _slang_multiply_swizzles (slang_swizzle *, const slang_swizzle *, const slang_swizzle *);\r
\r
-int _slang_assemble_constructor (slang_assembly_file *file, slang_operation *op,\r
- slang_assembly_flow_control *flow, slang_assembly_name_space *space,\r
- slang_assembly_local_info *info, struct slang_machine_ *);\r
+GLboolean _slang_assemble_constructor (slang_assemble_ctx *, slang_operation *);\r
\r
-int _slang_assemble_constructor_from_swizzle (slang_assembly_file *file, const slang_swizzle *swz,\r
- slang_type_specifier *spec, slang_type_specifier *master_spec, slang_assembly_local_info *info);\r
+GLboolean _slang_assemble_constructor_from_swizzle (slang_assemble_ctx *, const slang_swizzle *,\r
+ slang_type_specifier *, slang_type_specifier *);\r
\r
#ifdef __cplusplus\r
}\r
\r
/* slang_assembly_typeinfo */\r
\r
-int slang_assembly_typeinfo_construct (slang_assembly_typeinfo *ti)\r
+GLboolean slang_assembly_typeinfo_construct (slang_assembly_typeinfo *ti)\r
{\r
if (!slang_type_specifier_construct (&ti->spec))\r
- return 0;\r
+ return GL_FALSE;\r
ti->array_size = NULL;\r
- return 1;\r
+ return GL_TRUE;\r
}\r
\r
-void slang_assembly_typeinfo_destruct (slang_assembly_typeinfo *ti)\r
+GLvoid slang_assembly_typeinfo_destruct (slang_assembly_typeinfo *ti)\r
{\r
slang_type_specifier_destruct (&ti->spec);\r
/* do not free ti->array_size */\r
\r
/* _slang_typeof_operation() */\r
\r
-static int typeof_existing_function (const char *name, slang_operation *params,\r
- unsigned int num_params, slang_assembly_name_space *space, slang_type_specifier *spec,\r
+static GLboolean typeof_existing_function (const char *name, slang_operation *params,\r
+ GLuint num_params, slang_assembly_name_space *space, slang_type_specifier *spec,\r
slang_atom_pool *atoms)\r
{\r
slang_atom atom;\r
- int exists;\r
+ GLboolean exists;\r
\r
atom = slang_atom_pool_atom (atoms, name);\r
if (!_slang_typeof_function (atom, params, num_params, space, spec, &exists, atoms))\r
- return 0;\r
+ return GL_FALSE;\r
return exists;\r
}\r
\r
-int _slang_typeof_operation (slang_operation *op, slang_assembly_name_space *space,\r
+GLboolean _slang_typeof_operation (slang_operation *op, slang_assembly_name_space *space,\r
slang_assembly_typeinfo *ti, slang_atom_pool *atoms)\r
{\r
- ti->can_be_referenced = 0;\r
- ti->is_swizzled = 0;\r
+ ti->can_be_referenced = GL_FALSE;\r
+ ti->is_swizzled = GL_FALSE;\r
\r
switch (op->type)\r
{\r
{\r
slang_variable *var;\r
\r
- var = _slang_locate_variable (op->locals, op->a_id, 1);\r
+ var = _slang_locate_variable (op->locals, op->a_id, GL_TRUE);\r
if (var == NULL)\r
- return 0;\r
+ return GL_FALSE;\r
if (!slang_type_specifier_copy (&ti->spec, &var->type.specifier))\r
- return 0;\r
- ti->can_be_referenced = 1;\r
+ return GL_FALSE;\r
+ ti->can_be_referenced = GL_TRUE;\r
ti->array_size = var->array_size;\r
}\r
break;\r
case slang_oper_sequence:\r
/* TODO: check [0] and [1] if they match */\r
if (!_slang_typeof_operation (&op->children[1], space, ti, atoms))\r
- return 0;\r
- ti->can_be_referenced = 0;\r
- ti->is_swizzled = 0;\r
+ return GL_FALSE;\r
+ ti->can_be_referenced = GL_FALSE;\r
+ ti->is_swizzled = GL_FALSE;\r
break;\r
/*case slang_oper_modassign:*/\r
/*case slang_oper_lshassign:*/\r
case slang_oper_select:\r
/* TODO: check [1] and [2] if they match */\r
if (!_slang_typeof_operation (&op->children[1], space, ti, atoms))\r
- return 0;\r
- ti->can_be_referenced = 0;\r
- ti->is_swizzled = 0;\r
+ return GL_FALSE;\r
+ ti->can_be_referenced = GL_FALSE;\r
+ ti->is_swizzled = GL_FALSE;\r
break;\r
/*case slang_oper_bitor:*/\r
/*case slang_oper_bitxor:*/\r
/*case slang_oper_rshift:*/\r
case slang_oper_add:\r
if (!typeof_existing_function ("+", op->children, 2, space, &ti->spec, atoms))\r
- return 0;\r
+ return GL_FALSE;\r
break;\r
case slang_oper_subtract:\r
if (!typeof_existing_function ("-", op->children, 2, space, &ti->spec, atoms))\r
- return 0;\r
+ return GL_FALSE;\r
break;\r
case slang_oper_multiply:\r
if (!typeof_existing_function ("*", op->children, 2, space, &ti->spec, atoms))\r
- return 0;\r
+ return GL_FALSE;\r
break;\r
case slang_oper_divide:\r
if (!typeof_existing_function ("/", op->children, 2, space, &ti->spec, atoms))\r
- return 0;\r
+ return GL_FALSE;\r
break;\r
/*case slang_oper_modulus:*/\r
case slang_oper_plus:\r
if (!_slang_typeof_operation (op->children, space, ti, atoms))\r
- return 0;\r
- ti->can_be_referenced = 0;\r
- ti->is_swizzled = 0;\r
+ return GL_FALSE;\r
+ ti->can_be_referenced = GL_FALSE;\r
+ ti->is_swizzled = GL_FALSE;\r
break;\r
case slang_oper_minus:\r
if (!typeof_existing_function ("-", op->children, 1, space, &ti->spec, atoms))\r
- return 0;\r
+ return GL_FALSE;\r
break;\r
/*case slang_oper_complement:*/\r
case slang_oper_subscript:\r
slang_assembly_typeinfo _ti;\r
\r
if (!slang_assembly_typeinfo_construct (&_ti))\r
- return 0;\r
+ return GL_FALSE;\r
if (!_slang_typeof_operation (op->children, space, &_ti, atoms))\r
{\r
slang_assembly_typeinfo_destruct (&_ti);\r
- return 0;\r
+ return GL_FALSE;\r
}\r
ti->can_be_referenced = _ti.can_be_referenced;\r
if (_ti.spec.type == slang_spec_array)\r
if (!slang_type_specifier_copy (&ti->spec, _ti.spec._array))\r
{\r
slang_assembly_typeinfo_destruct (&_ti);\r
- return 0;\r
+ return GL_FALSE;\r
}\r
}\r
else\r
if (!_slang_type_is_vector (_ti.spec.type) && !_slang_type_is_matrix (_ti.spec.type))\r
{\r
slang_assembly_typeinfo_destruct (&_ti);\r
- return 0;\r
+ return GL_FALSE;\r
}\r
ti->spec.type = _slang_type_base (_ti.spec.type);\r
}\r
break;\r
case slang_oper_call:\r
{\r
- int exists;\r
+ GLboolean exists;\r
\r
if (!_slang_typeof_function (op->a_id, op->children, op->num_children, space, &ti->spec,\r
&exists, atoms))\r
- return 0;\r
+ return GL_FALSE;\r
if (!exists)\r
{\r
-/* slang_struct *s = slang_struct_scope_find (space->structs, op->identifier, 1);\r
+ slang_struct *s = slang_struct_scope_find (space->structs, op->a_id, GL_TRUE);\r
if (s != NULL)\r
{\r
ti->spec.type = slang_spec_struct;\r
ti->spec._struct = (slang_struct *) slang_alloc_malloc (sizeof (slang_struct));\r
if (ti->spec._struct == NULL)\r
- return 0;\r
+ return GL_FALSE;\r
if (!slang_struct_construct (ti->spec._struct))\r
{\r
slang_alloc_free (ti->spec._struct);\r
ti->spec._struct = NULL;\r
- return 0;\r
+ return GL_FALSE;\r
}\r
if (!slang_struct_copy (ti->spec._struct, s))\r
- return 0;\r
+ return GL_FALSE;\r
}\r
else\r
-*/ {\r
+ {\r
const char *name;\r
slang_type_specifier_type type;\r
\r
name = slang_atom_pool_id (atoms, op->a_id);\r
type = slang_type_specifier_type_from_string (name);\r
if (type == slang_spec_void)\r
- return 0;\r
+ return GL_FALSE;\r
ti->spec.type = type;\r
}\r
}\r
slang_assembly_typeinfo _ti;\r
\r
if (!slang_assembly_typeinfo_construct (&_ti))\r
- return 0;\r
+ return GL_FALSE;\r
if (!_slang_typeof_operation (op->children, space, &_ti, atoms))\r
{\r
slang_assembly_typeinfo_destruct (&_ti);\r
- return 0;\r
+ return GL_FALSE;\r
}\r
if (_ti.spec.type == slang_spec_struct)\r
{\r
slang_variable *field;\r
\r
- field = _slang_locate_variable (_ti.spec._struct->fields, op->a_id, 0);\r
+ field = _slang_locate_variable (_ti.spec._struct->fields, op->a_id, GL_FALSE);\r
if (field == NULL)\r
{\r
slang_assembly_typeinfo_destruct (&_ti);\r
- return 0;\r
+ return GL_FALSE;\r
}\r
if (!slang_type_specifier_copy (&ti->spec, &field->type.specifier))\r
{\r
slang_assembly_typeinfo_destruct (&_ti);\r
- return 0;\r
+ return GL_FALSE;\r
}\r
ti->can_be_referenced = _ti.can_be_referenced;\r
}\r
else\r
{\r
- unsigned int rows;\r
+ GLuint rows;\r
const char *swizzle;\r
slang_type_specifier_type base;\r
\r
if (!_slang_type_is_vector (_ti.spec.type))\r
{\r
slang_assembly_typeinfo_destruct (&_ti);\r
- return 0;\r
+ return GL_FALSE;\r
}\r
rows = _slang_type_dim (_ti.spec.type);\r
swizzle = slang_atom_pool_id (atoms, op->a_id);\r
if (!_slang_is_swizzle (swizzle, rows, &ti->swz))\r
{\r
slang_assembly_typeinfo_destruct (&_ti);\r
- return 0;\r
+ return GL_FALSE;\r
}\r
- ti->is_swizzled = 1;\r
+ ti->is_swizzled = GL_TRUE;\r
ti->can_be_referenced = _ti.can_be_referenced && _slang_is_swizzle_mask (&ti->swz,\r
rows);\r
if (_ti.is_swizzled)\r
ti->spec.type = slang_spec_bvec2;\r
break;\r
default:\r
- _mesa_problem(NULL, "unexepected base in _slang_typeof_operation");\r
- ti->spec.type = slang_spec_void;\r
+ break;\r
}\r
break;\r
case 3:\r
ti->spec.type = slang_spec_bvec3;\r
break;\r
default:\r
- _mesa_problem(NULL, "unexepected base in _slang_typeof_operation");\r
- ti->spec.type = slang_spec_void;\r
+ break;\r
}\r
break;\r
case 4:\r
ti->spec.type = slang_spec_bvec4;\r
break;\r
default:\r
- _mesa_problem(NULL, "unexepected base in _slang_typeof_operation");\r
- ti->spec.type = slang_spec_void;\r
+ break;\r
}\r
break;\r
default:\r
case slang_oper_postincrement:\r
case slang_oper_postdecrement:\r
if (!_slang_typeof_operation (op->children, space, ti, atoms))\r
- return 0;\r
- ti->can_be_referenced = 0;\r
- ti->is_swizzled = 0;\r
+ return GL_FALSE;\r
+ ti->can_be_referenced = GL_FALSE;\r
+ ti->is_swizzled = GL_FALSE;\r
break;\r
default:\r
- return 0;\r
+ return GL_FALSE;\r
}\r
- return 1;\r
+\r
+ return GL_TRUE;\r
}\r
\r
/* _slang_typeof_function() */\r
\r
-int _slang_typeof_function (slang_atom a_name, slang_operation *params, unsigned int num_params,\r
- slang_assembly_name_space *space, slang_type_specifier *spec, int *exists, slang_atom_pool *atoms)\r
+GLboolean _slang_typeof_function (slang_atom a_name, slang_operation *params, GLuint num_params,\r
+ slang_assembly_name_space *space, slang_type_specifier *spec, GLboolean *exists,\r
+ slang_atom_pool *atoms)\r
{\r
slang_function *fun;\r
\r
fun = _slang_locate_function (space->funcs, a_name, params, num_params, space, atoms);\r
*exists = fun != NULL;\r
if (fun == NULL)\r
- return 1;\r
+ return GL_TRUE;\r
return slang_type_specifier_copy (spec, &fun->header.type.specifier);\r
}\r
\r
/* _slang_type_is_matrix() */\r
\r
-int _slang_type_is_matrix (slang_type_specifier_type ty)\r
+GLboolean _slang_type_is_matrix (slang_type_specifier_type ty)\r
{\r
switch (ty)\r
{\r
case slang_spec_mat2:\r
case slang_spec_mat3:\r
case slang_spec_mat4:\r
- return 1;\r
+ return GL_TRUE;\r
default:\r
- return 0;\r
+ return GL_FALSE;\r
}\r
}\r
\r
/* _slang_type_is_vector() */\r
\r
-int _slang_type_is_vector (slang_type_specifier_type ty)\r
+GLboolean _slang_type_is_vector (slang_type_specifier_type ty)\r
{\r
switch (ty)\r
{\r
case slang_spec_bvec2:\r
case slang_spec_bvec3:\r
case slang_spec_bvec4:\r
- return 1;\r
+ return GL_TRUE;\r
default:\r
- return 0;\r
+ return GL_FALSE;\r
}\r
}\r
\r
\r
/* _slang_type_dim */\r
\r
-unsigned int _slang_type_dim (slang_type_specifier_type ty)\r
+GLuint _slang_type_dim (slang_type_specifier_type ty)\r
{\r
switch (ty)\r
{\r
\r
typedef struct slang_assembly_typeinfo_\r
{\r
- int can_be_referenced;\r
- int is_swizzled;\r
+ GLboolean can_be_referenced;\r
+ GLboolean is_swizzled;\r
slang_swizzle swz;\r
slang_type_specifier spec;\r
slang_operation *array_size;\r
} slang_assembly_typeinfo;\r
\r
-int slang_assembly_typeinfo_construct (slang_assembly_typeinfo *);\r
-void slang_assembly_typeinfo_destruct (slang_assembly_typeinfo *);\r
+GLboolean slang_assembly_typeinfo_construct (slang_assembly_typeinfo *);\r
+GLvoid slang_assembly_typeinfo_destruct (slang_assembly_typeinfo *);\r
\r
/*\r
- retrieves type information about an operation\r
- returns 1 on success\r
- returns 0 otherwise\r
-*/\r
-int _slang_typeof_operation (slang_operation *, slang_assembly_name_space *,\r
+ * Retrieves type information about an operation.\r
+ * Returns GL_TRUE on success.\r
+ * Returns GL_FALSE otherwise.\r
+ */\r
+GLboolean _slang_typeof_operation (slang_operation *, slang_assembly_name_space *,\r
slang_assembly_typeinfo *, slang_atom_pool *);\r
\r
/*\r
- retrieves type of a function prototype, if one exists\r
- returns 1 on success, even if the function was not found\r
- returns 0 otherwise\r
-*/\r
-int _slang_typeof_function (slang_atom a_name, slang_operation *params, unsigned int num_params,\r
- slang_assembly_name_space *space, slang_type_specifier *spec, int *exists, slang_atom_pool *);\r
+ * Retrieves type of a function prototype, if one exists.\r
+ * Returns GL_TRUE on success, even if the function was not found.\r
+ * Returns GL_FALSE otherwise.\r
+ */\r
+GLboolean _slang_typeof_function (slang_atom a_name, slang_operation *params, GLuint num_params,\r
+ slang_assembly_name_space *, slang_type_specifier *spec, GLboolean *exists, slang_atom_pool *);\r
+\r
+GLboolean _slang_type_is_matrix (slang_type_specifier_type);\r
+\r
+GLboolean _slang_type_is_vector (slang_type_specifier_type);\r
\r
-int _slang_type_is_matrix (slang_type_specifier_type);\r
-int _slang_type_is_vector (slang_type_specifier_type);\r
slang_type_specifier_type _slang_type_base (slang_type_specifier_type);\r
-unsigned int _slang_type_dim (slang_type_specifier_type);\r
+\r
+GLuint _slang_type_dim (slang_type_specifier_type);\r
\r
#ifdef __cplusplus\r
}\r
* slang front-end compiler
* \author Michal Krol
*/
-\r
-#include "imports.h"\r
-#include "grammar_mesa.h"\r
+
+#include "imports.h"
+#include "grammar_mesa.h"
#include "slang_utility.h"
#include "slang_compile.h"
#include "slang_preprocess.h"
-#include "slang_storage.h"\r
-#include "slang_assemble.h"\r
-#include "slang_execute.h"\r
+#include "slang_storage.h"
+#include "slang_assemble.h"
+#include "slang_execute.h"
/*
- This is a straightforward implementation of the slang front-end compiler.
- Lots of error-checking functionality is missing but every well-formed shader source should
- compile successfully and execute as expected. However, some semantically ill-formed shaders
- may be accepted resulting in undefined behaviour.
-*/\r
-\r
-/* slang_var_pool */\r
-\r
-static GLuint slang_var_pool_alloc (slang_var_pool *pool, unsigned int size)\r
-{\r
- GLuint addr;\r
-\r
- addr = pool->next_addr;\r
- pool->next_addr += size;\r
- return addr;\r
+ * This is a straightforward implementation of the slang front-end compiler.
+ * Lots of error-checking functionality is missing but every well-formed shader source should
+ * compile successfully and execute as expected. However, some semantically ill-formed shaders
+ * may be accepted resulting in undefined behaviour.
+ */
+
+/* slang_var_pool */
+
+static GLuint slang_var_pool_alloc (slang_var_pool *pool, unsigned int size)
+{
+ GLuint addr;
+
+ addr = pool->next_addr;
+ pool->next_addr += size;
+ return addr;
}
/* slang_translation_unit */
int slang_translation_unit_construct (slang_translation_unit *unit)
{
- unit->assembly = (slang_assembly_file *) slang_alloc_malloc (sizeof (slang_assembly_file));\r
- if (unit->assembly == NULL)\r
- return 0;\r
- if (!slang_assembly_file_construct (unit->assembly))\r
- {\r
- slang_alloc_free (unit->assembly);\r
- return 0;\r
- }\r
- unit->global_pool = (slang_var_pool *) slang_alloc_malloc (sizeof (slang_var_pool));\r
- if (unit->global_pool == NULL)\r
- {\r
- slang_assembly_file_destruct (unit->assembly);\r
- slang_alloc_free (unit->assembly);\r
- return 0;\r
- }\r
- unit->global_pool->next_addr = 0;\r
- unit->machine = (slang_machine *) slang_alloc_malloc (sizeof (slang_machine));\r
- if (unit->machine == NULL)\r
- {\r
- slang_alloc_free (unit->global_pool);\r
- slang_assembly_file_destruct (unit->assembly);\r
- slang_alloc_free (unit->assembly);\r
- return 0;\r
- }\r
- slang_machine_init (unit->machine);\r
- unit->atom_pool = (slang_atom_pool *) slang_alloc_malloc (sizeof (slang_atom_pool));\r
- if (unit->atom_pool == NULL)\r
- {\r
- slang_alloc_free (unit->machine);\r
- slang_alloc_free (unit->global_pool);\r
- slang_assembly_file_destruct (unit->assembly);\r
- slang_alloc_free (unit->assembly);\r
- return 0;\r
- }\r
- slang_atom_pool_construct (unit->atom_pool);\r
- if (!slang_translation_unit_construct2 (unit, unit->assembly, unit->global_pool, unit->machine,\r
- unit->atom_pool))\r
- {\r
- slang_alloc_free (unit->atom_pool);\r
- slang_alloc_free (unit->machine);\r
- slang_alloc_free (unit->global_pool);\r
- slang_assembly_file_destruct (unit->assembly);\r
- slang_alloc_free (unit->assembly);\r
- return 0;\r
- }\r
- unit->free_assembly = 1;\r
- unit->free_global_pool = 1;\r
- unit->free_machine = 1;\r
- unit->free_atom_pool = 1;\r
+ unit->assembly = (slang_assembly_file *) slang_alloc_malloc (sizeof (slang_assembly_file));
+ if (unit->assembly == NULL)
+ return 0;
+ if (!slang_assembly_file_construct (unit->assembly))
+ {
+ slang_alloc_free (unit->assembly);
+ return 0;
+ }
+ unit->global_pool = (slang_var_pool *) slang_alloc_malloc (sizeof (slang_var_pool));
+ if (unit->global_pool == NULL)
+ {
+ slang_assembly_file_destruct (unit->assembly);
+ slang_alloc_free (unit->assembly);
+ return 0;
+ }
+ unit->global_pool->next_addr = 0;
+ unit->machine = (slang_machine *) slang_alloc_malloc (sizeof (slang_machine));
+ if (unit->machine == NULL)
+ {
+ slang_alloc_free (unit->global_pool);
+ slang_assembly_file_destruct (unit->assembly);
+ slang_alloc_free (unit->assembly);
+ return 0;
+ }
+ slang_machine_init (unit->machine);
+ unit->atom_pool = (slang_atom_pool *) slang_alloc_malloc (sizeof (slang_atom_pool));
+ if (unit->atom_pool == NULL)
+ {
+ slang_alloc_free (unit->machine);
+ slang_alloc_free (unit->global_pool);
+ slang_assembly_file_destruct (unit->assembly);
+ slang_alloc_free (unit->assembly);
+ return 0;
+ }
+ slang_atom_pool_construct (unit->atom_pool);
+ if (!slang_translation_unit_construct2 (unit, unit->assembly, unit->global_pool, unit->machine,
+ unit->atom_pool))
+ {
+ slang_alloc_free (unit->atom_pool);
+ slang_alloc_free (unit->machine);
+ slang_alloc_free (unit->global_pool);
+ slang_assembly_file_destruct (unit->assembly);
+ slang_alloc_free (unit->assembly);
+ return 0;
+ }
+ unit->free_assembly = 1;
+ unit->free_global_pool = 1;
+ unit->free_machine = 1;
+ unit->free_atom_pool = 1;
+ return 1;
+}
+
+int slang_translation_unit_construct2 (slang_translation_unit *unit, slang_assembly_file *file,
+ slang_var_pool *pool, struct slang_machine_ *mach, slang_atom_pool *atoms)
+{
+ if (!slang_variable_scope_construct (&unit->globals))
+ return 0;
+ if (!slang_function_scope_construct (&unit->functions))
+ {
+ slang_variable_scope_destruct (&unit->globals);
+ return 0;
+ }
+ if (!slang_struct_scope_construct (&unit->structs))
+ {
+ slang_variable_scope_destruct (&unit->globals);
+ slang_function_scope_destruct (&unit->functions);
+ return 0;
+ }
+ unit->assembly = file;
+ unit->free_assembly = 0;
+ unit->global_pool = pool;
+ unit->free_global_pool = 0;
+ unit->machine = mach;
+ unit->free_machine = 0;
+ unit->atom_pool = atoms;
+ unit->free_atom_pool = 0;
return 1;
-}\r
-\r
-int slang_translation_unit_construct2 (slang_translation_unit *unit, slang_assembly_file *file,\r
- slang_var_pool *pool, struct slang_machine_ *mach, slang_atom_pool *atoms)\r
-{\r
- if (!slang_variable_scope_construct (&unit->globals))\r
- return 0;\r
- if (!slang_function_scope_construct (&unit->functions))\r
- {\r
- slang_variable_scope_destruct (&unit->globals);\r
- return 0;\r
- }\r
- if (!slang_struct_scope_construct (&unit->structs))\r
- {\r
- slang_variable_scope_destruct (&unit->globals);\r
- slang_function_scope_destruct (&unit->functions);\r
- return 0;\r
- }\r
- unit->assembly = file;\r
- unit->free_assembly = 0;\r
- unit->global_pool = pool;\r
- unit->free_global_pool = 0;\r
- unit->machine = mach;\r
- unit->free_machine = 0;\r
- unit->atom_pool = atoms;\r
- unit->free_atom_pool = 0;\r
- return 1;\r
}
void slang_translation_unit_destruct (slang_translation_unit *unit)
{
slang_variable_scope_destruct (&unit->globals);
slang_function_scope_destruct (&unit->functions);
- slang_struct_scope_destruct (&unit->structs);\r
- if (unit->free_assembly)\r
- {\r
- slang_assembly_file_destruct (unit->assembly);\r
- slang_alloc_free (unit->assembly);\r
- }\r
- if (unit->free_global_pool)\r
- slang_alloc_free (unit->global_pool);\r
- if (unit->free_machine)\r
- slang_alloc_free (unit->machine);\r
- if (unit->free_atom_pool)\r
- {\r
- slang_atom_pool_destruct (unit->atom_pool);\r
- slang_alloc_free (unit->atom_pool);\r
+ slang_struct_scope_destruct (&unit->structs);
+ if (unit->free_assembly)
+ {
+ slang_assembly_file_destruct (unit->assembly);
+ slang_alloc_free (unit->assembly);
+ }
+ if (unit->free_global_pool)
+ slang_alloc_free (unit->global_pool);
+ if (unit->free_machine)
+ slang_alloc_free (unit->machine);
+ if (unit->free_atom_pool)
+ {
+ slang_atom_pool_destruct (unit->atom_pool);
+ slang_alloc_free (unit->atom_pool);
}
}
static int slang_info_log_message (slang_info_log *log, const char *prefix, const char *msg)
{
- unsigned int new_size;\r
+ unsigned int new_size;
if (log->dont_free_text)
return 0;
new_size = slang_string_length (prefix) + 3 + slang_string_length (msg);
if (log->text != NULL)
- {\r
- unsigned int text_len = slang_string_length (log->text);\r
+ {
+ unsigned int text_len = slang_string_length (log->text);
log->text = (char *) slang_alloc_realloc (log->text, text_len + 1, new_size + text_len + 1);
}
{
const byte *I;
slang_info_log *L;
- int parsing_builtin;\r
- int global_scope;\r
+ int parsing_builtin;
+ int global_scope;
slang_atom_pool *atoms;
-} slang_parse_ctx;\r
-\r
-/* slang_output_ctx */\r
-\r
-typedef struct slang_output_ctx_\r
-{\r
- slang_variable_scope *vars;\r
- slang_function_scope *funs;\r
- slang_struct_scope *structs;\r
- slang_assembly_file *assembly;\r
- slang_var_pool *global_pool;\r
- slang_machine *machine;\r
+} slang_parse_ctx;
+
+/* slang_output_ctx */
+
+typedef struct slang_output_ctx_
+{
+ slang_variable_scope *vars;
+ slang_function_scope *funs;
+ slang_struct_scope *structs;
+ slang_assembly_file *assembly;
+ slang_var_pool *global_pool;
+ slang_machine *machine;
} slang_output_ctx;
/* _slang_compile() */
static void parse_identifier_str (slang_parse_ctx *C, char **id)
{
- *id = (char *) C->I;\r
+ *id = (char *) C->I;
C->I += _mesa_strlen (*id) + 1;
-}\r
-\r
-static slang_atom parse_identifier (slang_parse_ctx *C)\r
-{\r
- const char *id;\r
- \r
- id = (const char *) C->I;\r
- C->I += _mesa_strlen (id) + 1;\r
- return slang_atom_pool_atom (C->atoms, id);\r
+}
+
+static slang_atom parse_identifier (slang_parse_ctx *C)
+{
+ const char *id;
+
+ id = (const char *) C->I;
+ C->I += _mesa_strlen (id) + 1;
+ return slang_atom_pool_atom (C->atoms, id);
}
static int parse_number (slang_parse_ctx *C, int *number)
parse_identifier_str (C, &integral);
parse_identifier_str (C, &fractional);
- parse_identifier_str (C, &exponent);\r
+ parse_identifier_str (C, &exponent);
- whole = (char *) (slang_alloc_malloc ((_mesa_strlen (integral) + _mesa_strlen (fractional) +\r
+ whole = (char *) (slang_alloc_malloc ((_mesa_strlen (integral) + _mesa_strlen (fractional) +
_mesa_strlen (exponent) + 3) * sizeof (char)));
if (whole == NULL)
{
}
static int parse_statement (slang_parse_ctx *, slang_output_ctx *, slang_operation *);
-static int parse_expression (slang_parse_ctx *, slang_output_ctx *, slang_operation *);\r
-static int parse_type_specifier (slang_parse_ctx *, slang_output_ctx *, slang_type_specifier *);\r
-\r
-/* structure field */\r
-#define FIELD_NONE 0\r
-#define FIELD_NEXT 1\r
-#define FIELD_ARRAY 2\r
-\r
-static int parse_struct_field_var (slang_parse_ctx *C, slang_output_ctx *O, slang_variable *var)\r
-{\r
- var->a_name = parse_identifier (C);\r
- if (var->a_name == SLANG_ATOM_NULL)\r
- return 0;\r
-\r
- switch (*C->I++)\r
- {\r
- case FIELD_NONE:\r
- break;\r
- case FIELD_ARRAY:\r
- var->array_size = (slang_operation *) slang_alloc_malloc (sizeof (slang_operation));\r
- if (var->array_size == NULL)\r
- {\r
- slang_info_log_memory (C->L);\r
- return 0;\r
- }\r
- if (!slang_operation_construct (var->array_size))\r
- {\r
- slang_alloc_free (var->array_size);\r
- var->array_size = NULL;\r
- return 0;\r
- }\r
- if (!parse_expression (C, O, var->array_size))\r
- return 0;\r
- break;\r
- default:\r
- return 0;\r
- }\r
-\r
- return 1;\r
-}\r
-\r
-static int parse_struct_field (slang_parse_ctx *C, slang_output_ctx *O, slang_struct *st,\r
- slang_type_specifier *sp)\r
-{\r
- slang_output_ctx o = *O;\r
-\r
- o.structs = st->structs;\r
- if (!parse_type_specifier (C, &o, sp))\r
- return 0;\r
- do\r
- {\r
- slang_variable *var;\r
-\r
- st->fields->variables = (slang_variable *) slang_alloc_realloc (st->fields->variables,\r
- st->fields->num_variables * sizeof (slang_variable),\r
- (st->fields->num_variables + 1) * sizeof (slang_variable));\r
- if (st->fields->variables == NULL)\r
- {\r
- slang_info_log_memory (C->L);\r
- return 0;\r
- }\r
- var = &st->fields->variables[st->fields->num_variables];\r
- if (!slang_variable_construct (var))\r
- return 0;\r
- st->fields->num_variables++;\r
- if (!slang_type_specifier_copy (&var->type.specifier, sp))\r
- return 0;\r
- if (!parse_struct_field_var (C, &o, var))\r
- return 0;\r
- }\r
- while (*C->I++ != FIELD_NONE);\r
-\r
- return 1;\r
-}\r
-\r
-static int parse_struct (slang_parse_ctx *C, slang_output_ctx *O, slang_struct **st)\r
-{\r
- slang_atom a_name;\r
- const char *name;\r
-\r
- /* parse struct name (if any) and make sure it is unique in current scope */\r
- a_name = parse_identifier (C);\r
- if (a_name == SLANG_ATOM_NULL)\r
- return 0;\r
- name = slang_atom_pool_id (C->atoms, a_name);\r
- if (name[0] != '\0' && slang_struct_scope_find (O->structs, a_name, 0) != NULL)\r
- {\r
- slang_info_log_error (C->L, "%s: duplicate type name", name);\r
- return 0;\r
- }\r
-\r
- /* set-up a new struct */\r
- *st = (slang_struct *) slang_alloc_malloc (sizeof (slang_struct));\r
- if (*st == NULL)\r
- {\r
- slang_info_log_memory (C->L);\r
- return 0;\r
- }\r
- if (!slang_struct_construct (*st))\r
- {\r
- slang_alloc_free (*st);\r
- *st = NULL;\r
- slang_info_log_memory (C->L);\r
- return 0;\r
- }\r
- (**st).a_name = a_name;\r
- (**st).structs->outer_scope = O->structs;\r
-\r
- /* parse individual struct fields */\r
- do\r
- {\r
- slang_type_specifier sp;\r
-\r
- if (!slang_type_specifier_construct (&sp))\r
- return 0;\r
- if (!parse_struct_field (C, O, *st, &sp))\r
- {\r
- slang_type_specifier_destruct (&sp);\r
- return 0;\r
- }\r
- }\r
- while (*C->I++ != FIELD_NONE);\r
-\r
- /* if named struct, copy it to current scope */\r
- if (name[0] != '\0')\r
- {\r
- slang_struct *s;\r
-\r
- O->structs->structs = (slang_struct *) slang_alloc_realloc (O->structs->structs,\r
- O->structs->num_structs * sizeof (slang_struct),\r
- (O->structs->num_structs + 1) * sizeof (slang_struct));\r
- if (O->structs->structs == NULL)\r
- {\r
- slang_info_log_memory (C->L);\r
- return 0;\r
- }\r
- s = &O->structs->structs[O->structs->num_structs];\r
- if (!slang_struct_construct (s))\r
- return 0;\r
- O->structs->num_structs++;\r
- if (!slang_struct_copy (s, *st))\r
- return 0;\r
- }\r
-\r
- return 1;\r
+static int parse_expression (slang_parse_ctx *, slang_output_ctx *, slang_operation *);
+static int parse_type_specifier (slang_parse_ctx *, slang_output_ctx *, slang_type_specifier *);
+
+/* structure field */
+#define FIELD_NONE 0
+#define FIELD_NEXT 1
+#define FIELD_ARRAY 2
+
+static int parse_struct_field_var (slang_parse_ctx *C, slang_output_ctx *O, slang_variable *var)
+{
+ var->a_name = parse_identifier (C);
+ if (var->a_name == SLANG_ATOM_NULL)
+ return 0;
+
+ switch (*C->I++)
+ {
+ case FIELD_NONE:
+ break;
+ case FIELD_ARRAY:
+ var->array_size = (slang_operation *) slang_alloc_malloc (sizeof (slang_operation));
+ if (var->array_size == NULL)
+ {
+ slang_info_log_memory (C->L);
+ return 0;
+ }
+ if (!slang_operation_construct (var->array_size))
+ {
+ slang_alloc_free (var->array_size);
+ var->array_size = NULL;
+ return 0;
+ }
+ if (!parse_expression (C, O, var->array_size))
+ return 0;
+ break;
+ default:
+ return 0;
+ }
+
+ return 1;
+}
+
+static int parse_struct_field (slang_parse_ctx *C, slang_output_ctx *O, slang_struct *st,
+ slang_type_specifier *sp)
+{
+ slang_output_ctx o = *O;
+
+ o.structs = st->structs;
+ if (!parse_type_specifier (C, &o, sp))
+ return 0;
+ do
+ {
+ slang_variable *var;
+
+ st->fields->variables = (slang_variable *) slang_alloc_realloc (st->fields->variables,
+ st->fields->num_variables * sizeof (slang_variable),
+ (st->fields->num_variables + 1) * sizeof (slang_variable));
+ if (st->fields->variables == NULL)
+ {
+ slang_info_log_memory (C->L);
+ return 0;
+ }
+ var = &st->fields->variables[st->fields->num_variables];
+ if (!slang_variable_construct (var))
+ return 0;
+ st->fields->num_variables++;
+ if (!slang_type_specifier_copy (&var->type.specifier, sp))
+ return 0;
+ if (!parse_struct_field_var (C, &o, var))
+ return 0;
+ }
+ while (*C->I++ != FIELD_NONE);
+
+ return 1;
+}
+
+static int parse_struct (slang_parse_ctx *C, slang_output_ctx *O, slang_struct **st)
+{
+ slang_atom a_name;
+ const char *name;
+
+ /* parse struct name (if any) and make sure it is unique in current scope */
+ a_name = parse_identifier (C);
+ if (a_name == SLANG_ATOM_NULL)
+ return 0;
+ name = slang_atom_pool_id (C->atoms, a_name);
+ if (name[0] != '\0' && slang_struct_scope_find (O->structs, a_name, 0) != NULL)
+ {
+ slang_info_log_error (C->L, "%s: duplicate type name", name);
+ return 0;
+ }
+
+ /* set-up a new struct */
+ *st = (slang_struct *) slang_alloc_malloc (sizeof (slang_struct));
+ if (*st == NULL)
+ {
+ slang_info_log_memory (C->L);
+ return 0;
+ }
+ if (!slang_struct_construct (*st))
+ {
+ slang_alloc_free (*st);
+ *st = NULL;
+ slang_info_log_memory (C->L);
+ return 0;
+ }
+ (**st).a_name = a_name;
+ (**st).structs->outer_scope = O->structs;
+
+ /* parse individual struct fields */
+ do
+ {
+ slang_type_specifier sp;
+
+ if (!slang_type_specifier_construct (&sp))
+ return 0;
+ if (!parse_struct_field (C, O, *st, &sp))
+ {
+ slang_type_specifier_destruct (&sp);
+ return 0;
+ }
+ }
+ while (*C->I++ != FIELD_NONE);
+
+ /* if named struct, copy it to current scope */
+ if (name[0] != '\0')
+ {
+ slang_struct *s;
+
+ O->structs->structs = (slang_struct *) slang_alloc_realloc (O->structs->structs,
+ O->structs->num_structs * sizeof (slang_struct),
+ (O->structs->num_structs + 1) * sizeof (slang_struct));
+ if (O->structs->structs == NULL)
+ {
+ slang_info_log_memory (C->L);
+ return 0;
+ }
+ s = &O->structs->structs[O->structs->num_structs];
+ if (!slang_struct_construct (s))
+ return 0;
+ O->structs->num_structs++;
+ if (!slang_struct_copy (s, *st))
+ return 0;
+ }
+
+ return 1;
}
/* type qualifier */
spec->type = slang_spec_sampler2DShadow;
break;
case TYPE_SPECIFIER_STRUCT:
- spec->type = slang_spec_struct;\r
+ spec->type = slang_spec_struct;
if (!parse_struct (C, O, &spec->_struct))
return 0;
break;
- case TYPE_SPECIFIER_TYPENAME:\r
+ case TYPE_SPECIFIER_TYPENAME:
spec->type = slang_spec_struct;
{
slang_atom a_name;
- slang_struct *stru;\r
+ slang_struct *stru;
- a_name = parse_identifier (C);\r
+ a_name = parse_identifier (C);
if (a_name == NULL)
- return 0;\r
+ return 0;
stru = slang_struct_scope_find (O->structs, a_name, 1);
if (stru == NULL)
{
- slang_info_log_error (C->L, "%s: undeclared type name",\r
+ slang_info_log_error (C->L, "%s: undeclared type name",
slang_atom_pool_id (C->atoms, a_name));
return 0;
}
return 1;
}
-static int parse_fully_specified_type (slang_parse_ctx *C, slang_output_ctx *O,\r
+static int parse_fully_specified_type (slang_parse_ctx *C, slang_output_ctx *O,
slang_fully_specified_type *type)
{
if (!parse_type_qualifier (C, &type->qualifier))
#define OP_POSTINCREMENT 60
#define OP_POSTDECREMENT 61
-static int parse_child_operation (slang_parse_ctx *C, slang_output_ctx *O, slang_operation *oper,\r
+static int parse_child_operation (slang_parse_ctx *C, slang_output_ctx *O, slang_operation *oper,
int statement)
-{\r
- slang_operation *ch;\r
+{
+ slang_operation *ch;
oper->children = (slang_operation *) slang_alloc_realloc (oper->children,
oper->num_children * sizeof (slang_operation),
{
slang_info_log_memory (C->L);
return 0;
- }\r
+ }
ch = &oper->children[oper->num_children];
if (!slang_operation_construct (ch))
{
oper->locals->outer_scope = O->vars;
switch (*C->I++)
{
- case OP_BLOCK_BEGIN_NO_NEW_SCOPE:\r
+ case OP_BLOCK_BEGIN_NO_NEW_SCOPE:
/* parse child statements, do not create new variable scope */
oper->type = slang_oper_block_no_new_scope;
while (*C->I != OP_END)
return 0;
C->I++;
break;
- case OP_BLOCK_BEGIN_NEW_SCOPE:\r
+ case OP_BLOCK_BEGIN_NEW_SCOPE:
/* parse child statements, create new variable scope */
- {\r
- slang_output_ctx o = *O;\r
-\r
- oper->type = slang_oper_block_new_scope;\r
+ {
+ slang_output_ctx o = *O;
+
+ oper->type = slang_oper_block_new_scope;
o.vars = oper->locals;
- while (*C->I != OP_END)\r
+ while (*C->I != OP_END)
if (!parse_child_operation (C, &o, oper, 1))
- return 0;\r
- C->I++;\r
+ return 0;
+ C->I++;
}
break;
- case OP_DECLARE:\r
+ case OP_DECLARE:
/* local variable declaration, individual declarators are stored as children identifiers */
oper->type = slang_oper_variable_decl;
{
- const unsigned int first_var = O->vars->num_variables;\r
-\r
+ const unsigned int first_var = O->vars->num_variables;
+
/* parse the declaration, note that there can be zero or more than one declarators */
if (!parse_declaration (C, O))
return 0;
if (first_var < O->vars->num_variables)
{
const unsigned int num_vars = O->vars->num_variables - first_var;
- unsigned int i;\r
+ unsigned int i;
oper->children = (slang_operation *) slang_alloc_malloc (num_vars * sizeof (
slang_operation));
}
for (i = first_var; i < O->vars->num_variables; i++)
{
- slang_operation *o = &oper->children[i - first_var];\r
+ slang_operation *o = &oper->children[i - first_var];
o->type = slang_oper_identifier;
o->locals->outer_scope = O->vars;
}
}
break;
- case OP_ASM:\r
+ case OP_ASM:
/* the __asm statement, parse the mnemonic and all its arguments as expressions */
- oper->type = slang_oper_asm;\r
- oper->a_id = parse_identifier (C);\r
+ oper->type = slang_oper_asm;
+ oper->a_id = parse_identifier (C);
if (oper->a_id == SLANG_ATOM_NULL)
return 0;
while (*C->I != OP_END)
return 0;
break;
case OP_WHILE:
- {\r
- slang_output_ctx o = *O;\r
-\r
- oper->type = slang_oper_while;\r
+ {
+ slang_output_ctx o = *O;
+
+ oper->type = slang_oper_while;
o.vars = oper->locals;
if (!parse_child_operation (C, &o, oper, 1))
return 0;
if (!parse_child_operation (C, &o, oper, 1))
- return 0;\r
+ return 0;
}
break;
case OP_DO:
return 0;
break;
case OP_FOR:
- {\r
- slang_output_ctx o = *O;\r
-\r
- oper->type = slang_oper_for;\r
+ {
+ slang_output_ctx o = *O;
+
+ oper->type = slang_oper_for;
o.vars = oper->locals;
if (!parse_child_operation (C, &o, oper, 1))
return 0;
if (!parse_child_operation (C, &o, oper, 0))
return 0;
if (!parse_child_operation (C, &o, oper, 1))
- return 0;\r
+ return 0;
}
break;
default:
return 0;
}
return 1;
-}\r
-\r
-static int handle_nary_expression (slang_parse_ctx *C, slang_operation *op, slang_operation **ops,\r
- unsigned int *total_ops, unsigned int n)\r
-{\r
- unsigned int i;\r
-\r
- op->children = (slang_operation *) slang_alloc_malloc (n * sizeof (slang_operation));\r
- if (op->children == NULL)\r
- {\r
- slang_info_log_memory (C->L);\r
- return 0;\r
- }\r
- op->num_children = n;\r
-\r
- for (i = 0; i < n; i++)\r
- op->children[i] = (*ops)[*total_ops - (n + 1 - i)];\r
- (*ops)[*total_ops - (n + 1)] = (*ops)[*total_ops - 1];\r
- *total_ops -= n;\r
-\r
- *ops = (slang_operation *) slang_alloc_realloc (*ops, (*total_ops + n) * sizeof (slang_operation),\r
- *total_ops * sizeof (slang_operation));\r
- if (*ops == NULL)\r
- {\r
- slang_info_log_memory (C->L);\r
- return 0;\r
- }\r
- return 1;\r
+}
+
+static int handle_nary_expression (slang_parse_ctx *C, slang_operation *op, slang_operation **ops,
+ unsigned int *total_ops, unsigned int n)
+{
+ unsigned int i;
+
+ op->children = (slang_operation *) slang_alloc_malloc (n * sizeof (slang_operation));
+ if (op->children == NULL)
+ {
+ slang_info_log_memory (C->L);
+ return 0;
+ }
+ op->num_children = n;
+
+ for (i = 0; i < n; i++)
+ op->children[i] = (*ops)[*total_ops - (n + 1 - i)];
+ (*ops)[*total_ops - (n + 1)] = (*ops)[*total_ops - 1];
+ *total_ops -= n;
+
+ *ops = (slang_operation *) slang_alloc_realloc (*ops, (*total_ops + n) * sizeof (slang_operation),
+ *total_ops * sizeof (slang_operation));
+ if (*ops == NULL)
+ {
+ slang_info_log_memory (C->L);
+ return 0;
+ }
+ return 1;
}
static int is_constructor_name (const char *name, slang_atom a_name, slang_struct_scope *structs)
while (*C->I != OP_END)
{
slang_operation *op;
- const unsigned int op_code = *C->I++;\r
-\r
+ const unsigned int op_code = *C->I++;
+
/* allocate default operation, becomes a no-op if not used */
ops = (slang_operation *) slang_alloc_realloc (ops,
num_ops * sizeof (slang_operation), (num_ops + 1) * sizeof (slang_operation));
return 0;
}
num_ops++;
- op->locals->outer_scope = O->vars;\r
+ op->locals->outer_scope = O->vars;
switch (op_code)
{
break;
case OP_PUSH_IDENTIFIER:
op->type = slang_oper_identifier;
- op->a_id = parse_identifier (C);\r
+ op->a_id = parse_identifier (C);
if (op->a_id == SLANG_ATOM_NULL)
return 0;
break;
break;
case OP_CALL:
op->type = slang_oper_call;
- op->a_id = parse_identifier (C);\r
+ op->a_id = parse_identifier (C);
if (op->a_id == SLANG_ATOM_NULL)
return 0;
while (*C->I != OP_END)
if (!parse_child_operation (C, O, op, 0))
return 0;
C->I++;
- if (!C->parsing_builtin && !slang_function_scope_find_by_name (O->funs, op->a_id, 1))\r
- {\r
- const char *id;\r
-\r
+ if (!C->parsing_builtin && !slang_function_scope_find_by_name (O->funs, op->a_id, 1))
+ {
+ const char *id;
+
id = slang_atom_pool_id (C->atoms, op->a_id);
if (!is_constructor_name (id, op->a_id, O->structs))
{
slang_info_log_error (C->L, "%s: undeclared function name", id);
return 0;
- }\r
+ }
}
break;
case OP_FIELD:
op->type = slang_oper_field;
- op->a_id = parse_identifier (C);\r
+ op->a_id = parse_identifier (C);
if (op->a_id == SLANG_ATOM_NULL)
return 0;
if (!handle_nary_expression (C, op, &ops, &num_ops, 1))
return 0;
}
}
- C->I++;\r
+ C->I++;
*oper = *ops;
slang_alloc_free (ops);
#define PARAMETER_ARRAY_NOT_PRESENT 0
#define PARAMETER_ARRAY_PRESENT 1
-static int parse_parameter_declaration (slang_parse_ctx *C, slang_output_ctx *O,\r
+static int parse_parameter_declaration (slang_parse_ctx *C, slang_output_ctx *O,
slang_variable *param)
{
- slang_storage_aggregate agg;\r
-\r
- /* parse and validate the parameter's type qualifiers (there can be two at most) because\r
+ slang_storage_aggregate agg;
+
+ /* parse and validate the parameter's type qualifiers (there can be two at most) because
* not all combinations are valid */
if (!parse_type_qualifier (C, ¶m->type.qualifier))
return 0;
break;
default:
return 0;
- }\r
-\r
+ }
+
/* parse parameter's type specifier and name */
if (!parse_type_specifier (C, O, ¶m->type.specifier))
- return 0;\r
+ return 0;
param->a_name = parse_identifier (C);
- if (param->a_name == SLANG_ATOM_NULL)\r
- return 0;\r
-\r
+ if (param->a_name == SLANG_ATOM_NULL)
+ return 0;
+
/* if the parameter is an array, parse its size (the size must be explicitly defined */
if (*C->I++ == PARAMETER_ARRAY_PRESENT)
{
return 0;
}
if (!parse_expression (C, O, param->array_size))
- return 0;\r
+ return 0;
/* TODO: execute the array_size */
- }\r
-\r
- /* calculate the parameter size */\r
- if (!slang_storage_aggregate_construct (&agg))\r
- return 0;\r
- if (!_slang_aggregate_variable (&agg, ¶m->type.specifier, param->array_size, O->funs,\r
- O->structs, O->vars, O->machine, O->assembly, C->atoms))\r
- {\r
- slang_storage_aggregate_destruct (&agg);\r
- return 0;\r
- }\r
- param->size = _slang_sizeof_aggregate (&agg);\r
- slang_storage_aggregate_destruct (&agg);\r
- /* TODO: allocate the local address here? */\r
+ }
+
+ /* calculate the parameter size */
+ if (!slang_storage_aggregate_construct (&agg))
+ return 0;
+ if (!_slang_aggregate_variable (&agg, ¶m->type.specifier, param->array_size, O->funs,
+ O->structs, O->vars, O->machine, O->assembly, C->atoms))
+ {
+ slang_storage_aggregate_destruct (&agg);
+ return 0;
+ }
+ param->size = _slang_sizeof_aggregate (&agg);
+ slang_storage_aggregate_destruct (&agg);
+ /* TODO: allocate the local address here? */
return 1;
}
static slang_atom parse_operator_name (slang_parse_ctx *C)
{
- unsigned int i;\r
+ unsigned int i;
- for (i = 0; i < sizeof (operator_names) / sizeof (*operator_names); i++)\r
+ for (i = 0; i < sizeof (operator_names) / sizeof (*operator_names); i++)
{
if (operator_names[i].o_code == (unsigned int) (*C->I))
{
}
C->I++;
return atom;
- }\r
+ }
}
return 0;
}
static int parse_function_prototype (slang_parse_ctx *C, slang_output_ctx *O, slang_function *func)
-{\r
+{
/* parse function type and name */
if (!parse_fully_specified_type (C, O, &func->header.type))
return 0;
switch (*C->I++)
{
- case FUNCTION_ORDINARY:\r
+ case FUNCTION_ORDINARY:
func->kind = slang_func_ordinary;
func->header.a_name = parse_identifier (C);
- if (func->header.a_name == SLANG_ATOM_NULL)\r
- return 0;\r
+ if (func->header.a_name == SLANG_ATOM_NULL)
+ return 0;
break;
case FUNCTION_CONSTRUCTOR:
func->kind = slang_func_constructor;
break;
case FUNCTION_OPERATOR:
func->kind = slang_func_operator;
- func->header.a_name = parse_operator_name (C);\r
+ func->header.a_name = parse_operator_name (C);
if (func->header.a_name == SLANG_ATOM_NULL)
return 0;
break;
default:
return 0;
- }\r
-\r
+ }
+
/* parse function parameters */
while (*C->I++ == PARAMETER_NEXT)
- {\r
- slang_variable *p;\r
+ {
+ slang_variable *p;
func->parameters->variables = (slang_variable *) slang_alloc_realloc (
func->parameters->variables,
{
slang_info_log_memory (C->L);
return 0;
- }\r
+ }
p = &func->parameters->variables[func->parameters->num_variables];
- if (!slang_variable_construct (p))\r
- return 0;\r
+ if (!slang_variable_construct (p))
+ return 0;
func->parameters->num_variables++;
if (!parse_parameter_declaration (C, O, p))
return 0;
- }\r
-\r
- /* function formal parameters and local variables share the same scope, so save\r
- * the information about param count in a seperate place\r
- * also link the scope to the global variable scope so when a given identifier is not\r
+ }
+
+ /* function formal parameters and local variables share the same scope, so save
+ * the information about param count in a seperate place
+ * also link the scope to the global variable scope so when a given identifier is not
* found here, the search process continues in the global space */
- func->param_count = func->parameters->num_variables;\r
+ func->param_count = func->parameters->num_variables;
func->parameters->outer_scope = O->vars;
return 1;
}
static int parse_function_definition (slang_parse_ctx *C, slang_output_ctx *O, slang_function *func)
-{\r
- slang_output_ctx o = *O;\r
+{
+ slang_output_ctx o = *O;
if (!parse_function_prototype (C, O, func))
- return 0;\r
-\r
+ return 0;
+
/* create function's body operation */
func->body = (slang_operation *) slang_alloc_malloc (sizeof (slang_operation));
if (func->body == NULL)
func->body = NULL;
slang_info_log_memory (C->L);
return 0;
- }\r
-\r
- /* to parse the body the parse context is modified in order to capture parsed variables\r
- * into function's local variable scope */\r
- C->global_scope = 0;\r
+ }
+
+ /* to parse the body the parse context is modified in order to capture parsed variables
+ * into function's local variable scope */
+ C->global_scope = 0;
o.vars = func->parameters;
if (!parse_statement (C, &o, func->body))
- return 0;\r
+ return 0;
C->global_scope = 1;
return 1;
-}\r
-\r
-static int initialize_global (slang_assemble_ctx *A, slang_variable *var)\r
-{\r
- slang_assembly_file_restore_point point;\r
- slang_machine mach;\r
- slang_assembly_local_info info;\r
- slang_operation op_id, op_assign;\r
- int result;\r
- slang_assembly_flow_control flow;\r
- slang_assembly_stack_info stk;\r
-\r
- /* save the current assembly */\r
- if (!slang_assembly_file_restore_point_save (A->file, &point))\r
- return 0;\r
-\r
- /* setup the machine */\r
- mach = *A->mach;\r
- mach.ip = A->file->count;\r
-\r
- /* allocate local storage for expression */\r
- info.ret_size = 0;\r
- info.addr_tmp = 0;\r
- info.swizzle_tmp = 4;\r
- if (!slang_assembly_file_push_label (A->file, slang_asm_local_alloc, 20))\r
- return 0;\r
- if (!slang_assembly_file_push_label (A->file, slang_asm_enter, 20))\r
- return 0;\r
-\r
- /* construct the left side of assignment */\r
- if (!slang_operation_construct (&op_id))\r
- return 0;\r
- op_id.type = slang_oper_identifier;\r
- op_id.a_id = var->a_name;\r
-\r
- /* put the variable into operation's scope */\r
- op_id.locals->variables = (slang_variable *) slang_alloc_malloc (sizeof (slang_variable));\r
- if (op_id.locals->variables == NULL)\r
- {\r
- slang_operation_destruct (&op_id);\r
- return 0;\r
- }\r
- op_id.locals->num_variables = 1;\r
- op_id.locals->variables[0] = *var;\r
-\r
- /* construct the assignment expression */\r
- if (!slang_operation_construct (&op_assign))\r
- {\r
- op_id.locals->num_variables = 0;\r
- slang_operation_destruct (&op_id);\r
- return 0;\r
- }\r
- op_assign.type = slang_oper_assign;\r
- op_assign.children = (slang_operation *) slang_alloc_malloc (2 * sizeof (slang_operation));\r
- if (op_assign.children == NULL)\r
- {\r
- slang_operation_destruct (&op_assign);\r
- op_id.locals->num_variables = 0;\r
- slang_operation_destruct (&op_id);\r
- return 0;\r
- }\r
- op_assign.num_children = 2;\r
- op_assign.children[0] = op_id;\r
- op_assign.children[1] = *var->initializer;\r
-\r
- /* insert the actual expression */\r
- result = _slang_assemble_operation (A->file, &op_assign, 0, &flow, &A->space, &info, &stk, A->mach, A->atoms);\r
-\r
- /* carefully destroy the operations */\r
- op_assign.num_children = 0;\r
- slang_alloc_free (op_assign.children);\r
- op_assign.children = NULL;\r
- slang_operation_destruct (&op_assign);\r
- op_id.locals->num_variables = 0;\r
- slang_operation_destruct (&op_id);\r
-\r
- if (!result)\r
- return 0;\r
- if (!slang_assembly_file_push (A->file, slang_asm_exit))\r
- return 0;\r
-\r
- /* execute the expression */\r
- if (!_slang_execute2 (A->file, &mach))\r
- return 0;\r
-\r
- /* restore the old assembly */\r
- if (!slang_assembly_file_restore_point_load (A->file, &point))\r
- return 0;\r
-\r
- /* now we copy the contents of the initialized variable back to the original machine */\r
- _mesa_memcpy ((GLubyte *) A->mach->mem + var->address, (GLubyte *) mach.mem + var->address,\r
- var->size);\r
-\r
- return 1;\r
+}
+
+static GLboolean initialize_global (slang_assemble_ctx *A, slang_variable *var)
+{
+ slang_assembly_file_restore_point point;
+ slang_machine mach;
+ slang_assembly_local_info save_local = A->local;
+ slang_operation op_id, op_assign;
+ GLboolean result;
+
+ /* save the current assembly */
+ if (!slang_assembly_file_restore_point_save (A->file, &point))
+ return GL_FALSE;
+
+ /* setup the machine */
+ mach = *A->mach;
+ mach.ip = A->file->count;
+
+ /* allocate local storage for expression */
+ A->local.ret_size = 0;
+ A->local.addr_tmp = 0;
+ A->local.swizzle_tmp = 4;
+ if (!slang_assembly_file_push_label (A->file, slang_asm_local_alloc, 20))
+ return GL_FALSE;
+ if (!slang_assembly_file_push_label (A->file, slang_asm_enter, 20))
+ return GL_FALSE;
+
+ /* construct the left side of assignment */
+ if (!slang_operation_construct (&op_id))
+ return GL_FALSE;
+ op_id.type = slang_oper_identifier;
+ op_id.a_id = var->a_name;
+
+ /* put the variable into operation's scope */
+ op_id.locals->variables = (slang_variable *) slang_alloc_malloc (sizeof (slang_variable));
+ if (op_id.locals->variables == NULL)
+ {
+ slang_operation_destruct (&op_id);
+ return GL_FALSE;
+ }
+ op_id.locals->num_variables = 1;
+ op_id.locals->variables[0] = *var;
+
+ /* construct the assignment expression */
+ if (!slang_operation_construct (&op_assign))
+ {
+ op_id.locals->num_variables = 0;
+ slang_operation_destruct (&op_id);
+ return GL_FALSE;
+ }
+ op_assign.type = slang_oper_assign;
+ op_assign.children = (slang_operation *) slang_alloc_malloc (2 * sizeof (slang_operation));
+ if (op_assign.children == NULL)
+ {
+ slang_operation_destruct (&op_assign);
+ op_id.locals->num_variables = 0;
+ slang_operation_destruct (&op_id);
+ return GL_FALSE;
+ }
+ op_assign.num_children = 2;
+ op_assign.children[0] = op_id;
+ op_assign.children[1] = *var->initializer;
+
+ /* insert the actual expression */
+ result = _slang_assemble_operation_ (A, &op_assign, slang_ref_forbid);
+
+ /* carefully destroy the operations */
+ op_assign.num_children = 0;
+ slang_alloc_free (op_assign.children);
+ op_assign.children = NULL;
+ slang_operation_destruct (&op_assign);
+ op_id.locals->num_variables = 0;
+ slang_operation_destruct (&op_id);
+
+ if (!result)
+ return GL_FALSE;
+ if (!slang_assembly_file_push (A->file, slang_asm_exit))
+ return GL_FALSE;
+
+ /* execute the expression */
+ if (!_slang_execute2 (A->file, &mach))
+ return GL_FALSE;
+
+ /* restore the old assembly */
+ if (!slang_assembly_file_restore_point_load (A->file, &point))
+ return GL_FALSE;
+ A->local = save_local;
+
+ /* now we copy the contents of the initialized variable back to the original machine */
+ _mesa_memcpy ((GLubyte *) A->mach->mem + var->address, (GLubyte *) mach.mem + var->address,
+ var->size);
+
+ return GL_TRUE;
}
/* init declarator list */
#define VARIABLE_ARRAY_EXPLICIT 3
#define VARIABLE_ARRAY_UNKNOWN 4
-static int parse_init_declarator (slang_parse_ctx *C, slang_output_ctx *O,\r
+static int parse_init_declarator (slang_parse_ctx *C, slang_output_ctx *O,
const slang_fully_specified_type *type)
{
- slang_variable *var;\r
-\r
- /* empty init declatator (without name, e.g. "float ;") */\r
+ slang_variable *var;
+
+ /* empty init declatator (without name, e.g. "float ;") */
if (*C->I++ == VARIABLE_NONE)
- return 1;\r
-\r
+ return 1;
+
/* make room for the new variable and initialize it */
O->vars->variables = (slang_variable *) slang_alloc_realloc (O->vars->variables,
O->vars->num_variables * sizeof (slang_variable),
return 0;
}
var = &O->vars->variables[O->vars->num_variables];
- if (!slang_variable_construct (var))\r
- return 0;\r
- O->vars->num_variables++;\r
-\r
- /* copy the declarator qualifier type, parse the identifier */\r
+ if (!slang_variable_construct (var))
+ return 0;
+ O->vars->num_variables++;
+
+ /* copy the declarator qualifier type, parse the identifier */
var->global = C->global_scope;
var->type.qualifier = type->qualifier;
var->a_name = parse_identifier (C);
- if (var->a_name == SLANG_ATOM_NULL)\r
- return 0;\r
+ if (var->a_name == SLANG_ATOM_NULL)
+ return 0;
switch (*C->I++)
{
- case VARIABLE_NONE:\r
+ case VARIABLE_NONE:
/* simple variable declarator - just copy the specifier */
if (!slang_type_specifier_copy (&var->type.specifier, &type->specifier))
return 0;
break;
- case VARIABLE_INITIALIZER:\r
+ case VARIABLE_INITIALIZER:
/* initialized variable - copy the specifier and parse the expression */
if (!slang_type_specifier_copy (&var->type.specifier, &type->specifier))
return 0;
slang_info_log_memory (C->L);
return 0;
}
- if (!slang_type_specifier_construct (var->type.specifier._array))\r
- {\r
- slang_alloc_free (var->type.specifier._array);\r
- var->type.specifier._array = NULL;\r
- slang_info_log_memory (C->L);\r
- return 0;\r
+ if (!slang_type_specifier_construct (var->type.specifier._array))
+ {
+ slang_alloc_free (var->type.specifier._array);
+ var->type.specifier._array = NULL;
+ slang_info_log_memory (C->L);
+ return 0;
}
if (!slang_type_specifier_copy (var->type.specifier._array, &type->specifier))
return 0;
break;
default:
return 0;
- }\r
-\r
+ }
+
/* allocate global address space for a variable with a known size */
if (C->global_scope && !(var->type.specifier.type == slang_spec_array && var->array_size == NULL))
{
slang_storage_aggregate agg;
- if (!slang_storage_aggregate_construct (&agg))\r
+ if (!slang_storage_aggregate_construct (&agg))
return 0;
if (!_slang_aggregate_variable (&agg, &var->type.specifier, var->array_size, O->funs,
O->structs, O->vars, O->machine, O->assembly, C->atoms))
{
slang_storage_aggregate_destruct (&agg);
return 0;
- }\r
- var->size = _slang_sizeof_aggregate (&agg);\r
- slang_storage_aggregate_destruct (&agg);\r
+ }
+ var->size = _slang_sizeof_aggregate (&agg);
+ slang_storage_aggregate_destruct (&agg);
var->address = slang_var_pool_alloc (O->global_pool, var->size);
- }\r
-\r
- /* initialize global variable */\r
- if (C->global_scope && var->initializer != NULL)\r
- {\r
- slang_assemble_ctx A;\r
-\r
- A.file = O->assembly;\r
- A.mach = O->machine;\r
- A.atoms = C->atoms;\r
- A.space.funcs = O->funs;\r
- A.space.structs = O->structs;\r
- A.space.vars = O->vars;\r
- if (!initialize_global (&A, var))\r
- return 0;\r
+ }
+
+ /* initialize global variable */
+ if (C->global_scope && var->initializer != NULL)
+ {
+ slang_assemble_ctx A;
+
+ A.file = O->assembly;
+ A.mach = O->machine;
+ A.atoms = C->atoms;
+ A.space.funcs = O->funs;
+ A.space.structs = O->structs;
+ A.space.vars = O->vars;
+ if (!initialize_global (&A, var))
+ return 0;
}
return 1;
}
static int parse_init_declarator_list (slang_parse_ctx *C, slang_output_ctx *O)
{
slang_fully_specified_type type;
-\r
+
/* parse the fully specified type, common to all declarators */
- if (!slang_fully_specified_type_construct (&type))\r
+ if (!slang_fully_specified_type_construct (&type))
return 0;
if (!parse_fully_specified_type (C, O, &type))
{
slang_fully_specified_type_destruct (&type);
return 0;
- }\r
-\r
+ }
+
/* parse declarators, pass-in the parsed type */
do
{
return 0;
}
}
- while (*C->I++ == DECLARATOR_NEXT);\r
+ while (*C->I++ == DECLARATOR_NEXT);
slang_fully_specified_type_destruct (&type);
return 1;
}
-static int parse_function (slang_parse_ctx *C, slang_output_ctx *O, int definition,\r
+static int parse_function (slang_parse_ctx *C, slang_output_ctx *O, int definition,
slang_function **parsed_func_ret)
{
slang_function parsed_func, *found_func;
/* parse function definition/declaration */
- if (!slang_function_construct (&parsed_func))\r
+ if (!slang_function_construct (&parsed_func))
return 0;
if (definition)
{
{
/* add the parsed function to the function list */
O->funs->functions = (slang_function *) slang_alloc_realloc (O->funs->functions,
- O->funs->num_functions * sizeof (slang_function),\r
+ O->funs->num_functions * sizeof (slang_function),
(O->funs->num_functions + 1) * sizeof (slang_function));
if (O->funs->functions == NULL)
{
{
/* TODO: check function return type qualifiers and specifiers */
if (definition)
- {\r
+ {
if (found_func->body != NULL)
{
slang_info_log_error (C->L, "%s: function already has a body",
slang_atom_pool_id (C->atoms, parsed_func.header.a_name));
slang_function_destruct (&parsed_func);
return 0;
- }\r
-\r
- /* destroy the existing function declaration and replace it with the new one,\r
- * remember to save the fixup table */\r
- parsed_func.fixups = found_func->fixups;\r
+ }
+
+ /* destroy the existing function declaration and replace it with the new one,
+ * remember to save the fixup table */
+ parsed_func.fixups = found_func->fixups;
slang_fixup_table_init (&found_func->fixups);
slang_function_destruct (found_func);
*found_func = parsed_func;
/* assemble the parsed function */
{
slang_assemble_ctx A;
-\r
- A.file = O->assembly;\r
- A.mach = O->machine;\r
- A.atoms = C->atoms;\r
+
+ A.file = O->assembly;
+ A.mach = O->machine;
+ A.atoms = C->atoms;
A.space.funcs = O->funs;
A.space.structs = O->structs;
- A.space.vars = O->vars;\r
- if (!_slang_assemble_function (&A, *parsed_func_ret))\r
- return 0;\r
+ A.space.vars = O->vars;
+ if (!_slang_assemble_function (&A, *parsed_func_ret))
+ return 0;
}
return 1;
}
if (!parse_init_declarator_list (C, O))
return 0;
break;
- case DECLARATION_FUNCTION_PROTOTYPE:\r
- {\r
- slang_function *dummy_func;\r
+ case DECLARATION_FUNCTION_PROTOTYPE:
+ {
+ slang_function *dummy_func;
if (!parse_function (C, O, 0, &dummy_func))
- return 0;\r
+ return 0;
}
break;
default:
#define EXTERNAL_DECLARATION 2
static int parse_translation_unit (slang_parse_ctx *C, slang_translation_unit *unit)
-{\r
- slang_output_ctx o;\r
-\r
- /* setup output context */\r
- o.funs = &unit->functions;\r
- o.structs = &unit->structs;\r
- o.vars = &unit->globals;\r
- o.assembly = unit->assembly;\r
- o.global_pool = unit->global_pool;\r
- o.machine = unit->machine;\r
-\r
+{
+ slang_output_ctx o;
+
+ /* setup output context */
+ o.funs = &unit->functions;
+ o.structs = &unit->structs;
+ o.vars = &unit->globals;
+ o.assembly = unit->assembly;
+ o.global_pool = unit->global_pool;
+ o.machine = unit->machine;
+
/* parse individual functions and declarations */
while (*C->I != EXTERNAL_NULL)
{
switch (*C->I++)
{
- case EXTERNAL_FUNCTION_DEFINITION:\r
- {\r
- slang_function *func;\r
+ case EXTERNAL_FUNCTION_DEFINITION:
+ {
+ slang_function *func;
if (!parse_function (C, &o, 1, &func))
- return 0;\r
+ return 0;
}
break;
case EXTERNAL_DECLARATION:
}
C->I++;
return 1;
-}\r
-\r
-#define BUILTIN_CORE 0\r
-#define BUILTIN_COMMON 1\r
-#define BUILTIN_TARGET 2\r
+}
+
+#define BUILTIN_CORE 0
+#define BUILTIN_COMMON 1
+#define BUILTIN_TARGET 2
#define BUILTIN_TOTAL 3
static int compile_binary (const byte *prod, slang_translation_unit *unit, slang_unit_type type,
- slang_info_log *log, slang_translation_unit *builtins, slang_assembly_file *file,\r
- slang_var_pool *pool, slang_machine *mach, slang_translation_unit *downlink,\r
+ slang_info_log *log, slang_translation_unit *builtins, slang_assembly_file *file,
+ slang_var_pool *pool, slang_machine *mach, slang_translation_unit *downlink,
slang_atom_pool *atoms)
{
- slang_parse_ctx C;\r
-\r
- /* create translation unit object */\r
- if (file != NULL)\r
- {\r
- if (!slang_translation_unit_construct2 (unit, file, pool, mach, atoms))\r
- return 0;\r
- unit->type = type;\r
+ slang_parse_ctx C;
+
+ /* create translation unit object */
+ if (file != NULL)
+ {
+ if (!slang_translation_unit_construct2 (unit, file, pool, mach, atoms))
+ return 0;
+ unit->type = type;
}
/* set-up parse context */
C.I = prod;
C.L = log;
- C.parsing_builtin = builtins == NULL;\r
- C.global_scope = 1;\r
- C.atoms = unit->atom_pool;\r
+ C.parsing_builtin = builtins == NULL;
+ C.global_scope = 1;
+ C.atoms = unit->atom_pool;
if (!check_revision (&C))
- {\r
- slang_translation_unit_destruct (unit);\r
- return 0;\r
+ {
+ slang_translation_unit_destruct (unit);
+ return 0;
}
if (downlink != NULL)
slang_info_log_error (log, buf);
return 0;
}
-\r
+
/* syntax is okay - translate it to internal representation */
- if (!compile_binary (prod, unit, type, log, builtins, NULL, NULL, NULL,\r
+ if (!compile_binary (prod, unit, type, log, builtins, NULL, NULL, NULL,
&builtins[BUILTIN_TARGET], NULL))
{
grammar_alloc_free (prod);
static const byte slang_vertex_builtin_gc[] = {
#include "library/slang_vertex_builtin_gc.h"
-};\r
-\r
-static int compile (grammar *id, slang_translation_unit *builtin_units, int *compiled,\r
- const char *source, slang_translation_unit *unit, slang_unit_type type, slang_info_log *log)\r
-{\r
- slang_translation_unit *builtins = NULL;\r
-\r
- /* load slang grammar */\r
- *id = grammar_load_from_text ((const byte *) (slang_shader_syn));\r
- if (*id == 0)\r
- {\r
- byte buf[1024];\r
- int pos;\r
-\r
- grammar_get_last_error (buf, 1024, &pos);\r
- slang_info_log_error (log, (const char *) (buf));\r
- return 0;\r
- }\r
-\r
- /* set shader type - the syntax is slightly different for different shaders */\r
- if (type == slang_unit_fragment_shader || type == slang_unit_fragment_builtin)\r
- grammar_set_reg8 (*id, (const byte *) "shader_type", 1);\r
- else\r
- grammar_set_reg8 (*id, (const byte *) "shader_type", 2);\r
-\r
- /* enable language extensions */\r
- grammar_set_reg8 (*id, (const byte *) "parsing_builtin", 1);\r
-\r
- /* if parsing user-specified shader, load built-in library */\r
- if (type == slang_unit_fragment_shader || type == slang_unit_vertex_shader)\r
- {\r
- /* compile core functionality first */\r
- if (!compile_binary (slang_core_gc, &builtin_units[BUILTIN_CORE],\r
- slang_unit_fragment_builtin, log, NULL, unit->assembly, unit->global_pool,\r
- unit->machine, NULL, unit->atom_pool))\r
- return 0;\r
- compiled[BUILTIN_CORE] = 1;\r
-\r
- /* compile common functions and variables, link to core */\r
- if (!compile_binary (slang_common_builtin_gc, &builtin_units[BUILTIN_COMMON],\r
- slang_unit_fragment_builtin, log, NULL, unit->assembly, unit->global_pool,\r
- unit->machine, &builtin_units[BUILTIN_CORE], unit->atom_pool))\r
- return 0;\r
- compiled[BUILTIN_COMMON] = 1;\r
-\r
- /* compile target-specific functions and variables, link to common */\r
- if (type == slang_unit_fragment_shader)\r
- {\r
- if (!compile_binary (slang_fragment_builtin_gc, &builtin_units[BUILTIN_TARGET],\r
- slang_unit_fragment_builtin, log, NULL, unit->assembly, unit->global_pool,\r
- unit->machine, &builtin_units[BUILTIN_COMMON], unit->atom_pool))\r
- return 0;\r
- }\r
- else if (type == slang_unit_vertex_shader)\r
- {\r
- if (!compile_binary (slang_vertex_builtin_gc, &builtin_units[BUILTIN_TARGET],\r
- slang_unit_vertex_builtin, log, NULL, unit->assembly, unit->global_pool,\r
- unit->machine, &builtin_units[BUILTIN_COMMON], unit->atom_pool))\r
- return 0;\r
- }\r
- compiled[BUILTIN_TARGET] = 1;\r
-\r
- /* disable language extensions */\r
- grammar_set_reg8 (*id, (const byte *) "parsing_builtin", 0);\r
- builtins = builtin_units;\r
- }\r
-\r
- /* compile the actual shader - pass-in built-in library for external shader */\r
- if (!compile_with_grammar (*id, source, unit, type, log, builtins))\r
- return 0;\r
-\r
- return 1;\r
+};
+
+static int compile (grammar *id, slang_translation_unit *builtin_units, int *compiled,
+ const char *source, slang_translation_unit *unit, slang_unit_type type, slang_info_log *log)
+{
+ slang_translation_unit *builtins = NULL;
+
+ /* load slang grammar */
+ *id = grammar_load_from_text ((const byte *) (slang_shader_syn));
+ if (*id == 0)
+ {
+ byte buf[1024];
+ int pos;
+
+ grammar_get_last_error (buf, 1024, &pos);
+ slang_info_log_error (log, (const char *) (buf));
+ return 0;
+ }
+
+ /* set shader type - the syntax is slightly different for different shaders */
+ if (type == slang_unit_fragment_shader || type == slang_unit_fragment_builtin)
+ grammar_set_reg8 (*id, (const byte *) "shader_type", 1);
+ else
+ grammar_set_reg8 (*id, (const byte *) "shader_type", 2);
+
+ /* enable language extensions */
+ grammar_set_reg8 (*id, (const byte *) "parsing_builtin", 1);
+
+ /* if parsing user-specified shader, load built-in library */
+ if (type == slang_unit_fragment_shader || type == slang_unit_vertex_shader)
+ {
+ /* compile core functionality first */
+ if (!compile_binary (slang_core_gc, &builtin_units[BUILTIN_CORE],
+ slang_unit_fragment_builtin, log, NULL, unit->assembly, unit->global_pool,
+ unit->machine, NULL, unit->atom_pool))
+ return 0;
+ compiled[BUILTIN_CORE] = 1;
+
+ /* compile common functions and variables, link to core */
+ if (!compile_binary (slang_common_builtin_gc, &builtin_units[BUILTIN_COMMON],
+ slang_unit_fragment_builtin, log, NULL, unit->assembly, unit->global_pool,
+ unit->machine, &builtin_units[BUILTIN_CORE], unit->atom_pool))
+ return 0;
+ compiled[BUILTIN_COMMON] = 1;
+
+ /* compile target-specific functions and variables, link to common */
+ if (type == slang_unit_fragment_shader)
+ {
+ if (!compile_binary (slang_fragment_builtin_gc, &builtin_units[BUILTIN_TARGET],
+ slang_unit_fragment_builtin, log, NULL, unit->assembly, unit->global_pool,
+ unit->machine, &builtin_units[BUILTIN_COMMON], unit->atom_pool))
+ return 0;
+ }
+ else if (type == slang_unit_vertex_shader)
+ {
+ if (!compile_binary (slang_vertex_builtin_gc, &builtin_units[BUILTIN_TARGET],
+ slang_unit_vertex_builtin, log, NULL, unit->assembly, unit->global_pool,
+ unit->machine, &builtin_units[BUILTIN_COMMON], unit->atom_pool))
+ return 0;
+ }
+ compiled[BUILTIN_TARGET] = 1;
+
+ /* disable language extensions */
+ grammar_set_reg8 (*id, (const byte *) "parsing_builtin", 0);
+ builtins = builtin_units;
+ }
+
+ /* compile the actual shader - pass-in built-in library for external shader */
+ if (!compile_with_grammar (*id, source, unit, type, log, builtins))
+ return 0;
+
+ return 1;
}
-\r
+
int _slang_compile (const char *source, slang_translation_unit *unit, slang_unit_type type,
slang_info_log *log)
-{\r
+{
int success;
grammar id = 0;
-// slang_translation_unit builtin_units[BUILTIN_TOTAL];\r
- slang_translation_unit *builtin_units;\r
- int compiled[BUILTIN_TOTAL] = { 0 };\r
-\r
- /* create the main unit first */\r
- if (!slang_translation_unit_construct (unit))\r
- return 0;\r
+/* slang_translation_unit builtin_units[BUILTIN_TOTAL];*/
+ slang_translation_unit *builtin_units;
+ int compiled[BUILTIN_TOTAL] = { 0 };
+
+ /* create the main unit first */
+ if (!slang_translation_unit_construct (unit))
+ return 0;
unit->type = type;
-\r
+
builtin_units = (slang_translation_unit *) slang_alloc_malloc (BUILTIN_TOTAL * sizeof (slang_translation_unit));
success = compile (&id, builtin_units, compiled, source, unit, type, log);
- /* destroy built-in library */\r
+ /* destroy built-in library */
/* XXX: free with the unit */
/*if (type == slang_unit_fragment_shader || type == slang_unit_vertex_shader)
- {\r
- int i;\r
-\r
- for (i = 0; i < BUILTIN_TOTAL; i++)\r
+ {
+ int i;
+
+ for (i = 0; i < BUILTIN_TOTAL; i++)
if (compiled[i] != 0)
slang_translation_unit_destruct (&builtin_units[i]);
- }*/\r
+ }*/
if (id != 0)
- grammar_destroy (id);\r
+ grammar_destroy (id);
return success;
}
return 1;\r
}\r
\r
-slang_variable *_slang_locate_variable (slang_variable_scope *scope, slang_atom a_name, int all)\r
+slang_variable *_slang_locate_variable (slang_variable_scope *scope, slang_atom a_name, GLboolean all)\r
{\r
- unsigned int i;\r
+ GLuint i;\r
\r
for (i = 0; i < scope->num_variables; i++)\r
if (a_name == scope->variables[i].a_name)\r
void slang_variable_destruct (slang_variable *);\r
int slang_variable_copy (slang_variable *, const slang_variable *);\r
\r
-slang_variable *_slang_locate_variable (slang_variable_scope *scope, slang_atom a_name, int all);\r
+slang_variable *_slang_locate_variable (slang_variable_scope *, slang_atom a_name, GLboolean all);\r
\r
#ifdef __cplusplus\r
}\r
#include "slang_assemble.h"\r
#include "slang_storage.h"\r
#include "slang_execute.h"\r
+#include "slang_library_noise.h"\r
\r
#define DEBUG_SLANG 0\r
\r
case slang_asm_float_ceil:\r
fprintf (f, "float_ceil");\r
break;\r
+ case slang_asm_float_noise1:\r
+ fprintf (f, "float_noise1");\r
+ break;\r
+ case slang_asm_float_noise2:\r
+ fprintf (f, "float_noise2");\r
+ break;\r
+ case slang_asm_float_noise3:\r
+ fprintf (f, "float_noise3");\r
+ break;\r
+ case slang_asm_float_noise4:\r
+ fprintf (f, "float_noise4");\r
+ break;\r
case slang_asm_int_copy:\r
fprintf (f, "int_copy\t%d, %d", a->param[0], a->param[1]);\r
break;\r
case slang_asm_float_ceil:\r
stack[mach->sp]._float = CEILF (stack[mach->sp]._float);\r
break;\r
+ case slang_asm_float_noise1:\r
+ stack[mach->sp]._float = _slang_library_noise1 (stack[mach->sp]._float);\r
+ break;\r
+ case slang_asm_float_noise2:\r
+ stack[mach->sp + 1]._float = _slang_library_noise2 (stack[mach->sp]._float,\r
+ stack[mach->sp + 1]._float);\r
+ mach->sp++;\r
+ break;\r
+ case slang_asm_float_noise3:\r
+ stack[mach->sp + 2]._float = _slang_library_noise3 (stack[mach->sp]._float,\r
+ stack[mach->sp + 1]._float, stack[mach->sp + 2]._float);\r
+ mach->sp += 2;\r
+ break;\r
+ case slang_asm_float_noise4:\r
+ stack[mach->sp + 3]._float = _slang_library_noise4 (stack[mach->sp]._float,\r
+ stack[mach->sp + 1]._float, stack[mach->sp + 2]._float, stack[mach->sp + 3]._float);\r
+ mach->sp += 3;\r
+ break;\r
case slang_asm_int_to_float:\r
break;\r
case slang_asm_int_to_addr:\r
case slang_asm_bool_print:\r
_mesa_printf ("slang print: %s\n", (GLint) stack[mach->sp]._float ? "true" : "false");\r
break;\r
+ default:\r
+ assert (0);\r
}\r
}\r
\r
--- /dev/null
+/*\r
+ * Mesa 3-D graphics library\r
+ * Version: 6.5\r
+ *\r
+ * Copyright (C) 2006 Brian Paul All Rights Reserved.\r
+ *\r
+ * Permission is hereby granted, free of charge, to any person obtaining a\r
+ * copy of this software and associated documentation files (the "Software"),\r
+ * to deal in the Software without restriction, including without limitation\r
+ * the rights to use, copy, modify, merge, publish, distribute, sublicense,\r
+ * and/or sell copies of the Software, and to permit persons to whom the\r
+ * Software is furnished to do so, subject to the following conditions:\r
+ *\r
+ * The above copyright notice and this permission notice shall be included\r
+ * in all copies or substantial portions of the Software.\r
+ *\r
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS\r
+ * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,\r
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL\r
+ * BRIAN PAUL BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN\r
+ * AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN\r
+ * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.\r
+ */\r
+\r
+#include "imports.h"\r
+\r
+/*\r
+ * SimplexNoise1234\r
+ * Copyright © 2003-2005, Stefan Gustavson\r
+ *\r
+ * Contact: stegu@itn.liu.se\r
+ *\r
+ * This library is free software; you can redistribute it and/or\r
+ * modify it under the terms of the GNU General Public\r
+ * License as published by the Free Software Foundation; either\r
+ * version 2 of the License, or (at your option) any later version.\r
+ *\r
+ * This library is distributed in the hope that it will be useful,\r
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of\r
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU\r
+ * General Public License for more details.\r
+ *\r
+ * You should have received a copy of the GNU General Public\r
+ * License along with this library; if not, write to the Free Software\r
+ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA\r
+ */\r
+\r
+/** \file\r
+ \brief C implementation of Perlin Simplex Noise over 1,2,3, and 4 dimensions.\r
+ \author Stefan Gustavson (stegu@itn.liu.se)\r
+*/\r
+\r
+/*\r
+ * This implementation is "Simplex Noise" as presented by\r
+ * Ken Perlin at a relatively obscure and not often cited course\r
+ * session "Real-Time Shading" at Siggraph 2001 (before real\r
+ * time shading actually took on), under the title "hardware noise".\r
+ * The 3D function is numerically equivalent to his Java reference\r
+ * code available in the PDF course notes, although I re-implemented\r
+ * it from scratch to get more readable code. The 1D, 2D and 4D cases\r
+ * were implemented from scratch by me from Ken Perlin's text.\r
+ *\r
+ * This file has no dependencies on any other file, not even its own\r
+ * header file. The header file is made for use by external code only.\r
+ */\r
+\r
+\r
+#define FASTFLOOR(x) ( ((x)>0) ? ((int)x) : (((int)x)-1) )\r
+\r
+/*\r
+ * ---------------------------------------------------------------------\r
+ * Static data\r
+ */\r
+\r
+/*\r
+ * Permutation table. This is just a random jumble of all numbers 0-255,\r
+ * repeated twice to avoid wrapping the index at 255 for each lookup.\r
+ * This needs to be exactly the same for all instances on all platforms,\r
+ * so it's easiest to just keep it as static explicit data.\r
+ * This also removes the need for any initialisation of this class.\r
+ *\r
+ * Note that making this an int[] instead of a char[] might make the\r
+ * code run faster on platforms with a high penalty for unaligned single\r
+ * byte addressing. Intel x86 is generally single-byte-friendly, but\r
+ * some other CPUs are faster with 4-aligned reads.\r
+ * However, a char[] is smaller, which avoids cache trashing, and that\r
+ * is probably the most important aspect on most architectures.\r
+ * This array is accessed a *lot* by the noise functions.\r
+ * A vector-valued noise over 3D accesses it 96 times, and a\r
+ * float-valued 4D noise 64 times. We want this to fit in the cache!\r
+ */\r
+unsigned char perm[512] = {151,160,137,91,90,15,\r
+ 131,13,201,95,96,53,194,233,7,225,140,36,103,30,69,142,8,99,37,240,21,10,23,\r
+ 190, 6,148,247,120,234,75,0,26,197,62,94,252,219,203,117,35,11,32,57,177,33,\r
+ 88,237,149,56,87,174,20,125,136,171,168, 68,175,74,165,71,134,139,48,27,166,\r
+ 77,146,158,231,83,111,229,122,60,211,133,230,220,105,92,41,55,46,245,40,244,\r
+ 102,143,54, 65,25,63,161, 1,216,80,73,209,76,132,187,208, 89,18,169,200,196,\r
+ 135,130,116,188,159,86,164,100,109,198,173,186, 3,64,52,217,226,250,124,123,\r
+ 5,202,38,147,118,126,255,82,85,212,207,206,59,227,47,16,58,17,182,189,28,42,\r
+ 223,183,170,213,119,248,152, 2,44,154,163, 70,221,153,101,155,167, 43,172,9,\r
+ 129,22,39,253, 19,98,108,110,79,113,224,232,178,185, 112,104,218,246,97,228,\r
+ 251,34,242,193,238,210,144,12,191,179,162,241, 81,51,145,235,249,14,239,107,\r
+ 49,192,214, 31,181,199,106,157,184, 84,204,176,115,121,50,45,127, 4,150,254,\r
+ 138,236,205,93,222,114,67,29,24,72,243,141,128,195,78,66,215,61,156,180,\r
+ 151,160,137,91,90,15,\r
+ 131,13,201,95,96,53,194,233,7,225,140,36,103,30,69,142,8,99,37,240,21,10,23,\r
+ 190, 6,148,247,120,234,75,0,26,197,62,94,252,219,203,117,35,11,32,57,177,33,\r
+ 88,237,149,56,87,174,20,125,136,171,168, 68,175,74,165,71,134,139,48,27,166,\r
+ 77,146,158,231,83,111,229,122,60,211,133,230,220,105,92,41,55,46,245,40,244,\r
+ 102,143,54, 65,25,63,161, 1,216,80,73,209,76,132,187,208, 89,18,169,200,196,\r
+ 135,130,116,188,159,86,164,100,109,198,173,186, 3,64,52,217,226,250,124,123,\r
+ 5,202,38,147,118,126,255,82,85,212,207,206,59,227,47,16,58,17,182,189,28,42,\r
+ 223,183,170,213,119,248,152, 2,44,154,163, 70,221,153,101,155,167, 43,172,9,\r
+ 129,22,39,253, 19,98,108,110,79,113,224,232,178,185, 112,104,218,246,97,228,\r
+ 251,34,242,193,238,210,144,12,191,179,162,241, 81,51,145,235,249,14,239,107,\r
+ 49,192,214, 31,181,199,106,157,184, 84,204,176,115,121,50,45,127, 4,150,254,\r
+ 138,236,205,93,222,114,67,29,24,72,243,141,128,195,78,66,215,61,156,180 \r
+};\r
+\r
+/*\r
+ * ---------------------------------------------------------------------\r
+ */\r
+\r
+/*\r
+ * Helper functions to compute gradients-dot-residualvectors (1D to 4D)\r
+ * Note that these generate gradients of more than unit length. To make\r
+ * a close match with the value range of classic Perlin noise, the final\r
+ * noise values need to be rescaled to fit nicely within [-1,1].\r
+ * (The simplex noise functions as such also have different scaling.)\r
+ * Note also that these noise functions are the most practical and useful\r
+ * signed version of Perlin noise. To return values according to the\r
+ * RenderMan specification from the SL noise() and pnoise() functions,\r
+ * the noise values need to be scaled and offset to [0,1], like this:\r
+ * float SLnoise = (SimplexNoise1234::noise(x,y,z) + 1.0) * 0.5;\r
+ */\r
+\r
+static float grad1( int hash, float x ) {\r
+ int h = hash & 15;\r
+ float grad = 1.0f + (h & 7); /* Gradient value 1.0, 2.0, ..., 8.0 */\r
+ if (h&8) grad = -grad; /* Set a random sign for the gradient */\r
+ return ( grad * x ); /* Multiply the gradient with the distance */\r
+}\r
+\r
+static float grad2( int hash, float x, float y ) {\r
+ int h = hash & 7; /* Convert low 3 bits of hash code */\r
+ float u = h<4 ? x : y; /* into 8 simple gradient directions, */\r
+ float v = h<4 ? y : x; /* and compute the dot product with (x,y). */\r
+ return ((h&1)? -u : u) + ((h&2)? -2.0f*v : 2.0f*v);\r
+}\r
+\r
+static float grad3( int hash, float x, float y , float z ) {\r
+ int h = hash & 15; /* Convert low 4 bits of hash code into 12 simple */\r
+ float u = h<8 ? x : y; /* gradient directions, and compute dot product. */\r
+ float v = h<4 ? y : h==12||h==14 ? x : z; /* Fix repeats at h = 12 to 15 */\r
+ return ((h&1)? -u : u) + ((h&2)? -v : v);\r
+}\r
+\r
+static float grad4( int hash, float x, float y, float z, float t ) {\r
+ int h = hash & 31; /* Convert low 5 bits of hash code into 32 simple */\r
+ float u = h<24 ? x : y; /* gradient directions, and compute dot product. */\r
+ float v = h<16 ? y : z;\r
+ float w = h<8 ? z : t;\r
+ return ((h&1)? -u : u) + ((h&2)? -v : v) + ((h&4)? -w : w);\r
+}\r
+\r
+ /* A lookup table to traverse the simplex around a given point in 4D. */\r
+ /* Details can be found where this table is used, in the 4D noise method. */\r
+ /* TODO: This should not be required, backport it from Bill's GLSL code! */\r
+ static unsigned char simplex[64][4] = {\r
+ {0,1,2,3},{0,1,3,2},{0,0,0,0},{0,2,3,1},{0,0,0,0},{0,0,0,0},{0,0,0,0},{1,2,3,0},\r
+ {0,2,1,3},{0,0,0,0},{0,3,1,2},{0,3,2,1},{0,0,0,0},{0,0,0,0},{0,0,0,0},{1,3,2,0},\r
+ {0,0,0,0},{0,0,0,0},{0,0,0,0},{0,0,0,0},{0,0,0,0},{0,0,0,0},{0,0,0,0},{0,0,0,0},\r
+ {1,2,0,3},{0,0,0,0},{1,3,0,2},{0,0,0,0},{0,0,0,0},{0,0,0,0},{2,3,0,1},{2,3,1,0},\r
+ {1,0,2,3},{1,0,3,2},{0,0,0,0},{0,0,0,0},{0,0,0,0},{2,0,3,1},{0,0,0,0},{2,1,3,0},\r
+ {0,0,0,0},{0,0,0,0},{0,0,0,0},{0,0,0,0},{0,0,0,0},{0,0,0,0},{0,0,0,0},{0,0,0,0},\r
+ {2,0,1,3},{0,0,0,0},{0,0,0,0},{0,0,0,0},{3,0,1,2},{3,0,2,1},{0,0,0,0},{3,1,2,0},\r
+ {2,1,0,3},{0,0,0,0},{0,0,0,0},{0,0,0,0},{3,1,0,2},{0,0,0,0},{3,2,0,1},{3,2,1,0}};\r
+\r
+/* 1D simplex noise */\r
+GLfloat _slang_library_noise1 (GLfloat x)\r
+{\r
+ int i0 = FASTFLOOR(x);\r
+ int i1 = i0 + 1;\r
+ float x0 = x - i0;\r
+ float x1 = x0 - 1.0f;\r
+ float t1 = 1.0f - x1*x1;\r
+ float n0, n1;\r
+\r
+ float t0 = 1.0f - x0*x0;\r
+/* if(t0 < 0.0f) t0 = 0.0f; // this never happens for the 1D case */\r
+ t0 *= t0;\r
+ n0 = t0 * t0 * grad1(perm[i0 & 0xff], x0);\r
+\r
+/* if(t1 < 0.0f) t1 = 0.0f; // this never happens for the 1D case */\r
+ t1 *= t1;\r
+ n1 = t1 * t1 * grad1(perm[i1 & 0xff], x1);\r
+ /* The maximum value of this noise is 8*(3/4)^4 = 2.53125 */\r
+ /* A factor of 0.395 would scale to fit exactly within [-1,1], but */\r
+ /* we want to match PRMan's 1D noise, so we scale it down some more. */\r
+ return 0.25f * (n0 + n1);\r
+}\r
+\r
+/* 2D simplex noise */\r
+GLfloat _slang_library_noise2 (GLfloat x, GLfloat y)\r
+{\r
+#define F2 0.366025403f /* F2 = 0.5*(sqrt(3.0)-1.0) */\r
+#define G2 0.211324865f /* G2 = (3.0-Math.sqrt(3.0))/6.0 */\r
+\r
+ float n0, n1, n2; /* Noise contributions from the three corners */\r
+\r
+ /* Skew the input space to determine which simplex cell we're in */\r
+ float s = (x+y)*F2; /* Hairy factor for 2D */\r
+ float xs = x + s;\r
+ float ys = y + s;\r
+ int i = FASTFLOOR(xs);\r
+ int j = FASTFLOOR(ys);\r
+\r
+ float t = (float)(i+j)*G2;\r
+ float X0 = i-t; /* Unskew the cell origin back to (x,y) space */\r
+ float Y0 = j-t;\r
+ float x0 = x-X0; /* The x,y distances from the cell origin */\r
+ float y0 = y-Y0;\r
+\r
+ float x1, y1, x2, y2;\r
+ int ii, jj;\r
+ float t0, t1, t2;\r
+\r
+ /* For the 2D case, the simplex shape is an equilateral triangle. */\r
+ /* Determine which simplex we are in. */\r
+ int i1, j1; /* Offsets for second (middle) corner of simplex in (i,j) coords */\r
+ if(x0>y0) {i1=1; j1=0;} /* lower triangle, XY order: (0,0)->(1,0)->(1,1) */\r
+ else {i1=0; j1=1;} /* upper triangle, YX order: (0,0)->(0,1)->(1,1) */\r
+\r
+ /* A step of (1,0) in (i,j) means a step of (1-c,-c) in (x,y), and */\r
+ /* a step of (0,1) in (i,j) means a step of (-c,1-c) in (x,y), where */\r
+ /* c = (3-sqrt(3))/6 */\r
+\r
+ x1 = x0 - i1 + G2; /* Offsets for middle corner in (x,y) unskewed coords */\r
+ y1 = y0 - j1 + G2;\r
+ x2 = x0 - 1.0f + 2.0f * G2; /* Offsets for last corner in (x,y) unskewed coords */\r
+ y2 = y0 - 1.0f + 2.0f * G2;\r
+\r
+ /* Wrap the integer indices at 256, to avoid indexing perm[] out of bounds */\r
+ ii = i % 256;\r
+ jj = j % 256;\r
+\r
+ /* Calculate the contribution from the three corners */\r
+ t0 = 0.5f - x0*x0-y0*y0;\r
+ if(t0 < 0.0f) n0 = 0.0f;\r
+ else {\r
+ t0 *= t0;\r
+ n0 = t0 * t0 * grad2(perm[ii+perm[jj]], x0, y0); \r
+ }\r
+\r
+ t1 = 0.5f - x1*x1-y1*y1;\r
+ if(t1 < 0.0f) n1 = 0.0f;\r
+ else {\r
+ t1 *= t1;\r
+ n1 = t1 * t1 * grad2(perm[ii+i1+perm[jj+j1]], x1, y1);\r
+ }\r
+\r
+ t2 = 0.5f - x2*x2-y2*y2;\r
+ if(t2 < 0.0f) n2 = 0.0f;\r
+ else {\r
+ t2 *= t2;\r
+ n2 = t2 * t2 * grad2(perm[ii+1+perm[jj+1]], x2, y2);\r
+ }\r
+\r
+ /* Add contributions from each corner to get the final noise value. */\r
+ /* The result is scaled to return values in the interval [-1,1]. */\r
+ return 40.0f * (n0 + n1 + n2); /* TODO: The scale factor is preliminary! */\r
+}\r
+\r
+/* 3D simplex noise */\r
+GLfloat _slang_library_noise3 (GLfloat x, GLfloat y, GLfloat z)\r
+{\r
+/* Simple skewing factors for the 3D case */\r
+#define F3 0.333333333f\r
+#define G3 0.166666667f\r
+\r
+ float n0, n1, n2, n3; /* Noise contributions from the four corners */\r
+\r
+ /* Skew the input space to determine which simplex cell we're in */\r
+ float s = (x+y+z)*F3; /* Very nice and simple skew factor for 3D */\r
+ float xs = x+s;\r
+ float ys = y+s;\r
+ float zs = z+s;\r
+ int i = FASTFLOOR(xs);\r
+ int j = FASTFLOOR(ys);\r
+ int k = FASTFLOOR(zs);\r
+\r
+ float t = (float)(i+j+k)*G3; \r
+ float X0 = i-t; /* Unskew the cell origin back to (x,y,z) space */\r
+ float Y0 = j-t;\r
+ float Z0 = k-t;\r
+ float x0 = x-X0; /* The x,y,z distances from the cell origin */\r
+ float y0 = y-Y0;\r
+ float z0 = z-Z0;\r
+\r
+ float x1, y1, z1, x2, y2, z2, x3, y3, z3;\r
+ int ii, jj, kk;\r
+ float t0, t1, t2, t3;\r
+\r
+ /* For the 3D case, the simplex shape is a slightly irregular tetrahedron. */\r
+ /* Determine which simplex we are in. */\r
+ int i1, j1, k1; /* Offsets for second corner of simplex in (i,j,k) coords */\r
+ int i2, j2, k2; /* Offsets for third corner of simplex in (i,j,k) coords */\r
+\r
+/* This code would benefit from a backport from the GLSL version! */\r
+ if(x0>=y0) {\r
+ if(y0>=z0)\r
+ { i1=1; j1=0; k1=0; i2=1; j2=1; k2=0; } /* X Y Z order */\r
+ else if(x0>=z0) { i1=1; j1=0; k1=0; i2=1; j2=0; k2=1; } /* X Z Y order */\r
+ else { i1=0; j1=0; k1=1; i2=1; j2=0; k2=1; } /* Z X Y order */\r
+ }\r
+ else { /* x0<y0 */\r
+ if(y0<z0) { i1=0; j1=0; k1=1; i2=0; j2=1; k2=1; } /* Z Y X order */\r
+ else if(x0<z0) { i1=0; j1=1; k1=0; i2=0; j2=1; k2=1; } /* Y Z X order */\r
+ else { i1=0; j1=1; k1=0; i2=1; j2=1; k2=0; } /* Y X Z order */\r
+ }\r
+\r
+ /* A step of (1,0,0) in (i,j,k) means a step of (1-c,-c,-c) in (x,y,z), */\r
+ /* a step of (0,1,0) in (i,j,k) means a step of (-c,1-c,-c) in (x,y,z), and */\r
+ /* a step of (0,0,1) in (i,j,k) means a step of (-c,-c,1-c) in (x,y,z), where */\r
+ /* c = 1/6. */\r
+\r
+ x1 = x0 - i1 + G3; /* Offsets for second corner in (x,y,z) coords */\r
+ y1 = y0 - j1 + G3;\r
+ z1 = z0 - k1 + G3;\r
+ x2 = x0 - i2 + 2.0f*G3; /* Offsets for third corner in (x,y,z) coords */\r
+ y2 = y0 - j2 + 2.0f*G3;\r
+ z2 = z0 - k2 + 2.0f*G3;\r
+ x3 = x0 - 1.0f + 3.0f*G3; /* Offsets for last corner in (x,y,z) coords */\r
+ y3 = y0 - 1.0f + 3.0f*G3;\r
+ z3 = z0 - 1.0f + 3.0f*G3;\r
+\r
+ /* Wrap the integer indices at 256, to avoid indexing perm[] out of bounds */\r
+ ii = i % 256;\r
+ jj = j % 256;\r
+ kk = k % 256;\r
+\r
+ /* Calculate the contribution from the four corners */\r
+ t0 = 0.6f - x0*x0 - y0*y0 - z0*z0;\r
+ if(t0 < 0.0f) n0 = 0.0f;\r
+ else {\r
+ t0 *= t0;\r
+ n0 = t0 * t0 * grad3(perm[ii+perm[jj+perm[kk]]], x0, y0, z0);\r
+ }\r
+\r
+ t1 = 0.6f - x1*x1 - y1*y1 - z1*z1;\r
+ if(t1 < 0.0f) n1 = 0.0f;\r
+ else {\r
+ t1 *= t1;\r
+ n1 = t1 * t1 * grad3(perm[ii+i1+perm[jj+j1+perm[kk+k1]]], x1, y1, z1);\r
+ }\r
+\r
+ t2 = 0.6f - x2*x2 - y2*y2 - z2*z2;\r
+ if(t2 < 0.0f) n2 = 0.0f;\r
+ else {\r
+ t2 *= t2;\r
+ n2 = t2 * t2 * grad3(perm[ii+i2+perm[jj+j2+perm[kk+k2]]], x2, y2, z2);\r
+ }\r
+\r
+ t3 = 0.6f - x3*x3 - y3*y3 - z3*z3;\r
+ if(t3<0.0f) n3 = 0.0f;\r
+ else {\r
+ t3 *= t3;\r
+ n3 = t3 * t3 * grad3(perm[ii+1+perm[jj+1+perm[kk+1]]], x3, y3, z3);\r
+ }\r
+\r
+ /* Add contributions from each corner to get the final noise value. */\r
+ /* The result is scaled to stay just inside [-1,1] */\r
+ return 32.0f * (n0 + n1 + n2 + n3); /* TODO: The scale factor is preliminary! */\r
+}\r
+\r
+/* 4D simplex noise */\r
+GLfloat _slang_library_noise4 (GLfloat x, GLfloat y, GLfloat z, GLfloat w)\r
+{\r
+ /* The skewing and unskewing factors are hairy again for the 4D case */\r
+#define F4 0.309016994f /* F4 = (Math.sqrt(5.0)-1.0)/4.0 */\r
+#define G4 0.138196601f /* G4 = (5.0-Math.sqrt(5.0))/20.0 */\r
+\r
+ float n0, n1, n2, n3, n4; /* Noise contributions from the five corners */\r
+\r
+ /* Skew the (x,y,z,w) space to determine which cell of 24 simplices we're in */\r
+ float s = (x + y + z + w) * F4; /* Factor for 4D skewing */\r
+ float xs = x + s;\r
+ float ys = y + s;\r
+ float zs = z + s;\r
+ float ws = w + s;\r
+ int i = FASTFLOOR(xs);\r
+ int j = FASTFLOOR(ys);\r
+ int k = FASTFLOOR(zs);\r
+ int l = FASTFLOOR(ws);\r
+\r
+ float t = (i + j + k + l) * G4; /* Factor for 4D unskewing */\r
+ float X0 = i - t; /* Unskew the cell origin back to (x,y,z,w) space */\r
+ float Y0 = j - t;\r
+ float Z0 = k - t;\r
+ float W0 = l - t;\r
+\r
+ float x0 = x - X0; /* The x,y,z,w distances from the cell origin */\r
+ float y0 = y - Y0;\r
+ float z0 = z - Z0;\r
+ float w0 = w - W0;\r
+\r
+ /* For the 4D case, the simplex is a 4D shape I won't even try to describe. */\r
+ /* To find out which of the 24 possible simplices we're in, we need to */\r
+ /* determine the magnitude ordering of x0, y0, z0 and w0. */\r
+ /* The method below is a good way of finding the ordering of x,y,z,w and */\r
+ /* then find the correct traversal order for the simplex we\92re in. */\r
+ /* First, six pair-wise comparisons are performed between each possible pair */\r
+ /* of the four coordinates, and the results are used to add up binary bits */\r
+ /* for an integer index. */\r
+ int c1 = (x0 > y0) ? 32 : 0;\r
+ int c2 = (x0 > z0) ? 16 : 0;\r
+ int c3 = (y0 > z0) ? 8 : 0;\r
+ int c4 = (x0 > w0) ? 4 : 0;\r
+ int c5 = (y0 > w0) ? 2 : 0;\r
+ int c6 = (z0 > w0) ? 1 : 0;\r
+ int c = c1 + c2 + c3 + c4 + c5 + c6;\r
+\r
+ int i1, j1, k1, l1; /* The integer offsets for the second simplex corner */\r
+ int i2, j2, k2, l2; /* The integer offsets for the third simplex corner */\r
+ int i3, j3, k3, l3; /* The integer offsets for the fourth simplex corner */\r
+\r
+ float x1, y1, z1, w1, x2, y2, z2, w2, x3, y3, z3, w3, x4, y4, z4, w4;\r
+ int ii, jj, kk, ll;\r
+ float t0, t1, t2, t3, t4;\r
+\r
+ /* simplex[c] is a 4-vector with the numbers 0, 1, 2 and 3 in some order. */\r
+ /* Many values of c will never occur, since e.g. x>y>z>w makes x<z, y<w and x<w */\r
+ /* impossible. Only the 24 indices which have non-zero entries make any sense. */\r
+ /* We use a thresholding to set the coordinates in turn from the largest magnitude. */\r
+ /* The number 3 in the "simplex" array is at the position of the largest coordinate. */\r
+ i1 = simplex[c][0]>=3 ? 1 : 0;\r
+ j1 = simplex[c][1]>=3 ? 1 : 0;\r
+ k1 = simplex[c][2]>=3 ? 1 : 0;\r
+ l1 = simplex[c][3]>=3 ? 1 : 0;\r
+ /* The number 2 in the "simplex" array is at the second largest coordinate. */\r
+ i2 = simplex[c][0]>=2 ? 1 : 0;\r
+ j2 = simplex[c][1]>=2 ? 1 : 0;\r
+ k2 = simplex[c][2]>=2 ? 1 : 0;\r
+ l2 = simplex[c][3]>=2 ? 1 : 0;\r
+ /* The number 1 in the "simplex" array is at the second smallest coordinate. */\r
+ i3 = simplex[c][0]>=1 ? 1 : 0;\r
+ j3 = simplex[c][1]>=1 ? 1 : 0;\r
+ k3 = simplex[c][2]>=1 ? 1 : 0;\r
+ l3 = simplex[c][3]>=1 ? 1 : 0;\r
+ /* The fifth corner has all coordinate offsets = 1, so no need to look that up. */\r
+\r
+ x1 = x0 - i1 + G4; /* Offsets for second corner in (x,y,z,w) coords */\r
+ y1 = y0 - j1 + G4;\r
+ z1 = z0 - k1 + G4;\r
+ w1 = w0 - l1 + G4;\r
+ x2 = x0 - i2 + 2.0f*G4; /* Offsets for third corner in (x,y,z,w) coords */\r
+ y2 = y0 - j2 + 2.0f*G4;\r
+ z2 = z0 - k2 + 2.0f*G4;\r
+ w2 = w0 - l2 + 2.0f*G4;\r
+ x3 = x0 - i3 + 3.0f*G4; /* Offsets for fourth corner in (x,y,z,w) coords */\r
+ y3 = y0 - j3 + 3.0f*G4;\r
+ z3 = z0 - k3 + 3.0f*G4;\r
+ w3 = w0 - l3 + 3.0f*G4;\r
+ x4 = x0 - 1.0f + 4.0f*G4; /* Offsets for last corner in (x,y,z,w) coords */\r
+ y4 = y0 - 1.0f + 4.0f*G4;\r
+ z4 = z0 - 1.0f + 4.0f*G4;\r
+ w4 = w0 - 1.0f + 4.0f*G4;\r
+\r
+ /* Wrap the integer indices at 256, to avoid indexing perm[] out of bounds */\r
+ ii = i % 256;\r
+ jj = j % 256;\r
+ kk = k % 256;\r
+ ll = l % 256;\r
+\r
+ /* Calculate the contribution from the five corners */\r
+ t0 = 0.6f - x0*x0 - y0*y0 - z0*z0 - w0*w0;\r
+ if(t0 < 0.0f) n0 = 0.0f;\r
+ else {\r
+ t0 *= t0;\r
+ n0 = t0 * t0 * grad4(perm[ii+perm[jj+perm[kk+perm[ll]]]], x0, y0, z0, w0);\r
+ }\r
+\r
+ t1 = 0.6f - x1*x1 - y1*y1 - z1*z1 - w1*w1;\r
+ if(t1 < 0.0f) n1 = 0.0f;\r
+ else {\r
+ t1 *= t1;\r
+ n1 = t1 * t1 * grad4(perm[ii+i1+perm[jj+j1+perm[kk+k1+perm[ll+l1]]]], x1, y1, z1, w1);\r
+ }\r
+\r
+ t2 = 0.6f - x2*x2 - y2*y2 - z2*z2 - w2*w2;\r
+ if(t2 < 0.0f) n2 = 0.0f;\r
+ else {\r
+ t2 *= t2;\r
+ n2 = t2 * t2 * grad4(perm[ii+i2+perm[jj+j2+perm[kk+k2+perm[ll+l2]]]], x2, y2, z2, w2);\r
+ }\r
+\r
+ t3 = 0.6f - x3*x3 - y3*y3 - z3*z3 - w3*w3;\r
+ if(t3 < 0.0f) n3 = 0.0f;\r
+ else {\r
+ t3 *= t3;\r
+ n3 = t3 * t3 * grad4(perm[ii+i3+perm[jj+j3+perm[kk+k3+perm[ll+l3]]]], x3, y3, z3, w3);\r
+ }\r
+\r
+ t4 = 0.6f - x4*x4 - y4*y4 - z4*z4 - w4*w4;\r
+ if(t4 < 0.0f) n4 = 0.0f;\r
+ else {\r
+ t4 *= t4;\r
+ n4 = t4 * t4 * grad4(perm[ii+1+perm[jj+1+perm[kk+1+perm[ll+1]]]], x4, y4, z4, w4);\r
+ }\r
+\r
+ /* Sum up and scale the result to cover the range [-1,1] */\r
+ return 27.0f * (n0 + n1 + n2 + n3 + n4); /* TODO: The scale factor is preliminary! */\r
+}\r
+\r
--- /dev/null
+/*\r
+ * Mesa 3-D graphics library\r
+ * Version: 6.5\r
+ *\r
+ * Copyright (C) 2006 Brian Paul All Rights Reserved.\r
+ *\r
+ * Permission is hereby granted, free of charge, to any person obtaining a\r
+ * copy of this software and associated documentation files (the "Software"),\r
+ * to deal in the Software without restriction, including without limitation\r
+ * the rights to use, copy, modify, merge, publish, distribute, sublicense,\r
+ * and/or sell copies of the Software, and to permit persons to whom the\r
+ * Software is furnished to do so, subject to the following conditions:\r
+ *\r
+ * The above copyright notice and this permission notice shall be included\r
+ * in all copies or substantial portions of the Software.\r
+ *\r
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS\r
+ * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,\r
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL\r
+ * BRIAN PAUL BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN\r
+ * AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN\r
+ * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.\r
+ */\r
+\r
+#if !defined SLANG_LIBRARY_NOISE_H\r
+#define SLANG_LIBRARY_NOISE_H\r
+\r
+#if defined __cplusplus\r
+extern "C" {\r
+#endif\r
+\r
+GLfloat _slang_library_noise1 (GLfloat);\r
+GLfloat _slang_library_noise2 (GLfloat, GLfloat);\r
+GLfloat _slang_library_noise3 (GLfloat, GLfloat, GLfloat);\r
+GLfloat _slang_library_noise4 (GLfloat, GLfloat, GLfloat, GLfloat);\r
+\r
+#ifdef __cplusplus\r
+}\r
+#endif\r
+\r
+#endif\r
+\r
/* slang_storage_array */
-int slang_storage_array_construct (slang_storage_array *arr)
+GLboolean slang_storage_array_construct (slang_storage_array *arr)
{
arr->type = slang_stor_aggregate;
arr->aggregate = NULL;
arr->length = 0;\r
- return 1;
+ return GL_TRUE;
}
-void slang_storage_array_destruct (slang_storage_array *arr)
+GLvoid slang_storage_array_destruct (slang_storage_array *arr)
{
if (arr->aggregate != NULL)
{
/* slang_storage_aggregate */
-int slang_storage_aggregate_construct (slang_storage_aggregate *agg)
+GLboolean slang_storage_aggregate_construct (slang_storage_aggregate *agg)
{
agg->arrays = NULL;
agg->count = 0;\r
- return 1;
+ return GL_TRUE;
}
-void slang_storage_aggregate_destruct (slang_storage_aggregate *agg)
+GLvoid slang_storage_aggregate_destruct (slang_storage_aggregate *agg)
{
- unsigned int i;\r
+ GLuint i;\r
for (i = 0; i < agg->count; i++)
slang_storage_array_destruct (agg->arrays + i);
static slang_storage_array *slang_storage_aggregate_push_new (slang_storage_aggregate *agg)
{
- slang_storage_array *arr = NULL;
+ slang_storage_array *arr = NULL;\r
+
agg->arrays = (slang_storage_array *) slang_alloc_realloc (agg->arrays, agg->count * sizeof (
slang_storage_array), (agg->count + 1) * sizeof (slang_storage_array));
if (agg->arrays != NULL)
/* _slang_aggregate_variable() */
-static int aggregate_vector (slang_storage_aggregate *agg, slang_storage_type basic_type,
- unsigned int row_count)
+static GLboolean aggregate_vector (slang_storage_aggregate *agg, slang_storage_type basic_type,
+ GLuint row_count)
{
slang_storage_array *arr = slang_storage_aggregate_push_new (agg);
if (arr == NULL)
- return 0;
+ return GL_FALSE;
arr->type = basic_type;
arr->length = row_count;
- return 1;
+ return GL_TRUE;
}
-static int aggregate_matrix (slang_storage_aggregate *agg, slang_storage_type basic_type,
- unsigned int dimension)
+static GLboolean aggregate_matrix (slang_storage_aggregate *agg, slang_storage_type basic_type,
+ GLuint dimension)
{
slang_storage_array *arr = slang_storage_aggregate_push_new (agg);\r
if (arr == NULL)
- return 0;
+ return GL_FALSE;
arr->type = slang_stor_aggregate;
arr->length = dimension;
- arr->aggregate = (slang_storage_aggregate *) slang_alloc_malloc (sizeof (
- slang_storage_aggregate));
+ arr->aggregate = (slang_storage_aggregate *) slang_alloc_malloc (sizeof (slang_storage_aggregate));
if (arr->aggregate == NULL)
- return 0;
+ return GL_FALSE;
if (!slang_storage_aggregate_construct (arr->aggregate))\r
{\r
slang_alloc_free (arr->aggregate);\r
arr->aggregate = NULL;\r
- return 0;\r
+ return GL_FALSE;\r
}
if (!aggregate_vector (arr->aggregate, basic_type, dimension))
- return 0;
- return 1;
+ return GL_FALSE;
+ return GL_TRUE;
}
-static int aggregate_variables (slang_storage_aggregate *agg, slang_variable_scope *vars,
+static GLboolean aggregate_variables (slang_storage_aggregate *agg, slang_variable_scope *vars,
slang_function_scope *funcs, slang_struct_scope *structs, slang_variable_scope *globals,\r
slang_machine *mach, slang_assembly_file *file, slang_atom_pool *atoms)
{
- unsigned int i;
+ GLuint i;\r
+
for (i = 0; i < vars->num_variables; i++)
if (!_slang_aggregate_variable (agg, &vars->variables[i].type.specifier,
vars->variables[i].array_size, funcs, structs, globals, mach, file, atoms))
- return 0;
- return 1;
+ return GL_FALSE;
+ return GL_TRUE;
}
\r
-static int eval_array_size (slang_assembly_file *file, slang_machine *pmach,\r
+static GLboolean eval_array_size (slang_assembly_file *file, slang_machine *pmach,\r
slang_assembly_name_space *space, slang_operation *array_size, GLuint *plength,\r
slang_atom_pool *atoms)\r
{\r
slang_assembly_file_restore_point point;\r
- slang_assembly_local_info info;\r
- slang_assembly_flow_control flow;\r
- slang_assembly_stack_info stk;\r
slang_machine mach;\r
+ slang_assemble_ctx A;\r
+\r
+ A.file = file;\r
+ A.mach = pmach;\r
+ A.atoms = atoms;\r
+ A.space = *space;\r
+ A.local.ret_size = 0;\r
+ A.local.addr_tmp = 0;\r
+ A.local.swizzle_tmp = 4;\r
\r
/* save the current assembly */\r
if (!slang_assembly_file_restore_point_save (file, &point))\r
- return 0;\r
+ return GL_FALSE;\r
\r
/* setup the machine */\r
mach = *pmach;\r
mach.ip = file->count;\r
\r
/* allocate local storage for expression */\r
- info.ret_size = 0;\r
- info.addr_tmp = 0;\r
- info.swizzle_tmp = 4;\r
if (!slang_assembly_file_push_label (file, slang_asm_local_alloc, 20))\r
- return 0;\r
+ return GL_FALSE;\r
if (!slang_assembly_file_push_label (file, slang_asm_enter, 20))\r
- return 0;\r
+ return GL_FALSE;\r
\r
/* insert the actual expression */\r
- if (!_slang_assemble_operation (file, array_size, 0, &flow, space, &info, &stk, pmach, atoms))\r
- return 0;\r
+ if (!_slang_assemble_operation_ (&A, array_size, slang_ref_forbid))\r
+ return GL_FALSE;\r
if (!slang_assembly_file_push (file, slang_asm_exit))\r
- return 0;\r
+ return GL_FALSE;\r
\r
/* execute the expression */\r
if (!_slang_execute2 (file, &mach))\r
- return 0;\r
+ return GL_FALSE;\r
\r
/* the evaluated expression is on top of the stack */\r
*plength = (GLuint) mach.mem[mach.sp + SLANG_MACHINE_GLOBAL_SIZE]._float;\r
\r
/* restore the old assembly */\r
if (!slang_assembly_file_restore_point_load (file, &point))\r
- return 0;\r
- return 1;\r
+ return GL_FALSE;\r
+\r
+ return GL_TRUE;\r
}\r
-int _slang_aggregate_variable (slang_storage_aggregate *agg, slang_type_specifier *spec,
+GLboolean _slang_aggregate_variable (slang_storage_aggregate *agg, slang_type_specifier *spec,
slang_operation *array_size, slang_function_scope *funcs, slang_struct_scope *structs,
slang_variable_scope *vars, slang_machine *mach, slang_assembly_file *file,\r
slang_atom_pool *atoms)
arr = slang_storage_aggregate_push_new (agg);
if (arr == NULL)
- return 0;
+ return GL_FALSE;
arr->type = slang_stor_aggregate;
- arr->aggregate = (slang_storage_aggregate *) slang_alloc_malloc (sizeof (
- slang_storage_aggregate));
+ arr->aggregate = (slang_storage_aggregate *) slang_alloc_malloc (sizeof (slang_storage_aggregate));
if (arr->aggregate == NULL)
- return 0;
+ return GL_FALSE;
if (!slang_storage_aggregate_construct (arr->aggregate))\r
{\r
slang_alloc_free (arr->aggregate);\r
arr->aggregate = NULL;\r
- return 0;\r
+ return GL_FALSE;\r
}
if (!_slang_aggregate_variable (arr->aggregate, spec->_array, NULL, funcs, structs,\r
vars, mach, file, atoms))
- return 0;\r
+ return GL_FALSE;\r
space.funcs = funcs;\r
space.structs = structs;\r
space.vars = vars;\r
if (!eval_array_size (file, mach, &space, array_size, &arr->length, atoms))\r
- return 0;
+ return GL_FALSE;
}
- return 1;
+ return GL_TRUE;
default:
- return 0;
+ return GL_FALSE;
}
}
/* _slang_sizeof_aggregate() */
-unsigned int _slang_sizeof_aggregate (const slang_storage_aggregate *agg)
+GLuint _slang_sizeof_aggregate (const slang_storage_aggregate *agg)
{
- unsigned int i, size = 0;\r
+ GLuint i, size = 0;\r
for (i = 0; i < agg->count; i++)
{
- unsigned int element_size;\r
+ GLuint element_size;\r
if (agg->arrays[i].type == slang_stor_aggregate)
element_size = _slang_sizeof_aggregate (agg->arrays[i].aggregate);
/* _slang_flatten_aggregate () */
-int _slang_flatten_aggregate (slang_storage_aggregate *flat, const slang_storage_aggregate *agg)
+GLboolean _slang_flatten_aggregate (slang_storage_aggregate *flat, const slang_storage_aggregate *agg)
{
- unsigned int i;\r
+ GLuint i;\r
for (i = 0; i < agg->count; i++)
{
- unsigned int j;\r
+ GLuint j;\r
for (j = 0; j < agg->arrays[i].length; j++)
{
if (agg->arrays[i].type == slang_stor_aggregate)
{
if (!_slang_flatten_aggregate (flat, agg->arrays[i].aggregate))
- return 0;
+ return GL_FALSE;
}
else
{
arr = slang_storage_aggregate_push_new (flat);
if (arr == NULL)
- return 0;
+ return GL_FALSE;
arr->type = agg->arrays[i].type;
arr->length = 1;
}
}
}
- return 1;
+ return GL_TRUE;
}
#endif
/*
- Program variable data storage is kept completely transparent to the front-end compiler. It is
- up to the back-end how the data is actually allocated. The slang_storage_type enum
- provides the basic information about how the memory is interpreted. This abstract piece
- of memory is called a data slot. A data slot of a particular type has a fixed size.
-
- For now, only the three basic types are supported, that is bool, int and float. Other built-in
- types like vector or matrix can easily be decomposed into a series of basic types.
-*/
+ * Program variable data storage is kept completely transparent to the front-end compiler. It is
+ * up to the back-end how the data is actually allocated. The slang_storage_type enum
+ * provides the basic information about how the memory is interpreted. This abstract piece
+ * of memory is called a data slot. A data slot of a particular type has a fixed size.
+ *
+ * For now, only the three basic types are supported, that is bool, int and float. Other built-in
+ * types like vector or matrix can easily be decomposed into a series of basic types.
+ */
typedef enum slang_storage_type_
{
slang_stor_aggregate,
} slang_storage_type;
/*
- The slang_storage_array structure groups data slots of the same type into an array. This
- array has a fixed length. Arrays are required to have a size equal to the sum of sizes of its
- elements. They are also required to support indirect addressing. That is, if B references
- first data slot in the array, S is the size of the data slot and I is the integral index that
- is not known at compile time, B+I*S references I-th data slot.
-
- This structure is also used to break down built-in data types that are not supported directly.
- Vectors, like vec3, are constructed from arrays of their basic types. Matrices are formed of
- an array of column vectors, which are in turn processed as other vectors.
-*/
+ * The slang_storage_array structure groups data slots of the same type into an array. This
+ * array has a fixed length. Arrays are required to have a size equal to the sum of sizes of its
+ * elements. They are also required to support indirect addressing. That is, if B references
+ * first data slot in the array, S is the size of the data slot and I is the integral index that
+ * is not known at compile time, B+I*S references I-th data slot.
+ *\r
+ * This structure is also used to break down built-in data types that are not supported directly.
+ * Vectors, like vec3, are constructed from arrays of their basic types. Matrices are formed of
+ * an array of column vectors, which are in turn processed as other vectors.
+ */
typedef struct slang_storage_array_
{
slang_storage_type type;
struct slang_storage_aggregate_ *aggregate; /* slang_stor_aggregate */
- unsigned int length;
+ GLuint length;
} slang_storage_array;
-int slang_storage_array_construct (slang_storage_array *);
-void slang_storage_array_destruct (slang_storage_array *);
+GLboolean slang_storage_array_construct (slang_storage_array *);
+GLvoid slang_storage_array_destruct (slang_storage_array *);
/*
- The slang_storage_aggregate structure relaxes the indirect addressing requirement for
- slang_storage_array structure. Aggregates are always accessed statically - its member
- addresses are well-known at compile time. For example, user-defined types are implemented as
- aggregates. Aggregates can collect data of a different type.
-*/
+ * The slang_storage_aggregate structure relaxes the indirect addressing requirement for
+ * slang_storage_array structure. Aggregates are always accessed statically - its member
+ * addresses are well-known at compile time. For example, user-defined types are implemented as
+ * aggregates. Aggregates can collect data of a different type.
+ */
typedef struct slang_storage_aggregate_
{
slang_storage_array *arrays;
- unsigned int count;
+ GLuint count;
} slang_storage_aggregate;
-int slang_storage_aggregate_construct (slang_storage_aggregate *);
-void slang_storage_aggregate_destruct (slang_storage_aggregate *);
+GLboolean slang_storage_aggregate_construct (slang_storage_aggregate *);
+GLvoid slang_storage_aggregate_destruct (slang_storage_aggregate *);
-int _slang_aggregate_variable (slang_storage_aggregate *, struct slang_type_specifier_ *,
+GLboolean _slang_aggregate_variable (slang_storage_aggregate *, struct slang_type_specifier_ *,
struct slang_operation_ *, struct slang_function_scope_ *, slang_struct_scope *,
slang_variable_scope *, struct slang_machine_ *, struct slang_assembly_file_ *,\r
slang_atom_pool *);
/*
- returns total size (in machine units) of the given aggregate
- returns 0 on error
-*/
-unsigned int _slang_sizeof_aggregate (const slang_storage_aggregate *);
+ * Returns total size (in machine units) of the given aggregate.
+ * Returns 0 on error.
+ */
+GLuint _slang_sizeof_aggregate (const slang_storage_aggregate *);
/*
- converts structured aggregate to a flat one, with arrays of generic type being
- one-element long
- returns 1 on success
- returns 0 otherwise
-*/
-int _slang_flatten_aggregate (slang_storage_aggregate *, const slang_storage_aggregate *);
+ * Converts structured aggregate to a flat one, with arrays of generic type being
+ * one-element long.
+ * Returns GL_TRUE on success.
+ * Returns GL_FALSE otherwise.
+ */
+GLboolean _slang_flatten_aggregate (slang_storage_aggregate *, const slang_storage_aggregate *);
#ifdef __cplusplus
}
shader/slang/slang_compile_struct.c \
shader/slang/slang_compile_variable.c \
shader/slang/slang_execute.c \
+ shader/slang/slang_library_noise.c \
shader/slang/slang_preprocess.c \
shader/slang/slang_storage.c \
shader/slang/slang_utility.c
_mesa_memcpy (&store->outputs[attr].data[i], vec, 16);\r
}\r
\r
-static void fetch_uniform_mat4 (const char *name, const GLmatrix *matrix, GLuint index,\r
+static void fetch_uniform_mat4 (const char *name, GLmatrix *matrix, GLuint index,\r
struct gl2_vertex_shader_intf **vs)\r
{\r
- /* XXX: transpose? */\r
+ GLuint len;\r
+ GLfloat mat[16];\r
+ char buffer[64];\r
+\r
+ _mesa_strcpy (buffer, name);\r
+ len = _mesa_strlen (name);\r
+\r
+ /* we want inverse matrix */\r
+ if (!matrix->inv)\r
+ {\r
+ /* allocate inverse matrix and make it dirty */\r
+ _math_matrix_alloc_inv (matrix);\r
+ _math_matrix_loadf (matrix, matrix->m);\r
+ }\r
+ _math_matrix_analyse (matrix);\r
+\r
+ /* identity */\r
_slang_fetch_mat4 (vs, name, matrix->m, index, 1);\r
+\r
+ /* transpose */\r
+ _mesa_strcpy (buffer + len, "Transpose");\r
+ _math_transposef (mat, matrix->m);\r
+ _slang_fetch_mat4 (vs, buffer, mat, index, 1);\r
+\r
+ /* inverse */\r
+ _mesa_strcpy (buffer + len, "Inverse");\r
+ _slang_fetch_mat4 (vs, buffer, matrix->inv, index, 1);\r
+\r
+ /* inverse transpose */\r
+ _mesa_strcpy (buffer + len, "InverseTranspose");\r
+ _math_transposef (mat, matrix->inv);\r
+ _slang_fetch_mat4 (vs, buffer, mat, index, 1);\r
}\r
\r
static void fetch_normal_matrix (const char *name, GLmatrix *matrix,\r
GLfloat mat[9];\r
\r
_math_matrix_analyse (matrix);\r
+\r
+ /* inverse transpose */\r
mat[0] = matrix->inv[0];\r
- mat[1] = matrix->inv[1];\r
- mat[2] = matrix->inv[2];\r
- mat[3] = matrix->inv[4];\r
+ mat[1] = matrix->inv[4];\r
+ mat[2] = matrix->inv[8];\r
+ mat[3] = matrix->inv[1];\r
mat[4] = matrix->inv[5];\r
- mat[5] = matrix->inv[6];\r
- mat[6] = matrix->inv[8];\r
- mat[7] = matrix->inv[9];\r
+ mat[5] = matrix->inv[9];\r
+ mat[6] = matrix->inv[2];\r
+ mat[7] = matrix->inv[6];\r
mat[8] = matrix->inv[10];\r
_slang_fetch_mat3 (vs, name, mat, 0, 1);\r
}\r
for (j = 0; j < 8; j++)\r
fetch_uniform_mat4 ("gl_TextureMatrix", ctx->TextureMatrixStack[j].Top, j, vs);\r
fetch_normal_matrix ("gl_NormalMatrix", ctx->ModelviewMatrixStack.Top, vs);\r
- /* XXX: fetch uniform mat4 gl_ModelViewMatrixInverse */\r
- /* XXX: fetch uniform mat4 gl_ProjectionMatrixInverse */\r
- /* XXX: fetch uniform mat4 gl_ModelViewProjectionMatrixInverse */\r
- /* XXX: fetch uniform mat4 gl_TextureMatrixInverse */\r
- /* XXX: fetch uniform mat4 gl_ModelViewMatrixTranspose */\r
- /* XXX: fetch uniform mat4 gl_ProjectionMatrixTranspose */\r
- /* XXX: fetch uniform mat4 gl_ModelViewProjectionMatrixTranspose */\r
- /* XXX: fetch uniform mat4 gl_TextureMatrixTranspose */\r
- /* XXX: fetch uniform mat4 gl_ModelViewMatrixInverseTranspose */\r
- /* XXX: fetch uniform mat4 gl_ProjectionMatrixInverseTranspose */\r
- /* XXX: fetch uniform mat4 gl_ModelViewProjectionMatrixInverseTranspose */\r
- /* XXX: fetch uniform mat4 gl_TextureMatrixInverseTranspose */\r
/* XXX: fetch uniform float gl_NormalScale */\r
/* XXX: fetch uniform mat4 gl_ClipPlane */\r
/* XXX: fetch uniform mat4 gl_TextureEnvColor */\r
# End Source File\r
# Begin Source File\r
\r
+SOURCE=..\..\..\..\src\mesa\shader\slang\slang_library_noise.c\r
+# End Source File\r
+# Begin Source File\r
+\r
SOURCE=..\..\..\..\src\mesa\shader\slang\slang_preprocess.c\r
# End Source File\r
# Begin Source File\r
# End Source File\r
# Begin Source File\r
\r
+SOURCE=..\..\..\..\src\mesa\shader\slang\slang_library_noise.h\r
+# End Source File\r
+# Begin Source File\r
+\r
SOURCE=..\..\..\..\src\mesa\shader\slang\slang_mesa.h\r
# End Source File\r
# Begin Source File\r