runtime.c @ 37b7eecfdf6e

Add conditionals
author Steve Losh <steve@stevelosh.com>
date Thu, 04 Mar 2021 20:25:44 -0500
parents 87674bc4c220
children 01ba812a486a
#include <stdio.h>
#include <stdint.h>

// Bools
#define bool_f 0x1F
#define bool_t 0x3F

// 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 0x2F

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;
}