sfrp 1.2.1 → 1.4.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: a8a2b6d7ba628032ad44048b3b99c9c2c8b9f0ad
4
- data.tar.gz: 4d02328743284353e0858ff153764c4bb299dbf9
3
+ metadata.gz: cda721742189d74dac30ae37d3d0ec59d4b97085
4
+ data.tar.gz: 2a9ebf80928a7718b4241d5718f6f8d5fa1e035b
5
5
  SHA512:
6
- metadata.gz: 5fae12fd32c4a1b97ad57d759e49e08fdf60c29b0ce0bc831e921ff02cafd0850c7b395f0c373e9bb3ac6736fa6d3ebbfb47ea4b5abe84a53c6dee522ef0fbf8
7
- data.tar.gz: 697d4d030cb46f28f5146aeccd5cf5e09310ec77905c6180c0403eff50426a97c2a1ef547050d3b7abecb40940fe639c26e8ce9bf8e9346d58390b3cd4bd3e62
6
+ metadata.gz: ead9d2c66049bd7bf9debe408f39ccaa4c7e842096c830274ac7c3ced18f4ee426f0522b845d3394eaba2023e5cebf18b3066b7a3dc9bf2de62779c45f8718cc
7
+ data.tar.gz: d658239d964311003df0fa64798981d0cb9dbcd75dfc63cdc8599fc6bef846707e8c9c5f4629d15753ed6d1654856944f22d257b9e9838abcffb7ae43191be69
data/README.md CHANGED
@@ -19,12 +19,12 @@ Write following simple accumulator program.
19
19
  ```
20
20
  -- Main.sfrp
21
21
  import Base
22
- import IO.STDIO as IO
22
+ import Base.STDIO as IO
23
23
 
24
24
  in @x from IO.$getInt()
25
25
  out IO.$putInt(@y)
26
26
 
27
- @y 0 = @x + @@y
27
+ @y init 0 = @x + @@y
28
28
  ```
29
29
 
30
30
  Compile and Run the program.
@@ -13,6 +13,9 @@ type Tuple5[a, b, c, d, e] = Tuple5(a, b, c, d, e)
13
13
  fst(pair : (a, b)) : a = x where (x, _) = pair
14
14
  snd(pair : (a, b)) : b = y where (_, y) = pair
15
15
 
16
+ infixl <> 0
17
+ op <>(a : Unit, b : Unit) : Unit = Unit
18
+
16
19
  foreign - as '-(Int) : Int
17
20
  foreign + as '+(Int) : Int
18
21
  foreign ! as '!(Bool) : Bool
