doc: add intermediate representation language
This commit is contained in:
105
doc/ir/Sum.ir
Normal file
105
doc/ir/Sum.ir
Normal file
@@ -0,0 +1,105 @@
|
||||
record source_filename = "Sum.im"
|
||||
|
||||
record package_scope = "net.doorstuck.test"
|
||||
|
||||
data @.str.0 = str "Finds the sum of a set of numbers."
|
||||
data @.str.1 = str "Number (blank to finish): "
|
||||
|
||||
define iblock {
|
||||
; cout put:'Finds the sum of a set of numbers.'
|
||||
%1 = alloca id
|
||||
store id @.str.0, ptr %1
|
||||
|
||||
%2 = load ptr %1
|
||||
%3 = load id @cout
|
||||
|
||||
call @_M03putE(id %3, id %2)
|
||||
|
||||
L0001.cond:
|
||||
br label @L0001.body
|
||||
|
||||
L0001.body:
|
||||
; cout
|
||||
%4 = load id @cout
|
||||
|
||||
; 'Number (blank to finish): '
|
||||
%5 = alloca id
|
||||
store str @.str.1, ptr %5
|
||||
|
||||
;; cout print:'Number (blank to finish): '
|
||||
call @_M05printE(id %4, id %5)
|
||||
|
||||
|
||||
; cout
|
||||
%6 = load id @cout
|
||||
|
||||
;; cout flush
|
||||
call @_M5flushE(id %6)
|
||||
|
||||
|
||||
; v
|
||||
%7 = alloca i32
|
||||
|
||||
; 0
|
||||
%8 = i32 #0
|
||||
|
||||
;; v = 0
|
||||
store i32 %8, ptr %7
|
||||
|
||||
|
||||
; input
|
||||
%9 = alloca id
|
||||
|
||||
; cin
|
||||
%10 = load id @cin
|
||||
|
||||
; cin readLine
|
||||
%11 = call @_M8readLineE(id %10)
|
||||
|
||||
;; input = cin readLine
|
||||
store id %11, ptr %9
|
||||
|
||||
L0002.if:
|
||||
; ''
|
||||
%12 = load ptr @String
|
||||
%13 = call @_M3newE(id %12)
|
||||
|
||||
; input
|
||||
%14 = load ptr %9
|
||||
|
||||
; input == ''
|
||||
%15 = cmp eq id %14, %13
|
||||
|
||||
;; if input == ''
|
||||
br i1 %15, label @L0002.then, label @L0002.else
|
||||
|
||||
L0002.then:
|
||||
;; then
|
||||
|
||||
; break
|
||||
br label @L0001.end
|
||||
|
||||
br label @L0002.end
|
||||
|
||||
L0002.else:
|
||||
;; else
|
||||
br label @L0002.end
|
||||
|
||||
L0002.end:
|
||||
;; end
|
||||
|
||||
; Int
|
||||
%17 = load id @Int
|
||||
|
||||
; input
|
||||
%18 = load ptr %9
|
||||
|
||||
; Int parse:input
|
||||
%19 = call @_M5parseE(id %17, id %18)
|
||||
|
||||
;; v = Int parse:input
|
||||
store id %19, ptr %7
|
||||
|
||||
|
||||
L0001.end:
|
||||
}
|
||||
@@ -1,15 +1,3 @@
|
||||
package simple.pkg
|
||||
v = 2 + 3 * 4.
|
||||
|
||||
use std.io
|
||||
|
||||
class Simple
|
||||
- init(name:name age:age)
|
||||
v = 1 + 2 squared + not 3.
|
||||
self::name = name.
|
||||
self::age = age!
|
||||
|
||||
- name | ^self::name.
|
||||
|
||||
- age
|
||||
^self::age!
|
||||
end
|
||||
cout put:v
|
||||
|
||||
@@ -1,29 +1,28 @@
|
||||
package net.doorstuck.test
|
||||
|
||||
cout put:'Finds the sum of a set of numbers.'
|
||||
cout put:'Finds the sum of a set of numbers.'.
|
||||
|
||||
sum = 0
|
||||
sum = 0.
|
||||
|
||||
while true do
|
||||
cout print:'Number (blank to finish): '
|
||||
cout flush
|
||||
cout print:'Number (blank to finish): '.
|
||||
cout flush.
|
||||
|
||||
input = ''
|
||||
v = 0
|
||||
cin get:input
|
||||
v = 0.
|
||||
input = cin readLine.
|
||||
|
||||
if input == '' then
|
||||
break
|
||||
end
|
||||
|
||||
try
|
||||
v = Int parse:input
|
||||
catch (#err:number_format, err)
|
||||
cout put:'{input} is not a valid number.'
|
||||
v = Int parse:input.
|
||||
|
||||
if v == null then
|
||||
cout put:'{input} is not a valid number.'.
|
||||
continue
|
||||
end
|
||||
|
||||
sum += v
|
||||
sum += v.
|
||||
end
|
||||
|
||||
cout put:'Sum: {sum}'
|
||||
|
||||
Reference in New Issue
Block a user