1
0
mirror of https://github.com/janet-lang/janet synced 2025-11-03 09:03:02 +00:00

More work on drawing example and frontend changes.

This commit is contained in:
Calvin Rose
2024-12-01 08:43:54 -06:00
parent 046d299d77
commit 4396f01297
4 changed files with 35 additions and 21 deletions

View File

@@ -15,9 +15,15 @@
(defpointer cursor p32)
# Linux syscalls
(defn-syscall brk:p32 12 [amount:uint])
(defn-syscall exit:void 60 [code:int])
(defn-syscall write:void 1 [fd:int data:p32 size:uint])
# (defn-syscall brk:p32 12 [amount:uint])
# (defn-syscall exit:void 60 [code:int])
# (defn-syscall write:void 1 [fd:int data:p32 size:uint])
# (defn-syscall write_string 1 [fd:int data:pointer size:uint])
# External
(defn-external write:void [fd:int mem:pointer size:uint])
(defn-external exit:void [x:int])
(defn-external malloc:p32 [size:uint])
(defsys w32:void [c:cursor x:uint]
(def p:p32 (load c))
@@ -34,10 +40,10 @@
(defsys makebmp:p32 [w:uint h:uint]
(def size:uint (+ 56 (* w h 4)))
(def mem:p32 (brk size))
(def mem:p32 (malloc size))
(def c:cursor (cast (malloc 4)))
#(def cursor_data:p32 mem)
#(def c:cursor (address cursor_data))
(def c:cursor (cast (brk 4)))
(store c mem)
(w16 c 0x4D42) # ascii "BM"
(w32 c size)
@@ -72,18 +78,15 @@
(write 1 mem size)
(return mem))
(defsys _start:void []
(defsys main:int []
(def w:uint 512)
(def h:uint 512)
# (makebmp w h)
(def size:uint (+ 56 (* w h 4)))
(def mem:p32 (brk size))
(store mem (the uint 0x4d424d42))
(write 1 mem 4)
#(write 1 (cast "hello, world!\n") 14)
(exit 0)
(return))
(makebmp w h)
(return 0))
####
(dumpx64)
#(dumpx64)
(print "#include <unistd.h>")
(dumpc)

View File

@@ -153,6 +153,17 @@
(array/push into ~(pointer-add ,slot ,base-slot ,offset-slot))
slot)
'pointer-sub
(do
(assert (= 2 (length args)))
(def [base offset] args)
(def base-slot (visit1 base into false type-hint))
(def offset-slot (visit1 offset into false 'int))
(def slot (get-slot))
(when type-hint (array/push into ~(bind ,slot ,type-hint)))
(array/push into ~(pointer-subtract ,slot ,base-slot ,offset-slot))
slot)
# Type hinting
'the
(do

View File

@@ -1,5 +1,5 @@
#!/usr/bin/env bash
valgrind build/janet examples/sysir/drawing.janet > temp.nasm
nasm -felf64 temp.nasm -l temp.lst -o temp.o
ld -o temp.bin -dynamic-linker /lib64/ld-linux-x86-64.so.2 -lc temp.o
valgrind ./temp.bin
valgrind build/janet examples/sysir/drawing.janet > temp.c
cc temp.c
./a.out > temp.bmp
feh temp.bmp