flat assembler
Message board for the users of flat assembler.

Index > High Level Languages > Compiler for Drive language with prefix syntax

Author
Thread Post new topic Reply to topic
DSblizzard



Joined: 23 Oct 2019
Posts: 15
Location: Ryazan, Russia
DSblizzard 11 Dec 2019, 10:05
Language currently have almost no advantages except clean design ( and compilation to fasm Smile ).

Features and limitations:

Dynamic typing.

Uniform prefix syntax. Example:
Code:
(def [compile_logic_op stmt_box fn_name] [
  (= stmt (get_val stmt_box))
  (if (== fn_name "not") [
    (compile_arg (elt stmt 1))
    (emit "mov rdi, [rax + IntValOffset]")
    (emit "btc rdi, 0")
    (emit_val_to_header "int")
  ] 1 [
    (for arg_pos in (.. 1 (len stmt)) [
      (compile_arg (elt stmt arg_pos))
    ])
    (emit (+ "mov r10, " (str (- (len stmt) 1))))
    (emit_call (with_prefix fn_name))
  ])
])
    

String nesting with increasing length not as 2^n but as n*log(n). Example:
C, level 0: "\""
Drive, level 0: '"""' or 0"""0
C, level 1: "\"\\\"\""
Drive, level 1: ''"'"""'"'' or 1"0"""0"1
C, level 2: "\"\\\"\\\\\\\"\\\"\""
Drive, level 2: '''"''"'"""'"''"''' or 2"1"0"""0"1"2
Instead of ' characters or numbers can be almost any sequences of symbols. Strings without escape symbols can be unconvenient sometimes, but there is (chr) function for getting special characters in Drive.

Minimalistic uniform ways to modify lists and strings. There is (set_sub) instead of "insert", "delete" and "append". Currently (set_sub) is implemented only for lists.
Code:
(= l [1 2 3])
(set_sub l [4 5] 1 2)
(print l) # [1 4 5 3]
(set_sub l [] 0 2)
(print l) # [5 3]
    


Arguments are passed by reference. Therefore there will be no separate getters and setters with duplication of code, no boxing of ints.

Main data structure is list implemented as dynamic array with unmovable header, pointing to expandable array of pointers to "joints" which in turn point to headers for actual elements. So there is many levels of indirection, but passing by reference with simple implementation and intuitive rules cannot be made simpler - I tried.

Pretty weak handling of input errors and no exception catching, only throwing.

Tracing garbage collector.

(if) with multiple branches.

No command line flags, input file is "in.dr.txt". This file and included should have new lines consisting of single character with ASCII code 10.

Parser + interpreter + python to drive compiler + drive to fasm compiler were implemented in 2 months of free time. Performance of compiled programs is similar to performance of CPython programs. Drive compiles itself (3300 lines total) in 3.26 seconds and produces 124 kloc of assembly output. (Previous numbers were for version with debugging turned on). Drive is written in itself, first version was interpreted (source in Python).


Description: Drive compiler
Download
Filename: Drive.rar
Filesize: 736.11 KB
Downloaded: 885 Time(s)



Last edited by DSblizzard on 11 Dec 2019, 14:40; edited 6 times in total
Post 11 Dec 2019, 10:05
View user's profile Send private message Reply with quote
redsock



Joined: 09 Oct 2009
Posts: 435
Location: Australia
redsock 11 Dec 2019, 10:08
Just a quick comment, your example code not being formatted inside [ code ] ... [ /code ] tags realy makes it hard to read... is there any indenting to that or coding style that makes it easier to read?

Edit: Lol, either you edited it or someone helped you Smile much better thanks
Post 11 Dec 2019, 10:08
View user's profile Send private message Reply with quote
Display posts from previous:
Post new topic Reply to topic

Jump to:  


< Last Thread | Next Thread >
Forum Rules:
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum
You cannot attach files in this forum
You can download files in this forum


Copyright © 1999-2025, Tomasz Grysztar. Also on GitHub, YouTube.

Website powered by rwasa.