Skip to content

Commit 1a7cbcc

Browse files
committed
Support subtraction for a pc
This is now used in LoweredCodeUtils
1 parent 82cdea9 commit 1a7cbcc

File tree

2 files changed

+7
-1
lines changed

2 files changed

+7
-1
lines changed

src/JuliaInterpreter.jl

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
module JuliaInterpreter
22

33
using Base.Meta
4-
import Base: +, convert, isless
4+
import Base: +, -, convert, isless
55
using Core: CodeInfo, SSAValue, SlotNumber, TypeMapEntry, SimpleVector, LineInfoNode, GotoNode, Slot,
66
GeneratedFunctionStub, MethodInstance, NewvarNode, TypeName
77

@@ -24,6 +24,7 @@ struct JuliaProgramCounter
2424
next_stmt::Int
2525
end
2626
+(x::JuliaProgramCounter, y::Integer) = JuliaProgramCounter(x.next_stmt+y)
27+
-(x::JuliaProgramCounter, y::Integer) = JuliaProgramCounter(x.next_stmt-y)
2728
convert(::Type{Int}, pc::JuliaProgramCounter) = pc.next_stmt
2829
isless(x::JuliaProgramCounter, y::Integer) = isless(x.next_stmt, y)
2930

test/interpret.jl

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,11 @@ using JuliaInterpreter
22
using JuliaInterpreter: enter_call_expr
33
using Test, InteractiveUtils
44

5+
pc = JuliaInterpreter.JuliaProgramCounter(2)
6+
@test convert(Int, pc) == 2
7+
@test convert(Int, pc+1) == 3
8+
@test convert(Int, pc-1) == 1
9+
510
module Isolated end
611

712
function summer(A)

0 commit comments

Comments
 (0)