Skip to content

Instantly share code, notes, and snippets.

View edubart's full-sized avatar

Eduardo Bart edubart

View GitHub Profile
--------------------------------------------------------------------------------
-- 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 / 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*
@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 / 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 / arduino-gameoflife.lua
Created September 17, 2020 22:31
Arduino Game of Life in Nelua
require 'arduino'
-- user configurable defines
local CELL_SIZE: cint <comptime> = 4 -- the height and width of each cell
local DELAY: cint <comptime> = 50 -- number of milliseconds delay between the display of each generation
-- end of user configurable defines
local ROWS: cint <comptime> = (DISPLAY_HEIGHT // CELL_SIZE)
local COLUMNS: cint <comptime> = (DISPLAY_WIDTH // CELL_SIZE)
##[=[
linklib 'lua'
cinclude '<lua.h>'
cinclude '<lauxlib.h>'
cinclude '<lualib.h>'
local ccdefs = require 'nelua.ccompiler'.get_cc_defines('<lua.h>')
static_assert(ccdefs.LUA_VERSION_NUM == 504, 'unsupported Lua version')
local c2nelua = {
['double'] = float64,
@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 / 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)
##[[
cflags '-I/usr/include/tensorflow'
linklib 'tensorflow'
cinclude '<tensorflow/c/c_api.h>'
]]
global TF_AttrType: type <cimport, nodecl, using> = @enum(cint){
TF_ATTR_STRING = 0,
TF_ATTR_INT = 1,
TF_ATTR_FLOAT = 2,
TF_ATTR_BOOL = 3,
##[[
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