@@ 1,65 1,27 @@
-# available factors:
+# for an overview of factors, see compiler.noir.renoir
- EQ|NE $x $a $b
- LE|LT|GE|GT $x $a $b
- ADD|SUB|MUL|DIV $x $a $b
- IDPAIR $ab $a $b
- CONST|MACRO $value
- NAMEABLE|CCONV|CRETTYPE|CELEMENTTYPE|GLOBAL $value
- CFUNCTION $cfunction $cconv $rtype $numargs
- FNTYPEPARAM $cfunction $index $type
- CVARIADIC $cvariadic $cfunction $numargs
- VATYPEPARAM $cvariadic $index $type
- OP $macro $effect $op
- ARGCOUNT $macro $effect $op
- ARG $macro $effect $index $value
- FOLLOW $macro $value $target
- NDEP $macro $effect $value $mode
- DEP $macro $effect $value $mode
- SIZEOF $macro $value $size
- ANCHOROF $macro $value $anchor
- TYPESIZEOF $T $size
- FOLDOP $x $op $a $b
- EXPORT $macro $key $value
- REPLACEOF $macro $value
- VAMAP $va_index $key $value
- VA $va_index $key $value
- VACOUNT $index $count
- RANGE $i $begin $end
- RRANGE $i $begin $end
- FUNC $func $ftype $macro
- SYMINFO $target $name
- KINDOF $value $T
- INDEXOF $value $index
- METAOP? $op $is_meta
- SIDEOP? $op $is_side
- CONSTDATA $const $sym
- INDEXDATA $index $sym
- INSTANCE $destmacro $sourcemacro $key
+# preprocessing rules
+$RULE FOLLOWARG
+ ;
+ !FOLLOWARG $ctx $id $i $arg
+ ;
+ ARG $ctx $id $i ($CAT $arg _)
+ FOLLOW $ctx ($CAT $arg _) $arg
+$RULE FOLLOWDEP
+ ;
+ !FOLLOWDEP $ctx $id $arg $mode
+ ;
+ DEP $ctx $id ($CAT $arg _) $mode
+ FOLLOW $ctx ($CAT $arg _) $arg
-# template only:
-
- COMPLAIN|CGENERROR|EXPLAIN|REMARK $macro $value $symbol
- DUMP $value
- DUMPVA $index
- TRACE $macro $value
- FNTYPEVA $type $cconv $rtype $index
- VATYPEVA $type $ftype $index
- DLIMPORT $dlsym $name
- ALIAS $macro $value $target
-
-# TODO:
- an unreachable instance effect using a macro that has no side effects can be
- removed.
+# define renoir rule
OP2-fold
# fold constant arithmetic operations
;
OP $ctx $id $op
- ARG $ctx $id 1 $b_
- ARG $ctx $id 0 $a_
- FOLLOW $ctx $a_ $a
+ !FOLLOWARG $ctx $id 0 $a
CONST $a
- FOLLOW $ctx $b_ $b
+ !FOLLOWARG $ctx $id 1 $b
CONST $b
FOLDOP2 $x $op $a $b
;
@@ 67,11 29,9 @@ OP2-fold
case-fold
;
OP $ctx $id case
- ARG $ctx $id 1 $b_
- ARG $ctx $id 0 $a_
- FOLLOW $ctx $a_ $a
+ !FOLLOWARG $ctx $id 0 $a
CONST $a
- FOLLOW $ctx $b_ $b
+ !FOLLOWARG $ctx $id 1 $b
CONST $b
;
RULE
@@ 87,8 47,7 @@ case-fold
DLIMPORT
;
OP $ctx $id DLIMPORT
- ARG $ctx $id 0 $name_
- FOLLOW $ctx $name_ $name
+ !FOLLOWARG $ctx $id 0 $name
CONST $name
;
DLIMPORT $dlid $name
@@ 96,11 55,9 @@ DLIMPORT
SYMINFO
;
OP $ctx $id SYMINFO
- ARG $ctx $id 1 $name_
- FOLLOW $ctx $name_ $name
+ !FOLLOWARG $ctx $id 1 $name
CONST $name
- ARG $ctx $id 0 $target_
- FOLLOW $ctx $target_ $target
+ !FOLLOWARG $ctx $id 0 $target
NAMEABLE $target
;
SYMINFO $target $name
@@ 108,14 65,11 @@ SYMINFO
SYMINFO-CLOSURE
;
OP $ctx $id SYMINFO
- ARG $ctx $id 1 $name_
- FOLLOW $ctx $name_ $name
+ !FOLLOWARG $ctx $id 1 $name
CONST $name
- ARG $ctx $id 0 $target___
- FOLLOW $ctx $target___ $target__
+ !FOLLOWARG $ctx $id 0 $target__
OP $ctx $target__ CLOSURE
- ARG $ctx $target__ 0 $target_
- FOLLOW $ctx $target_ $target
+ !FOLLOWARG $ctx $target__ 0 $target
NAMEABLE $target
;
SYMINFO $target $name
@@ 123,19 77,16 @@ SYMINFO-CLOSURE
FNTYPE
;
OP $ctx $id FNTYPE
- ARG $ctx $id 0 $cconv_
- FOLLOW $ctx $cconv_ $cconv
+ !FOLLOWARG $ctx $id 0 $cconv
CCONV $cconv
- ARG $ctx $id 1 $rtype_
- FOLLOW $ctx $rtype_ $rtype
+ !FOLLOWARG $ctx $id 1 $rtype
CRETTYPE $rtype
ARGCOUNT $ctx $id $argcount
RULE () ((VACOUNT 0 0))
RULE
;
RANGE $i 2 $argcount
- ARG $ctx $id $i $arg_
- FOLLOW $ctx $arg_ $arg
+ !FOLLOWARG $ctx $id $i $arg
CELEMENTTYPE $arg
;
VA 0 _ $arg
@@ 147,16 98,14 @@ FNTYPE
VATYPE
;
OP $ctx $id VATYPE
- ARG $ctx $id 0 $ftype_
- FOLLOW $ctx $ftype_ $ftype
+ !FOLLOWARG $ctx $id 0 $ftype
KINDOF $ftype CFunction
ARGCOUNT $ctx $id $argcount
RULE () ((VACOUNT 0 0))
RULE
;
RANGE $i 1 $argcount
- ARG $ctx $id $i $arg_
- FOLLOW $ctx $arg_ $arg
+ !FOLLOWARG $ctx $id $i $arg
CELEMENTTYPE $arg
;
VA 0 _ $arg
@@ 168,11 117,9 @@ VATYPE
FUNC
;
OP $ctx $id FUNC
- ARG $ctx $id 0 $ftype_
- FOLLOW $ctx $ftype_ $ftype
+ !FOLLOWARG $ctx $id 0 $ftype
KINDOF $ftype CFunction
- ARG $ctx $id 1 $macro_
- FOLLOW $ctx $macro_ $macro
+ !FOLLOWARG $ctx $id 1 $macro
MACRO $macro
;
RULE
@@ 192,14 139,12 @@ FUNC
SAME
;
OP $ctx $id SAME
- ARG $ctx $id 0 $a_
- FOLLOW $ctx $a_ $a
+ !FOLLOWARG $ctx $id 0 $a
NOT
KINDOF $a Instruction
OP $ctx $a $tmpop
METAOP? $tmpop true
- ARG $ctx $id 0 $b_
- FOLLOW $ctx $b_ $b
+ !FOLLOWARG $ctx $id 0 $b
NOT
KINDOF $a Instruction
OP $ctx $a $tmpop
@@ 220,14 165,11 @@ SAME
ATTRTO
;
OP $ctx $id ATTRTO
- ARG $ctx $id 0 $dest_
- FOLLOW $ctx $dest_ $dest
+ !FOLLOWARG $ctx $id 0 $dest
MACRO $dest
- ARG $ctx $id 1 $name_
- FOLLOW $ctx $name_ $name
+ !FOLLOWARG $ctx $id 1 $name
CONST $name
- ARG $ctx $id 2 $value_
- FOLLOW $ctx $value_ $value
+ !FOLLOWARG $ctx $id 2 $value
NOT
KINDOF $value Instruction
;
@@ 236,8 178,7 @@ ATTRTO
#MAPOF
;
OP $ctx $id MAPOF
- ARG $ctx $id 0 $src_
- FOLLOW $ctx $src_ $src
+ !FOLLOWARG $ctx $id 0 $src
MACRO $src
;
ALIAS $ctx $id $src_
@@ 245,11 186,9 @@ ATTRTO
# needs to be rewritten for inlined instances
;
OP $ctx $id ATTROF
- ARG $ctx $id 0 $src_
- FOLLOW $ctx $src_ $src
+ !FOLLOWARG $ctx $id 0 $src
MACRO $src
- ARG $ctx $id 1 $name_
- FOLLOW $ctx $name_ $name
+ !FOLLOWARG $ctx $id 1 $name
CONST $name
EXPORT $src $name $value_
FOLLOW $src $value_ $value
@@ 273,11 212,9 @@ ATTRTO
REPLACEOF
;
OP $ctx $id REPLACEOF
- ARG $ctx $id 0 $inst_
- FOLLOW $ctx $inst_ $inst
+ !FOLLOWARG $ctx $id 0 $inst
OP $ctx $inst MAP
- ARG $ctx $inst 0 $src_
- FOLLOW $ctx $src_ $src
+ !FOLLOWARG $ctx $inst 0 $src
MACRO $src
REPLACEOF $src $value_
INDEXOF $value_ $idx_
@@ 318,14 255,12 @@ CLOSURE-resolve-va-upattr
we assume that the closure is uniquely used and do not instance it
;
OP $ctx $id CLOSURE
- ARG $ctx $id 0 $macro_
- FOLLOW $ctx $macro_ $macro
+ !FOLLOWARG $ctx $id 0 $macro
MACRO $macro
OP $macro $mid UPATTR
ARG $macro $mid 0 $i_
ADD $i $i_ 1
- ARG $ctx $id $i $value_
- FOLLOW $ctx $value_ $value
+ !FOLLOWARG $ctx $id $i $value
OP $ctx $value VA
;
OP $macro $mid VA
@@ 352,16 287,13 @@ CLOSURE-resolve-closure-upattr
;
# match closure containing another valid closure as argument
OP $ctx $id CLOSURE
- ARG $ctx $id 0 $macro_
- FOLLOW $ctx $macro_ $macro
+ !FOLLOWARG $ctx $id 0 $macro
MACRO $macro
ARGCOUNT $ctx $id $argcount
RANGE $idx 1 $argcount
- ARG $ctx $id $idx $arg_
- FOLLOW $ctx $arg_ $clid
+ !FOLLOWARG $ctx $id $idx $clid
OP $ctx $clid CLOSURE
- ARG $ctx $clid 0 $clmacro_
- FOLLOW $ctx $clmacro_ $clmacro
+ !FOLLOWARG $ctx $clid 0 $clmacro
MACRO $clmacro
ARGCOUNT $ctx $clid $clargcount
SUB $start $clargcount 1
@@ 398,8 330,7 @@ CLOSURE-resolve-upattr
we assume that the closure is uniquely used and do not instance it
;
OP $ctx $id CLOSURE
- ARG $ctx $id 0 $macro_
- FOLLOW $ctx $macro_ $macro
+ !FOLLOWARG $ctx $id 0 $macro
MACRO $macro
RULE () ((VACOUNT 0 0) (VACOUNT 1 0) (VACOUNT 2 0))
RULE
@@ 407,8 338,7 @@ CLOSURE-resolve-upattr
OP $macro $mid UPATTR
ARG $macro $mid 0 $i_
ADD $i $i_ 1
- ARG $ctx $id $i $value_
- FOLLOW $ctx $value_ $value
+ !FOLLOWARG $ctx $id $i $value
GLOBAL $value
;
VA 0 _ $mid
@@ 429,8 359,7 @@ CLOSURE-resolve-upattr
# remove unused upattrs from closure
;
OP $ctx $id CLOSURE
- ARG $ctx $id 0 $macro_
- FOLLOW $ctx $macro_ $macro
+ !FOLLOWARG $ctx $id 0 $macro
MACRO $macro
ARGCOUNT $ctx $id $original_n
RULE () ((VACOUNT 0 0) (VACOUNT 1 0))
@@ 484,8 413,7 @@ CLOSURE-0
OP $ctx $id CLOSURE
ARGCOUNT $ctx $id $n
EQ true $n 1
- ARG $ctx $id 0 $macro_
- FOLLOW $ctx $macro_ $macro
+ !FOLLOWARG $ctx $id 0 $macro
MACRO $macro
;
ALIAS $ctx $id $macro_
@@ 493,12 421,10 @@ APPLY-MACRO
# inline APPLY to macro
;
OP $ctx $id APPLY
- ARG $ctx $id 0 $macro_
- FOLLOW $ctx $macro_ $macro
+ !FOLLOWARG $ctx $id 0 $macro
MACRO $macro
NOT # no argument to APPLY is a meta-instruction
- ARG $ctx $id _ $tmp_
- FOLLOW $ctx $tmp_ $tmp
+ !FOLLOWARG $ctx $id _ $tmp
KINDOF $tmp Instruction
OP $ctx $tmp $tmpop
METAOP? $tmpop true
@@ 583,15 509,12 @@ APPLY-CLOSURE
# inline APPLY to closure
;
OP $ctx $id APPLY
- ARG $ctx $id 0 $closure_
- FOLLOW $ctx $closure_ $closure
+ !FOLLOWARG $ctx $id 0 $closure
OP $ctx $closure CLOSURE
- ARG $ctx $closure 0 $macro_
- FOLLOW $ctx $macro_ $macro
+ !FOLLOWARG $ctx $closure 0 $macro
MACRO $macro
NOT # no argument to APPLY is a meta-instruction
- ARG $ctx $id _ $tmp_
- FOLLOW $ctx $tmp_ $tmp
+ !FOLLOWARG $ctx $id _ $tmp
KINDOF $tmp Instruction
OP $ctx $tmp $tmpop
METAOP? $tmpop true
@@ 686,19 609,16 @@ APPLY-CLOSURE
# transform APPLY to closure with upattrs to APPLY to macro with upattrs as arguments
;
OP $ctx $id APPLY
- ARG $ctx $id 0 $closure_
- FOLLOW $ctx $closure_ $closure
+ !FOLLOWARG $ctx $id 0 $closure
OP $ctx $closure CLOSURE
ARGCOUNT $ctx $closure $closure_n
NE true $closure_n 1
- ARG $ctx $closure 0 $macro_
- FOLLOW $ctx $macro_ $macro
+ !FOLLOWARG $ctx $closure 0 $macro
MACRO $macro
ARGCOUNT $ctx $id $id_n
SUB $numinattrs $id_n 1
NOT
- ARG $ctx $id _ $tmp_
- FOLLOW $ctx $tmp_ $tmp
+ !FOLLOWARG $ctx $id _ $tmp
KINDOF $tmp Instruction
OP $ctx $tmp $tmpop
METAOP? $tmpop true
@@ 726,19 646,16 @@ APPLY-operator
# promote APPLY on operator to real effect if it has no meta deps
;
OP $ctx $id APPLY
- ARG $ctx $id 0 $f_
- FOLLOW $ctx $f_ $f
+ !FOLLOWARG $ctx $id 0 $f
KINDOF $f Op
METAOP? $f false
NOT
- ARG $ctx $id _ $tmp_
- FOLLOW $ctx $tmp_ $tmp
+ !FOLLOWARG $ctx $id _ $tmp
KINDOF $tmp Instruction
OP $ctx $tmp $tmpop
METAOP? $tmpop true
NOT
- DEP $ctx $id $tmp_ _
- FOLLOW $ctx $tmp_ $tmp
+ !FOLLOWDEP $ctx $id $tmp _
KINDOF $tmp Instruction
OP $ctx $tmp $tmpop
METAOP? $tmpop true
@@ 759,8 676,7 @@ APPLY-operator
# transform global arguments passed to instance to instance with inlined argument
;
OP $ctx $id instance
- ARG $ctx $id 0 $macro_
- FOLLOW $ctx $macro_ $macro
+ !FOLLOWARG $ctx $id 0 $macro
MACRO $macro
RULE () ((VACOUNT 0 0) (VACOUNT 1 0) (VACOUNT 2 0))
RULE
@@ 768,8 684,7 @@ APPLY-operator
OP $macro $mid INATTR
ARG $macro $mid 0 $i_
ADD $i $i_ 1
- ARG $ctx $id $i $value_
- FOLLOW $ctx $value_ $value
+ !FOLLOWARG $ctx $id $i $value
GLOBAL $value
;
VA 0 _ $mid
@@ 799,8 714,7 @@ or-elide-unused
RULE () ((VACOUNT 0 0))
RULE
;
- ARG $ctx $id $i $arg_
- FOLLOW $ctx $arg_ $arg
+ !FOLLOWARG $ctx $id $i $arg
KINDOF $arg ConstUndef
;
VA 0 _ $i
@@ 833,8 747,7 @@ pass-elide-constant
# elide pass effect with constant
;
OP $ctx $id pass
- ARG $ctx $id 0 $arg_
- FOLLOW $ctx $arg_ $arg
+ !FOLLOWARG $ctx $id 0 $arg
NOT
KINDOF $arg Instruction
NOT
@@ 845,8 758,7 @@ DEP-fold
# fold decidable dependencies
;
OP $ctx $id _
- DEP $ctx $id $src_ $mode
- FOLLOW $ctx $src_ $src
+ !FOLLOWDEP $ctx $id $src $mode
KINDOF $src $srckind
NE true $srckind Instruction
;
@@ 896,8 808,7 @@ DEP-fold
EQ false $op MAP
EQ false $op CLOSURE
ARGCOUNT $ctx $id $n
- ARG $ctx $id $i $arg_
- FOLLOW $ctx $arg_ $arg
+ !FOLLOWARG $ctx $id $i $arg
OP $ctx $arg VA
ADD $i+1 $i 1
;
@@ 930,8 841,7 @@ SLICE-convert-const-to-indexattr
;
OP $ctx $fx SLICE
RANGE $i 1 3
- ARG $ctx $fx $i $arg_
- FOLLOW $ctx $arg_ $arg
+ !FOLLOWARG $ctx $fx $i $arg
CONST $arg
CONSTDATA $arg $argd
INDEXDATA $argi $argd
@@ 940,20 850,16 @@ SLICE-convert-const-to-indexattr
SLICE-VA
;
OP $ctx $fx SLICE
- ARG $ctx $fx 0 $id_
- FOLLOW $ctx $id_ $id
+ !FOLLOWARG $ctx $fx 0 $id
OP $ctx $id VA
NOT
- ARG $ctx $id _ $arg_
- FOLLOW $ctx $arg_ $arg
+ !FOLLOWARG $ctx $id _ $arg
OP $ctx $arg $op
METAOP? $op true
ARGCOUNT $ctx $id $n
- ARG $ctx $fx 1 $begin_
- FOLLOW $ctx $begin_ $begin
+ !FOLLOWARG $ctx $fx 1 $begin
KINDOF $begin IndexAttr
- ARG $ctx $fx 2 $end_
- FOLLOW $ctx $end_ $end
+ !FOLLOWARG $ctx $fx 2 $end
KINDOF $end IndexAttr
;
OP $ctx $fx VA
@@ 968,12 874,10 @@ COUNTOF-VA
# count elements in a reduced VA
;
OP $ctx $fx COUNTOF
- ARG $ctx $fx 0 $id_
- FOLLOW $ctx $id_ $id
+ !FOLLOWARG $ctx $fx 0 $id
OP $ctx $id VA
NOT
- ARG $ctx $id _ $arg_
- FOLLOW $ctx $arg_ $arg
+ !FOLLOWARG $ctx $id _ $arg
OP $ctx $arg $op
METAOP? $op true
ARGCOUNT $ctx $id $n