Declarative Objects

Post on 03-Jan-2016

50 views 0 download

description

Declarative Objects. 7/22/10 Jonathan Edwards sdg csail MIT. CMP AX,[BX] JE SKIP MOV AX,2. class Task { int start ; int end ;. class Task { int start; int end; int length { get {return end - start;} set {end = start + value;} }. class Task { int start; - PowerPoint PPT Presentation

Transcript of Declarative Objects

Declarative Objects

7/22/10Jonathan Edwards

sdg csail MIT

CMP AX,[BX]JE SKIPMOV AX,2

class Task { int start; int end;

class Task { int start; int end; int length { get {return end - start;} set {end = start + value;} }

class Task { int start; int end; int length { get {return end - start;} set {end = start + value;} } // start after t, increment length void slipAfter(Task t) {

class Task { int start; int end; int length { get {return end - start;} set {end = start + value;} } // start after t, increment length void slipAfter(Task t) { start = t.end; length = length + 1; }}

class Task { int start; int end; int length { get {return end - start;} set {end = start + value;} } // start after t, increment length void slipAfter(Task t) { start = t.end; length = length + 1; }}

class Task { int start; int end; int length { get {return end - start;} set {end = start + value;} } // start after t, increment length void slipAfter(Task t) { length = length + 1; start = t.end; }}

class Task { int start; int end; int length { get {return end - start;} set {end = start + value;} } // start after t, increment length void slipAfter(Task t) { int oldLength = length; start = t.end; length = oldLength + 1; }}

class Task { int start { get {return end - length;} set {end = value + length;} } int end; int length; // start after t, increment length void slipAfter(Task t) { length = length + 1; start = t.end; }}

?class Task { int start; int end; int length { get {return end - start;} set {end = start + value;} } void slipAfter(Task t) { int oldLength = length; start = t.end; length = oldLength + 1; }}

Pac-Man

!

pre-state post-state

length

startend

+ 1–get

length

startend + set

length

startend

t

thisthis

#1 #2

#3

#4

Task = obj { start: int end: int length ::= end – start length trig { end <= start + length} slipAfter = act { t: Task start <= t.end length <= \length + 1}}

Task = obj { start: int end: int length ::= end – start length trig { end <= start + length} slipAfter = act { t: Task start <= t.end length <= \length + 1}}

#1

#4

#3#2

Compiler

1. \length := end – start

2. length := \length + 13. start := t.end 4. end := start + length

what how

Declarative Programming

Compiler

what how

Compiler

Parallel Processing

what how

Compiler

Distributed Processing

Pointers

pre-state post-state

length

startend

+ 1–get

length

startend + set

length

startend

t

thisthis

pre-state post-state

length

startend

+ 1–get

length

startend + set

length

startend

t

thisthis

t == this

pre-state post-state

length

startend

+ 1–get

length

startend + set

length

startend

t

thisthis

t == this

Huh?

pointers ⇒ undecidable dataflow

Compiler

Pick two

Declarativeprogramming

Data structures

Mutablestate

CircuitsFunctions

Imperativeprogramming

Nesting & Binding

Model-View dataflow

Project = obj { task1: Task task2: Task }

length

startend

Task

task1task2

Project

length

startend

Task

Project = obj { task1: Task task2: Task }

Project

length

startend

length

startend

task2

task1

Project = obj { task1: Task task2: Task task2.start ::=> task1.end }

Project

length

startend

length

startend

task2

task1

bidirectional binding

tasks

length

@3F25Cstartend

length

startend

@5E820

tasks: dom Task

tasks

length

task1startend

length

@3F25Cstartend

length

startend

@5E820

tasks: dom Tasktask1 => tasks

cursorquantified binding

tasks

length

task1startend

length

@3F25Cstartend

length

startend

@5E820

tasks: dom Tasktask1 => taskstask2 => tasks

task2startend

length

tasks

length

task1startend

length

@3F25Cstartend

length

startend

@5E820

tasks: dom Tasktask1 => taskstask2 => taskstask2.slipAfter(task1)

task2start

+endlength

tasks

length

task1startend

length

@3F25Cstartend

length

startend

@5E820

tasks: dom Tasktask1 => taskstask2 => taskstask2.slipAfter(task1)

task2start

+end

length

length

task1startend

length

startend

@5E820 task2startend

length

length

task1startend

length

startend

@5E820 task2start

+endlength

User

Model

DB

queryupdate

getset

outputinput

View

Model-View dataflow

internal state

external world

•outputs•getters•queries

•inputs•setters•triggers

Model-View dataflow

internal state

external world✘

•outputs•getters•queries

•inputs•setters•triggers

Model-View dataflow

internal state

external world

•functional•lazy

•mutating•eager

Model-View dataflow

internal state

external world

•functional•lazy

•mutating•eager•callbacks•events

✘✘

New rules, new patterns

• Synchronous reactive programming– Input event triggers atomic state transition– Output is pure function of new state– Asynchronicity layered on top

• Syntax order irrelevant – no control flow • Pre-state readable throughout transition• Fields can change once per transition• Actions can’t see effects of own changes

prog { t +=> task1 t.slipAfter(task2) step \t.end ?gtr 10 t.end <= 10}

progressive binding

stepguard result of prev step

Progression

step

length

startend

length

startend

length

startend

length

startend

+ 1+ gtr 10 10

prog

length

startend

task1 task1

task2

t t?

pre-state post-state

✘✘

length

startend

length

startend

length

startend

length

startend

+ 1+ gtr 10 10

hyp

length

startend

task1 task1

task2

t t?

pre-state post-state

Technical Summary• Nesting gives objects a location in global tree• Bindings propagate changes through relative

paths in tree (precise static effects)• Bindings are directed: input, output, or both– Input is change-driven, cascades eagerly– Output is lazy pure functional– Each is statically acyclic based on tree path effects– Outputs do not feedback to inputs

• Imperative islands in a declarative sea

Pick two

Declarativeprogramming

Data structures

Mutablestate

Declarative Objects

Declarativeprogramming

Nesting & Binding

Model-Viewdataflow

CMP AX,[BX]JE SKIPMOV AX,2

Imperative Programming

Declarative Programming