Skip Navigation

InitialsDiceBearhttps://github.com/dicebear/dicebearhttps://creativecommons.org/publicdomain/zero/1.0/„Initials” (https://github.com/dicebear/dicebear) by „DiceBear”, licensed under „CC0 1.0” (https://creativecommons.org/publicdomain/zero/1.0/)CT
ChubakPDP11+TakeWithGrainOfSalt @ ChubakPDP11 @programming.dev
Posts
0
Comments
70
Joined
1 yr. ago

  • You don't need any garbage 3rd party packages. Just use ctypes.

    Read the documentation for ctypes. You can use any native object in Python the way you do in C using ctypes.

    Whatever you do, don't trust some god-forsaken 3rd party package. I think people have forgotten to be clever and resourceful these days. A binary object is itself a package, why would you use s another package to communicate with it?

    Here's how you can import libc into Python:

     
        
    from ctypes import CDLL
    
    libc = CDLL(None)
    
      

    Just pass it path to the binary object that holds the symbols for GPIO.

    Some tricks. Here's how you can use libc to make a syscall in Python:

     
        
    libc = CDLL(None)
    
    TIME_NR = <syscall nr for time(2) on your arch>
    
    libc.syscall(TIME_NR)
    
    
    
      
  • So I am going to explain the concept of macro preprocessors to you --- m5.awk is a macro preprocessor, so is m4 so is GPP so is C's CPP, so is my Ekipp and so is my AllocPP.pl. They all work like this:

    1- Frank Frankis (hereby referred to as FF) creates a file called my-file.randext --- randext here meaning that macro prerpcoessors work on all kind of files, be it a C code, a Python code, an HTML template, your tax files, your notes to your GF, your angry letter to your boss, etc;

    2- There are dozens and dozens of uses for a macro preprocessors, but let's say FF wants to obliterate two birds with one sniper shot, he wishes to write a manual for his new Car XAshtray (TM), in HTML and Markdown, but he wants it to be contained within one single file -- and he wishes to reuse certain fragments of text, certain HTML tags, certain Markdown syntaxes, to be 'reusable', just like a 'function' is reusable piece of code in an imperative language (but not a functional language!) or how a template works in C++, etc.

    3- FF enters the file with his favorite text editor. He defines these 'functions', which are the 'macro' part of a macro preprocessor. Think what 'macro' means. It means 'big picture' basically. I think the better term here is 'meta'. These two words have a close relationship in the English language, don't they?

    Now let's see what macro preprocessor FF uses. Since GPP is really similar in syntax to C's preprocessor (at least with default settings) let's use GPP. I would use my Ekipp here but I honestly have forgotten the syntax (believe it or not, creating a language does not mean you are good at it).

     
        
    #ifdef __HTML__
    #define TITLE <h1>My Car XAshtray Manual</h1>
    #define SUBTITLE <h5>Throw your ash on me</h5>
    #define BOLDEN(text) <b>text</b>
    #elif __MARKDOWN__
    #define TITLE  \# My Car XAhtray Manual
    #define SUBTITLE \#\#\#\#\# Throw your ash on me
    #define BOLDEN(text) **text**
    #else
    #error "Must define a target language"
    #endif
    
    
      

    FF keeps defining these. Now comes writing the actual manual.

    Keep in mind that GPP stands for 'Generic Preprocessor', it's a text macro prerpcoessor and not a language preprocessor like CPP (C's preprocessor) is. m4 and Ekipp are like that. My AllocPP.pl is a language preprocessor, it preprocesses C. So now, this means FF can now freely treat my-file.randext as a text file, with a 'language', the Macro Preprocessor language, defining the output (I'll talk about what I mean by 'output' soon).

    So he writes his manual:

     
        
    TITLE
    SUBTITLE
    
    Hello! Are you okay? Why did you buy this ashtray? BOLDEN(ARE YOU OKAY?). In this manual I will teach you how to use my ashtray...
    ...
    
      

    Replace the last ellipse with rest of the text, the Car Ashtray manual.

    Now, FF needs to 'preprocess' this text file. This is, well, the 'preprocessing' part of a macro preprocessor. It's like compiling a program with a compiler, except you are compiling text-to-text instead of text-to-binary.

     
        
    gpp -D__MARKDOWN__ my-file.randext > my-manual.md
    ``
    But what happened at `-D__MARKDOWN__`? I think you have already guessed. In the 'program' we asserted if '__MARKDOWN__' is 'defined', then then define those macros as Markdown, else HTML. We can also define a macro with a value:
    
    
    
      

    gpp -DMyMacro=MyValue my-file.randext > my-manual.md

     
        
    
    Now, GPP has more built-in macros like `#ifdef`, they are called 'meta macros` (as opposted to the macros you yourself define). There's `#include` which includes a file. There `#exec` which executes a shell command. Etc etc.
    
    Now, you can read more about GPP on its Github. I was in touch with its maintainer, Tristan Miller, very recently when I showed him my Ekipp. He has made a new version of GPP so don't install it from your package manager like apt, install it from source because the release is very recent and these packages take ages to be updated. GPP is just one C file, very neat and clean. Read the man page (`man 1 gpp`) for more info.
    
    m4 and m5 or Ekipp etc, as I said, are too, generic text preprpocessors. My Ekipp has this feature where, you can treat any program like PHP works:
    
    
    
      

    #! delimexec $ ''awk "{ print $1; }"'' | <== foo bar ==>

     
        
    
    This will run the AWK program in the file.
    
    You can install my Ekipp using these commands:
    
    
    
      

    sudo apt-get install libreadline-dev libgc-dev libunistring-dev wget -qO- https://raw.githubusercontent.com/Chubek/Ekipp/master/install.sh | sudo sh

     
        
    
    Bring up `man 1 ekipp` to learn about it.
    
    Keep in mind that Ekipp has some bugs. I will have to completely rewrite it honestly but I am busy making an implementation of ASLD (github.com/Chubek/asdl) and I am working on an implementation of AWK and later C so a macro preprocessor does not bite me really.
    
    Thanks.
    
    
    
    
    
      
  • I forgot to mention, tools like Bison and Autoconf use m4. Andrew Appel calls languages that need preprocessing 'weak'. The specs for D also call C 'weak' for needing to be preprocessed. Preprocessing is almost an abandoned practice, at least in the world of programming, because Scheme-like 'hygenic macros' have taken their place. Some languages like Rust and Zig are attempting to reinvent the wheel by re-inventing macros, but Scheme had it right in the 70s. Truly, C and Pascal's preprocessor were out the door in the 70s, let alone, now.

    Here's another preprocessor that is 'neat: GPP.

    I have made my own preprocessor, it's very nasty and has a lot of bugs because I was an idiot when I made it: https://github.com/Chubek/Ekipp

    I have half a mind to remake Ekipp. I don't know what purpose would it serve. But it's just neat, I think preprocessors are neat, as useless as they are.

  • It does not really need to explain what it 'is' because

    1- a paper has been released on ACM explaining it, you can download it for free from here: https://dl.acm.org/doi/pdf/10.1145/353474.353484

    2- It's name is m5, most people in the UNIX world know what m4 is. If you have Linux, bring up info m4.

    Imagine this, when you use C, there is a preprocessor that does all the #include and #defines, m4 is like that and m5 is like that too. Preprocessing used to be big, but now it's not. If you wanna see an example of preprocessing, look at this preprocessor I made for C: https://gist.github.com/Chubek/b2846855e5bb71a67c7e3effc6beefd6

  • People are designing languages with JetBrains MPS and I am making an AWK interpreter in C with Yacc, Lex and my own implementation of ASDL. Why do I do this to myself? It seems like the technology I like is way behind. Like C is a language created for freaking mini-computers like VAX and PDP-11 and I still use it? I knew about MPS, I just felt a strong dislike towards it. Now that I am no longer a pill addict, I have to reconsider the technology I choose to implement my stuff. C lacks portability, and QoL features.

    (Psyche! All you n000bz can be stuck with your Fischer-Price toys --- I'll do it MY way, the 70s WAY!!!!1)

  • I hate this word arrangement in the title. It reminds me of painfully oblique 'breadtube' videos. "Getting naked near an elementary school and eating whipped cream off your boyfriend's ass is good, 'actually'!" I think the first person who used it might have been the chick who got hit by hotdogs in that old GIF.

  • I really recommend creating a compiler or an interpreter from scratch, don't even use an IR like LLVM or MIR. Just hack and slash your way though a C compiler, it's the simplest language most people know. Don't care about 'optimization' at first, fuck optimization. Just grab Yacc/Lex or a PEG parser generator that works with the language you like most and have ot generate assembly code for simple expressions. Like, make a bc(1) native compiler! Interprets are fun too. You can use VMGEN to generate a superfast VM in C, and then bind it to another language using SWIG.
    Also never imagine usability. Noobdy is going to use your C compiler for any serious work. It's just for education. Post it online to receive feedback.

    You cna start by writing DSLs. For example, I am implementing the ASDL language from this old paper.

    Also if you are going to do it as an example in your resume, just stop. Nobody cares, because it's a trivial task to write a compiler, even if you write backend, forntned, and the LP yourself! Do something money-loving people loike, like making some bullshit mobile app that tracks your gym sweat volume.

  • I kinda like that I am as far away from the web world as possible. The only time I deal with anything web-related making a static blog software for myself. As Alan Kay puts it, web is ill, because it has been a hack from day -1. Every time you make a web application, you are using a mule to carry a city worth of cargo on its back.

    Web was created for static pages. Use it for static pages. The only website that does not do this and I use is Youtube. I only then visit HackerNoon and Lemmy instances, both of which come out of Web's tube of shit proud.

    i wish I could post my conversation (barely a conversation, what do I have to converse with someone who's worked with magnetic core, I just agreed) with Alan Kay on Quora, but I tried to login, and it was so bloated, I could not find the conversation.

    I apologize if this hurts your feelings that your 'lil protocol sucks. Read about Dough Englebert's NLS.

    Thanks.

  • I subconsciously knew this, I currently am making a simple data exchange format to use with a program, and I am using PEG to create a parser. Chances of errors happning in this DXF is really low, but if the parser can't parse it, it's invalid.