<commit_before>package openfl.utils;


import lime.graphics.opengl.GL;
import openfl._internal.aglsl.assembler.FS;
import openfl._internal.aglsl.assembler.Part;
import openfl._internal.aglsl.assembler.Opcode;
import openfl._internal.aglsl.assembler.OpcodeMap;
import openfl._internal.aglsl.assembler.RegMap;
import openfl._internal.aglsl.assembler.Sampler;
import openfl._internal.aglsl.assembler.SamplerMap;
import openfl._internal.aglsl.AGALTokenizer;
import openfl._internal.aglsl.AGLSLCompiler;
import openfl._internal.aglsl.AGLSLParser;
import openfl._internal.aglsl.Description;
import openfl.display3D.Context3DProgramType;
import openfl.errors.Error;


class AGALMiniAssembler {
	
	
	public var agalcode:ByteArray;
	public var error:String;
	
	private var __cur:Part;
	private var __debugEnabled:Bool;
	private var __r:Map<String, Part>;
	
	
	public function new (debugging:Bool = false) {
		
		__r = new Map ();
		__cur = new Part ();
		
	}
	
	
	public function assemble (programType:Context3DProgramType, source:String):Dynamic {
		
		#if flash
		
		var agalMiniAssembler:AGALMiniAssembler = new AGALMiniAssembler ();
		var data:ByteArray = null;
		var concatSource:String;
		
		switch (programType) {
			
			case VERTEX:
				
				concatSource = "part vertex 1 \n" + source + "endpart";
				agalMiniAssembler.__assemble (concatSource);
				data = agalMiniAssembler.__r.get ("vertex").data;
			
			case FRAGMENT:
				
				concatSource = "part fragment 1 \n" + source + "endpart";
				agalMiniAssembler.__assemble (concatSource);
				data = agalMiniAssembler.__r.get ("fragment").data;
			
			default:
				
				throw "Unknown Context3DProgramType";
			
		}
		
		return agalcode = data;
		
		#elseif (cpp || neko || js)
		
		var aglsl:AGLSLCompiler = new AGLSLCompiler ();
		var glType:Int;
		var shaderType:String;
		
		switch (programType) {
			
			case VERTEX:
				
				glType = GL.VERTEX_SHADER;
				shaderType = "vertex";
			
			case FRAGMENT:
				
				glType = GL.FRAGMENT_SHADER;
				shaderType = "fragment";
			
		}
		
		//trace ("--- AGAL ---\n" + shaderSource);
		
		var shaderSourceString = aglsl.compile (shaderType, source);
		var shader = GL.createShader (glType);
		
		GL.shaderSource (shader, shaderSourceString);
		GL.compileShader (shader);
		
		if (GL.getShaderParameter (shader, GL.COMPILE_STATUS) == 0) {
			
			trace("--- ERR ---\n" + shaderSourceString);<commit_msg>Docs fix<commit_after>package openfl.utils;


import lime.graphics.opengl.GL;
import openfl._internal.aglsl.assembler.FS;
import openfl._internal.aglsl.assembler.Part;
import openfl._internal.aglsl.assembler.Opcode;
import openfl._internal.aglsl.assembler.OpcodeMap;
import openfl._internal.aglsl.assembler.RegMap;
import openfl._internal.aglsl.assembler.Sampler;
import openfl._internal.aglsl.assembler.SamplerMap;
import openfl._internal.aglsl.AGALTokenizer;
import openfl._internal.aglsl.AGLSLCompiler;
import openfl._internal.aglsl.AGLSLParser;
import openfl._internal.aglsl.Description;
import openfl.display3D.Context3DProgramType;
import openfl.errors.Error;


class AGALMiniAssembler {
	
	
	public var agalcode:ByteArray;
	public var error:String;
	
	private var __cur:Part;
	private var __debugEnabled:Bool;
	private var __r:Map<String, Part>;
	
	
	public function new (debugging:Bool = false) {
		
		__r = new Map ();
		__cur = new Part ();
		
	}
	
	
	public function assemble (programType:Context3DProgramType, source:String):Dynamic {
		
		#if flash
		
		var agalMiniAssembler:AGALMiniAssembler = new AGALMiniAssembler ();
		var data:ByteArray = null;
		var concatSource:String;
		
		switch (programType) {
			
			case VERTEX:
				
				concatSource = "part vertex 1 \n" + source + "endpart";
				agalMiniAssembler.__assemble (concatSource);
				data = agalMiniAssembler.__r.get ("vertex").data;
			
			case FRAGMENT:
				
				concatSource = "part fragment 1 \n" + source + "endpart";
				agalMiniAssembler.__assemble (concatSource);
				data = agalMiniAssembler.__r.get ("fragment").data;
			
			default:
				
				throw "Unknown Context3DProgramType";
			
		}
		
		return agalcode = data;
		
		#elseif (cpp || neko || js)
		
		var aglsl:AGLSLCompiler = new AGLSLCompiler ();
		var glType:Int;
		var shaderType:String;
		
		switch (programType) {
			
			case VERTEX:
				
				glType = GL.VERTEX_SHADER;
				shaderType = "vertex";
			
			default:
				
				glType = GL.FRAGMENT_SHADER;
				shaderType = "fragment";
			
		}
		
		//trace ("--- AGAL ---\n" + shaderSource);
		
		var shaderSourceString = aglsl.compile (shaderType, source);
		var shader = GL.createShader (glType);
		
		GL.shaderSource (shader, shaderSourceString);
		GL.compileShader (shader);
		
		if (GL.getShaderParameter (shader, GL.COMPILE_STATUS) == 0) {
			
			trace("--- ERR ---\n" + shaderSourceString);
{'fraction_non_alphanumeric': 0.109600501987032, 'fraction_numerical': 0.0029282576866764276, 'mean_word_length': 3.6653658536585367, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 5, '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': '5543532', 'n_tokens_mistral': 1932, 'n_tokens_neox': 1627, 'n_words': 329}