@@ -63,17 +63,27 @@ public ScriptContext visitAssignment_statement(ntsParser.Assignment_statementCon
6363 @ Override
6464 public ScriptContext visitGetField_statement (ntsParser .GetField_statementContext ctx ) {
6565 String fieldName = ctx .field .getText ();
66- Variable variable = scriptContext .getVariable (ctx .fieldOwner .getText ()).orElseThrow (() -> new RuntimeException ("Unknown variable " + ctx .fieldOwner .getText ()));
66+ String fieldOwnerName = ctx .fieldOwner .getText ();
67+
68+ Optional <Variable > variableOptional = scriptContext .getVariable (ctx .fieldOwner .getText ());
69+
70+ if (variableOptional .isEmpty ()) {
71+ Enum enumValue = scriptContext .getEnumValue (fieldOwnerName , fieldName );
72+ addInsn (FieldAccess .forEnumeration (new EnumerationDescription .ForLoadedEnumeration (enumValue )));
73+ return scriptContext ;
74+ }
75+
76+
77+ Variable variable = variableOptional .get ();
6778 addInsn (variable .load ());
68- String variableName = ctx .fieldOwner .getText ();
6979
7080 Variable c = scriptContext .currentScope ().lastVariableOnStack ;
7181
7282 //when we accessing function param
7383 if (c == null ) {
7484 c = scriptContext .currentScope ().findVariable (ctx .fieldOwner .getText ());
7585 }
76- Variable fieldOwner = scriptContext .getVariable (variableName ).get ();
86+ Variable fieldOwner = scriptContext .getVariable (fieldOwnerName ).get ();
7787
7888 try {
7989 Field field = fieldOwner .getRuntimeType ().getField (fieldName );
@@ -222,8 +232,9 @@ public ScriptContext visitReturn_statement(ntsParser.Return_statementContext ctx
222232 var rtype = ctx .rval ();
223233
224234
225- if (rtype .type_enum () != null || rtype .type_literal () != null ) {
235+ if (rtype .getField_statement () != null || rtype .type_literal () != null ) {
226236 visitChildren (rtype );
237+ //todo enum or field rimirive from field
227238 addInsn (MethodReturn .REFERENCE );
228239
229240 } else if (rtype .type_bool () != null ) {
@@ -239,15 +250,6 @@ public ScriptContext visitReturn_statement(ntsParser.Return_statementContext ctx
239250 return scriptContext ;
240251 }
241252
242- @ Override
243- public ScriptContext visitType_enum (ntsParser .Type_enumContext ctx ) {
244- String type = ctx .type .getText ();
245- String value = ctx .value .getText ();
246- Enum enumValue = scriptContext .getEnumValue (type , value );
247- addInsn (FieldAccess .forEnumeration (new EnumerationDescription .ForLoadedEnumeration (enumValue )));
248- return scriptContext ;
249- }
250-
251253 @ Override
252254 public ScriptContext visitFunction_call (ntsParser .Function_callContext ctx ) {
253255 String line = ctx .getText ();
0 commit comments