<commit_before>import { Type, TypeMap } from '../type';
import {
  PrimitiveType,
  FunType,
  VariadicFunType,
  OverloadedType,
  ConstructorType,
  InstanceType,
  CodeType,
  INT,
  FLOAT,
  ANY,
  VOID,
  STRING,
  BOOLEAN
} from '../type';
import * as ast from '../ast';
import { CompilerIR, Prog, nearest_quote } from '../compile/ir';
import { varsym } from './emitutil';
import { Emitter, specialized_prog } from './emitter';
import { FUNC_ANNOTATION } from './js';

// General OpenGL-related backend components.

// Special GLSL matrix and vector types.
// Someday, a more structured notion of generic vector and matrix types would
// be better. For now, we just support a handful of common types.
export const FLOAT2 = new PrimitiveType("Float2");
export const FLOAT3 = new PrimitiveType("Float3");
export const FLOAT4 = new PrimitiveType("Float4");
export const FLOAT3X3 = new PrimitiveType("Float3x3");
export const FLOAT4X4 = new PrimitiveType("Float4x4");
export const ARRAY = new ConstructorType("Array");
export const INT3 = new PrimitiveType("Int3");
export const INT4 = new PrimitiveType("Int4");

// A type for textures (on the CPU) and sampler IDs (on the GPU).
export const TEXTURE = new PrimitiveType("Texture");
export const CUBE_TEXTURE = new PrimitiveType("CubeTexture");
export const FRAMEBUFFER = new PrimitiveType("Framebuffer");

export const GL_TYPES: TypeMap = {
  "Float2": FLOAT2,
  "Float3": FLOAT3,
  "Float4": FLOAT4,
  "Vec2": FLOAT2,
  "Vec3": FLOAT3,  // Convenient OpenGL-esque names.
  "Vec4": FLOAT4,
  "Float3x3": FLOAT3X3,
  "Float4x4": FLOAT4X4,
  "Mat3": FLOAT3X3,
  "Mat4": FLOAT4X4,
  "Int3": INT3,
  "Int4": INT4,
  "Array": ARRAY,

  // TODO This Mesh type is used by the dingus. It is an opaque type. It would
  // be nice if the dingus could declare the Mesh type itself rather than
  // needing to bake it in here.
  "Mesh": new PrimitiveType("Mesh"),

  "Texture": TEXTURE,
  "CubeTexture": CUBE_TEXTURE,
  "Framebuffer": FRAMEBUFFER,
  "Image": new PrimitiveType("Image"),
};

export const NUMERIC_TYPES: Type[] = [
  FLOAT3, FLOAT4,
  FLOAT3X3, FLOAT4X4,
  INT3, INT4,
];

export const TYPE_NAMES: { [_: string]: string } = {
  "Int": "int",
  "Int3": "ivec3",
  "Int4": "ivec4",
  "Float": "float",
  "Float2": "vec2",
  "Float3": "vec3",
  "Float4": "vec4",
  "Float3x3": "mat3",
  "Float4x4": "mat4",
  "Texture": "sampler2D",
  "CubeTexture": "samplerCube",
};

export const FRAG_INTRINSIC = "fragment";
export const VTX_INTRINSIC = "vertex";
export const SHADER_ANNOTATION = "glsl";

