@@ -36,7 +36,7 @@ public String toString() {
3636 @ Override
3737 public PiccodeValue execute (Integer frame ) {
3838
39- if (lhs instanceof IdentifierAst id && Context .modules . containsKey (id .text )) {
39+ if (lhs instanceof IdentifierAst id && Context .top . getValue (id .text ) != null && Context . top . getValue ( id . text ) instanceof PiccodeModule ) {
4040 var err = new PiccodeException (file , line , column , "Cannot access the module `" + id .text + "` using dot. Please use `::` instead" );
4141 err .frame = frame ;
4242 throw err ;
@@ -56,10 +56,6 @@ public PiccodeValue execute(Integer frame) {
5656 return processArrayIndexing (tupl .array (), rhs .execute (frame ), frame );
5757 }
5858
59- if (left instanceof PiccodeModule mod ) {
60- return process (new IdentifierAst (mod .name ), mod , frame );
61- }
62-
6359 if (!(left instanceof PiccodeObject )) {
6460 var err = new PiccodeException (file , line , column , "Invalid expression on the side of `.` : " + lhs + " has value " + left + " which is not an object" );
6561 err .frame = frame ;
@@ -112,70 +108,6 @@ public PiccodeValue execute(Integer frame) {
112108 return value ;
113109 }
114110
115- private PiccodeValue process (IdentifierAst id , PiccodeModule mod , Integer frame ) {
116- var ctx = frame == null
117- ? Context .top
118- : Context .getContextAt (frame );
119-
120- if (rhs instanceof IdentifierAst _id ) {
121- for (var node : mod .nodes ) {
122- if (node instanceof VarDecl vd && vd .name .equals (_id .text )) {
123- return node .execute (frame );
124- }
125- if (node instanceof FunctionAst func && func .name .equals (_id .text )) {
126- node .execute (frame );
127- var result = ctx .getValue (_id .text );
128- if (result == null ) {
129- var err = new PiccodeException (func .file , func .line , func .column , "Function `" + _id .text + "` is not defined" );
130- err .frame = frame ;
131- var nm = ctx .getSimilarName (_id .text );
132- if (nm != null && !nm .isEmpty ()) {
133- var note = new PiccodeException (func .file , func .line , func .column , "Maybe you meant `" + nm + "`" );
134- err .addNote (note );
135- }
136- throw err ;
137- }
138- return result ;
139- }
140- if (node instanceof ModuleAst _mod && _mod .name .equals (_id .text )) {
141- node .execute (frame );
142- return Context .modules .get (_id .text );
143- }
144- }
145-
146- var err = new PiccodeException (file , line , column , "No function or identifier " + _id .text + " found in module " + id .text );
147- err .frame = frame ;
148- throw err ;
149- }
150-
151- var call = (CallAst ) rhs ;
152-
153- if (!(call .expr instanceof IdentifierAst )) {
154- var err = new PiccodeException (file , line , column , "Invalid function reference in module access module " + id .text + ": " + call .expr );
155- err .frame = frame ;
156- throw err ;
157- }
158-
159- var _id = (IdentifierAst ) call .expr ;
160- for (var node : mod .nodes ) {
161- if (node instanceof VarDecl vd && vd .name .equals (_id .text )) {
162- return node .execute (frame );
163- }
164- if (node instanceof FunctionAst func && func .name .equals (_id .text )) {
165- node .execute (frame );
166- //return Context.top.getValue(_id.text);
167- return call .execute (frame );
168- }
169- if (node instanceof ModuleAst _mod && _mod .name .equals (_id .text )) {
170- node .execute (frame );
171- return Context .modules .get (_id .text );
172- }
173- }
174-
175- var err = new PiccodeException (file , line , column , "No function or identifier " + _id .text + " found in module " + id .text );
176- err .frame = frame ;
177- throw err ;
178- }
179111
180112 private PiccodeValue processArrayIndexing (PiccodeValue [] arr , PiccodeValue execute , Integer frame ) {
181113 if (!(execute instanceof PiccodeNumber )) {
0 commit comments