![]() (make-memptr :mem (memptr-mem ptr1) :ptr (- (memptr-ptr ptr1) (memptr-ptr ptr2))))Īs you can see I don't do anything with type declarations, so arithmetic performance is going to be terrible. "Trying to subtract pointers from two different memory segments") (assert (eq (memptr-mem ptr1) (memptr-mem ptr2)) () (defmethod vacietis.c:- ((ptr1 memptr) (ptr2 memptr)) (make-memptr :mem (memptr-mem ptr) :ptr (+ x (memptr-ptr ptr)))) (defmethod vacietis.c:+ ((ptr memptr) (x integer)) (defmethod vacietis.c:+ ((x number) (y number)) (plate-ptr (funcall (place-ptr-closure ptr) new-value)))) (memptr (setf (aref (memptr-mem ptr) (memptr-ptr ptr)) new-value)) (defun (setf vacietis.c:deref*) (new-value ptr) (place-ptr (funcall (place-ptr-closure ptr))))) (memptr (aref (memptr-mem ptr) (memptr-ptr ptr))) `(make-place-ptr :closure (lambda (&optional ,new-value) (defmacro vacietis.c:mkptr& (place) need to deal w/function pointers (make-memptr :mem (make-array size :adjustable t :initial-element 0))) (defun allocate-memory (size) shared by malloc and static allocation ![]() > What I can't wrap my head around is how one would implement pointer-arithmetic with these closures? According to the CERN people, CINT has "slightly less than 400,000 lines of code." ( ). I think I figured out how to do gotos in JavaScript by using a trampoline with local CPS-rewriting, which is IMO the largest challenge for an interoperable C->JS translator.Īs to how to do this for C++, don't ask me. This should also extend to "compiling" C to other languages like JavaScript, without having to go through the whole "emulate LLVM or MIPS" garbage that other projects like that do. There's a few things I need to finish with #includes, enums, stdlib and the variable-length struct hack, but that should be done in the next few weeks. Otherwise the project is now where you can compile-file/load a C file just like you do a Lisp file by setting the readtable. I think I'll also need a little source fudging magic for setjmp/longjmp. But that's a problem for portable C software anyway. The only problem is how to deal with casting arrays of integers (or whatever) to arrays of bytes. Pointers are trivial to implement with closures (Oleg explains how: but I discovered the technique independently around 2004). This is surprisingly easy because C is largely a small subset of Common Lisp. I am writing a C to Common Lisp translator right now ( ). Neither of them are interpreters, just "interactive" compilers like Lisp ones are. ) and Scott Burson's (hn user ScottBurson) ZetaC for TI Explorers/LMIs and Symbolics 3600s (now available under the public domain: ). The first C "interpreters" I know of were for Lisp machines: Symbolics' C compiler (. To provide more precedents and a little history: ![]()
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |