Skip to content

Instantly share code, notes, and snippets.

View edubart's full-sized avatar

Eduardo Bart edubart

View GitHub Profile
@edubart
edubart / pcall.lua
Last active July 13, 2021 13:41
Experimental pcall implementation for Nelua
##[[
local typedefs = require 'nelua.typedefs'
typedefs.function_annots.noerror = true
local cgenerator = require 'nelua.cgenerator'
local CEmitter = require 'nelua.cemitter'
local orig_Call = cgenerator.visitors.Call
function cgenerator.visitors.Call(context, node, emitter, ...)
local isblockcall = context:get_visiting_node(1).tag == 'Block'
local funcscope = context.scope:get_up_scope_of_kind('is_function')
local funcsym = funcscope and funcscope.funcsym
##[[
if GLSL then
primtypes.number = primtypes.float32
primtypes.integer = primtypes.cint
primtypes.uinteger = primtypes.cuint
else
primtypes.number = primtypes.float32
primtypes.integer = primtypes.int32
primtypes.uinteger = primtypes.uint32
end
@edubart
edubart / nldoc.lua
Created May 26, 2021 15:06
Nelua doc tool
local fs = require 'nelua.utils.fs'
local traits = require 'nelua.utils.traits'
local stringer = require 'nelua.utils.stringer'
local parser = require 'nelua.syntaxdefs'().parser
local re = require 'nelua.thirdparty.relabel'
local filename = 'lib/string.nelua'
local filecode = fs.ereadfile(filename)
local ast = parser:parse(filecode, filename)
@edubart
edubart / bench.lua
Last active January 26, 2021 15:21
rdtsc in luajit for x86_64
collectgarbage('stop') -- we don't want the GC to generate noise in the benchmarks
local function bench(f, n)
collectgarbage('collect')
n = n or 1000000
local rdtsc = require 'rdtsc'
local s = rdtsc()
for _=1,n do
f()
end
@edubart
edubart / luacov-scm-1.rockspec
Created August 19, 2020 12:06
luacov rockspec for lua 5.4
package = "luacov"
version = "scm-1"
source = {
url = "git+https://github.com/keplerproject/luacov.git",
}
description = {
summary = "Coverage analysis tool for Lua scripts",
detailed = [[
LuaCov is a simple coverage analysis tool for Lua scripts.
When a Lua script is run with the luacov module, it
@edubart
edubart / xt_entropy.c
Created May 9, 2020 15:25
Network traffic entropy calculator in kernel
#ifndef __KERNEL__
#define __KERNEL__
#endif
#ifndef MODULE
#define MODULE
#endif
#include <generated/autoconf.h>
#include <linux/kernel.h>
#include <linux/module.h>
@edubart
edubart / c2nelua.lua
Last active April 5, 2020 00:37
c2nelua rudimentar experiment
local re = require 'relabel'
local file = require 'pl.file'
local stringx = require 'pl.stringx'
local grammar = [[
body <- {| line+ |}
line <- (extern / anyline)
anyline <- linerest
linerest<- [^;]* ';' sp
sp <- %s*
--------------------------------------------------------------------------------
-- meta programming utilities for inheritance
##[[
local function check_record_type(sym)
staticassert(sym and sym.type and sym.type:is_type() and sym.value:is_record(),
"symbol '%s' must be a type holding a record type", sym.name)
return sym.value
end
@edubart
edubart / inheretance_example.cpp
Created February 3, 2020 13:53
inheretance_example.cpp
#include <stdint.h>
#include <stdio.h>
struct Shape {
Shape(int64_t x, int64_t y): x(x), y(y) {}
virtual int64_t area() {return 0;}
int64_t x, y;
};
struct Rectangle : public Shape {
@edubart
edubart / raytrace.lua
Created May 31, 2019 22:00
euluna raytracer test
!!strict
-- optimize for performance
!!cflags '-O3 -ffast-math -march=native -fno-plt -flto -fopenmp -rdynamic -g'
!!ldflags '-flto'
--------------------------------------------------------------------------------
-- SDL
-- import SDL headers