Skip to content

Commit

Permalink
Run-time for iniquity-plus.
Browse files Browse the repository at this point in the history
  • Loading branch information
dvanhorn committed Nov 14, 2024
1 parent cff18d5 commit d69e3ec
Show file tree
Hide file tree
Showing 9 changed files with 1,200 additions and 0 deletions.
44 changes: 44 additions & 0 deletions iniquity-plus/Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
UNAME := $(shell uname)

ifeq ($(UNAME), Darwin)
format=macho64
CC=arch -x86_64 gcc
else
format=elf64
CC=gcc
endif

objs = \
main.o \
print.o \
values.o \
io.o

default: submit.zip

submit.zip:
zip submit.zip -r * \
-x \*.[os] -x \*~ -x \*zip \
-x \*Zone.Identifier -x \*\*compiled\*\*

runtime.o: $(objs)
ld -r $(objs) -o runtime.o

%.run: %.o runtime.o
$(CC) runtime.o $< -o $@

.c.o:
$(CC) -fPIC -c -g -o $@ $<

.s.o:
nasm -g -f $(format) -o $@ $<

%.s: %.rkt
cat $< | racket -t compile-stdin.rkt -m > $@

clean:
@$(RM) *.o *.s *.run ||:
@echo "$(shell basename $(shell pwd)): cleaned!"

%.test: %.run %.rkt
@test "$(shell ./$(<))" = "$(shell racket $(word 2,$^))"
25 changes: 25 additions & 0 deletions iniquity-plus/io.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
#include <stdio.h>
#include <inttypes.h>
#include "types.h"
#include "values.h"
#include "runtime.h"

val_t read_byte(void)
{
char c = getc(in);
return (c == EOF) ? val_wrap_eof() : val_wrap_byte(c);
}

val_t peek_byte(void)
{
char c = getc(in);
ungetc(c, in);
return (c == EOF) ? val_wrap_eof() : val_wrap_byte(c);

}

val_t write_byte(val_t c)
{
putc((char) val_unwrap_int(c), out);
return val_wrap_void();
}
41 changes: 41 additions & 0 deletions iniquity-plus/main.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
#include <stdio.h>
#include <stdlib.h>
#include "values.h"
#include "print.h"
#include "runtime.h"

FILE* in;
FILE* out;
void (*error_handler)();
val_t *heap;

void error_exit()
{
printf("err\n");
exit(1);
}

void raise_error()
{
return error_handler();
}

int main(int argc, char** argv)
{
in = stdin;
out = stdout;
error_handler = &error_exit;
heap = malloc(8 * heap_size);

val_t result;

result = entry(heap);

print_result(result);

if (val_typeof(result) != T_VOID)
putchar('\n');

free(heap);
return 0;
}
Loading

0 comments on commit d69e3ec

Please sign in to comment.