├── .gitignore ├── Makefile.in ├── Makefile.inc.in ├── README.md ├── bootstrap ├── 32bit_little_endian │ └── .gitignore ├── 64bit_little_endian │ ├── .gitattributes │ ├── convergec.bootstrap │ └── convergel.bootstrap └── Makefile.in ├── compiler ├── .gitignore ├── Compiler │ ├── BC_Exec.cv │ ├── BC_Lib.cv │ ├── BC_Mod.cv │ ├── BC_Pkg.cv │ ├── Code_Gen.cv │ ├── Core.cv │ ├── Eval.cv │ ├── IMod_Gen.cv │ ├── ITree.cv │ ├── ITree_PP.cv │ ├── ITree_Rename.cv │ ├── ITree_WF.cv │ ├── Instrs_Opt.cv │ ├── Lift.cv │ ├── Link.cv │ ├── Parser.cv │ ├── QQ_Mode.cv │ ├── Targets │ │ ├── Available.cv │ │ ├── Sixty_Four_Bit.cv │ │ └── Thirty_Two_Bit.cv │ └── Tokenizer.cv ├── Makefile.in ├── convergec.cv ├── convergei.cv ├── convergel.cv └── convergep.cv ├── configure ├── docs ├── .gitignore ├── CHANGES ├── CREDITS ├── Makefile.in ├── README ├── ctmp │ └── index.html ├── cvd_to_html.cv ├── footer.inc ├── header.inc ├── index.html ├── install │ ├── INSTALL │ ├── README.BSD │ ├── README.Cygwin │ ├── README.MacOSX │ ├── README.MinGW │ └── README.cross ├── modules_cvd │ ├── Array.cvd │ ├── Builtins.cvd │ ├── CEI.cvd │ ├── CPK.Earley.DSL.cvd │ ├── Exceptions.cvd │ ├── File.cvd │ ├── Functional.cvd │ ├── Maths.cvd │ ├── PCRE.cvd │ ├── Platform.Env.cvd │ ├── Platform.Exec.cvd │ ├── Platform.Host.cvd │ ├── Platform.Properties.cvd │ ├── Random.cvd │ ├── Sort.cvd │ ├── Strings.cvd │ ├── Sys.cvd │ ├── Time.cvd │ ├── VM.cvd │ ├── XML.Nodes.cvd │ ├── XML.XDM.cvd │ └── XML.XHTML.cvd ├── modules_html │ └── .gitignore ├── quick_intro │ └── index.html └── tools │ ├── compiler.html │ ├── convergei.html │ ├── convergep.html │ ├── documentation.html │ └── index.html ├── examples ├── Makefile.in ├── benchmarks │ ├── .gitignore │ ├── Makefile.in │ ├── cvstone.cv │ ├── fannkuch-redux.cv │ └── richards.cv ├── compile_time │ ├── .gitignore │ ├── Makefile.in │ ├── ani_funcs.cv │ ├── fib_cache.cv │ ├── nested.cv │ ├── powers.cv │ └── printf.cv ├── dsls │ ├── Makefile.in │ ├── statemachine │ │ ├── .gitignore │ │ ├── Makefile.in │ │ ├── README │ │ ├── SM1.cv │ │ ├── SM2.cv │ │ ├── SM3.cv │ │ ├── SM4.cv │ │ ├── SM5.cv │ │ ├── ex1.cv │ │ ├── ex2.cv │ │ ├── ex3.cv │ │ ├── ex4.cv │ │ └── ex5.cv │ └── wsi_asm │ │ ├── .gitignore │ │ ├── Makefile.in │ │ ├── README │ │ ├── WSI_Asm.cv │ │ ├── ex1.cv │ │ ├── ex2.cv │ │ ├── ex3.cv │ │ ├── ex4.cv │ │ └── fib.cv └── metaclasses │ ├── .gitignore │ ├── Makefile.in │ └── singleton.cv ├── install-sh ├── lib ├── .gitignore ├── Makefile.Stdlib.in ├── Makefile.in └── Stdlib │ ├── Backtrace.cv │ ├── CEI.cv │ ├── CPK │ ├── Earley │ │ ├── DSL.cv │ │ ├── Grammar.cv │ │ └── Parser.cv │ ├── Token.cv │ ├── Tokens.cv │ ├── Traverser.cv │ └── Tree.cv │ ├── File.cv │ ├── Functional.cv │ ├── Maths.cv │ ├── Numbers.cv │ ├── Parse_Args.cv │ ├── Platform │ ├── Env.cv │ ├── Exec.cv │ ├── Host.cv │ └── Properties.cv │ ├── Sort.cv │ ├── Strings.cv │ ├── Time.cv │ └── XML │ ├── Nodes.cv │ ├── XDM.cv │ └── XHTML.cv ├── platform └── MinGW │ ├── convergec.bat │ ├── convergei.bat │ ├── convergel.bat │ ├── convergep.bat │ └── cvd_to_html.bat ├── tests ├── Makefile.in ├── lang │ ├── Lang_Test.cv │ ├── Makefile.in │ ├── builtins │ │ ├── .gitignore │ │ ├── Makefile.in │ │ ├── class1.cv │ │ ├── int1.cv │ │ ├── list1.cv │ │ ├── str1.cv │ │ └── tests.cv │ ├── namespaces │ │ ├── .gitignore │ │ ├── Makefile.in │ │ ├── ns1.cv │ │ ├── ns2.cv │ │ ├── ns3.cv │ │ ├── ns4.cv │ │ ├── ns5.cv │ │ ├── ns6.cv │ │ ├── ns7.cv │ │ ├── qq1.cv │ │ ├── qq2.cv │ │ ├── qq3.cv │ │ ├── qq4.cv │ │ ├── qq5.cv │ │ ├── qq6.cv │ │ ├── qq7.cv │ │ ├── qq8.cv │ │ └── tests.cv │ └── splicing │ │ ├── .gitignore │ │ ├── Makefile.in │ │ ├── result1.cv │ │ ├── result2.cv │ │ ├── result3.cv │ │ ├── result4.cv │ │ ├── tests.cv │ │ ├── type1.cv │ │ └── type2.cv └── threads │ ├── Makefile.in │ ├── pthreads │ ├── 1.cv │ └── Makefile.in │ └── single_thread │ └── Makefile.in └── vm ├── .gitignore ├── Builtins.py ├── Bytecode.py ├── Config.py.in ├── Core.py ├── Makefile.in ├── Modules ├── Con_Array.py ├── Con_C_Earley_Parser.py ├── Con_C_Platform_Env.py ├── Con_C_Platform_Exec.py ├── Con_C_Platform_Host.py ├── Con_C_Platform_Properties.py ├── Con_C_Strings.py ├── Con_C_Time.py ├── Con_Curses.py ├── Con_Exceptions.py ├── Con_PCRE.py ├── Con_POSIX_File.py ├── Con_Random.py ├── Con_Sys.py ├── Con_Thread.py ├── Con_VM.py ├── __init__.py └── libXML2.py ├── Stdlib_Modules.py ├── Target.py ├── VM.py ├── main.py └── platform ├── fgetln.c └── fgetln.h /.gitignore: -------------------------------------------------------------------------------- 1 | # Boring file regexps: 2 | *.o 3 | *~ 4 | *.a 5 | *Makefile 6 | *Makefile.inc 7 | autom4te.cache 8 | config.log 9 | config.status 10 | *.core 11 | *.cvb 12 | *.cvl 13 | converge-* 14 | -------------------------------------------------------------------------------- /Makefile.in: -------------------------------------------------------------------------------- 1 | all: 2 | cd vm && ${MAKE} ${MFLAGS} 3 | ifeq (${wildcard lib/Stdlib.cvl}, ) 4 | @echo "===> lib/Stdlib.cvl does not exist: compiling minimal library" 5 | cd lib && ${MAKE} ${MFLAGS} minimal 6 | cd compiler && ${MAKE} ${MFLAGS} minimal 7 | @echo "===> compiling rest of library" 8 | cd lib && ${MAKE} ${MFLAGS} 9 | cd compiler && ${MAKE} ${MFLAGS} 10 | else 11 | cd lib && ${MAKE} ${MFLAGS} 12 | cd compiler && ${MAKE} ${MFLAGS} 13 | endif 14 | cd docs && ${MAKE} ${MFLAGS} 15 | 16 | install: all 17 | cd vm && ${MAKE} ${MFLAGS} install 18 | cd lib && ${MAKE} ${MFLAGS} install 19 | cd compiler && ${MAKE} ${MFLAGS} install 20 | cd examples && ${MAKE} ${MFLAGS} install 21 | cd docs && ${MAKE} ${MFLAGS} install 22 | 23 | clean: 24 | cd bootstrap && ${MAKE} ${MFLAGS} clean 25 | cd vm && ${MAKE} ${MFLAGS} clean 26 | cd lib && ${MAKE} ${MFLAGS} clean 27 | cd compiler && ${MAKE} ${MFLAGS} clean 28 | cd examples && ${MAKE} ${MFLAGS} clean 29 | cd docs && ${MAKE} ${MFLAGS} clean 30 | cd tests && ${MAKE} ${MFLAGS} clean 31 | 32 | ifdef CON_TARGET 33 | cross: all 34 | cd lib && ${MAKE} ${MFLAGS} cross 35 | cd compiler && ${MAKE} ${MFLAGS} cross 36 | 37 | cross-clean: 38 | cd lib && ${MAKE} ${MFLAGS} cross-clean 39 | cd compiler && ${MAKE} ${MFLAGS} cross-clean 40 | endif 41 | 42 | distclean: 43 | cd bootstrap && ${MAKE} ${MFLAGS} distclean 44 | cd vm && ${MAKE} ${MFLAGS} distclean 45 | cd lib && ${MAKE} ${MFLAGS} distclean 46 | cd compiler && ${MAKE} ${MFLAGS} distclean 47 | cd examples && ${MAKE} ${MFLAGS} distclean 48 | cd docs && ${MAKE} ${MFLAGS} distclean 49 | cd tests && ${MAKE} ${MFLAGS} distclean 50 | rm -rf Makefile Makefile.inc 51 | 52 | regress: all 53 | cd examples && ${MAKE} ${MFLAGS} regress 54 | cd tests && ${MAKE} ${MFLAGS} regress 55 | 56 | release: distclean 57 | mkdir converge-@CONVERGE_VERSION@ 58 | find . -type d | grep -v "\.git" | grep -v "^\.$$" | sed "s/^\..//" | grep -v "converge-@CONVERGE_VERSION@" | xargs -I {} mkdir -p converge-@CONVERGE_VERSION@/{} 59 | find . \! -type d | grep -v "\.git" | sed "s/^\..//" | grep -v "^autom4te.cache" | grep -v "config\..*" | grep -v "\.binaries" | grep -v "\.gitignore" | grep -v "\.core$$" | grep -v ".depend$$" | grep -v "converge-@CONVERGE_VERSION@" | xargs -I {} cp -r {} converge-@CONVERGE_VERSION@/{} 60 | tar cfz converge-@CONVERGE_VERSION@.tar.gz converge-@CONVERGE_VERSION@ 61 | @echo "\nMake sure that this distribution has the correct version and date!\n @CONVERGE_VERSION@ (@CONVERGE_DATE@)" 62 | 63 | 64 | include @abs_top_srcdir@/Makefile.inc 65 | -------------------------------------------------------------------------------- /Makefile.inc.in: -------------------------------------------------------------------------------- 1 | CONVERGE_DIR=@abs_top_srcdir@ 2 | 3 | CONVERGE_VM_DIR=${CONVERGE_DIR}/vm 4 | CONVERGE_VM=${CONVERGE_VM_DIR}/converge 5 | 6 | CONVERGE_COMPILER_DIR=${CONVERGE_DIR}/compiler 7 | CONVERGEC=${CONVERGE_COMPILER_DIR}/convergec 8 | CONVERGEL=${CONVERGE_COMPILER_DIR}/convergel 9 | CONVERGED=${CONVERGE_COMPILER_DIR}/converged 10 | CONVERGE_COMPILER_LIB=${CONVERGE_COMPILER_DIR}/libcompiler.cvl 11 | 12 | CONVERGE_LIB_DIR=${CONVERGE_DIR}/lib 13 | 14 | CONVERGE_STDLIB_DIR=${CONVERGE_LIB_DIR}/Stdlib 15 | CONVERGE_STDLIB=${CONVERGE_LIB_DIR}/Stdlib.cvl 16 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # Converge 2 | 3 | See the `docs/` directory for documentation, including installation instructions. 4 | -------------------------------------------------------------------------------- /bootstrap/32bit_little_endian/.gitignore: -------------------------------------------------------------------------------- 1 | *.bootstrap 2 | -------------------------------------------------------------------------------- /bootstrap/64bit_little_endian/.gitattributes: -------------------------------------------------------------------------------- 1 | *.bootstrap -crlf -diff -merge 2 | -------------------------------------------------------------------------------- /bootstrap/64bit_little_endian/convergec.bootstrap: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ltratt/converge/21027f148e4353321ec2377bee36f41b93f3c010/bootstrap/64bit_little_endian/convergec.bootstrap -------------------------------------------------------------------------------- /bootstrap/64bit_little_endian/convergel.bootstrap: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ltratt/converge/21027f148e4353321ec2377bee36f41b93f3c010/bootstrap/64bit_little_endian/convergel.bootstrap -------------------------------------------------------------------------------- /bootstrap/Makefile.in: -------------------------------------------------------------------------------- 1 | clean: 2 | 3 | distclean: 4 | rm -f Makefile convergec.bootstrap convergel.bootstrap 5 | -------------------------------------------------------------------------------- /compiler/.gitignore: -------------------------------------------------------------------------------- 1 | converge[cilp] 2 | -------------------------------------------------------------------------------- /compiler/Compiler/BC_Exec.cv: -------------------------------------------------------------------------------- 1 | // Copyright (c) 2003-2006 King's College London, created by Laurence Tratt 2 | // 3 | // Permission is hereby granted, free of charge, to any person obtaining a copy 4 | // of this software and associated documentation files (the "Software"), to 5 | // deal in the Software without restriction, including without limitation the 6 | // rights to use, copy, modify, merge, publish, distribute, sublicense, and/or 7 | // sell copies of the Software, and to permit persons to whom the Software is 8 | // furnished to do so, subject to the following conditions: 9 | // 10 | // The above copyright notice and this permission notice shall be included in 11 | // all copies or substantial portions of the Software. 12 | // 13 | // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 14 | // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 15 | // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 16 | // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 17 | // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING 18 | // FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS 19 | // IN THE SOFTWARE. 20 | 21 | 22 | // 23 | // This module handles executable files. It should be brought into line with the other BC_* modules. 24 | // 25 | 26 | 27 | import Array 28 | import BC_Mod 29 | 30 | 31 | 32 | 33 | EXEC_INIT_STR := "CONVEXEC" 34 | 35 | EXEC_BYTECODE_HEADER := 0 36 | EXEC_BYTECODE_FORMAT_VERSION := 2 37 | EXEC_BYTECODE_NUM_MODULES := 3 38 | EXEC_BYTECODE_MODULE_OFFSETS := 4 39 | 40 | 41 | 42 | 43 | func serialize(target, bc_mods): 44 | 45 | ser_mods := Array::Array.new(target.ARRAY_TYPE) 46 | ser_mods_offsets := [] 47 | for mod := bc_mods.iter(): 48 | ser_mods_offsets.append(ser_mods.len_bytes()) 49 | ser_mods.extend_from_string(mod.serialize()) 50 | 51 | bc := Array::Array.new(target.ARRAY_TYPE) 52 | bc.extend_from_string(EXEC_INIT_STR) 53 | bc.append(0) // Version 54 | bc.append(-1) // Number of modules 55 | bc[target.LIBRARY_BYTECODE_NUM_MODULES] := ser_mods_offsets.len() 56 | 57 | preamble_length := (bc.len() + ser_mods_offsets.len()) * target.WORDSIZE 58 | for mod_offset := ser_mods_offsets.iter(): 59 | bc.append(preamble_length + mod_offset) 60 | 61 | bc.extend(ser_mods) 62 | 63 | sh_header := "#! /usr/bin/env converge\n" 64 | ser := sh_header + "\n" * (target.align(sh_header.len()) - sh_header.len()) + bc.serialize() 65 | 66 | return ser 67 | 68 | 69 | 70 | func deserialize(target, exec_str): 71 | 72 | raise "XXX" 73 | exec_array := Array::Array.new(target.ARRAY_TYPE, exec_str) 74 | 75 | if exec_array[0 : EXEC_INIT_STR.len() / target.WORDSIZE].to_str() != EXEC_INIT_STR: 76 | raise "XXX" 77 | 78 | modules := [] 79 | for i := 0.iter_to(exec_array[EXEC_BYTECODE_NUM_MODULES]): 80 | module_offset := exec_array[EXEC_BYTECODE_MODULE_OFFSETS + i] / target.WORDSIZE 81 | to := module_offset + (exec_array[module_offset + target.MODULE_BYTECODE_SIZE] / target.WORDSIZE) 82 | module := BC_Mod::BC_Mod.new(target) 83 | module.deserialize_array(exec_array[module_offset : to]) 84 | modules.append([exec_str[module_offset * target.WORDSIZE : to * target.WORDSIZE], module]) 85 | assert module.serialize() == exec_str[module_offset * target.WORDSIZE : to * target.WORDSIZE] 86 | 87 | return modules 88 | 89 | 90 | 91 | // 92 | // Succeeds if bc appears to be a valid Converge executeable. 93 | // 94 | 95 | func is_bc_exec(bc): 96 | 97 | i := 0 98 | if bc.prefixed_by("#!"): 99 | i += bc.find_index("\n") 100 | while i < bc.len() & bc[i] == "\n": 101 | i += 1 102 | 103 | if bc.prefixed_by(EXEC_INIT_STR, i): 104 | return 1 105 | 106 | fail 107 | -------------------------------------------------------------------------------- /compiler/Compiler/BC_Lib.cv: -------------------------------------------------------------------------------- 1 | // Copyright (c) 2003-2006 King's College London, created by Laurence Tratt 2 | // 3 | // Permission is hereby granted, free of charge, to any person obtaining a copy 4 | // of this software and associated documentation files (the "Software"), to 5 | // deal in the Software without restriction, including without limitation the 6 | // rights to use, copy, modify, merge, publish, distribute, sublicense, and/or 7 | // sell copies of the Software, and to permit persons to whom the Software is 8 | // furnished to do so, subject to the following conditions: 9 | // 10 | // The above copyright notice and this permission notice shall be included in 11 | // all copies or substantial portions of the Software. 12 | // 13 | // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 14 | // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 15 | // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 16 | // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 17 | // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING 18 | // FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS 19 | // IN THE SOFTWARE. 20 | 21 | 22 | // 23 | // This module handles .cvl files. 24 | // 25 | 26 | 27 | import Array, File, Sys 28 | import BC_Mod, BC_Pkg 29 | 30 | 31 | 32 | 33 | // 34 | 35 | LIB_INIT_STR := "CONVLIBR" 36 | LIBRARY_VERSION := 0 37 | 38 | 39 | 40 | 41 | 42 | class BC_Lib: 43 | 44 | func init(self, target): 45 | 46 | self._target := target 47 | 48 | 49 | 50 | func deserialize(self, mod_str): 51 | 52 | library := Array::Array.new(self._target.ARRAY_TYPE, mod_str) 53 | 54 | main_pkg := null 55 | self._bc_mods_map := Dict{} 56 | for i := 0.iter_to(library[self._target.LIBRARY_BYTECODE_NUM_MODULES]): 57 | mod_offset := library[self._target.LIBRARY_BYTECODE_MODULE_OFFSETS + i] / self._target.WORDSIZE 58 | 59 | assert BC_Mod::MOD_INIT_STR.len() == BC_Pkg::PKG_INIT_STR.len() 60 | 61 | mod_header := mod_str[mod_offset * self._target.WORDSIZE : mod_offset * self._target.WORDSIZE + BC_Mod::MOD_INIT_STR.len()] 62 | 63 | ndif mod_header == BC_Mod::MOD_INIT_STR: 64 | to := mod_offset + library[mod_offset + self._target.MODULE_BYTECODE_SIZE] / self._target.WORDSIZE 65 | bc_mod := BC_Mod::BC_Mod.new(self._target) 66 | bc_mod.deserialize_str(mod_str[mod_offset * self._target.WORDSIZE : to * self._target.WORDSIZE]) 67 | elif mod_header == BC_Pkg::PKG_INIT_STR: 68 | to := mod_offset + library[mod_offset + self._target.PKG_BYTECODE_SIZE] / self._target.WORDSIZE 69 | bc_mod := BC_Pkg::BC_Pkg.new(self._target) 70 | bc_mod.deserialize_str(mod_str[mod_offset * self._target.WORDSIZE : to * self._target.WORDSIZE]) 71 | 72 | if main_pkg is null: 73 | main_pkg := bc_mod 74 | self._bc_mods_map[bc_mod.get_mod_id()] := bc_mod 75 | 76 | self._main_pkg := main_pkg 77 | 78 | 79 | 80 | func get_main_pkg(self): 81 | 82 | return self._main_pkg 83 | 84 | 85 | 86 | func find_mod_id(self, mod_id): 87 | 88 | return self._bc_mods_map.find(mod_id) 89 | 90 | 91 | 92 | func iter_bc_mods(self): 93 | 94 | for yield self._bc_mods_map.iter_vals() 95 | 96 | fail 97 | 98 | 99 | 100 | func serialize(self): 101 | 102 | library := Array::Array.new(self._target.ARRAY_TYPE) 103 | library.extend_from_string(LIB_INIT_STR) 104 | library.append(LIBRARY_VERSION) 105 | 106 | library.append(self.modules.len()) 107 | library.append(-1) // Offset to modules offsets 108 | 109 | library[self._target.LIBRARY_BYTECODE_MODULE_OFFSETS] := library.len_bytes() 110 | 111 | serialized_modules := Array::Array.new(self._target.ARRAY_TYPE) 112 | for module := self.modules.iter(): 113 | library.append(library.len_bytes() + serialized_modules.len_bytes()) 114 | serialized_modules.extend_from_string(module.serialize()) 115 | 116 | library.extend(serialized_modules) 117 | 118 | return library 119 | 120 | 121 | 122 | 123 | // 124 | // Succeeds if bc appears to be a valid Converge bytecode package. 125 | // 126 | 127 | func is_bc_lib(bc): 128 | 129 | if bc.prefixed_by(LIB_INIT_STR): 130 | return 1 131 | 132 | fail 133 | -------------------------------------------------------------------------------- /compiler/Compiler/Lift.cv: -------------------------------------------------------------------------------- 1 | // Copyright (c) 2007 Laurence Tratt 2 | // 3 | // Permission is hereby granted, free of charge, to any person obtaining a copy 4 | // of this software and associated documentation files (the "Software"), to 5 | // deal in the Software without restriction, including without limitation the 6 | // rights to use, copy, modify, merge, publish, distribute, sublicense, and/or 7 | // sell copies of the Software, and to permit persons to whom the Software is 8 | // furnished to do so, subject to the following conditions: 9 | // 10 | // The above copyright notice and this permission notice shall be included in 11 | // all copies or substantial portions of the Software. 12 | // 13 | // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 14 | // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 15 | // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 16 | // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 17 | // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING 18 | // FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS 19 | // IN THE SOFTWARE. 20 | 21 | 22 | // 23 | // This module contains code for 'lifting' normal Converge values into their AST equivalents. 24 | // Ultimately this should probably provide some sort of interface to allow non-builtin objects to be 25 | // lifted. 26 | // 27 | 28 | 29 | import Builtins, Exceptions, Strings, Thread 30 | import ITree 31 | 32 | 33 | 34 | 35 | func lift(obj, src_infos := null): 36 | 37 | if src_infos is null: 38 | src_infos := Thread::get_continuation_src_infos(2) 39 | else: 40 | src_infos += Thread::get_continuation_src_infos(2) 41 | 42 | if Builtins::String.instantiated(obj): 43 | return ITree::IString.new(obj, src_infos) 44 | elif Builtins::Int.instantiated(obj): 45 | return ITree::IInt.new(obj, src_infos) 46 | elif Builtins::List.instantiated(obj): 47 | elems := [] 48 | for e := obj.iter(): 49 | elems.append(lift(e, src_infos)) 50 | return ITree::IList.new(elems, src_infos) 51 | elif Builtins::Set.instantiated(obj): 52 | elems := [] 53 | for e := obj.iter(): 54 | elems.append(lift(e, src_infos)) 55 | return ITree::ISet.new(elems, src_infos) 56 | elif Builtins::Dict.instantiated(obj): 57 | elems := [] 58 | for key, val := obj.iter(): 59 | ikey := lift(key, src_infos) 60 | ival := lift(val, src_infos) 61 | dict_elem := ITree::IDict_Elem.new(ikey, ival, src_infos) 62 | elems.append(dict_elem) 63 | return ITree::IDict.new(elems, src_infos) 64 | else: 65 | raise Exceptions::Exception.new(Strings::format("Don't know how to lift instance of '%s': '%s'.", obj.instance_of.name, obj.to_str())) 66 | -------------------------------------------------------------------------------- /compiler/Compiler/Targets/Available.cv: -------------------------------------------------------------------------------- 1 | // Copyright (c) 2003-2006 King's College London, created by Laurence Tratt 2 | // 3 | // Permission is hereby granted, free of charge, to any person obtaining a copy 4 | // of this software and associated documentation files (the "Software"), to 5 | // deal in the Software without restriction, including without limitation the 6 | // rights to use, copy, modify, merge, publish, distribute, sublicense, and/or 7 | // sell copies of the Software, and to permit persons to whom the Software is 8 | // furnished to do so, subject to the following conditions: 9 | // 10 | // The above copyright notice and this permission notice shall be included in 11 | // all copies or substantial portions of the Software. 12 | // 13 | // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 14 | // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 15 | // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 16 | // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 17 | // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING 18 | // FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS 19 | // IN THE SOFTWARE. 20 | 21 | // 22 | // This file contains a dictionary of available targets. On some platforms it may not be possible to 23 | // use certain targets, hence this list. 24 | // 25 | 26 | import Thirty_Two_Bit, Sixty_Four_Bit 27 | 28 | 29 | 30 | 31 | TARGETS := Dict{"32bit" : Thirty_Two_Bit::Target, "64bit" : Sixty_Four_Bit::Target} 32 | -------------------------------------------------------------------------------- /compiler/Makefile.in: -------------------------------------------------------------------------------- 1 | include @abs_top_srcdir@/Makefile.inc 2 | 3 | bindir = @bindir@ 4 | libdir = @libdir@ 5 | conlibdir = ${libdir}/converge-@CONVERGE_VERSION@ 6 | INSTALL = @INSTALL@ 7 | 8 | OBJS = Compiler.cvb Compiler/Parser.cvb Compiler/Tokenizer.cvb Compiler/IMod_Gen.cvb \ 9 | Compiler/ITree.cvb Compiler/Code_Gen.cvb Compiler/Targets/Thirty_Two_Bit.cvb \ 10 | Compiler/Core.cvb Compiler/BC_Mod.cvb Compiler/QQ_Mode.cvb Compiler/ITree_PP.cvb \ 11 | Compiler/ITree_WF.cvb Compiler/BC_Lib.cvb Compiler/BC_Exec.cvb Compiler/Eval.cvb \ 12 | Compiler/Lift.cvb Compiler/Link.cvb Compiler/ITree_Rename.cvb Compiler/BC_Pkg.cvb \ 13 | Compiler/Targets.cvb Compiler/Targets/Sixty_Four_Bit.cvb Compiler/Targets/Available.cvb \ 14 | Compiler/Instrs_Opt.cvb convergec.cvb convergei.cvb convergel.cvb convergep.cvb 15 | 16 | 17 | %.cvb: %.cv 18 | ${CONVERGE_VM} ${CONVERGEC} -I ${CONVERGE_STDLIB_DIR} -o $@ $< 19 | 20 | %.cvb: % 21 | ${CONVERGE_VM} ${CONVERGEC} -o $@ $< 22 | 23 | 24 | all: Compiler.cvl convergec convergei convergel convergep 25 | 26 | minimal: Compiler.cvl convergec convergel 27 | 28 | install: all 29 | ${INSTALL} -d ${DESTDIR}${bindir} 30 | ${INSTALL} -c -m 555 convergec ${DESTDIR}${bindir} 31 | ${INSTALL} -c -m 555 convergei ${DESTDIR}${bindir} 32 | ${INSTALL} -c -m 555 convergel ${DESTDIR}${bindir} 33 | ${INSTALL} -c -m 555 convergep ${DESTDIR}${bindir} 34 | ifeq (@PLATFORM@, MinGW) 35 | ${INSTALL} -c -m 555 ../platform/MinGW/convergec.bat ${DESTDIR}${bindir} 36 | ${INSTALL} -c -m 555 ../platform/MinGW/convergei.bat ${DESTDIR}${bindir} 37 | ${INSTALL} -c -m 555 ../platform/MinGW/convergel.bat ${DESTDIR}${bindir} 38 | ${INSTALL} -c -m 555 ../platform/MinGW/convergep.bat ${DESTDIR}${bindir} 39 | endif 40 | ${INSTALL} -d ${DESTDIR}${conlibdir} 41 | ${INSTALL} -c -m 444 Compiler.cvl ${DESTDIR}${conlibdir} 42 | 43 | 44 | ifdef CON_TARGET 45 | CROSS_OBJS = ${OBJS:.cvb=.${CON_TARGET}.cvb} 46 | 47 | %.${CON_TARGET}.cvb: %.cv 48 | ${CONVERGE_VM} ${CONVERGEC} -T ${CON_TARGET} -I ${CONVERGE_STDLIB_DIR} -o $@ $< 49 | 50 | %.${CON_TARGET}.cvb: % 51 | ${CONVERGE_VM} ${CONVERGEC} -T ${CON_TARGET} -o $@ $< 52 | 53 | cross: ${CROSS_OBJS} ${CONVERGE_LIB_DIR}/Stdlib.${CON_TARGET}.cvl 54 | ${CONVERGE_VM} ${CONVERGEL} -T ${CON_TARGET} -o convergec.${CON_TARGET} convergec.${CON_TARGET}.cvb ${CROSS_OBJS} ${CONVERGE_LIB_DIR}/Stdlib.${CON_TARGET}.cvl 55 | ${CONVERGE_VM} ${CONVERGEL} -T ${CON_TARGET} -o convergel.${CON_TARGET} convergel.${CON_TARGET}.cvb ${CROSS_OBJS} ${CONVERGE_LIB_DIR}/Stdlib.${CON_TARGET}.cvl 56 | 57 | cross-clean: 58 | rm -f ${CROSS_OBJS} convergec.${CON_TARGET} convergel.${CON_TARGET} 59 | endif 60 | 61 | 62 | ifeq ($(MAKECMDGOALS),minimal) 63 | # In minimal mode, Stdlib.cvl won't have been created, so we need to manually pass .cvb files to 64 | # convergel. Bootstrapping is such great fun. 65 | STDLIB_OBJS=`find ../lib/ -name "*.cvb"` 66 | endif 67 | 68 | Compiler.cvl: ${OBJS} 69 | ${CONVERGE_VM} ${CONVERGEL} -l -o Compiler.cvl Compiler.cvb ${OBJS} 70 | 71 | convergec: ${OBJS} 72 | ${CONVERGE_VM} ${CONVERGEL} -o convergec convergec.cvb ${OBJS} ${STDLIB_OBJS} 73 | 74 | convergei: ${OBJS} 75 | ${CONVERGE_VM} ${CONVERGEL} -o convergei convergei.cvb ${OBJS} 76 | 77 | convergel: ${OBJS} 78 | ${CONVERGE_VM} ${CONVERGEL} -o convergel convergel.cvb ${OBJ_FILES} ${STDLIB_OBJS} 79 | 80 | convergep: ${OBJS} 81 | ${CONVERGE_VM} ${CONVERGEL} -o convergep convergep.cvb ${OBJ_FILES} 82 | 83 | clean: 84 | rm -f Compiler.cvl ${OBJS} converge[cilp].cvb 85 | 86 | distclean: clean 87 | rm -f Makefile convergec convergei convergel convergep 88 | -------------------------------------------------------------------------------- /compiler/convergei.cv: -------------------------------------------------------------------------------- 1 | // Copyright (c) 2007 King's College London, created by Laurence Tratt 2 | // 3 | // Permission is hereby granted, free of charge, to any person obtaining a copy 4 | // of this software and associated documentation files (the "Software"), to 5 | // deal in the Software without restriction, including without limitation the 6 | // rights to use, copy, modify, merge, publish, distribute, sublicense, and/or 7 | // sell copies of the Software, and to permit persons to whom the Software is 8 | // furnished to do so, subject to the following conditions: 9 | // 10 | // The above copyright notice and this permission notice shall be included in 11 | // all copies or substantial portions of the Software. 12 | // 13 | // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 14 | // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 15 | // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 16 | // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 17 | // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING 18 | // FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS 19 | // IN THE SOFTWARE. 20 | 21 | 22 | import Backtrace, File, Exceptions, Strings, Sys 23 | import Compiler::Core, Compiler::Eval 24 | 25 | 26 | 27 | 28 | 29 | // 30 | // We use this "dummy" exception to signify to the interactive compiler that an error condition has 31 | // occurred, but we don't want to print out a backtrace. This is a nice hack. 32 | // 33 | 34 | class _Dummy_Exception(Exceptions::Exception): 35 | pass 36 | 37 | 38 | 39 | 40 | class _Interactive_Compiler(Eval::Eval_Compiler): 41 | 42 | func error(self, msg, src_infos := null): 43 | 44 | self._print_msg("Error", msg, src_infos) 45 | 46 | raise _Dummy_Exception.new() 47 | 48 | 49 | 50 | func warning(self, msg, src_infos := null): 51 | 52 | self._print_msg("Warning", msg, src_infos) 53 | 54 | 55 | 56 | func _print_msg(self, pre_msg, msg, src_infos := null): 57 | 58 | Sys::stderr.writeln(Strings::format("%s: %s", pre_msg, msg)) 59 | Sys::stderr.flush() 60 | 61 | 62 | 63 | 64 | func main(): 65 | 66 | includes := [File::canon_path(".")] 67 | 68 | Sys::println("Converge ", Sys::version, " (", Sys::version_date, ")") 69 | d := Dict{} 70 | while 1: 71 | Sys::print(">>> ") 72 | input := [] 73 | while 1: 74 | Sys::stderr.flush() 75 | Sys::stdout.flush() 76 | if not (line := Sys::stdin.readln()): 77 | Sys::exit(0) 78 | 79 | input.append(line) 80 | st_line := line.stripped() 81 | 82 | if st_line == "": 83 | break 84 | 85 | if input.len() == 1 & not (st_line[-1] == ":" | st_line[-1] == "\\"): 86 | break 87 | 88 | Sys::print("... ") 89 | 90 | input := Strings::join(input, "\n") 91 | if input.stripped() == "": 92 | continue 93 | 94 | try: 95 | compiler := _Interactive_Compiler.new() 96 | Core::push_compiler(compiler) 97 | if rtn := compiler.eval_str(input, d, includes): 98 | Sys::println(rtn) 99 | Core::pop_compiler() 100 | catch _Dummy_Exception into e: 101 | pass 102 | catch Exceptions::System_Exit_Exception into e: 103 | Sys::exit(e.code) 104 | catch Exceptions::Exception into e: 105 | Backtrace::print_best(e) 106 | -------------------------------------------------------------------------------- /compiler/convergep.cv: -------------------------------------------------------------------------------- 1 | // Copyright (c) 2003-2006 King's College London, created by Laurence Tratt 2 | // 3 | // Permission is hereby granted, free of charge, to any person obtaining a copy 4 | // of this software and associated documentation files (the "Software"), to 5 | // deal in the Software without restriction, including without limitation the 6 | // rights to use, copy, modify, merge, publish, distribute, sublicense, and/or 7 | // sell copies of the Software, and to permit persons to whom the Software is 8 | // furnished to do so, subject to the following conditions: 9 | // 10 | // The above copyright notice and this permission notice shall be included in 11 | // all copies or substantial portions of the Software. 12 | // 13 | // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 14 | // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 15 | // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 16 | // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 17 | // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING 18 | // FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS 19 | // IN THE SOFTWARE. 20 | 21 | 22 | import File, Strings, Sys 23 | import CPK::Earley::Grammar, CPK::Tree 24 | import Compiler::Core, Compiler::Parser, Compiler::Tokenizer 25 | 26 | 27 | 28 | class Parser_Compiler: 29 | 30 | func init(self, path): 31 | 32 | file := File::File.new(path, "r") 33 | 34 | Core::push_compiler(self) 35 | 36 | self.tokenizer := Tokenizer::Tokenizer.new() 37 | self.tokenizer.tokenize(file.read(), [[path, 0]], [], []) 38 | tokens_map := Tokenizer::tokens_map([], []) 39 | grammar, rule_names := Grammar::compile(Parser::GRAMMAR, "top_level", tokens_map) 40 | 41 | parse_tree := Parser::Parser.new().parse(grammar, rule_names, tokens_map, self.tokenizer.tokens) 42 | 43 | Core::pop_compiler() 44 | 45 | Sys::println(Tree::pp_tree(parse_tree)) 46 | 47 | 48 | 49 | func error(self, msg, src_infos := null): 50 | 51 | self._print_msg("Error", msg, src_infos) 52 | Sys::exit(1) 53 | 54 | 55 | 56 | func warning(self, msg, src_infos := null): 57 | 58 | self._print_msg("Warning", msg, src_infos) 59 | 60 | 61 | 62 | func _print_msg(self, pre_msg, msg, src_infos := null): 63 | 64 | if not src_infos is null: 65 | assert src_infos.len() > 0 66 | 67 | Sys::stderr.write(Strings::format("%s: ", pre_msg)) 68 | 69 | for src_info := src_infos.iter(): 70 | src_offset := src_info[1] 71 | newlines := self.tokenizer.newlines 72 | line := 0 73 | while line < newlines.len(): 74 | if src_offset < newlines[line]: 75 | break 76 | line += 1 77 | col := src_offset - newlines[line - 1] 78 | 79 | Sys::stderr.write(Strings::format("Line %d, column %d: ", line, col)) 80 | 81 | Sys::stderr.writeln(msg) 82 | else: 83 | Sys::stderr.writeln(Strings::format("%s: %s", pre_msg, msg)) 84 | 85 | 86 | 87 | func main(): 88 | 89 | for path := Sys::argv.iter(): 90 | Parser_Compiler.new(path) 91 | -------------------------------------------------------------------------------- /docs/.gitignore: -------------------------------------------------------------------------------- 1 | cvd_to_html 2 | -------------------------------------------------------------------------------- /docs/CHANGES: -------------------------------------------------------------------------------- 1 | ================================================================================ 2 | Converge changes file 3 | ================================================================================ 4 | 5 | 2014-02-25 Converge 2.1 6 | 7 | This is a minor bugfix release that fixes portability issues. It also 8 | synchronises the VM with RPython 2.2.1, allowing Converge to build on recent 9 | RPython releases. This therefore brings advantages such as incremental 10 | garbage collection. 11 | 12 | 13 | 2012-07-31 Converge 2.0 14 | 15 | This release contains a new VM written in RPython. Depending on your program 16 | and the length of time it runs, this will lead to a 2x-100x speedup. Programs 17 | should run as before, but will need to be recompiled (the easiest way of 18 | doing this is, on the first run of a program on Converge 2.0 to use the "-f" 19 | switch which forces a recompile). 20 | 21 | 22 | 2011-05-29 Converge 1.2 23 | 24 | This release contains many portability fixes and optimisations. Converge should 25 | now run with full optimisations on all major platforms. 26 | 27 | There are also several compile-time meta-programming fixes, documentation 28 | enhancments, and additional functions (e.g. File::temp_file). 29 | 30 | 31 | 2009-09-08 Converge 1.1 32 | 33 | This release contains many minor fixes and enhancements. Major changes include: 34 | 35 | * Src infos are now triples (src file, src offset, len) meaning that error 36 | reporting is now much more detailed. 37 | 38 | * Parse trees have now changed representation from lists to instances of 39 | specific classes. Parse tree walking code needs to be updated accordingly. 40 | 41 | * Simple dynamic linking of core libraries. 42 | 43 | * Much enhanced backtraces (when curses is available). 44 | 45 | 46 | 47 | 2008-02-25 Converge 1.0 48 | 49 | Initial public release of the 1.0 series. 50 | -------------------------------------------------------------------------------- /docs/CREDITS: -------------------------------------------------------------------------------- 1 | Converge owes thanks to the following (in alphabetic order): 2 | 3 | Alexandre Bergel 4 | Martin Berger 5 | Carl Friedrich Bolz 6 | Armin Rigo 7 | Laurence Tratt 8 | Naveneetha Vasudevan -------------------------------------------------------------------------------- /docs/Makefile.in: -------------------------------------------------------------------------------- 1 | include @abs_top_srcdir@/Makefile.inc 2 | 3 | prefix = @prefix@ 4 | bindir = @bindir@ 5 | datadir = @datadir@ 6 | condocsdir = ${datadir}/doc/converge-@CONVERGE_VERSION@ 7 | INSTALL = @INSTALL@ 8 | 9 | 10 | MANUALS = modules_cvd/Array.cvd modules_cvd/Builtins.cvd modules_cvd/CEI.cvd \ 11 | modules_cvd/CPK.Earley.DSL.cvd modules_cvd/Exceptions.cvd modules_cvd/File.cvd \ 12 | modules_cvd/Functional.cvd modules_cvd/Maths.cvd modules_cvd/PCRE.cvd \ 13 | modules_cvd/Platform.Env.cvd modules_cvd/Platform.Properties.cvd modules_cvd/Platform.Exec.cvd \ 14 | modules_cvd/Platform.Host.cvd modules_cvd/Random.cvd modules_cvd/Sort.cvd modules_cvd/Sys.cvd \ 15 | modules_cvd/Strings.cvd modules_cvd/Time.cvd modules_cvd/VM.cvd modules_cvd/XML.Nodes.cvd \ 16 | modules_cvd/XML.XDM.cvd modules_cvd/XML.XHTML.cvd 17 | 18 | 19 | %.cvb: %.cv 20 | ${CONVERGE_VM} ${CONVERGEC} -o $@ $< 21 | 22 | 23 | all: cvd_to_html 24 | ${CONVERGE_VM} cvd_to_html -o modules_html ${subst /,@DIR_SEP@,${MANUALS}} 25 | 26 | install: all 27 | ${INSTALL} -d ${DESTDIR}${bindir} 28 | ${INSTALL} -c -m 555 cvd_to_html ${DESTDIR}${bindir} 29 | ifeq (@PLATFORM@, MinGW) 30 | ${INSTALL} -c -m 555 ../platform/MinGW/cvd_to_html.bat ${DESTDIR}${bindir} 31 | endif 32 | ${INSTALL} -d ${DESTDIR}${condocsdir} 33 | ${INSTALL} -c -m 444 index.html header.inc footer.inc ${DESTDIR}${condocsdir} 34 | ${INSTALL} -d ${DESTDIR}${condocsdir}/ctmp 35 | ${INSTALL} -c -m 444 ctmp/*.html ${DESTDIR}${condocsdir}/ctmp 36 | ${INSTALL} -d ${DESTDIR}${condocsdir}/modules_html 37 | ${INSTALL} -c -m 444 modules_html/*.html ${DESTDIR}${condocsdir}/modules_html 38 | ${INSTALL} -d ${DESTDIR}${condocsdir}/quick_intro 39 | ${INSTALL} -c -m 444 quick_intro/*.html ${DESTDIR}${condocsdir}/quick_intro 40 | ${INSTALL} -d ${DESTDIR}${condocsdir}/tools 41 | ${INSTALL} -c -m 444 tools/*.html ${DESTDIR}${condocsdir}/tools 42 | 43 | cvd_to_html: cvd_to_html.cvb ${CONVERGE_LIB} 44 | ${CONVERGE_VM} ${CONVERGEL} -o cvd_to_html cvd_to_html.cvb 45 | 46 | clean: 47 | rm -f cvd_to_html cvd_to_html.cvb modules_html/*.html 48 | 49 | distclean: clean 50 | rm -f Makefile 51 | -------------------------------------------------------------------------------- /docs/README: -------------------------------------------------------------------------------- 1 | ================================================================================ 2 | Converge documentation 3 | ================================================================================ 4 | 5 | 6 | First time users 7 | ================== 8 | 9 | If you are new to Converge and want to work out how to install it, check 10 | install/INSTALL and then (if necessary) install/README.X where "X" is your 11 | platform. You may then wish to read quick_intro/index.html for a whistle-top 12 | tour of the language's major features. 13 | 14 | 15 | 16 | Detailed information 17 | ====================== 18 | 19 | If you wish to find out about all the documenation that comes with Converge, 20 | herewith a brief description of the various documentation: 21 | 22 | CHANGES A description of the major changes between versions 23 | 24 | CREDITS A list of people 25 | 26 | ctmp/ 27 | index.html A detailed explanation of compile-time meta-progamming in 28 | Converge. This is, in a sense, a detailed addendum to the 29 | "quick intro". 30 | 31 | install/ 32 | INSTALL General installation instructions 33 | README.X Specific instructions for platform X 34 | 35 | modules_html/ 36 | index.html Links to documentation on all parts of Converge's standard 37 | libraries. Note this documentation is built from the XML 38 | in the "modules_cvd" directory; modules_html is thus not 39 | populated until the whole Converge system is built. 40 | 41 | quick_intro/ 42 | index.html An overview of Converge's major language features. 43 | 44 | tools/ 45 | index.html Detailed explanations of the various tools (convergec, 46 | convergei, convergep, cvd_to_html) that come with 47 | Converge. 48 | -------------------------------------------------------------------------------- /docs/footer.inc: -------------------------------------------------------------------------------- 1 | 2 | 3 | -------------------------------------------------------------------------------- /docs/header.inc: -------------------------------------------------------------------------------- 1 | 2 | Converge 3 | 4 | -------------------------------------------------------------------------------- /docs/index.html: -------------------------------------------------------------------------------- 1 | 2 | 3 |

