Skip to content

Commit 73cc00e

Browse files
authored
Improve line:column tracking (quickjs-ng#660)
Emit source locations manually for more precise tracking. Don't infer them from emitted bytecode opcodes because that leads to inaccurate and sometimes surprising results. Speeds up code generation (although infinitesimally) as a bonus. Fixes: quickjs-ng#236
1 parent c8be383 commit 73cc00e

File tree

7 files changed

+1507
-1522
lines changed

7 files changed

+1507
-1522
lines changed

gen/function_source.c

+24-27
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,9 @@
22

33
#include "quickjs-libc.h"
44

5-
const uint32_t qjsc_function_source_size = 338;
5+
const uint32_t qjsc_function_source_size = 314;
66

7-
const uint8_t qjsc_function_source[338] = {
7+
const uint8_t qjsc_function_source[314] = {
88
0x11, 0x05, 0x01, 0x30, 0x74, 0x65, 0x73, 0x74,
99
0x73, 0x2f, 0x66, 0x75, 0x6e, 0x63, 0x74, 0x69,
1010
0x6f, 0x6e, 0x5f, 0x73, 0x6f, 0x75, 0x72, 0x63,
@@ -23,31 +23,28 @@ const uint8_t qjsc_function_source[338] = {
2323
0x00, 0xc2, 0x03, 0x00, 0x0d, 0xc0, 0x03, 0x01,
2424
0x01, 0x0c, 0x43, 0xfa, 0x01, 0xc0, 0x03, 0x00,
2525
0x00, 0x00, 0x01, 0x00, 0x00, 0x03, 0x00, 0xbc,
26-
0x2a, 0x28, 0xbc, 0x03, 0x03, 0x01, 0x04, 0x02,
27-
0x1e, 0x0c, 0x0e, 0x1a, 0x66, 0x75, 0x6e, 0x63,
28-
0x74, 0x69, 0x6f, 0x6e, 0x20, 0x66, 0x28, 0x29,
29-
0x20, 0x7b, 0x20, 0x72, 0x65, 0x74, 0x75, 0x72,
30-
0x6e, 0x20, 0x34, 0x32, 0x20, 0x7d, 0x0c, 0x03,
31-
0xc2, 0x04, 0x08, 0xcc, 0x08, 0xea, 0x05, 0xbf,
32-
0x00, 0xe2, 0x29, 0x04, 0xe2, 0x00, 0x00, 0x00,
33-
0xe1, 0x61, 0x00, 0x00, 0xde, 0x42, 0x38, 0x00,
34-
0x00, 0x00, 0x24, 0x00, 0x00, 0xc9, 0x62, 0x00,
35-
0x00, 0x65, 0x00, 0x00, 0xaf, 0xea, 0x0b, 0x38,
36-
0x95, 0x00, 0x00, 0x00, 0x62, 0x00, 0x00, 0xef,
37-
0x2f, 0x61, 0x02, 0x00, 0x61, 0x01, 0x00, 0x38,
38-
0x3b, 0x00, 0x00, 0x00, 0x65, 0x00, 0x00, 0x04,
39-
0xe0, 0x00, 0x00, 0x00, 0x9d, 0x31, 0x01, 0x00,
40-
0x03, 0x00, 0xca, 0x62, 0x01, 0x00, 0x42, 0x38,
41-
0x00, 0x00, 0x00, 0x24, 0x00, 0x00, 0xcb, 0x62,
42-
0x02, 0x00, 0x65, 0x00, 0x00, 0xaf, 0xea, 0x0b,
43-
0x38, 0x95, 0x00, 0x00, 0x00, 0x62, 0x02, 0x00,
44-
0xef, 0x2f, 0x68, 0x02, 0x00, 0x68, 0x01, 0x00,
45-
0x06, 0x2e, 0xbc, 0x03, 0x01, 0x01, 0x22, 0x1f,
46-
0x01, 0x27, 0x1c, 0x1b, 0x04, 0x0a, 0x1d, 0x12,
47-
0x26, 0x35, 0x17, 0x11, 0x18, 0x20, 0x1c, 0x37,
48-
0x41, 0x21, 0x1c, 0x2a, 0x18, 0x1b, 0x04, 0x26,
49-
0x11, 0x3f, 0x17, 0x11, 0x18, 0x20, 0x1c, 0x53,
50-
0x41, 0x00,
26+
0x2a, 0x28, 0xbc, 0x03, 0x03, 0x01, 0x00, 0x1a,
27+
0x66, 0x75, 0x6e, 0x63, 0x74, 0x69, 0x6f, 0x6e,
28+
0x20, 0x66, 0x28, 0x29, 0x20, 0x7b, 0x20, 0x72,
29+
0x65, 0x74, 0x75, 0x72, 0x6e, 0x20, 0x34, 0x32,
30+
0x20, 0x7d, 0x0c, 0x03, 0xc2, 0x04, 0x08, 0xcc,
31+
0x08, 0xea, 0x05, 0xbf, 0x00, 0xe2, 0x29, 0x04,
32+
0xe2, 0x00, 0x00, 0x00, 0xe1, 0x61, 0x00, 0x00,
33+
0xde, 0x42, 0x38, 0x00, 0x00, 0x00, 0x24, 0x00,
34+
0x00, 0xc9, 0x62, 0x00, 0x00, 0x65, 0x00, 0x00,
35+
0xaf, 0xea, 0x0b, 0x38, 0x95, 0x00, 0x00, 0x00,
36+
0x62, 0x00, 0x00, 0xef, 0x2f, 0x61, 0x02, 0x00,
37+
0x61, 0x01, 0x00, 0x38, 0x3b, 0x00, 0x00, 0x00,
38+
0x65, 0x00, 0x00, 0x04, 0xe0, 0x00, 0x00, 0x00,
39+
0x9d, 0x31, 0x01, 0x00, 0x03, 0x00, 0xca, 0x62,
40+
0x01, 0x00, 0x42, 0x38, 0x00, 0x00, 0x00, 0x24,
41+
0x00, 0x00, 0xcb, 0x62, 0x02, 0x00, 0x65, 0x00,
42+
0x00, 0xaf, 0xea, 0x0b, 0x38, 0x95, 0x00, 0x00,
43+
0x00, 0x62, 0x02, 0x00, 0xef, 0x2f, 0x68, 0x02,
44+
0x00, 0x68, 0x01, 0x00, 0x06, 0x2e, 0xbc, 0x03,
45+
0x01, 0x01, 0x0e, 0x00, 0x1c, 0x0a, 0x2a, 0x5d,
46+
0x18, 0x00, 0x10, 0x08, 0x25, 0x76, 0x0e, 0x5d,
47+
0x18, 0x00,
5148
};
5249

5350
static JSContext *JS_NewCustomContext(JSRuntime *rt)

gen/hello.c

+3-4
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,9 @@
22

33
#include "quickjs-libc.h"
44

5-
const uint32_t qjsc_hello_size = 105;
5+
const uint32_t qjsc_hello_size = 103;
66

7-
const uint8_t qjsc_hello[105] = {
7+
const uint8_t qjsc_hello[103] = {
88
0x11, 0x04, 0x01, 0x22, 0x65, 0x78, 0x61, 0x6d,
99
0x70, 0x6c, 0x65, 0x73, 0x2f, 0x68, 0x65, 0x6c,
1010
0x6c, 0x6f, 0x2e, 0x6a, 0x73, 0x01, 0x0e, 0x63,
@@ -17,8 +17,7 @@ const uint8_t qjsc_hello[105] = {
1717
0x02, 0x29, 0x38, 0xdf, 0x00, 0x00, 0x00, 0x42,
1818
0xe0, 0x00, 0x00, 0x00, 0x04, 0xe1, 0x00, 0x00,
1919
0x00, 0x24, 0x01, 0x00, 0x0e, 0x06, 0x2e, 0xbc,
20-
0x03, 0x01, 0x01, 0x04, 0x01, 0x01, 0x17, 0x02,
21-
0x00,
20+
0x03, 0x01, 0x01, 0x02, 0x48, 0x0e, 0x00,
2221
};
2322

2423
static JSContext *JS_NewCustomContext(JSRuntime *rt)

gen/hello_module.c

+27-32
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,9 @@
22

33
#include "quickjs-libc.h"
44

5-
const uint32_t qjsc_fib_module_size = 314;
5+
const uint32_t qjsc_fib_module_size = 282;
66

7-
const uint8_t qjsc_fib_module[314] = {
7+
const uint8_t qjsc_fib_module[282] = {
88
0x11, 0x03, 0x01, 0x2c, 0x65, 0x78, 0x61, 0x6d,
99
0x70, 0x6c, 0x65, 0x73, 0x2f, 0x66, 0x69, 0x62,
1010
0x5f, 0x6d, 0x6f, 0x64, 0x75, 0x6c, 0x65, 0x2e,
@@ -19,37 +19,33 @@ const uint8_t qjsc_fib_module[314] = {
1919
0xb4, 0xa7, 0xea, 0x03, 0xb4, 0x28, 0xd1, 0xb5,
2020
0xac, 0xea, 0x03, 0xb5, 0x28, 0xdd, 0xd1, 0xb5,
2121
0x9e, 0xef, 0xdd, 0xd1, 0xb6, 0x9e, 0xef, 0x9d,
22-
0x28, 0xbc, 0x03, 0x02, 0x08, 0x20, 0x04, 0x00,
23-
0x07, 0x06, 0x07, 0x06, 0x12, 0x09, 0x08, 0x07,
24-
0x07, 0x10, 0x07, 0x06, 0x07, 0x06, 0x12, 0x13,
25-
0x08, 0x07, 0x08, 0x16, 0x0c, 0x0c, 0x07, 0x04,
26-
0x0c, 0x0a, 0x0c, 0x0c, 0x07, 0x04, 0x8d, 0x01,
27-
0x66, 0x75, 0x6e, 0x63, 0x74, 0x69, 0x6f, 0x6e,
28-
0x20, 0x66, 0x69, 0x62, 0x28, 0x6e, 0x29, 0x0a,
29-
0x7b, 0x0a, 0x20, 0x20, 0x20, 0x20, 0x69, 0x66,
30-
0x20, 0x28, 0x6e, 0x20, 0x3c, 0x3d, 0x20, 0x30,
31-
0x29, 0x0a, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20,
22+
0x28, 0xbc, 0x03, 0x02, 0x08, 0x06, 0x00, 0x0f,
23+
0x0e, 0x10, 0x1b, 0x1a, 0x8d, 0x01, 0x66, 0x75,
24+
0x6e, 0x63, 0x74, 0x69, 0x6f, 0x6e, 0x20, 0x66,
25+
0x69, 0x62, 0x28, 0x6e, 0x29, 0x0a, 0x7b, 0x0a,
26+
0x20, 0x20, 0x20, 0x20, 0x69, 0x66, 0x20, 0x28,
27+
0x6e, 0x20, 0x3c, 0x3d, 0x20, 0x30, 0x29, 0x0a,
28+
0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20,
29+
0x72, 0x65, 0x74, 0x75, 0x72, 0x6e, 0x20, 0x30,
30+
0x3b, 0x0a, 0x20, 0x20, 0x20, 0x20, 0x65, 0x6c,
31+
0x73, 0x65, 0x20, 0x69, 0x66, 0x20, 0x28, 0x6e,
32+
0x20, 0x3d, 0x3d, 0x20, 0x31, 0x29, 0x0a, 0x20,
33+
0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x72,
34+
0x65, 0x74, 0x75, 0x72, 0x6e, 0x20, 0x31, 0x3b,
35+
0x0a, 0x20, 0x20, 0x20, 0x20, 0x65, 0x6c, 0x73,
36+
0x65, 0x0a, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20,
3237
0x20, 0x20, 0x72, 0x65, 0x74, 0x75, 0x72, 0x6e,
33-
0x20, 0x30, 0x3b, 0x0a, 0x20, 0x20, 0x20, 0x20,
34-
0x65, 0x6c, 0x73, 0x65, 0x20, 0x69, 0x66, 0x20,
35-
0x28, 0x6e, 0x20, 0x3d, 0x3d, 0x20, 0x31, 0x29,
36-
0x0a, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20,
37-
0x20, 0x72, 0x65, 0x74, 0x75, 0x72, 0x6e, 0x20,
38-
0x31, 0x3b, 0x0a, 0x20, 0x20, 0x20, 0x20, 0x65,
39-
0x6c, 0x73, 0x65, 0x0a, 0x20, 0x20, 0x20, 0x20,
40-
0x20, 0x20, 0x20, 0x20, 0x72, 0x65, 0x74, 0x75,
41-
0x72, 0x6e, 0x20, 0x66, 0x69, 0x62, 0x28, 0x6e,
42-
0x20, 0x2d, 0x20, 0x31, 0x29, 0x20, 0x2b, 0x20,
43-
0x66, 0x69, 0x62, 0x28, 0x6e, 0x20, 0x2d, 0x20,
44-
0x32, 0x29, 0x3b, 0x0a, 0x7d, 0x08, 0xea, 0x05,
45-
0xbf, 0x00, 0xe1, 0x29, 0x06, 0x2e, 0xbc, 0x03,
46-
0x01, 0x01, 0x06, 0x01, 0x01, 0x00, 0x07, 0x14,
47-
0x02, 0x00,
38+
0x20, 0x66, 0x69, 0x62, 0x28, 0x6e, 0x20, 0x2d,
39+
0x20, 0x31, 0x29, 0x20, 0x2b, 0x20, 0x66, 0x69,
40+
0x62, 0x28, 0x6e, 0x20, 0x2d, 0x20, 0x32, 0x29,
41+
0x3b, 0x0a, 0x7d, 0x08, 0xea, 0x05, 0xbf, 0x00,
42+
0xe1, 0x29, 0x06, 0x2e, 0xbc, 0x03, 0x01, 0x01,
43+
0x00, 0x00,
4844
};
4945

50-
const uint32_t qjsc_hello_module_size = 185;
46+
const uint32_t qjsc_hello_module_size = 183;
5147

52-
const uint8_t qjsc_hello_module[185] = {
48+
const uint8_t qjsc_hello_module[183] = {
5349
0x11, 0x07, 0x01, 0x30, 0x65, 0x78, 0x61, 0x6d,
5450
0x70, 0x6c, 0x65, 0x73, 0x2f, 0x68, 0x65, 0x6c,
5551
0x6c, 0x6f, 0x5f, 0x6d, 0x6f, 0x64, 0x75, 0x6c,
@@ -71,9 +67,8 @@ const uint8_t qjsc_hello_module[185] = {
7167
0x00, 0x00, 0x00, 0x42, 0xe2, 0x00, 0x00, 0x00,
7268
0x04, 0xe4, 0x00, 0x00, 0x00, 0x65, 0x00, 0x00,
7369
0xbc, 0x0a, 0xef, 0x24, 0x02, 0x00, 0x0e, 0x06,
74-
0x2e, 0xbc, 0x03, 0x01, 0x01, 0x0a, 0x01, 0x01,
75-
0x00, 0x04, 0x0a, 0x02, 0x62, 0x00, 0x4d, 0x30,
76-
0x00,
70+
0x2e, 0xbc, 0x03, 0x01, 0x01, 0x08, 0x18, 0x28,
71+
0x36, 0x17, 0x62, 0x00, 0x2a, 0x20, 0x00,
7772
};
7873

7974
static JSContext *JS_NewCustomContext(JSRuntime *rt)

0 commit comments

Comments
 (0)