小编top*_*hat的帖子

LLVM stdin/stdout/stderr

如何在LLVM中声明stdin,stout和stderr(最好是C版本)?我试图在我正在创建的玩具语言中使用一些stdio函数.一个这样的功能是fgets:

char * fgets ( char * str, int num, FILE * stream );
Run Code Online (Sandbox Code Playgroud)

为了使用我需要的stdin.所以我写了一些LLVM API代码来生成我找到的FILE的定义,并声明stdin了一个外部全局.代码生成了这个:

%file = type { i32, i8*, i8*, i8*, i8*, i8*, i8*, i8*, i8*, i8*, i8*, i8*, %marker*, %file*, i32, i32, i64, i16, i8, [1 x i8], i8*, i64, i8*, i8*, i8*, i8*, i64, i32, [20 x i8] }
%marker = type { %marker*, %file*, i32 }

@stdin = external global %file*
Run Code Online (Sandbox Code Playgroud)

但是,当我运行生成的模块时,它给了我这个错误: …

llvm

11
推荐指数
2
解决办法
2428
查看次数

C扩展中的Ruby关键字参数

如何从C扩展中处理Ruby 2.0.0关键字参数?

背景

def example(name: 'Bob' hat_color: 'red')
  puts "#{name} has a #{hat_color} hat!"
end

example                                  #=> "Bob has a red hat!"
example(name: 'Joe', hat_color: 'blue')  #=> "Joe has a blue hat!"
Run Code Online (Sandbox Code Playgroud)

在处理具有许多不同调用序列或选项的方法时,关键字参数(如上所述)非常有用.我在C扩展中有一个这样的方法(一个blit处理我项目中大部分OpenGL绘图的方法),我想知道如何从ruby中获取方法句柄关键字参数.

思路

根据我所做的一些研究,我认为这样的处理可以通过C函数的:选项来完成rb_scan_args.但是,我一直无法找到有关如何使用它的任何信息.

c ruby ruby-c-extension

8
推荐指数
1
解决办法
362
查看次数

标签 统计

c ×1

llvm ×1

ruby ×1

ruby-c-extension ×1