瀏覽代碼

Split up primitives into primitives and semi-primitives

Yentl Van Tendeloo 8 年之前
父節點
當前提交
32b61cb4eb
共有 3 個文件被更改,包括 52 次插入11 次删除
  1. 0 10
      bootstrap/primitives.alc
  2. 49 0
      bootstrap/semi_primitives.alc
  3. 3 1
      interface/HUTN/includes/primitives.alh

+ 0 - 10
bootstrap/primitives.alc

@@ -1,5 +1,4 @@
 Boolean function value_eq(a: Element, b: Element) = ?primitives/value_eq
-Boolean function value_neq(a: Element, b: Element) = ?primitives/value_neq
 Boolean function bool_and(a: Boolean, b: Boolean) = ?primitives/bool_and
 Boolean function bool_or(a: Boolean, b: Boolean) = ?primitives/bool_or
 Boolean function bool_not(a: Boolean) = ?primitives/bool_not
@@ -15,7 +14,6 @@ Element function read_edge_src(a: Element) = ?primitives/read_edge_src
 Element function read_edge_dst(a: Element) = ?primitives/read_edge_dst
 Boolean function delete_element(a: Element) = ?primitives/delete_element
 Boolean function element_eq(a: Element, b: Element) = ?primitives/element_eq
-Boolean function element_neq(a: Element, b: Element) = ?primitives/element_neq
 Float function cast_i2f(a: Integer) = ?primitives/cast_i2f
 String function cast_i2s(a: Integer) = ?primitives/cast_i2s
 Boolean function cast_i2b(a: Integer) = ?primitives/cast_i2b
@@ -39,7 +37,6 @@ Element function dict_delete_node(a: Element, b: Element) = ?primitives/dict_del
 Element function dict_read(a: Element, b: Element) = ?primitives/dict_read
 Element function dict_read_edge(a: Element, b: Element) = ?primitives/dict_read_edge
 Element function dict_read_node(a: Element, b: Element) = ?primitives/dict_read_node
-Integer function dict_len(a: Element) = ?primitives/dict_len
 Boolean function dict_in(a: Element, b: Element) = ?primitives/dict_in
 Boolean function dict_in_node(a: Element, b: Element) = ?primitives/dict_in_node
 Element function dict_keys(a: Element) = ?primitives/dict_keys
@@ -49,21 +46,14 @@ Float function float_multiplication(a: Float, b: Float) = ?primitives/float_mult
 Float function float_division(a: Float, b: Float) = ?primitives/float_division
 Boolean function float_gt(a: Float, b: Float) = ?primitives/float_gt
 Boolean function float_lt(a: Float, b: Float) = ?primitives/float_lt
-Boolean function float_neg(a: Float) = ?primitives/float_neg
 Integer function integer_addition(a: Integer, b: Integer) = ?primitives/integer_addition
 Integer function integer_subtraction(a: Integer, b: Integer) = ?primitives/integer_subtraction
 Integer function integer_multiplication(a: Integer, b: Integer) = ?primitives/integer_multiplication
 Integer function integer_division(a: Integer, b: Integer) = ?primitives/integer_division
 Boolean function integer_gt(a: Integer, b: Integer) = ?primitives/integer_gt
 Boolean function integer_lt(a: Integer, b: Integer) = ?primitives/integer_lt
-Boolean function integer_neg(a: Integer) = ?primitives/integer_neg
-Element function list_read(a: Element, b: Integer) = ?primitives/list_read
-Element function list_append(a: Element, b: Element) = ?primitives/list_append
 Element function list_insert(a: Element, b: Element, c: Integer) = ?primitives/list_insert
 Element function list_delete(a: Element, b: Integer) = ?primitives/list_delete
-Integer function list_len(a: Element) = ?primitives/list_len
-Element function set_add(a: Element, b: Element) = ?primitives/set_add
-Element function set_pop(a: Element) = ?primitives/set_pop
 Element function set_remove(a: Element, b: Element) = ?primitives/set_remove
 Boolean function set_in(a: Element, b: Element) = ?primitives/set_in
 Element function set_remove_node(a: Element, b: Element) = ?primitives/set_remove_node

+ 49 - 0
bootstrap/semi_primitives.alc

@@ -1,5 +1,54 @@
 include "primitives.alh"
 
+Boolean function value_neq(a : Element, b : Element):
+	return bool_not(value_eq(a, b))!
+
+Boolean function element_neq(a : Element, b : Element):
+	return bool_not(element_eq(a, b))!
+
+Integer function dict_len(a : Element):
+	return read_nr_out(a)!
+
+Integer function list_len(a : Element):
+	return read_nr_out(a)!
+
+Integer function set_len(a : Element):
+	return read_nr_out(a)!
+
+Float function float_neg(a : Float):
+	return float_subtraction(0, a)!
+
+Integer function integer_neg(a : Integer):
+	return integer_subtraction(0, a)!
+
+Element function list_read(a : Element, b : Integer):
+	return dict_read(a, b)!
+
+Element function list_append(a : Element, b : Element):
+	dict_add(a, integer_addition(list_len(a), 1), b)
+	return a!
+
+Element function set_add(a : Element, b : Element):
+	if (bool_not(set_in(a, b))):
+		create_edge(a, b)
+	return a!
+
+Element function set_pop(a : Element):
+	if (integer_gt(set_len(a), 0)):
+		Element edge
+		edge = read_out(a, 0)
+		edge = read_edge_dst(edge)
+		delete_element(edge)
+		return edge!
+	else:
+		return read_root()
+
+Element function set_read(a : Element):
+	if (integer_gt(set_len(a), 0)):
+		return read_edge_dst(read_out(a, 0))!
+	else:
+		return read_root()
+
 Void function sleep(a : Float):
 	__sleep(a, False)
 	return!

+ 3 - 1
interface/HUTN/includes/primitives.alh

@@ -47,11 +47,11 @@ Float function float_addition(a: Float, b: Float)
 Float function float_subtraction(a: Float, b: Float) 
 Float function float_multiplication(a: Float, b: Float) 
 Float function float_division(a: Float, b: Float) 
+Float function float_neg(a: Float)
 Boolean function float_gt(a: Float, b: Float) 
 Boolean function float_gte(a: Float, b: Float) 
 Boolean function float_lt(a: Float, b: Float) 
 Boolean function float_lte(a: Float, b: Float) 
-Boolean function float_neg(a: Float)
 Integer function integer_addition(a: Integer, b: Integer)
 Integer function integer_subtraction(a: Integer, b: Integer) 
 Integer function integer_multiplication(a: Integer, b: Integer) 
@@ -69,10 +69,12 @@ Element function list_delete(a: Element, b: Integer)
 Integer function list_len(a: Element) 
 Element function set_add(a: Element, b: Element) 
 Element function set_pop(a: Element) 
+Element function set_read(a : Element)
 Element function set_remove(a: Element, b: Element) 
 Boolean function set_in(a: Element, b: Element) 
 Element function set_remove_node(a: Element, b: Element) 
 Element function set_in_node(a: Element, b: Element) 
+Integer function set_len(a: Element)
 String function string_join(a: String, b: String) 
 String function string_get(a: String, b: Integer) 
 String function string_substr(a: String, b: Integer, c: Integer)