This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import numpy as np | |
import bimpy | |
class Axis: | |
def __init__(self, size=None, xlim=(0, 1), ylim=(0, 1), bg_color=0x55FFFFFF): | |
self.xlim = xlim | |
self.ylim = ylim | |
if size is None: |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const INLINE_THRESHOLD: usize = 32; // inline words up to a length of 32 commands | |
type Stack = Vec<Data>; | |
#[derive(Debug, Copy, Clone, PartialEq)] | |
struct WordId(usize); | |
type Result<T> = std::result::Result<T, ForthError>; | |
#[derive(Debug)] |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from functools import cmp_to_key | |
class StackItem: pass | |
class Row(StackItem): | |
def __init__(self, name=''): | |
self.name = name | |
def __repr__(self): | |
return '..' + self.name |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
use std::any::Any; | |
type State = Vec<Object>; | |
trait ObjectProtocol: std::fmt::Debug { | |
fn as_any(&self) -> &dyn Any; | |
fn as_number(&self) -> Option<&dyn NumberProtocol>; | |
fn repr(&self, _state: &mut State); | |
fn is_number(&self) -> bool { self.as_number().is_some() } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
use std::collections::HashMap; | |
use std::rc::Rc; | |
type State = Vec<Object>; | |
type Closure = Rc<Fn(&mut State)>; | |
#[derive(Clone)] | |
enum Object { | |
Int(i32), |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
use std::cell::RefCell; | |
use std::collections::HashSet; | |
use std::rc::Rc; | |
type Result<T> = std::result::Result<T, AlignError>; | |
#[derive(Debug, Clone, PartialEq)] | |
struct StackEffect { | |
inputs: StackSequence, | |
outputs: StackSequence, |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
//! Demonstration of implementing tail calls in Rust through trampolining. | |
//! Although the core types are generic, there are a few restrictions with | |
//! this approach: | |
//! 1. Functions take exactly one argument and return one value. This can be | |
//! worked around by taking and returning compound types. | |
//! 2. Functions must have the same type signature to be able to tail-call | |
//! each other. I.e. a function that takes an i32 cannot call a another | |
//! function that takes an i64, even if they return the same type. To | |
//! work around this restriction one has to use dynamic typing, which | |
//! comes at a runtime cost. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
use std::collections::HashMap; | |
type T = i64; | |
enum Label { | |
FactIterativeLoop, | |
Done, | |
} | |
pub fn main() { |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from ctypes import CFUNCTYPE, c_int32, c_voidp, c_char | |
import llvmlite.binding as llvm | |
from llvmlite import ir | |
hello_world_source = """ | |
++++++++ Set Cell #0 to 8 | |
[ | |
>++++ Add 4 to Cell #1; this will always set Cell #1 to 4 | |
[ as the cell will be cleared by the loop | |
>++ Add 2 to Cell #2 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <stdbool.h> | |
#include <memory.h> | |
#define NIL 0 | |
#define POINTER 1 | |
#define NUMBER 2 | |
typedef struct TaggedCell TaggedCell; | |
struct TaggedCell { |