runtime.c @ 87674bc4c220

Add remaining unary primitives, fix large immediate representation
author Steve Losh <steve@stevelosh.com>
date Wed, 03 Mar 2021 21:33:32 -0500
parents de18bb93f9ec
children 37b7eecfdf6e
#include <stdio.h>
#include <stdint.h>

// Bools
#define bool_f 0x2F
#define bool_t 0x6F

// Fixnums
#define fx_mask  0x03
#define fx_tag   0x00
#define fx_shift 2

// Characters
#define ch_mask  0xFF
#define ch_tag   0x0F
#define ch_shift 8

// Nil
#define nil 0x3F

typedef uint64_t ptr;

ptr scheme_entry();

static void print_ptr(ptr x) {
    if ((x & fx_mask) == fx_tag) {
        printf("%ld", ((int64_t)x >> fx_shift));
    } else if ((x & ch_mask) == ch_tag) {
        printf("#\\%c", ((int)x >> ch_shift));
    } else if (x == bool_f) {
        printf("#f");
    } else if (x == bool_t) {
        printf("#t");
    } else if (x == nil) {
        printf("()");
    } else {
        printf("#<unknown #x%016lx>", x);
    }

    printf("\n");
}

int main(int argc, char** argv) {
    print_ptr(scheme_entry());
    return 0;
}