Browse Source

Add new samples

mingodad 7 years ago
parent
commit
986a8bd415

+ 4 - 1
SquiLu/samples/test-ifdef.nut

@@ -1,4 +1,7 @@
-//#include "test-ifdef.nut"
+#define NESTED_INCLUDE
+#ifdef NESTED_INCLUDE
+#include "test-array.nut"
+#endif
 
 # define DEBUG
 

+ 9 - 0
SquiLu/samples/test-long-str.nut

@@ -0,0 +1,9 @@
+auto txt = R"DAD((?x)
+dad
+)DA
+
+(x)))))))D
+
+)DAD";
+
+print(txt);

+ 88 - 0
SquiLu/samples/test-parameters-type.nut

@@ -0,0 +1,88 @@
+let isDone2: bool_t = false;
+let isDone: boolean = false;
+int_t ifunc(int_t p);
+extern string_t sfunc(string_t p);
+
+array_t ary = [1,2,3];
+
+int_t vi;
+float_t vf;
+string_t vs;
+
+
+function one(a: integer, b : integer, c : number) : number
+{
+	return a + b + c;
+}
+
+int_t two(int_t a, int_t b, int_t c)
+{
+	return a + b + c;
+}
+
+string_t three(string_t a, string_t b, string_t c)
+{
+	return a + b + c;
+}
+
+print(one(1111,2222,3333));
+print(two(1111,2222,3333));
+
+int_t vi0;
+int_t vi1 = 111;
+int_t vi2 = 222;
+int_t vi3 = 333;
+
+print(two(vi1,vi2,vi3));
+
+print(three("s111","s222","s333"));
+
+class Klass
+{
+	int_t idata;
+	
+	Klass(int_t a)
+	{
+		idata = a;
+	}
+	
+	int_t get()
+	{
+		return idata;
+	}
+	
+	void add(int_t b)
+	{
+		idata += b;
+	}
+}
+
+local Klass2 = class 
+{
+	int_t idata;
+	
+	constructor(int_t a)
+	{
+		idata = a;
+	}
+	
+	int_t get()
+	{
+		return idata;
+	}
+	
+	void add(int_t b)
+	{
+		idata += b;
+	}
+}
+
+auto klass = new Klass(50);
+print(klass->get());
+klass->add(20);
+print(klass->get());
+
+auto klass2 = new Klass2(50);
+print(klass2->get());
+klass2->add(20);
+print(klass2->get());

+ 217 - 0
SquiLu/samples/test-pefix-tree.nut

