1616import org .piccode .ast .FunctionAst ;
1717import org .piccode .ast .IdentifierAst ;
1818import org .piccode .ast .ImportAst ;
19+ import org .piccode .ast .ImportModuleCreateAst ;
1920import org .piccode .ast .ModuleAst ;
2021import org .piccode .ast .PiccodeVisitor ;
2122import org .piccode .ast .ReturnAst ;
@@ -121,10 +122,13 @@ public static List<Ast> compileDeclarationsAndGetExpressions(String file, String
121122 prepareGlobalScope (file );
122123
123124 for (var stmt : result .nodes ) {
124- if ((stmt instanceof ImportAst ) || (stmt instanceof ModuleAst ) || (stmt instanceof FunctionAst )) {
125+ if ((stmt instanceof ImportAst )) {
126+ stmt .execute (null );
127+ } else if (stmt instanceof ImportModuleCreateAst ){
125128 stmt .execute (null );
126- } else {
127129 nodes .add (stmt );
130+ } else {
131+ stmt .execute (null );
128132 }
129133 }
130134
@@ -149,7 +153,7 @@ public static List<Ast> compileDeclarationsAndGetExpressions(String file, String
149153 return nodes ;
150154 }
151155 }
152- public static PiccodeValue execute (List <Ast > nodes ) {
156+ public static PiccodeValue execute (List <Ast > nodes , Boolean hasError ) {
153157 try {
154158 PiccodeValue res = new PiccodeUnit ();
155159 var has_main = false ;
@@ -172,30 +176,33 @@ public static PiccodeValue execute(List<Ast> nodes) {
172176 }
173177
174178 if (has_main ) {
175- var _result = new CallAst (new IdentifierAst ("main" ), List .of ()).execute (null );
176- return _result ;
179+ res = new CallAst (new IdentifierAst ("main" ), List .of ()).execute (null );
177180 }
178181
179182 Context .top .dropStackFrame ();
183+ hasError = false ;
180184 return res ;
181185 } catch (PiccodeReturnException ret ) {
182186 if (Context .top .getFramesCount () > 0 ) {
183187 Context .top .dropStackFrame ();
184188 }
189+ hasError = false ;
185190 return ret .value ;
186191 } catch (PiccodeException e ) {
187192 if (Context .top .getFramesCount () > 0 ) {
188193 Context .top .dropStackFrame ();
189194 }
190195 //Context.top.dropStackFrame();
191196 e .reportError (exitOnError );
197+ hasError = true ;
192198 //e.printStackTrace();
193199 return new PiccodeUnit ();
194200 } catch (Exception rte ) {
195201 if (Context .top .getFramesCount () > 0 ) {
196202 Context .top .dropStackFrame ();
197203 }
198204 rte .printStackTrace ();
205+ hasError = true ;
199206 return new PiccodeUnit ();
200207 }
201208 }
0 commit comments