Circline -- An Easy Graph Language Haikuo Liu Jia zhang Qing Lan - - PowerPoint PPT Presentation

circline an easy graph language
SMART_READER_LITE
LIVE PREVIEW

Circline -- An Easy Graph Language Haikuo Liu Jia zhang Qing Lan - - PowerPoint PPT Presentation

Circline -- An Easy Graph Language Haikuo Liu Jia zhang Qing Lan Zehao Song Language Summary Basic: Integer, Floating Point 64 bit, Boolean, String, Null Data Structure: List, Dict, Node, Graph Operations: Arithmetic Operation, Logic


slide-1
SLIDE 1

Circline -- An Easy Graph Language

Haikuo Liu Jia zhang Qing Lan Zehao Song

slide-2
SLIDE 2

Language Summary

Basic: Integer, Floating Point 64 bit, Boolean, String, Null Data Structure: List, Dict, Node, Graph Operations: Arithmetic Operation, Logic Operation, Conditional Operation, Graph Operation

slide-3
SLIDE 3

Language Feature

  • Native Support on Node, Edge and Graph Definition & Operation
  • Function and variables declared everywhere, Support nested function
  • Support List, Hashmap basic Data structure

Circle + Line =

slide-4
SLIDE 4

Node & Graph - Merge Graph

node a = node(“a”); graph g1 = a -> b -> c; graph g2 = c -> [d, e]; graph gh = g1 + g2;

a b c d e c

+

a -> b -> c a -> (b -> c) c -> [d, e]

slide-5
SLIDE 5

Node & Graph - Merge Graph

node a = node(“a”); graph g1 = a -> b -> c; graph g2 = c -> [d, e]; graph gh = g1 + g2;

a b c d e

a -> b -> c -> [d, e]

slide-6
SLIDE 6

Node & Graph - Graph Subtraction

a b c d e

a -> b -> c

  • > [d -> e, e]

c d e

c -> [d, e]

  • =

a b c d e

list<graph>

  • =
slide-7
SLIDE 7

Node & Graph - Node Removal

a b c d e

a -> b -> c

  • > [d -> e, e]

c

  • =

a b d e

list<graph> c

  • =
slide-8
SLIDE 8

Node & Graph - Neighbors

gh @ a => [ b ] gh @ b => [c, d, e] gh @ c => []

b c e d

graph gh = a -> b -> [c, d, e]

a

slide-9
SLIDE 9

Node & Graph - Edge Value

gh @ (a, b) => 1 gh @ (b, a) => null gh @ (b, d) => 3

b c e 4 d 3 2 a 1

graph gh = a -> 1&b -> [2&c, 3&d, 4&e] graph gh = a -> 1&b -> [2,3,4]& [c,d,e]

slide-10
SLIDE 10

List

list<int> li = [ 1, 2, 3]; ❖ Array ➢ get() ➢ set() ❖ Queue ➢ add() ➢ remove() ❖ Stack ➢ push() ➢ pop() list<float> lf = [1, 1.2, 3]; list<graph> lg = [a, a -> b];

Auto Conversion

slide-11
SLIDE 11

Dict

node a = node("a"); node b = node("b"); dict<node> set = { a: a }; set.has(a) => true set.get(b) => false set.get(a) => 1 ❖ Map ➢ put() ➢ get() ❖ Set ➢ has() ➢ keys()

slide-12
SLIDE 12

Nested Functions

int d = 1; int b(int c) { int d = 2; int a() { return d + c; } return a(); } print( b(3) ); /* Output 5 */ print( d ); /* Output 1 */ ❖ Access Outer Variables ❖ Scoping - Static

slide-13
SLIDE 13

System Architechture

slide-14
SLIDE 14

Scanner/Parser

slide-15
SLIDE 15

Organizer

  • A bridge between Circline and C
  • Format the functions and variables
slide-16
SLIDE 16

Semantic Check

The cast returned by Organizer is a list of function objects. cast: [func1, func2, …, funcn] Loop through all function objects and check each function objects. For nest scope situation, we try to search in parent scope if the variable is not found in current scope.

slide-17
SLIDE 17

Code Generation - CAST to LLVM Assembly

declare external functions (C Libraries) for function in program: declare all variables in function for statement in function: for expression in statement: codegen( expression )

Code Generator CAST LLVM Assembly

slide-18
SLIDE 18

Code Generator - C Library

int show(int a) { return a+1; }

define i32 @show(i32) #0 { %2 = alloca i32, align 4 store i32 %0, i32* %2, align 4 %3 = load i32, i32* %2, align 4 %4 = add nsw i32 %3, 1 ret i32 %4 }

utils.c utils.ll Bytecode utils.bc code.ll

declare i32 @show(i32) %tmp = call i32 @show(i32 1) clang -S -emit-llvm clang -emit-llvm

code

clang utils.bc code.ll

Executable

slide-19
SLIDE 19

Automated Build and Test -- Save Time!

Makefile: make all/test (Find target and build build build) Travis-CI Online Code check

slide-20
SLIDE 20

Compile & Run

circline.native Scan/Parse/Codegen Link Run utils.bc source source.ll source.exe

sh circline.sh <code> Let’s try to run it!

slide-21
SLIDE 21

Case Study -- BFS & DFS

BFS Code BFS Printout DFS Code DFS Printout

slide-22
SLIDE 22

Case Study -- Dijkstra Algorithm

slide-23
SLIDE 23

Project Timeline & Contribution

slide-24
SLIDE 24

With Special Thanks to Alexandra, our TA who continuously support our project