如何将变量传递到准引用部分?
我正在使用llvm-quote-general并希望将 Type
传递到我使用准引用器构建的指令中。
我可以仅从文本构建指令:
alloci64 :: Instruction
alloci64 = [lli|alloc i64|]
我希望能够传递一个类型。这样做的语法是什么?
alloc :: Type -> Instruction
alloc t = [lli|alloc t|]
我已经尝试了以下所有方法,但没有一个有效。它们会导致词法分析器错误
。
[lli|alloc $t|]
[lli|alloc $$t|]
[lli|alloc $t$|]
[lli|alloc $$t$$|]
库中的quasiquoter是用happy生成的。查看源代码,我能找到的与反引号相关的标记最接近的是符号 happy_dollar_dollar
,它似乎没有在任何地方定义。
编辑:我解决了 Type
的问题;一个例子是 [lli|alloc $type:t]
操作数
我用 Type
解决了这个问题,但仍然不知道如何对一般内容进行反引号。我想使用Operand
来构建指令。尝试这样做会导致错误。
add' :: Operand -> Operand -> Instruction
add' a b = [lli|add $opr:a $opr:b|]
^
parse error on `ANTI_OPR'
pre-happy source建议以下所有内容(包括 $opr:
)应该执行某些操作
<0> {
"$dl:" / { allowAnti } { lexAnti Tanti_dl }
"$dlM:" / { allowAnti } { lexAntiM Tanti_dl }
"$tt:" / { allowAnti } { lexAnti Tanti_tt }
"$ttM:" / { allowAnti } { lexAntiM Tanti_tt }
"$def:" / { allowAnti } { lexAnti Tanti_def }
"$defM:" / { allowAnti } { lexAntiM Tanti_def }
"$defs:" / { allowAnti } { lexAnti Tanti_defs }
"$defsM:" / { allowAnti } { lexAntiM Tanti_defs }
"$bb:" / { allowAnti } { lexAnti Tanti_bb }
"$bbM:" / { allowAnti } { lexAntiM Tanti_bb }
"$bbs:" / { allowAnti } { lexAnti Tanti_bbs }
"$bbsM:" / { allowAnti } { lexAntiM Tanti_bbs }
"$instr:" / { allowAnti } { lexAnti Tanti_instr }
"$instrM:" / { allowAnti } { lexAntiM Tanti_instr }
"$instrs:" / { allowAnti } { lexAnti Tanti_instrs }
"$instrsM:" / { allowAnti } { lexAntiM Tanti_instrs }
"$type:" / { allowAnti } { lexAnti Tanti_type }
"$typeM:" / { allowAnti } { lexAntiM Tanti_type }
"$opr:" / { allowAnti } { lexAnti Tanti_opr }
"$oprM:" / { allowAnti } { lexAntiM Tanti_opr }
"$const:" / { allowAnti } { lexAnti Tanti_const }
"$constM:" / { allowAnti } { lexAntiM Tanti_const }
"$id:" / { allowAnti } { lexAnti Tanti_id }
"$idM:" / { allowAnti } { lexAntiM Tanti_id }
"$gid:" / { allowAnti } { lexAnti Tanti_gid }
"$gidM:" / { allowAnti } { lexAntiM Tanti_gid }
"$param:" / { allowAnti } { lexAnti Tanti_param }
"$paramM:" / { allowAnti } { lexAntiM Tanti_param }
"$params:" / { allowAnti } { lexAnti Tanti_params }
"$paramsM:" / { allowAnti } { lexAntiM Tanti_params }
}
最佳答案
再摆弄一些,以下有效
alloc :: Type -> Instruction
alloc t = [lli|alloc $type:t|]
字符串“type”
位于 the source code其他示例包含类似 $exp:e1
的文本,但没有解释它的含义。
关于haskell - 准引用 LLVM 中的引用变量,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/27885679/