Skip to content

Commit f227fe3

Browse files
committed
int events from ryml WIP: update java code WIP
1 parent 5a9253c commit f227fe3

File tree

6 files changed

+108
-69
lines changed

6 files changed

+108
-69
lines changed

rapidyaml/native/org_rapidyaml_Rapidyaml.h

Lines changed: 22 additions & 6 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

rapidyaml/native/ysparse_evt.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -59,12 +59,12 @@ RYML_EXPORT bool ysparse_parse(ysparse *obj,
5959
return obj->m_handler.fits_buffers();
6060
}
6161

62-
RYML_EXPORT int ysparse_parse_reqsize_evt(ysparse *obj)
62+
RYML_EXPORT int ysparse_reqsize_evt(ysparse *obj)
6363
{
6464
return obj->m_handler.required_size_events();
6565
}
6666

67-
RYML_EXPORT int ysparse_parse_reqsize_arena(ysparse *obj)
67+
RYML_EXPORT int ysparse_reqsize_arena(ysparse *obj)
6868
{
6969
return (int)obj->m_handler.required_size_arena();
7070
}

rapidyaml/native/ysparse_evt.hpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -93,10 +93,10 @@ RYML_EXPORT bool ysparse_parse(ysparse *ryml2evt,
9393
int *evt, size_type evt_size);
9494

9595
/** Get the required size for the event buffer, from the last parse call */
96-
RYML_EXPORT int ysparse_parse_reqsize_evt(ysparse *ryml2evt);
96+
RYML_EXPORT int ysparse_reqsize_evt(ysparse *ryml2evt);
9797

9898
/** Get the required size for the arena buffer, from the last parse call */
99-
RYML_EXPORT int ysparse_parse_reqsize_arena(ysparse *ryml2evt);
99+
RYML_EXPORT int ysparse_reqsize_arena(ysparse *ryml2evt);
100100

101101
#if defined(__cplusplus)
102102
}

rapidyaml/native/ysparse_test.cpp

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -143,7 +143,7 @@ struct TestCase
143143
arena.str, (size_type)arena.len,
144144
&output[0], (size_type)output.size());
145145
CHECK(fits_buffers);
146-
int reqsize_evt = ysparse_parse_reqsize_evt(ryml2evt);
146+
int reqsize_evt = ysparse_reqsize_evt(ryml2evt);
147147
CHECK_MSG((size_t)reqsize_evt == expected_size(evt), "%d vs %zu", reqsize_evt, expected_size(evt));
148148
CHECK(reqsize_evt != 0);
149149
CHECK(reqsize_evt <= estimated_size);
@@ -173,8 +173,8 @@ struct TestCase
173173
arena.str, (size_type)arena.len,
174174
output.data(), (size_type)output.size());
175175
CHECK(!fits_buffers);
176-
int reqsize_evt = ysparse_parse_reqsize_evt(ryml2evt);
177-
int reqsize_arena = ysparse_parse_reqsize_arena(ryml2evt);
176+
int reqsize_evt = ysparse_reqsize_evt(ryml2evt);
177+
int reqsize_arena = ysparse_reqsize_arena(ryml2evt);
178178
CHECK(reqsize_evt == expected_size(evt));
179179
CHECK(reqsize_evt != 0);
180180
CHECK(reqsize_evt <= estimated_size);
@@ -188,8 +188,8 @@ struct TestCase
188188
arena.str, (size_type)arena.len,
189189
output.data(), (size_type)output.size());
190190
CHECK(fits_buffers2);
191-
int reqsize_evt2 = ysparse_parse_reqsize_evt(ryml2evt);
192-
int reqsize_arena2 = ysparse_parse_reqsize_arena(ryml2evt);
191+
int reqsize_evt2 = ysparse_reqsize_evt(ryml2evt);
192+
int reqsize_arena2 = ysparse_reqsize_arena(ryml2evt);
193193
CHECK(reqsize_evt2 == reqsize_evt);
194194
CHECK(reqsize_arena2 == reqsize_arena);
195195
output.resize(reqsize_evt2);
@@ -214,8 +214,8 @@ struct TestCase
214214
nullptr, 0,
215215
nullptr, 0);
216216
CHECK(!fits_buffers);
217-
int reqsize_evt = ysparse_parse_reqsize_evt(ryml2evt);
218-
int reqsize_arena = ysparse_parse_reqsize_arena(ryml2evt);
217+
int reqsize_evt = ysparse_reqsize_evt(ryml2evt);
218+
int reqsize_arena = ysparse_reqsize_arena(ryml2evt);
219219
CHECK(reqsize_evt == expected_size(evt));
220220
CHECK(reqsize_evt <= estimated_size);
221221
CHECK(reqsize_evt != 0);
@@ -231,8 +231,8 @@ struct TestCase
231231
arena.str, (size_type)arena.len,
232232
output.data(), (size_type)output.size());
233233
CHECK(fits_buffers2);
234-
int reqsize_evt2 = ysparse_parse_reqsize_evt(ryml2evt);
235-
int reqsize_arena2 = ysparse_parse_reqsize_arena(ryml2evt);
234+
int reqsize_evt2 = ysparse_reqsize_evt(ryml2evt);
235+
int reqsize_arena2 = ysparse_reqsize_arena(ryml2evt);
236236
CHECK(reqsize_evt2 == reqsize_evt);
237237
CHECK(reqsize_arena2 == reqsize_arena);
238238
CHECK(reqsize_evt2 == output.size());

