在我的SBT项目中,我有一个输入文件,src/main/greeting/Greeting.txt其中包含以下内容:
Hello, world!
Run Code Online (Sandbox Code Playgroud)
这是我build.sbt从Greeting.txt文件中生成Scala源:
sourceGenerators in Compile += Def.task{
println("GENERATING FILES")
val inputFile = file("src/main/greeting/Greeting.txt")
val generatedFile =
(sourceManaged in Compile).value / "scala" / "Main.scala"
val greeting = IO.read(inputFile).trim
IO.write(
generatedFile,
s"""object Main extends App { println("${greeting}") }"""
)
Seq(generatedFile)
}.taskValue
Run Code Online (Sandbox Code Playgroud)
这build.sbt很好,除了它每次编译/运行我的项目时都运行我的任务来生成Scala源.我希望它只在Greeting.txt-file已更改时运行这些任务.我怎样才能做到这一点?
生成项目的Bash脚本:
#!/bin/bash
mkdir sourceGeneratorsExample
cd sourceGeneratorsExample
mkdir -p src/main/scala
mkdir -p src/main/greeting
echo "Hello, world!" >> src/main/greeting/Greeting.txt
cat <<HEREDOC > build.sbt
sourceGenerators in …Run Code Online (Sandbox Code Playgroud) 我正在用C编写一个概念验证JIT编译器,它目前正在生成汇编代码串.C中的内联汇编功能仅处理编译时已知的字符串文字,因此我无法使用它来运行生成的运行时代码.
我已经阅读过使用mmap()在运行时执行生成的机器代码,但是如果可能的话,我想避免使用机器代码.
有谁知道任何解决方案?我曾想过将它写入文件并在所述文件上调用汇编程序和链接器,但这样做会很麻烦而且很慢.
在我的.vimrc中,我有:
:au BufWinEnter * let w:m1=matchadd('Search', '\%>80v.\+', -1)
Run Code Online (Sandbox Code Playgroud)
突出显示超过80个字符限制的行.如何设置它以便通过按功能键来打开/关闭它?
我在haskell写一个玩具语言.我正在使用Alex生成扫描仪.每次我使用cabal构建项目时,都会收到以下警告:
dist/build/optimiser/optimiser-tmp/Lexer.hs:465:1: Warning:
Tab character
dist/build/optimiser/optimiser-tmp/Lexer.hs:466:1: Warning:
Tab character
dist/build/optimiser/optimiser-tmp/Lexer.hs:467:1: Warning:
Tab character
dist/build/optimiser/optimiser-tmp/Lexer.hs:471:1: Warning:
Tab character
dist/build/optimiser/optimiser-tmp/Lexer.hs:472:1: Warning:
Tab character
(plus about 10 more of these warnings)
Run Code Online (Sandbox Code Playgroud)
似乎alex生成的扫描程序使用制表符而不是空格,而ghc的默认行为是警告用户这一点.
是否有人知道如何强制亚力克使用空格,或者从ghc(通过cabal)压制这些警告?
我一直在得到一个我无法弄清楚的分段错误.导致分段错误的功能如下所示:
Expression *IntegerLiteral_init(int intgr) {
Expression *the_exp = safe_alloc(sizeof(Expression));
the_exp->type = expr_IntegerLiteral;
the_exp->expr->intgr = intgr;
the_exp->exec_count = 0;
return the_exp;
}
Run Code Online (Sandbox Code Playgroud)
表达式定义为:
typedef struct {
expr_type type;
u_expr *expr;
int exec_count;
} Expression;
Run Code Online (Sandbox Code Playgroud)
定义了u_expr和expr_type:
typedef union {
char *ident;
int intgr;
} u_expr;
typedef enum {
expr_Identifier,
expr_IntegerLiteral
} expr_type;
Run Code Online (Sandbox Code Playgroud)
expr_type是的枚举expr_IntegerLiteral和expr_Identifier.
根据GDB的说法,段错误是由线引起的:the_exp->expr->intgr = intgr;.奇怪的是,它并不总是会导致段错误 - 如果我以这种方式调用函数会发生段错误:
Expression *e = IntegerLiteral_init(0);
Run Code Online (Sandbox Code Playgroud)
但在我的程序的另一部分,我称之为:
Expression *e;
...
e = IntegerLiteral_init(
(int)strtol(num_str, (char **)NULL, 10));
Run Code Online (Sandbox Code Playgroud)
这没有任何问题.num_str …
计算映射的惯用方法是什么,映射的映射是另一个映射的映射,没有其键是给定集合成员的映射?
例如,从给定的集合和下图:
Map(A -> v, B -> w, C -> x, D -> y, E -> z)
Set(A, C, E)
Run Code Online (Sandbox Code Playgroud)
我们的功能会产生:
Map(B -> w, D -> y)
Run Code Online (Sandbox Code Playgroud) c ×2
scala ×2
alex ×1
assembly ×1
cabal ×1
dictionary ×1
gnu ×1
haskell ×1
jit ×1
machine-code ×1
sbt ×1
set ×1
text-editor ×1
vim ×1