├── src ├── hlsl_parser │ ├── generate_parser.bat │ ├── generate_parser.sh │ ├── HLSLConverter.h │ ├── HLSLParserListener.h │ ├── HLSLConverter.cpp │ └── HLSLParserListener.cpp ├── host │ └── lua-5.3.0 │ │ ├── doc │ │ ├── logo.gif │ │ ├── osi-certified-72x60.png │ │ ├── manual.css │ │ ├── lua.css │ │ ├── lua.1 │ │ └── luac.1 │ │ ├── README │ │ └── src │ │ ├── lua.hpp │ │ ├── lapi.h │ │ ├── lundump.h │ │ ├── lprefix.h │ │ ├── lualib.h │ │ ├── lstring.h │ │ ├── ldebug.h │ │ ├── ldo.h │ │ ├── lfunc.h │ │ ├── lzio.h │ │ ├── ltable.h │ │ ├── lzio.c │ │ ├── linit.c │ │ ├── ltm.h │ │ ├── lvm.h │ │ ├── lctype.h │ │ ├── lctype.c │ │ ├── llex.h │ │ ├── lmem.h │ │ ├── lmem.c │ │ ├── lcode.h │ │ ├── lparser.h │ │ ├── lopcodes.c │ │ ├── lfunc.c │ │ ├── ltm.c │ │ ├── lcorolib.c │ │ └── lgc.h ├── generator │ ├── ast_generator.lua │ ├── hlsl_generator.lua │ └── generator_utils.lua ├── process │ ├── optimizer.lua │ ├── ast_processor.lua │ ├── file_checker.lua │ ├── ast_rewrite_comparison.lua │ ├── ast_rewrite_if.lua │ ├── ast_rewriter.lua │ ├── ast_rewrite_constants.lua │ └── function_replacer.lua ├── utilities │ ├── copy.lua │ ├── tree.lua │ ├── string.lua │ ├── output.lua │ ├── debug.lua │ └── argument_parser.lua ├── test │ └── tokenizer.lua ├── _manifest.lua ├── printer │ └── printer_manager.lua └── _shader_shaker_main.lua ├── contrib ├── antlr.jar ├── antlr3.inl ├── antlr3filestream.inl ├── antlr3errors.hpp ├── antlr3.hpp ├── antlr3filestream.hpp ├── antlr3cyclicdfa.hpp ├── antlr3treeparser.hpp └── antlr3memory.hpp ├── test ├── parser │ ├── index.fx │ ├── struct.fx │ ├── for_statement.fx │ ├── minus_statement.fx │ ├── arithmetic.fx │ ├── while_statement.fx │ ├── if_statement.fx │ ├── struct.reference.ast │ ├── float4_constructor_assignment.fx │ ├── textures.fx │ ├── minus_statement.reference.ast │ ├── index.reference.ast │ ├── for_statement.reference.ast │ ├── function.fx │ ├── ps_return.fx │ ├── textures.reference.ast │ ├── while_statement.reference.ast │ ├── float4_constructor_assignment.reference.ast │ ├── arithmetic.reference.ast │ ├── variables.fx │ ├── variables.reference.ast │ └── if_statement.reference.ast ├── optim │ ├── constant_folding │ │ ├── addition.fx │ │ ├── multiplication.fx │ │ ├── comparison.fx │ │ ├── boolean_operator.fx │ │ ├── if_condition.fx │ │ ├── addition.reference.ast │ │ ├── comparison.reference.ast │ │ ├── multiplication.reference.ast │ │ └── if_condition.reference.ast │ ├── replace_functions1.fx │ ├── constants_replacement.fx │ ├── clean_constants.fx │ ├── replace_functions0.fx │ ├── constants_replacement.reference.ast │ ├── replace_functions1.reference.ast │ └── clean_constants.reference.ast └── build.xml ├── .travis.yml ├── .gitignore ├── include └── ShaderShaker.h ├── samples └── test.lua ├── README.md └── scripts └── embed.lua /src/hlsl_parser/generate_parser.bat: -------------------------------------------------------------------------------- 1 | java -cp ../../contrib/antlr.jar org.antlr.Tool HLSL.g -------------------------------------------------------------------------------- /contrib/antlr.jar: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/FishingCactus/ShaderShaker/HEAD/contrib/antlr.jar -------------------------------------------------------------------------------- /src/host/lua-5.3.0/doc/logo.gif: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/FishingCactus/ShaderShaker/HEAD/src/host/lua-5.3.0/doc/logo.gif -------------------------------------------------------------------------------- /test/parser/index.fx: -------------------------------------------------------------------------------- 1 | bool test() 2 | { 3 | float4x4 foo; 4 | 5 | float3 bar = foo[3].xyz; 6 | 7 | return false; 8 | } -------------------------------------------------------------------------------- /src/hlsl_parser/generate_parser.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | java -Xmx512M -cp ../../contrib/antlr.jar org.antlr.Tool -report -Xwatchconversion HLSL.g 4 | -------------------------------------------------------------------------------- /src/host/lua-5.3.0/doc/osi-certified-72x60.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/FishingCactus/ShaderShaker/HEAD/src/host/lua-5.3.0/doc/osi-certified-72x60.png -------------------------------------------------------------------------------- /src/host/lua-5.3.0/README: -------------------------------------------------------------------------------- 1 | 2 | This is Lua 5.3.0, released on 06 Jan 2015. 3 | 4 | For installation instructions, license details, and 5 | further information about Lua, see doc/readme.html. 6 | 7 | -------------------------------------------------------------------------------- /test/parser/struct.fx: -------------------------------------------------------------------------------- 1 | struct VS_OUTPUT 2 | { 3 | float4 Position : SV_POSITION; 4 | float4 Diffuse : COLOR0; 5 | float2 TextureUV : TEXCOORD0; 6 | }; 7 | 8 | VS_OUTPUT 9 | some_struct; -------------------------------------------------------------------------------- /test/parser/for_statement.fx: -------------------------------------------------------------------------------- 1 | void test() 2 | { 3 | for( int index = 0; index < 10; ++index ) 4 | { 5 | if( index > 5 ) 6 | { 7 | break; 8 | } 9 | } 10 | } -------------------------------------------------------------------------------- /src/generator/ast_generator.lua: -------------------------------------------------------------------------------- 1 | AstGenerator = 2 | { 3 | ProcessAst = function( ast ) 4 | ShaderPrint( table.tostring_ast( ast ) ) 5 | end 6 | } 7 | 8 | RegisterPrinter( AstGenerator, "ast", "ast" ) -------------------------------------------------------------------------------- /contrib/antlr3.inl: -------------------------------------------------------------------------------- 1 | ANTLR_BEGIN_NAMESPACE() 2 | 3 | //static 4 | ANTLR_INLINE void GenericStream::displayRecognitionError( const StringType& str ) 5 | { 6 | fprintf(stderr, str.c_str() ); 7 | } 8 | 9 | ANTLR_END_NAMESPACE() -------------------------------------------------------------------------------- /test/parser/minus_statement.fx: -------------------------------------------------------------------------------- 1 | float3 2 | LightDirection0; 3 | 4 | float4 RenderSceneVS() 5 | { 6 | float3 7 | light_direction; 8 | 9 | light_direction = normalize( -LightDirection0 ); 10 | } -------------------------------------------------------------------------------- /src/host/lua-5.3.0/src/lua.hpp: -------------------------------------------------------------------------------- 1 | // lua.hpp 2 | // Lua header files for C++ 3 | // <> not supplied automatically because Lua also compiles as C++ 4 | 5 | extern "C" { 6 | #include "lua.h" 7 | #include "lualib.h" 8 | #include "lauxlib.h" 9 | } 10 | -------------------------------------------------------------------------------- /test/parser/arithmetic.fx: -------------------------------------------------------------------------------- 1 | float test_function( 2 | float a, 3 | int b, 4 | float c 5 | ) 6 | { 7 | const float d = 1.0; 8 | const float e = 2.0; 9 | const float f = 3.0; 10 | return ( a * b + c - ( d + e ) / f * 0.5 ) / ( 2.0 * e ); 11 | } -------------------------------------------------------------------------------- /test/optim/constant_folding/addition.fx: -------------------------------------------------------------------------------- 1 | float add_0_r( float a, float b ) 2 | { 3 | return a + b + 0.0f; 4 | } 5 | 6 | float add_0_l( float a, float b ) 7 | { 8 | return 0.0f + a + b; 9 | } 10 | 11 | float add_0_m( float a, float b ) 12 | { 13 | return a + 0.0f + b; 14 | } -------------------------------------------------------------------------------- /test/parser/while_statement.fx: -------------------------------------------------------------------------------- 1 | int test( float a, bool b, int c ) 2 | { 3 | int 4 | index; 5 | bool 6 | result; 7 | 8 | do 9 | { 10 | a -= 1.0; 11 | 12 | result = a < 0.0; 13 | } 14 | while( result ); 15 | 16 | while( index < c ) 17 | { 18 | ++index; 19 | } 20 | 21 | return 0; 22 | } -------------------------------------------------------------------------------- /src/process/optimizer.lua: -------------------------------------------------------------------------------- 1 | Optimizer = { 2 | } 3 | 4 | function Optimizer.Process( ast_node, options ) 5 | local constants_optimizer = ConstantsOptimizer:new( ast_node, options.constants_replacement ) 6 | local shader_parameter_inliner = ShaderParameterInliner:new( ast_node, constants_optimizer ) 7 | 8 | shader_parameter_inliner:Process() 9 | constants_optimizer:Process() 10 | end -------------------------------------------------------------------------------- /.travis.yml: -------------------------------------------------------------------------------- 1 | language: cpp 2 | before_install: 3 | - sudo bash -c "echo 'deb http://lgp203.free.fr/ubuntu quantal universe' >> /etc/apt/sources.list.d/lgp203.free.fr.source.list" 4 | - sudo apt-get update 5 | install: sudo apt-get install --force-yes make premake4 6 | compiler: 7 | - gcc 8 | - clang 9 | # Change this to your needs 10 | before_script: pushd src/hlsl_parser/ && ./generate_parser.sh && popd 11 | script: premake4 embed && premake4 gmake && make 12 | -------------------------------------------------------------------------------- /test/parser/if_statement.fx: -------------------------------------------------------------------------------- 1 | bool test( 2 | float a, 3 | float x 4 | ) 5 | { 6 | if( a == x ) 7 | return false; 8 | 9 | if( a < x || a > x ) 10 | { 11 | return true; 12 | } 13 | 14 | if( a + x > 10.0f ) 15 | { 16 | return x + a <= 23.35f; 17 | } 18 | else if( !(a - x < 5.0f) ) 19 | { 20 | a = 1.0; 21 | return a >= x; 22 | } 23 | else 24 | { 25 | a = x; 26 | } 27 | 28 | return false; 29 | } -------------------------------------------------------------------------------- /src/host/lua-5.3.0/doc/manual.css: -------------------------------------------------------------------------------- 1 | h3 code { 2 | font-family: inherit ; 3 | font-size: inherit ; 4 | } 5 | 6 | pre, code { 7 | font-size: 12pt ; 8 | } 9 | 10 | span.apii { 11 | float: right ; 12 | font-family: inherit ; 13 | font-style: normal ; 14 | font-size: small ; 15 | color: gray ; 16 | } 17 | 18 | p+h1, ul+h1 { 19 | font-style: normal ; 20 | padding-top: 0.4em ; 21 | padding-bottom: 0.4em ; 22 | padding-left: 16px ; 23 | margin-left: -16px ; 24 | background-color: #D0D0FF ; 25 | border-radius: 8px ; 26 | border: solid #000080 1px ; 27 | } 28 | -------------------------------------------------------------------------------- /test/parser/struct.reference.ast: -------------------------------------------------------------------------------- 1 | 2 | { 3 | struct_definition 4 | { 5 | "VS_OUTPUT", 6 | field 7 | { 8 | type{"float4"}, 9 | ID{"Position"}, 10 | semantic{"SV_POSITION"} 11 | }, 12 | field 13 | { 14 | type{"float4"}, 15 | ID{"Diffuse"}, 16 | semantic{"COLOR0"} 17 | }, 18 | field 19 | { 20 | type{"float2"}, 21 | ID{"TextureUV"}, 22 | semantic{"TEXCOORD0"} 23 | } 24 | } 25 | } -------------------------------------------------------------------------------- /test/optim/constant_folding/multiplication.fx: -------------------------------------------------------------------------------- 1 | float multiplied_by_0_r( float a, float b ) 2 | { 3 | return a * b * 0.0f; 4 | } 5 | 6 | float multiplied_by_0_l( float a, float b ) 7 | { 8 | return 0.0f * a * b; 9 | } 10 | 11 | float multiplied_by_0_m( float a, float b ) 12 | { 13 | return a * 0.0f * b; 14 | } 15 | 16 | float multiplied_by_1_r( float a, float b ) 17 | { 18 | return a * b * 1.0f; 19 | } 20 | 21 | float multiplied_by_1_l( float a, float b ) 22 | { 23 | return 1.0f * a * b; 24 | } 25 | 26 | float multiplied_by_1_m( float a, float b ) 27 | { 28 | return a * 1.0f * b; 29 | } -------------------------------------------------------------------------------- /test/optim/replace_functions1.fx: -------------------------------------------------------------------------------- 1 | float3 GetPosition( 2 | float x, 3 | float y, 4 | float z, 5 | float w 6 | ) 7 | { 8 | return float3( x, y, z ); 9 | } 10 | 11 | float4 GetPosition( 12 | float x, 13 | float y, 14 | float z 15 | ) 16 | { 17 | return float4( x, y, z, 0.0f ); 18 | } 19 | 20 | float3 GetStrangePosition( 21 | float x, 22 | float y, 23 | float z 24 | ) 25 | { 26 | return float3( x, y, z ) * 10.0f; 27 | } 28 | 29 | float3 GetPosition( 30 | float x, 31 | float y, 32 | float z 33 | ) 34 | { 35 | return float3( x, y, z ) * 2.0f; 36 | } -------------------------------------------------------------------------------- /test/parser/float4_constructor_assignment.fx: -------------------------------------------------------------------------------- 1 | // ~~ 2 | 3 | struct VS_TEXTURED_INPUT 4 | { 5 | float2 Position : POSITION; 6 | float2 TextureCoordinate : TEXCOORD0; 7 | }; 8 | 9 | struct VS_TEXTURED_OUTPUT 10 | { 11 | float4 Position : POSITION; 12 | float2 TextureCoordinate : TEXCOORD0; 13 | }; 14 | 15 | // ~~ 16 | 17 | VS_TEXTURED_OUTPUT vs( 18 | VS_TEXTURED_INPUT input 19 | ) 20 | { 21 | VS_TEXTURED_OUTPUT 22 | output; 23 | 24 | output.Position = float4( input.Position, 0, 1 ); 25 | output.TextureCoordinate = input.TextureCoordinate; 26 | 27 | return output; 28 | } -------------------------------------------------------------------------------- /test/parser/textures.fx: -------------------------------------------------------------------------------- 1 | Texture SourceTexture1; 2 | Texture1D SourceTexture2; 3 | Texture1DArray SourceTexture3; 4 | Texture2D SourceTexture4; 5 | Texture2DArray SourceTexture5; 6 | Texture3D SourceTexture6; 7 | TextureCube SourceTexture7; 8 | 9 | texture SourceTexture1; 10 | texture1D SourceTexture2; 11 | texture1DArray SourceTexture3; 12 | texture2D SourceTexture4; 13 | texture2DArray SourceTexture5; 14 | texture3D SourceTexture6; 15 | textureCube SourceTexture7; 16 | 17 | sampler2D SourceTextureSampler 18 | { 19 | Texture = ; 20 | MinFilter = LINEAR; 21 | MagFilter = LINEAR; 22 | MipFilter = LINEAR; 23 | }; -------------------------------------------------------------------------------- /src/hlsl_parser/HLSLConverter.h: -------------------------------------------------------------------------------- 1 | #ifndef HLSLCONVERTER 2 | #define HLSLCONVERTER 3 | 4 | #include 5 | 6 | #include 7 | #include "HLSLParserListener.h" 8 | 9 | class HLSLConverter 10 | { 11 | public: 12 | 13 | HLSLConverter( lua_State * state ) : Listener( state ) 14 | { 15 | 16 | } 17 | 18 | void LoadAst( 19 | const std::string & filename 20 | ); 21 | 22 | static int ParseAst( 23 | lua_State * lua_state 24 | ); 25 | 26 | private: 27 | 28 | HLSLParserListener 29 | Listener; 30 | 31 | }; 32 | 33 | #endif -------------------------------------------------------------------------------- /src/host/lua-5.3.0/src/lapi.h: -------------------------------------------------------------------------------- 1 | /* 2 | ** $Id: lapi.h,v 2.8 2014/07/15 21:26:50 roberto Exp $ 3 | ** Auxiliary functions from Lua API 4 | ** See Copyright Notice in lua.h 5 | */ 6 | 7 | #ifndef lapi_h 8 | #define lapi_h 9 | 10 | 11 | #include "llimits.h" 12 | #include "lstate.h" 13 | 14 | #define api_incr_top(L) {L->top++; api_check(L->top <= L->ci->top, \ 15 | "stack overflow");} 16 | 17 | #define adjustresults(L,nres) \ 18 | { if ((nres) == LUA_MULTRET && L->ci->top < L->top) L->ci->top = L->top; } 19 | 20 | #define api_checknelems(L,n) api_check((n) < (L->top - L->ci->func), \ 21 | "not enough elements in the stack") 22 | 23 | 24 | #endif 25 | -------------------------------------------------------------------------------- /src/process/ast_processor.lua: -------------------------------------------------------------------------------- 1 | AstProcessor = {} 2 | 3 | function AstProcessor.Process( options ) 4 | 5 | local ast_node = GenerateAstFromFileName( options.input_file ) 6 | 7 | if #options.replacement_files > 0 then 8 | local function_replacer 9 | 10 | if options.inline_replacement_functions then 11 | function_replacer = FunctionInliner:new() 12 | else 13 | function_replacer = FunctionReplacer:new() 14 | end 15 | 16 | function_replacer:Process( ast_node, options.replacement_files ) 17 | end 18 | 19 | if options.optimize then 20 | Optimizer.Process( ast_node, options ) 21 | end 22 | 23 | return ast_node 24 | end -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | # Compiled Object files 2 | *.slo 3 | *.lo 4 | *.o 5 | obj/* 6 | 7 | # Compiled Dynamic libraries 8 | *.so 9 | 10 | # Compiled Static libraries 11 | *.lai 12 | *.la 13 | *.a 14 | 15 | #Compiled Binaries 16 | bin/* 17 | 18 | #Generated project 19 | *.xcodeproj 20 | *.xcworkspace 21 | src/host/scripts.cpp 22 | src/hlsl_parser/HLSLParser.* 23 | src/hlsl_parser/HLSLLexer.* 24 | *.sln 25 | *.vcxproj 26 | *.filters 27 | *.tokens 28 | *.ipch 29 | output.ast 30 | output.fx 31 | premake4.exe 32 | *.opensdf 33 | *.sdf 34 | *.suo 35 | *.vcxproj.user 36 | output.glfx 37 | ShaderShaker.deproj 38 | ShaderShaker.deuser 39 | _ReSharper.* 40 | output2.ast 41 | *.deproj 42 | *.deuser 43 | Makefile 44 | *.make 45 | 46 | -------------------------------------------------------------------------------- /src/utilities/copy.lua: -------------------------------------------------------------------------------- 1 | -- http://lua-users.org/wiki/CopyTable 2 | 3 | function DeepCopy( object ) 4 | local lookup_table = {} 5 | 6 | local function _copy( object ) 7 | if type( object ) ~= "table" then 8 | return object 9 | elseif lookup_table[ object ] then 10 | return lookup_table[ object ] 11 | end 12 | 13 | local new_table = {} 14 | lookup_table[ object ] = new_table 15 | for index, value in pairs( object ) do 16 | new_table[ _copy( index ) ] = _copy( value ) 17 | end 18 | 19 | return setmetatable( new_table, _copy( getmetatable(object) ) ) 20 | end 21 | 22 | return _copy( object ) 23 | end -------------------------------------------------------------------------------- /src/process/file_checker.lua: -------------------------------------------------------------------------------- 1 | FileChecker = {} 2 | 3 | function FileChecker.Process( input_file, ast ) 4 | SelectPrinter( input_file ); 5 | InitializeOutputPrint() 6 | 7 | GetSelectedPrinter().ProcessAst( ast ) 8 | 9 | local generated_file = tokenizer( _G.CodeOutput[ 1 ].text ); 10 | 11 | local file = assert( io.open( input_file, "r" ) ) 12 | local ground_truth = tokenizer( file:read("*all") ) 13 | file:close() 14 | 15 | repeat 16 | token_a, value_a = generated_file() 17 | token_b, value_b = ground_truth() 18 | 19 | if token_a ~= token_b or value_a ~= value_b then 20 | error( "expected " .. value_b .. ", got " .. value_a ) 21 | return 1 22 | end 23 | 24 | until token_a == nil and token_b == nil 25 | end -------------------------------------------------------------------------------- /test/optim/constant_folding/comparison.fx: -------------------------------------------------------------------------------- 1 | bool smaller_true() 2 | { 3 | return 1 < 2; 4 | } 5 | 6 | bool smaller_false() 7 | { 8 | return 2 < 2; 9 | } 10 | 11 | bool smaller_false2() 12 | { 13 | return 3 < 2; 14 | } 15 | 16 | bool smaller_equal_true() 17 | { 18 | return 1 <= 2; 19 | } 20 | 21 | bool smaller_equal_true2() 22 | { 23 | return 2 <= 2; 24 | } 25 | 26 | bool smaller_equal_false() 27 | { 28 | return 3 <= 2; 29 | } 30 | 31 | bool greater_false() 32 | { 33 | return 1 > 2; 34 | } 35 | 36 | bool greater_false2() 37 | { 38 | return 2 > 2; 39 | } 40 | 41 | bool greater_true() 42 | { 43 | return 3 > 2; 44 | } 45 | 46 | bool greater_equal_false() 47 | { 48 | return 1 >= 2; 49 | } 50 | 51 | bool greater_equal_true() 52 | { 53 | return 2 >= 2; 54 | } 55 | 56 | bool greater_equal_true2() 57 | { 58 | return 3 >= 2; 59 | } 60 | -------------------------------------------------------------------------------- /test/parser/minus_statement.reference.ast: -------------------------------------------------------------------------------- 1 | 2 | { 3 | variable_declaration 4 | { 5 | storage{}, 6 | modifier{}, 7 | type{"float3"}, 8 | variable{"LightDirection0"} 9 | }, 10 | function 11 | { 12 | type{"float4"}, 13 | ID{"RenderSceneVS"}, 14 | function_body 15 | { 16 | variable_declaration 17 | { 18 | storage{}, 19 | modifier{}, 20 | type{"float3"}, 21 | variable{"light_direction"} 22 | }, 23 | =_statement 24 | { 25 | variable{"light_direction"}, 26 | call 27 | { 28 | "normalize", 29 | argument_expression_list{unary_-{variable{"LightDirection0"}}} 30 | } 31 | } 32 | } 33 | } 34 | } -------------------------------------------------------------------------------- /test/optim/constants_replacement.fx: -------------------------------------------------------------------------------- 1 | bool ItUsesVertexSkinning = false; 2 | bool ItUsesDiffuseColor = false; 3 | 4 | bool test( 5 | float a, 6 | float x 7 | ) 8 | { 9 | if( ItUsesVertexSkinning ) 10 | { 11 | int i = 0; 12 | } 13 | 14 | if( !ItUsesVertexSkinning ) 15 | { 16 | int i = 9; 17 | } 18 | 19 | if( ItUsesVertexSkinning ) 20 | { 21 | int i = 1; 22 | } 23 | else 24 | { 25 | int i = 2; 26 | } 27 | 28 | if( !ItUsesVertexSkinning ) 29 | { 30 | int i = 3; 31 | } 32 | else 33 | { 34 | int i = 4; 35 | } 36 | 37 | if( !ItUsesVertexSkinning ) 38 | { 39 | int i = 6; 40 | } 41 | else if ( !ItUsesDiffuseColor ) 42 | { 43 | int i = 7; 44 | } 45 | else 46 | { 47 | int i = 8; 48 | } 49 | 50 | return true; 51 | } -------------------------------------------------------------------------------- /include/ShaderShaker.h: -------------------------------------------------------------------------------- 1 | #ifndef SHADER_SHAKER_H 2 | #define SHADER_SHAKER_H 3 | 4 | #ifdef __cplusplus 5 | extern "C"{ 6 | #endif 7 | 8 | struct ShaderShakerContext; 9 | 10 | void ShaderShakerSetLogCallback( void ( *log_print )( const char * ) ); 11 | void ShaderShakerSetReadFileContentCallback( void ( *read_file_content )( void * content, size_t & size, const char * ) ); 12 | ShaderShakerContext * ShaderShakerCreateContext( int argc, const char* const * argv ); 13 | ShaderShakerContext * ShaderShakerCreateContextWithLanguage( const char * language ); 14 | void ShaderShakerDestroyContext( ShaderShakerContext * context ); 15 | const char * ShaderShakerGetProcessedCode( ShaderShakerContext * context, int file_index ); 16 | bool ShaderShakerLoadShaderFile( ShaderShakerContext * context ); 17 | 18 | 19 | #ifdef __cplusplus 20 | }; 21 | #endif 22 | 23 | 24 | #endif 25 | -------------------------------------------------------------------------------- /src/utilities/tree.lua: -------------------------------------------------------------------------------- 1 | function WalkTree( parent_node, node_function ) 2 | 3 | if parent_node == nil or type( parent_node ) ~= "table" then 4 | return 5 | end 6 | 7 | for child_node_index=1, #parent_node do 8 | local child_node = parent_node[ child_node_index ] 9 | WalkTree( child_node, node_function ) 10 | node_function( child_node, parent_node, child_node_index ) 11 | end 12 | end 13 | 14 | function IterateTableByKeyOrder( t, sort_function ) 15 | local a = {} 16 | 17 | for n in pairs( t ) do 18 | table.insert( a, n ) 19 | end 20 | 21 | table.sort( a, sort_function ) 22 | 23 | local i = 0 -- iterator variable 24 | local iter = function () -- iterator function 25 | i = i + 1 26 | if a[i] == nil then 27 | return nil 28 | else 29 | return a[i], t[a[i]] 30 | end 31 | end 32 | 33 | return iter 34 | end -------------------------------------------------------------------------------- /src/utilities/string.lua: -------------------------------------------------------------------------------- 1 | function isboolean( string ) 2 | return string == "true" or string == "false" 3 | end 4 | 5 | function toboolean( string ) 6 | if isboolean( string ) then 7 | return string == "true" 8 | end 9 | 10 | return nil 11 | end 12 | 13 | function string.starts( String,Start ) 14 | return string.sub( String, 1, string.len( Start ) ) ==Start 15 | end 16 | 17 | function string.ends( String, End ) 18 | return End == '' or string.sub( String,-string.len( End ) ) == End 19 | end 20 | 21 | function string.explode( str, delimiter ) 22 | if ( delimiter == '' ) then 23 | return false 24 | end 25 | 26 | local pos,arr = 0,{} 27 | 28 | for st,sp in function() return string.find( str, delimiter, pos, true) end do 29 | table.insert( arr,string.sub( str,pos,st-1 ) ) 30 | pos = sp + 1 31 | end 32 | 33 | table.insert( arr,string.sub( str,pos ) ) 34 | 35 | return arr 36 | end -------------------------------------------------------------------------------- /src/utilities/output.lua: -------------------------------------------------------------------------------- 1 | 2 | local stream 3 | 4 | function ShaderPrint( ... ) 5 | local argument = {...} 6 | 7 | if type( argument[ 1 ] ) == "number" then 8 | stream:write( string.rep( "\t", argument[1] ) ) 9 | stream:write( argument[ 2 ] ) 10 | else 11 | stream:write( argument[ 1 ] ) 12 | end 13 | end 14 | 15 | function InitializeOutputPrint() 16 | stream = { 17 | text = "", 18 | write = function( self, data ) 19 | self.text = self.text .. data 20 | if decoda_output then 21 | decoda_output( data ) 22 | end 23 | end, 24 | } 25 | 26 | _G.CodeOutput = _G.CodeOutput or {} 27 | table.insert( _G.CodeOutput, stream ) 28 | end 29 | 30 | function InitializeOutputFile( file ) 31 | 32 | stream, error_message = io.open( file, "w" ) 33 | 34 | if stream == nil then 35 | error( "Error while opening file : " .. error_message, 2 ) 36 | end 37 | end -------------------------------------------------------------------------------- /src/host/lua-5.3.0/src/lundump.h: -------------------------------------------------------------------------------- 1 | /* 2 | ** $Id: lundump.h,v 1.44 2014/06/19 18:27:20 roberto Exp $ 3 | ** load precompiled Lua chunks 4 | ** See Copyright Notice in lua.h 5 | */ 6 | 7 | #ifndef lundump_h 8 | #define lundump_h 9 | 10 | #include "llimits.h" 11 | #include "lobject.h" 12 | #include "lzio.h" 13 | 14 | 15 | /* data to catch conversion errors */ 16 | #define LUAC_DATA "\x19\x93\r\n\x1a\n" 17 | 18 | #define LUAC_INT 0x5678 19 | #define LUAC_NUM cast_num(370.5) 20 | 21 | #define MYINT(s) (s[0]-'0') 22 | #define LUAC_VERSION (MYINT(LUA_VERSION_MAJOR)*16+MYINT(LUA_VERSION_MINOR)) 23 | #define LUAC_FORMAT 0 /* this is the official format */ 24 | 25 | /* load one chunk; from lundump.c */ 26 | LUAI_FUNC LClosure* luaU_undump (lua_State* L, ZIO* Z, Mbuffer* buff, 27 | const char* name); 28 | 29 | /* dump one chunk; from ldump.c */ 30 | LUAI_FUNC int luaU_dump (lua_State* L, const Proto* f, lua_Writer w, 31 | void* data, int strip); 32 | 33 | #endif 34 | -------------------------------------------------------------------------------- /test/optim/constant_folding/boolean_operator.fx: -------------------------------------------------------------------------------- 1 | bool and_false_r( bool a, bool b ) 2 | { 3 | return a && b && false; 4 | } 5 | 6 | bool and_false_r( bool a, bool b ) 7 | { 8 | return false && a && b; 9 | } 10 | 11 | bool and_false_m( bool a, bool b ) 12 | { 13 | return a && false && b; 14 | } 15 | 16 | bool and_true_r( bool a, bool b ) 17 | { 18 | return a && b && true; 19 | } 20 | 21 | bool and_true_r( bool a, bool b ) 22 | { 23 | return true && a && b; 24 | } 25 | 26 | bool and_true_m( bool a, bool b ) 27 | { 28 | return a && true && b; 29 | } 30 | 31 | bool or_false_r( bool a, bool b ) 32 | { 33 | return a || b || false; 34 | } 35 | 36 | bool or_false_r( bool a, bool b ) 37 | { 38 | return false || a || b; 39 | } 40 | 41 | bool or_false_m( bool a, bool b ) 42 | { 43 | return a || false || b; 44 | } 45 | 46 | bool or_true_r( bool a, bool b ) 47 | { 48 | return a || b || true; 49 | } 50 | 51 | bool or_true_r( bool a, bool b ) 52 | { 53 | return true || a || b; 54 | } 55 | 56 | bool or_true_m( bool a, bool b ) 57 | { 58 | return a || true || b; 59 | } -------------------------------------------------------------------------------- /test/parser/index.reference.ast: -------------------------------------------------------------------------------- 1 | 2 | { 3 | function 4 | { 5 | type{"bool"}, 6 | ID{"test"}, 7 | function_body 8 | { 9 | variable_declaration 10 | { 11 | storage{}, 12 | modifier{}, 13 | type{"float4x4"}, 14 | variable{"foo"} 15 | }, 16 | variable_declaration 17 | { 18 | storage{}, 19 | modifier{}, 20 | type{"float3"}, 21 | variable 22 | { 23 | "bar", 24 | swizzle 25 | { 26 | variable 27 | { 28 | "foo", 29 | index{int_literal{"3"}} 30 | }, 31 | "xyz" 32 | } 33 | } 34 | }, 35 | return{bool_literal{"false"}} 36 | } 37 | } 38 | } -------------------------------------------------------------------------------- /src/host/lua-5.3.0/src/lprefix.h: -------------------------------------------------------------------------------- 1 | /* 2 | ** $Id: lprefix.h,v 1.2 2014/12/29 16:54:13 roberto Exp $ 3 | ** Definitions for Lua code that must come before any other header file 4 | ** See Copyright Notice in lua.h 5 | */ 6 | 7 | #ifndef lprefix_h 8 | #define lprefix_h 9 | 10 | 11 | /* 12 | ** Allows POSIX/XSI stuff 13 | */ 14 | #if !defined(LUA_USE_C89) /* { */ 15 | 16 | #if !defined(_XOPEN_SOURCE) 17 | #define _XOPEN_SOURCE 600 18 | #elif _XOPEN_SOURCE == 0 19 | #undef _XOPEN_SOURCE /* use -D_XOPEN_SOURCE=0 to undefine it */ 20 | #endif 21 | 22 | /* 23 | ** Allows manipulation of large files in gcc and some other compilers 24 | */ 25 | #if !defined(LUA_32BITS) && !defined(_FILE_OFFSET_BITS) 26 | #define _LARGEFILE_SOURCE 1 27 | #define _FILE_OFFSET_BITS 64 28 | #endif 29 | 30 | #endif /* } */ 31 | 32 | 33 | /* 34 | ** Windows stuff 35 | */ 36 | #if defined(_WIN32) /* { */ 37 | 38 | #if !defined(_CRT_SECURE_NO_WARNINGS) 39 | #define _CRT_SECURE_NO_WARNINGS /* avoid warnings about ISO C functions */ 40 | #endif 41 | 42 | #endif /* } */ 43 | 44 | #endif 45 | 46 | -------------------------------------------------------------------------------- /test/optim/clean_constants.fx: -------------------------------------------------------------------------------- 1 | float 2 | scalar_float, 3 | scalar_float_with_value = 0.5f; 4 | float2 5 | vector2_float, 6 | vector2_float_with_value = { 0.5f, 1.0f }; 7 | 8 | struct VS_OUTPUT 9 | { 10 | float4 Position : SV_POSITION; 11 | float4 Diffuse : COLOR0; 12 | float2 TextureUV : TEXCOORD0; 13 | }; 14 | 15 | VS_OUTPUT RenderSceneVS( float4 vPos : POSITION, 16 | float3 vNormal : NORMAL, 17 | float2 vTexCoord0 : TEXCOORD, 18 | uniform int nNumLights, 19 | uniform bool bTexture, 20 | uniform bool bAnimate ) 21 | { 22 | VS_OUTPUT Output; 23 | 24 | const float d = 1.0; 25 | const float e = 2.0; 26 | const float f = 3.0; 27 | const float g = 40 + scalar_float_with_value; 28 | 29 | output.Position.x = d + e; 30 | 31 | return Output; 32 | } 33 | 34 | // ~~ 35 | 36 | technique Default 37 | { 38 | pass P0 39 | { 40 | VertexShader = compile vs_3_0 RenderSceneVS( 1, true, false ); 41 | } 42 | } -------------------------------------------------------------------------------- /src/hlsl_parser/HLSLParserListener.h: -------------------------------------------------------------------------------- 1 | #ifndef HLSLPARSERLISTENER 2 | #define HLSLPARSERLISTENER 3 | 4 | struct Parameter; 5 | struct SamplerParameter; 6 | #include 7 | #include 8 | 9 | class HLSLParserListener 10 | { 11 | public: 12 | 13 | HLSLParserListener( lua_State * state ); 14 | 15 | void PushNode(); 16 | void PushNode( const char * name ); 17 | void PushNode( const std::string & name ){ PushNode( name.c_str() ); } 18 | void AddValue( const std::string & value ); 19 | void SetKeyValue( const std::string & key, const std::string & value ); 20 | void Assign(); 21 | void PopNode(); 22 | void SwapTopNodes(); 23 | 24 | private: 25 | 26 | lua_State 27 | * State; 28 | 29 | }; 30 | 31 | #define ast_push(...) Listener->PushNode( __VA_ARGS__ ) 32 | #define ast_set( _key_, _value_ ) Listener->SetKeyValue( _key_, _value_ ) 33 | #define ast_setname( _value_ ) Listener->SetKeyValue( "name", _value_ ) 34 | #define ast_addvalue( _value_ ) Listener->AddValue( _value_ ) 35 | #define ast_assign() Listener->Assign() 36 | #define ast_pop() Listener->PopNode() 37 | #define ast_swap() Listener->SwapTopNodes() 38 | 39 | #endif -------------------------------------------------------------------------------- /src/process/ast_rewrite_comparison.lua: -------------------------------------------------------------------------------- 1 | 2 | local function if_argument_literal( node ) 3 | local name_1 = node[ 1 ].name 4 | local name_2 = node[ 2 ].name 5 | return ( name_1 == "int_literal" or name_1 == "float_literal" ) 6 | and ( name_2 == "int_literal" or name_2 == "float_literal" ) 7 | and tonumber( node[ 1 ][ 1 ] ) ~= nil 8 | and tonumber( node[ 2 ][ 1 ] ) ~= nil 9 | end 10 | 11 | local function replace_by_result( operator ) 12 | 13 | local ls = loadstring or load 14 | 15 | return function( node, parent, index ) 16 | 17 | local value = assert( ls( 'return ' .. node[ 1 ][ 1 ] .. operator .. node[ 2 ][ 1 ] ) )() 18 | 19 | parent[ index ] = { name = "bool_literal", [ 1 ] = tostring( value ) } 20 | end 21 | end 22 | 23 | ast_rewrite_less_rules = 24 | { 25 | {if_argument_literal, replace_by_result( '<') }, 26 | } 27 | 28 | ast_rewrite_less_than_rules = 29 | { 30 | {if_argument_literal, replace_by_result( '<=' )}, 31 | } 32 | 33 | ast_rewrite_greater_rules = 34 | { 35 | {if_argument_literal, replace_by_result( '>' ) }, 36 | } 37 | 38 | ast_rewrite_greater_than_rules = 39 | { 40 | {if_argument_literal, replace_by_result( '>=')}, 41 | } 42 | 43 | 44 | -------------------------------------------------------------------------------- /src/generator/hlsl_generator.lua: -------------------------------------------------------------------------------- 1 | i = 0 2 | options = {} 3 | 4 | local HLSLGenerator_mt = { 5 | __index = function( t, name ) 6 | if options.hlsl_version == "11" and HLSLGenerator11[ name ] ~= nil then 7 | return HLSLGenerator11[ name ] 8 | else 9 | return HLSLGenerator9[ name ] 10 | end 11 | end 12 | } 13 | 14 | HLSLGenerator = { 15 | ["ProcessAst"] = function( ast, o ) 16 | options = o or {} 17 | 18 | for _, value in ipairs( ast ) do 19 | if HLSLGenerator[ "process_" .. value.name ] == nil then 20 | error( "No printer for ast node '" .. value.name .. "' in HLSL printer", 1 ) 21 | end 22 | 23 | i = 0 24 | 25 | ShaderPrint( HLSLGenerator[ "process_" .. value.name ]( value ) .. '\n' ) 26 | end 27 | end, 28 | 29 | ["ProcessNode"] = function( node ) 30 | if HLSLGenerator[ "process_" .. node.name ] == nil then 31 | error( "No printer for ast node '" .. node.name .. "' in HLSL printer", 1 ) 32 | end 33 | 34 | return HLSLGenerator[ "process_" .. node.name ]( node ) 35 | end, 36 | } 37 | 38 | setmetatable( HLSLGenerator, HLSLGenerator_mt ) 39 | 40 | RegisterPrinter( HLSLGenerator, "hlsl", "fx" ) -------------------------------------------------------------------------------- /src/hlsl_parser/HLSLConverter.cpp: -------------------------------------------------------------------------------- 1 | #include "HLSLConverter.h" 2 | #include "HLSLLexer.hpp" 3 | #include "HLSLParser.hpp" 4 | #include 5 | 6 | 7 | int HLSLConverter::ParseAst( 8 | lua_State * lua_state 9 | ) 10 | { 11 | HLSLConverter 12 | converter( lua_state ); 13 | int 14 | top; 15 | 16 | lua_newtable( lua_state ); 17 | top = lua_gettop( lua_state ); 18 | 19 | converter.LoadAst( lua_tostring( lua_state, -2 ) ); 20 | 21 | if( top != lua_gettop( lua_state ) ) 22 | { 23 | std::cerr << "Something went wrong with the parsing, there's items left on the stack : it was " << top 24 | << " now is " << lua_gettop( lua_state ) << std::endl; 25 | } 26 | 27 | assert( lua_istable( lua_state, -1 ) ); 28 | 29 | return 1; 30 | } 31 | 32 | void HLSLConverter::LoadAst( 33 | const std::string & filename 34 | ) 35 | { 36 | HLSLLexerTraits::InputStreamType input( (ANTLR_UINT8*)filename.c_str(), ANTLR_ENC_8BIT); 37 | HLSLLexer lexer(&input); // TLexerNew is generated by ANTLR 38 | HLSLLexerTraits::TokenStreamType token_stream(ANTLR_SIZE_HINT, lexer.get_tokSource() ); 39 | HLSLParser parser(&token_stream); // TParserNew is generated by ANTLR3 40 | 41 | parser.Listener = &Listener; 42 | parser.translation_unit(); 43 | 44 | } -------------------------------------------------------------------------------- /src/test/tokenizer.lua: -------------------------------------------------------------------------------- 1 | -- Heavily inspired by http://snippets.luacode.org/?p=snippets/String_Tokenizer_113 2 | 3 | 4 | local function _tokenizer(str) 5 | local yield = coroutine.yield 6 | local i = 1 7 | local i1,i2 8 | local function find(pat) 9 | i1,i2 = str:find(pat,i) 10 | return i1 ~= nil 11 | end 12 | local function token() 13 | return str:sub(i,i2) 14 | end 15 | while true do 16 | if find '^%s+' then 17 | -- ignore 18 | elseif find '^[%+%-]*%d+' then 19 | local ilast = i 20 | i = i2+1 -- just after the sequence of digits 21 | -- fractional part? 22 | local _,idx = str:find('^%.%d+',i) 23 | if idx then 24 | i2 = idx 25 | i = i2+1 26 | end 27 | -- exponent part? 28 | _,idx = str:find('^[eE][%+%-]*%d+',i) 29 | if idx then 30 | i2 = idx 31 | end 32 | i = ilast 33 | yield('number',tonumber(token())) 34 | elseif find '^[_%a][_%w]*' then 35 | yield('iden',token()) 36 | elseif find '^"[^"]*"' or find "^'[^']*'" then 37 | -- strip the quotes 38 | yield('string',token():sub(2,-2)) 39 | else -- any other character 40 | local ch = str:sub(i,i) 41 | if ch == '' then return 'eof','eof' end 42 | i2 = i 43 | yield(ch,ch) 44 | end 45 | i = i2+1 46 | end 47 | end 48 | 49 | function tokenizer(str) 50 | return coroutine.wrap(function() _tokenizer(str) end) 51 | end -------------------------------------------------------------------------------- /test/optim/replace_functions0.fx: -------------------------------------------------------------------------------- 1 | struct VS_OUTPUT 2 | { 3 | float4 Position : SV_POSITION; 4 | float4 Diffuse : COLOR0; 5 | float2 TextureUV : TEXCOORD0; 6 | }; 7 | 8 | float3 GetPosition( 9 | float x, 10 | float y, 11 | float z 12 | ) 13 | { 14 | return float3( x, y, z ); 15 | } 16 | 17 | void HelloWorld( 18 | float in_data 19 | ) 20 | { 21 | float r = in_data * in_data; 22 | } 23 | 24 | float Blah( 25 | float d, 26 | float e 27 | ) 28 | { 29 | return d * e; 30 | } 31 | 32 | // ~~ 33 | 34 | VS_OUTPUT RenderSceneVS( float4 vPos : POSITION, 35 | float3 vNormal : NORMAL, 36 | float2 vTexCoord0 : TEXCOORD, 37 | uniform int nNumLights, 38 | uniform bool bTexture, 39 | uniform bool bAnimate ) 40 | { 41 | VS_OUTPUT Output; 42 | 43 | const float d = 1.0; 44 | const float e = 2.0; 45 | const float f = 3.0; 46 | 47 | output.Position.x = d + e; 48 | 49 | output.Position = float4( GetPosition( d, e, f ), 0.0f ); 50 | 51 | HelloWorld( Blah( d + e ) ); 52 | 53 | return Output; 54 | } 55 | 56 | // ~~ 57 | 58 | technique Default 59 | { 60 | pass P0 61 | { 62 | VertexShader = compile vs_3_0 RenderSceneVS( 0, false, false ); 63 | } 64 | } -------------------------------------------------------------------------------- /src/_manifest.lua: -------------------------------------------------------------------------------- 1 | 2 | 3 | return { 4 | 5 | -- Intermediate representation 6 | 7 | "ir/ast_to_ir.lua", 8 | 9 | -- Printer 10 | 11 | "printer/printer_manager.lua", -- Must remain first of printer files 12 | 13 | -- Code Generator 14 | 15 | "generator/generator_utils.lua", 16 | "generator/ast_generator.lua", 17 | "generator/hlsl9_generator.lua", 18 | "generator/hlsl11_generator.lua", 19 | "generator/hlsl_generator.lua", 20 | "generator/glsl_generator.lua", 21 | 22 | -- Utilities 23 | 24 | "utilities/copy.lua", 25 | "utilities/argument_parser.lua", 26 | "utilities/output.lua", 27 | "utilities/debug.lua", 28 | "utilities/reflection.lua", 29 | "utilities/glsl_helper.lua", 30 | "utilities/string.lua", 31 | "utilities/tree.lua", 32 | 33 | -- Process 34 | 35 | "process/ast_processor.lua", 36 | "process/ast_rewrite_if.lua", 37 | "process/ast_rewrite_constants.lua", 38 | "process/ast_rewrite_comparison.lua", 39 | "process/ast_rewriter.lua", 40 | "process/file_checker.lua", 41 | --"process/function_replacement.lua", 42 | "process/function_replacer.lua", 43 | "process/function_inliner.lua", 44 | "process/optimizer.lua", 45 | "process/constants_optimizer.lua", 46 | "process/shader_parameter_inliner.lua", 47 | 48 | -- Test 49 | 50 | "test/tokenizer.lua" 51 | } 52 | -------------------------------------------------------------------------------- /test/parser/for_statement.reference.ast: -------------------------------------------------------------------------------- 1 | 2 | { 3 | function 4 | { 5 | type{"void"}, 6 | ID{"test"}, 7 | function_body 8 | { 9 | for 10 | { 11 | variable_declaration 12 | { 13 | storage{}, 14 | modifier{}, 15 | type{"int"}, 16 | variable 17 | { 18 | "index", 19 | int_literal{"0"} 20 | } 21 | }, 22 | < 23 | { 24 | variable{"index"}, 25 | int_literal{"10"} 26 | }, 27 | pre_modify 28 | { 29 | "++", 30 | variable{"index"} 31 | }, 32 | block 33 | { 34 | if 35 | { 36 | if_block 37 | { 38 | > 39 | { 40 | variable{"index"}, 41 | int_literal{"5"} 42 | }, 43 | block{break{}} 44 | } 45 | } 46 | } 47 | } 48 | } 49 | } 50 | } -------------------------------------------------------------------------------- /src/host/lua-5.3.0/src/lualib.h: -------------------------------------------------------------------------------- 1 | /* 2 | ** $Id: lualib.h,v 1.44 2014/02/06 17:32:33 roberto Exp $ 3 | ** Lua standard libraries 4 | ** See Copyright Notice in lua.h 5 | */ 6 | 7 | 8 | #ifndef lualib_h 9 | #define lualib_h 10 | 11 | #include "lua.h" 12 | 13 | 14 | 15 | LUAMOD_API int (luaopen_base) (lua_State *L); 16 | 17 | #define LUA_COLIBNAME "coroutine" 18 | LUAMOD_API int (luaopen_coroutine) (lua_State *L); 19 | 20 | #define LUA_TABLIBNAME "table" 21 | LUAMOD_API int (luaopen_table) (lua_State *L); 22 | 23 | #define LUA_IOLIBNAME "io" 24 | LUAMOD_API int (luaopen_io) (lua_State *L); 25 | 26 | #define LUA_OSLIBNAME "os" 27 | LUAMOD_API int (luaopen_os) (lua_State *L); 28 | 29 | #define LUA_STRLIBNAME "string" 30 | LUAMOD_API int (luaopen_string) (lua_State *L); 31 | 32 | #define LUA_UTF8LIBNAME "utf8" 33 | LUAMOD_API int (luaopen_utf8) (lua_State *L); 34 | 35 | #define LUA_BITLIBNAME "bit32" 36 | LUAMOD_API int (luaopen_bit32) (lua_State *L); 37 | 38 | #define LUA_MATHLIBNAME "math" 39 | LUAMOD_API int (luaopen_math) (lua_State *L); 40 | 41 | #define LUA_DBLIBNAME "debug" 42 | LUAMOD_API int (luaopen_debug) (lua_State *L); 43 | 44 | #define LUA_LOADLIBNAME "package" 45 | LUAMOD_API int (luaopen_package) (lua_State *L); 46 | 47 | 48 | /* open all previous libraries */ 49 | LUALIB_API void (luaL_openlibs) (lua_State *L); 50 | 51 | 52 | 53 | #if !defined(lua_assert) 54 | #define lua_assert(x) ((void)0) 55 | #endif 56 | 57 | 58 | #endif 59 | -------------------------------------------------------------------------------- /test/parser/function.fx: -------------------------------------------------------------------------------- 1 | struct VS_OUTPUT 2 | { 3 | float4 Position : SV_POSITION; 4 | float4 Diffuse : COLOR0; 5 | float2 TextureUV : TEXCOORD0; 6 | }; 7 | 8 | VS_OUTPUT RenderSceneVS( float4 vPos : POSITION, 9 | float3 vNormal : NORMAL, 10 | float2 vTexCoord0 : TEXCOORD, 11 | 12 | in const float2 vpos, 13 | out const float3 world_space_view_vector, 14 | 15 | uniform int nNumLights, 16 | uniform bool bTexture, 17 | uniform bool bAnimate 18 | ) 19 | { 20 | VS_OUTPUT Output; 21 | 22 | const float d = 1.0; 23 | const float e = 2.0; 24 | const float f = 3.0; 25 | 26 | output.Position.x = d + e; 27 | 28 | return Output; 29 | } 30 | 31 | float4 PSMain( 32 | const VS_OUTPUT input, 33 | in float2 vpos : VPOS, 34 | 35 | uniform const bool it_has_rim, 36 | uniform const bool it_uses_light_prepass, 37 | uniform const bool it_uses_color_overlay, 38 | uniform const bool it_uses_fog, 39 | uniform const bool it_uses_forward_lights 40 | ) : COLOR0 41 | { 42 | 43 | } 44 | 45 | // ~~ 46 | 47 | technique Default 48 | { 49 | pass P0 50 | { 51 | VertexShader = compile vs_3_0 RenderSceneVS( 3, true, true ); 52 | PixelShader = compile ps_3_0 PSMain(); 53 | } 54 | } -------------------------------------------------------------------------------- /src/host/lua-5.3.0/src/lstring.h: -------------------------------------------------------------------------------- 1 | /* 2 | ** $Id: lstring.h,v 1.56 2014/07/18 14:46:47 roberto Exp $ 3 | ** String table (keep all strings handled by Lua) 4 | ** See Copyright Notice in lua.h 5 | */ 6 | 7 | #ifndef lstring_h 8 | #define lstring_h 9 | 10 | #include "lgc.h" 11 | #include "lobject.h" 12 | #include "lstate.h" 13 | 14 | 15 | #define sizelstring(l) (sizeof(union UTString) + ((l) + 1) * sizeof(char)) 16 | #define sizestring(s) sizelstring((s)->len) 17 | 18 | #define sizeludata(l) (sizeof(union UUdata) + (l)) 19 | #define sizeudata(u) sizeludata((u)->len) 20 | 21 | #define luaS_newliteral(L, s) (luaS_newlstr(L, "" s, \ 22 | (sizeof(s)/sizeof(char))-1)) 23 | 24 | 25 | /* 26 | ** test whether a string is a reserved word 27 | */ 28 | #define isreserved(s) ((s)->tt == LUA_TSHRSTR && (s)->extra > 0) 29 | 30 | 31 | /* 32 | ** equality for short strings, which are always internalized 33 | */ 34 | #define eqshrstr(a,b) check_exp((a)->tt == LUA_TSHRSTR, (a) == (b)) 35 | 36 | 37 | LUAI_FUNC unsigned int luaS_hash (const char *str, size_t l, unsigned int seed); 38 | LUAI_FUNC int luaS_eqlngstr (TString *a, TString *b); 39 | LUAI_FUNC void luaS_resize (lua_State *L, int newsize); 40 | LUAI_FUNC void luaS_remove (lua_State *L, TString *ts); 41 | LUAI_FUNC Udata *luaS_newudata (lua_State *L, size_t s); 42 | LUAI_FUNC TString *luaS_newlstr (lua_State *L, const char *str, size_t l); 43 | LUAI_FUNC TString *luaS_new (lua_State *L, const char *str); 44 | 45 | 46 | #endif 47 | -------------------------------------------------------------------------------- /samples/test.lua: -------------------------------------------------------------------------------- 1 | 2 | Texture2D "DiffuseTexture" 3 | 4 | Constant( "float4", "DiffuseColor" ) 5 | Constant( "float4x4", "Projection" ) 6 | Constant( "float4x4", "WorldView" ) 7 | 8 | ItHasDiffuseTexture = true 9 | 10 | function VertexShader() 11 | 12 | DefineInput() 13 | InputAttribute( "Position", "float3", "POSITION" ); 14 | InputAttribute( "TexCoord", "float2", "TEXCOORD0" ); 15 | InputAttribute( "Color", "float4", "COLOR0" ); 16 | EndInput() 17 | 18 | local output = DefineStructure( "output" ) 19 | StructureAttribute( "Position", "float4", "POSITION" ); 20 | StructureAttribute( "TexCoord", "float2", "TEXCOORD0" ); 21 | StructureAttribute( "Color", "float4", "COLOR0" ); 22 | EndStructure() 23 | 24 | b = float4( 0, 1, 2, 3 ); 25 | 26 | local wvp = Projection * WorldView; 27 | output.Position = wvp * float4( input.Position, 1 ); 28 | output.Color = 2 * b * DiffuseColor * input.Color; 29 | output.TexCoord = input.TexCoord.xy 30 | 31 | return output; 32 | end 33 | 34 | function PixelShader() 35 | 36 | DefineInput() 37 | InputAttribute( "TexCoord", "float2", "TEXCOORD0" ); 38 | InputAttribute( "Color", "float4", "COLOR0" ); 39 | EndInput() 40 | 41 | local output = DefineStructure( "output" ) 42 | StructureAttribute( "Color", "float4", "COLOR0" ); 43 | EndStructure() 44 | 45 | output.Color = input.Color * tex2D( DiffuseTexture, input.TexCoord ); 46 | return output; 47 | end 48 | 49 | technique{ 50 | name = "Default", 51 | vs = VertexShader(), 52 | ps = PixelShader() 53 | } -------------------------------------------------------------------------------- /src/host/lua-5.3.0/src/ldebug.h: -------------------------------------------------------------------------------- 1 | /* 2 | ** $Id: ldebug.h,v 2.12 2014/11/10 14:46:05 roberto Exp $ 3 | ** Auxiliary functions from Debug Interface module 4 | ** See Copyright Notice in lua.h 5 | */ 6 | 7 | #ifndef ldebug_h 8 | #define ldebug_h 9 | 10 | 11 | #include "lstate.h" 12 | 13 | 14 | #define pcRel(pc, p) (cast(int, (pc) - (p)->code) - 1) 15 | 16 | #define getfuncline(f,pc) (((f)->lineinfo) ? (f)->lineinfo[pc] : -1) 17 | 18 | #define resethookcount(L) (L->hookcount = L->basehookcount) 19 | 20 | /* Active Lua function (given call info) */ 21 | #define ci_func(ci) (clLvalue((ci)->func)) 22 | 23 | 24 | LUAI_FUNC l_noret luaG_typeerror (lua_State *L, const TValue *o, 25 | const char *opname); 26 | LUAI_FUNC l_noret luaG_concaterror (lua_State *L, const TValue *p1, 27 | const TValue *p2); 28 | LUAI_FUNC l_noret luaG_opinterror (lua_State *L, const TValue *p1, 29 | const TValue *p2, 30 | const char *msg); 31 | LUAI_FUNC l_noret luaG_tointerror (lua_State *L, const TValue *p1, 32 | const TValue *p2); 33 | LUAI_FUNC l_noret luaG_ordererror (lua_State *L, const TValue *p1, 34 | const TValue *p2); 35 | LUAI_FUNC l_noret luaG_runerror (lua_State *L, const char *fmt, ...); 36 | LUAI_FUNC l_noret luaG_errormsg (lua_State *L); 37 | LUAI_FUNC void luaG_traceexec (lua_State *L); 38 | 39 | 40 | #endif 41 | -------------------------------------------------------------------------------- /test/optim/constant_folding/if_condition.fx: -------------------------------------------------------------------------------- 1 | float if_true( bool a ) 2 | { 3 | if( true ) 4 | { 5 | return 1.0f; 6 | } 7 | else if( a ) 8 | { 9 | return 2.0f; 10 | } 11 | else 12 | { 13 | return 3.0f; 14 | } 15 | } 16 | 17 | float else_if_true( bool a, bool b ) 18 | { 19 | if( a ) 20 | { 21 | return 1.0f; 22 | } 23 | else if( true ) 24 | { 25 | return 2.0f; 26 | } 27 | else if( b ) 28 | { 29 | return 3.0f; 30 | } 31 | else 32 | { 33 | return 4.0f; 34 | } 35 | } 36 | 37 | float else_if_2_true( bool a, bool b ) 38 | { 39 | if( a ) 40 | { 41 | return 1.0f; 42 | } 43 | else if( b ) 44 | { 45 | return 2.0f; 46 | } 47 | else if( true ) 48 | { 49 | return 3.0f; 50 | } 51 | else 52 | { 53 | return 4.0f; 54 | } 55 | } 56 | 57 | float if_false( bool a ) 58 | { 59 | if( false ) 60 | { 61 | return 1.0f; 62 | } 63 | else if( a ) 64 | { 65 | return 2.0f; 66 | } 67 | else 68 | { 69 | return 3.0f; 70 | } 71 | } 72 | 73 | float else_if_false( bool a, bool b ) 74 | { 75 | if( a ) 76 | { 77 | return 1.0f; 78 | } 79 | else if( false ) 80 | { 81 | return 2.0f; 82 | } 83 | else if( b ) 84 | { 85 | return 3.0f; 86 | } 87 | else 88 | { 89 | return 4.0f; 90 | } 91 | } 92 | 93 | float else_if_2_false( bool a, bool b ) 94 | { 95 | if( a ) 96 | { 97 | return 1.0f; 98 | } 99 | else if( b ) 100 | { 101 | return 2.0f; 102 | } 103 | else if( false ) 104 | { 105 | return 3.0f; 106 | } 107 | else 108 | { 109 | return 4.0f; 110 | } 111 | } 112 | -------------------------------------------------------------------------------- /src/printer/printer_manager.lua: -------------------------------------------------------------------------------- 1 | local PrinterTable = {} 2 | local SelectedPrinter 3 | 4 | function RegisterPrinter( printer, name, file_extension ) 5 | 6 | PrinterTable[ name ] = { printer = printer, extension = file_extension }; 7 | end 8 | 9 | 10 | function GetSelectedPrinter() 11 | if SelectedPrinter == nil then 12 | error( "No printer selected" ) 13 | end 14 | return SelectedPrinter 15 | end 16 | 17 | function SelectPrinter( filename, override_name ) 18 | 19 | if override_name ~= nil then 20 | if PrinterTable[ override_name ] == nil then 21 | error( "Invalid language name" ) 22 | end 23 | 24 | SelectedPrinter = PrinterTable[ override_name ].printer 25 | return 26 | end 27 | 28 | if filename == "console_output" then 29 | error( "Language should be specified when outputing to the console" ) 30 | end 31 | 32 | local 33 | extension = nil 34 | 35 | for index = string.len( filename ), 1, -1 do 36 | local character = string.sub( filename, index, index ) 37 | if character == '.' then 38 | extension = string.sub( filename, index + 1 ) 39 | break 40 | end 41 | end 42 | 43 | if extension == nil then 44 | error( "Unable to extract file extension" ); 45 | end 46 | 47 | for name, description in pairs( PrinterTable ) do 48 | 49 | if description.extension == extension then 50 | SelectedPrinter = description.printer 51 | return 52 | end 53 | 54 | end 55 | 56 | error( "Unable to detect language from file extension" ) 57 | end -------------------------------------------------------------------------------- /src/_shader_shaker_main.lua: -------------------------------------------------------------------------------- 1 | local 2 | options = {} 3 | 4 | function _shader_shaker_main( script_path, argument_table ) 5 | 6 | -- if running off the disk (in debug mode), load everything 7 | -- listed in _manifest.lua; the list divisions make sure 8 | -- everything gets initialized in the proper order. 9 | 10 | if script_path then 11 | local scripts = dofile(script_path .. "/_manifest.lua") 12 | for _,v in ipairs(scripts) do 13 | dofile( script_path .. "/" .. v ) 14 | end 15 | end 16 | 17 | local argument_parser = ArgumentParser:new() 18 | 19 | options = argument_parser:GetParsedArguments( argument_table ) 20 | end 21 | 22 | 23 | function _shaker_shaker_process_files() 24 | local 25 | ast 26 | 27 | print( "Processing " .. options.input_file ) 28 | 29 | ast = AstProcessor.Process( options ) 30 | 31 | if options.check_file then 32 | 33 | FileChecker.Process( options.check_file, ast ) 34 | 35 | collectgarbage() 36 | return 0 37 | 38 | else 39 | 40 | for i, output_file in ipairs( options.output_files ) do 41 | local ast_copy = DeepCopy( ast ) 42 | 43 | SelectPrinter( output_file, options.force_language ) 44 | 45 | if output_file ~= "console_output" then 46 | InitializeOutputFile( output_file, options ) 47 | else 48 | InitializeOutputPrint( options ) 49 | end 50 | 51 | GetSelectedPrinter().ProcessAst( ast_copy, options ) 52 | 53 | end 54 | end 55 | 56 | collectgarbage() 57 | return 0 58 | end -------------------------------------------------------------------------------- /src/process/ast_rewrite_if.lua: -------------------------------------------------------------------------------- 1 | 2 | local function if_block_( value ) 3 | return function( node ) 4 | return node[ 1 ].name == "bool_literal" and node[ 1 ][ 1 ] == value 5 | end 6 | end 7 | 8 | local function keep_if_block( node, parent, index ) 9 | assert( index == 1 ) 10 | assert( node[ 2 ].name == "block" ) 11 | 12 | while table.remove( parent ) ~= nil do end 13 | parent.name = "block" 14 | parent[ 1 ] = node[ 2 ][ 1 ]; 15 | end 16 | 17 | local function transform_to_else_and_discard_following( node, parent, index ) 18 | 19 | while #parent > index do 20 | table.remove( parent ) 21 | end 22 | 23 | node.name = "else_block" 24 | table.remove( node, 1 ) 25 | end 26 | 27 | local function discard_if( node, parent, index ) 28 | assert( index == 1 ) 29 | 30 | if #parent == 1 then 31 | table.remove( parent ) 32 | parent.name = "nop" 33 | elseif parent[ 2 ].name == "else_block" then 34 | table.remove( parent ) 35 | parent.name = "block" 36 | parent[ 1 ] = node[ 2 ][ 1 ]; 37 | else 38 | assert( parent[ 2 ].name == "else_if_block" ) 39 | 40 | table.remove( parent, 1 ) 41 | parent[ 1 ].name = "if_block" 42 | end 43 | end 44 | 45 | local function discard_block( node, parent, index ) 46 | table.remove( parent, index ) 47 | end 48 | 49 | 50 | ast_rewrite_if_block_rules = 51 | { 52 | {if_block_( "true" ), keep_if_block}, 53 | {if_block_( "false" ), discard_if}, 54 | } 55 | 56 | ast_rewrite_else_if_block_rules = 57 | { 58 | {if_block_( "true" ), transform_to_else_and_discard_following }, 59 | {if_block_( "false" ), discard_block}, 60 | } 61 | -------------------------------------------------------------------------------- /src/host/lua-5.3.0/src/ldo.h: -------------------------------------------------------------------------------- 1 | /* 2 | ** $Id: ldo.h,v 2.21 2014/10/25 11:50:46 roberto Exp $ 3 | ** Stack and Call structure of Lua 4 | ** See Copyright Notice in lua.h 5 | */ 6 | 7 | #ifndef ldo_h 8 | #define ldo_h 9 | 10 | 11 | #include "lobject.h" 12 | #include "lstate.h" 13 | #include "lzio.h" 14 | 15 | 16 | #define luaD_checkstack(L,n) if (L->stack_last - L->top <= (n)) \ 17 | luaD_growstack(L, n); else condmovestack(L); 18 | 19 | 20 | #define incr_top(L) {L->top++; luaD_checkstack(L,0);} 21 | 22 | #define savestack(L,p) ((char *)(p) - (char *)L->stack) 23 | #define restorestack(L,n) ((TValue *)((char *)L->stack + (n))) 24 | 25 | 26 | /* type of protected functions, to be ran by 'runprotected' */ 27 | typedef void (*Pfunc) (lua_State *L, void *ud); 28 | 29 | LUAI_FUNC int luaD_protectedparser (lua_State *L, ZIO *z, const char *name, 30 | const char *mode); 31 | LUAI_FUNC void luaD_hook (lua_State *L, int event, int line); 32 | LUAI_FUNC int luaD_precall (lua_State *L, StkId func, int nresults); 33 | LUAI_FUNC void luaD_call (lua_State *L, StkId func, int nResults, 34 | int allowyield); 35 | LUAI_FUNC int luaD_pcall (lua_State *L, Pfunc func, void *u, 36 | ptrdiff_t oldtop, ptrdiff_t ef); 37 | LUAI_FUNC int luaD_poscall (lua_State *L, StkId firstResult); 38 | LUAI_FUNC void luaD_reallocstack (lua_State *L, int newsize); 39 | LUAI_FUNC void luaD_growstack (lua_State *L, int n); 40 | LUAI_FUNC void luaD_shrinkstack (lua_State *L); 41 | 42 | LUAI_FUNC l_noret luaD_throw (lua_State *L, int errcode); 43 | LUAI_FUNC int luaD_rawrunprotected (lua_State *L, Pfunc f, void *ud); 44 | 45 | #endif 46 | 47 | -------------------------------------------------------------------------------- /src/host/lua-5.3.0/src/lfunc.h: -------------------------------------------------------------------------------- 1 | /* 2 | ** $Id: lfunc.h,v 2.14 2014/06/19 18:27:20 roberto Exp $ 3 | ** Auxiliary functions to manipulate prototypes and closures 4 | ** See Copyright Notice in lua.h 5 | */ 6 | 7 | #ifndef lfunc_h 8 | #define lfunc_h 9 | 10 | 11 | #include "lobject.h" 12 | 13 | 14 | #define sizeCclosure(n) (cast(int, sizeof(CClosure)) + \ 15 | cast(int, sizeof(TValue)*((n)-1))) 16 | 17 | #define sizeLclosure(n) (cast(int, sizeof(LClosure)) + \ 18 | cast(int, sizeof(TValue *)*((n)-1))) 19 | 20 | 21 | /* test whether thread is in 'twups' list */ 22 | #define isintwups(L) (L->twups != L) 23 | 24 | 25 | /* 26 | ** Upvalues for Lua closures 27 | */ 28 | struct UpVal { 29 | TValue *v; /* points to stack or to its own value */ 30 | lu_mem refcount; /* reference counter */ 31 | union { 32 | struct { /* (when open) */ 33 | UpVal *next; /* linked list */ 34 | int touched; /* mark to avoid cycles with dead threads */ 35 | } open; 36 | TValue value; /* the value (when closed) */ 37 | } u; 38 | }; 39 | 40 | #define upisopen(up) ((up)->v != &(up)->u.value) 41 | 42 | 43 | LUAI_FUNC Proto *luaF_newproto (lua_State *L); 44 | LUAI_FUNC CClosure *luaF_newCclosure (lua_State *L, int nelems); 45 | LUAI_FUNC LClosure *luaF_newLclosure (lua_State *L, int nelems); 46 | LUAI_FUNC void luaF_initupvals (lua_State *L, LClosure *cl); 47 | LUAI_FUNC UpVal *luaF_findupval (lua_State *L, StkId level); 48 | LUAI_FUNC void luaF_close (lua_State *L, StkId level); 49 | LUAI_FUNC void luaF_freeproto (lua_State *L, Proto *f); 50 | LUAI_FUNC const char *luaF_getlocalname (const Proto *func, int local_number, 51 | int pc); 52 | 53 | 54 | #endif 55 | -------------------------------------------------------------------------------- /src/host/lua-5.3.0/src/lzio.h: -------------------------------------------------------------------------------- 1 | /* 2 | ** $Id: lzio.h,v 1.30 2014/12/19 17:26:14 roberto Exp $ 3 | ** Buffered streams 4 | ** See Copyright Notice in lua.h 5 | */ 6 | 7 | 8 | #ifndef lzio_h 9 | #define lzio_h 10 | 11 | #include "lua.h" 12 | 13 | #include "lmem.h" 14 | 15 | 16 | #define EOZ (-1) /* end of stream */ 17 | 18 | typedef struct Zio ZIO; 19 | 20 | #define zgetc(z) (((z)->n--)>0 ? cast_uchar(*(z)->p++) : luaZ_fill(z)) 21 | 22 | 23 | typedef struct Mbuffer { 24 | char *buffer; 25 | size_t n; 26 | size_t buffsize; 27 | } Mbuffer; 28 | 29 | #define luaZ_initbuffer(L, buff) ((buff)->buffer = NULL, (buff)->buffsize = 0) 30 | 31 | #define luaZ_buffer(buff) ((buff)->buffer) 32 | #define luaZ_sizebuffer(buff) ((buff)->buffsize) 33 | #define luaZ_bufflen(buff) ((buff)->n) 34 | 35 | #define luaZ_buffremove(buff,i) ((buff)->n -= (i)) 36 | #define luaZ_resetbuffer(buff) ((buff)->n = 0) 37 | 38 | 39 | #define luaZ_resizebuffer(L, buff, size) \ 40 | ((buff)->buffer = luaM_reallocvchar(L, (buff)->buffer, \ 41 | (buff)->buffsize, size), \ 42 | (buff)->buffsize = size) 43 | 44 | #define luaZ_freebuffer(L, buff) luaZ_resizebuffer(L, buff, 0) 45 | 46 | 47 | LUAI_FUNC char *luaZ_openspace (lua_State *L, Mbuffer *buff, size_t n); 48 | LUAI_FUNC void luaZ_init (lua_State *L, ZIO *z, lua_Reader reader, 49 | void *data); 50 | LUAI_FUNC size_t luaZ_read (ZIO* z, void *b, size_t n); /* read next n bytes */ 51 | 52 | 53 | 54 | /* --------- Private Part ------------------ */ 55 | 56 | struct Zio { 57 | size_t n; /* bytes still unread */ 58 | const char *p; /* current position in buffer */ 59 | lua_Reader reader; /* reader function */ 60 | void *data; /* additional data */ 61 | lua_State *L; /* Lua state (for reader) */ 62 | }; 63 | 64 | 65 | LUAI_FUNC int luaZ_fill (ZIO *z); 66 | 67 | #endif 68 | -------------------------------------------------------------------------------- /src/host/lua-5.3.0/src/ltable.h: -------------------------------------------------------------------------------- 1 | /* 2 | ** $Id: ltable.h,v 2.20 2014/09/04 18:15:29 roberto Exp $ 3 | ** Lua tables (hash) 4 | ** See Copyright Notice in lua.h 5 | */ 6 | 7 | #ifndef ltable_h 8 | #define ltable_h 9 | 10 | #include "lobject.h" 11 | 12 | 13 | #define gnode(t,i) (&(t)->node[i]) 14 | #define gval(n) (&(n)->i_val) 15 | #define gnext(n) ((n)->i_key.nk.next) 16 | 17 | 18 | /* 'const' to avoid wrong writings that can mess up field 'next' */ 19 | #define gkey(n) cast(const TValue*, (&(n)->i_key.tvk)) 20 | 21 | #define wgkey(n) (&(n)->i_key.nk) 22 | 23 | #define invalidateTMcache(t) ((t)->flags = 0) 24 | 25 | 26 | /* returns the key, given the value of a table entry */ 27 | #define keyfromval(v) \ 28 | (gkey(cast(Node *, cast(char *, (v)) - offsetof(Node, i_val)))) 29 | 30 | 31 | LUAI_FUNC const TValue *luaH_getint (Table *t, lua_Integer key); 32 | LUAI_FUNC void luaH_setint (lua_State *L, Table *t, lua_Integer key, 33 | TValue *value); 34 | LUAI_FUNC const TValue *luaH_getstr (Table *t, TString *key); 35 | LUAI_FUNC const TValue *luaH_get (Table *t, const TValue *key); 36 | LUAI_FUNC TValue *luaH_newkey (lua_State *L, Table *t, const TValue *key); 37 | LUAI_FUNC TValue *luaH_set (lua_State *L, Table *t, const TValue *key); 38 | LUAI_FUNC Table *luaH_new (lua_State *L); 39 | LUAI_FUNC void luaH_resize (lua_State *L, Table *t, unsigned int nasize, 40 | unsigned int nhsize); 41 | LUAI_FUNC void luaH_resizearray (lua_State *L, Table *t, unsigned int nasize); 42 | LUAI_FUNC void luaH_free (lua_State *L, Table *t); 43 | LUAI_FUNC int luaH_next (lua_State *L, Table *t, StkId key); 44 | LUAI_FUNC int luaH_getn (Table *t); 45 | 46 | 47 | #if defined(LUA_DEBUG) 48 | LUAI_FUNC Node *luaH_mainposition (const Table *t, const TValue *key); 49 | LUAI_FUNC int luaH_isdummy (Node *n); 50 | #endif 51 | 52 | 53 | #endif 54 | -------------------------------------------------------------------------------- /src/process/ast_rewriter.lua: -------------------------------------------------------------------------------- 1 | AstRewriter = { 2 | } 3 | 4 | function AstRewriter:new() 5 | local instance = {} 6 | setmetatable( instance, self ) 7 | self.__index = self 8 | return instance 9 | end 10 | 11 | function AstRewriter:Process( parent_node ) 12 | local node_rewrite_table = 13 | { 14 | ['unary_!'] = ast_rewrite_unary_not_rules, 15 | ['if_block'] = ast_rewrite_if_block_rules, 16 | ['else_if_block'] = ast_rewrite_else_if_block_rules, 17 | [ '*' ] = ast_rewrite_multiplication_rules, 18 | [ '+' ] = ast_rewrite_addition_rules, 19 | [ '&&' ] = ast_rewrite_boolean_and_rules, 20 | [ '||' ] = ast_rewrite_boolean_or_rules, 21 | [ '<' ] = ast_rewrite_less_rules, 22 | [ '<=' ] = ast_rewrite_less_than_rules, 23 | [ '>' ] = ast_rewrite_greater_rules, 24 | [ '>=' ] = ast_rewrite_greater_than_rules, 25 | } 26 | 27 | local rewrite_node = function( node, parent, index ) 28 | local it_has_changed = false 29 | 30 | if node == nil then 31 | -- Tricky: Rewrite might delete next node and for does not reevaluate 32 | return 33 | end 34 | 35 | repeat 36 | local rewrite_table = node_rewrite_table[ node.name ] 37 | 38 | if rewrite_table == nil then 39 | return 40 | end 41 | 42 | local function evaluate() 43 | for _, predicate_action in pairs( rewrite_table ) do 44 | if ( predicate_action[1] )( node ) == true then 45 | ( predicate_action[2] )( node, parent, index ) 46 | return true 47 | end 48 | end 49 | return false 50 | end 51 | 52 | it_has_changed = evaluate() 53 | 54 | until it_has_changed == false or node ~= parent[ index ] 55 | end 56 | 57 | WalkTree( parent_node, rewrite_node ) 58 | end 59 | -------------------------------------------------------------------------------- /src/host/lua-5.3.0/src/lzio.c: -------------------------------------------------------------------------------- 1 | /* 2 | ** $Id: lzio.c,v 1.36 2014/11/02 19:19:04 roberto Exp $ 3 | ** Buffered streams 4 | ** See Copyright Notice in lua.h 5 | */ 6 | 7 | #define lzio_c 8 | #define LUA_CORE 9 | 10 | #include "lprefix.h" 11 | 12 | 13 | #include 14 | 15 | #include "lua.h" 16 | 17 | #include "llimits.h" 18 | #include "lmem.h" 19 | #include "lstate.h" 20 | #include "lzio.h" 21 | 22 | 23 | int luaZ_fill (ZIO *z) { 24 | size_t size; 25 | lua_State *L = z->L; 26 | const char *buff; 27 | lua_unlock(L); 28 | buff = z->reader(L, z->data, &size); 29 | lua_lock(L); 30 | if (buff == NULL || size == 0) 31 | return EOZ; 32 | z->n = size - 1; /* discount char being returned */ 33 | z->p = buff; 34 | return cast_uchar(*(z->p++)); 35 | } 36 | 37 | 38 | void luaZ_init (lua_State *L, ZIO *z, lua_Reader reader, void *data) { 39 | z->L = L; 40 | z->reader = reader; 41 | z->data = data; 42 | z->n = 0; 43 | z->p = NULL; 44 | } 45 | 46 | 47 | /* --------------------------------------------------------------- read --- */ 48 | size_t luaZ_read (ZIO *z, void *b, size_t n) { 49 | while (n) { 50 | size_t m; 51 | if (z->n == 0) { /* no bytes in buffer? */ 52 | if (luaZ_fill(z) == EOZ) /* try to read more */ 53 | return n; /* no more input; return number of missing bytes */ 54 | else { 55 | z->n++; /* luaZ_fill consumed first byte; put it back */ 56 | z->p--; 57 | } 58 | } 59 | m = (n <= z->n) ? n : z->n; /* min. between n and z->n */ 60 | memcpy(b, z->p, m); 61 | z->n -= m; 62 | z->p += m; 63 | b = (char *)b + m; 64 | n -= m; 65 | } 66 | return 0; 67 | } 68 | 69 | /* ------------------------------------------------------------------------ */ 70 | char *luaZ_openspace (lua_State *L, Mbuffer *buff, size_t n) { 71 | if (n > buff->buffsize) { 72 | if (n < LUA_MINBUFFER) n = LUA_MINBUFFER; 73 | luaZ_resizebuffer(L, buff, n); 74 | } 75 | return buff->buffer; 76 | } 77 | 78 | 79 | -------------------------------------------------------------------------------- /test/parser/ps_return.fx: -------------------------------------------------------------------------------- 1 | struct VS_TEXTURED_INPUT 2 | { 3 | float2 Position : POSITION; 4 | float2 TextureCoordinate : TEXCOORD0; 5 | }; 6 | 7 | struct VS_TEXTURED_OUTPUT 8 | { 9 | float4 Position : POSITION; 10 | float2 TextureCoordinate : TEXCOORD0; 11 | }; 12 | 13 | float2 HelloWorld( 14 | uniform float2 toto 15 | ) 16 | { 17 | return toto * 1.5f; 18 | } 19 | 20 | VS_TEXTURED_OUTPUT vs( 21 | VS_TEXTURED_INPUT input, 22 | uniform bool hello, 23 | uniform float2 toto 24 | ) 25 | { 26 | VS_TEXTURED_OUTPUT 27 | output; 28 | 29 | output.Position = float4( input.Position, 0, 1 ); 30 | output.TextureCoordinate = input.TextureCoordinate * toto; 31 | 32 | if ( hello ) 33 | { 34 | output.TextureCoordinate *= HelloWorld( toto ); 35 | } 36 | 37 | return output; 38 | } 39 | 40 | float4 pixel_shader_common( 41 | float2 texture_coordinate : TEXCOORD0, 42 | uniform bool it_use_shadow_mask 43 | ) 44 | { 45 | float4 46 | result = { 0.0f, 0.0f, 0.0f, 0.0f }; 47 | 48 | return result; 49 | } 50 | 51 | // ~~ 52 | 53 | float4 ps( 54 | float2 texture_coordinate : TEXCOORD0, 55 | uniform bool it_use_shadow_mask 56 | ) : COLOR0 57 | { 58 | return pixel_shader_common( texture_coordinate, it_use_shadow_mask ); 59 | } 60 | 61 | // ~~ 62 | 63 | float4 ps_with_water( 64 | float2 texture_coordinate : TEXCOORD0, 65 | float2 vpos : VPOS, 66 | uniform bool it_use_shadow_mask 67 | ) : COLOR0 68 | { 69 | float4 70 | color_multiplier; 71 | 72 | return color_multiplier * pixel_shader_common( texture_coordinate, it_use_shadow_mask ); 73 | } 74 | 75 | technique DefaultWithShadowMapAndWater 76 | { 77 | pass P0 78 | { 79 | VertexShader = compile vs_3_0 vs( false, float2( 0.5f, 1.5 * 2.0f ) ); 80 | PixelShader = compile ps_3_0 ps_with_water( true ); 81 | } 82 | } 83 | -------------------------------------------------------------------------------- /src/host/lua-5.3.0/src/linit.c: -------------------------------------------------------------------------------- 1 | /* 2 | ** $Id: linit.c,v 1.38 2015/01/05 13:48:33 roberto Exp $ 3 | ** Initialization of libraries for lua.c and other clients 4 | ** See Copyright Notice in lua.h 5 | */ 6 | 7 | 8 | #define linit_c 9 | #define LUA_LIB 10 | 11 | /* 12 | ** If you embed Lua in your program and need to open the standard 13 | ** libraries, call luaL_openlibs in your program. If you need a 14 | ** different set of libraries, copy this file to your project and edit 15 | ** it to suit your needs. 16 | ** 17 | ** You can also *preload* libraries, so that a later 'require' can 18 | ** open the library, which is already linked to the application. 19 | ** For that, do the following code: 20 | ** 21 | ** luaL_getsubtable(L, LUA_REGISTRYINDEX, "_PRELOAD"); 22 | ** lua_pushcfunction(L, luaopen_modname); 23 | ** lua_setfield(L, -2, modname); 24 | ** lua_pop(L, 1); // remove _PRELOAD table 25 | */ 26 | 27 | #include "lprefix.h" 28 | 29 | 30 | #include 31 | 32 | #include "lua.h" 33 | 34 | #include "lualib.h" 35 | #include "lauxlib.h" 36 | 37 | 38 | /* 39 | ** these libs are loaded by lua.c and are readily available to any Lua 40 | ** program 41 | */ 42 | static const luaL_Reg loadedlibs[] = { 43 | {"_G", luaopen_base}, 44 | {LUA_LOADLIBNAME, luaopen_package}, 45 | {LUA_COLIBNAME, luaopen_coroutine}, 46 | {LUA_TABLIBNAME, luaopen_table}, 47 | {LUA_IOLIBNAME, luaopen_io}, 48 | {LUA_OSLIBNAME, luaopen_os}, 49 | {LUA_STRLIBNAME, luaopen_string}, 50 | {LUA_MATHLIBNAME, luaopen_math}, 51 | {LUA_UTF8LIBNAME, luaopen_utf8}, 52 | {LUA_DBLIBNAME, luaopen_debug}, 53 | #if defined(LUA_COMPAT_BITLIB) 54 | {LUA_BITLIBNAME, luaopen_bit32}, 55 | #endif 56 | {NULL, NULL} 57 | }; 58 | 59 | 60 | LUALIB_API void luaL_openlibs (lua_State *L) { 61 | const luaL_Reg *lib; 62 | /* "require" functions from 'loadedlibs' and set results to global table */ 63 | for (lib = loadedlibs; lib->func; lib++) { 64 | luaL_requiref(L, lib->name, lib->func, 1); 65 | lua_pop(L, 1); /* remove lib */ 66 | } 67 | } 68 | 69 | -------------------------------------------------------------------------------- /test/build.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | 27 | 28 | 29 | 30 | 31 | 32 | 33 | 34 | 35 | 36 | 37 | 38 | 39 | 40 | 41 | 42 | 43 | 44 | 45 | 46 | 47 | 48 | 49 | 50 | 51 | 52 | 53 | 54 | 55 | 56 | 57 | 58 | 59 | 60 | 61 | 62 | 63 | -------------------------------------------------------------------------------- /test/optim/constant_folding/addition.reference.ast: -------------------------------------------------------------------------------- 1 | 2 | { 3 | function 4 | { 5 | type{"float"}, 6 | ID{"add_0_r"}, 7 | argument_list 8 | { 9 | argument 10 | { 11 | type{"float"}, 12 | ID{"a"} 13 | }, 14 | argument 15 | { 16 | type{"float"}, 17 | ID{"b"} 18 | } 19 | }, 20 | function_body 21 | { 22 | return 23 | { 24 | + 25 | { 26 | variable{"a"}, 27 | variable{"b"} 28 | } 29 | } 30 | } 31 | }, 32 | function 33 | { 34 | type{"float"}, 35 | ID{"add_0_l"}, 36 | argument_list 37 | { 38 | argument 39 | { 40 | type{"float"}, 41 | ID{"a"} 42 | }, 43 | argument 44 | { 45 | type{"float"}, 46 | ID{"b"} 47 | } 48 | }, 49 | function_body 50 | { 51 | return 52 | { 53 | + 54 | { 55 | variable{"a"}, 56 | variable{"b"} 57 | } 58 | } 59 | } 60 | }, 61 | function 62 | { 63 | type{"float"}, 64 | ID{"add_0_m"}, 65 | argument_list 66 | { 67 | argument 68 | { 69 | type{"float"}, 70 | ID{"a"} 71 | }, 72 | argument 73 | { 74 | type{"float"}, 75 | ID{"b"} 76 | } 77 | }, 78 | function_body 79 | { 80 | return 81 | { 82 | + 83 | { 84 | variable{"a"}, 85 | variable{"b"} 86 | } 87 | } 88 | } 89 | } 90 | } -------------------------------------------------------------------------------- /src/host/lua-5.3.0/src/ltm.h: -------------------------------------------------------------------------------- 1 | /* 2 | ** $Id: ltm.h,v 2.21 2014/10/25 11:50:46 roberto Exp $ 3 | ** Tag methods 4 | ** See Copyright Notice in lua.h 5 | */ 6 | 7 | #ifndef ltm_h 8 | #define ltm_h 9 | 10 | 11 | #include "lobject.h" 12 | 13 | 14 | /* 15 | * WARNING: if you change the order of this enumeration, 16 | * grep "ORDER TM" and "ORDER OP" 17 | */ 18 | typedef enum { 19 | TM_INDEX, 20 | TM_NEWINDEX, 21 | TM_GC, 22 | TM_MODE, 23 | TM_LEN, 24 | TM_EQ, /* last tag method with fast access */ 25 | TM_ADD, 26 | TM_SUB, 27 | TM_MUL, 28 | TM_MOD, 29 | TM_POW, 30 | TM_DIV, 31 | TM_IDIV, 32 | TM_BAND, 33 | TM_BOR, 34 | TM_BXOR, 35 | TM_SHL, 36 | TM_SHR, 37 | TM_UNM, 38 | TM_BNOT, 39 | TM_LT, 40 | TM_LE, 41 | TM_CONCAT, 42 | TM_CALL, 43 | TM_N /* number of elements in the enum */ 44 | } TMS; 45 | 46 | 47 | 48 | #define gfasttm(g,et,e) ((et) == NULL ? NULL : \ 49 | ((et)->flags & (1u<<(e))) ? NULL : luaT_gettm(et, e, (g)->tmname[e])) 50 | 51 | #define fasttm(l,et,e) gfasttm(G(l), et, e) 52 | 53 | #define ttypename(x) luaT_typenames_[(x) + 1] 54 | #define objtypename(x) ttypename(ttnov(x)) 55 | 56 | LUAI_DDEC const char *const luaT_typenames_[LUA_TOTALTAGS]; 57 | 58 | 59 | LUAI_FUNC const TValue *luaT_gettm (Table *events, TMS event, TString *ename); 60 | LUAI_FUNC const TValue *luaT_gettmbyobj (lua_State *L, const TValue *o, 61 | TMS event); 62 | LUAI_FUNC void luaT_init (lua_State *L); 63 | 64 | LUAI_FUNC void luaT_callTM (lua_State *L, const TValue *f, const TValue *p1, 65 | const TValue *p2, TValue *p3, int hasres); 66 | LUAI_FUNC int luaT_callbinTM (lua_State *L, const TValue *p1, const TValue *p2, 67 | StkId res, TMS event); 68 | LUAI_FUNC void luaT_trybinTM (lua_State *L, const TValue *p1, const TValue *p2, 69 | StkId res, TMS event); 70 | LUAI_FUNC int luaT_callorderTM (lua_State *L, const TValue *p1, 71 | const TValue *p2, TMS event); 72 | 73 | 74 | 75 | #endif 76 | -------------------------------------------------------------------------------- /test/parser/textures.reference.ast: -------------------------------------------------------------------------------- 1 | 2 | { 3 | texture_declaration 4 | { 5 | type{"Texture"}, 6 | "SourceTexture1" 7 | }, 8 | texture_declaration 9 | { 10 | type{"Texture1D"}, 11 | "SourceTexture2" 12 | }, 13 | texture_declaration 14 | { 15 | type{"Texture1DArray"}, 16 | "SourceTexture3" 17 | }, 18 | texture_declaration 19 | { 20 | type{"Texture2D"}, 21 | "SourceTexture4" 22 | }, 23 | texture_declaration 24 | { 25 | type{"Texture2DArray"}, 26 | "SourceTexture5" 27 | }, 28 | texture_declaration 29 | { 30 | type{"Texture3D"}, 31 | "SourceTexture6" 32 | }, 33 | texture_declaration 34 | { 35 | type{"TextureCube"}, 36 | "SourceTexture7" 37 | }, 38 | texture_declaration 39 | { 40 | type{"texture"}, 41 | "SourceTexture1" 42 | }, 43 | texture_declaration 44 | { 45 | type{"texture1D"}, 46 | "SourceTexture2" 47 | }, 48 | texture_declaration 49 | { 50 | type{"texture1DArray"}, 51 | "SourceTexture3" 52 | }, 53 | texture_declaration 54 | { 55 | type{"texture2D"}, 56 | "SourceTexture4" 57 | }, 58 | texture_declaration 59 | { 60 | type{"texture2DArray"}, 61 | "SourceTexture5" 62 | }, 63 | texture_declaration 64 | { 65 | type{"texture3D"}, 66 | "SourceTexture6" 67 | }, 68 | texture_declaration 69 | { 70 | type{"textureCube"}, 71 | "SourceTexture7" 72 | }, 73 | sampler_declaration 74 | { 75 | type{"sampler2D"}, 76 | "SourceTextureSampler", 77 | texture{"SourceTexture1"}, 78 | parameter 79 | { 80 | "MinFilter", 81 | "LINEAR" 82 | }, 83 | parameter 84 | { 85 | "MagFilter", 86 | "LINEAR" 87 | }, 88 | parameter 89 | { 90 | "MipFilter", 91 | "LINEAR" 92 | } 93 | } 94 | } -------------------------------------------------------------------------------- /src/host/lua-5.3.0/src/lvm.h: -------------------------------------------------------------------------------- 1 | /* 2 | ** $Id: lvm.h,v 2.34 2014/08/01 17:24:02 roberto Exp $ 3 | ** Lua virtual machine 4 | ** See Copyright Notice in lua.h 5 | */ 6 | 7 | #ifndef lvm_h 8 | #define lvm_h 9 | 10 | 11 | #include "ldo.h" 12 | #include "lobject.h" 13 | #include "ltm.h" 14 | 15 | 16 | #if !defined(LUA_NOCVTN2S) 17 | #define cvt2str(o) ttisnumber(o) 18 | #else 19 | #define cvt2str(o) 0 /* no conversion from numbers to strings */ 20 | #endif 21 | 22 | 23 | #if !defined(LUA_NOCVTS2N) 24 | #define cvt2num(o) ttisstring(o) 25 | #else 26 | #define cvt2num(o) 0 /* no conversion from strings to numbers */ 27 | #endif 28 | 29 | 30 | #define tonumber(o,n) \ 31 | (ttisfloat(o) ? (*(n) = fltvalue(o), 1) : luaV_tonumber_(o,n)) 32 | 33 | #define tointeger(o,i) \ 34 | (ttisinteger(o) ? (*(i) = ivalue(o), 1) : luaV_tointeger_(o,i)) 35 | 36 | #define intop(op,v1,v2) l_castU2S(l_castS2U(v1) op l_castS2U(v2)) 37 | 38 | #define luaV_rawequalobj(t1,t2) luaV_equalobj(NULL,t1,t2) 39 | 40 | 41 | LUAI_FUNC int luaV_equalobj (lua_State *L, const TValue *t1, const TValue *t2); 42 | LUAI_FUNC int luaV_lessthan (lua_State *L, const TValue *l, const TValue *r); 43 | LUAI_FUNC int luaV_lessequal (lua_State *L, const TValue *l, const TValue *r); 44 | LUAI_FUNC int luaV_tonumber_ (const TValue *obj, lua_Number *n); 45 | LUAI_FUNC int luaV_tointeger_ (const TValue *obj, lua_Integer *p); 46 | LUAI_FUNC void luaV_gettable (lua_State *L, const TValue *t, TValue *key, 47 | StkId val); 48 | LUAI_FUNC void luaV_settable (lua_State *L, const TValue *t, TValue *key, 49 | StkId val); 50 | LUAI_FUNC void luaV_finishOp (lua_State *L); 51 | LUAI_FUNC void luaV_execute (lua_State *L); 52 | LUAI_FUNC void luaV_concat (lua_State *L, int total); 53 | LUAI_FUNC lua_Integer luaV_div (lua_State *L, lua_Integer x, lua_Integer y); 54 | LUAI_FUNC lua_Integer luaV_mod (lua_State *L, lua_Integer x, lua_Integer y); 55 | LUAI_FUNC lua_Integer luaV_shiftl (lua_Integer x, lua_Integer y); 56 | LUAI_FUNC void luaV_objlen (lua_State *L, StkId ra, const TValue *rb); 57 | 58 | #endif 59 | -------------------------------------------------------------------------------- /src/hlsl_parser/HLSLParserListener.cpp: -------------------------------------------------------------------------------- 1 | #include "HLSLParserListener.h" 2 | #include "HLSLParser.hpp" 3 | 4 | 5 | HLSLParserListener::HLSLParserListener( lua_State * state ) : State( state ) 6 | { 7 | 8 | } 9 | 10 | void HLSLParserListener::PushNode() 11 | { 12 | lua_checkstack( State, 1 ); 13 | lua_newtable( State ); 14 | } 15 | 16 | void HLSLParserListener::PushNode( const char * name ) 17 | { 18 | lua_checkstack( State, 3 ); 19 | lua_newtable( State ); 20 | lua_pushstring( State, "name" ); 21 | lua_pushstring( State, name ); 22 | lua_rawset( State, -3 ); 23 | } 24 | 25 | void HLSLParserListener::AddValue( const std::string & value ) 26 | { 27 | int 28 | index; 29 | 30 | lua_checkstack( State, 3 ); 31 | 32 | assert( lua_istable( State, -1 ) ); 33 | 34 | #if LUA_VERSION_NUM >= 502 35 | lua_len( State, -1 ); 36 | index = lua_tointeger( State, -1 ); 37 | lua_pop( State, 1 ); 38 | #else 39 | index = lua_objlen( State, -1 ); 40 | #endif 41 | 42 | lua_pushstring( State, value.c_str() ); 43 | lua_rawseti( State, -2, index + 1 ); 44 | } 45 | 46 | void HLSLParserListener::SetKeyValue( const std::string & key, const std::string & value ) 47 | { 48 | lua_checkstack( State, 3 ); 49 | 50 | assert( lua_istable( State, -1 ) ); 51 | lua_pushstring( State, key.c_str() ); 52 | lua_pushstring( State, value.c_str() ); 53 | lua_rawset( State, -3 ); 54 | } 55 | 56 | void HLSLParserListener::Assign() 57 | { 58 | int 59 | index; 60 | 61 | lua_checkstack( State, 3 ); 62 | 63 | assert( lua_istable( State, -2) ); 64 | 65 | #if LUA_VERSION_NUM >= 502 66 | lua_len( State, -2 ); 67 | index = lua_tointeger( State, -1 ); 68 | lua_pop( State, 1 ); 69 | #else 70 | index = lua_objlen( State, -2 ); 71 | #endif 72 | 73 | lua_rawseti( State, -2, index + 1 ); 74 | } 75 | 76 | void HLSLParserListener::PopNode() 77 | { 78 | lua_pop( State, 1 ); 79 | } 80 | 81 | void HLSLParserListener::SwapTopNodes() 82 | { 83 | lua_pushvalue(State, -2 ); 84 | lua_remove(State, -3 ); 85 | } -------------------------------------------------------------------------------- /contrib/antlr3filestream.inl: -------------------------------------------------------------------------------- 1 | ANTLR_BEGIN_NAMESPACE() 2 | 3 | template 4 | ANTLR_FDSC FileUtils::AntlrFopen(const ANTLR_UINT8* filename, const char * mode) 5 | { 6 | return (ANTLR_FDSC)fopen((const char *)filename, mode); 7 | } 8 | 9 | template 10 | void FileUtils::AntlrFclose (ANTLR_FDSC fd) 11 | { 12 | fclose(fd); 13 | } 14 | 15 | template 16 | ANTLR_UINT32 FileUtils::AntlrFsize(const ANTLR_UINT8* filename) 17 | { 18 | struct _stat statbuf; 19 | 20 | _stat((const char *)filename, &statbuf); 21 | 22 | return (ANTLR_UINT32)statbuf.st_size; 23 | } 24 | 25 | template 26 | ANTLR_UINT32 FileUtils::AntlrFread(ANTLR_FDSC fdsc, ANTLR_UINT32 count, void* data) 27 | { 28 | return (ANTLR_UINT32)fread(data, (size_t)count, 1, fdsc); 29 | } 30 | 31 | template 32 | template 33 | ANTLR_UINT32 FileUtils::AntlrRead8Bit(InputStreamType* input, const ANTLR_UINT8* fileName) 34 | { 35 | ANTLR_FDSC infile; 36 | ANTLR_UINT32 fSize; 37 | 38 | /* Open the OS file in read binary mode 39 | */ 40 | infile = FileUtils::AntlrFopen(fileName, "rb"); 41 | 42 | /* Check that it was there 43 | */ 44 | // if (infile == NULL) 45 | // { 46 | // ParseFileAbsentException ex; 47 | // throw ex; 48 | // } 49 | 50 | /* It was there, so we can read the bytes now 51 | */ 52 | fSize = FileUtils::AntlrFsize(fileName); /* Size of input file */ 53 | 54 | /* Allocate buffer for this input set 55 | */ 56 | void* data = ImplTraits::AllocPolicyType::alloc(fSize); 57 | /* Now we read the file. Characters are not converted to 58 | * the internal ANTLR encoding until they are read from the buffer 59 | */ 60 | FileUtils::AntlrFread(infile, fSize, data ); 61 | 62 | input->set_data( (unsigned char*) data ); 63 | input->set_sizeBuf( fSize ); 64 | 65 | input->set_isAllocated(true); 66 | 67 | /* And close the file handle 68 | */ 69 | FileUtils::AntlrFclose(infile); 70 | 71 | return ANTLR_SUCCESS; 72 | } 73 | 74 | ANTLR_END_NAMESPACE() 75 | -------------------------------------------------------------------------------- /src/host/lua-5.3.0/doc/lua.css: -------------------------------------------------------------------------------- 1 | html { 2 | background-color: #F8F8F8 ; 3 | } 4 | 5 | body { 6 | border: solid #a0a0a0 1px ; 7 | border-radius: 20px ; 8 | padding: 26px ; 9 | margin: 16px ; 10 | color: #000000 ; 11 | background-color: #FFFFFF ; 12 | font-family: Helvetica, Arial, sans-serif ; 13 | text-align: justify ; 14 | } 15 | 16 | h1, h2, h3, h4 { 17 | font-family: Verdana, Geneva, sans-serif ; 18 | font-weight: normal ; 19 | font-style: normal ; 20 | } 21 | 22 | h2 { 23 | padding-top: 0.4em ; 24 | padding-bottom: 0.4em ; 25 | padding-left: 0.8em ; 26 | padding-right: 0.8em ; 27 | background-color: #D0D0FF ; 28 | border-radius: 8px ; 29 | border: solid #a0a0a0 1px ; 30 | } 31 | 32 | h3 { 33 | padding-left: 0.5em ; 34 | border-left: solid #D0D0FF 1em ; 35 | } 36 | 37 | table h3 { 38 | padding-left: 0px ; 39 | border-left: none ; 40 | } 41 | 42 | a:link { 43 | color: #000080 ; 44 | background-color: inherit ; 45 | text-decoration: none ; 46 | } 47 | 48 | a:visited { 49 | background-color: inherit ; 50 | text-decoration: none ; 51 | } 52 | 53 | a:link:hover, a:visited:hover { 54 | color: #000080 ; 55 | background-color: #D0D0FF ; 56 | border-radius: 4px; 57 | } 58 | 59 | a:link:active, a:visited:active { 60 | color: #FF0000 ; 61 | } 62 | 63 | h1 a img { 64 | vertical-align: text-bottom ; 65 | } 66 | 67 | hr { 68 | border: 0 ; 69 | height: 1px ; 70 | color: #a0a0a0 ; 71 | background-color: #a0a0a0 ; 72 | display: none ; 73 | } 74 | 75 | table hr { 76 | display: block ; 77 | } 78 | 79 | :target { 80 | background-color: #F8F8F8 ; 81 | padding: 8px ; 82 | border: solid #a0a0a0 2px ; 83 | border-radius: 8px ; 84 | } 85 | 86 | .footer { 87 | color: gray ; 88 | font-size: x-small ; 89 | } 90 | 91 | input[type=text] { 92 | border: solid #a0a0a0 2px ; 93 | border-radius: 2em ; 94 | background-image: url('images/search.png') ; 95 | background-repeat: no-repeat ; 96 | background-position: 4px center ; 97 | padding-left: 20px ; 98 | height: 2em ; 99 | } 100 | 101 | pre.session { 102 | background-color: #F8F8F8 ; 103 | padding: 1em ; 104 | border-radius: 8px ; 105 | } 106 | -------------------------------------------------------------------------------- /test/optim/constants_replacement.reference.ast: -------------------------------------------------------------------------------- 1 | 2 | { 3 | function 4 | { 5 | type{"bool"}, 6 | ID{"test"}, 7 | argument_list 8 | { 9 | argument 10 | { 11 | type{"float"}, 12 | ID{"a"} 13 | }, 14 | argument 15 | { 16 | type{"float"}, 17 | ID{"x"} 18 | } 19 | }, 20 | function_body 21 | { 22 | nop{}, 23 | block 24 | { 25 | variable_declaration 26 | { 27 | storage{}, 28 | modifier{}, 29 | type{"int"}, 30 | variable 31 | { 32 | "i", 33 | literal{"9"} 34 | } 35 | } 36 | }, 37 | block 38 | { 39 | variable_declaration 40 | { 41 | storage{}, 42 | modifier{}, 43 | type{"int"}, 44 | variable 45 | { 46 | "i", 47 | literal{"1"} 48 | } 49 | } 50 | }, 51 | block 52 | { 53 | variable_declaration 54 | { 55 | storage{}, 56 | modifier{}, 57 | type{"int"}, 58 | variable 59 | { 60 | "i", 61 | literal{"3"} 62 | } 63 | } 64 | }, 65 | block 66 | { 67 | variable_declaration 68 | { 69 | storage{}, 70 | modifier{}, 71 | type{"int"}, 72 | variable 73 | { 74 | "i", 75 | literal{"6"} 76 | } 77 | } 78 | }, 79 | return{literal{"true"}} 80 | } 81 | } 82 | } -------------------------------------------------------------------------------- /test/parser/while_statement.reference.ast: -------------------------------------------------------------------------------- 1 | 2 | { 3 | function 4 | { 5 | type{"int"}, 6 | ID{"test"}, 7 | argument_list 8 | { 9 | argument 10 | { 11 | type{"float"}, 12 | ID{"a"} 13 | }, 14 | argument 15 | { 16 | type{"bool"}, 17 | ID{"b"} 18 | }, 19 | argument 20 | { 21 | type{"int"}, 22 | ID{"c"} 23 | } 24 | }, 25 | function_body 26 | { 27 | variable_declaration 28 | { 29 | storage{}, 30 | modifier{}, 31 | type{"int"}, 32 | variable{"index"} 33 | }, 34 | variable_declaration 35 | { 36 | storage{}, 37 | modifier{}, 38 | type{"bool"}, 39 | variable{"result"} 40 | }, 41 | do_while 42 | { 43 | block 44 | { 45 | -=_statement 46 | { 47 | variable{"a"}, 48 | float_literal{"1.0"} 49 | }, 50 | =_statement 51 | { 52 | variable{"result"}, 53 | < 54 | { 55 | variable{"a"}, 56 | float_literal{"0.0"} 57 | } 58 | } 59 | }, 60 | variable{"result"} 61 | }, 62 | while 63 | { 64 | < 65 | { 66 | variable{"index"}, 67 | variable{"c"} 68 | }, 69 | block 70 | { 71 | pre_modify_statement 72 | { 73 | "++", 74 | variable{"index"} 75 | } 76 | } 77 | }, 78 | return{int_literal{"0"}} 79 | } 80 | } 81 | } -------------------------------------------------------------------------------- /contrib/antlr3errors.hpp: -------------------------------------------------------------------------------- 1 | #ifndef _ANTLR3ERRORS_HPP 2 | #define _ANTLR3ERRORS_HPP 3 | 4 | // [The "BSD licence"] 5 | // Copyright (c) 2005-2009 Gokulakannan Somasundaram, ElectronDB 6 | 7 | // 8 | // All rights reserved. 9 | // 10 | // Redistribution and use in source and binary forms, with or without 11 | // modification, are permitted provided that the following conditions 12 | // are met: 13 | // 1. Redistributions of source code must retain the above copyright 14 | // notice, this list of conditions and the following disclaimer. 15 | // 2. Redistributions in binary form must reproduce the above copyright 16 | // notice, this list of conditions and the following disclaimer in the 17 | // documentation and/or other materials provided with the distribution. 18 | // 3. The name of the author may not be used to endorse or promote products 19 | // derived from this software without specific prior written permission. 20 | // 21 | // THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR 22 | // IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES 23 | // OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. 24 | // IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, 25 | // INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT 26 | // NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 27 | // DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 28 | // THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 29 | // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF 30 | // THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 31 | 32 | #define ANTLR_SUCCESS 0 33 | #define ANTLR_FAIL 1 34 | 35 | /** Indicates end of character stream and is an invalid Unicode code point. */ 36 | #define ANTLR_CHARSTREAM_EOF 0xFFFFFFFF 37 | 38 | /** Indicates memoizing on a rule failed. 39 | */ 40 | #define MEMO_RULE_FAILED 0xFFFFFFFE 41 | #define MEMO_RULE_UNKNOWN 0xFFFFFFFF 42 | 43 | 44 | #define ANTLR_ERR_BASE 0 45 | #define ANTLR_ERR_NOMEM (ANTLR_ERR_BASE + 1) 46 | #define ANTLR_ERR_NOFILE (ANTLR_ERR_BASE + 2) 47 | #define ANTLR_ERR_HASHDUP (ANTLR_ERR_BASE + 3) 48 | 49 | #endif /* _ANTLR3ERRORS_H */ 50 | -------------------------------------------------------------------------------- /src/host/lua-5.3.0/src/lctype.h: -------------------------------------------------------------------------------- 1 | /* 2 | ** $Id: lctype.h,v 1.12 2011/07/15 12:50:29 roberto Exp $ 3 | ** 'ctype' functions for Lua 4 | ** See Copyright Notice in lua.h 5 | */ 6 | 7 | #ifndef lctype_h 8 | #define lctype_h 9 | 10 | #include "lua.h" 11 | 12 | 13 | /* 14 | ** WARNING: the functions defined here do not necessarily correspond 15 | ** to the similar functions in the standard C ctype.h. They are 16 | ** optimized for the specific needs of Lua 17 | */ 18 | 19 | #if !defined(LUA_USE_CTYPE) 20 | 21 | #if 'A' == 65 && '0' == 48 22 | /* ASCII case: can use its own tables; faster and fixed */ 23 | #define LUA_USE_CTYPE 0 24 | #else 25 | /* must use standard C ctype */ 26 | #define LUA_USE_CTYPE 1 27 | #endif 28 | 29 | #endif 30 | 31 | 32 | #if !LUA_USE_CTYPE /* { */ 33 | 34 | #include 35 | 36 | #include "llimits.h" 37 | 38 | 39 | #define ALPHABIT 0 40 | #define DIGITBIT 1 41 | #define PRINTBIT 2 42 | #define SPACEBIT 3 43 | #define XDIGITBIT 4 44 | 45 | 46 | #define MASK(B) (1 << (B)) 47 | 48 | 49 | /* 50 | ** add 1 to char to allow index -1 (EOZ) 51 | */ 52 | #define testprop(c,p) (luai_ctype_[(c)+1] & (p)) 53 | 54 | /* 55 | ** 'lalpha' (Lua alphabetic) and 'lalnum' (Lua alphanumeric) both include '_' 56 | */ 57 | #define lislalpha(c) testprop(c, MASK(ALPHABIT)) 58 | #define lislalnum(c) testprop(c, (MASK(ALPHABIT) | MASK(DIGITBIT))) 59 | #define lisdigit(c) testprop(c, MASK(DIGITBIT)) 60 | #define lisspace(c) testprop(c, MASK(SPACEBIT)) 61 | #define lisprint(c) testprop(c, MASK(PRINTBIT)) 62 | #define lisxdigit(c) testprop(c, MASK(XDIGITBIT)) 63 | 64 | /* 65 | ** this 'ltolower' only works for alphabetic characters 66 | */ 67 | #define ltolower(c) ((c) | ('A' ^ 'a')) 68 | 69 | 70 | /* two more entries for 0 and -1 (EOZ) */ 71 | LUAI_DDEC const lu_byte luai_ctype_[UCHAR_MAX + 2]; 72 | 73 | 74 | #else /* }{ */ 75 | 76 | /* 77 | ** use standard C ctypes 78 | */ 79 | 80 | #include 81 | 82 | 83 | #define lislalpha(c) (isalpha(c) || (c) == '_') 84 | #define lislalnum(c) (isalnum(c) || (c) == '_') 85 | #define lisdigit(c) (isdigit(c)) 86 | #define lisspace(c) (isspace(c)) 87 | #define lisprint(c) (isprint(c)) 88 | #define lisxdigit(c) (isxdigit(c)) 89 | 90 | #define ltolower(c) (tolower(c)) 91 | 92 | #endif /* } */ 93 | 94 | #endif 95 | 96 | -------------------------------------------------------------------------------- /src/host/lua-5.3.0/src/lctype.c: -------------------------------------------------------------------------------- 1 | /* 2 | ** $Id: lctype.c,v 1.12 2014/11/02 19:19:04 roberto Exp $ 3 | ** 'ctype' functions for Lua 4 | ** See Copyright Notice in lua.h 5 | */ 6 | 7 | #define lctype_c 8 | #define LUA_CORE 9 | 10 | #include "lprefix.h" 11 | 12 | 13 | #include "lctype.h" 14 | 15 | #if !LUA_USE_CTYPE /* { */ 16 | 17 | #include 18 | 19 | LUAI_DDEF const lu_byte luai_ctype_[UCHAR_MAX + 2] = { 20 | 0x00, /* EOZ */ 21 | 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0. */ 22 | 0x00, 0x08, 0x08, 0x08, 0x08, 0x08, 0x00, 0x00, 23 | 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 1. */ 24 | 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 25 | 0x0c, 0x04, 0x04, 0x04, 0x04, 0x04, 0x04, 0x04, /* 2. */ 26 | 0x04, 0x04, 0x04, 0x04, 0x04, 0x04, 0x04, 0x04, 27 | 0x16, 0x16, 0x16, 0x16, 0x16, 0x16, 0x16, 0x16, /* 3. */ 28 | 0x16, 0x16, 0x04, 0x04, 0x04, 0x04, 0x04, 0x04, 29 | 0x04, 0x15, 0x15, 0x15, 0x15, 0x15, 0x15, 0x05, /* 4. */ 30 | 0x05, 0x05, 0x05, 0x05, 0x05, 0x05, 0x05, 0x05, 31 | 0x05, 0x05, 0x05, 0x05, 0x05, 0x05, 0x05, 0x05, /* 5. */ 32 | 0x05, 0x05, 0x05, 0x04, 0x04, 0x04, 0x04, 0x05, 33 | 0x04, 0x15, 0x15, 0x15, 0x15, 0x15, 0x15, 0x05, /* 6. */ 34 | 0x05, 0x05, 0x05, 0x05, 0x05, 0x05, 0x05, 0x05, 35 | 0x05, 0x05, 0x05, 0x05, 0x05, 0x05, 0x05, 0x05, /* 7. */ 36 | 0x05, 0x05, 0x05, 0x04, 0x04, 0x04, 0x04, 0x00, 37 | 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 8. */ 38 | 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 39 | 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 9. */ 40 | 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 41 | 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* a. */ 42 | 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 43 | 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* b. */ 44 | 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 45 | 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* c. */ 46 | 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 47 | 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* d. */ 48 | 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 49 | 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* e. */ 50 | 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 51 | 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* f. */ 52 | 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 53 | }; 54 | 55 | #endif /* } */ 56 | -------------------------------------------------------------------------------- /test/parser/float4_constructor_assignment.reference.ast: -------------------------------------------------------------------------------- 1 | 2 | { 3 | struct_definition 4 | { 5 | "VS_TEXTURED_INPUT", 6 | field 7 | { 8 | type{"float2"}, 9 | ID{"Position"}, 10 | semantic{"POSITION"} 11 | }, 12 | field 13 | { 14 | type{"float2"}, 15 | ID{"TextureCoordinate"}, 16 | semantic{"TEXCOORD0"} 17 | } 18 | }, 19 | struct_definition 20 | { 21 | "VS_TEXTURED_OUTPUT", 22 | field 23 | { 24 | type{"float4"}, 25 | ID{"Position"}, 26 | semantic{"POSITION"} 27 | }, 28 | field 29 | { 30 | type{"float2"}, 31 | ID{"TextureCoordinate"}, 32 | semantic{"TEXCOORD0"} 33 | } 34 | }, 35 | function 36 | { 37 | type{"VS_TEXTURED_OUTPUT"}, 38 | ID{"vs"}, 39 | argument_list 40 | { 41 | argument 42 | { 43 | type{"VS_TEXTURED_INPUT"}, 44 | ID{"input"} 45 | } 46 | }, 47 | function_body 48 | { 49 | variable_declaration 50 | { 51 | storage{}, 52 | modifier{}, 53 | type{"VS_TEXTURED_OUTPUT"}, 54 | variable{"output"} 55 | }, 56 | =_statement 57 | { 58 | postfix 59 | { 60 | variable{"output"}, 61 | variable{"Position"} 62 | }, 63 | constructor 64 | { 65 | type{"float4"}, 66 | argument_expression_list 67 | { 68 | postfix 69 | { 70 | variable{"input"}, 71 | variable{"Position"} 72 | }, 73 | int_literal{"0"}, 74 | int_literal{"1"} 75 | } 76 | } 77 | }, 78 | =_statement 79 | { 80 | postfix 81 | { 82 | variable{"output"}, 83 | variable{"TextureCoordinate"} 84 | }, 85 | postfix 86 | { 87 | variable{"input"}, 88 | variable{"TextureCoordinate"} 89 | } 90 | }, 91 | return{variable{"output"}} 92 | } 93 | } 94 | } -------------------------------------------------------------------------------- /contrib/antlr3.hpp: -------------------------------------------------------------------------------- 1 | #ifndef _ANTLR3_HPP 2 | #define _ANTLR3_HPP 3 | 4 | // [The "BSD licence"] 5 | // Copyright (c) 2005-2009 Gokulakannan Somasundaram, ElectronDB 6 | // 7 | // All rights reserved. 8 | // 9 | // Redistribution and use in source and binary forms, with or without 10 | // modification, are permitted provided that the following conditions 11 | // are met: 12 | // 1. Redistributions of source code must retain the above copyright 13 | // notice, this list of conditions and the following disclaimer. 14 | // 2. Redistributions in binary form must reproduce the above copyright 15 | // notice, this list of conditions and the following disclaimer in the 16 | // documentation and/or other materials provided with the distribution. 17 | // 3. The name of the author may not be used to endorse or promote products 18 | // derived from this software without specific prior written permission. 19 | // 20 | // THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR 21 | // IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES 22 | // OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. 23 | // IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, 24 | // INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT 25 | // NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 26 | // DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 27 | // THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 28 | // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF 29 | // THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 30 | 31 | #include 32 | #include 33 | 34 | #include "antlr3defs.hpp" 35 | 36 | #include "antlr3errors.hpp" 37 | #include "antlr3memory.hpp" 38 | 39 | #include "antlr3recognizersharedstate.hpp" 40 | #include "antlr3baserecognizer.hpp" 41 | #include "antlr3bitset.hpp" 42 | #include "antlr3collections.hpp" 43 | #include "antlr3commontoken.hpp" 44 | #include "antlr3commontree.hpp" 45 | #include "antlr3commontreeadaptor.hpp" 46 | #include "antlr3cyclicdfa.hpp" 47 | #include "antlr3debugeventlistener.hpp" 48 | #include "antlr3exception.hpp" 49 | #include "antlr3filestream.hpp" 50 | #include "antlr3intstream.hpp" 51 | #include "antlr3input.hpp" 52 | #include "antlr3tokenstream.hpp" 53 | #include "antlr3commontreenodestream.hpp" 54 | #include "antlr3lexer.hpp" 55 | #include "antlr3parser.hpp" 56 | #include "antlr3rewritestreams.hpp" 57 | #include "antlr3traits.hpp" 58 | #include "antlr3treeparser.hpp" 59 | 60 | #endif 61 | -------------------------------------------------------------------------------- /src/host/lua-5.3.0/src/llex.h: -------------------------------------------------------------------------------- 1 | /* 2 | ** $Id: llex.h,v 1.78 2014/10/29 15:38:24 roberto Exp $ 3 | ** Lexical Analyzer 4 | ** See Copyright Notice in lua.h 5 | */ 6 | 7 | #ifndef llex_h 8 | #define llex_h 9 | 10 | #include "lobject.h" 11 | #include "lzio.h" 12 | 13 | 14 | #define FIRST_RESERVED 257 15 | 16 | 17 | #if !defined(LUA_ENV) 18 | #define LUA_ENV "_ENV" 19 | #endif 20 | 21 | 22 | /* 23 | * WARNING: if you change the order of this enumeration, 24 | * grep "ORDER RESERVED" 25 | */ 26 | enum RESERVED { 27 | /* terminal symbols denoted by reserved words */ 28 | TK_AND = FIRST_RESERVED, TK_BREAK, 29 | TK_DO, TK_ELSE, TK_ELSEIF, TK_END, TK_FALSE, TK_FOR, TK_FUNCTION, 30 | TK_GOTO, TK_IF, TK_IN, TK_LOCAL, TK_NIL, TK_NOT, TK_OR, TK_REPEAT, 31 | TK_RETURN, TK_THEN, TK_TRUE, TK_UNTIL, TK_WHILE, 32 | /* other terminal symbols */ 33 | TK_IDIV, TK_CONCAT, TK_DOTS, TK_EQ, TK_GE, TK_LE, TK_NE, 34 | TK_SHL, TK_SHR, 35 | TK_DBCOLON, TK_EOS, 36 | TK_FLT, TK_INT, TK_NAME, TK_STRING 37 | }; 38 | 39 | /* number of reserved words */ 40 | #define NUM_RESERVED (cast(int, TK_WHILE-FIRST_RESERVED+1)) 41 | 42 | 43 | typedef union { 44 | lua_Number r; 45 | lua_Integer i; 46 | TString *ts; 47 | } SemInfo; /* semantics information */ 48 | 49 | 50 | typedef struct Token { 51 | int token; 52 | SemInfo seminfo; 53 | } Token; 54 | 55 | 56 | /* state of the lexer plus state of the parser when shared by all 57 | functions */ 58 | typedef struct LexState { 59 | int current; /* current character (charint) */ 60 | int linenumber; /* input line counter */ 61 | int lastline; /* line of last token 'consumed' */ 62 | Token t; /* current token */ 63 | Token lookahead; /* look ahead token */ 64 | struct FuncState *fs; /* current function (parser) */ 65 | struct lua_State *L; 66 | ZIO *z; /* input stream */ 67 | Mbuffer *buff; /* buffer for tokens */ 68 | Table *h; /* to avoid collection/reuse strings */ 69 | struct Dyndata *dyd; /* dynamic structures used by the parser */ 70 | TString *source; /* current source name */ 71 | TString *envn; /* environment variable name */ 72 | char decpoint; /* locale decimal point */ 73 | } LexState; 74 | 75 | 76 | LUAI_FUNC void luaX_init (lua_State *L); 77 | LUAI_FUNC void luaX_setinput (lua_State *L, LexState *ls, ZIO *z, 78 | TString *source, int firstchar); 79 | LUAI_FUNC TString *luaX_newstring (LexState *ls, const char *str, size_t l); 80 | LUAI_FUNC void luaX_next (LexState *ls); 81 | LUAI_FUNC int luaX_lookahead (LexState *ls); 82 | LUAI_FUNC l_noret luaX_syntaxerror (LexState *ls, const char *s); 83 | LUAI_FUNC const char *luaX_token2str (LexState *ls, int token); 84 | 85 | 86 | #endif 87 | -------------------------------------------------------------------------------- /src/host/lua-5.3.0/src/lmem.h: -------------------------------------------------------------------------------- 1 | /* 2 | ** $Id: lmem.h,v 1.43 2014/12/19 17:26:14 roberto Exp $ 3 | ** Interface to Memory Manager 4 | ** See Copyright Notice in lua.h 5 | */ 6 | 7 | #ifndef lmem_h 8 | #define lmem_h 9 | 10 | 11 | #include 12 | 13 | #include "llimits.h" 14 | #include "lua.h" 15 | 16 | 17 | /* 18 | ** This macro reallocs a vector 'b' from 'on' to 'n' elements, where 19 | ** each element has size 'e'. In case of arithmetic overflow of the 20 | ** product 'n'*'e', it raises an error (calling 'luaM_toobig'). Because 21 | ** 'e' is always constant, it avoids the runtime division MAX_SIZET/(e). 22 | ** 23 | ** (The macro is somewhat complex to avoid warnings: The 'sizeof' 24 | ** comparison avoids a runtime comparison when overflow cannot occur. 25 | ** The compiler should be able to optimize the real test by itself, but 26 | ** when it does it, it may give a warning about "comparison is always 27 | ** false due to limited range of data type"; the +1 tricks the compiler, 28 | ** avoiding this warning but also this optimization.) 29 | */ 30 | #define luaM_reallocv(L,b,on,n,e) \ 31 | (((sizeof(n) >= sizeof(size_t) && cast(size_t, (n)) + 1 > MAX_SIZET/(e)) \ 32 | ? luaM_toobig(L) : cast_void(0)) , \ 33 | luaM_realloc_(L, (b), (on)*(e), (n)*(e))) 34 | 35 | /* 36 | ** Arrays of chars do not need any test 37 | */ 38 | #define luaM_reallocvchar(L,b,on,n) \ 39 | cast(char *, luaM_realloc_(L, (b), (on)*sizeof(char), (n)*sizeof(char))) 40 | 41 | #define luaM_freemem(L, b, s) luaM_realloc_(L, (b), (s), 0) 42 | #define luaM_free(L, b) luaM_realloc_(L, (b), sizeof(*(b)), 0) 43 | #define luaM_freearray(L, b, n) luaM_realloc_(L, (b), (n)*sizeof(*(b)), 0) 44 | 45 | #define luaM_malloc(L,s) luaM_realloc_(L, NULL, 0, (s)) 46 | #define luaM_new(L,t) cast(t *, luaM_malloc(L, sizeof(t))) 47 | #define luaM_newvector(L,n,t) \ 48 | cast(t *, luaM_reallocv(L, NULL, 0, n, sizeof(t))) 49 | 50 | #define luaM_newobject(L,tag,s) luaM_realloc_(L, NULL, tag, (s)) 51 | 52 | #define luaM_growvector(L,v,nelems,size,t,limit,e) \ 53 | if ((nelems)+1 > (size)) \ 54 | ((v)=cast(t *, luaM_growaux_(L,v,&(size),sizeof(t),limit,e))) 55 | 56 | #define luaM_reallocvector(L, v,oldn,n,t) \ 57 | ((v)=cast(t *, luaM_reallocv(L, v, oldn, n, sizeof(t)))) 58 | 59 | LUAI_FUNC l_noret luaM_toobig (lua_State *L); 60 | 61 | /* not to be called directly */ 62 | LUAI_FUNC void *luaM_realloc_ (lua_State *L, void *block, size_t oldsize, 63 | size_t size); 64 | LUAI_FUNC void *luaM_growaux_ (lua_State *L, void *block, int *size, 65 | size_t size_elem, int limit, 66 | const char *what); 67 | 68 | #endif 69 | 70 | -------------------------------------------------------------------------------- /src/host/lua-5.3.0/doc/lua.1: -------------------------------------------------------------------------------- 1 | .TH LUA 1 "$Date: 2014/12/10 15:55:45 $" 2 | .SH NAME 3 | lua \- Lua interpreter 4 | .SH SYNOPSIS 5 | .B lua 6 | [ 7 | .I options 8 | ] 9 | [ 10 | .I script 11 | [ 12 | .I args 13 | ] 14 | ] 15 | .SH DESCRIPTION 16 | .B lua 17 | is the standalone Lua interpreter. 18 | It loads and executes Lua programs, 19 | either in textual source form or 20 | in precompiled binary form. 21 | (Precompiled binaries are output by 22 | .BR luac , 23 | the Lua compiler.) 24 | .B lua 25 | can be used as a batch interpreter and also interactively. 26 | .LP 27 | The given 28 | .I options 29 | are handled in order and then 30 | the Lua program in file 31 | .I script 32 | is loaded and executed. 33 | The given 34 | .I args 35 | are available to 36 | .I script 37 | as strings in a global table named 38 | .BR arg . 39 | If no options or arguments are given, 40 | then 41 | .B "\-v \-i" 42 | is assumed when the standard input is a terminal; 43 | otherwise, 44 | .B "\-" 45 | is assumed. 46 | .LP 47 | In interactive mode, 48 | .B lua 49 | prompts the user, 50 | reads lines from the standard input, 51 | and executes them as they are read. 52 | If the line contains an expression or list of expressions, 53 | then the line is evaluated and the results are printed. 54 | If a line does not contain a complete statement, 55 | then a secondary prompt is displayed and 56 | lines are read until a complete statement is formed or 57 | a syntax error is found. 58 | .LP 59 | At the very start, 60 | before even handling the command line, 61 | .B lua 62 | checks the contents of the environment variables 63 | .B LUA_INIT_5_3 64 | or 65 | .BR LUA_INIT , 66 | in that order. 67 | If the contents is of the form 68 | .RI '@ filename ', 69 | then 70 | .I filename 71 | is executed. 72 | Otherwise, the string is assumed to be a Lua statement and is executed. 73 | .SH OPTIONS 74 | .TP 75 | .BI \-e " stat" 76 | execute statement 77 | .IR stat . 78 | .TP 79 | .B \-i 80 | enter interactive mode after executing 81 | .IR script . 82 | .TP 83 | .BI \-l " name" 84 | execute the equivalent of 85 | .IB name =require(' name ') 86 | before executing 87 | .IR script . 88 | .TP 89 | .B \-v 90 | show version information. 91 | .TP 92 | .B \-E 93 | ignore environment variables. 94 | .TP 95 | .B \-\- 96 | stop handling options. 97 | .TP 98 | .B \- 99 | stop handling options and execute the standard input as a file. 100 | .SH "SEE ALSO" 101 | .BR luac (1) 102 | .br 103 | The documentation at lua.org, 104 | especially section 7 of the reference manual. 105 | .SH DIAGNOSTICS 106 | Error messages should be self explanatory. 107 | .SH AUTHORS 108 | R. Ierusalimschy, 109 | L. H. de Figueiredo, 110 | W. Celes 111 | .\" EOF 112 | -------------------------------------------------------------------------------- /src/utilities/debug.lua: -------------------------------------------------------------------------------- 1 | 2 | function table.val_to_str ( v ) 3 | if "string" == type( v ) then 4 | v = string.gsub( v, "\n", "\\n" ) 5 | if string.match( string.gsub(v,"[^'\"]",""), '^"+$' ) then 6 | return "'" .. v .. "'" 7 | end 8 | return '"' .. string.gsub(v,'"', '\\"' ) .. '"' 9 | else 10 | return "table" == type( v ) and table.tostring( v ) or 11 | tostring( v ) 12 | end 13 | end 14 | 15 | function table.key_to_str ( k ) 16 | if "string" == type( k ) and string.match( k, "^[_%a][_%a%d]*$" ) then 17 | return k 18 | else 19 | return "[" .. table.val_to_str( k ) .. "]" 20 | end 21 | end 22 | 23 | function table.tostring( tbl ) 24 | local result, done = {}, {} 25 | if type(tbl) ~= "table" then error( "table expected", 2 ) end 26 | for k, v in ipairs( tbl ) do 27 | table.insert( result, table.val_to_str( v ) ) 28 | done[ k ] = true 29 | end 30 | for k, v in pairs( tbl ) do 31 | if not done[ k ] then 32 | table.insert( result, 33 | table.key_to_str( k ) .. "=" .. table.val_to_str( v ) ) 34 | end 35 | end 36 | return "{" .. table.concat( result, "," ) .. "}" 37 | end 38 | 39 | function table.val_to_str_ast( v, indentation ) 40 | if "string" == type( v ) then 41 | v = string.gsub( v, "\n", "\\n" ) 42 | if string.match( string.gsub(v,"[^'\"]",""), '^"+$' ) then 43 | return string.rep( " ", indentation ).. "'" .. v .. "'" 44 | end 45 | return string.rep( " ", indentation ).. '"' .. string.gsub(v,'"', '\\"' ) .. '"' 46 | else 47 | return "table" == type( v ) and table.tostring_ast( v, indentation ) or 48 | tostring( v ) 49 | end 50 | end 51 | 52 | function table.tostring_ast( ast, indentation ) 53 | local result, done = {}, {} 54 | indentation = indentation or 0 55 | 56 | if type(ast) ~= "table" then error( "table expected", 2 ) end 57 | for k, v in ipairs( ast ) do 58 | table.insert( result, table.val_to_str_ast( v, indentation + 1 ) ) 59 | done[ k ] = true 60 | end 61 | for k, v in pairs( ast ) do 62 | if not done[ k ] and k ~= "name" then 63 | table.insert( result, 64 | table.key_to_str( k ) .. "=" .. table.val_to_str_ast( v, indentation + 1 ) ) 65 | end 66 | end 67 | local prefix = string.rep( " ", indentation ) 68 | 69 | if #result == 0 then 70 | return prefix .. ( ast.name or "" ) .. "{}" 71 | elseif #result == 1 and string.find(result[1], '\n') == nil then 72 | return prefix .. ( ast.name or "" ) .. "{" .. string.sub(result[1], (indentation+1) 73 | * 4 + 1) .. "}" 74 | else 75 | return prefix .. ( ast.name or "" ) .. "\n" 76 | .. prefix .. "{\n" 77 | .. table.concat( result, ",\n" ) .. "\n" 78 | .. prefix .. "}" 79 | end 80 | end -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | ShaderShaker [![Build Status](https://travis-ci.org/FishingCactus/ShaderShaker.png)](https://travis-ci.org/FishingCactus/ShaderShaker) 2 | ============ 3 | 4 | Shader Shaker has bee developed to solve our two main problems with shader development : 5 | 6 | - The multiple languages our engine needs to support 7 | - The combinational number of shader with the supported rendering technique 8 | 9 | How it works 10 | ------------ 11 | 12 | The architecture is simple : 13 | 14 | 1. The HLSL files are converted to lua AST using a ANTLR parser. 15 | 2. The AST is then processed, cleaned and optimized. 16 | 3. Finally, a writer generates code. 17 | 18 | The AST conversion is done in C++, but every other process is completely done in lua. We choose lua to allow easy customization of the tool. 19 | 20 | How to build 21 | ------------ 22 | 23 | Premake is used as project generator. To build the project, follow those steps : 24 | 25 | cd src/hlsl_parser # go to HLSL parser directory 26 | ./generate_parser.sh # generate the HLSL parser (use .bat file for Windows systems) 27 | premake embed # generate a script to embed all scripts in release mode 28 | premake gmake # or any target you want to use ( vs2010, xcode4, ... ) 29 | 30 | You now have a valid project to build. 31 | 32 | How to use 33 | ---------- 34 | The tool comes in 2 forms : a binary or a dynamic library. 35 | The first can be used in asset compilation phase, while the latter can be used for runtime code generation. 36 | 37 | To use the command line tools, here are the arguments : 38 | 39 | shader_shaker [options] input_file 40 | Options can be any of these : 41 | -f language : selects language when no output file is given. Supported for now are hlsl, glsl or ast 42 | -o output_file : the output file extension is used to select the language ( .fx, .glfx, .ast) 43 | -r replacement_file : provides a file use for replacement ( see Function Replacement ) 44 | 45 | For the moment, the glfx format is specific to our engine, Mojito. It consists of an xml that contains technique definition, similar to an HLSL effect file. But a generic glsl processor will be written soon. 46 | 47 | Function Replacement 48 | -------------------- 49 | 50 | To manage the combination of shaders, this tools contains a function replacement mechanism. E.g., the same base shader will be used for all type of rendering ( forward, light prepass and deffered ). Function replacement will be used to specialize the base shader. A function called GetLightContribution() might use light parameter while it use a light buffer in other technique. Using `-r`, you can provided a file that contains replacement functions. Function signature will be used to determine which function to replace. 51 | -------------------------------------------------------------------------------- /test/parser/arithmetic.reference.ast: -------------------------------------------------------------------------------- 1 | 2 | { 3 | function 4 | { 5 | type{"float"}, 6 | ID{"test_function"}, 7 | argument_list 8 | { 9 | argument 10 | { 11 | type{"float"}, 12 | ID{"a"} 13 | }, 14 | argument 15 | { 16 | type{"int"}, 17 | ID{"b"} 18 | }, 19 | argument 20 | { 21 | type{"float"}, 22 | ID{"c"} 23 | } 24 | }, 25 | function_body 26 | { 27 | variable_declaration 28 | { 29 | storage{}, 30 | modifier{"const"}, 31 | type{"float"}, 32 | variable 33 | { 34 | "d", 35 | float_literal{"1.0"} 36 | } 37 | }, 38 | variable_declaration 39 | { 40 | storage{}, 41 | modifier{"const"}, 42 | type{"float"}, 43 | variable 44 | { 45 | "e", 46 | float_literal{"2.0"} 47 | } 48 | }, 49 | variable_declaration 50 | { 51 | storage{}, 52 | modifier{"const"}, 53 | type{"float"}, 54 | variable 55 | { 56 | "f", 57 | float_literal{"3.0"} 58 | } 59 | }, 60 | return 61 | { 62 | / 63 | { 64 | - 65 | { 66 | + 67 | { 68 | * 69 | { 70 | variable{"a"}, 71 | variable{"b"} 72 | }, 73 | variable{"c"} 74 | }, 75 | * 76 | { 77 | / 78 | { 79 | + 80 | { 81 | variable{"d"}, 82 | variable{"e"} 83 | }, 84 | variable{"f"} 85 | }, 86 | float_literal{"0.5"} 87 | } 88 | }, 89 | * 90 | { 91 | float_literal{"2.0"}, 92 | variable{"e"} 93 | } 94 | } 95 | } 96 | } 97 | } 98 | } -------------------------------------------------------------------------------- /src/process/ast_rewrite_constants.lua: -------------------------------------------------------------------------------- 1 | 2 | local function if_literal_zero( index ) 3 | return function( node ) 4 | local node_value = node[ index ][ 1 ]; 5 | 6 | return ( node[ index ].name == "int_literal" or node[ index ].name == "float_literal" ) 7 | and ( node_value == "0" or node_value == "0.0" or node_value == "0.0f" ) 8 | end 9 | end 10 | 11 | local function if_literal_one( index ) 12 | return function( node ) 13 | local node_value = node[ index ][ 1 ]; 14 | 15 | return ( node[ index ].name == "int_literal" or node[ index ].name == "float_literal" ) 16 | and ( node_value == "1" or node_value == "1.0" or node_value == "1.0f" ) 17 | end 18 | end 19 | 20 | local function if_literal_true( index ) 21 | return function( node ) 22 | local node_value = node[ index ][ 1 ]; 23 | 24 | return node[ index ].name == "bool_literal" and node_value == "true" 25 | end 26 | end 27 | 28 | local function if_literal_false( index ) 29 | return function( node ) 30 | local node_value = node[ index ][ 1 ]; 31 | 32 | return node[ index ].name == "bool_literal" and node_value == "false" 33 | end 34 | end 35 | 36 | local function replace_by_right_block( node, parent, index ) 37 | parent[ index ] = node[ 2 ] 38 | end 39 | 40 | local function replace_by_left_block( node, parent, index ) 41 | parent[ index ] = node[ 1 ] 42 | end 43 | 44 | local function replace_by_( value ) 45 | return function( node, parent, index ) 46 | parent[ index ] = { name ='literal', [1] = value } 47 | end 48 | end 49 | 50 | 51 | 52 | ast_rewrite_multiplication_rules = 53 | { 54 | {if_literal_zero( 1 ), replace_by_left_block}, 55 | {if_literal_zero( 2 ), replace_by_right_block}, 56 | {if_literal_one( 1 ), replace_by_right_block}, 57 | {if_literal_one( 2 ), replace_by_left_block} 58 | } 59 | 60 | ast_rewrite_addition_rules = 61 | { 62 | {if_literal_zero( 1 ), replace_by_right_block}, 63 | {if_literal_zero( 2 ), replace_by_left_block}, 64 | } 65 | 66 | ast_rewrite_boolean_and_rules = 67 | { 68 | {if_literal_false( 1 ), replace_by_left_block}, 69 | {if_literal_false( 2 ), replace_by_right_block}, 70 | {if_literal_true( 1 ), replace_by_right_block}, 71 | {if_literal_true( 2 ), replace_by_left_block}, 72 | } 73 | 74 | ast_rewrite_boolean_or_rules = 75 | { 76 | {if_literal_false( 1 ), replace_by_right_block}, 77 | {if_literal_false( 2 ), replace_by_left_block}, 78 | {if_literal_true( 1 ), replace_by_left_block}, 79 | {if_literal_true( 2 ), replace_by_right_block}, 80 | } 81 | 82 | ast_rewrite_unary_not_rules = 83 | { 84 | {if_literal_zero( 1 ), replace_by_( "true" ) }, 85 | {if_literal_false( 1 ), replace_by_( "true" ) }, 86 | {if_literal_one( 1 ), replace_by_( "false" ) }, 87 | {if_literal_true( 1 ), replace_by_( "false" ) } 88 | } 89 | -------------------------------------------------------------------------------- /scripts/embed.lua: -------------------------------------------------------------------------------- 1 | -- Credits goes to premake4. This code has been copied from there. 2 | -- Embed the Lua scripts into src/host/scripts.cpp as static data buffers. 3 | -- I embed the actual scripts, rather than Lua bytecodes, because the 4 | -- bytecodes are not portable to different architectures, which causes 5 | -- issues in Mac OS X Universal builds. 6 | -- 7 | 8 | local function stripfile(fname) 9 | local f = io.open(fname) 10 | local s = assert(f:read("*a")) 11 | f:close() 12 | 13 | -- strip tabs 14 | s = s:gsub("[\t]", "") 15 | 16 | -- strip any CRs 17 | s = s:gsub("[\r]", "") 18 | 19 | -- strip out block comments 20 | s = s:gsub("%-%-%[%[.-%-%-%]%]", "") 21 | 22 | -- strip out inline comments 23 | s = s:gsub("\n%-%-[^\n]*", "") 24 | 25 | -- escape backslashes 26 | s = s:gsub("\\", "\\\\") 27 | 28 | -- strip duplicate line feeds 29 | s = s:gsub("\n+", "\n") 30 | 31 | -- strip out leading comments 32 | s = s:gsub("^%-%-\n", "") 33 | 34 | -- escape line feeds 35 | s = s:gsub("\n", "\\n") 36 | 37 | -- escape double quote marks 38 | s = s:gsub("\"", "\\\"") 39 | 40 | return s 41 | end 42 | 43 | 44 | local function writeline(out, s, continues) 45 | out:write("\t\"") 46 | out:write(s) 47 | out:write(iif(continues, "\"\n", "\",\n")) 48 | end 49 | 50 | 51 | local function writefile(out, fname, contents) 52 | local max = 1024 53 | 54 | out:write("\t/* " .. fname .. " */\n") 55 | 56 | -- break up large strings to fit in Visual Studio's string length limit 57 | local start = 1 58 | local len = contents:len() 59 | while start <= len do 60 | local n = len - start 61 | if n > max then n = max end 62 | local finish = start + n 63 | 64 | -- make sure I don't cut an escape sequence 65 | while contents:sub(finish, finish) == "\\" do 66 | finish = finish - 1 67 | end 68 | 69 | writeline(out, contents:sub(start, finish), finish < len) 70 | start = finish + 1 71 | end 72 | 73 | out:write("\n") 74 | end 75 | 76 | 77 | function doembed() 78 | -- load the manifest of script files 79 | scripts = dofile("src/_manifest.lua") 80 | 81 | -- main script always goes at the end 82 | table.insert(scripts, "_shader_shaker_main.lua") 83 | 84 | -- open scripts.c and write the file header 85 | local out = io.open("src/host/scripts.cpp", "w+b") 86 | out:write("/* ShaderShaker's Lua scripts, as static data buffers for release mode builds */\n") 87 | out:write("/* DO NOT EDIT - this file is autogenerated */\n") 88 | out:write("/* To regenerate this file, run: premake4 embed */ \n\n") 89 | out:write("const char* builtin_scripts[] = {\n") 90 | 91 | for i,fn in ipairs(scripts) do 92 | print(fn) 93 | local s = stripfile("src/" .. fn) 94 | writefile(out, fn, s) 95 | end 96 | 97 | out:write("\t0\n};\n"); 98 | out:close() 99 | end 100 | -------------------------------------------------------------------------------- /contrib/antlr3filestream.hpp: -------------------------------------------------------------------------------- 1 | #ifndef _ANTLR3_FILESTREAM_HPP 2 | #define _ANTLR3_FILESTREAM_HPP 3 | 4 | // [The "BSD licence"] 5 | // Copyright (c) 2005-2009 Gokulakannan Somasundaram, ElectronDB 6 | 7 | // 8 | // All rights reserved. 9 | // 10 | // Redistribution and use in source and binary forms, with or without 11 | // modification, are permitted provided that the following conditions 12 | // are met: 13 | // 1. Redistributions of source code must retain the above copyright 14 | // notice, this list of conditions and the following disclaimer. 15 | // 2. Redistributions in binary form must reproduce the above copyright 16 | // notice, this list of conditions and the following disclaimer in the 17 | // documentation and/or other materials provided with the distribution. 18 | // 3. The name of the author may not be used to endorse or promote products 19 | // derived from this software without specific prior written permission. 20 | // 21 | // THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR 22 | // IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES 23 | // OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. 24 | // IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, 25 | // INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT 26 | // NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 27 | // DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 28 | // THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 29 | // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF 30 | // THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 31 | 32 | #include 33 | #include 34 | 35 | #include "antlr3defs.hpp" 36 | 37 | ANTLR_BEGIN_NAMESPACE() 38 | 39 | template 40 | class FileUtils 41 | { 42 | public: 43 | /** \brief Open an operating system file and return the descriptor 44 | * We just use the common open() and related functions here. 45 | * Later we might find better ways on systems 46 | * such as Windows and OpenVMS for instance. But the idea is to read the 47 | * while file at once anyway, so it may be irrelevant. 48 | */ 49 | static ANTLR_FDSC AntlrFopen(const ANTLR_UINT8* filename, const char * mode); 50 | 51 | /** \brief Close an operating system file and free any handles 52 | * etc. 53 | */ 54 | static void AntlrFclose (ANTLR_FDSC fd); 55 | 56 | static ANTLR_UINT32 AntlrFsize(const ANTLR_UINT8* filename); 57 | template 58 | static ANTLR_UINT32 AntlrRead8Bit(InputStreamType* input, const ANTLR_UINT8* fileName); 59 | static ANTLR_UINT32 AntlrFread(ANTLR_FDSC fdsc, ANTLR_UINT32 count, void* data); 60 | 61 | }; 62 | 63 | class ParseFileAbsentException : public std::exception 64 | { 65 | virtual const char* what() const throw() 66 | { 67 | return " Parse File not Present"; 68 | } 69 | }; 70 | 71 | ANTLR_END_NAMESPACE() 72 | 73 | #include "antlr3filestream.inl" 74 | 75 | #endif 76 | -------------------------------------------------------------------------------- /src/host/lua-5.3.0/src/lmem.c: -------------------------------------------------------------------------------- 1 | /* 2 | ** $Id: lmem.c,v 1.89 2014/11/02 19:33:33 roberto Exp $ 3 | ** Interface to Memory Manager 4 | ** See Copyright Notice in lua.h 5 | */ 6 | 7 | #define lmem_c 8 | #define LUA_CORE 9 | 10 | #include "lprefix.h" 11 | 12 | 13 | #include 14 | 15 | #include "lua.h" 16 | 17 | #include "ldebug.h" 18 | #include "ldo.h" 19 | #include "lgc.h" 20 | #include "lmem.h" 21 | #include "lobject.h" 22 | #include "lstate.h" 23 | 24 | 25 | 26 | /* 27 | ** About the realloc function: 28 | ** void * frealloc (void *ud, void *ptr, size_t osize, size_t nsize); 29 | ** ('osize' is the old size, 'nsize' is the new size) 30 | ** 31 | ** * frealloc(ud, NULL, x, s) creates a new block of size 's' (no 32 | ** matter 'x'). 33 | ** 34 | ** * frealloc(ud, p, x, 0) frees the block 'p' 35 | ** (in this specific case, frealloc must return NULL); 36 | ** particularly, frealloc(ud, NULL, 0, 0) does nothing 37 | ** (which is equivalent to free(NULL) in ISO C) 38 | ** 39 | ** frealloc returns NULL if it cannot create or reallocate the area 40 | ** (any reallocation to an equal or smaller size cannot fail!) 41 | */ 42 | 43 | 44 | 45 | #define MINSIZEARRAY 4 46 | 47 | 48 | void *luaM_growaux_ (lua_State *L, void *block, int *size, size_t size_elems, 49 | int limit, const char *what) { 50 | void *newblock; 51 | int newsize; 52 | if (*size >= limit/2) { /* cannot double it? */ 53 | if (*size >= limit) /* cannot grow even a little? */ 54 | luaG_runerror(L, "too many %s (limit is %d)", what, limit); 55 | newsize = limit; /* still have at least one free place */ 56 | } 57 | else { 58 | newsize = (*size)*2; 59 | if (newsize < MINSIZEARRAY) 60 | newsize = MINSIZEARRAY; /* minimum size */ 61 | } 62 | newblock = luaM_reallocv(L, block, *size, newsize, size_elems); 63 | *size = newsize; /* update only when everything else is OK */ 64 | return newblock; 65 | } 66 | 67 | 68 | l_noret luaM_toobig (lua_State *L) { 69 | luaG_runerror(L, "memory allocation error: block too big"); 70 | } 71 | 72 | 73 | 74 | /* 75 | ** generic allocation routine. 76 | */ 77 | void *luaM_realloc_ (lua_State *L, void *block, size_t osize, size_t nsize) { 78 | void *newblock; 79 | global_State *g = G(L); 80 | size_t realosize = (block) ? osize : 0; 81 | lua_assert((realosize == 0) == (block == NULL)); 82 | #if defined(HARDMEMTESTS) 83 | if (nsize > realosize && g->gcrunning) 84 | luaC_fullgc(L, 1); /* force a GC whenever possible */ 85 | #endif 86 | newblock = (*g->frealloc)(g->ud, block, osize, nsize); 87 | if (newblock == NULL && nsize > 0) { 88 | api_check( nsize > realosize, 89 | "realloc cannot fail when shrinking a block"); 90 | luaC_fullgc(L, 1); /* try to free some memory... */ 91 | newblock = (*g->frealloc)(g->ud, block, osize, nsize); /* try again */ 92 | if (newblock == NULL) 93 | luaD_throw(L, LUA_ERRMEM); 94 | } 95 | lua_assert((nsize == 0) == (newblock == NULL)); 96 | g->GCdebt = (g->GCdebt + nsize) - realosize; 97 | return newblock; 98 | } 99 | 100 | -------------------------------------------------------------------------------- /test/parser/variables.fx: -------------------------------------------------------------------------------- 1 | float 2 | scalar_float, 3 | scalar_float_with_value = 0.5f; 4 | float2 5 | vector2_float, 6 | vector2_float_with_value = { 0.5f, 1.0f }; 7 | float3 8 | vector3_float, 9 | vector3_float_with_value = { 0.0f, -1.0f, -1.0f }; 10 | float4 11 | vector4_float, 12 | vector4_float_with_value = { 0.0f, -1.0f, -1.0f, -2.5f }; 13 | float4x4 14 | matrix4_float; 15 | int 16 | scalar_int, 17 | scalar_int_with_value = 5; 18 | shared float 19 | shared_variable; 20 | const int 21 | const_variable; 22 | 23 | float4 24 | vector4_float, 25 | vector4_float_with_value = { 0.0f, -1.0f, -1.0f, -2.5f }; 26 | 27 | float 28 | casting_test = (float) some_variable; 29 | float 30 | boneWeights[4] = (float[4])input.BoneWeights; 31 | 32 | bool 33 | ItUsesDiffuseColor 34 | < 35 | string UIName = "Use diffuse color"; 36 | > = false; 37 | 38 | float4 AmbientLightColor3DSMax 39 | < 40 | string UIWidget = "Color"; 41 | string UIName = "3DSMax Global Lighting"; 42 | > = { 0.047f, 0.047f, 0.07f, 1.0f }; 43 | 44 | float4 AmbientLightColor3DSMax : COLOR0 45 | < 46 | string UIWidget = "Color"; 47 | string UIName = "3DSMax Global Lighting"; 48 | > = { 0.047f, 0.047f, 0.07f, 1.0f }; 49 | 50 | float4x4 WorldITXf : WorldInverseTranspose 51 | < 52 | string UIWidget="None"; 53 | >; 54 | 55 | float4x3 56 | BoneTable[ 64 ]; 57 | 58 | float Kr 59 | < 60 | string UIWidget = "slider"; 61 | string UIName = "Reflection Strength"; 62 | float UIMin = 0.0; 63 | float UIMax = 1.0; 64 | float UIStep = 0.01; 65 | > = 1.0; 66 | 67 | texture2D SpecularTexture : DIFFUSE 68 | < 69 | string ResourceName = "default_color.dds"; 70 | string UIName = "Specular Texture"; 71 | string ResourceType = "2D"; 72 | >; 73 | 74 | sampler2D SpecularTextureSampler = sampler_state 75 | { 76 | Texture = ; 77 | AddressU = Wrap; 78 | AddressV = Wrap; 79 | FILTER = MIN_MAG_MIP_LINEAR; 80 | }; 81 | 82 | float3 Light1Position3DSMax : POSITION 83 | < 84 | string UIName = "Light 1 position"; 85 | string Object = "PointLight"; 86 | string Space = "World"; 87 | int refID = 1; 88 | > = { 1.0, 0.0, 0.0 }; 89 | 90 | struct LightStruct 91 | { 92 | float3 LightVector; 93 | float4 LightColor; 94 | }; 95 | 96 | struct VS_INPUT 97 | { 98 | float3 Position : POSITION; 99 | int4 BoneIndices : BLENDINDICES; 100 | float4 BoneWeights : BLENDWEIGHT; 101 | float3 Normal : NORMAL; 102 | float3 Tangent : TANGENT; 103 | float3 Binormal : BINORMAL; 104 | float2 DiffuseTexCoord0 : TEXCOORD0; 105 | float2 DiffuseTexCoord1 : TEXCOORD1; 106 | float3 Color : TEXCOORD2; 107 | float3 Color : COLOR0; 108 | float3 Color : VPOS; 109 | }; -------------------------------------------------------------------------------- /src/process/function_replacer.lua: -------------------------------------------------------------------------------- 1 | FunctionReplacer = { 2 | function_name_to_ast = {} 3 | } 4 | 5 | function FunctionReplacer:new () 6 | local instance = {} 7 | setmetatable( instance, self ) 8 | self.__index = self 9 | return instance 10 | end 11 | 12 | function FunctionReplacer:Process( ast_node, replacement_file_names ) 13 | for index, name in ipairs( replacement_file_names ) do 14 | local replace_ast = GenerateAstFromFileName( name ) 15 | 16 | self.function_name_to_ast = GetFunctionNamesFromAst( replace_ast ) 17 | end 18 | 19 | local replaced_functions = self:ReplaceFunctions( ast_node ) 20 | 21 | -- Some replaced functions may need additional functions. Add them to the AST 22 | for function_name, function_ast in pairs( self.function_name_to_ast ) do 23 | if not replaced_functions[ function_name ] then 24 | table.insert( ast_node, 1, function_ast ) 25 | end 26 | end 27 | end 28 | 29 | function FunctionReplacer:ReplaceFunctions( ast_node ) 30 | local replaced_functions = {} 31 | 32 | for ast_function_node, ast_function_index in NodeOfType( ast_node, "function", false ) do 33 | local 34 | id, 35 | type 36 | local 37 | arguments = {} 38 | 39 | id = GetDataByName( ast_function_node, "ID" ) 40 | type = GetDataByName( ast_function_node, "type" ) 41 | 42 | for ast_function_argument_node in NodeOfType( ast_function_node, "argument", true ) do 43 | table.insert( arguments, GetDataByName( ast_function_argument_node, "type" ) ) 44 | -- just add more info here like the const or uniform 45 | end 46 | 47 | local replace_function_ast = self.function_name_to_ast[ id ] or nil 48 | 49 | if replace_function_ast ~= nil then 50 | local 51 | is_valid = true 52 | 53 | if id == GetDataByName( replace_function_ast, "ID" ) and type == GetDataByName( replace_function_ast, "type" ) then 54 | local 55 | replace_arguments = {} 56 | local 57 | valid_arguments = true 58 | 59 | for replace_function_argument_node in NodeOfType( replace_function_ast, "argument", true ) do 60 | table.insert( replace_arguments, GetDataByName( replace_function_argument_node, "type" ) ) 61 | -- just add more info here like the const or uniform 62 | end 63 | 64 | if #replace_arguments == #arguments then 65 | for index = 1, #arguments, 1 do 66 | if replace_arguments[ index ] ~= arguments[ index ] then 67 | is_valid = false 68 | break; 69 | end 70 | end 71 | else 72 | is_valid = false 73 | end 74 | else 75 | is_valid = false 76 | end 77 | 78 | if is_valid then 79 | ast_node[ ast_function_index ] = replace_function_ast 80 | replaced_functions[ id ] = true 81 | break; 82 | end 83 | end 84 | end 85 | 86 | return replaced_functions 87 | end -------------------------------------------------------------------------------- /test/optim/constant_folding/comparison.reference.ast: -------------------------------------------------------------------------------- 1 | 2 | { 3 | function 4 | { 5 | type{"bool"}, 6 | ID{"smaller_true"}, 7 | function_body 8 | { 9 | return 10 | { 11 | bool_literal{"true"} 12 | } 13 | } 14 | }, 15 | function 16 | { 17 | type{"bool"}, 18 | ID{"smaller_false"}, 19 | function_body 20 | { 21 | return 22 | { 23 | bool_literal{"false"} 24 | } 25 | } 26 | }, 27 | function 28 | { 29 | type{"bool"}, 30 | ID{"smaller_false2"}, 31 | function_body 32 | { 33 | return 34 | { 35 | bool_literal{"false"} 36 | } 37 | } 38 | }, 39 | function 40 | { 41 | type{"bool"}, 42 | ID{"smaller_equal_true"}, 43 | function_body 44 | { 45 | return 46 | { 47 | bool_literal{"true"} 48 | } 49 | } 50 | }, 51 | function 52 | { 53 | type{"bool"}, 54 | ID{"smaller_equal_true2"}, 55 | function_body 56 | { 57 | return 58 | { 59 | bool_literal{"true"} 60 | } 61 | } 62 | }, 63 | function 64 | { 65 | type{"bool"}, 66 | ID{"smaller_equal_false"}, 67 | function_body 68 | { 69 | return 70 | { 71 | bool_literal{"false"} 72 | } 73 | } 74 | }, 75 | function 76 | { 77 | type{"bool"}, 78 | ID{"greater_false"}, 79 | function_body 80 | { 81 | return 82 | { 83 | bool_literal{"false"} 84 | } 85 | } 86 | }, 87 | function 88 | { 89 | type{"bool"}, 90 | ID{"greater_false2"}, 91 | function_body 92 | { 93 | return 94 | { 95 | bool_literal{"false"} 96 | } 97 | } 98 | }, 99 | function 100 | { 101 | type{"bool"}, 102 | ID{"greater_true"}, 103 | function_body 104 | { 105 | return 106 | { 107 | bool_literal{"true"} 108 | } 109 | } 110 | }, 111 | function 112 | { 113 | type{"bool"}, 114 | ID{"greater_equal_false"}, 115 | function_body 116 | { 117 | return 118 | { 119 | bool_literal{"false"} 120 | } 121 | } 122 | }, 123 | function 124 | { 125 | type{"bool"}, 126 | ID{"greater_equal_true"}, 127 | function_body 128 | { 129 | return 130 | { 131 | bool_literal{"true"} 132 | } 133 | } 134 | }, 135 | function 136 | { 137 | type{"bool"}, 138 | ID{"greater_equal_true2"}, 139 | function_body 140 | { 141 | return 142 | { 143 | bool_literal{"true"} 144 | } 145 | } 146 | } 147 | } -------------------------------------------------------------------------------- /test/parser/variables.reference.ast: -------------------------------------------------------------------------------- 1 | 2 | { 3 | texture_declaration 4 | { 5 | type{"texture2D"}, 6 | "SpecularTexture", 7 | semantic{"DIFFUSE"}, 8 | annotations 9 | { 10 | entry 11 | { 12 | "string", 13 | "ResourceName", 14 | '"default_color.dds"' 15 | }, 16 | entry 17 | { 18 | "string", 19 | "UIName", 20 | '"Specular Texture"' 21 | }, 22 | entry 23 | { 24 | "string", 25 | "ResourceType", 26 | '"2D"' 27 | } 28 | } 29 | }, 30 | sampler_declaration 31 | { 32 | type{"sampler2D"}, 33 | "SpecularTextureSampler", 34 | texture{"SpecularTexture"}, 35 | parameter 36 | { 37 | "AddressU", 38 | "Wrap" 39 | }, 40 | parameter 41 | { 42 | "AddressV", 43 | "Wrap" 44 | }, 45 | parameter 46 | { 47 | "FILTER", 48 | "MIN_MAG_MIP_LINEAR" 49 | } 50 | }, 51 | struct_definition 52 | { 53 | "LightStruct", 54 | field 55 | { 56 | type{"float3"}, 57 | ID{"LightVector"} 58 | }, 59 | field 60 | { 61 | type{"float4"}, 62 | ID{"LightColor"} 63 | } 64 | }, 65 | struct_definition 66 | { 67 | "VS_INPUT", 68 | field 69 | { 70 | type{"float3"}, 71 | ID{"Position"}, 72 | semantic{"POSITION"} 73 | }, 74 | field 75 | { 76 | type{"int4"}, 77 | ID{"BoneIndices"}, 78 | semantic{"BLENDINDICES"} 79 | }, 80 | field 81 | { 82 | type{"float4"}, 83 | ID{"BoneWeights"}, 84 | semantic{"BLENDWEIGHT"} 85 | }, 86 | field 87 | { 88 | type{"float3"}, 89 | ID{"Normal"}, 90 | semantic{"NORMAL"} 91 | }, 92 | field 93 | { 94 | type{"float3"}, 95 | ID{"Tangent"}, 96 | semantic{"TANGENT"} 97 | }, 98 | field 99 | { 100 | type{"float3"}, 101 | ID{"Binormal"}, 102 | semantic{"BINORMAL"} 103 | }, 104 | field 105 | { 106 | type{"float2"}, 107 | ID{"DiffuseTexCoord0"}, 108 | semantic{"TEXCOORD0"} 109 | }, 110 | field 111 | { 112 | type{"float2"}, 113 | ID{"DiffuseTexCoord1"}, 114 | semantic{"TEXCOORD1"} 115 | }, 116 | field 117 | { 118 | type{"float3"}, 119 | ID{"Color"}, 120 | semantic{"TEXCOORD2"} 121 | }, 122 | field 123 | { 124 | type{"float3"}, 125 | ID{"Color"}, 126 | semantic{"COLOR0"} 127 | }, 128 | field 129 | { 130 | type{"float3"}, 131 | ID{"Color"}, 132 | semantic{"VPOS"} 133 | } 134 | } 135 | } -------------------------------------------------------------------------------- /src/host/lua-5.3.0/src/lcode.h: -------------------------------------------------------------------------------- 1 | /* 2 | ** $Id: lcode.h,v 1.63 2013/12/30 20:47:58 roberto Exp $ 3 | ** Code generator for Lua 4 | ** See Copyright Notice in lua.h 5 | */ 6 | 7 | #ifndef lcode_h 8 | #define lcode_h 9 | 10 | #include "llex.h" 11 | #include "lobject.h" 12 | #include "lopcodes.h" 13 | #include "lparser.h" 14 | 15 | 16 | /* 17 | ** Marks the end of a patch list. It is an invalid value both as an absolute 18 | ** address, and as a list link (would link an element to itself). 19 | */ 20 | #define NO_JUMP (-1) 21 | 22 | 23 | /* 24 | ** grep "ORDER OPR" if you change these enums (ORDER OP) 25 | */ 26 | typedef enum BinOpr { 27 | OPR_ADD, OPR_SUB, OPR_MUL, OPR_MOD, OPR_POW, 28 | OPR_DIV, 29 | OPR_IDIV, 30 | OPR_BAND, OPR_BOR, OPR_BXOR, 31 | OPR_SHL, OPR_SHR, 32 | OPR_CONCAT, 33 | OPR_EQ, OPR_LT, OPR_LE, 34 | OPR_NE, OPR_GT, OPR_GE, 35 | OPR_AND, OPR_OR, 36 | OPR_NOBINOPR 37 | } BinOpr; 38 | 39 | 40 | typedef enum UnOpr { OPR_MINUS, OPR_BNOT, OPR_NOT, OPR_LEN, OPR_NOUNOPR } UnOpr; 41 | 42 | 43 | #define getcode(fs,e) ((fs)->f->code[(e)->u.info]) 44 | 45 | #define luaK_codeAsBx(fs,o,A,sBx) luaK_codeABx(fs,o,A,(sBx)+MAXARG_sBx) 46 | 47 | #define luaK_setmultret(fs,e) luaK_setreturns(fs, e, LUA_MULTRET) 48 | 49 | #define luaK_jumpto(fs,t) luaK_patchlist(fs, luaK_jump(fs), t) 50 | 51 | LUAI_FUNC int luaK_codeABx (FuncState *fs, OpCode o, int A, unsigned int Bx); 52 | LUAI_FUNC int luaK_codeABC (FuncState *fs, OpCode o, int A, int B, int C); 53 | LUAI_FUNC int luaK_codek (FuncState *fs, int reg, int k); 54 | LUAI_FUNC void luaK_fixline (FuncState *fs, int line); 55 | LUAI_FUNC void luaK_nil (FuncState *fs, int from, int n); 56 | LUAI_FUNC void luaK_reserveregs (FuncState *fs, int n); 57 | LUAI_FUNC void luaK_checkstack (FuncState *fs, int n); 58 | LUAI_FUNC int luaK_stringK (FuncState *fs, TString *s); 59 | LUAI_FUNC int luaK_intK (FuncState *fs, lua_Integer n); 60 | LUAI_FUNC void luaK_dischargevars (FuncState *fs, expdesc *e); 61 | LUAI_FUNC int luaK_exp2anyreg (FuncState *fs, expdesc *e); 62 | LUAI_FUNC void luaK_exp2anyregup (FuncState *fs, expdesc *e); 63 | LUAI_FUNC void luaK_exp2nextreg (FuncState *fs, expdesc *e); 64 | LUAI_FUNC void luaK_exp2val (FuncState *fs, expdesc *e); 65 | LUAI_FUNC int luaK_exp2RK (FuncState *fs, expdesc *e); 66 | LUAI_FUNC void luaK_self (FuncState *fs, expdesc *e, expdesc *key); 67 | LUAI_FUNC void luaK_indexed (FuncState *fs, expdesc *t, expdesc *k); 68 | LUAI_FUNC void luaK_goiftrue (FuncState *fs, expdesc *e); 69 | LUAI_FUNC void luaK_goiffalse (FuncState *fs, expdesc *e); 70 | LUAI_FUNC void luaK_storevar (FuncState *fs, expdesc *var, expdesc *e); 71 | LUAI_FUNC void luaK_setreturns (FuncState *fs, expdesc *e, int nresults); 72 | LUAI_FUNC void luaK_setoneret (FuncState *fs, expdesc *e); 73 | LUAI_FUNC int luaK_jump (FuncState *fs); 74 | LUAI_FUNC void luaK_ret (FuncState *fs, int first, int nret); 75 | LUAI_FUNC void luaK_patchlist (FuncState *fs, int list, int target); 76 | LUAI_FUNC void luaK_patchtohere (FuncState *fs, int list); 77 | LUAI_FUNC void luaK_patchclose (FuncState *fs, int list, int level); 78 | LUAI_FUNC void luaK_concat (FuncState *fs, int *l1, int l2); 79 | LUAI_FUNC int luaK_getlabel (FuncState *fs); 80 | LUAI_FUNC void luaK_prefix (FuncState *fs, UnOpr op, expdesc *v, int line); 81 | LUAI_FUNC void luaK_infix (FuncState *fs, BinOpr op, expdesc *v); 82 | LUAI_FUNC void luaK_posfix (FuncState *fs, BinOpr op, expdesc *v1, 83 | expdesc *v2, int line); 84 | LUAI_FUNC void luaK_setlist (FuncState *fs, int base, int nelems, int tostore); 85 | 86 | 87 | #endif 88 | -------------------------------------------------------------------------------- /test/optim/constant_folding/multiplication.reference.ast: -------------------------------------------------------------------------------- 1 | 2 | { 3 | function 4 | { 5 | type{"float"}, 6 | ID{"multiplied_by_0_r"}, 7 | argument_list 8 | { 9 | argument 10 | { 11 | type{"float"}, 12 | ID{"a"} 13 | }, 14 | argument 15 | { 16 | type{"float"}, 17 | ID{"b"} 18 | } 19 | }, 20 | function_body{return{float_literal{"0.0f"}}} 21 | }, 22 | function 23 | { 24 | type{"float"}, 25 | ID{"multiplied_by_0_l"}, 26 | argument_list 27 | { 28 | argument 29 | { 30 | type{"float"}, 31 | ID{"a"} 32 | }, 33 | argument 34 | { 35 | type{"float"}, 36 | ID{"b"} 37 | } 38 | }, 39 | function_body{return{float_literal{"0.0f"}}} 40 | }, 41 | function 42 | { 43 | type{"float"}, 44 | ID{"multiplied_by_0_m"}, 45 | argument_list 46 | { 47 | argument 48 | { 49 | type{"float"}, 50 | ID{"a"} 51 | }, 52 | argument 53 | { 54 | type{"float"}, 55 | ID{"b"} 56 | } 57 | }, 58 | function_body{return{float_literal{"0.0f"}}} 59 | }, 60 | function 61 | { 62 | type{"float"}, 63 | ID{"multiplied_by_1_r"}, 64 | argument_list 65 | { 66 | argument 67 | { 68 | type{"float"}, 69 | ID{"a"} 70 | }, 71 | argument 72 | { 73 | type{"float"}, 74 | ID{"b"} 75 | } 76 | }, 77 | function_body 78 | { 79 | return 80 | { 81 | * 82 | { 83 | variable{"a"}, 84 | variable{"b"} 85 | } 86 | } 87 | } 88 | }, 89 | function 90 | { 91 | type{"float"}, 92 | ID{"multiplied_by_1_l"}, 93 | argument_list 94 | { 95 | argument 96 | { 97 | type{"float"}, 98 | ID{"a"} 99 | }, 100 | argument 101 | { 102 | type{"float"}, 103 | ID{"b"} 104 | } 105 | }, 106 | function_body 107 | { 108 | return 109 | { 110 | * 111 | { 112 | variable{"a"}, 113 | variable{"b"} 114 | } 115 | } 116 | } 117 | }, 118 | function 119 | { 120 | type{"float"}, 121 | ID{"multiplied_by_1_m"}, 122 | argument_list 123 | { 124 | argument 125 | { 126 | type{"float"}, 127 | ID{"a"} 128 | }, 129 | argument 130 | { 131 | type{"float"}, 132 | ID{"b"} 133 | } 134 | }, 135 | function_body 136 | { 137 | return 138 | { 139 | * 140 | { 141 | variable{"a"}, 142 | variable{"b"} 143 | } 144 | } 145 | } 146 | } 147 | } -------------------------------------------------------------------------------- /src/host/lua-5.3.0/doc/luac.1: -------------------------------------------------------------------------------- 1 | .\" $Id: luac.man,v 1.29 2011/11/16 13:53:40 lhf Exp $ 2 | .TH LUAC 1 "$Date: 2011/11/16 13:53:40 $" 3 | .SH NAME 4 | luac \- Lua compiler 5 | .SH SYNOPSIS 6 | .B luac 7 | [ 8 | .I options 9 | ] [ 10 | .I filenames 11 | ] 12 | .SH DESCRIPTION 13 | .B luac 14 | is the Lua compiler. 15 | It translates programs written in the Lua programming language 16 | into binary files containing precompiled chunks 17 | that can be later loaded and executed. 18 | .LP 19 | The main advantages of precompiling chunks are: 20 | faster loading, 21 | protecting source code from accidental user changes, 22 | and 23 | off-line syntax checking. 24 | Precompiling does not imply faster execution 25 | because in Lua chunks are always compiled into bytecodes before being executed. 26 | .B luac 27 | simply allows those bytecodes to be saved in a file for later execution. 28 | Precompiled chunks are not necessarily smaller than the corresponding source. 29 | The main goal in precompiling is faster loading. 30 | .LP 31 | In the command line, 32 | you can mix 33 | text files containing Lua source and 34 | binary files containing precompiled chunks. 35 | .B luac 36 | produces a single output file containing the combined bytecodes 37 | for all files given. 38 | Executing the combined file is equivalent to executing the given files. 39 | By default, 40 | the output file is named 41 | .BR luac.out , 42 | but you can change this with the 43 | .B \-o 44 | option. 45 | .LP 46 | Precompiled chunks are 47 | .I not 48 | portable across different architectures. 49 | Moreover, 50 | the internal format of precompiled chunks 51 | is likely to change when a new version of Lua is released. 52 | Make sure you save the source files of all Lua programs that you precompile. 53 | .LP 54 | .SH OPTIONS 55 | .TP 56 | .B \-l 57 | produce a listing of the compiled bytecode for Lua's virtual machine. 58 | Listing bytecodes is useful to learn about Lua's virtual machine. 59 | If no files are given, then 60 | .B luac 61 | loads 62 | .B luac.out 63 | and lists its contents. 64 | Use 65 | .B \-l \-l 66 | for a full listing. 67 | .TP 68 | .BI \-o " file" 69 | output to 70 | .IR file , 71 | instead of the default 72 | .BR luac.out . 73 | (You can use 74 | .B "'\-'" 75 | for standard output, 76 | but not on platforms that open standard output in text mode.) 77 | The output file may be one of the given files because 78 | all files are loaded before the output file is written. 79 | Be careful not to overwrite precious files. 80 | .TP 81 | .B \-p 82 | load files but do not generate any output file. 83 | Used mainly for syntax checking and for testing precompiled chunks: 84 | corrupted files will probably generate errors when loaded. 85 | If no files are given, then 86 | .B luac 87 | loads 88 | .B luac.out 89 | and tests its contents. 90 | No messages are displayed if the file loads without errors. 91 | .TP 92 | .B \-s 93 | strip debug information before writing the output file. 94 | This saves some space in very large chunks, 95 | but if errors occur when running a stripped chunk, 96 | then the error messages may not contain the full information they usually do. 97 | In particular, 98 | line numbers and names of local variables are lost. 99 | .TP 100 | .B \-v 101 | show version information. 102 | .TP 103 | .B \-\- 104 | stop handling options. 105 | .TP 106 | .B \- 107 | stop handling options and process standard input. 108 | .SH "SEE ALSO" 109 | .BR lua (1) 110 | .br 111 | The documentation at lua.org. 112 | .SH DIAGNOSTICS 113 | Error messages should be self explanatory. 114 | .SH AUTHORS 115 | R. Ierusalimschy, 116 | L. H. de Figueiredo, 117 | W. Celes 118 | .\" EOF 119 | -------------------------------------------------------------------------------- /src/host/lua-5.3.0/src/lparser.h: -------------------------------------------------------------------------------- 1 | /* 2 | ** $Id: lparser.h,v 1.74 2014/10/25 11:50:46 roberto Exp $ 3 | ** Lua Parser 4 | ** See Copyright Notice in lua.h 5 | */ 6 | 7 | #ifndef lparser_h 8 | #define lparser_h 9 | 10 | #include "llimits.h" 11 | #include "lobject.h" 12 | #include "lzio.h" 13 | 14 | 15 | /* 16 | ** Expression descriptor 17 | */ 18 | 19 | typedef enum { 20 | VVOID, /* no value */ 21 | VNIL, 22 | VTRUE, 23 | VFALSE, 24 | VK, /* info = index of constant in 'k' */ 25 | VKFLT, /* nval = numerical float value */ 26 | VKINT, /* nval = numerical integer value */ 27 | VNONRELOC, /* info = result register */ 28 | VLOCAL, /* info = local register */ 29 | VUPVAL, /* info = index of upvalue in 'upvalues' */ 30 | VINDEXED, /* t = table register/upvalue; idx = index R/K */ 31 | VJMP, /* info = instruction pc */ 32 | VRELOCABLE, /* info = instruction pc */ 33 | VCALL, /* info = instruction pc */ 34 | VVARARG /* info = instruction pc */ 35 | } expkind; 36 | 37 | 38 | #define vkisvar(k) (VLOCAL <= (k) && (k) <= VINDEXED) 39 | #define vkisinreg(k) ((k) == VNONRELOC || (k) == VLOCAL) 40 | 41 | typedef struct expdesc { 42 | expkind k; 43 | union { 44 | struct { /* for indexed variables (VINDEXED) */ 45 | short idx; /* index (R/K) */ 46 | lu_byte t; /* table (register or upvalue) */ 47 | lu_byte vt; /* whether 't' is register (VLOCAL) or upvalue (VUPVAL) */ 48 | } ind; 49 | int info; /* for generic use */ 50 | lua_Number nval; /* for VKFLT */ 51 | lua_Integer ival; /* for VKINT */ 52 | } u; 53 | int t; /* patch list of 'exit when true' */ 54 | int f; /* patch list of 'exit when false' */ 55 | } expdesc; 56 | 57 | 58 | /* description of active local variable */ 59 | typedef struct Vardesc { 60 | short idx; /* variable index in stack */ 61 | } Vardesc; 62 | 63 | 64 | /* description of pending goto statements and label statements */ 65 | typedef struct Labeldesc { 66 | TString *name; /* label identifier */ 67 | int pc; /* position in code */ 68 | int line; /* line where it appeared */ 69 | lu_byte nactvar; /* local level where it appears in current block */ 70 | } Labeldesc; 71 | 72 | 73 | /* list of labels or gotos */ 74 | typedef struct Labellist { 75 | Labeldesc *arr; /* array */ 76 | int n; /* number of entries in use */ 77 | int size; /* array size */ 78 | } Labellist; 79 | 80 | 81 | /* dynamic structures used by the parser */ 82 | typedef struct Dyndata { 83 | struct { /* list of active local variables */ 84 | Vardesc *arr; 85 | int n; 86 | int size; 87 | } actvar; 88 | Labellist gt; /* list of pending gotos */ 89 | Labellist label; /* list of active labels */ 90 | } Dyndata; 91 | 92 | 93 | /* control of blocks */ 94 | struct BlockCnt; /* defined in lparser.c */ 95 | 96 | 97 | /* state needed to generate code for a given function */ 98 | typedef struct FuncState { 99 | Proto *f; /* current function header */ 100 | struct FuncState *prev; /* enclosing function */ 101 | struct LexState *ls; /* lexical state */ 102 | struct BlockCnt *bl; /* chain of current blocks */ 103 | int pc; /* next position to code (equivalent to 'ncode') */ 104 | int lasttarget; /* 'label' of last 'jump label' */ 105 | int jpc; /* list of pending jumps to 'pc' */ 106 | int nk; /* number of elements in 'k' */ 107 | int np; /* number of elements in 'p' */ 108 | int firstlocal; /* index of first local var (in Dyndata array) */ 109 | short nlocvars; /* number of elements in 'f->locvars' */ 110 | lu_byte nactvar; /* number of active local variables */ 111 | lu_byte nups; /* number of upvalues */ 112 | lu_byte freereg; /* first free register */ 113 | } FuncState; 114 | 115 | 116 | LUAI_FUNC LClosure *luaY_parser (lua_State *L, ZIO *z, Mbuffer *buff, 117 | Dyndata *dyd, const char *name, int firstchar); 118 | 119 | 120 | #endif 121 | -------------------------------------------------------------------------------- /test/parser/if_statement.reference.ast: -------------------------------------------------------------------------------- 1 | 2 | { 3 | function 4 | { 5 | type{"bool"}, 6 | ID{"test"}, 7 | argument_list 8 | { 9 | argument 10 | { 11 | type{"float"}, 12 | ID{"a"} 13 | }, 14 | argument 15 | { 16 | type{"float"}, 17 | ID{"x"} 18 | } 19 | }, 20 | function_body 21 | { 22 | if 23 | { 24 | if_block 25 | { 26 | == 27 | { 28 | variable{"a"}, 29 | variable{"x"} 30 | }, 31 | return{bool_literal{"false"}} 32 | } 33 | }, 34 | if 35 | { 36 | if_block 37 | { 38 | || 39 | { 40 | < 41 | { 42 | variable{"a"}, 43 | variable{"x"} 44 | }, 45 | > 46 | { 47 | variable{"a"}, 48 | variable{"x"} 49 | } 50 | }, 51 | block{return{bool_literal{"true"}}} 52 | } 53 | }, 54 | if 55 | { 56 | if_block 57 | { 58 | > 59 | { 60 | + 61 | { 62 | variable{"a"}, 63 | variable{"x"} 64 | }, 65 | float_literal{"10.0f"} 66 | }, 67 | block 68 | { 69 | return 70 | { 71 | <= 72 | { 73 | + 74 | { 75 | variable{"x"}, 76 | variable{"a"} 77 | }, 78 | float_literal{"23.35f"} 79 | } 80 | } 81 | } 82 | }, 83 | else_if_block 84 | { 85 | unary_! 86 | { 87 | < 88 | { 89 | - 90 | { 91 | variable{"a"}, 92 | variable{"x"} 93 | }, 94 | float_literal{"5.0f"} 95 | } 96 | }, 97 | block 98 | { 99 | =_statement 100 | { 101 | variable{"a"}, 102 | float_literal{"1.0"} 103 | }, 104 | return 105 | { 106 | >= 107 | { 108 | variable{"a"}, 109 | variable{"x"} 110 | } 111 | } 112 | } 113 | }, 114 | else_block 115 | { 116 | block 117 | { 118 | =_statement 119 | { 120 | variable{"a"}, 121 | variable{"x"} 122 | } 123 | } 124 | } 125 | }, 126 | return{bool_literal{"false"}} 127 | } 128 | } 129 | } -------------------------------------------------------------------------------- /src/host/lua-5.3.0/src/lopcodes.c: -------------------------------------------------------------------------------- 1 | /* 2 | ** $Id: lopcodes.c,v 1.55 2015/01/05 13:48:33 roberto Exp $ 3 | ** Opcodes for Lua virtual machine 4 | ** See Copyright Notice in lua.h 5 | */ 6 | 7 | #define lopcodes_c 8 | #define LUA_CORE 9 | 10 | #include "lprefix.h" 11 | 12 | 13 | #include 14 | 15 | #include "lopcodes.h" 16 | 17 | 18 | /* ORDER OP */ 19 | 20 | LUAI_DDEF const char *const luaP_opnames[NUM_OPCODES+1] = { 21 | "MOVE", 22 | "LOADK", 23 | "LOADKX", 24 | "LOADBOOL", 25 | "LOADNIL", 26 | "GETUPVAL", 27 | "GETTABUP", 28 | "GETTABLE", 29 | "SETTABUP", 30 | "SETUPVAL", 31 | "SETTABLE", 32 | "NEWTABLE", 33 | "SELF", 34 | "ADD", 35 | "SUB", 36 | "MUL", 37 | "MOD", 38 | "POW", 39 | "DIV", 40 | "IDIV", 41 | "BAND", 42 | "BOR", 43 | "BXOR", 44 | "SHL", 45 | "SHR", 46 | "UNM", 47 | "BNOT", 48 | "NOT", 49 | "LEN", 50 | "CONCAT", 51 | "JMP", 52 | "EQ", 53 | "LT", 54 | "LE", 55 | "TEST", 56 | "TESTSET", 57 | "CALL", 58 | "TAILCALL", 59 | "RETURN", 60 | "FORLOOP", 61 | "FORPREP", 62 | "TFORCALL", 63 | "TFORLOOP", 64 | "SETLIST", 65 | "CLOSURE", 66 | "VARARG", 67 | "EXTRAARG", 68 | NULL 69 | }; 70 | 71 | 72 | #define opmode(t,a,b,c,m) (((t)<<7) | ((a)<<6) | ((b)<<4) | ((c)<<2) | (m)) 73 | 74 | LUAI_DDEF const lu_byte luaP_opmodes[NUM_OPCODES] = { 75 | /* T A B C mode opcode */ 76 | opmode(0, 1, OpArgR, OpArgN, iABC) /* OP_MOVE */ 77 | ,opmode(0, 1, OpArgK, OpArgN, iABx) /* OP_LOADK */ 78 | ,opmode(0, 1, OpArgN, OpArgN, iABx) /* OP_LOADKX */ 79 | ,opmode(0, 1, OpArgU, OpArgU, iABC) /* OP_LOADBOOL */ 80 | ,opmode(0, 1, OpArgU, OpArgN, iABC) /* OP_LOADNIL */ 81 | ,opmode(0, 1, OpArgU, OpArgN, iABC) /* OP_GETUPVAL */ 82 | ,opmode(0, 1, OpArgU, OpArgK, iABC) /* OP_GETTABUP */ 83 | ,opmode(0, 1, OpArgR, OpArgK, iABC) /* OP_GETTABLE */ 84 | ,opmode(0, 0, OpArgK, OpArgK, iABC) /* OP_SETTABUP */ 85 | ,opmode(0, 0, OpArgU, OpArgN, iABC) /* OP_SETUPVAL */ 86 | ,opmode(0, 0, OpArgK, OpArgK, iABC) /* OP_SETTABLE */ 87 | ,opmode(0, 1, OpArgU, OpArgU, iABC) /* OP_NEWTABLE */ 88 | ,opmode(0, 1, OpArgR, OpArgK, iABC) /* OP_SELF */ 89 | ,opmode(0, 1, OpArgK, OpArgK, iABC) /* OP_ADD */ 90 | ,opmode(0, 1, OpArgK, OpArgK, iABC) /* OP_SUB */ 91 | ,opmode(0, 1, OpArgK, OpArgK, iABC) /* OP_MUL */ 92 | ,opmode(0, 1, OpArgK, OpArgK, iABC) /* OP_MOD */ 93 | ,opmode(0, 1, OpArgK, OpArgK, iABC) /* OP_POW */ 94 | ,opmode(0, 1, OpArgK, OpArgK, iABC) /* OP_DIV */ 95 | ,opmode(0, 1, OpArgK, OpArgK, iABC) /* OP_IDIV */ 96 | ,opmode(0, 1, OpArgK, OpArgK, iABC) /* OP_BAND */ 97 | ,opmode(0, 1, OpArgK, OpArgK, iABC) /* OP_BOR */ 98 | ,opmode(0, 1, OpArgK, OpArgK, iABC) /* OP_BXOR */ 99 | ,opmode(0, 1, OpArgK, OpArgK, iABC) /* OP_SHL */ 100 | ,opmode(0, 1, OpArgK, OpArgK, iABC) /* OP_SHR */ 101 | ,opmode(0, 1, OpArgR, OpArgN, iABC) /* OP_UNM */ 102 | ,opmode(0, 1, OpArgR, OpArgN, iABC) /* OP_BNOT */ 103 | ,opmode(0, 1, OpArgR, OpArgN, iABC) /* OP_NOT */ 104 | ,opmode(0, 1, OpArgR, OpArgN, iABC) /* OP_LEN */ 105 | ,opmode(0, 1, OpArgR, OpArgR, iABC) /* OP_CONCAT */ 106 | ,opmode(0, 0, OpArgR, OpArgN, iAsBx) /* OP_JMP */ 107 | ,opmode(1, 0, OpArgK, OpArgK, iABC) /* OP_EQ */ 108 | ,opmode(1, 0, OpArgK, OpArgK, iABC) /* OP_LT */ 109 | ,opmode(1, 0, OpArgK, OpArgK, iABC) /* OP_LE */ 110 | ,opmode(1, 0, OpArgN, OpArgU, iABC) /* OP_TEST */ 111 | ,opmode(1, 1, OpArgR, OpArgU, iABC) /* OP_TESTSET */ 112 | ,opmode(0, 1, OpArgU, OpArgU, iABC) /* OP_CALL */ 113 | ,opmode(0, 1, OpArgU, OpArgU, iABC) /* OP_TAILCALL */ 114 | ,opmode(0, 0, OpArgU, OpArgN, iABC) /* OP_RETURN */ 115 | ,opmode(0, 1, OpArgR, OpArgN, iAsBx) /* OP_FORLOOP */ 116 | ,opmode(0, 1, OpArgR, OpArgN, iAsBx) /* OP_FORPREP */ 117 | ,opmode(0, 0, OpArgN, OpArgU, iABC) /* OP_TFORCALL */ 118 | ,opmode(0, 1, OpArgR, OpArgN, iAsBx) /* OP_TFORLOOP */ 119 | ,opmode(0, 0, OpArgU, OpArgU, iABC) /* OP_SETLIST */ 120 | ,opmode(0, 1, OpArgU, OpArgN, iABx) /* OP_CLOSURE */ 121 | ,opmode(0, 1, OpArgU, OpArgN, iABC) /* OP_VARARG */ 122 | ,opmode(0, 0, OpArgU, OpArgU, iAx) /* OP_EXTRAARG */ 123 | }; 124 | 125 | -------------------------------------------------------------------------------- /src/host/lua-5.3.0/src/lfunc.c: -------------------------------------------------------------------------------- 1 | /* 2 | ** $Id: lfunc.c,v 2.45 2014/11/02 19:19:04 roberto Exp $ 3 | ** Auxiliary functions to manipulate prototypes and closures 4 | ** See Copyright Notice in lua.h 5 | */ 6 | 7 | #define lfunc_c 8 | #define LUA_CORE 9 | 10 | #include "lprefix.h" 11 | 12 | 13 | #include 14 | 15 | #include "lua.h" 16 | 17 | #include "lfunc.h" 18 | #include "lgc.h" 19 | #include "lmem.h" 20 | #include "lobject.h" 21 | #include "lstate.h" 22 | 23 | 24 | 25 | CClosure *luaF_newCclosure (lua_State *L, int n) { 26 | GCObject *o = luaC_newobj(L, LUA_TCCL, sizeCclosure(n)); 27 | CClosure *c = gco2ccl(o); 28 | c->nupvalues = cast_byte(n); 29 | return c; 30 | } 31 | 32 | 33 | LClosure *luaF_newLclosure (lua_State *L, int n) { 34 | GCObject *o = luaC_newobj(L, LUA_TLCL, sizeLclosure(n)); 35 | LClosure *c = gco2lcl(o); 36 | c->p = NULL; 37 | c->nupvalues = cast_byte(n); 38 | while (n--) c->upvals[n] = NULL; 39 | return c; 40 | } 41 | 42 | /* 43 | ** fill a closure with new closed upvalues 44 | */ 45 | void luaF_initupvals (lua_State *L, LClosure *cl) { 46 | int i; 47 | for (i = 0; i < cl->nupvalues; i++) { 48 | UpVal *uv = luaM_new(L, UpVal); 49 | uv->refcount = 1; 50 | uv->v = &uv->u.value; /* make it closed */ 51 | setnilvalue(uv->v); 52 | cl->upvals[i] = uv; 53 | } 54 | } 55 | 56 | 57 | UpVal *luaF_findupval (lua_State *L, StkId level) { 58 | UpVal **pp = &L->openupval; 59 | UpVal *p; 60 | UpVal *uv; 61 | lua_assert(isintwups(L) || L->openupval == NULL); 62 | while (*pp != NULL && (p = *pp)->v >= level) { 63 | lua_assert(upisopen(p)); 64 | if (p->v == level) /* found a corresponding upvalue? */ 65 | return p; /* return it */ 66 | pp = &p->u.open.next; 67 | } 68 | /* not found: create a new upvalue */ 69 | uv = luaM_new(L, UpVal); 70 | uv->refcount = 0; 71 | uv->u.open.next = *pp; /* link it to list of open upvalues */ 72 | uv->u.open.touched = 1; 73 | *pp = uv; 74 | uv->v = level; /* current value lives in the stack */ 75 | if (!isintwups(L)) { /* thread not in list of threads with upvalues? */ 76 | L->twups = G(L)->twups; /* link it to the list */ 77 | G(L)->twups = L; 78 | } 79 | return uv; 80 | } 81 | 82 | 83 | void luaF_close (lua_State *L, StkId level) { 84 | UpVal *uv; 85 | while (L->openupval != NULL && (uv = L->openupval)->v >= level) { 86 | lua_assert(upisopen(uv)); 87 | L->openupval = uv->u.open.next; /* remove from 'open' list */ 88 | if (uv->refcount == 0) /* no references? */ 89 | luaM_free(L, uv); /* free upvalue */ 90 | else { 91 | setobj(L, &uv->u.value, uv->v); /* move value to upvalue slot */ 92 | uv->v = &uv->u.value; /* now current value lives here */ 93 | luaC_upvalbarrier(L, uv); 94 | } 95 | } 96 | } 97 | 98 | 99 | Proto *luaF_newproto (lua_State *L) { 100 | GCObject *o = luaC_newobj(L, LUA_TPROTO, sizeof(Proto)); 101 | Proto *f = gco2p(o); 102 | f->k = NULL; 103 | f->sizek = 0; 104 | f->p = NULL; 105 | f->sizep = 0; 106 | f->code = NULL; 107 | f->cache = NULL; 108 | f->sizecode = 0; 109 | f->lineinfo = NULL; 110 | f->sizelineinfo = 0; 111 | f->upvalues = NULL; 112 | f->sizeupvalues = 0; 113 | f->numparams = 0; 114 | f->is_vararg = 0; 115 | f->maxstacksize = 0; 116 | f->locvars = NULL; 117 | f->sizelocvars = 0; 118 | f->linedefined = 0; 119 | f->lastlinedefined = 0; 120 | f->source = NULL; 121 | return f; 122 | } 123 | 124 | 125 | void luaF_freeproto (lua_State *L, Proto *f) { 126 | luaM_freearray(L, f->code, f->sizecode); 127 | luaM_freearray(L, f->p, f->sizep); 128 | luaM_freearray(L, f->k, f->sizek); 129 | luaM_freearray(L, f->lineinfo, f->sizelineinfo); 130 | luaM_freearray(L, f->locvars, f->sizelocvars); 131 | luaM_freearray(L, f->upvalues, f->sizeupvalues); 132 | luaM_free(L, f); 133 | } 134 | 135 | 136 | /* 137 | ** Look for n-th local variable at line 'line' in function 'func'. 138 | ** Returns NULL if not found. 139 | */ 140 | const char *luaF_getlocalname (const Proto *f, int local_number, int pc) { 141 | int i; 142 | for (i = 0; isizelocvars && f->locvars[i].startpc <= pc; i++) { 143 | if (pc < f->locvars[i].endpc) { /* is variable active? */ 144 | local_number--; 145 | if (local_number == 0) 146 | return getstr(f->locvars[i].varname); 147 | } 148 | } 149 | return NULL; /* not found */ 150 | } 151 | 152 | -------------------------------------------------------------------------------- /contrib/antlr3cyclicdfa.hpp: -------------------------------------------------------------------------------- 1 | /// Definition of a cyclic dfa structure such that it can be 2 | /// initialized at compile time and have only a single 3 | /// runtime function that can deal with all cyclic dfa 4 | /// structures and show Java how it is done ;-) 5 | /// 6 | #ifndef ANTLR3_CYCLICDFA_HPP 7 | #define ANTLR3_CYCLICDFA_HPP 8 | 9 | // [The "BSD licence"] 10 | // Copyright (c) 2005-2009 Gokulakannan Somasundaram, ElectronDB 11 | 12 | // 13 | // All rights reserved. 14 | // 15 | // Redistribution and use in source and binary forms, with or without 16 | // modification, are permitted provided that the following conditions 17 | // are met: 18 | // 1. Redistributions of source code must retain the above copyright 19 | // notice, this list of conditions and the following disclaimer. 20 | // 2. Redistributions in binary form must reproduce the above copyright 21 | // notice, this list of conditions and the following disclaimer in the 22 | // documentation and/or other materials provided with the distribution. 23 | // 3. The name of the author may not be used to endorse or promote products 24 | // derived from this software without specific prior written permission. 25 | // 26 | // THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR 27 | // IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES 28 | // OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. 29 | // IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, 30 | // INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT 31 | // NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 32 | // DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 33 | // THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 34 | // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF 35 | // THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 36 | 37 | #include "antlr3defs.hpp" 38 | 39 | #ifdef ANTLR3_WINDOWS 40 | #pragma warning (push) 41 | #pragma warning (disable : 4510) 42 | #pragma warning (disable : 4512) 43 | #pragma warning (disable : 4610) 44 | #endif 45 | 46 | ANTLR_BEGIN_NAMESPACE() 47 | 48 | template 49 | class CyclicDFA : public ImplTraits::AllocPolicyType 50 | { 51 | public: 52 | typedef typename CtxType::StreamType StreamType; 53 | typedef typename CtxType::ExceptionBaseType ExceptionBaseType; 54 | typedef typename ImplTraits::template RecognizerType RecognizerType; 55 | typedef typename StreamType::IntStreamType IntStreamType; 56 | typedef typename StreamType::TokenType TokenType; 57 | typedef TokenType CommonTokenType; 58 | typedef CtxType ContextType; 59 | 60 | private: 61 | /// Decision number that a particular static structure 62 | /// represents. 63 | /// 64 | const ANTLR_INT32 m_decisionNumber; 65 | 66 | /// What this decision represents 67 | /// 68 | const ANTLR_UCHAR* m_description; 69 | const ANTLR_INT32* const m_eot; 70 | const ANTLR_INT32* const m_eof; 71 | const ANTLR_INT32* const m_min; 72 | const ANTLR_INT32* const m_max; 73 | const ANTLR_INT32* const m_accept; 74 | const ANTLR_INT32* const m_special; 75 | const ANTLR_INT32* const *const m_transition; 76 | 77 | public: 78 | CyclicDFA( ANTLR_INT32 decisionNumber 79 | , const ANTLR_UCHAR* description 80 | , const ANTLR_INT32* const eot 81 | , const ANTLR_INT32* const eof 82 | , const ANTLR_INT32* const min 83 | , const ANTLR_INT32* const max 84 | , const ANTLR_INT32* const accept 85 | , const ANTLR_INT32* const special 86 | , const ANTLR_INT32* const *const transition ); 87 | CyclicDFA( const CyclicDFA& cdfa ); 88 | CyclicDFA& operator=( const CyclicDFA& dfa); 89 | 90 | ANTLR_INT32 specialStateTransition(CtxType * ctx, RecognizerType* recognizer, IntStreamType* is, ANTLR_INT32 s); 91 | ANTLR_INT32 specialTransition(CtxType * ctx, RecognizerType* recognizer, IntStreamType* is, ANTLR_INT32 s); 92 | 93 | template 94 | ANTLR_INT32 predict(CtxType* ctx, RecognizerType* recognizer, IntStreamType* is, SuperType& super); 95 | 96 | private: 97 | void noViableAlt(RecognizerType* rec, ANTLR_UINT32 s); 98 | }; 99 | 100 | ANTLR_END_NAMESPACE() 101 | 102 | #ifdef ANTLR3_WINDOWS 103 | #pragma warning (pop) 104 | #endif 105 | 106 | #include "antlr3cyclicdfa.inl" 107 | 108 | #endif 109 | -------------------------------------------------------------------------------- /contrib/antlr3treeparser.hpp: -------------------------------------------------------------------------------- 1 | #ifndef ANTLR3TREEPARSER_HPP 2 | #define ANTLR3TREEPARSER_HPP 3 | 4 | // [The "BSD licence"] 5 | // Copyright (c) 2005-2009 Gokulakannan Somasundaram, ElectronDB 6 | 7 | // 8 | // All rights reserved. 9 | // 10 | // Redistribution and use in source and binary forms, with or without 11 | // modification, are permitted provided that the following conditions 12 | // are met: 13 | // 1. Redistributions of source code must retain the above copyright 14 | // notice, this list of conditions and the following disclaimer. 15 | // 2. Redistributions in binary form must reproduce the above copyright 16 | // notice, this list of conditions and the following disclaimer in the 17 | // documentation and/or other materials provided with the distribution. 18 | // 3. The name of the author may not be used to endorse or promote products 19 | // derived from this software without specific prior written permission. 20 | // 21 | // THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR 22 | // IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES 23 | // OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. 24 | // IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, 25 | // INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT 26 | // NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 27 | // DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 28 | // THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 29 | // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF 30 | // THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 31 | 32 | #include "antlr3defs.hpp" 33 | 34 | /** Internal structure representing an element in a hash bucket. 35 | * Stores the original key so that duplicate keys can be rejected 36 | * if necessary, and contains function can be supported If the hash key 37 | * could be unique I would have invented the perfect compression algorithm ;-) 38 | */ 39 | ANTLR_BEGIN_NAMESPACE() 40 | 41 | template 42 | class TreeParser : public ImplTraits::template RecognizerType< TreeParser > 43 | { 44 | public: 45 | typedef typename ImplTraits::TreeNodeStreamType TreeNodeStreamType; 46 | typedef TreeNodeStreamType StreamType; 47 | typedef typename TreeNodeStreamType::IntStreamType IntStreamType; 48 | typedef typename ImplTraits::TreeType TreeType; 49 | typedef TreeType TokenType; 50 | typedef typename ImplTraits::template ExceptionBase ExceptionBaseType; 51 | typedef typename ImplTraits::template RecognizerType< TreeParser > RecognizerType; 52 | typedef typename RecognizerType::RecognizerSharedStateType RecognizerSharedStateType; 53 | typedef Empty TokenSourceType; 54 | typedef typename ImplTraits::BitsetListType BitsetListType; 55 | typedef typename ImplTraits::StringType StringType; 56 | typedef typename ImplTraits::CommonTokenType CommonTokenType; 57 | 58 | private: 59 | /** Pointer to the common tree node stream for the parser 60 | */ 61 | TreeNodeStreamType* m_ctnstream; 62 | 63 | public: 64 | TreeParser( ANTLR_UINT32 sizeHint, TreeNodeStreamType* ctnstream, 65 | RecognizerSharedStateType* state); 66 | TreeNodeStreamType* get_ctnstream() const; 67 | IntStreamType* get_istream() const; 68 | RecognizerType* get_rec(); 69 | 70 | //same as above. Just that get_istream exists for lexer, parser, treeparser 71 | //get_parser_istream exists only for parser, treeparser. So use it accordingly 72 | IntStreamType* get_parser_istream() const; 73 | 74 | /** Set the input stream and reset the parser 75 | */ 76 | void setTreeNodeStream(TreeNodeStreamType* input); 77 | 78 | /** Return a pointer to the input stream 79 | */ 80 | TreeNodeStreamType* getTreeNodeStream(); 81 | 82 | TokenType* getMissingSymbol( IntStreamType* istream, 83 | ExceptionBaseType* e, 84 | ANTLR_UINT32 expectedTokenType, 85 | BitsetListType* follow); 86 | 87 | /** Pointer to a function that knows how to free resources of an ANTLR3 tree parser. 88 | */ 89 | ~TreeParser(); 90 | 91 | void fillExceptionData( ExceptionBaseType* ex ); 92 | void displayRecognitionError( ANTLR_UINT8** tokenNames, ExceptionBaseType* ex ); 93 | void exConstruct(); 94 | void mismatch(ANTLR_UINT32 ttype, BitsetListType* follow); 95 | }; 96 | 97 | ANTLR_END_NAMESPACE() 98 | 99 | #include "antlr3treeparser.inl" 100 | 101 | #endif 102 | -------------------------------------------------------------------------------- /src/host/lua-5.3.0/src/ltm.c: -------------------------------------------------------------------------------- 1 | /* 2 | ** $Id: ltm.c,v 2.33 2014/11/21 12:15:57 roberto Exp $ 3 | ** Tag methods 4 | ** See Copyright Notice in lua.h 5 | */ 6 | 7 | #define ltm_c 8 | #define LUA_CORE 9 | 10 | #include "lprefix.h" 11 | 12 | 13 | #include 14 | 15 | #include "lua.h" 16 | 17 | #include "ldebug.h" 18 | #include "ldo.h" 19 | #include "lobject.h" 20 | #include "lstate.h" 21 | #include "lstring.h" 22 | #include "ltable.h" 23 | #include "ltm.h" 24 | #include "lvm.h" 25 | 26 | 27 | static const char udatatypename[] = "userdata"; 28 | 29 | LUAI_DDEF const char *const luaT_typenames_[LUA_TOTALTAGS] = { 30 | "no value", 31 | "nil", "boolean", udatatypename, "number", 32 | "string", "table", "function", udatatypename, "thread", 33 | "proto" /* this last case is used for tests only */ 34 | }; 35 | 36 | 37 | void luaT_init (lua_State *L) { 38 | static const char *const luaT_eventname[] = { /* ORDER TM */ 39 | "__index", "__newindex", 40 | "__gc", "__mode", "__len", "__eq", 41 | "__add", "__sub", "__mul", "__mod", "__pow", 42 | "__div", "__idiv", 43 | "__band", "__bor", "__bxor", "__shl", "__shr", 44 | "__unm", "__bnot", "__lt", "__le", 45 | "__concat", "__call" 46 | }; 47 | int i; 48 | for (i=0; itmname[i] = luaS_new(L, luaT_eventname[i]); 50 | luaC_fix(L, obj2gco(G(L)->tmname[i])); /* never collect these names */ 51 | } 52 | } 53 | 54 | 55 | /* 56 | ** function to be used with macro "fasttm": optimized for absence of 57 | ** tag methods 58 | */ 59 | const TValue *luaT_gettm (Table *events, TMS event, TString *ename) { 60 | const TValue *tm = luaH_getstr(events, ename); 61 | lua_assert(event <= TM_EQ); 62 | if (ttisnil(tm)) { /* no tag method? */ 63 | events->flags |= cast_byte(1u<metatable; 75 | break; 76 | case LUA_TUSERDATA: 77 | mt = uvalue(o)->metatable; 78 | break; 79 | default: 80 | mt = G(L)->mt[ttnov(o)]; 81 | } 82 | return (mt ? luaH_getstr(mt, G(L)->tmname[event]) : luaO_nilobject); 83 | } 84 | 85 | 86 | void luaT_callTM (lua_State *L, const TValue *f, const TValue *p1, 87 | const TValue *p2, TValue *p3, int hasres) { 88 | ptrdiff_t result = savestack(L, p3); 89 | setobj2s(L, L->top++, f); /* push function (assume EXTRA_STACK) */ 90 | setobj2s(L, L->top++, p1); /* 1st argument */ 91 | setobj2s(L, L->top++, p2); /* 2nd argument */ 92 | if (!hasres) /* no result? 'p3' is third argument */ 93 | setobj2s(L, L->top++, p3); /* 3rd argument */ 94 | /* metamethod may yield only when called from Lua code */ 95 | luaD_call(L, L->top - (4 - hasres), hasres, isLua(L->ci)); 96 | if (hasres) { /* if has result, move it to its place */ 97 | p3 = restorestack(L, result); 98 | setobjs2s(L, p3, --L->top); 99 | } 100 | } 101 | 102 | 103 | int luaT_callbinTM (lua_State *L, const TValue *p1, const TValue *p2, 104 | StkId res, TMS event) { 105 | const TValue *tm = luaT_gettmbyobj(L, p1, event); /* try first operand */ 106 | if (ttisnil(tm)) 107 | tm = luaT_gettmbyobj(L, p2, event); /* try second operand */ 108 | if (ttisnil(tm)) return 0; 109 | luaT_callTM(L, tm, p1, p2, res, 1); 110 | return 1; 111 | } 112 | 113 | 114 | void luaT_trybinTM (lua_State *L, const TValue *p1, const TValue *p2, 115 | StkId res, TMS event) { 116 | if (!luaT_callbinTM(L, p1, p2, res, event)) { 117 | switch (event) { 118 | case TM_CONCAT: 119 | luaG_concaterror(L, p1, p2); 120 | case TM_BAND: case TM_BOR: case TM_BXOR: 121 | case TM_SHL: case TM_SHR: case TM_BNOT: { 122 | lua_Number dummy; 123 | if (tonumber(p1, &dummy) && tonumber(p2, &dummy)) 124 | luaG_tointerror(L, p1, p2); 125 | else 126 | luaG_opinterror(L, p1, p2, "perform bitwise operation on"); 127 | /* else go through */ 128 | } 129 | default: 130 | luaG_opinterror(L, p1, p2, "perform arithmetic on"); 131 | } 132 | } 133 | } 134 | 135 | 136 | int luaT_callorderTM (lua_State *L, const TValue *p1, const TValue *p2, 137 | TMS event) { 138 | if (!luaT_callbinTM(L, p1, p2, L->top, event)) 139 | return -1; /* no metamethod */ 140 | else 141 | return !l_isfalse(L->top); 142 | } 143 | 144 | -------------------------------------------------------------------------------- /src/host/lua-5.3.0/src/lcorolib.c: -------------------------------------------------------------------------------- 1 | /* 2 | ** $Id: lcorolib.c,v 1.9 2014/11/02 19:19:04 roberto Exp $ 3 | ** Coroutine Library 4 | ** See Copyright Notice in lua.h 5 | */ 6 | 7 | #define lcorolib_c 8 | #define LUA_LIB 9 | 10 | #include "lprefix.h" 11 | 12 | 13 | #include 14 | 15 | #include "lua.h" 16 | 17 | #include "lauxlib.h" 18 | #include "lualib.h" 19 | 20 | 21 | static lua_State *getco (lua_State *L) { 22 | lua_State *co = lua_tothread(L, 1); 23 | luaL_argcheck(L, co, 1, "thread expected"); 24 | return co; 25 | } 26 | 27 | 28 | static int auxresume (lua_State *L, lua_State *co, int narg) { 29 | int status; 30 | if (!lua_checkstack(co, narg)) { 31 | lua_pushliteral(L, "too many arguments to resume"); 32 | return -1; /* error flag */ 33 | } 34 | if (lua_status(co) == LUA_OK && lua_gettop(co) == 0) { 35 | lua_pushliteral(L, "cannot resume dead coroutine"); 36 | return -1; /* error flag */ 37 | } 38 | lua_xmove(L, co, narg); 39 | status = lua_resume(co, L, narg); 40 | if (status == LUA_OK || status == LUA_YIELD) { 41 | int nres = lua_gettop(co); 42 | if (!lua_checkstack(L, nres + 1)) { 43 | lua_pop(co, nres); /* remove results anyway */ 44 | lua_pushliteral(L, "too many results to resume"); 45 | return -1; /* error flag */ 46 | } 47 | lua_xmove(co, L, nres); /* move yielded values */ 48 | return nres; 49 | } 50 | else { 51 | lua_xmove(co, L, 1); /* move error message */ 52 | return -1; /* error flag */ 53 | } 54 | } 55 | 56 | 57 | static int luaB_coresume (lua_State *L) { 58 | lua_State *co = getco(L); 59 | int r; 60 | r = auxresume(L, co, lua_gettop(L) - 1); 61 | if (r < 0) { 62 | lua_pushboolean(L, 0); 63 | lua_insert(L, -2); 64 | return 2; /* return false + error message */ 65 | } 66 | else { 67 | lua_pushboolean(L, 1); 68 | lua_insert(L, -(r + 1)); 69 | return r + 1; /* return true + 'resume' returns */ 70 | } 71 | } 72 | 73 | 74 | static int luaB_auxwrap (lua_State *L) { 75 | lua_State *co = lua_tothread(L, lua_upvalueindex(1)); 76 | int r = auxresume(L, co, lua_gettop(L)); 77 | if (r < 0) { 78 | if (lua_isstring(L, -1)) { /* error object is a string? */ 79 | luaL_where(L, 1); /* add extra info */ 80 | lua_insert(L, -2); 81 | lua_concat(L, 2); 82 | } 83 | return lua_error(L); /* propagate error */ 84 | } 85 | return r; 86 | } 87 | 88 | 89 | static int luaB_cocreate (lua_State *L) { 90 | lua_State *NL; 91 | luaL_checktype(L, 1, LUA_TFUNCTION); 92 | NL = lua_newthread(L); 93 | lua_pushvalue(L, 1); /* move function to top */ 94 | lua_xmove(L, NL, 1); /* move function from L to NL */ 95 | return 1; 96 | } 97 | 98 | 99 | static int luaB_cowrap (lua_State *L) { 100 | luaB_cocreate(L); 101 | lua_pushcclosure(L, luaB_auxwrap, 1); 102 | return 1; 103 | } 104 | 105 | 106 | static int luaB_yield (lua_State *L) { 107 | return lua_yield(L, lua_gettop(L)); 108 | } 109 | 110 | 111 | static int luaB_costatus (lua_State *L) { 112 | lua_State *co = getco(L); 113 | if (L == co) lua_pushliteral(L, "running"); 114 | else { 115 | switch (lua_status(co)) { 116 | case LUA_YIELD: 117 | lua_pushliteral(L, "suspended"); 118 | break; 119 | case LUA_OK: { 120 | lua_Debug ar; 121 | if (lua_getstack(co, 0, &ar) > 0) /* does it have frames? */ 122 | lua_pushliteral(L, "normal"); /* it is running */ 123 | else if (lua_gettop(co) == 0) 124 | lua_pushliteral(L, "dead"); 125 | else 126 | lua_pushliteral(L, "suspended"); /* initial state */ 127 | break; 128 | } 129 | default: /* some error occurred */ 130 | lua_pushliteral(L, "dead"); 131 | break; 132 | } 133 | } 134 | return 1; 135 | } 136 | 137 | 138 | static int luaB_yieldable (lua_State *L) { 139 | lua_pushboolean(L, lua_isyieldable(L)); 140 | return 1; 141 | } 142 | 143 | 144 | static int luaB_corunning (lua_State *L) { 145 | int ismain = lua_pushthread(L); 146 | lua_pushboolean(L, ismain); 147 | return 2; 148 | } 149 | 150 | 151 | static const luaL_Reg co_funcs[] = { 152 | {"create", luaB_cocreate}, 153 | {"resume", luaB_coresume}, 154 | {"running", luaB_corunning}, 155 | {"status", luaB_costatus}, 156 | {"wrap", luaB_cowrap}, 157 | {"yield", luaB_yield}, 158 | {"isyieldable", luaB_yieldable}, 159 | {NULL, NULL} 160 | }; 161 | 162 | 163 | 164 | LUAMOD_API int luaopen_coroutine (lua_State *L) { 165 | luaL_newlib(L, co_funcs); 166 | return 1; 167 | } 168 | 169 | -------------------------------------------------------------------------------- /test/optim/replace_functions1.reference.ast: -------------------------------------------------------------------------------- 1 | 2 | { 3 | function 4 | { 5 | type{"float3"}, 6 | ID{"GetPosition"}, 7 | argument_list 8 | { 9 | argument 10 | { 11 | type{"float"}, 12 | ID{"x"} 13 | }, 14 | argument 15 | { 16 | type{"float"}, 17 | ID{"y"} 18 | }, 19 | argument 20 | { 21 | type{"float"}, 22 | ID{"z"} 23 | }, 24 | argument 25 | { 26 | type{"float"}, 27 | ID{"w"} 28 | } 29 | }, 30 | function_body 31 | { 32 | return 33 | { 34 | constructor 35 | { 36 | type{"float3"}, 37 | argument_expression_list 38 | { 39 | variable{"x"}, 40 | variable{"y"}, 41 | variable{"z"} 42 | } 43 | } 44 | } 45 | } 46 | }, 47 | function 48 | { 49 | type{"float4"}, 50 | ID{"GetPosition"}, 51 | argument_list 52 | { 53 | argument 54 | { 55 | type{"float"}, 56 | ID{"x"} 57 | }, 58 | argument 59 | { 60 | type{"float"}, 61 | ID{"y"} 62 | }, 63 | argument 64 | { 65 | type{"float"}, 66 | ID{"z"} 67 | } 68 | }, 69 | function_body 70 | { 71 | return 72 | { 73 | constructor 74 | { 75 | type{"float4"}, 76 | argument_expression_list 77 | { 78 | variable{"x"}, 79 | variable{"y"}, 80 | variable{"z"}, 81 | float_literal{"0.0f"} 82 | } 83 | } 84 | } 85 | } 86 | }, 87 | function 88 | { 89 | type{"float3"}, 90 | ID{"GetStrangePosition"}, 91 | argument_list 92 | { 93 | argument 94 | { 95 | type{"float"}, 96 | ID{"x"} 97 | }, 98 | argument 99 | { 100 | type{"float"}, 101 | ID{"y"} 102 | }, 103 | argument 104 | { 105 | type{"float"}, 106 | ID{"z"} 107 | } 108 | }, 109 | function_body 110 | { 111 | return 112 | { 113 | * 114 | { 115 | constructor 116 | { 117 | type{"float3"}, 118 | argument_expression_list 119 | { 120 | variable{"x"}, 121 | variable{"y"}, 122 | variable{"z"} 123 | } 124 | }, 125 | float_literal{"10.0f"} 126 | } 127 | } 128 | } 129 | }, 130 | function 131 | { 132 | type{"float3"}, 133 | ID{"GetPosition"}, 134 | argument_list 135 | { 136 | argument 137 | { 138 | type{"float"}, 139 | ID{"x"} 140 | }, 141 | argument 142 | { 143 | type{"float"}, 144 | ID{"y"} 145 | }, 146 | argument 147 | { 148 | type{"float"}, 149 | ID{"z"} 150 | } 151 | }, 152 | function_body 153 | { 154 | return 155 | { 156 | * 157 | { 158 | constructor 159 | { 160 | type{"float3"}, 161 | argument_expression_list 162 | { 163 | variable{"x"}, 164 | variable{"y"}, 165 | variable{"z"} 166 | } 167 | }, 168 | float_literal{"2.0f"} 169 | } 170 | } 171 | } 172 | } 173 | } -------------------------------------------------------------------------------- /src/utilities/argument_parser.lua: -------------------------------------------------------------------------------- 1 | ArgumentParser = {} 2 | 3 | function ArgumentParser:new() 4 | local instance = {} 5 | setmetatable( instance, self ) 6 | 7 | self.__index = self 8 | 9 | return instance 10 | end 11 | 12 | function ArgumentParser:GetParsedArguments( arguments ) 13 | 14 | --local result = {} 15 | local arg_item = { output_files = {}, constants_replacement = {}, hlsl_version = "9", optimize = true, export_sampler_filter_semantic = true, default_precision = "", replacement_files = {}, inline_replacement_functions = false } 16 | local previous_argument = "" 17 | 18 | for i, argument in ipairs( arguments ) do 19 | 20 | if string.sub( argument, 1, 1 ) == '-' then 21 | 22 | local arg_option = string.sub( argument, 2 ) 23 | 24 | if arg_option == 'o' or arg_option == 'c' then 25 | previous_argument = arg_option 26 | elseif arg_option == 'f' then 27 | if arg_item.force_language then 28 | error( "You cannot force another language before you give an input file", 1 ) 29 | end 30 | 31 | previous_argument = 'f' 32 | elseif arg_option == 'r' then 33 | if arg_item.replacement_file then 34 | error( "You cannot specify another replacement file before you give an input file", 1 ) 35 | end 36 | 37 | previous_argument = 'r' 38 | elseif arg_option == 'ri' then 39 | previous_argument = 'ri' 40 | arg_item.inline_replacement_functions = true 41 | elseif arg_option == 't' then 42 | if arg_item.technique then 43 | error( "You can specify only one technique for each input file", 1 ) 44 | end 45 | 46 | previous_argument = 't' 47 | elseif arg_option == 'optimization' then 48 | previous_argument = 'optimization' 49 | elseif arg_option == 'check' then 50 | previous_argument = 'check' 51 | elseif arg_option == 'default_precision' then 52 | previous_argument = 'default_precision' 53 | elseif arg_option == 'export_sampler_filter_semantic' then 54 | previous_argument = 'export_sampler_filter_semantic' 55 | elseif arg_option == 'hlsl_version' then 56 | previous_argument = 'hlsl_version' 57 | else 58 | previous_argument = 'UNSUPPORTED_ARGUMENT' 59 | end 60 | 61 | else 62 | 63 | if previous_argument == 'o' then 64 | table.insert( arg_item.output_files, argument ) 65 | elseif previous_argument == 'f' then 66 | arg_item.force_language = argument 67 | elseif previous_argument == 'r' then 68 | table.insert( arg_item.replacement_files, argument ) 69 | elseif previous_argument == 't' then 70 | arg_item.technique = argument 71 | elseif arg_item.input_file then 72 | error( "You can only specify another input file if you give an -o, -f or/and -r option before", 1 ) 73 | elseif previous_argument == 'c' then 74 | local constants_table = string.explode( argument, '=' ) 75 | 76 | arg_item.constants_replacement[ constants_table[ 1 ] ] = constants_table[ 2 ] 77 | elseif previous_argument == 'optimization' then 78 | arg_item.optimize = toboolean( argument ) 79 | elseif previous_argument == 'default_precision' then 80 | arg_item.default_precision = argument 81 | elseif previous_argument == 'export_sampler_filter_semantic' then 82 | arg_item.export_sampler_filter_semantic = toboolean( argument ) 83 | elseif previous_argument == 'hlsl_version' then 84 | arg_item.hlsl_version = argument 85 | elseif previous_argument == 'check' then 86 | arg_item.check_file = argument 87 | elseif previous_argument ~= "UNSUPPORTED_ARGUMENT" then 88 | arg_item.input_file = argument 89 | if #arg_item.output_files == 0 then 90 | table.insert( arg_item.output_files, 'console_output' ) 91 | end 92 | --table.insert( result, arg_item ) 93 | --arg_item = {} 94 | 95 | break 96 | end 97 | 98 | previous_argument = "" 99 | 100 | end 101 | end 102 | 103 | return arg_item 104 | 105 | end -------------------------------------------------------------------------------- /test/optim/constant_folding/if_condition.reference.ast: -------------------------------------------------------------------------------- 1 | 2 | { 3 | function 4 | { 5 | type{"float"}, 6 | ID{"if_true"}, 7 | argument_list 8 | { 9 | argument 10 | { 11 | type{"bool"}, 12 | ID{"a"} 13 | } 14 | }, 15 | function_body{block{return{float_literal{"1.0f"}}}} 16 | }, 17 | function 18 | { 19 | type{"float"}, 20 | ID{"else_if_true"}, 21 | argument_list 22 | { 23 | argument 24 | { 25 | type{"bool"}, 26 | ID{"a"} 27 | }, 28 | argument 29 | { 30 | type{"bool"}, 31 | ID{"b"} 32 | } 33 | }, 34 | function_body 35 | { 36 | if 37 | { 38 | if_block 39 | { 40 | variable{"a"}, 41 | block{return{float_literal{"1.0f"}}} 42 | }, 43 | else_block{block{return{float_literal{"2.0f"}}}} 44 | } 45 | } 46 | }, 47 | function 48 | { 49 | type{"float"}, 50 | ID{"else_if_2_true"}, 51 | argument_list 52 | { 53 | argument 54 | { 55 | type{"bool"}, 56 | ID{"a"} 57 | }, 58 | argument 59 | { 60 | type{"bool"}, 61 | ID{"b"} 62 | } 63 | }, 64 | function_body 65 | { 66 | if 67 | { 68 | if_block 69 | { 70 | variable{"a"}, 71 | block{return{float_literal{"1.0f"}}} 72 | }, 73 | else_if_block 74 | { 75 | variable{"b"}, 76 | block{return{float_literal{"2.0f"}}} 77 | }, 78 | else_block{block{return{float_literal{"3.0f"}}}} 79 | } 80 | } 81 | }, 82 | function 83 | { 84 | type{"float"}, 85 | ID{"if_false"}, 86 | argument_list 87 | { 88 | argument 89 | { 90 | type{"bool"}, 91 | ID{"a"} 92 | } 93 | }, 94 | function_body 95 | { 96 | if 97 | { 98 | if_block 99 | { 100 | variable{"a"}, 101 | block{return{float_literal{"2.0f"}}} 102 | }, 103 | else_block{block{return{float_literal{"3.0f"}}}} 104 | } 105 | } 106 | }, 107 | function 108 | { 109 | type{"float"}, 110 | ID{"else_if_false"}, 111 | argument_list 112 | { 113 | argument 114 | { 115 | type{"bool"}, 116 | ID{"a"} 117 | }, 118 | argument 119 | { 120 | type{"bool"}, 121 | ID{"b"} 122 | } 123 | }, 124 | function_body 125 | { 126 | if 127 | { 128 | if_block 129 | { 130 | variable{"a"}, 131 | block{return{float_literal{"1.0f"}}} 132 | }, 133 | else_if_block 134 | { 135 | variable{"b"}, 136 | block{return{float_literal{"3.0f"}}} 137 | }, 138 | else_block{block{return{float_literal{"4.0f"}}}} 139 | } 140 | } 141 | }, 142 | function 143 | { 144 | type{"float"}, 145 | ID{"else_if_2_false"}, 146 | argument_list 147 | { 148 | argument 149 | { 150 | type{"bool"}, 151 | ID{"a"} 152 | }, 153 | argument 154 | { 155 | type{"bool"}, 156 | ID{"b"} 157 | } 158 | }, 159 | function_body 160 | { 161 | if 162 | { 163 | if_block 164 | { 165 | variable{"a"}, 166 | block{return{float_literal{"1.0f"}}} 167 | }, 168 | else_if_block 169 | { 170 | variable{"b"}, 171 | block{return{float_literal{"2.0f"}}} 172 | }, 173 | else_block{block{return{float_literal{"4.0f"}}}} 174 | } 175 | } 176 | } 177 | } -------------------------------------------------------------------------------- /test/optim/clean_constants.reference.ast: -------------------------------------------------------------------------------- 1 | 2 | { 3 | variable_declaration 4 | { 5 | storage{}, 6 | modifier{}, 7 | type{"float"}, 8 | variable 9 | { 10 | "scalar_float_with_value", 11 | float_literal{"0.5f"} 12 | } 13 | }, 14 | struct_definition 15 | { 16 | "VS_OUTPUT", 17 | field 18 | { 19 | type{"float4"}, 20 | ID{"Position"}, 21 | semantic{"SV_POSITION"} 22 | }, 23 | field 24 | { 25 | type{"float4"}, 26 | ID{"Diffuse"}, 27 | semantic{"COLOR0"} 28 | }, 29 | field 30 | { 31 | type{"float2"}, 32 | ID{"TextureUV"}, 33 | semantic{"TEXCOORD0"} 34 | } 35 | }, 36 | function 37 | { 38 | type{"VS_OUTPUT"}, 39 | ID{"RenderSceneVS"}, 40 | argument_list 41 | { 42 | argument 43 | { 44 | type{"float4"}, 45 | ID{"vPos"}, 46 | semantic{"POSITION"} 47 | }, 48 | argument 49 | { 50 | type{"float3"}, 51 | ID{"vNormal"}, 52 | semantic{"NORMAL"} 53 | }, 54 | argument 55 | { 56 | type{"float2"}, 57 | ID{"vTexCoord0"}, 58 | semantic{"TEXCOORD"} 59 | }, 60 | argument 61 | { 62 | input_modifier{"uniform"}, 63 | type{"int"}, 64 | ID{"nNumLights"} 65 | }, 66 | argument 67 | { 68 | input_modifier{"uniform"}, 69 | type{"bool"}, 70 | ID{"bTexture"} 71 | }, 72 | argument 73 | { 74 | input_modifier{"uniform"}, 75 | type{"bool"}, 76 | ID{"bAnimate"} 77 | } 78 | }, 79 | function_body 80 | { 81 | variable_declaration 82 | { 83 | storage{}, 84 | modifier{}, 85 | type{"VS_OUTPUT"}, 86 | variable{"Output"} 87 | }, 88 | variable_declaration 89 | { 90 | storage{}, 91 | modifier{"const"}, 92 | type{"float"}, 93 | variable 94 | { 95 | "d", 96 | float_literal{"1.0"} 97 | } 98 | }, 99 | variable_declaration 100 | { 101 | storage{}, 102 | modifier{"const"}, 103 | type{"float"}, 104 | variable 105 | { 106 | "e", 107 | float_literal{"2.0"} 108 | } 109 | }, 110 | variable_declaration 111 | { 112 | storage{}, 113 | modifier{"const"}, 114 | type{"float"}, 115 | variable 116 | { 117 | "f", 118 | float_literal{"3.0"} 119 | } 120 | }, 121 | variable_declaration 122 | { 123 | storage{}, 124 | modifier{"const"}, 125 | type{"float"}, 126 | variable 127 | { 128 | "g", 129 | + 130 | { 131 | int_literal{"40"}, 132 | variable{"scalar_float_with_value"} 133 | } 134 | } 135 | }, 136 | =_statement 137 | { 138 | swizzle 139 | { 140 | postfix 141 | { 142 | variable{"output"}, 143 | variable{"Position"} 144 | }, 145 | "x" 146 | }, 147 | + 148 | { 149 | variable{"d"}, 150 | variable{"e"} 151 | } 152 | }, 153 | return{variable{"Output"}} 154 | } 155 | }, 156 | technique 157 | { 158 | "Default", 159 | pass 160 | { 161 | "P0", 162 | shader_call 163 | { 164 | "VertexShader", 165 | "vs_3_0", 166 | "RenderSceneVS", 167 | argument_expression_list 168 | { 169 | int_literal{"1"}, 170 | bool_literal{"true"}, 171 | bool_literal{"false"} 172 | } 173 | } 174 | } 175 | } 176 | } -------------------------------------------------------------------------------- /src/host/lua-5.3.0/src/lgc.h: -------------------------------------------------------------------------------- 1 | /* 2 | ** $Id: lgc.h,v 2.86 2014/10/25 11:50:46 roberto Exp $ 3 | ** Garbage Collector 4 | ** See Copyright Notice in lua.h 5 | */ 6 | 7 | #ifndef lgc_h 8 | #define lgc_h 9 | 10 | 11 | #include "lobject.h" 12 | #include "lstate.h" 13 | 14 | /* 15 | ** Collectable objects may have one of three colors: white, which 16 | ** means the object is not marked; gray, which means the 17 | ** object is marked, but its references may be not marked; and 18 | ** black, which means that the object and all its references are marked. 19 | ** The main invariant of the garbage collector, while marking objects, 20 | ** is that a black object can never point to a white one. Moreover, 21 | ** any gray object must be in a "gray list" (gray, grayagain, weak, 22 | ** allweak, ephemeron) so that it can be visited again before finishing 23 | ** the collection cycle. These lists have no meaning when the invariant 24 | ** is not being enforced (e.g., sweep phase). 25 | */ 26 | 27 | 28 | 29 | /* how much to allocate before next GC step */ 30 | #if !defined(GCSTEPSIZE) 31 | /* ~100 small strings */ 32 | #define GCSTEPSIZE (cast_int(100 * sizeof(TString))) 33 | #endif 34 | 35 | 36 | /* 37 | ** Possible states of the Garbage Collector 38 | */ 39 | #define GCSpropagate 0 40 | #define GCSatomic 1 41 | #define GCSswpallgc 2 42 | #define GCSswpfinobj 3 43 | #define GCSswptobefnz 4 44 | #define GCSswpend 5 45 | #define GCScallfin 6 46 | #define GCSpause 7 47 | 48 | 49 | #define issweepphase(g) \ 50 | (GCSswpallgc <= (g)->gcstate && (g)->gcstate <= GCSswpend) 51 | 52 | 53 | /* 54 | ** macro to tell when main invariant (white objects cannot point to black 55 | ** ones) must be kept. During a collection, the sweep 56 | ** phase may break the invariant, as objects turned white may point to 57 | ** still-black objects. The invariant is restored when sweep ends and 58 | ** all objects are white again. 59 | */ 60 | 61 | #define keepinvariant(g) ((g)->gcstate <= GCSatomic) 62 | 63 | 64 | /* 65 | ** some useful bit tricks 66 | */ 67 | #define resetbits(x,m) ((x) &= cast(lu_byte, ~(m))) 68 | #define setbits(x,m) ((x) |= (m)) 69 | #define testbits(x,m) ((x) & (m)) 70 | #define bitmask(b) (1<<(b)) 71 | #define bit2mask(b1,b2) (bitmask(b1) | bitmask(b2)) 72 | #define l_setbit(x,b) setbits(x, bitmask(b)) 73 | #define resetbit(x,b) resetbits(x, bitmask(b)) 74 | #define testbit(x,b) testbits(x, bitmask(b)) 75 | 76 | 77 | /* Layout for bit use in 'marked' field: */ 78 | #define WHITE0BIT 0 /* object is white (type 0) */ 79 | #define WHITE1BIT 1 /* object is white (type 1) */ 80 | #define BLACKBIT 2 /* object is black */ 81 | #define FINALIZEDBIT 3 /* object has been marked for finalization */ 82 | /* bit 7 is currently used by tests (luaL_checkmemory) */ 83 | 84 | #define WHITEBITS bit2mask(WHITE0BIT, WHITE1BIT) 85 | 86 | 87 | #define iswhite(x) testbits((x)->marked, WHITEBITS) 88 | #define isblack(x) testbit((x)->marked, BLACKBIT) 89 | #define isgray(x) /* neither white nor black */ \ 90 | (!testbits((x)->marked, WHITEBITS | bitmask(BLACKBIT))) 91 | 92 | #define tofinalize(x) testbit((x)->marked, FINALIZEDBIT) 93 | 94 | #define otherwhite(g) ((g)->currentwhite ^ WHITEBITS) 95 | #define isdeadm(ow,m) (!(((m) ^ WHITEBITS) & (ow))) 96 | #define isdead(g,v) isdeadm(otherwhite(g), (v)->marked) 97 | 98 | #define changewhite(x) ((x)->marked ^= WHITEBITS) 99 | #define gray2black(x) l_setbit((x)->marked, BLACKBIT) 100 | 101 | #define luaC_white(g) cast(lu_byte, (g)->currentwhite & WHITEBITS) 102 | 103 | 104 | #define luaC_condGC(L,c) \ 105 | {if (G(L)->GCdebt > 0) {c;}; condchangemem(L);} 106 | #define luaC_checkGC(L) luaC_condGC(L, luaC_step(L);) 107 | 108 | 109 | #define luaC_barrier(L,p,v) { \ 110 | if (iscollectable(v) && isblack(p) && iswhite(gcvalue(v))) \ 111 | luaC_barrier_(L,obj2gco(p),gcvalue(v)); } 112 | 113 | #define luaC_barrierback(L,p,v) { \ 114 | if (iscollectable(v) && isblack(p) && iswhite(gcvalue(v))) \ 115 | luaC_barrierback_(L,p); } 116 | 117 | #define luaC_objbarrier(L,p,o) { \ 118 | if (isblack(p) && iswhite(o)) \ 119 | luaC_barrier_(L,obj2gco(p),obj2gco(o)); } 120 | 121 | #define luaC_upvalbarrier(L,uv) \ 122 | { if (iscollectable((uv)->v) && !upisopen(uv)) \ 123 | luaC_upvalbarrier_(L,uv); } 124 | 125 | LUAI_FUNC void luaC_fix (lua_State *L, GCObject *o); 126 | LUAI_FUNC void luaC_freeallobjects (lua_State *L); 127 | LUAI_FUNC void luaC_step (lua_State *L); 128 | LUAI_FUNC void luaC_runtilstate (lua_State *L, int statesmask); 129 | LUAI_FUNC void luaC_fullgc (lua_State *L, int isemergency); 130 | LUAI_FUNC GCObject *luaC_newobj (lua_State *L, int tt, size_t sz); 131 | LUAI_FUNC void luaC_barrier_ (lua_State *L, GCObject *o, GCObject *v); 132 | LUAI_FUNC void luaC_barrierback_ (lua_State *L, Table *o); 133 | LUAI_FUNC void luaC_upvalbarrier_ (lua_State *L, UpVal *uv); 134 | LUAI_FUNC void luaC_checkfinalizer (lua_State *L, GCObject *o, Table *mt); 135 | LUAI_FUNC void luaC_upvdeccount (lua_State *L, UpVal *uv); 136 | 137 | 138 | #endif 139 | -------------------------------------------------------------------------------- /src/generator/generator_utils.lua: -------------------------------------------------------------------------------- 1 | local OperatorPrecedence = { 2 | 3 | ['/'] = 1, 4 | ['%'] = 1, 5 | ['*'] = 2, 6 | ['+'] = 3, 7 | ['-'] = 3, 8 | ['>>'] = 4, 9 | ['<<'] = 4, 10 | ['>'] = 5, 11 | ['<'] = 5, 12 | ['>='] = 5, 13 | ['<='] = 5, 14 | ['=='] = 6, 15 | ['!='] = 6, 16 | ['&'] = 7, 17 | ['^'] = 8, 18 | ['|'] = 9, 19 | ['&&'] = 11, 20 | ['||'] = 12, 21 | } 22 | 23 | 24 | function GetOperatorPrecedence( operator ) 25 | 26 | return OperatorPrecedence[ operator ] or 0 27 | end 28 | 29 | function GetDataByName( node, name, recursive ) 30 | if node.name and node.name == name then 31 | return node[ 1 ]; 32 | else 33 | if type( node ) == "table" then 34 | for _, child_node in ipairs( node ) do 35 | if child_node.name and child_node.name == name then 36 | return child_node[ 1 ]; 37 | end 38 | 39 | if recursive then 40 | local 41 | result; 42 | 43 | result = GetDataByName( child_node, name, recursive ); 44 | 45 | if result then 46 | return result; 47 | end 48 | end 49 | end 50 | end 51 | end 52 | 53 | return nil; 54 | end 55 | 56 | function GetCountOfType( node, type_name, recursive ) 57 | local 58 | count; 59 | 60 | count = 0; 61 | 62 | if type( node ) == "table" then 63 | for _, child_node in ipairs( node ) do 64 | if child_node.name and child_node.name == type_name then 65 | count = count + 1; 66 | end 67 | 68 | if recursive then 69 | count = count + GetCountOfType( child_node, type_name, resursive ); 70 | end 71 | end 72 | end 73 | 74 | return count; 75 | end 76 | 77 | function BruteForceFindValue( node, value ) 78 | if type( node ) == "table" then 79 | for k, child_node in pairs( node ) do 80 | if child_node == value then 81 | return true; 82 | else 83 | if child_node then 84 | if BruteForceFindValue( child_node, value ) then 85 | return true; 86 | end 87 | end 88 | end 89 | end 90 | else 91 | return node == value; 92 | end 93 | 94 | return false; 95 | end 96 | 97 | local function _GetNodeOfType( node, type_name, recursive ) 98 | local yield = coroutine.yield 99 | 100 | for index, child_node in ipairs( node ) do 101 | local 102 | child_node = node[ index ] 103 | 104 | if type( child_node ) == 'table' then 105 | if child_node.name == type_name then 106 | yield( child_node, index, node ) 107 | end 108 | 109 | if recursive then 110 | _GetNodeOfType( child_node, type_name, recursive ) 111 | end 112 | end 113 | end 114 | end 115 | 116 | function NodeOfType( node, type_name, recursive ) 117 | if recursive == nil then 118 | recursive = true 119 | end 120 | 121 | return coroutine.wrap(function() _GetNodeOfType( node, type_name, recursive ) end) 122 | end 123 | 124 | local function _GetInverseNodeOfType( node, type_name, recursive ) 125 | local yield = coroutine.yield 126 | 127 | for index=#node, 1, -1 do 128 | local 129 | child_node = node[ index ] 130 | 131 | if type( child_node ) == 'table' then 132 | if child_node.name == type_name then 133 | yield( child_node, index, node ) 134 | end 135 | 136 | if recursive then 137 | _GetInverseNodeOfType( child_node, type_name, recursive ) 138 | end 139 | end 140 | end 141 | end 142 | 143 | function InverseNodeOfType( node, type_name, recursive ) 144 | if recursive == nil then 145 | recursive = true; 146 | end 147 | 148 | return coroutine.wrap(function() _GetInverseNodeOfType( node, type_name, recursive ) end) 149 | end 150 | 151 | function GenerateAstFromFileName( file_name ) 152 | local 153 | ast; 154 | local 155 | extension = "" 156 | 157 | for index = string.len( file_name ), 1, -1 do 158 | local character = string.sub( file_name, index, index ) 159 | if character == '.' then 160 | extension = string.sub( file_name, index + 1 ) 161 | break 162 | end 163 | end 164 | 165 | if extension == "lua" or extension == "ssl" then 166 | ast = dofile( file_name ) 167 | elseif extension == "fx" then 168 | 169 | ast = ParseHLSL( file_name ) 170 | 171 | if ast == nil then 172 | error( "Fail to load hlsl code from " .. file_name ); 173 | end 174 | else 175 | error( "Unsupported file extension while trying to load " .. file_name ); 176 | end 177 | 178 | return ast; 179 | end 180 | -------------------------------------------------------------------------------- /contrib/antlr3memory.hpp: -------------------------------------------------------------------------------- 1 | #ifndef _ANTLR3MEMORY_HPP 2 | #define _ANTLR3MEMORY_HPP 3 | 4 | // [The "BSD licence"] 5 | // Copyright (c) 2005-2009 Gokulakannan Somasundaram, ElectronDB 6 | 7 | // 8 | // All rights reserved. 9 | // 10 | // Redistribution and use in source and binary forms, with or without 11 | // modification, are permitted provided that the following conditions 12 | // are met: 13 | // 1. Redistributions of source code must retain the above copyright 14 | // notice, this list of conditions and the following disclaimer. 15 | // 2. Redistributions in binary form must reproduce the above copyright 16 | // notice, this list of conditions and the following disclaimer in the 17 | // documentation and/or other materials provided with the distribution. 18 | // 3. The name of the author may not be used to endorse or promote products 19 | // derived from this software without specific prior written permission. 20 | // 21 | // THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR 22 | // IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES 23 | // OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. 24 | // IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, 25 | // INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT 26 | // NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 27 | // DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 28 | // THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 29 | // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF 30 | // THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 31 | 32 | #include 33 | 34 | #include 35 | #include 36 | #include 37 | #include 38 | #include 39 | 40 | #include "antlr3defs.hpp" 41 | 42 | ANTLR_BEGIN_NAMESPACE() 43 | 44 | class DefaultAllocPolicy 45 | { 46 | public: 47 | //limitation of c++. unable to write a typedef 48 | template 49 | class AllocatorType : public std::allocator 50 | { 51 | public: 52 | typedef TYPE value_type; 53 | typedef value_type* pointer; 54 | typedef const value_type* const_pointer; 55 | typedef value_type& reference; 56 | typedef const value_type& const_reference; 57 | typedef size_t size_type; 58 | typedef ptrdiff_t difference_type; 59 | template struct rebind { 60 | typedef AllocatorType other; 61 | }; 62 | 63 | AllocatorType() throw() {} 64 | AllocatorType( const AllocatorType& ) throw() {} 65 | template AllocatorType(const AllocatorType& ) throw(){} 66 | }; 67 | 68 | template 69 | class VectorType : public std::vector< TYPE, AllocatorType > 70 | { 71 | }; 72 | 73 | template 74 | class ListType : public std::deque< TYPE, AllocatorType > 75 | { 76 | }; 77 | 78 | template 79 | class StackType : public std::deque< TYPE, AllocatorType > 80 | { 81 | public: 82 | void push( const TYPE& elem ) { this->push_back(elem); } 83 | void pop() { this->pop_back(); } 84 | TYPE& peek() { return this->back(); } 85 | TYPE& top() { return this->back(); } 86 | const TYPE& peek() const { return this->back(); } 87 | const TYPE& top() const { return this->back(); } 88 | }; 89 | 90 | 91 | template 92 | class OrderedSetType : public std::set< TYPE, std::less, AllocatorType > 93 | { 94 | }; 95 | 96 | template 97 | class UnOrderedSetType : public std::set< TYPE, std::less, AllocatorType > 98 | { 99 | }; 100 | 101 | template 102 | class UnOrderedMapType : public std::map< KeyType, ValueType, std::less, 103 | AllocatorType > > 104 | { 105 | }; 106 | 107 | template 108 | class OrderedMapType : public std::map< KeyType, ValueType, std::less, 109 | AllocatorType > > 110 | { 111 | }; 112 | 113 | static void* operator new (std::size_t bytes) 114 | { 115 | void* p = alloc(bytes); 116 | return p; 117 | } 118 | static void* operator new (std::size_t , void* p) { return p; } 119 | static void* operator new[]( std::size_t bytes) 120 | { 121 | void* p = alloc(bytes); 122 | return p; 123 | } 124 | static void operator delete(void* p) 125 | { 126 | DefaultAllocPolicy::free(p); 127 | } 128 | static void operator delete(void* , void* ) {} //placement delete 129 | 130 | static void operator delete[](void* p) 131 | { 132 | DefaultAllocPolicy::free(p); 133 | } 134 | 135 | static void* alloc( std::size_t bytes ) 136 | { 137 | void* p = malloc(bytes); 138 | // if( p== NULL ) 139 | // throw std::bad_alloc(); 140 | return p; 141 | } 142 | 143 | static void* alloc0( std::size_t bytes ) 144 | { 145 | void* p = DefaultAllocPolicy::alloc(bytes); 146 | memset(p, 0, bytes ); 147 | return p; 148 | } 149 | 150 | static void free( void* p ) 151 | { 152 | return ::free(p); 153 | } 154 | 155 | static void* realloc(void *ptr, size_t size) 156 | { 157 | return ::realloc( ptr, size ); 158 | } 159 | }; 160 | 161 | ANTLR_END_NAMESPACE() 162 | 163 | #endif /* _ANTLR3MEMORY_H */ 164 | --------------------------------------------------------------------------------