langs a-z
This commit is contained in:
parent
db842d013d
commit
d066446780
11389 changed files with 98361 additions and 1020 deletions
|
|
@ -0,0 +1,3 @@
|
|||
proc strcmp(a, b: cstring): cint {.importc: "strcmp", nodecl.}
|
||||
echo strcmp("abc", "def")
|
||||
echo strcmp("hello", "hello")
|
||||
|
|
@ -0,0 +1,3 @@
|
|||
void myfunc_a();
|
||||
float myfunc_b(int, float);
|
||||
char *myfunc_c(int *);
|
||||
|
|
@ -0,0 +1,3 @@
|
|||
external myfunc_a: unit -> unit = "caml_myfunc_a"
|
||||
external myfunc_b: int -> float -> float = "caml_myfunc_b"
|
||||
external myfunc_c: int array -> string = "caml_myfunc_c"
|
||||
|
|
@ -0,0 +1,30 @@
|
|||
#include <caml/mlvalues.h>
|
||||
#include <caml/alloc.h>
|
||||
#include <mylib.h>
|
||||
|
||||
CAMLprim value
|
||||
caml_myfunc_a(value unit) {
|
||||
myfunc_a();
|
||||
return Val_unit;
|
||||
}
|
||||
|
||||
CAMLprim value
|
||||
caml_myfunc_b(value a; value b) {
|
||||
float c = myfunc_b(Int_val(a), Double_val(b));
|
||||
return caml_copy_double(c);
|
||||
}
|
||||
|
||||
CAMLprim value
|
||||
caml_myfunc_c(value ml_array) {
|
||||
int i, len;
|
||||
int *arr;
|
||||
char *s;
|
||||
len = Wosize_val(ml_array);
|
||||
arr = malloc(len * sizeof(int));
|
||||
for (i=0; i < len; i++) {
|
||||
arr[i] = Int_val(Field(ml_array, i));
|
||||
}
|
||||
s = myfunc_c(arr);
|
||||
free(arr);
|
||||
return caml_copy_string(s);
|
||||
}
|
||||
|
|
@ -0,0 +1,26 @@
|
|||
wrap_mylib.o: wrap_mylib.c
|
||||
ocamlc -c -ccopt -I/usr/include/mylib $<
|
||||
|
||||
dllmylib_stubs.so: wrap_mylib.o
|
||||
ocamlmklib -o mylib_stubs $< -lmylib
|
||||
|
||||
mylib.mli: mylib.ml
|
||||
ocamlc -i $< > $@
|
||||
|
||||
mylib.cmi: mylib.mli
|
||||
ocamlc -c $<
|
||||
|
||||
mylib.cmo: mylib.ml mylib.cmi
|
||||
ocamlc -c $<
|
||||
|
||||
mylib.cma: mylib.cmo dllmylib_stubs.so
|
||||
ocamlc -a -o $@ $< -dllib -lmylib_stubs -cclib -lmylib
|
||||
|
||||
mylib.cmx: mylib.ml mylib.cmi
|
||||
ocamlopt -c $<
|
||||
|
||||
mylib.cmxa: mylib.cmx dllmylib_stubs.so
|
||||
ocamlopt -a -o $@ $< -cclib -lmylib_stubs -cclib -lmylib
|
||||
|
||||
clean:
|
||||
rm -f *.[oa] *.so *.cm[ixoa] *.cmxa
|
||||
|
|
@ -0,0 +1,21 @@
|
|||
#include "mozart.h"
|
||||
#include <string.h>
|
||||
|
||||
OZ_BI_define(c_strdup,1,1)
|
||||
{
|
||||
OZ_declareVirtualString(0, s1);
|
||||
char* s2 = strdup(s1);
|
||||
OZ_Term s3 = OZ_string(s2);
|
||||
free( s2 );
|
||||
OZ_RETURN( s3 );
|
||||
}
|
||||
OZ_BI_end
|
||||
|
||||
OZ_C_proc_interface * oz_init_module(void)
|
||||
{
|
||||
static OZ_C_proc_interface table[] = {
|
||||
{"strdup",1,1,c_strdup},
|
||||
{0,0,0,0}
|
||||
};
|
||||
return table;
|
||||
}
|
||||
|
|
@ -0,0 +1,6 @@
|
|||
makefile(
|
||||
lib : [
|
||||
'strdup.o' 'strdup.so'
|
||||
]
|
||||
rules:o('strdup.so':ld('strdup.o'))
|
||||
)
|
||||
|
|
@ -0,0 +1,4 @@
|
|||
declare
|
||||
[Strdup] = {Module.link ['strdup.so{native}']}
|
||||
in
|
||||
{System.showInfo {Strdup.strdup "hello"}}
|
||||
|
|
@ -0,0 +1,3 @@
|
|||
declare strdup entry (character (30) varyingz) options (fastcall16);
|
||||
|
||||
put (strdup('hello world') );
|
||||
|
|
@ -0,0 +1,9 @@
|
|||
use NativeCall;
|
||||
|
||||
sub strdup(Str $s --> OpaquePointer) is native {*}
|
||||
sub puts(OpaquePointer $p --> int) is native {*}
|
||||
sub free(OpaquePointer $p --> int) is native {*}
|
||||
|
||||
my $p = strdup("Success!");
|
||||
say 'puts returns ', puts($p);
|
||||
say 'free returns ', free($p);
|
||||
|
|
@ -0,0 +1,39 @@
|
|||
; Call_a_foreign_language_function.fasm -> Call_a_foreign_language_function.obj
|
||||
; the assembler code...
|
||||
|
||||
; format COFF or
|
||||
; format COFF64 classic (DJGPP) variants of COFF file
|
||||
|
||||
; format MS COFF or
|
||||
; format MS COFF64 Microsoft's variants of COFF file
|
||||
|
||||
format MS COFF
|
||||
|
||||
include "Win32A.Inc"
|
||||
|
||||
section ".text" executable readable code
|
||||
|
||||
proc strucase stdcall str:dword
|
||||
xor eax,eax
|
||||
mov ebx,[str]
|
||||
strucase_loop:
|
||||
mov al,byte[ebx]
|
||||
cmp al,0
|
||||
jz strucase_is_null_byte
|
||||
cmp al,'a'
|
||||
jb strucase_skip
|
||||
cmp al,'z'
|
||||
ja strucase_skip
|
||||
and al,11011111b
|
||||
strucase_skip:
|
||||
; mov byte[ebx],al
|
||||
xchg al,byte[ebx]
|
||||
inc ebx
|
||||
jmp strucase_loop
|
||||
strucase_is_null_byte:
|
||||
xor eax,eax
|
||||
mov eax,[str]
|
||||
ret
|
||||
endp
|
||||
|
||||
public strucase as "_strucase@4"
|
||||
|
|
@ -0,0 +1,10 @@
|
|||
; the PureBasic code...
|
||||
|
||||
Import "Call_a_foreign_language_function.obj"
|
||||
strucase(t.s) As "_strucase@4"
|
||||
EndImport
|
||||
|
||||
t.s="hElLo WoRld!!"
|
||||
*r=StrUcase(t.s) ; PureBasic is case-insensitive
|
||||
; cw(peeks(*r))
|
||||
Debug peeks(*r)
|
||||
|
|
@ -0,0 +1,22 @@
|
|||
Declare Function CreateFileW Lib "Kernel32" (FileName As WString, DesiredAccess As Integer, ShareMode As Integer, SecurityAttributes As Integer, _
|
||||
CreateDisposition As Integer, Flags As Integer, Template As Integer) As Integer
|
||||
Declare Function WriteFile Lib "Kernel32" (fHandle As Integer, writeData As Ptr, numOfBytes As Integer, ByRef numOfBytesWritten As Integer, _
|
||||
overlapped As Ptr) As Boolean
|
||||
Declare Function GetLastError Lib "Kernel32" () As Integer
|
||||
Declare Function CloseHandle Lib "kernel32" (hObject As Integer) As Boolean
|
||||
|
||||
Const FILE_SHARE_READ = &h00000001
|
||||
Const FILE_SHARE_WRITE = &h00000002
|
||||
Const OPEN_EXISTING = 3
|
||||
|
||||
Dim fHandle As Integer = CreateFileW("C:\foo.txt", 0, FILE_SHARE_READ Or FILE_SHARE_WRITE, 0, OPEN_EXISTING, 0, 0)
|
||||
If fHandle > 0 Then
|
||||
Dim mb As MemoryBlock = "Hello, World!"
|
||||
Dim bytesWritten As Integer
|
||||
If Not WriteFile(fHandle, mb, mb.Size, bytesWritten, Nil) Then
|
||||
MsgBox("Error Number: " + Str(GetLastError))
|
||||
End If
|
||||
Call CloseHandle(fHandle)
|
||||
Else
|
||||
MsgBox("Error Number: " + Str(GetLastError))
|
||||
End If
|
||||
Loading…
Add table
Add a link
Reference in a new issue