some shit

This commit is contained in:
nils polek 2024-01-18 19:15:56 +00:00
parent 9b4a9faa8d
commit 6319ddcad9
11 changed files with 53 additions and 24 deletions

1
.gitignore vendored
View File

@ -4,3 +4,4 @@ njvm
njvm.dSYM
njvm.exe
njvm2
test

View File

@ -5,7 +5,7 @@ build:
gcc -g -Wall -Lbigint/build/lib -o njvm njvm.o support.o -lbigint
run: build
./njvm programs/prog1.bin
./njvm prog.bin
debug: build
./njvm --debug prog.bin

43
Makefile3 Normal file
View File

@ -0,0 +1,43 @@
# Makefile for a simple C program
# Compiler
CC = gcc
# program to Run
F = prog.bin
# Compiler flags
CFLAGS = -g -Wall -Ibigint/build/include
LDFLAGS = -g -Wall -Lbigint/build/lib
# Source file
SRC = njvm.c
# Executable name
TARGET = njvm
njvm.o:
$(CC) $(CFLAGS) -o njvm.o -c njvm.c
support.o:
$(CC) $(CFLAGS) -o support.o -c support.c
# Default target
all: njvm.o support.o
$(CC) $(LDFLAGS) -o $(TARGET) njvm.o support.o -lbigint
# Clean up
clean:
rm -f $(OBJ) $(TARGET)
debug: all
./$(TARGET) --debug $(F)
run: all
./$(TARGET) $(F)
nja: ./nja/nja$(V)
./nja/nja$(V) $(IN) $(OUT)
njc: ./njc/njc$(V)
./njc/njc$(V) $(IN) $(OUT)

View File

@ -1,6 +1,6 @@
#ifndef CONSTS
#define CONSTS
#define VERSION 6;
#define VERSION 6
#endif /* ifndef CONSTS
#define CONSTS

View File

@ -34,10 +34,10 @@ void breakpoint(){
//todo
}
void debugMenu(int fp, struct stack stack, int* debug){
void debugMenu(int fp, struct stack stack, int* debug, int point){
char input[20];
while (true) {
printf("DEBUG: inspect, list, breakpoint, run, step, quit?");
printf("DEBUG(%i): inspect, list, breakpoint, run, step, quit?",point);
fgets(input, 20, stdin);
printf("%s",input);
if(input[0] == 'i') {inspect(stack,fp);}

14
njvm.c
View File

@ -29,13 +29,6 @@ unsigned fp;
void version(void) {
printf("Ninja Virtual Machine version %i (compiled %s, %s)\n", 0, __DATE__, __TIME__);
bigFromInt(9);
bip.op1 = bip.res;
bigFromInt(10);
bip.op2 = bip.res;
bigAdd();
bip.op1 = bip.res;
bigPrint(stdout);
}
void help(void) {
@ -48,7 +41,7 @@ void execute(struct program program) {
StackSlot tempSlot;
ObjRef tempObj;
for (i = 0; i < *program.size; ++i) {
if (debug == 1) debugMenu(fp, stack, &debug);
if (debug == 1) debugMenu(fp, stack, &debug, i);
switch (program.program[i] >> 24) {
case HALT:
if (debug == 1) printf("halt\n");
@ -148,8 +141,8 @@ void execute(struct program program) {
if (debug == 1) printf("ne: %i != %i\n", peek(stack, 2), peek(stack, 1));
bip.op2 = pop(stack).u.objRef;
bip.op1 = pop(stack).u.objRef;
if (bigCmp() != 0) push(stack, stackSlotWithObjRef(getIntObj(true)));
else push(stack, stackSlotWithObjRef(getIntObj(false)));
bigFromInt(bigCmp() != 0);
push(stack,stackSlotWithObjRef(bip.res));
break;
case EQ:
if (debug == 1) printf("eq: %i == %i\n", peek(stack, 2), peek(stack, 1));
@ -191,6 +184,7 @@ void execute(struct program program) {
if (debug == 1) printf("pop: %i\n", peek(stack, 1));
bip.op1 = pop(stack).u.objRef;
int b = bigToInt();
printf("%i , %i",b, false);
if (b == false) {
i = SIGN_EXTEND(IMMEDIATE(program.program[i])) - 1;
if (debug == 1) printf("new i: %i\n", i);

BIN
njvm.o

Binary file not shown.

BIN
njvm6 Executable file

Binary file not shown.

BIN
prog.bin

Binary file not shown.

BIN
support.o

Binary file not shown.

9
test.c
View File

@ -1,9 +0,0 @@
#include <stdio.h>
#include "bigint.h"
int main(int argc, char *argv[])
{
printf("Hallo Welt\n");
bigFromInt(5);
return 0;
}