Add StackOver/UnderFlow
This commit is contained in:
@@ -176,8 +176,7 @@ class VM
|
|||||||
{
|
{
|
||||||
if(stacki >= this.stack.length)
|
if(stacki >= this.stack.length)
|
||||||
{
|
{
|
||||||
writeln("Stack OF");
|
throw new StackOverFlow();
|
||||||
readln();
|
|
||||||
}
|
}
|
||||||
stack[stacki++] = value;
|
stack[stacki++] = value;
|
||||||
}
|
}
|
||||||
@@ -193,8 +192,7 @@ class VM
|
|||||||
{
|
{
|
||||||
if(stacki <= bp)
|
if(stacki <= bp)
|
||||||
{
|
{
|
||||||
writeln("Stack underflow");
|
throw new StackUnderFlow();
|
||||||
readln();
|
|
||||||
}
|
}
|
||||||
value = stack[--stacki];
|
value = stack[--stacki];
|
||||||
}
|
}
|
||||||
@@ -202,8 +200,7 @@ class VM
|
|||||||
{
|
{
|
||||||
if(stacki <= bp)
|
if(stacki <= bp)
|
||||||
{
|
{
|
||||||
writeln("Stack underflow");
|
throw new StackUnderFlow();
|
||||||
readln();
|
|
||||||
}
|
}
|
||||||
--stacki;
|
--stacki;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -56,6 +56,22 @@ class IllegalFunctionCall : SmileBasicError
|
|||||||
super("Illegal function call(" ~ func ~ ")");
|
super("Illegal function call(" ~ func ~ ")");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
class StackOverFlow : SmileBasicError
|
||||||
|
{
|
||||||
|
this()
|
||||||
|
{
|
||||||
|
this.errnum = 5;
|
||||||
|
super("Stack overflow");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
class StackUnderFlow : SmileBasicError
|
||||||
|
{
|
||||||
|
this()
|
||||||
|
{
|
||||||
|
this.errnum = 6;
|
||||||
|
super("Stack underflow");
|
||||||
|
}
|
||||||
|
}
|
||||||
class TypeMismatch : SmileBasicError
|
class TypeMismatch : SmileBasicError
|
||||||
{
|
{
|
||||||
this()
|
this()
|
||||||
|
|||||||
Reference in New Issue
Block a user