├── .gitignore ├── AUTHORS ├── CMakeLists.txt ├── LICENSE ├── README.rst ├── benchmark ├── _lib │ ├── benchmark.clv │ └── classes │ │ └── language.clv ├── run.clv ├── run.sh ├── tests │ ├── polynomial │ │ ├── info.txt │ │ ├── tespol.clv │ │ ├── tespol.java │ │ ├── tespol.php │ │ ├── tespol.py │ │ └── tespol.rb │ └── threads-single │ │ ├── info.txt │ │ ├── threads_001.c │ │ ├── threads_001.clv │ │ ├── threads_001.java │ │ ├── threads_001.lua │ │ ├── threads_001.php │ │ ├── threads_001.py │ │ └── threads_001.rb └── threads │ ├── threads_001.c │ ├── threads_001.clv │ ├── threads_001.java │ ├── threads_001.lua │ ├── threads_001.php │ ├── threads_001.py │ └── threads_001.rb ├── cmake ├── FindCLEVER.cmake ├── FindCMakeParseArguments.cmake └── FindRE2C.cmake ├── core ├── ast.cc ├── ast.h ├── astdump.h ├── asttransformer.h ├── astvisitor.cc ├── astvisitor.h ├── cexception.h ├── clever.cc ├── clever.h ├── codegen.cc ├── codegen.h ├── compiler.cc ├── compiler.h ├── cstring.cc ├── cstring.h ├── cthread.cc ├── cthread.h ├── driver.cc ├── driver.h ├── environment.cc ├── environment.h ├── evaluator.cc ├── evaluator.h ├── ir.h ├── irbuilder.h ├── location.hh ├── main.cc ├── modmanager.cc ├── modmanager.h ├── module.h ├── native_types.h ├── opcode.cc ├── opcode.h ├── parser.cc ├── parser.hh ├── parser.y ├── platform.h ├── position.hh ├── refcounted.h ├── resolver.cc ├── resolver.h ├── scanner.cc ├── scanner.h ├── scanner.re ├── scope.cc ├── scope.h ├── stack.hh ├── type.cc ├── type.h ├── user.h ├── value.cc ├── value.h ├── vm.cc └── vm.h ├── dependencies.cmake ├── environment.cmake ├── extra ├── testrunner.cc ├── testrunner.clv └── testrunner.h ├── modules.cmake ├── modules ├── db │ ├── CMakeLists.txt │ ├── db_forwarder.h │ ├── db_pkg.cc │ ├── db_pkg.h │ ├── mysql │ │ ├── CMakeLists.txt │ │ ├── cmysql.cc │ │ ├── cmysql.h │ │ ├── module.cc │ │ ├── module.h │ │ ├── mysql.cc │ │ └── mysql.h │ └── sqlite3 │ │ ├── CMakeLists.txt │ │ ├── module.cc │ │ ├── module.h │ │ ├── sqlite3.cc │ │ └── sqlite3.h ├── gui │ ├── CMakeLists.txt │ ├── gui_forwarder.h │ ├── gui_pkg.cc │ ├── gui_pkg.h │ └── ncurses │ │ ├── CMakeLists.txt │ │ ├── cncurses.cc │ │ ├── cncurses.h │ │ ├── module.cc │ │ ├── module.h │ │ ├── ncurses.cc │ │ └── ncurses.h └── std │ ├── CMakeLists.txt │ ├── clever │ ├── CMakeLists.txt │ ├── module.cc │ ├── module.h │ ├── type.cc │ └── type.h │ ├── collection │ ├── CMakeLists.txt │ ├── cqueue.cc │ ├── cqueue.h │ ├── cset.cc │ ├── cset.h │ ├── cstack.cc │ ├── cstack.h │ ├── module.cc │ └── module.h │ ├── concurrent │ ├── CMakeLists.txt │ ├── condition.cc │ ├── condition.h │ ├── module.cc │ ├── module.h │ ├── mutex.cc │ ├── mutex.h │ ├── sync.cc │ ├── sync.h │ ├── thread.cc │ └── thread.h │ ├── core │ ├── array.cc │ ├── array.h │ ├── bool.cc │ ├── bool.h │ ├── core.cc │ ├── core.h │ ├── double.cc │ ├── double.h │ ├── function.h │ ├── int.cc │ ├── int.h │ ├── map.cc │ ├── map.h │ ├── str.cc │ └── str.h │ ├── crypto │ ├── CMakeLists.txt │ ├── base64.h │ ├── crypto.cc │ ├── crypto.h │ ├── md5.cc │ └── md5.h │ ├── date │ ├── CMakeLists.txt │ ├── date.cc │ ├── date.h │ ├── module.cc │ └── module.h │ ├── events │ ├── CMakeLists.txt │ ├── events.cc │ └── events.h │ ├── fcgi │ ├── CMakeLists.txt │ ├── fcgi.cc │ ├── fcgi.clv │ ├── fcgi.h │ ├── server.cc │ └── server.h │ ├── ffi │ ├── CMakeLists.txt │ ├── ffi.cc │ ├── ffi.h │ ├── ffistruct.cc │ ├── ffistruct.h │ └── ffitypes.h │ ├── file │ ├── CMakeLists.txt │ ├── cfile.cc │ ├── cfile.h │ ├── file.cc │ └── file.h │ ├── getopt │ ├── CMakeLists.txt │ ├── module.cc │ └── module.h │ ├── io │ ├── CMakeLists.txt │ ├── io.cc │ ├── io.h │ ├── serializer.cc │ └── serializer.h │ ├── json │ ├── CMakeLists.txt │ ├── json.cc │ └── json.h │ ├── logging │ └── logger.clv │ ├── math │ ├── CMakeLists.txt │ ├── math.cc │ └── math.h │ ├── net │ ├── CMakeLists.txt │ ├── csocket.cc │ ├── csocket.h │ ├── net.cc │ ├── net.h │ ├── tcpsocket.cc │ └── tcpsocket.h │ ├── reflection │ ├── CMakeLists.txt │ ├── reflect.cc │ ├── reflect.h │ ├── reflection.cc │ └── reflection.h │ ├── regex │ ├── CMakeLists.txt │ ├── pcre.cc │ ├── pcre.h │ ├── regex.cc │ └── regex.h │ ├── std_forwarder.h │ ├── std_pkg.cc │ ├── std_pkg.h │ ├── sys │ ├── CMakeLists.txt │ ├── sys.cc │ └── sys.h │ └── unicode │ ├── CMakeLists.txt │ ├── string.cc │ ├── string.h │ ├── unicode.cc │ └── unicode.h ├── samples ├── bimap.clv ├── chronos │ └── sync.clv ├── graph.clv ├── json.clv ├── logging.clv └── wildX │ ├── engine │ ├── game.clv │ └── paint.clv │ └── wildX.clv ├── tests ├── .gitignore ├── db.sqlite3 │ └── test_001.test ├── lang │ ├── anon_001.test │ ├── anon_002.test │ ├── anon_003.test │ ├── array_001.test │ ├── array_002.test │ ├── array_003.test │ ├── array_004.test │ ├── array_005.test │ ├── array_006.test │ ├── array_007.test │ ├── array_008.test │ ├── array_009.test │ ├── array_010.test │ ├── array_011.test │ ├── array_012.test │ ├── array_014.test │ ├── array_015.test │ ├── array_016.test │ ├── array_017.test │ ├── array_018.testt │ ├── array_019.test │ ├── array_020.test │ ├── array_021.test │ ├── arrayiterator_001.test │ ├── arrayiterator_002.test │ ├── assign_001.test │ ├── assign_002.test │ ├── assign_003.test │ ├── assign_004.test │ ├── assign_005.test │ ├── break_001.test │ ├── class_001.test │ ├── class_002.test │ ├── class_003.test │ ├── class_004.test │ ├── class_005.test │ ├── class_006.test │ ├── class_007.test │ ├── closure_001.test │ ├── closure_002.test │ ├── const_001.test │ ├── const_002.test │ ├── const_003.test │ ├── continue_001.test │ ├── continue_002.test │ ├── fcall_001.test │ ├── fcall_002.test │ ├── fcall_003.test │ ├── fcall_004.test │ ├── fcall_005.test │ ├── fcall_006.test │ ├── fcall_007.test │ ├── fcall_008.test │ ├── fcall_009.test │ ├── fcall_010.test │ ├── fcall_011.test │ ├── fcall_012.test │ ├── fcall_013.test │ ├── fcall_014.test │ ├── fcall_015.test │ ├── fcall_016.test │ ├── fdecl_001.test │ ├── for_001.test │ ├── for_002.test │ ├── if_001.test │ ├── if_002.test │ ├── if_003.test │ ├── if_004.test │ ├── import_001.clv │ ├── import_001.test │ ├── import_002.test │ ├── import_003.test │ ├── instantiation_001.test │ ├── instantiation_002.test │ ├── map_001.test │ ├── map_002.test │ ├── map_003.test │ ├── map_004.test │ ├── mcall_001.test │ ├── mcall_002.test │ ├── operator_001.test │ ├── operator_002.test │ ├── operator_003.test │ ├── operator_004.test │ ├── operator_005.test │ ├── operator_006.test │ ├── operator_007.test │ ├── prop_access_001.test │ ├── prop_access_002.test │ ├── recursion_001.test │ ├── scope_001.test │ ├── scope_002.test │ ├── scope_003.test │ ├── smcall_001.test │ ├── smcall_002.test │ ├── smcall_003.test │ ├── smcall_004.test │ ├── static_001.test │ ├── static_002.test │ ├── string_001.test │ ├── string_002.test │ ├── string_003.test │ ├── string_004.test │ ├── string_005.test │ ├── string_006.test │ ├── string_007.test │ ├── string_008.test │ ├── subscript_001.test │ ├── subscript_002.test │ ├── subscript_003.test │ ├── subscript_004.test │ ├── subscript_005.test │ ├── switch_001.test │ ├── switch_002.test │ ├── switch_003.test │ ├── switch_004.test │ ├── switch_005.test │ ├── switch_006.test │ ├── switch_007.test │ ├── switch_008.test │ ├── switch_009.test │ ├── this_001.test │ ├── this_002.test │ ├── this_003.test │ ├── this_004.test │ ├── this_005.test │ ├── this_006.test │ ├── this_007.test │ ├── try_001.test │ ├── try_002.test │ ├── try_003.test │ ├── try_004.test │ ├── try_005.test │ ├── variadic_001.test │ ├── variadic_002.test │ ├── variadic_003.test │ ├── variadic_005.test │ ├── variadic_006.test │ ├── while_001.test │ └── while_002.test ├── samples │ ├── factorial.test │ └── graph.test ├── std.collection │ ├── collection_001.test │ ├── collection_002.test │ ├── priority_queue_001.test │ ├── queue_001.test │ ├── queue_002.test │ ├── set_001.test │ ├── set_002.test │ ├── set_003.test │ ├── set_004.test │ ├── set_005.test │ ├── set_006.test │ ├── set_007.test │ ├── stack_001.test │ └── stack_002.test ├── std.concurrent │ ├── condition_001.test │ ├── mutex_001.test │ ├── thread_001.test │ ├── thread_002.test │ └── thread_003.test ├── std.crypto │ ├── base64_001.test │ └── md5_001.test ├── std.date │ └── date_001.test ├── std.events │ ├── events_001.test │ └── events_002.test ├── std.ffi │ ├── ffi_001.c │ ├── ffi_001.sh │ └── ffi_001.test ├── std.file │ ├── file_001.test │ ├── file_002.test │ └── file_003.test ├── std.math │ └── pi_001.test ├── std.reflection │ ├── reflect_001.test │ ├── reflect_getnumargs_001.test │ ├── reflect_getnumreqargs_001.test │ ├── reflect_isarray_001.test │ ├── reflect_isdouble_001.test │ ├── reflect_isfunction_001.test │ ├── reflect_isint_001.test │ ├── reflect_ismap_001.test │ ├── reflect_isstring_001.test │ ├── reflect_isvariadic_001.test │ └── type_001.test ├── std.regex │ ├── error_001.test │ ├── group_001.test │ └── matches_001.test └── std.unicode │ └── unicode_001.test └── win32 ├── dirent.h ├── win32.cc └── win32.h /.gitignore: -------------------------------------------------------------------------------- 1 | CMakeFiles/ 2 | Makefile 3 | cmake_install.cmake 4 | CMakeCache.txt 5 | build* 6 | extra/testrunner 7 | clever 8 | test.txt 9 | update.sh 10 | make-c++11.sh 11 | tests/*/*.out 12 | *.tmp 13 | *.dSYM 14 | *~ 15 | *.d 16 | *.o 17 | *.so 18 | *.dll 19 | *.a 20 | *.class 21 | *.exe 22 | *.lib 23 | *.manifest 24 | gmon.out 25 | testrunner 26 | CPackConfig.cmake 27 | CPackSourceConfig.cmake 28 | _CPack_Packages/ 29 | install_manifest.txt 30 | a.clh 31 | a.clv 32 | a.txt 33 | array.clv 34 | const.clv 35 | extra/.DS_Store 36 | extra/darwin10.supp 37 | samples/.DS_Store 38 | samples/wgraph.clh 39 | *.dylib 40 | callgrind* 41 | benchmark/threads/threads_001.class 42 | -------------------------------------------------------------------------------- /AUTHORS: -------------------------------------------------------------------------------- 1 | Clever Team 2 | ================================================================================ 3 | 4 | In this file we'll try to log the name of everyone who have contributed to 5 | the Clever project. 6 | 7 | -------------------------------------------------------------------------------- 8 | Core 9 | -------------------------------------------------------------------------------- 10 | 11 | + Language Design and Implementation 12 | - Felipe Pena - felipe at clever-lang.org 13 | - Higor Eurípedes - higor at clever-lang.org 14 | - Murilo Adriano Vasconcelos - murilo at clever-lang.org 15 | - Péricles Lopes Machado - pericles at clever-lang.org 16 | 17 | + Build system 18 | - Higor Eurípedes - higor at clever-lang.org 19 | 20 | + Windows and Haiku port 21 | - Ricardo Gomes da Silva - ricardo at clever-lang.org 22 | 23 | + Benchmark script, testing and module improvements 24 | - Pedro Faria 25 | 26 | -------------------------------------------------------------------------------- 27 | Modules 28 | -------------------------------------------------------------------------------- 29 | 30 | + Collection module 31 | - Felipe Pena, Péricles Lopes Machado 32 | 33 | + Concurrent module 34 | - Joe Watkins, Péricles Lopes Machado 35 | 36 | + Crypto module 37 | - Felipe Pena 38 | 39 | + Date module 40 | - Joe Watkins 41 | 42 | + Events module 43 | - Péricles Lopes Machado 44 | 45 | + FastCGI module 46 | - Joe Watkins 47 | 48 | + File module 49 | - Murilo Adriano Vasconcelos 50 | 51 | + FFI module 52 | - Péricles Lopes Machado 53 | 54 | + JSON module 55 | - Murilo Adriano Vasconcelos 56 | 57 | + Math module 58 | - Felipe Pena 59 | 60 | + MySQL module 61 | - Henrique M. Decaria 62 | 63 | + NCurses 64 | - Péricles Lopes Machado 65 | 66 | + Net module 67 | - Ricardo Gomes da Silva, Felipe Pena 68 | 69 | + Reflection module 70 | - Felipe Pena 71 | 72 | + Regex module 73 | - Felipe Pena 74 | 75 | + SQLite3 module 76 | - Felipe Pena 77 | 78 | + Sys module 79 | - Felipe Pena 80 | 81 | + Unicode module 82 | - Joe Watkins 83 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | Clever programming language 2 | Copyright (c) 2011-2013 Clever Team 3 | 4 | Permission is hereby granted, free of charge, to any person 5 | obtaining a copy of this software and associated documentation 6 | files (the "Software"), to deal in the Software without 7 | restriction, including without limitation the rights to use, 8 | copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the 10 | Software is furnished to do so, subject to the following 11 | conditions: 12 | The above copyright notice and this permission notice shall be 13 | included in all copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, 16 | EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES 17 | OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND 18 | NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT 19 | HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, 20 | WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING 21 | FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR 22 | OTHER DEALINGS IN THE SOFTWARE. 23 | -------------------------------------------------------------------------------- /benchmark/_lib/classes/language.clv: -------------------------------------------------------------------------------- 1 | import std.regex.*; 2 | 3 | class Language 4 | { 5 | var name; 6 | var command; 7 | var check_cmd; 8 | var version_er; 9 | var extension; 10 | var version; 11 | var is_ok; 12 | 13 | function Language(name, command, check_cmd, version_er, extension) 14 | { 15 | this.name = name; 16 | this.command = command; 17 | this.check_cmd = check_cmd; 18 | this.version_er = version_er; 19 | this.extension = extension; 20 | this.is_ok = false; 21 | } 22 | 23 | function check() { 24 | var version_str = _exec(this.check_cmd); 25 | var re = Regex.new(this.version_er); 26 | if (!re.match(version_str)) { 27 | return false; 28 | } 29 | 30 | this.version = re.group(1); 31 | this.is_ok = true; 32 | 33 | return true; 34 | } 35 | } 36 | -------------------------------------------------------------------------------- /benchmark/run.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | echo "Running threads benchmark..." 4 | 5 | cd threads 6 | echo "threads/threads_001.clv:" 7 | ../../clever threads_001.clv 8 | echo "[OK]" 9 | 10 | echo "threads/threads_001.py: [python version]" 11 | python threads_001.py 12 | echo "[OK]" 13 | 14 | echo "threads/threads_001.lua: [lua version]" 15 | lua threads_001.lua 16 | echo "[OK]" 17 | 18 | echo "threads/threads_001.php: [php version]" 19 | php threads_001.php 20 | echo "[OK]" 21 | 22 | echo "threads/threads_001.rb: [ruby version]" 23 | ruby threads_001.rb 24 | echo "[OK]" 25 | 26 | echo "threads/threads_001.c: [C version]" 27 | gcc -O2 -o threads_001.exe threads_001.c 28 | ./threads_001.exe 29 | echo "[OK]" 30 | 31 | echo "threads/threads_001.java: [Java version]" 32 | javac threads_001.java 33 | java threads_001 34 | 35 | -------------------------------------------------------------------------------- /benchmark/tests/polynomial/info.txt: -------------------------------------------------------------------------------- 1 | Computes the same 100-term polynomial 100,000 times inside a single function body 2 | ref: http://dan.corlan.net/bench.html -------------------------------------------------------------------------------- /benchmark/tests/polynomial/tespol.clv: -------------------------------------------------------------------------------- 1 | import std.io.*; 2 | 3 | function dopoly(x) { 4 | var pol = []; 5 | var mu = 10.0; 6 | var s = 0.0; 7 | 8 | for (var j = 0; j<100; j++) { 9 | mu = (mu + 2.0) / 2.0; 10 | pol.append(mu); 11 | } 12 | 13 | for (var j=0; j<100; j++) { 14 | s = x*s + pol[j]; 15 | } 16 | 17 | return s; 18 | } 19 | 20 | var n = 100000; 21 | var x = 0.2; 22 | var pu = 0.0; 23 | 24 | for(var i=0; i 2 | #include 3 | #include 4 | 5 | int main() 6 | { 7 | 8 | time_t t0 = clock(); 9 | 10 | int L = 10000000; 11 | long long acc = 0; 12 | int ini = 0, fim = 2 * L; 13 | while (ini <= fim) acc += ini++; 14 | 15 | time_t t1 = clock(); 16 | 17 | printf("C\n"); 18 | printf("%lld\n", acc); 19 | return 0; 20 | } 21 | 22 | -------------------------------------------------------------------------------- /benchmark/tests/threads-single/threads_001.clv: -------------------------------------------------------------------------------- 1 | import std.io.*; 2 | 3 | const L = 10000000; 4 | 5 | function proc(ini, fim) 6 | { 7 | var acc = 0, i = ini; 8 | while (i <= fim) { 9 | acc = acc + i++; 10 | } 11 | return acc; 12 | } 13 | 14 | 15 | var r2 = proc(0, 2 * L); 16 | 17 | println("clever"); 18 | println(r2); 19 | -------------------------------------------------------------------------------- /benchmark/tests/threads-single/threads_001.java: -------------------------------------------------------------------------------- 1 | public class threads_001 { 2 | public static void main(String[] args) { 3 | //double t0 = System.currentTimeMillis(); 4 | long acc = 0; 5 | int L = 10000000; 6 | int n = 2 * L; 7 | 8 | for (int i = 0; i <= n; ++i) acc += i; 9 | 10 | //double t1 = System.currentTimeMillis(); 11 | //System.out.println("Time elapsed single-thread version Java: " + (t1 - t0) / 1000); 12 | System.out.println("Java"); 13 | System.out.println(acc); 14 | } 15 | } 16 | -------------------------------------------------------------------------------- /benchmark/tests/threads-single/threads_001.lua: -------------------------------------------------------------------------------- 1 | 2 | function process(ini, fim) 3 | local acc = 0; 4 | local i = ini; 5 | 6 | while (i <= fim) do 7 | acc = acc + i; 8 | i = i+1; 9 | end 10 | 11 | return acc; 12 | end 13 | 14 | local L = 10000000; 15 | print("Lua"); 16 | print(string.format('%d',process(0, 2 * L))); 17 | -------------------------------------------------------------------------------- /benchmark/tests/threads-single/threads_001.php: -------------------------------------------------------------------------------- 1 | 2 | #include 3 | #include 4 | 5 | int main() 6 | { 7 | 8 | time_t t0 = clock(); 9 | 10 | int L = 10000000; 11 | long long acc = 0; 12 | int ini = 0, fim = 2 * L; 13 | while (ini <= fim) acc += ini++; 14 | 15 | time_t t1 = clock(); 16 | 17 | printf("Time elapsed single-thread C: %.2lf\n", (float)(t1 - t0) / CLOCKS_PER_SEC); 18 | printf("Result : %lld\n", acc); 19 | return 0; 20 | } 21 | 22 | -------------------------------------------------------------------------------- /benchmark/threads/threads_001.clv: -------------------------------------------------------------------------------- 1 | import std.sys.*; 2 | import std.io.*; 3 | import std.concurrent.*; 4 | 5 | const L = 10000000; 6 | 7 | function proc(ini, fim) 8 | { 9 | var acc = 0, i = ini; 10 | while (i <= fim) { 11 | acc = acc + i++; 12 | } 13 | return acc; 14 | } 15 | 16 | var thread = [Thread.new(proc, 0, L), Thread.new(proc, L + 1, 2 * L)]; 17 | 18 | var tini = time(); 19 | thread.each(function(z){z.start();}); 20 | thread.each(function(z){z.wait();}); 21 | var tfim = time(); 22 | 23 | var r1 = thread[0].result() + thread[1].result(); 24 | var t1 = (tfim - tini) / 2; 25 | 26 | tini = time(); 27 | var r2 = proc(0, 2 * L); 28 | tfim = time(); 29 | 30 | var t2 = (tfim - tini); 31 | 32 | printf("Time elapsed single-thread version clever: \1 \n", t2); 33 | printf("Time elapsed multi-thread version clever: \1 \n", t1); 34 | 35 | if (r2 == r1) { 36 | printf("Relative time difference: \1 %\n", 100 * (t2-t1) / t2); 37 | printf("Result: \1\n", r1); 38 | } else { 39 | printf("Test threads_001.clv failed!\n"); 40 | } 41 | 42 | -------------------------------------------------------------------------------- /benchmark/threads/threads_001.java: -------------------------------------------------------------------------------- 1 | public class threads_001 { 2 | public static void main(String[] args) { 3 | double t0 = System.currentTimeMillis(); 4 | long acc = 0; 5 | int L = 10000000; 6 | int n = 2 * L; 7 | 8 | for (int i = 0; i <= n; ++i) acc += i; 9 | 10 | double t1 = System.currentTimeMillis(); 11 | System.out.println("Time elapsed single-thread version Java: " + (t1 - t0) / 1000); 12 | System.out.println("Result: " + acc); 13 | } 14 | } 15 | -------------------------------------------------------------------------------- /benchmark/threads/threads_001.lua: -------------------------------------------------------------------------------- 1 | 2 | function process(ini, fim) 3 | local acc = 0; 4 | local i = ini; 5 | 6 | while (i <= fim) do 7 | acc = acc + i; 8 | i = i+1; 9 | end 10 | 11 | return acc; 12 | end 13 | 14 | local t0 = os.clock(); 15 | local L = 10000000; 16 | print(string.format('Result : %d',process(0, 2 * L))); 17 | local t2 = os.clock(); 18 | print(string.format('Time elapsed single-thread lua: %.2f', t2 - t0)); 19 | 20 | -------------------------------------------------------------------------------- /benchmark/threads/threads_001.php: -------------------------------------------------------------------------------- 1 | 12 | #include "core/value.h" 13 | #include "modules/std/core/str.h" 14 | 15 | namespace clever { 16 | // make sure you supply at least one value 17 | #define clever_throw(...) clever->exception->setException(__VA_ARGS__) 18 | 19 | class CException { 20 | public: 21 | CException() 22 | : m_exception(NULL) {} 23 | 24 | ~CException() { 25 | clever_delref(m_exception); 26 | } 27 | 28 | void clear() { m_exception = NULL; } 29 | 30 | Value* getException() const { return m_exception; } 31 | 32 | bool hasException() const { return m_exception != NULL; } 33 | 34 | void setException(const char* format, ...) { 35 | std::ostringstream out; 36 | va_list args; 37 | 38 | va_start(args, format); 39 | vsprintf(out, format, args); 40 | 41 | if (UNEXPECTED(m_exception == NULL)) { 42 | m_exception = new Value; 43 | } 44 | m_exception->setStr(new StrObject(out.str())); 45 | } 46 | 47 | void setException(Value* exception) { 48 | if (UNEXPECTED(m_exception == NULL)) { 49 | m_exception = new Value; 50 | } 51 | m_exception->copy(exception); 52 | } 53 | private: 54 | Value* m_exception; 55 | 56 | DISALLOW_COPY_AND_ASSIGN(CException); 57 | }; 58 | 59 | } // clever 60 | 61 | #endif // CLEVER_CEXCEPTION_H 62 | -------------------------------------------------------------------------------- /core/cstring.cc: -------------------------------------------------------------------------------- 1 | /** 2 | * Clever programming language 3 | * Copyright (c) Clever Team 4 | * 5 | * This file is distributed under the MIT license. See LICENSE for details. 6 | */ 7 | 8 | #include "core/cstring.h" 9 | 10 | namespace clever { 11 | 12 | CStringTable* g_cstring_tbl = new CStringTable; 13 | 14 | } // clever 15 | -------------------------------------------------------------------------------- /core/cthread.h: -------------------------------------------------------------------------------- 1 | /** 2 | * Clever programming language 3 | * Copyright (c) Clever Team 4 | * 5 | * This file is distributed under the MIT license. See LICENSE for details. 6 | */ 7 | 8 | #ifndef CLEVER_CTHREAD_H 9 | #define CLEVER_CTHREAD_H 10 | 11 | #ifndef CLEVER_WIN32 12 | # include 13 | #else 14 | # include 15 | #endif 16 | #include "core/clever.h" 17 | 18 | namespace clever { 19 | 20 | class CMutex { 21 | public: 22 | CMutex(); 23 | 24 | ~CMutex(); 25 | 26 | bool lock(); 27 | bool unlock(); 28 | bool trylock(); 29 | 30 | 31 | #ifndef CLEVER_WIN32 32 | pthread_mutex_t m_mut; 33 | #else 34 | HANDLE m_mut; 35 | #endif 36 | 37 | private: 38 | DISALLOW_COPY_AND_ASSIGN(CMutex); 39 | }; 40 | 41 | #ifndef CLEVER_WIN32 42 | # define CLEVER_THREAD_FUNC(name) void* name(void *arg) 43 | typedef void* (*ThreadFunc)(void*); 44 | #else 45 | typedef DWORD (*ThreadFunc)(LPVOID); 46 | # define CLEVER_THREAD_FUNC(name) DWORD name(void *arg) 47 | #endif 48 | 49 | class CThread { 50 | public: 51 | CThread() 52 | : m_is_running(false) {} 53 | 54 | ~CThread() { 55 | if (m_is_running) { 56 | wait(); 57 | } 58 | } 59 | 60 | void create(ThreadFunc, void*); 61 | 62 | bool isRunning() { return m_is_running; } 63 | 64 | int wait(); 65 | 66 | private: 67 | bool m_is_running; 68 | #ifndef CLEVER_WIN32 69 | pthread_t t_handler; 70 | #else 71 | HANDLE t_handler; 72 | #endif 73 | DISALLOW_COPY_AND_ASSIGN(CThread); 74 | }; 75 | 76 | class CCondition { 77 | public: 78 | CCondition(); 79 | 80 | ~CCondition(); 81 | 82 | bool signal(); 83 | bool broadcast(); 84 | bool wait(CMutex&); 85 | 86 | private: 87 | pthread_cond_t condition; 88 | }; 89 | 90 | } // clever 91 | 92 | #endif // CLEVER_CTHREAD_H 93 | -------------------------------------------------------------------------------- /core/environment.cc: -------------------------------------------------------------------------------- 1 | /** 2 | * Clever programming language 3 | * Copyright (c) Clever Team 4 | * 5 | * This file is distributed under the MIT license. See LICENSE for details. 6 | */ 7 | 8 | #include "core/environment.h" 9 | #include "core/value.h" 10 | 11 | namespace clever { 12 | 13 | Environment* Environment::clone() 14 | { 15 | Environment* env = new Environment(m_outer, m_scoped); 16 | 17 | env->m_ret_val = m_ret_val; 18 | env->m_ret_addr = m_ret_addr; 19 | 20 | if (m_temp) 21 | env->m_temp = m_temp->clone(); 22 | 23 | env->m_data.reserve(m_data.size()); 24 | 25 | for (size_t i = 0, size = m_data.size(); i < size; ++i) 26 | env->pushValue(m_data[i]->clone()); 27 | 28 | return env; 29 | } 30 | 31 | Environment* Environment::activate(Environment* outer) 32 | { 33 | Environment* env = clone(); 34 | 35 | if (outer) { 36 | clever_delref(env->m_outer); 37 | env->m_outer = outer; 38 | clever_addref(env->m_outer); 39 | } 40 | 41 | env->m_scoped = false; 42 | 43 | return env; 44 | } 45 | 46 | Value* Environment::getValue(const ValueOffset& offset) const 47 | { 48 | if (offset.first == 0) { // local 49 | clever_assert(offset.second < m_data.size(), 50 | "`offset.second` must be within `m_data` limits."); 51 | 52 | return m_data[offset.second]; 53 | } 54 | 55 | size_t depth = offset.first; 56 | Environment* env = m_outer; 57 | 58 | while (env && --depth) { 59 | env = env->m_outer; 60 | } 61 | 62 | clever_assert(depth == 0, 63 | "`depth` must be zero, otherwise we failed to find the environment."); 64 | clever_assert(offset.second < env->m_data.size(), 65 | "`offset.second` must be within `m_data` bounds."); 66 | clever_assert_not_null(env); 67 | 68 | return env->m_data[offset.second]; 69 | } 70 | 71 | } // clever 72 | -------------------------------------------------------------------------------- /core/evaluator.cc: -------------------------------------------------------------------------------- 1 | /** 2 | * Clever programming language 3 | * Copyright (c) Clever Team 4 | * 5 | * This file is distributed under the MIT license. See LICENSE for details. 6 | */ 7 | 8 | #include "core/evaluator.h" 9 | 10 | namespace clever { namespace ast { 11 | 12 | Node* Evaluator::transform(Node* node) { 13 | return node; 14 | } 15 | 16 | Node* Evaluator::transform(NodeArray* node) { 17 | NodeList nlist(node->getNodes()); 18 | NodeList::iterator cur(nlist.begin()), end(nlist.end()); 19 | 20 | node->getNodes().clear(); 21 | 22 | while (cur != end) { 23 | *cur = (*cur)->accept(*this); 24 | 25 | if (*cur) { 26 | node->append(*cur); 27 | } 28 | 29 | ++cur; 30 | } 31 | 32 | return node; 33 | } 34 | 35 | Node* Evaluator::transform(VariableDecl* node) { 36 | if (node->hasAssignment()) { 37 | node->setAssignment(static_cast( 38 | node->getAssignment()->accept(*this)) 39 | ); 40 | } 41 | 42 | return node; 43 | } 44 | 45 | Node* Evaluator::transform(Assignment* node) { 46 | node->setRhs(node->getRhs()->accept(*this)); 47 | 48 | return node; 49 | } 50 | 51 | Node* Evaluator::transform(Arithmetic* node) { 52 | 53 | if (node->getLhs()->getIntLit() && node->getRhs()->getIntLit()) { 54 | long lhs, rhs, val = 0; 55 | 56 | lhs = node->getLhs()->getIntLit()->getValue(); 57 | rhs = node->getRhs()->getIntLit()->getValue(); 58 | 59 | switch (node->getOperator()) { 60 | case Arithmetic::MOP_ADD: val = lhs + rhs; break; 61 | case Arithmetic::MOP_SUB: val = lhs - rhs; break; 62 | case Arithmetic::MOP_MUL: val = lhs * rhs; break; 63 | case Arithmetic::MOP_DIV: val = lhs / rhs; break; 64 | case Arithmetic::MOP_MOD: val = lhs % rhs; break; 65 | } 66 | 67 | Node* tnode = new IntLit(val, node->getLocation()); 68 | node->delRef(); 69 | 70 | return tnode; 71 | } 72 | 73 | return node; 74 | } 75 | 76 | }} 77 | -------------------------------------------------------------------------------- /core/evaluator.h: -------------------------------------------------------------------------------- 1 | /** 2 | * Clever programming language 3 | * Copyright (c) Clever Team 4 | * 5 | * This file is distributed under the MIT license. See LICENSE for details. 6 | */ 7 | 8 | #ifndef CLEVER_EVALUATOR_H 9 | #define CLEVER_EVALUATOR_H 10 | 11 | #include "core/asttransformer.h" 12 | 13 | namespace clever { namespace ast { 14 | 15 | class Evaluator: public Transformer { 16 | public: 17 | Evaluator() 18 | : Transformer() {} 19 | 20 | ~Evaluator() {} 21 | 22 | virtual Node* transform(Node* node); 23 | virtual Node* transform(NodeArray* node); 24 | virtual Node* transform(VariableDecl* node); 25 | virtual Node* transform(Assignment* node); 26 | virtual Node* transform(Arithmetic* node); 27 | }; 28 | 29 | }} 30 | 31 | #endif // CLEVER_EVALUATOR_H 32 | -------------------------------------------------------------------------------- /core/ir.h: -------------------------------------------------------------------------------- 1 | /** 2 | * Clever programming language 3 | * Copyright (c) Clever Team 4 | * 5 | * This file is distributed under the MIT license. See LICENSE for details. 6 | */ 7 | 8 | #ifndef CLEVER_IR_H 9 | #define CLEVER_IR_H 10 | 11 | #include 12 | #include "core/opcode.h" 13 | #include "core/environment.h" 14 | #include "core/location.hh" 15 | 16 | namespace clever { 17 | 18 | class Value; 19 | 20 | enum OperandType { 21 | UNUSED, // Operand is not used 22 | FETCH_VAR, // For fetching a variables 23 | FETCH_CONST, // For fetching a constant 24 | FETCH_TMP, // For fetching a temporary value 25 | JMP_ADDR // For instr addr 26 | }; 27 | 28 | struct Operand { 29 | OperandType op_type; 30 | ValueOffset voffset; 31 | size_t jmp_addr; 32 | 33 | Operand() 34 | : op_type(UNUSED), voffset(0,0), jmp_addr(0) {} 35 | 36 | Operand(OperandType _op_type) 37 | : op_type(_op_type), voffset(0,0), jmp_addr(0) {} 38 | 39 | Operand(OperandType op_type_, const ValueOffset& voffset_) 40 | : op_type(op_type_), voffset(voffset_), jmp_addr(0) {} 41 | 42 | Operand(OperandType op_type_, size_t jmp_addr_) 43 | : op_type(op_type_), voffset(0,0), jmp_addr(jmp_addr_) {} 44 | }; 45 | 46 | /// Intermediate representation 47 | struct IR { 48 | IR() 49 | : opcode(OP_HALT) {} 50 | 51 | explicit IR(Opcode _op) 52 | : opcode(_op) {} 53 | 54 | IR(Opcode _op, Operand _op1) 55 | : opcode(_op), op1(_op1) {} 56 | 57 | IR(Opcode _op, Operand _op1, Operand _op2) 58 | : opcode(_op), op1(_op1), op2(_op2) {} 59 | 60 | Opcode opcode; 61 | Operand op1, op2, result; 62 | location loc; 63 | }; 64 | 65 | // Deque of VM instructions 66 | typedef std::deque IRVector; 67 | 68 | } // clever 69 | 70 | #endif // CLEVER_IR_H 71 | -------------------------------------------------------------------------------- /core/modmanager.h: -------------------------------------------------------------------------------- 1 | /** 2 | * Clever programming language 3 | * Copyright (c) Clever Team 4 | * 5 | * This file is distributed under the MIT license. See LICENSE for details. 6 | */ 7 | 8 | #ifndef CLEVER_MODMANAGER_H 9 | #define CLEVER_MODMANAGER_H 10 | 11 | #ifdef CLEVER_MSVC 12 | #include 13 | #else 14 | #include 15 | #endif 16 | #include 17 | #include "core/module.h" 18 | #include "core/ast.h" 19 | 20 | namespace clever { 21 | 22 | class Value; 23 | class Environment; 24 | class Driver; 25 | 26 | /// Package manager 27 | class ModManager { 28 | public: 29 | enum ImportKind { 30 | NONE = 0, 31 | TYPE = 1<<0, 32 | FUNCTION = 1<<1, 33 | ALL = TYPE | FUNCTION, 34 | NAMESPACE = 1<<2 35 | }; 36 | 37 | ModManager(Driver* driver) 38 | : m_driver(driver), m_user(NULL) {} 39 | 40 | ~ModManager() {} 41 | 42 | /// Initialization routine 43 | void init(); 44 | 45 | /// Shutdown routine 46 | void shutdown(); 47 | 48 | void setIncludePath(const std::string& path) { m_include_path = path; } 49 | 50 | Module* getUserModule() const { return m_user; } 51 | 52 | /// Adds a new package to the map 53 | void addModule(const std::string&, Module*); 54 | 55 | /// Imports the module to the current scope 56 | ast::Node* importModule(Scope*, const std::string&, 57 | size_t = ModManager::ALL, const CString* = NULL) const; 58 | 59 | ast::Node* importFile(Scope*, const std::string&, 60 | size_t = ModManager::ALL, const CString* = NULL) const; 61 | 62 | void loadVar(Scope*, const CString*, Value*) const; 63 | void loadModule(Scope*, Module*, size_t, const CString*) const; 64 | void loadModuleContent(Scope*, Module*, size_t, const CString*, const std::string&) const; 65 | void loadFunction(Scope*, const std::string&, Function*) const; 66 | void loadType(Scope*, const std::string&, Type*) const; 67 | private: 68 | Driver* m_driver; 69 | ModuleMap m_mods; 70 | Module* m_user; 71 | std::string m_include_path; 72 | }; 73 | 74 | } // clever 75 | 76 | #endif // CLEVER_MODMANAGER_H 77 | -------------------------------------------------------------------------------- /core/native_types.h: -------------------------------------------------------------------------------- 1 | /** 2 | * Clever programming language 3 | * Copyright (c) Clever Team 4 | * 5 | * This file is distributed under the MIT license. See LICENSE for details. 6 | */ 7 | 8 | #ifndef CLEVER_NATIVE_TYPES_H 9 | #define CLEVER_NATIVE_TYPES_H 10 | 11 | #include "modules/std/core/int.h" 12 | #include "modules/std/core/double.h" 13 | #include "modules/std/core/str.h" 14 | #include "modules/std/core/function.h" 15 | #include "modules/std/core/bool.h" 16 | #include "modules/std/core/array.h" 17 | #include "modules/std/core/map.h" 18 | 19 | #endif // CLEVER_NATIVE_TYPES_H 20 | -------------------------------------------------------------------------------- /core/resolver.h: -------------------------------------------------------------------------------- 1 | /** 2 | * Clever programming language 3 | * Copyright (c) Clever Team 4 | * 5 | * This file is distributed under the MIT license. See LICENSE for details. 6 | */ 7 | 8 | #ifndef CLEVER_RESOLVER_H 9 | #define CLEVER_RESOLVER_H 10 | 11 | #include "core/astvisitor.h" 12 | #include "core/module.h" 13 | 14 | namespace clever { 15 | class ModManager; 16 | class Scope; 17 | class Environment; 18 | class Type; 19 | } 20 | 21 | namespace clever { namespace ast { 22 | 23 | class Resolver: public Visitor { 24 | public: 25 | Resolver(const ModManager&, const std::string&); 26 | 27 | ~Resolver() {} 28 | 29 | void initGlobalScope(); 30 | 31 | Scope* getSymTable() const { return m_symtable; } 32 | 33 | Environment* getGlobalEnv() const { 34 | clever_assert(m_stack.size() == 1, 35 | "There must be only one entry on the stack"); 36 | 37 | return m_stack.top(); 38 | } 39 | 40 | virtual void visit(Block*); 41 | virtual void visit(VariableDecl*); 42 | virtual void visit(FunctionDecl*); 43 | virtual void visit(Ident*); 44 | virtual void visit(Type*); 45 | virtual void visit(Import*); 46 | virtual void visit(Catch*); 47 | virtual void visit(ClassDef*); 48 | virtual void visit(AttrDecl*); 49 | virtual void visit(For*); 50 | virtual void visit(ForEach*); 51 | private: 52 | const ModManager& m_modmanager; 53 | const std::string& m_ns_name; 54 | Scope* m_symtable; 55 | Scope* m_scope; 56 | std::stack m_stack; 57 | Module* m_mod; 58 | clever::Type* m_class; 59 | const Function* m_func; 60 | 61 | DISALLOW_COPY_AND_ASSIGN(Resolver); 62 | }; 63 | 64 | }} // clever::ast 65 | 66 | #endif // CLEVER_RESOLVER_H 67 | -------------------------------------------------------------------------------- /core/scanner.h: -------------------------------------------------------------------------------- 1 | /** 2 | * Clever programming language 3 | * Copyright (c) Clever Team 4 | * 5 | * This file is distributed under the MIT license. See LICENSE for details. 6 | */ 7 | 8 | #ifndef CLEVER_SCANNER_H 9 | #define CLEVER_SCANNER_H 10 | 11 | #include "core/clever.h" 12 | 13 | namespace clever { 14 | 15 | enum YYCONDTYPE { 16 | yycINITIAL, 17 | yycST_COMMENT, 18 | yycST_MULTILINE_COMMENT, 19 | yycST_END_OF_SCRIPT 20 | }; 21 | 22 | #define YYGETCONDITION() s.state 23 | #define YYSETCONDITION(x) s.state = yyc##x 24 | 25 | #define YYCTYPE unsigned char 26 | #define YYMARKER s.ctx 27 | #define YYCTXMARKER s.ctx 28 | #define YYCURSOR cursor 29 | #define YYLIMIT s.yylimit 30 | 31 | #define SKIP() s.cur = s.yylex + 1; goto next_token; 32 | #define RET(i) s.cur = cursor; return i; 33 | 34 | class ScannerState { 35 | public: 36 | ScannerState() 37 | : state(0) {} 38 | 39 | ~ScannerState() {} 40 | 41 | void set_cursor(const unsigned char* cursor) { cur = cursor; } 42 | void set_limit(const unsigned char* limit) { yylimit = limit; } 43 | 44 | int state; 45 | const unsigned char *cur, *yylex, *ctx, *yylimit; 46 | 47 | std::string& getSource() {return m_source; } 48 | private: 49 | std::string m_source; 50 | 51 | DISALLOW_COPY_AND_ASSIGN(ScannerState); 52 | }; 53 | 54 | } // clever 55 | 56 | #endif // CLEVER_SCANNER_H 57 | -------------------------------------------------------------------------------- /core/user.h: -------------------------------------------------------------------------------- 1 | /** 2 | * Clever programming language 3 | * Copyright (c) Clever Team 4 | * 5 | * This file is distributed under the MIT license. See LICENSE for details. 6 | */ 7 | 8 | #ifndef CLEVER_USER_H 9 | #define CLEVER_USER_H 10 | 11 | #include "core/module.h" 12 | #include "core/type.h" 13 | #include "core/cstring.h" 14 | 15 | namespace clever { 16 | 17 | class Environment; 18 | 19 | // User object representation 20 | class UserObject : public TypeObject { 21 | public: 22 | UserObject() 23 | : m_env(NULL) {} 24 | 25 | ~UserObject() {} 26 | 27 | void setEnvironment(Environment* env) { m_env = env; } 28 | Environment* getEnvironment() const { return m_env; } 29 | private: 30 | Environment* m_env; 31 | 32 | DISALLOW_COPY_AND_ASSIGN(UserObject); 33 | }; 34 | 35 | // User type representation 36 | class UserType : public Type { 37 | public: 38 | UserType(const CString* name) 39 | : Type(*name, USER_TYPE), m_env(NULL) {} 40 | 41 | ~UserType() {} 42 | 43 | virtual void init() { 44 | setConstructor((MethodPtr)&UserType::ctor); 45 | } 46 | 47 | void setEnvironment(Environment* env) { m_env = env; } 48 | Environment* getEnvironment() const { return m_env; } 49 | 50 | CLEVER_METHOD(ctor) { 51 | result->setObj(this, new UserObject); 52 | } 53 | private: 54 | Environment* m_env; 55 | 56 | DISALLOW_COPY_AND_ASSIGN(UserType); 57 | }; 58 | 59 | // User module representation 60 | class UserModule: public Module { 61 | public: 62 | UserModule() 63 | : Module("_user") {} 64 | 65 | ~UserModule() {} 66 | 67 | void init() {} 68 | private: 69 | DISALLOW_COPY_AND_ASSIGN(UserModule); 70 | }; 71 | 72 | } // clever 73 | 74 | #endif // CLEVER_USER_H 75 | -------------------------------------------------------------------------------- /dependencies.cmake: -------------------------------------------------------------------------------- 1 | # 2 | # Clever programming language 3 | # Copyright (c) 2011-2013 Clever Team 4 | # 5 | # dependencies.cmake - 3rd-party library dependency 6 | # 7 | 8 | # 3rd-party libraries 9 | # --------------------------------------------------------------------------- 10 | # TODO(heuripedes): minimize the scope of the add_definitions() 11 | # pthread 12 | clever_add_lib(PTHREAD 13 | LIBS pthread 14 | INCS pthread.h) 15 | 16 | # libpcrecpp 17 | clever_add_lib(PCRECPP 18 | INCS pcrecpp.h 19 | LIBS pcre pcrecpp 20 | PKGS libpcrecpp) 21 | 22 | if(PCRECPP_FOUND) 23 | add_definitions(-DHAVE_PCRECPP) 24 | endif() 25 | 26 | # libicu 27 | clever_add_lib(ICU 28 | LIBS icuuc 29 | INCS unicode/ustring.h 30 | PKGS icu-uc) 31 | 32 | # libfcgi 33 | clever_add_lib(FCGI 34 | LIBS fcgi fcgi++ 35 | INCS fcgi_config.h) 36 | 37 | # cgicc 38 | clever_add_lib(CGICC 39 | LIBS cgicc 40 | INCS cgicc/Cgicc.h) 41 | 42 | # libffi 43 | clever_add_lib(FFI 44 | LIBS ffi 45 | INCS ffi.h 46 | PKGS libffi) 47 | 48 | # libmysqlclient 49 | clever_add_lib(MYSQLC 50 | LIBS mysqlclient 51 | INCS mysql/mysql.h) 52 | 53 | # libsqlite3 54 | clever_add_lib(SQLITE3 55 | LIBS sqlite3 56 | INCS sqlite3.h 57 | PKGS sqlite3) 58 | 59 | # libncurses 60 | clever_add_lib(NCURSES 61 | LIBS ncurses 62 | INCS curses.h 63 | ) 64 | 65 | -------------------------------------------------------------------------------- /extra/testrunner.h: -------------------------------------------------------------------------------- 1 | /** 2 | * Clever programming language 3 | * Copyright (c) Clever Team 4 | * 5 | * This file is distributed under the MIT license. See LICENSE for details. 6 | */ 7 | 8 | #ifndef CLEVER_TESTRUNNER_H 9 | #define CLEVER_TESTRUNNER_H 10 | 11 | #include 12 | #include 13 | #ifndef CLEVER_WIN32 14 | #include 15 | #else 16 | #include 17 | #endif 18 | #include 19 | 20 | class TestRunner { 21 | public: 22 | enum { FAIL_ONLY = 1 }; 23 | 24 | TestRunner() 25 | : valgrind(false), helgrind(false), pass(0), fail(0), leak(0), flags(0), races(0), skip(0) 26 | { start_time = clock(); } 27 | 28 | ~TestRunner(); 29 | 30 | std::string read_file(const char*) const; 31 | void find(const char* dir); 32 | void run(void); 33 | bool show_result(void) const; 34 | void write_file(std::string&, std::string&); 35 | void setFlags(unsigned int val) { flags |= val; } 36 | unsigned int getFlags() const { return flags; } 37 | 38 | bool valgrind; 39 | bool helgrind; 40 | private: 41 | unsigned int pass, fail, leak, flags, races, skip; 42 | clock_t start_time; 43 | std::vector files; 44 | std::vector tmp_files; 45 | 46 | void load_folder(const char* dir); 47 | 48 | static bool fileExists(const std::string&); 49 | static size_t fileSize(const std::string&); 50 | static void writeLog(const std::string&, const std::string&); 51 | static bool checkTest(const std::string&); 52 | static void runSection(const std::string&); 53 | }; 54 | 55 | #endif // CLEVER_TESTRUNNER_H 56 | -------------------------------------------------------------------------------- /modules/db/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | 2 | set(CLEVER_MODULES) 3 | 4 | if(DB_MYSQL) 5 | list(APPEND CLEVER_MODULES mysql) 6 | endif() 7 | 8 | if(DB_SQLITE3) 9 | list(APPEND CLEVER_MODULES sqlite3) 10 | endif() 11 | 12 | foreach(module ${CLEVER_MODULES}) 13 | add_subdirectory(${module}) 14 | endforeach() 15 | 16 | add_library(modules_db STATIC 17 | db_pkg.cc 18 | ) 19 | 20 | foreach(module ${CLEVER_MODULES}) 21 | add_dependencies(modules_db "modules_db_${module}") 22 | target_link_libraries(modules_db "modules_db_${module}") 23 | endforeach() 24 | 25 | 26 | -------------------------------------------------------------------------------- /modules/db/db_forwarder.h: -------------------------------------------------------------------------------- 1 | /** 2 | * Clever programming language 3 | * Copyright (c) 2011-2012 Clever Team 4 | * 5 | * Permission is hereby granted, free of charge, to any person 6 | * obtaining a copy of this software and associated documentation 7 | * files (the "Software"), to deal in the Software without 8 | * restriction, including without limitation the rights to use, 9 | * copy, modify, merge, publish, distribute, sublicense, and/or sell 10 | * copies of the Software, and to permit persons to whom the 11 | * Software is furnished to do so, subject to the following 12 | * conditions: 13 | * The above copyright notice and this permission notice shall be 14 | * included in all copies or substantial portions of the Software. 15 | * 16 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, 17 | * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES 18 | * OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND 19 | * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT 20 | * HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, 21 | * WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING 22 | * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR 23 | * OTHER DEALINGS IN THE SOFTWARE. 24 | */ 25 | 26 | #ifdef HAVE_MOD_DB_MYSQL 27 | # include "modules/db/mysql/module.h" 28 | #endif 29 | 30 | #ifdef HAVE_MOD_DB_SQLITE3 31 | # include "modules/db/sqlite3/module.h" 32 | #endif 33 | -------------------------------------------------------------------------------- /modules/db/db_pkg.cc: -------------------------------------------------------------------------------- 1 | /** 2 | * Clever programming language 3 | * Copyright (c) Clever Team 4 | * 5 | * This file is distributed under the MIT license. See LICENSE for details. 6 | */ 7 | 8 | #include "modules/db/db_pkg.h" 9 | 10 | namespace clever { namespace modules { 11 | 12 | // Initializes Db package 13 | void Db::init() 14 | { 15 | #ifdef HAVE_MOD_DB_MYSQL 16 | addModule(new db::MysqlModule); 17 | #endif 18 | 19 | #ifdef HAVE_MOD_DB_SQLITE3 20 | addModule(new db::SQLite3Module); 21 | #endif 22 | } 23 | 24 | }} // clever::modules 25 | -------------------------------------------------------------------------------- /modules/db/db_pkg.h: -------------------------------------------------------------------------------- 1 | /** 2 | * Clever programming language 3 | * Copyright (c) Clever Team 4 | * 5 | * This file is distributed under the MIT license. See LICENSE for details. 6 | */ 7 | 8 | #ifndef CLEVER_DB_PACKAGE_H 9 | #define CLEVER_DB_PACKAGE_H 10 | 11 | #include "core/clever.h" 12 | #include "modules/db/db_forwarder.h" 13 | #include "core/module.h" 14 | 15 | namespace clever { namespace modules { 16 | 17 | class Db : public Module { 18 | public: 19 | Db() 20 | : Module("db") {} 21 | 22 | ~Db() {} 23 | 24 | CLEVER_MODULE_VIRTUAL_METHODS_DECLARATION; 25 | private: 26 | DISALLOW_COPY_AND_ASSIGN(Db); 27 | }; 28 | 29 | }} // clever::modules 30 | 31 | #endif // CLEVER_DB_PACKAGE_H 32 | -------------------------------------------------------------------------------- /modules/db/mysql/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | 2 | add_library(modules_db_mysql STATIC 3 | module.cc 4 | cmysql.cc 5 | mysql.cc 6 | ) 7 | 8 | -------------------------------------------------------------------------------- /modules/db/mysql/cmysql.h: -------------------------------------------------------------------------------- 1 | /** 2 | * Clever programming language 3 | * Copyright (c) Clever Team 4 | * 5 | * This file is distributed under the MIT license. See LICENSE for details. 6 | */ 7 | 8 | #ifndef CLEVER_DB_CMYSQL_H 9 | #define CLEVER_DB_CMYSQL_H 10 | 11 | #include 12 | 13 | #include 14 | 15 | #include "core/cstring.h" 16 | #include "core/value.h" 17 | #include "core/type.h" 18 | #include "modules/std/core/map.h" 19 | 20 | 21 | namespace clever { 22 | 23 | 24 | class CMysql { 25 | public: 26 | CMysql() 27 | : m_connection(NULL), m_port(3306), m_resultset(NULL) { init(); } 28 | 29 | ~CMysql() {} 30 | 31 | void setHost(const std::string& host) { m_host = host; } 32 | void setUser(const std::string& user) { m_user = user; } 33 | void setPasswd(const std::string& passwd) { m_passwd = passwd; } 34 | void setDb(const std::string& db) { m_db = db; } 35 | void setPort(int port) { m_port = port; } 36 | 37 | bool connect(); 38 | bool query(const char* stmt); 39 | MapObject* fetchRow(); 40 | unsigned int errno(); 41 | const char* error(); 42 | 43 | std::string dump(); 44 | private: 45 | 46 | void init(); 47 | 48 | MYSQL* m_connection; 49 | 50 | std::string m_host; 51 | std::string m_user; 52 | std::string m_passwd; 53 | std::string m_db; 54 | 55 | int m_port; 56 | 57 | MYSQL_RES* m_resultset; 58 | 59 | DISALLOW_COPY_AND_ASSIGN(CMysql); 60 | }; 61 | 62 | } // clever 63 | 64 | #endif // CLEVER_DB_CMYSQL_H 65 | -------------------------------------------------------------------------------- /modules/db/mysql/module.cc: -------------------------------------------------------------------------------- 1 | /** 2 | * Clever programming language 3 | * Copyright (c) Clever Team 4 | * 5 | * This file is distributed under the MIT license. See LICENSE for details. 6 | */ 7 | 8 | #include "modules/db/mysql/module.h" 9 | #include "modules/db/mysql/mysql.h" 10 | 11 | namespace clever { namespace modules { namespace db { 12 | 13 | /// Initializes Mysql module 14 | CLEVER_MODULE_INIT(MysqlModule) 15 | { 16 | addType(new Mysql); 17 | } 18 | 19 | }}} // clever::modules::db 20 | -------------------------------------------------------------------------------- /modules/db/mysql/module.h: -------------------------------------------------------------------------------- 1 | /** 2 | * Clever programming language 3 | * Copyright (c) Clever Team 4 | * 5 | * This file is distributed under the MIT license. See LICENSE for details. 6 | */ 7 | 8 | #ifndef CLEVER_DB_MYSQL_MODULE_H 9 | #define CLEVER_DB_MYSQL_MODULE_H 10 | 11 | #include "core/module.h" 12 | 13 | namespace clever { namespace modules { namespace db { 14 | 15 | /// Mysql Module 16 | class MysqlModule : public Module { 17 | public: 18 | MysqlModule() 19 | : Module("db.mysql") {} 20 | 21 | ~MysqlModule() {} 22 | 23 | CLEVER_MODULE_VIRTUAL_METHODS_DECLARATION; 24 | private: 25 | DISALLOW_COPY_AND_ASSIGN(MysqlModule); 26 | }; 27 | 28 | }}} // clever::modules::db 29 | 30 | #endif // CLEVER_DB_MYSQL_MODULE_H 31 | -------------------------------------------------------------------------------- /modules/db/mysql/mysql.h: -------------------------------------------------------------------------------- 1 | /** 2 | * Clever programming language 3 | * Copyright (c) Clever Team 4 | * 5 | * This file is distributed under the MIT license. See LICENSE for details. 6 | */ 7 | 8 | #ifndef CLEVER_DB_MYSQL_H 9 | #define CLEVER_DB_MYSQL_H 10 | 11 | #include 12 | #include "core/cstring.h" 13 | #include "core/value.h" 14 | #include "core/type.h" 15 | #include "modules/db/mysql/cmysql.h" 16 | 17 | namespace clever { namespace modules { namespace db { 18 | 19 | class MysqlObject : public TypeObject { 20 | public: 21 | MysqlObject() {} 22 | 23 | ~MysqlObject() {} 24 | 25 | CMysql& getMysql() { return m_mysql; } 26 | 27 | private: 28 | CMysql m_mysql; 29 | 30 | DISALLOW_COPY_AND_ASSIGN(MysqlObject); 31 | }; 32 | 33 | class Mysql : public Type { 34 | public: 35 | Mysql() 36 | : Type("Mysql") {} 37 | 38 | ~Mysql() {} 39 | 40 | virtual void init(); 41 | 42 | CLEVER_METHOD(ctor); 43 | CLEVER_METHOD(connect); 44 | CLEVER_METHOD(query); 45 | CLEVER_METHOD(fetchRow); 46 | CLEVER_METHOD(getErrorNumber); 47 | CLEVER_METHOD(getError); 48 | 49 | private: 50 | DISALLOW_COPY_AND_ASSIGN(Mysql); 51 | }; 52 | 53 | }}} // clever::modules::db 54 | 55 | #endif // CLEVER_DB_MYSQL_H 56 | -------------------------------------------------------------------------------- /modules/db/sqlite3/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | 2 | add_library(modules_db_sqlite3 STATIC 3 | module.cc 4 | sqlite3.cc 5 | ) 6 | 7 | -------------------------------------------------------------------------------- /modules/db/sqlite3/module.cc: -------------------------------------------------------------------------------- 1 | /** 2 | * Clever programming language 3 | * Copyright (c) Clever Team 4 | * 5 | * This file is distributed under the MIT license. See LICENSE for details. 6 | */ 7 | 8 | #include "modules/db/sqlite3/module.h" 9 | #include "modules/db/sqlite3/sqlite3.h" 10 | 11 | namespace clever { namespace modules { namespace db { 12 | 13 | CLEVER_MODULE_INIT(SQLite3Module) 14 | { 15 | SQLite3Type* sqlite_type = new SQLite3Type(); 16 | SQLite3TypeStmt* stmt_type = new SQLite3TypeStmt(sqlite_type); 17 | SQLite3TypeResult* result_type = new SQLite3TypeResult(sqlite_type); 18 | 19 | addType(sqlite_type); 20 | addType(stmt_type); 21 | addType(result_type); 22 | 23 | sqlite_type->result_type = result_type; 24 | sqlite_type->stmt_type = stmt_type; 25 | } 26 | 27 | }}} // clever::modules::db 28 | -------------------------------------------------------------------------------- /modules/db/sqlite3/module.h: -------------------------------------------------------------------------------- 1 | /** 2 | * Clever programming language 3 | * Copyright (c) Clever Team 4 | * 5 | * This file is distributed under the MIT license. See LICENSE for details. 6 | */ 7 | 8 | #ifndef CLEVER_DB_MOD_SQLITE3_H 9 | #define CLEVER_DB_MOD_SQLITE3_H 10 | 11 | #include "core/module.h" 12 | 13 | namespace clever { namespace modules { namespace db { 14 | 15 | class SQLite3Module : public Module { 16 | public: 17 | SQLite3Module() 18 | : Module("db.sqlite3"), m_result(NULL), m_stmt(NULL) {} 19 | 20 | ~SQLite3Module() {} 21 | 22 | CLEVER_MODULE_VIRTUAL_METHODS_DECLARATION; 23 | 24 | const Type* getResultType() const { return m_result; } 25 | const Type* getStmtType() const { return m_stmt; } 26 | private: 27 | Type* m_result; 28 | Type* m_stmt; 29 | 30 | DISALLOW_COPY_AND_ASSIGN(SQLite3Module); 31 | }; 32 | 33 | }}} // clever::modules::db 34 | 35 | #endif // CLEVER_DB_MOD_SQLITE3_H 36 | -------------------------------------------------------------------------------- /modules/gui/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | 2 | set(CLEVER_MODULES) 3 | 4 | if (GUI_NCURSES) 5 | list(APPEND CLEVER_MODULES ncurses) 6 | endif (GUI_NCURSES) 7 | 8 | 9 | 10 | foreach (module ${CLEVER_MODULES}) 11 | add_subdirectory(${module}) 12 | endforeach (module) 13 | 14 | add_library(modules_gui STATIC 15 | gui_pkg.cc 16 | ) 17 | 18 | foreach (module ${CLEVER_MODULES}) 19 | add_dependencies(modules_gui "modules_gui_${module}") 20 | target_link_libraries(modules_gui "modules_gui_${module}") 21 | endforeach (module) 22 | 23 | 24 | -------------------------------------------------------------------------------- /modules/gui/gui_forwarder.h: -------------------------------------------------------------------------------- 1 | /** 2 | * Clever programming language 3 | * Copyright (c) Clever Team 4 | * 5 | * This file is distributed under the MIT license. See LICENSE for details. 6 | */ 7 | #include "modules/std/core/core.h" 8 | 9 | 10 | #ifdef HAVE_MOD_GUI_NCURSES 11 | # include "modules/gui/ncurses/module.h" 12 | #endif 13 | -------------------------------------------------------------------------------- /modules/gui/gui_pkg.cc: -------------------------------------------------------------------------------- 1 | /** 2 | * Clever programming language 3 | * Copyright (c) Clever Team 4 | * 5 | * This file is distributed under the MIT license. See LICENSE for details. 6 | */ 7 | 8 | #include "modules/gui/gui_pkg.h" 9 | #include "modules/gui/ncurses/module.h" 10 | 11 | namespace clever { namespace modules { 12 | 13 | // Initializes Gui package 14 | void Gui::init() 15 | { 16 | #if HAVE_MOD_GUI_NCURSES 17 | addModule(new gui::NCursesModule); 18 | #endif 19 | } 20 | 21 | }} // clever::modules 22 | -------------------------------------------------------------------------------- /modules/gui/gui_pkg.h: -------------------------------------------------------------------------------- 1 | /** 2 | * Clever programming language 3 | * Copyright (c) Clever Team 4 | * 5 | * This file is distributed under the MIT license. See LICENSE for details. 6 | */ 7 | 8 | #ifndef CLEVER_GUI_PACKAGE_H 9 | #define CLEVER_GUI_PACKAGE_H 10 | 11 | #include "core/clever.h" 12 | #include "modules/gui/gui_forwarder.h" 13 | #include "core/module.h" 14 | 15 | namespace clever { namespace modules { 16 | 17 | class Gui : public Module { 18 | public: 19 | Gui() 20 | : Module("gui") {} 21 | 22 | ~Gui() {} 23 | 24 | CLEVER_MODULE_VIRTUAL_METHODS_DECLARATION; 25 | private: 26 | DISALLOW_COPY_AND_ASSIGN(Gui); 27 | }; 28 | 29 | }} // clever::modules 30 | 31 | #endif // CLEVER_GUI_PACKAGE_H 32 | -------------------------------------------------------------------------------- /modules/gui/ncurses/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | add_library(modules_gui_ncurses STATIC 2 | module.cc 3 | ncurses.cc 4 | cncurses.cc 5 | ) 6 | -------------------------------------------------------------------------------- /modules/gui/ncurses/cncurses.h: -------------------------------------------------------------------------------- 1 | /** 2 | * Clever programming language 3 | * Copyright (c) Clever Team 4 | * 5 | * This file is distributed under the MIT license. See LICENSE for details. 6 | */ 7 | 8 | #ifndef CLEVER_GUI_CNCURSES_H 9 | #define CLEVER_GUI_CNCURSES_H 10 | 11 | #include 12 | 13 | #include 14 | 15 | #include "core/cstring.h" 16 | #include "core/value.h" 17 | #include "core/type.h" 18 | #include "modules/std/core/map.h" 19 | 20 | 21 | namespace clever { 22 | 23 | 24 | class CNCurses { 25 | public: 26 | CNCurses(int m_sleep_time = 0, WINDOW* father = NULL, bool m_enable_colors = false, 27 | int w = 0, int h = 0, int x = 0, int y = 0, bool m_enable_keypad = false); 28 | ~CNCurses(); 29 | 30 | void close(); 31 | void hide(); 32 | void exit(); 33 | 34 | bool status(); 35 | bool hasColors(); 36 | void startColor() { ::start_color(); } 37 | static bool isPrintable(int ch); 38 | bool isChild(); 39 | 40 | void noEcho() { ::noecho(); } 41 | 42 | int nColors(); 43 | int setColor(short id, void* handler); 44 | int getKey(); 45 | 46 | void box(int x, int y); 47 | 48 | void move(int x, int y); 49 | 50 | void enableKeyPad(); 51 | void deleteLine(); 52 | void addColor(short id, short color_1, short color_2); 53 | void addStr(int x, int y, const char* str); 54 | void addChar(int x, int y, int v); 55 | void printStr(int x, int y, const char* str); 56 | void refresh(); 57 | void sleep(); 58 | 59 | WINDOW* getWindow() { return m_win; } 60 | 61 | int getPosX() { return pos_x; } 62 | int getPosY() { return pos_y; } 63 | 64 | int getWidth() { return width; } 65 | int getHeight() { return height; } 66 | 67 | private: 68 | bool m_is_closed; 69 | int m_sleep_time; 70 | 71 | bool m_enable_colors; 72 | 73 | WINDOW* m_win; 74 | WINDOW* m_father; 75 | 76 | int width, height; 77 | int pos_x, pos_y; 78 | 79 | bool m_status; 80 | 81 | 82 | DISALLOW_COPY_AND_ASSIGN(CNCurses); 83 | }; 84 | 85 | } // clever 86 | 87 | #endif // CLEVER_GUI_CNCURSES_H 88 | -------------------------------------------------------------------------------- /modules/gui/ncurses/module.cc: -------------------------------------------------------------------------------- 1 | /** 2 | * Clever programming language 3 | * Copyright (c) Clever Team 4 | * 5 | * This file is distributed under the MIT license. See LICENSE for details. 6 | */ 7 | 8 | #include "modules/gui/ncurses/module.h" 9 | #include "modules/gui/ncurses/ncurses.h" 10 | 11 | namespace clever { namespace modules { namespace gui { 12 | 13 | /// Initializes ncurses module 14 | 15 | Type* g_key_type_ref; 16 | 17 | CLEVER_MODULE_INIT(NCursesModule) 18 | { 19 | addType(new NCurses); 20 | addType(g_key_type_ref = new Key); 21 | } 22 | 23 | }}} // clever::modules::gui 24 | -------------------------------------------------------------------------------- /modules/gui/ncurses/module.h: -------------------------------------------------------------------------------- 1 | /** 2 | * Clever programming language 3 | * Copyright (c) Clever Team 4 | * 5 | * This file is distributed under the MIT license. See LICENSE for details. 6 | */ 7 | 8 | #ifndef CLEVER_GUI_NCURSES_MODULE_H 9 | #define CLEVER_GUI_NCURSES_MODULE_H 10 | 11 | #include "core/module.h" 12 | 13 | namespace clever { namespace modules { namespace gui { 14 | 15 | /// NCurses Module 16 | class NCursesModule : public Module { 17 | public: 18 | NCursesModule() 19 | : Module("gui.ncurses") {} 20 | 21 | ~NCursesModule() {} 22 | 23 | CLEVER_MODULE_VIRTUAL_METHODS_DECLARATION; 24 | private: 25 | DISALLOW_COPY_AND_ASSIGN(NCursesModule); 26 | }; 27 | 28 | }}} // clever::modules::gui 29 | 30 | #endif // CLEVER_GUI_NCURSES_MODULE_H 31 | -------------------------------------------------------------------------------- /modules/std/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | 2 | set(CLEVER_MODULES) 3 | 4 | if(STD_FFI) 5 | list(APPEND CLEVER_MODULES ffi) 6 | endif() 7 | 8 | if(STD_REGEX) 9 | list(APPEND CLEVER_MODULES regex) 10 | endif() 11 | 12 | if(STD_CLEVER) 13 | list(APPEND CLEVER_MODULES clever) 14 | endif() 15 | 16 | if(STD_CONCURRENT) 17 | list(APPEND CLEVER_MODULES concurrent) 18 | endif() 19 | 20 | if(STD_EVENTS) 21 | list(APPEND CLEVER_MODULES events) 22 | endif() 23 | 24 | if(STD_DATE) 25 | list(APPEND CLEVER_MODULES date) 26 | endif() 27 | 28 | if(STD_FILE) 29 | list(APPEND CLEVER_MODULES file) 30 | endif() 31 | 32 | if(STD_IO) 33 | list(APPEND CLEVER_MODULES io) 34 | endif() 35 | 36 | if(STD_UNICODE) 37 | list(APPEND CLEVER_MODULES unicode) 38 | endif() 39 | 40 | if(STD_FCGI) 41 | list(APPEND CLEVER_MODULES fcgi) 42 | endif() 43 | 44 | if(STD_MATH) 45 | list(APPEND CLEVER_MODULES math) 46 | endif() 47 | 48 | if(STD_NET) 49 | list(APPEND CLEVER_MODULES net) 50 | endif() 51 | 52 | if(STD_SYS) 53 | list(APPEND CLEVER_MODULES sys) 54 | endif() 55 | 56 | if(STD_REFLECTION) 57 | list(APPEND CLEVER_MODULES reflection) 58 | endif() 59 | 60 | if(STD_CRYPTO) 61 | list(APPEND CLEVER_MODULES crypto) 62 | endif() 63 | 64 | if(STD_JSON) 65 | list(APPEND CLEVER_MODULES json) 66 | endif() 67 | 68 | if(STD_COLLECTION) 69 | list(APPEND CLEVER_MODULES collection) 70 | endif() 71 | 72 | if(STD_GETOPT) 73 | list(APPEND CLEVER_MODULES getopt) 74 | endif() 75 | 76 | foreach(module ${CLEVER_MODULES}) 77 | add_subdirectory(${module}) 78 | endforeach() 79 | 80 | add_library(modules_std STATIC 81 | std_pkg.cc 82 | ) 83 | 84 | foreach(module ${CLEVER_MODULES}) 85 | add_dependencies(modules_std "modules_std_${module}") 86 | target_link_libraries(modules_std "modules_std_${module}") 87 | endforeach() 88 | 89 | 90 | -------------------------------------------------------------------------------- /modules/std/clever/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | 2 | add_library(modules_std_clever STATIC 3 | module.cc 4 | type.cc 5 | ) 6 | -------------------------------------------------------------------------------- /modules/std/clever/module.cc: -------------------------------------------------------------------------------- 1 | /** 2 | * Clever programming language 3 | * Copyright (c) Clever Team 4 | * 5 | * This file is distributed under the MIT license. See LICENSE for details. 6 | */ 7 | 8 | #include "core/clever.h" 9 | #include "modules/std/clever/module.h" 10 | #include "modules/std/clever/type.h" 11 | 12 | namespace clever { namespace modules { namespace std { 13 | 14 | /// Standard clever module initialization 15 | CLEVER_MODULE_INIT(CleverModule) 16 | { 17 | addType(new CleverType); 18 | } 19 | 20 | }}} // clever::modules::std 21 | -------------------------------------------------------------------------------- /modules/std/clever/module.h: -------------------------------------------------------------------------------- 1 | /** 2 | * Clever programming language 3 | * Copyright (c) Clever Team 4 | * 5 | * This file is distributed under the MIT license. See LICENSE for details. 6 | */ 7 | 8 | #ifndef CLEVER_MOD_CLEVER_H 9 | #define CLEVER_MOD_CLEVER_H 10 | 11 | #include "core/module.h" 12 | 13 | namespace clever { namespace modules { namespace std { 14 | 15 | class CleverModule : public Module { 16 | public: 17 | CleverModule() 18 | : Module("std.clever") {} 19 | 20 | ~CleverModule() {} 21 | 22 | CLEVER_MODULE_VIRTUAL_METHODS_DECLARATION; 23 | }; 24 | 25 | 26 | }}} // clever::modules::std 27 | 28 | #endif // CLEVER_MOD_CLEVER_H 29 | -------------------------------------------------------------------------------- /modules/std/clever/type.cc: -------------------------------------------------------------------------------- 1 | /** 2 | * Clever programming language 3 | * Copyright (c) Clever Team 4 | * 5 | * This file is distributed under the MIT license. See LICENSE for details. 6 | */ 7 | 8 | #include "core/clever.h" 9 | #include "core/value.h" 10 | #include "modules/std/core/function.h" 11 | #include "modules/std/clever/type.h" 12 | 13 | namespace clever { namespace modules { namespace std { 14 | 15 | // String Clever::buildDate() 16 | // Returns the string containing the date and time which Clever has been built 17 | CLEVER_METHOD(CleverType::buildDate) 18 | { 19 | if (!clever_static_check_no_args()) { 20 | return; 21 | } 22 | result->setStr(new StrObject(__DATE__ " " __TIME__)); 23 | } 24 | 25 | // Bool Clever::hasThreads() 26 | // Returns a boolean indicating if Clever has been built with threads support 27 | CLEVER_METHOD(CleverType::hasThreads) 28 | { 29 | if (!clever_static_check_no_args()) { 30 | return; 31 | } 32 | #ifdef CLEVER_THREADS 33 | result->setBool(true); 34 | #else 35 | result->setBool(false); 36 | #endif 37 | } 38 | 39 | // Int Clever::getVersion() 40 | // Returns the Clever version as integer 41 | CLEVER_METHOD(CleverType::getVersion) 42 | { 43 | if (!clever_static_check_no_args()) { 44 | return; 45 | } 46 | 47 | result->setInt(CLEVER_VERSION); 48 | } 49 | 50 | 51 | // String Clever::getStringVersion() 52 | // Returns the Clever version as string 53 | CLEVER_METHOD(CleverType::getStringVersion) 54 | { 55 | if (!clever_static_check_no_args()) { 56 | return; 57 | } 58 | 59 | result->setStr(new StrObject(CLEVER_VERSION_STRING)); 60 | } 61 | 62 | // Clever type initialization 63 | void CleverType::init() 64 | { 65 | addMethod(new Function("buildDate", (MethodPtr) &CleverType::buildDate)) 66 | ->setStatic(); 67 | 68 | addMethod(new Function("hasThreads", (MethodPtr) &CleverType::hasThreads)) 69 | ->setStatic(); 70 | 71 | addMethod(new Function("getVersion", (MethodPtr) &CleverType::getVersion)) 72 | ->setStatic(); 73 | 74 | addMethod(new Function("getStringVersion", (MethodPtr) &CleverType::getStringVersion)) 75 | ->setStatic(); 76 | } 77 | 78 | }}} // clever 79 | -------------------------------------------------------------------------------- /modules/std/clever/type.h: -------------------------------------------------------------------------------- 1 | /** 2 | * Clever programming language 3 | * Copyright (c) Clever Team 4 | * 5 | * This file is distributed under the MIT license. See LICENSE for details. 6 | */ 7 | 8 | #ifndef CLEVER_MOD_CLEVER_TYPE_H 9 | #define CLEVER_MOD_CLEVER_TYPE_H 10 | 11 | #include "core/type.h" 12 | #include 13 | 14 | namespace clever { namespace modules { namespace std { 15 | 16 | class CleverType : public Type { 17 | public: 18 | CleverType() 19 | : Type("Clever") {} 20 | 21 | ~CleverType() {} 22 | 23 | void init(); 24 | 25 | CLEVER_METHOD(buildDate); 26 | CLEVER_METHOD(hasThreads); 27 | CLEVER_METHOD(getVersion); 28 | CLEVER_METHOD(getStringVersion); 29 | }; 30 | 31 | }}} // clever::modules::std 32 | 33 | #endif // CLEVER_MOD_CLEVER_TYPE_H 34 | -------------------------------------------------------------------------------- /modules/std/collection/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | 2 | add_library(modules_std_collection STATIC 3 | module.cc 4 | cstack.cc 5 | cqueue.cc 6 | cset.cc 7 | ) 8 | -------------------------------------------------------------------------------- /modules/std/collection/cset.h: -------------------------------------------------------------------------------- 1 | /** 2 | * Clever programming language 3 | * Copyright (c) Clever Team 4 | * 5 | * This file is distributed under the MIT license. See LICENSE for details. 6 | */ 7 | 8 | #ifndef CLEVER_STD_SET_H 9 | #define CLEVER_STD_SET_H 10 | 11 | #include 12 | #include "core/type.h" 13 | 14 | namespace clever { namespace modules { namespace std { 15 | 16 | struct CSetValue { 17 | CSetValue(Value* elem, const Function* func_, const VM* vm_) 18 | : element(elem), comp(func_), vm(vm_) {} 19 | 20 | ~CSetValue() {} 21 | 22 | Value* element; 23 | const Function* comp; 24 | const VM* vm; 25 | }; 26 | 27 | struct CSetObjectCompare { 28 | bool operator()(const CSetValue& a, const CSetValue& b) const; 29 | }; 30 | 31 | struct CSetObject : public TypeObject { 32 | CSetObject(const Function* func) 33 | : comp(func) {} 34 | 35 | ~CSetObject() { 36 | ::std::set::const_iterator it(set.begin()), 37 | end(set.end()); 38 | 39 | for (; it != end; ++it) { 40 | clever_delref(it->element); 41 | } 42 | } 43 | 44 | ::std::set set; 45 | const Function* comp; 46 | }; 47 | 48 | class CSet : public Type { 49 | public: 50 | CSet() 51 | : Type("Set") {} 52 | 53 | ~CSet() {} 54 | 55 | virtual void init(); 56 | virtual ::std::string toString(TypeObject*) const; 57 | 58 | // Methods 59 | CLEVER_METHOD(ctor); 60 | CLEVER_METHOD(insert); 61 | CLEVER_METHOD(size); 62 | CLEVER_METHOD(empty); 63 | CLEVER_METHOD(find); 64 | 65 | // Operators 66 | CLEVER_TYPE_OPERATOR(add); 67 | CLEVER_TYPE_OPERATOR(mul); 68 | CLEVER_TYPE_OPERATOR(sub); 69 | CLEVER_TYPE_OPERATOR(div); 70 | 71 | private: 72 | DISALLOW_COPY_AND_ASSIGN(CSet); 73 | }; 74 | 75 | }}} // clever::modules::std 76 | 77 | #endif // CLEVER_STD_SET_H 78 | -------------------------------------------------------------------------------- /modules/std/collection/cstack.h: -------------------------------------------------------------------------------- 1 | /** 2 | * Clever programming language 3 | * Copyright (c) Clever Team 4 | * 5 | * This file is distributed under the MIT license. See LICENSE for details. 6 | */ 7 | 8 | #ifndef CLEVER_STD_CSTACK_H 9 | #define CLEVER_STD_CSTACK_H 10 | 11 | #include 12 | #include "core/type.h" 13 | 14 | namespace clever { namespace modules { namespace std { 15 | 16 | struct CStackObject : public TypeObject { 17 | CStackObject() {} 18 | 19 | ~CStackObject() { 20 | while (!stack.empty()) { 21 | clever_delref(stack.top()); 22 | stack.pop(); 23 | } 24 | } 25 | 26 | ::std::stack stack; 27 | }; 28 | 29 | class CStack : public Type { 30 | public: 31 | CStack() 32 | : Type("Stack") {} 33 | 34 | ~CStack() {} 35 | 36 | virtual void init(); 37 | 38 | // Methods 39 | CLEVER_METHOD(ctor); 40 | CLEVER_METHOD(push); 41 | CLEVER_METHOD(pop); 42 | CLEVER_METHOD(top); 43 | CLEVER_METHOD(size); 44 | CLEVER_METHOD(empty); 45 | private: 46 | DISALLOW_COPY_AND_ASSIGN(CStack); 47 | }; 48 | 49 | }}} // clever::modules::std 50 | 51 | #endif // CLEVER_STD_CSTACK_H 52 | -------------------------------------------------------------------------------- /modules/std/collection/module.cc: -------------------------------------------------------------------------------- 1 | /** 2 | * Clever programming language 3 | * Copyright (c) Clever Team 4 | * 5 | * This file is distributed under the MIT license. See LICENSE for details. 6 | */ 7 | 8 | #include "modules/std/collection/module.h" 9 | #include "modules/std/collection/cstack.h" 10 | #include "modules/std/collection/cqueue.h" 11 | #include "modules/std/collection/cset.h" 12 | 13 | namespace clever { namespace modules { namespace std { 14 | 15 | CLEVER_MODULE_INIT(CollectionModule) 16 | { 17 | addType(new CStack); 18 | addType(new CQueue); 19 | addType(new CPQueue); 20 | addType(new CSet); 21 | } 22 | 23 | }}} // clever::modules::std 24 | -------------------------------------------------------------------------------- /modules/std/collection/module.h: -------------------------------------------------------------------------------- 1 | /** 2 | * Clever programming language 3 | * Copyright (c) Clever Team 4 | * 5 | * This file is distributed under the MIT license. See LICENSE for details. 6 | */ 7 | 8 | #ifndef CLEVER_STD_COLLECTION_H 9 | #define CLEVER_STD_COLLECTION_H 10 | 11 | #include "core/module.h" 12 | 13 | namespace clever { namespace modules { namespace std { 14 | 15 | /// Standard Collection Module 16 | class CollectionModule : public Module { 17 | public: 18 | CollectionModule() 19 | : Module("std.collection") {} 20 | 21 | ~CollectionModule() {} 22 | 23 | CLEVER_MODULE_VIRTUAL_METHODS_DECLARATION; 24 | private: 25 | DISALLOW_COPY_AND_ASSIGN(CollectionModule); 26 | }; 27 | 28 | }}} // clever::modules::std 29 | 30 | #endif // CLEVER_STD_COLLECTION_H 31 | -------------------------------------------------------------------------------- /modules/std/concurrent/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | 2 | add_library(modules_std_concurrent STATIC 3 | module.cc 4 | mutex.cc 5 | condition.cc 6 | thread.cc 7 | sync.cc 8 | ) 9 | -------------------------------------------------------------------------------- /modules/std/concurrent/condition.h: -------------------------------------------------------------------------------- 1 | /** 2 | * Clever programming language 3 | * Copyright (c) Clever Team 4 | * 5 | * This file is distributed under the MIT license. See LICENSE for details. 6 | */ 7 | 8 | #ifndef CLEVER_STD_CONCURRENT_CONDITION_H 9 | #define CLEVER_STD_CONCURRENT_CONDITION_H 10 | 11 | #include 12 | 13 | #include "core/cstring.h" 14 | #include "core/type.h" 15 | #include "core/cthread.h" 16 | 17 | namespace clever { namespace modules { namespace std { 18 | 19 | struct ConditionObject : public TypeObject { 20 | ConditionObject() 21 | : condition() {} 22 | 23 | ~ConditionObject() {} 24 | 25 | CCondition condition; 26 | }; 27 | 28 | class Condition : public Type { 29 | public: 30 | Condition() 31 | : Type("Condition") {} 32 | 33 | ~Condition() {} 34 | 35 | virtual void init(); 36 | 37 | CLEVER_METHOD(ctor); 38 | CLEVER_METHOD(signal); 39 | CLEVER_METHOD(broadcast); 40 | CLEVER_METHOD(wait); 41 | }; 42 | 43 | }}} // clever::modules::std 44 | 45 | #endif // CLEVER_STD_CONCURRENT_CONDITION_H 46 | -------------------------------------------------------------------------------- /modules/std/concurrent/module.cc: -------------------------------------------------------------------------------- 1 | /** 2 | * Clever programming language 3 | * Copyright (c) Clever Team 4 | * 5 | * This file is distributed under the MIT license. See LICENSE for details. 6 | */ 7 | #include "core/value.h" 8 | #include "core/modmanager.h" 9 | #include "modules/std/concurrent/condition.h" 10 | #include "modules/std/concurrent/module.h" 11 | #include "modules/std/concurrent/mutex.h" 12 | #include "modules/std/concurrent/thread.h" 13 | #include "modules/std/concurrent/sync.h" 14 | 15 | #ifndef CLEVER_THREADS_BEBUG 16 | #undef clever_debug 17 | #define clever_debug(...) 18 | #endif 19 | 20 | namespace clever { namespace modules { namespace std { 21 | 22 | /// Initializes Standard Concurrency module 23 | CLEVER_MODULE_INIT(ConcurrencyModule) 24 | { 25 | addType(new Mutex); 26 | addType(new Condition); 27 | addType(new Thread); 28 | addType(new Sync); 29 | } 30 | 31 | }}} // clever::modules::std 32 | -------------------------------------------------------------------------------- /modules/std/concurrent/module.h: -------------------------------------------------------------------------------- 1 | /** 2 | * Clever programming language 3 | * Copyright (c) Clever Team 4 | * 5 | * This file is distributed under the MIT license. See LICENSE for details. 6 | */ 7 | 8 | #ifndef CLEVER_STD_CONCURRENT_H 9 | #define CLEVER_STD_CONCURRENT_H 10 | 11 | #include "core/vm.h" 12 | #include "core/module.h" 13 | 14 | namespace clever { namespace modules { namespace std { 15 | 16 | /// Standard Concurrency Module 17 | class ConcurrencyModule : public Module { 18 | public: 19 | ConcurrencyModule() 20 | : Module("std.concurrent") { } 21 | 22 | CLEVER_MODULE_VIRTUAL_METHODS_DECLARATION; 23 | private: 24 | DISALLOW_COPY_AND_ASSIGN(ConcurrencyModule); 25 | }; 26 | 27 | }}} // clever::modules::std 28 | 29 | #endif // CLEVER_STD_CONCURRENT_H 30 | -------------------------------------------------------------------------------- /modules/std/concurrent/mutex.cc: -------------------------------------------------------------------------------- 1 | /** 2 | * Clever programming language 3 | * Copyright (c) Clever Team 4 | * 5 | * This file is distributed under the MIT license. See LICENSE for details. 6 | */ 7 | 8 | #include "core/clever.h" 9 | #include "core/value.h" 10 | #include "core/type.h" 11 | #include "modules/std/concurrent/mutex.h" 12 | #include "modules/std/core/function.h" 13 | 14 | #ifndef CLEVER_THREADS_BEBUG 15 | #undef clever_debug 16 | #define clever_debug(...) 17 | #endif 18 | 19 | namespace clever { namespace modules { namespace std { 20 | 21 | CLEVER_METHOD(Mutex::lock) 22 | { 23 | MutexObject* mutex = clever_get_this(MutexObject*); 24 | if (!mutex) { 25 | //CLEVER_THROW(eventually); 26 | return; 27 | } 28 | 29 | result->setBool(mutex->mutex.lock()); 30 | } 31 | 32 | CLEVER_METHOD(Mutex::trylock) 33 | { 34 | MutexObject* mutex = clever_get_this(MutexObject*); 35 | if (!mutex) { 36 | //CLEVER_THROW(eventually); 37 | return; 38 | } 39 | 40 | result->setBool(mutex->mutex.trylock()); 41 | } 42 | 43 | CLEVER_METHOD(Mutex::unlock) 44 | { 45 | MutexObject* mutex = clever_get_this(MutexObject*); 46 | 47 | if (!mutex) { 48 | //CLEVER_THROW(eventually); 49 | return; 50 | } 51 | 52 | result->setBool(mutex->mutex.unlock()); 53 | } 54 | 55 | CLEVER_METHOD(Mutex::ctor) 56 | { 57 | result->setObj(this, new MutexObject); 58 | } 59 | 60 | CLEVER_TYPE_INIT(Mutex::init) 61 | { 62 | 63 | setConstructor((MethodPtr) &Mutex::ctor); 64 | 65 | addMethod(new Function("lock", (MethodPtr) &Mutex::lock)); 66 | addMethod(new Function("trylock", (MethodPtr) &Mutex::trylock)); 67 | addMethod(new Function("unlock", (MethodPtr) &Mutex::unlock)); 68 | } 69 | 70 | }}} // clever::modules::std 71 | -------------------------------------------------------------------------------- /modules/std/concurrent/mutex.h: -------------------------------------------------------------------------------- 1 | /** 2 | * Clever programming language 3 | * Copyright (c) Clever Team 4 | * 5 | * This file is distributed under the MIT license. See LICENSE for details. 6 | */ 7 | 8 | #ifndef CLEVER_STD_CONCURRENT_MUTEX_H 9 | #define CLEVER_STD_CONCURRENT_MUTEX_H 10 | 11 | #include 12 | 13 | #include "core/cstring.h" 14 | #include "core/type.h" 15 | #include "core/cthread.h" 16 | 17 | namespace clever { namespace modules { namespace std { 18 | 19 | struct MutexObject : public TypeObject { 20 | MutexObject() 21 | : mutex() {} 22 | 23 | ~MutexObject() { 24 | } 25 | 26 | CMutex mutex; 27 | }; 28 | 29 | class Mutex : public Type { 30 | public: 31 | Mutex() 32 | : Type("Mutex") {} 33 | 34 | ~Mutex() {} 35 | 36 | virtual void init(); 37 | 38 | CLEVER_METHOD(ctor); 39 | CLEVER_METHOD(lock); 40 | CLEVER_METHOD(unlock); 41 | CLEVER_METHOD(trylock); 42 | }; 43 | 44 | }}} // clever::modules::std 45 | 46 | #endif // CLEVER_STD_CONCURRENT_MUTEX_H 47 | -------------------------------------------------------------------------------- /modules/std/concurrent/sync.h: -------------------------------------------------------------------------------- 1 | /** 2 | * Clever programming language 3 | * Copyright (c) Clever Team 4 | * 5 | * This file is distributed under the MIT license. See LICENSE for details. 6 | */ 7 | 8 | #ifndef CLEVER_STD_CONCURRENT_SYNC_H 9 | #define CLEVER_STD_CONCURRENT_SYNC_H 10 | 11 | #include 12 | 13 | #include "core/cstring.h" 14 | #include "core/type.h" 15 | #include "core/cthread.h" 16 | 17 | namespace clever { namespace modules { namespace std { 18 | 19 | struct SyncObject : public TypeObject { 20 | SyncObject(size_t n_ids) 21 | : mutex(), n_ids(n_ids), next_id(0), m_status(true) {} 22 | 23 | ~SyncObject() {} 24 | 25 | size_t getID() { 26 | mutex.lock(); 27 | size_t v = next_id; 28 | mutex.unlock(); 29 | return v; 30 | } 31 | 32 | size_t nextID() { 33 | mutex.lock(); 34 | size_t v = next_id; 35 | next_id = (next_id + 1) % n_ids; 36 | mutex.unlock(); 37 | return v; 38 | } 39 | 40 | void setID(size_t v) { 41 | mutex.lock(); 42 | next_id = v; 43 | mutex.unlock(); 44 | } 45 | 46 | size_t getNIDs() { 47 | return n_ids; 48 | } 49 | 50 | bool status() { 51 | mutex.lock(); 52 | bool v = m_status; 53 | mutex.unlock(); 54 | return v; 55 | } 56 | 57 | void setStatus(bool v) { 58 | mutex.lock(); 59 | m_status = v; 60 | mutex.unlock(); 61 | } 62 | 63 | CMutex mutex; 64 | size_t n_ids; 65 | size_t next_id; 66 | bool m_status; 67 | }; 68 | 69 | class Sync : public Type { 70 | public: 71 | Sync() 72 | : Type("Sync") {} 73 | 74 | ~Sync() {} 75 | 76 | virtual void init(); 77 | 78 | CLEVER_METHOD(ctor); 79 | CLEVER_METHOD(status); 80 | CLEVER_METHOD(nextID); 81 | CLEVER_METHOD(setID); 82 | CLEVER_METHOD(setStatus); 83 | CLEVER_METHOD(getID); 84 | CLEVER_METHOD(getNIDs); 85 | }; 86 | 87 | }}} // clever::modules::std 88 | 89 | #endif // CLEVER_STD_CONCURRENT_SYNC_H 90 | -------------------------------------------------------------------------------- /modules/std/concurrent/thread.h: -------------------------------------------------------------------------------- 1 | /** 2 | * Clever programming language 3 | * Copyright (c) Clever Team 4 | * 5 | * This file is distributed under the MIT license. See LICENSE for details. 6 | */ 7 | 8 | #ifndef CLEVER_STD_CONCURRENT_THREAD_H 9 | #define CLEVER_STD_CONCURRENT_THREAD_H 10 | 11 | #include 12 | 13 | #include "core/cstring.h" 14 | #include "core/type.h" 15 | #include "core/cthread.h" 16 | 17 | namespace clever { namespace modules { namespace std { 18 | 19 | struct ThreadData : public TypeObject { 20 | ThreadData() 21 | : entry(NULL), result(NULL), vm(NULL) {} 22 | 23 | ~ThreadData(); 24 | 25 | CThread thread; 26 | CMutex lock; 27 | const Function* entry; 28 | Value* result; 29 | VM* vm; 30 | ::std::vector args; 31 | bool joined; 32 | }; 33 | 34 | class Thread : public Type { 35 | public: 36 | Thread() 37 | : Type("Thread") {} 38 | 39 | ~Thread() {} 40 | 41 | virtual void init(); 42 | 43 | CLEVER_METHOD(ctor); 44 | CLEVER_METHOD(start); 45 | CLEVER_METHOD(wait); 46 | CLEVER_METHOD(getResult); 47 | }; 48 | 49 | }}} // clever::modules::std 50 | 51 | #endif // CLEVER_STD_CONCURRENT_THREAD_H 52 | -------------------------------------------------------------------------------- /modules/std/core/bool.cc: -------------------------------------------------------------------------------- 1 | /** 2 | * Clever programming language 3 | * Copyright (c) Clever Team 4 | * 5 | * This file is distributed under the MIT license. See LICENSE for details. 6 | */ 7 | 8 | #include "modules/std/core/bool.h" 9 | #include "modules/std/core/function.h" 10 | 11 | namespace clever { 12 | 13 | CLEVER_TYPE_OPERATOR(BoolType::equal) 14 | { 15 | if (rhs->isBool()) { 16 | result->setBool(lhs->getBool() == rhs->getBool()); 17 | } 18 | } 19 | 20 | CLEVER_TYPE_OPERATOR(BoolType::not_equal) 21 | { 22 | if (rhs->isBool()) { 23 | result->setBool(lhs->getBool() != rhs->getBool()); 24 | } 25 | } 26 | 27 | CLEVER_TYPE_UNARY_OPERATOR(BoolType::not_op) 28 | { 29 | result->setBool(!lhs->getBool()); 30 | } 31 | 32 | // Bool::Bool() 33 | CLEVER_METHOD(BoolType::ctor) 34 | { 35 | result->setBool(true); 36 | } 37 | 38 | CLEVER_TYPE_INIT(BoolType::init) 39 | { 40 | setConstructor((MethodPtr) &BoolType::ctor); 41 | } 42 | 43 | } // clever 44 | -------------------------------------------------------------------------------- /modules/std/core/bool.h: -------------------------------------------------------------------------------- 1 | /** 2 | * Clever programming language 3 | * Copyright (c) Clever Team 4 | * 5 | * This file is distributed under the MIT license. See LICENSE for details. 6 | */ 7 | 8 | #ifndef CLEVER_BOOL_H 9 | #define CLEVER_BOOL_H 10 | 11 | #include 12 | #include "core/cstring.h" 13 | #include "core/value.h" 14 | #include "core/type.h" 15 | 16 | namespace clever { 17 | 18 | typedef SimpleTypeObject BoolObject; 19 | 20 | class BoolType : public Type { 21 | public: 22 | BoolType() 23 | : Type("Bool") {} 24 | 25 | ~BoolType() {} 26 | 27 | virtual void init(); 28 | 29 | std::string toString(TypeObject* value) const { 30 | if (static_cast(value)->value) { 31 | return "true"; 32 | } else { 33 | return "false"; 34 | } 35 | } 36 | 37 | CLEVER_METHOD(ctor); 38 | CLEVER_TYPE_OPERATOR(equal); 39 | CLEVER_TYPE_OPERATOR(not_equal); 40 | CLEVER_TYPE_UNARY_OPERATOR(not_op); 41 | private: 42 | DISALLOW_COPY_AND_ASSIGN(BoolType); 43 | }; 44 | 45 | } // clever 46 | 47 | #endif // CLEVER_BOOL_H 48 | -------------------------------------------------------------------------------- /modules/std/core/core.cc: -------------------------------------------------------------------------------- 1 | /** 2 | * Clever programming language 3 | * Copyright (c) Clever Team 4 | * 5 | * This file is distributed under the MIT license. See LICENSE for details. 6 | */ 7 | 8 | #include "modules/std/core/core.h" 9 | #include "core/modmanager.h" 10 | #include "core/value.h" 11 | #include "core/native_types.h" 12 | #include "core/type.h" 13 | 14 | namespace clever { 15 | 16 | // Native types 17 | Type* g_clever_int_type; 18 | Type* g_clever_double_type; 19 | Type* g_clever_str_type; 20 | Type* g_clever_func_type; 21 | Type* g_clever_bool_type; 22 | Type* g_clever_array_type; 23 | Type* g_clever_map_type; 24 | 25 | // Iterators 26 | Type* g_clever_arrayiterator_type; 27 | 28 | } // clever 29 | 30 | namespace clever { namespace modules { namespace std { 31 | 32 | CLEVER_MODULE_INIT(CoreModule) 33 | { 34 | // Native type allocation 35 | addType(CLEVER_FUNC_TYPE = new FuncType); 36 | addType(CLEVER_STR_TYPE = new StrType); 37 | addType(CLEVER_INT_TYPE = new IntType); 38 | addType(CLEVER_DOUBLE_TYPE = new DoubleType); 39 | addType(CLEVER_BOOL_TYPE = new BoolType); 40 | addType(CLEVER_ARRAY_TYPE = new ArrayType); 41 | addType(CLEVER_MAP_TYPE = new MapType); 42 | 43 | // Iterators 44 | addType(CLEVER_ARRAYITER_TYPE = new ArrayIterator); 45 | } 46 | 47 | }}} // clever::modules::std 48 | -------------------------------------------------------------------------------- /modules/std/core/core.h: -------------------------------------------------------------------------------- 1 | /** 2 | * Clever programming language 3 | * Copyright (c) Clever Team 4 | * 5 | * This file is distributed under the MIT license. See LICENSE for details. 6 | */ 7 | 8 | #ifndef CLEVER_STD_CORE_H 9 | #define CLEVER_STD_CORE_H 10 | 11 | #include "core/module.h" 12 | 13 | namespace clever { namespace modules { namespace std { 14 | 15 | /// Standard Core Module 16 | class CoreModule : public Module { 17 | public: 18 | CoreModule() 19 | : Module("std.core") {} 20 | 21 | ~CoreModule() {} 22 | 23 | CLEVER_MODULE_VIRTUAL_METHODS_DECLARATION; 24 | private: 25 | DISALLOW_COPY_AND_ASSIGN(CoreModule); 26 | }; 27 | 28 | }}} // clever::modules::std 29 | 30 | #endif // CLEVER_STD_CORE_H 31 | -------------------------------------------------------------------------------- /modules/std/core/double.h: -------------------------------------------------------------------------------- 1 | /** 2 | * Clever programming language 3 | * Copyright (c) Clever Team 4 | * 5 | * This file is distributed under the MIT license. See LICENSE for details. 6 | */ 7 | 8 | #ifndef CLEVER_DOUBLE_H 9 | #define CLEVER_DOUBLE_H 10 | 11 | #include 12 | #include "core/cstring.h" 13 | #include "core/value.h" 14 | #include "core/type.h" 15 | 16 | namespace clever { 17 | 18 | typedef SimpleTypeObject DoubleObject; 19 | 20 | class DoubleType : public Type { 21 | public: 22 | DoubleType() 23 | : Type("Double") {} 24 | 25 | ~DoubleType() {} 26 | 27 | virtual void init(); 28 | 29 | virtual std::string toString(TypeObject* data) const { 30 | std::ostringstream str; 31 | str << static_cast(data)->value; 32 | return str.str(); 33 | } 34 | 35 | CLEVER_TYPE_VIRTUAL_METHOD_DECLARATIONS; 36 | 37 | virtual void increment(Value* value, Clever* clever) const { 38 | value->setInt(value->getDouble()+1); 39 | } 40 | 41 | virtual void decrement(Value* value, Clever* clever) const { 42 | value->setInt(value->getDouble()-1); 43 | } 44 | 45 | CLEVER_METHOD(ctor); 46 | CLEVER_METHOD(to_String); 47 | private: 48 | DISALLOW_COPY_AND_ASSIGN(DoubleType); 49 | }; 50 | 51 | } // clever 52 | 53 | #endif // CLEVER_DOUBLE_H 54 | -------------------------------------------------------------------------------- /modules/std/core/int.h: -------------------------------------------------------------------------------- 1 | /** 2 | * Clever programming language 3 | * Copyright (c) Clever Team 4 | * 5 | * This file is distributed under the MIT license. See LICENSE for details. 6 | */ 7 | 8 | #ifndef CLEVER_INT_H 9 | #define CLEVER_INT_H 10 | 11 | #include 12 | #include "core/cstring.h" 13 | #include "core/value.h" 14 | #include "core/type.h" 15 | 16 | namespace clever { 17 | 18 | typedef SimpleTypeObject IntObject; 19 | 20 | class IntType : public Type { 21 | public: 22 | IntType() 23 | : Type("Int") {} 24 | 25 | ~IntType() {} 26 | 27 | virtual void init(); 28 | 29 | virtual std::string toString(TypeObject* data) const { 30 | std::ostringstream str; 31 | str << static_cast(data)->value; 32 | return str.str(); 33 | } 34 | 35 | CLEVER_TYPE_VIRTUAL_METHOD_DECLARATIONS; 36 | CLEVER_TYPE_VIRTUAL_BITWISE_OPERATORS; 37 | 38 | virtual void increment(Value* value, Clever* clever) const { 39 | value->setInt(value->getInt()+1); 40 | } 41 | 42 | virtual void decrement(Value* value, Clever* clever) const { 43 | value->setInt(value->getInt()-1); 44 | } 45 | 46 | CLEVER_METHOD(ctor); 47 | CLEVER_METHOD(to_String); 48 | private: 49 | DISALLOW_COPY_AND_ASSIGN(IntType); 50 | }; 51 | 52 | } // clever 53 | 54 | #endif // CLEVER_INT_H 55 | -------------------------------------------------------------------------------- /modules/std/core/map.h: -------------------------------------------------------------------------------- 1 | /** 2 | * Clever programming language 3 | * Copyright (c) Clever Team 4 | * 5 | * This file is distributed under the MIT license. See LICENSE for details. 6 | */ 7 | 8 | #ifndef CLEVER_MAP_H 9 | #define CLEVER_MAP_H 10 | 11 | #include 12 | #include 13 | #include "core/cstring.h" 14 | #include "core/value.h" 15 | #include "core/type.h" 16 | 17 | namespace clever { 18 | 19 | typedef std::pair MapObjectPair; 20 | 21 | class MapObject : public TypeObject{ 22 | public: 23 | MapObject() {} 24 | 25 | MapObject(const ::std::vector& args) { 26 | for (size_t i = 0, j = args.size(); i < j; i += 2) { 27 | Value* val = new Value(); 28 | 29 | val->copy(args[i+1]); 30 | 31 | insertValue(*args[i]->getStr(), val); 32 | } 33 | } 34 | 35 | ~MapObject() { 36 | ValueMap::const_iterator it(m_data.begin()), end(m_data.end()); 37 | 38 | for (; it != end; ++it) { 39 | clever_delref(it->second); 40 | } 41 | } 42 | 43 | void insertValue(const ::std::string& str, Value* val) { 44 | m_data.insert(ValuePair(str, val)); 45 | } 46 | 47 | std::map& getData() { return m_data; } 48 | private: 49 | std::map m_data; 50 | 51 | DISALLOW_COPY_AND_ASSIGN(MapObject); 52 | }; 53 | 54 | class MapType : public Type { 55 | public: 56 | MapType() 57 | : Type("Map") {} 58 | 59 | ~MapType() {} 60 | 61 | virtual void init(); 62 | virtual std::string toString(TypeObject*) const; 63 | 64 | virtual Value* CLEVER_FASTCALL at_op(CLEVER_TYPE_AT_OPERATOR_ARGS) const; 65 | 66 | CLEVER_METHOD(ctor); 67 | CLEVER_METHOD(each); 68 | CLEVER_METHOD(exists); 69 | CLEVER_METHOD(insert); 70 | CLEVER_METHOD(size); 71 | private: 72 | DISALLOW_COPY_AND_ASSIGN(MapType); 73 | }; 74 | 75 | } // clever 76 | 77 | #endif // CLEVER_MAP_H 78 | -------------------------------------------------------------------------------- /modules/std/crypto/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | 2 | add_library(modules_std_crypto STATIC 3 | crypto.cc 4 | md5.cc 5 | ) 6 | 7 | -------------------------------------------------------------------------------- /modules/std/crypto/crypto.cc: -------------------------------------------------------------------------------- 1 | /** 2 | * Clever programming language 3 | * Copyright (c) Clever Team 4 | * 5 | * This file is distributed under the MIT license. See LICENSE for details. 6 | */ 7 | 8 | #include "modules/std/crypto/crypto.h" 9 | #include "modules/std/crypto/md5.h" 10 | #include "modules/std/crypto/base64.h" 11 | 12 | namespace clever { namespace modules { namespace std { 13 | 14 | namespace crypto { 15 | 16 | // md5(string) 17 | // Returns the MD5 hashing for the supplied string 18 | static CLEVER_FUNCTION(md5) 19 | { 20 | if (!clever_static_check_args("s")) { 21 | return; 22 | } 23 | 24 | result->setStr(new StrObject(md5(*args[0]->getStr()))); 25 | } 26 | 27 | static CLEVER_FUNCTION(base64_encode) 28 | { 29 | if (!clever_static_check_args("s")) { 30 | return; 31 | } 32 | 33 | result->setStr(new StrObject(base64Encode(*args[0]->getStr()))); 34 | } 35 | 36 | static CLEVER_FUNCTION(base64_decode) 37 | { 38 | if (!clever_static_check_args("s")) { 39 | return; 40 | } 41 | 42 | result->setStr(new StrObject(base64Decode(*args[0]->getStr()))); 43 | } 44 | 45 | } // clever::modules::std::crypto 46 | 47 | CLEVER_MODULE_INIT(CryptoModule) 48 | { 49 | addFunction(new Function("md5", &CLEVER_NS_FNAME(crypto, md5))); 50 | addFunction(new Function("base64_encode", &CLEVER_NS_FNAME(crypto, base64_encode))); 51 | addFunction(new Function("base64_decode", &CLEVER_NS_FNAME(crypto, base64_decode))); 52 | } 53 | 54 | }}} // clever::modules::std 55 | -------------------------------------------------------------------------------- /modules/std/crypto/crypto.h: -------------------------------------------------------------------------------- 1 | /** 2 | * Clever programming language 3 | * Copyright (c) Clever Team 4 | * 5 | * This file is distributed under the MIT license. See LICENSE for details. 6 | */ 7 | 8 | #ifndef CLEVER_CRYPTO_H 9 | #define CLEVER_CRYPTO_H 10 | 11 | #include "core/module.h" 12 | 13 | namespace clever { namespace modules { namespace std { 14 | 15 | class CryptoModule : public Module { 16 | public: 17 | CryptoModule() 18 | : Module("std.crypto") {} 19 | 20 | ~CryptoModule() {} 21 | 22 | CLEVER_MODULE_VIRTUAL_METHODS_DECLARATION; 23 | private: 24 | DISALLOW_COPY_AND_ASSIGN(CryptoModule); 25 | }; 26 | 27 | }}} // clever::modules::std 28 | 29 | #endif // CLEVER_CRYPTO_H 30 | -------------------------------------------------------------------------------- /modules/std/date/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | 2 | add_library(modules_std_date STATIC 3 | module.cc 4 | date.cc 5 | ) 6 | -------------------------------------------------------------------------------- /modules/std/date/date.h: -------------------------------------------------------------------------------- 1 | /** 2 | * Clever programming language 3 | * Copyright (c) Clever Team 4 | * 5 | * This file is distributed under the MIT license. See LICENSE for details. 6 | */ 7 | 8 | #ifndef CLEVER_STD_DATE_DATE_H 9 | #define CLEVER_STD_DATE_DATE_H 10 | 11 | #include "core/cstring.h" 12 | #include "core/type.h" 13 | 14 | namespace clever { namespace modules { namespace std { 15 | 16 | struct DateObject : public TypeObject { 17 | DateObject() 18 | : intern(new time_t) {} 19 | 20 | ~DateObject() { 21 | delete intern; 22 | } 23 | 24 | time_t* intern; 25 | }; 26 | 27 | class Date : public Type { 28 | public: 29 | Date() 30 | : Type("Date") {} 31 | 32 | ~Date() {} 33 | 34 | virtual void init(); 35 | virtual ::std::string toString(TypeObject*) const; 36 | 37 | CLEVER_METHOD(ctor); 38 | CLEVER_METHOD(format); 39 | CLEVER_METHOD(uformat); 40 | CLEVER_METHOD(getTime); 41 | }; 42 | 43 | }}} // clever::modules::std 44 | 45 | #endif // CLEVER_STD_DATE_DATE_H 46 | -------------------------------------------------------------------------------- /modules/std/date/module.cc: -------------------------------------------------------------------------------- 1 | /** 2 | * Clever programming language 3 | * Copyright (c) Clever Team 4 | * 5 | * This file is distributed under the MIT license. See LICENSE for details. 6 | */ 7 | #include "core/value.h" 8 | #include "core/modmanager.h" 9 | #include "modules/std/date/module.h" 10 | #include "modules/std/date/date.h" 11 | 12 | namespace clever { namespace modules { namespace std { 13 | 14 | /// Standard date module initialization 15 | CLEVER_MODULE_INIT(DateModule) 16 | { 17 | addType(new Date); 18 | } 19 | 20 | }}} // clever::modules::std 21 | -------------------------------------------------------------------------------- /modules/std/date/module.h: -------------------------------------------------------------------------------- 1 | /** 2 | * Clever programming language 3 | * Copyright (c) Clever Team 4 | * 5 | * This file is distributed under the MIT license. See LICENSE for details. 6 | */ 7 | 8 | #ifndef CLEVER_STD_DATE_H 9 | #define CLEVER_STD_DATE_H 10 | 11 | #include "core/module.h" 12 | 13 | namespace clever { namespace modules { namespace std { 14 | 15 | /// Standard Date Module 16 | class DateModule : public Module { 17 | public: 18 | DateModule() 19 | : Module("std.date") { } 20 | 21 | ~DateModule() {} 22 | 23 | CLEVER_MODULE_VIRTUAL_METHODS_DECLARATION; 24 | private: 25 | DISALLOW_COPY_AND_ASSIGN(DateModule); 26 | }; 27 | 28 | }}} // clever::modules::std 29 | 30 | #endif // CLEVER_STD_DATE_H 31 | -------------------------------------------------------------------------------- /modules/std/events/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | add_library(modules_std_events STATIC 2 | events.cc 3 | ) 4 | -------------------------------------------------------------------------------- /modules/std/fcgi/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | 2 | add_library(modules_std_fcgi STATIC 3 | fcgi.cc 4 | server.cc 5 | ) 6 | 7 | list(APPEND CLEVER_INCLUDES ${FCGI_INCLUDE_DIRS}) 8 | list(APPEND CLEVER_LIBS ${FCGI_LIBRARIES}) 9 | -------------------------------------------------------------------------------- /modules/std/fcgi/fcgi.cc: -------------------------------------------------------------------------------- 1 | /** 2 | * Clever programming language 3 | * Copyright (c) Clever Team 4 | * 5 | * This file is distributed under the MIT license. See LICENSE for details. 6 | */ 7 | #include "core/value.h" 8 | #include "modules/std/core/function.h" 9 | #include "core/modmanager.h" 10 | #include "modules/std/fcgi/fcgi.h" 11 | #include "modules/std/fcgi/server.h" 12 | 13 | namespace clever { namespace modules { namespace std { 14 | 15 | /// Initializes Standard FCGI module 16 | CLEVER_MODULE_INIT(FCGIModule) 17 | { 18 | addType(new Server); 19 | } 20 | 21 | }}} // clever::modules::std 22 | -------------------------------------------------------------------------------- /modules/std/fcgi/fcgi.h: -------------------------------------------------------------------------------- 1 | /** 2 | * Clever programming language 3 | * Copyright (c) Clever Team 4 | * 5 | * This file is distributed under the MIT license. See LICENSE for details. 6 | */ 7 | 8 | #ifndef CLEVER_STD_FCGI_H 9 | #define CLEVER_STD_FCGI_H 10 | 11 | #include 12 | #ifdef _WIN32 13 | #include 14 | #else 15 | #include 16 | extern char** environ; 17 | #endif 18 | #include "fcgio.h" 19 | #include "fcgi_config.h" // HAVE_IOSTREAM_WITHASSIGN_STREAMBUF 20 | 21 | #include "core/module.h" 22 | 23 | #define CLEVER_FCGI_PAIR(k, v) ::std::pair< ::std::string, ::std::string>(k, v) 24 | #define CLEVER_FCGI_MAP ::std::map< ::std::string, ::std::string> 25 | #define CLEVER_FCGI_ITERATOR CLEVER_FCGI_MAP::const_iterator 26 | #define CLEVER_FCGI_NULL(k) CLEVER_FCGI_PAIR(k, ::std::string("")) 27 | #define CLEVER_FCGI_FIND(m, k) m->find(k) 28 | #define CLEVER_FCGI_BEGIN(m) m->begin() 29 | #define CLEVER_FCGI_END(m) m->end() 30 | #define CLEVER_FCGI_FETCH(f) CSTRING(f->second) 31 | 32 | namespace clever { namespace modules { namespace std { 33 | 34 | /// Standard FCGI Module 35 | class FCGIModule : public Module { 36 | public: 37 | FCGIModule() 38 | : Module("std.fcgi") {} 39 | 40 | ~FCGIModule() {} 41 | 42 | CLEVER_MODULE_VIRTUAL_METHODS_DECLARATION; 43 | private: 44 | DISALLOW_COPY_AND_ASSIGN(FCGIModule); 45 | }; 46 | 47 | }}} // clever::modules::std 48 | 49 | #endif // CLEVER_STD_FCGI_H 50 | -------------------------------------------------------------------------------- /modules/std/ffi/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | 2 | add_library(modules_std_ffi STATIC 3 | ffi.cc 4 | ffistruct.cc 5 | ) 6 | 7 | set_target_properties(modules_std_ffi 8 | PROPERTIES 9 | COMPILE_FLAGS "${FFI_CFLAGS}" 10 | #STATIC_LIBRARY_FLAGS "${FFI_LDFLAGS}" 11 | ) 12 | 13 | -------------------------------------------------------------------------------- /modules/std/ffi/ffi.h: -------------------------------------------------------------------------------- 1 | /** 2 | * Clever programming language 3 | * Copyright (c) Clever Team 4 | * 5 | * This file is distributed under the MIT license. See LICENSE for details. 6 | */ 7 | 8 | 9 | #ifndef CLEVER_STD_FFI_H 10 | #define CLEVER_STD_FFI_H 11 | 12 | #include 13 | #include 14 | #include 15 | #include "core/cstring.h" 16 | #include "core/type.h" 17 | #include "core/vm.h" 18 | #include "core/module.h" 19 | 20 | #ifdef CLEVER_APPLE 21 | # define MACOSX 22 | #endif 23 | 24 | namespace clever { namespace modules { namespace std { 25 | 26 | class FFI; 27 | typedef void* LibHandler; 28 | 29 | typedef ::std::map FFIMethodsMap; 30 | typedef ::std::map FFIMethodsStatus; 31 | 32 | struct FFIData : public TypeObject { 33 | FFIData(const FFI* type) 34 | : m_lib_handler(NULL), m_ffi(type) {} 35 | 36 | ~FFIData(); 37 | 38 | virtual MemberData getMember(const CString*) const; 39 | 40 | ::std::string m_func_name; 41 | ::std::string m_lib_name; 42 | LibHandler m_lib_handler; 43 | const FFI* m_ffi; 44 | }; 45 | 46 | class FFI : public Type { 47 | public: 48 | FFI() 49 | : Type("FFILib"), m_call_handler(NULL) {} 50 | 51 | ~FFI() { 52 | clever_delref(m_call_handler); 53 | } 54 | 55 | virtual void init(); 56 | 57 | MemberData getCallHandler() const { return MemberData(m_call_handler, MemberData::PUBLIC); } 58 | 59 | CLEVER_METHOD(ctor); 60 | CLEVER_METHOD(call); 61 | CLEVER_METHOD(exec); 62 | CLEVER_METHOD(load); 63 | CLEVER_METHOD(unload); 64 | CLEVER_METHOD(callThisFunction); 65 | private: 66 | Value* m_call_handler; 67 | 68 | DISALLOW_COPY_AND_ASSIGN(FFI); 69 | }; 70 | 71 | class FFIModule : public Module { 72 | public: 73 | FFIModule() 74 | : Module("std.ffi") {} 75 | 76 | ~FFIModule() {} 77 | 78 | CLEVER_MODULE_VIRTUAL_METHODS_DECLARATION; 79 | private: 80 | DISALLOW_COPY_AND_ASSIGN(FFIModule); 81 | }; 82 | 83 | }}} // clever::modules::std 84 | 85 | #endif // CLEVER_STD_FFI_H 86 | -------------------------------------------------------------------------------- /modules/std/ffi/ffitypes.h: -------------------------------------------------------------------------------- 1 | /** 2 | * Clever programming language 3 | * Copyright (c) Clever Team 4 | * 5 | * This file is distributed under the MIT license. See LICENSE for details. 6 | */ 7 | 8 | #ifndef CLEVER_STD_FFITYPES_H 9 | #define CLEVER_STD_FFITYPES_H 10 | 11 | #include 12 | #include "core/type.h" 13 | 14 | namespace clever { namespace modules { namespace std { 15 | 16 | class FFITypesBuilder : public TypeObject { 17 | public: 18 | FFITypesBuilder() {} 19 | 20 | FFITypesBuilder(const ::std::string& name) 21 | : m_name(name) {} 22 | 23 | ~FFITypesBuilder() {} 24 | 25 | const CString& getName() { return m_name; } 26 | private: 27 | ::std::string m_name; 28 | 29 | DISALLOW_COPY_AND_ASSIGN(FFITypesBuilder); 30 | }; 31 | 32 | class FFITypes : public Type { 33 | public: 34 | FFITypes() 35 | : Type("FFITypes") {} 36 | 37 | ~FFITypes() { 38 | ExtStructs::iterator it(m_structs.begin()), end(m_structs.end()); 39 | 40 | while (it != end) { 41 | if (it->second) { 42 | delete it->second; 43 | } 44 | ++it; 45 | } 46 | } 47 | 48 | virtual void init(); 49 | 50 | CLEVER_METHOD(ctor); 51 | CLEVER_METHOD(addMember); 52 | CLEVER_METHOD(addFunction); 53 | 54 | static ExtStruct* getStruct(const CString& name); 55 | 56 | static ExtStructs m_structs; 57 | 58 | private: 59 | DISALLOW_COPY_AND_ASSIGN(FFITypes); 60 | }; 61 | 62 | }}} // clever::modules::std 63 | 64 | #endif // CLEVER_STD_FFITYPES_H 65 | -------------------------------------------------------------------------------- /modules/std/file/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | 2 | add_library(modules_std_file STATIC 3 | cfile.cc 4 | file.cc 5 | ) 6 | -------------------------------------------------------------------------------- /modules/std/file/cfile.h: -------------------------------------------------------------------------------- 1 | /** 2 | * Clever programming language 3 | * Copyright (c) Clever Team 4 | * 5 | * This file is distributed under the MIT license. See LICENSE for details. 6 | */ 7 | 8 | #ifndef CLEVER_STD_CFILE_H 9 | #define CLEVER_STD_CFILE_H 10 | 11 | #include 12 | #include "core/type.h" 13 | 14 | namespace clever { namespace modules { namespace std { 15 | 16 | class CFileStream : public TypeObject { 17 | public: 18 | CFileStream(const char* src, ::std::ios_base::openmode mode) 19 | : m_fstream(src, mode) {} 20 | 21 | ~CFileStream() {} 22 | 23 | ::std::fstream& getStream() { return m_fstream; } 24 | private: 25 | ::std::fstream m_fstream; 26 | 27 | DISALLOW_COPY_AND_ASSIGN(CFileStream); 28 | }; 29 | 30 | class CFile : public Type { 31 | public: 32 | CFile() 33 | : Type("File") {} 34 | 35 | ~CFile() {} 36 | 37 | virtual void init(); 38 | 39 | private: 40 | CLEVER_METHOD(ctor); 41 | CLEVER_METHOD(read); 42 | CLEVER_METHOD(readLine); 43 | CLEVER_METHOD(eof); 44 | CLEVER_METHOD(write); 45 | CLEVER_METHOD(open); 46 | CLEVER_METHOD(close); 47 | CLEVER_METHOD(isOpen); 48 | 49 | DISALLOW_COPY_AND_ASSIGN(CFile); 50 | }; 51 | 52 | }}} // clever::modules::std 53 | 54 | #endif // CLEVER_STD_CFILE_H 55 | -------------------------------------------------------------------------------- /modules/std/file/file.h: -------------------------------------------------------------------------------- 1 | /** 2 | * Clever programming language 3 | * Copyright (c) Clever Team 4 | * 5 | * This file is distributed under the MIT license. See LICENSE for details. 6 | */ 7 | 8 | #ifndef CLEVER_STD_FILE_H 9 | #define CLEVER_STD_FILE_H 10 | 11 | #include "core/module.h" 12 | 13 | namespace clever { namespace modules { namespace std { 14 | 15 | /// Standard File Module 16 | class FileModule : public Module { 17 | public: 18 | FileModule() 19 | : Module("std.file") {} 20 | 21 | ~FileModule() {} 22 | 23 | CLEVER_MODULE_VIRTUAL_METHODS_DECLARATION; 24 | private: 25 | DISALLOW_COPY_AND_ASSIGN(FileModule); 26 | }; 27 | 28 | }}} // clever::modules::std 29 | 30 | #endif // CLEVER_STD_FILE_H 31 | -------------------------------------------------------------------------------- /modules/std/getopt/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | 2 | add_library(modules_std_getopt STATIC 3 | module.cc 4 | ) 5 | 6 | -------------------------------------------------------------------------------- /modules/std/getopt/module.cc: -------------------------------------------------------------------------------- 1 | /** 2 | * Clever programming language 3 | * Copyright (c) Clever Team 4 | * 5 | * This file is distributed under the MIT license. See LICENSE for details. 6 | */ 7 | 8 | #include "modules/std/getopt/module.h" 9 | #include "modules/std/core/array.h" 10 | #include "modules/std/core/map.h" 11 | 12 | namespace clever { namespace modules { namespace std { 13 | 14 | namespace getopt { 15 | 16 | static CLEVER_FUNCTION(getopt) 17 | { 18 | if (!clever_static_check_args("as|a")) { 19 | return; 20 | } 21 | 22 | MapObject* map = new MapObject; 23 | ArrayObject* argv = static_cast(args[0]->getObj()); 24 | const char* spec = args[1]->getStr()->c_str(); 25 | size_t nargs = argv->getData().size(); 26 | size_t nspec = args[1]->getStr()->size(); 27 | 28 | bool has_long_opts = args.size() == 3; 29 | ArrayObject* arr_opts = has_long_opts ? static_cast(args[2]->getObj()) : NULL; 30 | size_t nlongopts = has_long_opts ? arr_opts->getData().size() : 0; 31 | 32 | if (nargs == 0) { 33 | result->setObj(CLEVER_MAP_TYPE, map); 34 | return; 35 | } 36 | 37 | for (size_t i = 0; i < nargs; ++i) { 38 | const char* arg = argv->getData()[i]->getStr()->c_str(); 39 | 40 | if (arg[0] != '-' || arg[1] == '\0') { 41 | continue; 42 | } 43 | 44 | if (arg[1] == '-' && has_long_opts) { 45 | for (size_t j = 0; j < nlongopts; ++j) { 46 | if (::std::string(arg+2) == *arr_opts->getData()[j]->getStr()) { 47 | map->insertValue(::std::string(arg+2), 48 | new Value(true, true)); 49 | } 50 | } 51 | } else { 52 | for (size_t j = 0; j < nspec; ++j) { 53 | if (spec[j] == arg[1]) { 54 | map->insertValue(::std::string(&spec[j], 1), 55 | new Value(true, true)); 56 | } 57 | } 58 | } 59 | } 60 | 61 | result->setObj(CLEVER_MAP_TYPE, map); 62 | } 63 | 64 | } // clever::modules::std::getopt 65 | 66 | CLEVER_MODULE_INIT(GetoptModule) 67 | { 68 | addFunction(new Function("getopt", &CLEVER_NS_FNAME(getopt, getopt))); 69 | } 70 | 71 | }}} // clever::modules::std 72 | -------------------------------------------------------------------------------- /modules/std/getopt/module.h: -------------------------------------------------------------------------------- 1 | /** 2 | * Clever programming language 3 | * Copyright (c) Clever Team 4 | * 5 | * This file is distributed under the MIT license. See LICENSE for details. 6 | */ 7 | 8 | #ifndef CLEVER_STD_GETOPT_H 9 | #define CLEVER_STD_GETOPT_H 10 | 11 | #include "core/module.h" 12 | 13 | namespace clever { namespace modules { namespace std { 14 | 15 | class GetoptModule : public Module { 16 | public: 17 | GetoptModule() 18 | : Module("std.getopt") {} 19 | 20 | ~GetoptModule() {} 21 | 22 | CLEVER_MODULE_VIRTUAL_METHODS_DECLARATION; 23 | private: 24 | DISALLOW_COPY_AND_ASSIGN(GetoptModule); 25 | }; 26 | 27 | }}} // clever::modules::std 28 | 29 | #endif // CLEVER_STD_GETOPT_H 30 | -------------------------------------------------------------------------------- /modules/std/io/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | 2 | add_library(modules_std_io STATIC 3 | io.cc 4 | serializer.cc 5 | ) 6 | 7 | -------------------------------------------------------------------------------- /modules/std/io/io.h: -------------------------------------------------------------------------------- 1 | /** 2 | * Clever programming language 3 | * Copyright (c) Clever Team 4 | * 5 | * This file is distributed under the MIT license. See LICENSE for details. 6 | */ 7 | 8 | #ifndef CLEVER_STD_IO_H 9 | #define CLEVER_STD_IO_H 10 | 11 | #include "core/module.h" 12 | 13 | namespace clever { namespace modules { namespace std { 14 | 15 | /// Standard IO Module 16 | class IOModule : public Module { 17 | public: 18 | IOModule() 19 | : Module("std.io") {} 20 | 21 | ~IOModule() {} 22 | 23 | CLEVER_MODULE_VIRTUAL_METHODS_DECLARATION; 24 | private: 25 | DISALLOW_COPY_AND_ASSIGN(IOModule); 26 | }; 27 | 28 | }}} // clever::modules::std 29 | 30 | #endif // CLEVER_STD_IO_H 31 | -------------------------------------------------------------------------------- /modules/std/io/serializer.cc: -------------------------------------------------------------------------------- 1 | /** 2 | * Clever programming language 3 | * Copyright (c) Clever Team 4 | * 5 | * This file is distributed under the MIT license. See LICENSE for details. 6 | */ 7 | 8 | #include 9 | #include 10 | #include 11 | #include "core/cexception.h" 12 | #include "modules/std/core/function.h" 13 | #include "modules/std/io/serializer.h" 14 | 15 | namespace clever { namespace modules { namespace std { 16 | 17 | ::std::string Serializer::toString(TypeObject* obj) const 18 | { 19 | SerializerData* sobj = static_cast(obj); 20 | 21 | return sobj->type->toString(sobj->info.second); 22 | } 23 | 24 | // Serializer.serialize() 25 | CLEVER_METHOD(Serializer::doSerialize) 26 | { 27 | if (!clever_static_check_args(".")) { 28 | return; 29 | } 30 | 31 | SerializerData* sobj = new SerializerData(args[0]->getType()); 32 | 33 | sobj->info = args[0]->getType()->serialize(args[0]); 34 | 35 | clever_addref(args[0]->getObj()); 36 | 37 | result->setObj(this, sobj); 38 | } 39 | 40 | // Serializer.unserialize() 41 | CLEVER_METHOD(Serializer::doUnserialize) 42 | { 43 | if (!clever_static_check_args(".")) { 44 | return; 45 | } 46 | 47 | if (args[0]->getType() != this) { 48 | clever_throw("Parameter must be of SerializerData type"); 49 | return; 50 | } 51 | SerializerData* sobj = clever_get_object(SerializerData*, args[0]); 52 | Value* res = unserialize(sobj->type, sobj->info); 53 | 54 | if (res) { 55 | result->copy(res); 56 | clever_delref(res); 57 | } 58 | } 59 | 60 | // Serializer type initialization 61 | CLEVER_TYPE_INIT(Serializer::init) 62 | { 63 | addMethod(new Function("serialize", (MethodPtr)&Serializer::doSerialize)) 64 | ->setStatic(); 65 | 66 | addMethod(new Function("unserialize", (MethodPtr)&Serializer::doUnserialize)) 67 | ->setStatic(); 68 | } 69 | 70 | }}} // clever::modules::std 71 | -------------------------------------------------------------------------------- /modules/std/io/serializer.h: -------------------------------------------------------------------------------- 1 | /** 2 | * Clever programming language 3 | * Copyright (c) Clever Team 4 | * 5 | * This file is distributed under the MIT license. See LICENSE for details. 6 | */ 7 | 8 | #ifndef CLEVER_MOD_IO_SERIALIZER 9 | #define CLEVER_MOD_IO_SERIALIZER 10 | 11 | #include "core/type.h" 12 | 13 | namespace clever { namespace modules { namespace std { 14 | 15 | struct SerializerData : public TypeObject { 16 | SerializerData(const Type* type_) 17 | : type(type_) {} 18 | 19 | ~SerializerData() { 20 | if (info.second) { 21 | clever_delref(info.second); 22 | } 23 | } 24 | 25 | const Type* type; 26 | ::std::pair info; 27 | }; 28 | 29 | class Serializer : public Type { 30 | public: 31 | Serializer() 32 | : Type("Serializer") {} 33 | 34 | ~Serializer() {} 35 | 36 | virtual void init(); 37 | virtual ::std::string toString(TypeObject*) const; 38 | 39 | CLEVER_METHOD(doSerialize); 40 | CLEVER_METHOD(doUnserialize); 41 | 42 | private: 43 | DISALLOW_COPY_AND_ASSIGN(Serializer); 44 | }; 45 | 46 | }}} // clever::modules::std 47 | 48 | #endif // CLEVER_MOD_IO_SERIALIZER 49 | -------------------------------------------------------------------------------- /modules/std/json/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | 2 | add_library(modules_std_json STATIC 3 | json.cc 4 | ) 5 | -------------------------------------------------------------------------------- /modules/std/json/json.h: -------------------------------------------------------------------------------- 1 | /** 2 | * Clever programming language 3 | * Copyright (c) Clever Team 4 | * 5 | * This file is distributed under the MIT license. See LICENSE for details. 6 | */ 7 | 8 | #ifndef CLEVER_STD_JSON_H 9 | #define CLEVER_STD_JSON_H 10 | 11 | #include "core/module.h" 12 | 13 | namespace clever { namespace modules { namespace std { 14 | 15 | /// Standard File Module 16 | class JsonModule : public Module { 17 | public: 18 | JsonModule() 19 | : Module("std.json") {} 20 | 21 | ~JsonModule() {} 22 | 23 | CLEVER_MODULE_VIRTUAL_METHODS_DECLARATION; 24 | private: 25 | DISALLOW_COPY_AND_ASSIGN(JsonModule); 26 | }; 27 | 28 | }}} // clever::modules::std 29 | 30 | #endif // CLEVER_STD_JSON_H 31 | -------------------------------------------------------------------------------- /modules/std/math/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | 2 | add_library(modules_std_math STATIC 3 | math.cc 4 | ) 5 | 6 | -------------------------------------------------------------------------------- /modules/std/math/math.h: -------------------------------------------------------------------------------- 1 | /** 2 | * Clever programming language 3 | * Copyright (c) Clever Team 4 | * 5 | * This file is distributed under the MIT license. See LICENSE for details. 6 | */ 7 | 8 | #ifndef CLEVER_STD_MATH_H 9 | #define CLEVER_STD_MATH_H 10 | 11 | #include "core/module.h" 12 | #include "core/type.h" 13 | 14 | namespace clever { namespace modules { namespace std { 15 | 16 | /// Standard Math Module 17 | class Math : public Module { 18 | public: 19 | Math() 20 | : Module("std.math") {} 21 | 22 | ~Math() {} 23 | 24 | CLEVER_MODULE_VIRTUAL_METHODS_DECLARATION; 25 | private: 26 | DISALLOW_COPY_AND_ASSIGN(Math); 27 | }; 28 | 29 | }}} // clever::modules::std 30 | 31 | #endif // CLEVER_STD_MATH_H 32 | -------------------------------------------------------------------------------- /modules/std/net/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | 2 | add_library(modules_std_net STATIC 3 | net.cc 4 | csocket.cc 5 | tcpsocket.cc 6 | ) 7 | 8 | -------------------------------------------------------------------------------- /modules/std/net/csocket.h: -------------------------------------------------------------------------------- 1 | /** 2 | * Clever programming language 3 | * Copyright (c) Clever Team 4 | * 5 | * This file is distributed under the MIT license. See LICENSE for details. 6 | */ 7 | 8 | #ifndef CLEVER_CSOCKET_H 9 | #define CLEVER_CSOCKET_H 10 | 11 | #include 12 | #ifndef _WIN32 13 | #include 14 | #include 15 | #include 16 | #include 17 | #include 18 | #else 19 | #include 20 | #include 21 | #endif 22 | #include "core/clever.h" 23 | 24 | #ifndef NO_ERROR 25 | #define NO_ERROR 0 26 | #endif 27 | 28 | namespace clever { 29 | 30 | class CSocket { 31 | public: 32 | CSocket() 33 | : m_timeout(0) {} 34 | ~CSocket(); 35 | 36 | void setHost(const char *addr); 37 | void setPort(const int port); 38 | void setTimeout(const int time); 39 | 40 | bool connect(); 41 | bool close(); 42 | 43 | bool receive(const char *buffer, int length); 44 | bool send(const char *buffer, int length); 45 | 46 | bool isOpen(); 47 | bool poll(); 48 | 49 | std::string getErrorString() { return m_error_string; } 50 | int getError() { return m_error; } 51 | 52 | private: 53 | void resetError(); 54 | void setError(); 55 | 56 | // Error 57 | int m_error; 58 | std::string m_error_string; 59 | 60 | // Socket and socket-related 61 | int m_socket; 62 | struct sockaddr_in m_local; 63 | std::string m_host; 64 | std::string m_port; 65 | 66 | // Timeout 67 | unsigned int m_timeout; 68 | 69 | DISALLOW_COPY_AND_ASSIGN(CSocket); 70 | }; 71 | 72 | } // clever 73 | 74 | #endif // CLEVER_CSOCKET_H 75 | -------------------------------------------------------------------------------- /modules/std/net/net.cc: -------------------------------------------------------------------------------- 1 | /** 2 | * Clever programming language 3 | * Copyright (c) Clever Team 4 | * 5 | * This file is distributed under the MIT license. See LICENSE for details. 6 | */ 7 | 8 | #include "core/value.h" 9 | #include "modules/std/net/net.h" 10 | #include "modules/std/net/tcpsocket.h" 11 | #include "core/modmanager.h" 12 | 13 | namespace clever { namespace modules { namespace std { 14 | 15 | /// Initializes Standard module 16 | CLEVER_MODULE_INIT(NetModule) 17 | { 18 | addType(new net::TcpSocket()); 19 | } 20 | 21 | }}} // clever::modules::std 22 | -------------------------------------------------------------------------------- /modules/std/net/net.h: -------------------------------------------------------------------------------- 1 | /** 2 | * Clever programming language 3 | * Copyright (c) Clever Team 4 | * 5 | * This file is distributed under the MIT license. See LICENSE for details. 6 | */ 7 | 8 | #ifndef CLEVER_STD_NET_H 9 | #define CLEVER_STD_NET_H 10 | 11 | #include "core/module.h" 12 | #include "core/value.h" 13 | 14 | namespace clever { namespace modules { namespace std { 15 | 16 | class NetModule : public Module { 17 | public: 18 | NetModule() 19 | : Module("std.net") { } 20 | 21 | ~NetModule() { } 22 | 23 | CLEVER_MODULE_VIRTUAL_METHODS_DECLARATION; 24 | private: 25 | DISALLOW_COPY_AND_ASSIGN(NetModule); 26 | }; 27 | 28 | }}} // clever::modules::std 29 | 30 | #endif // CLEVER_STD_NET_H 31 | -------------------------------------------------------------------------------- /modules/std/net/tcpsocket.h: -------------------------------------------------------------------------------- 1 | /** 2 | * Clever programming language 3 | * Copyright (c) Clever Team 4 | * 5 | * This file is distributed under the MIT license. See LICENSE for details. 6 | */ 7 | 8 | #ifndef CLEVER_TCPSOCKET_H 9 | #define CLEVER_TCPSOCKET_H 10 | 11 | #include 12 | #include "core/type.h" 13 | #include "core/value.h" 14 | #include "modules/std/net/csocket.h" 15 | 16 | namespace clever { namespace modules { namespace std { namespace net { 17 | 18 | class SocketObject : public TypeObject { 19 | public: 20 | SocketObject() {} 21 | 22 | ~SocketObject() {} 23 | 24 | CSocket& getSocket() { return m_socket; } 25 | private: 26 | CSocket m_socket; 27 | 28 | DISALLOW_COPY_AND_ASSIGN(SocketObject); 29 | }; 30 | 31 | class TcpSocket : public Type { 32 | public: 33 | TcpSocket() : 34 | Type("TcpSocket") { } 35 | 36 | virtual void init(); 37 | 38 | // Type methods 39 | CLEVER_METHOD(ctor); 40 | CLEVER_METHOD(setHost); 41 | CLEVER_METHOD(setPort); 42 | CLEVER_METHOD(setTimeout); 43 | CLEVER_METHOD(connect); 44 | CLEVER_METHOD(close); 45 | CLEVER_METHOD(receive); 46 | CLEVER_METHOD(send); 47 | CLEVER_METHOD(isOpen); 48 | CLEVER_METHOD(poll); 49 | CLEVER_METHOD(good); 50 | CLEVER_METHOD(getError); 51 | CLEVER_METHOD(getErrorMessage); 52 | CLEVER_METHOD(do_assign); 53 | private: 54 | DISALLOW_COPY_AND_ASSIGN(TcpSocket); 55 | }; 56 | 57 | }}}} // clever::modules::std::net 58 | 59 | #endif // CLEVER_TCPSOCKET_H 60 | -------------------------------------------------------------------------------- /modules/std/reflection/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | 2 | add_library(modules_std_reflection STATIC 3 | reflection.cc 4 | reflect.cc 5 | ) 6 | 7 | -------------------------------------------------------------------------------- /modules/std/reflection/reflect.h: -------------------------------------------------------------------------------- 1 | /** 2 | * Clever programming language 3 | * Copyright (c) Clever Team 4 | * 5 | * This file is distributed under the MIT license. See LICENSE for details. 6 | */ 7 | 8 | #ifndef CLEVER_REFLECT_H 9 | #define CLEVER_REFLECT_H 10 | 11 | #include 12 | #include "core/type.h" 13 | 14 | namespace clever { namespace modules { namespace std { namespace reflection { 15 | 16 | class ReflectObject : public TypeObject { 17 | public: 18 | ReflectObject() 19 | : m_data(NULL) {} 20 | 21 | explicit ReflectObject(Value* data) 22 | : m_data(data) {} 23 | 24 | ~ReflectObject() {} 25 | 26 | void setData(Value* value) { m_data = value; } 27 | Value* getData() const { return m_data; } 28 | private: 29 | Value* m_data; 30 | 31 | DISALLOW_COPY_AND_ASSIGN(ReflectObject); 32 | }; 33 | 34 | class ReflectType : public Type { 35 | public: 36 | ReflectType() 37 | : Type("Reflect") {} 38 | 39 | ~ReflectType() {} 40 | 41 | virtual void init(); 42 | virtual ::std::string toString(TypeObject*) const; 43 | 44 | CLEVER_METHOD(ctor); 45 | CLEVER_METHOD(getType); 46 | 47 | CLEVER_METHOD(isFunction); 48 | CLEVER_METHOD(isInt); 49 | CLEVER_METHOD(isDouble); 50 | CLEVER_METHOD(isString); 51 | CLEVER_METHOD(isBool); 52 | CLEVER_METHOD(isMap); 53 | CLEVER_METHOD(isArray); 54 | 55 | CLEVER_METHOD(getName); 56 | CLEVER_METHOD(isStatic); 57 | CLEVER_METHOD(isVariadic); 58 | CLEVER_METHOD(isUserDefined); 59 | CLEVER_METHOD(isInternal); 60 | CLEVER_METHOD(getNumArgs); 61 | CLEVER_METHOD(getNumReqArgs); 62 | 63 | CLEVER_METHOD(getMethods); 64 | CLEVER_METHOD(getProperties); 65 | CLEVER_METHOD(getInternClassSizes); 66 | 67 | private: 68 | DISALLOW_COPY_AND_ASSIGN(ReflectType); 69 | }; 70 | 71 | }}}} // clever::modules::std::reflection 72 | 73 | #endif // CLEVER_REFLECT_H 74 | -------------------------------------------------------------------------------- /modules/std/reflection/reflection.h: -------------------------------------------------------------------------------- 1 | /** 2 | * Clever programming language 3 | * Copyright (c) Clever Team 4 | * 5 | * This file is distributed under the MIT license. See LICENSE for details. 6 | */ 7 | 8 | #ifndef CLEVER_STD_REFLECTION_H 9 | #define CLEVER_STD_REFLECTION_H 10 | 11 | #include "core/module.h" 12 | 13 | namespace clever { namespace modules { namespace std { 14 | 15 | /// Standard Reflection Module 16 | class Reflection : public Module { 17 | public: 18 | Reflection() 19 | : Module("std.reflection") {} 20 | 21 | ~Reflection() {} 22 | 23 | CLEVER_MODULE_VIRTUAL_METHODS_DECLARATION; 24 | private: 25 | DISALLOW_COPY_AND_ASSIGN(Reflection); 26 | }; 27 | 28 | }}} // clever::modules::std 29 | 30 | #endif // CLEVER_STD_IO_H 31 | -------------------------------------------------------------------------------- /modules/std/regex/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | 2 | add_library(modules_std_regex STATIC 3 | regex.cc 4 | pcre.cc 5 | ) 6 | 7 | list(APPEND CLEVER_INCLUDES ${PCRECPP_INCLUDE_DIRS}) 8 | list(APPEND CLEVER_LIBS ${PCRECPP_LIBRARIES}) 9 | 10 | -------------------------------------------------------------------------------- /modules/std/regex/pcre.h: -------------------------------------------------------------------------------- 1 | /** 2 | * Clever programming language 3 | * Copyright (c) Clever Team 4 | * 5 | * This file is distributed under the MIT license. See LICENSE for details. 6 | */ 7 | 8 | #ifndef CLEVER_STD_REGEX_PCRE_H 9 | #define CLEVER_STD_REGEX_PCRE_H 10 | 11 | #include 12 | #include "core/type.h" 13 | 14 | namespace clever { namespace modules { namespace std { namespace regex { 15 | 16 | struct PcreMatch { 17 | public: 18 | PcreMatch() 19 | : last_input(NULL), groups(NULL), matches(NULL), n_groups(0) {} 20 | 21 | ~PcreMatch() { 22 | if (groups == NULL) { 23 | return; 24 | } 25 | delete[] matches; 26 | 27 | for (int i = 0; i < n_groups; ++i) { 28 | delete groups[i]; 29 | } 30 | 31 | delete[] groups; 32 | } 33 | 34 | const CString* last_input; 35 | pcrecpp::Arg** groups; 36 | ::std::string* matches; 37 | int n_groups; 38 | pcrecpp::StringPiece input; 39 | private: 40 | DISALLOW_COPY_AND_ASSIGN(PcreMatch); 41 | }; 42 | 43 | struct PcreObject : public TypeObject { 44 | public: 45 | PcreObject() 46 | : re(NULL) {} 47 | 48 | virtual ~PcreObject() { 49 | if (re) { 50 | delete re; 51 | } 52 | } 53 | 54 | pcrecpp::RE* re; 55 | PcreMatch match; 56 | private: 57 | DISALLOW_COPY_AND_ASSIGN(PcreObject); 58 | }; 59 | 60 | class Pcre : public Type { 61 | public: 62 | Pcre() 63 | : Type("Regex") {} 64 | 65 | virtual void init(); 66 | 67 | // Methods 68 | CLEVER_METHOD(constructor); 69 | CLEVER_METHOD(test); 70 | CLEVER_METHOD(match); 71 | CLEVER_METHOD(group); 72 | CLEVER_METHOD(getPattern); 73 | CLEVER_METHOD(getError); 74 | CLEVER_METHOD(replace); 75 | CLEVER_METHOD(replaceAll); 76 | CLEVER_METHOD(do_assign); 77 | 78 | // Static methods 79 | CLEVER_METHOD(quote); 80 | private: 81 | DISALLOW_COPY_AND_ASSIGN(Pcre); 82 | }; 83 | 84 | }}}} // clever::modules::std::regex 85 | 86 | #endif 87 | -------------------------------------------------------------------------------- /modules/std/regex/regex.cc: -------------------------------------------------------------------------------- 1 | /** 2 | * Clever programming language 3 | * Copyright (c) Clever Team 4 | * 5 | * This file is distributed under the MIT license. See LICENSE for details. 6 | */ 7 | 8 | #include 9 | #include "modules/std/regex/regex.h" 10 | #include "modules/std/regex/pcre.h" 11 | 12 | namespace clever { namespace modules { namespace std { 13 | 14 | // Regex module initialization 15 | CLEVER_MODULE_INIT(Regex) 16 | { 17 | addType(new regex::Pcre); 18 | } 19 | 20 | }}} // clever::packages:std 21 | -------------------------------------------------------------------------------- /modules/std/regex/regex.h: -------------------------------------------------------------------------------- 1 | /** 2 | * Clever programming language 3 | * Copyright (c) Clever Team 4 | * 5 | * This file is distributed under the MIT license. See LICENSE for details. 6 | */ 7 | 8 | #ifndef CLEVER_STD_REGEX_H 9 | #define CLEVER_STD_REGEX_H 10 | 11 | #include "core/module.h" 12 | 13 | namespace clever { namespace modules { namespace std { 14 | 15 | class Regex : public Module { 16 | public: 17 | Regex() 18 | : Module("std.regex") {} 19 | 20 | ~Regex() {} 21 | 22 | CLEVER_MODULE_VIRTUAL_METHODS_DECLARATION; 23 | private: 24 | DISALLOW_COPY_AND_ASSIGN(Regex); 25 | }; 26 | 27 | }}} // clever::modules::std 28 | 29 | #endif 30 | -------------------------------------------------------------------------------- /modules/std/std_forwarder.h: -------------------------------------------------------------------------------- 1 | /** 2 | * Clever programming language 3 | * Copyright (c) Clever Team 4 | * 5 | * This file is distributed under the MIT license. See LICENSE for details. 6 | */ 7 | #include "modules/std/core/core.h" 8 | 9 | #ifdef HAVE_MOD_STD_CONCURRENT 10 | # include "modules/std/concurrent/module.h" 11 | #endif 12 | #ifdef HAVE_MOD_STD_EVENTS 13 | # include "modules/std/events/events.h" 14 | #endif 15 | #ifdef HAVE_MOD_STD_SYS 16 | # include "modules/std/sys/sys.h" 17 | #endif 18 | #ifdef HAVE_MOD_STD_DATE 19 | # include "modules/std/date/module.h" 20 | #endif 21 | #ifdef HAVE_MOD_STD_IO 22 | # include "modules/std/io/io.h" 23 | #endif 24 | #ifdef HAVE_MOD_STD_FILE 25 | # include "modules/std/file/file.h" 26 | #endif 27 | #ifdef HAVE_MOD_STD_REFLECTION 28 | # include "modules/std/reflection/reflection.h" 29 | #endif 30 | #ifdef HAVE_MOD_STD_MATH 31 | # include "modules/std/math/math.h" 32 | #endif 33 | #ifdef HAVE_MOD_STD_UNICODE 34 | # include "modules/std/unicode/unicode.h" 35 | #endif 36 | #ifdef HAVE_MOD_STD_NET 37 | # include "modules/std/net/net.h" 38 | #endif 39 | #ifdef HAVE_MOD_STD_FCGI 40 | # include "modules/std/fcgi/fcgi.h" 41 | #endif 42 | #ifdef HAVE_MOD_STD_CRYPTO 43 | # include "modules/std/crypto/crypto.h" 44 | #endif 45 | #ifdef HAVE_MOD_STD_FFI 46 | # include "modules/std/ffi/ffi.h" 47 | #endif 48 | #ifdef HAVE_MOD_STD_CLEVER 49 | # include "modules/std/clever/module.h" 50 | #endif 51 | #ifdef HAVE_MOD_STD_JSON 52 | # include "modules/std/json/json.h" 53 | #endif 54 | #ifdef HAVE_MOD_STD_REGEX 55 | # include "modules/std/regex/regex.h" 56 | #endif 57 | #ifdef HAVE_MOD_STD_COLLECTION 58 | # include "modules/std/collection/module.h" 59 | #endif 60 | #ifdef HAVE_MOD_STD_GETOPT 61 | # include "modules/std/getopt/module.h" 62 | #endif 63 | -------------------------------------------------------------------------------- /modules/std/std_pkg.cc: -------------------------------------------------------------------------------- 1 | /** 2 | * Clever programming language 3 | * Copyright (c) Clever Team 4 | * 5 | * This file is distributed under the MIT license. See LICENSE for details. 6 | */ 7 | 8 | #include "modules/std/std_pkg.h" 9 | 10 | namespace clever { namespace modules { 11 | 12 | // Initializes Std package 13 | void Std::init() 14 | { 15 | addModule(new std::CoreModule); 16 | #ifdef HAVE_MOD_STD_CLEVER 17 | addModule(new std::CleverModule); 18 | #endif 19 | #ifdef HAVE_MOD_STD_CONCURRENT 20 | addModule(new std::ConcurrencyModule); 21 | #endif 22 | #ifdef HAVE_MOD_STD_EVENTS 23 | addModule(new std::EventsModule); 24 | #endif 25 | #ifdef HAVE_MOD_STD_DATE 26 | addModule(new std::DateModule); 27 | #endif 28 | #ifdef HAVE_MOD_STD_IO 29 | addModule(new std::IOModule); 30 | #endif 31 | #ifdef HAVE_MOD_STD_REFLECTION 32 | addModule(new std::Reflection); 33 | #endif 34 | #ifdef HAVE_MOD_STD_MATH 35 | addModule(new std::Math); 36 | #endif 37 | #ifdef HAVE_MOD_STD_UNICODE 38 | addModule(new std::UnicodeModule); 39 | #endif 40 | #ifdef HAVE_MOD_STD_FCGI 41 | addModule(new std::FCGIModule); 42 | #endif 43 | #ifdef HAVE_MOD_STD_SYS 44 | addModule(new std::SYSModule); 45 | #endif 46 | #ifdef HAVE_MOD_STD_FILE 47 | addModule(new std::FileModule); 48 | #endif 49 | #ifdef HAVE_MOD_STD_NET 50 | addModule(new std::NetModule); 51 | #endif 52 | #ifdef HAVE_MOD_STD_CRYPTO 53 | addModule(new std::CryptoModule); 54 | #endif 55 | #ifdef HAVE_MOD_STD_FFI 56 | addModule(new std::FFIModule); 57 | #endif 58 | #ifdef HAVE_MOD_STD_JSON 59 | addModule(new std::JsonModule); 60 | #endif 61 | #ifdef HAVE_MOD_STD_REGEX 62 | addModule(new std::Regex); 63 | #endif 64 | #ifdef HAVE_MOD_STD_COLLECTION 65 | addModule(new std::CollectionModule); 66 | #endif 67 | #ifdef HAVE_MOD_STD_GETOPT 68 | addModule(new std::GetoptModule); 69 | #endif 70 | } 71 | 72 | }} // clever::modules 73 | -------------------------------------------------------------------------------- /modules/std/std_pkg.h: -------------------------------------------------------------------------------- 1 | /** 2 | * Clever programming language 3 | * Copyright (c) Clever Team 4 | * 5 | * This file is distributed under the MIT license. See LICENSE for details. 6 | */ 7 | 8 | #ifndef CLEVER_STD_PACKAGE_H 9 | #define CLEVER_STD_PACKAGE_H 10 | 11 | #include "core/clever.h" 12 | #include "modules/std/std_forwarder.h" 13 | #include "core/module.h" 14 | 15 | namespace clever { namespace modules { 16 | 17 | class Std : public Module { 18 | public: 19 | Std() 20 | : Module("std") {} 21 | 22 | ~Std() {} 23 | 24 | CLEVER_MODULE_VIRTUAL_METHODS_DECLARATION; 25 | private: 26 | DISALLOW_COPY_AND_ASSIGN(Std); 27 | }; 28 | 29 | }} // clever::modules 30 | 31 | #endif // CLEVER_STD_PACKAGE_H 32 | -------------------------------------------------------------------------------- /modules/std/sys/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | 2 | add_library(modules_std_sys STATIC 3 | sys.cc 4 | ) 5 | 6 | -------------------------------------------------------------------------------- /modules/std/sys/sys.h: -------------------------------------------------------------------------------- 1 | /** 2 | * Clever programming language 3 | * Copyright (c) Clever Team 4 | * 5 | * This file is distributed under the MIT license. See LICENSE for details. 6 | */ 7 | 8 | #ifndef CLEVER_STD_SYS_H 9 | #define CLEVER_STD_SYS_H 10 | 11 | #include "core/module.h" 12 | 13 | namespace clever { namespace modules { namespace std { 14 | 15 | /// Standard SYS module 16 | class SYSModule : public Module { 17 | public: 18 | SYSModule() 19 | : Module("std.sys") { } 20 | 21 | ~SYSModule() { } 22 | 23 | CLEVER_MODULE_VIRTUAL_METHODS_DECLARATION; 24 | private: 25 | DISALLOW_COPY_AND_ASSIGN(SYSModule); 26 | }; 27 | 28 | }}} // clever::modules::std 29 | 30 | #endif // CLEVER_STD_SYS_H 31 | -------------------------------------------------------------------------------- /modules/std/unicode/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | 2 | add_library(modules_std_unicode STATIC 3 | unicode.cc 4 | string.cc 5 | ) 6 | 7 | list(APPEND CLEVER_INCLUDES ${ICU_INCLUDE_DIRS}) 8 | list(APPEND CLEVER_LIBS ${ICU_LIBS}) 9 | -------------------------------------------------------------------------------- /modules/std/unicode/string.h: -------------------------------------------------------------------------------- 1 | /** 2 | * Clever programming language 3 | * Copyright (c) Clever Team 4 | * 5 | * This file is distributed under the MIT license. See LICENSE for details. 6 | */ 7 | 8 | #ifndef CLEVER_STD_UNICODE_STRING_H 9 | #define CLEVER_STD_UNICODE_STRING_H 10 | 11 | #include 12 | #include "core/cstring.h" 13 | #include "core/type.h" 14 | #include "unicode/unistr.h" 15 | #include "unicode/ustream.h" 16 | 17 | namespace clever { namespace modules { namespace std { 18 | 19 | #define CLEVER_USTR_TYPE UStringObject* 20 | #define CLEVER_USTR_CAST(what) (CLEVER_USTR_TYPE) what 21 | #define CLEVER_USTR_THIS() CLEVER_USTR_CAST(clever_this()->getObj()) 22 | #define CLEVER_USTR_OBJ(from) UStringObject(from->c_str(), from->size()) 23 | 24 | struct UStringObject : public TypeObject { 25 | UStringObject(const char* str, size_t size) 26 | : intern(new UnicodeString(str, size, US_INV)) {} 27 | 28 | ~UStringObject() { 29 | delete intern; 30 | } 31 | 32 | UnicodeString* intern; 33 | }; 34 | 35 | class UString : public Type { 36 | public: 37 | UString() 38 | : Type("UString") {} 39 | 40 | ~UString() {} 41 | 42 | virtual void init(); 43 | virtual void dump(TypeObject*, ::std::ostream&) const; 44 | 45 | CLEVER_METHOD(ctor); 46 | CLEVER_METHOD(size); 47 | CLEVER_METHOD(startsWith); 48 | CLEVER_METHOD(endsWith); 49 | CLEVER_METHOD(indexOf); 50 | CLEVER_METHOD(lastIndexOf); 51 | CLEVER_METHOD(toLower); 52 | CLEVER_METHOD(toUpper); 53 | CLEVER_METHOD(reverse); 54 | CLEVER_METHOD(trim); 55 | CLEVER_METHOD(truncate); 56 | CLEVER_METHOD(append); 57 | CLEVER_METHOD(replace); 58 | }; 59 | 60 | }}} // clever::modules::std 61 | 62 | #endif // CLEVER_STD_UNICODE_STRING_H 63 | -------------------------------------------------------------------------------- /modules/std/unicode/unicode.cc: -------------------------------------------------------------------------------- 1 | /** 2 | * Clever programming language 3 | * Copyright (c) Clever Team 4 | * 5 | * This file is distributed under the MIT license. See LICENSE for details. 6 | */ 7 | 8 | #include "core/cthread.h" 9 | #include "core/value.h" 10 | #include "modules/std/core/function.h" 11 | #include "core/modmanager.h" 12 | #include "modules/std/unicode/unicode.h" 13 | #include "modules/std/unicode/string.h" 14 | 15 | namespace clever { namespace modules { namespace std { 16 | 17 | /// Initializes Standard Unicode module 18 | CLEVER_MODULE_INIT(UnicodeModule) 19 | { 20 | addType(new UString); 21 | } 22 | 23 | }}} // clever::modules::std 24 | -------------------------------------------------------------------------------- /modules/std/unicode/unicode.h: -------------------------------------------------------------------------------- 1 | /** 2 | * Clever programming language 3 | * Copyright (c) Clever Team 4 | * 5 | * This file is distributed under the MIT license. See LICENSE for details. 6 | */ 7 | 8 | #ifndef CLEVER_STD_UNICODE_H 9 | #define CLEVER_STD_UNICODE_H 10 | 11 | #include "core/module.h" 12 | #include "unicode/uclean.h" 13 | 14 | namespace clever { namespace modules { namespace std { 15 | 16 | /// Standard Unicode Module 17 | class UnicodeModule : public Module { 18 | public: 19 | UnicodeModule() 20 | : Module("std.unicode") { } 21 | 22 | ~UnicodeModule() { 23 | u_cleanup(); 24 | } 25 | 26 | CLEVER_MODULE_VIRTUAL_METHODS_DECLARATION; 27 | private: 28 | DISALLOW_COPY_AND_ASSIGN(UnicodeModule); 29 | }; 30 | 31 | }}} // clever::modules::std 32 | 33 | #endif // CLEVER_STD_UNICODE_H 34 | -------------------------------------------------------------------------------- /samples/bimap.clv: -------------------------------------------------------------------------------- 1 | /** 2 | * Clever programming language 3 | * Copyright (c) Clever Team 4 | * 5 | * This file is distributed under the MIT license. See LICENSE for details. 6 | */ 7 | 8 | /** 9 | * Example of implementation of BiMap wich is a map which maps in the both 10 | * directions (key => value) and (value => key). 11 | * -- muriloadriano 12 | */ 13 | 14 | import std.*; 15 | 16 | class BiMap { 17 | var _map; 18 | 19 | function CustomMap() { 20 | this._map = {:}; 21 | } 22 | 23 | function insert(key, value) { 24 | this._map[key.toString()] = value; 25 | this._map[value.toString()] = key; 26 | } 27 | 28 | function get(key) { 29 | return this._map[key.toString()]; 30 | } 31 | 32 | function size() { 33 | return this._map.size(); 34 | } 35 | } 36 | 37 | // Example of use 38 | 39 | var map = BiMap.new; 40 | map.insert('pi', math:PI); 41 | map.insert(2.71828, 'e'); 42 | map.insert(1.61803, 'phi'); 43 | 44 | io:println(map.get('pi') + ' is ' + map.get(map.get('pi'))); 45 | io:println(map.get('phi') + ' is ' + map.get(map.get('phi'))); 46 | io:println(map.get('e') + ' is ' + map.get(2.71828)); 47 | 48 | // Expected output 49 | // 3.14159 is pi 50 | // 1.61803 is phi 51 | // 2.71828 is e -------------------------------------------------------------------------------- /samples/json.clv: -------------------------------------------------------------------------------- 1 | /** 2 | * Clever programming language 3 | * Copyright (c) Clever Team 4 | * 5 | * This file is distributed under the MIT license. See LICENSE for details. 6 | */ 7 | 8 | /** 9 | * Example of use of to_json function. 10 | */ 11 | 12 | import std.*; 13 | 14 | class Person { 15 | var name; 16 | var email; 17 | 18 | function Person(name, email) { 19 | this.name = name; 20 | this.email = email; 21 | } 22 | } 23 | 24 | class Language { 25 | var name; 26 | var version; 27 | var modules; 28 | var contributors; 29 | var links; 30 | 31 | function Language(name, version, modules, contributors, links) { 32 | this.name = name; 33 | this.version = version; 34 | this.modules = modules; 35 | this.contributors = contributors; 36 | this.links = links; 37 | } 38 | } 39 | 40 | var clever = Language.new('Clever Programming Language', '0.0.1a', 41 | [ 42 | 'db', 43 | 'gui', 44 | 'std' 45 | ], 46 | [ 47 | Person.new('Higor', 'heuripedes@clever-lang.org'), 48 | Person.new('Felipe', 'felipe@clever-lang.org'), 49 | Person.new('Murilo', 'murilo@clever-lang.org'), 50 | Person.new('Pericles', 'pmachado@clever-lang.org') 51 | ], 52 | { 53 | 'docs': 'http://clever-lang.org/doc/', 54 | 'repo': 'https://github.com/clever-lang/clever', 55 | 'home': 'http://clever-lang.org/' 56 | } 57 | ); 58 | 59 | io:println(json:to_json(clever)); -------------------------------------------------------------------------------- /samples/logging.clv: -------------------------------------------------------------------------------- 1 | /** 2 | * Clever programming language 3 | * Copyright (c) Clever Team 4 | * 5 | * This file is distributed under the MIT license. See LICENSE for details. 6 | */ 7 | 8 | /** 9 | * Example of std.logging module. 10 | */ 11 | 12 | import std.*; 13 | import modules.std.logging.logger.*; 14 | 15 | var logger = getLogger('test'); 16 | logger.warning('Sample warning!'); 17 | 18 | // Disabling waring reports 19 | logger.setEnabledLevels(ALL ^ WARNING); 20 | logger.warning('Do not print this warning!'); 21 | logger.info('This is an info!'); -------------------------------------------------------------------------------- /tests/.gitignore: -------------------------------------------------------------------------------- 1 | *.log 2 | *.mem 3 | -------------------------------------------------------------------------------- /tests/db.sqlite3/test_001.test: -------------------------------------------------------------------------------- 1 | Testing SQLite3 module 2 | ==CODE== 3 | import std.io.*; 4 | import db.sqlite3.*; 5 | import std.sys.*; 6 | 7 | system("rm test 2> /dev/null"); 8 | 9 | var conn = SQLite3.new("test"); 10 | 11 | conn.exec("CREATE TABLE IF NOT EXISTS test (id INTEGER, name TEXT)"); 12 | conn.query("INSERT INTO test VALUES (1, 'Felipe')"); 13 | println(conn.getLastId()); 14 | 15 | conn.query("INSERT INTO test VALUES (2, 'Higor')"); 16 | println(conn.getLastId()); 17 | 18 | var row; 19 | var stmt = conn.query("SELECT * FROM test"); 20 | 21 | while (row = stmt.fetch()) { 22 | println(row); 23 | } 24 | 25 | stmt.finalize(); 26 | conn.close(); 27 | 28 | system("rm test 2> /dev/null"); 29 | ==RESULT== 30 | 1 31 | 2 32 | {"id": 1, "name": Felipe} 33 | {"id": 2, "name": Higor} 34 | -------------------------------------------------------------------------------- /tests/lang/anon_001.test: -------------------------------------------------------------------------------- 1 | [FATAL] Testing anonymous functions 2 | ==CODE== 3 | import std.io.*; 4 | var a = 0 or function() { return "clever"; }; 5 | 6 | println(a); 7 | println(a()); 8 | ==RESULT== 9 | 0 10 | Fatal error: Cannot make a call from Int type on \S+ line 5 11 | -------------------------------------------------------------------------------- /tests/lang/anon_002.test: -------------------------------------------------------------------------------- 1 | Testing anonymous functions 2 | ==CODE== 3 | import std.io.*; 4 | 5 | var a = function () { 6 | return function () { 7 | return "clever"; 8 | }; 9 | }; 10 | 11 | var b = a(); 12 | 13 | println(b()); 14 | ==RESULT== 15 | clever 16 | -------------------------------------------------------------------------------- /tests/lang/anon_003.test: -------------------------------------------------------------------------------- 1 | Testing call from returned anonymous function 2 | ==CODE== 3 | import std.io.*; 4 | 5 | var c = 123; 6 | var a = function (x = 1) { 7 | return function () { 8 | println(c); 9 | }; 10 | }; 11 | 12 | a(10)(); 13 | ==RESULT== 14 | 123 15 | -------------------------------------------------------------------------------- /tests/lang/array_001.test: -------------------------------------------------------------------------------- 1 | Testing array 2 | ==CODE== 3 | import std.io.*; 4 | 5 | var a = [1, 2, 2 + 2]; 6 | 7 | println(a); 8 | ==RESULT== 9 | \[1, 2, 4\] 10 | -------------------------------------------------------------------------------- /tests/lang/array_002.test: -------------------------------------------------------------------------------- 1 | Testing array 2 | ==CODE== 3 | import std.io.*; 4 | 5 | var a = [1]; 6 | var b = [a, 2]; 7 | 8 | println(a, b); 9 | ==RESULT== 10 | \[1\] 11 | \[\[1\], 2\] 12 | -------------------------------------------------------------------------------- /tests/lang/array_003.test: -------------------------------------------------------------------------------- 1 | Testing array operation 2 | ==CODE== 3 | import std.io.*; 4 | 5 | try { 6 | println([2] - 1); 7 | } catch (e) { 8 | printf("Caught: \1\n", e); 9 | } 10 | ==RESULT== 11 | Caught: Cannot use \- operator with Array type 12 | -------------------------------------------------------------------------------- /tests/lang/array_004.test: -------------------------------------------------------------------------------- 1 | Testing array's append method 2 | ==CODE== 3 | import std.io.*; 4 | 5 | var a = [2]; a.append(3); println(a); 6 | ==RESULT== 7 | \[2, 3\] 8 | -------------------------------------------------------------------------------- /tests/lang/array_005.test: -------------------------------------------------------------------------------- 1 | Testing Array::each with an internal function 2 | ==CODE== 3 | import std.io.*; 4 | 5 | var arr = [1, 2, 3]; 6 | 7 | arr.each(println); 8 | ==RESULT== 9 | 1 10 | 2 11 | 3 12 | -------------------------------------------------------------------------------- /tests/lang/array_006.test: -------------------------------------------------------------------------------- 1 | Testing Array::each() using an user function 2 | ==CODE== 3 | import std.io.*; 4 | function printall(x) { println(x); } 5 | 6 | var a = [5,3]; a.each(printall); 7 | 8 | println("end!"); 9 | ==RESULT== 10 | 5 11 | 3 12 | end! 13 | -------------------------------------------------------------------------------- /tests/lang/array_007.test: -------------------------------------------------------------------------------- 1 | Testing array's each method 2 | ==CODE== 3 | import std.io.*; 4 | 5 | function test(x...) { 6 | println(x.at(0) * 2); 7 | } 8 | 9 | var z = [1, 2, 3]; 10 | 11 | z.each(test); 12 | ==RESULT== 13 | 2 14 | 4 15 | 6 16 | -------------------------------------------------------------------------------- /tests/lang/array_008.test: -------------------------------------------------------------------------------- 1 | Testing array's each method 2 | ==CODE== 3 | import std.io.*; 4 | 5 | function test(x, y = 2) { 6 | println(x, y); 7 | } 8 | 9 | var z = [1, 2, 3]; 10 | 11 | z.each(test); 12 | ==RESULT== 13 | 1 14 | 2 15 | 2 16 | 2 17 | 3 18 | 2 19 | -------------------------------------------------------------------------------- /tests/lang/array_009.test: -------------------------------------------------------------------------------- 1 | Testing array's each method 2 | ==CODE== 3 | import std.io.*; 4 | 5 | function test(x, y = 2) { 6 | return x*2; 7 | } 8 | 9 | var z = [1, 2, 3]; 10 | 11 | println(z.each(test)); 12 | 13 | ==RESULT== 14 | \[2, 4, 6\] 15 | -------------------------------------------------------------------------------- /tests/lang/array_010.test: -------------------------------------------------------------------------------- 1 | Testing array reversal 2 | ==CODE== 3 | import std.io.*; 4 | 5 | println([1,2,3,4,5,6,7,8,9].reverse()); 6 | ==RESULT== 7 | \[9, 8, 7, 6, 5, 4, 3, 2, 1\] 8 | -------------------------------------------------------------------------------- /tests/lang/array_011.test: -------------------------------------------------------------------------------- 1 | Testing array shift 2 | ==CODE== 3 | import std.io.*; 4 | 5 | var t = [1,2,3,4,5]; 6 | 7 | var o = t.shift(); 8 | println(o); 9 | println(t); 10 | ==RESULT== 11 | 1 12 | \[2, 3, 4, 5\] 13 | -------------------------------------------------------------------------------- /tests/lang/array_012.test: -------------------------------------------------------------------------------- 1 | Testing array reversal 2 | ==CODE== 3 | import std.io.*; 4 | 5 | var t = [1,2,3,4,5]; 6 | var o = t.pop(); 7 | println(o); 8 | println(t); 9 | ==RESULT== 10 | 5 11 | \[1, 2, 3, 4\] 12 | -------------------------------------------------------------------------------- /tests/lang/array_014.test: -------------------------------------------------------------------------------- 1 | Testing array range 2 | ==CODE== 3 | import std.io.*; 4 | 5 | var t = [1,2,3,4,5]; 6 | var o = t.range(0, 4); 7 | println(o); 8 | ==RESULT== 9 | \[1, 2, 3, 4, 5\] 10 | -------------------------------------------------------------------------------- /tests/lang/array_015.test: -------------------------------------------------------------------------------- 1 | Testing array range in reverse 2 | ==CODE== 3 | import std.io.*; 4 | 5 | var t = [1,2,3,4,5]; 6 | var o = t.range(4, 0); 7 | println(o); 8 | ==RESULT== 9 | \[5, 4, 3, 2, 1\] 10 | -------------------------------------------------------------------------------- /tests/lang/array_016.test: -------------------------------------------------------------------------------- 1 | Testing array out of range 2 | ==CODE== 3 | import std.io.*; 4 | 5 | var t = [1,2,3,4,5]; 6 | var o = t.range(6, 1); 7 | println(o); 8 | ==RESULT== 9 | \[\] 10 | -------------------------------------------------------------------------------- /tests/lang/array_017.test: -------------------------------------------------------------------------------- 1 | Testing array erase 2 | ==CODE== 3 | import std.io.*; 4 | 5 | var t = [1,2,3,4,5]; 6 | t.erase(0); 7 | println(t); 8 | t.erase(0); 9 | println(t); 10 | ==RESULT== 11 | \[2, 3, 4, 5\] 12 | \[3, 4, 5\] 13 | -------------------------------------------------------------------------------- /tests/lang/array_018.testt: -------------------------------------------------------------------------------- 1 | Testing array each with variable scopes 2 | ==CODE== 3 | import std.io.*; 4 | 5 | var t = [1,2,3]; 6 | var t2 = [4,5,6]; 7 | var foo = 'clever'; 8 | 9 | t.each(function(i) { 10 | println("i val: " + i + " -- foo val: " + foo); 11 | var bar = 'my clever'; 12 | 13 | t2.each(function(j) { 14 | println("i val: " + i + " -- foo val: " + foo + " -- j val: " + j + " -- bar val: " + bar); 15 | }); 16 | }); 17 | 18 | println(foo); 19 | ==RESULT== 20 | i val: 1 -- foo val: clever 21 | i val: 1 -- foo val: clever -- j val: 4 -- bar val: my clever 22 | i val: 1 -- foo val: clever -- j val: 5 -- bar val: my clever 23 | i val: 1 -- foo val: clever -- j val: 6 -- bar val: my clever 24 | i val: 2 -- foo val: clever 25 | i val: 2 -- foo val: clever -- j val: 4 -- bar val: my clever 26 | i val: 2 -- foo val: clever -- j val: 5 -- bar val: my clever 27 | i val: 2 -- foo val: clever -- j val: 6 -- bar val: my clever 28 | i val: 3 -- foo val: clever 29 | i val: 3 -- foo val: clever -- j val: 4 -- bar val: my clever 30 | i val: 3 -- foo val: clever -- j val: 5 -- bar val: my clever 31 | i val: 3 -- foo val: clever -- j val: 6 -- bar val: my clever 32 | clever 33 | -------------------------------------------------------------------------------- /tests/lang/array_019.test: -------------------------------------------------------------------------------- 1 | Testing array merge 2 | ==CODE== 3 | import std.io.*; 4 | 5 | println([1] + [2]); 6 | ==RESULT== 7 | \[1, 2\] 8 | -------------------------------------------------------------------------------- /tests/lang/array_020.test: -------------------------------------------------------------------------------- 1 | Testing append operation using += operator 2 | ==CODE== 3 | import std.io.*; 4 | 5 | var arr = []; 6 | 7 | function f(a, n) { 8 | a += [n]; 9 | } 10 | 11 | f(arr, 1); 12 | f(arr, 2); 13 | 14 | println(arr); 15 | ==RESULT== 16 | \[1, 2\] 17 | -------------------------------------------------------------------------------- /tests/lang/array_021.test: -------------------------------------------------------------------------------- 1 | Testing array writing and reading 2 | ==CODE== 3 | import std.io; 4 | 5 | var arr = []; 6 | 7 | arr.resize(1); 8 | 9 | arr[0] = 2; io:println(arr); 10 | arr[0] = 3; io:println(arr); 11 | ==RESULT== 12 | \[2\] 13 | \[3\] 14 | -------------------------------------------------------------------------------- /tests/lang/arrayiterator_001.test: -------------------------------------------------------------------------------- 1 | Testing ArrayIterator 2 | ==CODE== 3 | import std.*; 4 | 5 | var a = [2, 3, 5, 7, 11, 13, 17, 19, 23]; 6 | 7 | var beg = a.begin(), end = a.end(); 8 | 9 | while (beg != end) { 10 | io:println(beg.get()); 11 | beg = beg.next(); 12 | } 13 | ==RESULT== 14 | 2 15 | 3 16 | 5 17 | 7 18 | 11 19 | 13 20 | 17 21 | 19 22 | 23 23 | -------------------------------------------------------------------------------- /tests/lang/arrayiterator_002.test: -------------------------------------------------------------------------------- 1 | Testing ArrayIterator with an empty array 2 | ==CODE== 3 | import std.*; 4 | 5 | var a = []; 6 | 7 | var beg = a.begin(), end = a.end(); 8 | 9 | io:println('Start testing'); 10 | while (beg != end) { 11 | io:println(beg.get()); 12 | beg = beg.next(); 13 | } 14 | io:println('Done'); 15 | ==RESULT== 16 | Start testing 17 | Done 18 | -------------------------------------------------------------------------------- /tests/lang/assign_001.test: -------------------------------------------------------------------------------- 1 | Testing variable assignment 2 | ==CODE== 3 | import std.io.*; 4 | 5 | var a = 1; 6 | var b = 2; 7 | 8 | a = b; 9 | b = 3; 10 | 11 | println(a); 12 | println(b); 13 | ==RESULT== 14 | 2 15 | 3 16 | -------------------------------------------------------------------------------- /tests/lang/assign_002.test: -------------------------------------------------------------------------------- 1 | Testing variable assignment 2 | ==CODE== 3 | import std.io.*; 4 | 5 | var a = 10; 6 | println(a); 7 | 8 | var b = a / 2; 9 | println(b); 10 | 11 | var c = ++b; 12 | println(c); 13 | 14 | ==RESULT== 15 | 10 16 | 5 17 | 6 18 | -------------------------------------------------------------------------------- /tests/lang/assign_003.test: -------------------------------------------------------------------------------- 1 | Testing augmented assignment 2 | ==CODE== 3 | import std.io.*; 4 | 5 | var a = 10; 6 | 7 | println(a += 12); 8 | println(a); 9 | 10 | var b = a -= 10; 11 | println(b, a); 12 | ==RESULT== 13 | 22 14 | 22 15 | 12 16 | 12 17 | -------------------------------------------------------------------------------- /tests/lang/assign_004.test: -------------------------------------------------------------------------------- 1 | Testing augmented assignment 2 | ==CODE== 3 | import std.io.*; 4 | 5 | var a = [10]; 6 | 7 | println(a[0] += 12); 8 | println(a[0]); 9 | 10 | var b = a[0] -= 10; 11 | println(b, a[0]); 12 | ==RESULT== 13 | 22 14 | 22 15 | 12 16 | 12 17 | -------------------------------------------------------------------------------- /tests/lang/assign_005.test: -------------------------------------------------------------------------------- 1 | Testing augmented assignment 2 | ==CODE== 3 | import std.io.*; 4 | 5 | var a = [1]; 6 | 7 | println(a[0] <<= 3); 8 | println(a[0]); 9 | ==RESULT== 10 | 8 11 | 8 12 | -------------------------------------------------------------------------------- /tests/lang/break_001.test: -------------------------------------------------------------------------------- 1 | Testing break statement 2 | ==CODE== 3 | import std.io.*; 4 | var i = 10; 5 | 6 | while (i-- >= 0) { 7 | println(i); 8 | 9 | var b = i * 3; 10 | 11 | if (b == 15) { 12 | break; 13 | } 14 | } 15 | ==RESULT== 16 | 9 17 | 8 18 | 7 19 | 6 20 | 5 21 | -------------------------------------------------------------------------------- /tests/lang/class_001.test: -------------------------------------------------------------------------------- 1 | Testing class methods 2 | ==CODE== 3 | import std.io.*; 4 | 5 | class Foo { 6 | 7 | function test() { 8 | return "cool"; 9 | } 10 | 11 | } 12 | 13 | var foo = Foo.new; 14 | 15 | println(foo.test()); 16 | ==RESULT== 17 | cool 18 | -------------------------------------------------------------------------------- /tests/lang/class_002.test: -------------------------------------------------------------------------------- 1 | Testing variadic method 2 | ==CODE== 3 | import std.io.*; 4 | 5 | class Foo { 6 | 7 | function test(args...) { 8 | return args.at(0); 9 | } 10 | 11 | } 12 | 13 | var foo = Foo.new; 14 | 15 | println(foo.test(2)); 16 | ==RESULT== 17 | 2 18 | -------------------------------------------------------------------------------- /tests/lang/class_003.test: -------------------------------------------------------------------------------- 1 | Testing user class 2 | ==CODE== 3 | import std.io.*; 4 | 5 | class Foo { 6 | var a; 7 | 8 | function setA(v) { 9 | this.a = v; 10 | } 11 | 12 | function getA() { 13 | return this.a; 14 | } 15 | } 16 | 17 | var a = Foo.new; 18 | 19 | a.setA(123); 20 | println(a.getA()); 21 | ==RESULT== 22 | 123 23 | -------------------------------------------------------------------------------- /tests/lang/class_004.test: -------------------------------------------------------------------------------- 1 | Testing user class constructor 2 | ==CODE== 3 | import std.io.*; 4 | 5 | class Foo { 6 | var a; 7 | 8 | function Foo(a...) { 9 | println(a); 10 | } 11 | 12 | function setA(n = 2) { 13 | this.a = n; 14 | } 15 | function getA() { 16 | return this.a; 17 | } 18 | } 19 | 20 | var a = Foo.new(1,2,3), 21 | b = Foo.new; 22 | 23 | a.setA(1); 24 | b.setA(3); 25 | 26 | println(a.getA(), b.getA()); 27 | ==RESULT== 28 | \[1, 2, 3\] 29 | \[\] 30 | 1 31 | 3 32 | -------------------------------------------------------------------------------- /tests/lang/class_005.test: -------------------------------------------------------------------------------- 1 | Testing array on class member 2 | ==CODE== 3 | import std.io.*; 4 | 5 | class Bar { 6 | var name; 7 | 8 | function Bar(s) { 9 | this.name = s; 10 | } 11 | 12 | function run() { 13 | return this.name; 14 | } 15 | } 16 | 17 | class Foo { 18 | var arr; 19 | 20 | function Foo() { 21 | this.arr = []; 22 | } 23 | 24 | function append(s) { 25 | this.arr.append(Bar.new(s)); 26 | } 27 | 28 | function getItems() { 29 | var items = []; 30 | 31 | for (var i = 0; i < this.arr.size(); ++i) { 32 | items.append(this.arr[i].run()); 33 | } 34 | 35 | return items; 36 | } 37 | } 38 | 39 | var f = Foo.new; 40 | 41 | f.append('felipe'); 42 | f.append('pericles'); 43 | 44 | var results = f.getItems(); 45 | 46 | println(results); 47 | ==RESULT== 48 | \[felipe, pericles\] 49 | -------------------------------------------------------------------------------- /tests/lang/class_006.test: -------------------------------------------------------------------------------- 1 | Testing default argument in user class constructor 2 | ==CODE== 3 | import std.*; 4 | 5 | const NUM = 10; 6 | 7 | class Aa { 8 | function Aa(a, c = io:println, b = NUM) { 9 | c(b); 10 | } 11 | } 12 | 13 | var a = Aa.new(1); 14 | ==RESULT== 15 | 10 16 | -------------------------------------------------------------------------------- /tests/lang/class_007.test: -------------------------------------------------------------------------------- 1 | [FATAL] Testing member overwrite 2 | ==CODE== 3 | import std.io; 4 | 5 | class Test { 6 | function method() { 7 | io:println('aa'); 8 | } 9 | } 10 | 11 | var w = Test.new; 12 | w.method = 'aaa'; 13 | ==RESULT== 14 | Fatal error: Cannot assign to a const variable! on \S+ line 10 15 | -------------------------------------------------------------------------------- /tests/lang/closure_001.test: -------------------------------------------------------------------------------- 1 | Testing closure 2 | ==CODE== 3 | import std.io.*; 4 | 5 | var f = function (x) { 6 | return function () { 7 | return x; 8 | }; 9 | }; 10 | 11 | var a = f(123); 12 | var b = f(321); 13 | 14 | println(a(), b()); 15 | ==RESULT== 16 | 123 17 | 321 18 | -------------------------------------------------------------------------------- /tests/lang/closure_002.test: -------------------------------------------------------------------------------- 1 | Testing closure 2 | ==CODE== 3 | import std.io.*; 4 | 5 | var a = function() { 6 | var w = 2; 7 | 8 | var b = function() { 9 | println(w); 10 | }; 11 | 12 | b(); 13 | }; 14 | 15 | a(); 16 | ==RESULT== 17 | 2 18 | -------------------------------------------------------------------------------- /tests/lang/const_001.test: -------------------------------------------------------------------------------- 1 | Testing const variables 2 | ==CODE== 3 | import std.io.*; 4 | 5 | const MYCONSTANT = 1; 6 | var b = MYCONSTANT; 7 | b = 2; 8 | 9 | println(MYCONSTANT, b, MYCONSTANT + b); 10 | ==RESULT== 11 | 1 12 | 2 13 | 3 14 | -------------------------------------------------------------------------------- /tests/lang/const_002.test: -------------------------------------------------------------------------------- 1 | [FATAL] Testing const variables 2 | ==CODE== 3 | import std.io.*; 4 | 5 | const MYCONSTANT = 1; 6 | MYCONSTANT = 2; 7 | 8 | println(a); 9 | ==RESULT== 10 | Error: syntax error, unexpected '=' in \S+ on line \d+ 11 | -------------------------------------------------------------------------------- /tests/lang/const_003.test: -------------------------------------------------------------------------------- 1 | Testing const variables 2 | ==CODE== 3 | import std.io.*; 4 | 5 | const E = 2.71; 6 | 7 | println(E); 8 | ==RESULT== 9 | 2.71 10 | -------------------------------------------------------------------------------- /tests/lang/continue_001.test: -------------------------------------------------------------------------------- 1 | Testing continue statement 2 | ==CODE== 3 | import std.io.*; 4 | 5 | var i = 10; 6 | 7 | 8 | while (i-- > 0) { 9 | if (i > 5) { 10 | continue; 11 | } 12 | println(i); 13 | } 14 | ==RESULT== 15 | 5 16 | 4 17 | 3 18 | 2 19 | 1 20 | 0 21 | -------------------------------------------------------------------------------- /tests/lang/continue_002.test: -------------------------------------------------------------------------------- 1 | Testing continue statement in foor loop 2 | ==CODE== 3 | import std.io.*; 4 | for (var i = 0, j = 0; i < 4; ++i, ++j) { 5 | if (i==1) { continue;} 6 | println(i); 7 | println(j); 8 | println("here"); 9 | } 10 | ==RESULT== 11 | 0 12 | 0 13 | here 14 | 2 15 | 2 16 | here 17 | 3 18 | 3 19 | here 20 | -------------------------------------------------------------------------------- /tests/lang/fcall_001.test: -------------------------------------------------------------------------------- 1 | Testing function call 2 | ==CODE== 3 | import std.io.*; 4 | 5 | function test(foo) { 6 | println(foo); 7 | } 8 | 9 | test(123); 10 | ==RESULT== 11 | 123 12 | -------------------------------------------------------------------------------- /tests/lang/fcall_002.test: -------------------------------------------------------------------------------- 1 | Testing global function change inside a function 2 | ==CODE== 3 | import std.io.*; 4 | 5 | var a = 123; 6 | 7 | function b() { 8 | a = 321; 9 | } 10 | 11 | b(); 12 | 13 | println(a); 14 | ==RESULT== 15 | 321 16 | -------------------------------------------------------------------------------- /tests/lang/fcall_003.test: -------------------------------------------------------------------------------- 1 | Testing function call 2 | ==CODE== 3 | import std.io.*; 4 | 5 | function a(b) { println(b); return 2; } 6 | var b = a(123); 7 | println(b * 3); 8 | ==RESULT== 9 | 123 10 | 6 11 | -------------------------------------------------------------------------------- /tests/lang/fcall_004.test: -------------------------------------------------------------------------------- 1 | Testing return 2 | ==CODE== 3 | import std.io.*; 4 | 5 | function a(b) { return b + 1; } 6 | println(a(2)); 7 | 8 | ==RESULT== 9 | 3 10 | -------------------------------------------------------------------------------- /tests/lang/fcall_005.test: -------------------------------------------------------------------------------- 1 | Testing return 2 | ==CODE== 3 | import std.io.*; 4 | 5 | function a() { 6 | println(1); 7 | return; 8 | println(2); 9 | } 10 | 11 | a(); 12 | println(3); 13 | ==RESULT== 14 | 1 15 | 3 16 | -------------------------------------------------------------------------------- /tests/lang/fcall_006.test: -------------------------------------------------------------------------------- 1 | Testing default param 2 | ==CODE== 3 | import std.io.*; 4 | 5 | function a(b, c = 1) { println(b, c); } 6 | a(2); 7 | 8 | a(2, 3); 9 | ==RESULT== 10 | 2 11 | 1 12 | 2 13 | 3 14 | -------------------------------------------------------------------------------- /tests/lang/fcall_007.test: -------------------------------------------------------------------------------- 1 | Testing argument passing to function 2 | ==CODE== 3 | import std.io.*; 4 | 5 | function f() { 6 | return 3.toString(); 7 | } 8 | 9 | printf("\1 \2 \3\n",f(),f(),f()); 10 | println(3.toString(),3,3.toString()); 11 | ==RESULT== 12 | 3 3 3 13 | 3 14 | 3 15 | 3 16 | -------------------------------------------------------------------------------- /tests/lang/fcall_008.test: -------------------------------------------------------------------------------- 1 | Testing chaining function call 2 | ==CODE== 3 | import std.io.*; 4 | function a() { return function (x) { return x; }; } 5 | 6 | println(a()(12)); 7 | 8 | var c = a(); 9 | println(c(32)); 10 | 11 | ==RESULT== 12 | 12 13 | 32 14 | -------------------------------------------------------------------------------- /tests/lang/fcall_009.test: -------------------------------------------------------------------------------- 1 | Testing chaining function call 2 | ==CODE== 3 | import std.io.*; 4 | 5 | function a() { return function () { return function (x) { return x; }; }; } 6 | 7 | println(a()()(12)); 8 | ==RESULT== 9 | 12 10 | -------------------------------------------------------------------------------- /tests/lang/fcall_010.test: -------------------------------------------------------------------------------- 1 | [FATAL] Testing function call from null value 2 | ==CODE== 3 | var a; 4 | 5 | a(1); 6 | ==RESULT== 7 | Fatal error: Cannot make a call from null value on \S+ line 3 8 | -------------------------------------------------------------------------------- /tests/lang/fcall_011.test: -------------------------------------------------------------------------------- 1 | Testing array dereferencing 2 | ==CODE== 3 | import std.io.*; 4 | 5 | var arr = [1, 2]; 6 | 7 | function getarr() { 8 | return arr; 9 | } 10 | 11 | println(getarr()[0], getarr()[1]); 12 | ==RESULT== 13 | 1 14 | 2 15 | -------------------------------------------------------------------------------- /tests/lang/fcall_012.test: -------------------------------------------------------------------------------- 1 | Testing method call from function return 2 | ==CODE== 3 | import std.io.*; 4 | 5 | function test() { 6 | return "foobar"; 7 | } 8 | 9 | println(test().size()); 10 | ==RESULT== 11 | 6 12 | -------------------------------------------------------------------------------- /tests/lang/fcall_013.test: -------------------------------------------------------------------------------- 1 | Testing relative environment in callback 2 | ==CODE== 3 | import std.io.*; 4 | 5 | function _exec() { 6 | println(1); 7 | } 8 | 9 | class Environment { 10 | function validate() { 11 | [1].each(_exec); 12 | } 13 | } 14 | 15 | var env = Environment.new; 16 | 17 | env.validate(); 18 | ==RESULT== 19 | 1 20 | -------------------------------------------------------------------------------- /tests/lang/fcall_014.test: -------------------------------------------------------------------------------- 1 | Testing environment context 2 | ==CODE== 3 | import std.io.*; 4 | 5 | function _exec(command) { 6 | println(1); 7 | } 8 | 9 | class Language { 10 | function check() { 11 | _exec(1); 12 | } 13 | } 14 | 15 | class Environment { 16 | function validate() { 17 | [Language.new].each(function(l) { 18 | l.check(); 19 | }); 20 | } 21 | } 22 | 23 | var e = Environment.new; 24 | e.validate(); 25 | ==RESULT== 26 | 1 27 | -------------------------------------------------------------------------------- /tests/lang/fcall_015.test: -------------------------------------------------------------------------------- 1 | Testing function call through class member 2 | ==CODE== 3 | import std.io; 4 | 5 | function ww(x) { 6 | io:println(x); 7 | } 8 | 9 | class Writer { 10 | var writer; 11 | 12 | function Writer(writer) { 13 | this.writer = writer; 14 | } 15 | 16 | function write(msg) { 17 | this.writer(msg); 18 | } 19 | } 20 | 21 | var w = Writer.new(ww); 22 | w.write('hello world!'); 23 | ==RESULT== 24 | hello world! 25 | -------------------------------------------------------------------------------- /tests/lang/fcall_016.test: -------------------------------------------------------------------------------- 1 | Testing function call through class member 2 | ==CODE== 3 | import std.io; 4 | 5 | class Writer { 6 | var writer; 7 | 8 | function Writer(writer) { 9 | this.writer = writer; 10 | } 11 | 12 | function write(msg) { 13 | this.writer(msg); 14 | } 15 | } 16 | 17 | var w = Writer.new(io:println); 18 | w.write('hello world!'); 19 | ==RESULT== 20 | hello world! 21 | -------------------------------------------------------------------------------- /tests/lang/fdecl_001.test: -------------------------------------------------------------------------------- 1 | [FATAL] Invalid default argument position 2 | ==CODE== 3 | function f(a=1, b) { 4 | } 5 | ==RESULT== 6 | Compile error: Non-default argument found after the default argument list on \S+ line \d+ 7 | -------------------------------------------------------------------------------- /tests/lang/for_001.test: -------------------------------------------------------------------------------- 1 | Testing for loop 2 | ==CODE== 3 | import std.io.*; 4 | 5 | for (var a = 9; a >= 0; a--) { 6 | println(a); 7 | } 8 | 9 | ==RESULT== 10 | 9 11 | 8 12 | 7 13 | 6 14 | 5 15 | 4 16 | 3 17 | 2 18 | 1 19 | 0 20 | -------------------------------------------------------------------------------- /tests/lang/for_002.test: -------------------------------------------------------------------------------- 1 | Testing foreach style for loop 2 | ==CODE== 3 | import std.*; 4 | 5 | var fib = [1, 1, 2, 3, 5, 8, 13, 21, 34, 55, 89]; 6 | 7 | for (var iter in fib) { 8 | io:println(iter); 9 | } 10 | 11 | ==RESULT== 12 | 1 13 | 1 14 | 2 15 | 3 16 | 5 17 | 8 18 | 13 19 | 21 20 | 34 21 | 55 22 | 89 23 | -------------------------------------------------------------------------------- /tests/lang/if_001.test: -------------------------------------------------------------------------------- 1 | Testing if-elseif-else 2 | ==CODE== 3 | import std.io.*; 4 | if (1 - 1 != 0) { 5 | println(1); 6 | } else if (0 != 0) { 7 | println(2); 8 | } else if (0 != 0) { 9 | println(3); 10 | } else { 11 | println(4); 12 | } 13 | ==RESULT== 14 | 4 15 | -------------------------------------------------------------------------------- /tests/lang/if_002.test: -------------------------------------------------------------------------------- 1 | Testing boolean operator 2 | ==CODE== 3 | import std.io.*; 4 | 5 | if (1 && 2) { 6 | println(1); 7 | } 8 | 9 | if ((0 && 2) == false) { 10 | println(2); 11 | } 12 | 13 | if (0 == false) { 14 | println(3); 15 | } 16 | 17 | var a; 18 | if (a) { 19 | println(4); 20 | } 21 | var b = 0; 22 | if (b == false) { 23 | println(5); 24 | } 25 | 26 | if (++b) { 27 | println(6); 28 | } 29 | ==RESULT== 30 | 1 31 | 6 32 | -------------------------------------------------------------------------------- /tests/lang/if_003.test: -------------------------------------------------------------------------------- 1 | Testing selector operator 2 | ==CODE== 3 | import std.io.*; 4 | 5 | println(false or 2); 6 | 7 | var a; 8 | println(a or 1); 9 | 10 | a = 0; 11 | println(++a or 2); 12 | ==RESULT== 13 | 2 14 | 1 15 | 1 16 | -------------------------------------------------------------------------------- /tests/lang/if_004.test: -------------------------------------------------------------------------------- 1 | Testing selector operator 2 | ==CODE== 3 | import std.io.*; 4 | 5 | println(0 and 2); 6 | 7 | var a; 8 | println(a and 1); 9 | a = 0; 10 | println(++a and 2); 11 | ==RESULT== 12 | 2 13 | null 14 | 2 15 | -------------------------------------------------------------------------------- /tests/lang/import_001.clv: -------------------------------------------------------------------------------- 1 | println("foobar!"); 2 | -------------------------------------------------------------------------------- /tests/lang/import_001.test: -------------------------------------------------------------------------------- 1 | Testing import with user module 2 | ==CODE== 3 | import std.io.*; 4 | println(1); 5 | import import_001.*; 6 | println(2); 7 | ==RESULT== 8 | 1 9 | foobar! 10 | 2 11 | -------------------------------------------------------------------------------- /tests/lang/import_002.test: -------------------------------------------------------------------------------- 1 | Testing namespaced import 2 | ==CODE== 3 | import std; 4 | 5 | std:io:println(123); 6 | ==RESULT== 7 | 123 8 | -------------------------------------------------------------------------------- /tests/lang/import_003.test: -------------------------------------------------------------------------------- 1 | Testing namespaced type access 2 | ==CODE== 3 | import std; 4 | 5 | std:io:println(std:reflection:Reflect.new(1)); 6 | ==RESULT== 7 | Reflect\(Int\) 8 | -------------------------------------------------------------------------------- /tests/lang/instantiation_001.test: -------------------------------------------------------------------------------- 1 | Testing object instantiation 2 | ==CODE== 3 | import std.io.*; 4 | 5 | class Foo { 6 | function Foo() { 7 | println('Bar!'); 8 | } 9 | } 10 | 11 | Foo.new; 12 | ==RESULT== 13 | Bar! 14 | -------------------------------------------------------------------------------- /tests/lang/instantiation_002.test: -------------------------------------------------------------------------------- 1 | Testing member chaining 2 | ==CODE== 3 | import std.io.*; 4 | 5 | class Foo 6 | { 7 | var x; 8 | 9 | function Foo(y) { 10 | if (y > 0) { 11 | this.x = Foo.new(y - 1); 12 | } 13 | } 14 | } 15 | 16 | var x = Foo.new(3); 17 | 18 | println(x.x.x.x); 19 | println(x.x.x.x.x); 20 | ==RESULT== 21 | Foo 22 | null 23 | -------------------------------------------------------------------------------- /tests/lang/map_001.test: -------------------------------------------------------------------------------- 1 | Testing map type 2 | ==CODE== 3 | import std.io.*; 4 | 5 | var a = {"foo": 1, "bar": 3}; 6 | 7 | a.insert("c", 2); println(a); 8 | ==RESULT== 9 | {"bar": 3, "c": 2, "foo": 1} 10 | -------------------------------------------------------------------------------- /tests/lang/map_002.test: -------------------------------------------------------------------------------- 1 | Testing map eaching 2 | ==CODE== 3 | import std.io.*; 4 | 5 | println({"hello": "world", "we're": "clever"}.each(function(k, v){return v;})); 6 | ==RESULT== 7 | {"hello": world, "we're": clever} 8 | -------------------------------------------------------------------------------- /tests/lang/map_003.test: -------------------------------------------------------------------------------- 1 | Testing map key access 2 | ==CODE== 3 | import std.io.*; 4 | 5 | var map = {'foo': 123}; 6 | 7 | println(map['foo']); 8 | ==RESULT== 9 | 123 10 | -------------------------------------------------------------------------------- /tests/lang/map_004.test: -------------------------------------------------------------------------------- 1 | Testing writing and reading on map 2 | ==CODE== 3 | import std.io; 4 | 5 | var map = {:}; 6 | 7 | map["felipe"] = 123; 8 | 9 | io:println(map["felipe"]); 10 | ==RESULT== 11 | 123 12 | -------------------------------------------------------------------------------- /tests/lang/mcall_001.test: -------------------------------------------------------------------------------- 1 | Testing method call 2 | ==CODE== 3 | import std.io.*; 4 | 5 | var a = Int.new; 6 | 7 | println(a.toString() + "foo"); 8 | ==RESULT== 9 | 0foo 10 | -------------------------------------------------------------------------------- /tests/lang/mcall_002.test: -------------------------------------------------------------------------------- 1 | Testing method chaining 2 | ==CODE== 3 | import std.io; 4 | io:println('a, b, c, d'.replace('a', '1').replace('d', '4').replace('b', '3').replace('c', '5')); 5 | ==RESULT== 6 | 1, 3, 5, 4 7 | -------------------------------------------------------------------------------- /tests/lang/operator_001.test: -------------------------------------------------------------------------------- 1 | Testing operators with integer 2 | ==CODE== 3 | import std.io.*; 4 | 5 | println(1 > 0); 6 | println(1 < 0); 7 | println(1 != 0); 8 | println(1 == 0); 9 | 10 | ==RESULT== 11 | true 12 | false 13 | true 14 | false 15 | -------------------------------------------------------------------------------- /tests/lang/operator_002.test: -------------------------------------------------------------------------------- 1 | Testing operators with double 2 | ==CODE== 3 | import std.io.*; 4 | 5 | println(1.2 > 1.0); 6 | println(1.2 < 1.0); 7 | println(1.2 != 1.0); 8 | println(1.2 == 1.0); 9 | 10 | ==RESULT== 11 | true 12 | false 13 | true 14 | false 15 | -------------------------------------------------------------------------------- /tests/lang/operator_003.test: -------------------------------------------------------------------------------- 1 | Testing operators with string 2 | ==CODE== 3 | import std.io.*; 4 | 5 | println("foo" == "foo"); 6 | println("foo" == "foo "); 7 | println("foo" != "foo"); 8 | println("" == ""); 9 | 10 | ==RESULT== 11 | true 12 | false 13 | false 14 | true 15 | -------------------------------------------------------------------------------- /tests/lang/operator_004.test: -------------------------------------------------------------------------------- 1 | [FATAL] Testing increment operator on type which does not implement it 2 | ==CODE== 3 | var a = [1, 2, 3]; a++; 4 | ==RESULT== 5 | Fatal error: Unhandled exception! on \S+ line \d+ 6 | Message: Cannot use \+\+ operator with Array type 7 | Stack trace: 8 | 9 | -------------------------------------------------------------------------------- /tests/lang/operator_005.test: -------------------------------------------------------------------------------- 1 | Testing + operator 2 | ==CODE== 3 | import std.io.*; 4 | 5 | println(1 + "foo"); 6 | println("foo" + 1); 7 | 8 | println(1.2 + "bar"); 9 | println("bar" + 1.2); 10 | ==RESULT== 11 | 1foo 12 | foo1 13 | 1\.2bar 14 | bar1\.2 15 | -------------------------------------------------------------------------------- /tests/lang/operator_006.test: -------------------------------------------------------------------------------- 1 | Testing bitwise operators 2 | ==CODE== 3 | import std.io.*; 4 | 5 | println(1 << 2); // 4 6 | println(1 << 10); // 1024 7 | println(10 >> 1); // 5 8 | println((10 >> 1) | 0x3); // 7 9 | ==RESULT== 10 | 4 11 | 1024 12 | 5 13 | 7 14 | -------------------------------------------------------------------------------- /tests/lang/operator_007.test: -------------------------------------------------------------------------------- 1 | Testing == and != for user-defined types 2 | ==CODE== 3 | import std.*; 4 | 5 | class Foo {} 6 | 7 | var a = Foo.new; 8 | var b = a; 9 | var c = Foo.new; 10 | 11 | if (a == a) { 12 | io:println('ok'); 13 | } 14 | 15 | if (a != a) { 16 | io:println('FAIL'); 17 | } 18 | 19 | if (a == b) { 20 | io:println('ok'); 21 | } 22 | 23 | if (a != b) { 24 | io:println('FAIL'); 25 | } 26 | 27 | 28 | if (a != c) { 29 | io:println('ok'); 30 | } 31 | 32 | if (a == c) { 33 | io:println('FAIL'); 34 | } 35 | 36 | ==RESULT== 37 | ok 38 | ok 39 | ok 40 | -------------------------------------------------------------------------------- /tests/lang/prop_access_001.test: -------------------------------------------------------------------------------- 1 | Testing constant property access 2 | ==CODE== 3 | import std.io.*; 4 | 5 | println(Int.SIZE); 6 | ==RESULT== 7 | \d 8 | -------------------------------------------------------------------------------- /tests/lang/prop_access_002.test: -------------------------------------------------------------------------------- 1 | Testing property writing 2 | ==CODE== 3 | import std.io.*; 4 | 5 | class Foo { 6 | var a; 7 | 8 | function setA(n = 2) { 9 | this.a = n; 10 | } 11 | function getA() { 12 | return this.a; 13 | } 14 | } 15 | 16 | var c = Foo.new; 17 | 18 | c.setA(); 19 | 20 | println(c.a); 21 | println(c.getA()); 22 | 23 | c.setA(2000); 24 | println(c.a); 25 | println(c.getA()); 26 | ==RESULT== 27 | 2 28 | 2 29 | 2000 30 | 2000 31 | -------------------------------------------------------------------------------- /tests/lang/recursion_001.test: -------------------------------------------------------------------------------- 1 | Testing recurrency 2 | ==CODE== 3 | import std.io.*; 4 | 5 | function fib(x) { 6 | if (x < 1) { 7 | return 1; 8 | } 9 | return fib(x - 1) + fib(x - 2); 10 | } 11 | 12 | println(fib(10)); 13 | ==RESULT== 14 | 144 15 | -------------------------------------------------------------------------------- /tests/lang/scope_001.test: -------------------------------------------------------------------------------- 1 | Testing static scope 2 | ==CODE== 3 | import std.io.*; 4 | 5 | var a = 1; 6 | 7 | { 8 | var a = 2; 9 | 10 | println(a); 11 | } 12 | 13 | println(a); 14 | 15 | ==RESULT== 16 | 2 17 | 1 18 | -------------------------------------------------------------------------------- /tests/lang/scope_002.test: -------------------------------------------------------------------------------- 1 | Testing static scope 2 | ==CODE== 3 | import std.io.*; 4 | 5 | var a = 1; 6 | 7 | function fa() { return a; } 8 | 9 | { 10 | var a = 2; 11 | 12 | function fa() { return a; } 13 | 14 | println(fa()); 15 | } 16 | 17 | println(fa()); 18 | 19 | ==RESULT== 20 | 2 21 | 1 22 | -------------------------------------------------------------------------------- /tests/lang/scope_003.test: -------------------------------------------------------------------------------- 1 | Testing static scope 2 | ==CODE== 3 | import std.io.*; 4 | { function a() { return 2; } println(a()); } 5 | { function b() { return 3; } println(b()); } 6 | ==RESULT== 7 | 2 8 | 3 9 | -------------------------------------------------------------------------------- /tests/lang/smcall_001.test: -------------------------------------------------------------------------------- 1 | Testing static methods 2 | ==CODE== 3 | import std.io.*; 4 | 5 | class Foo { 6 | static function z(w) { 7 | println(w); 8 | } 9 | } 10 | 11 | Foo.z(123); 12 | ==RESULT== 13 | 123 14 | -------------------------------------------------------------------------------- /tests/lang/smcall_002.test: -------------------------------------------------------------------------------- 1 | [FATAL] Testing static methods 2 | ==CODE== 3 | import std.io.*; 4 | 5 | class Foo { 6 | static function z(w) { 7 | println(w); 8 | } 9 | } 10 | 11 | var f = Foo.new; 12 | f.z(123); 13 | 14 | ==RESULT== 15 | Fatal error: Method `Foo::z' cannot be called non-statically on \S+ line 10 16 | -------------------------------------------------------------------------------- /tests/lang/smcall_003.test: -------------------------------------------------------------------------------- 1 | Testing static method call 2 | ==CODE== 3 | import std.io.*; 4 | 5 | class Foo { 6 | static private function z(w) { 7 | println(w); 8 | } 9 | 10 | static function w() { 11 | Foo.z(123); 12 | } 13 | } 14 | 15 | Foo.w(); 16 | ==RESULT== 17 | 123 18 | -------------------------------------------------------------------------------- /tests/lang/smcall_004.test: -------------------------------------------------------------------------------- 1 | [FATAL] Testing static method call 2 | ==CODE== 3 | import std.io.*; 4 | 5 | class Foo { 6 | static private function z(w) { 7 | println(w); 8 | } 9 | 10 | static private function w() { 11 | Foo.z(123); 12 | } 13 | } 14 | 15 | Foo.w(); 16 | ==RESULT== 17 | Fatal error: Cannot access member `Foo::w' from context on \S+ line 13 18 | -------------------------------------------------------------------------------- /tests/lang/static_001.test: -------------------------------------------------------------------------------- 1 | [FATAL] Testing `this' access on static method 2 | ==CODE== 3 | import std.io; 4 | 5 | class Foo { 6 | static function abc() { 7 | this.a = 1; 8 | } 9 | } 10 | 11 | Foo.abc(); 12 | ==RESULT== 13 | Compile error: Cannot use `this' variable on static method on \S+ line 5 14 | -------------------------------------------------------------------------------- /tests/lang/static_002.test: -------------------------------------------------------------------------------- 1 | [FATAL] Testing `this` variable access on static method 2 | ==CODE== 3 | import std.io; 4 | 5 | class Foo { 6 | static function abc() { 7 | io:println(this.a); 8 | } 9 | } 10 | 11 | Foo.abc(); 12 | ==RESULT== 13 | Compile error: Cannot use `this' variable on static method on \S+ line 5 14 | -------------------------------------------------------------------------------- /tests/lang/string_001.test: -------------------------------------------------------------------------------- 1 | Simple string test 2 | ==CODE== 3 | import std.io.*; 4 | 5 | println("Hello clever"); 6 | 7 | printf("Testing the \1 function\n", "printf"); 8 | printf("Testing the \2 function with \1 items\n", "two", "printf"); 9 | var a = "10"; 10 | printf("One more test with \1 \2 \3 \4 \5 \6 \7 \8 \9 \10\n", 1, "two", 3, 4, 5, "six", 7, 8, 9, a); 11 | 12 | print("Print without new line"); 13 | println(""); 14 | ==RESULT== 15 | Hello clever 16 | Testing the printf function 17 | Testing the printf function with two items 18 | One more test with 1 two 3 4 5 six 7 8 9 10 19 | Print without new line 20 | -------------------------------------------------------------------------------- /tests/lang/string_002.test: -------------------------------------------------------------------------------- 1 | Testing String.format 2 | ==CODE== 3 | import std.io.*; 4 | 5 | println("Hello clever"); 6 | 7 | println(String.format("Testing the \1 function", "String.format")); 8 | println(String.format("Testing the \2 function with \1 items", "two", "String.format")); 9 | var a = "10"; 10 | println(String.format("One more test with \1 \2 \3 \4 \5 \6 \7 \8 \9 \10", 1, "two", 3, 4, 5, "six", 7, 8, 9, a)); 11 | 12 | print("Print without new line"); 13 | println(""); 14 | ==RESULT== 15 | Hello clever 16 | Testing the String.format function 17 | Testing the String.format function with two items 18 | One more test with 1 two 3 4 5 six 7 8 9 10 19 | Print without new line 20 | -------------------------------------------------------------------------------- /tests/lang/string_003.test: -------------------------------------------------------------------------------- 1 | String.find() 2 | ==CODE== 3 | import std.io.*; 4 | 5 | var s = "Hello Clever"; 6 | println(s.find("Hello")); 7 | println(s.find("Hello", 0)); 8 | println(s.find("Hello", 0, 4)); 9 | println(s.find("Clever")); 10 | println(s.find("Clever", 6)); 11 | println(s.find("Clever", 6, 6)); 12 | println(s.find("Hello Clever", 5)); 13 | println(s.find("Clever Hello")); 14 | ==RESULT== 15 | 0 16 | 0 17 | 0 18 | 6 19 | 6 20 | 6 21 | -1 22 | -1 23 | -------------------------------------------------------------------------------- /tests/lang/string_004.test: -------------------------------------------------------------------------------- 1 | String.findFirst() 2 | ==CODE== 3 | import std.io.*; 4 | 5 | var s = "Hello Clever"; 6 | println(s.findFirst("eo")); 7 | println(s.findFirst("eo", 6)); 8 | println(s.findFirst("eo", 4, 2)); 9 | 10 | ==RESULT== 11 | 1 12 | 8 13 | 4 14 | -------------------------------------------------------------------------------- /tests/lang/string_005.test: -------------------------------------------------------------------------------- 1 | String.findLast() 2 | ==CODE== 3 | import std.io.*; 4 | 5 | var s = "Hello Clever"; 6 | println(s.findLast("e")); 7 | println(s.findLast("o")); 8 | 9 | ==RESULT== 10 | 10 11 | 4 12 | -------------------------------------------------------------------------------- /tests/lang/string_006.test: -------------------------------------------------------------------------------- 1 | String.subString() 2 | ==CODE== 3 | import std.io.*; 4 | 5 | var s = "Hello Clever"; 6 | println(s.subString(0, 5)); 7 | println(s.subString(6)); 8 | 9 | ==RESULT== 10 | Hello 11 | Clever 12 | -------------------------------------------------------------------------------- /tests/lang/string_007.test: -------------------------------------------------------------------------------- 1 | String Comparison 2 | ==CODE== 3 | import std.io.*; 4 | 5 | var foo = "Clever"; 6 | var bar = "Clever"; 7 | 8 | println((foo == bar)); 9 | 10 | if (foo == bar) { 11 | println('ok'); 12 | } 13 | 14 | ==RESULT== 15 | true 16 | ok 17 | -------------------------------------------------------------------------------- /tests/lang/string_008.test: -------------------------------------------------------------------------------- 1 | String Comparison 2 | ==CODE== 3 | import std.io.*; 4 | var a = "abc"; 5 | 6 | println(a); 7 | a.setChar(1, "cs"); 8 | println(a); 9 | 10 | ==RESULT== 11 | abc 12 | acs 13 | -------------------------------------------------------------------------------- /tests/lang/subscript_001.test: -------------------------------------------------------------------------------- 1 | Testing subscript operator 2 | ==CODE== 3 | import std.io.*; 4 | 5 | var a = [1,2]; 6 | 7 | println(a[0]); 8 | 9 | a[1] = 1; 10 | 11 | println(a); 12 | ==RESULT== 13 | 1 14 | \[1, 1\] 15 | -------------------------------------------------------------------------------- /tests/lang/subscript_002.test: -------------------------------------------------------------------------------- 1 | Testing subscript operator out of bound 2 | ==CODE== 3 | import std.io.*; 4 | 5 | var a = []; 6 | 7 | try { 8 | println(a[1]); 9 | } catch (e) { 10 | println(e); 11 | } 12 | ==RESULT== 13 | Array index out of bound! 14 | -------------------------------------------------------------------------------- /tests/lang/subscript_003.test: -------------------------------------------------------------------------------- 1 | Testing subscript operator with property 2 | ==CODE== 3 | import std.io.*; 4 | 5 | class Foo { 6 | var arr; 7 | 8 | function Foo() { 9 | this.arr = [10, 20]; 10 | } 11 | } 12 | 13 | println((Foo.new).arr[0]); 14 | ==RESULT== 15 | 10 16 | -------------------------------------------------------------------------------- /tests/lang/subscript_004.test: -------------------------------------------------------------------------------- 1 | Testing subscript operator 2 | ==CODE== 3 | import std.io.*; 4 | 5 | var str = "foo"; 6 | println(str[0]); 7 | 8 | var arr = [1,2,3]; 9 | println(arr[2]); 10 | 11 | var map = {'felipe': 123}; 12 | println(map['felipe']); 13 | ==RESULT== 14 | f 15 | 3 16 | 123 17 | -------------------------------------------------------------------------------- /tests/lang/subscript_005.test: -------------------------------------------------------------------------------- 1 | Testing map item change 2 | ==CODE== 3 | import std.io.*; 4 | 5 | var arr = {'felipe': 1}; 6 | 7 | arr['felipe'] = 2; 8 | 9 | println(arr); 10 | ==RESULT== 11 | \{"felipe": 2\} 12 | -------------------------------------------------------------------------------- /tests/lang/switch_001.test: -------------------------------------------------------------------------------- 1 | Testing switch-case 2 | ==CODE== 3 | import std.io.*; 4 | 5 | var x = 3; 6 | 7 | switch (x) { 8 | case 3: 9 | println(3); 10 | break; 11 | case 1: 12 | println(1); 13 | break; 14 | case 2: 15 | println(2); 16 | break; 17 | } 18 | 19 | ==RESULT== 20 | 3 21 | -------------------------------------------------------------------------------- /tests/lang/switch_002.test: -------------------------------------------------------------------------------- 1 | Testing swith-case 2 | ==CODE== 3 | import std.io.*; 4 | 5 | var x = 3; 6 | 7 | switch (x) { 8 | case 3: 9 | println(3); 10 | case 1: 11 | println(1); 12 | break; 13 | case 2: 14 | println(2); 15 | break; 16 | } 17 | 18 | ==RESULT== 19 | 3 20 | 1 21 | -------------------------------------------------------------------------------- /tests/lang/switch_003.test: -------------------------------------------------------------------------------- 1 | Testing swith-case 2 | ==CODE== 3 | import std.io.*; 4 | 5 | var x = 4; 6 | 7 | switch (x) { 8 | case 3: 9 | println(3); 10 | break; 11 | case 1: 12 | println(1); 13 | break; 14 | case 2: 15 | println(2); 16 | break; 17 | } 18 | 19 | println("Done!"); 20 | 21 | ==RESULT== 22 | Done! 23 | -------------------------------------------------------------------------------- /tests/lang/switch_004.test: -------------------------------------------------------------------------------- 1 | Testing default case 2 | ==CODE== 3 | import std.io.*; 4 | 5 | switch (1) { 6 | default: 7 | println(123); 8 | case 3: 9 | println(3); 10 | break; 11 | } 12 | 13 | ==RESULT== 14 | 123 15 | 3 16 | -------------------------------------------------------------------------------- /tests/lang/switch_005.test: -------------------------------------------------------------------------------- 1 | Testing default case 2 | ==CODE== 3 | import std.io.*; 4 | 5 | switch (1) { 6 | default: 7 | println(123); 8 | break; 9 | case 3: 10 | println(3); 11 | break; 12 | } 13 | 14 | ==RESULT== 15 | 123 16 | -------------------------------------------------------------------------------- /tests/lang/switch_006.test: -------------------------------------------------------------------------------- 1 | Testing default case 2 | ==CODE== 3 | import std.io.*; 4 | 5 | switch (3) { 6 | default: 7 | println(123); 8 | break; 9 | case 3: 10 | println(3); 11 | break; 12 | } 13 | 14 | switch (3) { 15 | case 3: 16 | println(3); 17 | break; 18 | default: 19 | println(123); 20 | break; 21 | } 22 | 23 | ==RESULT== 24 | 3 25 | 3 26 | -------------------------------------------------------------------------------- /tests/lang/switch_007.test: -------------------------------------------------------------------------------- 1 | Testing default case 2 | ==CODE== 3 | import std.io.*; 4 | 5 | switch (1) { 6 | default: 7 | println(123); 8 | } 9 | 10 | ==RESULT== 11 | 123 12 | -------------------------------------------------------------------------------- /tests/lang/switch_008.test: -------------------------------------------------------------------------------- 1 | Testing default case 2 | ==CODE== 3 | import std.io.*; 4 | 5 | switch (3) { 6 | default: 7 | println(123); 8 | case 3: println(3); 9 | case 2: println(2); 10 | case 1: println(1); 11 | } 12 | 13 | ==RESULT== 14 | 3 15 | 2 16 | 1 17 | -------------------------------------------------------------------------------- /tests/lang/switch_009.test: -------------------------------------------------------------------------------- 1 | Testing default case 2 | ==CODE== 3 | import std.io.*; 4 | 5 | switch (4) { 6 | default:println(123); 7 | case 3: println(3); 8 | case 2: println(2); 9 | case 1: println(1); 10 | } 11 | 12 | 13 | ==RESULT== 14 | 123 15 | 3 16 | 2 17 | 1 18 | -------------------------------------------------------------------------------- /tests/lang/this_001.test: -------------------------------------------------------------------------------- 1 | Testing this variable 2 | ==CODE== 3 | import std.io.*; 4 | 5 | class Foo { 6 | var a; 7 | 8 | function getA() { return this.getX(); } 9 | 10 | function getX() { return 3; } 11 | } 12 | 13 | var foo = Foo.new; 14 | println(foo.getA()); 15 | 16 | foo = null; 17 | ==RESULT== 18 | 3 19 | -------------------------------------------------------------------------------- /tests/lang/this_002.test: -------------------------------------------------------------------------------- 1 | Testing object context 2 | ==CODE== 3 | import std.io.*; 4 | 5 | class Foo { 6 | var x; 7 | 8 | function setX(n) { this.x = n; } 9 | function getX() { return this.x; } 10 | } 11 | 12 | var a = Foo.new, 13 | b = Foo.new; 14 | 15 | a.setX(123); 16 | b.setX(321); 17 | 18 | println(a.getX(), b.getX()); 19 | 20 | ==RESULT== 21 | 123 22 | 321 23 | -------------------------------------------------------------------------------- /tests/lang/this_003.test: -------------------------------------------------------------------------------- 1 | [FATAL] Testing this variable overwrite 2 | ==CODE== 3 | import std.io.*; 4 | 5 | class Foo { 6 | var a; 7 | 8 | function Foo() { 9 | this = 2; 10 | } 11 | } 12 | 13 | var a = Foo.new; 14 | ==RESULT== 15 | Fatal error: Cannot assign to a const variable! on \S+ line \d+ 16 | -------------------------------------------------------------------------------- /tests/lang/this_004.test: -------------------------------------------------------------------------------- 1 | Testing property access on method chaining 2 | ==CODE== 3 | import std.io.*; 4 | 5 | class Foo { 6 | var x; 7 | function self() { 8 | this.x = 2; 9 | return this; 10 | } 11 | } 12 | 13 | var foo = Foo.new; 14 | println(foo.self().x); 15 | 16 | ==RESULT== 17 | 2 18 | -------------------------------------------------------------------------------- /tests/lang/this_005.test: -------------------------------------------------------------------------------- 1 | Testing object destruction 2 | ==CODE== 3 | import std.io.*; 4 | 5 | class Bar { var z; } 6 | 7 | class Foo { 8 | function bar() { 9 | Bar.new; 10 | } 11 | } 12 | 13 | var arr = [Foo.new]; 14 | 15 | arr.each(function(t) { 16 | t.bar(); 17 | }); 18 | 19 | println("Done!"); 20 | ==RESULT== 21 | Done! 22 | -------------------------------------------------------------------------------- /tests/lang/this_006.test: -------------------------------------------------------------------------------- 1 | Testing property access on write mode 2 | ==CODE== 3 | import std.io.*; 4 | 5 | class Cc { 6 | var x; 7 | 8 | function Cc(x) {this.x = x; } 9 | 10 | function foo() { ++this.x; println(this.x); } 11 | } 12 | 13 | var c = Cc.new(2); 14 | c.foo(); 15 | 16 | ==RESULT== 17 | 3 18 | -------------------------------------------------------------------------------- /tests/lang/this_007.test: -------------------------------------------------------------------------------- 1 | Testing member visibility 2 | ==CHECK== 3 | if (!Clever.hasThreads()) { 4 | println("skip"); 5 | } 6 | ==CODE== 7 | import std.io.*; 8 | import std.concurrent.*; 9 | 10 | function abc(x) { x.a = 1; } 11 | 12 | class Foo { 13 | var arr; 14 | var a; 15 | 16 | function Foo() { 17 | this.arr = []; 18 | this.arr.append(Thread.new(abc, this, 2, 3, 4)); 19 | } 20 | 21 | function run() { 22 | this.arr.each(function(l) { 23 | l.start(); 24 | }); 25 | } 26 | 27 | function end() { 28 | this.arr.each(function(l) { 29 | l.wait(); 30 | }); 31 | } 32 | } 33 | 34 | var f = Foo.new; 35 | 36 | f.run(); 37 | f.end(); 38 | 39 | println(f.a); 40 | ==RESULT== 41 | 1 42 | -------------------------------------------------------------------------------- /tests/lang/try_001.test: -------------------------------------------------------------------------------- 1 | Testing try-catch-finally 2 | ==CODE== 3 | import std.io.*; 4 | try { 5 | throw "yay!"; 6 | 7 | println(1); 8 | } catch (e) { 9 | printf("Caught: \1\n", e); 10 | } finally { 11 | println(3); 12 | } 13 | ==RESULT== 14 | Caught: yay! 15 | 3 16 | -------------------------------------------------------------------------------- /tests/lang/try_002.test: -------------------------------------------------------------------------------- 1 | Testing nested try-catch-finally 2 | ==CODE== 3 | import std.io.*; 4 | 5 | try { 6 | try { 7 | throw "E1"; 8 | println(1); 9 | } catch (e) { 10 | printf("Caught: \1\n", e); 11 | } finally { 12 | println(3); 13 | throw "E2"; 14 | } 15 | } catch (e) { 16 | printf("Caught: \1\n", e); 17 | } finally { 18 | println(4); 19 | } 20 | 21 | ==RESULT== 22 | Caught: E1 23 | 3 24 | Caught: E2 25 | 4 26 | -------------------------------------------------------------------------------- /tests/lang/try_003.test: -------------------------------------------------------------------------------- 1 | [FATAL] Testing exception 2 | ==CODE== 3 | import std.io.*; 4 | throw "ae"; 5 | ==RESULT== 6 | Fatal error: Unhandled exception! on \S+ line 2 7 | Message: ae 8 | Stack trace: 9 | 10 | -------------------------------------------------------------------------------- /tests/lang/try_004.test: -------------------------------------------------------------------------------- 1 | [FATAL] Testing exception 2 | ==CODE== 3 | import std.io.*; 4 | print(println+println); 5 | ==RESULT== 6 | Fatal error: Unhandled exception! on \S+ line 2 7 | Message: Cannot use \+ operator with Function type 8 | Stack trace: 9 | 10 | -------------------------------------------------------------------------------- /tests/lang/try_005.test: -------------------------------------------------------------------------------- 1 | Testing nested exception 2 | ==CODE== 3 | import std.io.*; 4 | try { 5 | try { 6 | throw "foo"; 7 | } catch (e) { 8 | println("level 2"); 9 | println(e); 10 | throw e; 11 | } 12 | } catch (e) { 13 | println("level 1"); 14 | println(e); 15 | } 16 | ==RESULT== 17 | level 2 18 | foo 19 | level 1 20 | foo 21 | -------------------------------------------------------------------------------- /tests/lang/variadic_001.test: -------------------------------------------------------------------------------- 1 | Testing variadic function 2 | ==CODE== 3 | import std.io.*; 4 | 5 | function foo(c =1,a...) { println(c,a); } 6 | 7 | foo(1,2); 8 | ==RESULT== 9 | 1 10 | \[2\] 11 | -------------------------------------------------------------------------------- /tests/lang/variadic_002.test: -------------------------------------------------------------------------------- 1 | Testing variadic function 2 | ==CODE== 3 | import std.io.*; 4 | 5 | function foo(c1,a...) { println(123,a); } 6 | 7 | foo(1,2); 8 | ==RESULT== 9 | 123 10 | \[2\] 11 | -------------------------------------------------------------------------------- /tests/lang/variadic_003.test: -------------------------------------------------------------------------------- 1 | Testing variadic function 2 | ==CODE== 3 | import std.io.*; 4 | 5 | function foo(a...) { println(a, a.size()); } 6 | 7 | foo(1, 2, 3, 4); 8 | ==RESULT== 9 | \[1, 2, 3, 4\] 10 | 4 11 | -------------------------------------------------------------------------------- /tests/lang/variadic_005.test: -------------------------------------------------------------------------------- 1 | Testing variadic function 2 | ==CODE== 3 | import std.io.*; 4 | 5 | function foo(a...) { println(a, a.size()); } 6 | 7 | foo(); 8 | ==RESULT== 9 | \[\] 10 | 0 11 | -------------------------------------------------------------------------------- /tests/lang/variadic_006.test: -------------------------------------------------------------------------------- 1 | Testing variadic function 2 | ==CODE== 3 | import std.io.*; 4 | 5 | function foo(b, a...) { println(b, a, a.size()); } 6 | 7 | foo(1); 8 | ==RESULT== 9 | 1 10 | \[\] 11 | 0 12 | -------------------------------------------------------------------------------- /tests/lang/while_001.test: -------------------------------------------------------------------------------- 1 | Testing while loop 2 | ==CODE== 3 | import std.io.*; 4 | 5 | var a = 10; 6 | 7 | while (a-- > 0) { 8 | println(a); 9 | } 10 | 11 | ==RESULT== 12 | 9 13 | 8 14 | 7 15 | 6 16 | 5 17 | 4 18 | 3 19 | 2 20 | 1 21 | 0 22 | -------------------------------------------------------------------------------- /tests/lang/while_002.test: -------------------------------------------------------------------------------- 1 | Testing do-while 2 | ==CODE== 3 | import std.io; 4 | 5 | var i = 10; 6 | 7 | do { 8 | io:println(i); 9 | } while (i-- > 2); 10 | ==RESULT== 11 | 10 12 | 9 13 | 8 14 | 7 15 | 6 16 | 5 17 | 4 18 | 3 19 | 2 20 | -------------------------------------------------------------------------------- /tests/samples/factorial.test: -------------------------------------------------------------------------------- 1 | Testing factorial 2 | ==CODE== 3 | import std.io.*; 4 | 5 | function fact(a) { 6 | if (a == 1) { 7 | return 1; 8 | } 9 | return a * fact(a-1); 10 | } 11 | 12 | println(fact(5)); 13 | println(fact(10)); 14 | ==RESULT== 15 | 120 16 | 3628800 17 | -------------------------------------------------------------------------------- /tests/std.collection/collection_001.test: -------------------------------------------------------------------------------- 1 | Testing Array, Set, Stack, PriorityQueue and Queue 2 | ==CODE== 3 | import std.collection.*; 4 | import std.io.*; 5 | 6 | var i = 0, j = 0; 7 | 8 | 9 | /*Queue*/ 10 | var q = Queue.new(); 11 | for (i = 0; i < 5; ++i) { 12 | q.push(i); 13 | } 14 | 15 | while (!q.empty()) { 16 | printf("q \1\n", q.front()); 17 | q.pop(); 18 | } 19 | 20 | /*Stack*/ 21 | q = Stack.new(); 22 | for (i = 0; i < 5; ++i) { 23 | q.push(i); 24 | } 25 | 26 | while (!q.empty()) { 27 | printf("s \1\n", q.top()); 28 | q.pop(); 29 | } 30 | 31 | 32 | /*PriorityQueue*/ 33 | 34 | function cmp(a, b) { 35 | return a < b; 36 | } 37 | 38 | q = PriorityQueue.new(cmp); 39 | for (i = -5; i < 5; ++i) { 40 | j = i * i; 41 | q.push(j); 42 | } 43 | 44 | 45 | while (!q.empty()) { 46 | printf("pq \1\n", q.top()); 47 | q.pop(); 48 | } 49 | 50 | /*Array*/ 51 | q = Array.new(); 52 | for (i = 0; i < 5; ++i) { 53 | q.append(i); 54 | } 55 | 56 | for (i = 0; i < 5; ++i) { 57 | printf("a \1\n", q[i]); 58 | } 59 | 60 | /*Set*/ 61 | q = Set.new(cmp); 62 | for (i = 0; i < 5; ++i) { 63 | q.insert(i); 64 | } 65 | printf("s "); 66 | println(q); 67 | 68 | 69 | 70 | ==RESULT== 71 | q 0 72 | q 1 73 | q 2 74 | q 3 75 | q 4 76 | s 4 77 | s 3 78 | s 2 79 | s 1 80 | s 0 81 | pq 25 82 | pq 16 83 | pq 16 84 | pq 9 85 | pq 9 86 | pq 4 87 | pq 4 88 | pq 1 89 | pq 1 90 | pq 0 91 | a 0 92 | a 1 93 | a 2 94 | a 3 95 | a 4 96 | s Set<0, 1, 2, 3, 4> 97 | -------------------------------------------------------------------------------- /tests/std.collection/priority_queue_001.test: -------------------------------------------------------------------------------- 1 | Testing PriorityQueue 2 | ==CODE== 3 | import std.collection.*; 4 | import std.io.*; 5 | 6 | 7 | function cmp(a, b) { 8 | return a < b; 9 | } 10 | 11 | var q = PriorityQueue.new(cmp); 12 | 13 | q.push(1); 14 | q.push(4); 15 | q.push(5); 16 | q.push(3); 17 | q.push(4); 18 | q.push(2); 19 | 20 | while (!q.empty()) { 21 | printf("\1\n", q.top()); 22 | q.pop(); 23 | } 24 | ==RESULT== 25 | 5 26 | 4 27 | 4 28 | 3 29 | 2 30 | 1 31 | -------------------------------------------------------------------------------- /tests/std.collection/queue_001.test: -------------------------------------------------------------------------------- 1 | Testing queue 2 | ==CODE== 3 | import std.io.*; 4 | import std.collection.*; 5 | 6 | var arr = [3, 2, 1]; 7 | var queue = Queue.new; 8 | 9 | arr.each(function(n) { queue.push(n); }); 10 | 11 | println("Size: " + queue.size()); 12 | 13 | while (!queue.empty()) { 14 | println(queue.front()); 15 | queue.pop(); 16 | } 17 | ==RESULT== 18 | Size: 3 19 | 3 20 | 2 21 | 1 22 | -------------------------------------------------------------------------------- /tests/std.collection/queue_002.test: -------------------------------------------------------------------------------- 1 | Testing queue destruction 2 | ==CODE== 3 | import std.io.*; 4 | import std.collection.*; 5 | 6 | var arr = [3, 2, 1]; 7 | var queue = Queue.new; 8 | 9 | arr.each(function(n) { queue.push(n); }); 10 | 11 | println("Size: " + queue.size()); 12 | ==RESULT== 13 | Size: 3 14 | -------------------------------------------------------------------------------- /tests/std.collection/set_001.test: -------------------------------------------------------------------------------- 1 | Testing set 2 | ==CODE== 3 | import std.io.*; 4 | import std.collection.*; 5 | 6 | var arr = [3, 2, 1]; 7 | 8 | function comp(a, b) { 9 | return a < b; 10 | } 11 | var set = Set.new(comp); 12 | 13 | arr.each(function(n) { set.insert(n); }); 14 | 15 | println("Size: " + set.size()); 16 | println(set); 17 | 18 | ==RESULT== 19 | Size: 3 20 | Set<1, 2, 3> 21 | -------------------------------------------------------------------------------- /tests/std.collection/set_002.test: -------------------------------------------------------------------------------- 1 | Testing Set.find() 2 | ==CODE== 3 | import std.io.*; 4 | import std.collection.*; 5 | 6 | var arr = [3, 2, 1]; 7 | 8 | function comp(a, b) { 9 | return a < b; 10 | } 11 | var set = Set.new(comp); 12 | 13 | arr.each(function(n) { set.insert(n); }); 14 | 15 | println(set.find(2)); 16 | ==RESULT== 17 | 2 18 | -------------------------------------------------------------------------------- /tests/std.collection/set_003.test: -------------------------------------------------------------------------------- 1 | Testing set union 2 | ==CODE== 3 | import std.io.*; 4 | import std.collection.*; 5 | 6 | var arr = [3, 2, 1]; 7 | var arr2 = [3, 9, 10]; 8 | 9 | function comp(a, b) { 10 | return a < b; 11 | } 12 | 13 | var set = Set.new(comp); 14 | var set2 = Set.new(comp); 15 | 16 | arr.each(function(n) { set.insert(n); }); 17 | arr2.each(function(n) { set2.insert(n); }); 18 | 19 | var set3 = set + set2; 20 | 21 | println("Size: " + (set+set2).size()); 22 | println((set+set2)); 23 | println(set3); 24 | ==RESULT== 25 | Size: 5 26 | Set<1, 2, 3, 9, 10> 27 | Set<1, 2, 3, 9, 10> 28 | -------------------------------------------------------------------------------- /tests/std.collection/set_004.test: -------------------------------------------------------------------------------- 1 | Testing set intersection 2 | ==CODE== 3 | import std.io.*; 4 | import std.collection.*; 5 | 6 | var arr = [3, 2, 1, 5, 6, 7]; 7 | var arr2 = [3, 2, 5, 9, 10]; 8 | 9 | function comp(a, b) { 10 | return a < b; 11 | } 12 | 13 | var set = Set.new(comp); 14 | var set2 = Set.new(comp); 15 | 16 | arr.each(function(n) { set.insert(n); }); 17 | arr2.each(function(n) { set2.insert(n); }); 18 | 19 | var set3 = set * set2; 20 | 21 | println("Size: " + (set * set2).size()); 22 | println(set * set2); 23 | println(set3); 24 | ==RESULT== 25 | Size: 3 26 | Set<2, 3, 5> 27 | Set<2, 3, 5> 28 | -------------------------------------------------------------------------------- /tests/std.collection/set_005.test: -------------------------------------------------------------------------------- 1 | Testing set diference 2 | ==CODE== 3 | import std.io.*; 4 | import std.collection.*; 5 | 6 | var arr = [3, 2, 1, 5, 6, 7]; 7 | var arr2 = [3, 2, 5, 9, 10]; 8 | 9 | function comp(a, b) { 10 | return a < b; 11 | } 12 | 13 | var set = Set.new(comp); 14 | var set2 = Set.new(comp); 15 | 16 | arr.each(function(n) { set.insert(n); }); 17 | arr2.each(function(n) { set2.insert(n); }); 18 | 19 | var set3 = set - set2; 20 | 21 | println("Size: " + (set - set2).size()); 22 | println(set - set2); 23 | println(set3); 24 | ==RESULT== 25 | Size: 3 26 | Set<1, 6, 7> 27 | Set<1, 6, 7> 28 | -------------------------------------------------------------------------------- /tests/std.collection/set_006.test: -------------------------------------------------------------------------------- 1 | Testing set symmetrical diference 2 | ==CODE== 3 | import std.io.*; 4 | import std.collection.*; 5 | 6 | var arr = [3, 2, 1, 5, 6, 7]; 7 | var arr2 = [3, 2, 5, 9, 10]; 8 | 9 | function comp(a, b) { 10 | return a < b; 11 | } 12 | 13 | var set = Set.new(comp); 14 | var set2 = Set.new(comp); 15 | 16 | arr.each(function(n) { set.insert(n); }); 17 | arr2.each(function(n) { set2.insert(n); }); 18 | 19 | var set3 = set / set2; 20 | 21 | println("Size: " + (set / set2).size()); 22 | println(set / set2); 23 | println(set3); 24 | ==RESULT== 25 | Size: 5 26 | Set<1, 6, 7, 9, 10> 27 | Set<1, 6, 7, 9, 10> 28 | -------------------------------------------------------------------------------- /tests/std.collection/set_007.test: -------------------------------------------------------------------------------- 1 | Testing set operations 2 | ==CODE== 3 | import std.io.*; 4 | import std.collection.*; 5 | 6 | var arr = [3, 2, 1, 5, 6, 7]; 7 | var arr2 = [3, 2, 5, 9, 10]; 8 | 9 | function comp(a, b) { 10 | return a < b; 11 | } 12 | 13 | var set = Set.new(comp); 14 | var set2 = Set.new(comp); 15 | 16 | arr.each(function(n) { set.insert(n); }); 17 | arr2.each(function(n) { set2.insert(n); }); 18 | 19 | var set3 = set + set2 - set * set2; 20 | 21 | println("Size: " + (set + set2 - set * set2).size()); 22 | println(set + set2 - set * set2); 23 | println(set3); 24 | println(set / set2); 25 | ==RESULT== 26 | Size: 5 27 | Set<1, 6, 7, 9, 10> 28 | Set<1, 6, 7, 9, 10> 29 | Set<1, 6, 7, 9, 10> 30 | -------------------------------------------------------------------------------- /tests/std.collection/stack_001.test: -------------------------------------------------------------------------------- 1 | Testing stack 2 | ==CODE== 3 | import std.io.*; 4 | import std.collection.*; 5 | 6 | var arr = [3, 2, 1]; 7 | var stack = Stack.new; 8 | 9 | arr.each(function(n) { stack.push(n); }); 10 | 11 | println("Size: " + stack.size()); 12 | 13 | while (!stack.empty()) { 14 | println(stack.top()); 15 | stack.pop(); 16 | } 17 | 18 | ==RESULT== 19 | Size: 3 20 | 1 21 | 2 22 | 3 23 | -------------------------------------------------------------------------------- /tests/std.collection/stack_002.test: -------------------------------------------------------------------------------- 1 | Testing stack destruction 2 | ==CODE== 3 | import std.io.*; 4 | import std.collection.*; 5 | 6 | var arr = [3, 2, 1]; 7 | var stack = Stack.new; 8 | 9 | arr.each(function(n) { stack.push(n); }); 10 | 11 | println("Size: " + stack.size()); 12 | 13 | ==RESULT== 14 | Size: 3 15 | -------------------------------------------------------------------------------- /tests/std.concurrent/condition_001.test: -------------------------------------------------------------------------------- 1 | Testing condition functionality 2 | ==CHECK== 3 | if (!Clever.hasThreads()) { 4 | println("skip"); 5 | } 6 | ==CODE== 7 | import std.io.*; 8 | import std.concurrent.*; 9 | 10 | var c = Condition.new(); 11 | var m = Mutex.new(); 12 | 13 | println(m.lock()); 14 | 15 | var thread = Thread.new(function(){ 16 | println(m.lock()); 17 | println(c.broadcast()); 18 | println(m.unlock()); 19 | }); 20 | 21 | thread.start(); 22 | 23 | println(c.wait(m)); 24 | 25 | println(m.unlock()); 26 | 27 | thread.wait(); 28 | ==RESULT== 29 | true 30 | true 31 | true 32 | true 33 | true 34 | true 35 | -------------------------------------------------------------------------------- /tests/std.concurrent/mutex_001.test: -------------------------------------------------------------------------------- 1 | Testing mutex functionality 2 | ==CODE== 3 | import std.io.*; 4 | import std.concurrent.*; 5 | 6 | var m = Mutex.new(); 7 | 8 | println(m.lock()); 9 | println(m.trylock()); 10 | println(m.unlock()); 11 | ==RESULT== 12 | true 13 | false 14 | true 15 | -------------------------------------------------------------------------------- /tests/std.concurrent/thread_001.test: -------------------------------------------------------------------------------- 1 | Testing threads in concurrent package [will fail in debug mode] 2 | ==CODE== 3 | import std.io.*; 4 | import std.concurrent.*; 5 | 6 | var test = Thread.new(function(){ 7 | printf("Hello World\n"); 8 | }); 9 | 10 | test.start(); 11 | test.wait(); 12 | ==RESULT== 13 | Hello World 14 | -------------------------------------------------------------------------------- /tests/std.concurrent/thread_002.test: -------------------------------------------------------------------------------- 1 | Testing threads inside threads in std.concurrent [will fail in debug mode] 2 | ==CODE== 3 | import std.io.*; 4 | import std.concurrent.*; 5 | 6 | var test = Thread.new(function(){ 7 | printf("Hello World\n"); 8 | var next = Thread.new(function(){ 9 | printf("Hello Again\n"); 10 | }); 11 | next.start(); 12 | next.wait(); 13 | }); 14 | 15 | 16 | test.start(); 17 | test.wait(); 18 | ==RESULT== 19 | Hello World 20 | Hello Again 21 | -------------------------------------------------------------------------------- /tests/std.concurrent/thread_003.test: -------------------------------------------------------------------------------- 1 | Testing threads.result() 2 | ==CODE== 3 | 4 | import std.io.*; 5 | import std.concurrent.*; 6 | 7 | function f(id) 8 | { 9 | return 3 * id; 10 | } 11 | var t1 = Thread.new(f, 1); 12 | var t2 = Thread.new(f, 2); 13 | 14 | t1.start(); 15 | t2.start(); 16 | 17 | t1.wait(); 18 | t2.wait(); 19 | 20 | printf("t1 = \1\n",t1.result()); 21 | printf("t2 = \1\n",t2.result()); 22 | ==RESULT== 23 | t1 = 3 24 | t2 = 6 25 | -------------------------------------------------------------------------------- /tests/std.crypto/base64_001.test: -------------------------------------------------------------------------------- 1 | Testing base64 2 | ==CODE== 3 | import std.io.*; 4 | import std.crypto.*; 5 | 6 | var v = base64_encode("foobar"); 7 | 8 | println(v, base64_decode(v)); 9 | ==RESULT== 10 | Zm9vYmFy 11 | foobar 12 | -------------------------------------------------------------------------------- /tests/std.crypto/md5_001.test: -------------------------------------------------------------------------------- 1 | Testing md5() function 2 | ==CODE== 3 | import std.io.*; 4 | import std.crypto.*; 5 | 6 | println(md5("foobar")); 7 | println(md5("f")); 8 | println(md5("F")); 9 | ==RESULT== 10 | 3858f62230ac3c915f300c664312c63f 11 | 8fa14cdd754f91cc6554c9e71929cce7 12 | 800618943025315f869e4e1f09471012 13 | -------------------------------------------------------------------------------- /tests/std.date/date_001.test: -------------------------------------------------------------------------------- 1 | Testing events in event package 2 | ==CODE== 3 | import std.*; 4 | 5 | 6 | var my_date = date:Date.new(1364710352); 7 | 8 | io:println(my_date.uformat('%Y:%m:%d')); 9 | io:println(my_date.uformat('%H:%M:%S')); 10 | 11 | ==RESULT== 12 | 2013:03:31 13 | 06:12:32 14 | -------------------------------------------------------------------------------- /tests/std.events/events_001.test: -------------------------------------------------------------------------------- 1 | Testing events in event package 2 | ==CODE== 3 | import std.events.*; 4 | import std.io.*; 5 | 6 | function foo1(x, y) { 7 | printf("foo1 : \1 \2\n", x, y); 8 | } 9 | 10 | function foo2(x, y, z) { 11 | printf("foo2 : \1 \2 \3\n", x, y, z); 12 | } 13 | 14 | function foo3(x, y) { 15 | printf("foo3 : \1 \2\n", x, y); 16 | } 17 | 18 | 19 | 20 | var e = Events.new(1000); 21 | 22 | e.connect("click", foo1); 23 | e.connect("click", foo3); 24 | 25 | e.connect("click2", foo2); 26 | 27 | 28 | e.emit("click", 1, 2); 29 | e.emit("click2", 1, 2, 3); 30 | 31 | e.emit("click", 1, 2); 32 | e.emit("click2", 1, 2, 3); 33 | 34 | e.finalize(); 35 | ==RESULT== 36 | foo1 : 1 2 37 | foo3 : 1 2 38 | foo2 : 1 2 3 39 | foo1 : 1 2 40 | foo3 : 1 2 41 | foo2 : 1 2 3 42 | -------------------------------------------------------------------------------- /tests/std.events/events_002.test: -------------------------------------------------------------------------------- 1 | Testing requisitions in event package 2 | ==CODE== 3 | import std.events.*; 4 | import std.io.*; 5 | 6 | function foo1(x, y) { 7 | printf("foo1 \1 \2 \n", x, y); 8 | } 9 | 10 | function foo2(x, y) { 11 | printf("foo2 \1 \2 \n", x, y); 12 | } 13 | 14 | function foo3(x, y) { 15 | printf("foo3 \1 \2 \n", x, y); 16 | } 17 | 18 | 19 | var e = Events.new(1); 20 | 21 | e.connect({'a0' : 1 , 'b0' : 2 , 'c0' : 3 }, foo1); 22 | e.connect({'a1' : 10 , 'b1' : 20 , 'c1' : 30 }, foo2); 23 | e.connect({'a2' : 100, 'b2' : 200, 'c2' : 3000}, foo3); 24 | 25 | e.set({'a0' : 1 , 'b0' : 2 , 'c0' : 3 }, 1, 2); 26 | e.set({'a1' : 10 , 'b1' : 20 , 'c1' : 30 }, 3, 4); 27 | e.set({'a2' : 100, 'b2' : 200, 'c2' : 3000}, 5, 6); 28 | 29 | e.finalize(); 30 | ==RESULT== 31 | foo1 1 2 32 | foo2 3 4 33 | foo3 5 6 34 | -------------------------------------------------------------------------------- /tests/std.ffi/ffi_001.c: -------------------------------------------------------------------------------- 1 | //File: hello.c 2 | //Description: A very simple C library 3 | #include 4 | #include 5 | 6 | typedef struct{ 7 | double l1; 8 | int l2; 9 | int l3; 10 | double l4; 11 | 12 | double y; 13 | int x; 14 | int z; 15 | double w; 16 | } C; 17 | 18 | void hello() { 19 | printf("Hello Clever FFI Module!\n"); 20 | } 21 | 22 | int add(int a, int b) { 23 | return a+b; 24 | } 25 | 26 | void printExt(char* s) { 27 | printf("S=%s\n",s); 28 | } 29 | 30 | int _sub(int a, int b){ 31 | return a-b; 32 | } 33 | 34 | 35 | void setC(C* s, int x, double y, int z, double w) { 36 | s->x = x; 37 | s->y = y; 38 | s->z = z; 39 | s->w = w; 40 | } 41 | 42 | int getCX(C* s) { 43 | return s->x; 44 | } 45 | 46 | double getCY(C* s) { 47 | return s->y; 48 | } 49 | 50 | int getCZ(C* s) { 51 | return s->z; 52 | } 53 | 54 | double getCW(C* s) { 55 | return s->w; 56 | } 57 | 58 | 59 | char* getStr() { 60 | char* str = (char*) malloc(5*sizeof(char)); 61 | sprintf(str, "%s", "dasd"); 62 | return str; 63 | } 64 | -------------------------------------------------------------------------------- /tests/std.ffi/ffi_001.sh: -------------------------------------------------------------------------------- 1 | cd tests/std.ffi/ 2 | rm -f *.o *.so 3 | gcc -fPIC -O3 -shared -c ffi_001.c 4 | gcc -shared -Wl,-soname,ffi_001.so -o ffi_001.so ffi_001.o -lc -ldl 5 | LD_LIBRARY_PATH=. 6 | 7 | -------------------------------------------------------------------------------- /tests/std.ffi/ffi_001.test: -------------------------------------------------------------------------------- 1 | Testing FFI and FFIStructure module 2 | ==CODE== 3 | 4 | import std.io.*; 5 | import std.ffi.*; 6 | import std.sys.*; 7 | 8 | system("sh tests/std.ffi/ffi_001.sh"); 9 | 10 | // FFI STRUCTURES DECLARATION 11 | var extS = FFITypes.new("ExtS"); 12 | 13 | extS.addMember("l1", FFITypes.DOUBLE); 14 | extS.addMember("l2", FFITypes.INT); 15 | extS.addMember("l3", FFITypes.INT); 16 | extS.addMember("l4", FFITypes.DOUBLE); 17 | 18 | 19 | extS.addMember("y", FFITypes.DOUBLE); 20 | extS.addMember("x", FFITypes.INT); 21 | extS.addMember("z", FFITypes.INT); 22 | extS.addMember("w", FFITypes.DOUBLE); 23 | 24 | 25 | var ffilib = FFITypes.new("tests/std.ffi/ffi_001"); 26 | 27 | ffilib.addFunction("setC", FFITypes.VOID, 28 | FFITypes.POINTER, FFITypes.INT, FFITypes.DOUBLE, FFITypes.INT, FFITypes.DOUBLE); 29 | 30 | ffilib.addFunction("getCX", FFITypes.INT, FFITypes.POINTER); 31 | ffilib.addFunction("getCY", FFITypes.DOUBLE, FFITypes.POINTER); 32 | ffilib.addFunction("getCZ", FFITypes.INT, FFITypes.POINTER); 33 | ffilib.addFunction("getCW", FFITypes.DOUBLE, FFITypes.POINTER); 34 | 35 | // FFI STRUCTURE CREATION 36 | var s = FFIStruct.new("ExtS"); 37 | 38 | s.setMember("x", 1); 39 | s.setMember("y", 3.123); 40 | s.setMember("z", 2); 41 | s.setMember("w", 902.1231375); 42 | 43 | println(s.x); 44 | println(s.y); 45 | println(s.z); 46 | println(s.w); 47 | 48 | var h = FFILib.new("tests/std.ffi/ffi_001"); 49 | 50 | // FFI CALL 51 | h.setC(s, 1111, 33.323123, 22, 283.123); 52 | 53 | println(s.x); 54 | println(s.y); 55 | println(s.z); 56 | println(s.w); 57 | 58 | println(h.getCX(s)); 59 | println(h.getCY(s)); 60 | println(h.getCZ(s)); 61 | println(h.getCW(s)); 62 | 63 | system("rm -f *.so *.o"); 64 | 65 | 66 | ==RESULT== 67 | 1 68 | 3.123 69 | 2 70 | 902.123 71 | 1111 72 | 33.3231 73 | 22 74 | 283.123 75 | 1111 76 | 33.3231 77 | 22 78 | 283.123 79 | -------------------------------------------------------------------------------- /tests/std.file/file_001.test: -------------------------------------------------------------------------------- 1 | Testing File operations 2 | ==CODE== 3 | import std.io.*; 4 | import std.file.*; 5 | import std.sys.*; 6 | 7 | var f = File.new('foo.bar', File.OUT | File.TRUNC); 8 | f.write('clever lang'); 9 | f.close(); 10 | 11 | f = File.new('foo.bar', File.IN); 12 | println(f.readLine()); 13 | f.close(); 14 | 15 | system("rm foo.bar"); 16 | ==RESULT== 17 | clever lang 18 | -------------------------------------------------------------------------------- /tests/std.file/file_002.test: -------------------------------------------------------------------------------- 1 | Testing Directories Manipulation 2 | ==CODE== 3 | import std.io.*; 4 | import std.file.*; 5 | 6 | if (is_dir('tests')) { 7 | println('Yep, its a dir!'); 8 | } 9 | 10 | if (is_dir('README.rst') == false) { 11 | println('Ops, its not a dir!'); 12 | } 13 | 14 | println(is_dir('dfasdfadsfadfadfadsfdasf')); 15 | 16 | ==RESULT== 17 | Yep, its a dir! 18 | Ops, its not a dir! 19 | false 20 | -------------------------------------------------------------------------------- /tests/std.file/file_003.test: -------------------------------------------------------------------------------- 1 | Testing File manipulations 2 | ==CODE== 3 | import std.io.*; 4 | import std.file.*; 5 | import std.sys.*; 6 | 7 | if (file_exists('foo.bar')) { 8 | println('File exists'); 9 | } else { 10 | println('File does not exists'); 11 | } 12 | 13 | var f = File.new('foo.bar', File.OUT | File.TRUNC); 14 | f.write('clever lang'); 15 | f.close(); 16 | 17 | rename('foo.bar', 'bar.foo'); 18 | 19 | if (file_exists('bar.foo')) { 20 | println('File exists'); 21 | } else { 22 | println('File does not exists'); 23 | } 24 | 25 | remove("bar.foo"); 26 | ==RESULT== 27 | File does not exists 28 | File exists 29 | -------------------------------------------------------------------------------- /tests/std.math/pi_001.test: -------------------------------------------------------------------------------- 1 | Testing module constant 2 | ==CODE== 3 | import std.*; 4 | 5 | io:println(math:PI); 6 | ==RESULT== 7 | 3\.14159 8 | -------------------------------------------------------------------------------- /tests/std.reflection/reflect_001.test: -------------------------------------------------------------------------------- 1 | Testing Reflect constructor 2 | ==CODE== 3 | import std.io.*; 4 | import std.reflection.*; 5 | 6 | var a = Reflect.new(print); 7 | 8 | a = Reflect.new(println); 9 | 10 | println("Done!"); 11 | ==RESULT== 12 | Done! 13 | -------------------------------------------------------------------------------- /tests/std.reflection/reflect_getnumargs_001.test: -------------------------------------------------------------------------------- 1 | Testing Reflect::getNumArgs() and Reflect::getNumReqArgs() 2 | ==CODE== 3 | import std.io.*; 4 | import std.reflection.*; 5 | 6 | function a(x, y = 1, z...) {} 7 | 8 | var r = Reflect.new(a); 9 | 10 | println(r.getNumArgs()); 11 | 12 | ==RESULT== 13 | 2 14 | -------------------------------------------------------------------------------- /tests/std.reflection/reflect_getnumreqargs_001.test: -------------------------------------------------------------------------------- 1 | Testing Reflect::getNumReqArgs() 2 | ==CODE== 3 | import std.io.*; 4 | import std.reflection.*; 5 | 6 | function a(x, y = 1, z...) {} 7 | 8 | var r = Reflect.new(a); 9 | 10 | println(r.getNumReqArgs()); 11 | 12 | ==RESULT== 13 | 1 14 | -------------------------------------------------------------------------------- /tests/std.reflection/reflect_isarray_001.test: -------------------------------------------------------------------------------- 1 | Testing Reflect::isArray() methods 2 | ==CODE== 3 | import std.io.*; 4 | import std.reflection.*; 5 | 6 | var a = Reflect.new(1); 7 | println(a.isArray()); 8 | 9 | a = Reflect.new(1.2); 10 | println(a.isArray()); 11 | 12 | a = Reflect.new([1, 2, 3]); 13 | println(a.isArray()); 14 | ==RESULT== 15 | false 16 | false 17 | true 18 | -------------------------------------------------------------------------------- /tests/std.reflection/reflect_isdouble_001.test: -------------------------------------------------------------------------------- 1 | Testing Reflect::isDouble() methods 2 | ==CODE== 3 | import std.io.*; 4 | import std.reflection.*; 5 | 6 | var a = Reflect.new(1); 7 | println(a.isDouble()); 8 | 9 | a = Reflect.new(1.2); 10 | println(a.isDouble()); 11 | ==RESULT== 12 | false 13 | true 14 | -------------------------------------------------------------------------------- /tests/std.reflection/reflect_isfunction_001.test: -------------------------------------------------------------------------------- 1 | Testing Reflect::isFunction() methods 2 | ==CODE== 3 | import std.io.*; 4 | import std.reflection.*; 5 | 6 | var a = Reflect.new(1); 7 | println(a.isFunction()); 8 | 9 | a = Reflect.new(1.2); 10 | println(a.isFunction()); 11 | 12 | a = Reflect.new(println); 13 | println(a.isFunction()); 14 | ==RESULT== 15 | false 16 | false 17 | true 18 | -------------------------------------------------------------------------------- /tests/std.reflection/reflect_isint_001.test: -------------------------------------------------------------------------------- 1 | Testing Reflect::isInt() methods 2 | ==CODE== 3 | import std.io.*; 4 | import std.reflection.*; 5 | 6 | var a = Reflect.new(1); 7 | println(a.isInt()); 8 | 9 | a = Reflect.new(1.2); 10 | println(a.isInt()); 11 | ==RESULT== 12 | true 13 | false 14 | -------------------------------------------------------------------------------- /tests/std.reflection/reflect_ismap_001.test: -------------------------------------------------------------------------------- 1 | Testing Reflect::isMap() methods 2 | ==CODE== 3 | import std.io.*; 4 | import std.reflection.*; 5 | 6 | var a = Reflect.new(1); 7 | println(a.isMap()); 8 | 9 | a = Reflect.new(1.2); 10 | println(a.isMap()); 11 | 12 | a = Reflect.new({"a": 1}); 13 | println(a.isMap()); 14 | ==RESULT== 15 | false 16 | false 17 | true 18 | -------------------------------------------------------------------------------- /tests/std.reflection/reflect_isstring_001.test: -------------------------------------------------------------------------------- 1 | Testing Reflect::isString() methods 2 | ==CODE== 3 | import std.io.*; 4 | import std.reflection.*; 5 | 6 | var a = Reflect.new(1); 7 | println(a.isString()); 8 | 9 | a = Reflect.new(1.2); 10 | println(a.isString()); 11 | 12 | a = Reflect.new("foo"); 13 | println(a.isString()); 14 | ==RESULT== 15 | false 16 | false 17 | true 18 | -------------------------------------------------------------------------------- /tests/std.reflection/reflect_isvariadic_001.test: -------------------------------------------------------------------------------- 1 | Testing Reflect::isVariadic() 2 | ==CODE== 3 | import std.io.*; 4 | import std.reflection.*; 5 | 6 | var r = Reflect.new(println); 7 | 8 | println(r.isVariadic()); 9 | ==RESULT== 10 | true 11 | -------------------------------------------------------------------------------- /tests/std.reflection/type_001.test: -------------------------------------------------------------------------------- 1 | Testing type() function 2 | ==CODE== 3 | import std.io.*; 4 | import std.reflection.*; 5 | 6 | println(type(println)); 7 | println(type(1)); 8 | println(type(1.2)); 9 | println(type(false)); 10 | println(type("foo")); 11 | ==RESULT== 12 | Function 13 | Int 14 | Double 15 | Bool 16 | String 17 | -------------------------------------------------------------------------------- /tests/std.regex/error_001.test: -------------------------------------------------------------------------------- 1 | Testing invalid pattern 2 | ==CODE== 3 | import std.io.*; 4 | import std.regex.*; 5 | 6 | var text = "foo.bar"; 7 | 8 | try { 9 | var re = Regex.new("[^."); 10 | 11 | while (re.match(text)) { 12 | println(re.group(0)); 13 | } 14 | } catch (e) { 15 | println("Error: " + e); 16 | } 17 | 18 | ==RESULT== 19 | Error: missing terminating \] for character class 20 | -------------------------------------------------------------------------------- /tests/std.regex/group_001.test: -------------------------------------------------------------------------------- 1 | Testing Regex::group() 2 | ==CODE== 3 | import std.io.*; 4 | import std.regex.*; 5 | 6 | var text = "test foo bar test"; 7 | 8 | var re = Regex.new("f\S+"); 9 | var re2 = Regex.new("te\S+"); 10 | 11 | if (re.match(text) && re2.match(text)) { 12 | println(re.group(0), re2.group(0)); 13 | } 14 | 15 | ==RESULT== 16 | foo 17 | test 18 | -------------------------------------------------------------------------------- /tests/std.regex/matches_001.test: -------------------------------------------------------------------------------- 1 | Testing Regex::matches() and Regex::group() 2 | ==CODE== 3 | import std.io.*; 4 | import std.regex.*; 5 | 6 | var text = "test foo bar test"; 7 | 8 | var re = Regex.new("f\S+"); 9 | 10 | if (re.match(text)) { 11 | println(re.group(0)); 12 | } 13 | ==RESULT== 14 | foo 15 | -------------------------------------------------------------------------------- /tests/std.unicode/unicode_001.test: -------------------------------------------------------------------------------- 1 | Simple UString tests 2 | ==CODE== 3 | import std.io.*; 4 | import std.unicode.*; 5 | 6 | var ustring = UString.new("Hello World さくら"); 7 | 8 | printf("UString: \1\n", ustring); 9 | printf("UString.getLength(ustring)=\1\n", ustring.size()); 10 | printf("UString.indexOf(W)=\1\n", ustring.indexOf("W")); 11 | printf("UString.lastIndexOf(o)=\1\n", ustring.lastIndexOf("o")); 12 | ustring.toUpper(); 13 | ustring.toLower(); 14 | printf("UString: \1\n", ustring); 15 | ==RESULT== 16 | UString: Hello World さくら 17 | UString.getLength\(ustring\)=21 18 | UString.indexOf\(W\)=6 19 | UString.lastIndexOf\(o\)=7 20 | UString: hello world さくら 21 | -------------------------------------------------------------------------------- /win32/win32.h: -------------------------------------------------------------------------------- 1 | /** 2 | * Clever programming language 3 | * Copyright (c) 2011-2012 Clever Team 4 | * 5 | * Permission is hereby granted, free of charge, to any person 6 | * obtaining a copy of this software and associated documentation 7 | * files (the "Software"), to deal in the Software without 8 | * restriction, including without limitation the rights to use, 9 | * copy, modify, merge, publish, distribute, sublicense, and/or sell 10 | * copies of the Software, and to permit persons to whom the 11 | * Software is furnished to do so, subject to the following 12 | * conditions: 13 | * The above copyright notice and this permission notice shall be 14 | * included in all copies or substantial portions of the Software. 15 | * 16 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, 17 | * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES 18 | * OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND 19 | * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT 20 | * HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, 21 | * WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING 22 | * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR 23 | * OTHER DEALINGS IN THE SOFTWARE. 24 | * 25 | */ 26 | 27 | #ifndef CLEVER_WIN32_H 28 | #define CLEVER_WIN32_H 29 | 30 | // Assuming that you're running a Windows 2000 or newer version... 31 | #if (_WIN32_WINNT <= 0x0500) 32 | #define _WIN32_WINNT 0x0500 33 | #endif 34 | 35 | #include 36 | 37 | // Do not define min/max macros. 38 | #define NOMINMAX 39 | #include 40 | 41 | std::string GetLastErrorStr(DWORD dwLastError); 42 | void CreateBackgroundProcess(std::string cline); 43 | 44 | #endif 45 | --------------------------------------------------------------------------------