Skip to content

Instantly share code, notes, and snippets.

View milesrout's full-sized avatar

Miles Rout milesrout

View GitHub Profile
int successor(int x) {
return x + 1;
}
future<int> successor_async(int x) {
promise<decltype(x + 1)> p;
thread([] {
p.set_value(x + 1);
}).detach();
return p.get_future();
namespace std {
template< class... >
using void_t = void;
namespace experimental {
struct nonesuch {
nonesuch() = delete;
~nonesuch() = delete;
nonesuch(nonesuch const&) = delete;
void operator=(nonesuch const&) = delete;
;;; as
;;;
;;; an assembler for the DCPU-16 assembly language
;;;
;;; accepts a file of no more than 512 words indicating the sectors on disk that hold a particular file.
;;; then reads those sectors in the order given, treating them as assembler source
;;; then assembles said source to produce a DCPU-16 binary.
;;; the supported binary format is an image that can be loaded directly from a disk by a bootloader:
;;; it contains an 'initial sector' which is written to the first part of the disk and that loads the rest
;;; of the binary.

DCPU-16E GAT/LAT:

The reason that the DCPU-16e supports both a global access table (GAT) and a local access table (LAT) is that the DCPU-16e supports multiple memory banks. As such, the global access table provides universal access restrictions (that is, entries apply to every memory bank) while the local access table entries that apply just to the memory bank that the local access table is on. Every memory bank has one local access table.

The DCPU-16e has eight memory banks numbered 000 to 111. There are three ways to use access tables. Firstly, you can simply not use them. This essentially disables the kernel/user mode distinction. If this is done, the INT and RFI instructions behave as they do on the DCPU-16. This is good for learning, but is quite insecure. Secondly, you can choose to only use the global access table. This means that the same access rules are applied to all memory banks equally. Thirdly, you can use both global and local access tables. Note that the local access table

@milesrout
milesrout / 000-dcpu16e
Last active October 29, 2017 04:35 — forked from MadMockers/gist:6365941
DCPU-16e 1.3
DCPU-16e Specification
Version 1.3
=== SUMMARY ====================================================================
* 16 bit words
* 8 banks of 0x10000 words of ram, numbered 0-7
* 8 registers (A, B, C, X, Y, Z, I, J)

Keybase proof

I hereby claim:

  • I am milesrout on github.
  • I am milesrout (https://keybase.io/milesrout) on keybase.
  • I have a public key ASB4vus1fC33TdrjMv_Hei3QwfDQl5e4f2PgApb8QWRuiQo

To claim this, I am signing this object:

Chalice:

Chalice is a C-like language that attempts to be modern without being "modern". Without having to worry about backwards compatibility with the legacy of C, Chalice has an opportunity to clean up the language significantly, removing many aspects from the language that are considered to have been mistakes, but without removing the aspects of C that make it such a strong, simple, easy-to-use language.

The syntax of Chalice is intentionally very similar to C. Chalice does not have classes or methods. Chalice does not have references (neither Java-style nor C++-style). Chalice is pass-by-value, like C. That isn't to say that Chalice is identical to C. Chalice doesn't have a carcinogenic declaration syntax. Chalice is designed to be able to be parsed using a single token of lookahead, and compiled in a single pass.

Chalice takes a lot of inspiration from the Linux kernel coding style guidelines. For example, spaces cannot be used as indentation. Trailing whitespace is a compiler error. Chalice

import itertools
import re
class Lexer:
def __init__(self, tokens):
self.tokens = tokens
self.regex = re.compile(self.combine_regexes(self.make_named_groups()))
def combine_regexes(self, named_groups):
return '|'.join(named_groups)
#ifndef FOO
#define FOO
#include <string>
namespace tec {
std::string utf8_encode(const std::wstring &wstr);
std::wstring utf8_decode(const std::string &str);
}
@milesrout
milesrout / file.py
Last active October 10, 2016 07:33
class _open_grailfile:
def __init__(self, path):
self.path = path
def __enter__(self):
"""Lock and open the Grailfile at the given path."""
# if the Grailfile is foobar/Grailfile, store a lock at foobar/.grail/LOCK
dotdir_path = _get_dotgrail_dir(path)
lock_path = dotdir_path / 'LOCK'