1
0

Implement PRGSIZE

This commit is contained in:
otya128
2016-12-28 16:20:50 +09:00
parent bffa0fe6ee
commit 5505d7c9f0
2 changed files with 39 additions and 1 deletions

View File

@@ -3198,6 +3198,19 @@ class BuiltinFunction
}
p.program.delete_(count);
}
static int PRGSIZE(PetitComputer p)
{
return PRGSIZE(p, p.vm.currentSlotNumber, 0);
}
static int PRGSIZE(PetitComputer p, int slot)
{
return PRGSIZE(p, slot, 0);
}
static int PRGSIZE(PetitComputer p, int slot, int type)
{
import otya.smilebasic.program;
return p.program.size(slot, cast(SizeType)type);
}
//alias void function(PetitComputer, Value[], Value[]) BuiltinFunc;
static BuiltinFunctions[wstring] builtinFunctions;
static wstring getBasicName(BFD)(const wstring def)

View File

@@ -3,7 +3,6 @@ import otya.smilebasic.error;
import std.range;
import std.container;
import std.algorithm;
import std.algorithm;
unittest
{
@@ -161,6 +160,13 @@ unittest
assert(slot.get() == "");
}
enum SizeType
{
Line = 0,
Char = 1,
FreeChar = 2,
}
struct Slot
{
DList!wstring program;
@@ -312,6 +318,21 @@ struct Slot
range = program.linearRemove(range.take(count));
}
}
int memorySize = 1048476;//WiiU..?
int size(SizeType type)
{
switch(type)
{
case SizeType.Line:
return program[].walkLength;
case SizeType.Char:
return program[].map!(x => x.length).sum;
case SizeType.FreeChar:
return (memorySize - program[].map!(x => x.length).sum).max(0);
default:
throw new OutOfRange("PRGSIZE", 2);
}
}
}
class Program
@@ -358,4 +379,8 @@ class Program
throw new UsePRGEDITBeforeAnyPRGFunction("PRGDEL");
this.slot[currentSlot].delete_(count);
}
int size(int slot, SizeType st)
{
return this.slot[slot].size(st);
}
}