Converge documentation

4 | 5 | 11 | 12 | -------------------------------------------------------------------------------- /docs/install/INSTALL: -------------------------------------------------------------------------------- 1 | To build Converge you need at a minimum PyPy's source. It is recommended you 2 | use at least PyPy 7.2.0, available from . 3 | You do not need to install PyPy, but Converge needs access to its source in 4 | order to build itself. The PYPY_SRC variable should point at the root of the 5 | PyPy source distribution. 6 | 7 | The easiest way of obtaining PyPy's source is to check PyPy out from its 8 | Mercurial repository: 9 | 10 | $ cd 11 | $ hg clone https://foss.heptapod.net/pypy/pypy 12 | $ export PYPY_SRC=/pypy 13 | 14 | Once you have obtained PyPy and set the PYPY_SRC variable appropriately then, 15 | subject to platform specific notes in README., one can normally 16 | build Converge by executing the following commands: 17 | 18 | $ ./configure 19 | $ make 20 | 21 | If you wish to run Converge's regression suite: 22 | 23 | $ make regress 24 | 25 | ================================================================================ 26 | 27 | Building from a git checkout 28 | 29 | Converge only keeps a bootstrap compiler for 64-bit machines in version control. 30 | If you are running another type of machine, you will need to download a recent 31 | snapshot and extract the appropriate bootstrap compiler and linker. e.g.: 32 | 33 | cp /bootstrap//convergec.bootstrap bootstrap/ 34 | cp /bootstrap//convergel.bootstrap bootstrap/ 35 | 36 | You then follow the normal build instructions as above. After doing so, it is 37 | then recommended that you rebuild once more to check that the newly compiled 38 | compiler functions correctly: 39 | 40 | make clean 41 | make 42 | 43 | After this you're done - please feel free to contribute patches! 44 | -------------------------------------------------------------------------------- /docs/install/README.BSD: -------------------------------------------------------------------------------- 1 | Because of the unfortunate incompatibilities between different makes, Converge 2 | is forced to use GNU make idioms in its makefiles. On BSD one thus has to 3 | substitute the "gmake" command for "make" 4 | -------------------------------------------------------------------------------- /docs/install/README.Cygwin: -------------------------------------------------------------------------------- 1 | To compile Converge in a standard Cygwin installation you will need to 2 | install at least the pcre, pcre-devel, libxml2, libxml2-devel, and gmake 3 | packages. 4 | 5 | You may find that compiling Converge under the normal Cygwin prompt causes a 6 | stack exception error to be raised. In such a case, try executing "startx" 7 | and compiling Converge under the xterm that opens. This seems to fix the 8 | problem - if anyone understands why, please get in touch. 9 | -------------------------------------------------------------------------------- /docs/install/README.MacOSX: -------------------------------------------------------------------------------- 1 | Building Converge on Mac OS X follows a typical "unixish" approach that users unfamiliar with unix may find confusing. The following steps should make the installation process simple: 2 | 3 | 1 - Let's assume that the Converge source has been decompressed into a folder named 'Converge' located on the desktop. 4 | 5 | 6 | 2 - Converge relies on two external libraries: PCRE (Perl Compatible Regular Expressions) and libxml2. PCRE is typically not found on Mac OS X systems, while libxml2 may be partially installed. In both cases full version need to be manually installed. Download the PCRE source code from http://pcre.org/ and decompress it into the Converge folder. Open a terminal (a.k.a xterm), go to the pcre-X.Y folder (where X.Y is the PCRE version number) and execute the following command: 7 | 8 | $ ./configure --prefix=$HOME/Desktop/Converge 9 | 10 | This invocation will build the Makefile needed to compile PCRE. It also says that it will have to be installed in the Converge folder. I am sure you do not not want to touch the Darwin filesystem :-) You can now invoke 'make' and then 'make install': 11 | 12 | $ make 13 | gcc -DHAVE_CONFIG_H -I. -O2 -MT pcre_compile.lo -MD -MP -MF .deps/pcre_compile.Tpo -c pcre_compile.c -o pcre_compile.o >/dev/null 2>&1 14 | mv -f .deps/pcre_compile.Tpo .deps/pcre_compile.Plo 15 | /bin/sh ./libtool --tag=CC 16 | ........ 17 | gcc -O2 -o .libs/pcredemo pcredemo.o ./.libs/libpcre.dylib 18 | creating pcredemo 19 | $ make install 20 | 21 | New folders titled 'bin', 'include' will have been created, and populated, in the Converge folder. 22 | 23 | 24 | 3 - Perform the same sequence of operations (with the same commands) for libxml2. 25 | 26 | 27 | 4 - The path has to be adjusted. The new 'bin' folder has to be included in the shell variable PATH. Simply execute: 28 | 29 | $ export PATH=$HOME/Desktop/Converge/bin/:$PATH 30 | 31 | Note that since we want to ensure that our versions of PCRE and libxml2 are picked up, rather than other versions that may have been previously installed we put the 'bin' folder at the beginning of $PATH. This command will only effect your current terminal, and its effects will be lost when you close the terminal. 32 | 33 | 34 | 5 - Converge can now be compiled. Following the instructions in the INSTALL file. 35 | 36 | 6 - If you now type 'converge' in your Terminal, you should see be taken to the interactive prompt: 37 | 38 | $ converge 39 | Converge current 40 | >>> 41 | 42 | The prompt can be exited from with Ctrl-D. You're done! Converge is installed! 43 | 44 | 45 | Originally written by: Alexandre Bergel, July 3, 2007 46 | 47 | Hardware used during the writing of this file: 48 | Mac book, OSX version 10.4.9. Processor 1.83GHz Intel Core 2 Duo. 49 | 1GB 667 MHz DDR2 SDRAM 50 | 51 | -------------------------------------------------------------------------------- /docs/install/README.MinGW: -------------------------------------------------------------------------------- 1 | MinGW is how Converge produces native Windows binaries. You will almost 2 | certainly need to install extra MinGW packages to get everthying up and 3 | running. 4 | 5 | The easiest way to compile things is to run "sh.exe" in MinGW/bin. You will 6 | first need to manually compile MinGW versions of PCRE and libXML2. I put 7 | these into C:\pcre and C:\libXML2 respectively. 8 | 9 | You may find that you need to alter your path for the configure script to 10 | execute correctly. The following works for me: 11 | 12 | "C:/MinGW/bin/sh.exe"-2.04$ export PATH=/c/MinGW/bin/:/c/pcre/bin/:/c/libxml2/bin/:$PATH 13 | 14 | Since the install script included with MinGW appears to be defective, you 15 | may need to specify an alternative via the INSTALL variable when running 16 | configure. A suitable alternative is included in the distribution, and can 17 | be used as follows: 18 | 19 | "C:/MinGW/bin/sh.exe"-2.04$ INSTALL=./install-sh ./configure 20 | -------------------------------------------------------------------------------- /docs/install/README.cross: -------------------------------------------------------------------------------- 1 | Cross-compiling for Converge means creating convergec and convergel binaries that 2 | can run on a target platform other than the one being used to create them. For 3 | example on a 64 bit system one can cross-compile to create 32 bit binaries by 4 | building the host Converge system as normal and then executing: 5 | 6 | make cross TARGET=32bit 7 | 8 | When this has finished the following two cross-compiled binaries will have been 9 | created: 10 | 11 | compiler/convergec.32bit 12 | compiler/convergel.32bit 13 | 14 | To clean the files created by cross-compilation one must execute: 15 | 16 | make cross-clean TARGET=32bit 17 | 18 | These files are not cleaned by the normal "make clean" target. 19 | 20 | Available targets are documented in compiler/Compiler/Targets/Available.cv. Note 21 | that some platforms are not capable of cross-compiling to other targets (e.g. 22 | currently the 32bit platform can not currently cross-compile the 64bit compiler). 23 | -------------------------------------------------------------------------------- /docs/modules_cvd/Array.cvd: -------------------------------------------------------------------------------- 1 | 2 | This module provides an efficient mechanism for storing and manipulating large numbers of primitive machine types. 3 | 4 | 5 | Array objects are created by calling the following function on the Array class object: 6 | 7 | 8 | 9 | null 10 | Creates an array of the type specified by type: 11 | 12 | 13 | 14 | 15 | 16 |
fArray of floats (size determined by architecture / OS).
iArray of integers (size determined by architecture / OS).
i32Array of 32-bit integers.
i64Array of 64-bit integers.
17 | If d is not null, it is taken to be a string representing the underlying data and which is added to the array via . 18 |
19 | 20 | Array objects support the following functions: 21 | 22 | 23 | 24 | Adds o to the end of the array. o must be of an appropriate type and value for this array. 25 | 26 | 27 | 28 | 29 | Appends each element returned by c.iter(). 30 | 31 | 32 | 33 | 34 | Extends this array with data from string which is assumed to be a raw representation of this arrays' data type. s.len() must be a multiple of this arrays' data type. 35 | 36 | 37 | 38 | 39 | Returns the element at position i, raising an exception if i is out of bounds. 40 | 41 | 42 | 43 | 0 44 | self.len() 45 | Returns a sub-array of the elements from position lower (inclusive) to upper (exclusive). An exception is raised if either index is out of bounds. 46 | 47 |
48 | 49 |
50 | -------------------------------------------------------------------------------- /docs/modules_cvd/CPK.Earley.DSL.cvd: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | This is a DSL implementation function for building parsers according to an Earlry grammar, where text is parsed according to the normal Converge tokenizer. Extra keywords and extra symbols that the tokenizer should recognise can be passed as lists of strings. start_rule specifies the top rule of the grammar. This function returns a quasi-quoted function which when spliced in takes two arguments dsl_block and src_infos and returns a parse tree of the DSL block. An example use is as follows: 8 |
 9 | parse := $<<DSL::mk_parser("rule", ["tok", "tok2"], [])>>:
