Skip to content

Commit 985ce3a

Browse files
authored
Merge pull request #14 from savi-lang/update
Update enum declarations for latest Savi version.
2 parents db27e2e + 936e999 commit 985ce3a

File tree

4 files changed

+50
-43
lines changed

4 files changed

+50
-43
lines changed

manifest.savi

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,15 @@
88
:dependency Spec v0
99
:from "github:savi-lang/Spec"
1010
:depends on Map
11+
:depends on Time
12+
:depends on Timer
1113

1214
:transitive dependency Map v0
1315
:from "github:savi-lang/Map"
16+
17+
:transitive dependency Time v0
18+
:from "github:savi-lang/Time"
19+
20+
:transitive dependency Timer v0
21+
:from "github:savi-lang/Timer"
22+
:depends on Time

src/_Op.savi

Lines changed: 13 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,25 +1,23 @@
11
:enum _Op
2-
:const bit_width U8: 8
3-
42
:fun non from!(byte U8): @from_u64!(byte.u64)
53

64
// We reserve everything below the minimum opcode to match the specified byte.
75
:fun non min_op U8: 0xF3
86

97
// This could theoretically be used for any byte, but we only use it for
108
// bytes from min_op and higher; all lower op codes indicate the byte itself.
11-
:member _OpByte: 0xF3
9+
:member Byte 0xF3
1210

13-
:member _OpMatch: 0xF4
14-
:member _OpRecursiveMatch: 0xF5 // For lookahead
15-
:member _OpJump: 0xF6
16-
:member _OpSplit: 0xF7
17-
:member _OpSplitMany: 0xF8
18-
:member _OpAnyByte: 0xF9
19-
:member _OpByteRange: 0xFA
20-
:member _OpSaveStart: 0xFB
21-
:member _OpSaveFinish: 0xFC
22-
:member _OpBackrefCompare: 0xFD
23-
:member _OpInlineZWA: 0xFE
24-
:member _OpRecursiveZWA: 0xFF
11+
:member Match 0xF4
12+
:member RecursiveMatch 0xF5 // For lookahead
13+
:member Jump 0xF6
14+
:member Split 0xF7
15+
:member SplitMany 0xF8
16+
:member AnyByte 0xF9
17+
:member ByteRange 0xFA
18+
:member SaveStart 0xFB
19+
:member SaveFinish 0xFC
20+
:member BackrefCompare 0xFD
21+
:member InlineZWA 0xFE
22+
:member RecursiveZWA 0xFF
2523

src/_ProgramWriter.savi

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -13,20 +13,20 @@
1313

1414
:fun ref compile(pattern _Pattern)
1515
@_pattern(pattern)
16-
@_op(_OpMatch)
16+
@_op(_Op.Match)
1717
@
1818

1919
:fun ref _pattern(pattern _Pattern)
2020
case pattern <: (
2121
| _PatternAnyByte |
22-
@_op(_OpAnyByte)
22+
@_op(_Op.AnyByte)
2323

2424
| _PatternByte |
25-
@_op(_OpByte)
25+
@_op(_Op.Byte)
2626
@_byte(pattern.byte)
2727

2828
| _PatternByteRange |
29-
@_op(_OpByteRange)
29+
@_op(_Op.ByteRange)
3030
@_byte(pattern.low)
3131
@_byte(pattern.high)
3232

@@ -35,7 +35,7 @@
3535
if (byte < _Op.min_op) (
3636
@_byte(byte)
3737
|
38-
@_op(_OpByte)
38+
@_op(_Op.Byte)
3939
@_byte(byte)
4040
)
4141
)
@@ -44,7 +44,7 @@
4444
pattern.children.each -> (child | @_pattern(child))
4545

4646
| _PatternOptional |
47-
@_op(_OpSplit)
47+
@_op(_Op.Split)
4848
primary_addr = @_later_addr
4949
secondary_addr = @_later_addr
5050

@@ -58,7 +58,7 @@
5858

5959
| _PatternZeroOrMore |
6060
start_cursor = @_cursor
61-
@_op(_OpSplit)
61+
@_op(_Op.Split)
6262
primary_addr = @_later_addr
6363
secondary_addr = @_later_addr
6464

@@ -68,7 +68,7 @@
6868
try @_store_current_cursor_at!(present_addr)
6969
@_pattern(pattern.child)
7070

71-
@_op(_OpJump)
71+
@_op(_Op.Jump)
7272
@_addr(start_cursor)
7373

7474
try @_store_current_cursor_at!(absent_addr)
@@ -77,7 +77,7 @@
7777
start_cursor = @_cursor
7878
@_pattern(pattern.child)
7979

