Skip to content

Instantly share code, notes, and snippets.

View edubart's full-sized avatar

Eduardo Bart edubart

View GitHub Profile
@edubart
edubart / main.nelua
Last active December 26, 2021 12:25
WASM4 Nelua template
require "wasm4"
local smiley: []uint8 = {
0b11000011,
0b10000001,
0b00100100,
0b00100100,
0b00000000,
0b00100100,
0b10011001,
@edubart
edubart / gfxtoy.nelua
Last active December 17, 2021 23:04
gfxtoy test
-- THIS whole framework is hacky and just a PROOF OF CONCEPT!
##[[
primtypes.number = primtypes.float32
primtypes.integer = primtypes.int32
primtypes.uinteger = primtypes.uint32
if OPENMP then
cflags '-fopenmp'
end
local function parallel_for()
@edubart
edubart / nene_microui.lua
Created September 22, 2021 01:13
Micro ui nene
require 'microui'
require 'hashmap'
require 'nene.core'
require 'nene.colors'
require 'nene.math'
require 'nene.font'
require 'nene.text_texture'
local mu: mu_Context
local nene: Nene
@edubart
edubart / nelua-opencv-example.cpp
Last active August 7, 2021 18:33
Example using OpenCV with Nelua
/* Generated by Nelua 0.2.0-dev */
/* Compile command: g++ -x c++ "/home/bart/projects/nelua/nelua-lang/nelua_cache/play/draft.c" -o "/home/bart/projects/nelua/nelua-lang/nelua_cache/play/draft" -fwrapv -g -Wall -Wextra -I/usr/include/opencv4 -DWITH_OPENEXR=OFF -lopencv_core -lopencv_imgcodecs -lopencv_highgui -lm */
/* Compile hash: 2oc8quwtnUC8s47mULrq1Bsh5u2U */
/* ------------------------------ DIRECTIVES -------------------------------- */
/* Disable some warnings that the generated code can trigger. */
#if defined(__clang__)
#pragma clang diagnostic ignored "-Wtype-limits"
#pragma clang diagnostic ignored "-Wwrite-strings"
#pragma clang diagnostic ignored "-Wunused"
#pragma clang diagnostic ignored "-Wunused-parameter"
@edubart
edubart / blueplanet.c
Last active July 27, 2021 22:05
Blue Planet in C
/* Generated by Nelua 0.2.0-dev */
/* Compile command: c2m "/home/bart/projects/nelua/nelua-lang/nelua_cache/demos/planet.c" -o "/home/bart/projects/nelua/nelua-lang/nelua_cache/demos/planet" -w -lSDL2 */
/* Compile hash: 2oufrcKZe8TBnJwdhtW2c9mqSzEe */
/* ------------------------------ DIRECTIVES -------------------------------- */
#include <math.h>
#include <stdint.h>
#define SDL_MAIN_HANDLED
#define SDL_DISABLE_MMINTRIN_H
#define SDL_DISABLE_IMMINTRIN_H
#define SDL_DISABLE_XMMINTRIN_H
@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
##[[
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,
@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