10 |     rule ::= a ( b )*
11 |     a ::= "TOK"
12 |         |
13 |     b ::= "TOK2"
14 | 
15 | func my_dsl(dsl_block, src_infos)
16 |     parse_tree := parse(dsl_block, src_infos)
17 |     ...
18 | 
19 | $<<my_dsl>>:
20 |     ...
21 | 
22 |
23 | 24 |
25 | -------------------------------------------------------------------------------- /docs/modules_cvd/Exceptions.cvd: -------------------------------------------------------------------------------- 1 | 2 |

Main Exception classes

3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 |

User exceptions

12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | 27 | 28 | 29 | 30 | 31 | 32 | 33 | 34 | 35 | 36 | 37 | 38 | 39 | 40 | 41 |

Internal exceptions

42 | 43 | These are exceptions which should not ever be explicitly considered by users. They are either the result of an internal problem with the Converge VM, or relate to an internal implementation detail which may be subject to change. 44 | 45 | 46 | 47 | 48 | 49 | 50 | 51 | 52 |

Module functions

53 | 54 | 55 | 56 | Returns a string of the backtrace encoded in the exception e. e itself should be an exception that has been raised i.e. it does not make sense to represent a backtrace from an exception object unless it has actually been raised. 57 | 58 |
59 | -------------------------------------------------------------------------------- /docs/modules_cvd/Functional.cvd: -------------------------------------------------------------------------------- 1 | 2 | This module provides means for programming in a functional style. 3 | 4 | 5 | 6 | 7 | Create a new list with the results of successively applying func_ to each element in c. 8 | 9 | 10 | 11 | 12 | 13 | null 14 | Uses func_ to reduce c to a single value. func_ must take two arguments and return a single value. 15 | 16 | If initializer is null, first applies func_(c[0], c[1]) using the return value a to apply func_(a, c[2]) and so on. 17 | 18 | If initializer is not null, first applies func_(a, c[0]) using the return value a' to apply func_(a', c[1]) and so on. 19 | 20 | 21 | 22 | -------------------------------------------------------------------------------- /docs/modules_cvd/Maths.cvd: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | Returns the object with the highest value in objs. 5 | 6 | 7 | 8 | 9 | Returns the object with the lowest value in objs. 10 | 11 | 12 | -------------------------------------------------------------------------------- /docs/modules_cvd/PCRE.cvd: -------------------------------------------------------------------------------- 1 | 2 | 3 | This module provides regular expression functions. See the PCRE documentation for the syntax and options that PCRE provides. 4 | 5 |

Important functions and classes in the PCRE module are as follows:

6 | 7 | 8 | 9 | Compiles the string pattern and returns a regular expression object. 10 | 11 | 12 | 13 |

Regular expression objects

14 | 15 |

Regular expression objects have the following slots:

16 | 17 | 18 | 19 | 0 20 | Attempts to match the regular expression against string s. match anchors its match to a particular position i which defaults to 0. In other words, if the regular expression does not match at that position, it does not search through the string looking for another position to match at. 21 | 22 |

If the match succeeds, a match object is returned; otherwise the function fails.

23 |
24 | 25 | 26 | 27 | 0 28 | Successively generates all match objects where the regular expression matches against the string s. The search starts at position i, which defaults to 0. 29 | 30 |

For each successful search, a match object is generated; when no more matches are found, the function fails.

31 |
32 | 33 | 34 |

Match objects

35 | 36 |

Match objects have the following slots:

37 | 38 | 39 | 40 | Returns the slice of the string matched by the group numbered group_num. Groups are specified within a regular expression by use of parentheses, and are numbered starting from 1. There is an implicit group 0 which returns the entire string matched by the regular expression. 41 | 42 |

Note that this effect can also be achieved via the slice notation i.e. match.get(X) is equivalent to match[X].

43 |
44 | 45 | 46 | 47 | Returns the start and end indices as a list [start, end] of the string matched by the group numbered group_num. Groups are specified within a regular expression by use of parentheses, and are numbered starting from 1. There is an implicit group 0 which returns the start and end indices of the entire string matched by the regular expression. 48 | 49 |
50 | -------------------------------------------------------------------------------- /docs/modules_cvd/Platform.Env.cvd: -------------------------------------------------------------------------------- 1 | 2 | This module provides platform dependent functions to manipulate the environment. 3 | 4 | 5 | 6 | Returns the value of name in the environment, failing if name is not found. 7 | 8 | 9 | 10 | 11 | Returns the value of name in the environment, raising an exception if name is not found. 12 | 13 | 14 | 15 | 16 | 17 | Sets the value of name to val in the environment. 18 | 19 | 20 | -------------------------------------------------------------------------------- /docs/modules_cvd/Platform.Exec.cvd: -------------------------------------------------------------------------------- 1 | 2 | This module provides platform dependent functions for executing other programs. 3 | 4 | 5 | 6 | Passes cmd to the shell for execution, returning the exit code of the program. 7 | 8 | 9 | -------------------------------------------------------------------------------- /docs/modules_cvd/Platform.Host.cvd: -------------------------------------------------------------------------------- 1 | 2 | This module provides platform dependent functions about the host computer. Exactly what constitutes a host may be platform dependent. 3 | 4 | 5 | Returns the hostname of the current host. 6 | 7 | 8 | -------------------------------------------------------------------------------- /docs/modules_cvd/Platform.Properties.cvd: -------------------------------------------------------------------------------- 1 | 2 | This module provides information about the underlying platform (OS, architecture etc.) that Converge is running on. The following attributes are defined: 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | Set to 1 if the underlying platform generally uses case sensitive filenames, or 0 otherwise. Note that this does not guarantee that specific file systems will respect this setting. 12 | 13 | 14 | 15 | Currently set to either or as appropriate. 16 | 17 | 18 | 19 | The name of the operating system. 20 | 21 | 22 | 23 | Integer value of the number of bits in a machine word. 24 | 25 | 26 | -------------------------------------------------------------------------------- /docs/modules_cvd/Random.cvd: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | Successively generates random elements form c. 5 | 6 | 7 | 8 | Returns a random integer between 0 and the maximum integer size of the machine. 9 | 10 | 11 | 12 | 13 | Shuffles c's elements into a pseudo-random order. Note that since the number of permutations for most lists is larger than the period of most random number generators, many possible random permutations can never be generated using this function. 14 | 15 | 16 | -------------------------------------------------------------------------------- /docs/modules_cvd/Sort.cvd: -------------------------------------------------------------------------------- 1 | 2 | This module provides various sorting mechanisms. 3 | 4 | 5 | 6 | func (x, y) { return x < y } 7 | Sort list in place into the order determined by the comparison function using the quickest available sorting algorithm. Note that the sort is not guaranteed to be stable. 8 | 9 | 10 | 11 | 12 | func (x, y) { return x < y } 13 | Sort list in place into the order determined by the comparison function using the non-stable heapsort algorithm. 14 | 15 | 16 | 17 | -------------------------------------------------------------------------------- /docs/modules_cvd/Strings.cvd: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | Returns a string based on the format string format which is printf-esque in nature and consumes arguments from args. Valid specifiers are %s for strings and %d for numbers. 7 | 8 | 9 | 10 | 11 | 12 | Concatenates list into a string inserting separator between each item in list. 13 | 14 | 15 | 16 | 17 | 18 | Splits the string str at each instance of the string separator, returning a list of the split string. 19 | 20 | 21 | 22 | 23 | Returns the longest common prefix of the strings in strings. e.g. lcp(["aab", "aca", "a"]) will return "a" while lcp(["aab", "aca", "b"]) will return "". 24 | 25 | 26 | 27 | -------------------------------------------------------------------------------- /docs/modules_cvd/Sys.cvd: -------------------------------------------------------------------------------- 1 | 2 | This module defines a number of important values: 3 | 4 | 5 | A list containing the command line arguments passed to the Converge program. 6 | 7 | 8 | 9 | A string containing the path of the current program. NB: This may be set to null (e.g. if the program was loaded from memory), and if present may not be a fully canonicalized path. 10 | 11 | 12 | 13 | A object representing standard input. 14 | 15 | 16 | 17 | A object representing standard input. 18 | 19 | 20 | 21 | A string denoting the version of the Converge virtual machine. Versions can be of any format (e.g. 1.2, 1.1-beta, current). Thus one can not determine whether one version string represents a "newer" version than another; one can simply test whether two version strings denote different versions not. 22 | 23 | 24 | Important functions and classes in this module are as follows: 25 | 26 | 27 | 28 | Exits the program with exit code code which must be an integer. 29 | 30 |

More correctly this raises a System_Exit_Exception which is caught as a special case by the "outer" Converge program.

31 |
32 | 33 | 34 | 35 | Prints all arguments passed to it to standard out. Strings are printed as is; all other objects have their to_str function called. 36 | 37 | 38 | 39 | 40 | Prints all arguments passed to it to standard out, and then prints a trailing newline. Strings are printed as is; all other objects have their to_str function called. 41 | 42 |
43 | -------------------------------------------------------------------------------- /docs/modules_cvd/Time.cvd: -------------------------------------------------------------------------------- 1 | 2 |

Time objects

3 | 4 | 5 | Denotes a specific instant in time. 6 | 7 | 8 | 9 | 10 | Creates a new time instant sec seconds + nsec nanoseconds since the local epoch. 11 | 12 | 13 | 14 | 15 | Returns the current system time as an . This function returns conventional wall clock time. 16 | 17 | 18 | 19 | Returns the current system time as an . This function guarantees to always return a monotonically increasing value; it is useful for timing purposes, as it is not skewed to reflect the realities of the outside world. Note: not all platforms support this functionality (e.g. OS X), in which case the value returned will be the same as . 20 | 21 | 22 |
23 | -------------------------------------------------------------------------------- /docs/modules_cvd/VM.cvd: -------------------------------------------------------------------------------- 1 | 2 | Important functions and classes in this module are as follows: 3 | 4 | 5 | 6 | Adds or replaces modules in the running VM. mods should be a list of modules. Note that this function does not import modules: it merely adds them into the VM so that they can then be imported e.g. by . 7 | 8 | 9 | 10 | 11 | Returns the module with identifier mod_id if it exists in the VM, failing otherwise. 12 | 13 | 14 | 15 | 16 | Imports the module with identifier mod_id. Raises an exception if no such module is in the VM. 17 | 18 | 19 | -------------------------------------------------------------------------------- /docs/modules_cvd/XML.Nodes.cvd: -------------------------------------------------------------------------------- 1 | 2 | 3 | The XML tree defined in this file is loosely inspired by the XOM API. 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | -------------------------------------------------------------------------------- /docs/modules_cvd/XML.XDM.cvd: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | Parses the XML contained in the string s and returns a Nodes::Doc object. 6 | 7 | 8 | 9 | 10 | 11 | Escapes illegal characters in s, replacing them with the appropriate XML entities. 12 | 13 | 14 | 15 | -------------------------------------------------------------------------------- /docs/modules_html/.gitignore: -------------------------------------------------------------------------------- 1 | *.html 2 | -------------------------------------------------------------------------------- /docs/tools/convergei.html: -------------------------------------------------------------------------------- 1 | 2 | 3 |

Interactive Converge

4 | 5 | Converge can be run in an interactive loop via the convergei program. This is automatically invoked if the VM is started with no arguments. The ... characters denote the prompt, and other lines output from the interactive session. 6 | 7 |
 8 | $ converge
 9 | Converge current
10 | >>> 2 + 3    
11 | 5
12 | >>>
13 | 
14 | 15 | convergei can be exited either by typing Ctrl-D, or by importing the Sys module and calling Sys::exit(code) where code is a number such as 0. 16 | 17 |

After each expression, Converge prints out the return value of the expression if it succeeded, or prints nothing if it failed. 18 | 19 |

20 | >>> 18 > 7
21 | 7
22 | >>> 7 > 18
23 | >>>
24 | 
25 | 26 |

convergei is aware of Converge's syntax and can be used to define functions and other compound statements. When it detects a ":" or "\" at the end of a line, it goes into continuation mode (marked by the ... characters), which is terminated by a blank line: 27 | 28 |

29 | >>> func f(x):
30 | ...     y := x * 2
31 | ...     return y
32 | ... 
33 | <Object@0x4c3a5c10>
34 | >>> f(3)
35 | 6
36 | >>>
37 | 
38 | 39 | 40 | -------------------------------------------------------------------------------- /docs/tools/convergep.html: -------------------------------------------------------------------------------- 1 | 2 | 3 |

convergep

4 | 5 | convergep is a simple tool which reads in a Converge file and pretty-prints its parse tree. This can be useful when performing compile-time meta-programming to see the structure of an input file. An example execution is as follows: 6 | 7 |
 8 | $ convergep hello.cv
 9 | top_level
10 |   -> defn
11 |     -> import
12 |       -> 
13 |       -> import_name
14 |         -> 
15 |       -> import_as
16 |   -> 
17 |   -> defn
18 |     -> func_defn
19 |       -> func_type
20 |         -> 
21 |       -> func_name
22 |         -> 
23 |       -> <(>
24 |       -> func_params
25 |       -> <)>
26 |       -> <:>
27 |       -> 
28 |       -> func_decls
29 |       -> expr_body
30 |         -> expr
31 |           -> application
32 |             -> expr
33 |               -> module_lookup
34 |                 -> name
35 |                   -> 
36 |                 -> <::>
37 |                 -> name
38 |                   -> 
39 |             -> <(>
40 |             -> expr
41 |               -> string
42 |                 -> 
43 |             -> <)>
44 |       -> 
45 | $
46 | 
47 | 48 | 49 | -------------------------------------------------------------------------------- /docs/tools/documentation.html: -------------------------------------------------------------------------------- 1 | 2 | 3 |

Documentation tools

4 | 5 |

cvd_to_html

6 | 7 | cvd_to_html reads in one or more .cvd documentation files and creates HTML output in a given directory. It is used as follows: 8 | 9 |
10 | $ cvd_to_html -o modules_html modules_cvd/Array.cvd modules_cvd/Builtins.cvd
11 | 
12 | 13 | 14 | -------------------------------------------------------------------------------- /docs/tools/index.html: -------------------------------------------------------------------------------- 1 | 2 | 3 |

Converge tools

