Fixed warnings that showed up when compiling for mono. Added Makefile and list of...
authorMichael Welch <michaelgwelch@gmail.com>
Thu, 1 Feb 2007 03:17:36 +0000 (03:17 +0000)
committerMichael Welch <michaelgwelch@gmail.com>
Thu, 1 Feb 2007 03:17:36 +0000 (03:17 +0000)
mbasic/ArrayElement.cs
mbasic/Makefile [new file with mode: 0644]
mbasic/Parser.cs
mbasic/Program.cs
mbasic/SyntaxTree/Function.cs
mbasic/mbasic.exe.sources [new file with mode: 0644]

index 9f18edc..347e5ff 100644 (file)
@@ -9,7 +9,6 @@ namespace mbasic
 {
     class ArrayElement : Location
     {
-        static readonly Type builtInsType = typeof(BuiltIns);
         VariableLocation location;
         Expression[] exprs;
         MethodInfo getMethod; // The Get method for string or number array
@@ -20,44 +19,30 @@ namespace mbasic
             this.exprs = exprs;
         }
 
-        public override void ConstrainType(SymbolTable symbols, bool isArray, int numDimensions)
+        public override void ConstrainType(SymbolTable symbols, 
+            bool isArray, int numDimensions)
         {
             location.ConstrainType(symbols, true, exprs.Length);
             foreach (Expression expr in exprs)
             {
                 BasicType indexType = expr.GetBasicType();
-                if (indexType != BasicType.Number && indexType != BasicType.Boolean) throw new Exception("type error");
+                if (indexType != BasicType.Number && 
+                    indexType != BasicType.Boolean) 
+                    throw new Exception("type error");
             }
-
-
-            switch (exprs.Length)
+            string commas = new String(',', exprs.Length - 1);
+            Type t;
+            if (location.BasicType == BasicType.StringArray) 
+            {
+                t = Type.GetType("System.String[" + commas + "]");
+            }
+            else 
             {
-                case 1:
-                    getMethod = (location.BasicType == BasicType.StringArray) ?
-                        builtInsType.GetMethod("GetStringValue1") :
-                        builtInsType.GetMethod("GetNumberValue1");
-                    setMethod = (location.BasicType == BasicType.StringArray) ?
-                        builtInsType.GetMethod("SetStringValue1") :
-                        builtInsType.GetMethod("SetNumberValue1");
-                    break;
-                case 2:
-                    getMethod = (location.BasicType == BasicType.StringArray) ?
-                        builtInsType.GetMethod("GetStringValue2") :
-                        builtInsType.GetMethod("GetNumberValue2");
-                    setMethod = (location.BasicType == BasicType.StringArray) ?
-                        builtInsType.GetMethod("SetStringValue2") :
-                        builtInsType.GetMethod("SetNumberValue2");
-                    break;
-                case 3:
-                    getMethod = (location.BasicType == BasicType.StringArray) ?
-                        builtInsType.GetMethod("GetStringValue3") :
-                        builtInsType.GetMethod("GetNumberValue3");
-                    setMethod = (location.BasicType == BasicType.StringArray) ?
-                        builtInsType.GetMethod("SetStringValue3") :
-                        builtInsType.GetMethod("SetNumberValue3");
-                    break;
+                t = Type.GetType("System.Double[" + commas + "]");
             }
 
+            getMethod = t.GetMethod("Get");
+            setMethod = t.GetMethod("Set");
         }
 
         public override mbasic.SyntaxTree.BasicType BasicType
@@ -78,7 +63,8 @@ namespace mbasic
 
 
 
-        public override void EmitStore(ILGenerator gen, List<LocalBuilder> locals, Expression value)
+        public override void EmitStore(ILGenerator gen, 
+            List<LocalBuilder> locals, Expression value)
         {
             this.location.EmitLoad(gen, locals);
             foreach (Expression expr in exprs)
diff --git a/mbasic/Makefile b/mbasic/Makefile
new file mode 100644 (file)
index 0000000..644acd9
--- /dev/null
@@ -0,0 +1,7 @@
+sources := mbasic.exe.sources
+MCS := gmcs
+OUTPUTDIR := ../bin
+
+.PHONY: all
+all: $(sources)
+       $(MCS) -debug -r:$(OUTPUTDIR)/TiBasicRuntime.dll -out:$(OUTPUTDIR)/mbasic.exe @$< 
index 65bf949..bd2729d 100644 (file)
@@ -35,12 +35,10 @@ namespace mbasic
         public Lexer lexer;
         SortedList<string, object[]> data;
         Token lookahead;
-        SymbolTable symbols;
         public Parser(Stream stream, SymbolTable symbols, SortedList<string, object[]> data)
         {
             lexer = new Lexer(stream, symbols);
             this.data = data;
-            this.symbols = symbols;
         }
 
         public Statement Parse()
@@ -171,7 +169,6 @@ namespace mbasic
             }
             Match(Token.RightParen);
             
-            //symbols[index].Dimension(dimension);
 
             return new ArrayDeclaration(index, dimensions.ToArray());
         }
