* Bug fixes gscript

Fri, 13 Feb 2015 11:02:15 +0200

author
cemkalyoncu
date
Fri, 13 Feb 2015 11:02:15 +0200
branch
gscript
changeset 626
5a1c61c1bd0d
parent 625
dbefa4e69a01
child 627
baaf20034d1b

* Bug fixes
* Better svg view control

Source/Scripting/Compilers.h file | annotate | diff | comparison | revisions
Source/Scripting/Compilers/AST.cpp file | annotate | diff | comparison | revisions
Source/Scripting/Compilers/IL.cpp file | annotate | diff | comparison | revisions
Source/Scripting/Compilers/PD.cpp file | annotate | diff | comparison | revisions
Source/Scripting/Scripting.cpp file | annotate | diff | comparison | revisions
Testing/Source/Manual/Generic.cpp file | annotate | diff | comparison | revisions
--- a/Source/Scripting/Compilers.h	Fri Feb 13 10:25:05 2015 +0200
+++ b/Source/Scripting/Compilers.h	Fri Feb 13 11:02:15 2015 +0200
@@ -54,7 +54,7 @@
 		
 		void eatwhite(const std::string &input, int &ch);
 		
-		void jinst(std::string input, int ch);
+		void jinst(std::string input, int &ch);
 	};
 
 	/// Programming dialect compiler
--- a/Source/Scripting/Compilers/AST.cpp	Fri Feb 13 10:25:05 2015 +0200
+++ b/Source/Scripting/Compilers/AST.cpp	Fri Feb 13 11:02:15 2015 +0200
@@ -417,27 +417,33 @@
 		else if(tree->Type==ASTNode::FunctionCall || tree->Type==ASTNode::MethodCall) {
 			auto v=compilevalue(*tree, list, tempind, false);
 		}
+		
 		//Keyword call
 		else if(tree->Type==ASTNode::Keyword) {
-			Instruction instmark, inst;
-			
-			//Mark the start of the keyword
-			instmark.Type=InstructionType::Mark;
-			instmark.Name.Name=tree->Text;
-			list.push_back(instmark);
-			
-			//Call the keyword as a function
-			inst.Type=InstructionType::FunctionCall;
-			inst.Name.SetStringLiteral(tree->Text);
-			
-			//keywords do not have return values
-			inst.Store=0;
-			
-			//parameters
-			for(auto &p : tree->Leaves) {
-				inst.Parameters.push_back(compilevalue(p, list, tempind));
-			}
-			list.push_back(inst);
+// 			if(tree->Text=="if") {
+// 				
+// 			}
+// 			else {
+				Instruction instmark, inst;
+				
+				//Mark the start of the keyword
+				instmark.Type=InstructionType::Mark;
+				instmark.Name.Name=tree->Text;
+				list.push_back(instmark);
+				
+				//Call the keyword as a function
+				inst.Type=InstructionType::FunctionCall;
+				inst.Name.SetStringLiteral(tree->Text);
+				
+				//keywords do not have return values
+				inst.Store=0;
+				
+				//parameters
+				for(auto &p : tree->Leaves) {
+					inst.Parameters.push_back(compilevalue(p, list, tempind));
+				}
+				list.push_back(inst);
+// 			}
 		}
 		else {
 			ASSERT(false, "Unknown top level AST Node");
--- a/Source/Scripting/Compilers/IL.cpp	Fri Feb 13 10:25:05 2015 +0200
+++ b/Source/Scripting/Compilers/IL.cpp	Fri Feb 13 11:02:15 2015 +0200
@@ -181,6 +181,7 @@
 				
 			case 6:
 				this->jinst(input, ch);
+				break;
 		}
 		
 		eatwhite(input, ch);
@@ -243,7 +244,7 @@
 		}
 	}			
 	
