Skip to content

Instantly share code, notes, and snippets.

Avatar

Oleg Šelajev shelajev

View GitHub Profile
View Main.java
import java.io.FileInputStream; import java.io.FileOutputStream; import java.io.ObjectInputStream; import java.io.ObjectOutputStream; import java.util.List; import java.util.stream.Collectors; import java.util.stream.Stream;
public class Main {
private static String filename = "fib1000";
static Stream<Long> fibonacciStream() {
return Stream.iterate(new long[]{1, 0}, (f) -> new long[]{f[0] + f[1], f[0]}).map(f -> f[0]);
}
public static void main(String[] args) throws Exception {
List<Long> fib1000 = fibonacciStream().limit(1000).collect(Collectors.toList());
View PrimesCommand.java
package primes;
import io.micronaut.configuration.picocli.PicocliRunner;
import io.micronaut.context.ApplicationContext;
import picocli.CommandLine;
import picocli.CommandLine.Command;
import picocli.CommandLine.Option;
import picocli.CommandLine.Parameters;
import javax.inject.*;
import java.util.*;
@Command(name = "primes", description = "...",
View keccak-calls.cob
cob_procedure_params[0] = &f_8;
cob_procedure_params[1] = &f_9;
cob_procedure_params[2] = COB_SET_DATA (f_12, b_12);
cob_procedure_params[3] = COB_SET_DATA (f_13, b_13);
cob_procedure_params[4] = &f_10;
cob_procedure_params[5] = COB_SET_DATA (f_14, b_14);
cob_procedure_params[6] = &f_11;
cob_glob_ptr->cob_call_params = 7;
cob_glob_ptr->cob_stmt_exception = 0;
if (unlikely((cob_glob_ptr->cob_exception_code & 0x0b00) == 0x0b00)) cob_glob_ptr->cob_exception_code = 0;
View keccak-wrapper.cob
IDENTIFICATION DIVISION.
PROGRAM-ID. KECCAK-Wrapper.
ENVIRONMENT DIVISION.
DATA DIVISION.
WORKING-STORAGE SECTION.
01 WS-KECCAK-RATE BINARY-LONG UNSIGNED.
01 WS-KECCAK-CAPACITY BINARY-LONG UNSIGNED.
View c-struct-for-cobol.c
struct __attribute__((packed)) KECCAK__Wrapper__struct_LNK_KECCAK {
unsigned int LNK_KECCAK_RATE;
unsigned int LNK_KECCAK_CAPACITY;
void *LNK_KECCAK_INPUT;
unsigned long LNK_KECCAK_INPUT_BYTE_LEN;
void *LNK_KECCAK_DELIMITED_SUFFIX;
void *LNK_KECCAK_OUTPUT;
unsigned long LNK_KECCAK_OUTPUT_BYTE_LEN;
};
POLYGLOT_DECLARE_STRUCT(KECCAK__Wrapper__struct_LNK_KECCAK)
View makefile.txt
COBCOPTS = -free -Q "-Wl,-rpath -Wl,$(MANAGED_LIBRARIES_PATH)/lib -Wl,-rpath -Wl,$(GRAALVM_LIBRARIES_PATH)"
# create dynamic library that can by loaded by Sulong
KECCAK.so: KECCAK.cob
cobc $(COBCOPTS) -m -fstatic-call -fno-gen-c-decl-static-call -G KECCAK-Wrapper-struct -lpolyglot-mock KECCAK.cob
TESTSHA3-256: TESTSHA3-256.cob KECCAK.so
cobc $(COBCOPTS) -x TESTSHA3-256.cob -lpolyglot-mock
View keccak-wrapper.cob
IDENTIFICATION DIVISION.
PROGRAM-ID. KECCAK-Wrapper-struct.
ENVIRONMENT DIVISION.
DATA DIVISION.
WORKING-STORAGE SECTION.
LINKAGE SECTION.
01 LNK-KECCAK.
View js-for-cobol.js
// load C Code
var cobol = Polyglot.evalFile("llvm", "KECCAK.so");
(function SHA3_256(sha_input, sha_input_length, sha_output) {
cobol.KECCAK__Wrapper__struct({
LNK_KECCAK_RATE: 1088,
LNK_KECCAK_CAPACITY: 512,
LNK_KECCAK_INPUT: sha_input,
LNK_KECCAK_INPUT_BYTE_LEN: sha_input_length,
View call_polyglot_eval_file.cob
CALL WS-SHA3-256-JS-POINTER USING WS-INPUT
WS-INPUT-BYTE-LEN
WS-SHA3-256-OUTPUT
END-CALL
View pol.cob
*> interoperability fields
01 WS-SHA3-256-JS-POINTER PROGRAM-POINTER.
01 WS-JS PIC X(3).
01 WS-SHA3-256-JS-FILENAME PIC X(50).
MOVE Z'js' TO WS-JS.
MOVE Z'SHA3-256.js' TO WS-SHA3-256-JS-FILENAME.
*> get javascript function
CALL STATIC "polyglot_eval_file" using