Skip to content

Commit dd08aea

Browse files
committed
fix startpos/endpos codegen
1 parent f2d005c commit dd08aea

File tree

10 files changed

+946
-931
lines changed

10 files changed

+946
-931
lines changed

boot/moonyacc.js

Lines changed: 53 additions & 51 deletions
Original file line numberDiff line numberDiff line change
@@ -930,21 +930,22 @@ function $64$moonbitlang$47$yacc$47$lib$47$elab$46$BindingSubject$Data(param0, p
930930
this._1 = param1;
931931
}
932932
$64$moonbitlang$47$yacc$47$lib$47$elab$46$BindingSubject$Data.prototype.$tag = 0;
933-
const $64$moonbitlang$47$yacc$47$lib$47$elab$46$BindingSubject$LastPos = { $tag: 1 };
934-
function $64$moonbitlang$47$yacc$47$lib$47$elab$46$BindingSubject$StartPos(param0) {
933+
function $64$moonbitlang$47$yacc$47$lib$47$elab$46$BindingSubject$StartPosOf(param0) {
935934
this._0 = param0;
936935
}
937-
$64$moonbitlang$47$yacc$47$lib$47$elab$46$BindingSubject$StartPos.prototype.$tag = 2;
938-
function $64$moonbitlang$47$yacc$47$lib$47$elab$46$BindingSubject$EndPos(param0) {
936+
$64$moonbitlang$47$yacc$47$lib$47$elab$46$BindingSubject$StartPosOf.prototype.$tag = 1;
937+
function $64$moonbitlang$47$yacc$47$lib$47$elab$46$BindingSubject$EndPosOf(param0) {
939938
this._0 = param0;
940939
}
941-
$64$moonbitlang$47$yacc$47$lib$47$elab$46$BindingSubject$EndPos.prototype.$tag = 3;
942-
const $64$moonbitlang$47$yacc$47$lib$47$elab$46$BindingSubject$SymbolStartPos = { $tag: 4 };
940+
$64$moonbitlang$47$yacc$47$lib$47$elab$46$BindingSubject$EndPosOf.prototype.$tag = 2;
941+
const $64$moonbitlang$47$yacc$47$lib$47$elab$46$BindingSubject$StartPos = { $tag: 3 };
942+
const $64$moonbitlang$47$yacc$47$lib$47$elab$46$BindingSubject$EndPos = { $tag: 4 };
943+
const $64$moonbitlang$47$yacc$47$lib$47$elab$46$BindingSubject$SymbolStartPos = { $tag: 5 };
943944
function $64$moonbitlang$47$yacc$47$lib$47$elab$46$BindingSubject$SubAction(param0, param1) {
944945
this._0 = param0;
945946
this._1 = param1;
946947
}
947-
$64$moonbitlang$47$yacc$47$lib$47$elab$46$BindingSubject$SubAction.prototype.$tag = 5;
948+
$64$moonbitlang$47$yacc$47$lib$47$elab$46$BindingSubject$SubAction.prototype.$tag = 6;
948949
function $64$moonbitlang$47$yacc$47$lib$47$elab$46$TypeExpr$Constr(param0, param1, param2) {
949950
this._0 = param0;
950951
this._1 = param1;
@@ -17632,7 +17633,7 @@ function moonbitlang$yacc$lib$parser$$yy_action_11(_last_pos, _args) {
1763217633
const _YYObj_String = _bind;
1763317634
const _image = _YYObj_String._0;
1763417635
const _start_pos = moonbitlang$core$array$$ArrayView$op_get$123$(_args, 0)._1;
17635-
const _end_pos = moonbitlang$core$array$$ArrayView$op_get$123$(_args, 0)._2;
17636+
const _end_pos = moonbitlang$core$array$$ArrayView$op_get$123$(_args, moonbitlang$core$array$$ArrayView$length$123$(_args) - 1 | 0)._2;
1763617637
return new Error$moonbitlang$47$yacc$47$lib$47$parser$46$YYObj__ast_Term$46$YYObj__ast_Term(new $64$moonbitlang$47$yacc$47$lib$47$ast$46$Term$Image(_image, { _0: _start_pos, _1: _end_pos }));
1763717638
} else {
1763817639
return $panic();
@@ -17691,7 +17692,7 @@ function moonbitlang$yacc$lib$parser$$yy_action_16(_last_pos, _args) {
1769117692
const _YYObj__String__Int__Array__ast_SubstItem__ = _bind;
1769217693
const _code = _YYObj__String__Int__Array__ast_SubstItem__._0;
1769317694
const _start_pos = moonbitlang$core$array$$ArrayView$op_get$123$(_args, 0)._1;
17694-
const _end_pos = moonbitlang$core$array$$ArrayView$op_get$123$(_args, 0)._2;
17695+
const _end_pos = moonbitlang$core$array$$ArrayView$op_get$123$(_args, moonbitlang$core$array$$ArrayView$length$123$(_args) - 1 | 0)._2;
1769517696
const _code$2 = _code._0;
1769617697
const _utf8_pos = _code._1;
1769717698
const _subst = _code._2;
@@ -17871,7 +17872,7 @@ function moonbitlang$yacc$lib$parser$$yy_action_28(_last_pos, _args) {
1787117872
const _YYObj__ast_PrecSymbol_ = _bind$2;
1787217873
const _prec = _YYObj__ast_PrecSymbol_._0;
1787317874
const _start_pos = moonbitlang$core$array$$ArrayView$op_get$123$(_args, 0)._1;
17874-
const _end_pos = moonbitlang$core$array$$ArrayView$op_get$123$(_args, 1)._2;
17875+
const _end_pos = moonbitlang$core$array$$ArrayView$op_get$123$(_args, moonbitlang$core$array$$ArrayView$length$123$(_args) - 1 | 0)._2;
1787517876
return new Error$moonbitlang$47$yacc$47$lib$47$parser$46$YYObj__ast_ClauseWithoutAction$46$YYObj__ast_ClauseWithoutAction({ items: moonbitlang$core$immut$list$$T$to_array$72$(_item_list), prec: _prec, loc: { _0: _start_pos, _1: _end_pos - _start_pos | 0 } });
1787617877
} else {
1787717878
return $panic();
@@ -17886,7 +17887,7 @@ function moonbitlang$yacc$lib$parser$$yy_action_29(_last_pos, _args) {
1788617887
const _YYObj__ast_PrecSymbol_ = _bind;
1788717888
const _prec = _YYObj__ast_PrecSymbol_._0;
1788817889
const _start_pos = moonbitlang$core$array$$ArrayView$op_get$123$(_args, 0)._1;
17889-
const _end_pos = moonbitlang$core$array$$ArrayView$op_get$123$(_args, 0)._2;
17890+
const _end_pos = moonbitlang$core$array$$ArrayView$op_get$123$(_args, moonbitlang$core$array$$ArrayView$length$123$(_args) - 1 | 0)._2;
1789017891
return new Error$moonbitlang$47$yacc$47$lib$47$parser$46$YYObj__ast_ClauseWithoutAction$46$YYObj__ast_ClauseWithoutAction({ items: [], prec: _prec, loc: { _0: _start_pos, _1: _end_pos - _start_pos | 0 } });
1789117892
} else {
1789217893
return $panic();
@@ -18107,7 +18108,7 @@ function moonbitlang$yacc$lib$parser$$yy_action_46(_last_pos, _args) {
1810718108
const _YYObj__ast_Symbol = _bind;
1810818109
const _symbol = _YYObj__ast_Symbol._0;
1810918110
const _start_pos = moonbitlang$core$array$$ArrayView$op_get$123$(_args, 0)._1;
18110-
const _end_pos = moonbitlang$core$array$$ArrayView$op_get$123$(_args, 0)._2;
18111+
const _end_pos = moonbitlang$core$array$$ArrayView$op_get$123$(_args, moonbitlang$core$array$$ArrayView$length$123$(_args) - 1 | 0)._2;
1811118112
return new Error$moonbitlang$47$yacc$47$lib$47$parser$46$YYObj__ast_Term$46$YYObj__ast_Term(new $64$moonbitlang$47$yacc$47$lib$47$ast$46$Term$Symbol(_symbol, { _0: _start_pos, _1: _end_pos }));
1811218113
} else {
1811318114
return $panic();
@@ -25408,9 +25409,8 @@ function moonbitlang$yacc$lib$elab$$elaborate_action$46$item_ident_to_index$248$
2540825409
}
2540925410
}
2541025411
function moonbitlang$yacc$lib$elab$$elaborate_action$46$add_binding$249$(_env, desc) {
25411-
const items = _env._4;
25412-
const visited = _env._3;
25413-
const arity = _env._2;
25412+
const items = _env._3;
25413+
const visited = _env._2;
2541425414
const bindings = _env._1;
2541525415
const name_to_index = _env._0;
2541625416
let _tmp = desc;
@@ -25427,40 +25427,30 @@ function moonbitlang$yacc$lib$elab$$elaborate_action$46$add_binding$249$(_env, d
2542725427
return;
2542825428
}
2542925429
case 1: {
25430-
if (arity === 0) {
25431-
moonbitlang$core$array$$Array$push$17$(bindings, { _0: $64$moonbitlang$47$yacc$47$lib$47$elab$46$BindingSubject$LastPos, _1: "_start_pos" });
25432-
return;
25433-
} else {
25434-
moonbitlang$core$array$$Array$push$17$(bindings, { _0: new $64$moonbitlang$47$yacc$47$lib$47$elab$46$BindingSubject$StartPos(0), _1: "_start_pos" });
25435-
return;
25436-
}
25430+
moonbitlang$core$array$$Array$push$17$(bindings, { _0: $64$moonbitlang$47$yacc$47$lib$47$elab$46$BindingSubject$StartPos, _1: "_start_pos" });
25431+
return;
2543725432
}
2543825433
case 3: {
2543925434
moonbitlang$yacc$lib$elab$$elaborate_action$46$add_binding$249$(_env, $64$moonbitlang$47$yacc$47$lib$47$ast$46$SubstItemDesc$StartPos);
2544025435
_tmp = $64$moonbitlang$47$yacc$47$lib$47$ast$46$SubstItemDesc$EndPos;
2544125436
continue _L;
2544225437
}
2544325438
case 2: {
25444-
if (arity === 0) {
25445-
moonbitlang$core$array$$Array$push$17$(bindings, { _0: $64$moonbitlang$47$yacc$47$lib$47$elab$46$BindingSubject$LastPos, _1: "_end_pos" });
25446-
return;
25447-
} else {
25448-
moonbitlang$core$array$$Array$push$17$(bindings, { _0: new $64$moonbitlang$47$yacc$47$lib$47$elab$46$BindingSubject$EndPos(arity - 1 | 0), _1: "_end_pos" });
25449-
return;
25450-
}
25439+
moonbitlang$core$array$$Array$push$17$(bindings, { _0: $64$moonbitlang$47$yacc$47$lib$47$elab$46$BindingSubject$EndPos, _1: "_end_pos" });
25440+
return;
2545125441
}
2545225442
case 4: {
2545325443
const _StartPosOf = desc$2;
2545425444
const _arg = _StartPosOf._0;
2545525445
const index = moonbitlang$yacc$lib$elab$$elaborate_action$46$item_ident_to_index$248$(name_to_index, _arg);
25456-
moonbitlang$core$array$$Array$push$17$(bindings, { _0: new $64$moonbitlang$47$yacc$47$lib$47$elab$46$BindingSubject$StartPos(index), _1: `_start_pos_of_item${moonbitlang$core$builtin$$Show$to_string$13$(index)}` });
25446+
moonbitlang$core$array$$Array$push$17$(bindings, { _0: new $64$moonbitlang$47$yacc$47$lib$47$elab$46$BindingSubject$StartPosOf(index), _1: `_start_pos_of_item${moonbitlang$core$builtin$$Show$to_string$13$(index)}` });
2545725447
return;
2545825448
}
2545925449
case 5: {
2546025450
const _EndPosOf = desc$2;
2546125451
const _arg$2 = _EndPosOf._0;
2546225452
const index$2 = moonbitlang$yacc$lib$elab$$elaborate_action$46$item_ident_to_index$248$(name_to_index, _arg$2);
25463-
moonbitlang$core$array$$Array$push$17$(bindings, { _0: new $64$moonbitlang$47$yacc$47$lib$47$elab$46$BindingSubject$EndPos(index$2), _1: `_end_pos_of_item${moonbitlang$core$builtin$$Show$to_string$13$(index$2)}` });
25453+
moonbitlang$core$array$$Array$push$17$(bindings, { _0: new $64$moonbitlang$47$yacc$47$lib$47$elab$46$BindingSubject$EndPosOf(index$2), _1: `_end_pos_of_item${moonbitlang$core$builtin$$Show$to_string$13$(index$2)}` });
2546425454
return;
2546525455
}
2546625456
case 6: {
@@ -25509,7 +25499,7 @@ function moonbitlang$yacc$lib$elab$$elaborate_action(items, ast_action, parser_s
2550925499
}
2551025500
const bindings = [];
2551125501
const visited = moonbitlang$core$sorted_set$$new$44$();
25512-
const _env = { _0: name_to_index, _1: bindings, _2: arity, _3: visited, _4: items };
25502+
const _env = { _0: name_to_index, _1: bindings, _2: visited, _3: items };
2551325503
const body = [];
2551425504
if (json_cst === 0) {
2551525505
const _len$2 = items.length;
@@ -26607,21 +26597,21 @@ function moonbitlang$yacc$lib$desugar$$eliminate_inline_rules$46$cont$260$(_env,
2660726597
}
2660826598
break;
2660926599
}
26610-
case 2: {
26611-
const _StartPos = _subject;
26612-
const _data_index$2 = _StartPos._0;
26600+
case 1: {
26601+
const _StartPosOf = _subject;
26602+
const _data_index$2 = _StartPosOf._0;
2661326603
if (_data_index$2 > start_index) {
26614-
new_subject = new $64$moonbitlang$47$yacc$47$lib$47$elab$46$BindingSubject$StartPos(_data_index$2 + index_shift | 0);
26604+
new_subject = new $64$moonbitlang$47$yacc$47$lib$47$elab$46$BindingSubject$StartPosOf(_data_index$2 + index_shift | 0);
2661526605
} else {
2661626606
break _L$5;
2661726607
}
2661826608
break;
2661926609
}
26620-
case 3: {
26621-
const _EndPos = _subject;
26622-
const _data_index$3 = _EndPos._0;
26610+
case 2: {
26611+
const _EndPosOf = _subject;
26612+
const _data_index$3 = _EndPosOf._0;
2662326613
if (_data_index$3 > start_index) {
26624-
new_subject = new $64$moonbitlang$47$yacc$47$lib$47$elab$46$BindingSubject$EndPos(_data_index$3 + index_shift | 0);
26614+
new_subject = new $64$moonbitlang$47$yacc$47$lib$47$elab$46$BindingSubject$EndPosOf(_data_index$3 + index_shift | 0);
2662526615
} else {
2662626616
break _L$5;
2662726617
}
@@ -28427,23 +28417,35 @@ function moonbitlang$yacc$lib$codegen$gen_mbt$$codegen(grammar, automaton, meta,
2842728417
}
2842828418
break;
2842928419
}
28430-
case 1: {
28431-
moonbitlang$core$builtin$$Logger$write_string$247$(output, ` let ${moonbitlang$core$builtin$$Show$to_string$14$(binding._1)} = _last_pos\n`);
28420+
case 3: {
28421+
if (action.arity === 0) {
28422+
moonbitlang$core$builtin$$Logger$write_string$247$(output, ` let ${moonbitlang$core$builtin$$Show$to_string$14$(binding._1)} = _last_pos\n`);
28423+
} else {
28424+
moonbitlang$core$builtin$$Logger$write_string$247$(output, ` let ${moonbitlang$core$builtin$$Show$to_string$14$(binding._1)} = _args[0].1\n`);
28425+
}
2843228426
break;
2843328427
}
28434-
case 2: {
28435-
const _StartPos = _bind$4;
28436-
const _index$2 = _StartPos._0;
28428+
case 4: {
28429+
if (action.arity === 0) {
28430+
moonbitlang$core$builtin$$Logger$write_string$247$(output, ` let ${moonbitlang$core$builtin$$Show$to_string$14$(binding._1)} = _last_pos\n`);
28431+
} else {
28432+
moonbitlang$core$builtin$$Logger$write_string$247$(output, ` let ${moonbitlang$core$builtin$$Show$to_string$14$(binding._1)} = _args[_args.length() - 1].2\n`);
28433+
}
28434+
break;
28435+
}
28436+
case 1: {
28437+
const _StartPosOf = _bind$4;
28438+
const _index$2 = _StartPosOf._0;
2843728439
index = _index$2;
2843828440
break _L$2;
2843928441
}
28440-
case 3: {
28441-
const _EndPos = _bind$4;
28442-
const _index$3 = _EndPos._0;
28442+
case 2: {
28443+
const _EndPosOf = _bind$4;
28444+
const _index$3 = _EndPosOf._0;
2844328445
index = _index$3;
2844428446
break _L$2;
2844528447
}
28446-
case 4: {
28448+
case 5: {
2844728449
moonbitlang$core$sorted_set$$T$add$14$(used_runtime_funcs, "_get_symbol_start_pos");
2844828450
moonbitlang$core$builtin$$Logger$write_string$247$(output, ` let ${moonbitlang$core$builtin$$Show$to_string$14$(binding._1)} = _get_symbol_start_pos(_args, _last_pos)\n`);
2844928451
break;
@@ -28489,11 +28491,11 @@ function moonbitlang$yacc$lib$codegen$gen_mbt$$codegen(grammar, automaton, meta,
2848928491
const _bind$4 = binding._0;
2849028492
let field;
2849128493
switch (_bind$4.$tag) {
28492-
case 2: {
28494+
case 1: {
2849328495
field = 1;
2849428496
break;
2849528497
}
28496-
case 3: {
28498+
case 2: {
2849728499
field = 2;
2849828500
break;
2849928501
}

moon.mod.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "moonbitlang/yacc",
3-
"version": "0.3.28",
3+
"version": "0.3.30",
44
"deps": {
55
"moonbitlang/x": "0.4.23",
66
"Yoorkin/ArgParser": "0.1.9"

src/lib/codegen/gen_mbt/gen_mbt.mbt

Lines changed: 31 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -518,13 +518,35 @@ fn codegen(
518518
)
519519
}
520520
}
521-
LastPos =>
522-
output.write_string(
523-
$| let \{binding.1} = _last_pos
524-
$|
525-
,
526-
)
527-
StartPos(index) | EndPos(index) =>
521+
StartPos =>
522+
if action.arity == 0 {
523+
output.write_string(
524+
$| let \{binding.1} = _last_pos
525+
$|
526+
,
527+
)
528+
} else {
529+
output.write_string(
530+
$| let \{binding.1} = _args[0].1
531+
$|
532+
,
533+
)
534+
}
535+
EndPos =>
536+
if action.arity == 0 {
537+
output.write_string(
538+
$| let \{binding.1} = _last_pos
539+
$|
540+
,
541+
)
542+
} else {
543+
output.write_string(
544+
$| let \{binding.1} = _args[_args.length() - 1].2
545+
$|
546+
,
547+
)
548+
}
549+
StartPosOf(index) | EndPosOf(index) =>
528550
if action.arity == 0 {
529551
output.write_string(
530552
$| let \{binding.1} = _last_pos
@@ -533,8 +555,8 @@ fn codegen(
533555
)
534556
} else {
535557
let field = match binding.0 {
536-
StartPos(_) => 1
537-
EndPos(_) => 2
558+
StartPosOf(_) => 1
559+
EndPosOf(_) => 2
538560
_ => panic()
539561
}
540562
output.write_string(

src/lib/desugar/eliminate_inline.mbt

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -91,10 +91,10 @@ fn eliminate_inline_rules(
9191
SubAction(index=subaction_index, type_~)
9292
Data(data_index, type_~) if data_index > start_index =>
9393
Data(data_index + index_shift, type_~)
94-
StartPos(data_index) if data_index > start_index =>
95-
StartPos(data_index + index_shift)
96-
EndPos(data_index) if data_index > start_index =>
97-
EndPos(data_index + index_shift)
94+
StartPosOf(data_index) if data_index > start_index =>
95+
StartPosOf(data_index + index_shift)
96+
EndPosOf(data_index) if data_index > start_index =>
97+
EndPosOf(data_index + index_shift)
9898
_ => subject
9999
}
100100
(new_subject, code)

src/lib/elab/east.mbt

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -136,9 +136,10 @@ pub(all) struct SubAction {
136136
///|
137137
pub(all) enum BindingSubject {
138138
Data(Int, type_~ : TypeExpr)
139-
LastPos
140-
StartPos(Int)
141-
EndPos(Int)
139+
StartPosOf(Int)
140+
EndPosOf(Int)
141+
StartPos
142+
EndPos
142143
SymbolStartPos
143144
SubAction(index~ : Int, type_~ : TypeExpr)
144145
}

src/lib/elab/elaborate.mbt

Lines changed: 4 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -422,29 +422,19 @@ fn elaborate_action(
422422
let name = "_dollar\{index}"
423423
bindings.push((Data(index - 1, type_=items[index - 1].type_()), name))
424424
}
425-
StartPos =>
426-
if arity == 0 {
427-
bindings.push((LastPos, "_start_pos"))
428-
} else {
429-
bindings.push((StartPos(0), "_start_pos"))
430-
}
425+
StartPos => bindings.push((StartPos, "_start_pos"))
431426
Loc => {
432427
add_binding(StartPos)
433428
add_binding(EndPos)
434429
}
435-
EndPos =>
436-
if arity == 0 {
437-
bindings.push((LastPos, "_end_pos"))
438-
} else {
439-
bindings.push((EndPos(arity - 1), "_end_pos"))
440-
}
430+
EndPos => bindings.push((EndPos, "_end_pos"))
441431
StartPosOf(arg) => {
442432
let index = item_ident_to_index(arg)
443-
bindings.push((StartPos(index), "_start_pos_of_item\{index}"))
433+
bindings.push((StartPosOf(index), "_start_pos_of_item\{index}"))
444434
}
445435
EndPosOf(arg) => {
446436
let index = item_ident_to_index(arg)
447-
bindings.push((EndPos(index), "_end_pos_of_item\{index}"))
437+
bindings.push((EndPosOf(index), "_end_pos_of_item\{index}"))
448438
}
449439
LocOf(arg) => {
450440
add_binding(StartPosOf(arg))

0 commit comments

Comments
 (0)