Better HN
topnewbestaskshowjobs
Log inSign up

nineties

416 karma · joined Jun 11, 2015 (11y ago) · 13 submissions

Founder and CEO of Idein Inc. http://idein.jp
Submissions

1.

Show HN: Bootstrapping a compiler from raw machine code(github.com ↗)

3 points · by nineties · 10mo ago · discuss

comment 4y ago · link · parent

Sorry. I found a bug in the *Hello World* program I posted above. The Q operation requires an integer argument, an exit status.

So

    kHtketkltkltkotk tkWtkotkrtkltkdtk!tk:k0-tQ
is wrong. The below is correct.

    kHtketkltkltkotk tkWtkotkrtkltkdtk!tk:k0-tk0k0-Q

comment 4y ago · link · parent

Thank you db48x. Yes, that's the reason. I added them to the first dictionary since these instructions are very simple even when writing in machine language.

In case of mod and divmod, implementing them with add, sub and loop has a serious performance issue. Replacing it with shift operations, bit operations, add, sub and loops could be an option.

comment 4y ago · link · parent

This project is to bootstrap a language processor from a hand-written ELF binary. This is a hobby project and is not intended for any practical use, but constructing a language processor completely from scratch is a lot of fun. Please try running, reading and playing with the code!

Bootstrapping proceeds as follows:

1. Implement a simple Forth interpreter (really) by handwriting ELF.

2. Grow it into a relatively expressive language through self-extension.

Since writing a program in machine language by hand is a tough work, the first interpreter is designed to be very simple. Every built-in word is single-letter and the interpreter just repeats that reads a character, looks it up from the dictionary and executes it. Also there is no error checking.

This is the actual code for the first interpreter, which is a 136-byte implementation of the interpreter followed by a built-in dictionary of 888 bytes.

https://github.com/nineties/planckforth/blob/main/planck.xxd

The first interpreter and language is so esoteric that, for example, the Hello World looks like this.

    $ ./planck
    kHtketkltkltkotk tkWtkotkrtkltkdtk!tk:k0-tQ
bootstrap.fs self-extends this. After running bootstrap.fs, the Hello World program can be written like this:

    $ ./planck < bootstrap.fs
    ." Hello World!" cr
At the beginning of bootstrap.fs, you can only use one-letter words, so the code is difficult to read as shown below.

    $ head bootstrap.fs
    h@l@h@!h@C+h!k1k0-h@$k:k0-h@k1k0-+$h@C+h!ih@!h@C+h!kefh@!h@C+h!l!
    h@l@h@!h@C+h!k1k0-h@$k h@k1k0-+$h@C+h!ih@!h@C+h!kefh@!h@C+h!l!
    
    h@l@ h@!h@C+h! k1k0-h@$ k\h@k1k0-+$ h@C+h!
        i       h@!h@C+h!
        kkf     h@!h@C+h!
        kLf     h@!h@C+h!
        k:k0-   h@!h@C+h!
        k=f     h@!h@C+h!
        kJf     h@!h@C+h!
However, at the end, you can write a normal Forth program as follows. In this way, the interpreter and the language are self-extended during the execution of the script.

    $ tail bootstrap.fs
            next-arg dup argv @ !
            included
        else
            ." Welcome to PlanckForth " version type
            ."  [" runtime type ." ]" cr
            copyright
            ." Type 'bye' to exit." cr
            s" /dev/tty" included
        then
    ; execute
Various functionalities like compile mode, immediate mode, control-flow structures, literals, variables, constants, file I/O, heap memory, etc. will be available after running bootstrap.fs.

Also, the language and bootstrap.fs are designed to be as environment-independent as possible, so you can implement the runtime in other languages as well. As an example, I added an implementation of the runtime in C and Python 3.

There is no space for detailed explanation here. So please read the following source code and comments.

https://github.com/nineties/planckforth/blob/main/bootstrap....

Also, there is a commentary article in Japanese here. I hope you can read it with google translate. (I will write it in English if I have time. someday.)

https://qiita.com/9_ties/items/349b2ed65b7cd8a7d580

Feedbacks and pull requests such as runtime implementations in other languages are very welcome.

Thank you for reading.

5.

