this is a very good blog post՝ back to basics about strings in C and Pascal. i suggest you to read it, and now i’ll tell you something else:
in Oberon, Wirth decided to give up on Pascal strings, and use zero terminated strings.
however, there is no need to run by the whole array to find out the length of the string. we don’t even need to have a separate field that holds the length՝ compiler knows the length of the static string.
thus it can do compile time tests. for example we have the following Oberon source՝
MODULE tst;
IMPORT Out;
VAR i: SHORTINT;
str: ARRAY 1024 OF CHAR;
BEGIN
FOR i := 0 TO LEN(str) DO
Out.Int(i, 0); Out.Ln
END;
END tst.
lets try to compile it՝
[2020-09-02 16:00:20] $ voc -m tst.Mod
tst.Mod Compiling tst.
9: FOR i := 0 TO LEN(str) DO
^
pos 102 err 113 incompatible assignment
Module compilation failed.
[2020-09-02 16:00:21] $
voc compiles Oberon source to C, which is very good to illustrate what happens. if we have՝
str: ARRAY 16 OF CHAR;
then the output C code will be՝
static CHAR tst_str[16];
nothing more։ no field for the length.
still, this՝
FOR i := 0 TO LEN(str) DO
will translate to՝
tst_i = 0;
while (tst_i <= 16) {
as i said we know the length at compile time. doesn’t matter if you generate C or assembly, you already know the number, you can put the number to the output assembly code as well.
when we write a function which receives strings, we should not knowt the length of the received string, we just use ARRAY OF CHAR
as an argument՝
MODULE tst2;
PROCEDURE addStrs(VAR a, b: ARRAY OF CHAR);
BEGIN
(* do smth useful here *)
END addStrs;
PROCEDURE test*;
VAR
s0: ARRAY 32 OF CHAR;
s1: ARRAY 64 OF CHAR;
BEGIN
addStrs(s0, s1);
END test;
END tst2.
therefore C code will be՝
static void tst2_addStrs (CHAR *a, ADDRESS a__len, CHAR *b, ADDRESS b__len)
{
/* here we think we can do smth useful */
}
void tst2_test (void)
{
CHAR s0[32];
CHAR s1[64];
tst2_addStrs((void*)s0, 32, (void*)s1, 64);
}
as we see՝ the function also gets the length of strings. and if we do LEN(a)
we get the length without any calculations.
now let’s see how dynamic strings work՝
MODULE tst3;
PROCEDURE addStrs(VAR a, b: ARRAY OF CHAR);
BEGIN
(* do smth useful here *)
END addStrs;
PROCEDURE test*(i: INTEGER);
VAR
s: ARRAY 32 OF CHAR;
ps: POINTER TO ARRAY OF CHAR;
BEGIN
NEW(ps, i);
addStrs(s, ps^);
END test;
END tst3.
now we hase a static string՝ s and we allocate a dynamic string with its pointer ps
.
lets assume we don’t know the size of ps^
string (^
means dereference) and we will receive the length of the allocated string as a function argument. it is not known at compile time.
first function remains unchanged, second function gets translated like this՝
static void tst3_addStrs (CHAR *a, ADDRESS a__len, CHAR *b, ADDRESS b__len)
{
/* do smth useful here */
}
void tst3_test (INT16 i)
{
CHAR s[32];
struct {
ADDRESS len[1];
CHAR data[1];
} *ps = NIL;
ps = __NEWARR(NIL, 1, 1, 1, 1, ((ADDRESS)(i)));
tst3_addStrs((void*)s, 32, (void*)ps->data, ps->len[0]);
}
the _NEWARR
is a bit more complicated function, which is a part of the runtime.
but we can understand what it does՝ it allocates a space in the heap, and the pointer ps
we get now points to the struct
, which has a data
field and len
field.
this is a runtime information, and in this case we have to keep a separate field for the length of the string.
that’s it.
#oberon #c #pascal #wirth #programming #programming-languages #programming_languages #design #implementation #vishap #voc #compiler #compilation #strings #string #heap #stack #storage #storage-management #storage_management #length
build your own lisp - very good book online http://www.buildyourownlisp.com/ #programming #compiler #lisp #book
very interesting discussion for me https://github.com/modula3/cm3/issues/12
What do you think about implementing properties in Objects?
OBJECT
...
PROPERTIES
intValue : INTEGER READ GetIntValue() WRITE SetIntValue();
I wouldn’t mind adding some things like this as long as they are very obviously simple syntactic sugar for existing operations. This looks like something like that…
shouldn’t it be, though
PROPERTIES
intValue : INTEGER
READ := GetIntValue() : INTEGER
WRITE := SetIntValue(to : INTEGER);
to more closely match the syntax for methods.
Also it won’t work on RECORDs, which is a bit odd.
I suppose it follows the existing property (which I would not want to break) that you can almost always change a T = REF RECORD … to T = OBJECT … without breaking anything, but not the other way around.
#modula #programming #programming_languages #modula-3 #cm3 #modula3 #compiler
amazing story on how he wrote a C compiler in 40 days: http://www.sigbus.info/how-i-wrote-a-self-hosting-c-compiler-in-40-days.html
#compiler #programming #programming_languages #language
I have managed to port Wirth’s PICL language compiler (which generates code for PIC16F84) to GNU/Linux(used voc to compile it), I mean, it’s possible to run it, compile sample programs with it on my desktop. Now need to make some more improvements and write a manual so that people can use it.
#pic #pic16f84 #embedded #embedded_programming #programming #screenshot #compiler #wirth #picl #programming_languages #hardware #hardware_programming #oberon
very interesting resource for those who are interested in compilers: http://turbopascal.org/turbo-pascal-internals
#internals #compiler #source #code #programming #compilers #pascal #turbo_pascal #book #analysis #reverse_engineering #research
This page refers to some technologies as “computer science fiction”. Among them to Oberon. This brings another meaning to Vishap oberon compiler. Oberon is like aliens, ghosts. And Vishaps.
#computer_science_fiction #fiction #cs #computer_science #vishap #aliens #ghosts #vishaps #dragon #dragons #compiler #oberon #oberon-2 #compilers #technologies
The Performance Cost of Integer Overflow Checking http://danluu.com/integer-overflow/
#overflow #check #compiler
this competition demonstrates that their compiler generates poor code for loops http://www.astrobe.com/forum/viewtopic.php?f=4&t=448
#compiler #oberon #competition
improved a little bit and added readme
https://github.com/norayr/rrro
#oberon #risc #compiler
Running 4 copies of an operating system at once
Dick explained to me that they were using an operating system from a company called Telesoft. Telesoft, headed by UCSD Pascal author Ken Bowles, was building an Ada compiler on top of its ROS (Renaissance Operating System) product. He told me (and I remember this clearly) that they had the operating system running in single user mode but that they wanted to run it in multi-user mode. At that point I was barely 21 years old. I had written a whole bunch of system-level 6502 assembler code and I had a really good ground-up understanding of the way that contemporary computer hardware worked. After studying the manual for the SUN board, I decided that I could simply break the 2MB of physical memory in to 4 chunks of 512KB each and run 4 copies of the operating system, gaining control via interrupts and device drivers.
#6502 #telesoft #pascal #ada #operating-systems #ucsd-pascal #compiler #ros #renaissance-operating-system #programming #history #computing #programming-languages #sun #intellimac #unix #msx #motorola68000 #68000 #68k #motorola-68k #ibm #stanford #research #memory
պատահաբար հանդիպեցի՝ http://listarc.com/showthread.php?5356219-FPGA+toolchain+again. (:
#oberon #voc #vishap #feedback #compiler
վիշապ օբերոն կոմպիլյատորի մակոսի պորտը նոր աւարտեցի։ ։Ճ
i’ve just finished macosx port of vishap oberon compiler
#oberon #voc #vishap #compiler #macosx #programming
New edition of Wirth’s book Project Oberon is out. It describes not only built from scratch software(entire operating system and compiler), but design of the hardware as well.
The vast complexity of popular operating systems makes them not only obscure, but also provides opportunities for “back doors”. They allow external agents to introduce spies and devils unnoticed by the user, making the system attackable and corruptible. The only safe remedy is to build a safe system anew from scratch.
http://www.inf.ethz.ch/personal/wirth/ProjectOberon/index.html
#oberon #wirth #niklaus-wirth #risc #programming #fpga #books #programming-languages #compilers #operating-systems #compiler #freedom #design #security #privacy #surveillance #reliability
http://www.youtube.com/watch?v=Wn32zePbFpc
Statically Recompiling #NES #Games into Native Executables with #LLVM and #Go
#compiler #retro #6502 #nintendo #mario #zelda #fun #emulation #jamulator #rom #programming
https://github.com/norayr/voc/commit/a3214b81549d7c1d4654c62af52514261ed08ed0
different modules can be now compiled into one elf at once (no separate linking command needed). for example, if M0 imports M1 then
voc -l M1.Mod -s M0.Mod -M
where -l is a global option (show line numbers, I don’t use it, I need only position, and do :goto in vim to get it)
-s means generate symbol file, we need it to compile M0, and check types throughout module boundaries
-M means generate main module and link it statically to libVishapOberon.
#voc #vishap-oberon #oberon #oberon-2 #compiler #linking #programming
I have published Vishap Oberon compiler
#vishap #voc #oberon #oberon-2 #compiler #ofront #pascal #modula-2 #fork #github #compilers #վիշապ #օբերոն #կոմպիլյատոր #պասկալ #մոդուլա֊2 #ծրագրավորում
when I read about new cool project built with #raspberry-pi I think - okay - they didn’t do any low level #programming. They used #python, and they have all those #drivers ready to use. If it is considered a tool for #children - then what will they learn, they couldn’t learn by using a #GNU/Linux pc?
That’s why when I read about cheap #Linux boards I afraid that #8bit #microcontrollers won’t be used and thus less and less people would tinker with low level staff. And if they don’t deal with it, they don’t have deep understanding of how it works.
That’s why I appreciate #Arduino, and I hope it won’t be ousted from #market. Actually, that language and #compiler which comes with Arduino is too lame. I never programmed #AVR with that language, I used gcc, and thus Arduino + #gcc is a good #toy for a child. I agree. But I am not so sure about #raspberrypi
An Introduction to #GCC #Compiler #Intrinsics in #Vector Processing http://www.linuxjournal.com/content/introduction-gcc-compiler-intrinsics-vector-processing?page=0,0