Skip to content

Instantly share code, notes, and snippets.

View hashmal's full-sized avatar

Jérémy Pinat hashmal

View GitHub Profile
@hashmal
hashmal / protocol.c
Created February 22, 2013 05:18
Not necessarily a good idea: "protocols" in plain old C.
#include <stdio.h>
#include <stdlib.h>
typedef void *any;
#define protocol(n) struct n
#define end(_)
// DECLARING THE SHOW PROTOCOL ///////////////////////////////////////////////
@hashmal
hashmal / shirka_draft.mkd
Last active July 3, 2020 14:03
Design of the Shirka programming language.

Shirka

Automatic garbage collection has made possible the implementation of many flexible, high-level languages in which memory management can simply be ignored most of the time. Unfortunately, garbage collectors have some properties that make their use in several fields (namely real-time applications) unpractical or even impossible:

  • Program execution is suspended during garbage collection cycles ("GC
@hashmal
hashmal / shirkagl.shk
Last active December 15, 2015 23:19
What OpenGL in Shirka could look like...
-- assuming the following operations are defined:
--
-- with -- require a module
-- case -- branching operation
-- ABORT -- terminate program
-- the `while' operation is normally already defined. The following
-- definition is here to show how adding new constructs to Shirka is done.
(=> while)
[ => condition
@hashmal
hashmal / tpk_obfuscated.shk
Created April 12, 2013 07:32
[Shirka] Trabb Pardo-Knuth algorithm, simple layout obfuscation.
-- Trabb Pardo-Knuth algorithm, simple layout obfuscation.
(=> >>) [ -> x x <- x ] (=> <<) [ -> x ] (=> ><) [ -> x -> y <- x <- y ] (=>
puts) [ print '\n print ] (=> if) [ uncons -> iftrue uncons -> iffalse << ->
cond cond iftrue !? cond not iffalse !? ] (=> while) [ => cond => op [ cond [
op tail ] !? ] => tail tail ] (=> times) [ >< => op2 ([>> 0 >] while) [ 1 - ->
count op2 <- count ] << ] (=> each) [ => op-each length -> n (n times) [
uncons op-each ] << ] (=> list/reverse) [ "" >< ([length 0 = not] while) [ ->
src -> dest <- src uncons -> el -> src <- dest <- el cons <- src ] << ] (=>
gets) [ "" TRUE ([] while) [ getc >> '\n = not (if) [ [ cons TRUE ] [ cons
list/reverse FALSE ] ] ] ] (=> get-value) [ gets $parse length 1 = (if) [ [
@hashmal
hashmal / name-conv.md
Created April 13, 2013 19:41
Random thoughts about naming conventions in Shirka

Since Shirka is a tacit programming language, and the order of "arguments" is uncomon, it can be difficult to reason about what input operations need. In the following example:

while

It is quite natural to think the operation uses two objects from the stack: a value to check and something to do. However it is not clear in what order both objects must be on the stack.

In concatenative languages, any subexpression can be replaced with a name that represents the same subexpression.

Reserving operations in Shirka remove this property:

42 -> x   x   <- x      -- works

42 -> x [ x   <- x ] !  -- cannot undefine x

1 -> x 2 -> x <- x -- result is 2

@hashmal
hashmal / try.md
Last active December 16, 2015 05:59

Proposal for "try blocks"

To fail gracefully, an operation needs to manipulate a different stack in order to be able to recover from an error (if an error occurs, the stack is in an undetermined state).

A try block can terminate in two ways:

  • The computation succeeded. In this case, its stack contents
@hashmal
hashmal / try.shk
Last active December 16, 2015 06:29
-- try/rescue example
[] -- This list will be used as a data-stack by the `try' operation.
(try) [ derp ] -- `derp' is undefined
(rescue) [ "Error happened. Recovering." puts ]
"Recovered from error." puts
-- When run, it displays the following:
(with) "lib/atl.shk"
(test/runSuite) [
("true" test/case) [ -- this test always succeeds
(test/assertions) [
[ TRUE ]
]
]
# Compiled source #
###################
*.com
*.class
*.dll
*.exe
*.o
*.ali
*.so