@@ -0,0 +1,79 @@
1
+ #include <avr/io.h>
2
+
3
+ int debouncing(unsigned char count[], int pin_val, int num) {
4
+ if (pin_val) {
5
+ switch (count[num]) {
6
+ case 2:
7
+ count[num] = 1;
8
+ return 1;
9
+ case 1:
10
+ break;
11
+ case 0:
12
+ count[num] = 10;
13
+ break;
14
+ default:
15
+ count[num]--;
16
+ }
17
+ } else {
18
+ count[num] = 0;
19
+ }
20
+ return 0;
21
+ }
22
+
23
+
24
+ // PB
25
+
26
+ int pinB(int num) {
27
+ DDRB &= ~(1 << num);
28
+ return (PINB & (1 << num)) == 0 ? 0 : 1;
29
+ }
30
+
31
+ int posEdgePB(int num) {
32
+ static unsigned char count[8];
33
+ return debouncing(count, pinB(num), num);
34
+ }
35
+
36
+ int portB(int port_num, int high_or_low) {
37
+ high_or_low = (high_or_low == 0 ? 0 : 1);
38
+ DDRB |= 1 << port_num;
39
+ PORTB = (~(1 << port_num) & PORTB) | (high_or_low << port_num);
40
+ return 0;
41
+ }
42
+
43
+ // PC
44
+
45
+ int pinC(int num) {
46
+ DDRC &= ~(1 << num);
47
+ return (PINC & (1 << num)) == 0 ? 0 : 1;
48
+ }
49
+
50
+ int posEdgePC(int num) {
51
+ static unsigned char count[8];
52
+ return debouncing(count, pinC(num), num);
53
+ }
54
+
55
+ int portC(int port_num, int high_or_low) {
56
+ high_or_low = (high_or_low == 0 ? 0 : 1);
57
+ DDRC |= 1 << port_num;
58
+ PORTC = (~(1 << port_num) & PORTC) | (high_or_low << port_num);
59
+ return 0;
60
+ }
61
+
62
+ // PD
63
+
64
+ int pinD(int num) {
65
+ DDRD &= ~(1 << num);
66
+ return (PIND & (1 << num)) == 0 ? 0 : 1;
67
+ }
68
+
69
+ int posEdgePD(int num) {
70
+ static unsigned char count[8];
71
+ return debouncing(count, pinD(num), num);
72
+ }
73
+
74
+ int portD(int port_num, int high_or_low) {
75
+ high_or_low = (high_or_low == 0 ? 0 : 1);
76
+ DDRD |= 1 << port_num;
77
+ PORTD = (~(1 << port_num) & PORTD) | (high_or_low << port_num);
78
+ return 0;
79
+ }
@@ -0,0 +1,15 @@
1
+ #ifndef IO_AVR_ATMEGA8_GPIO
2
+ #define IO_AVR_ATMEGA8_GPIO
3
+
4
+ // PB
5
+ int pinB(int);
6
+ int posEdgePB(int);
7
+ int portB(int, int);
8
+
9
+ // PC
10
+ int portC(int, int);
11
+
12
+ // PD
13
+ int portD(int, int);
14
+
15
+ #endif
@@ -0,0 +1,73 @@
1
+ import Base
2
+
3
+ -- PB
4
+
5
+ foreign pinB as $pinB(Int) : Bool
6
+ in @pinB0 from $pinB(0)
7
+ in @pinB1 from $pinB(1)
8
+ in @pinB2 from $pinB(2)
9
+ in @pinB3 from $pinB(3)
10
+ in @pinB4 from $pinB(4)
11
+ in @pinB5 from $pinB(5)
12
+ in @pinB6 from $pinB(6)
13
+ in @pinB7 from $pinB(7)
14
+
15
+ foreign posEdgePB as $posEdgePB(Int) : Bool
16
+ in @posEdgePB0 from $posEdgePB(0)
17
+ in @posEdgePB1 from $posEdgePB(1)
18
+ in @posEdgePB2 from $posEdgePB(2)
19
+ in @posEdgePB3 from $posEdgePB(3)
20
+ in @posEdgePB4 from $posEdgePB(4)
21
+ in @posEdgePB5 from $posEdgePB(5)
22
+ in @posEdgePB6 from $posEdgePB(6)
23
+ in @posEdgePB7 from $posEdgePB(7)
24
+
25
+ foreign portB as $portB(Int, Bool) : Unit
26
+
27
+ -- PC
28
+
29
+ foreign pinC as $pinC(Int) : Bool
30
+ in @pinC0 from $pinC(0)
31
+ in @pinC1 from $pinC(1)
32
+ in @pinC2 from $pinC(2)
33
+ in @pinC3 from $pinC(3)
34
+ in @pinC4 from $pinC(4)
35
+ in @pinC5 from $pinC(5)
36
+ in @pinC6 from $pinC(6)
37
+ in @pinC7 from $pinC(7)
38
+
39
+ foreign posEdgePC as $posEdgePC(Int) : Bool
40
+ in @posEdgePC0 from $posEdgePC(0)
41
+ in @posEdgePC1 from $posEdgePC(1)
42
+ in @posEdgePC2 from $posEdgePC(2)
43
+ in @posEdgePC3 from $posEdgePC(3)
44
+ in @posEdgePC4 from $posEdgePC(4)
45
+ in @posEdgePC5 from $posEdgePC(5)
46
+ in @posEdgePC6 from $posEdgePC(6)
47
+ in @posEdgePC7 from $posEdgePC(7)
48
+
49
+ foreign portC as $portC(Int, Bool) : Unit
50
+
51
+ -- PD
52
+
53
+ foreign pinD as $pinD(Int) : Bool
54
+ in @pinD0 from $pinD(0)
55
+ in @pinD1 from $pinD(1)
56
+ in @pinD2 from $pinD(2)
57
+ in @pinD3 from $pinD(3)
58
+ in @pinD4 from $pinD(4)
59
+ in @pinD5 from $pinD(5)
60
+ in @pinD6 from $pinD(6)
61
+ in @pinD7 from $pinD(7)
62
+
63
+ foreign posEdgePD as $posEdgePD(Int) : Bool
64
+ in @posEdgePD0 from $posEdgePD(0)
65
+ in @posEdgePD1 from $posEdgePD(1)
66
+ in @posEdgePD2 from $posEdgePD(2)
67
+ in @posEdgePD3 from $posEdgePD(3)
68
+ in @posEdgePD4 from $posEdgePD(4)
69
+ in @posEdgePD5 from $posEdgePD(5)
70
+ in @posEdgePD6 from $posEdgePD(6)
71
+ in @posEdgePD7 from $posEdgePD(7)
72
+
73
+ foreign portD as $portD(Int, Bool) : Unit
File without changes
File without changes
File without changes
File without changes
File without changes
data/lib/sfrp/flat/dsl.rb CHANGED
@@ -2,32 +2,32 @@ module SFRP
2
2
  module Flat
3
3
  extend SFRP::F = self
4
4
 
5
- def t(tconst_str, args, sp = nil)
6
- TypeAnnotationType.new(tconst_str, args, sp)
5
+ def t(tconst_str, args)
6
+ TypeAnnotationType.new(tconst_str, args)
7
7
  end
8
8
 
9
- def tv(var_str, sp = nil)
10
- TypeAnnotationVar.new(var_str, sp)
9
+ def tv(var_str)
10
+ TypeAnnotationVar.new(var_str)
11
11
  end
12
12
 
13
13
  def ft(ret_t, arg_ts)
14
14
  FuncTypeAnnotation.new(ret_t, arg_ts)
15
15
  end
16
16
 
17
- def v_e(var_str, sp = nil)
18
- VarRefExp.new(var_str, sp)
17
+ def v_e(var_str)
18
+ VarRefExp.new(var_str)
19
19
  end
20
20
 
21
- def nr_e(node_str, last, sp = nil)
22
- NodeRefExp.new(node_str, last, sp)
21
+ def nr_e(node_str, last)
22
+ NodeRefExp.new(node_str, last)
23
23
  end
24
24
 
25
- def call_e(func_str, args, sp = nil)
26
- FuncCallExp.new(func_str, args, sp)
25
+ def call_e(func_str, args)
26
+ FuncCallExp.new(func_str, args)
27
27
  end
28
28
 
29
- def vc_call_e(vconst_str, args, sp = nil)
30
- VConstCallExp.new(vconst_str, args, sp)
29
+ def vc_call_e(vconst_str, args)
30
+ VConstCallExp.new(vconst_str, args)
31
31
  end
32
32
  end
33
33
  end
@@ -1,6 +1,6 @@
1
1
  module SFRP
2
2
  module Flat
