1
0

TABの実装

This commit is contained in:
otya128
2015-08-30 13:41:52 +09:00
parent 4c45325f3e
commit 45c72df297
5 changed files with 75 additions and 19 deletions

View File

@@ -1,3 +1,7 @@
TABSTEP=4
FOR i=0 TO 20
?"A","B",
NEXT
SPSET 0,1206 SPSET 0,1206
SPANIM 0,"I",-90,1209,0 SPANIM 0,"I",-90,1209,0
WHILE 1 WHILE 1

View File

@@ -224,7 +224,7 @@ class PrintCode : Code
case ValueType.String: case ValueType.String:
//write(arg.stringValue); //write(arg.stringValue);
if(vm.petitcomputer) if(vm.petitcomputer)
vm.petitcomputer.printConsole(arg.stringValue); vm.petitcomputer.printConsoleString(arg.stringValue);
break; break;
default: default:
//type mismatch //type mismatch
@@ -1421,7 +1421,7 @@ class PushSystemVariable : Code
} }
override void execute(VM vm) override void execute(VM vm)
{ {
vm.push(var.value(vm)); vm.push(var.value);
} }
override string toString(VM vm) override string toString(VM vm)
{ {

View File

@@ -192,12 +192,20 @@ class Compiler
sysVariable["CSRZ"] = new CSRZ(); sysVariable["CSRZ"] = new CSRZ();
addSystemVariable("VERSION", new Version()); addSystemVariable("VERSION", new Version());
addSystemVariable("FREEMEM", new FreeMem()); addSystemVariable("FREEMEM", new FreeMem());
addSystemVariable("TABSTEP", new TabStep());
} }
void addSystemVariable(wstring name, SystemVariable var) void addSystemVariable(wstring name, SystemVariable var)
{ {
global[name] = VMVariable(-1); global[name] = VMVariable(-1);
sysVariable[name] = var; sysVariable[name] = var;
} }
void registerSystemVariable(VM vm)
{
foreach(k, ref v; sysVariable)
{
v.vm = vm;
}
}
SystemVariable[wstring] sysVariable; SystemVariable[wstring] sysVariable;
Code[] code; Code[] code;
VMVariable[wstring] global; VMVariable[wstring] global;
@@ -1030,7 +1038,9 @@ class Compiler
code[i] = new RestoreCode(s.data.label[restore.label], s.data); code[i] = new RestoreCode(s.data.label[restore.label], s.data);
} }
} }
return new VM(code, globalIndex + 1, global, functions, s.data, globalLabel, debugInfo); VM vm = new VM(code, globalIndex + 1, global, functions, s.data, globalLabel, debugInfo);
registerSystemVariable(vm);
return vm;
} }
} }

View File

