1- using OwnLang . ast . lib ;
1+ using OwnLang . ast . lib ;
22using System ;
33using System . Collections . Generic ;
44using System . Linq ;
@@ -11,17 +11,72 @@ class AssignmentStatement : Statement
1111 {
1212 private string variable ;
1313 private Expression expression ;
14+ private bool isTypedef ;
15+ public Value value ;
1416
15- public AssignmentStatement ( string variable , Expression expression )
17+ public AssignmentStatement ( string variable , Expression expression , bool isTypedef = false )
1618 {
1719 this . variable = variable ;
1820 this . expression = expression ;
21+ this . isTypedef = isTypedef ;
1922 }
2023
2124 public void execute ( )
2225 {
23- // expression.eval()
24- Value result = expression . eval ( ) ;
26+ Value result ;
27+ if ( isTypedef )
28+ {
29+ if ( value is NumberValue )
30+ {
31+ result = ( NumberValue ) expression . eval ( ) ;
32+ Variables . set ( variable , result ) ;
33+ return ;
34+ }
35+ if ( value is BoolValue )
36+ {
37+ result = ( BoolValue ) expression . eval ( ) ;
38+ Variables . set ( variable , result ) ;
39+ return ;
40+ }
41+ if ( value is StringValue )
42+ {
43+ result = ( StringValue ) expression . eval ( ) ;
44+ Variables . set ( variable , result ) ;
45+ return ;
46+ }
47+ if ( value is EnumValue )
48+ {
49+ result = ( EnumValue ) expression . eval ( ) ;
50+ Variables . set ( variable , result ) ;
51+ return ;
52+ }
53+ if ( value is ObjectValue )
54+ {
55+ result = ( ObjectValue ) expression . eval ( ) ;
56+ Variables . set ( variable , result ) ;
57+ return ;
58+ }
59+ if ( value is ArrayValue )
60+ {
61+ result = ( ArrayValue ) expression . eval ( ) ;
62+ Variables . set ( variable , result ) ;
63+ return ;
64+ }
65+ if ( value is StackValue )
66+ {
67+ result = ( StackValue ) expression . eval ( ) ;
68+ Variables . set ( variable , result ) ;
69+ return ;
70+ }
71+ if ( value is DictionaryValue )
72+ {
73+ result = ( DictionaryValue ) expression . eval ( ) ;
74+ Variables . set ( variable , result ) ;
75+ return ;
76+ }
77+
78+ }
79+ result = expression . eval ( ) ;
2580 Variables . set ( variable , result ) ;
2681 }
2782
0 commit comments