@@ -701,7 +698,6 @@ namespace mbasic
 
 
 
-        private void Error() { throw new Exception("Error during parsing"); }
 
         private Statement ForStatement()
         {
@@ -720,7 +716,6 @@ namespace mbasic
 
             Match(Token.EndOfLine);
 
-            LineId blockStart = lexer.LineId;
             Block block = Block(Token.Next);
 
             LineId endLine = lexer.LineId;  // This is the line that the NEXT keyword is used on
index 24dea74..bb86268 100644 (file)
@@ -42,7 +42,7 @@ namespace mbasic
         static void Main(string[] args)
         {
             bool debug = true;
-            bool runit = true;
+            bool runit = false;
 
             string fileName = args[0];
             string assemblyName = Path.GetFileNameWithoutExtension(fileName);
index faff1b0..a83f37b 100644 (file)
@@ -29,7 +29,6 @@ namespace mbasic.SyntaxTree
 {
     class Function : Expression
     {
-        private static readonly Type stringType = typeof(string);
         private static readonly Type numberType = typeof(double);
         private static readonly Type builtinsType = typeof(BuiltIns);
         private static readonly MethodInfo rndMethod =
diff --git a/mbasic/mbasic.exe.sources b/mbasic/mbasic.exe.sources
new file mode 100644 (file)
index 0000000..977e238
--- /dev/null
@@ -0,0 +1,50 @@
+ArrayElement.cs
+Lexer.cs
+LineId.cs
+Location.cs
+Parser.cs
+Program.cs
+SymbolTable.cs
+Token.cs
+Variable.cs
+VariableLocation.cs
+SyntaxTree/Add.cs
+SyntaxTree/ArrayDeclaration.cs
+SyntaxTree/Assign.cs
+SyntaxTree/BasicType.cs
+SyntaxTree/BinaryOperator.cs
+SyntaxTree/Block.cs
+SyntaxTree/BuiltInsMethodCall.cs
+SyntaxTree/Concatenate.cs
+SyntaxTree/Data.cs
+SyntaxTree/Division.cs
+SyntaxTree/End.cs
+SyntaxTree/Equals.cs
+SyntaxTree/Expression.cs
+SyntaxTree/For.cs
+SyntaxTree/Function.cs
+SyntaxTree/Gosub.cs
+SyntaxTree/Goto.cs
+SyntaxTree/GreaterThan.cs
+SyntaxTree/If.cs
+SyntaxTree/Input.cs
+SyntaxTree/LessThan.cs
+SyntaxTree/Multiply.cs
+SyntaxTree/Negative.cs
+SyntaxTree/Node.cs
+SyntaxTree/NumberLiteral.cs
+SyntaxTree/OptionBaseStatement.cs
+SyntaxTree/Power.cs
+SyntaxTree/Print.cs
+SyntaxTree/Randomize.cs
+SyntaxTree/Read.cs
+SyntaxTree/RelationalExpression.cs
+SyntaxTree/Remark.cs
+SyntaxTree/Restore.cs
+SyntaxTree/Return.cs
+SyntaxTree/Statement.cs
+SyntaxTree/StringLiteral.cs
+SyntaxTree/Subroutine.cs
+SyntaxTree/Subtract.cs
+SyntaxTree/Tab.cs
+SyntaxTree/VariableReference.cs