Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 13 additions & 0 deletions souffle/Souffle.VM.RuntimeOperations.pas
Original file line number Diff line number Diff line change
Expand Up @@ -161,6 +161,14 @@ TSouffleRuntimeOperations = class abstract
const ATemplate: TSouffleFunctionTemplate;
const AOperandIndex: UInt8); virtual;

{ ── Property violations (1) ──
Called by the VM when a property write is rejected (non-writable,
non-extensible, frozen, sealed). Frontends override to throw the
appropriate language-level error. Default is a no-op. }

procedure PropertyWriteViolation(const AObject: TSouffleValue;
const AKey: string); virtual;

{ ── Type enforcement (1) ──
Called by the VM when a strictly-typed local SET fails the type
check. AValue is the value being stored, AExpectedType is the
Expand Down Expand Up @@ -213,6 +221,11 @@ procedure TSouffleRuntimeOperations.CheckLocalType(
begin
end;

procedure TSouffleRuntimeOperations.PropertyWriteViolation(
const AObject: TSouffleValue; const AKey: string);
begin
end;

procedure TSouffleRuntimeOperations.MarkExternalRoots;
begin
end;
Expand Down
52 changes: 49 additions & 3 deletions souffle/Souffle.VM.pas
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,8 @@ TSouffleVM = class

function DelegateGet(const AObject: TSouffleHeapObject;
const AKey: string; out AValue: TSouffleValue): Boolean;
function SetPropertyViaBlueprintSetter(const ABp: TSouffleBlueprint;
const AKey: string; const AObject, AValue: TSouffleValue): Boolean;
public
constructor Create(const ARuntimeOps: TSouffleRuntimeOperations);
destructor Destroy; override;
Expand Down Expand Up @@ -1699,6 +1701,7 @@ procedure TSouffleVM.ExecuteRuntimeOp(const AFrame: PSouffleVMCallFrame;
StrIter: TSouffleStringIterator;
PropKey: string;
PropVal: TSouffleValue;
Rec: TSouffleRecord;
begin
Base := AFrame^.BaseRegister;

Expand Down Expand Up @@ -2025,9 +2028,29 @@ procedure TSouffleVM.ExecuteRuntimeOp(const AFrame: PSouffleVMCallFrame;
OP_RT_SET_PROP:
begin
A := DecodeA(AInstruction); B := DecodeB(AInstruction); C := DecodeC(AInstruction);
FRuntimeOps.SetProperty(FRegisters[Base + A],
AFrame^.Template.GetConstant(B).StringValue,
FRegisters[Base + C]);
PropKey := AFrame^.Template.GetConstant(B).StringValue;
if SouffleIsReference(FRegisters[Base + A]) and
(FRegisters[Base + A].AsReference is TSouffleRecord) then
begin
Rec := TSouffleRecord(FRegisters[Base + A].AsReference);
if Rec.HasSetters and Rec.Setters.Get(PropKey, PropVal) then
begin
if SouffleIsReference(PropVal) and
(PropVal.AsReference is TSouffleClosure) then
ExecuteFunction(TSouffleClosure(PropVal.AsReference),
[FRegisters[Base + A], FRegisters[Base + C]]);
end
else if Assigned(Rec.Blueprint) and
SetPropertyViaBlueprintSetter(Rec.Blueprint, PropKey,
FRegisters[Base + A], FRegisters[Base + C]) then
{ setter found and invoked in blueprint chain }
else if not Rec.PutChecked(PropKey, FRegisters[Base + C]) then
FRuntimeOps.PropertyWriteViolation(
FRegisters[Base + A], PropKey);
end
else
FRuntimeOps.SetProperty(FRegisters[Base + A], PropKey,
FRegisters[Base + C]);
end;
OP_RT_GET_INDEX:
begin
Expand Down Expand Up @@ -2343,6 +2366,29 @@ function TSouffleVM.DelegateGet(const AObject: TSouffleHeapObject;
Result := False;
end;

function TSouffleVM.SetPropertyViaBlueprintSetter(
const ABp: TSouffleBlueprint; const AKey: string;
const AObject, AValue: TSouffleValue): Boolean;
var
Bp: TSouffleBlueprint;
SetterVal: TSouffleValue;
begin
Bp := ABp;
while Assigned(Bp) do
begin
if Bp.HasSetters and Bp.Setters.Get(AKey, SetterVal) then
begin
if SouffleIsReference(SetterVal) and
(SetterVal.AsReference is TSouffleClosure) then
ExecuteFunction(TSouffleClosure(SetterVal.AsReference),
[AObject, AValue]);
Exit(True);
end;
Bp := Bp.SuperBlueprint;
end;
Result := False;
end;

function TSouffleVM.MaterializeConstant(
const AConstant: TSouffleBytecodeConstant): TSouffleValue;
begin
Expand Down
2 changes: 1 addition & 1 deletion units/Goccia.Runtime.Operations.pas
Original file line number Diff line number Diff line change
Expand Up @@ -314,7 +314,7 @@ TGocciaRuntimeOperations = class(TSouffleRuntimeOperations)
const AValue: TSouffleValue): Boolean;

procedure PropertyWriteViolation(const AObject: TSouffleValue;
const AKey: string);
const AKey: string); override;
procedure PropertyDeleteViolation(const AObject: TSouffleValue;
const AKey: string);
procedure ThrowTypeErrorMessage(
Expand Down
Loading