3
- class Function < Struct.new(:str, :ret_ta, :pstrs, :ptas, :exp, :ffi_str, :sp)
3
+ class Function < Struct.new(:str, :ret_ta, :pstrs, :ptas, :exp, :ffi_str)
4
4
  def to_poly(_src_set, dest_set)
5
5
  pstrs.reject(&:nil?).each do |s|
6
6
  raise DuplicatedVariableError.new(s) if pstrs.count(s) > 1
@@ -20,7 +20,7 @@ module SFRP
20
20
  end
21
21
  end
22
22
 
23
- class TConst < Struct.new(:str, :pstrs, :vc_strs, :native_str, :static, :sp)
23
+ class TConst < Struct.new(:str, :pstrs, :vc_strs, :native_str, :static)
24
24
  def type_annot
25
25
  TypeAnnotationType.new(str, pstrs.map { |s| TypeAnnotationVar.new(s) })
26
26
  end
@@ -31,7 +31,7 @@ module SFRP
31
31
  end
32
32
  end
33
33
 
34
- class VConst < Struct.new(:str, :tconst_str, :native_str, :param_tas, :sp)
34
+ class VConst < Struct.new(:str, :tconst_str, :native_str, :param_tas)
35
35
  def to_poly(src_set, dest_set)
36
36
  tconst = src_set.tconst(tconst_str)
37
37
  fta = FuncTypeAnnotation.new(tconst.type_annot, param_tas)
@@ -39,7 +39,7 @@ module SFRP
39
39
  end
40
40
  end
41
41
 
42
- class Node < Struct.new(:str, :ta, :exp, :init_exp, :sp)
42
+ class Node < Struct.new(:str, :ta, :exp, :init_exp)
43
43
  def initialized?
44
44
  !init_exp.nil?
45
45
  end
@@ -69,19 +69,19 @@ module SFRP
69
69
  end
70
70
  end
71
71
 
72
- class FuncTypeAnnotation < Struct.new(:ret_ta, :arg_tas, :sp)
72
+ class FuncTypeAnnotation < Struct.new(:ret_ta, :arg_tas)
73
73
  def to_poly
74
74
  Poly::FuncTypeAnnotation.new(ret_ta.to_poly, arg_tas.map(&:to_poly))
75
75
  end
76
76
  end
77
77
 
78
- class TypeAnnotationType < Struct.new(:tconst_str, :arg_tas, :sp)
78
+ class TypeAnnotationType < Struct.new(:tconst_str, :arg_tas)
79
79
  def to_poly
80
80
  P.t(tconst_str, *arg_tas.map(&:to_poly))
81
81
  end
82
82
  end
83
83
 
84
- class TypeAnnotationVar < Struct.new(:var_str, :sp)
84
+ class TypeAnnotationVar < Struct.new(:var_str)
85
85
  def to_poly
86
86
  P.tv(var_str)
87
87
  end
@@ -1,9 +1,9 @@
1
1
  module SFRP
2
2
  module Flat
3
- class FuncCallExp < Struct.new(:func_str, :arg_exps, :sp)
3
+ class FuncCallExp < Struct.new(:func_str, :arg_exps)
4
4
  def lift_node_ref(collected_node_refs)
5
5
  args = arg_exps.map { |e| e.lift_node_ref(collected_node_refs) }
6
- FuncCallExp.new(func_str, args, sp)
6
+ FuncCallExp.new(func_str, args)
7
7
  end
8
8
 
9
9
  def alpha_convert(table, serial)
@@ -16,10 +16,10 @@ module SFRP
16
16
  end
17
17
  end
18
18
 
19
- class VConstCallExp < Struct.new(:vconst_str, :arg_exps, :sp)
19
+ class VConstCallExp < Struct.new(:vconst_str, :arg_exps)
20
20
  def lift_node_ref(collected_node_refs)
21
21
  args = arg_exps.map { |e| e.lift_node_ref(collected_node_refs) }
22
- VConstCallExp.new(vconst_str, args, sp)
22
+ VConstCallExp.new(vconst_str, args)
23
23
  end
24
24
 
25
25
  def alpha_convert(table, serial)
@@ -32,7 +32,7 @@ module SFRP
32
32
  end
33
33
  end
34
34
 
35
- class NodeRefExp < Struct.new(:node_str, :last, :sp)
35
+ class NodeRefExp < Struct.new(:node_str, :last)
36
36
  NodeRef = Struct.new(:node_str, :last)
37
37
 
38
38
  def lift_node_ref(collected_node_refs)
@@ -40,7 +40,7 @@ module SFRP
40
40
  unless collected_node_refs.include?(node_ref)
41
41
  collected_node_refs << node_ref
42
42
  end
43
- VarRefExp.new("__node_ref_#{collected_node_refs.index(node_ref)}", sp)
43
+ VarRefExp.new("__node_ref_#{collected_node_refs.index(node_ref)}")
44
44
  end
45
45
 
46
46
  def alpha_convert(_table, _serial)
@@ -52,10 +52,10 @@ module SFRP
52
52
  end
53
53
  end
54
54
 
55
- class MatchExp < Struct.new(:left_exp, :cases, :sp)
55
+ class MatchExp < Struct.new(:left_exp, :cases)
56
56
  Case = Struct.new(:pattern, :exp)
57
57
 
58
- class Pattern < Struct.new(:vconst_str, :ref_var_str, :args, :sp)
58
+ class Pattern < Struct.new(:vconst_str, :ref_var_str, :args)
59
59
  def alpha_convert(table, serial)
60
60
  new_ref_var_str =
61
61
  ref_var_str && (table[ref_var_str] = "_alpha#{serial.shift}")
@@ -84,7 +84,7 @@ module SFRP
84
84
  new_cases = cases.map do |c|
