From 23fc93e15ea74a26107b497edb27537985413b7e Mon Sep 17 00:00:00 2001 From: snaulX Date: Sun, 22 Sep 2019 19:10:09 +0300 Subject: [PATCH] Add ToStringExpression --- test/test.bld | 2 +- wolvm/Value.cs | 2 +- wolvm/VirtualMachine.cs | 3 ++- wolvm/expressions/ToStringExpression.cs | 17 +++++++++++++++++ 4 files changed, 21 insertions(+), 3 deletions(-) create mode 100644 wolvm/expressions/ToStringExpression.cs diff --git a/test/test.bld b/test/test.bld index dc49b3a..2f6572b 100644 --- a/test/test.bld +++ b/test/test.bld @@ -74,6 +74,6 @@ main { plus : <12:double>, <10:double>, <678:double>; @sum.#set : ( plus : <12:double>, <13:double> ) ; System.print : ; - #print : ( ParseDouble : @sum ) ; + #print : ( toString : @sum ) ; } end \ No newline at end of file diff --git a/wolvm/Value.cs b/wolvm/Value.cs index 3fcedb9..dcbd48e 100644 --- a/wolvm/Value.cs +++ b/wolvm/Value.cs @@ -69,7 +69,7 @@ public Value GetField(string name) } } - public bool CheckType(string name) => VirtualMachine.GetWolClass(name) == type ? true : false; //thanks C# for one-string functions)) + public bool CheckType(string name) => name == type.strtype ? true : false; //thanks C# for one-string functions)) public static Value GetSmallValue(string val, Value parent = null) { diff --git a/wolvm/VirtualMachine.cs b/wolvm/VirtualMachine.cs index d1aa169..f220451 100644 --- a/wolvm/VirtualMachine.cs +++ b/wolvm/VirtualMachine.cs @@ -25,7 +25,8 @@ public static class VirtualMachine { "ParseInt", new ParseIntExpression() }, { "set", new SetExpression() }, { "ParseDouble", new ParseDoubleExpression() }, - { "System.input", new InputExpression() } + { "System.input", new InputExpression() }, + { "toString", new ToStringExpression() } }; private static bool test = false; diff --git a/wolvm/expressions/ToStringExpression.cs b/wolvm/expressions/ToStringExpression.cs new file mode 100644 index 0000000..2fc8618 --- /dev/null +++ b/wolvm/expressions/ToStringExpression.cs @@ -0,0 +1,17 @@ +using System; +using System.Collections.Generic; +using System.Text; + +namespace wolvm +{ + public class ToStringExpression : VMExpression + { + public Value ParseExpression(params Value[] args) + { + Value val = args[0]; + if (val.CheckType("double")) return new Value(new wolString(((wolDouble)val.type).value.ToString())); + else if (val.CheckType("int")) return new Value(new wolString(((wolInt)val.type).value.ToString())); + else return new Value(new wolString(System.Text.RegularExpressions.Regex.Escape(val.type.strtype))); + } + } +}