rapidyaml/src/main/java/org/rapidyaml/Evt.java

Lines changed: 32 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -14,30 +14,48 @@ public class Evt {
1414
public static final int ALIA = 1 << 9; // =ALI
1515

1616
// Style flags
17-
public static final int PLAI = 1 << 16; // : (plain scalar)
18-
public static final int SQUO = 1 << 17; // ' (single-quoted scalar)
19-
public static final int DQUO = 1 << 18; // " (double-quoted scalar)
20-
public static final int LITL = 1 << 19; // | (block literal scalar)
21-
public static final int FOLD = 1 << 20; // > (block folded scalar)
17+
public static final int PLAI = 1 << 10; // : (plain scalar)
18+
public static final int SQUO = 1 << 11; // ' (single-quoted scalar)
19+
public static final int DQUO = 1 << 12; // " (double-quoted scalar)
20+
public static final int LITL = 1 << 13; // | (block literal scalar)
21+
public static final int FOLD = 1 << 14; // > (block folded scalar)
2222

23-
public static final int FLOW = 1 << 21; // flow container:
23+
public static final int FLOW = 1 << 15; // flow container:
2424
// [] for seqs or {} for maps
25-
public static final int BLCK = 1 << 22; // block container
25+
public static final int BLCK = 1 << 16; // block container
2626

2727
// Modifiers
28-
public static final int ANCH = 1 << 24; // anchor
29-
public static final int TAG_ = 1 << 25; // tag
28+
public static final int ANCH = 1 << 17; // anchor
29+
public static final int TAG_ = 1 << 18; // tag
3030

3131
// Structure flags
32-
public static final int KEY_ = 1 << 26; // as key
33-
public static final int VAL_ = 1 << 27; // as value
34-
public static final int EXPL = 1 << 28; // --- (with BDOC) or
32+
public static final int KEY_ = 1 << 19; // as key
33+
public static final int VAL_ = 1 << 20; // as value
34+
public static final int EXPL = 1 << 21; // --- (with BDOC) or
3535
// ... (with EDOC)
3636
// (may be fused with FLOW
3737
// if needed)
3838

39-
// Utility flags
40-
public static final int LAST = EXPL;
39+
// Buffer flags
40+
///< IMPORTANT. Marks events whose string was placed in the
41+
///< arena. Fhis happens when the filtered string is larger than the
42+
///< original string in the YAML code (eg from tags that resolve to
43+
///< a larger string, or from "\L" or "\P" in double quotes, which
44+
///< expand from two to three bytes). Because of this size
45+
///< expansion, the filtered string cannot be placed in the original
46+
///< source and needs to be placed in the arena.
47+
public static final int AREN = 1 << 22;
48+
///< special flag to enable look back in the event array. it
49+
///< signifies that the previous event has a string, meaning that
50+
///< the jump back to that event is 3 positions. without this flag it
51+
///< would be impossible to jump to the previous event
52+
public static final int PSTR = (1 << 23);
53+
///< special flag to mark a scalar as unfiltered (when the parser
54+
///< is set not to filter)
55+
public static final int UNFILT = (1 << 24);
56+
57+
// Utility flags/masks
58+
public static final int LAST = UNFILT;
4159
public static final int MASK = ((LAST << 1) - 1);
4260
public static final int HAS_STR = SCLR|ALIA|ANCH|TAG_;
4361

rapidyaml/src/main/java/org/rapidyaml/Rapidyaml.java

Lines changed: 41 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -12,22 +12,23 @@
1212
* Interface with the librapidyaml shared library
1313
*/
1414
public class Rapidyaml {
15-
public static String RAPIDYAML_NAME = "rapidyaml.0.8.0";
16-
public static String RAPIDYAML_LIBNAME = "librapidyaml.0.8.0.so";
15+
public static String RAPIDYAML_NAME = "ysparse.0.9.0";
16+
public static String RAPIDYAML_LIBNAME = "ysparse.0.9.0.so";
1717

18+
private final long ysparse; ///< pointer to the c++ object
1819
private native long ysparse_init();
1920
private native void ysparse_destroy(long ysparse);
2021
private native void ysparse_timing_set(boolean yes);
21-
private native int ysparse_parse(
22-
long ysparse, String filename,
23-
byte[] ys, int ys_length,
24-
int[] evt, int evt_length);
25-
private native int ysparse_parse_buf(
26-
long ysparse, String filename,
27-
ByteBuffer ys, int ys_length,
28-
IntBuffer evt, int evt_length);
29-
private final long ysparse;
30-
22+
private native boolean ysparse_parse(long ysparse, String filename,
23+
byte[] ys, int ys_length,
24+
byte[] arena, int arena_length,
25+
int[] evt, int evt_length);
26+
private native boolean ysparse_parse_buf(long ysparse, String filename,
27+
ByteBuffer ys, int ys_length,
28+
ByteBuffer arena, int arena_length,
29+
IntBuffer evt, int evt_length);
30+
private native int ysparse_reqsize_evt(long ysparse);
31+
private native int ysparse_reqsize_arena(long ysparse);
3132

3233

3334
// XXX this 'main' is for testing
@@ -72,34 +73,32 @@ public Rapidyaml() throws Exception, IOException {
7273
// EVT
7374
//------------------------
7475

75-
public int parseYsToEvt(
76-
byte[] src, int[] evts
77-
) throws Exception {
78-
return parseYsToEvt("yamlscript", src, evts);
76+
public boolean parseYs(byte[] src, byte[] arena, int[] evts) throws Exception
77+
{
78+
return parseYs("yamlscript", src, arena, evts);
7979
}
8080

81-
public int parseYsToEvtBuf(
82-
ByteBuffer src, IntBuffer evt
83-
) throws Exception {
84-
return parseYsToEvtBuf("yamlscript", src, evt);
81+
public boolean parseYsDirect(ByteBuffer src, ByteBuffer arena, IntBuffer evt) throws Exception
82+
{
83+
return parseYsDirect("yamlscript", src, arena, evt);
8584
}
8685

87-
public int parseYsToEvt(
88-
String filename, byte[] src, int[] evts
89-
) throws Exception {
86+
public boolean parseYs(String filename, byte[] src, byte[] arena, int[] evts) throws Exception
87+
{
9088
long t = timingStart("ysparse");
91-
int required_size = ysparse_parse(
92-
this.ysparse, filename,
93-
src, src.length, evts, evts.length);
89+
boolean fits_buffers = ysparse_parse(this.ysparse, filename,
90+
src, src.length,
91+
arena, arena.length,
92+
evts, evts.length);
9493
timingStop("ysparse", t, src.length);
95-
return required_size;
94+
return fits_buffers;
9695
}
9796

98-
public int parseYsToEvtBuf(
99-
String filename, ByteBuffer src, IntBuffer evt
100-
) throws Exception {
97+
public boolean parseYsDirect(String filename, ByteBuffer src, ByteBuffer arena, IntBuffer evt) throws Exception {
10198
if (! src.isDirect())
10299
throw new RuntimeException("src must be direct");
100+
if (! arena.isDirect())
101+
throw new RuntimeException("arena must be direct");
103102
if (! evt.isDirect())
104103
throw new RuntimeException("evt must be direct");
105104
// the byte order for src does not matter
@@ -108,15 +107,21 @@ public int parseYsToEvtBuf(
108107
throw new RuntimeException("evt byte order must be native");
109108
long t = timingStart("ysparseBuf");
110109
evt.position(evt.capacity());
111-
int reqsize = ysparse_parse_buf(
112-
this.ysparse, filename,
113-
src, src.position(), evt, evt.capacity());
114-
if (reqsize <= evt.capacity())
115-
evt.position(reqsize);
110+
boolean fits_buffers = ysparse_parse_buf(this.ysparse, filename,
111+
src, src.position(),
112+
arena, arena.position(),
113+
evt, evt.capacity());
114+
if (fits_buffers)
115+
evt.position(ysparse_reqsize_evt(this.ysparse));
116116
timingStop("ysparseBuf", t, src.position());
117-
return reqsize;
117+
return fits_buffers;
118118
}
119119

120+
/** Get the required size for the event output buffer, from the last parse call */
121+
public int reqsizeEvt() { return ysparse_reqsize_evt(this.ysparse); }
122+
/** Get the required size for the arena buffer, from the last parse call */
123+
public int reqsizeArena() { return ysparse_reqsize_arena(this.ysparse); }
124+
120125
public static IntBuffer mkIntBuffer(int numInts) {
121126
ByteBuffer bb = ByteBuffer.allocateDirect(/*numBytes*/4 * numInts);
122127
// !!! need to explicitly set the byte order to the native order

0 commit comments

Comments
 (0)