Skip to content

Commit

Permalink
Use variable cells in bytecode
Browse files Browse the repository at this point in the history
  • Loading branch information
Bike committed Sep 24, 2023
1 parent ecdca6f commit 01ea80e
Show file tree
Hide file tree
Showing 4 changed files with 30 additions and 31 deletions.
2 changes: 1 addition & 1 deletion include/clasp/core/bytecode_compiler.h
Original file line number Diff line number Diff line change
Expand Up @@ -850,7 +850,7 @@ class VariableCellInfo_O : public General_O {
}
public:
CL_LISPIFY_NAME(VariableCellInfo/vname)
CL_DEFMETHOD T_sp vname() { return this->_vname; }
CL_DEFMETHOD Symbol_sp vname() { return this->_vname; }
};

class Module_O : public General_O {
Expand Down
52 changes: 26 additions & 26 deletions src/core/bytecode.cc
Original file line number Diff line number Diff line change
Expand Up @@ -800,35 +800,35 @@ gctools::return_type bytecode_vm(VirtualMachine& vm,
DBG_VM("special-bind %" PRIu8 "\n", c);
T_sp value((gctools::Tagged)(vm.pop(sp)));
pc++;
T_sp symbol((gctools::Tagged)literals[c]);
T_sp cell((gctools::Tagged)literals[c]);
vm._pc = pc;
call_with_variable_bound(symbol, value,
[&]() { return bytecode_vm(vm, literals, closed,
closure,
fp, sp,
lcc_nargs, lcc_args);
});
call_with_cell_bound(gc::As_assert<VariableCell_sp>(cell),
value,
[&]() { return bytecode_vm(vm, literals, closed,
closure,
fp, sp,
lcc_nargs, lcc_args);
});
sp = vm._stackPointer;
pc = vm._pc;
break;
}
case vm_symbol_value: {
uint8_t c = *(++pc);
DBG_VM("symbol-value %" PRIu8 "\n", c);
T_sp sym_sp((gctools::Tagged)literals[c]);
Symbol_sp sym = gc::As_assert<Symbol_sp>(sym_sp);
vm.push(sp, sym->symbolValue().raw_());
T_sp cell_sp((gctools::Tagged)literals[c]);
VariableCell_sp cell = gc::As_assert<VariableCell_sp>(cell_sp);
vm.push(sp, cell->value().raw_());
pc++;
break;
}
case vm_symbol_value_set: {
uint8_t c = *(++pc);
DBG_VM("symbol-value-set %" PRIu8 "\n", c);
T_sp sym_sp((gctools::Tagged)literals[c]);
ASSERT(gc::IsA<Symbol_sp>(sym_sp));
Symbol_sp sym = gc::As_assert<Symbol_sp>(sym_sp);
T_sp cell_sp((gctools::Tagged)literals[c]);
VariableCell_sp cell = gc::As_assert<VariableCell_sp>(cell_sp);
T_sp value((gctools::Tagged)(vm.pop(sp)));
sym->setf_symbolValue(value);
cell->set_value(value);
pc++;
break;
}
Expand Down Expand Up @@ -1299,13 +1299,13 @@ static unsigned char *long_dispatch(VirtualMachine& vm,
DBG_VM("long special-bind %" PRIu16 "\n", c);
T_sp value((gctools::Tagged)(vm.pop(sp)));
pc += 3;
T_sp symbol((gctools::Tagged)literals[c]);
T_sp cell((gctools::Tagged)literals[c]);
vm._pc = pc;
call_with_variable_bound(symbol, value,
[&]() { return bytecode_vm(vm, literals, closed,
closure,
fp, sp, lcc_nargs, lcc_args);
});
call_with_cell_bound(gc::As_assert<VariableCell_sp>(cell), value,
[&]() { return bytecode_vm(vm, literals, closed,
closure,
fp, sp, lcc_nargs, lcc_args);
});
pc = vm._pc;
sp = vm._stackPointer;
break;
Expand All @@ -1314,20 +1314,20 @@ static unsigned char *long_dispatch(VirtualMachine& vm,
uint8_t low = *(++pc);
uint16_t n = low + (*(++pc) << 8);
DBG_VM1("long symbol-value %" PRIu16 "\n", n);
T_sp sym_sp((gctools::Tagged)literals[n]);
Symbol_sp sym = gc::As_assert<Symbol_sp>(sym_sp);
vm.push(sp, sym->symbolValue().raw_());
T_sp cell_sp((gctools::Tagged)literals[n]);
VariableCell_sp cell = gc::As_assert<VariableCell_sp>(cell_sp);
vm.push(sp, cell->value().raw_());
pc++;
break;
}
case vm_symbol_value_set: {
uint8_t low = *(++pc);
uint16_t n = low + (*(++pc) << 8);
DBG_VM1("long symbol-value %" PRIu16 "\n", n);
T_sp sym_sp((gctools::Tagged)literals[n]);
Symbol_sp sym = gc::As_assert<Symbol_sp>(sym_sp);
T_sp cell_sp((gctools::Tagged)literals[n]);
VariableCell_sp cell = gc::As_assert<VariableCell_sp>(cell_sp);
T_sp value((gctools::Tagged)(vm.pop(sp)));
sym->setf_symbolValue(value);
cell->set_value(value);
pc++;
break;
}
Expand Down
2 changes: 1 addition & 1 deletion src/core/bytecode_compiler.cc
Original file line number Diff line number Diff line change
Expand Up @@ -1136,7 +1136,7 @@ void Module_O::link_load(T_sp compile_info) {
else if (gc::IsA<FunctionCellInfo_sp>(lit))
(*literals)[i] = core__ensure_function_cell(gc::As_unsafe<FunctionCellInfo_sp>(lit)->fname());
else if (gc::IsA<VariableCellInfo_sp>(lit))
(*literals)[i] = gc::As_unsafe<VariableCellInfo_sp>(lit)->vname();
(*literals)[i] = gc::As_unsafe<VariableCellInfo_sp>(lit)->vname()->ensureVariableCell();
else SIMPLE_ERROR("BUG: Weird thing in compiler literals vector: {}",
_rep_(lit));
}
Expand Down
5 changes: 2 additions & 3 deletions src/core/loadltv.cc
Original file line number Diff line number Diff line change
Expand Up @@ -617,10 +617,9 @@ struct loadltv {
}

void op_vcell() {
// We also don't really have variable cells.
size_t index = read_index();
T_sp name = get_ltv(read_index());
set_ltv(name, index);
Symbol_sp name = gc::As<Symbol_sp>(get_ltv(read_index()));
set_ltv(name->ensureVariableCell(), index);
}

void op_create() {
Expand Down

0 comments on commit 01ea80e

Please sign in to comment.