85
85
  Case.new(c.pattern, c.exp.lift_node_ref(collected_node_refs))
86
86
  end
87
- MatchExp.new(new_left_exp, new_cases, sp)
87
+ MatchExp.new(new_left_exp, new_cases)
88
88
  end
89
89
 
90
90
  def alpha_convert(table, serial)
@@ -107,7 +107,7 @@ module SFRP
107
107
  end
108
108
  end
109
109
 
110
- class VarRefExp < Struct.new(:var_str, :sp)
110
+ class VarRefExp < Struct.new(:var_str)
111
111
  def lift_node_ref(_collected_node_refs)
112
112
  self
113
113
  end
@@ -132,7 +132,7 @@ module SFRP
132
132
  ws? >> str(')')).as(:output_def)
133
133
  }
134
134
  rule(:init_def_maybe) {
135
- (ws? >> exp.as(:init_exp)).maybe.as(:init_def_maybe)
135
+ (ws? >> str('init') >> ws >> exp.as(:init_exp)).maybe.as(:init_def_maybe)
136
136
  }
137
137
  rule(:foreign_str) {
138
138
  (str('{') >> match['^}'].repeat(1).as(:str) >> str('}'))
@@ -185,7 +185,8 @@ module SFRP
185
185
 
186
186
  # pattern
187
187
  rule(:any_pattern => simple(:x)) {
188
- Raw::MatchExp::Pattern.new(nil, x.to_s, [])
188
+ var_str = x.to_s
189
+ Raw::MatchExp::Pattern.new(nil, var_str == '_' ? nil : var_str, [])
189
190
  }
190
191
  rule(:vc_pattern_with_paren => subtree(:x)) {
191
192
  Raw::MatchExp::Pattern.new(x[:vconst_ref], x[:var_ref], x[:args])
data/lib/sfrp/raw/dsl.rb CHANGED
@@ -6,36 +6,36 @@ module SFRP
6
6
  Ref.new(rname, qualifier)
7
7
  end
8
8
 
9
- def t(tconst_ref, args, sp = nil)
10
- TypeAnnotationType.new(tconst_ref, args, sp)
9
+ def t(tconst_ref, args)
10
+ TypeAnnotationType.new(tconst_ref, args)
11
11
  end
12
12
 
13
- def tv(var_str, sp = nil)
14
- TypeAnnotationVar.new(var_str, sp)
13
+ def tv(var_str)
14
+ TypeAnnotationVar.new(var_str)
15
15
  end
16
16
 
17
17
  def ft(ret_t, arg_ts)
18
18
  FuncTypeAnnotation.new(ret_t, arg_ts)
19
19
  end
20
20
 
21
- def v_e(var_str, sp = nil)
22
- VarRefExp.new(var_str, sp)
21
+ def v_e(var_str)
22
+ VarRefExp.new(var_str)
23
23
  end
24
24
 
25
- def nr_e(node_ref, last, sp = nil)
26
- NodeRefExp.new(node_ref, last, sp)
25
+ def nr_e(node_ref, last)
26
+ NodeRefExp.new(node_ref, last)
27
27
  end
28
28
 
29
- def call_e(func_ref, args, sp = nil)
30
- FuncCallExp.new(func_ref, args, sp)
29
+ def call_e(func_ref, args)
30
+ FuncCallExp.new(func_ref, args)
31
31
  end
32
32
 
33
- def vc_call_e(vconst_ref, args, sp = nil)
34
- VConstCallExp.new(vconst_ref, args, sp)
33
+ def vc_call_e(vconst_ref, args)
34
+ VConstCallExp.new(vconst_ref, args)
35
35
  end
36
36
 
37
- def seq_e(exps, func_refs, sp = nil)
38
- SequenceExp.new(exps, func_refs, sp)
37
+ def seq_e(exps, func_refs)
38
+ SequenceExp.new(exps, func_refs)
39
39
  end
40
40
  end
41
41
  end
@@ -1,6 +1,6 @@
1
1
  module SFRP
2
2
  module Raw
3
- class Function < Struct.new(:rname, :ns, :ret_ta, :pstrs, :ptas, :exp, :ffi_str, :effect, :sp)
3
+ class Function < Struct.new(:rname, :ns, :ret_ta, :pstrs, :ptas, :exp, :ffi_str, :effect)
4
4
  def absolute_name
5
5
  ns.absolute_name(rname)
6
6
  end
@@ -15,35 +15,35 @@ module SFRP
15
15
  flat_ret_ta = ret_ta && ret_ta.to_flat(src_set, ns)
16
16
  flat_ptas = ptas.map { |ta| ta && ta.to_flat(src_set, ns) }
17
17
  dest_set << Flat::Function.new(
18
- absolute_name, flat_ret_ta, pstrs, flat_ptas, flat_exp, ffi_str, sp
18
+ absolute_name, flat_ret_ta, pstrs, flat_ptas, flat_exp, ffi_str
19
19
  )
20
20
  end
21
21
  end
22
22
 
23
- class TConst < Struct.new(:rname, :ns, :pstrs, :vconsts, :native_str, :static, :sp)
23
+ class TConst < Struct.new(:rname, :ns, :pstrs, :vconsts, :native_str, :static)
24
24
  def absolute_name
25
25
  ns.absolute_name(rname)
26
26
  end
27
27
 
28
28
  def gen_flat(_src_set, dest_set)
29
29
  vconst_strs = vconsts.map(&:absolute_name)
30
- dest_set << Flat::TConst.new(absolute_name, pstrs, vconst_strs, native_str, static, sp)
30
+ dest_set << Flat::TConst.new(absolute_name, pstrs, vconst_strs, native_str, static)
31
31
  end
32
32
  end
33
33
 
34
- class VConst < Struct.new(:rname, :tconst_rname, :ns, :native_str, :param_tas, :sp)
34
+ class VConst < Struct.new(:rname, :tconst_rname, :ns, :native_str, :param_tas)
35
35
  def absolute_name
36
36
  ns.absolute_name(rname)
37
37
  end
38
38
 
39
39
  def gen_flat(src_set, dest_set)
40
- tconst_str = src_set.tconst(ns, Ref.new(tconst_rname), sp).absolute_name
40
+ tconst_str = src_set.tconst(ns, Ref.new(tconst_rname)).absolute_name
41
41
  flat_param_tas = param_tas.map { |ta| ta.to_flat(src_set, ns) }
42
- dest_set << Flat::VConst.new(absolute_name, tconst_str, native_str, flat_param_tas, sp)
42
+ dest_set << Flat::VConst.new(absolute_name, tconst_str, native_str, flat_param_tas)
43
43
  end
44
44
  end
45
45
 
46
- class PrimTConst < Struct.new(:rname, :ns, :native_str, :pat, :rep, :sp)
46
+ class PrimTConst < Struct.new(:rname, :ns, :native_str, :pat, :rep)
47
47
  def absolute_name
48
48
  ns.absolute_name(rname)
49
49
  end
@@ -54,11 +54,11 @@ module SFRP
54
54
 
55
55
  def make_vconst(vconst_str)
56
56
  raise vconst_str unless vconst_match?(vconst_str)
57
- VConst.new(vconst_str, rname, ns, vconst_str.gsub(pat, rep), [], sp)
57
+ VConst.new(vconst_str, rname, ns, vconst_str.gsub(pat, rep), [])
58
58
  end
59
59
 
60
60
  def gen_flat(_src_set, dest_set)
61
- dest_set << Flat::TConst.new(absolute_name, [], nil, native_str, true, sp)
61
+ dest_set << Flat::TConst.new(absolute_name, [], nil, native_str, true)
62
62
  end
63
63
  end
64
64
 
@@ -78,7 +78,7 @@ module SFRP
78
78
  end
79
79
  end
80
80
 
81
- class Node < Struct.new(:rname, :ns, :ta, :exp, :init_exp, :sp)
81
+ class Node < Struct.new(:rname, :ns, :ta, :exp, :init_exp)
82
82
  def absolute_name
83
83
  ns.absolute_name(rname)
84
84
  end
@@ -92,11 +92,11 @@ module SFRP
92
92
  flat_ta = ta && ta.to_flat(src_set, ns)
93
93
  flat_init_exp = init_exp && init_exp.to_flat(src_set, ns)
94
94
  flat_exp = exp && exp.to_flat(src_set, ns)
95
- dest_set << Flat::Node.new(absolute_name, flat_ta, flat_exp, flat_init_exp, sp)
95
+ dest_set << Flat::Node.new(absolute_name, flat_ta, flat_exp, flat_init_exp)
96
96
  end
97
97
  end
98
98
 
99
- class Output < Struct.new(:ns, :exps, :func_ref, :line_number, :sp)
99
+ class Output < Struct.new(:ns, :exps, :func_ref, :line_number)
100
100
  def rname
101
101
  "%output_line#{line_number}"
102
102
  end
@@ -106,25 +106,25 @@ module SFRP
106
106
  end
107
107
 
108
108
  def convert
109
- exp = FuncCallExp.new(func_ref, exps, false, sp)
109
+ exp = FuncCallExp.new(func_ref, exps, false)
110
110
  ta = TypeAnnotationType.new(Ref.new('Unit'), [])
111
- Node.new(rname, ns, ta, exp, nil, sp)
111
+ Node.new(rname, ns, ta, exp, nil)
112
112
  end
113
113
  end
114
114
 
115
- class Input < Struct.new(:rname, :ns, :ta, :arg_exps, :init_exp, :func_ref, :sp)
115
+ class Input < Struct.new(:rname, :ns, :ta, :arg_exps, :init_exp, :func_ref)
116
116
  def convert
117
- exp = FuncCallExp.new(func_ref, arg_exps, false, sp)
118
- Node.new(rname, ns, ta, exp, init_exp, sp)
117
+ exp = FuncCallExp.new(func_ref, arg_exps, false)
118
+ Node.new(rname, ns, ta, exp, init_exp)
119
119
  end
120
120
  end
121
121
 
122
- class Infix < Struct.new(:ns, :func_ref, :priority, :direction, :sp)
122
+ class Infix < Struct.new(:ns, :func_ref, :priority, :direction)
123
123
  LEFT, RIGHT, NONE = :left, :right, :none
124
124
 
125
125
  def absolute_func_name(set)
126
- func_name = set.func(ns, func_ref, sp).absolute_name
127
- raise NameError.new(func_ref.to_s, sp) unless func_name
126
+ func_name = set.func(ns, func_ref).absolute_name
127
+ raise NameError.new(func_ref.to_s) unless func_name
128
128
  func_name
129
129
  end
130
130
 
@@ -140,24 +140,24 @@ module SFRP
140
140
  end
141
141
  end
142
142
 
143
- class FuncTypeAnnotation < Struct.new(:ret_ta, :arg_tas, :sp)
143
+ class FuncTypeAnnotation < Struct.new(:ret_ta, :arg_tas)
144
144
  def to_flat(set, ns)
145
145
  flat_arg_tas = arg_tas.map { |ta| ta.to_flat(set, ns) }
146
- Flat::FuncTypeAnnotation.new(ret_ta.to_flat(set, ns), flat_arg_tas, sp)
146
+ Flat::FuncTypeAnnotation.new(ret_ta.to_flat(set, ns), flat_arg_tas)
147
147
  end
148
148
  end
149
149
 
150
- class TypeAnnotationType < Struct.new(:tconst_ref, :arg_tas, :sp)
150
+ class TypeAnnotationType < Struct.new(:tconst_ref, :arg_tas)
151
151
  def to_flat(set, ns)
152
- ab_tc_name = set.tconst(ns, tconst_ref, sp).absolute_name
152
+ ab_tc_name = set.tconst(ns, tconst_ref).absolute_name
153
153
  flat_arg_tas = arg_tas.map { |ta| ta.to_flat(set, ns) }
154
- Flat::TypeAnnotationType.new(ab_tc_name, flat_arg_tas, sp)
154
+ Flat::TypeAnnotationType.new(ab_tc_name, flat_arg_tas)
155
155
  end
156
156
  end
157
157
 
158
- class TypeAnnotationVar < Struct.new(:var_str, :sp)
158
+ class TypeAnnotationVar < Struct.new(:var_str)
159
159
  def to_flat(_set, _ns)
160
- Flat::TypeAnnotationVar.new(var_str, sp)
160
+ Flat::TypeAnnotationVar.new(var_str)
161
161
  end
162
162
  end
163
163
  end
@@ -1,23 +1,23 @@
1
1
  module SFRP
2
2
  module Raw
3
- class FuncCallExp < Struct.new(:func_ref, :arg_exps, :effect, :sp)
3
+ class FuncCallExp < Struct.new(:func_ref, :arg_exps, :effect)
4
4
  def vconst_refs
5
5
  arg_exps.flat_map(&:vconst_refs)
6
6
  end
7
7
 
8
8
  def blame_side_effect
9
- raise IllegalSideEffectError.new(func_ref.to_s, sp) if effect
9
+ raise IllegalSideEffectError.new(func_ref.to_s) if effect
10
10
  arg_exps.each(&:blame_side_effect)
11
11
  end
12
12
 
13
13
  def to_flat(set, ns)
14
- ab_func_name = set.func(ns, func_ref, sp).absolute_name
14
+ ab_func_name = set.func(ns, func_ref).absolute_name
15
15
  args = arg_exps.map { |e| e.to_flat(set, ns) }
16
- Flat::FuncCallExp.new(ab_func_name, args, sp)
16
+ Flat::FuncCallExp.new(ab_func_name, args)
17
17
  end
18
18
  end
19
19
 
20
- class VConstCallExp < Struct.new(:vconst_ref, :arg_exps, :sp)
20
+ class VConstCallExp < Struct.new(:vconst_ref, :arg_exps)
21
21
  def vconst_refs
22
22
  [vconst_ref, *arg_exps.flat_map(&:vconst_refs)]
23
23
  end
@@ -27,13 +27,13 @@ module SFRP
27
27
  end
28
28
 
29
29
  def to_flat(set, ns)
30
- ab_vc_name = set.vconst(ns, vconst_ref, sp).absolute_name
30
+ ab_vc_name = set.vconst(ns, vconst_ref).absolute_name
31
31
  args = arg_exps.map { |e| e.to_flat(set, ns) }
32
- Flat::VConstCallExp.new(ab_vc_name, args, sp)
32
+ Flat::VConstCallExp.new(ab_vc_name, args)
33
33
  end
34
34
  end
35
35
 
36
- class NodeRefExp < Struct.new(:node_ref, :last, :sp)
36
+ class NodeRefExp < Struct.new(:node_ref, :last)
37
37
  def vconst_refs
38
38
  []
39
39
  end
@@ -43,15 +43,15 @@ module SFRP
43
43
  end
44
44
 
45
45
  def to_flat(set, ns)
46
- ab_node_name = set.node(ns, node_ref, sp).absolute_name
46
+ ab_node_name = set.node(ns, node_ref).absolute_name
47
47
  Flat::NodeRefExp.new(ab_node_name, last)
48
48
  end
49
49
  end
50
50
 
51
- class MatchExp < Struct.new(:left_exp, :cases, :sp)
51
+ class MatchExp < Struct.new(:left_exp, :cases)
52
52
  Case = Struct.new(:pattern, :exp)
53
53
 
54
- class Pattern < Struct.new(:vconst_ref, :ref_var_str, :args, :sp)
54
+ class Pattern < Struct.new(:vconst_ref, :ref_var_str, :args)
55
55
  def vconst_refs
56
56
  (vconst_ref ? [vconst_ref] : []) + args.flat_map(&:vconst_refs)
57
57
  end
@@ -59,10 +59,10 @@ module SFRP
59
59
  def to_flat(set, ns)
60
60
  flat_args = args.map { |a| a.to_flat(set, ns) }
61
61
  if vconst_ref
62
- ab_vc_name = set.vconst(ns, vconst_ref, sp).absolute_name
63
- Flat::MatchExp::Pattern.new(ab_vc_name, ref_var_str, flat_args, sp)
62
+ ab_vc_name = set.vconst(ns, vconst_ref).absolute_name
63
+ Flat::MatchExp::Pattern.new(ab_vc_name, ref_var_str, flat_args)
64
64
  else
65
- Flat::MatchExp::Pattern.new(nil, ref_var_str, flat_args, sp)
65
+ Flat::MatchExp::Pattern.new(nil, ref_var_str, flat_args)
66
66
  end
67
67
  end
68
68
  end
@@ -81,11 +81,11 @@ module SFRP
81
81
  flat_pattern = c.pattern.to_flat(set, ns)
82
82
  Flat::MatchExp::Case.new(flat_pattern, c.exp.to_flat(set, ns))
83
83
  end
84
- Flat::MatchExp.new(left_exp.to_flat(set, ns), flat_cases, sp)
84
+ Flat::MatchExp.new(left_exp.to_flat(set, ns), flat_cases)
85
85
  end
86
86
  end
87
87
 
88
- class VarRefExp < Struct.new(:var_str, :sp)
88
+ class VarRefExp < Struct.new(:var_str)
89
89
  def vconst_refs
90
90
  []
91
91
  end
@@ -95,11 +95,11 @@ module SFRP
95
95
  end
96
96
 
97
97
  def to_flat(_set, _ns)
98
- Flat::VarRefExp.new(var_str, sp)
98
+ Flat::VarRefExp.new(var_str)
99
99
  end
100
100
  end
101
101
 
102
- class SequenceExp < Struct.new(:exps, :func_refs, :sp)
102
+ class SequenceExp < Struct.new(:exps, :func_refs)
103
103
  def vconst_refs
104
104
  exps.flat_map(&:vconst_refs)
105
105
  end
@@ -110,11 +110,11 @@ module SFRP
110
110
 
111
111
  def convert(set, ns)
112
112
  return exps[0] if exps.size == 1
113
- pos = set.weakest_op_position(ns, func_refs, sp)
114
- lseq = SequenceExp.new(exps.take(pos + 1), func_refs.take(pos), sp)
115
- rseq = SequenceExp.new(exps.drop(pos + 1), func_refs.drop(pos + 1), sp)
113
+ pos = set.weakest_op_position(ns, func_refs)
114
+ lseq = SequenceExp.new(exps.take(pos + 1), func_refs.take(pos))
115
+ rseq = SequenceExp.new(exps.drop(pos + 1), func_refs.drop(pos + 1))
116
116
  args = [lseq.convert(set, ns), rseq.convert(set, ns)]
117
- FuncCallExp.new(func_refs[pos], args, false, sp)
117
+ FuncCallExp.new(func_refs[pos], args, false)
118
118
  end
119
119
 
120
120
  def to_flat(set, ns)
@@ -136,23 +136,23 @@ module SFRP
136
136
  end
137
137
  end
138
138
 
139
- class IfExp < Struct.new(:cond_exp, :then_exp, :else_exp, :sp)
139
+ class IfExp < Struct.new(:cond_exp, :then_exp, :else_exp)
140
140
  include SugarExp
141
141
 
142
142
  def convert
143
143
  cases = [
144
144
  MatchExp::Case.new(
145
- MatchExp::Pattern.new(Ref.new('True'), nil, [], sp), then_exp
145
+ MatchExp::Pattern.new(Ref.new('True'), nil, []), then_exp
146
146
  ),
147
147
  MatchExp::Case.new(
148
- MatchExp::Pattern.new(Ref.new('False'), nil, [], sp), else_exp
148
+ MatchExp::Pattern.new(Ref.new('False'), nil, []), else_exp
149
149
  )
150
150
  ]
151
- MatchExp.new(cond_exp, cases, sp)
151
+ MatchExp.new(cond_exp, cases)
152
152
  end
153
153
  end
154
154
 
155
- class LetExp < Struct.new(:exp, :assignments, :sp)
155
+ class LetExp < Struct.new(:exp, :assignments)
156
156
  include SugarExp
157
157
 
158
158
  Assignment = Struct.new(:pattern, :exp)
@@ -160,7 +160,7 @@ module SFRP
160
160
  def convert
161
161
  raise if assignments.empty?
162
162
  assignments.reverse.reduce(exp) do |e, ass|
163
- MatchExp.new(ass.exp, [MatchExp::Case.new(ass.pattern, e)], sp)
163
+ MatchExp.new(ass.exp, [MatchExp::Case.new(ass.pattern, e)])
164
164
  end
165
165
  end
166
166
  end
@@ -1,6 +1,6 @@
1
1
  module SFRP
2
2
  module Raw
3
- class Ref < Struct.new(:relative_name, :qualifier_name, :sp)
3
+ class Ref < Struct.new(:relative_name, :qualifier_name)
4
4
  def to_s
5
5
  return relative_name if qualifier_name.nil?
6
6
  qualifier_name + '.' + relative_name
data/lib/sfrp/raw/set.rb CHANGED
@@ -56,36 +56,36 @@ module SFRP
56
56
  end
57
57
  end
58
58
 
59
- def weakest_op_position(ns, func_refs, sp)
60
- ab_func_names = func_refs.map { |fr| func(ns, fr, sp).absolute_name }
59
+ def weakest_op_position(ns, func_refs)
60
+ ab_func_names = func_refs.map { |fr| func(ns, fr).absolute_name }
61
61
  infix_h = Hash[@infixies.map { |i| [i.absolute_func_name(self), i] }]
62
62
  ab_func_names.each_with_index.map do |x, idx|
63
63
  [(infix_h.key?(x) ? infix_h[x].absolute_priority(idx) : [0, 0]), idx]
64
64
  end.min[1]
65
65
  end
66
66
 
67
- def func(ns, func_ref, sp)
68
- resolve(ns, func_ref, @func_h, sp)
67
+ def func(ns, func_ref)
68
+ resolve(ns, func_ref, @func_h)
69
69
  end
70
70
 
71
- def vconst(ns, vconst_ref, sp)
72
- resolve(ns, vconst_ref, @vconst_h, sp)
71
+ def vconst(ns, vconst_ref)
72
+ resolve(ns, vconst_ref, @vconst_h)
73
73
  end
74
74
 
75
- def node(ns, node_ref, sp)
76
- resolve(ns, node_ref, @node_h, sp)
75
+ def node(ns, node_ref)
76
+ resolve(ns, node_ref, @node_h)
77
77
  end
78
78
 
79
- def tconst(ns, tconst_ref, sp)
80
- resolve(ns, tconst_ref, @tconst_h, sp)
79
+ def tconst(ns, tconst_ref)
80
+ resolve(ns, tconst_ref, @tconst_h)
81
81
  end
82
82
 
83
83
  private
84
84
 
85
- def resolve(ns, ref, hash, sp)
85
+ def resolve(ns, ref, hash)
86
86
  hits = ns.search_for_absolute_names(ref).select { |x| hash.key?(x) }
87
- raise NameError.new(ref.to_s, sp) if hits.empty?
88
- raise AmbiguousNameError.new(ref.to_s, hits, sp) if hits.size > 1
87
+ raise NameError.new(ref.to_s) if hits.empty?
88
+ raise AmbiguousNameError.new(ref.to_s, hits) if hits.size > 1
89
89
  hash[hits[0]]
90
90
  end
91
91
 
data/lib/sfrp/version.rb CHANGED
@@ -1,3 +1,3 @@
1
1
  module SFRP
2
- VERSION = '1.2.1'
2
+ VERSION = '1.4.0'
3
3
  end
data/spec/sfrp/Test.sfrp CHANGED
@@ -1,4 +1,4 @@
1
1
  type Unit = Unit
2
2
  $nop(x) = Unit
3
- @unit(Unit) = @@unit
3
+ @unit init Unit = @@unit
4
4
  out $nop(@unit)
@@ -15,6 +15,6 @@ f(x, y) = let t = (p, p) where p = (x, y)
15
15
  i = 100
16
16
  in (t, i)
17
17
 
18
- in @pin False from $pin(0)
19
- @acc 0 = @@acc + - - 1
18
+ in @pin init False from $pin(0)
19
+ @acc init 0 = @@acc + - - 1
20
20
  out $world(@pin, @acc)
@@ -1,10 +1,10 @@
1
1
  import Base
2
- import Base.IO.STDIO as SIO
2
+ import Base.STDIO as SIO
3
3
 
4
4
  foreign init as $initProgram(Int) : Unit
5
5
  init $initProgram(0)
6
6
 
7
- in @input 0 from SIO.$getInt()
7
+ in @input init 0 from SIO.$getInt()
8
8
  out SIO.$putInt(@x)
9
9
 
10
10
  @x : Int = -(@@input * 1 + @input * 2)
@@ -1,8 +1,8 @@
1
1
  import Base
2
- import Base.IO.STDIO as SIO
2
+ import Base.STDIO as SIO
3
3
  import SubDir.Lib as Lib
4
4
 
5
5
  in @maybeInt : Maybe[Int] from Lib.$getMaybeInt()
6
6
  out SIO.$putInt(@acc)
7
7
 
8
- @acc 0 : Int = @@acc + Lib.getOrElse(@maybeInt, 0)
8
+ @acc init 0 : Int = @@acc + Lib.getOrElse(@maybeInt, 0)
@@ -1,5 +1,5 @@
1
1
  import Base
2
- import Base.IO.STDIO as SIO
2
+ import Base.STDIO as SIO
3
3
 
4
4
  $getMaybeInt() : Maybe[Int] = case SIO.$getIntPair() of
5
5
  (0, _) -> Nothing
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: sfrp
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.2.1
4
+ version: 1.4.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Kensuke Sawada
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2016-10-13 00:00:00.000000000 Z
11
+ date: 2016-12-11 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler
@@ -168,15 +168,15 @@ files:
168
168
  - README.md
169
169
  - Rakefile
170
170
  - base-library/Base.sfrp
171
- - base-library/Base/IO/AVR/ATMEGA8/GPIO.c
172
- - base-library/Base/IO/AVR/ATMEGA8/GPIO.h
173
- - base-library/Base/IO/AVR/ATMEGA8/GPIO.sfrp
174
- - base-library/Base/IO/AVR/ATMEGA8/Timer.c
175
- - base-library/Base/IO/AVR/ATMEGA8/Timer.h
176
- - base-library/Base/IO/AVR/ATMEGA8/Timer.sfrp
177
- - base-library/Base/IO/STDIO.c
178
- - base-library/Base/IO/STDIO.h
179
- - base-library/Base/IO/STDIO.sfrp
171
+ - base-library/Base/AVR/ATMEGA8/GPIO.c
172
+ - base-library/Base/AVR/ATMEGA8/GPIO.h
173
+ - base-library/Base/AVR/ATMEGA8/GPIO.sfrp
174
+ - base-library/Base/AVR/ATMEGA8/Timer.c
175
+ - base-library/Base/AVR/ATMEGA8/Timer.h
176
+ - base-library/Base/AVR/ATMEGA8/Timer.sfrp
177
+ - base-library/Base/STDIO.c
178
+ - base-library/Base/STDIO.h
179
+ - base-library/Base/STDIO.sfrp
180
180
  - bin/sfrp
181
181
  - lib/sfrp.rb
182
182
  - lib/sfrp/command.rb
@@ -1,8 +0,0 @@
1
- #include <avr/io.h>
2
-
3
- int portD(int port_num, int high_or_low) {
4
- high_or_low = (high_or_low == 0 ? 0 : 1);
5
- DDRD |= 1 << port_num;
6
- PORTD = (~(1 << port_num) & PORTD) | (high_or_low << port_num);
7
- return 0;
8
- }
@@ -1,6 +0,0 @@
1
- #ifndef IO_AVR_ATMEGA8_GPIO
2
- #define IO_AVR_ATMEGA8_GPIO
3
-
4
- int portD(int, int);
5
-
6
- #endif
@@ -1,4 +0,0 @@
1
- import Base
2
-
3
- -- PORT-D
4
- foreign portD as $portD(Int, Bool) : Unit