1212 */
1313
1414import { HeadFn } from "./exprs/basicFunctions/head" ;
15+ import { IsEmptyFn } from "./exprs/basicFunctions/isEmpty" ;
1516import { Length } from "./exprs/basicFunctions/len" ;
1617import { PushFn } from "./exprs/basicFunctions/push" ;
1718import { Puts } from "./exprs/basicFunctions/puts" ;
@@ -60,26 +61,29 @@ class ExecutionContext {
6061 setVariable ( name : string , val : any ) {
6162 const mp = this . getTop ( ) ;
6263 if ( mp . has ( name ) ) {
63- throw new Error ( `Variable ${ name } is already declared` ) ;
64+ throw new Error ( `Runtime Error: Variable ${ name } is already declared` ) ;
6465 }
6566 if ( this . basic . has ( name ) ) {
66- throw new Error ( `Cannot Declare builtin function: ${ name } ` ) ;
67+ throw new Error ( `Runtime Error: Cannot Declare builtin function: ${ name } ` ) ;
6768 }
6869 mp . set ( name , val ) ;
6970 }
7071 setForce ( name : string , val : any ) {
7172 if ( this . isBuiltin ( name ) ) {
72- throw new Error ( `Cannot set builtin function ${ name } as arguments` ) ;
73+ throw new Error ( `Runtime Error: Cannot set builtin function ${ name } as arguments` ) ;
7374 }
7475 const mp = this . getTop ( ) ;
7576 mp . set ( name , val ) ;
7677 }
7778 getVariable ( name : string ) {
7879 const mp = this . getTop ( ) ;
7980 if ( ! mp . has ( name ) && ! this . basic . has ( name ) ) {
80- throw new Error ( `Variable ${ name } is not declared` ) ;
81+ throw new Error ( `Runtime Error: Variable ${ name } is not declared` ) ;
8182 }
82- return mp . get ( name ) || this . basic . get ( name ) ! ;
83+ if ( mp . has ( name ) ) {
84+ return mp . get ( name ) ! ;
85+ }
86+ return this . basic . get ( name ) ! ;
8387 }
8488 constructor ( ) {
8589 this . stack = new Stack < Map < string , any > > ( ) ;
@@ -90,6 +94,7 @@ class ExecutionContext {
9094 this . basic . set ( "head" , HeadFn . create ( ) ) ;
9195 this . basic . set ( "tail" , TailFn . create ( ) ) ;
9296 this . basic . set ( 'puts' , Puts . create ( ) ) ;
97+ this . basic . set ( 'isEmpty' , IsEmptyFn . create ( ) ) ;
9398 }
9499 isBuiltin ( str : string ) : boolean {
95100 return this . basic . has ( str ) ;
0 commit comments