Show HN: PlanckForth – Bootstrapping an interpreter from handwritten 1kb binary(github.com ↗)

132 points · by nineties · 4y ago · 19 comments

comment 4y ago · link · parent

This project is to bootstrap a language processor from a hand-written ELF binary. This is a hobby project and is not intended for any practical use, but constructing a language processor completely from scratch is a lot of fun. Please try running, reading and playing with the code!

Bootstrapping proceeds as follows:

1. Implement a simple Forth interpreter (really) by handwriting ELF. 2. Grow it into a relatively expressive language through self-extension.

Since writing a program in machine language by hand is a tough work, the first interpreter is designed to be very simple. Every built-in word is single-letter and the interpreter just repeats that reads a character, looks it up from the dictionary and executes it. Also there is no error checking.

This is the actual code for the first interpreter, which is a 136-byte implementation of the interpreter followed by a built-in dictionary of 888 bytes.

https://github.com/nineties/planckforth/blob/main/planck.xxd

The first interpreter and language is so esoteric that, for example, the Hello World looks like this.

    $ ./planck
    kHtketkltkltkotk tkWtkotkrtkltkdtk!tk:k0-tQ
bootstrap.fs self-extends this. After running bootstrap.fs, the Hello World program can be written like this

    $ ./planck < bootstrap.fs
    ." Hello World!" cr
At the beginning of bootstrap.fs, you can only use one-letter words, so the code is difficult to read as shown below.

    $ head bootstrap.fs
    h@l@h@!h@C+h!k1k0-h@$k:k0-h@k1k0-+$h@C+h!ih@!h@C+h!kefh@!h@C+h!l!
    h@l@h@!h@C+h!k1k0-h@$k h@k1k0-+$h@C+h!ih@!h@C+h!kefh@!h@C+h!l!
    
    h@l@ h@!h@C+h! k1k0-h@$ k\h@k1k0-+$ h@C+h!
        i       h@!h@C+h!
        kkf     h@!h@C+h!
        kLf     h@!h@C+h!
        k:k0-   h@!h@C+h!
        k=f     h@!h@C+h!
        kJf     h@!h@C+h!
However, at the end, you can write a normal Forth program as follows. In this way, the interpreter and the language are extended during the execution of the single script.

    $ tail bootstrap.fs
            next-arg dup argv @ !
            included
        else
            ." Welcome to PlanckForth " version type
            ."  [" runtime type ." ]" cr
            copyright
            ." Type 'bye' to exit." cr
            s" /dev/tty" included
        then
    ; execute
Various functionalities like compile mode, immediate mode, control-flow structures, literals, variables, constants, file I/O, heap memory, etc. will be available after running bootstrap.fs.

Also, the language and bootstrap.fs are designed to be as environment-independent as possible, so you can implement the runtime in other languages as well. As an example, I added an implementation of the runtime in C and Python 3.

There is no space for detailed explanation here. So please read the following source code and comments.

https://github.com/nineties/planckforth/blob/main/bootstrap....

Also, there is a commentary article in Japanese here. I hope you can read it with google translate. (I will write it in English if I have time. someday.)

https://qiita.com/9_ties/items/349b2ed65b7cd8a7d580

Feedbacks and pull requests such as runtime implementations in other languages are very welcome.

Thank you for reading.

7.

Show HN: PlanckForth: Bootstrapping an Interpreter from Handwritten 1KB Binary(github.com ↗)

10 points · by nineties · 5y ago · discuss

8.

Actcast Combines IFTTT-Like Service with AI and Raspberry Pi 3 / Zero(cnx-software.com ↗)

1 points · by nineties · 7y ago · discuss

comment 7y ago · link · parent

Blog article about this release: https://blog.idein.jp/post/181016515935/alphareleaseen

10.

Show HN: Try running deep learning inference on Raspberry Pi(actcast.io ↗)

53 points · by nineties · 7y ago · 11 comments

11.

Show HN: Actcast alpha has been released – Intelligent Sensing for Everyone(blog.idein.jp ↗)

3 points · by nineties · 7y ago · discuss

12.

Creating a language using only assembly language(speakerdeck.com ↗)

347 points · by nineties · 11y ago · 65 comments