Overview
Comment: | Added example script which converts Tcl script using Critcl to C files |
---|---|
Timelines: | family | ancestors | descendants | both | trunk |
Files: | files | file ages | folders |
SHA1: |
e5ddd6aaff4ab8ca3d0c275e6004b66d |
User & Date: | rkeene on 2019-06-05 00:33:53 |
Other Links: | manifest | tags |
Context
2019-06-05
| ||
00:34 | Example for compiling tcllibc -- very specific check-in: 40255f4a4f user: rkeene tags: trunk | |
00:33 | Added example script which converts Tcl script using Critcl to C files check-in: e5ddd6aaff user: rkeene tags: trunk | |
00:32 | Many improvements, especially for critcl compatibility check-in: c808df56cc user: rkeene tags: trunk | |
Changes
Added build/tcc-critcl-to-c.tcl version [b3fa452a32].
> > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > | 1 2 3 4 5 6 7 8 9 10 11 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 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 | #! /usr/bin/env tclsh #package require -exact critcl 0 catch { source tcc4tcl.tcl } package provide tcc4tcl 0 catch { source tcc4critcl.tcl } err # Emit a library by default set packageName "PACKAGENAME" set packageVersion "0" set outputMode "library" proc ::critcl::_allocateHandle {} { if {[info exists ::critcl::handle]} { return $::critcl::handle } switch -exact $::outputMode { "library" { set ::critcl::handle [::tcc4tcl::new $::packageName [list $::packageName $::packageVersion]] } "application" { set ::critcl::handle [::tcc4tcl::new $::packageName] } "direct" { set ::critcl::handle [::tcc4tcl::new] } } return $::critcl::handle } # Build up C code from arguments foreach script $argv { if {[info exists nextParam]} { set thisParam $nextParam unset nextParam switch -exact -- $thisParam { "--package" { set ::packageName [lindex $script 0] set ::packageVersion [lindex $script 1] if {$::packageVersion eq ""} { set ::packageVersion "@PACKAGEVERSION@" } continue } "--mode" { set ::outputMode $script continue } default { puts stderr "Internal error: incomplete nextParam $nextParam" exit 1 } } } switch -exact -- $script { "--package" - "--mode" { set nextParam $script continue } "--help" { puts {Usage: tcc-critcl-to-c.tcl [--package <nameAndVersion>] [--mode {library|application|direct}] <tclScripts...>} exit 0 } } set ::critcl::dir [file dirname $script] source $script if {[info exists ::critcl::handle]} { $::critcl::handle add_include_path $::critcl::dir } } # If no Critcl functions have been used, do nothing if {![info exists ::critcl::handle]} { exit 0 } set map [list] if {$packageVersion eq "@PACKAGEVERSION@"} { catch { set packageVersion 0 set packageVersion [package present $packageName] } lappend map @PACKAGEVERSION@ $packageVersion } # Emit the resulting C code puts [string map $map [$::critcl::handle code]] |