Add (possibly buggy) putc_file.lb

This commit is contained in:
bʰedoh₂ swé 2024-06-19 04:30:58 +05:00
parent 7e4f9ed095
commit 3659b96b81
4 changed files with 29 additions and 1 deletions

View File

@ -9,7 +9,7 @@ endif
%.$(LIBSUFFIX): %.c
$(CC) -shared -fPIC $(CFLAGS) $< -o $@
all: native/fopen.$(LIBSUFFIX) native/fgetc.$(LIBSUFFIX) native/feof.$(LIBSUFFIX)
all: native/fopen.$(LIBSUFFIX) native/fgetc.$(LIBSUFFIX) native/feof.$(LIBSUFFIX) native/fputc.$(LIBSUFFIX) native/fclose.$(LIBSUFFIX)
clean:
rm native/*.$(LIBSUFFIX)

14
native/fputc.c Normal file
View File

@ -0,0 +1,14 @@
#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 symbol = pop();
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(fputc(symbol, file));
}

5
putc_file.lb Normal file
View File

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

9
puttest.lb Normal file
View File

@ -0,0 +1,9 @@
@ 0
$string somefile.txt
#string w
#exec liblabafile/open_file.lb
#exec std/dup4.lb
push 70
#exec liblabafile/putc_file.lb
pop
#exec liblabafile/close_file.lb