-	void Intermediate::jinst(std::string input, int ch) {
+	void Intermediate::jinst(std::string input, int &ch) {
 		List.resize(List.size()+1);
 		auto &inst=List.back();
 		auto type=CheckInputFor(input, ch, 'a', 't', 'f');
--- a/Source/Scripting/Compilers/PD.cpp	Fri Feb 13 10:25:05 2015 +0200
+++ b/Source/Scripting/Compilers/PD.cpp	Fri Feb 13 11:02:15 2015 +0200
@@ -16,10 +16,11 @@
 #	include "../../Console.h"
 #endif
 
+
 ///@cond INTERNAL
 
 namespace Gorgon { namespace Scripting { namespace Compilers {
-
+	bool showsvg__=false;
 	namespace {
 
 		struct Token {
@@ -66,7 +67,10 @@
 					case Float:
 						return Data(Types::Float(), String::To<float>(repr));
 					case Bool:
-						return Data(Types::Bool(), String::To<bool>(repr));
+						if(repr=="true")
+							return Data(Types::Bool(), true);
+						else 
+							return Data(Types::Bool(), String::To<bool>(repr));
 					case String:
 						return Data(Types::String(), repr);
 					default:
@@ -967,7 +971,8 @@
 				strlines.push_back(Disassemble(&(*it)));
 			}
 			
-			ASTToSVG(input, *ret, strlines, true);
+			if(showsvg__)
+				ASTToSVG(input, *ret, strlines, true);
 			
 		}
 		
--- a/Source/Scripting/Scripting.cpp	Fri Feb 13 10:25:05 2015 +0200
+++ b/Source/Scripting/Scripting.cpp	Fri Feb 13 11:02:15 2015 +0200
@@ -46,8 +46,12 @@
 		switch(provider.GetDialect()) {
 		case InputProvider::Intermediate:
 			parser=new Compilers::Intermediate();
+			break;
 		case InputProvider::Programming:
 			parser=new Compilers::Programming();
+			break;
+		default:
+			Utils::ASSERT_FALSE("Unknown dialect");
 		}
 	}
 
--- a/Testing/Source/Manual/Generic.cpp	Fri Feb 13 10:25:05 2015 +0200
+++ b/Testing/Source/Manual/Generic.cpp	Fri Feb 13 11:02:15 2015 +0200
@@ -1,5 +1,6 @@
 #include <Source/Scripting.h>
 #include <Source/Scripting/VirtualMachine.h>
+#include <Source/Scripting/Embedding.h>
 #include <thread>
 #include <iostream>
 #include "../../../Source/Scripting/VirtualMachine.h"
@@ -7,8 +8,8 @@
 
 using namespace Gorgon::Scripting;
 
-const std::string source = 
-R"(
+const std::string source = "";
+/*R"(
 	a=4
 	b=6
 	if a>b
@@ -18,10 +19,11 @@
 	end
 )";
 
-/*R"(# $a = 4;
+R"(# $a = 4;
+
 $"a" = i"4"
-
-."1" = fns"help" !"type"
+#ja"5"
+."1" = fms"help" !"type"
 fns"echo" s""
 fns"echo" s"Type help" 
 fns"echo" ."1"
@@ -34,11 +36,11 @@
 
 $"i" = i"1"
 fkm"while"
-."1" = fns"<" $"i" i"5"
+."1" = fms"<" $"i" i"5"
 fns"while" ."1"
 	fns"echo" $"i"
 
-	."1" = fns"+" $"i" i"1"
+	."1" = fms"+" $"i" i"1"
 	$"i" = ."1"
 	
 	#fns"break"
@@ -65,7 +67,7 @@
 mms"[]" !"float" f"5" f"7"
 
 # echo "3=pi ? " + (3=pi)
-."1" = fns"=" i"3" !"pi"
+."1" = fms"=" i"3" !"pi"
 ."2" = fms"+" s"3=pi ? " ."1"
 fns"echo" s"The result is " ."2"
 x"1"
@@ -97,8 +99,16 @@
 # end
 fkm"end"
 fns"end"
+fns"return"
+)";*/
 
-)";*/
+namespace Gorgon { namespace Scripting { namespace Compilers {
+	extern bool showsvg__;
+} } }
+
+void togglesvg() {
+	Compilers::showsvg__=!Compilers::showsvg__;
+}
 
 namespace Gorgon { namespace Geometry {
 	extern Scripting::Library LibGeometry;
@@ -115,6 +125,13 @@
 	VirtualMachine vm;
 	Gorgon::Geometry::init_scripting();
 	vm.AddLibrary(Gorgon::Geometry::LibGeometry);
+	
+	Library mylib;
+	mylib.AddFunctions({
+		new MappedFunction("svg", "", nullptr, nullptr, ParameterList{}, 
+						   MappedFunctions(togglesvg), MappedMethods(), KeywordTag)
+	});
+	vm.AddLibrary(mylib);
 
 	std::cout<<std::endl<<std::endl;
 	Gorgon::Console::SetBold();

mercurial