From 88c015c34fd169b07472e998d8aa9915af28409f Mon Sep 17 00:00:00 2001 From: otya128 Date: Wed, 28 Dec 2016 16:27:49 +0900 Subject: [PATCH] Implement PRGNAME$ --- SMILEBASIC/VM.d | 2 +- SMILEBASIC/builtinfunctions.d | 10 +++++++++- SMILEBASIC/petitcomputer.d | 2 +- SMILEBASIC/program.d | 18 ++++++++++++------ 4 files changed, 23 insertions(+), 9 deletions(-) diff --git a/SMILEBASIC/VM.d b/SMILEBASIC/VM.d index 977ff4f..9fe1c19 100644 --- a/SMILEBASIC/VM.d +++ b/SMILEBASIC/VM.d @@ -2334,7 +2334,7 @@ class Exec : Code } wstring content; if (vm.petitcomputer.project.loadFile(file.project, "TXT", file.name, content)) - vm.petitcomputer.program.slot[slot].load(content); + vm.petitcomputer.program.slot[slot].load(file.name, content); else throw new LoadFailed();//TODO:DIALOG? } diff --git a/SMILEBASIC/builtinfunctions.d b/SMILEBASIC/builtinfunctions.d index 83b9ef1..171f332 100644 --- a/SMILEBASIC/builtinfunctions.d +++ b/SMILEBASIC/builtinfunctions.d @@ -2280,7 +2280,7 @@ class BuiltinFunction //not exist return; } - p.program.slot[lot].load(txt); + p.program.slot[lot].load(filename, txt); return; } if(resname.indexOf("GRP") == 0) @@ -3211,6 +3211,14 @@ class BuiltinFunction import otya.smilebasic.program; return p.program.size(slot, cast(SizeType)type); } + static wstring PRGNAME(PetitComputer p) + { + return p.program.name(p.vm.currentSlotNumber); + } + static wstring PRGNAME(PetitComputer p, int slot) + { + return p.program.name(slot); + } //alias void function(PetitComputer, Value[], Value[]) BuiltinFunc; static BuiltinFunctions[wstring] builtinFunctions; static wstring getBasicName(BFD)(const wstring def) diff --git a/SMILEBASIC/petitcomputer.d b/SMILEBASIC/petitcomputer.d index 0bafe0f..ed3bcf8 100644 --- a/SMILEBASIC/petitcomputer.d +++ b/SMILEBASIC/petitcomputer.d @@ -1093,7 +1093,7 @@ class PetitComputer nodirectmode = true; if (nodirectmode) { - program.slot[0].load(readText(inputfile).to!wstring); + program.slot[0].load(inputfile.to!wstring, readText(inputfile).to!wstring); runSlot(0); } else diff --git a/SMILEBASIC/program.d b/SMILEBASIC/program.d index f50c677..462672f 100644 --- a/SMILEBASIC/program.d +++ b/SMILEBASIC/program.d @@ -169,16 +169,18 @@ enum SizeType struct Slot { - DList!wstring program; - DList!wstring.Range range; + private DList!wstring program; + private DList!wstring.Range range; + wstring name; void init() { program = make!(DList!wstring)(["\n"w]); range = program[]; } - void load(wstring data) + void load(wstring filename, wstring data) { + name = filename; program.clear(); foreach(l; splitter(data, "\n")) { @@ -324,11 +326,11 @@ struct Slot switch(type) { case SizeType.Line: - return program[].walkLength; + return cast(int)program[].walkLength; case SizeType.Char: - return program[].map!(x => x.length).sum; + return cast(int)program[].map!(x => x.length).sum; case SizeType.FreeChar: - return (memorySize - program[].map!(x => x.length).sum).max(0); + return cast(int)(memorySize - program[].map!(x => x.length).sum).max(0); default: throw new OutOfRange("PRGSIZE", 2); } @@ -383,4 +385,8 @@ class Program { return this.slot[slot].size(st); } + wstring name(int slot) + { + return this.slot[slot].name; + } }