@@ -1602,7 +1602,10 @@ class PetitComputer
printConsoleString(i.to!wstring); printConsoleString(i.to!wstring);
} }
} }
//0<=TABSTEP<=16
int TABSTEP = 4;
byte consoleAttr; byte consoleAttr;
int tab;
void printConsoleString(wstring text) void printConsoleString(wstring text)
{ {
//consolem.lock(); //consolem.lock();
@@ -1614,16 +1617,32 @@ class PetitComputer
{ {
CSRY = consoleHeightC - 1; CSRY = consoleHeightC - 1;
} }
if(c != '\r' && c != '\n') if(c == '\t')
{ {
consoleC[CSRY][CSRX].character = c; import std.algorithm : min;
consoleC[CSRY][CSRX].foreColor = consoleForeColor; if(tab == 2 && CSRX == 0)
consoleC[CSRY][CSRX].backColor = consoleBackColor; {
consoleC[CSRY][CSRX].z = CSRZ; CSRX--;
consoleC[CSRY][CSRX].attr = consoleAttr; }
else
{
auto t = min(CSRX + TABSTEP - CSRX % TABSTEP, consoleWidthC - 1);
consoleC[CSRY][CSRX..t] = ConsoleCharacter(0, consoleForeColor, consoleBackColor, consoleAttr, CSRZ);
CSRX += TABSTEP - (CSRX % TABSTEP) - 1;
if(CSRX + 1 >= consoleWidthC)
{
CSRX = consoleWidthC - 2;
}
tab = true;
}
}
else if(c != '\n')
{
consoleC[CSRY][CSRX] = ConsoleCharacter(c, consoleForeColor, consoleBackColor, consoleAttr, CSRZ);
tab = tab ? 2 : 0;
} }
CSRX++; CSRX++;
if(CSRX >= consoleWidthC || c == '\n' || c == '\r') if(CSRX >= consoleWidthC || c == '\n')
{ {
CSRX = 0; CSRX = 0;
CSRY++; CSRY++;

View File

@@ -4,8 +4,9 @@ import otya.smilebasic.error;
import otya.smilebasic.vm; import otya.smilebasic.vm;
class SystemVariable class SystemVariable
{ {
VM vm;
@property @property
abstract Value value(VM vm); abstract Value value();
@property @property
void value(Value value) void value(Value value)
{ {
@@ -18,7 +19,7 @@ import std.conv;
class Date : SystemVariable class Date : SystemVariable
{ {
@property @property
override Value value(VM vm) override Value value()
{ {
auto currentTime = Clock.currTime(); auto currentTime = Clock.currTime();
wstring timeString = format("%04d/%02d/%02d", currentTime.year, currentTime.month, currentTime.day).to!wstring; wstring timeString = format("%04d/%02d/%02d", currentTime.year, currentTime.month, currentTime.day).to!wstring;
@@ -28,7 +29,7 @@ class Date : SystemVariable
class Time : SystemVariable class Time : SystemVariable
{ {
@property @property
override Value value(VM vm) override Value value()
{ {
auto currentTime = Clock.currTime(); auto currentTime = Clock.currTime();
wstring timeString = format("%02d:%02d:%02d", currentTime.hour, currentTime.minute, currentTime.second).to!wstring; wstring timeString = format("%02d:%02d:%02d", currentTime.hour, currentTime.minute, currentTime.second).to!wstring;
@@ -38,7 +39,7 @@ class Time : SystemVariable
class Maincnt : SystemVariable class Maincnt : SystemVariable
{ {
@property @property
override Value value(VM vm) override Value value()
{ {
return Value(vm.petitcomputer.maincnt); return Value(vm.petitcomputer.maincnt);
} }
@@ -46,7 +47,7 @@ class Maincnt : SystemVariable
class CSRX : SystemVariable class CSRX : SystemVariable
{ {
@property @property
override Value value(VM vm) override Value value()
{ {
return Value(vm.petitcomputer.CSRX); return Value(vm.petitcomputer.CSRX);
} }
@@ -54,7 +55,7 @@ class CSRX : SystemVariable
class CSRY : SystemVariable class CSRY : SystemVariable
{ {
@property @property
override Value value(VM vm) override Value value()
{ {
return Value(vm.petitcomputer.CSRY); return Value(vm.petitcomputer.CSRY);
} }
@@ -62,15 +63,37 @@ class CSRY : SystemVariable
class CSRZ : SystemVariable class CSRZ : SystemVariable
{ {
@property @property
override Value value(VM vm) override Value value()
{ {
return Value(vm.petitcomputer.CSRZ); return Value(vm.petitcomputer.CSRZ);
} }
} }
class TabStep : SystemVariable
{
@property
override Value value()
{
return Value(vm.petitcomputer.TABSTEP);
}
@property
override void value(Value value)
{
if(!value.isNumber)
{
throw new TypeMismatch();
}
int i = value.castInteger;
if(i < 0 || i > 16)
{
throw new OutOfRange();
}
vm.petitcomputer.TABSTEP = i;
}
}
class Version : SystemVariable class Version : SystemVariable
{ {
@property @property
override Value value(VM vm) override Value value()
{ {
return Value(0x3010000); return Value(0x3010000);
} }
@@ -78,7 +101,7 @@ class Version : SystemVariable
class FreeMem : SystemVariable class FreeMem : SystemVariable
{ {
@property @property
override Value value(VM vm) override Value value()
{ {
return Value(8327164); return Value(8327164);
} }