Skip to content

Commit dc5d27c

Browse files
Fix Value problem
1 parent 890f406 commit dc5d27c

File tree

4 files changed

+41
-14
lines changed

4 files changed

+41
-14
lines changed

EZCode/EZHelp.cs

Lines changed: 22 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
using static EZCodeLanguage.Parser;
22
using static EZCodeLanguage.Interpreter;
33
using System.Data;
4+
using System.Diagnostics;
45

56
namespace EZCodeLanguage
67
{
@@ -159,10 +160,10 @@ public object ObjectParse(object obj, object type, bool to_string, string arrayS
159160
object o = obj;
160161
do
161162
{
162-
string n = obj.ToString();
163+
object n = obj;
163164
o = obj;
164165
DataType data = DataType.GetType(type.ToString(), Interpreter.Classes);
165-
if (Interpreter.Vars.Any(x => x.Name == n)) Interpreter.Vars.FirstOrDefault(x => x.Name == n).DataType = data;
166+
if (Interpreter.Vars.Any(x => x.Name == n.ToString())) Interpreter.Vars.FirstOrDefault(x => x.Name == n.ToString()).DataType = data;
166167
obj = Interpreter.GetValue(n, data, arraySeperator);
167168
} while (obj != o);
168169
}
@@ -1129,5 +1130,24 @@ public string DateTimeDayOfWeek(object _time)
11291130
DateTime dateTime = DateTimeExtract(_time);
11301131
return dateTime.DayOfWeek.ToString();
11311132
}
1133+
public Stopwatch StopwatchStart()
1134+
{
1135+
return Stopwatch.StartNew();
1136+
}
1137+
public void StopwatchEnd(object _stopwatch)
1138+
{
1139+
Stopwatch stopwatch = (Stopwatch)ObjectParse(_stopwatch, "stopwatch");
1140+
stopwatch.Stop();
1141+
}
1142+
public float StopwatchElapsedSeconds(object _stopwatch)
1143+
{
1144+
Stopwatch stopwatch = (Stopwatch)ObjectParse(_stopwatch, "stopwatch");
1145+
return (float)stopwatch.Elapsed.TotalSeconds;
1146+
}
1147+
public float StopwatchElapsedMiliseconds(object _stopwatch)
1148+
{
1149+
Stopwatch stopwatch = (Stopwatch)ObjectParse(_stopwatch, "stopwatch");
1150+
return (float)stopwatch.Elapsed.TotalMilliseconds;
1151+
}
11321152
}
11331153
}

EZCode/Interpreter.cs

Lines changed: 6 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -268,7 +268,7 @@ public void Interperate(LineWithTokens[] LineTokens)
268268
{
269269
if (var.Value is Class || (var.DataType.ObjectClass != null && var.DataType.Type != DataType.Types._null))
270270
{
271-
Class c = var.Value is Class ? new Class(var.Value as Class) : new Class(var.DataType.ObjectClass);
271+
Class c = var.Value is Class ? var.Value as Class : var.DataType.ObjectClass;
272272

273273
if (c.Properties.Any(x => x.Name.ToLower() == "value"))
274274
c.Properties.FirstOrDefault(x => x.Name.ToLower() == "value").Value ??= var.Value;
@@ -290,15 +290,7 @@ public void Interperate(LineWithTokens[] LineTokens)
290290
object value = SingleLine(line);
291291
line.Tokens = backup_tokens;
292292
Methods = backupMethods;
293-
Vars = backupVars.Select(x =>
294-
{
295-
if (x.Name == var.Name)
296-
{
297-
var.Value = Vars.FirstOrDefault(x => x.Name.ToLower() == "value").Value;
298-
return var;
299-
}
300-
else return x;
301-
}).ToArray();
293+
Vars = backupVars;
302294
Return = value;
303295
}
304296
else
@@ -1299,6 +1291,10 @@ public object GetValue(object obj, DataType? type = null, string arraySeperator
12991291
DoClass(_c);
13001292
}
13011293
}
1294+
else if (v.Value is not null)
1295+
{
1296+
obj = v.Value;
1297+
}
13021298
}
13031299
else if (Methods.FirstOrDefault(x => x.Name == first) is Method m)
13041300
{

EZCode/Parser.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1145,7 +1145,7 @@ just trying to get string version of parts */
11451145
string[]? vars = null;
11461146
int skip = 1; // what to skip for the rest of the codeLine
11471147
// checks if there are any parameters and if the arrow '~>' is used. Similar to ':' in normal methods
1148-
if (parts.Length - 1 > 2 && parts[i + 2].ToString() == "~>")
1148+
if (parts.Length - 1 > i + 1 && parts[i + 2].ToString() == "~>")
11491149
{
11501150
// increment skip
11511151
skip++;

TestEnv/Code.ezcode

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,16 @@
11
include main, time
22

33
method start {
4-
print 'datetime dayofweek : 5/5/2024'
4+
stopwatch clock new
5+
clock start
6+
7+
int i new : 0
8+
loop 10 {
9+
i + 1
10+
print 'i'
11+
}
12+
dispose i
13+
14+
clock end
15+
print 'clock elapsed-seconds'
516
}

0 commit comments

Comments
 (0)