@@ -0,0 +1,217 @@
+auto word_list = [==[
+account_id
+accounts
+active
+address
+batch_order_line_id
+buy_description
+buy_discount
+buy_notes
+buy_other_costs
+buy_price
+buy_quantity_min
+buys
+cash
+_cdate_
+city
+code
+company
+contact
+country
+date
+days
+delete
+description
+discount_amt
+discount_over_sales
+discount_pct
+email
+entities
+entity_address
+entity_city
+entity_country
+entity_id
+entity_name
+entity_order_number
+entity_phone
+entity_sales_tax_exempt
+entity_state
+entity_tax_number
+entity_use_sales_tax2
+entity_zip
+fax
+first_total
+gps_coordinates
+group_id
+group_set
+id
+image
+image_id
+images
+inactive
+insert
+irpf_pct_retention
+is_active
+line_subtotal
+line_total
+lines_count
+markup_to_discount
+_mdate_
+measure_unit_id
+mime_type
+months
+name
+notes
+only_prices_older
+order_by_creation
+order_by_modification
+order_date
+order_id
+order_number
+order_type_id
+order_types
+order_valid_till_date
+orders
+orders_lines
+parent_id
+payment_type_id
+payment_types
+periode_count
+periode_type
+phone
+price
+price_decimals
+price_formula
+product_id
+products
+quantity
+query_limit
+reference
+reference_code
+sales
+sales_tax1_amt
+sales_tax1_pct
+sales_tax2_amt
+sales_tax2_pct
+sales_tax_exempt
+sales_tax_id
+sell_description
+sell_markup
+sell_notes
+sell_price
+sell_price2
+sell_quantity_min
+sell_without_stock
+series
+show_on_buys
+show_on_sales
+show_on_web
+show_price_on_web
+state
+stock_max
+stock_min
+subtotal_amt
+supplier_code
+tags
+tax_exempt
+tax_number
+thumbnail
+total
+total_amt
+trigger
+unit_weight
+units_by_package
+update
+use_sales_tax2
+user_code
+warranty_id
+web
+weeks
+weight
+weight_total
+with_accounts
+with_headers
+with_images
+xref_order_line_id
+years
+zip
+]==];
+
+/*
+word_list.gmatch(
+	"\"([^\"]+)\"",
+	function(m)
+	{
+		print(m);
+		return true;
+	}
+);
+*/
+
+word_list = word_list.split('\n');
+word_list.sort();
+//print(word_list.join("\n"));
+
+auto prefix_level = array(word_list.len());
+
+auto min(a,b) {return a < b ? a : b;}
+auto prev_word;
+
+foreach(idx, word in word_list)
+{
+	if(idx > 0)
+	{
+		auto i=0, len = min(prev_word.len(), word.len());
+		for(; i < len && (prev_word[i] == word[i]) ; ++i);
+		prefix_level[idx] = i;
+	}
+	else
+	{
+		prefix_level[idx] = 0;
+	}
+	prev_word = word;
+}
+
+foreach(idx, word in word_list)
+{
+	//if(prefix_level[idx] == 0)
+		print(prefix_level[idx], idx, word);
+}
+
+/*
+#include "/home/mingo/dev/SquiLu/SquiLu/samples/Trie.nut"
+
+var the_trie = new Trie({});
+
+foreach(word in word_list) the_trie.add(word);
+
+print(the_trie.contains("with_images"));
+*/
+
+/*
+#include "/home/mingo/dev/SquiLu/SquiLu/samples/perfect-hash.nut"
+
+var mywords = {};
+foreach(idx, word in word_list)
+{
+	mywords[word] <- idx+1;
+	//mywords[word] <- word;
+}
+
+var ph = perfect_hash_create(mywords);
+
+foreach(k,v in mywords)
+{
+	print(k,v, perfect_hash_lookup(ph[0], ph[1], k));
+}
+
+foreach(k,v in ph[0])
+{
+	print(k,v);
+}
+
+foreach(k,v in ph[1])
+{
+	print(k,v);
+}
+*/

+ 73 - 0
SquiLu/samples/test-sqlite-stmt-timing.nut

@@ -0,0 +1,73 @@
+auto db = SQLite3(":memory:");
+
+db.exec_dml("create table test(id integer primary key, value text)");
+auto stmt_insert = db.prepare("insert into test(value) values(?)");
+
+auto max_loop = 10000;
+auto start_time;
+
+start_time = os.clock();
+for(auto i=0; i < max_loop; ++i)
+{
+	stmt_insert.bind(1, "dad" + i);
+	stmt_insert.step();
+	stmt_insert.reset();
+}
+print("Time spent", os.clock() - start_time);
+db.exec_dml("delete from test");
+
+start_time = os.clock();
+for(auto i=0; i < max_loop; ++i)
+{
+	{
+		auto stmt_sr = db.stmt_scope_reset(stmt_insert);
+		stmt_insert.bind(1, "dad" + i);
+		stmt_insert.step();
+	}
+}
+print("Time spent", os.clock() - start_time);
+db.exec_dml("delete from test");
+
+start_time = os.clock();
+for(auto i=0; i < max_loop; ++i)
+{
+	stmt_insert.bind_exec("dad" + i);
+}
+print("Time spent", os.clock() - start_time);
+db.exec_dml("delete from test");
+
+start_time = os.clock();
+db.exec_dml("begin");
+for(auto i=0; i < max_loop; ++i)
+{
+	stmt_insert.bind(1, "dad" + i);
+	stmt_insert.step();
+	stmt_insert.reset();
+}
+print("Time spent", os.clock() - start_time);
+db.exec_dml("delete from test");
+db.exec_dml("commit");
+
+start_time = os.clock();
+db.exec_dml("begin");
+for(auto i=0; i < max_loop; ++i)
+{
+	{
+		auto stmt_sr = db.stmt_scope_reset(stmt_insert);
+		stmt_insert.bind(1, "dad" + i);
+		stmt_insert.step();
+	}
+}
+print("Time spent", os.clock() - start_time);
+db.exec_dml("delete from test");
+db.exec_dml("commit");
+
+start_time = os.clock();
+db.exec_dml("begin");
+for(auto i=0; i < max_loop; ++i)
+{
+	stmt_insert.bind_exec("dad" + i);
+}
+print("Time spent", os.clock() - start_time);
+db.exec_dml("delete from test");
+db.exec_dml("commit");