Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion devices/posixfs.c
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ Cell* posixfs_open(Cell* cpath) {

printf("[posixfs] trying to read file of len %d…\r\n",len);
Cell* res = alloc_num_bytes(len);
int read_len = fread(res->addr, len, 1, f);
int read_len = fread(res->addr, 1, len, f);
// TODO: close?
_file_cell = res;
return res;
Expand Down
2 changes: 1 addition & 1 deletion sledge/alloc.c
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
#include "alloc.h"
#include <malloc.h>
#include <stdlib.h>
#include <stdint.h>
#include "stream.h"

Expand Down
8 changes: 7 additions & 1 deletion sledge/build_x64.sh
Original file line number Diff line number Diff line change
@@ -1,2 +1,8 @@
gcc -g -o sledge --std=gnu99 -I. sledge.c reader.c writer.c alloc.c strmap.c stream.c ../devices/sdl2.c ../devices/posixfs.c -lm -lSDL2 -DCPU_X64 -DDEV_SDL -DDEV_POSIXFS
#!/bin/sh

if [ `uname` = "Darwin" ] ; then
CFLAGS="${CFLAGS} -I/opt/local/include -L/opt/local/lib"
fi

cc -g -o sledge --std=gnu99 -I. ${CFLAGS} sledge.c reader.c writer.c alloc.c strmap.c stream.c ../devices/sdl2.c ../devices/posixfs.c -lm -lSDL2 -DCPU_X64 -DDEV_SDL -DDEV_POSIXFS

8 changes: 8 additions & 0 deletions sledge/compiler_x64_hosted.c
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
#if defined(__APPLE__) && defined(__MACH__)
#define MAP_ANONYMOUS MAP_ANON
#endif

//#define DEBUG

Cell* execute_jitted(void* binary) {
Expand Down Expand Up @@ -34,7 +38,11 @@ int compile_for_platform(Cell* expr, Cell** res) {
// prefix with arm-none-eabi- on ARM -mlittle-endian

system("as /tmp/jit_out.s -o /tmp/jit_out.o");
#if defined(__APPLE__) && defined(__MACH__)
system("gobjcopy /tmp/jit_out.o -O binary /tmp/jit_out.bin");
#else
system("objcopy /tmp/jit_out.o -O binary /tmp/jit_out.bin");
#endif

FILE* binary_f = fopen("/tmp/jit_out.bin","r");

Expand Down
8 changes: 8 additions & 0 deletions sledge/jit_x64.c
Original file line number Diff line number Diff line change
Expand Up @@ -85,10 +85,12 @@ void jit_str_stack(int sreg, int offset) {
}

void jit_inc_stack(int offset) {
if (offset == 0) return;
fprintf(jit_out, "addq $%d, %%rsp\n", offset);
}

void jit_dec_stack(int offset) {
if (offset == 0) return;
fprintf(jit_out, "subq $%d, %%rsp\n", offset);
}

Expand Down Expand Up @@ -167,7 +169,13 @@ void jit_divr(int dreg, int sreg) {

void jit_call(void* func, char* note) {
fprintf(jit_out, "mov $%p, %%rax\n", func);
#if defined(__APPLE__) && defined(__MACH__)
fprintf(jit_out, "subq $8, %%rsp\n");
#endif
fprintf(jit_out, "callq *%%rax # %s\n", note);
#if defined(__APPLE__) && defined(__MACH__)
fprintf(jit_out, "addq $8, %%rsp\n");
#endif
}

void jit_callr(int reg) {
Expand Down
11 changes: 11 additions & 0 deletions sledge/minilisp.h
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@

#include "strmap.h"

#ifndef BLAND
#define KNRM "\x1B[0m"
#define KRED "\x1B[31m"
#define KGRN "\x1B[32m"
Expand All @@ -13,6 +14,16 @@
#define KMAG "\x1B[35m"
#define KCYN "\x1B[36m"
#define KWHT "\x1B[37m"
#else
#define KNRM ""
#define KRED ""
#define KGRN ""
#define KYEL ""
#define KBLU ""
#define KMAG ""
#define KCYN ""
#define KWHT ""
#endif

#define TAG_FREED 0
#define TAG_INT 1
Expand Down