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
| %T = type { i8, i64 } | |
| declare %T* @allocate_new_pair() | |
| declare %T @number(i32 %num) | |
| define i1 @is_null(%T %obj) { | |
| %tag = extractvalue %T %obj, 0 | |
| %cond = icmp eq i8 %tag, 0 | |
| br i1 %cond, label %yes, label %no |
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 | |
| # All these initializations are required for code generation! | |
| llvm.initialize() | |
| llvm.initialize_native_target() | |
| llvm.initialize_native_asmprinter() # yes, even this one | |
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
| # This is a python translation of the continuation passing style conversions | |
| # found in http://matt.might.net/articles/cps-conversion/ | |
| count = 1 | |
| def gensym(name): | |
| global count | |
| name = name + str(count) | |
| count += 1 | |
| return 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
| #[derive(Debug, Clone, PartialEq)] | |
| pub enum Obj { | |
| Nil, | |
| Sym(&'static str), | |
| Pair(Box<Obj>, Box<Obj>), | |
| } | |
| impl Obj { | |
| pub fn cons(car: Obj, cdr: Obj) -> Self { | |
| Obj::Pair(Box::new(car), Box::new(cdr)) |
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
| [package] | |
| edition = "2018" | |
| name = "forth" | |
| version = "1.7.0" | |
| [dependencies] | |
| cranelift = "0.37.0" | |
| cranelift-module = "0.37.0" | |
| cranelift-simplejit = "0.37.0" |
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
| #[derive(Debug, Copy, Clone)] | |
| enum AtomicValue { | |
| Undefined, | |
| Nil, | |
| Integer(i64), | |
| Pointer(*mut Self), | |
| Record(*mut Self, u32), | |
| Pair(*mut Self), | |
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::HashSet; | |
| fn main() { | |
| let mut gc = Memory::new(); | |
| gc.set_base(estimate_stack_pointer_address()); | |
| let s = Box::new(Box::new(inner_main(&mut gc))); // Disaster! | |
| gc.collect_stack(); | |
| inner_main(&mut gc); | |
| gc.collect_stack(); | |
| println!("=============="); |
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::Cell; | |
| macro_rules! scm_meaning { | |
| (()) => {Scm::Nil}; | |
| (<) => {Scm::from(Scm::less)}; | |
| (>) => {Scm::from(Scm::greater)}; | |
| (+) => {Scm::from(Scm::add)}; | |
| (-) => {Scm::from(Scm::sub)}; | |
| (*) => {Scm::from(Scm::mul)}; | |
| (/) => {Scm::from(Scm::div)}; |
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
| (define (meaning e r) | |
| (if (atom? e) | |
| (if (symbol? e) (meaning-reference e r) | |
| (meaning-quotation e r)) | |
| (case (car e) | |
| ((quote) (meaning-quotation (cadr e) r)) | |
| ((set!) (meaning-assignment (cadr e) (caddr e) r)) | |
| ((begin) (meaning-sequence (cdr e) r)) | |
| ((if) (meaning-alternative (cadr e) (caddr e) (cadddr e) r)) | |
| ((lambda) (meaning-abstraction (cadr e) (cddr e) r)) |
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
| // Variant 1: globals in struct | |
| /* | |
| (import (scheme base) (example counter)) | |
| (display (count)) (newline) | |
| (display (count)) (newline) | |
| */ | |
| use example_counter::*; |