Skip to content

Commit

Permalink
set系の命令はスタックへの要素追加を行わないように修正
Browse files Browse the repository at this point in the history
  • Loading branch information
sile committed Apr 22, 2012
1 parent 629c8ec commit d904bda
Show file tree
Hide file tree
Showing 3 changed files with 33 additions and 16 deletions.
4 changes: 2 additions & 2 deletions plvm/include/psil/vm/DataStack.hh
Expand Up @@ -38,8 +38,8 @@ namespace psil {
stack.resize(top); stack.resize(top);
} }


type::Object* local_get(unsigned index) { return stack[base+index]; } type::Object* localGet(unsigned index) { return stack[base+index]; }
type::Object* local_set(unsigned index, type::Object* value) { return stack[base+index] = value; } void localSet(unsigned index, type::Object* value) { stack[base+index] = value; }


std::string show() const; std::string show() const;


Expand Down
41 changes: 29 additions & 12 deletions plvm/include/psil/vm/Instruction.hh
Expand Up @@ -57,9 +57,10 @@ namespace psil {
case 201: _lambda(); break; case 201: _lambda(); break;
case 202: _localget(); break; case 202: _localget(); break;
case 203: _localset(); break; case 203: _localset(); break;
case 204: _reference(); break; case 204: _local_mkref(); break;
case 205: _refget(); break; case 205: _local_refget(); break;
case 206: _refset(); break; case 206: _local_refset(); break;
case 207: _local_toref(); break;


case 250: _print(); break; case 250: _print(); break;


Expand Down Expand Up @@ -121,7 +122,7 @@ namespace psil {
push(to<Symbol>(pop())->getValue()); push(to<Symbol>(pop())->getValue());
} }
void _symset() { void _symset() {
push(to<Symbol>(pop())->setValue(pop())); to<Symbol>(pop())->setValue(pop());
} }
void _constget() { void _constget() {
push(env.getConstantTable().get(readUint2())); push(env.getConstantTable().get(readUint2()));
Expand Down Expand Up @@ -231,23 +232,29 @@ namespace psil {
} }


void _localget() { void _localget() {
push(env.getDataStack().local_get(readUint1())); push(env.getDataStack().localGet(readUint1()));
} }


void _localset() { void _localset() {
push(env.getDataStack().local_set(readUint1(), pop())); env.getDataStack().localSet(readUint1(), pop());
} }


void _reference() { void _local_mkref() {
push(Reference::make(pop())); env.getDataStack().localSet(readUint1(), Reference::make(pop()));
} }


void _refget() { void _local_refget() {
push(to<Reference>(pop())->getValue()); push(to<Reference>(env.getDataStack().localGet(readUint1()))->getValue());
} }


void _refset() { void _local_refset() {
push(to<Reference>(pop())->setValue(pop())); Reference* ref = to<Reference>(env.getDataStack().localGet(readUint1()));
ref->setValue(pop());
}

void _local_toref() {
Object* o = env.getDataStack().localGet(readUint1());
env.getDataStack().localSet(readUint1(), Reference::make(o));
} }


// //
Expand All @@ -272,6 +279,11 @@ namespace psil {


ds.setBase(nextBase); ds.setBase(nextBase);
ds.reserve(lambda.getLocalVarCount()); ds.reserve(lambda.getLocalVarCount());
/*
for(uint1 i=0; i < lambda.getLocalVarCount(); i++) {
push(Undef::make());
}
*/
} }


void create_tail_callframe(Lambda& lambda) { void create_tail_callframe(Lambda& lambda) {
Expand All @@ -281,6 +293,11 @@ namespace psil {
DataStack& ds = env.getDataStack(); DataStack& ds = env.getDataStack();
ds.setBase(ds.getTop()); ds.setBase(ds.getTop());
ds.reserve(lambda.getLocalVarCount()); ds.reserve(lambda.getLocalVarCount());
/*
for(uint1 i=0; i < lambda.getLocalVarCount(); i++) {
push(Undef::make());
}
*/
} }


opcode_t readOp() { opcode_t readOp() {
Expand Down
4 changes: 2 additions & 2 deletions plvm/include/psil/vm/Object.hh
Expand Up @@ -106,7 +106,7 @@ namespace psil {


const std::string& getName() const { return name; } const std::string& getName() const { return name; }
Object* getValue() const { return value; } Object* getValue() const { return value; }
Object* setValue(Object* o) { return value=o; } void setValue(Object* o) { value=o; }


private: private:
const std::string name; const std::string name;
Expand Down Expand Up @@ -261,7 +261,7 @@ namespace psil {
std::string show() const { return std::string("<REF ") + value->show() + ">"; } std::string show() const { return std::string("<REF ") + value->show() + ">"; }


Object* getValue() const { return value; } Object* getValue() const { return value; }
Object* setValue(Object* x) { return value=x; } void setValue(Object* x) { value=x; }


private: private:
Object* value; Object* value;
Expand Down

0 comments on commit d904bda

Please sign in to comment.