This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
require 'ffi' | |
require 'llvm/core' | |
require 'llvm/analysis' | |
require 'llvm/execution_engine' | |
CALLBACK_TYPE = LLVM.Function([LLVM::Int], LLVM.Void) | |
mod = LLVM::Module.new("test.fprintf") | |
do_work = mod.functions.add("do_work", [CALLBACK_TYPE.pointer], LLVM.Void) do |fn, callback| |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
require 'llvm/core' | |
require 'llvm/analysis' | |
require 'llvm/execution_engine' | |
mod = LLVM::Module.new("test.fprintf") | |
str = "value = %d\n" | |
V_STRING = mod.globals.add(LLVM::Array(LLVM::Int8, str.size + 1), "str") do |value| | |
value.linkage = :internal |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
require 'llvm/core' | |
require 'llvm/analysis' | |
require 'llvm/execution_engine' | |
mod = LLVM::Module.new("test") | |
str = "Hello, World!" | |
STRING = mod.globals.add(LLVM::Array(LLVM::Int8, str.size + 1), "str") do |value| | |
value.linkage = :internal |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# LLVM::JITCompiler#run_function can't handle aggregate value | |
engine = LLVM::JITCompiler.new(module) | |
function = module.functions["doSomething"] | |
pointer = engine.pointer_to_global(function) | |
fn = FFI::Function.new(:int, [:int], pointer) | |
fn.call(123) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <stdio.h> | |
int putd(double x) { | |
printf("putd: %.2f\n", x); | |
return 1; | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
julia> @async begin | |
server = listen(2000) | |
while true | |
sock = accept(server) | |
println("Hello World\n") | |
end | |
end | |
Task (queued) @0x00007fe0d62ae100 | |
julia> connect(2000) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Programming Elixir | |
# Exercise: ListsAndRecursion-2 | |
# | |
# Write max(list) that returns the element with the maximum | |
# value in the list. (This is slightly trickier than it sounds.) | |
# | |
# http://forums.pragprog.com/forums/322/topics/Exercise:%20ListsAndRecursion-2 | |
defmodule Max do | |
def max([a]), do: a |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
! Copyright (C) 2013 Takanori Ishikawa. | |
! See http://factorcode.org/license.txt for BSD license. | |
USING: tools.test fizzbuzz ; | |
IN: fizzbuzz.tests | |
! divisible3? | |
[ t ] [ 0 divisible3? ] unit-test | |
[ f ] [ 1 divisible3? ] unit-test | |
[ t ] [ 3 divisible3? ] unit-test |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
FIXNUM_MASK = (0..64).map {|n| (1<<n)-1 } | |
.select {|m| m.instance_of?(Fixnum) } | |
.max | |
# irb(main):009:0> 10000000000000000000000.class | |
# => Bignum | |
# irb(main):010:0> (10000000000000000000000 & FIXNUM_MASK).class | |
# => Fixnum |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
; ModuleID = 'hello' | |
@.str = private constant [14 x i8] c"Hello, World!\00" | |
declare i32 @puts(i8* nocapture) nounwind | |
define i32 @main() { | |
%1 = call i32 @puts(i8* getelementptr inbounds ([14 x i8]* @.str, i32 0, i32 0)) | |
ret i32 0 | |
} |