Kind of works

This commit is contained in:
bʰedoh₂ swé 2024-06-18 19:04:23 +05:00
parent 0d102315c8
commit 4c92b22e6d
10 changed files with 132 additions and 0 deletions

15
Makefile Normal file
View File

@ -0,0 +1,15 @@
CFLAGS ?=
ifeq ($(OS),Windows_NT)
LIBSUFFIX = dll
else
LIBSUFFIX = so
endif
%.$(LIBSUFFIX): %.c
$(CC) -shared -fPIC $(CFLAGS) $< -o $@
all: native/fopen.$(LIBSUFFIX) native/fgetc.$(LIBSUFFIX) native/feof.$(LIBSUFFIX)
clean:
rm native/*.$(LIBSUFFIX)

5
close_file.lb Normal file
View File

@ -0,0 +1,5 @@
@ 0
args 4
size
#exec std/rev.lb
#native liblabafile/native/fclose

5
eof_file.lb Normal file
View File

@ -0,0 +1,5 @@
@ 0
args 4
size
#exec std/rev.lb
#native liblabafile/native/feof

5
getc_file.lb Normal file
View File

@ -0,0 +1,5 @@
@ 0
args 4
size
#exec std/rev.lb
#native liblabafile/native/fgetc

11
native/fclose.c Normal file
View File

@ -0,0 +1,11 @@
#include <stdlib.h>
#include <stdio.h>
void labashka(unsigned short (*pop)(void), void (*push)(unsigned short), size_t (*len)(void), size_t max_size ) {
FILE *file = NULL;
file = (void*)((size_t)(pop()) << (16*0) | (size_t)file);
file = (void*)((size_t)(pop()) << (16*1) | (size_t)file);
file = (void*)((size_t)(pop()) << (16*2) | (size_t)file);
file = (void*)((size_t)(pop()) << (16*3) | (size_t)file);
push(fclose(file));
}

11
native/feof.c Normal file
View File

@ -0,0 +1,11 @@
#include <stdlib.h>
#include <stdio.h>
void labashka(unsigned short (*pop)(void), void (*push)(unsigned short), size_t (*len)(void), size_t max_size ) {
FILE *file = NULL;
file = (void*)((size_t)(pop()) << (16*0) | (size_t)file);
file = (void*)((size_t)(pop()) << (16*1) | (size_t)file);
file = (void*)((size_t)(pop()) << (16*2) | (size_t)file);
file = (void*)((size_t)(pop()) << (16*3) | (size_t)file);
push(feof(file));
}

11
native/fgetc.c Normal file
View File

@ -0,0 +1,11 @@
#include <stdlib.h>
#include <stdio.h>
void labashka(unsigned short (*pop)(void), void (*push)(unsigned short), size_t (*len)(void), size_t max_size ) {
FILE *file = NULL;
file = (void*)((size_t)(pop()) << (16*0) | (size_t)file);
file = (void*)((size_t)(pop()) << (16*1) | (size_t)file);
file = (void*)((size_t)(pop()) << (16*2) | (size_t)file);
file = (void*)((size_t)(pop()) << (16*3) | (size_t)file);
push(fgetc(file));
}

20
native/fopen.c Normal file
View File

@ -0,0 +1,20 @@
#include <stdlib.h>
#include <stdio.h>
void labashka(unsigned short (*pop)(void), void (*push)(unsigned short), size_t (*len)(void), size_t max_size ) {
unsigned short modelen = pop();
char *mode = calloc(modelen, sizeof(char));
for (short i = modelen - 1; i != -1; i--)
mode[i] = pop();
unsigned short filenamelen = pop();
char *filename = calloc(filenamelen, sizeof(char));
for (short i = filenamelen - 1; i != -1; i--)
filename[i] = pop();
FILE *file = fopen(filename, mode);
push((short)((0xFFFF000000000000 & (long)file) >> (16*3) ));
push((short)((0x0000FFFF00000000 & (long)file) >> (16*2) ));
push((short)((0x00000000FFFF0000 & (long)file) >> (16*1) ));
push((short)((0x000000000000FFFF & (long)file) >> (16*0) ));
}

23
open_file.lb Normal file
View File

@ -0,0 +1,23 @@
@ 0
args 0
size
#exec std/string/array/rev.lb
args 1
dup
; |str_size str_size...>
@ 1
kjz 2
#expr -
args 1
#exec std/rot.lb
#exec std/rot.lb
jmp 1
@ 2
pop
#exec std/string/array/rev.lb
#exec std/string/array/swap.lb
#native liblabafile/native/fopen

26
test.lb Normal file
View File

@ -0,0 +1,26 @@
; Чё-то кириллицей.
@ 0
$string liblabafile/test.lb
$string r
#exec liblabafile/open_file.lb
@ 1
#exec std/dup4.lb
#exec liblabafile/getc_file.lb
; |char ptr[4]>
push 4
pick
push 4
pick
push 4
pick
push 4
pick
; |ptr[4] char ptr[4]>
#exec liblabafile/eof_file.lb
jnz 2
putc
jmp 1
@ 2
quit