我有以下代码:
import sys
def entry_point(argv):
sys.exit(1)
return 0
def target(*args):
return entry_point, None
Run Code Online (Sandbox Code Playgroud)
但是,当我运行时,python ./pypy/pypy/translator/goal/translate.py t.py
我收到以下错误:
...
[translation:ERROR] Exception: unexpected prebuilt constant: <built-in function exit>
[translation:ERROR] Processing block:
[translation:ERROR] block@9 is a <class 'pypy.objspace.flow.flowcontext.SpamBlock'>
[translation:ERROR] in (t:3)entry_point
[translation:ERROR] containing the following operations:
[translation:ERROR] v0 = simple_call((builtin_function_or_method exit), (1))
[translation:ERROR] --end--
Run Code Online (Sandbox Code Playgroud)
实际上有更多的错误,但我认为只有最后一部分是相关的.如果你认为它可能会有所帮助,请发表评论,然后我会编辑.
实际上,当我将sys.exit替换为更简单的类似sys.stdout.write时,我会遇到另一个错误.
import sys
def entry_point(argv):
sys.stdout.write('some mesg\n')
return 0
def target(*args):
return entry_point, None
Run Code Online (Sandbox Code Playgroud)
给我:
...
[translation:ERROR] AnnotatorError: annotation of v0 degenerated to SomeObject()
[translation:ERROR] v0 = …
Run Code Online (Sandbox Code Playgroud) 我有一个类需要使用某种地图.默认情况下,我想使用std::map
,但我也希望让用户能够根据需要使用不同的东西(例如std::unordered_map
,甚至用户创建一个).
所以我的代码看起来像
#include <map>
template<class Key, template<class, class> class Map = std::map>
class MyClass {
};
int main() {
MyClass<int> mc;
}
Run Code Online (Sandbox Code Playgroud)
但是,g ++抱怨道
test.cpp:3:61: error: template template argument has different template parameters than its corresponding template template parameter
template<class Key, template<class, class> class Map = std::map>
^
test.cpp:8:14: note: while checking a default template argument used here
MyClass<int> mc;
~~~~~~~~~~~^
/Library/Developer/CommandLineTools/usr/bin/../include/c++/v1/map:781:1: note: too many template parameters in template template argument
template <class _Key, class _Tp, …
Run Code Online (Sandbox Code Playgroud) 如果log_error_count
至少1
在过去一分钟内增加了,我想收到警报。
所以最初我的查询看起来像
ALERT BackendErrors
IF rate(log_error_count[1m]) > 0
FOR 1s
...
Run Code Online (Sandbox Code Playgroud)
但后来我尝试使用普罗米修斯仪表板对图表进行理智检查。
使用查询
log_error_count
Run Code Online (Sandbox Code Playgroud)
我的图表看起来像
当我查看带有查询的图表时
rate(log_error_count[2m])
Run Code Online (Sandbox Code Playgroud)
我的图表看起来像
事实上,我也试过函数irate
、changes
、 和delta
,它们都变为零。
为什么速率为零,我的查询需要看起来像什么才能在计数器增加一次时发出警报?
是否有任何可扩展的解释型编程语言是用标准的,独立于平台的C或C++编写的?
我希望能够简单地将所有源代码放在一个目录中,使用任何符合标准的C或C++编译器编译源代码,并生成一个可执行文件,以指定的脚本语言读取和解释脚本文件.
似乎许多编程语言"用C语言编写"通常包含许多依赖于它们所在平台的特性,因此,需要一些配置程序来运行基于您的目标系统(例如Autoconf),这会使事情复杂化并限制交叉平台兼容性.
问题原因:
我有兴趣学习编程语言设计.在完成了涉及yacc,lex和llvm的教程后,我玩了一些玩具编程语言.然而,最近我对研究用可移植C/C++编写的编程语言感兴趣,因此,我可以在任何支持标准C或C++编译器(甚至可能在我的ipad上)的机器上研究程序和代码,有一个相当统一的经验.
由于这仅用于教育目的,脚本语言不需要支持像C这样的超低级功能,也不需要像Java一样使用GUI(我不认为你可以编写任何类型的GUI仅限于标准C无论如何/ C++或任何复杂的io.但是,我希望语言足够完整,以便在语言中编写一些有用的程序是可行的(例如,应该可以使用C/C++扩展语言,以便您可以像tty上的shell一样使用它) .
谢谢.
编辑:
@AndréCaron如果至少语言的核心是100%独立于平台,我更喜欢它.如果该语言包含一个依赖于其他库以使其"更有用"的大型标准库,那就没关系了,但是,我希望能够剥离标准库并仅使用该语言的核心(可能使用自定义)手写的图书馆)如果我想.
我正在读这篇文章,有一次它给了我这个nasm程序:
; tiny.asm
BITS 32
GLOBAL main
SECTION .text
main:
mov eax, 42
ret
Run Code Online (Sandbox Code Playgroud)
并告诉我运行以下命令:
$ nasm -f elf tiny.asm
$ gcc -Wall -s tiny.o
Run Code Online (Sandbox Code Playgroud)
我收到以下错误:
ld: warning: option -s is obsolete and being ignored
ld: warning: ignoring file tiny.o, file was built for unsupported file format which is not the architecture being linked (x86_64)
Undefined symbols for architecture x86_64:
"_main", referenced from:
start in crt1.10.6.o
ld: symbol(s) not found for architecture x86_64
collect2: ld returned 1 exit …
Run Code Online (Sandbox Code Playgroud) 在我输入的控制台上
>>> class S(str): pass
...
>>> a = 'hello'
>>> b = S('hello')
>>> d = {a:a, b:b}
>>> d
{'hello': 'hello'}
>>> type(d[a])
<class '__main__.S'>
>>> type(d[b])
<class '__main__.S'>
Run Code Online (Sandbox Code Playgroud)
我一开始认为d
只保留一对的原因是因为hash(a)
并hash(b)
返回了相同的值,所以我尝试了:
>>> class A(object):
... def __hash__(self):
... return 0
...
>>> class B(object):
... def __hash__(self):
... return 0
...
>>> d = {A():A(),B():B()}
>>> d
{<__main__.A object at 0x101808b90>: <__main__.A object at 0x101808b10>, <__main__.B object at 0x101808d10>: <__main__.B object at 0x101808cd0>} …
Run Code Online (Sandbox Code Playgroud) 我想分割使用字符串-
,+=
,==
,=
,+
作为分隔符,和空格.我想保留分隔符,除非它是空白区域.
我已尝试使用以下代码实现此目的:
def tokenize(s):
import re
pattern = re.compile("(\-|\+\=|\=\=|\=|\+)|\s+")
return pattern.split(s)
print(tokenize("hello-+==== =+ there"))
Run Code Online (Sandbox Code Playgroud)
我期待输出
['hello', '-', '+=', '==', '=', '=', '+', 'there']
Run Code Online (Sandbox Code Playgroud)
但是我得到了
['hello', '-', '', '+=', '', '==', '', '=', '', None, '', '=', '', '+', '', None, 'there']
Run Code Online (Sandbox Code Playgroud)
这几乎是我想要的,除了有很多无关的None
s和空字符串.
为什么它会以这种方式运行,我怎么能改变它以获得我想要的东西?
特别是,我在C++中有一些阻塞队列,我想等到其中任何一个都有一些我可以弹出的项目.
我能想到的唯一机制是为每个从其输入队列弹出的队列生成一个单独的线程,并将其提供给原始线程可以等待的主队列.
生成N个新线程然后每次想要从一组队列弹出时都杀掉所有线程似乎有点资源.
Golang是否实现了一些我可以在自己的C++代码中实现的更优雅的机制?
class A {}
class B extends A {}
object Sample {
def foo(a: Set[A]) {
println("Hi Set[A]")
}
// def foo(a: String) {
// println("Hi A")
// }
}
Sample.foo(Set(new B()))
Run Code Online (Sandbox Code Playgroud)
上面的代码很愉快scala
.但是,当我取消注释时foo(a: String)
,代码无法编译:
test.scala:13: error: overloaded method value foo with alternatives:
(a: String)Unit <and>
(a: Set[this.A])Unit
cannot be applied to (scala.collection.immutable.Set[this.B])
Sample.foo(Set(new B()))
^
one error found
Run Code Online (Sandbox Code Playgroud)
foo(a: String)
似乎它应该与试图foo
用一个调用无关Set[B]
.到底是怎么回事?
编辑:
让我感到困惑的不仅仅是为什么未注释的版本不能编译,而是为什么它在编译时会foo(a: String)
被注释掉.我通过添加方法改变了什么foo(a: String)
?
Set
不变不能解释为何在 …
在Python中,我可以通过回放zip来获得zip的"反转"
a = [1,2,3]
b = [4,5,6]
c = zip(a,b) # [(1,4),(2,5),(3,6)]
Run Code Online (Sandbox Code Playgroud)
相反,如果我开始c
,我可以a
和b
回用下面的
c = [(1,4),(2,5),(3,6)]
a, b = zip(*c)
Run Code Online (Sandbox Code Playgroud)
但是,在Ruby中,似乎只有一种zip
方法,因此我不确定我能以完全相同的方式做到这一点......
在Ruby中是否有某种类似的好习惯用于"解压缩"列表列表?
我知道你可以做到
c[0].zip(*c[1..-1])
Run Code Online (Sandbox Code Playgroud)
基本上在语义上是相同的东西,但这种方式看起来并不那么直观......
c++ ×3
python ×3
c ×1
dictionary ×1
gcc ×1
go ×1
interpreter ×1
macos ×1
nasm ×1
overloading ×1
prometheus ×1
pypy ×1
regex ×1
rpython ×1
ruby ×1
scala ×1
templates ×1