4 | 5 | Documentation for the following tools is available: 6 | 7 | 13 | 14 | 15 | -------------------------------------------------------------------------------- /examples/Makefile.in: -------------------------------------------------------------------------------- 1 | all: 2 | cd benchmarks && ${MAKE} ${MFLAGS} 3 | cd compile_time && ${MAKE} ${MFLAGS} 4 | cd dsls && ${MAKE} ${MFLAGS} 5 | cd metaclasses && ${MAKE} ${MFLAGS} 6 | 7 | install: 8 | cd benchmarks && ${MAKE} ${MFLAGS} install 9 | cd compile_time && ${MAKE} ${MFLAGS} install 10 | cd dsls && ${MAKE} ${MFLAGS} install 11 | cd metaclasses && ${MAKE} ${MFLAGS} install 12 | 13 | clean: 14 | cd benchmarks && ${MAKE} ${MFLAGS} clean 15 | cd compile_time && ${MAKE} ${MFLAGS} clean 16 | cd dsls && ${MAKE} ${MFLAGS} clean 17 | cd metaclasses && ${MAKE} ${MFLAGS} clean 18 | 19 | distclean: clean 20 | cd benchmarks && ${MAKE} ${MFLAGS} distclean 21 | cd compile_time && ${MAKE} ${MFLAGS} distclean 22 | cd dsls && ${MAKE} ${MFLAGS} distclean 23 | cd metaclasses && ${MAKE} ${MFLAGS} distclean 24 | rm -f Makefile 25 | 26 | regress: 27 | cd benchmarks && ${MAKE} ${MFLAGS} regress 28 | cd compile_time && ${MAKE} ${MFLAGS} regress 29 | cd dsls && ${MAKE} ${MFLAGS} regress 30 | cd metaclasses && ${MAKE} ${MFLAGS} regress 31 | -------------------------------------------------------------------------------- /examples/benchmarks/.gitignore: -------------------------------------------------------------------------------- 1 | cvstone 2 | fannkuch-redux 3 | richards -------------------------------------------------------------------------------- /examples/benchmarks/Makefile.in: -------------------------------------------------------------------------------- 1 | include @abs_top_srcdir@/Makefile.inc 2 | 3 | all: cvstone fannkuch-redux richards 4 | 5 | cvstone: cvstone.cv 6 | ${CONVERGE_VM} ${CONVERGEC} -m cvstone.cv 7 | 8 | fannkuch-redux: fannkuch-redux.cv 9 | ${CONVERGE_VM} ${CONVERGEC} -m fannkuch-redux.cv 10 | 11 | richards: richards.cv 12 | ${CONVERGE_VM} ${CONVERGEC} -m richards.cv 13 | 14 | install: 15 | 16 | clean: 17 | rm -f cvstone cvstone.cvb fannkuch-redux fannkuch-redux.cvb richards richards.cvb 18 | 19 | distclean: clean 20 | rm -f Makefile 21 | 22 | regress: all 23 | ${CONVERGE_VM} cvstone 24 | ${CONVERGE_VM} richards -------------------------------------------------------------------------------- /examples/benchmarks/fannkuch-redux.cv: -------------------------------------------------------------------------------- 1 | // The Computer Language Benchmarks Game 2 | // http://shootout.alioth.debian.org/ 3 | 4 | // contributed by Isaac Gouy 5 | // converted to Java by Oleg Mazurov 6 | // converted to Python by Buck Golemon 7 | // modified by Justin Peel 8 | // converted to Converge by Laurence Tratt 9 | 10 | import Builtins, Strings, Sys 11 | 12 | func range(n): 13 | t := [] 14 | i := 0 15 | while i < n: 16 | t.append(i) 17 | i += 1 18 | return t 19 | 20 | func fannkuch(n): 21 | maxFlipsCount := 0 22 | permSign := 1 23 | checksum := 0 24 | 25 | perm1 := range(n) 26 | count := perm1[:] 27 | nm := n - 1 28 | while 1: 29 | k := perm1[0] 30 | if k != 0: 31 | perm := perm1[:] 32 | flipsCount := 1 33 | kk := perm[k] 34 | while kk != 0: 35 | i := 0 36 | while i <= k / 2: 37 | t := perm[i] 38 | perm[i] := perm[k - i] 39 | perm[k - i] := t 40 | i += 1 41 | flipsCount += 1 42 | k := kk 43 | kk := perm[kk] 44 | if maxFlipsCount < flipsCount: 45 | maxFlipsCount := flipsCount 46 | if permSign == 1: 47 | checksum += flipsCount 48 | else: 49 | checksum += -flipsCount 50 | 51 | // Use incremental change to generate another permutation 52 | if permSign == 1: 53 | t := perm1[0] 54 | perm1[0],perm1[1] := [perm1[1],perm1[0]] 55 | permSign := 0 56 | else: 57 | perm1[1],perm1[2] := [perm1[2],perm1[1]] 58 | permSign := 1 59 | r := 2 60 | while r < n - 1: 61 | if count[r] != 0: 62 | break 63 | count[r] := r 64 | perm0 := perm1[0] 65 | perm1[:r+1] := perm1[1:r+2] 66 | perm1[r+1] := perm0 67 | r += 1 68 | exhausted: 69 | r := nm 70 | if count[r] == 0: 71 | Sys::println(checksum) 72 | return maxFlipsCount 73 | count[r] -= 1 74 | 75 | func main(): 76 | n := Builtins::Int.new(Sys::argv[0]) 77 | Sys::println(Strings::format("Pfannkuchen(%d) = %d", n, fannkuch(n))) -------------------------------------------------------------------------------- /examples/compile_time/.gitignore: -------------------------------------------------------------------------------- 1 | ani_funcs 2 | fib_cache 3 | nested 4 | powers 5 | printf 6 | -------------------------------------------------------------------------------- /examples/compile_time/Makefile.in: -------------------------------------------------------------------------------- 1 | include @abs_top_srcdir@/Makefile.inc 2 | 3 | prefix = @prefix@ 4 | exec_prefix = @exec_prefix@ 5 | bindir = @bindir@ 6 | datarootdir = @datarootdir@ 7 | datadir = @datadir@ 8 | conexamplesdir = ${datadir}/examples/converge-@CONVERGE_VERSION@ 9 | INSTALL = @INSTALL@ 10 | 11 | 12 | %.cvb: %.cv 13 | ${CONVERGE_VM} ${CONVERGEC} -o $@ $< 14 | 15 | 16 | all: ani_funcs fib_cache nested powers printf 17 | 18 | install: all 19 | ${INSTALL} -d ${DESTDIR}${conexamplesdir}/compile_time 20 | ${INSTALL} -c -m 444 fib_cache.cv nested.cv powers.cv printf.cv ${DESTDIR}${conexamplesdir}/compile_time 21 | 22 | ani_funcs: ani_funcs.cvb 23 | ${CONVERGE_VM} ${CONVERGEL} -o ani_funcs ani_funcs.cvb 24 | 25 | fib_cache: fib_cache.cvb 26 | ${CONVERGE_VM} ${CONVERGEL} -o fib_cache fib_cache.cvb 27 | 28 | nested: nested.cvb 29 | ${CONVERGE_VM} ${CONVERGEL} -o nested nested.cvb 30 | 31 | powers: powers.cvb 32 | ${CONVERGE_VM} ${CONVERGEL} -o powers powers.cvb 33 | 34 | printf: printf.cvb 35 | ${CONVERGE_VM} ${CONVERGEL} -o printf printf.cvb 36 | 37 | clean: 38 | rm -f ani_funcs fib_cache nested powers printf *.cvb 39 | 40 | distclean: clean 41 | rm -f Makefile 42 | 43 | regress: all 44 | -------------------------------------------------------------------------------- /examples/compile_time/ani_funcs.cv: -------------------------------------------------------------------------------- 1 | // Copyright (c) 2008 Laurence Tratt 2 | // 3 | // Permission is hereby granted, free of charge, to any person obtaining a copy 4 | // of this software and associated documentation files (the "Software"), to 5 | // deal in the Software without restriction, including without limitation the 6 | // rights to use, copy, modify, merge, publish, distribute, sublicense, and/or 7 | // sell copies of the Software, and to permit persons to whom the Software is 8 | // furnished to do so, subject to the following conditions: 9 | // 10 | // The above copyright notice and this permission notice shall be included in 11 | // all copies or substantial portions of the Software. 12 | // 13 | // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 14 | // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 15 | // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 16 | // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 17 | // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING 18 | // FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS 19 | // IN THE SOFTWARE. 20 | 21 | 22 | // 23 | // A simple example of using CTMP to generate multiple functions; each generated function when called 24 | // prints out the same name as the function itself. 25 | // 26 | 27 | 28 | import CEI, Sys 29 | 30 | 31 | 32 | 33 | func pfuncs(names): 34 | funcs := [] 35 | for name := names.iter(): 36 | funcs.append([| 37 | func $c{CEI::ivar(name)}(): 38 | Sys::println(${CEI::istring(name)}) 39 | |]) 40 | 41 | return funcs 42 | 43 | 44 | 45 | $c 46 | 47 | 48 | 49 | 50 | func main(): 51 | 52 | dog() 53 | cat() 54 | -------------------------------------------------------------------------------- /examples/compile_time/fib_cache.cv: -------------------------------------------------------------------------------- 1 | // Copyright (c) 2008 Laurence Tratt 2 | // 3 | // Permission is hereby granted, free of charge, to any person obtaining a copy 4 | // of this software and associated documentation files (the "Software"), to 5 | // deal in the Software without restriction, including without limitation the 6 | // rights to use, copy, modify, merge, publish, distribute, sublicense, and/or 7 | // sell copies of the Software, and to permit persons to whom the Software is 8 | // furnished to do so, subject to the following conditions: 9 | // 10 | // The above copyright notice and this permission notice shall be included in 11 | // all copies or substantial portions of the Software. 12 | // 13 | // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 14 | // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 15 | // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 16 | // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 17 | // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING 18 | // FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS 19 | // IN THE SOFTWARE. 20 | 21 | 22 | // 23 | // This is a simple example of how to pre-compute the first n entries of the Fibonacci sequence at 24 | // compile-time using the standard definition of the Fibonacci function. Since fib(n) is very slow 25 | // when n is bigger than about 15, pre-computing these numbers can lead to a huge efficiency gain 26 | // at run-time (depending on the machine between a factor of 400x-500x). 27 | // 28 | // If you want to see the difference in action, just run this file twice: on the first time it'll 29 | // take a while to compile and print out the first 30 numbers in the Fibonacci sequence. On the 30 | // second run it'll print them out virtually straight away. 31 | // 32 | 33 | 34 | import CEI, Sys 35 | 36 | 37 | 38 | 39 | // 40 | // The classic definition of the Fibonacci sequence. 41 | // 42 | 43 | func fib(n): 44 | 45 | if n == 0: 46 | return 0 47 | elif n == 1: 48 | return 1 49 | else: 50 | return fib(n - 1) + fib(n - 2) 51 | 52 | 53 | 54 | // 55 | // Returns the Fibonacci sequence as a list from 0 to n. 56 | // 57 | 58 | func fibs_upto(n): 59 | 60 | fibs := [] 61 | i := 0 62 | while i < n: 63 | fibs.append(fib(i)) 64 | i += 1 65 | 66 | return fibs 67 | 68 | 69 | 70 | // 71 | // Calculate the Fibonacci sequence at compile-time up-to 30, and "lift" the result so that it's 72 | // translated from a list of numbers into an ITree list of ITree ints (i.e. we convert the list of 73 | // numbers into it's abstract syntax tree equivalent). 74 | // 75 | 76 | cfibs := $ 77 | 78 | 79 | 80 | func main(): 81 | 82 | Sys::println(cfibs) 83 | 84 | -------------------------------------------------------------------------------- /examples/compile_time/nested.cv: -------------------------------------------------------------------------------- 1 | // Copyright (c) 2007 Laurence Tratt 2 | // 3 | // Permission is hereby granted, free of charge, to any person obtaining a copy 4 | // of this software and associated documentation files (the "Software"), to 5 | // deal in the Software without restriction, including without limitation the 6 | // rights to use, copy, modify, merge, publish, distribute, sublicense, and/or 7 | // sell copies of the Software, and to permit persons to whom the Software is 8 | // furnished to do so, subject to the following conditions: 9 | // 10 | // The above copyright notice and this permission notice shall be included in 11 | // all copies or substantial portions of the Software. 12 | // 13 | // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 14 | // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 15 | // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 16 | // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 17 | // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING 18 | // FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS 19 | // IN THE SOFTWARE. 20 | 21 | 22 | // 23 | // This file might seem a slightly gratuitous example, but people seem to be very interested in it. 24 | // It defines the Converge equivalent of a "macro" which generates a "macro". More accurately, it 25 | // uses nested quasi-quoting, so what we effectively have is an ITree which when spliced in and 26 | // evaluated creates another ITree. To fully resolve a nested quasi-quote n levels deep, one has to 27 | // splice it n times. 28 | // 29 | // In this example, we only use two levels of nested quasi-quoting, but the general principle should 30 | // be fairly clear. 31 | // 32 | 33 | import CEI, Strings, Sys 34 | 35 | 36 | 37 | // 38 | // Given a string s, returns a quasi-quoted dynamically scoped function, whose result, when called 39 | // and then spliced in, is a function which takes a string and returns a string. 40 | // 41 | // If this makes your head hurt, the best way to understand things is to run this file as 42 | // "converge -v nested.cv" and then analyse the output. There's a lot of stuff in there, but you 43 | // can eventually work out that your leg isn't being pulled. 44 | // 45 | 46 | func f(s): 47 | 48 | it := [| 49 | func &g(s2): 50 | it2 := [| 51 | func &h(s3): 52 | return Strings::format("Nested '%s' '%s' '%s'.", \ 53 | ${CEI::lift(${CEI::lift(s)})}, ${CEI::lift(s2)}, s3) 54 | |] 55 | Sys::println("Elided ITree generated by g:\n", CEI::elided_pp_itree(it2, self_module.mod_id)) 56 | return it2 57 | |] 58 | 59 | Sys::println("Elided ITree generated by f:\n", CEI::elided_pp_itree(it, self_module.mod_id), "\n") 60 | return it 61 | 62 | 63 | 64 | // Splice in the result from calling f(); essentially, this creates a function called g at this 65 | // location which will look a bit like this: 66 | // 67 | // func g(s2): 68 | // it := [| 69 | // func &h(s3): 70 | // return Strings::format("Nested '%s'.", ${CEI::lift("foo")}, ${CEI::lift(s2)}, s3) 71 | // |] 72 | // Sys::println("Elided ITree generated by g:\n", CEI::pp_itree(it, self_module.mod_id)) 73 | // return it 74 | // 75 | // The actual function which gets created has a mountain of ickiness in it to ensure that scoping 76 | // and so on work as expected (most of the variables above get renamed to something else to 77 | // ensure hygiene); you can see the real tree by running this file. 78 | 79 | $c 80 | 81 | 82 | 83 | // Now when we splice the result of calling g, we cancel out what was originally nested 84 | // quasi-quoting. 85 | // 86 | // In other words, splicing in the result of calling g will create a function which looks roughly 87 | // like: 88 | // 89 | // func h(s3): 90 | // return Strings::format("Nested '%s' '%s' '%s'.", "foo", "woo", s3)) 91 | 92 | $c 93 | 94 | 95 | func main(): 96 | 97 | Sys::println("Spliced g value = ", h("zoo")) 98 | -------------------------------------------------------------------------------- /examples/compile_time/powers.cv: -------------------------------------------------------------------------------- 1 | // Copyright (c) 2007 Laurence Tratt 2 | // 3 | // Permission is hereby granted, free of charge, to any person obtaining a copy 4 | // of this software and associated documentation files (the "Software"), to 5 | // deal in the Software without restriction, including without limitation the 6 | // rights to use, copy, modify, merge, publish, distribute, sublicense, and/or 7 | // sell copies of the Software, and to permit persons to whom the Software is 8 | // furnished to do so, subject to the following conditions: 9 | // 10 | // The above copyright notice and this permission notice shall be included in 11 | // all copies or substantial portions of the Software. 12 | // 13 | // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 14 | // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 15 | // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 16 | // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 17 | // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING 18 | // FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS 19 | // IN THE SOFTWARE. 20 | 21 | 22 | // 23 | // This file is based on an example from "DSL Implementation in MetaOCaml, Template Haskell, and 24 | // C++" by Czarnecki, O'Donnell, Striegnitz, Taha. 25 | // 26 | 27 | 28 | import CEI, Sys 29 | 30 | 31 | 32 | 33 | func expand_power(n, x): 34 | 35 | if n == 0: 36 | return [| 1 |] 37 | else: 38 | return [| $c{x} * $c{expand_power(n - 1, x)} |] 39 | 40 | 41 | 42 | func mk_power(n): 43 | 44 | it := [| 45 | func (&x): 46 | return $c{expand_power(n, [| &x |])} 47 | |] 48 | 49 | Sys::println("mk_power(", n, ") generated:\n") 50 | Sys::println(CEI::pp_itree(it)) 51 | 52 | return it 53 | 54 | 55 | 56 | power3 := $ 57 | 58 | 59 | 60 | func main(): 61 | 62 | Sys::println("3^3 = ", power3(3)) 63 | -------------------------------------------------------------------------------- /examples/dsls/Makefile.in: -------------------------------------------------------------------------------- 1 | include @abs_top_srcdir@/Makefile.inc 2 | 3 | prefix = @prefix@ 4 | exec_prefix = @exec_prefix@ 5 | bindir = @bindir@ 6 | datarootdir = @datarootdir@ 7 | datadir = @datadir@ 8 | conexamplesdir = ${datadir}/examples/converge-@CONVERGE_VERSION@ 9 | INSTALL = @INSTALL@ 10 | 11 | 12 | %.cvb: %.cv 13 | ${CONVERGE_VM} ${CONVERGEC} -o $@ $< 14 | 15 | 16 | all: 17 | cd statemachine && ${MAKE} ${MFLAGS} 18 | cd wsi_asm && ${MAKE} ${MFLAGS} 19 | 20 | install: all 21 | cd statemachine && ${MAKE} ${MFLAGS} install 22 | cd wsi_asm && ${MAKE} ${MFLAGS} install 23 | 24 | clean: 25 | cd statemachine && ${MAKE} ${MFLAGS} clean 26 | cd wsi_asm && ${MAKE} ${MFLAGS} clean 27 | 28 | distclean: clean 29 | cd statemachine && ${MAKE} ${MFLAGS} distclean 30 | cd wsi_asm && ${MAKE} ${MFLAGS} distclean 31 | rm -f Makefile 32 | 33 | regress: 34 | cd statemachine && ${MAKE} ${MFLAGS} regress 35 | cd wsi_asm && ${MAKE} ${MFLAGS} regress 36 | -------------------------------------------------------------------------------- /examples/dsls/statemachine/.gitignore: -------------------------------------------------------------------------------- 1 | ex[1-5] 2 | -------------------------------------------------------------------------------- /examples/dsls/statemachine/Makefile.in: -------------------------------------------------------------------------------- 1 | include @abs_top_srcdir@/Makefile.inc 2 | 3 | prefix = @prefix@ 4 | exec_prefix = @exec_prefix@ 5 | bindir = @bindir@ 6 | datarootdir = @datarootdir@ 7 | datadir = @datadir@ 8 | conexamplesdir = ${datadir}/examples/converge-@CONVERGE_VERSION@ 9 | INSTALL = @INSTALL@ 10 | 11 | 12 | EXAMPLE_VERSIONS = 1 2 3 4 5 13 | 14 | 15 | all: ${foreach e,${EXAMPLE_VERSIONS}, ex${e}} 16 | 17 | 18 | ${foreach e,${EXAMPLE_VERSIONS}, ex${e}}: ${foreach e,${EXAMPLE_VERSIONS}, ex${e}.cv} 19 | ${CONVERGE_VM} ${CONVERGEC} -mv $@.cv 20 | 21 | 22 | STATEMACHINEDIR = ${DESTDIR}${conexamplesdir}/dsls/statemachine 23 | install: all 24 | ${INSTALL} -d ${STATEMACHINEDIR} 25 | ${INSTALL} -c -m 444 README ${STATEMACHINEDIR} 26 | ${foreach v,${EXAMPLE_VERSIONS},${INSTALL} -c -m 444 SM${v}.cv ${STATEMACHINEDIR}/SM${v}.cv;} 27 | ${foreach v,${EXAMPLE_VERSIONS},${INSTALL} -c -m 444 ex${v}.cv ${STATEMACHINEDIR}/ex${v}.cv;} 28 | 29 | clean: 30 | ${foreach v,${EXAMPLE_VERSIONS},rm -f SM${v}.cvb;} 31 | ${foreach v,${EXAMPLE_VERSIONS},rm -f ex${v}.cvb;} 32 | ${foreach v,${EXAMPLE_VERSIONS},rm -f ex${v};} 33 | 34 | distclean: clean 35 | rm -f Makefile 36 | 37 | regress: all 38 | ${CONVERGE_VM} -v ex1.cv 39 | ${CONVERGE_VM} -v ex2.cv 40 | ${CONVERGE_VM} -v ex3.cv 41 | -------------------------------------------------------------------------------- /examples/dsls/statemachine/README: -------------------------------------------------------------------------------- 1 | The examples in this directory show an example of a statemachine DSL evolving in 2 | power and reliability. It is intended to show a small, but realistic, example of 3 | DSL development. It is a good first starting point for learning about DSL 4 | development in Converge. 5 | 6 | Each evolution of the DSL comes with two files SMr.cv and exr.cv where r is 7 | the DSL's version number. Therefore SM1.cv and ex1.cv are the starting 8 | point. Each version of the DSL is runnable. e.g. to run the first version 9 | type: 10 | 11 | $ converge -v ex1.cv 12 | 13 | The DSL and its implementation will be compiled and run. The first three 14 | versions are non-interactive, whereas the fourth and fifth versions require 15 | input from the user. 16 | 17 | A brief description of each version now follows: 18 | 19 | 1: Very simple implementation allowing only states, transitions, and events. 20 | Events received by the system cause transitions to be taken; if no valid 21 | transition is found for a given event, an exception is raised. 22 | 23 | Try making a syntactic error in the input (e.g. change a "to" keyword to 24 | "ro"), and you will get a compile-time error pinpointing exactly where 25 | the mistake occurred - notice that this is automatic and required no 26 | extra effort from the DSL implementor. 27 | 28 | 2: Guards (effectively preconditions), variables and simple actions (updating 29 | variables) on top of version 1. This is expressive enough for a decent 30 | subset of statemachines. The general format of a transition is: 31 | 32 | "TRANSITION" "FROM" "TO" : "[" "]" 33 | "/" 34 | 35 | where , "[" "]", and "/" are all optional. 36 | 37 | However there is a notable usability problem with this example. If the 38 | user makes a mistake in their input which leads to a run-time exception, 39 | then the resulting run-time exception will be in terms of the SMr.cv file, 40 | not the exr.cv file. To simulate this, change one of the actions from: 41 | 42 | drinks := drinks - 1 43 | 44 | to: 45 | 46 | drinks := drinks - "woo" 47 | 48 | As you will see, the resulting exception does not provide much assistance 49 | for debugging purposes. 50 | 51 | 3: The same as version 2, but extra src infos are added to generated code. 52 | Make the same run-time-exception-raising change to one of the actions 53 | as you did to version 2, and you will see that the resulting exception now 54 | also pinpoints exactly where within the ex3.cv the error resulted from. 55 | 56 | This is achived by adding src infos to quasi-quoted code e.g.: 57 | 58 | [| ... |] 59 | 60 | 4: Allow functions to be called from actions. Some "built in" functions are 61 | added to the statemachine (the input() function returns input from the 62 | user). Non-built in functions are assumed to be calls to user-defined 63 | functions outside the statemachine. This allows the statemachine in ex4.cv 64 | sufficient power to model a cash-machine including user input. To use the 65 | statemachine, first choose an account number (1 or 2), and then choose 66 | whether to Withdraw or Finish. If you withdraw, you will be asked for an 67 | amount; you can not overdraw an account. 68 | 69 | There is a subtle problem with this version of the DSL. If you use certain 70 | names for functions, then seemingly inexplicable behaviour occurs. Try for 71 | example renaming the read_card function (and all references to it) to 72 | "sm" which will trigger this problem. The reason this happens is that the 73 | DSL dynamically scopes references to unknown functions; in other words the 74 | read_card function is translated to an unmolested read_card variable 75 | without being renamed to a fresh name. Parts of the generated DSL code use 76 | - for their own convenience - dynamically scoped names too (e.g. "sm" which 77 | you will see in SM4.cv as "&sm"). In other words, this version of the DSL 78 | suffers from a hygiene problem. 79 | 80 | 5: Same as version 4, but without the hygiene problem. This version of the DSL 81 | renames unknown functions such as read_card to a fresh name; in the 82 | generated code it then uses the rename declaration to ensure that the fresh 83 | name is the one in scope. This means that the generated code looks roughly 84 | as follows: 85 | 86 | rename read_card as $$20$$ 87 | ... 88 | $$20$$(...) 89 | 90 | This version of the DSL thus solves the hygiene problem of version 4. 91 | -------------------------------------------------------------------------------- /examples/dsls/statemachine/ex1.cv: -------------------------------------------------------------------------------- 1 | // Copyright (c) 2008 Laurence Tratt 2 | // 3 | // Permission is hereby granted, free of charge, to any person obtaining a copy 4 | // of this software and associated documentation files (the "Software"), to 5 | // deal in the Software without restriction, including without limitation the 6 | // rights to use, copy, modify, merge, publish, distribute, sublicense, and/or 7 | // sell copies of the Software, and to permit persons to whom the Software is 8 | // furnished to do so, subject to the following conditions: 9 | // 10 | // The above copyright notice and this permission notice shall be included in 11 | // all copies or substantial portions of the Software. 12 | // 13 | // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 14 | // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 15 | // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 16 | // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 17 | // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING 18 | // FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS 19 | // IN THE SOFTWARE. 20 | 21 | 22 | import SM1 23 | 24 | 25 | 26 | 27 | Door := $<>: 28 | state Opened 29 | state Closed 30 | 31 | transition from Opened to Closed: close 32 | transition from Closed to Opened: open 33 | 34 | 35 | 36 | func main(): 37 | 38 | door := Door.new() 39 | door.event("close") 40 | door.event("open") 41 | // Firing the following event will violate the statemachine, and so will lead to an exception 42 | // being raised. 43 | // door.event("Opening") 44 | -------------------------------------------------------------------------------- /examples/dsls/statemachine/ex2.cv: -------------------------------------------------------------------------------- 1 | // Copyright (c) 2008 Laurence Tratt 2 | // 3 | // Permission is hereby granted, free of charge, to any person obtaining a copy 4 | // of this software and associated documentation files (the "Software"), to 5 | // deal in the Software without restriction, including without limitation the 6 | // rights to use, copy, modify, merge, publish, distribute, sublicense, and/or 7 | // sell copies of the Software, and to permit persons to whom the Software is 8 | // furnished to do so, subject to the following conditions: 9 | // 10 | // The above copyright notice and this permission notice shall be included in 11 | // all copies or substantial portions of the Software. 12 | // 13 | // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 14 | // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 15 | // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 16 | // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 17 | // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING 18 | // FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS 19 | // IN THE SOFTWARE. 20 | 21 | 22 | import SM2 23 | 24 | 25 | 26 | 27 | Vending_Machine := $<>: 28 | drinks := 1 29 | sweets := 2 30 | 31 | state Waiting 32 | state Vend_Drink 33 | state Vend_Sweet 34 | state Empty 35 | 36 | transition vending_drink from Waiting to Vend_Drink: Vend_Drink [ drinks > 0 ] / drinks := drinks - 1 37 | transition vended_drink from Vend_Drink to Waiting: Vended [drinks > 0 or sweets > 0] 38 | 39 | transition vending_sweet from Waiting to Vend_Sweet: Vend_Sweet [ sweets > 0 ] / sweets := sweets - 1 40 | transition vended_sweet from Vend_Sweet to Waiting: Vended [sweets > 0 or drinks > 0] 41 | 42 | transition empty from Vend_Sweet to Empty: Vended [drinks == 0 and sweets == 0] 43 | transition empty from Vend_Drink to Empty: Vended [drinks == 0 and sweets == 0] 44 | 45 | 46 | 47 | func main(): 48 | 49 | vending_machine := Vending_Machine.new() 50 | vending_machine.event("Vend_Drink") 51 | vending_machine.event("Vended") 52 | vending_machine.event("Vend_Sweet") 53 | vending_machine.event("Vended") 54 | vending_machine.event("Vend_Sweet") 55 | vending_machine.event("Vended") 56 | // Firing the following event will cause an exception as there are no sweets left to vend: 57 | // vending_machine.event("Vend_Sweet") 58 | -------------------------------------------------------------------------------- /examples/dsls/statemachine/ex3.cv: -------------------------------------------------------------------------------- 1 | // Copyright (c) 2008 Laurence Tratt 2 | // 3 | // Permission is hereby granted, free of charge, to any person obtaining a copy 4 | // of this software and associated documentation files (the "Software"), to 5 | // deal in the Software without restriction, including without limitation the 6 | // rights to use, copy, modify, merge, publish, distribute, sublicense, and/or 7 | // sell copies of the Software, and to permit persons to whom the Software is 8 | // furnished to do so, subject to the following conditions: 9 | // 10 | // The above copyright notice and this permission notice shall be included in 11 | // all copies or substantial portions of the Software. 12 | // 13 | // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 14 | // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 15 | // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 16 | // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 17 | // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING 18 | // FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS 19 | // IN THE SOFTWARE. 20 | 21 | 22 | import SM3 23 | 24 | 25 | 26 | 27 | Vending_Machine := $<>: 28 | drinks := 1 29 | sweets := 2 30 | 31 | state Waiting 32 | state Vend_Drink 33 | state Vend_Sweet 34 | state Empty 35 | 36 | transition vending_drink from Waiting to Vend_Drink: Vend_Drink [ drinks > 0 ] / drinks := drinks - 1 37 | transition vended_drink from Vend_Drink to Waiting: Vended [drinks > 0 or sweets > 0] 38 | 39 | transition vending_sweet from Waiting to Vend_Sweet: Vend_Sweet [ sweets > 0 ] / sweets := sweets - 1 40 | transition vended_sweet from Vend_Sweet to Waiting: Vended [sweets > 0 or drinks > 0] 41 | 42 | transition empty from Vend_Sweet to Empty: Vended [drinks == 0 and sweets == 0] 43 | transition empty from Vend_Drink to Empty: Vended [drinks == 0 and sweets == 0] 44 | 45 | 46 | 47 | func main(): 48 | 49 | vending_machine := Vending_Machine.new() 50 | vending_machine.event("Vend_Drink") 51 | vending_machine.event("Vended") 52 | vending_machine.event("Vend_Sweet") 53 | vending_machine.event("Vended") 54 | vending_machine.event("Vend_Sweet") 55 | vending_machine.event("Vended") 56 | // Firing the following event will cause an exception as there are no sweets left to vend: 57 | // vending_machine.event("Vend_Sweet") 58 | -------------------------------------------------------------------------------- /examples/dsls/statemachine/ex4.cv: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ltratt/converge/21027f148e4353321ec2377bee36f41b93f3c010/examples/dsls/statemachine/ex4.cv -------------------------------------------------------------------------------- /examples/dsls/statemachine/ex5.cv: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ltratt/converge/21027f148e4353321ec2377bee36f41b93f3c010/examples/dsls/statemachine/ex5.cv -------------------------------------------------------------------------------- /examples/dsls/wsi_asm/.gitignore: -------------------------------------------------------------------------------- 1 | ex[1-4] 2 | fib 3 | -------------------------------------------------------------------------------- /examples/dsls/wsi_asm/Makefile.in: -------------------------------------------------------------------------------- 1 | include @abs_top_srcdir@/Makefile.inc 2 | 3 | prefix = @prefix@ 4 | exec_prefix = @exec_prefix@ 5 | bindir = @bindir@ 6 | datarootdir = @datarootdir@ 7 | datadir = @datadir@ 8 | conexamplesdir = ${datadir}/examples/converge-@CONVERGE_VERSION@ 9 | INSTALL = @INSTALL@ 10 | 11 | 12 | EXAMPLES = ex1 ex2 ex3 ex4 fib 13 | 14 | 15 | all: ${foreach e,${EXAMPLES}, ${e}} 16 | 17 | 18 | ${foreach e,${EXAMPLES}, ${e}}: ${foreach e,${EXAMPLES}, ${e}.cv} 19 | ${CONVERGE_VM} ${CONVERGEC} -mv $@.cv 20 | 21 | 22 | WSI_ASMDIR = ${DESTDIR}${conexamplesdir}/dsls/wsi_asm 23 | install: all 24 | ${INSTALL} -d ${WSI_ASMDIR} 25 | ${INSTALL} -c -m 444 README ${WSI_ASMDIR} 26 | ${foreach e,${EXAMPLES},${INSTALL} -c -m 444 ${e}.cv ${WSI_ASMDIR};} 27 | ${INSTALL} -c -m 444 WSI_Asm.cv ${WSI_ASMDIR} 28 | 29 | clean: 30 | rm -f WSI_Asm.cvb 31 | ${foreach e,${EXAMPLES},rm -f ${e}.cvb;} 32 | ${foreach e,${EXAMPLES},rm -f ${e};} 33 | 34 | distclean: clean 35 | rm -f Makefile 36 | 37 | regress: all 38 | ${CONVERGE_VM} -v ex1.cv 39 | ${CONVERGE_VM} -v ex2.cv 40 | ${CONVERGE_VM} -v ex3.cv 41 | ${CONVERGE_VM} -v ex4.cv 42 | -------------------------------------------------------------------------------- /examples/dsls/wsi_asm/README: -------------------------------------------------------------------------------- 1 | The examples in this directory are of a simple, idealised assembler for a Word 2 | Size Independent (WSI) VM. WSI essentially means that the VM in question 3 | abstracts away from issues such as the bit size of an integer (it's not 4 | defined), which means that addresses start at 0 and monotonically increase by 1. 5 | Instructions begin at address 0; the stack starts at the end of memory and grows 6 | downwards. Addresses and integers are synonymous, and labels can be used 7 | wherever addresses are valid. Any memory location can be overwritten. Invalid 8 | actions lead to "seg faults" (represented by normal Converge expressions). The 9 | VM defines built-in routines to perform some primitive operations. 10 | 11 | By default the VM has 8 registers R0 to R7 inclusive. R7 is the Program Counter 12 | (PC) storing the address of the current instruction. R6 is the stack pointer 13 | pointing to the first free stack address. The default size of memory is 524288 14 | words. 15 | 16 | An assembly program is a sequence of lines. Each line specifies an action or a 17 | label. Actions are things like: 18 | 19 | R0 := 2 // Store the value 2 into R0 20 | R1 := R0 + 1 // Assign the value stored into R0, and incremented by 2, into R1 21 | 22 | Labels are identifiers followed by a colon: 23 | 24 | L0: 25 | 26 | There are 8 types of action: 27 | 28 | R0 := // Store into R0 29 | [R0] := // Store into the address stored in R0 30 | CALL L0 // Call L0, storing the return PC on the stack 31 | RTN // Pop the return PC from the stack and jump to it 32 | PUSH R1 // Push R1 onto the stack 33 | POP R2 // Pop R1 from the stack 34 | SWI printi // Execute the specified SoftWare Interrupt routine 35 | if jmp L2 // If is true, jump to L2; "if " is optional 36 | 37 | There are 5 types of expression: 38 | 39 | R0 // Read the contents of R0 40 | L0 // Substitute the address of L0 41 | R0 + R2 // Add R0 and R1 42 | R0 + 2 // Add R0 and 2 43 | [R2] // Read the value in the address stored in R2 44 | 45 | Note that expressions involving [+-*/] are all of the form or 46 | to approximate the limitations of typical assembler 47 | instructions. Note that this also implicitly means that there are no precedence 48 | issues to consider. 49 | 50 | The VM defines the following builtin SWIs: 51 | 52 | exit // Exits the program unconditionally 53 | printi // Prints the integer in R0 to screen 54 | inputi // Reads an integer from stdin, placing the result in R0 55 | 56 | There are 5 examples included with this DSL. ex1.cv to ex4.cv inclusive 57 | demonstrate low-level features with artifical examples. fib.cv defines a 58 | recursive fibonacci function. Execute this as follows: 59 | 60 | $ converge fib.cv 61 | > 62 | 63 | At the ">" prompt enter a number in the Fibonacci sequence e.g. 8: 64 | 65 | $ converge fib.cv 66 | > 8 67 | 21 68 | $ 69 | -------------------------------------------------------------------------------- /examples/dsls/wsi_asm/ex1.cv: -------------------------------------------------------------------------------- 1 | import WSI_Asm 2 | 3 | 4 | 5 | 6 | func main(): 7 | test := $<>: 8 | R0 := 0 9 | L0: 10 | SWI printi 11 | R0 := R0 + 2 12 | IF R0 < 8 JMP L0 13 | SWI exit 14 | 15 | test.new().exec() 16 | -------------------------------------------------------------------------------- /examples/dsls/wsi_asm/ex2.cv: -------------------------------------------------------------------------------- 1 | import WSI_Asm 2 | 3 | 4 | 5 | 6 | func main(): 7 | test := $<>: 8 | R0 := 0 9 | L0: 10 | CALL inc 11 | IF R0 < 8 JMP L0 12 | SWI exit 13 | 14 | inc: 15 | SWI printi 16 | R0 := R0 + 2 17 | RTN 18 | 19 | test.new().exec() 20 | -------------------------------------------------------------------------------- /examples/dsls/wsi_asm/ex3.cv: -------------------------------------------------------------------------------- 1 | import WSI_Asm 2 | 3 | 4 | 5 | 6 | func main(): 7 | test := $<>: 8 | R0 := 0 9 | L0: 10 | CALL inc 11 | SWI exit 12 | 13 | inc: 14 | SWI printi 15 | R0 := R0 + 2 16 | IF R0 == 8 JMP inc_finish 17 | CALL inc 18 | inc_finish: 19 | RTN 20 | 21 | test.new().exec() 22 | -------------------------------------------------------------------------------- /examples/dsls/wsi_asm/ex4.cv: -------------------------------------------------------------------------------- 1 | import WSI_Asm 2 | 3 | 4 | 5 | 6 | func main(): 7 | test := $<>: 8 | R0 := L0 9 | [R0] := 2 10 | R0 := 0 11 | R1 := L0 12 | R0 := [R1] 13 | [R1] := R0 + 2 14 | SWI printi 15 | R0 := [R1] 16 | SWI printi 17 | SWI exit 18 | L0: 19 | 20 | test.new().exec() 21 | -------------------------------------------------------------------------------- /examples/dsls/wsi_asm/fib.cv: -------------------------------------------------------------------------------- 1 | import WSI_Asm 2 | 3 | 4 | 5 | 6 | func main(): 7 | test := $<>: 8 | SWI inputi 9 | CALL fib 10 | SWI printi 11 | SWI exit 12 | 13 | // 14 | // fib(n) reads in an int on R0 and outputs an int on R0. 15 | // 16 | 17 | fib: 18 | // This routine corrupts R1 and R2, so push them onto the stack. 19 | PUSH R1 20 | PUSH R2 21 | IF R0 == 0 JMP fib0 // fib(0) == 0 22 | IF R0 == 1 JMP fib1 // fib(1) == 1 23 | // fib(n) where n > 1 24 | R1 := R0 25 | R0 := R1 - 1 26 | CALL fib 27 | R2 := R0 28 | R0 := R1 - 2 29 | CALL fib 30 | R0 := R2 + R0 31 | JMP fib_finish 32 | fib0: // fib(0) == 0 33 | R0 := 0 34 | JMP fib_finish 35 | fib1: // fib(1) == 1 36 | R0 := 1 37 | fib_finish: 38 | POP R2 39 | POP R1 40 | RTN 41 | 42 | test.new().exec() 43 | -------------------------------------------------------------------------------- /examples/metaclasses/.gitignore: -------------------------------------------------------------------------------- 1 | singleton 2 | -------------------------------------------------------------------------------- /examples/metaclasses/Makefile.in: -------------------------------------------------------------------------------- 1 | include @abs_top_srcdir@/Makefile.inc 2 | 3 | prefix = @prefix@ 4 | exec_prefix = @exec_prefix@ 5 | bindir = @bindir@ 6 | datarootdir = @datarootdir@ 7 | datadir = @datadir@ 8 | conexamplesdir = ${datadir}/examples/converge-@CONVERGE_VERSION@ 9 | INSTALL = @INSTALL@ 10 | 11 | 12 | %.cvb: %.cv 13 | ${CONVERGE_VM} ${CONVERGEC} -o $@ $< 14 | 15 | 16 | all: singleton 17 | 18 | install: all 19 | ${INSTALL} -d ${DESTDIR}${conexamplesdir}/metaclasses 20 | ${INSTALL} -c -m 444 singleton.cv ${DESTDIR}${conexamplesdir}/metaclasses 21 | 22 | singleton: singleton.cvb 23 | ${CONVERGE_VM} ${CONVERGEL} -o singleton singleton.cvb 24 | 25 | clean: 26 | rm -f singleton singleton.cvb 27 | 28 | distclean: clean 29 | rm -f Makefile 30 | 31 | regress: all 32 | -------------------------------------------------------------------------------- /examples/metaclasses/singleton.cv: -------------------------------------------------------------------------------- 1 | import Builtins, Sys 2 | 3 | 4 | 5 | 6 | class Singleton(Builtins::Class): 7 | 8 | func new(self): 9 | 10 | if not self.find_slot("instance"): 11 | self.instance := exbi Builtins::Class.new() 12 | 13 | return self.instance 14 | 15 | 16 | 17 | 18 | class M metaclass Singleton: 19 | 20 | x := 0 21 | 22 | 23 | 24 | 25 | func main(): 26 | 27 | Sys::print("Two instantiations of Object produce the same object: ") 28 | if Builtins::Object.new() is Builtins::Object.new(): 29 | Sys::println("true") 30 | else: 31 | Sys::println("false") 32 | Sys::print("Two instantiations of M produce the same object: ") 33 | if M.new() is M.new(): 34 | Sys::println("true") 35 | else: 36 | Sys::println("false") 37 | 38 | -------------------------------------------------------------------------------- /lib/.gitignore: -------------------------------------------------------------------------------- 1 | Makefile.Stdlib 2 | -------------------------------------------------------------------------------- /lib/Makefile.Stdlib.in: -------------------------------------------------------------------------------- 1 | include @abs_top_srcdir@/Makefile.inc 2 | 3 | prefix = @prefix@ 4 | exec_prefix = @exec_prefix@ 5 | libdir = @libdir@ 6 | conlibdir = ${libdir}/converge-@CONVERGE_VERSION@ 7 | INSTALL = @INSTALL@ 8 | 9 | MINIMAL_OBJS = Stdlib.cvb Stdlib/Backtrace.cvb Stdlib/CPK.cvb Stdlib/CPK/Earley.cvb \ 10 | Stdlib/CPK/Earley/Grammar.cvb Stdlib/CPK/Earley/Parser.cvb Stdlib/CPK/Token.cvb \ 11 | Stdlib/CPK/Tokens.cvb Stdlib/CPK/Tree.cvb Stdlib/File.cvb Stdlib/Functional.cvb \ 12 | Stdlib/Maths.cvb Stdlib/Numbers.cvb Stdlib/Parse_Args.cvb Stdlib/Platform.cvb \ 13 | Stdlib/Platform/Properties.cvb Stdlib/Platform/Host.cvb Stdlib/Strings.cvb Stdlib/Time.cvb 14 | 15 | MAXIMAL_OBJS = Stdlib/CEI.cvb Stdlib/CPK/Earley/DSL.cvb Stdlib/CPK/Traverser.cvb \ 16 | Stdlib/Platform/Env.cvb Stdlib/Platform/Exec.cvb Stdlib/Sort.cvb Stdlib/XML/Nodes.cvb \ 17 | Stdlib/XML.cvb Stdlib/XML/XDM.cvb Stdlib/XML/XHTML.cvb 18 | 19 | ALL_OBJS = ${MINIMAL_OBJS} ${MAXIMAL_OBJS} 20 | 21 | 22 | %.cvb: %.cv 23 | ${CONVERGE_VM} ${CONVERGEC} -I Stdlib -o $@ $< 24 | 25 | %.cvb: % 26 | ${CONVERGE_VM} ${CONVERGEC} -o $@ $< 27 | 28 | 29 | all: Stdlib.cvl 30 | 31 | minimal: ${MINIMAL_OBJS} 32 | 33 | install: all 34 | ${INSTALL} -d ${DESTDIR}${conlibdir} 35 | ${INSTALL} -c -m 444 Stdlib.cvl ${DESTDIR}${conlibdir} 36 | 37 | 38 | ifdef CON_TARGET 39 | CROSS_OBJS = ${ALL_OBJS:.cvb=.${CON_TARGET}.cvb} 40 | 41 | %.${CON_TARGET}.cvb: %.cv 42 | ${CONVERGE_VM} ${CONVERGEC} -T ${CON_TARGET} -I ${CONVERGE_COMPILER_DIR} -o $@ $< 43 | 44 | %.${CON_TARGET}.cvb: % 45 | ${CONVERGE_VM} ${CONVERGEC} -T ${CON_TARGET} -o $@ $< 46 | 47 | cross: ${CROSS_OBJS} 48 | ${CONVERGE_VM} ${CONVERGEL} -l -T ${CON_TARGET} -o Stdlib.${CON_TARGET}.cvl Stdlib.${CON_TARGET}.cvb ${CROSS_OBJS} 49 | 50 | cross-clean: 51 | rm -f ${CROSS_OBJS} Stdlib.${CON_TARGET}.cvl 52 | endif 53 | 54 | 55 | Stdlib.cvl: ${ALL_OBJS} 56 | ${CONVERGE_VM} ${CONVERGEL} -l -o Stdlib.cvl Stdlib.cvb ${ALL_OBJS} 57 | 58 | clean: 59 | rm -f ${ALL_OBJS} Stdlib.cvl 60 | 61 | distclean: clean 62 | rm -f Makefile.Stdlib 63 | -------------------------------------------------------------------------------- /lib/Makefile.in: -------------------------------------------------------------------------------- 1 | include @abs_top_srcdir@/Makefile.inc 2 | 3 | prefix = @prefix@ 4 | exec_prefix = @exec_prefix@ 5 | libdir = @libdir@ 6 | conlibdir = ${libdir}/converge-@CONVERGE_VERSION@ 7 | INSTALL = @INSTALL@ 8 | 9 | 10 | all: 11 | ${MAKE} -f Makefile.Stdlib ${MFLAGS} 12 | 13 | minimal: 14 | ${MAKE} -f Makefile.Stdlib ${MFLAGS} minimal 15 | 16 | install: all 17 | ${MAKE} -f Makefile.Stdlib ${MFLAGS} ${MFLAGS} install 18 | 19 | cross: all 20 | ${MAKE} -f Makefile.Stdlib ${MFLAGS} ${MFLAGS} cross 21 | 22 | cross-clean: 23 | ${MAKE} -f Makefile.Stdlib ${MFLAGS} ${MFLAGS} cross-clean 24 | 25 | clean: 26 | ${MAKE} -f Makefile.Stdlib ${MFLAGS} clean 27 | 28 | distclean: clean 29 | ${MAKE} -f Makefile.Stdlib ${MFLAGS} distclean 30 | rm -f Makefile 31 | -------------------------------------------------------------------------------- /lib/Stdlib/CEI.cv: -------------------------------------------------------------------------------- 1 | // Copyright (c) 2003-2006 King's College London, created by Laurence Tratt 2 | // 3 | // Permission is hereby granted, free of charge, to any person obtaining a copy 4 | // of this software and associated documentation files (the "Software"), to 5 | // deal in the Software without restriction, including without limitation the 6 | // rights to use, copy, modify, merge, publish, distribute, sublicense, and/or 7 | // sell copies of the Software, and to permit persons to whom the Software is 8 | // furnished to do so, subject to the following conditions: 9 | // 10 | // The above copyright notice and this permission notice shall be included in 11 | // all copies or substantial portions of the Software. 12 | // 13 | // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 14 | // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 15 | // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 16 | // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 17 | // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING 18 | // FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS 19 | // IN THE SOFTWARE. 20 | 21 | 22 | import Builtins, Exceptions, Strings, Thread 23 | import CPK::Earley::Grammar 24 | import Compiler::Core, Compiler::Parser, Compiler::Eval, Compiler::ITree, Compiler::ITree_PP, Compiler::ITree_Rename, Compiler::ITree_WF, Compiler::Lift, Compiler::Tokenizer 25 | 26 | 27 | 28 | 29 | func compiler(): 30 | 31 | return Core::peek_compiler() 32 | 33 | 34 | 35 | func error(msg, src_infos := null): 36 | 37 | Core::peek_compiler().error(msg, src_infos) 38 | 39 | 40 | 41 | func warning(msg, src_infos := null): 42 | 43 | Core::peek_compiler().warning(msg, src_infos) 44 | 45 | 46 | 47 | func eval(str, vars := Dict{}, includes := []): 48 | 49 | return Eval::eval(str, vars, includes) 50 | 51 | 52 | 53 | func eval_itree(itree): 54 | 55 | return Eval::eval_itree(itree) 56 | 57 | 58 | 59 | func fresh_name(name := null): 60 | 61 | return Core::fresh_name(name) 62 | 63 | 64 | 65 | func pp_itree(itree): 66 | 67 | return ITree_PP::pp(itree) 68 | 69 | 70 | 71 | func elided_pp_itree(itree, self_mod_id := null): 72 | 73 | return ITree_PP::elided_pp(itree, self_mod_id) 74 | 75 | 76 | 77 | func rename_itree(itree, rename_vars := null): 78 | 79 | if rename_vars is null: 80 | return ITree_Rename::rename_fresh(itree) 81 | else: 82 | return ITree_Rename::rename_(itree) 83 | 84 | 85 | 86 | func embeddable_itree(itree, except_vars := Set{}): 87 | 88 | if Builtins::List.instantiated(itree): 89 | itrees := itree 90 | else: 91 | itrees := [itree] 92 | 93 | all_vars := Set{} 94 | for itree := itrees.iter(): 95 | all_vars.extend(itree.free_vars) 96 | all_vars.extend(itree.bound_vars) 97 | 98 | rename_vars := all_vars.complement(except_vars) 99 | 100 | renames := Dict{} 101 | rename_elems := [] 102 | for var := rename_vars.iter(): 103 | fn := fresh_name(var) 104 | renames[var] := fn 105 | rename_elems.append(irename(ivar(var), ivar(fn))) 106 | 107 | return [ITree_Rename::rename_(itree, renames), rename_elems] 108 | 109 | 110 | 111 | func lift(obj, src_infos := null): 112 | 113 | return Lift::lift(obj, src_infos) 114 | 115 | 116 | 117 | // 118 | // Create all the factory functions for ITree elements. 119 | // 120 | 121 | $c 148 | -------------------------------------------------------------------------------- /lib/Stdlib/CPK/Earley/DSL.cv: -------------------------------------------------------------------------------- 1 | import Strings 2 | import Compiler::Tokenizer 3 | import CEI, Grammar, Parser 4 | 5 | 6 | 7 | class _DSL_Parser(Parser::Parser): 8 | 9 | func error(self, token): 10 | 11 | if token.value is null: 12 | token_print := token.type 13 | else: 14 | token_print := token.value 15 | 16 | msg := Strings::format("Parsing error at or near `%s' token.", token_print) 17 | CEI::error(msg, token.src_infos) 18 | 19 | 20 | 21 | 22 | func mk_parser(start_rule, extra_keywords := [], extra_symbols := []): 23 | 24 | func dif(dsl_block, src_infos): 25 | 26 | tokens_map := Tokenizer::tokens_map(extra_symbols, extra_keywords) 27 | grammar, rule_names := Grammar::compile(dsl_block, start_rule, tokens_map) 28 | 29 | iextra_keywords := CEI::lift(extra_keywords) 30 | iextra_symbols := CEI::lift(extra_symbols) 31 | igrammar := CEI::lift(grammar) 32 | irule_names := CEI::lift(rule_names) 33 | itokens_map := CEI::lift(tokens_map) 34 | 35 | return [| 36 | func (dsl_block, src_infos): 37 | 38 | tokenizer := Tokenizer::Tokenizer.new() 39 | tokenizer.tokenize(dsl_block, src_infos, ${iextra_keywords}, ${iextra_symbols}) 40 | 41 | parser := _DSL_Parser.new(src_infos) 42 | 43 | return parser.parse(${igrammar}, ${irule_names}, ${itokens_map}, tokenizer.tokens) 44 | |] 45 | 46 | return dif 47 | -------------------------------------------------------------------------------- /lib/Stdlib/CPK/Earley/Parser.cv: -------------------------------------------------------------------------------- 1 | // Copyright (c) 2003-2006 King's College London, created by Laurence Tratt 2 | // 3 | // Permission is hereby granted, free of charge, to any person obtaining a copy 4 | // of this software and associated documentation files (the "Software"), to 5 | // deal in the Software without restriction, including without limitation the 6 | // rights to use, copy, modify, merge, publish, distribute, sublicense, and/or 7 | // sell copies of the Software, and to permit persons to whom the Software is 8 | // furnished to do so, subject to the following conditions: 9 | // 10 | // The above copyright notice and this permission notice shall be included in 11 | // all copies or substantial portions of the Software. 12 | // 13 | // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 14 | // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 15 | // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 16 | // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 17 | // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING 18 | // FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS 19 | // IN THE SOFTWARE. 20 | 21 | 22 | import C_Earley_Parser 23 | 24 | Parser := C_Earley_Parser::Parser 25 | -------------------------------------------------------------------------------- /lib/Stdlib/CPK/Token.cv: -------------------------------------------------------------------------------- 1 | // Copyright (c) 2003-2006 King's College London, created by Laurence Tratt 2 | // 3 | // Permission is hereby granted, free of charge, to any person obtaining a copy 4 | // of this software and associated documentation files (the "Software"), to 5 | // deal in the Software without restriction, including without limitation the 6 | // rights to use, copy, modify, merge, publish, distribute, sublicense, and/or 7 | // sell copies of the Software, and to permit persons to whom the Software is 8 | // furnished to do so, subject to the following conditions: 9 | // 10 | // The above copyright notice and this permission notice shall be included in 11 | // all copies or substantial portions of the Software. 12 | // 13 | // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 14 | // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 15 | // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 16 | // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 17 | // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING 18 | // FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS 19 | // IN THE SOFTWARE. 20 | 21 | 22 | import Builtins, Strings 23 | 24 | 25 | 26 | 27 | class Token: 28 | 29 | 30 | func init(self, type, value, src_infos): 31 | 32 | self.type := type 33 | self.value := value 34 | self.src_infos := src_infos 35 | 36 | 37 | 38 | func to_str(self): 39 | 40 | if self.value is null: 41 | return Strings::format("<%s>", self.type) 42 | elif Builtins::List.instantiated(self.value): 43 | return Strings::format("<%s %s>", self.type, self.value.to_str()) 44 | else: 45 | return Strings::format("<%s %s>", self.type, self.value) 46 | -------------------------------------------------------------------------------- /lib/Stdlib/CPK/Tokens.cv: -------------------------------------------------------------------------------- 1 | // Copyright (c) 2003-2006 King's College London, created by Laurence Tratt 2 | // 3 | // Permission is hereby granted, free of charge, to any person obtaining a copy 4 | // of this software and associated documentation files (the "Software"), to 5 | // deal in the Software without restriction, including without limitation the 6 | // rights to use, copy, modify, merge, publish, distribute, sublicense, and/or 7 | // sell copies of the Software, and to permit persons to whom the Software is 8 | // furnished to do so, subject to the following conditions: 9 | // 10 | // The above copyright notice and this permission notice shall be included in 11 | // all copies or substantial portions of the Software. 12 | // 13 | // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 14 | // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 15 | // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 16 | // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 17 | // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING 18 | // FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS 19 | // IN THE SOFTWARE. 20 | 21 | 22 | func tokens_map(list): 23 | 24 | map := Dict{} 25 | i := 0 26 | for terminal := list.iter(): 27 | map[terminal] := i 28 | i += 1 29 | 30 | return map 31 | -------------------------------------------------------------------------------- /lib/Stdlib/CPK/Traverser.cv: -------------------------------------------------------------------------------- 1 | // Copyright (c) 2003-2006 King's College London, created by Laurence Tratt 2 | // 3 | // Permission is hereby granted, free of charge, to any person obtaining a copy 4 | // of this software and associated documentation files (the "Software"), to 5 | // deal in the Software without restriction, including without limitation the 6 | // rights to use, copy, modify, merge, publish, distribute, sublicense, and/or 7 | // sell copies of the Software, and to permit persons to whom the Software is 8 | // furnished to do so, subject to the following conditions: 9 | // 10 | // The above copyright notice and this permission notice shall be included in 11 | // all copies or substantial portions of the Software. 12 | // 13 | // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 14 | // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 15 | // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 16 | // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 17 | // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING 18 | // FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS 19 | // IN THE SOFTWARE. 20 | 21 | 22 | import Builtins, Exceptions, Strings, Sys 23 | import Tree 24 | 25 | 26 | 27 | 28 | class Traverser: 29 | 30 | func _preorder(self, node): 31 | 32 | if not Tree::Non_Term.instantiated(node): 33 | fail 34 | 35 | name := "_t_" + node.name 36 | if self.find_slot(name): 37 | return self.get_slot(name)(node) 38 | else: 39 | return self._default(node) 40 | 41 | 42 | 43 | 44 | class Liberal_Traverser(Traverser): 45 | 46 | func _default(self, node): 47 | 48 | for c := node[0 : ].iter(): 49 | self.preorder(c) 50 | 51 | return null 52 | 53 | 54 | 55 | 56 | class Strict_Traverser(Traverser): 57 | 58 | func _default(self, node): 59 | 60 | raise Exceptions::User_Exception.new(Strings::format("Unknown node '%s'.", node.name)) 61 | -------------------------------------------------------------------------------- /lib/Stdlib/CPK/Tree.cv: -------------------------------------------------------------------------------- 1 | // Copyright (c) 2003-2006 King's College London, created by Laurence Tratt 2 | // 3 | // Permission is hereby granted, free of charge, to any person obtaining a copy 4 | // of this software and associated documentation files (the "Software"), to 5 | // deal in the Software without restriction, including without limitation the 6 | // rights to use, copy, modify, merge, publish, distribute, sublicense, and/or 7 | // sell copies of the Software, and to permit persons to whom the Software is 8 | // furnished to do so, subject to the following conditions: 9 | // 10 | // The above copyright notice and this permission notice shall be included in 11 | // all copies or substantial portions of the Software. 12 | // 13 | // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 14 | // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 15 | // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 16 | // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 17 | // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING 18 | // FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS 19 | // IN THE SOFTWARE. 20 | 21 | 22 | import Builtins, Strings, Sys 23 | 24 | 25 | 26 | 27 | class Non_Term: 28 | 29 | func init(self, name, children, src_infos): 30 | 31 | self.name := name 32 | self.children := children 33 | self.src_infos := src_infos 34 | 35 | 36 | 37 | func to_str(self): 38 | 39 | return pp_tree(self) 40 | 41 | 42 | 43 | func get(self, i): 44 | 45 | return self.children[i] 46 | 47 | 48 | 49 | func get_slice(self, i, j): 50 | 51 | return self.children[i : j] 52 | 53 | 54 | 55 | func len(self): 56 | 57 | return self.children.len() 58 | 59 | 60 | 61 | func iter(self, i := 0): 62 | 63 | for yield self.children.iter(i) 64 | 65 | fail 66 | 67 | 68 | 69 | func riter(self, i := 0): 70 | 71 | for yield self.children.riter(i) 72 | 73 | fail 74 | 75 | 76 | 77 | 78 | _INDENT := " " 79 | 80 | // 81 | // Given a parse_tree as a list, return a pretty printed string representing the parse tree. 82 | // 83 | 84 | func pp_tree(list, indent_level := 0): 85 | 86 | output := [list.name] 87 | output.append(" " + list.src_infos.to_str()) 88 | for elem := list.iter(0): 89 | output.append("\n") 90 | output.append(_INDENT * (indent_level + 1)) 91 | output.append("-> ") 92 | if Non_Term.instantiated(elem): 93 | output.append(pp_tree(elem, indent_level + 1)) 94 | else: 95 | if elem.value is null: 96 | output.extend(["<", elem.type, ">"]) 97 | else: 98 | output.extend(["<", elem.type, " ", elem.value, ">"]) 99 | output.append(" " + elem.src_infos.to_str()) 100 | 101 | return Strings::join(output, "") 102 | -------------------------------------------------------------------------------- /lib/Stdlib/Functional.cv: -------------------------------------------------------------------------------- 1 | // Copyright (c) 2003-2006 King's College London, created by Laurence Tratt 2 | // 3 | // Permission is hereby granted, free of charge, to any person obtaining a copy 4 | // of this software and associated documentation files (the "Software"), to 5 | // deal in the Software without restriction, including without limitation the 6 | // rights to use, copy, modify, merge, publish, distribute, sublicense, and/or 7 | // sell copies of the Software, and to permit persons to whom the Software is 8 | // furnished to do so, subject to the following conditions: 9 | // 10 | // The above copyright notice and this permission notice shall be included in 11 | // all copies or substantial portions of the Software. 12 | // 13 | // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 14 | // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 15 | // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 16 | // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 17 | // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING 18 | // FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS 19 | // IN THE SOFTWARE. 20 | 21 | 22 | import Exceptions, Sys 23 | 24 | 25 | 26 | 27 | func map(func_, list): 28 | 29 | new_list := [] 30 | for elem := list.iter(): 31 | if not mapped := func_(elem): 32 | raise Exceptions::Exception("Function passed to 'map' did not return an element.") 33 | new_list.append(mapped) 34 | 35 | return new_list 36 | 37 | 38 | 39 | func foldl(func_, list, initializer := null): 40 | 41 | if list.len() == 0 & initializer is null: 42 | raise Exceptions::Exception("foldl passed an empty list and no initializer.") 43 | elif list.len() == 0: 44 | return initializer 45 | 46 | if list.len() == 1: 47 | return list[0] 48 | 49 | if not initializer is null: 50 | accumulator := initializer 51 | i := 0 52 | else: 53 | accumulator := func_(list[0], list[1]) 54 | i := 2 55 | while i < list.len(): 56 | if not accumulator := func_(accumulator, list[i]): 57 | raise Exceptions::Exception("Function passed to foldl did not return an element.") 58 | i += 1 59 | 60 | return accumulator 61 | -------------------------------------------------------------------------------- /lib/Stdlib/Maths.cv: -------------------------------------------------------------------------------- 1 | // Copyright (c) 2003-2006 King's College London, created by Laurence Tratt 2 | // 3 | // Permission is hereby granted, free of charge, to any person obtaining a copy 4 | // of this software and associated documentation files (the "Software"), to 5 | // deal in the Software without restriction, including without limitation the 6 | // rights to use, copy, modify, merge, publish, distribute, sublicense, and/or 7 | // sell copies of the Software, and to permit persons to whom the Software is 8 | // furnished to do so, subject to the following conditions: 9 | // 10 | // The above copyright notice and this permission notice shall be included in 11 | // all copies or substantial portions of the Software. 12 | // 13 | // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 14 | // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 15 | // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 16 | // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 17 | // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING 18 | // FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS 19 | // IN THE SOFTWARE. 20 | 21 | 22 | import Builtins, Exceptions 23 | 24 | 25 | 26 | 27 | func max(*objs): 28 | 29 | if objs.len() < 1: 30 | raise Exceptions::Parameter_Exception("Maximum value can only be computed when passed one or more objects") 31 | 32 | current_max := objs[0] 33 | for i := 1.iter_to(objs.len()): 34 | if objs[i] > current_max: 35 | current_max := objs[i] 36 | 37 | return current_max 38 | 39 | 40 | 41 | func min(*objs): 42 | 43 | if objs.len() < 1: 44 | raise Exceptions::Parameter_Exception("Minimum value can only be computed when passed one or more objects") 45 | 46 | current_min := objs[0] 47 | for i := 1.iter_to(objs.len()): 48 | if objs[i] < current_min: 49 | current_min := objs[i] 50 | 51 | return current_min 52 | 53 | 54 | 55 | func powerset(s): 56 | 57 | array := [0] * s.len() 58 | sl := Builtins::List.new(s) 59 | while 1: 60 | ss := Set{} // Subset 61 | 62 | for i := 0.iter_to(s.len()): 63 | if array[i] == 1: 64 | ss.add(sl[i]) 65 | yield ss 66 | 67 | for i := (s.len() - 1).iter_to(-1, -1): 68 | if array[i] == 0: 69 | array[i] := 1 70 | break 71 | else: 72 | array[i] := 0 73 | exhausted: 74 | fail 75 | -------------------------------------------------------------------------------- /lib/Stdlib/Numbers.cv: -------------------------------------------------------------------------------- 1 | // Copyright (c) 2003-2006 King's College London, created by Laurence Tratt 2 | // 3 | // Permission is hereby granted, free of charge, to any person obtaining a copy 4 | // of this software and associated documentation files (the "Software"), to 5 | // deal in the Software without restriction, including without limitation the 6 | // rights to use, copy, modify, merge, publish, distribute, sublicense, and/or 7 | // sell copies of the Software, and to permit persons to whom the Software is 8 | // furnished to do so, subject to the following conditions: 9 | // 10 | // The above copyright notice and this permission notice shall be included in 11 | // all copies or substantial portions of the Software. 12 | // 13 | // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 14 | // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 15 | // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 16 | // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 17 | // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING 18 | // FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS 19 | // IN THE SOFTWARE. 20 | 21 | 22 | import Builtins 23 | 24 | 25 | 26 | 27 | func parse(num): 28 | 29 | // XXX 30 | 31 | return Builtins::Int.new(num) 32 | -------------------------------------------------------------------------------- /lib/Stdlib/Platform/Env.cv: -------------------------------------------------------------------------------- 1 | import C_Platform_Env 2 | 3 | 4 | 5 | 6 | find_var := C_Platform_Env::find_var 7 | get_var := C_Platform_Env::get_var 8 | set_var := C_Platform_Env::set_var 9 | -------------------------------------------------------------------------------- /lib/Stdlib/Platform/Exec.cv: -------------------------------------------------------------------------------- 1 | import C_Platform_Exec 2 | 3 | 4 | 5 | 6 | sh_cmd := C_Platform_Exec::sh_cmd 7 | -------------------------------------------------------------------------------- /lib/Stdlib/Platform/Host.cv: -------------------------------------------------------------------------------- 1 | import C_Platform_Host 2 | 3 | 4 | 5 | 6 | get_hostname := C_Platform_Host::get_hostname 7 | -------------------------------------------------------------------------------- /lib/Stdlib/Platform/Properties.cv: -------------------------------------------------------------------------------- 1 | import C_Platform_Properties 2 | 3 | 4 | 5 | 6 | case_sensitive_filenames := C_Platform_Properties::case_sensitive_filenames 7 | endianness := C_Platform_Properties::endianness 8 | word_bits := C_Platform_Properties::word_bits 9 | osname := C_Platform_Properties::osname 10 | -------------------------------------------------------------------------------- /lib/Stdlib/Sort.cv: -------------------------------------------------------------------------------- 1 | // Copyright (c) 2003-2006 King's College London, created by Laurence Tratt 2 | // 3 | // Permission is hereby granted, free of charge, to any person obtaining a copy 4 | // of this software and associated documentation files (the "Software"), to 5 | // deal in the Software without restriction, including without limitation the 6 | // rights to use, copy, modify, merge, publish, distribute, sublicense, and/or 7 | // sell copies of the Software, and to permit persons to whom the Software is 8 | // furnished to do so, subject to the following conditions: 9 | // 10 | // The above copyright notice and this permission notice shall be included in 11 | // all copies or substantial portions of the Software. 12 | // 13 | // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 14 | // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 15 | // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 16 | // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 17 | // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING 18 | // FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS 19 | // IN THE SOFTWARE. 20 | 21 | 22 | // 23 | // Sort 'list' in place into the order determined by 'comparison' using the quickest available 24 | // sorting algorithm. Note that the sort is not guaranteed to be stable. 25 | // 26 | 27 | func sort(list, comparison := func (x, y) { return x < y }): 28 | 29 | heapsort(list, comparison) 30 | 31 | 32 | 33 | // 34 | // Sort 'list' in place into the order determined by 'comparison' using the heapsort algorithm. 35 | // 36 | 37 | func heapsort(list, comparison := func (x, y) { return x < y }): 38 | 39 | // This implementation of heapsort is as described at: 40 | // 41 | // http://en.wikipedia.org/wiki/Heapsort 42 | 43 | start := list.len().idiv(2) - 1 44 | while start >= 0: 45 | _heapsort_sift(list, comparison, start, list.len()) 46 | start := start - 1 47 | 48 | end := list.len() - 1 49 | while end > 0: 50 | t := list[0] 51 | list[0] := list[end] 52 | list[end] := t 53 | _heapsort_sift(list, comparison, 0, end) 54 | end := end - 1 55 | 56 | 57 | 58 | func _heapsort_sift(list, comparison, start, count): 59 | 60 | while (child := start * 2 + 1) < count: 61 | if child < count - 1 & comparison(list[child], list[child + 1]): 62 | child += 1 63 | if comparison(list[start], list[child]): 64 | t := list[start] 65 | list[start] := list[child] 66 | list[child] := t 67 | start := child 68 | else: 69 | return 70 | -------------------------------------------------------------------------------- /lib/Stdlib/Strings.cv: -------------------------------------------------------------------------------- 1 | // Copyright (c) 2003-2006 King's College London, created by Laurence Tratt 2 | // 3 | // Permission is hereby granted, free of charge, to any person obtaining a copy 4 | // of this software and associated documentation files (the "Software"), to 5 | // deal in the Software without restriction, including without limitation the 6 | // rights to use, copy, modify, merge, publish, distribute, sublicense, and/or 7 | // sell copies of the Software, and to permit persons to whom the Software is 8 | // furnished to do so, subject to the following conditions: 9 | // 10 | // The above copyright notice and this permission notice shall be included in 11 | // all copies or substantial portions of the Software. 12 | // 13 | // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 14 | // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 15 | // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 16 | // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 17 | // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING 18 | // FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS 19 | // IN THE SOFTWARE. 20 | 21 | 22 | import Builtins, C_Strings, Exceptions, Functional, Maths, Sys 23 | 24 | 25 | 26 | 27 | func format(format, *args): 28 | 29 | str := "" 30 | 31 | i := 0 32 | j := 0 33 | while i < format.len(): 34 | if format[i] == "%" & i + 1 < format.len(): 35 | if format[i + 1] == "%": 36 | str += format[i] 37 | i += 2 38 | else: 39 | if j == args.len(): 40 | raise Exceptions::Parameters_Exception.new("Too few parameters passed for format string.") 41 | if format[i + 1] == "s": 42 | if not Builtins::String.instantiated(args[j]): 43 | raise Exceptions::Type_Exception.new(Builtins::String.path(), args[j], "parameter " + (j + 2).to_str()) 44 | str += args[j] 45 | i += 2 46 | j += 1 47 | elif format[i + 1] == "d": 48 | if not Builtins::Int.instantiated(args[j]): 49 | raise Exceptions::Type_Exception.new(Builtins::Int.path(), args[j], "parameter " + (j + 2).to_str()) 50 | str += args[j].to_str() 51 | i += 2 52 | j += 1 53 | elif format[i + 1] == "f": 54 | if not Builtins::Float.instantiated(args[j]): 55 | raise Exceptions::Type_Exception.new(Builtins::Float.path(), args[j], "parameter " + (j + 2).to_str()) 56 | str += args[j].to_str() 57 | i += 2 58 | j += 1 59 | else: 60 | raise Exceptions::Exception.new("Unknown identifier '" + format[i + 1] + "'") 61 | else: 62 | str += format[i] 63 | i += 1 64 | if j < args.len(): 65 | raise Exceptions::Parameters_Exception.new("Too many parameters passed.") 66 | 67 | return str 68 | 69 | 70 | 71 | func join(list, separator): 72 | 73 | return C_Strings::join(list, separator) 74 | 75 | 76 | 77 | func split(str, seperator): 78 | 79 | split_str := [] 80 | i := 0 81 | for j := str.find_index(seperator): 82 | split_str.append(str[i : j]) 83 | i := j + seperator.len() 84 | if i < str.len(): 85 | split_str.append(str[i : ]) 86 | 87 | return split_str 88 | 89 | 90 | 91 | // 92 | // Returns the Longest Common Prefix among a list of strings. 93 | // 94 | 95 | func lcp(strings): 96 | 97 | if strings.len() == 0: 98 | return "" 99 | 100 | i := Maths::min.apply(Functional::map(func (x) { 101 | return x.len() 102 | }, strings)) 103 | 104 | while i > 0: 105 | prefix := strings[0][ : i] 106 | j := 1 107 | while j < strings.len(): 108 | if not strings[j].prefixed_by(prefix): 109 | break 110 | j += 1 111 | exhausted: 112 | return prefix 113 | 114 | i -= 1 115 | 116 | return "" 117 | -------------------------------------------------------------------------------- /lib/Stdlib/Time.cv: -------------------------------------------------------------------------------- 1 | // Copyright (c) 2007 Laurence Tratt 2 | // 3 | // Permission is hereby granted, free of charge, to any person obtaining a copy 4 | // of this software and associated documentation files (the "Software"), to 5 | // deal in the Software without restriction, including without limitation the 6 | // rights to use, copy, modify, merge, publish, distribute, sublicense, and/or 7 | // sell copies of the Software, and to permit persons to whom the Software is 8 | // furnished to do so, subject to the following conditions: 9 | // 10 | // The above copyright notice and this permission notice shall be included in 11 | // all copies or substantial portions of the Software. 12 | // 13 | // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 14 | // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 15 | // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 16 | // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 17 | // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING 18 | // FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS 19 | // IN THE SOFTWARE. 20 | 21 | 22 | import C_Time, Exceptions, Strings 23 | 24 | 25 | 26 | 27 | class Time_Exception(Exceptions::User_Exception): 28 | pass 29 | 30 | 31 | 32 | 33 | class Instant: 34 | 35 | func init(self, sec, nsec): 36 | 37 | if nsec < 0 | nsec >= 100000*10000: 38 | raise Time_Exception.new("Invalid nsec value") 39 | 40 | self.sec := sec 41 | self.nsec := nsec 42 | 43 | 44 | 45 | func to_str(self): 46 | 47 | return Strings::format("", self.sec, self.nsec) 48 | 49 | 50 | 51 | func ==(self, o): 52 | 53 | if self.sec == o.sec & self.nsec == o.nsec: 54 | return 1 55 | 56 | fail 57 | 58 | 59 | 60 | func !=(self, o): 61 | 62 | if self.sec != o.sec | self.nsec != o.nsec: 63 | return 1 64 | 65 | fail 66 | 67 | 68 | 69 | func <(self, o): 70 | 71 | if self.sec < o.sec: 72 | return 1 73 | elif self.sec == o.sec & self.nsec < o.nsec: 74 | return 1 75 | 76 | fail 77 | 78 | 79 | 80 | func >(self, o): 81 | 82 | if self.sec > o.sec: 83 | return 1 84 | elif self.sec == o.sec & self.nsec > o.nsec: 85 | return 1 86 | 87 | fail 88 | 89 | 90 | 91 | func -(self, o): 92 | 93 | if self.nsec - o.nsec < 0: 94 | return mk_timespec(self.sec - o.sec - 1, (100000*10000) + (self.nsec - o.nsec)) 95 | else: 96 | return mk_timespec(self.sec - o.sec, self.nsec - o.nsec) 97 | 98 | 99 | 100 | func as_float(self): 101 | 102 | return self.sec + self.nsec / (100000*10000) 103 | 104 | 105 | 106 | 107 | func current(): 108 | 109 | return Instant.new.apply(C_Time::current()) 110 | 111 | 112 | 113 | func current_mono(): 114 | 115 | return Instant.new.apply(C_Time::current_mono()) 116 | 117 | 118 | 119 | func mk_timespec(sec, nsec): 120 | 121 | return Instant.new(sec, nsec) 122 | -------------------------------------------------------------------------------- /lib/Stdlib/XML/Nodes.cv: -------------------------------------------------------------------------------- 1 | import Builtins, Exceptions, Strings 2 | import libXML2 3 | 4 | 5 | 6 | 7 | XML_Exception := libXML2::XML_Exception 8 | 9 | 10 | 11 | 12 | class Doc(Builtins::List): 13 | 14 | func get_root_elem(self): 15 | 16 | for elem := self.iter(): 17 | if Elem.instantiated(elem): 18 | return elem 19 | 20 | raise "XXX" 21 | 22 | 23 | 24 | 25 | class Attr: 26 | 27 | func init(self, name, val, prefix := "", namespace := ""): 28 | 29 | if (prefix == "" & namespace != "") | (prefix != "" & namespace == ""): 30 | raise "XXX" 31 | 32 | self.name := name 33 | self.val := val 34 | self.prefix := prefix 35 | self.namespace := namespace 36 | 37 | 38 | 39 | func hash(self): 40 | 41 | return Strings::format("%s:%s", self.prefix, self.name).hash() 42 | 43 | 44 | 45 | 46 | class Elem(Builtins::List): 47 | 48 | func init(self, name, attrs := [], prefix := "", namespace := ""): 49 | 50 | self.name := name 51 | self._attr_namespaces := Dict{} 52 | for attr := attrs.iter(): 53 | if not (attr_namespace := self._attr_namespaces.find(attr.namespace)): 54 | self._attr_namespaces[attr.namespace] := attr_namespace := Dict{} 55 | attr_namespace[attr.name] := attr 56 | self.prefix := prefix 57 | self.namespace := namespace 58 | 59 | 60 | 61 | func to_xml(self): 62 | 63 | pp_attrs := [] 64 | for namespace, attrs := self._attr_namespaces.iter(): 65 | for attr := attrs.iter_vals(): 66 | if namespace == "": 67 | pp_attrs.append(Strings::format("%s=\"%s\"", attr.name, attr.val)) 68 | else: 69 | raise "XXX" 70 | pp_attrs := Strings::join(pp_attrs, " ") 71 | 72 | pp_body := [] 73 | for node := self.iter(): 74 | if Builtins::String.instantiated(node): 75 | pp_body.append(node) 76 | else: 77 | pp_body.append(node.to_xml()) 78 | pp_body := Strings::join(pp_body, "") 79 | 80 | if pp_attrs.len() == 0: 81 | if self.len() == 0: 82 | return Strings::format("<%s />", self.name) 83 | else: 84 | return Strings::format("<%s>%s", self.name, pp_body, self.name) 85 | else: 86 | if self.len() == 0: 87 | return Strings::format("<%s %s/>", self.name, pp_attrs) 88 | else: 89 | return Strings::format("<%s %s>%s", self.name, pp_attrs, pp_body, self.name) 90 | 91 | 92 | 93 | func find_attr(self, name, namespace := ""): 94 | 95 | if not (namespace := self._attr_namespaces.find(namespace)): 96 | fail 97 | else: 98 | return namespace.find(name) 99 | 100 | 101 | 102 | func get_attr(self, name, namespace := ""): 103 | 104 | return self._attr_namespaces[namespace][name] 105 | 106 | 107 | 108 | func iter_attrs(self): 109 | 110 | for x, attrs := self._attr_namespaces.iter(): 111 | for name, attr := attrs.iter(): 112 | yield attr 113 | 114 | fail 115 | 116 | 117 | 118 | func iter_elems(self): 119 | 120 | for node := self.iter(): 121 | if Elem.instantiated(node): 122 | yield node 123 | 124 | fail 125 | 126 | 127 | 128 | func get_elem(self, name, namespace := ""): 129 | 130 | lc_name := name.lower_cased() 131 | for node := self.iter(): 132 | if Elem.instantiated(node) & node.name.lower_cased() == lc_name & node.namespace == namespace: 133 | return node 134 | 135 | raise XML_Exception.new(Strings::format("No such element '%s'.", name)) 136 | 137 | 138 | 139 | func iter_elem(self, name, namespace := ""): 140 | 141 | lc_name := name.lower_cased() 142 | for node := self.iter(): 143 | if Elem.instantiated(node) & node.name.lower_cased() == lc_name & node.namespace == namespace: 144 | yield node 145 | 146 | fail 147 | -------------------------------------------------------------------------------- /lib/Stdlib/XML/XDM.cv: -------------------------------------------------------------------------------- 1 | import libXML2 2 | import Nodes 3 | 4 | 5 | 6 | 7 | func parse(xml): 8 | 9 | return libXML2::parse(xml, Nodes) 10 | 11 | 12 | 13 | // 14 | // Sanitize a string, replacing illegal characters with XML entities. 15 | // 16 | 17 | func escape_str(s): 18 | 19 | s := s.replaced("&", "&") 20 | s := s.replaced("<", "<") 21 | s := s.replaced(">", ">") 22 | s := s.replaced("'", "'") 23 | s := s.replaced("\"", """) 24 | 25 | return s 26 | -------------------------------------------------------------------------------- /lib/Stdlib/XML/XHTML.cv: -------------------------------------------------------------------------------- 1 | // Copyright (c) 2007 Laurence Tratt 2 | // 3 | // Permission is hereby granted, free of charge, to any person obtaining a copy 4 | // of this software and associated documentation files (the "Software"), to 5 | // deal in the Software without restriction, including without limitation the 6 | // rights to use, copy, modify, merge, publish, distribute, sublicense, and/or 7 | // sell copies of the Software, and to permit persons to whom the Software is 8 | // furnished to do so, subject to the following conditions: 9 | // 10 | // The above copyright notice and this permission notice shall be included in 11 | // all copies or substantial portions of the Software. 12 | // 13 | // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 14 | // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 15 | // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 16 | // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 17 | // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING 18 | // FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS 19 | // IN THE SOFTWARE. 20 | 21 | 22 | import CEI, Builtins, Strings 23 | import Nodes 24 | 25 | 26 | 27 | 28 | ELEMS := ["a", "abbr", "access", "action", "address", "blockcode", "blockquote", "body", "br", "caption", "cite", "code", "col", "colgroup", "dd", "delete", "dfn", "di", "dispatch", "div", "dl", "dt", "em", "group", "h1", "h2", "h3", "h4", "h5", "h6", "handler", "head", "heading", "html", "img", "input", "insert", "kbd", "l", "label", "li", "link", "load", "message", "meta", "model", "nl", "object", "ol", "output", "p", "param", "pre", "quote", "range", "rebuild", "recalculate", "refresh", "repeat", "reset", "revalidate", "samp", "secret", "section", "select1", "select", "send", "separator", "setfocus", "setindex", "setvalue", "span", "standby", "strong", "style", "sub", "submit", "summary", "sup", "switch", "table", "tbody", "td", "textarea", "tfoot", "th", "thead", "title", "tr", "trigger", "ul", "upload", "var"] 29 | 30 | 31 | 32 | // 33 | // Escapes illegal characters in 's' with XHTML entities. 34 | // 35 | 36 | func escape_str(s): 37 | 38 | s := s.replaced("&", "&") 39 | s := s.replaced("<", "<") 40 | s := s.replaced(">", ">") 41 | s := s.replaced("'", "'") 42 | s := s.replaced("\"", """) 43 | 44 | return s 45 | 46 | 47 | 48 | // 49 | // Converts a dictionary of (name, val) pairs into a list of Nodes::Attr instances. 50 | // 51 | 52 | func _conv_attrs(attrs): 53 | 54 | xml_attrs := [] 55 | 56 | for name, val := attrs.iter(): 57 | xml_attrs.append(Nodes::Attr.new(name, val)) 58 | 59 | return xml_attrs 60 | 61 | 62 | 63 | // 64 | // Generate all the HTML creating functions. 65 | // 66 | 67 | $c 83 | -------------------------------------------------------------------------------- /platform/MinGW/convergec.bat: -------------------------------------------------------------------------------- 1 | @echo off 2 | %~dp0converge %~dp0convergec %* 3 | -------------------------------------------------------------------------------- /platform/MinGW/convergei.bat: -------------------------------------------------------------------------------- 1 | @echo off 2 | %~dp0converge %~dp0convergei %* 3 | -------------------------------------------------------------------------------- /platform/MinGW/convergel.bat: -------------------------------------------------------------------------------- 1 | @echo off 2 | %~dp0converge %~dp0convergel %* 3 | -------------------------------------------------------------------------------- /platform/MinGW/convergep.bat: -------------------------------------------------------------------------------- 1 | @echo off 2 | %~dp0converge %~dp0convergep %* 3 | -------------------------------------------------------------------------------- /platform/MinGW/cvd_to_html.bat: -------------------------------------------------------------------------------- 1 | @echo off 2 | %~dp0converge %~dp0cvd_to_html %* 3 | 4 | -------------------------------------------------------------------------------- /tests/Makefile.in: -------------------------------------------------------------------------------- 1 | include @abs_top_srcdir@/Makefile.inc 2 | 3 | 4 | all: 5 | 6 | clean: 7 | cd lang && ${MAKE} ${MFLAGS} clean 8 | cd threads && ${MAKE} ${MFLAGS} clean 9 | 10 | distclean: 11 | cd lang && ${MAKE} ${MFLAGS} distclean 12 | cd threads && ${MAKE} ${MFLAGS} distclean 13 | rm -f Makefile 14 | 15 | regress: 16 | cd lang && ${MAKE} ${MFLAGS} regress 17 | -------------------------------------------------------------------------------- /tests/lang/Makefile.in: -------------------------------------------------------------------------------- 1 | include @abs_top_srcdir@/Makefile.inc 2 | 3 | 4 | OBJ_FILES = Lang_Test.cvb 5 | 6 | 7 | all: 8 | cd builtins && ${MAKE} ${MFLAGS} 9 | cd namespaces && ${MAKE} ${MFLAGS} 10 | cd splicing && ${MAKE} ${MFLAGS} 11 | 12 | clean: 13 | cd builtins && ${MAKE} ${MFLAGS} clean 14 | cd namespaces && ${MAKE} ${MFLAGS} clean 15 | cd splicing && ${MAKE} ${MFLAGS} clean 16 | rm -f ${OBJ_FILES} 17 | 18 | distclean: clean 19 | cd builtins && ${MAKE} ${MFLAGS} distclean 20 | cd namespaces && ${MAKE} ${MFLAGS} distclean 21 | cd splicing && ${MAKE} ${MFLAGS} distclean 22 | rm -f Makefile 23 | 24 | regress: 25 | cd builtins && ${MAKE} ${MFLAGS} regress 26 | cd namespaces && ${MAKE} ${MFLAGS} regress 27 | cd splicing && ${MAKE} ${MFLAGS} regress -------------------------------------------------------------------------------- /tests/lang/builtins/.gitignore: -------------------------------------------------------------------------------- 1 | class1 2 | list1 3 | str1 4 | tests -------------------------------------------------------------------------------- /tests/lang/builtins/Makefile.in: -------------------------------------------------------------------------------- 1 | include @abs_top_srcdir@/Makefile.inc 2 | 3 | 4 | TESTS = class1 int1 list1 str1 5 | 6 | 7 | all: 8 | ${CONVERGE_VM} ${CONVERGEC} -I .. -m tests.cv 9 | 10 | clean: 11 | ${foreach test,${TESTS},rm -f ${test} ${test}.cvb} 12 | rm -f tests.cvb tests 13 | 14 | distclean: clean 15 | rm -f Makefile 16 | 17 | regress: all 18 | ${CONVERGE_VM} tests 19 | -------------------------------------------------------------------------------- /tests/lang/builtins/class1.cv: -------------------------------------------------------------------------------- 1 | // Copyright (c) 2011 King's College London, created by Laurence Tratt 2 | // 3 | // Permission is hereby granted, free of charge, to any person obtaining a copy 4 | // of this software and associated documentation files (the "Software"), to 5 | // deal in the Software without restriction, including without limitation the 6 | // rights to use, copy, modify, merge, publish, distribute, sublicense, and/or 7 | // sell copies of the Software, and to permit persons to whom the Software is 8 | // furnished to do so, subject to the following conditions: 9 | // 10 | // The above copyright notice and this permission notice shall be included in 11 | // all copies or substantial portions of the Software. 12 | // 13 | // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 14 | // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 15 | // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 16 | // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 17 | // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING 18 | // FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS 19 | // IN THE SOFTWARE. 20 | 21 | 22 | import Builtins, Exceptions, Sys 23 | 24 | 25 | 26 | func test_simple_add_field(): 27 | class C: 28 | pass 29 | 30 | c := C.new() 31 | C.set_field("x", 1) 32 | assert c.x == 1 33 | 34 | 35 | func test_nested_add_field(): 36 | class B: 37 | pass 38 | 39 | class C(B): 40 | pass 41 | 42 | c := C.new() 43 | B.set_field("x", 1) 44 | assert c.x == 1 45 | 46 | 47 | func main(): 48 | 49 | // We want to check that the JIT handles nested adding of fields, so we embed everything in a 50 | // sufficiently long loop that we can be sure that the JIT is operating. 51 | 52 | i := 0 53 | while i < 100000: 54 | test_simple_add_field() 55 | i += 1 56 | 57 | i := 0 58 | while i < 100000: 59 | test_nested_add_field() 60 | i += 1 -------------------------------------------------------------------------------- /tests/lang/builtins/int1.cv: -------------------------------------------------------------------------------- 1 | // Copyright (c) 2011 King's College London, created by Laurence Tratt 2 | // 3 | // Permission is hereby granted, free of charge, to any person obtaining a copy 4 | // of this software and associated documentation files (the "Software"), to 5 | // deal in the Software without restriction, including without limitation the 6 | // rights to use, copy, modify, merge, publish, distribute, sublicense, and/or 7 | // sell copies of the Software, and to permit persons to whom the Software is 8 | // furnished to do so, subject to the following conditions: 9 | // 10 | // The above copyright notice and this permission notice shall be included in 11 | // all copies or substantial portions of the Software. 12 | // 13 | // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 14 | // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 15 | // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 16 | // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 17 | // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING 18 | // FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS 19 | // IN THE SOFTWARE. 20 | 21 | 22 | import Builtins, Sys 23 | 24 | 25 | 26 | func test_add(): 27 | assert 0 + 0 == 0 28 | 29 | 30 | func test_equality(): 31 | assert 0 == 0 32 | assert 0 == -0 33 | assert 0 != 1 34 | 35 | 36 | func test_identity(): 37 | assert 0 is 0 38 | assert 1 is 3 - 2 39 | assert not 0 is 1 40 | 41 | 42 | func main(): 43 | 44 | test_add() 45 | test_equality() 46 | test_identity() -------------------------------------------------------------------------------- /tests/lang/builtins/list1.cv: -------------------------------------------------------------------------------- 1 | // Copyright (c) 2011 King's College London, created by Laurence Tratt 2 | // 3 | // Permission is hereby granted, free of charge, to any person obtaining a copy 4 | // of this software and associated documentation files (the "Software"), to 5 | // deal in the Software without restriction, including without limitation the 6 | // rights to use, copy, modify, merge, publish, distribute, sublicense, and/or 7 | // sell copies of the Software, and to permit persons to whom the Software is 8 | // furnished to do so, subject to the following conditions: 9 | // 10 | // The above copyright notice and this permission notice shall be included in 11 | // all copies or substantial portions of the Software. 12 | // 13 | // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 14 | // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 15 | // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 16 | // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 17 | // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING 18 | // FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS 19 | // IN THE SOFTWARE. 20 | 21 | 22 | import Builtins, Sys 23 | 24 | 25 | 26 | func test_add(): 27 | assert [] + [] == [] 28 | assert [[]] + [] == [[]] 29 | assert [] + [[]] == [[]] 30 | assert [1] + [2] == [1, 2] 31 | 32 | 33 | func test_equality(): 34 | assert [] == [] 35 | assert [[]] == [[]] 36 | assert [1,2,3] == [1,2,3] 37 | assert [1,2,3] != [1,2] 38 | assert [1,2,3] != [1,2,3,4] 39 | assert not [1,2,3] == [1,2] 40 | assert not [1,2,3] == [1,2,3,4] 41 | 42 | 43 | func test_flattening(): 44 | assert [].flattened() == [] 45 | assert [[]].flattened() == [] 46 | assert [[[]]].flattened() == [] 47 | assert [1, 2, [3, [4, 5]], 6].flattened() == [1, 2, 3, 4, 5, 6] 48 | 49 | 50 | func test_mult(): 51 | assert [] * 0 == [] 52 | assert [1] * 0 == [] 53 | assert [1] * 1 == [1] 54 | assert [1] * 2 == [1, 1] 55 | assert [1, 2] * 2 == [1, 2, 1, 2] 56 | 57 | 58 | func test_removal(): 59 | x := [1,2,3,2] 60 | x.remove(2) 61 | assert x == [1,3,2] 62 | x := [1,2,3,2] 63 | for x.remove(2) 64 | assert x == [1,3] 65 | 66 | 67 | func test_slicing(): 68 | assert [1,2,3][1:2] == [2] 69 | x := [1,2,3,4] 70 | x[1:3] := [5,6] 71 | assert x == [1,5,6,4] 72 | x := [1,2,3,4] 73 | x[1:3] := [5] 74 | assert x == [1,5,4] 75 | x := [1,2,3,4] 76 | x[1:3] := [] 77 | assert x == [1,4] 78 | 79 | 80 | func main(): 81 | 82 | test_add() 83 | test_equality() 84 | test_flattening() 85 | test_mult() 86 | test_removal() 87 | test_slicing() 88 | -------------------------------------------------------------------------------- /tests/lang/builtins/str1.cv: -------------------------------------------------------------------------------- 1 | // Copyright (c) 2011 King's College London, created by Laurence Tratt 2 | // 3 | // Permission is hereby granted, free of charge, to any person obtaining a copy 4 | // of this software and associated documentation files (the "Software"), to 5 | // deal in the Software without restriction, including without limitation the 6 | // rights to use, copy, modify, merge, publish, distribute, sublicense, and/or 7 | // sell copies of the Software, and to permit persons to whom the Software is 8 | // furnished to do so, subject to the following conditions: 9 | // 10 | // The above copyright notice and this permission notice shall be included in 11 | // all copies or substantial portions of the Software. 12 | // 13 | // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 14 | // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 15 | // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 16 | // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 17 | // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING 18 | // FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS 19 | // IN THE SOFTWARE. 20 | 21 | 22 | import Sys 23 | 24 | 25 | 26 | func test_casing(): 27 | assert "abcdef".lower_cased() == "abcdef" 28 | assert "ABCdef".lower_cased() == "abcdef" 29 | assert "ABCDEF".lower_cased() == "abcdef" 30 | assert "abcdef".upper_cased() == "ABCDEF" 31 | assert "abcDEF".upper_cased() == "ABCDEF" 32 | assert "ABCDEF".upper_cased() == "ABCDEF" 33 | 34 | 35 | func test_equality(): 36 | assert "abc" == "abc" 37 | assert "a" != "b" 38 | assert "a" < "b" 39 | assert not "b" < "a" 40 | assert "b" > "a" 41 | assert not "a" > "b" 42 | 43 | 44 | func test_finding(): 45 | assert "abc".find("a") == "a" 46 | assert "abc".find("c") == "c" 47 | assert "abc".find("abc") == "abc" 48 | assert not "abc".find("d") 49 | assert not "abc".find("abcd") 50 | i := 0 51 | for x := "abcaa".find("a"): 52 | assert x == "a" 53 | i += 1 54 | assert i == 3 55 | i := 0 56 | for x := "abcaa".find_index("a"): 57 | if i == 0: 58 | assert x == 0 59 | elif i == 1: 60 | assert x == 3 61 | elif i == 2: 62 | assert x == 4 63 | i += 1 64 | assert i == 3 65 | i := 0 66 | for x := "abcaa".rfind_index("a"): 67 | if i == 0: 68 | assert x == 4 69 | elif i == 1: 70 | assert x == 3 71 | elif i == 2: 72 | assert x == 0 73 | i += 1 74 | assert i == 3 75 | 76 | 77 | func test_prefixing_suffixing(): 78 | assert "abc".prefixed_by("a") 79 | assert "abc".prefixed_by("abc") 80 | assert not "abc".prefixed_by("bc") 81 | assert "abc".prefixed_by("bc", 1) 82 | assert "abc".suffixed_by("c") 83 | assert "abc".suffixed_by("abc") 84 | assert "abc".suffixed_by("ab", -1) 85 | assert not "abc".suffixed_by("ab") 86 | 87 | 88 | func test_replacing(): 89 | assert "abc".replaced("a", "d") == "dbc" 90 | assert "abc".replaced("c", "d") == "abd" 91 | assert "abc".replaced("d", "") == "abc" 92 | assert "abc".replaced("abc", "def") == "def" 93 | assert "aa".replaced("a", "b") == "bb" 94 | assert "aa".replaced("a", "ab") == "abab" 95 | assert "aa".replaced("a", "bc") == "bcbc" 96 | assert "aa".replaced("a", "ba") == "baba" 97 | 98 | 99 | func test_stripping(): 100 | assert " \t \tabc ".stripped() == "abc" 101 | assert " \t \tabc \t \t".lstripped() == "abc \t \t" 102 | assert "abc".stripped() == "abc" 103 | 104 | 105 | func main(): 106 | 107 | test_casing() 108 | test_equality() 109 | test_finding() 110 | test_replacing() 111 | test_stripping() 112 | test_prefixing_suffixing() -------------------------------------------------------------------------------- /tests/lang/builtins/tests.cv: -------------------------------------------------------------------------------- 1 | // Copyright (c) 2011 King's College London, created by Laurence Tratt 2 | // 3 | // Permission is hereby granted, free of charge, to any person obtaining a copy 4 | // of this software and associated documentation files (the "Software"), to 5 | // deal in the Software without restriction, including without limitation the 6 | // rights to use, copy, modify, merge, publish, distribute, sublicense, and/or 7 | // sell copies of the Software, and to permit persons to whom the Software is 8 | // furnished to do so, subject to the following conditions: 9 | // 10 | // The above copyright notice and this permission notice shall be included in 11 | // all copies or substantial portions of the Software. 12 | // 13 | // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 14 | // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 15 | // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 16 | // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 17 | // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING 18 | // FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS 19 | // IN THE SOFTWARE. 20 | 21 | 22 | import Sys 23 | import Lang_Test 24 | 25 | 26 | 27 | 28 | tests := $<>: 29 | "class1.cv" 30 | "int1.cv" 31 | "list1.cv" 32 | "str1.cv" 33 | 34 | 35 | 36 | func main(): 37 | 38 | if tests.new().run_all() != 0: 39 | Sys::exit(1) 40 | -------------------------------------------------------------------------------- /tests/lang/namespaces/.gitignore: -------------------------------------------------------------------------------- 1 | ns[1-9] 2 | qq[1-9] 3 | tests 4 | -------------------------------------------------------------------------------- /tests/lang/namespaces/Makefile.in: -------------------------------------------------------------------------------- 1 | include @abs_top_srcdir@/Makefile.inc 2 | 3 | 4 | TESTS = ns1 ns2 ns3 ns4 ns5 ns6 qq1 qq2 qq3 qq4 qq5 qq6 qq7 5 | 6 | 7 | all: 8 | ${CONVERGE_VM} ${CONVERGEC} -I .. -m tests.cv 9 | 10 | clean: 11 | ${foreach test,${TESTS},rm -f ${test} ${test}.cvb} 12 | rm -f tests.cvb tests 13 | 14 | distclean: clean 15 | rm -f Makefile 16 | 17 | regress: all 18 | ${CONVERGE_VM} tests 19 | -------------------------------------------------------------------------------- /tests/lang/namespaces/ns1.cv: -------------------------------------------------------------------------------- 1 | import Sys 2 | 3 | 4 | func main(): 5 | 6 | x := 2 7 | 8 | func () { 9 | x := 4 10 | }() 11 | 12 | assert x == 2 13 | -------------------------------------------------------------------------------- /tests/lang/namespaces/ns2.cv: -------------------------------------------------------------------------------- 1 | import Sys 2 | 3 | 4 | func main(): 5 | 6 | x := 2 7 | 8 | func () { 9 | nonlocal x 10 | x := 4 11 | }() 12 | 13 | assert x == 4 14 | -------------------------------------------------------------------------------- /tests/lang/namespaces/ns3.cv: -------------------------------------------------------------------------------- 1 | import CEI, Sys 2 | 3 | 4 | 5 | x := 2 6 | 7 | func f(): 8 | 9 | rename x as y 10 | 11 | x := 10 12 | y += 2 13 | 14 | 15 | 16 | func main(): 17 | 18 | assert x == 2 19 | f() 20 | assert x == 4 21 | -------------------------------------------------------------------------------- /tests/lang/namespaces/ns4.cv: -------------------------------------------------------------------------------- 1 | import CEI, Sys 2 | 3 | 4 | 5 | x := 2 6 | 7 | func f(): 8 | 9 | rename $c 10 | 11 | x := 10 12 | y += 2 13 | 14 | 15 | 16 | func main(): 17 | 18 | assert x == 2 19 | f() 20 | assert x == 4 21 | -------------------------------------------------------------------------------- /tests/lang/namespaces/ns5.cv: -------------------------------------------------------------------------------- 1 | import CEI, Sys 2 | 3 | 4 | 5 | func main(): 6 | 7 | [| 8 | func x(): 9 | pass 10 | |] 11 | -------------------------------------------------------------------------------- /tests/lang/namespaces/ns6.cv: -------------------------------------------------------------------------------- 1 | // 2 | // Check that we can't rename a variable which doesn't exist. 3 | // 4 | 5 | 6 | import CEI, Sys 7 | 8 | 9 | 10 | func main(): 11 | rename x as y 12 | pass 13 | -------------------------------------------------------------------------------- /tests/lang/namespaces/ns7.cv: -------------------------------------------------------------------------------- 1 | // 2 | // Check that we can't access a renamed variable. 3 | // 4 | 5 | 6 | import CEI, Sys 7 | 8 | 9 | 10 | x := 2 11 | 12 | func main(): 13 | rename x as y 14 | z := x 15 | -------------------------------------------------------------------------------- /tests/lang/namespaces/qq1.cv: -------------------------------------------------------------------------------- 1 | import Sys 2 | 3 | 4 | 5 | x := 2 6 | 7 | func f(): 8 | 9 | return [| 10 | func (): 11 | x += 2 12 | |] 13 | 14 | 15 | 16 | func main(): 17 | 18 | $() 19 | -------------------------------------------------------------------------------- /tests/lang/namespaces/qq2.cv: -------------------------------------------------------------------------------- 1 | import Sys 2 | 3 | 4 | 5 | x := 2 6 | 7 | func f(): 8 | 9 | return [| 10 | func (): 11 | nonlocal x 12 | 13 | x += 2 14 | |] 15 | 16 | 17 | 18 | func main(): 19 | 20 | $() 21 | assert x == 4 22 | -------------------------------------------------------------------------------- /tests/lang/namespaces/qq3.cv: -------------------------------------------------------------------------------- 1 | import CEI, Sys 2 | 3 | 4 | 5 | x := 2 6 | 7 | func f(): 8 | 9 | return [| 10 | func (): 11 | rename x as y 12 | 13 | x := 10 14 | y += 2 15 | |] 16 | 17 | 18 | 19 | func main(): 20 | 21 | assert x == 2 22 | $() 23 | assert x == 4 24 | -------------------------------------------------------------------------------- /tests/lang/namespaces/qq4.cv: -------------------------------------------------------------------------------- 1 | import CEI, Sys 2 | 3 | 4 | 5 | x := 2 6 | 7 | func f(): 8 | 9 | y := CEI::ivar(CEI::fresh_name()) 10 | 11 | return [| 12 | func (): 13 | rename x as $c{y} 14 | 15 | $c{y} += 2 16 | |] 17 | 18 | 19 | 20 | func main(): 21 | 22 | assert x == 2 23 | $() 24 | assert x == 4 25 | -------------------------------------------------------------------------------- /tests/lang/namespaces/qq5.cv: -------------------------------------------------------------------------------- 1 | import CEI, Sys 2 | 3 | 4 | 5 | x := 2 6 | 7 | func f(): 8 | 9 | y := CEI::ivar(CEI::fresh_name()) 10 | x := CEI::ivar("x") 11 | 12 | return [| 13 | func (): 14 | rename $c{x} as $c{y} 15 | 16 | $c{y} += 2 17 | |] 18 | 19 | 20 | 21 | func main(): 22 | 23 | assert x == 2 24 | $c() 25 | assert x == 4 26 | -------------------------------------------------------------------------------- /tests/lang/namespaces/qq6.cv: -------------------------------------------------------------------------------- 1 | import CEI, Sys 2 | 3 | 4 | 5 | x := 2 6 | 7 | func f(): 8 | 9 | y := CEI::ivar(CEI::fresh_name()) 10 | 11 | it := [| 12 | func (z := 2): 13 | rename x as $c{y} 14 | 15 | $c{y} += 2 16 | z 17 | |] 18 | Sys::println(CEI::pp_itree(it)) 19 | 20 | return it 21 | 22 | 23 | 24 | func main(): 25 | 26 | Sys::println(x) 27 | $c() 28 | Sys::println(x) 29 | -------------------------------------------------------------------------------- /tests/lang/namespaces/qq7.cv: -------------------------------------------------------------------------------- 1 | // 2 | // Check that inside quasi-quotes we can't rename a variable which doesn't exist. 3 | // 4 | 5 | 6 | import CEI, Sys 7 | 8 | 9 | 10 | func main(): 11 | 12 | [| 13 | func (): 14 | rename x as y 15 | pass 16 | |] 17 | -------------------------------------------------------------------------------- /tests/lang/namespaces/qq8.cv: -------------------------------------------------------------------------------- 1 | // 2 | // Check that we can't access a renamed variable. 3 | // 4 | 5 | 6 | import CEI, Sys 7 | 8 | 9 | 10 | x := 2 11 | 12 | func main(): 13 | [| 14 | func f(): 15 | rename x as y 16 | z := x 17 | |] 18 | -------------------------------------------------------------------------------- /tests/lang/namespaces/tests.cv: -------------------------------------------------------------------------------- 1 | // Copyright (c) 2008 Laurence Tratt 2 | // 3 | // Permission is hereby granted, free of charge, to any person obtaining a copy 4 | // of this software and associated documentation files (the "Software"), to 5 | // deal in the Software without restriction, including without limitation the 6 | // rights to use, copy, modify, merge, publish, distribute, sublicense, and/or 7 | // sell copies of the Software, and to permit persons to whom the Software is 8 | // furnished to do so, subject to the following conditions: 9 | // 10 | // The above copyright notice and this permission notice shall be included in 11 | // all copies or substantial portions of the Software. 12 | // 13 | // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 14 | // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 15 | // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 16 | // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 17 | // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING 18 | // FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS 19 | // IN THE SOFTWARE. 20 | 21 | 22 | import Sys 23 | import Lang_Test 24 | 25 | 26 | 27 | 28 | tests := $<>: 29 | "ns1.cv" 30 | 31 | "ns2.cv" 32 | 33 | "ns3.cv" 34 | 35 | "ns4.cv" 36 | 37 | "ns5.cv" 38 | 39 | "ns6.cv": 40 | ctime exception "Unknown variable 'x'." 41 | 42 | "ns7.cv": 43 | ctime exception "Variable 'x' not in scope (renamed to 'y')." 44 | 45 | "qq1.cv": 46 | rtime exception "Unassigned_Var_Exception" 47 | 48 | "qq2.cv" 49 | 50 | "qq3.cv" 51 | 52 | "qq4.cv" 53 | 54 | "qq5.cv" 55 | 56 | "qq6.cv" 57 | 58 | "qq7.cv": 59 | ctime exception "Unknown variable 'x'." 60 | 61 | "qq8.cv": 62 | ctime exception "Variable 'x' not in scope (renamed to 'y')." 63 | 64 | 65 | 66 | 67 | func main(): 68 | 69 | if tests.new().run_all() != 0: 70 | Sys::exit(1) 71 | -------------------------------------------------------------------------------- /tests/lang/splicing/.gitignore: -------------------------------------------------------------------------------- 1 | result[1-9] 2 | tests 3 | type[1-9] -------------------------------------------------------------------------------- /tests/lang/splicing/Makefile.in: -------------------------------------------------------------------------------- 1 | include @abs_top_srcdir@/Makefile.inc 2 | 3 | 4 | TESTS = result1 result2 result3 result4 type1 type2 5 | 6 | 7 | all: 8 | ${CONVERGE_VM} ${CONVERGEC} -I .. -m tests.cv 9 | 10 | clean: 11 | ${foreach test,${TESTS},rm -f ${test} ${test}.cvb} 12 | rm -f tests.cvb tests 13 | 14 | distclean: clean 15 | rm -f Makefile 16 | 17 | regress: all 18 | ${CONVERGE_VM} tests 19 | -------------------------------------------------------------------------------- /tests/lang/splicing/result1.cv: -------------------------------------------------------------------------------- 1 | func main(): 2 | // Check that valid values can be returned from splices. 3 | 4 | $<[| x := 2 |]> 5 | $c<[| x := 2 |]> 6 | $p -------------------------------------------------------------------------------- /tests/lang/splicing/result2.cv: -------------------------------------------------------------------------------- 1 | func main(): 2 | // Check that invalid values can't be returned from a splice. 3 | 4 | $ 5 | -------------------------------------------------------------------------------- /tests/lang/splicing/result3.cv: -------------------------------------------------------------------------------- 1 | func main(): 2 | // Check that invalid values can't be returned from a splice. 3 | 4 | $c 5 | -------------------------------------------------------------------------------- /tests/lang/splicing/result4.cv: -------------------------------------------------------------------------------- 1 | func main(): 2 | // Check that invalid values can't be returned from a splice. 3 | 4 | $c<2> 5 | -------------------------------------------------------------------------------- /tests/lang/splicing/tests.cv: -------------------------------------------------------------------------------- 1 | // Copyright (c) 2008 Laurence Tratt 2 | // 3 | // Permission is hereby granted, free of charge, to any person obtaining a copy 4 | // of this software and associated documentation files (the "Software"), to 5 | // deal in the Software without restriction, including without limitation the 6 | // rights to use, copy, modify, merge, publish, distribute, sublicense, and/or 7 | // sell copies of the Software, and to permit persons to whom the Software is 8 | // furnished to do so, subject to the following conditions: 9 | // 10 | // The above copyright notice and this permission notice shall be included in 11 | // all copies or substantial portions of the Software. 12 | // 13 | // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 14 | // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 15 | // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 16 | // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 17 | // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING 18 | // FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS 19 | // IN THE SOFTWARE. 20 | 21 | 22 | import Sys 23 | import Lang_Test 24 | 25 | 26 | 27 | 28 | tests := $<>: 29 | "type1.cv" 30 | 31 | "type2.cv": 32 | ctime exception "Unknown variable 'x'." 33 | 34 | "result1.cv" 35 | 36 | "result2.cv": 37 | ctime exception "Splice returned null" 38 | 39 | "result3.cv": 40 | ctime exception "Splice returned null" 41 | 42 | "result4.cv": 43 | ctime exception "Splice returned 'Int' instead of '[IRoot, List(IRoot)]'" 44 | 45 | 46 | 47 | 48 | func main(): 49 | 50 | if tests.new().run_all() != 0: 51 | Sys::exit(1) 52 | -------------------------------------------------------------------------------- /tests/lang/splicing/type1.cv: -------------------------------------------------------------------------------- 1 | func main(): 2 | // Check that all the valid splice types exist. 3 | 4 | $<[| 1 |]> 5 | $c<[| 1 |]> 6 | $p<[| 1 |]> -------------------------------------------------------------------------------- /tests/lang/splicing/type2.cv: -------------------------------------------------------------------------------- 1 | func main(): 2 | // Check that invalid splice types can't be specified. 3 | 4 | $r<[| 1| ]> -------------------------------------------------------------------------------- /tests/threads/Makefile.in: -------------------------------------------------------------------------------- 1 | include @abs_top_srcdir@/Makefile.inc 2 | 3 | 4 | all: 5 | cd @CON_THREAD_TEST_DIR@ && ${MAKE} ${MFLAGS} 6 | 7 | clean: 8 | cd pthreads && ${MAKE} ${MFLAGS} clean 9 | cd single_thread && ${MAKE} ${MFLAGS} clean 10 | 11 | distclean: 12 | cd pthreads && ${MAKE} ${MFLAGS} distclean 13 | cd single_thread && ${MAKE} ${MFLAGS} distclean 14 | rm -f Makefile 15 | -------------------------------------------------------------------------------- /tests/threads/pthreads/1.cv: -------------------------------------------------------------------------------- 1 | // Copyright (c) 2003-2006 King's College London, created by Laurence Tratt 2 | // 3 | // Permission is hereby granted, free of charge, to any person obtaining a copy 4 | // of this software and associated documentation files (the "Software"), to 5 | // deal in the Software without restriction, including without limitation the 6 | // rights to use, copy, modify, merge, publish, distribute, sublicense, and/or 7 | // sell copies of the Software, and to permit persons to whom the Software is 8 | // furnished to do so, subject to the following conditions: 9 | // 10 | // The above copyright notice and this permission notice shall be included in 11 | // all copies or substantial portions of the Software. 12 | // 13 | // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 14 | // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 15 | // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 16 | // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 17 | // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING 18 | // FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS 19 | // IN THE SOFTWARE. 20 | 21 | 22 | import PThreads, Sys 23 | 24 | 25 | 26 | result := [] 27 | 28 | func run(): 29 | 30 | nonlocal result 31 | 32 | result.append(result.len()) 33 | 34 | for x := result.iter(): 35 | pass 36 | 37 | for i := 0.iter_to(1000): 38 | if i == result.len(): 39 | result.append(i) 40 | 41 | Sys::println(result.len()) 42 | 43 | 44 | func main(): 45 | 46 | threads := [] 47 | for i := 0.iter_to(100): 48 | thread := PThreads::PThread.new(run) 49 | threads.append(thread) 50 | thread.start() 51 | 52 | for thread := threads.iter(): 53 | thread.join() 54 | 55 | Sys::println("Final: ", result) 56 | -------------------------------------------------------------------------------- /tests/threads/pthreads/Makefile.in: -------------------------------------------------------------------------------- 1 | include @abs_top_srcdir@/Makefile.inc 2 | 3 | OBJ_FILES = 1.cvb 4 | 5 | 6 | %.cvb: %.cv 7 | ${CONVERGE_VM} ${CONVERGEC} -o $@ $< 8 | 9 | 10 | all: 1 11 | 12 | 1: ${OBJ_FILES} ${CONVERGE_LIB} 13 | ${CONVERGE_VM} ${CONVERGEL} -o 1 1.cvb ${OBJ_FILES} 14 | 15 | clean: 16 | rm -f convergep ${OBJ_FILES} 17 | 18 | distclean: clean 19 | rm -f Makefile 20 | -------------------------------------------------------------------------------- /tests/threads/single_thread/Makefile.in: -------------------------------------------------------------------------------- 1 | all: 2 | 3 | clean: 4 | 5 | distclean: 6 | rm -f Makefile 7 | -------------------------------------------------------------------------------- /vm/.gitignore: -------------------------------------------------------------------------------- 1 | *.pyc 2 | converge 3 | Config.py -------------------------------------------------------------------------------- /vm/Config.py.in: -------------------------------------------------------------------------------- 1 | # Copyright (c) 2011 King's College London, created by Laurence Tratt 2 | # 3 | # Permission is hereby granted, free of charge, to any person obtaining a copy 4 | # of this software and associated documentation files (the "Software"), to 5 | # deal in the Software without restriction, including without limitation the 6 | # rights to use, copy, modify, merge, publish, distribute, sublicense, and/or 7 | # sell copies of the Software, and to permit persons to whom the Software is 8 | # furnished to do so, subject to the following conditions: 9 | # 10 | # The above copyright notice and this permission notice shall be included in 11 | # all copies or substantial portions of the Software. 12 | # 13 | # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 14 | # IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 15 | # FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 16 | # AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 17 | # LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING 18 | # FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS 19 | # IN THE SOFTWARE. 20 | 21 | import time 22 | 23 | 24 | CON_VERSION = "@CONVERGE_VERSION@" 25 | CON_DATE = "@CONVERGE_DATE@" 26 | 27 | PLATFORM = "@PLATFORM@" 28 | 29 | # Stuff needed for building the system. 30 | 31 | def _sanitise(dirs): 32 | dirs = dirs.strip() 33 | if not dirs: 34 | return [] 35 | else: 36 | return [x for x in dirs.split(" ") if x != ""] 37 | 38 | LIBPCRE_INCLUDE_DIRS = _sanitise("@LIBPCRE_INCLUDE_DIRS@") 39 | LIBPCRE_LIBRARY_DIRS = _sanitise("@LIBPCRE_LIBRARY_DIRS@") 40 | LIBPCRE_LIBRARIES = _sanitise("@LIBPCRE_LIBRARIES@") 41 | LIBPCRE_LINK_FLAGS = _sanitise("@LIBPCRE_LINK_FLAGS@") 42 | LIBPCRE_A = "@LIBPCRE_A@" 43 | 44 | LIBXML2_INCLUDE_DIRS = _sanitise("@LIBXML2_INCLUDE_DIRS@") 45 | LIBXML2_LIBRARY_DIRS = _sanitise("@LIBXML2_LIBRARY_DIRS@") 46 | LIBXML2_LIBRARIES = _sanitise("@LIBXML2_LIBRARIES@") 47 | LIBXML2_LINK_FLAGS = _sanitise("@LIBXML2_LINK_FLAGS@") 48 | LIBXML2_A = "@LIBXML2_A@" -------------------------------------------------------------------------------- /vm/Makefile.in: -------------------------------------------------------------------------------- 1 | PYTHON=@PYTHON@ 2 | RPYTHON=@RPYTHON@ 3 | INSTALL=@INSTALL@ 4 | bindir=@bindir@ 5 | 6 | all: converge 7 | 8 | converge: *.py Modules/*.py 9 | ${PYTHON} ${RPYTHON} -O@RPYTHON_OPT@ @NO_ASMGCC_HACK@ --output=converge main.py 10 | 11 | install: 12 | ${INSTALL} -d ${DESTDIR}${bindir} 13 | ${INSTALL} -c -m 555 converge@EXEC_EXT@ ${DESTDIR}${bindir} 14 | 15 | clean: 16 | rm -rf converge 17 | 18 | distclean: clean 19 | rm -f Makefile 20 | -------------------------------------------------------------------------------- /vm/Modules/Con_C_Platform_Env.py: -------------------------------------------------------------------------------- 1 | # Copyright (c) 2011 King's College London, created by Laurence Tratt 2 | # 3 | # Permission is hereby granted, free of charge, to any person obtaining a copy 4 | # of this software and associated documentation files (the "Software"), to 5 | # deal in the Software without restriction, including without limitation the 6 | # rights to use, copy, modify, merge, publish, distribute, sublicense, and/or 7 | # sell copies of the Software, and to permit persons to whom the Software is 8 | # furnished to do so, subject to the following conditions: 9 | # 10 | # The above copyright notice and this permission notice shall be included in 11 | # all copies or substantial portions of the Software. 12 | # 13 | # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 14 | # IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 15 | # FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 16 | # AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 17 | # LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING 18 | # FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS 19 | # IN THE SOFTWARE. 20 | 21 | 22 | from Builtins import * 23 | 24 | 25 | 26 | 27 | def init(vm): 28 | return new_c_con_module(vm, "C_Platform_Env", "C_Platform_Env", __file__, import_, \ 29 | ["find_var", "get_var", "set_var"]) 30 | 31 | 32 | @con_object_proc 33 | def import_(vm): 34 | (mod,),_ = vm.decode_args("O") 35 | 36 | return vm.get_builtin(BUILTIN_NULL_OBJ) 37 | -------------------------------------------------------------------------------- /vm/Modules/Con_C_Platform_Exec.py: -------------------------------------------------------------------------------- 1 | # Copyright (c) 2011 King's College London, created by Laurence Tratt 2 | # 3 | # Permission is hereby granted, free of charge, to any person obtaining a copy 4 | # of this software and associated documentation files (the "Software"), to 5 | # deal in the Software without restriction, including without limitation the 6 | # rights to use, copy, modify, merge, publish, distribute, sublicense, and/or 7 | # sell copies of the Software, and to permit persons to whom the Software is 8 | # furnished to do so, subject to the following conditions: 9 | # 10 | # The above copyright notice and this permission notice shall be included in 11 | # all copies or substantial portions of the Software. 12 | # 13 | # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 14 | # IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 15 | # FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 16 | # AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 17 | # LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING 18 | # FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS 19 | # IN THE SOFTWARE. 20 | 21 | 22 | import os 23 | from rpython.rtyper.lltypesystem import lltype, rffi 24 | from rpython.rtyper.tool import rffi_platform as platform 25 | from rpython.rlib import rarithmetic, rposix 26 | from rpython.translator.tool.cbuild import ExternalCompilationInfo 27 | from Builtins import * 28 | 29 | 30 | 31 | eci = ExternalCompilationInfo(includes=["stdlib.h"]) 32 | 33 | system = rffi.llexternal("system", [rffi.CCHARP], rffi.INT, compilation_info=eci) 34 | 35 | class CConfig: 36 | _compilation_info_ = eci 37 | 38 | cconfig = platform.configure(CConfig) 39 | 40 | 41 | 42 | def init(vm): 43 | return new_c_con_module(vm, "C_Platform_Exec", "C_Platform_Exec", __file__, import_, \ 44 | ["sh_cmd"]) 45 | 46 | 47 | @con_object_proc 48 | def import_(vm): 49 | (mod,),_ = vm.decode_args("O") 50 | 51 | new_c_con_func_for_mod(vm, "sh_cmd", sh_cmd, mod) 52 | 53 | return vm.get_builtin(BUILTIN_NULL_OBJ) 54 | 55 | 56 | @con_object_proc 57 | def sh_cmd(vm): 58 | (cmd_o,),_ = vm.decode_args("S") 59 | assert isinstance(cmd_o, Con_String) 60 | 61 | r = system(cmd_o.v) 62 | if r == -1: 63 | vm.raise_helper("Exception", [Con_String(vm, os.strerror(rposix.get_saved_errno()))]) 64 | 65 | return Con_Int(vm, os.WEXITSTATUS(r)) 66 | -------------------------------------------------------------------------------- /vm/Modules/Con_C_Platform_Host.py: -------------------------------------------------------------------------------- 1 | # Copyright (c) 2011 King's College London, created by Laurence Tratt 2 | # 3 | # Permission is hereby granted, free of charge, to any person obtaining a copy 4 | # of this software and associated documentation files (the "Software"), to 5 | # deal in the Software without restriction, including without limitation the 6 | # rights to use, copy, modify, merge, publish, distribute, sublicense, and/or 7 | # sell copies of the Software, and to permit persons to whom the Software is 8 | # furnished to do so, subject to the following conditions: 9 | # 10 | # The above copyright notice and this permission notice shall be included in 11 | # all copies or substantial portions of the Software. 12 | # 13 | # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 14 | # IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 15 | # FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 16 | # AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 17 | # LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING 18 | # FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS 19 | # IN THE SOFTWARE. 20 | 21 | 22 | from rpython.rlib import rsocket 23 | from Builtins import * 24 | 25 | 26 | 27 | 28 | def init(vm): 29 | return new_c_con_module(vm, "C_Platform_Host", "C_Platform_Host", __file__, import_, \ 30 | ["get_hostname"]) 31 | 32 | 33 | @con_object_proc 34 | def import_(vm): 35 | (mod,),_ = vm.decode_args("O") 36 | 37 | new_c_con_func_for_mod(vm, "get_hostname", get_hostname, mod) 38 | 39 | return vm.get_builtin(BUILTIN_NULL_OBJ) 40 | 41 | 42 | @con_object_proc 43 | def get_hostname(vm): 44 | _,_ = vm.decode_args() 45 | 46 | return Con_String(vm, rsocket.gethostname()) 47 | -------------------------------------------------------------------------------- /vm/Modules/Con_C_Platform_Properties.py: -------------------------------------------------------------------------------- 1 | # Copyright (c) 2011 King's College London, created by Laurence Tratt 2 | # 3 | # Permission is hereby granted, free of charge, to any person obtaining a copy 4 | # of this software and associated documentation files (the "Software"), to 5 | # deal in the Software without restriction, including without limitation the 6 | # rights to use, copy, modify, merge, publish, distribute, sublicense, and/or 7 | # sell copies of the Software, and to permit persons to whom the Software is 8 | # furnished to do so, subject to the following conditions: 9 | # 10 | # The above copyright notice and this permission notice shall be included in 11 | # all copies or substantial portions of the Software. 12 | # 13 | # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 14 | # IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 15 | # FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 16 | # AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 17 | # LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING 18 | # FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS 19 | # IN THE SOFTWARE. 20 | 21 | 22 | import os, sys 23 | import Config 24 | from Builtins import * 25 | from Core import * 26 | 27 | 28 | 29 | 30 | 31 | def init(vm): 32 | return new_c_con_module(vm, "C_Platform_Properties", "C_Platform_Properties", __file__, \ 33 | import_, \ 34 | ["word_bits", "LITTLE_ENDIAN", "BIG_ENDIAN", "endianness", "osname", \ 35 | "case_sensitive_filenames"]) 36 | 37 | 38 | @con_object_proc 39 | def import_(vm): 40 | (mod,),_ = vm.decode_args("O") 41 | 42 | mod.set_defn(vm, "word_bits", Con_Int(vm, Target.INTSIZE * 8)) 43 | mod.set_defn(vm, "LITTLE_ENDIAN", Con_String(vm, "LITTLE_ENDIAN")) 44 | mod.set_defn(vm, "BIG_ENDIAN", Con_String(vm, "BIG_ENDIAN")) 45 | mod.set_defn(vm, "endianness", Con_String(vm, ENDIANNESS)) 46 | mod.set_defn(vm, "osname", Con_String(vm, Config.PLATFORM)) 47 | mod.set_defn(vm, "case_sensitive_filenames", Con_Int(vm, CASE_SENSITIVE_FILENAMES)) 48 | 49 | return vm.get_builtin(BUILTIN_NULL_OBJ) 50 | -------------------------------------------------------------------------------- /vm/Modules/Con_C_Strings.py: -------------------------------------------------------------------------------- 1 | # Copyright (c) 2011 King's College London, created by Laurence Tratt 2 | # 3 | # Permission is hereby granted, free of charge, to any person obtaining a copy 4 | # of this software and associated documentation files (the "Software"), to 5 | # deal in the Software without restriction, including without limitation the 6 | # rights to use, copy, modify, merge, publish, distribute, sublicense, and/or 7 | # sell copies of the Software, and to permit persons to whom the Software is 8 | # furnished to do so, subject to the following conditions: 9 | # 10 | # The above copyright notice and this permission notice shall be included in 11 | # all copies or substantial portions of the Software. 12 | # 13 | # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 14 | # IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 15 | # FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 16 | # AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 17 | # LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING 18 | # FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS 19 | # IN THE SOFTWARE. 20 | 21 | 22 | from Builtins import * 23 | 24 | 25 | 26 | 27 | def init(vm): 28 | return new_c_con_module(vm, "C_Strings", "C_Strings", __file__, import_, \ 29 | ["join"]) 30 | 31 | 32 | @con_object_proc 33 | def import_(vm): 34 | (mod,),_ = vm.decode_args("O") 35 | 36 | new_c_con_func_for_mod(vm, "join", join, mod) 37 | 38 | return vm.get_builtin(BUILTIN_NULL_OBJ) 39 | 40 | 41 | @con_object_proc 42 | def join(vm): 43 | (list_o, sep_o),_ = vm.decode_args("OS") 44 | assert isinstance(sep_o, Con_String) 45 | 46 | out = [] 47 | vm.pre_get_slot_apply_pump(list_o, "iter") 48 | while 1: 49 | e_o = vm.apply_pump() 50 | if not e_o: 51 | break 52 | out.append(type_check_string(vm, e_o).v) 53 | 54 | return Con_String(vm, sep_o.v.join(out)) 55 | -------------------------------------------------------------------------------- /vm/Modules/Con_C_Time.py: -------------------------------------------------------------------------------- 1 | # Copyright (c) 2011 King's College London, created by Laurence Tratt 2 | # 3 | # Permission is hereby granted, free of charge, to any person obtaining a copy 4 | # of this software and associated documentation files (the "Software"), to 5 | # deal in the Software without restriction, including without limitation the 6 | # rights to use, copy, modify, merge, publish, distribute, sublicense, and/or 7 | # sell copies of the Software, and to permit persons to whom the Software is 8 | # furnished to do so, subject to the following conditions: 9 | # 10 | # The above copyright notice and this permission notice shall be included in 11 | # all copies or substantial portions of the Software. 12 | # 13 | # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 14 | # IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 15 | # FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 16 | # AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 17 | # LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING 18 | # FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS 19 | # IN THE SOFTWARE. 20 | 21 | 22 | from rpython.rlib import rarithmetic 23 | from rpython.rtyper.lltypesystem import lltype, rffi 24 | from rpython.rtyper.tool import rffi_platform as platform 25 | from rpython.translator.tool.cbuild import ExternalCompilationInfo 26 | from Builtins import * 27 | 28 | 29 | 30 | eci = ExternalCompilationInfo(includes=["time.h", "sys/time.h"]) 31 | 32 | class CConfig: 33 | _compilation_info_ = eci 34 | TIMEVAL = platform.Struct("struct timeval", [("tv_sec", rffi.LONG), ("tv_usec", rffi.LONG)]) 35 | TIMEZONE = platform.Struct("struct timezone", []) 36 | TIMESPEC = platform.Struct("struct timespec", [("tv_sec", rffi.TIME_T), ("tv_nsec", rffi.LONG)]) 37 | CLOCK_MONOTONIC = platform.DefinedConstantInteger("CLOCK_MONOTONIC") 38 | 39 | cconfig = platform.configure(CConfig) 40 | 41 | TIMEVAL = cconfig["TIMEVAL"] 42 | TIMEVALP = lltype.Ptr(TIMEVAL) 43 | TIMEZONE = cconfig["TIMEZONE"] 44 | TIMEZONEP = lltype.Ptr(TIMEZONE) 45 | TIMESPEC = cconfig["TIMESPEC"] 46 | TIMESPECP = lltype.Ptr(TIMESPEC) 47 | CLOCK_MONOTONIC = cconfig["CLOCK_MONOTONIC"] 48 | 49 | gettimeofday = rffi.llexternal('gettimeofday', [TIMEVALP, TIMEZONEP], rffi.INT, compilation_info=eci) 50 | if platform.has("clock_gettime", "#include "): 51 | HAS_CLOCK_GETTIME = True 52 | clock_gettime = rffi.llexternal('clock_gettime', [rffi.INT, TIMESPECP], rffi.INT, compilation_info=eci) 53 | else: 54 | HAS_CLOCK_GETTIME = False 55 | 56 | 57 | def init(vm): 58 | return new_c_con_module(vm, "C_Time", "C_Time", __file__, import_, \ 59 | ["current", "current_mono"]) 60 | 61 | 62 | @con_object_proc 63 | def import_(vm): 64 | (mod,),_ = vm.decode_args("O") 65 | 66 | new_c_con_func_for_mod(vm, "current", current, mod) 67 | if HAS_CLOCK_GETTIME: 68 | new_c_con_func_for_mod(vm, "current_mono", current_mono, mod) 69 | else: 70 | # OS X, and maybe other OSs, doesn't have clock_gettime, so we fall back on a less accurate 71 | # timing method as being better than nothing. 72 | new_c_con_func_for_mod(vm, "current_mono", current, mod) 73 | 74 | return vm.get_builtin(BUILTIN_NULL_OBJ) 75 | 76 | 77 | @con_object_proc 78 | def current(vm): 79 | _,_ = vm.decode_args() 80 | 81 | with lltype.scoped_alloc(TIMEVAL) as tp: 82 | if gettimeofday(tp, lltype.nullptr(TIMEZONEP.TO)) != 0: 83 | raise Exception("XXX") 84 | sec = rarithmetic.r_int(tp.c_tv_sec) 85 | usec = rarithmetic.r_int(tp.c_tv_usec) 86 | 87 | return Con_List(vm, [Con_Int(vm, sec), Con_Int(vm, usec * 1000)]) 88 | 89 | 90 | @con_object_proc 91 | def current_mono(vm): 92 | _,_ = vm.decode_args() 93 | 94 | with lltype.scoped_alloc(TIMESPEC) as ts: 95 | if clock_gettime(CLOCK_MONOTONIC, ts) != 0: 96 | raise Exception("XXX") 97 | sec = rarithmetic.r_int(ts.c_tv_sec) 98 | nsec = rarithmetic.r_int(ts.c_tv_nsec) 99 | 100 | return Con_List(vm, [Con_Int(vm, sec), Con_Int(vm, nsec)]) 101 | -------------------------------------------------------------------------------- /vm/Modules/Con_Sys.py: -------------------------------------------------------------------------------- 1 | # Copyright (c) 2011 King's College London, created by Laurence Tratt 2 | # 3 | # Permission is hereby granted, free of charge, to any person obtaining a copy 4 | # of this software and associated documentation files (the "Software"), to 5 | # deal in the Software without restriction, including without limitation the 6 | # rights to use, copy, modify, merge, publish, distribute, sublicense, and/or 7 | # sell copies of the Software, and to permit persons to whom the Software is 8 | # furnished to do so, subject to the following conditions: 9 | # 10 | # The above copyright notice and this permission notice shall be included in 11 | # all copies or substantial portions of the Software. 12 | # 13 | # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 14 | # IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 15 | # FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 16 | # AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 17 | # LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING 18 | # FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS 19 | # IN THE SOFTWARE. 20 | 21 | 22 | import sys 23 | import Config 24 | from Builtins import * 25 | 26 | 27 | 28 | 29 | def init(vm): 30 | mod = new_c_con_module(vm, "Sys", "Sys", __file__, import_, \ 31 | ["print", "println", "stdin", "stdout", "stderr", "vm_path", "program_path", "argv", \ 32 | "version", "version_date", "exit"]) 33 | vm.set_builtin(BUILTIN_SYS_MODULE, mod) 34 | 35 | return mod 36 | 37 | 38 | @con_object_proc 39 | def import_(vm): 40 | (mod,),_ = vm.decode_args("O") 41 | 42 | mod.set_defn(vm, "vm_path", Con_String(vm, vm.vm_path)) 43 | mod.set_defn(vm, "argv", Con_List(vm, [Con_String(vm, x) for x in vm.argv])) 44 | 45 | new_c_con_func_for_mod(vm, "exit", exit, mod) 46 | new_c_con_func_for_mod(vm, "print", print_, mod) 47 | new_c_con_func_for_mod(vm, "println", println, mod) 48 | 49 | # Setup stdin, stderr, and stout 50 | 51 | file_mod = vm.get_builtin(BUILTIN_C_FILE_MODULE) 52 | file_class = file_mod.get_defn(vm, "File") 53 | mod.set_defn(vm, "stdin", \ 54 | vm.get_slot_apply(file_class, "new", [Con_Int(vm, 0), Con_String(vm, "r")])) 55 | mod.set_defn(vm, "stdout", \ 56 | vm.get_slot_apply(file_class, "new", [Con_Int(vm, 1), Con_String(vm, "w")])) 57 | mod.set_defn(vm, "stderr", \ 58 | vm.get_slot_apply(file_class, "new", [Con_Int(vm, 2), Con_String(vm, "w")])) 59 | 60 | # Version info 61 | 62 | mod.set_defn(vm, "version", Con_String(vm, Config.CON_VERSION)) 63 | mod.set_defn(vm, "version_date", Con_String(vm, Config.CON_DATE)) 64 | 65 | return vm.get_builtin(BUILTIN_NULL_OBJ) 66 | 67 | 68 | @con_object_proc 69 | def exit(vm): 70 | (c_o,),_ = vm.decode_args(opt="I") 71 | 72 | if c_o is None: 73 | c_o = Con_Int(vm, 0) 74 | 75 | raise vm.raise_helper("System_Exit_Exception", [c_o]) 76 | 77 | 78 | @con_object_proc 79 | def print_(vm): 80 | mod = vm.get_funcs_mod() 81 | _,vargs = vm.decode_args(vargs=True) 82 | stdout = mod.get_defn(vm, "stdout") 83 | 84 | for o in vargs: 85 | if isinstance(o, Con_String): 86 | vm.get_slot_apply(stdout, "write", [o]) 87 | else: 88 | vm.get_slot_apply(stdout, "write", [vm.get_slot_apply(o, "to_str")]) 89 | 90 | return vm.get_builtin(BUILTIN_NULL_OBJ) 91 | 92 | 93 | @con_object_proc 94 | def println(vm): 95 | mod = vm.get_funcs_mod() 96 | _,vargs = vm.decode_args(vargs=True) 97 | stdout = mod.get_defn(vm, "stdout") 98 | 99 | for o in vargs: 100 | if isinstance(o, Con_String): 101 | vm.get_slot_apply(stdout, "write", [o]) 102 | else: 103 | vm.get_slot_apply(stdout, "write", [vm.get_slot_apply(o, "to_str")]) 104 | vm.get_slot_apply(stdout, "write", [Con_String(vm, "\n")]) 105 | 106 | return vm.get_builtin(BUILTIN_NULL_OBJ) 107 | -------------------------------------------------------------------------------- /vm/Modules/Con_Thread.py: -------------------------------------------------------------------------------- 1 | # Copyright (c) 2011 King's College London, created by Laurence Tratt 2 | # 3 | # Permission is hereby granted, free of charge, to any person obtaining a copy 4 | # of this software and associated documentation files (the "Software"), to 5 | # deal in the Software without restriction, including without limitation the 6 | # rights to use, copy, modify, merge, publish, distribute, sublicense, and/or 7 | # sell copies of the Software, and to permit persons to whom the Software is 8 | # furnished to do so, subject to the following conditions: 9 | # 10 | # The above copyright notice and this permission notice shall be included in 11 | # all copies or substantial portions of the Software. 12 | # 13 | # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 14 | # IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 15 | # FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 16 | # AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 17 | # LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING 18 | # FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS 19 | # IN THE SOFTWARE. 20 | 21 | 22 | from Builtins import * 23 | 24 | 25 | 26 | 27 | def init(vm): 28 | return new_c_con_module(vm, "Thread", "Thread", __file__, import_, \ 29 | ["get_continuation_src_infos"]) 30 | 31 | 32 | @con_object_proc 33 | def import_(vm): 34 | (mod,),_ = vm.decode_args("O") 35 | 36 | new_c_con_func_for_mod(vm, "get_continuation_src_infos", get_continuation_src_infos, mod) 37 | 38 | return vm.get_builtin(BUILTIN_NULL_OBJ) 39 | 40 | 41 | @con_object_proc 42 | def get_continuation_src_infos(vm): 43 | (levs_o,),_ = vm.decode_args("I") 44 | assert isinstance(levs_o, Con_Int) 45 | 46 | mod, bc_off = vm.get_mod_and_bc_off(levs_o.v) 47 | if bc_off > -1: 48 | src_infos = mod.bc_off_to_src_infos(vm, bc_off) 49 | else: 50 | src_infos = vm.get_builtin(BUILTIN_NULL_OBJ) 51 | 52 | return src_infos 53 | -------------------------------------------------------------------------------- /vm/Modules/Con_VM.py: -------------------------------------------------------------------------------- 1 | # Copyright (c) 2011 King's College London, created by Laurence Tratt 2 | # 3 | # Permission is hereby granted, free of charge, to any person obtaining a copy 4 | # of this software and associated documentation files (the "Software"), to 5 | # deal in the Software without restriction, including without limitation the 6 | # rights to use, copy, modify, merge, publish, distribute, sublicense, and/or 7 | # sell copies of the Software, and to permit persons to whom the Software is 8 | # furnished to do so, subject to the following conditions: 9 | # 10 | # The above copyright notice and this permission notice shall be included in 11 | # all copies or substantial portions of the Software. 12 | # 13 | # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 14 | # IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 15 | # FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 16 | # AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 17 | # LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING 18 | # FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS 19 | # IN THE SOFTWARE. 20 | 21 | 22 | from Builtins import * 23 | 24 | 25 | 26 | 27 | def init(vm): 28 | return new_c_con_module(vm, "VM", "VM", __file__, \ 29 | import_, \ 30 | ["add_modules", "del_mod", "find_module", "import_module", "iter_mods"]) 31 | 32 | 33 | @con_object_proc 34 | def import_(vm): 35 | (mod,),_ = vm.decode_args("O") 36 | 37 | new_c_con_func_for_mod(vm, "add_modules", add_modules, mod) 38 | new_c_con_func_for_mod(vm, "del_mod", del_mod, mod) 39 | new_c_con_func_for_mod(vm, "find_module", find_module, mod) 40 | new_c_con_func_for_mod(vm, "import_module", import_module, mod) 41 | new_c_con_func_for_mod(vm, "iter_mods", iter_mods, mod) 42 | 43 | return vm.get_builtin(BUILTIN_NULL_OBJ) 44 | 45 | 46 | @con_object_proc 47 | def add_modules(vm): 48 | (mods_o,),_ = vm.decode_args("O") 49 | 50 | vm.pre_get_slot_apply_pump(mods_o, "iter") 51 | while 1: 52 | e_o = vm.apply_pump() 53 | if not e_o: 54 | break 55 | e_o = type_check_module(vm, e_o) 56 | vm.mods[e_o.id_] = e_o 57 | 58 | return vm.get_builtin(BUILTIN_NULL_OBJ) 59 | 60 | 61 | @con_object_proc 62 | def del_mod(vm): 63 | (mod_id_o,),_ = vm.decode_args("S") 64 | assert isinstance(mod_id_o, Con_String) 65 | 66 | if mod_id_o.v not in vm.mods: 67 | vm.raise_helper("Key_Exception", [mod_id_o]) 68 | 69 | del vm.mods[mod_id_o.v] 70 | 71 | return vm.get_builtin(BUILTIN_NULL_OBJ) 72 | 73 | 74 | @con_object_proc 75 | def find_module(vm): 76 | (mod_id_o,),_ = vm.decode_args("S") 77 | assert isinstance(mod_id_o, Con_String) 78 | 79 | m_o = vm.find_mod(mod_id_o.v) 80 | if m_o is None: 81 | m_o = vm.get_builtin(BUILTIN_FAIL_OBJ) 82 | 83 | return m_o 84 | 85 | 86 | @con_object_proc 87 | def import_module(vm): 88 | (mod_o,),_ = vm.decode_args("M") 89 | assert isinstance(mod_o, Con_Module) 90 | 91 | mod_o.import_(vm) 92 | return mod_o 93 | 94 | 95 | @con_object_gen 96 | def iter_mods(vm): 97 | _,_ = vm.decode_args("") 98 | 99 | for mod in vm.mods.values(): 100 | yield mod 101 | -------------------------------------------------------------------------------- /vm/Modules/__init__.py: -------------------------------------------------------------------------------- 1 | # Copyright (c) 2011 King's College London, created by Laurence Tratt 2 | # 3 | # Permission is hereby granted, free of charge, to any person obtaining a copy 4 | # of this software and associated documentation files (the "Software"), to 5 | # deal in the Software without restriction, including without limitation the 6 | # rights to use, copy, modify, merge, publish, distribute, sublicense, and/or 7 | # sell copies of the Software, and to permit persons to whom the Software is 8 | # furnished to do so, subject to the following conditions: 9 | # 10 | # The above copyright notice and this permission notice shall be included in 11 | # all copies or substantial portions of the Software. 12 | # 13 | # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 14 | # IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 15 | # FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 16 | # AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 17 | # LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING 18 | # FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS 19 | # IN THE SOFTWARE. 20 | 21 | 22 | __all__ = ["Con_Array", "Con_C_Earley_Parser", "Con_C_Platform_Env", "Con_C_Platform_Exec", \ 23 | "Con_C_Platform_Host", "Con_C_Platform_Properties", "Con_C_Strings", "Con_C_Time", "Con_Curses", \ 24 | "Con_Exceptions", "Con_PCRE", "Con_POSIX_File", "Random", "Con_Sys", "Con_Thread", "Con_VM", \ 25 | "libXML2"] 26 | 27 | import Con_Array, Con_C_Earley_Parser, Con_C_Platform_Env, Con_C_Platform_Exec, \ 28 | Con_C_Platform_Host, Con_C_Platform_Properties, Con_C_Strings, Con_C_Time, Con_Curses, \ 29 | Con_Exceptions, Con_PCRE, Con_POSIX_File, Con_Random, Con_Sys, Con_Thread, Con_VM, libXML2 30 | 31 | BUILTIN_MODULES = \ 32 | [Con_Array.init, Con_C_Earley_Parser.init, Con_C_Platform_Env.init, Con_C_Platform_Exec.init, \ 33 | Con_C_Platform_Host.init, Con_C_Platform_Properties.init, Con_C_Strings.init, Con_C_Time.init, \ 34 | Con_Curses.init, Con_Exceptions.init, Con_PCRE.init, Con_POSIX_File.init, Con_Random.init, \ 35 | Con_Sys.init, Con_Thread.init, Con_VM.init, libXML2.init] -------------------------------------------------------------------------------- /vm/Stdlib_Modules.py: -------------------------------------------------------------------------------- 1 | # Copyright (c) 2011 King's College London, created by Laurence Tratt 2 | # 3 | # Permission is hereby granted, free of charge, to any person obtaining a copy 4 | # of this software and associated documentation files (the "Software"), to 5 | # deal in the Software without restriction, including without limitation the 6 | # rights to use, copy, modify, merge, publish, distribute, sublicense, and/or 7 | # sell copies of the Software, and to permit persons to whom the Software is 8 | # furnished to do so, subject to the following conditions: 9 | # 10 | # The above copyright notice and this permission notice shall be included in 11 | # all copies or substantial portions of the Software. 12 | # 13 | # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 14 | # IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 15 | # FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 16 | # AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 17 | # LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING 18 | # FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS 19 | # IN THE SOFTWARE. 20 | 21 | 22 | STDLIB_ARRAY = "Array" 23 | STDLIB_BUILTINS = "Builtins" 24 | STDLIB_CURSES = "Curses" 25 | STDLIB_C_EARLEY_PARSER = "C_Earley_Parser" 26 | STDLIB_C_PLATFORM_ENV = "C_Platform_Env" 27 | STDLIB_C_PLATFORM_EXEC = "C_Platform_Exec" 28 | STDLIB_C_PLATFORM_HOST = "C_Platform_Host" 29 | STDLIB_C_PLATFORM_PROPERTIES = "C_Platform_Properties" 30 | STDLIB_C_STRINGS = "C_Strings" 31 | STDLIB_C_TIME = "C_Time" 32 | STDLIB_EXCEPTIONS = "Exceptions" 33 | STDLIB_LIBXML2 = "libXML2" 34 | STDLIB_PCRE = "PCRE" 35 | STDLIB_POSIX_FILE = "POSIX_File" 36 | STDLIB_RANDOM = "Random" 37 | STDLIB_SYS = "Sys" 38 | STDLIB_THREAD = "Thread" 39 | STDLIB_VM = "VM" 40 | STDLIB_CPK_EARLEY_DSL = "/Stdlib/CPK/Earley/DSL.cv" 41 | STDLIB_CPK_EARLEY_GRAMMAR = "/Stdlib/CPK/Earley/Grammar.cv" 42 | STDLIB_CPK_EARLEY_PARSER = "/Stdlib/CPK/Earley/Parser.cv" 43 | STDLIB_CPK_TOKEN = "/Stdlib/CPK/Token.cv" 44 | STDLIB_CPK_TOKENS = "/Stdlib/CPK/Tokens.cv" 45 | STDLIB_CPK_TRAVERSER = "/Stdlib/CPK/Traverser.cv" 46 | STDLIB_CPK_TREE = "/Stdlib/CPK/Tree.cv" 47 | STDLIB_PLATFORM_ENV = "/Stdlib/Platform/Env.cv" 48 | STDLIB_PLATFORM_EXEC = "/Stdlib/Platform/Exec.cv" 49 | STDLIB_PLATFORM_HOST = "/Stdlib/Platform/Host.cv" 50 | STDLIB_PLATFORM_PROPERTIES = "/Stdlib/Platform/Properties.cv" 51 | STDLIB_XML_NODES = "/Stdlib/XML/Nodes.cv" 52 | STDLIB_XML_XDM = "/Stdlib/XML/XDM.cv" 53 | STDLIB_XML_XHTML = "/Stdlib/XML/XHTML.cv" 54 | STDLIB_BACKTRACE = "/Stdlib/Backtrace.cv" 55 | STDLIB_CEI = "/Stdlib/CEI.cv" 56 | STDLIB_FILE = "/Stdlib/File.cv" 57 | STDLIB_FUNCTIONAL = "/Stdlib/Functional.cv" 58 | STDLIB_MATHS = "/Stdlib/Maths.cv" 59 | STDLIB_NUMBERS = "/Stdlib/Numbers.cv" 60 | STDLIB_PARSE_ARGS = "/Stdlib/Parse_Args.cv" 61 | STDLIB_SORT = "/Stdlib/Sort.cv" 62 | STDLIB_STRINGS = "/Stdlib/Strings.cv" 63 | STDLIB_TIME = "/Stdlib/Time.cv" 64 | -------------------------------------------------------------------------------- /vm/platform/fgetln.c: -------------------------------------------------------------------------------- 1 | /* $OpenPackages: util.c,v 1.10 2001/07/22 01:00:52 harlan Exp $ */ 2 | /* $OpenBSD: util.c,v 1.16 2001/05/23 12:34:51 espie Exp $ */ 3 | /* $NetBSD: util.c,v 1.10 1996/12/31 17:56:04 christos Exp $ */ 4 | /* $TenDRA: contrib/make/util.c,v 1.5 2003/02/11 21:16:16 asmodai Exp $ */ 5 | 6 | /* 7 | * Copyright (c) 2001 Marc Espie. 8 | * 9 | * Redistribution and use in source and binary forms, with or without 10 | * modification, are permitted provided that the following conditions 11 | * are met: 12 | * 1. Redistributions of source code must retain the above copyright 13 | * notice, this list of conditions and the following disclaimer. 14 | * 2. Redistributions in binary form must reproduce the above copyright 15 | * notice, this list of conditions and the following disclaimer in the 16 | * documentation and/or other materials provided with the distribution. 17 | * 18 | * THIS SOFTWARE IS PROVIDED BY THE OPENBSD PROJECT AND CONTRIBUTORS 19 | * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 20 | * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 21 | * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE OPENBSD 22 | * PROJECT OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 23 | * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 24 | * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 25 | * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 26 | * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 27 | * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 28 | * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 29 | */ 30 | 31 | #include 32 | #include 33 | #include 34 | #include 35 | 36 | 37 | static void removeCR(char *s) 38 | { 39 | while (*s) { 40 | if (*s == '\r' && s[1] == '\n') { 41 | *s = '\n'; 42 | s[1] = 0; 43 | break; 44 | } 45 | s++; 46 | } 47 | } 48 | 49 | char *fgetln(FILE *stream, size_t *len) 50 | { 51 | static char *buffer = NULL; 52 | static size_t buflen = 0; 53 | 54 | if (buflen == 0) { 55 | buflen = 512; 56 | buffer = malloc(buflen+1); 57 | } 58 | if (fgets(buffer, buflen+1, stream) == NULL) 59 | return NULL; 60 | removeCR(buffer); 61 | *len = strlen(buffer); 62 | while (*len == buflen && buffer[*len-1] != '\n') { 63 | buffer = realloc(buffer, 2*buflen + 1); 64 | if (fgets(buffer + buflen, buflen + 1, stream) == NULL) 65 | return NULL; 66 | removeCR(buffer); 67 | *len += strlen(buffer + buflen); 68 | buflen *= 2; 69 | } 70 | return buffer; 71 | } 72 | -------------------------------------------------------------------------------- /vm/platform/fgetln.h: -------------------------------------------------------------------------------- 1 | static void removeCR(char *); 2 | char *fgetln(FILE *, size_t *); --------------------------------------------------------------------------------