80-
@_op(_OpSplit)
80+
@_op(_Op.Split)
8181
if pattern.is_non_greedy (
8282
after_addr = @_later_addr
8383
@_addr(start_cursor)
@@ -90,30 +90,30 @@
9090

9191
| _PatternChoice |
9292
if (pattern.children.size == 2) (
93-
@_op(_OpSplit)
93+
@_op(_Op.Split)
9494
primary_addr = @_later_addr
9595
secondary_addr = @_later_addr
9696

9797
try @_store_current_cursor_at!(primary_addr)
9898
try @_pattern(pattern.children[0]!)
9999

100-
@_op(_OpJump)
100+
@_op(_Op.Jump)
101101
after_addr = @_later_addr
102102

103103
try @_store_current_cursor_at!(secondary_addr)
104104
try @_pattern(pattern.children[1]!)
105105

106106
try @_store_current_cursor_at!(after_addr)
107107
|
108-
@_op(_OpSplitMany)
108+
@_op(_Op.SplitMany)
109109
branch_addrs Array(U32) = []
110110
pattern.children.each -> (child | branch_addrs << @_later_addr)
111111
@_addr(0) // branch list terminator
112112

113113
after_addrs Array(U32) = []
114114
pattern.children.each_with_index -> (child, index |
115115
if (index > 0) (
116-
@_op(_OpJump)
116+
@_op(_Op.Jump)
117117
after_addrs << @_later_addr
118118
)
119119
try @_store_current_cursor_at!(branch_addrs[index]!)

src/_SimpleVM.savi

Lines changed: 15 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -36,29 +36,29 @@
3636
run_threads.each_until -> (address |
3737
program_byte = @program[address]!
3838
case (
39-
// For _OpAnyByte, consume the byte of input regardless of what it is,
39+
// For _Op.AnyByte, consume the byte of input regardless of what it is,
4040
// then continue with the next byte of the program.
41-
| _OpAnyByte.u8 == program_byte |
41+
| _Op.AnyByte.u8 == program_byte |
4242
@_continue!(next_threads, address +! 1)
4343

44-
// For _OpByteRange, we read the next two bytes in the program,
44+
// For _Op.ByteRange, we read the next two bytes in the program,
4545
// continuing only if the input byte is within that range.
46-
| _OpByteRange.u8 == program_byte |
46+
| _Op.ByteRange.u8 == program_byte |
4747
low = @program[address +! 1]!
4848
high = @program[address +! 2]!
4949
if (input_byte >= low && input_byte <= high) (
5050
@_continue!(next_threads, address +! 3)
5151
)
5252

53-
// For _OpByte, we read the next byte in the bytecode program,
53+
// For _Op.Byte, we read the next byte in the bytecode program,
5454
// and compare it to the input byte to see if it fails to match.
55-
| _OpByte.u8 == program_byte |
55+
| _Op.Byte.u8 == program_byte |
5656
if (input_byte == @program[address +! 1]!) (
5757
@_continue!(next_threads, address +! 2)
5858
)
5959

6060
// If the program byte is below the op code range, then it is
61-
// an implied _OpByte op code with that byte as the expected byte,
61+
// an implied _Op.Byte op code with that byte as the expected byte,
6262
// so we compare it against the input byte same as we did above.
6363
| _Op.min_op > program_byte |
6464
if (input_byte == program_byte) (
@@ -97,19 +97,19 @@
9797
// that are ready to consume input in the main input-consuming loop.
9898
program_byte = @program[address]!
9999
case (
100-
// _OpJump jumps to the given address by enqueuing that address.
101-
| _OpJump.u8 == program_byte |
100+
// _Op.Jump jumps to the given address by enqueuing that address.
101+
| _Op.Jump.u8 == program_byte |
102102
@_continue!(threads, @program.read_native_u32!(address +! 1).usize)
103103

104-
// _OpSplit jumps to the both of the given addresses simultaneously
104+
// _Op.Split jumps to the both of the given addresses simultaneously
105105
// by enqueuing them both as threads with the given priority order.
106-
| _OpSplit.u8 == program_byte |
106+
| _Op.Split.u8 == program_byte |
107107
@_continue!(threads, @program.read_native_u32!(address +! 1).usize)
108108
@_continue!(threads, @program.read_native_u32!(address +! 5).usize)
109109

110-
// _OpSplitMany jumps to the all of the given addresses simultaneously
110+
// _Op.SplitMany jumps to the all of the given addresses simultaneously
111111
// by enqueuing them all as threads with the given priority order.
112-
| _OpSplitMany.u8 == program_byte |
112+
| _Op.SplitMany.u8 == program_byte |
113113
next_address = address +! 1
114114
keep_going = True
115115
while keep_going (
@@ -123,9 +123,9 @@
123123
)
124124
)
125125

126-
// If this is an _OpMatch, we've completed a full match.
126+
// If this is an _Op.Match, we've completed a full match.
127127
// There is no need to continue the program in such a case.
128-
| _OpMatch.u8 == program_byte |
128+
| _Op.Match.u8 == program_byte |
129129
@did_match = True
130130

131131
// If it's an opcode we don't handle here, we put the address on the

0 commit comments

Comments
 (0)