예제 #1
0
        private int RunDirect()
        {
            var input = cmda.GetStringDefault("file", null);

            if (string.IsNullOrWhiteSpace(input) || !File.Exists(input))
            {
                return(Fail("Please specify a valid input file"));
            }

            try
            {
                string inputCode = File.ReadAllText(input);
                var    parser    = new TextFungeParser();

                var prog = parser.GenerateAst(inputCode);
                var env  = new RunnerEnvironment();

                prog.RunDirect(env, TextFungeParser.ExtractDisplayFromTFFormat(inputCode));

                return(0);
            }
            catch (BefunGenException ex)
            {
                return(Fail("Error while compiling:\n\n" + ex));
            }
            catch (Exception ex)
            {
                return(Fail("Internal error:\n\n" + ex));
            }
        }
예제 #2
0
        private int RunCompile()
        {
            Console.WriteLine();
            Console.WriteLine("" + _title + " (c) Mike Schwoerer @ mikescher.com");

            var input = cmda.GetStringDefault("file", null);

            if (string.IsNullOrWhiteSpace(input) || !File.Exists(input))
            {
                return(Fail("Please specify a valid input file"));
            }

            var output = cmda.GetStringDefault("out", Path.ChangeExtension(input, "b93"));

            if (string.IsNullOrWhiteSpace(input))
            {
                return(Fail("Please specify a valid output file"));
            }

            ASTObject.CGO = new CodeGenOptions
            {
                NumberLiteralRepresentation = cmda.GetEnumDefault("numrep", NumberRep.Best),
                SetNOPCellsToCustom         = cmda.GetBoolDefault("specnop", false),

                DefaultNumeralValue   = (byte)cmda.GetUIntDefaultRange("init_number", 0, 0, 255),
                DefaultCharacterValue = (char)cmda.GetUIntDefaultRange("init_char", ' ', 0, 255),
                DefaultBooleanValue   = cmda.GetBoolDefault("init_bool", false),

                StripDoubleStringmodeToogle    = cmda.GetBoolDefault("o_stringmode", true),
                CompressHorizontalCombining    = cmda.GetBoolDefault("o_compresshorz", true),
                CompressVerticalCombining      = cmda.GetBoolDefault("o_compressvert", true),
                CompileTimeEvaluateExpressions = cmda.GetBoolDefault("o_staticexpr", true),
                RemUnreferencedMethods         = cmda.GetBoolDefault("o_unused", true),

                ExtendedBooleanCast = cmda.GetBoolDefault("safe_boolcast", false),
                DisplayModuloAccess = cmda.GetBoolDefault("safe_displacc", false),

                DefaultVarDeclarationWidth = cmda.GetIntDefaultRange("varwidthmin", 16, 0, 2048),

                DefaultDisplayValue    = (char)cmda.GetUIntDefaultRange("displ_char", ' ', 0, 255),
                DisplayBorder          = (char)cmda.GetUIntDefaultRange("displ_borderchar", '#', 0, 255),
                DisplayBorderThickness = cmda.GetIntDefaultRange("displ_borderwidth", 1, 0, 128),

                DefaultVarDeclarationSymbol = (char)cmda.GetUIntDefaultRange("chr_vardecl", ' ', 0, 255),
                DefaultTempSymbol           = (char)cmda.GetUIntDefaultRange("chr_tmpdecl", ' ', 0, 255),
                DefaultResultTempSymbol     = (char)cmda.GetUIntDefaultRange("chr_tempresult", ' ', 0, 255),
                CustomNOPSymbol             = (char)cmda.GetUIntDefaultRange("chr_nop", '@', 0, 255)
            };

            try
            {
                Console.Out.WriteLine("Reading from " + Path.GetFullPath(input));
                string inputCode = File.ReadAllText(input);

                var parser = new TextFungeParser();

                string outputCode = parser.GenerateCode(inputCode, TextFungeParser.ExtractDisplayFromTFFormat(inputCode), cmda.IsSet("debug"));

                Console.Out.WriteLine("Writing to " + Path.GetFullPath(output));
                File.WriteAllText(output, outputCode, Encoding.UTF8);

                return(0);
            }
            catch (BefunGenException ex)
            {
                return(Fail("Error while compiling:\n\n" + ex));
            }
            catch (Exception ex)
            {
                return(Fail("Internal error:\n\n" + ex));
            }
        }