SlideShare a Scribd company logo
1 of 57
Inferno,  Limbo  e la Dis Virtual Machine Minetti Scola Maia Alberto Davide Nicoletta
Inferno: One HOT OS ,[object Object],Il nome, come anche quello della ditta che lo produce, Vita Nuova Holdings, è stato ispirato dalle opere letterarie di Dante Alighieri, in particolare la Divina Commedia.
Inferno ,[object Object],[object Object],Plan 9 fu plasmato come il successore di Unix nei Bell Labs sotto il supporto di Dennis Ritchie.
Inferno: 3 principi di programmazione ,[object Object],[object Object],[object Object]
Inferno: scopo ,[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object]
Inferno: Tutto è un file!! ,[object Object]
Inferno: portabilità ,[object Object],[object Object],[object Object],[object Object],[object Object]
Styx ,[object Object],[object Object],[object Object],[object Object],[object Object]
Styx: operazioni ,[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],http://www.vitanuova.com/inferno/man/5/INDEX.html
Styx: connessione remota TCP ,[object Object],[object Object],[object Object],[object Object],[object Object]
Limbo ,[object Object],[object Object],[object Object],[object Object]
Limbo (2) ,[object Object],[object Object],[object Object],[object Object],[object Object]
Object Based ,[object Object],[object Object],[object Object],[object Object]
Caratterizzazione secondo Cardelli e Wegner ,[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object]
Limbo: come si presenta ,[object Object],[object Object],implement Command; include "sys.m"; sys: Sys; include "draw.m"; include "sh.m"; init(nil: ref Draw->Context, nil: list of string) { sys = load Sys Sys->PATH; sys->print("Hello World!"); } Hello World in Limbo i, j: int = 1; r, s: real = 1.0;  x: int = 1;  y := 1; #dichiaraz. e assegnaz. func(radius: int, angle: int): int proc(parameters: string) Declaration Examples in Limbo
Limbo: tipi primitivi ,[object Object],[object Object],[object Object],[object Object],[object Object],Byte (8 bit unsigned) Short word (16 bit ...) Int (32 bit signed) Short float (32 bit floating point) Big (64 bit unsigned) Real (64 bit floating point IEEE) List Array String Tuple (ordered collection of items) Channel (for inter-process communication) Adt (Abstract Data Type like a C record) Pick (discriminated union type) Module Primitive Data in Limbo
Limbo: array ,[object Object],[object Object],Slice : sub-array con un index-range e riferimento all’array originale. a : array [4] of int; a[0]=1; a[1]=2; a[2]=3; a[3]=4; slice := a[1:2]; #slice contiene [2; 3] Arrays in Limbo
Limbo: Adt ,[object Object],[object Object],[object Object],[object Object],[object Object],Riferimento a se stesso, come il this, sintassi simile al Perl Point: adt { x, y: int; add: fn (p: Point, q: Point): Point; eq: fn (p: Point, q: Point): int; }; Rect: adt { min, max: Point; contains: fn(r: self Rect, p: Point): int; }; Rect.contains(r: self Rect, p: Point){...} ... r1: Rect; p1: Point; ... if (r1.contains(p1)) ... Adt in Limbo
Limbo: tuple ,[object Object],[object Object],[object Object],Tuple with functions in Limbo Table: adt { ... lookup: fn(ht: self ref Table, name: string) : (int, string); }; Table.lookup(ht: self ref Table, name: string) : (int, string) {  ... if (tname == name) return (1, tval); return (0, ""); } nvtab = Table.alloc(101);  # make a Table nvtab.add("Rob", "Pike"); nvtab.add("Howard", "Trickey"); (p, phil) := nvtab.lookup("Phil"); (q, sean) := nvtab.lookup("Sean");
Limbo: Liste ,[object Object],[object Object],[object Object],[object Object],[object Object],sys: Sys = load Sys Sys->PATH; iCount: int = len argv; while( iCount-- > 1 ) { sys->print("%s ", hd( argv = tl argv )); } sys->print(""); List Operators in Limbo stuff: list of int; ... stuff = 30 :: (20 :: (10 :: stuff)); (head,tail) := (hd stuff, tl stuff);  :: operators in Limbo
Limbo: chan ,[object Object],[object Object],Se il canale è vuoto e si tenta di leggere il programma aspetterà finchè qualcosa non verrà inviato su quel canale. Se non ci sono riceventi e si tenta di scrivere il mittente si blocca. chan utilizzabili per sincronizzare più thread c: chan of (int, string); c  <- =  (123, “Hello!”); #scrittura (num, stringa) =  <-  c #lettura chan in Limbo
Limbo: chan particolarità L’operatore  <-   può prendere come argomento un array di canali. Limbo fornisce l’ alt  statement, la sua struttura è simile a quella di un  case . a: array [2] of chan of string; a[0] = chan of string; a[1] = chan of string; . . . ( i , s) :=  <-  a; # s has now the string from channel a[ i ] array di chan in Limbo outchan := chan of string; inchan := chan of int; ciclo: while(){ alt { i := <-inchan => if(i==0) break ciclo; sys->print(&quot;Received %d&quot;, i); outchan <- = &quot;message&quot; => sys->print(&quot;Sent the message&quot;); } } alt in Limbo
Limbo:  alt  statement Utilizzando  *  il programma non viene bloccato, se nessun canale è ready viene eseguito lo statement corrispondente a  * . Lo statement  alt  testa la possibilità di leggere o scrivere (dipende dall’operatore) su ogni canale al suo interno, se nessun canale è pronto il programma si blocca e aspetta che un canale sia pronto, poi viene scelto casualmente un canale che è ready e il controllo viene associato al suo statement. Questo statement è simile a select() e a poll() in Unix. alt { (a, b) =  <-  ch1  =>  …; (a, b, c) =  <-  ch2  =>  …; k =  <-  ch3  =>  …; * =>  …; } alt in Limbo
Chan Linda-like ,[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object]
Limbo: spawn ,[object Object],[object Object],spawn function(20, (“nuovo”, 5.2)); function(x :int, (s :string, h :real)) :void{ ... } spawn in Limbo
Limbo: module ,[object Object],[object Object],[object Object],[object Object],[object Object]
Limbo: modulo di esempio implement Tennis; include &quot;sys.m&quot;; sys: Sys; include &quot;rand.m&quot;; rand: Rand; include &quot;draw.m&quot;; Tennis: module { init: fn (nil: ref Draw->Context, argv: list of string); }; init(nil: ref Draw->Context, argv: list of string) { sys = load Sys Sys->PATH; rand = load Rand Rand->PATH; field:= chan of int; gpid := sys->pctl(Sys->NEWPGRP, nil); rand->init( sys->millisec() ); spawn opponent(field, gpid); while( 1 ) { serve(&quot;Nadal&quot;, gpid, field); receive(&quot;Nadal&quot;, gpid, field); } } serve(who: string, gpid: int, field: chan of int) { ball := rand->rand(100); sys->print(&quot;%s[%d]: servo %d&quot;, who, gpid, ball); field <-= ball; } receive(who: string, gpid: int, field: chan of int) { ball := <-field; sys->print(&quot;%s[%d] ricevo %d &quot;, who, gpid, ball); if( ball > 80 ) { sys->print(&quot;HO PERSO!&quot;); killpgroup(gpid); } sys->print(&quot;&quot;); } killpgroup(gpid: int) { sys->fprint( sys->open(&quot;/prog/&quot; + string gpid + &quot;/ctl&quot;, Sys->OWRITE), “killgrp&quot;); exit; } opponent(field: chan of int, gpid: int) { while( 1 ) { receive(&quot;Federer&quot;, gpid, field); serve(&quot;Federer&quot;, gpid, field); } } Due thread che giocano a tennis in Limbo  
Limbo: modulo Monitor # Mon.m – Interfaccia al modulo Monitor Mon: module { PATH:  con  &quot;/dis/lib/Mon.dis&quot;; Monitor: adt { create: fn(): Monitor; lock: fn(m: self Monitor); unlock: fn(m: self Monitor); ch: chan of int; }; }; # Mon.b – Implementazione del Monitor implement Mon; include &quot;Mon.m&quot;; Monitor.create(): Monitor { m := Monitor(chan of int); spawn lockproc(m.ch); return m; } Monitor.lock(m: self Monitor) { m.ch <- = 0; } Monitor.unlock(m: self Monitor) {  <- m.ch; } lockproc(ch: chan of int) { for (;;) { <- ch;  # wait for someone to lock ch <- = 0; # wait for someone to unlock } } Implementazione di un Monitor per la concorrenza in Limbo
Limbo: utilizzo del Monitor ,[object Object],Per utilizzare un modulo è necessario assegnarlo ad una variabile. include &quot;Mon.m&quot;;   mp: Mon;   Monitor: import mp; mp = load Mon Mon->PATH; l := Monitor.create(); . . . l . lock(); # region of code to be protected; # only one thread can execute here at once. l . unlock(); utilizzo del Monitor in Limbo
Limbo: Reference e Indirections ,[object Object],[object Object],L’operatore  ref  è diverso dall’operatore unario  &  di C;  ref  crea un nuovo oggetto e ritorna un handle a quest’ultimo, piuttosto che generare un handle all’oggetto esistente. Point: adt { ... }; p: Point; pp: ref Point; p = Point(1, 2); pp = ref p; # pp is a new Point; *pp has value (1, 2) p = Point(3, 4); # This makes *pp differ from p *pp = Point(4, 5); # This does not affect p Ref e * con un adt in Limbo
Limbo: approfondimento  ref Non fa quello che ci si aspetta A: adt {n: int;}; f(a: ref A){ a.n = 100; } init(){ a: A; a.n=50; f(ref a); sys->print(&quot;%d&quot;, a.n); } Questo codice  non  stampa “100”! Equivale a questo codice C: a = malloc(sizeof(A));  b = malloc(sizeof(A));  memcpy(b, a, sizeof(A));  f(b);  Questo codice è giusto A: adt {n: int;}; f(a: ref A){ a.n = 100; } init(){ a:= ref A; a.n = 50; b:= a; f(b); sys->print(&quot;%d&quot;, a.n); } Questo codice stampa “100”! Implementazione di una semplicissima bash in Limbo
Limbo:un interprete dei comandi ,[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],Implementazione di una semplicissima bash in Limbo
Limbo: librerie standard ,[object Object],[object Object],[object Object],[object Object],[object Object],[object Object]
Limbo: Codice e sintassi importazione di moduli Definizione dell’interfaccia del modulo Hello Contesto grafico command-line arguments Impl del metodo Per convenzione ogni dichiarazione di modulo include un Pathname costante che punta al codice per il modulo implement Hello; include &quot;sys.m&quot;; sys: Sys; include &quot;draw.m&quot;; Hello: module { init: fn(ctxt: ref Draw->Context, argv: list of string); }; init(ctxt: ref Draw->Context, argv: list of string) { sys = load Sys Sys->PATH; sys->print(&quot;hello, world&quot;); } File .b => “Hello World” Limbo di esempio
Limbo: Hello World grafico implement Hello2; include &quot;sys.m&quot;; sys: Sys; include &quot;draw.m&quot;; draw: Draw; include &quot;tk.m&quot;; tk: Tk; Hello2: module{ init:  fn(ctxt: ref Draw->Context, argv: list of string);}; init(ctxt: ref Draw->Context, argv: list of string){ sys = load Sys Sys->PATH; draw = load Draw Draw->PATH; tk = load Tk Tk->PATH; t := tk->toplevel(ctxt.screen, &quot;&quot;); tk->cmd(t, &quot;button .b -text {hello, world}&quot;); tk->cmd(t, &quot;pack .b&quot;); tk->cmd(t, &quot;update&quot;); sys->sleep(10000); # wait 10 seconds} File .b => “Hello World” grafico Limbo
Limbo: altri esempi ,[object Object],[object Object],[object Object],[object Object]
Conclusioni su Limbo ,[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object]
Dis Virtual Machine ,[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object]
Dis: memory-to-memory ,[object Object],[object Object],[object Object],[object Object],[object Object]
Esempio: memory-to-memory PC = 17 old_WP = 0x03 FP = 0x95 MP = 0xB0 0x1C 0x1B 0x1A 0x19 0x18 0x17 0x16 0x15 0x14 0x13 0x12 0x11 0x10 CPU 0x1C WP: PC = 86 old_WP = 0x1C FP = 0x88 MP = 0xB0 0x18 PC = 95 PC = 18 ... 17: a:= function(x, y, z); 18: ... ... 85: function(x, y, z: int): Point { 86:  if(...) ... ... 95:  return p; } Adt in Limbo WP
Dis e altre VM Caratteristiche Dis Java C# .Net Codice oggetto BYTECODE BYTECODE CLI Virtual Machine Reg-Based Stack-based Stack-based Obj-Oriented No, ma OB si si Tipi di base tanti pochi pochi Concetto thread nativo java.lang.Thread System.Threading  Carica/Scarica modulo dinamicamente si no no Garbage Collector ,[object Object],[object Object],[object Object],Scelto dall’ implementazione Mark and sweep
Dis: Garbage Collector ,[object Object],[object Object]
Dis: struttura del codice ,[object Object],[object Object],Dis: struttura della memoria Indirizzata come bytes. I dati che non occupano esattamente un multiplo di un byte vengono riepiti con padding.
Dis: indirizzamento ,[object Object],[object Object],[object Object],[object Object]
Dis: istruzioni ,[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],10(fp) indirect dal registro fp 20(mp) indirect da mp $0x123 immediate value 10(20(fp)) double indirect rispetto a fp 10(20(mp)) double indirect rispetto a mp
Dis: dimensione degli operandi La dimensione e il tipo degli operandi sono specificati dall’ultimo carattere dell’istruzione. carattere dimensione W Word (32 bit) B Byte (8 bit) F Float (64 bit) L LongInt (64 bit) P puntatore addx - Add Syntax: addb src1, src2, dst addf src1, src2, dst addw src1, src2, dst addl src1, src2, dst Function: dst = src1 + src2 Istruzione ADD in Dis
Dis: Add strings ,[object Object],[object Object],addc - Add strings Syntax: addc src1, src2, dst L’istruzione addc concatena le due stringhe Unicode puntate da src1 e src2; il risultato è puntato da dst. Istruzione di concatenamento di stringhe in Dis
Ulteriore confronto tra JVM e Dis ,[object Object],[object Object],[object Object],[object Object]
Architettura a stack ,[object Object],[object Object],[object Object],[object Object],[object Object],Somma i primi due dati nello stack e memorizza il risultato in cima allo stack o fa lo store in un’altra posizione x = a + b + c LOAD a  # push a onto stack LOAD b ADD      # pop 2 elements, add them, push the result LOAD c ADD STORE x  ADD in VM stack-based
Architettura a registri ,[object Object],[object Object],[object Object],[object Object],Somma due registri  e salva il risultato in un nuovo registro x = a + b + c ADD temp, a, b   # temp = a + b ADD x, temp, c ADD in VM register-based
VM stack-based ,[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object]
VM register-based ,[object Object],[object Object],[object Object],[object Object],[object Object]
Bytecode RB vs Bytecode SB High-level linguage: c = a + b; d = a + 4; e = b * 3; 5 variabili e 3 statement REG-BASED 1:getvar R1, &quot;a&quot; 2:getvar R2, &quot;b&quot; 3:getvar R3, &quot;c&quot; 4:getvar R4, &quot;d&quot; 5:getvar R5, &quot;e&quot; 6:add R3, R1, R2 7:add R4, R1, 4 8:mul R5, R2, 3  8 ops, 9 parameters 11:add 12:push 'd' 13:storevar 14:push 'b' 15:getvar 16:push 3 17:multiply 18:push 'e' 19:storevar  BYTECODE register-based e BYTECODE stack-based STACK-BASED 1:push 'a' 2:getvar 3:push b' 4:getvar 5:add 6:push 'c' 7:storevar 8:push 'a' 9:getvar 10:push 4 19 ops, 9 parameters
Dis: Compilazione Separata ,[object Object],[object Object],[object Object]
Dis: Elementi della symbol table Header File table PC table Adt table Fn table Data table
Conclusioni su Dis ,[object Object],[object Object],[object Object],[object Object],[object Object],[object Object]
Bibliografia ,[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object]

More Related Content

What's hot

05 2 integrali-conversioni-costanti-preproc-inclusione
05 2 integrali-conversioni-costanti-preproc-inclusione05 2 integrali-conversioni-costanti-preproc-inclusione
05 2 integrali-conversioni-costanti-preproc-inclusione
Piero Fraternali
 
[Ebook ita - security] introduzione alle tecniche di exploit - mori - ifoa ...
[Ebook   ita - security] introduzione alle tecniche di exploit - mori - ifoa ...[Ebook   ita - security] introduzione alle tecniche di exploit - mori - ifoa ...
[Ebook ita - security] introduzione alle tecniche di exploit - mori - ifoa ...
UltraUploader
 
Pe t2 perl-caratteristiche
Pe t2 perl-caratteristichePe t2 perl-caratteristiche
Pe t2 perl-caratteristiche
Majong DevJfu
 

What's hot (20)

A short introduction about traffic shaping and K-Shaper tool --- speech at Ha...
A short introduction about traffic shaping and K-Shaper tool --- speech at Ha...A short introduction about traffic shaping and K-Shaper tool --- speech at Ha...
A short introduction about traffic shaping and K-Shaper tool --- speech at Ha...
 
2006 Py03 intermedio
2006 Py03 intermedio2006 Py03 intermedio
2006 Py03 intermedio
 
2006 Py01 intro
2006 Py01 intro2006 Py01 intro
2006 Py01 intro
 
05 2 integrali-conversioni-costanti-preproc-inclusione
05 2 integrali-conversioni-costanti-preproc-inclusione05 2 integrali-conversioni-costanti-preproc-inclusione
05 2 integrali-conversioni-costanti-preproc-inclusione
 
[Ebook ita - security] introduzione alle tecniche di exploit - mori - ifoa ...
[Ebook   ita - security] introduzione alle tecniche di exploit - mori - ifoa ...[Ebook   ita - security] introduzione alle tecniche di exploit - mori - ifoa ...
[Ebook ita - security] introduzione alle tecniche di exploit - mori - ifoa ...
 
Pe t2 perl-caratteristiche
Pe t2 perl-caratteristichePe t2 perl-caratteristiche
Pe t2 perl-caratteristiche
 
Pycrashcourse
PycrashcoursePycrashcourse
Pycrashcourse
 
Programming iOS lezione 3
Programming iOS lezione 3Programming iOS lezione 3
Programming iOS lezione 3
 
Python@Unina - Theory
Python@Unina - TheoryPython@Unina - Theory
Python@Unina - Theory
 
06 3 struct
06 3 struct06 3 struct
06 3 struct
 
T3 esempio runtime
T3 esempio runtimeT3 esempio runtime
T3 esempio runtime
 
Pe t4 perl-oggetti
Pe t4 perl-oggettiPe t4 perl-oggetti
Pe t4 perl-oggetti
 
Multithreading, multiprocessing e Asincronia
Multithreading, multiprocessing e AsincroniaMultithreading, multiprocessing e Asincronia
Multithreading, multiprocessing e Asincronia
 
05 1 intro-struttura
05 1 intro-struttura05 1 intro-struttura
05 1 intro-struttura
 
T7 librerie
T7 librerieT7 librerie
T7 librerie
 
Pe t1 perl-intro
Pe t1 perl-introPe t1 perl-intro
Pe t1 perl-intro
 
Programmazione funzionale e Stream in Java
Programmazione funzionale e Stream in JavaProgrammazione funzionale e Stream in Java
Programmazione funzionale e Stream in Java
 
11 I File
11   I File11   I File
11 I File
 
Spyppolare o non spyppolare
Spyppolare o non spyppolareSpyppolare o non spyppolare
Spyppolare o non spyppolare
 
Pe t3 perl-moduli
Pe t3 perl-moduliPe t3 perl-moduli
Pe t3 perl-moduli
 

Viewers also liked

Использование специальных типов данных PostgreSQL в ORM Doctrine
Использование специальных типов данных PostgreSQL в ORM DoctrineИспользование специальных типов данных PostgreSQL в ORM Doctrine
Использование специальных типов данных PostgreSQL в ORM Doctrine
Alexander Korotkov
 

Viewers also liked (9)

Minetti master thesis
Minetti master thesisMinetti master thesis
Minetti master thesis
 
Telegraph Cq Italian
Telegraph Cq ItalianTelegraph Cq Italian
Telegraph Cq Italian
 
Index for meshes 3d
Index for meshes 3dIndex for meshes 3d
Index for meshes 3d
 
Moodle for teachers
Moodle for teachersMoodle for teachers
Moodle for teachers
 
R programming language
R programming languageR programming language
R programming language
 
Index for meshes 2d
Index for meshes 2dIndex for meshes 2d
Index for meshes 2d
 
Development and analysis of a virtual keyboard optimized (Italian)
Development and analysis of a virtual keyboard optimized (Italian)Development and analysis of a virtual keyboard optimized (Italian)
Development and analysis of a virtual keyboard optimized (Italian)
 
Использование специальных типов данных PostgreSQL в ORM Doctrine
Использование специальных типов данных PostgreSQL в ORM DoctrineИспользование специальных типов данных PostgreSQL в ORM Doctrine
Использование специальных типов данных PostgreSQL в ORM Doctrine
 
Gnutella Italian Printable
Gnutella Italian PrintableGnutella Italian Printable
Gnutella Italian Printable
 

Similar to Inferno Limbo Italian

Sistema operativo Unix e Linux
Sistema operativo Unix e LinuxSistema operativo Unix e Linux
Sistema operativo Unix e Linux
Giulia Shkreli
 
Pycrashcourse3.1
Pycrashcourse3.1Pycrashcourse3.1
Pycrashcourse3.1
rik0
 
Pycrashcourse3.0
Pycrashcourse3.0Pycrashcourse3.0
Pycrashcourse3.0
rik0
 
Esercitazione 1 (27 febbraio 2012)
Esercitazione 1 (27 febbraio 2012)Esercitazione 1 (27 febbraio 2012)
Esercitazione 1 (27 febbraio 2012)
STELITANO
 
LinuxDay 2004 - Linux - Storia e caratteristiche vincenti - slides
LinuxDay 2004 - Linux - Storia e caratteristiche vincenti - slidesLinuxDay 2004 - Linux - Storia e caratteristiche vincenti - slides
LinuxDay 2004 - Linux - Storia e caratteristiche vincenti - slides
Maurizio Antonelli
 

Similar to Inferno Limbo Italian (20)

GNU Linux introduction
GNU Linux introductionGNU Linux introduction
GNU Linux introduction
 
Corso c++
Corso c++Corso c++
Corso c++
 
Presentazione Oz - Mozart
Presentazione Oz - MozartPresentazione Oz - Mozart
Presentazione Oz - Mozart
 
Sistema operativo Unix e Linux
Sistema operativo Unix e LinuxSistema operativo Unix e Linux
Sistema operativo Unix e Linux
 
Pycrashcourse3.1
Pycrashcourse3.1Pycrashcourse3.1
Pycrashcourse3.1
 
Modulo 1 - Lezione 1
Modulo 1 - Lezione 1Modulo 1 - Lezione 1
Modulo 1 - Lezione 1
 
GNU Linux Programming introduction
GNU Linux Programming introductionGNU Linux Programming introduction
GNU Linux Programming introduction
 
Pycrashcourse3.0
Pycrashcourse3.0Pycrashcourse3.0
Pycrashcourse3.0
 
Rest sdk
Rest sdkRest sdk
Rest sdk
 
Bash intro
Bash introBash intro
Bash intro
 
Linux@Unina
Linux@UninaLinux@Unina
Linux@Unina
 
Dot net framework 2
Dot net framework 2Dot net framework 2
Dot net framework 2
 
Vb.Net
Vb.NetVb.Net
Vb.Net
 
Bash programming
Bash programmingBash programming
Bash programming
 
Tools & librerie PHP
Tools & librerie PHPTools & librerie PHP
Tools & librerie PHP
 
Packet Sniffing
Packet SniffingPacket Sniffing
Packet Sniffing
 
Esercitazione 1 (27 febbraio 2012)
Esercitazione 1 (27 febbraio 2012)Esercitazione 1 (27 febbraio 2012)
Esercitazione 1 (27 febbraio 2012)
 
Presentazione java7
Presentazione java7Presentazione java7
Presentazione java7
 
Coding class da scratch a python
Coding class  da scratch a pythonCoding class  da scratch a python
Coding class da scratch a python
 
LinuxDay 2004 - Linux - Storia e caratteristiche vincenti - slides
LinuxDay 2004 - Linux - Storia e caratteristiche vincenti - slidesLinuxDay 2004 - Linux - Storia e caratteristiche vincenti - slides
LinuxDay 2004 - Linux - Storia e caratteristiche vincenti - slides
 

Inferno Limbo Italian

  • 1. Inferno, Limbo e la Dis Virtual Machine Minetti Scola Maia Alberto Davide Nicoletta
  • 2.
  • 3.
  • 4.
  • 5.
  • 6.
  • 7.
  • 8.
  • 9.
  • 10.
  • 11.
  • 12.
  • 13.
  • 14.
  • 15.
  • 16.
  • 17.
  • 18.
  • 19.
  • 20.
  • 21.
  • 22. Limbo: chan particolarità L’operatore <- può prendere come argomento un array di canali. Limbo fornisce l’ alt statement, la sua struttura è simile a quella di un case . a: array [2] of chan of string; a[0] = chan of string; a[1] = chan of string; . . . ( i , s) := <- a; # s has now the string from channel a[ i ] array di chan in Limbo outchan := chan of string; inchan := chan of int; ciclo: while(){ alt { i := <-inchan => if(i==0) break ciclo; sys->print(&quot;Received %d&quot;, i); outchan <- = &quot;message&quot; => sys->print(&quot;Sent the message&quot;); } } alt in Limbo
  • 23. Limbo: alt statement Utilizzando * il programma non viene bloccato, se nessun canale è ready viene eseguito lo statement corrispondente a * . Lo statement alt testa la possibilità di leggere o scrivere (dipende dall’operatore) su ogni canale al suo interno, se nessun canale è pronto il programma si blocca e aspetta che un canale sia pronto, poi viene scelto casualmente un canale che è ready e il controllo viene associato al suo statement. Questo statement è simile a select() e a poll() in Unix. alt { (a, b) = <- ch1 => …; (a, b, c) = <- ch2 => …; k = <- ch3 => …; * => …; } alt in Limbo
  • 24.
  • 25.
  • 26.
  • 27. Limbo: modulo di esempio implement Tennis; include &quot;sys.m&quot;; sys: Sys; include &quot;rand.m&quot;; rand: Rand; include &quot;draw.m&quot;; Tennis: module { init: fn (nil: ref Draw->Context, argv: list of string); }; init(nil: ref Draw->Context, argv: list of string) { sys = load Sys Sys->PATH; rand = load Rand Rand->PATH; field:= chan of int; gpid := sys->pctl(Sys->NEWPGRP, nil); rand->init( sys->millisec() ); spawn opponent(field, gpid); while( 1 ) { serve(&quot;Nadal&quot;, gpid, field); receive(&quot;Nadal&quot;, gpid, field); } } serve(who: string, gpid: int, field: chan of int) { ball := rand->rand(100); sys->print(&quot;%s[%d]: servo %d&quot;, who, gpid, ball); field <-= ball; } receive(who: string, gpid: int, field: chan of int) { ball := <-field; sys->print(&quot;%s[%d] ricevo %d &quot;, who, gpid, ball); if( ball > 80 ) { sys->print(&quot;HO PERSO!&quot;); killpgroup(gpid); } sys->print(&quot;&quot;); } killpgroup(gpid: int) { sys->fprint( sys->open(&quot;/prog/&quot; + string gpid + &quot;/ctl&quot;, Sys->OWRITE), “killgrp&quot;); exit; } opponent(field: chan of int, gpid: int) { while( 1 ) { receive(&quot;Federer&quot;, gpid, field); serve(&quot;Federer&quot;, gpid, field); } } Due thread che giocano a tennis in Limbo 
  • 28. Limbo: modulo Monitor # Mon.m – Interfaccia al modulo Monitor Mon: module { PATH: con &quot;/dis/lib/Mon.dis&quot;; Monitor: adt { create: fn(): Monitor; lock: fn(m: self Monitor); unlock: fn(m: self Monitor); ch: chan of int; }; }; # Mon.b – Implementazione del Monitor implement Mon; include &quot;Mon.m&quot;; Monitor.create(): Monitor { m := Monitor(chan of int); spawn lockproc(m.ch); return m; } Monitor.lock(m: self Monitor) { m.ch <- = 0; } Monitor.unlock(m: self Monitor) { <- m.ch; } lockproc(ch: chan of int) { for (;;) { <- ch; # wait for someone to lock ch <- = 0; # wait for someone to unlock } } Implementazione di un Monitor per la concorrenza in Limbo
  • 29.
  • 30.
  • 31. Limbo: approfondimento ref Non fa quello che ci si aspetta A: adt {n: int;}; f(a: ref A){ a.n = 100; } init(){ a: A; a.n=50; f(ref a); sys->print(&quot;%d&quot;, a.n); } Questo codice non stampa “100”! Equivale a questo codice C: a = malloc(sizeof(A)); b = malloc(sizeof(A)); memcpy(b, a, sizeof(A)); f(b); Questo codice è giusto A: adt {n: int;}; f(a: ref A){ a.n = 100; } init(){ a:= ref A; a.n = 50; b:= a; f(b); sys->print(&quot;%d&quot;, a.n); } Questo codice stampa “100”! Implementazione di una semplicissima bash in Limbo
  • 32.
  • 33.
  • 34. Limbo: Codice e sintassi importazione di moduli Definizione dell’interfaccia del modulo Hello Contesto grafico command-line arguments Impl del metodo Per convenzione ogni dichiarazione di modulo include un Pathname costante che punta al codice per il modulo implement Hello; include &quot;sys.m&quot;; sys: Sys; include &quot;draw.m&quot;; Hello: module { init: fn(ctxt: ref Draw->Context, argv: list of string); }; init(ctxt: ref Draw->Context, argv: list of string) { sys = load Sys Sys->PATH; sys->print(&quot;hello, world&quot;); } File .b => “Hello World” Limbo di esempio
  • 35. Limbo: Hello World grafico implement Hello2; include &quot;sys.m&quot;; sys: Sys; include &quot;draw.m&quot;; draw: Draw; include &quot;tk.m&quot;; tk: Tk; Hello2: module{ init: fn(ctxt: ref Draw->Context, argv: list of string);}; init(ctxt: ref Draw->Context, argv: list of string){ sys = load Sys Sys->PATH; draw = load Draw Draw->PATH; tk = load Tk Tk->PATH; t := tk->toplevel(ctxt.screen, &quot;&quot;); tk->cmd(t, &quot;button .b -text {hello, world}&quot;); tk->cmd(t, &quot;pack .b&quot;); tk->cmd(t, &quot;update&quot;); sys->sleep(10000); # wait 10 seconds} File .b => “Hello World” grafico Limbo
  • 36.
  • 37.
  • 38.
  • 39.
  • 40. Esempio: memory-to-memory PC = 17 old_WP = 0x03 FP = 0x95 MP = 0xB0 0x1C 0x1B 0x1A 0x19 0x18 0x17 0x16 0x15 0x14 0x13 0x12 0x11 0x10 CPU 0x1C WP: PC = 86 old_WP = 0x1C FP = 0x88 MP = 0xB0 0x18 PC = 95 PC = 18 ... 17: a:= function(x, y, z); 18: ... ... 85: function(x, y, z: int): Point { 86: if(...) ... ... 95: return p; } Adt in Limbo WP
  • 41.
  • 42.
  • 43.
  • 44.
  • 45.
  • 46. Dis: dimensione degli operandi La dimensione e il tipo degli operandi sono specificati dall’ultimo carattere dell’istruzione. carattere dimensione W Word (32 bit) B Byte (8 bit) F Float (64 bit) L LongInt (64 bit) P puntatore addx - Add Syntax: addb src1, src2, dst addf src1, src2, dst addw src1, src2, dst addl src1, src2, dst Function: dst = src1 + src2 Istruzione ADD in Dis
  • 47.
  • 48.
  • 49.
  • 50.
  • 51.
  • 52.
  • 53. Bytecode RB vs Bytecode SB High-level linguage: c = a + b; d = a + 4; e = b * 3; 5 variabili e 3 statement REG-BASED 1:getvar R1, &quot;a&quot; 2:getvar R2, &quot;b&quot; 3:getvar R3, &quot;c&quot; 4:getvar R4, &quot;d&quot; 5:getvar R5, &quot;e&quot; 6:add R3, R1, R2 7:add R4, R1, 4 8:mul R5, R2, 3 8 ops, 9 parameters 11:add 12:push 'd' 13:storevar 14:push 'b' 15:getvar 16:push 3 17:multiply 18:push 'e' 19:storevar BYTECODE register-based e BYTECODE stack-based STACK-BASED 1:push 'a' 2:getvar 3:push b' 4:getvar 5:add 6:push 'c' 7:storevar 8:push 'a' 9:getvar 10:push 4 19 ops, 9 parameters
  • 54.
  • 55. Dis: Elementi della symbol table Header File table PC table Adt table Fn table Data table
  • 56.
  • 57.