Skip to content

Instantly share code, notes, and snippets.

View dockimbel's full-sized avatar

Nenad Rakocevic dockimbel

View GitHub Profile
REBOL [
Title: "Red/System ELF format emitter"
Author: "Nenad Rakocevic"
File: %ELF.r
Rights: "Copyright (C) 2011 Nenad Rakocevic. All rights reserved."
License: "BSD-3 - https://github.com/dockimbel/Red/blob/master/BSD-3-License.txt"
]
context [
defs: [
REBOL [
Title: "Red/System ELF format emitter"
Author: "Andreas Bolka, Nenad Rakocevic"
File: %ELF.r
Rights: "Copyright (C) 2011 Andreas Bolka, Nenad Rakocevic. All rights reserved."
License: "BSD-3 - https://github.com/dockimbel/Red/blob/origin/BSD-3-License.txt"
]
context [
defs: [
@dockimbel
dockimbel / gist:1062078
Created July 3, 2011 08:51
Attempt to reproduce issue #120 (Type-casting of string element to integer does not work)
Red/System []
#import [
"msvcrt.dll" cdecl [ ; Windows
calloc: "calloc" [ ; Allocate zero-filled memory.
chunks [integer!]
size [integer!]
return: [c-string!]
]
memcpy: "memcpy" [ ; Copy memory range.
@dockimbel
dockimbel / gist:1278718
Created October 11, 2011 17:13
UTF-8 codepoints validation rules
overlong: charset "^(C0)^(C1)"
invalid-bytes: union overlong charset [#"^(F5)" - #"^(FF)"]
cont-byte: charset [#"^(80)" - #"^(BF)"]
one-byte-codepoint: charset [#"^(00)" - #"^(7F)"]
two-bytes-codepoint: reduce [
charset [#"^(C2)" - #"^(DF)"]
cont-byte
@dockimbel
dockimbel / browser.reds
Created October 30, 2011 16:45
Webkit-based browser by Kaj de Vos
Red/System [
Title: "Lazy Sunday Afternoon Browser"
Author: "Kaj de Vos"
]
#include %GTK-WebKit.reds
home: "http://www.red-lang.org/"
address: function [
@dockimbel
dockimbel / fourtytwo.reds
Created November 18, 2011 18:23
Simple functon import test
Red/System []
#import [
"libc.so.6" cdecl [
quit: "exit" [
status [integer!]
]
]
]
@dockimbel
dockimbel / gist:1508186
Created December 21, 2011 23:25
Not working abs(x) routine for x = -2^31
; Division routine
93c4: e3510000 cmp r1, #0
93c8: 0a000014 beq 0x9420
93cc: e1b02001 movs r2, r1 ; r2: divisor
93d0: e212c102 ands ip, r2, #-2147483648 ; 0x80000000
93d4: 40225fc2 eormi r5, r2, r2, asr #31
93d8: 40452fc2 submi r2, r5, r2, asr #31
93dc: e1b01000 movs r1, r0 ; r1: dividend
93e0: e03cc041 eors ip, ip, r1, asr #32
93e4: 40215fc1 eormi r5, r1, r1, asr #31
@dockimbel
dockimbel / sym-test.reds
Created January 22, 2012 23:53
Simple math function bindings generates a missing symbol on Linux (works ok on Win/OSX)
Red/System []
#import [
LIBC-file cdecl [
sin: "sin" [
x [float!]
return: [float!]
]
]
]
@dockimbel
dockimbel / sub64.reds
Created January 24, 2012 23:59
Rough implementation of 64-bit integer subtraction
Red/System []
int64!: alias struct! [high [integer!] low [integer!]]
sub64: func [
a [int64!]
b [int64!]
return: [int64!]
/local
diff [int64!] offset [integer!]
@dockimbel
dockimbel / ftoi.reds
Created June 12, 2012 20:28
Float32! to integer! conversion routine
Red/System [
Title: "Float32! to integer! conversion routine"
Author: "Nenad Rakocevic"
Rights: "Copyright (C) 2011 Nenad Rakocevic. All rights reserved."
License: "BSD-3 - https://github.com/dockimbel/Red/blob/origin/BSD-3-License.txt"
Note: "Thanks to François Jouen for providing me the C code for ftoi()"
]
float-to-integer: func [
f [float32!] ;-- float 32-bit value to convert