const _GL_UNARY_TYPE = new OverloadedType([
  new FunType([INT], INT),
  new FunType([FLOAT], FLOAT),
  new FunType([FLOAT2], FLOAT2),
  new FunType([FLOAT3], FLOAT3),
  new FunType([FLOAT4], FLOAT4),
]);
const _GL_BINARY_TYPE = new OverloadedType([
  new FunType([INT, INT], INT),
  new FunType([FLOAT, FLOAT], FLOAT),
  new FunType([FLOAT2, FLOAT2], FLOAT2),
  new FunType([FLOAT3, FLOAT3], FLOAT3),
  new FunType([FLOAT4, FLOAT4], FLOAT4),
  new FunType([FLOAT3X3, FLOAT3X3], FLOAT3X3),
  new FunType([FLOAT4X4, FLOAT4X4], FLOAT4X4),

  // Vector-by-scalar.
  new FunType([FLOAT2, FLOAT], FLOAT2),
  new FunType([FLOAT3, FLOAT], FLOAT3),
  new FunType([FLOAT4, FLOAT], FLOAT4),
]);
const _GL_ARITH_UNARY_TYPE = new OverloadedType([
  new FunType([INT], INT),
  new FunType([FLOAT], FLOAT),
  new FunType([FLOAT2], FLOAT2),
  new FunType([FLOAT3], FLOAT3),
  new FunType([FLOAT4], FLOAT4),
  new FunType([FLOAT3X3], FLOAT3X3),
  new FunType([FLOAT4X4], FLOAT4X4),
]);
const _GL_ARITH_BINARY_TYPE = new OverloadedType([
  new FunType([INT, INT], INT),
  new FunType([FLOAT, FLOAT], FLOAT),
  new FunType([FLOAT2, FLOAT2], FLOAT2),
  new FunType([FLOAT3, FLOAT3], FLOAT3),
  new FunType([FLOAT4, FLOAT4], FLOAT4),
  new FunType([FLOAT3X3, FLOAT3X3], FLOAT3X3),
  new FunType([FLOAT4X4, FLOAT4X4], FLOAT4X4),

  // Vector- or matrix-by-scalar.
  new FunType([FLOAT2, FLOAT], FLOAT2),
  new FunType([FLOAT, FLOAT2], FLOAT2),
  new FunType([FLOAT3, FLOAT], FLOAT3),
  new FunType([FLOAT, FLOAT3], FLOAT3),
  new FunType([FLOAT4, FLOAT], FLOAT4),
  new FunType([FLOAT, FLOAT4], FLOAT4),
  new FunType([FLOAT3X3, FLOAT], FLOAT3X3),
  new FunType([FLOAT, FLOAT3X3], FLOAT3X3),
  new FunType([FLOAT4X4, FLOAT], FLOAT4X4),
  new FunType([FLOAT, FLOAT4X4], FLOAT4X4),
]);
const _GL_COMPARE_TYPE = new OverloadedType([
  new FunType([INT, INT], BOOLEAN),
  new FunType([FLOAT, FLOAT], BOOLEAN),
]);
const _GL_ARITH_UNARY_BINARY_TYPE = new OverloadedType(
  _GL_ARITH_UNARY_TYPE.types.concat(_GL_ARITH_BINARY_TYPE.types)
);
const _GL_MUL_TYPE = new OverloadedType([
  new FunType([INT, INT], INT),
  new FunType([FLOAT, FLOAT], FLOAT),
  new FunType([FLOAT2, FLOAT2], FLOAT2),
  new FunType([FLOAT3, FLOAT3], FLOAT3),
  new FunType([FLOAT4, FLOAT4], FLOAT4),
  new FunType([FLOAT3X3, FLOAT3X3], FLOAT3X3),
  new FunType([FLOAT4X4, FLOAT4X4], FLOAT4X4),

  // Vector-by-scalar.
  new FunType([FLOAT2, FLOAT], FLOAT2),
  new FunType([FLOAT3, FLOAT], FLOAT3),
  new FunType([FLOAT4, FLOAT], FLOAT4),
  new FunType([FLOAT, FLOAT2], FLOAT2),
  new FunType([FLOAT, FLOAT3], FLOAT3),
  new FunType([FLOAT, FLOAT4], FLOAT4),

  // Matrix-by-scalar.
  new FunType([FLOAT4X4, FLOAT], FLOAT4X4),
  new FunType([FLOAT, FLOAT4X4], FLOAT4X4),
  new FunType([FLOAT3X3, FLOAT], FLOAT3X3),
  new FunType([FLOAT, FLOAT3X3], FLOAT3X3),

  // Multiplication gets special type cases for matrix-vector multiply.
  new FunType([FLOAT3X3, FLOAT3], FLOAT3),
  new FunType([FLOAT4X4, FLOAT4], FLOAT4),
]);
export const INTRINSICS: TypeMap = {
  render: new FunType([new CodeType(ANY, FUNC_ANNOTATION)], VOID),
  vertex: new FunType([new CodeType(ANY, SHADER_ANNOTATION)], VOID),
  fragment: new FunType([new CodeType(ANY, SHADER_ANNOTATION)], VOID),
  gl_Position: FLOAT4,
  gl_FragColor: FLOAT4,<commit_msg>[add] add gl_FragCoord in gl.ts<commit_after>import { Type, TypeMap } from '../type';
import {
  PrimitiveType,
  FunType,
  VariadicFunType,
  OverloadedType,
  ConstructorType,
  InstanceType,
  CodeType,
  INT,
  FLOAT,
  ANY,
  VOID,
  STRING,
  BOOLEAN
} from '../type';
import * as ast from '../ast';
import { CompilerIR, Prog, nearest_quote } from '../compile/ir';
import { varsym } from './emitutil';
import { Emitter, specialized_prog } from './emitter';
import { FUNC_ANNOTATION } from './js';

// General OpenGL-related backend components.

// Special GLSL matrix and vector types.
// Someday, a more structured notion of generic vector and matrix types would
// be better. For now, we just support a handful of common types.
export const FLOAT2 = new PrimitiveType("Float2");
export const FLOAT3 = new PrimitiveType("Float3");
export const FLOAT4 = new PrimitiveType("Float4");
export const FLOAT3X3 = new PrimitiveType("Float3x3");
export const FLOAT4X4 = new PrimitiveType("Float4x4");
export const ARRAY = new ConstructorType("Array");
export const INT3 = new PrimitiveType("Int3");
export const INT4 = new PrimitiveType("Int4");

// A type for textures (on the CPU) and sampler IDs (on the GPU).
export const TEXTURE = new PrimitiveType("Texture");
export const CUBE_TEXTURE = new PrimitiveType("CubeTexture");
export const FRAMEBUFFER = new PrimitiveType("Framebuffer");

export const GL_TYPES: TypeMap = {
  "Float2": FLOAT2,
  "Float3": FLOAT3,
  "Float4": FLOAT4,
  "Vec2": FLOAT2,
  "Vec3": FLOAT3,  // Convenient OpenGL-esque names.
  "Vec4": FLOAT4,
  "Float3x3": FLOAT3X3,
  "Float4x4": FLOAT4X4,
  "Mat3": FLOAT3X3,
  "Mat4": FLOAT4X4,
  "Int3": INT3,
  "Int4": INT4,
  "Array": ARRAY,

  // TODO This Mesh type is used by the dingus. It is an opaque type. It would
  // be nice if the dingus could declare the Mesh type itself rather than
  // needing to bake it in here.
  "Mesh": new PrimitiveType("Mesh"),

  "Texture": TEXTURE,
  "CubeTexture": CUBE_TEXTURE,
  "Framebuffer": FRAMEBUFFER,
  "Image": new PrimitiveType("Image"),
};

export const NUMERIC_TYPES: Type[] = [
  FLOAT3, FLOAT4,
  FLOAT3X3, FLOAT4X4,
  INT3, INT4,
];

export const TYPE_NAMES: { [_: string]: string } = {
  "Int": "int",
  "Int3": "ivec3",
  "Int4": "ivec4",
  "Float": "float",
  "Float2": "vec2",
  "Float3": "vec3",
  "Float4": "vec4",
  "Float3x3": "mat3",
  "Float4x4": "mat4",
  "Texture": "sampler2D",
  "CubeTexture": "samplerCube",
};

export const FRAG_INTRINSIC = "fragment";
export const VTX_INTRINSIC = "vertex";
export const SHADER_ANNOTATION = "glsl";

const _GL_UNARY_TYPE = new OverloadedType([
  new FunType([INT], INT),
  new FunType([FLOAT], FLOAT),
  new FunType([FLOAT2], FLOAT2),
  new FunType([FLOAT3], FLOAT3),
  new FunType([FLOAT4], FLOAT4),
]);
const _GL_BINARY_TYPE = new OverloadedType([
  new FunType([INT, INT], INT),
  new FunType([FLOAT, FLOAT], FLOAT),
  new FunType([FLOAT2, FLOAT2], FLOAT2),
  new FunType([FLOAT3, FLOAT3], FLOAT3),
  new FunType([FLOAT4, FLOAT4], FLOAT4),
  new FunType([FLOAT3X3, FLOAT3X3], FLOAT3X3),
  new FunType([FLOAT4X4, FLOAT4X4], FLOAT4X4),

  // Vector-by-scalar.
  new FunType([FLOAT2, FLOAT], FLOAT2),
  new FunType([FLOAT3, FLOAT], FLOAT3),
  new FunType([FLOAT4, FLOAT], FLOAT4),
]);
const _GL_ARITH_UNARY_TYPE = new OverloadedType([
  new FunType([INT], INT),
  new FunType([FLOAT], FLOAT),
  new FunType([FLOAT2], FLOAT2),
  new FunType([FLOAT3], FLOAT3),
  new FunType([FLOAT4], FLOAT4),
  new FunType([FLOAT3X3], FLOAT3X3),
  new FunType([FLOAT4X4], FLOAT4X4),
]);
const _GL_ARITH_BINARY_TYPE = new OverloadedType([
  new FunType([INT, INT], INT),
  new FunType([FLOAT, FLOAT], FLOAT),
  new FunType([FLOAT2, FLOAT2], FLOAT2),
  new FunType([FLOAT3, FLOAT3], FLOAT3),
  new FunType([FLOAT4, FLOAT4], FLOAT4),
  new FunType([FLOAT3X3, FLOAT3X3], FLOAT3X3),
  new FunType([FLOAT4X4, FLOAT4X4], FLOAT4X4),

  // Vector- or matrix-by-scalar.
  new FunType([FLOAT2, FLOAT], FLOAT2),
  new FunType([FLOAT, FLOAT2], FLOAT2),
  new FunType([FLOAT3, FLOAT], FLOAT3),
  new FunType([FLOAT, FLOAT3], FLOAT3),
  new FunType([FLOAT4, FLOAT], FLOAT4),
  new FunType([FLOAT, FLOAT4], FLOAT4),
  new FunType([FLOAT3X3, FLOAT], FLOAT3X3),
  new FunType([FLOAT, FLOAT3X3], FLOAT3X3),
  new FunType([FLOAT4X4, FLOAT], FLOAT4X4),
  new FunType([FLOAT, FLOAT4X4], FLOAT4X4),
]);
const _GL_COMPARE_TYPE = new OverloadedType([
  new FunType([INT, INT], BOOLEAN),
  new FunType([FLOAT, FLOAT], BOOLEAN),
]);
const _GL_ARITH_UNARY_BINARY_TYPE = new OverloadedType(
  _GL_ARITH_UNARY_TYPE.types.concat(_GL_ARITH_BINARY_TYPE.types)
);
const _GL_MUL_TYPE = new OverloadedType([
  new FunType([INT, INT], INT),
  new FunType([FLOAT, FLOAT], FLOAT),
  new FunType([FLOAT2, FLOAT2], FLOAT2),
  new FunType([FLOAT3, FLOAT3], FLOAT3),
  new FunType([FLOAT4, FLOAT4], FLOAT4),
  new FunType([FLOAT3X3, FLOAT3X3], FLOAT3X3),
  new FunType([FLOAT4X4, FLOAT4X4], FLOAT4X4),

  // Vector-by-scalar.
  new FunType([FLOAT2, FLOAT], FLOAT2),
  new FunType([FLOAT3, FLOAT], FLOAT3),
  new FunType([FLOAT4, FLOAT], FLOAT4),
  new FunType([FLOAT, FLOAT2], FLOAT2),
  new FunType([FLOAT, FLOAT3], FLOAT3),
  new FunType([FLOAT, FLOAT4], FLOAT4),

  // Matrix-by-scalar.
  new FunType([FLOAT4X4, FLOAT], FLOAT4X4),
  new FunType([FLOAT, FLOAT4X4], FLOAT4X4),
  new FunType([FLOAT3X3, FLOAT], FLOAT3X3),
  new FunType([FLOAT, FLOAT3X3], FLOAT3X3),

  // Multiplication gets special type cases for matrix-vector multiply.
  new FunType([FLOAT3X3, FLOAT3], FLOAT3),
  new FunType([FLOAT4X4, FLOAT4], FLOAT4),
]);
export const INTRINSICS: TypeMap = {
  render: new FunType([new CodeType(ANY, FUNC_ANNOTATION)], VOID),
  vertex: new FunType([new CodeType(ANY, SHADER_ANNOTATION)], VOID),
  fragment: new FunType([new CodeType(ANY, SHADER_ANNOTATION)], VOID),
  gl_Position: FLOAT4,
  gl_FragCoord: FLOAT4,
  gl_FragColor: FLOAT4,
{'fraction_non_alphanumeric': 0.15033407572383073, 'fraction_numerical': 0.03914682199760151, 'mean_word_length': 4.981045081967213, 'pattern_counts': {'":': 58, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '1311571', 'n_tokens_mistral': 4766, 'n_tokens_neox': 4694, 'n_words': 1151}