Implement USE
This commit is contained in:
@@ -96,6 +96,15 @@ class VM
|
|||||||
void loadSlot(int slot, Code[] code, int len, VMVariable[wstring] globalTable, Function[wstring] functions, DataTable gdt/*GNU Debugging Tools*/,
|
void loadSlot(int slot, Code[] code, int len, VMVariable[wstring] globalTable, Function[wstring] functions, DataTable gdt/*GNU Debugging Tools*/,
|
||||||
int[wstring] globalLabel, DebugInfo dinfo)
|
int[wstring] globalLabel, DebugInfo dinfo)
|
||||||
{
|
{
|
||||||
|
//unload common function
|
||||||
|
if (slots[slot])
|
||||||
|
foreach(f ; slots[slot].functions)
|
||||||
|
{
|
||||||
|
if (f.isCommon)
|
||||||
|
{
|
||||||
|
commonFunctions.remove(f.name);
|
||||||
|
}
|
||||||
|
}
|
||||||
auto s = this.slots[slot];
|
auto s = this.slots[slot];
|
||||||
s.isUsed = true;
|
s.isUsed = true;
|
||||||
s.code = code;
|
s.code = code;
|
||||||
@@ -107,6 +116,15 @@ class VM
|
|||||||
s.global[v.index] = Value(v.type);
|
s.global[v.index] = Value(v.type);
|
||||||
}
|
}
|
||||||
s.functions = functions;
|
s.functions = functions;
|
||||||
|
foreach(f ; functions)
|
||||||
|
{
|
||||||
|
if (f.isCommon)
|
||||||
|
{
|
||||||
|
if (f.name in commonFunctions)
|
||||||
|
throw new DuplicateFunction(slot, dinfo.getLocationByAddress(f.address));
|
||||||
|
commonFunctions[f.name] = f;
|
||||||
|
}
|
||||||
|
}
|
||||||
s.globalDataTable = gdt;
|
s.globalDataTable = gdt;
|
||||||
s.globalLabel = globalLabel;
|
s.globalLabel = globalLabel;
|
||||||
s.debugInfo = dinfo;
|
s.debugInfo = dinfo;
|
||||||
@@ -2239,6 +2257,19 @@ class Use : Code
|
|||||||
{
|
{
|
||||||
Value arg;
|
Value arg;
|
||||||
vm.pop(arg);
|
vm.pop(arg);
|
||||||
|
int slot;
|
||||||
|
if (arg.isNumber)
|
||||||
|
{
|
||||||
|
slot = arg.castInteger;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
throw new TypeMismatch();
|
||||||
|
}
|
||||||
|
import otya.smilebasic.parser;
|
||||||
|
auto parser = new Parser(cast(immutable)vm.petitcomputer.slot[slot].text);
|
||||||
|
auto compiler = parser.compiler;
|
||||||
|
compiler.compile(vm, slot);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -103,6 +103,7 @@ class Function
|
|||||||
int[wstring] label;
|
int[wstring] label;
|
||||||
bool returnExpr;
|
bool returnExpr;
|
||||||
int outArgCount;
|
int outArgCount;
|
||||||
|
bool isCommon;
|
||||||
/**
|
/**
|
||||||
0:bp
|
0:bp
|
||||||
1:pc
|
1:pc
|
||||||
@@ -110,7 +111,7 @@ class Function
|
|||||||
3:data index
|
3:data index
|
||||||
4:function pointer
|
4:function pointer
|
||||||
*/
|
*/
|
||||||
this(int address, wstring name, bool returnExpr, int argCount)
|
this(int address, wstring name, bool returnExpr, int argCount, bool isCommon)
|
||||||
{
|
{
|
||||||
this.address = address;
|
this.address = address;
|
||||||
this.name = name;
|
this.name = name;
|
||||||
@@ -121,6 +122,7 @@ class Function
|
|||||||
{
|
{
|
||||||
outArgCount = 1;
|
outArgCount = 1;
|
||||||
}
|
}
|
||||||
|
this.isCommon = isCommon;
|
||||||
}
|
}
|
||||||
int getLocalVarIndex(wstring name, Compiler c)
|
int getLocalVarIndex(wstring name, Compiler c)
|
||||||
{
|
{
|
||||||
@@ -866,7 +868,7 @@ class Compiler
|
|||||||
throw new CantUseFromDirectMode();
|
throw new CantUseFromDirectMode();
|
||||||
}
|
}
|
||||||
auto skip = genCodeGoto();
|
auto skip = genCodeGoto();
|
||||||
Function func = new Function(cast(int)this.code.length, node.name, node.returnExpr, cast(int)node.arguments.length);
|
Function func = new Function(cast(int)this.code.length, node.name, node.returnExpr, cast(int)node.arguments.length, node.isCommon);
|
||||||
Scope sc = new Scope(func);
|
Scope sc = new Scope(func);
|
||||||
foreach(wstring arg; node.arguments)
|
foreach(wstring arg; node.arguments)
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -2,6 +2,8 @@ module otya.smilebasic.error;
|
|||||||
import std.exception;
|
import std.exception;
|
||||||
import std.string;
|
import std.string;
|
||||||
import std.conv;
|
import std.conv;
|
||||||
|
import otya.smilebasic.token;
|
||||||
|
|
||||||
class SmileBasicError : Exception
|
class SmileBasicError : Exception
|
||||||
{
|
{
|
||||||
int errnum;
|
int errnum;
|
||||||
@@ -154,6 +156,14 @@ class DuplicateVariable : SmileBasicError
|
|||||||
super("Duplicate variable");
|
super("Duplicate variable");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
class DuplicateFunction : SmileBasicError
|
||||||
|
{
|
||||||
|
this(int slot, SourceLocation loc)
|
||||||
|
{
|
||||||
|
this.errnum = 19;
|
||||||
|
super(slot, loc.line, "Duplicate function");
|
||||||
|
}
|
||||||
|
}
|
||||||
class ReturnWithoutGosub : SmileBasicError
|
class ReturnWithoutGosub : SmileBasicError
|
||||||
{
|
{
|
||||||
this()
|
this()
|
||||||
|
|||||||
Reference in New Issue
Block a user