├── .gitattributes ├── .gitignore ├── .travis.yml ├── LICENSE ├── NOTICE ├── README ├── make ├── makefile ├── makefile.vc └── vcbuild.bat └── src ├── boot ├── actions.r ├── booters.r ├── draw.r ├── errors.r ├── graphics.r ├── modes.r ├── natives.r ├── ops.r ├── platforms.r ├── root.r ├── shape.r ├── strings.r ├── sysobj.r ├── task.r ├── text.r ├── types-ext.r ├── types.r ├── typespec.r ├── version.r └── words.r ├── core ├── a-constants.c ├── a-globals.c ├── a-lib.c ├── a-lib2.c ├── a-stubs.c ├── b-init.c ├── b-main.c ├── c-do.c ├── c-error.c ├── c-frame.c ├── c-function.c ├── c-port.c ├── c-task.c ├── c-word.c ├── d-crash.c ├── d-dump.c ├── d-print.c ├── f-blocks.c ├── f-deci.c ├── f-dtoa.c ├── f-enbase.c ├── f-extension.c ├── f-math.c ├── f-modify.c ├── f-qsort.c ├── f-random.c ├── f-round.c ├── f-series.c ├── f-stubs.c ├── l-scan.c ├── l-types.c ├── m-gc.c ├── m-pools.c ├── m-series.c ├── n-control.c ├── n-data.c ├── n-graphics.c ├── n-io.c ├── n-loop.c ├── n-math.c ├── n-sets.c ├── n-strings.c ├── n-system.c ├── p-clipboard.c ├── p-console.c ├── p-dir.c ├── p-dns.c ├── p-event.c ├── p-file.c ├── p-net.c ├── p-timer.c ├── s-cases.c ├── s-crc.c ├── s-file.c ├── s-find.c ├── s-make.c ├── s-mold.c ├── s-ops.c ├── s-trim.c ├── s-unicode.c ├── t-bitset.c ├── t-block.c ├── t-char.c ├── t-datatype.c ├── t-date.c ├── t-decimal.c ├── t-event.c ├── t-function.c ├── t-gob.c ├── t-image.c ├── t-integer.c ├── t-logic.c ├── t-map.c ├── t-money.c ├── t-none.c ├── t-object.c ├── t-pair.c ├── t-port.c ├── t-string.c ├── t-time.c ├── t-tuple.c ├── t-typeset.c ├── t-utype.c ├── t-vector.c ├── t-word.c ├── u-bmp.c ├── u-compress.c ├── u-dialect.c ├── u-gif.c ├── u-jpg.c ├── u-md5.c ├── u-parse.c ├── u-png.c ├── u-sha1.c └── u-zlib.c ├── include ├── reb-args.h ├── reb-c.h ├── reb-codec.h ├── reb-config.h ├── reb-defs.h ├── reb-device.h ├── reb-dtoa.h ├── reb-event.h ├── reb-ext.h ├── reb-file.h ├── reb-filereq.h ├── reb-gob.h ├── reb-host.h ├── reb-math.h ├── reb-net.h ├── reb-series.h ├── reb-value.h ├── sys-core.h ├── sys-dec-to-char.h ├── sys-deci-funcs.h ├── sys-deci.h ├── sys-globals.h ├── sys-jpg.h ├── sys-mem.h ├── sys-net.h ├── sys-panics.h ├── sys-scan.h ├── sys-stack.h ├── sys-state.h ├── sys-value.h └── sys-zlib.h ├── mezz ├── base-constants.r ├── base-debug.r ├── base-defs.r ├── base-files.r ├── base-funcs.r ├── base-series.r ├── boot-files.r ├── dial-draw.r ├── dial-effect.r ├── dial-text.r ├── mezz-banner.r ├── mezz-colors.r ├── mezz-control.r ├── mezz-debug.r ├── mezz-files.r ├── mezz-func.r ├── mezz-help.r ├── mezz-math.r ├── mezz-save.r ├── mezz-secure.r ├── mezz-series.r ├── mezz-shell.r ├── mezz-tail.r ├── mezz-types.r ├── prot-http.r ├── sys-base.r ├── sys-codec.r ├── sys-load.r ├── sys-ports.r ├── sys-start.r └── view-funcs.r ├── os ├── dev-dns.c ├── dev-net.c ├── host-args.c ├── host-device.c ├── host-ext-test.c ├── host-main.c ├── host-stdio.c ├── posix │ ├── dev-event.c │ ├── dev-file.c │ ├── dev-stdio.c │ ├── host-lib.c │ ├── host-readline.c │ └── host-window.c └── win32 │ ├── dev-clipboard.c │ ├── dev-event.c │ ├── dev-file.c │ ├── dev-stdio.c │ ├── host-draw.c │ ├── host-effect.c │ ├── host-event.c │ ├── host-graphics.c │ ├── host-lib.c │ ├── host-text.c │ ├── host-window.c │ └── rpic-test.c └── tools ├── file-base.r ├── form-header.r ├── make-boot.r ├── make-headers.r ├── make-host-ext.r ├── make-host-init.r ├── make-make.r ├── make-os-ext.r ├── make-reb-lib.r └── systems.r /.gitattributes: -------------------------------------------------------------------------------- 1 | # Auto detect text files and perform LF normalization 2 | * text=auto 3 | 4 | # Custom for Visual Studio 5 | *.cs diff=csharp 6 | *.sln merge=union 7 | *.csproj merge=union 8 | *.vbproj merge=union 9 | *.fsproj merge=union 10 | *.dbproj merge=union 11 | 12 | # Standard to msysgit 13 | *.doc diff=astextplain 14 | *.DOC diff=astextplain 15 | *.docx diff=astextplain 16 | *.DOCX diff=astextplain 17 | *.dot diff=astextplain 18 | *.DOT diff=astextplain 19 | *.pdf diff=astextplain 20 | *.PDF diff=astextplain 21 | *.rtf diff=astextplain 22 | *.RTF diff=astextplain 23 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | ################# 2 | ## REBOL R3 3 | ################# 4 | 5 | make/r3* 6 | make/objs/ 7 | src/boot/boot-code.r 8 | src/boot/host-init.r 9 | src/core/b-boot.c 10 | src/include/ext-types.h 11 | src/include/host-* 12 | src/include/reb-dialect.h 13 | src/include/reb-evtypes.h 14 | src/include/reb-lib-lib.h 15 | src/include/reb-lib.h 16 | src/include/reb-types.h 17 | src/include/tmp-* 18 | src/tools/reb-lib-doc.txt 19 | src/reb-lib-doc.txt 20 | 21 | ################# 22 | ## Eclipse 23 | ################# 24 | 25 | *.pydevproject 26 | .project 27 | .metadata 28 | bin/ 29 | tmp/ 30 | *.tmp 31 | *.bak 32 | *.swp 33 | *~.nib 34 | local.properties 35 | .classpath 36 | .settings/ 37 | .loadpath 38 | 39 | # External tool builders 40 | .externalToolBuilders/ 41 | 42 | # Locally stored "Eclipse launch configurations" 43 | *.launch 44 | 45 | # CDT-specific 46 | .cproject 47 | 48 | # PDT-specific 49 | .buildpath 50 | 51 | 52 | ################# 53 | ## Visual Studio 54 | ################# 55 | 56 | ## Ignore Visual Studio temporary files, build results, and 57 | ## files generated by popular Visual Studio add-ons. 58 | 59 | # User-specific files 60 | *.suo 61 | *.user 62 | *.sln.docstates 63 | 64 | # Build results 65 | [Dd]ebug/ 66 | [Rr]elease/ 67 | *_i.c 68 | *_p.c 69 | *.ilk 70 | *.meta 71 | *.obj 72 | *.pch 73 | *.pdb 74 | *.pgc 75 | *.pgd 76 | *.rsp 77 | *.sbr 78 | *.tlb 79 | *.tli 80 | *.tlh 81 | *.tmp 82 | *.vspscc 83 | .builds 84 | *.dotCover 85 | 86 | ## TODO: If you have NuGet Package Restore enabled, uncomment this 87 | #packages/ 88 | 89 | # Visual C++ cache files 90 | ipch/ 91 | *.aps 92 | *.ncb 93 | *.opensdf 94 | *.sdf 95 | 96 | # Visual Studio profiler 97 | *.psess 98 | *.vsp 99 | 100 | # ReSharper is a .NET coding add-in 101 | _ReSharper* 102 | 103 | # Installshield output folder 104 | [Ee]xpress 105 | 106 | # DocProject is a documentation generator add-in 107 | DocProject/buildhelp/ 108 | DocProject/Help/*.HxT 109 | DocProject/Help/*.HxC 110 | DocProject/Help/*.hhc 111 | DocProject/Help/*.hhk 112 | DocProject/Help/*.hhp 113 | DocProject/Help/Html2 114 | DocProject/Help/html 115 | 116 | # Click-Once directory 117 | publish 118 | 119 | # Others 120 | [Bb]in 121 | [Oo]bj 122 | sql 123 | TestResults 124 | *.Cache 125 | ClientBin 126 | stylecop.* 127 | ~$* 128 | *.dbmdl 129 | Generated_Code #added for RIA/Silverlight projects 130 | 131 | # Backup & report files from converting an old project file to a newer 132 | # Visual Studio version. Backup files are not needed, because we have git ;-) 133 | _UpgradeReport_Files/ 134 | Backup*/ 135 | UpgradeLog*.XML 136 | 137 | 138 | 139 | ############ 140 | ## Windows 141 | ############ 142 | 143 | # Windows image file caches 144 | Thumbs.db 145 | 146 | # Folder config file 147 | Desktop.ini 148 | 149 | 150 | ############# 151 | ## Python 152 | ############# 153 | 154 | *.py[co] 155 | 156 | # Packages 157 | *.egg 158 | *.egg-info 159 | dist 160 | build 161 | eggs 162 | parts 163 | bin 164 | var 165 | sdist 166 | develop-eggs 167 | .installed.cfg 168 | 169 | # Installer logs 170 | pip-log.txt 171 | 172 | # Unit test / coverage reports 173 | .coverage 174 | .tox 175 | 176 | #Translations 177 | *.mo 178 | 179 | #Mr Developer 180 | .mr.developer.cfg 181 | 182 | # Mac crap 183 | .DS_Store 184 | -------------------------------------------------------------------------------- /.travis.yml: -------------------------------------------------------------------------------- 1 | # 2 | # .travis.yaml contains YAML-formatted (http://www.yaml.org/) build 3 | # instructions for continuous integration via Travis CI 4 | # (http://docs.travis-ci.com/). 5 | # 6 | 7 | notifications: 8 | email: false 9 | 10 | language: c 11 | 12 | compiler: 13 | - gcc 14 | 15 | env: 16 | matrix: 17 | # Linux x86 18 | - OS_ID=0.4.4 19 | # Linux x64 20 | - OS_ID=0.4.40 21 | 22 | before_install: 23 | - sudo apt-get update 24 | 25 | install: 26 | # gcc-multilib: 27 | # For building 32b binaries on a 64b host (not necessary when we build 28 | # for 64b). 29 | # valgrind: 30 | # For basic sanity checking of our freshly built binaries. 31 | # libc6:i386: 32 | # For running the 32b bootstrap rebol ("r3-make") on a 64b host. 33 | # libc6-dbg:i386: 34 | # For running valgrind on a 32b subject-under-test on a 64b host. 35 | - sudo apt-get install -y gcc-multilib valgrind libc6:i386 libc6-dbg:i386 36 | # Fetch a Rebol bootstrap binary, which is needed for building Rebol. 37 | - wget http://www.rebol.com/r3/downloads/r3-a111-4-2.tar.gz 38 | - tar xvzf r3-a111-4-2.tar.gz 39 | - cp r3 make/r3-make 40 | 41 | script: 42 | - cd make/ 43 | - make make OS_ID=${OS_ID} 44 | - make clean prep r3 45 | - valgrind --error-exitcode=42 --leak-check=full ./r3 --do 'print {Hello!}' 46 | -------------------------------------------------------------------------------- /NOTICE: -------------------------------------------------------------------------------- 1 | REBOL [R3] Language Interpreter and Run-time Environment 2 | Copyright 2012 REBOL Technologies 3 | REBOL is a trademark of REBOL Technologies 4 | Licensed under the Apache License, Version 2.0 5 | See included LICENSE file for details 6 | 7 | 8 | Credits for Non-REBOL orginated C files and modules 9 | --------------------------------------------------- 10 | 11 | Unicode encoding/decoding functions: 12 | Copyright 2001-2004 Unicode, Inc. 13 | 14 | MD5: 15 | This software contains code derived from the RSA Data Security 16 | Inc. MD5 Message-Digest Algorithm, including various 17 | modifications by Spyglass Inc., Carnegie Mellon University, and 18 | Bell Communications Research, Inc (Bellcore). 19 | 20 | SHA1: 21 | Copyright 1995-1998 Eric Young (eay@cryptsoft.com) 22 | All rights reserved. 23 | 24 | ZLIB general purpose compression library: 25 | Version 1.1.2, March 19th, 1998 26 | Copyright 1995-1998 Jean-loup Gailly and Mark Adler 27 | 28 | JPEG decoder: 29 | Copyright 1994-1996, Thomas G. Lane. 30 | This file is part of the Independent JPEG Group's software. 31 | 32 | dtoa: 33 | The author of this software is David M. Gay. 34 | Copyright (c) 1991, 2000, 2001 by Lucent Technologies. 35 | 36 | qsort: 37 | Copyright (c) 1992, 1993 The Regents of the University of California. 38 | -------------------------------------------------------------------------------- /README: -------------------------------------------------------------------------------- 1 | Rebol [R3] Source Code Distribution 2 | Date: 12-Dec-2012 3 | Version: 2.101.0 4 | From: Carl Sassenrath 5 | Web: www.rebol.com 6 | 7 | 8 | Build Target: 9 | 10 | This first release is intended for non-Windows systems like Linux, Mac, BSD, 11 | Android, etc. However, it will build for Windows, but I've not included the 12 | typical MSVC project files. I'll try to get that added, but it's not that 13 | tough to create one yourself. You will need to set struct align to 4 bytes. 14 | 15 | 16 | About the Makefile: 17 | 18 | You might notice that the makefile is a bit old-fashioned. That's because I 19 | still support Rebol on some very old systems that don't offer newer makefile 20 | features. So, please keep that in mind and stick with this simple format. 21 | 22 | Also, the makefile is built by Rebol. Typing "make make" will rebuild it, 23 | and you can also select a different platform target by providing 24 | the Rebol platform identifier typing e.g. "make make OS_ID=0.4.4" (Linux 25 | Libc6 2.11 platform version). 26 | 27 | 28 | Build Instructions: 29 | 30 | Parts of Rebol are built by Rebol. So, to build it, you'll need to download a 31 | running binary into the local make directory. Call it r3-make. 32 | 33 | The build happens in the make directory. It will create an obj sub-dir for 34 | storing the object files. I prefer this over mixing the source and object 35 | files into the same directory. 36 | 37 | You may need to do "make clean" for clean make session. 38 | 39 | The biggest step is to do the "make prep" which will use Rebol to configure 40 | and build a number of important C header files. 41 | 42 | If you are building for a new platform that has no existing Rebol, you can use 43 | "make prep" to build all the files you need on an existing platform and copy 44 | them to the new platform. 45 | 46 | After the prep, just run "make" or "make r3" and the rest of the system will 47 | build. 48 | 49 | 50 | Toolchain Note: 51 | 52 | Rebol builds on many different compilers over a range of systems. Although 53 | the C source doesn't strictly follow any one standard, it's quite portable 54 | and I've yet to find a toolchain that won't build it. You can even cross 55 | compile it for embedded systems quite easily. If you run into a problem, 56 | it's probably something fairly simple. Don't over complicate it. 57 | 58 | 59 | Note to Contributors: 60 | 61 | I welcome your help with porting Rebol to many more devices and making various 62 | improvements. I just ask that you: 63 | 64 | 1. Keep code clear and simple. 65 | 2. Document unusual code, reasoning, or gotchas. 66 | 3. Use same style for code, vars, indent(4), comments, etc. 67 | 4. Keep in mind Linux, OS X, BSD, big/little endian CPUs. 68 | 5. Test everything, then test it again. 69 | 70 | Enjoy your new Rebol freedom, 71 | 72 | -Carl 73 | 74 | Bug reporting note: 75 | 76 | Report bugs, wishes, etc. at the 77 | 78 | http://curecode.org/rebol3/view-tickets.rsp 79 | 80 | site. -------------------------------------------------------------------------------- /make/makefile.vc: -------------------------------------------------------------------------------- 1 | # Makefile for Visual Studio's nmake 2 | # TODO: this should be automatically generated, like Makefile 3 | 4 | CC= cl.exe 5 | LD= link.exe 6 | 7 | UP= .. 8 | T= $(UP)\src\tools 9 | CD= ./ 10 | 11 | I= /I..\src\include 12 | TO_OS= TO_WIN32 13 | OS_ID= 0.4.4 14 | 15 | CFLAGS=/c /Os /D "UNICODE" /D "WIN32" /W3 /GR- /Zi /GS /Gy /GF /EHs-c- /GL /D "NDEBUG" /D "_CRT_SECURE_NO_WARNINGS" 16 | 17 | RAPI_FLAGS= $(CFLAGS) 18 | HOST_FLAGS= $(CFLAGS) 19 | RLIB_FLAGS= 20 | 21 | RFLAGS= $(RAPI_FLAGS) $(I) /D$(TO_OS) /DREB_API 22 | HFLAGS= $(HOST_FLAGS) $(I) /D$(TO_OS) /DREB_CORE 23 | 24 | LIBS= user32.lib ws2_32.lib advapi32.lib shell32.lib comdlg32.lib 25 | LDFLAGS = /nologo /DEBUG /RELEASE /opt:ref /opt:icf /LTCG 26 | 27 | REBOL= r3-make.exe -qs 28 | 29 | all: prep r3.exe 30 | 31 | prep: 32 | $(REBOL) $T/make-headers.r 33 | $(REBOL) $T/make-boot.r $(OS_ID) 34 | $(REBOL) $T/make-host-init.r 35 | $(REBOL) $T/make-os-ext.r # ok, but not always 36 | $(REBOL) $T/make-host-ext.r 37 | $(REBOL) $T/make-reb-lib.r 38 | 39 | objs: 40 | mkdir objs 41 | 42 | OBJS = objs/a-constants.obj objs/a-globals.obj objs/a-lib.obj objs/b-boot.obj \ 43 | objs/b-init.obj objs/c-do.obj objs/c-error.obj objs/c-frame.obj \ 44 | objs/c-function.obj objs/c-port.obj objs/c-task.obj objs/c-word.obj \ 45 | objs/d-crash.obj objs/d-dump.obj objs/d-print.obj objs/f-blocks.obj \ 46 | objs/f-deci.obj objs/f-enbase.obj objs/f-extension.obj objs/f-math.obj \ 47 | objs/f-modify.obj objs/f-random.obj objs/f-round.obj objs/f-series.obj \ 48 | objs/f-stubs.obj objs/l-scan.obj objs/l-types.obj objs/m-gc.obj \ 49 | objs/m-pools.obj objs/m-series.obj objs/n-control.obj objs/n-data.obj \ 50 | objs/n-io.obj objs/n-loop.obj objs/n-math.obj objs/n-sets.obj \ 51 | objs/n-strings.obj objs/n-system.obj objs/p-clipboard.obj objs/p-console.obj \ 52 | objs/p-dir.obj objs/p-dns.obj objs/p-event.obj objs/p-file.obj \ 53 | objs/p-net.obj objs/s-cases.obj objs/s-crc.obj objs/s-file.obj \ 54 | objs/s-find.obj objs/s-make.obj objs/s-mold.obj objs/s-ops.obj \ 55 | objs/s-trim.obj objs/s-unicode.obj objs/t-bitset.obj objs/t-block.obj \ 56 | objs/t-char.obj objs/t-datatype.obj objs/t-date.obj objs/t-decimal.obj \ 57 | objs/t-event.obj objs/t-function.obj objs/t-gob.obj objs/t-image.obj \ 58 | objs/t-integer.obj objs/t-logic.obj objs/t-map.obj objs/t-money.obj \ 59 | objs/t-none.obj objs/t-object.obj objs/t-pair.obj objs/t-port.obj \ 60 | objs/t-string.obj objs/t-time.obj objs/t-tuple.obj objs/t-typeset.obj \ 61 | objs/t-utype.obj objs/t-vector.obj objs/t-word.obj objs/u-bmp.obj \ 62 | objs/u-compress.obj objs/u-dialect.obj objs/u-gif.obj objs/u-jpg.obj \ 63 | objs/u-md5.obj objs/u-parse.obj objs/u-png.obj objs/u-sha1.obj \ 64 | objs/u-zlib.obj 65 | 66 | HOST = objs/host-main.obj objs/host-args.obj objs/host-device.obj objs/host-stdio.obj \ 67 | objs/dev-net.obj objs/dev-dns.obj objs/host-lib.obj \ 68 | objs/dev-stdio.obj objs/dev-event.obj objs/dev-file.obj \ 69 | objs/dev-clipboard.obj 70 | 71 | # Directly linked r3 executable: 72 | r3.exe: objs $(OBJS) $(HOST) 73 | $(LD) $(LDFLAGS) $(OBJS) $(HOST) $(LIBS) /PDB:$*.pdb /OUT:r3.exe /SUBSYSTEM:WINDOWS 74 | 75 | {..\src\core}.c{objs}.obj:: 76 | $(CC) $(RFLAGS) /Foobjs\ /Fdobjs\vc80.pdb $< 77 | 78 | {..\src\os}.c{objs}.obj:: 79 | $(CC) $(HFLAGS) /Foobjs\ /Fdobjs\vc80.pdb $< 80 | 81 | {..\src\os\win32}.c{objs}.obj:: 82 | $(CC) $(HFLAGS) /Foobjs\ /Fdobjs\vc80.pdb $< 83 | -------------------------------------------------------------------------------- /make/vcbuild.bat: -------------------------------------------------------------------------------- 1 | @ECHO OFF 2 | 3 | REM Allow to explicitly specify the desired Visual Studio version 4 | IF /I "%1" == "vc12" GOTO TRY_VS12 5 | IF /I "%1" == "vc10" GOTO TRY_VS10 6 | IF /I "%1" == "vc9" GOTO TRY_VS9 7 | 8 | REM vs9 is VS 2008 9 | :TRY_VS9 10 | CALL "%VS90COMNTOOLS%\vsvars32.bat" 2>NUL 11 | IF NOT ERRORLEVEL 1 GOTO BUILD 12 | 13 | REM vs10 is VS 2010 14 | :TRY_VS10 15 | CALL "%VS100COMNTOOLS%\vsvars32.bat" 2>NUL 16 | IF NOT ERRORLEVEL 1 GOTO BUILD 17 | 18 | REM vs12 is VS 2012 19 | :TRY_VS12 20 | CALL "%VS110COMNTOOLS%\vsvars32.bat" 2>NUL 21 | IF NOT ERRORLEVEL 1 GOTO BUILD 22 | 23 | ECHO Visual Studio 2012, 2010, or 2008 doesn't seem to be installed 24 | EXIT /B 1 25 | 26 | :BUILD 27 | nmake -f makefile.vc all 28 | 29 | -------------------------------------------------------------------------------- /src/boot/booters.r: -------------------------------------------------------------------------------- 1 | REBOL [ 2 | System: "REBOL [R3] Language Interpreter and Run-time Environment" 3 | Title: "Special boot native function specs" 4 | Rights: { 5 | Copyright 2012 REBOL Technologies 6 | REBOL is a trademark of REBOL Technologies 7 | } 8 | License: { 9 | Licensed under the Apache License, Version 2.0. 10 | See: http://www.apache.org/licenses/LICENSE-2.0 11 | } 12 | Purpose: { 13 | These are used to define natives and actions. 14 | Bind attributes for this block are: BIND_SET and SHALLOW 15 | } 16 | ] 17 | 18 | ; Special block used as spec to the datatype test functions (e.g. time?): 19 | ["Returns TRUE if it is this type." value [any-type!] 0] 20 | 21 | ; The native function must be defined first. This is a 22 | ; special boot function created manually within the C code. 23 | native: native [ 24 | {Creates native function (for internal usage only).} 25 | spec ; [block!] -- no check required, we know it is correct 26 | ] 27 | 28 | action: native [ 29 | {Creates datatype action (for internal usage only).} 30 | spec ; [block!] -- no check required, we know it is correct 31 | ] 32 | -------------------------------------------------------------------------------- /src/boot/graphics.r: -------------------------------------------------------------------------------- 1 | REBOL [ 2 | System: "REBOL [R3] Language Interpreter and Run-time Environment" 3 | Title: "REBOL Graphics" 4 | Rights: { 5 | Copyright 2012 REBOL Technologies 6 | REBOL is a trademark of REBOL Technologies 7 | } 8 | License: { 9 | Licensed under the Apache License, Version 2.0. 10 | See: http://www.apache.org/licenses/LICENSE-2.0 11 | } 12 | Name: graphics 13 | Type: extension 14 | Exports: [] ; added by make-host-ext.r 15 | Note: "Run make-host-ext.r to convert" 16 | ] 17 | 18 | words: [ 19 | ;gui-metric 20 | screen-size 21 | border-size 22 | border-fixed 23 | title-size 24 | work-origin 25 | work-size 26 | ] 27 | 28 | ;temp hack - will be removed later 29 | init-words: command [ 30 | words [block!] 31 | ] 32 | 33 | init-words words 34 | 35 | init: command [ 36 | "Initialize graphics subsystem." 37 | gob [gob!] "The screen gob (root gob)" 38 | ] 39 | 40 | caret-to-offset: command [ 41 | "Returns the xy offset (pair) for a specific string position in a graphics object." 42 | gob [gob!] 43 | element [integer! block!] "The position of the string in the richtext block" 44 | position [integer! string!] "The position within the string" 45 | ] 46 | 47 | cursor: command [ 48 | "Changes the mouse cursor image." 49 | image [integer! image! none!] 50 | ] 51 | 52 | offset-to-caret: command [ ;returns pair! instead of the block..needs to be fixed 53 | "Returns the richtext block at the string position for an XY offset in the graphics object." 54 | gob [gob!] 55 | position [pair!] 56 | ] 57 | 58 | show: command [ 59 | "Display or update a graphical object or block of them." 60 | gob [gob! none!] 61 | ] 62 | 63 | size-text: command [ 64 | "Returns the size of text rendered by a graphics object." 65 | gob [gob!] 66 | ] 67 | 68 | draw: command [ 69 | "Renders draw dialect (scalable vector graphics) to an image (returned)." 70 | image [image! pair!] "Image or size of image" 71 | commands [block!] "Draw commands" 72 | ] 73 | 74 | gui-metric: command [ 75 | "Returns specific gui related metric setting." 76 | keyword [word!] "Available keywords: SCREEN-SIZE, BORDER-SIZE, BORDER-FIXED, TITLE-SIZE, WORK-ORIGIN and WORK-SIZE." 77 | ] 78 | 79 | ;#not-yet-used [ 80 | ; 81 | ;effect: command [ 82 | ; "Renders effect dialect to an image (returned)." 83 | ; image [image! pair!] "Image or size of image" 84 | ; commands [block!] "Effect commands" 85 | ;] 86 | ; 87 | ;] 88 | -------------------------------------------------------------------------------- /src/boot/modes.r: -------------------------------------------------------------------------------- 1 | REBOL [ 2 | System: "REBOL [R3] Language Interpreter and Run-time Environment" 3 | Title: "Port modes" 4 | Rights: { 5 | Copyright 2012 REBOL Technologies 6 | REBOL is a trademark of REBOL Technologies 7 | } 8 | License: { 9 | Licensed under the Apache License, Version 2.0. 10 | See: http://www.apache.org/licenses/LICENSE-2.0 11 | } 12 | ] 13 | 14 | owner-read 15 | owner-write 16 | owner-execute 17 | group-read 18 | group-write 19 | group-execute 20 | world-read 21 | world-write 22 | world-execute 23 | -------------------------------------------------------------------------------- /src/boot/ops.r: -------------------------------------------------------------------------------- 1 | REBOL [ 2 | System: "REBOL [R3] Language Interpreter and Run-time Environment" 3 | Title: "Infix operator symbol definitions" 4 | Rights: { 5 | Copyright 2012 REBOL Technologies 6 | REBOL is a trademark of REBOL Technologies 7 | } 8 | License: { 9 | Licensed under the Apache License, Version 2.0. 10 | See: http://www.apache.org/licenses/LICENSE-2.0 11 | } 12 | Purpose: { 13 | This table maps infix operator symbols to function names. 14 | } 15 | ] 16 | 17 | + add 18 | - subtract 19 | * multiply 20 | / divide 21 | // remainder 22 | ** power 23 | = equal? 24 | =? same? 25 | == strict-equal? 26 | != not-equal? 27 | <> not-equal? 28 | !== strict-not-equal? 29 | < lesser? 30 | <= lesser-or-equal? 31 | > greater? 32 | >= greater-or-equal? 33 | & and~ 34 | | or~ 35 | and and~ 36 | or or~ 37 | xor xor~ 38 | -------------------------------------------------------------------------------- /src/boot/platforms.r: -------------------------------------------------------------------------------- 1 | REBOL [ 2 | System: "REBOL [R3] Language Interpreter and Run-time Environment" 3 | Title: "Platform definitions" 4 | Rights: { 5 | Copyright 2012 REBOL Technologies 6 | REBOL is a trademark of REBOL Technologies 7 | } 8 | License: { 9 | Licensed under the Apache License, Version 2.0. 10 | See: http://www.apache.org/licenses/LICENSE-2.0 11 | } 12 | Purpose: { 13 | Platform identification found in system object. 14 | } 15 | ] 16 | 17 | 1 Amiga [ 18 | 1 m68k20+ 19 | 2 m68k 20 | 3 ppc 21 | ] 22 | 23 | 2 Macintosh [ 24 | 1 mac-ppc 25 | 2 mac-m68k 26 | 3 mac-misc 27 | 4 osx-ppc 28 | 5 osx-x86 29 | 40 osx-x64 30 | ] 31 | 32 | 3 Windows [ 33 | 1 win32-x86 34 | 2 dec-alpha 35 | 40 win32-x64 36 | ] 37 | 38 | 4 Linux [ 39 | 1 libc5-x86 40 | 2 libc6-2-3-x86 41 | 3 libc6-2-5-x86 42 | 4 libc6-2-11-x86 43 | 10 libc6-ppc 44 | 20 libc6-arm 45 | 21 bionic-arm 46 | 30 libc6-mips 47 | 40 libc-x64 48 | ] 49 | 50 | 5 Haiku [ 51 | 75 x86-32 52 | ] 53 | 54 | 6 BSDi [ 55 | 1 x86 56 | ] 57 | 58 | 7 FreeBSD [ 59 | 1 x86 60 | 2 elf-x86 61 | 40 elf-x64 62 | ] 63 | 64 | 8 NetBSD [ 65 | 1 x86 66 | 2 ppc 67 | 3 m68k 68 | 4 dec-alpha 69 | 5 sparc 70 | ] 71 | 72 | 9 OpenBSD [ 73 | 1 x86 74 | 2 ppc 75 | 3 m68k 76 | 4 elf-x86 77 | 5 sparc 78 | ] 79 | 80 | 10 Sun [ 81 | 1 sparc 82 | ] 83 | 84 | 11 SGI [] 85 | 86 | 12 HP [] 87 | 88 | 13 Android [ 89 | 1 arm 90 | ] 91 | 92 | 14 free-slot [] 93 | 94 | 15 WindowsCE [ 95 | 1 sh3 96 | 2 mips 97 | 5 arm 98 | 6 sh4 99 | ] 100 | -------------------------------------------------------------------------------- /src/boot/root.r: -------------------------------------------------------------------------------- 1 | REBOL [ 2 | System: "REBOL [R3] Language Interpreter and Run-time Environment" 3 | Title: "Root context" 4 | Rights: { 5 | Copyright 2012 REBOL Technologies 6 | REBOL is a trademark of REBOL Technologies 7 | } 8 | License: { 9 | Licensed under the Apache License, Version 2.0. 10 | See: http://www.apache.org/licenses/LICENSE-2.0 11 | } 12 | Purpose: { 13 | Root system values. This context is hand-made very early at boot time 14 | to allow it to hold key system values during boot up. Most of these 15 | are put here to prevent them from being garbage collected. 16 | } 17 | Note: "See Task Context for per-task globals" 18 | ] 19 | 20 | self ; (hand-built CONTEXT! value - but, has no WORD table!) 21 | root ; the root context as a block (for GC protection) 22 | 23 | system ; system object 24 | errobj ; error object template 25 | strings ; low-level strings accessed via Boot_Strs[] (GC protection) 26 | typesets ; block of TYPESETs used by system; expandable 27 | noneval ; NONE value 28 | noname ; noname function word 29 | 30 | boot ; boot block defined in boot.r (GC'd after boot is done) 31 | 32 | -------------------------------------------------------------------------------- /src/boot/shape.r: -------------------------------------------------------------------------------- 1 | REBOL [ 2 | System: "REBOL [R3] Language Interpreter and Run-time Environment" 3 | Title: "REBOL Graphics - SHAPE commands" 4 | Rights: { 5 | Copyright 2012 REBOL Technologies 6 | REBOL is a trademark of REBOL Technologies 7 | } 8 | License: { 9 | Licensed under the Apache License, Version 2.0. 10 | See: http://www.apache.org/licenses/LICENSE-2.0 11 | } 12 | Name: shape 13 | Type: extension 14 | Exports: none 15 | Note: "Run make-host-ext.r to convert" 16 | ] 17 | 18 | ;don't change order of already defined words unless you know what you are doing 19 | 20 | words: [ 21 | ;arc 22 | negative 23 | positive 24 | small 25 | large 26 | ] 27 | 28 | ;temp hack - will be removed later 29 | init-words: command [ 30 | words [block!] 31 | ] 32 | 33 | init-words words 34 | 35 | ;please alphabetize the order of commands so it easier to lookup things 36 | 37 | arc: command [ 38 | "Draws an elliptical arc from the current point." 39 | end-point [pair!] 40 | radius [pair!] 41 | angle [number!] 42 | 'sweep-flag [word!] "The arc will be drawn in POSITIVE or NEGATIVE angle direction" 43 | 'arc-flag [word!] "User SMALL or LARGE arc sweep" 44 | ] 45 | 46 | arc': command [ 47 | "Draws an elliptical arc from the current point.(uses relative coordinates)" 48 | end-point [pair!] 49 | radius [pair!] 50 | angle [number!] 51 | 'sweep-flag [word!] "The arc will be drawn in POSITIVE or NEGATIVE angle direction" 52 | 'arc-flag [word!] "User SMALL or LARGE arc sweep" 53 | ] 54 | 55 | close: command [ 56 | "Closes previously defined set of lines in the SHAPE block." 57 | ] 58 | 59 | curv: command [ 60 | "Draws a cubic Bezier curve or polybezier using two points." 61 | points [block!] "Block of point pairs (2nd control point, end point)" 62 | ] 63 | 64 | curv': command [ 65 | "Draws a cubic Bezier curve or polybezier using two points.(uses relative coordinates)" 66 | points [block!] "Block of point pairs (2nd control point, end point)" 67 | ] 68 | 69 | curve: command [ 70 | "Draws a cubic Bezier curve or polybezier using three points." 71 | points [block!] "Block of point triplets (1st control point, 2nd control point, end point)" 72 | ] 73 | 74 | curve': command [ 75 | "Draws a cubic Bezier curve or polybezier using three points.(uses relative coordinates)" 76 | points [block!] "Block of point triplets (1st control point, 2nd control point, end point)" 77 | ] 78 | 79 | hline: command [ 80 | "Draws a horizontal line from the current point." 81 | end-x [number!] 82 | ] 83 | 84 | hline': command [ 85 | "Draws a horizontal line from the current point.(uses relative coordinates)" 86 | end-x [number!] 87 | ] 88 | 89 | line: command [ 90 | "Draws a line from the current point through the given points." 91 | points [pair! block!] 92 | ] 93 | 94 | line': command [ 95 | "Draws a line from the current point through the given points.(uses relative coordinates)" 96 | points [pair! block!] 97 | ] 98 | 99 | move: command [ 100 | "Set's the starting point for a new path without drawing anything." 101 | point [pair!] 102 | ] 103 | 104 | move': command [ 105 | "Set's the starting point for a new path without drawing anything.(uses relative coordinates)" 106 | point [pair!] 107 | ] 108 | 109 | qcurv: command [ 110 | "Draws a quadratic Bezier curve from the current point to end point." 111 | end-point [pair!] 112 | ] 113 | 114 | qcurv': command [ 115 | "Draws a quadratic Bezier curve from the current point to end point.(uses relative coordinates)" 116 | end-point [pair!] 117 | ] 118 | 119 | qcurve: command [ 120 | "Draws a quadratic Bezier curve using two points." 121 | points [block!] "Block of point pairs (control point, end point)" 122 | ] 123 | 124 | qcurve': command [ 125 | "Draws a quadratic Bezier curve using two points.(uses relative coordinates)" 126 | points [block!] "Block of point pairs (control point, end point)" 127 | ] 128 | 129 | vline: command [ 130 | "Draws a vertical line from the current point." 131 | end-y [number!] 132 | ] 133 | 134 | vline': command [ 135 | "Draws a vertical line from the current point.(uses relative coordinates)" 136 | end-y [number!] 137 | ] 138 | -------------------------------------------------------------------------------- /src/boot/strings.r: -------------------------------------------------------------------------------- 1 | REBOL [ 2 | System: "REBOL [R3] Language Interpreter and Run-time Environment" 3 | Title: "Low-level strings" 4 | Rights: { 5 | Copyright 2012 REBOL Technologies 6 | REBOL is a trademark of REBOL Technologies 7 | } 8 | License: { 9 | Licensed under the Apache License, Version 2.0. 10 | See: http://www.apache.org/licenses/LICENSE-2.0 11 | } 12 | Purpose: { 13 | This section holds lower-level C strings used in various parts 14 | of the system. This section is unique, because it constructs a 15 | single C string that contains all the specified strings below. 16 | This is done to eliminate series headers required for normal 17 | REBOL strings. The strings are referenced using Boot_Strs[RS_*] 18 | where * is the set-word (and is zero based). For example: 19 | RS_SCAN+3 refers to "end-of-paren" 20 | } 21 | ] 22 | 23 | scan: ; Used by scanner. Keep in sync with Value_Types in scan.h file! 24 | "end-of-script" 25 | "line" 26 | "end-of-block" 27 | "end-of-paren" 28 | "word" 29 | "word-set" 30 | "word-get" 31 | "word-lit" 32 | "none" 33 | "logic" 34 | "integer" 35 | "decimal" 36 | "percent" 37 | "money" 38 | "time" 39 | "date" 40 | "char" 41 | "block" 42 | "paren" 43 | "string" 44 | "binary" 45 | "pair" 46 | "tuple" 47 | "file" 48 | "email" 49 | "url" 50 | "issue" 51 | "tag" 52 | "path" 53 | "refine" 54 | "construct" 55 | 56 | info: 57 | "Booting..." 58 | 59 | ;secure: 60 | ; "Script requests permission to " 61 | ; "Script requests permission to lower security level" 62 | ; "REBOL - Security Violation" 63 | ; "unknown" 64 | 65 | ;secopts: 66 | ; "open a port for read only on: " 67 | ; "open a port for read/write on: " 68 | ; "delete: " 69 | ; "rename: " 70 | ; "make a directory named: " 71 | ; "lower security" 72 | ; "execute a system shell command: " 73 | 74 | trace: 75 | "trace" 76 | "%-02d: %50r" 77 | " : %50r" 78 | " : %s %50m" 79 | " : %s" 80 | "--> %s" 81 | "<-- %s ==" 82 | "Parse match: %r" 83 | "Parse input: %s" 84 | "Parse back: %r" 85 | "**: error : %r %r" ; 10 86 | 87 | stack: 88 | "STACK Expanded - DSP: %d MAX: %d" 89 | "^/STACK[%d] %s[%d] %s" 90 | 91 | dump: 92 | "^/--REBOL Kernel Dump--" 93 | "Evaluator:" 94 | " Cycles: %d" ; only lower bits 95 | " Counter: %d" 96 | " Dose: %d" 97 | " Signals: %x" 98 | " Sigmask: %x" 99 | " DSP: %d" 100 | " DSF: %d" 101 | "Memory/GC:" 102 | " Ballast: %d" 103 | " Disable: %d" 104 | " Protect: %d" 105 | " Infants: %d" 106 | 107 | ;stats: 108 | ; "Stats: bad series value: %d in: %x offset: %d size: %d" 109 | 110 | error: 111 | "out of memory (req %d bytes)" 112 | "invalid series width %d got %d type %d" 113 | ; "error catalog object out of range" 114 | ; "error num in category out of range" 115 | "error already caught" 116 | "stack overflow" 117 | "I/O error" 118 | "too many words" 119 | "word list buffer in use" 120 | "locked series" 121 | "error recycled" 122 | "top level error not caught" 123 | "error state underflow" 124 | "event queue overflow (WAIT recursion?)" 125 | "not available (NA)" 126 | 127 | errs: 128 | " error: " 129 | "(improperly formatted error)" 130 | "** Where: " 131 | "** Near: " 132 | 133 | watch: 134 | "RECYCLING: " 135 | "%d series" 136 | "obj-copy: %d %m" 137 | 138 | extension: 139 | "RX_Init" 140 | "RX_Quit" 141 | "RX_Call" 142 | 143 | ;plugin: 144 | ; "cannot open" 145 | ; "missing function" 146 | ; "wrong version" 147 | ; "no header" 148 | ; "bad header" 149 | ; "boot code failed" 150 | -------------------------------------------------------------------------------- /src/boot/task.r: -------------------------------------------------------------------------------- 1 | REBOL [ 2 | System: "REBOL [R3] Language Interpreter and Run-time Environment" 3 | Title: "Task context" 4 | Rights: { 5 | Copyright 2012 REBOL Technologies 6 | REBOL is a trademark of REBOL Technologies 7 | } 8 | License: { 9 | Licensed under the Apache License, Version 2.0. 10 | See: http://www.apache.org/licenses/LICENSE-2.0 11 | } 12 | Purpose: { 13 | Globals used for each task. Prevents GC of these values. 14 | See also the Root Context (program-wide globals) 15 | } 16 | ] 17 | 18 | self 19 | stack ; data stack 20 | ballast ; current memory ballast (used for GC) 21 | max-ballast ; ballast reset value 22 | this-error ; current error 23 | this-value ; for holding an error argument during throw back 24 | stack-error ; special stack error object 25 | this-context ; current context 26 | buf-emit ; temporary emit output block 27 | buf-words ; temporary word cache 28 | buf-utf8 ; UTF8 reused buffer 29 | buf-print ; temporary print output - used by raw print 30 | buf-form ; temporary form buffer - used by raw print 31 | buf-mold ; temporary mold buffer - used by mold 32 | mold-loop ; mold loop detection 33 | err-temps ; error temporaries 34 | 35 | -------------------------------------------------------------------------------- /src/boot/text.r: -------------------------------------------------------------------------------- 1 | REBOL [ 2 | System: "REBOL [R3] Language Interpreter and Run-time Environment" 3 | Title: "REBOL Graphics - TEXT commands" 4 | Rights: { 5 | Copyright 2012 REBOL Technologies 6 | REBOL is a trademark of REBOL Technologies 7 | } 8 | License: { 9 | Licensed under the Apache License, Version 2.0. 10 | See: http://www.apache.org/licenses/LICENSE-2.0 11 | } 12 | Name: text 13 | Type: extension 14 | Exports: none 15 | Note: "Run make-host-ext.r to convert" 16 | ] 17 | 18 | ;don't change order of already defined words unless you know what you are doing 19 | 20 | words: [ 21 | aliased 22 | antialiased 23 | vectorial 24 | 25 | ;font object words 26 | name 27 | style 28 | size 29 | color 30 | offset 31 | space 32 | shadow 33 | 34 | ;para object words 35 | origin 36 | margin 37 | indent 38 | tabs 39 | wrap? 40 | scroll 41 | align 42 | valign 43 | 44 | ;para/align values 45 | center 46 | right 47 | left 48 | 49 | ;para/valign values 50 | middle 51 | top 52 | bottom 53 | 54 | ;font/style values 55 | bold 56 | italic 57 | underline 58 | 59 | ;caret object words 60 | caret 61 | highlight-start 62 | highlight-end 63 | ] 64 | 65 | ;temp hack - will be removed later 66 | init-words: command [ 67 | words [block!] 68 | ] 69 | 70 | init-words words 71 | 72 | ;please alphabetize the order of commands so it easier to lookup things 73 | 74 | anti-alias: command [ 75 | "Sets aliasing mode." 76 | state [logic!] 77 | ] 78 | 79 | b: bold: command [ 80 | "Sets font BOLD style." 81 | state [logic!] 82 | ] 83 | 84 | caret: command [ 85 | "Sets paragraph attributes." 86 | caret-attributes [object!] 87 | ] 88 | 89 | center: command [ 90 | "Sets text alignment." 91 | ] 92 | 93 | color: command [ 94 | "Sets font color." 95 | font-color [tuple!] 96 | ] 97 | 98 | drop: command [ 99 | "Removes N previous style setting from the stack." 100 | count [integer!] 101 | ] 102 | 103 | font: command [ 104 | "Sets font attributes." 105 | font-attributes [object!] 106 | ] 107 | 108 | i: italic: command [ 109 | "Sets font ITALIC style." 110 | state [logic!] 111 | ] 112 | 113 | left: command [ 114 | "Sets text alignment." 115 | ] 116 | 117 | nl: newline: command [ 118 | "Breaks the text line." 119 | ] 120 | 121 | para: command [ 122 | "Sets paragraph attributes." 123 | para-attributes [object!] 124 | ] 125 | 126 | right: command [ 127 | "Sets text alignment." 128 | ] 129 | 130 | scroll: command [ 131 | "Sets text position." 132 | offset [pair!] 133 | ] 134 | 135 | shadow: command [ 136 | "Enables shadow effect for text." 137 | offset [pair!] 138 | color [tuple!] 139 | spread [integer!] 140 | ] 141 | 142 | size: command [ 143 | "Sets font size." 144 | font-size [integer!] 145 | ] 146 | 147 | text: command [ 148 | "Renders text string." 149 | text [string!] 150 | ] 151 | 152 | u: underline: command [ 153 | "Sets font UNDERLINE style." 154 | state [logic!] 155 | ] 156 | 157 | -------------------------------------------------------------------------------- /src/boot/types-ext.r: -------------------------------------------------------------------------------- 1 | REBOL [ 2 | System: "REBOL [R3] Language Interpreter and Run-time Environment" 3 | Title: "Extension datatypes" 4 | Rights: { 5 | Copyright 2012 REBOL Technologies 6 | REBOL is a trademark of REBOL Technologies 7 | } 8 | License: { 9 | Licensed under the Apache License, Version 2.0 10 | See: http://www.apache.org/licenses/LICENSE-2.0 11 | } 12 | Purpose: { 13 | Used to build C enums and definitions for extensions. 14 | } 15 | ] 16 | 17 | end 0 0 18 | unset * null 19 | none * null 20 | handle * ptr 21 | 22 | logic 4 32 23 | integer * 64 24 | decimal * 64 25 | percent * 64 26 | 27 | char 10 32 28 | pair * 64 29 | tuple * 64 30 | time * 64 31 | date * date 32 | 33 | word 16 sym 34 | set-word * sym 35 | get-word * sym 36 | lit-word * sym 37 | refinement * sym 38 | issue * sym 39 | 40 | string 24 ser 41 | file * ser 42 | email * ser 43 | url * ser 44 | tag * ser 45 | 46 | block 32 ser 47 | paren * ser 48 | path * ser 49 | set-path * ser 50 | get-path * ser 51 | lit-path * ser 52 | 53 | binary 40 ser 54 | bitset * ser 55 | vector * ser 56 | image * image 57 | 58 | gob 47 ser 59 | 60 | object 48 ptr 61 | module * ptr 62 | 63 | -------------------------------------------------------------------------------- /src/boot/typespec.r: -------------------------------------------------------------------------------- 1 | REBOL [ 2 | System: "REBOL [R3] Language Interpreter and Run-time Environment" 3 | Title: "Datatype help spec" 4 | Rights: { 5 | Copyright 2012 REBOL Technologies 6 | REBOL is a trademark of REBOL Technologies 7 | } 8 | License: { 9 | Licensed under the Apache License, Version 2.0 10 | See: http://www.apache.org/licenses/LICENSE-2.0 11 | } 12 | Purpose: { 13 | Provides useful information about datatypes. 14 | Can be expanded to include info like min-max ranges. 15 | } 16 | ] 17 | 18 | action ["datatype native function (standard polymorphic)" function] 19 | binary ["string series of bytes" string] 20 | bitset ["set of bit flags" string] 21 | block ["series of values" block] 22 | char ["8bit and 16bit character" scalar] 23 | closure ["function with persistent locals (indefinite extent)" function] 24 | datatype ["type of datatype" symbol] 25 | date ["day, month, year, time of day, and timezone" scalar] 26 | decimal ["64bit floating point number (IEEE standard)" scalar] 27 | email ["email address" string] 28 | end ["internal marker for end of block" internal] 29 | error ["errors and throws" object] 30 | event ["user interface event (efficiently sized)" opt-object] 31 | file ["file name or path" string] 32 | frame ["internal context frame" internal] 33 | function ["interpreted function (user-defined or mezzanine)" function] 34 | get-path ["the value of a path" block] 35 | get-word ["the value of a word (variable)" word] 36 | gob ["graphical object" opt-object] 37 | handle ["arbitrary internal object or value" internal] 38 | image ["RGB image with alpha channel" vector] 39 | integer ["64 bit integer" scalar] 40 | issue ["identifying marker word" word] 41 | library ["external library reference" internal] 42 | lit-path ["literal path value" block] 43 | lit-word ["literal word value" word] 44 | logic ["boolean true or false" scalar] 45 | map ["name-value pairs (hash associative)" block] 46 | module ["loadable context of code and data" object] 47 | money ["high precision decimals with denomination (opt)" scalar] 48 | native ["direct CPU evaluated function" function] 49 | none ["no value represented" scalar] 50 | object ["context of names with values" object] 51 | op ["infix operator (special evaluation exception)" function] 52 | pair ["two dimensional point or size" scalar] 53 | paren ["automatically evaluating block" block] 54 | path ["refinements to functions, objects, files" block] 55 | percent ["special form of decimals (used mainly for layout)" scalar] 56 | port ["external series, an I/O channel" object] 57 | rebcode ["virtual machine function" block] 58 | refinement ["variation of meaning or location" word] 59 | command ["special dispatch-based function" function] 60 | set-path ["definition of a path's value" block] 61 | set-word ["definition of a word's value" word] 62 | string ["string series of characters" string] 63 | struct ["native structure definition" block] 64 | tag ["markup string (HTML or XML)" string] 65 | task ["evaluation environment" object] 66 | time ["time of day or duration" scalar] 67 | tuple ["sequence of small integers (colors, versions, IP)" scalar] 68 | typeset ["set of datatypes" opt-object] 69 | unicode ["string of unicoded characters" string] 70 | unset ["no value returned or set" internal] 71 | url ["uniform resource locator or identifier" string] 72 | utype ["user defined datatype" object] 73 | vector ["high performance arrays (single datatype)" vector] 74 | word ["word (symbol or variable)" word] 75 | 76 | -------------------------------------------------------------------------------- /src/boot/version.r: -------------------------------------------------------------------------------- 1 | 2.101.0.3.1 2 | -------------------------------------------------------------------------------- /src/boot/words.r: -------------------------------------------------------------------------------- 1 | REBOL [ 2 | System: "REBOL [R3] Language Interpreter and Run-time Environment" 3 | Title: "Canonical words" 4 | Rights: { 5 | Copyright 2012 REBOL Technologies 6 | REBOL is a trademark of REBOL Technologies 7 | } 8 | License: { 9 | Licensed under the Apache License, Version 2.0 10 | See: http://www.apache.org/licenses/LICENSE-2.0 11 | } 12 | Purpose: { 13 | These words are used internally by REBOL and must have specific canon 14 | word values in order to be correctly identified. 15 | } 16 | ] 17 | 18 | any-type! 19 | any-word! 20 | any-path! 21 | any-function! 22 | number! 23 | scalar! 24 | series! 25 | any-string! 26 | any-object! 27 | any-block! 28 | 29 | datatypes 30 | 31 | native 32 | self 33 | none 34 | true 35 | false 36 | on 37 | off 38 | yes 39 | no 40 | pi 41 | 42 | rebol 43 | 44 | system 45 | 46 | ;boot levels 47 | base 48 | sys 49 | mods 50 | 51 | ;reflectors: 52 | spec 53 | body 54 | words 55 | values 56 | types 57 | title 58 | 59 | x 60 | y 61 | + 62 | - 63 | * 64 | unsigned 65 | -unnamed- ; lambda (unnamed) functions 66 | -apply- ; apply func 67 | code ; error field 68 | delect 69 | 70 | ; Secure: (add to system/state/policies object too) 71 | secure 72 | protect 73 | net 74 | call 75 | envr 76 | eval 77 | memory 78 | debug 79 | browse 80 | extension 81 | ;dir - below 82 | ;file - below 83 | 84 | ; Time: 85 | hour 86 | minute 87 | second 88 | 89 | ; Date: 90 | year 91 | month 92 | day 93 | time 94 | date 95 | weekday 96 | julian 97 | yearday 98 | zone 99 | utc 100 | 101 | ; Parse: - These words must not reserved above!! 102 | parse 103 | | ; must be first 104 | ; prep words: 105 | set 106 | copy 107 | some 108 | any 109 | opt 110 | not 111 | and 112 | then 113 | remove 114 | insert 115 | change 116 | if 117 | fail 118 | reject 119 | while 120 | return 121 | limit 122 | ?? 123 | accept 124 | break 125 | ; match words: 126 | skip 127 | to 128 | thru 129 | quote 130 | do 131 | into 132 | only 133 | end ; must be last 134 | 135 | ; Event: 136 | type 137 | key 138 | port 139 | mode 140 | window 141 | double 142 | control 143 | shift 144 | 145 | ; Checksum 146 | sha1 147 | md4 148 | md5 149 | crc32 150 | 151 | ; Codec actions 152 | identify 153 | decode 154 | encode 155 | 156 | ; Schemes 157 | console 158 | file 159 | dir 160 | event 161 | callback 162 | dns 163 | tcp 164 | udp 165 | clipboard 166 | 167 | ; Gobs: 168 | gob 169 | offset 170 | size 171 | pane 172 | parent 173 | image 174 | draw 175 | text 176 | effect 177 | color 178 | flags 179 | rgb 180 | alpha 181 | data 182 | resize 183 | no-title 184 | no-border 185 | dropable 186 | transparent 187 | popup 188 | modal 189 | on-top 190 | hidden 191 | owner 192 | 193 | *port-modes* 194 | 195 | bits 196 | crash 197 | crash-dump 198 | watch-recycle 199 | watch-obj-copy 200 | stack-size 201 | 202 | -------------------------------------------------------------------------------- /src/core/a-constants.c: -------------------------------------------------------------------------------- 1 | /*********************************************************************** 2 | ** 3 | ** REBOL [R3] Language Interpreter and Run-time Environment 4 | ** 5 | ** Copyright 2012 REBOL Technologies 6 | ** REBOL is a trademark of REBOL Technologies 7 | ** 8 | ** Licensed under the Apache License, Version 2.0 (the "License"); 9 | ** you may not use this file except in compliance with the License. 10 | ** You may obtain a copy of the License at 11 | ** 12 | ** http://www.apache.org/licenses/LICENSE-2.0 13 | ** 14 | ** Unless required by applicable law or agreed to in writing, software 15 | ** distributed under the License is distributed on an "AS IS" BASIS, 16 | ** WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 17 | ** See the License for the specific language governing permissions and 18 | ** limitations under the License. 19 | ** 20 | ************************************************************************ 21 | ** 22 | ** Module: a-constants.c 23 | ** Summary: special global constants and strings 24 | ** Section: environment 25 | ** Author: Carl Sassenrath 26 | ** Notes: 27 | ** Very few strings should be located here. Most strings are 28 | ** put in the compressed embedded boot image. That saves space, 29 | ** reduces tampering, and allows UTF8 encoding. See ../boot dir. 30 | ** 31 | ***********************************************************************/ 32 | 33 | #include "sys-core.h" 34 | 35 | #define BP (REBYTE*) 36 | 37 | const REBYTE Str_Banner[] = "REBOL 3 %d.%d.%d.%d.%d"; 38 | 39 | const char Str_REBOL[] = "REBOL"; 40 | 41 | const REBYTE * Str_Stack_Misaligned = { 42 | BP("!! Stack misaligned: %d") 43 | }; 44 | 45 | const REBYTE * const Crash_Msgs[] = { 46 | BP"REBOL System Error", 47 | BP"boot failure", 48 | BP"internal problem", 49 | BP"assertion failed", 50 | BP"invalid datatype %d", 51 | BP"unspecific", 52 | BP"\n\nProgram terminated abnormally.\nThis should never happen.\nPlease contact www.REBOL.com with details." 53 | }; 54 | 55 | const REBYTE * const Str_Dump[] = { 56 | BP"%s Series %x \"%s\": wide: %2d size: %6d bias: %d tail: %d rest: %d flags: %x" 57 | }; 58 | 59 | const REBYTE * Hex_Digits = BP"0123456789ABCDEF"; 60 | 61 | const REBYTE * const Bad_Ptr = BP"#[BAD-PTR]"; 62 | 63 | const REBYTE * const Esc_Names[] = { 64 | // Must match enum REBOL_Esc_Codes! 65 | BP"line", 66 | BP"tab", 67 | BP"page", 68 | BP"escape", 69 | BP"esc", 70 | BP"back", 71 | BP"del", 72 | BP"null" 73 | }; 74 | 75 | const REBYTE Esc_Codes[] = { 76 | // Must match enum REBOL_Esc_Codes! 77 | 10, 78 | 9, 79 | 12, 80 | 27, 81 | 27, 82 | 8, 83 | 127, 84 | 0 85 | }; 86 | 87 | const REBYTE Month_Lengths[12] = { 88 | 31, 29, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31 89 | }; 90 | 91 | const REBYTE * const Month_Names[12] = { 92 | BP"January", BP"February", BP"March", 93 | BP"April", BP"May", BP"June", 94 | BP"July", BP"August", BP"September", 95 | BP"October", BP"November", BP"December" 96 | }; 97 | 98 | -------------------------------------------------------------------------------- /src/core/a-globals.c: -------------------------------------------------------------------------------- 1 | /*********************************************************************** 2 | ** 3 | ** REBOL [R3] Language Interpreter and Run-time Environment 4 | ** 5 | ** Copyright 2012 REBOL Technologies 6 | ** REBOL is a trademark of REBOL Technologies 7 | ** 8 | ** Licensed under the Apache License, Version 2.0 (the "License"); 9 | ** you may not use this file except in compliance with the License. 10 | ** You may obtain a copy of the License at 11 | ** 12 | ** http://www.apache.org/licenses/LICENSE-2.0 13 | ** 14 | ** Unless required by applicable law or agreed to in writing, software 15 | ** distributed under the License is distributed on an "AS IS" BASIS, 16 | ** WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 17 | ** See the License for the specific language governing permissions and 18 | ** limitations under the License. 19 | ** 20 | ************************************************************************ 21 | ** 22 | ** Module: a-globals.c 23 | ** Summary: global variables 24 | ** Section: environment 25 | ** Author: Carl Sassenrath 26 | ** Notes: 27 | ** There are two types of global variables: 28 | ** process vars - single instance for main process 29 | ** thread vars - duplicated within each R3 task 30 | ** 31 | ***********************************************************************/ 32 | 33 | /* To do: there are still a few globals in various modules that need to be 34 | ** incorporated back into sys-globals.h. 35 | */ 36 | 37 | #include "sys-core.h" 38 | 39 | #undef PVAR 40 | #undef TVAR 41 | 42 | #define PVAR 43 | #define TVAR THREAD 44 | 45 | #include "sys-globals.h" 46 | -------------------------------------------------------------------------------- /src/core/a-lib2.c: -------------------------------------------------------------------------------- 1 | /*********************************************************************** 2 | ** 3 | ** REBOL [R3] Language Interpreter and Run-time Environment 4 | ** 5 | ** Copyright 2012 REBOL Technologies 6 | ** REBOL is a trademark of REBOL Technologies 7 | ** 8 | ** Licensed under the Apache License, Version 2.0 (the "License"); 9 | ** you may not use this file except in compliance with the License. 10 | ** You may obtain a copy of the License at 11 | ** 12 | ** http://www.apache.org/licenses/LICENSE-2.0 13 | ** 14 | ** Unless required by applicable law or agreed to in writing, software 15 | ** distributed under the License is distributed on an "AS IS" BASIS, 16 | ** WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 17 | ** See the License for the specific language governing permissions and 18 | ** limitations under the License. 19 | ** 20 | ************************************************************************ 21 | ** 22 | ** Module: a-lib2.c 23 | ** Summary: skip 24 | ** Section: environment 25 | ** Author: Carl Sassenrath 26 | ** Notes: 27 | ** 28 | ***********************************************************************/ 29 | 30 | #include "sys-core.h" 31 | #include "reb-dialect.h" 32 | #include "reb-ext.h" 33 | #include "sys-state.h" 34 | 35 | 36 | // Load this to verify function prototypes: 37 | #include "rebol-lib.h" 38 | 39 | /*********************************************************************** 40 | ** 41 | x*/ REBOL_API REBINT Reb_Dialect(REBINT dialect, REBSER *block, REBCNT *index, REBSER **arglist) 42 | /* 43 | ** Process a standard dialect. 44 | ** 45 | ** The index points to the next value to interpret and is updated 46 | ** on return (for next loop or error). The system/dialect 47 | ** object is used for the dialect specification. 48 | ** 49 | ** A block is returned with the arguments, ordered according 50 | ** to the dialect specification for the command. Note that the 51 | ** returned block is reset and reused with each command. (To 52 | ** minimize GC trash.). The cmd arg returns the command number 53 | ** or error number (when result is zero). 54 | ** 55 | ** A zero is returned for errors and end-of-block. For the former 56 | ** an error is returned in cmd. For the latter, cmd is zero. 57 | ** 58 | ***********************************************************************/ 59 | { 60 | REBVAL *val = Get_System(SYS_DIALECTS, 0); 61 | 62 | if (!IS_OBJECT(val) 63 | || dialect <= 0 64 | || dialect >= (REBINT)SERIES_TAIL(VAL_OBJ_FRAME(val)) 65 | ) { 66 | return -REB_DIALECT_MISSING; 67 | } 68 | 69 | val = Get_System(SYS_DIALECTS, dialect); 70 | if (!IS_OBJECT(val)) return -REB_DIALECT_MISSING;; 71 | return Do_Dialect(VAL_OBJ_FRAME(val), block, index, arglist); 72 | } 73 | 74 | 75 | /*********************************************************************** 76 | ** 77 | x*/ REBOL_API void Reb_Set_Var(void *var, void *value) 78 | /* 79 | ***********************************************************************/ 80 | { 81 | Set_Var(var, value); // Check context, index, range 82 | } 83 | 84 | 85 | /*********************************************************************** 86 | ** 87 | x*/ REBOL_API REBINT Reb_Map_Words(REBYTE **names, REBCNT *symbols) 88 | /* 89 | ** Given null terminated list of word names, supply the 90 | ** symbol values for those words. Return length. 91 | ** The names must be UTF8 valid. 92 | ** 93 | ***********************************************************************/ 94 | { 95 | REBINT count = 0; 96 | 97 | for (; *names; names++, count++) { 98 | *symbols++ = Make_Word(*names, 0); 99 | } 100 | *symbols++ = 0; 101 | 102 | return count; 103 | } 104 | 105 | 106 | /*********************************************************************** 107 | ** 108 | x*/ REBOL_API REBINT Reb_Find_Word(REBCNT sym, REBCNT *symbols, REBINT limit) 109 | /* 110 | ** Search a symbol list for a word, and return the index for it. 111 | ** Return -1 if not found. Limit can be used to control how many 112 | ** words in the symbol list will be compared. 113 | ** 114 | ***********************************************************************/ 115 | { 116 | REBINT index; 117 | 118 | if (sym >= SERIES_TAIL(PG_Word_Table.series)) return -1; 119 | if (limit == 0) limit = 100000; 120 | 121 | for (index = 0; limit > 0 && symbols[index]; limit--, index++) { 122 | if (sym == symbols[index] || SYMBOL_TO_CANON(sym) == SYMBOL_TO_CANON(symbols[index])) 123 | return index; 124 | } 125 | 126 | return -1; 127 | } 128 | -------------------------------------------------------------------------------- /src/core/a-stubs.c: -------------------------------------------------------------------------------- 1 | /*********************************************************************** 2 | ** 3 | ** REBOL [R3] Language Interpreter and Run-time Environment 4 | ** 5 | ** Copyright 2012 REBOL Technologies 6 | ** REBOL is a trademark of REBOL Technologies 7 | ** 8 | ** Licensed under the Apache License, Version 2.0 (the "License"); 9 | ** you may not use this file except in compliance with the License. 10 | ** You may obtain a copy of the License at 11 | ** 12 | ** http://www.apache.org/licenses/LICENSE-2.0 13 | ** 14 | ** Unless required by applicable law or agreed to in writing, software 15 | ** distributed under the License is distributed on an "AS IS" BASIS, 16 | ** WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 17 | ** See the License for the specific language governing permissions and 18 | ** limitations under the License. 19 | ** 20 | ************************************************************************ 21 | ** 22 | ** Module: a-stubs.c 23 | ** Summary: function stubs 24 | ** Section: environment 25 | ** Author: Carl Sassenrath 26 | ** Notes: 27 | ** 28 | ***********************************************************************/ 29 | 30 | #include "sys-core.h" 31 | -------------------------------------------------------------------------------- /src/core/b-main.c: -------------------------------------------------------------------------------- 1 | /*********************************************************************** 2 | ** 3 | ** REBOL [R3] Language Interpreter and Run-time Environment 4 | ** 5 | ** Copyright 2012 REBOL Technologies 6 | ** REBOL is a trademark of REBOL Technologies 7 | ** 8 | ** Licensed under the Apache License, Version 2.0 (the "License"); 9 | ** you may not use this file except in compliance with the License. 10 | ** You may obtain a copy of the License at 11 | ** 12 | ** http://www.apache.org/licenses/LICENSE-2.0 13 | ** 14 | ** Unless required by applicable law or agreed to in writing, software 15 | ** distributed under the License is distributed on an "AS IS" BASIS, 16 | ** WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 17 | ** See the License for the specific language governing permissions and 18 | ** limitations under the License. 19 | ** 20 | ************************************************************************ 21 | ** 22 | ** Module: b-main.c 23 | ** Summary: skip 24 | ** Section: bootstrap 25 | ** Author: Carl Sassenrath 26 | ** Notes: 27 | ** 28 | ***********************************************************************/ 29 | #include "sys-core.h" 30 | 31 | static REBARGS Main_Args; // Not multi-threaded 32 | 33 | /*********************************************************************** 34 | ** 35 | */ char *Prompt_User() 36 | /* 37 | ***********************************************************************/ 38 | { 39 | char *text; 40 | 41 | Prin("DSP: %d Mem: %d >> ", DSP, PG_Mem_Usage); 42 | text = Input_Str(); 43 | if (*text == '\n') exit(0); 44 | return text; 45 | } 46 | 47 | 48 | /*********************************************************************** 49 | ** 50 | */ int main(int argc, char **argv) 51 | /* 52 | ***********************************************************************/ 53 | { 54 | char *cmd; 55 | 56 | // Parse command line arguments. Done early. May affect REBOL boot. 57 | Parse_Args(argc, argv, &Main_Args); 58 | 59 | Print_Str("REBOL 3.0\n"); 60 | 61 | REBOL_Init(&Main_Args); 62 | 63 | // Evaluate user input: 64 | while (TRUE) { 65 | cmd = Prompt_User(); 66 | REBOL_Do_String(cmd); 67 | if (!IS_UNSET(DS_TOP)) { 68 | //if (DSP > 0) { 69 | if (!IS_ERROR(DS_TOP)) { 70 | Prin("== "); 71 | Print_Value(DS_TOP, 0, TRUE); 72 | } else 73 | Print_Value(DS_TOP, 0, FALSE); 74 | //} 75 | } 76 | //DS_DROP; // result 77 | } 78 | 79 | return 0; 80 | } 81 | -------------------------------------------------------------------------------- /src/core/c-task.c: -------------------------------------------------------------------------------- 1 | /*********************************************************************** 2 | ** 3 | ** REBOL [R3] Language Interpreter and Run-time Environment 4 | ** 5 | ** Copyright 2012 REBOL Technologies 6 | ** REBOL is a trademark of REBOL Technologies 7 | ** 8 | ** Licensed under the Apache License, Version 2.0 (the "License"); 9 | ** you may not use this file except in compliance with the License. 10 | ** You may obtain a copy of the License at 11 | ** 12 | ** http://www.apache.org/licenses/LICENSE-2.0 13 | ** 14 | ** Unless required by applicable law or agreed to in writing, software 15 | ** distributed under the License is distributed on an "AS IS" BASIS, 16 | ** WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 17 | ** See the License for the specific language governing permissions and 18 | ** limitations under the License. 19 | ** 20 | ************************************************************************ 21 | ** 22 | ** Module: c-task.c 23 | ** Summary: sub-task support 24 | ** Section: core 25 | ** Author: Carl Sassenrath 26 | ** Notes: INCOMPLETE IMPLEMENTATION (partially operational) 27 | ** 28 | ***********************************************************************/ 29 | 30 | /* 31 | Making a Task: 32 | 33 | 1. Local copies of: 34 | Main globals 35 | For data stack 36 | Interpreter flags 37 | Memory management 38 | Root series (all or part?) 39 | Data stack 40 | System object (for module) 41 | C stack (thread provided) 42 | 43 | 2. Share copies of: 44 | Boot strings and values 45 | System functions (natives and mezzanine) 46 | Word table 47 | Various sub-objects of system object 48 | 49 | Task Spec is a module definition. Needs new context. 50 | 51 | Questions: 52 | System object is already copied for local user context 53 | System blocks might hold references to local series (how to GC) 54 | Can system values (objects and functions) be modified by other 55 | tasks? How are they protected? Is it good enough that our local 56 | references to functions refer to the older ones? How can we 57 | "update" our references? 58 | */ 59 | 60 | #include "sys-core.h" 61 | 62 | /*********************************************************************** 63 | ** 64 | */ static void Launch_Task(REBVAL *task) 65 | /* 66 | ***********************************************************************/ 67 | { 68 | REBSER *body; 69 | 70 | Debug_Str("Begin Task"); 71 | 72 | Init_Task(); 73 | body = Clone_Block(VAL_MOD_BODY(task)); 74 | OS_TASK_READY(0); 75 | Do_Blk(body, 0); 76 | 77 | Debug_Str("End Task"); 78 | } 79 | 80 | 81 | /*********************************************************************** 82 | ** 83 | */ void Do_Task(REBVAL *task) 84 | /* 85 | ***********************************************************************/ 86 | { 87 | OS_CREATE_THREAD((void*)Launch_Task, task, 50000); 88 | } 89 | -------------------------------------------------------------------------------- /src/core/d-crash.c: -------------------------------------------------------------------------------- 1 | /*********************************************************************** 2 | ** 3 | ** REBOL [R3] Language Interpreter and Run-time Environment 4 | ** 5 | ** Copyright 2012 REBOL Technologies 6 | ** REBOL is a trademark of REBOL Technologies 7 | ** 8 | ** Licensed under the Apache License, Version 2.0 (the "License"); 9 | ** you may not use this file except in compliance with the License. 10 | ** You may obtain a copy of the License at 11 | ** 12 | ** http://www.apache.org/licenses/LICENSE-2.0 13 | ** 14 | ** Unless required by applicable law or agreed to in writing, software 15 | ** distributed under the License is distributed on an "AS IS" BASIS, 16 | ** WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 17 | ** See the License for the specific language governing permissions and 18 | ** limitations under the License. 19 | ** 20 | ************************************************************************ 21 | ** 22 | ** Module: d-crash.c 23 | ** Summary: low level crash output 24 | ** Section: debug 25 | ** Author: Carl Sassenrath 26 | ** Notes: 27 | ** 28 | ***********************************************************************/ 29 | 30 | #include "sys-core.h" 31 | 32 | #define CRASH_BUF_SIZE 512 // space for crash print string 33 | 34 | extern const REBYTE * const Crash_Msgs[]; 35 | 36 | enum Crash_Msg_Nums { 37 | // Must align with Crash_Msgs[] array. 38 | CM_ERROR, 39 | CM_BOOT, 40 | CM_INTERNAL, 41 | CM_ASSERT, 42 | CM_DATATYPE, 43 | CM_DEBUG, 44 | CM_CONTACT 45 | }; 46 | 47 | 48 | /*********************************************************************** 49 | ** 50 | */ void Crash(REBINT id, ...) 51 | /* 52 | ** Print a failure message and abort. 53 | ** 54 | ** LATIN1 ONLY!! (For now) 55 | ** 56 | ** The error is identified by id number, which can reference an 57 | ** error message string in the boot strings block. 58 | ** 59 | ** Note that lower level error messages should not attempt to 60 | ** use the %r (mold value) format (uses higher level functions). 61 | ** 62 | ** See panics.h for list of crash errors. 63 | ** 64 | ***********************************************************************/ 65 | { 66 | va_list args; 67 | REBYTE buf[CRASH_BUF_SIZE]; 68 | REBYTE *msg; 69 | REBINT n = 0; 70 | 71 | va_start(args, id); 72 | 73 | DISABLE_GC; 74 | if (Reb_Opts->crash_dump) { 75 | Dump_Info(); 76 | Dump_Stack(0, 0); 77 | } 78 | 79 | // "REBOL PANIC #nnn:" 80 | COPY_BYTES(buf, Crash_Msgs[CM_ERROR], CRASH_BUF_SIZE); 81 | APPEND_BYTES(buf, " #", CRASH_BUF_SIZE); 82 | Form_Int(buf + LEN_BYTES(buf), id); 83 | APPEND_BYTES(buf, ": ", CRASH_BUF_SIZE); 84 | 85 | // "REBOL PANIC #nnn: put error message here" 86 | // The first few error types only print general error message. 87 | // Those errors > RP_STR_BASE have specific error messages (from boot.r). 88 | if (id < RP_BOOT_DATA) n = CM_DEBUG; 89 | else if (id < RP_INTERNAL) n = CM_BOOT; 90 | else if (id < RP_ASSERTS) n = CM_INTERNAL; 91 | else if (id < RP_DATATYPE) n = CM_ASSERT; 92 | else if (id < RP_STR_BASE) n = CM_DATATYPE; 93 | else if (id > RP_STR_BASE + RS_MAX - RS_ERROR) n = CM_DEBUG; 94 | 95 | // Use the above string or the boot string for the error (in boot.r): 96 | msg = (REBYTE*)(n >= 0 ? Crash_Msgs[n] : BOOT_STR(RS_ERROR, id - RP_STR_BASE - 1)); 97 | Form_Var_Args(buf + LEN_BYTES(buf), CRASH_BUF_SIZE - 1 - LEN_BYTES(buf), msg, args); 98 | 99 | APPEND_BYTES(buf, Crash_Msgs[CM_CONTACT], CRASH_BUF_SIZE); 100 | 101 | // Convert to OS-specific char-type: 102 | #ifdef disable_for_now //OS_WIDE_CHAR /// win98 does not support it 103 | { 104 | REBCHR s1[512]; 105 | REBCHR s2[2000]; 106 | 107 | n = TO_OS_STR(s1, Crash_Msgs[CM_ERROR], LEN_BYTES(Crash_Msgs[CM_ERROR])); 108 | if (n > 0) s1[n] = 0; // terminate 109 | else OS_EXIT(200); // bad conversion 110 | 111 | n = TO_OS_STR(s2, buf, LEN_BYTES(buf)); 112 | if (n > 0) s2[n] = 0; 113 | else OS_EXIT(200); 114 | 115 | OS_CRASH(s1, s2); 116 | } 117 | #else 118 | OS_CRASH(Crash_Msgs[CM_ERROR], buf); 119 | #endif 120 | } 121 | 122 | /*********************************************************************** 123 | ** 124 | */ void NA(void) 125 | /* 126 | ** Feature not available. 127 | ** 128 | ***********************************************************************/ 129 | { 130 | Crash(RP_NA); 131 | } 132 | -------------------------------------------------------------------------------- /src/core/p-console.c: -------------------------------------------------------------------------------- 1 | /*********************************************************************** 2 | ** 3 | ** REBOL [R3] Language Interpreter and Run-time Environment 4 | ** 5 | ** Copyright 2012 REBOL Technologies 6 | ** REBOL is a trademark of REBOL Technologies 7 | ** 8 | ** Licensed under the Apache License, Version 2.0 (the "License"); 9 | ** you may not use this file except in compliance with the License. 10 | ** You may obtain a copy of the License at 11 | ** 12 | ** http://www.apache.org/licenses/LICENSE-2.0 13 | ** 14 | ** Unless required by applicable law or agreed to in writing, software 15 | ** distributed under the License is distributed on an "AS IS" BASIS, 16 | ** WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 17 | ** See the License for the specific language governing permissions and 18 | ** limitations under the License. 19 | ** 20 | ************************************************************************ 21 | ** 22 | ** Module: p-console.c 23 | ** Summary: console port interface 24 | ** Section: ports 25 | ** Author: Carl Sassenrath 26 | ** Notes: 27 | ** 28 | ***********************************************************************/ 29 | 30 | #include "sys-core.h" 31 | 32 | 33 | #define OUT_BUF_SIZE 32*1024 34 | 35 | // Does OS use wide chars or byte chars (UTF-8): 36 | #ifdef OS_WIDE_CHAR 37 | #define MAKE_OS_BUFFER Make_Unicode 38 | #else 39 | #define MAKE_OS_BUFFER Make_Binary 40 | #endif 41 | 42 | /*********************************************************************** 43 | ** 44 | */ static int Console_Actor(REBVAL *ds, REBSER *port, REBCNT action) 45 | /* 46 | ***********************************************************************/ 47 | { 48 | REBREQ *req; 49 | REBINT result; 50 | REBVAL *arg = D_ARG(2); 51 | REBSER *ser; 52 | 53 | Validate_Port(port, action); 54 | 55 | arg = D_ARG(2); 56 | *D_RET = *D_ARG(1); 57 | 58 | req = Use_Port_State(port, RDI_STDIO, sizeof(REBREQ)); 59 | 60 | switch (action) { 61 | 62 | case A_READ: 63 | 64 | // If not open, open it: 65 | if (!IS_OPEN(req)) { 66 | if (OS_DO_DEVICE(req, RDC_OPEN)) Trap_Port(RE_CANNOT_OPEN, port, req->error); 67 | } 68 | 69 | // If no buffer, create a buffer: 70 | arg = OFV(port, STD_PORT_DATA); 71 | if (!IS_STRING(arg) && !IS_BINARY(arg)) { 72 | Set_Binary(arg, MAKE_OS_BUFFER(OUT_BUF_SIZE)); 73 | } 74 | ser = VAL_SERIES(arg); 75 | RESET_SERIES(ser); 76 | 77 | req->data = BIN_HEAD(ser); 78 | req->length = SERIES_AVAIL(ser); 79 | 80 | #ifdef nono 81 | // Is the buffer large enough? 82 | req->length = SERIES_AVAIL(ser); // space available 83 | if (req->length < OUT_BUF_SIZE/2) Extend_Series(ser, OUT_BUF_SIZE); 84 | req->length = SERIES_AVAIL(ser); 85 | 86 | // Don't make buffer too large: Bug #174 ????? 87 | if (req->length > 1024) req->length = 1024; //??? 88 | req->data = STR_TAIL(ser); // write at tail //??? 89 | if (SERIES_TAIL(ser) == 0) req->actual = 0; //??? 90 | #endif 91 | 92 | result = OS_DO_DEVICE(req, RDC_READ); 93 | if (result < 0) Trap_Port(RE_READ_ERROR, port, req->error); 94 | 95 | #ifdef nono 96 | // Does not belong here!! 97 | // Remove or replace CRs: 98 | result = 0; 99 | for (n = 0; n < req->actual; n++) { 100 | chr = GET_ANY_CHAR(ser, n); 101 | if (chr == CR) { 102 | chr = LF; 103 | // Skip LF if it follows: 104 | if ((n+1) < req->actual && 105 | LF == GET_ANY_CHAR(ser, n+1)) n++; 106 | } 107 | SET_ANY_CHAR(ser, result, chr); 108 | result++; 109 | } 110 | #endif 111 | // Another copy??? 112 | //Set_String(ds, Copy_OS_Str((void *)(ser->data), result)); 113 | Set_Binary(ds, Copy_Bytes(req->data, req->actual)); 114 | break; 115 | 116 | case A_OPEN: 117 | // ?? why??? 118 | //if (OS_DO_DEVICE(req, RDC_OPEN)) Trap_Port(RE_CANNOT_OPEN, port); 119 | SET_OPEN(req); 120 | break; 121 | 122 | case A_CLOSE: 123 | SET_CLOSED(req); 124 | //OS_DO_DEVICE(req, RDC_CLOSE); 125 | break; 126 | 127 | case A_OPENQ: 128 | if (IS_OPEN(req)) return R_TRUE; 129 | return R_FALSE; 130 | 131 | default: 132 | Trap_Action(REB_PORT, action); 133 | } 134 | 135 | return R_RET; 136 | } 137 | 138 | 139 | /*********************************************************************** 140 | ** 141 | */ void Init_Console_Scheme(void) 142 | /* 143 | ***********************************************************************/ 144 | { 145 | Register_Scheme(SYM_CONSOLE, 0, Console_Actor); 146 | } 147 | -------------------------------------------------------------------------------- /src/core/p-dns.c: -------------------------------------------------------------------------------- 1 | /*********************************************************************** 2 | ** 3 | ** REBOL [R3] Language Interpreter and Run-time Environment 4 | ** 5 | ** Copyright 2012 REBOL Technologies 6 | ** REBOL is a trademark of REBOL Technologies 7 | ** 8 | ** Licensed under the Apache License, Version 2.0 (the "License"); 9 | ** you may not use this file except in compliance with the License. 10 | ** You may obtain a copy of the License at 11 | ** 12 | ** http://www.apache.org/licenses/LICENSE-2.0 13 | ** 14 | ** Unless required by applicable law or agreed to in writing, software 15 | ** distributed under the License is distributed on an "AS IS" BASIS, 16 | ** WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 17 | ** See the License for the specific language governing permissions and 18 | ** limitations under the License. 19 | ** 20 | ************************************************************************ 21 | ** 22 | ** Module: p-dns.c 23 | ** Summary: DNS port interface 24 | ** Section: ports 25 | ** Author: Carl Sassenrath 26 | ** Notes: 27 | ** 28 | ***********************************************************************/ 29 | 30 | #include "sys-core.h" 31 | #include "reb-net.h" 32 | 33 | 34 | /*********************************************************************** 35 | ** 36 | */ static int DNS_Actor(REBVAL *ds, REBSER *port, REBCNT action) 37 | /* 38 | ***********************************************************************/ 39 | { 40 | REBVAL *spec; 41 | REBREQ *sock; 42 | REBINT result; 43 | REBVAL *arg; 44 | REBCNT len; 45 | REBOOL sync = FALSE; // act synchronously 46 | REBVAL tmp; 47 | 48 | Validate_Port(port, action); 49 | 50 | arg = D_ARG(2); 51 | *D_RET = *D_ARG(1); 52 | 53 | sock = Use_Port_State(port, RDI_DNS, sizeof(*sock)); 54 | spec = OFV(port, STD_PORT_SPEC); 55 | if (!IS_OBJECT(spec)) Trap0(RE_INVALID_PORT); 56 | 57 | sock->timeout = 4000; // where does this go? !!! 58 | 59 | switch (action) { 60 | 61 | case A_READ: 62 | if (!IS_OPEN(sock)) { 63 | if (OS_DO_DEVICE(sock, RDC_OPEN)) Trap_Port(RE_CANNOT_OPEN, port, sock->error); 64 | sync = TRUE; 65 | } 66 | 67 | arg = Obj_Value(spec, STD_PORT_SPEC_NET_HOST); 68 | 69 | if (IS_TUPLE(arg) && Scan_Tuple(VAL_BIN(arg), strlen(VAL_BIN(arg)), &tmp)) { 70 | SET_FLAG(sock->modes, RST_REVERSE); 71 | memcpy(&sock->net.remote_ip, VAL_TUPLE(&tmp), 4); 72 | } 73 | else if (IS_STRING(arg)) { 74 | sock->data = VAL_BIN(arg); 75 | } 76 | else Trap_Port(RE_INVALID_SPEC, port, -10); 77 | 78 | result = OS_DO_DEVICE(sock, RDC_READ); 79 | if (result < 0) Trap_Port(RE_READ_ERROR, port, sock->error); 80 | 81 | // Wait for it... 82 | if (sync && result == DR_PEND) { 83 | for (len = 0; GET_FLAG(sock->flags, RRF_PENDING) && len < 10; len++) { 84 | OS_WAIT(2000, 0); 85 | } 86 | len = 1; 87 | goto pick; 88 | } 89 | if (result == DR_DONE) { 90 | len = 1; 91 | goto pick; 92 | } 93 | break; 94 | 95 | case A_PICK: // FIRST - return result 96 | if (!IS_OPEN(sock)) Trap_Port(RE_NOT_OPEN, port, -12); 97 | len = Get_Num_Arg(arg); // Position 98 | pick: 99 | if (len == 1) { 100 | if (!sock->net.host_info || !GET_FLAG(sock->flags, RRF_DONE)) return R_NONE; 101 | if (sock->error) { 102 | OS_DO_DEVICE(sock, RDC_CLOSE); 103 | Trap_Port(RE_READ_ERROR, port, sock->error); 104 | } 105 | if (GET_FLAG(sock->modes, RST_REVERSE)) { 106 | Set_String(D_RET, Copy_Bytes(sock->data, LEN_BYTES(sock->data))); 107 | } else { 108 | Set_Tuple(D_RET, (REBYTE*)&sock->net.remote_ip, 4); 109 | } 110 | OS_DO_DEVICE(sock, RDC_CLOSE); 111 | } else Trap_Range(arg); 112 | break; 113 | 114 | case A_OPEN: 115 | if (OS_DO_DEVICE(sock, RDC_OPEN)) Trap_Port(RE_CANNOT_OPEN, port, -12); 116 | break; 117 | 118 | case A_CLOSE: 119 | OS_DO_DEVICE(sock, RDC_CLOSE); 120 | break; 121 | 122 | case A_OPENQ: 123 | if (IS_OPEN(sock)) return R_TRUE; 124 | return R_FALSE; 125 | 126 | case A_UPDATE: 127 | return R_NONE; 128 | 129 | default: 130 | Trap_Action(REB_PORT, action); 131 | } 132 | 133 | return R_RET; 134 | } 135 | 136 | 137 | /*********************************************************************** 138 | ** 139 | */ void Init_DNS_Scheme(void) 140 | /* 141 | ***********************************************************************/ 142 | { 143 | Register_Scheme(SYM_DNS, 0, DNS_Actor); 144 | } 145 | -------------------------------------------------------------------------------- /src/core/p-timer.c: -------------------------------------------------------------------------------- 1 | /*********************************************************************** 2 | ** 3 | ** REBOL [R3] Language Interpreter and Run-time Environment 4 | ** 5 | ** Copyright 2012 REBOL Technologies 6 | ** REBOL is a trademark of REBOL Technologies 7 | ** 8 | ** Licensed under the Apache License, Version 2.0 (the "License"); 9 | ** you may not use this file except in compliance with the License. 10 | ** You may obtain a copy of the License at 11 | ** 12 | ** http://www.apache.org/licenses/LICENSE-2.0 13 | ** 14 | ** Unless required by applicable law or agreed to in writing, software 15 | ** distributed under the License is distributed on an "AS IS" BASIS, 16 | ** WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 17 | ** See the License for the specific language governing permissions and 18 | ** limitations under the License. 19 | ** 20 | ************************************************************************ 21 | ** 22 | ** Module: p-timer.c 23 | ** Summary: timer port interface 24 | ** Section: ports 25 | ** Author: Carl Sassenrath 26 | ** Notes: NOT IMPLEMENTED 27 | ** 28 | ***********************************************************************/ 29 | /* 30 | General idea of usage: 31 | 32 | t: open timer://name 33 | write t 10 ; set timer - also allow: 1.23 1:23 34 | wait t 35 | clear t ; reset or delete? 36 | read t ; get timer value 37 | t/awake: func [event] [print "timer!"] 38 | one-shot vs restart timer 39 | */ 40 | 41 | #include "sys-core.h" 42 | 43 | 44 | /*********************************************************************** 45 | ** 46 | */ static int Event_Actor(REBVAL *ds, REBSER *port, REBCNT action) 47 | /* 48 | ***********************************************************************/ 49 | { 50 | REBVAL *spec; 51 | REBVAL *state; 52 | REBCNT result; 53 | REBVAL *arg; 54 | REBVAL save_port; 55 | 56 | Validate_Port(port, action); 57 | 58 | arg = D_ARG(2); 59 | *D_RET = *D_ARG(1); 60 | 61 | // Validate and fetch relevant PORT fields: 62 | state = BLK_SKIP(port, STD_PORT_STATE); 63 | spec = BLK_SKIP(port, STD_PORT_SPEC); 64 | if (!IS_OBJECT(spec)) Trap1(RE_INVALID_SPEC, spec); 65 | 66 | // Get or setup internal state data: 67 | if (!IS_BLOCK(state)) Set_Block(state, Make_Block(127)); 68 | 69 | switch (action) { 70 | 71 | case A_UPDATE: 72 | return R_NONE; 73 | 74 | // Normal block actions done on events: 75 | case A_POKE: 76 | if (!IS_EVENT(D_ARG(3))) Trap_Arg(D_ARG(3)); 77 | goto act_blk; 78 | case A_INSERT: 79 | case A_APPEND: 80 | //case A_PATH: // not allowed: port/foo is port object field access 81 | //case A_PATH_SET: // not allowed: above 82 | if (!IS_EVENT(arg)) Trap_Arg(arg); 83 | case A_PICK: 84 | act_blk: 85 | save_port = *D_ARG(1); // save for return 86 | *D_ARG(1) = *state; 87 | result = T_Block(ds, action); 88 | SET_FLAG(Eval_Signals, SIG_EVENT_PORT); 89 | if (action == A_INSERT || action == A_APPEND || action == A_REMOVE) { 90 | *D_RET = save_port; 91 | break; 92 | } 93 | return result; // return condition 94 | 95 | case A_CLEAR: 96 | VAL_TAIL(state) = 0; 97 | VAL_BLK_TERM(state); 98 | CLR_FLAG(Eval_Signals, SIG_EVENT_PORT); 99 | break; 100 | 101 | case A_LENGTHQ: 102 | SET_INTEGER(D_RET, VAL_TAIL(state)); 103 | break; 104 | 105 | case A_OPEN: 106 | if (!req) { //!!! 107 | req = OS_MAKE_DEVREQ(RDI_EVENT); 108 | SET_OPEN(req); 109 | OS_DO_DEVICE(req, RDC_CONNECT); // stays queued 110 | } 111 | break; 112 | 113 | default: 114 | Trap_Action(REB_PORT, action); 115 | } 116 | 117 | return R_RET; 118 | } 119 | 120 | 121 | /*********************************************************************** 122 | ** 123 | */ void Init_Timer_Scheme(void) 124 | /* 125 | ***********************************************************************/ 126 | { 127 | Register_Scheme(SYM_TIMER, 0, Event_Actor); 128 | } 129 | -------------------------------------------------------------------------------- /src/core/t-char.c: -------------------------------------------------------------------------------- 1 | /*********************************************************************** 2 | ** 3 | ** REBOL [R3] Language Interpreter and Run-time Environment 4 | ** 5 | ** Copyright 2012 REBOL Technologies 6 | ** REBOL is a trademark of REBOL Technologies 7 | ** 8 | ** Licensed under the Apache License, Version 2.0 (the "License"); 9 | ** you may not use this file except in compliance with the License. 10 | ** You may obtain a copy of the License at 11 | ** 12 | ** http://www.apache.org/licenses/LICENSE-2.0 13 | ** 14 | ** Unless required by applicable law or agreed to in writing, software 15 | ** distributed under the License is distributed on an "AS IS" BASIS, 16 | ** WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 17 | ** See the License for the specific language governing permissions and 18 | ** limitations under the License. 19 | ** 20 | ************************************************************************ 21 | ** 22 | ** Module: t-char.c 23 | ** Summary: character datatype 24 | ** Section: datatypes 25 | ** Author: Carl Sassenrath 26 | ** Notes: 27 | ** 28 | ***********************************************************************/ 29 | 30 | #include "sys-core.h" 31 | 32 | 33 | /*********************************************************************** 34 | ** 35 | */ REBINT CT_Char(REBVAL *a, REBVAL *b, REBINT mode) 36 | /* 37 | ***********************************************************************/ 38 | { 39 | REBINT num; 40 | 41 | if (mode >= 0) { 42 | if (mode < 2) 43 | num = LO_CASE(VAL_CHAR(a)) - LO_CASE(VAL_CHAR(b)); 44 | else 45 | num = VAL_CHAR(a) - VAL_CHAR(b); 46 | return (num == 0); 47 | } 48 | 49 | num = VAL_CHAR(a) - VAL_CHAR(b); 50 | if (mode == -1) return (num >= 0); 51 | return (num > 0); 52 | } 53 | 54 | 55 | /*********************************************************************** 56 | ** 57 | */ REBTYPE(Char) 58 | /* 59 | ***********************************************************************/ 60 | { 61 | REBINT chr = VAL_CHAR(D_ARG(1)); 62 | REBINT arg; 63 | REBVAL *val; 64 | 65 | if (IS_BINARY_ACT(action)) { 66 | val = D_ARG(2); 67 | if (IS_CHAR(val)) 68 | arg = VAL_CHAR(val); 69 | else if (IS_INTEGER(val)) 70 | arg = VAL_INT32(val); 71 | else if (IS_DECIMAL(val)) 72 | arg = (REBINT)VAL_DECIMAL(val); 73 | else 74 | Trap_Math_Args(REB_CHAR, action); 75 | } 76 | 77 | switch (action) { 78 | 79 | case A_ADD: chr += (REBUNI)arg; break; 80 | case A_SUBTRACT: 81 | chr -= (REBUNI)arg; 82 | if (IS_CHAR(D_ARG(2))) { 83 | DS_RET_INT(chr); 84 | return R_RET; 85 | } 86 | break; 87 | case A_MULTIPLY: chr *= arg; break; 88 | case A_DIVIDE: 89 | if (arg == 0) Trap0(RE_ZERO_DIVIDE); 90 | chr /= arg; 91 | break; 92 | case A_REMAINDER: 93 | if (arg == 0) Trap0(RE_ZERO_DIVIDE); 94 | chr %= arg; 95 | break; 96 | 97 | case A_AND: chr &= (REBUNI)arg; break; 98 | case A_OR: chr |= (REBUNI)arg; break; 99 | case A_XOR: chr ^= (REBUNI)arg; break; 100 | 101 | case A_NEGATE: chr = (REBUNI)-chr; break; 102 | case A_COMPLEMENT: chr = (REBUNI)~chr; break; 103 | case A_EVENQ: chr = (REBUNI)~chr; 104 | case A_ODDQ: DECIDE(chr & 1); 105 | 106 | case A_RANDOM: //!!! needs further definition ? random/zero 107 | if (D_REF(2)) { // /seed 108 | Set_Random(chr); 109 | return R_UNSET; 110 | } 111 | if (chr == 0) break; 112 | chr = (REBUNI)(1 + ((REBCNT)Random_Int(D_REF(3)) % chr)); // /secure 113 | break; 114 | 115 | case A_MAKE: 116 | case A_TO: 117 | val = D_ARG(2); 118 | 119 | switch(VAL_TYPE(val)) { 120 | case REB_CHAR: 121 | chr = VAL_CHAR(val); 122 | break; 123 | 124 | case REB_INTEGER: 125 | case REB_DECIMAL: 126 | arg = Int32(val); 127 | if (arg > MAX_UNI || arg < 0) goto bad_make; 128 | chr = arg; 129 | break; 130 | 131 | case REB_BINARY: 132 | { 133 | REBYTE *bp = VAL_BIN(val); 134 | arg = VAL_LEN(val); 135 | if (arg == 0) goto bad_make; 136 | if (*bp > 0x80) { 137 | if (!Legal_UTF8_Char(bp, arg)) goto bad_make; 138 | chr = Decode_UTF8_Char(&bp, 0); // zero on error 139 | if (!chr) goto bad_make; 140 | } 141 | else 142 | chr = *bp; 143 | } 144 | break; 145 | 146 | #ifdef removed 147 | // case REB_ISSUE: 148 | // Scan 8 or 16 bit hex str, will throw on error... 149 | arg = Scan_Hex_Value(VAL_DATA(val), VAL_LEN(val), (REBOOL)!VAL_BYTE_SIZE(val)); 150 | if (arg > MAX_UNI || arg < 0) goto bad_make; 151 | chr = arg; 152 | break; 153 | #endif 154 | 155 | case REB_STRING: 156 | if (VAL_INDEX(val) >= VAL_TAIL(val)) Trap_Make(REB_CHAR, val); 157 | chr = GET_ANY_CHAR(VAL_SERIES(val), VAL_INDEX(val)); 158 | break; 159 | 160 | default: 161 | bad_make: 162 | Trap_Make(REB_CHAR, val); 163 | } 164 | break; 165 | 166 | default: 167 | Trap_Action(REB_CHAR, action); 168 | } 169 | 170 | if ((chr >> 16) != 0 && (chr >> 16) != 0xffff) Trap1(RE_TYPE_LIMIT, Get_Type(REB_CHAR)); 171 | SET_CHAR(DS_RETURN, chr); 172 | return R_RET; 173 | 174 | is_false: 175 | return R_FALSE; 176 | 177 | is_true: 178 | return R_TRUE; 179 | } 180 | 181 | -------------------------------------------------------------------------------- /src/core/t-datatype.c: -------------------------------------------------------------------------------- 1 | /*********************************************************************** 2 | ** 3 | ** REBOL [R3] Language Interpreter and Run-time Environment 4 | ** 5 | ** Copyright 2012 REBOL Technologies 6 | ** REBOL is a trademark of REBOL Technologies 7 | ** 8 | ** Licensed under the Apache License, Version 2.0 (the "License"); 9 | ** you may not use this file except in compliance with the License. 10 | ** You may obtain a copy of the License at 11 | ** 12 | ** http://www.apache.org/licenses/LICENSE-2.0 13 | ** 14 | ** Unless required by applicable law or agreed to in writing, software 15 | ** distributed under the License is distributed on an "AS IS" BASIS, 16 | ** WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 17 | ** See the License for the specific language governing permissions and 18 | ** limitations under the License. 19 | ** 20 | ************************************************************************ 21 | ** 22 | ** Module: t-datatype.c 23 | ** Summary: datatype datatype 24 | ** Section: datatypes 25 | ** Author: Carl Sassenrath 26 | ** Notes: 27 | ** 28 | ***********************************************************************/ 29 | 30 | #include "sys-core.h" 31 | 32 | 33 | /*********************************************************************** 34 | ** 35 | */ REBINT CT_Datatype(REBVAL *a, REBVAL *b, REBINT mode) 36 | /* 37 | ***********************************************************************/ 38 | { 39 | if (mode >= 0) return (VAL_DATATYPE(a) == VAL_DATATYPE(b)); 40 | return -1; 41 | } 42 | 43 | 44 | /*********************************************************************** 45 | ** 46 | */ REBFLG MT_Datatype(REBVAL *out, REBVAL *data, REBCNT type) 47 | /* 48 | ***********************************************************************/ 49 | { 50 | if (!IS_WORD(data)) return FALSE; 51 | type = VAL_WORD_CANON(data); 52 | if (type > REB_MAX) return FALSE; 53 | VAL_SET(out, REB_DATATYPE); 54 | VAL_DATATYPE(out) = type-1; 55 | VAL_TYPE_SPEC(out) = 0; 56 | return TRUE; 57 | } 58 | 59 | 60 | /*********************************************************************** 61 | ** 62 | */ REBTYPE(Datatype) 63 | /* 64 | ***********************************************************************/ 65 | { 66 | REBVAL *value = D_ARG(1); 67 | REBVAL *arg = D_ARG(2); 68 | REBACT act; 69 | REBINT type = VAL_DATATYPE(value); 70 | REBSER *obj; 71 | REBINT n; 72 | 73 | switch (action) { 74 | 75 | case A_REFLECT: 76 | n = What_Reflector(arg); // zero on error 77 | if (n == OF_SPEC) { 78 | obj = Make_Std_Object(STD_TYPE_SPEC); 79 | Set_Object_Values(obj, BLK_HEAD(VAL_TYPE_SPEC(BLK_SKIP(Lib_Context, type+1)))); 80 | SET_OBJECT(D_RET, obj); 81 | } 82 | else if (n == OF_TITLE) { 83 | Set_String(D_RET, Copy_Series(VAL_SERIES(BLK_HEAD(VAL_TYPE_SPEC(BLK_SKIP(Lib_Context, type+1)))))); 84 | } 85 | else Trap_Reflect(VAL_TYPE(value), arg); 86 | break; 87 | 88 | case A_MAKE: 89 | case A_TO: 90 | if (type != REB_DATATYPE) { 91 | act = Value_Dispatch[type]; 92 | if (act) return act(ds, action); 93 | //return R_NONE; 94 | Trap_Make(type, arg); 95 | } 96 | // if (IS_NONE(arg)) return R_NONE; 97 | if (MT_Datatype(D_RET, arg, REB_DATATYPE)) 98 | break; 99 | 100 | Trap_Make(REB_DATATYPE, arg); 101 | 102 | default: 103 | Trap_Action(REB_DATATYPE, action); 104 | } 105 | 106 | return R_RET; 107 | } 108 | -------------------------------------------------------------------------------- /src/core/t-function.c: -------------------------------------------------------------------------------- 1 | /*********************************************************************** 2 | ** 3 | ** REBOL [R3] Language Interpreter and Run-time Environment 4 | ** 5 | ** Copyright 2012 REBOL Technologies 6 | ** REBOL is a trademark of REBOL Technologies 7 | ** 8 | ** Licensed under the Apache License, Version 2.0 (the "License"); 9 | ** you may not use this file except in compliance with the License. 10 | ** You may obtain a copy of the License at 11 | ** 12 | ** http://www.apache.org/licenses/LICENSE-2.0 13 | ** 14 | ** Unless required by applicable law or agreed to in writing, software 15 | ** distributed under the License is distributed on an "AS IS" BASIS, 16 | ** WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 17 | ** See the License for the specific language governing permissions and 18 | ** limitations under the License. 19 | ** 20 | ************************************************************************ 21 | ** 22 | ** Module: t-function.c 23 | ** Summary: function related datatypes 24 | ** Section: datatypes 25 | ** Author: Carl Sassenrath 26 | ** Notes: 27 | ** 28 | ***********************************************************************/ 29 | 30 | #include "sys-core.h" 31 | 32 | static REBOOL Same_Func(REBVAL *val, REBVAL *arg) 33 | { 34 | if (VAL_TYPE(val) == VAL_TYPE(arg) && 35 | VAL_FUNC_SPEC(val) == VAL_FUNC_SPEC(arg) && 36 | VAL_FUNC_ARGS(val) == VAL_FUNC_ARGS(arg) && 37 | VAL_FUNC_CODE(val) == VAL_FUNC_CODE(arg)) return TRUE; 38 | return FALSE; 39 | } 40 | 41 | 42 | /*********************************************************************** 43 | ** 44 | */ REBINT CT_Function(REBVAL *a, REBVAL *b, REBINT mode) 45 | /* 46 | ***********************************************************************/ 47 | { 48 | if (mode >= 0) return Same_Func(a, b); 49 | return -1; 50 | } 51 | 52 | 53 | /*********************************************************************** 54 | ** 55 | */ REBSER *As_Typesets(REBSER *types) 56 | /* 57 | ***********************************************************************/ 58 | { 59 | REBVAL *val; 60 | 61 | types = Copy_Block(types, 1); 62 | for (val = BLK_HEAD(types); NOT_END(val); val++) { 63 | SET_TYPE(val, REB_TYPESET); 64 | } 65 | return types; 66 | } 67 | 68 | 69 | /*********************************************************************** 70 | ** 71 | */ REBFLG MT_Function(REBVAL *out, REBVAL *data, REBCNT type) 72 | /* 73 | ***********************************************************************/ 74 | { 75 | return Make_Function(type, out, data); 76 | } 77 | 78 | 79 | /*********************************************************************** 80 | ** 81 | */ REBTYPE(Function) 82 | /* 83 | ***********************************************************************/ 84 | { 85 | REBVAL *value = D_ARG(1); 86 | REBVAL *arg = D_ARG(2); 87 | REBCNT type = VAL_TYPE(value); 88 | REBCNT n; 89 | 90 | switch (action) { 91 | 92 | case A_MAKE: 93 | case A_TO: 94 | // make function! [[args] [body]] 95 | if (IS_DATATYPE(value)) { 96 | n = VAL_DATATYPE(value); 97 | if (Make_Function(n, value, arg)) break; 98 | Trap_Make(n, arg); 99 | } 100 | 101 | // make :func [] 102 | // make :func [[args]] 103 | // make :func [* [body]] 104 | if (ANY_FUNC(value)) { 105 | if (!IS_BLOCK(arg)) goto bad_arg; 106 | if (!ANY_FUNC(value)) goto bad_arg; 107 | if (!Copy_Function(value, arg)) goto bad_arg; 108 | break; 109 | } 110 | if (!IS_NONE(arg)) goto bad_arg; 111 | // fall thru... 112 | case A_COPY: 113 | Copy_Function(value, 0); 114 | break; 115 | 116 | case A_REFLECT: 117 | n = What_Reflector(arg); // zero on error 118 | switch (n) { 119 | case OF_WORDS: 120 | //if (type == REB_CLOSURE) 121 | Set_Block(value, List_Func_Words(value)); 122 | //else 123 | // Set_Block(value, List_Func_Words(value)); 124 | break; 125 | case OF_BODY: 126 | of_type: 127 | switch (type) { 128 | case REB_FUNCTION: 129 | case REB_CLOSURE: 130 | Set_Block(value, Clone_Block(VAL_FUNC_BODY(value))); 131 | Unbind_Block(VAL_BLK(value), TRUE); 132 | break; 133 | case REB_NATIVE: 134 | case REB_COMMAND: 135 | case REB_ACTION: 136 | SET_NONE(value); 137 | break; 138 | case REB_OP: 139 | type = VAL_GET_EXT(value); // internal datatype 140 | goto of_type; 141 | } 142 | break; 143 | case OF_SPEC: 144 | Set_Block(value, Clone_Block(VAL_FUNC_SPEC(value))); 145 | Unbind_Block(VAL_BLK(value), TRUE); 146 | break; 147 | case OF_TYPES: 148 | Set_Block(value, As_Typesets(VAL_FUNC_ARGS(value))); 149 | break; 150 | case OF_TITLE: 151 | arg = BLK_HEAD(VAL_FUNC_SPEC(value)); 152 | for (; NOT_END(arg) && !IS_STRING(arg) && !IS_WORD(arg); arg++); 153 | if (!IS_STRING(arg)) return R_NONE; 154 | Set_String(value, Copy_Series(VAL_SERIES(arg))); 155 | break; 156 | default: 157 | bad_arg: 158 | Trap_Reflect(type, arg); 159 | } 160 | break; 161 | 162 | default: Trap_Action(type, action); 163 | } 164 | 165 | DS_RET_VALUE(value); 166 | return R_RET; 167 | } 168 | -------------------------------------------------------------------------------- /src/core/t-none.c: -------------------------------------------------------------------------------- 1 | /*********************************************************************** 2 | ** 3 | ** REBOL [R3] Language Interpreter and Run-time Environment 4 | ** 5 | ** Copyright 2012 REBOL Technologies 6 | ** REBOL is a trademark of REBOL Technologies 7 | ** 8 | ** Licensed under the Apache License, Version 2.0 (the "License"); 9 | ** you may not use this file except in compliance with the License. 10 | ** You may obtain a copy of the License at 11 | ** 12 | ** http://www.apache.org/licenses/LICENSE-2.0 13 | ** 14 | ** Unless required by applicable law or agreed to in writing, software 15 | ** distributed under the License is distributed on an "AS IS" BASIS, 16 | ** WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 17 | ** See the License for the specific language governing permissions and 18 | ** limitations under the License. 19 | ** 20 | ************************************************************************ 21 | ** 22 | ** Module: t-none.c 23 | ** Summary: none datatype 24 | ** Section: datatypes 25 | ** Author: Carl Sassenrath 26 | ** Notes: 27 | ** 28 | ***********************************************************************/ 29 | 30 | #include "sys-core.h" 31 | 32 | /*********************************************************************** 33 | ** 34 | */ REBINT CT_None(REBVAL *a, REBVAL *b, REBINT mode) 35 | /* 36 | ***********************************************************************/ 37 | { 38 | if (mode >= 0) return (VAL_TYPE(a) == VAL_TYPE(b)); 39 | return -1; 40 | } 41 | 42 | 43 | /*********************************************************************** 44 | ** 45 | */ REBFLG MT_None(REBVAL *out, REBVAL *data, REBCNT type) 46 | /* 47 | ***********************************************************************/ 48 | { 49 | VAL_SET(out, type); 50 | return TRUE; 51 | } 52 | 53 | 54 | /*********************************************************************** 55 | ** 56 | */ REBTYPE(None) 57 | /* 58 | ** ALSO used for unset! 59 | ** 60 | ***********************************************************************/ 61 | { 62 | REBVAL *val = D_ARG(1); 63 | 64 | switch (action) { 65 | 66 | case A_MAKE: 67 | case A_TO: 68 | if (IS_DATATYPE(val)) 69 | return VAL_DATATYPE(val) == REB_NONE ? R_NONE : R_UNSET; 70 | else 71 | return IS_NONE(val) ? R_NONE : R_UNSET; 72 | 73 | case A_TAILQ: 74 | if (IS_NONE(val)) return R_TRUE; 75 | goto trap_it; 76 | case A_INDEXQ: 77 | case A_LENGTHQ: 78 | case A_SELECT: 79 | case A_FIND: 80 | case A_REMOVE: 81 | case A_CLEAR: 82 | case A_TAKE: 83 | if (IS_NONE(val)) return R_NONE; 84 | default: 85 | trap_it: 86 | Trap_Action(VAL_TYPE(val), action); 87 | } 88 | 89 | return R_RET; 90 | } 91 | -------------------------------------------------------------------------------- /src/core/t-port.c: -------------------------------------------------------------------------------- 1 | /*********************************************************************** 2 | ** 3 | ** REBOL [R3] Language Interpreter and Run-time Environment 4 | ** 5 | ** Copyright 2012 REBOL Technologies 6 | ** REBOL is a trademark of REBOL Technologies 7 | ** 8 | ** Licensed under the Apache License, Version 2.0 (the "License"); 9 | ** you may not use this file except in compliance with the License. 10 | ** You may obtain a copy of the License at 11 | ** 12 | ** http://www.apache.org/licenses/LICENSE-2.0 13 | ** 14 | ** Unless required by applicable law or agreed to in writing, software 15 | ** distributed under the License is distributed on an "AS IS" BASIS, 16 | ** WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 17 | ** See the License for the specific language governing permissions and 18 | ** limitations under the License. 19 | ** 20 | ************************************************************************ 21 | ** 22 | ** Module: t-port.c 23 | ** Summary: port datatype 24 | ** Section: datatypes 25 | ** Author: Carl Sassenrath 26 | ** Notes: 27 | ** 28 | ***********************************************************************/ 29 | 30 | #include "sys-core.h" 31 | 32 | 33 | /*********************************************************************** 34 | ** 35 | */ REBINT CT_Port(REBVAL *a, REBVAL *b, REBINT mode) 36 | /* 37 | ***********************************************************************/ 38 | { 39 | if (mode < 0) return -1; 40 | return VAL_OBJ_FRAME(a) == VAL_OBJ_FRAME(b); 41 | } 42 | 43 | 44 | /*********************************************************************** 45 | ** 46 | */ REBFLG MT_Port(REBVAL *out, REBVAL *data, REBCNT type) 47 | /* 48 | ***********************************************************************/ 49 | { 50 | return FALSE; 51 | } 52 | 53 | 54 | /*********************************************************************** 55 | ** 56 | */ static REBVAL *As_Port(REBVAL *value) 57 | /* 58 | ** Make the port object if necessary. 59 | ** 60 | ***********************************************************************/ 61 | { 62 | REBVAL *ds; 63 | 64 | if (IS_PORT(value)) return value; 65 | 66 | value = Make_Port(value); 67 | ds = DS_RETURN; 68 | *D_ARG(1) = *value; 69 | 70 | return D_ARG(1); 71 | } 72 | 73 | 74 | /*********************************************************************** 75 | ** 76 | */ REBTYPE(Port) 77 | /* 78 | ***********************************************************************/ 79 | { 80 | REBVAL *value = D_ARG(1); 81 | REBVAL *arg = D_ARG(2); 82 | 83 | switch (action) { 84 | 85 | case A_READ: 86 | case A_WRITE: 87 | case A_QUERY: 88 | case A_OPEN: 89 | case A_CREATE: 90 | case A_DELETE: 91 | case A_RENAME: 92 | value = As_Port(value); 93 | case A_UPDATE: 94 | default: 95 | return Do_Port_Action(VAL_PORT(value), action); // Result on stack 96 | 97 | case A_REFLECT: 98 | return T_Object(ds, action); 99 | break; 100 | 101 | case A_MAKE: 102 | if (IS_DATATYPE(value)) value = Make_Port(arg); 103 | else Trap_Make(REB_PORT, value); 104 | break; 105 | 106 | case A_TO: 107 | if (!(IS_DATATYPE(value) && IS_OBJECT(arg))) Trap_Make(REB_PORT, arg); 108 | value = arg; 109 | VAL_SET(value, REB_PORT); 110 | break; 111 | } 112 | 113 | DS_Ret_Val(value); 114 | return R_RET; 115 | } 116 | -------------------------------------------------------------------------------- /src/core/t-utype.c: -------------------------------------------------------------------------------- 1 | /*********************************************************************** 2 | ** 3 | ** REBOL [R3] Language Interpreter and Run-time Environment 4 | ** 5 | ** Copyright 2012 REBOL Technologies 6 | ** REBOL is a trademark of REBOL Technologies 7 | ** 8 | ** Licensed under the Apache License, Version 2.0 (the "License"); 9 | ** you may not use this file except in compliance with the License. 10 | ** You may obtain a copy of the License at 11 | ** 12 | ** http://www.apache.org/licenses/LICENSE-2.0 13 | ** 14 | ** Unless required by applicable law or agreed to in writing, software 15 | ** distributed under the License is distributed on an "AS IS" BASIS, 16 | ** WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 17 | ** See the License for the specific language governing permissions and 18 | ** limitations under the License. 19 | ** 20 | ************************************************************************ 21 | ** 22 | ** Module: t-utype.c 23 | ** Summary: user defined datatype 24 | ** Section: datatypes 25 | ** Author: Carl Sassenrath 26 | ** Notes: NOT IMPLEMENTED 27 | ** 28 | ***********************************************************************/ 29 | 30 | #include "sys-core.h" 31 | 32 | #define SET_UTYPE(v,f) VAL_UTYPE_FUNC(v) = (f), VAL_UTYPE_DATA(v) = 0, VAL_SET(v, REB_UTYPE) 33 | 34 | 35 | /*********************************************************************** 36 | ** 37 | */ REBINT CT_Utype(REBVAL *a, REBVAL *b, REBINT mode) 38 | /* 39 | ***********************************************************************/ 40 | { 41 | return FALSE; 42 | } 43 | 44 | 45 | /*********************************************************************** 46 | ** 47 | */ REBFLG MT_Utype(REBVAL *out, REBVAL *data, REBCNT type) 48 | /* 49 | ***********************************************************************/ 50 | { 51 | return FALSE; 52 | } 53 | 54 | 55 | /*********************************************************************** 56 | ** 57 | */ REBTYPE(Utype) 58 | /* 59 | ***********************************************************************/ 60 | { 61 | REBVAL *value = D_ARG(1); 62 | REBVAL *arg = D_ARG(2); 63 | REBVAL *spec; 64 | REBVAL *body; 65 | 66 | if (action == A_MAKE) { 67 | // MAKE udef! [spec body] 68 | if (IS_DATATYPE(value)) { 69 | if (!IS_BLOCK(arg)) Trap_Arg(arg); 70 | spec = VAL_BLK(arg); 71 | if (!IS_BLOCK(spec)) Trap_Arg(arg); 72 | body = VAL_BLK_SKIP(arg, 1); 73 | if (!IS_BLOCK(body)) Trap_Arg(arg); 74 | 75 | spec = Get_System(SYS_STANDARD, STD_UTYPE); 76 | if (!IS_OBJECT(spec)) Trap_Arg(spec); 77 | SET_UTYPE(D_RET, Make_Object(VAL_OBJ_FRAME(spec), body)); 78 | VAL_UTYPE_DATA(D_RET) = 0; 79 | return R_RET; 80 | } 81 | else Trap_Arg(arg); 82 | } 83 | 84 | if (!IS_UTYPE(value)) Trap1(RE_INVALID_TYPE, Get_Type(REB_UTYPE)); 85 | // if (!VAL_UTYPE_DATA(D_RET) || SERIES_TAIL(VAL_UTYPE_FUNC(value)) <= action) 86 | // Trap_Action(REB_UTYPE, action); 87 | 88 | body = OFV(VAL_UTYPE_FUNC(value), action); 89 | if (!IS_FUNCTION(body)) Trap_Action(REB_UTYPE, action); 90 | 91 | Do_Function(body); 92 | 93 | return R_RET; 94 | } 95 | -------------------------------------------------------------------------------- /src/core/t-word.c: -------------------------------------------------------------------------------- 1 | /*********************************************************************** 2 | ** 3 | ** REBOL [R3] Language Interpreter and Run-time Environment 4 | ** 5 | ** Copyright 2012 REBOL Technologies 6 | ** REBOL is a trademark of REBOL Technologies 7 | ** 8 | ** Licensed under the Apache License, Version 2.0 (the "License"); 9 | ** you may not use this file except in compliance with the License. 10 | ** You may obtain a copy of the License at 11 | ** 12 | ** http://www.apache.org/licenses/LICENSE-2.0 13 | ** 14 | ** Unless required by applicable law or agreed to in writing, software 15 | ** distributed under the License is distributed on an "AS IS" BASIS, 16 | ** WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 17 | ** See the License for the specific language governing permissions and 18 | ** limitations under the License. 19 | ** 20 | ************************************************************************ 21 | ** 22 | ** Module: t-word.c 23 | ** Summary: word related datatypes 24 | ** Section: datatypes 25 | ** Author: Carl Sassenrath 26 | ** Notes: 27 | ** 28 | ***********************************************************************/ 29 | 30 | #include "sys-core.h" 31 | 32 | #ifdef not_used 33 | /*********************************************************************** 34 | ** 35 | ** REBFLG MT_Word(REBVAL *out, REBVAL *data, REBCNT type) 36 | ** 37 | ***********************************************************************/ 38 | { 39 | if (!IS_WORD(data)) return FALSE; 40 | *out = *data; 41 | VAL_SET(out, type); 42 | return TRUE; 43 | } 44 | #endif 45 | 46 | 47 | /*********************************************************************** 48 | ** 49 | */ REBINT CT_Word(REBVAL *a, REBVAL *b, REBINT mode) 50 | /* 51 | ***********************************************************************/ 52 | { 53 | REBINT e; 54 | REBINT diff; 55 | if (mode >= 0) { 56 | e = VAL_WORD_CANON(a) == VAL_WORD_CANON(b); 57 | if (mode == 1) e &= VAL_WORD_INDEX(a) == VAL_WORD_INDEX(b) 58 | && VAL_WORD_FRAME(a) == VAL_WORD_FRAME(b); 59 | else if (mode >= 2) { 60 | e = (VAL_WORD_SYM(a) == VAL_WORD_SYM(b) && 61 | VAL_WORD_INDEX(a) == VAL_WORD_INDEX(b) && 62 | VAL_WORD_FRAME(a) == VAL_WORD_FRAME(b)); 63 | } 64 | } else { 65 | diff = Compare_Word(a, b, FALSE); 66 | if (mode == -1) e = diff >= 0; 67 | else e = diff > 0; 68 | } 69 | return e; 70 | } 71 | 72 | 73 | /*********************************************************************** 74 | ** 75 | */ REBTYPE(Word) 76 | /* 77 | ***********************************************************************/ 78 | { 79 | REBVAL *val = D_ARG(1); 80 | REBVAL *arg = D_ARG(2); 81 | REBCNT type = VAL_TYPE(val); 82 | REBINT diff; 83 | REBCNT sym; 84 | 85 | switch (action) { 86 | case A_LENGTHQ: 87 | diff = LEN_BYTES(Get_Sym_Name(VAL_WORD_SYM(val))); 88 | if (type != REB_WORD) diff++; 89 | DS_Ret_Int(diff); 90 | break; 91 | 92 | case A_MAKE: 93 | case A_TO: 94 | // TO word! ... 95 | if (type == REB_DATATYPE) type = (REBCNT)VAL_DATATYPE(val); 96 | if (ANY_WORD(arg)) { 97 | VAL_SET(arg, type); 98 | return R_ARG2; 99 | } 100 | else { 101 | if (IS_STRING(arg)) { 102 | REBYTE *bp; 103 | REBCNT len; 104 | // Set sym. Rest is set below. 105 | bp = Qualify_String(arg, 255, &len, TRUE); 106 | if (type == REB_ISSUE) sym = Scan_Issue(bp, len); 107 | else sym = Scan_Word(bp, len); 108 | if (!sym) Trap1(RE_BAD_CHAR, arg); 109 | } 110 | else if (IS_CHAR(arg)) { 111 | REBYTE buf[8]; 112 | sym = Encode_UTF8_Char(&buf[0], VAL_CHAR(arg)); //returns length 113 | sym = Scan_Word(&buf[0], sym); 114 | if (!sym) Trap1(RE_BAD_CHAR, arg); 115 | } 116 | else if (IS_DATATYPE(arg)) { 117 | sym = VAL_DATATYPE(arg)+1; 118 | } 119 | else if (IS_LOGIC(arg)) { 120 | sym = IS_TRUE(arg) ? SYM_TRUE : SYM_FALSE; 121 | } 122 | else Trap_Types(RE_EXPECT_VAL, REB_WORD, VAL_TYPE(arg)); 123 | Set_Word(D_RET, sym, 0, 0); 124 | VAL_SET(D_RET, type); 125 | } 126 | break; 127 | 128 | default: 129 | Trap_Action(type, action); 130 | } 131 | 132 | return R_RET; 133 | } 134 | -------------------------------------------------------------------------------- /src/include/reb-args.h: -------------------------------------------------------------------------------- 1 | /*********************************************************************** 2 | ** 3 | ** REBOL [R3] Language Interpreter and Run-time Environment 4 | ** 5 | ** Copyright 2012 REBOL Technologies 6 | ** REBOL is a trademark of REBOL Technologies 7 | ** 8 | ** Licensed under the Apache License, Version 2.0 (the "License"); 9 | ** you may not use this file except in compliance with the License. 10 | ** You may obtain a copy of the License at 11 | ** 12 | ** http://www.apache.org/licenses/LICENSE-2.0 13 | ** 14 | ** Unless required by applicable law or agreed to in writing, software 15 | ** distributed under the License is distributed on an "AS IS" BASIS, 16 | ** WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 17 | ** See the License for the specific language governing permissions and 18 | ** limitations under the License. 19 | ** 20 | ************************************************************************ 21 | ** 22 | ** Summary: Program startup arguments 23 | ** Module: reb-args.h 24 | ** Author: Carl Sassenrath 25 | ** Notes: 26 | ** Arg struct is used by R3 lib, so must not be modified. 27 | ** 28 | ***********************************************************************/ 29 | 30 | // REBOL startup option structure: 31 | typedef struct rebol_args { 32 | REBCNT options; 33 | REBCHR *script; 34 | REBCHR *args; 35 | REBCHR *do_arg; 36 | REBCHR *version; 37 | REBCHR *debug; 38 | REBCHR *import; 39 | REBCHR *secure; 40 | REBCHR *boot; 41 | REBCHR *exe_path; 42 | REBCHR *home_dir; 43 | } REBARGS; 44 | 45 | // REBOL arg option flags: 46 | // Must stay matched to system/catalog/boot-flags. 47 | enum arg_opts { 48 | ROF_EXT, 49 | 50 | ROF_SCRIPT, 51 | ROF_ARGS, 52 | ROF_DO, 53 | ROF_IMPORT, 54 | ROF_VERSION, 55 | ROF_DEBUG, 56 | ROF_SECURE, 57 | 58 | ROF_HELP, 59 | ROF_VERS, 60 | ROF_QUIET, 61 | ROF_VERBOSE, 62 | ROF_SECURE_MIN, 63 | ROF_SECURE_MAX, 64 | ROF_TRACE, 65 | ROF_HALT, 66 | ROF_CGI, 67 | ROF_BOOT, 68 | ROF_NO_WINDOW, 69 | 70 | ROF_IGNORE, // not an option 71 | }; 72 | 73 | #define RO_EXT (1<bits field contains a block of memory allocated with Make_Mem 35 | // of size (->w * ->h * 4). This will be freed by the 36 | // REBNATIVE(do_codec) in n-system.c 37 | // 38 | // If your codec routine returns CODI_BINARY, it is 39 | // expected that the ->data field contains a block of memory 40 | // allocated with Make_Mem of size ->len. This will be freed by 41 | // the REBNATIVE(do_codec) in n-system.c 42 | // 43 | // If your codec routine returns CODI_TEXT, it is 44 | // expected that the ->data field is 3rd input binary! argument in 45 | // the REBNATIVE(do_codec) in n-system.c 46 | // so the deallocation is left to GC 47 | // 48 | typedef struct reb_codec_image { 49 | int action; 50 | int w; 51 | int h; 52 | int len; 53 | int alpha; 54 | unsigned char *data; 55 | union { 56 | u32 *bits; 57 | void *other; 58 | }; 59 | int error; 60 | } REBCDI; 61 | 62 | typedef REBINT (*codo)(REBCDI *cdi); 63 | 64 | // Media types: 65 | enum { 66 | CODI_ERROR, 67 | CODI_CHECK, // error code is inverted result (IDENTIFY) 68 | CODI_BINARY, 69 | CODI_TEXT, 70 | CODI_IMAGE, 71 | CODI_SOUND, 72 | CODI_BLOCK, 73 | }; 74 | 75 | // Codec commands: 76 | enum { 77 | CODI_IDENTIFY, 78 | CODI_DECODE, 79 | CODI_ENCODE, 80 | }; 81 | 82 | // Codec errors: 83 | enum { 84 | CODI_ERR_NA = 1, // Feature not available 85 | CODI_ERR_NO_ACTION, // Requested action unknown 86 | CODI_ERR_ENCODING, // Encoding method not supported 87 | CODI_ERR_SIGNATURE, // Header signature is not correct 88 | CODI_ERR_BIT_LEN, // Bit length is not supported 89 | CODI_ERR_BAD_TABLE, // Image tables are wrong 90 | CODI_ERR_BAD_DATA, // Generic 91 | }; 92 | -------------------------------------------------------------------------------- /src/include/reb-defs.h: -------------------------------------------------------------------------------- 1 | /*********************************************************************** 2 | ** 3 | ** REBOL [R3] Language Interpreter and Run-time Environment 4 | ** 5 | ** Copyright 2012 REBOL Technologies 6 | ** REBOL is a trademark of REBOL Technologies 7 | ** 8 | ** Licensed under the Apache License, Version 2.0 (the "License"); 9 | ** you may not use this file except in compliance with the License. 10 | ** You may obtain a copy of the License at 11 | ** 12 | ** http://www.apache.org/licenses/LICENSE-2.0 13 | ** 14 | ** Unless required by applicable law or agreed to in writing, software 15 | ** distributed under the License is distributed on an "AS IS" BASIS, 16 | ** WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 17 | ** See the License for the specific language governing permissions and 18 | ** limitations under the License. 19 | ** 20 | ************************************************************************ 21 | ** 22 | ** Summary: Miscellaneous structures and definitions 23 | ** Module: reb-defs.h 24 | ** Author: Carl Sassenrath 25 | ** Notes: 26 | ** This file is used by internal and external C code. It 27 | ** should not depend on many other header files prior to it. 28 | ** 29 | ***********************************************************************/ 30 | 31 | #ifndef REB_DEFS_H // due to sequences within the lib build itself 32 | #define REB_DEFS_H 33 | 34 | #ifndef REB_DEF 35 | typedef void *REBSER; 36 | typedef void *REBOBJ; 37 | #endif 38 | 39 | #pragma pack(4) 40 | 41 | // X/Y coordinate pair as floats: 42 | typedef struct rebol_xy_float { 43 | float x; 44 | float y; 45 | } REBXYF; 46 | 47 | // X/Y coordinate pair as integers: 48 | typedef struct rebol_xy_int { 49 | int x; 50 | int y; 51 | } REBXYI; 52 | 53 | #define REBPAR REBXYI // temporary until all sources are converted 54 | 55 | // Standard date and time: 56 | typedef struct rebol_dat { 57 | int year; 58 | int month; 59 | int day; 60 | int time; 61 | int nano; 62 | int zone; 63 | } REBOL_DAT; // not same as REBDAT 64 | 65 | // OS metrics: (not used as of A100!) 66 | typedef struct rebol_met { 67 | int len; // # entries in this table 68 | REBPAR screen_size; 69 | REBPAR title_size; 70 | REBPAR border_size; 71 | REBPAR border_fixed; 72 | REBPAR work_origin; 73 | REBPAR work_size; 74 | } X_REBOL_OS_METRICS; 75 | 76 | #pragma pack() 77 | 78 | #endif 79 | -------------------------------------------------------------------------------- /src/include/reb-event.h: -------------------------------------------------------------------------------- 1 | /*********************************************************************** 2 | ** 3 | ** REBOL [R3] Language Interpreter and Run-time Environment 4 | ** 5 | ** Copyright 2012 REBOL Technologies 6 | ** REBOL is a trademark of REBOL Technologies 7 | ** 8 | ** Licensed under the Apache License, Version 2.0 (the "License"); 9 | ** you may not use this file except in compliance with the License. 10 | ** You may obtain a copy of the License at 11 | ** 12 | ** http://www.apache.org/licenses/LICENSE-2.0 13 | ** 14 | ** Unless required by applicable law or agreed to in writing, software 15 | ** distributed under the License is distributed on an "AS IS" BASIS, 16 | ** WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 17 | ** See the License for the specific language governing permissions and 18 | ** limitations under the License. 19 | ** 20 | ************************************************************************ 21 | ** 22 | ** Summary: REBOL event definitions 23 | ** Module: reb-event.h 24 | ** Author: Carl Sassenrath 25 | ** Notes: 26 | ** 27 | ***********************************************************************/ 28 | 29 | // Note: size must be 12 bytes on 32-bit or 16 on 64-bit! 30 | 31 | #pragma pack(4) 32 | typedef struct rebol_event { 33 | u8 type; // event id (mouse-move, mouse-button, etc) 34 | u8 flags; // special flags 35 | u8 win; // window id 36 | u8 model; // port, object, gui, callback 37 | u32 data; // an x/y position or keycode (raw/decoded) 38 | union { 39 | REBREQ *req; // request (for device events) 40 | void *ser; // port or object 41 | }; 42 | } REBEVT; 43 | #pragma pack() 44 | 45 | // Special event flags: 46 | 47 | enum { 48 | EVF_COPIED, // event data has been copied 49 | EVF_HAS_XY, // map-event will work on it 50 | EVF_DOUBLE, // double click detected 51 | EVF_CONTROL, 52 | EVF_SHIFT, 53 | }; 54 | 55 | 56 | // Event port data model 57 | 58 | enum { 59 | EVM_DEVICE, // I/O request holds the port pointer 60 | EVM_PORT, // event holds port pointer 61 | EVM_OBJECT, // event holds object frame pointer 62 | EVM_GUI, // GUI event uses system/view/event/port 63 | EVM_CALLBACK, // Callback event uses system/ports/callback port 64 | }; 65 | 66 | // Special messages 67 | #define WM_DNS (WM_USER+100) 68 | -------------------------------------------------------------------------------- /src/include/reb-file.h: -------------------------------------------------------------------------------- 1 | /*********************************************************************** 2 | ** 3 | ** REBOL [R3] Language Interpreter and Run-time Environment 4 | ** 5 | ** Copyright 2012 REBOL Technologies 6 | ** REBOL is a trademark of REBOL Technologies 7 | ** 8 | ** Licensed under the Apache License, Version 2.0 (the "License"); 9 | ** you may not use this file except in compliance with the License. 10 | ** You may obtain a copy of the License at 11 | ** 12 | ** http://www.apache.org/licenses/LICENSE-2.0 13 | ** 14 | ** Unless required by applicable law or agreed to in writing, software 15 | ** distributed under the License is distributed on an "AS IS" BASIS, 16 | ** WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 17 | ** See the License for the specific language governing permissions and 18 | ** limitations under the License. 19 | ** 20 | ************************************************************************ 21 | ** 22 | ** Summary: Special file device definitions 23 | ** Module: reb-file.h 24 | ** Author: Carl Sassenrath 25 | ** Notes: 26 | ** 27 | ***********************************************************************/ 28 | 29 | // RFM - REBOL File Modes 30 | enum { 31 | RFM_READ = 0, 32 | RFM_WRITE, 33 | RFM_APPEND, 34 | RFM_SEEK, 35 | RFM_NEW, 36 | RFM_READONLY, 37 | RFM_TRUNCATE, 38 | RFM_RESEEK, // file index has moved, reseek 39 | RFM_NAME_MEM, // converted name allocated in mem 40 | RFM_DIR = 16, 41 | }; 42 | 43 | // RFE - REBOL File Error 44 | enum { 45 | RFE_BAD_PATH = 1, 46 | RFE_NO_MODES, // No file modes specified 47 | RFE_OPEN_FAIL, // File open failed 48 | RFE_BAD_SEEK, // Seek not supported for this file 49 | RFE_NO_HANDLE, // File struct has no handle 50 | RFE_NO_SEEK, // Seek action failed 51 | RFE_BAD_READ, // Read failed (general) 52 | RFE_BAD_WRITE, // Write failed (general) 53 | RFE_DISK_FULL, // No space on target volume 54 | }; 55 | 56 | #define MAX_FILE_NAME 1022 57 | -------------------------------------------------------------------------------- /src/include/reb-filereq.h: -------------------------------------------------------------------------------- 1 | /*********************************************************************** 2 | ** 3 | ** REBOL [R3] Language Interpreter and Run-time Environment 4 | ** 5 | ** Copyright 2012 REBOL Technologies 6 | ** REBOL is a trademark of REBOL Technologies 7 | ** 8 | ** Licensed under the Apache License, Version 2.0 (the "License"); 9 | ** you may not use this file except in compliance with the License. 10 | ** You may obtain a copy of the License at 11 | ** 12 | ** http://www.apache.org/licenses/LICENSE-2.0 13 | ** 14 | ** Unless required by applicable law or agreed to in writing, software 15 | ** distributed under the License is distributed on an "AS IS" BASIS, 16 | ** WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 17 | ** See the License for the specific language governing permissions and 18 | ** limitations under the License. 19 | ** 20 | ************************************************************************ 21 | ** 22 | ** Summary: File requestor definitions 23 | ** Module: reb-filereq.h 24 | ** Author: Carl Sassenrath 25 | ** Notes: 26 | ** 27 | ***********************************************************************/ 28 | 29 | #define MAX_FILE_REQ_BUF (16*1024) 30 | 31 | #pragma pack(4) 32 | typedef struct Reb_File_Requestor { 33 | REBCNT flags; // multi, load/save, unicode 34 | REBCHR *title; // title of requestor 35 | REBCHR *button; // button name 36 | REBCHR *dir; // dir path 37 | REBCHR *files; // buffer to hold results 38 | REBCHR *filter; // buffer to hold results 39 | REBINT len; // length of buffer 40 | } REBRFR; 41 | #pragma pack() 42 | 43 | // File Request Flags: 44 | enum { 45 | FRF_MULTI, 46 | FRF_SAVE, 47 | FRF_KEEP, 48 | }; 49 | 50 | -------------------------------------------------------------------------------- /src/include/reb-host.h: -------------------------------------------------------------------------------- 1 | /*********************************************************************** 2 | ** 3 | ** REBOL [R3] Language Interpreter and Run-time Environment 4 | ** 5 | ** Copyright 2012 REBOL Technologies 6 | ** REBOL is a trademark of REBOL Technologies 7 | ** 8 | ** Licensed under the Apache License, Version 2.0 (the "License"); 9 | ** you may not use this file except in compliance with the License. 10 | ** You may obtain a copy of the License at 11 | ** 12 | ** http://www.apache.org/licenses/LICENSE-2.0 13 | ** 14 | ** Unless required by applicable law or agreed to in writing, software 15 | ** distributed under the License is distributed on an "AS IS" BASIS, 16 | ** WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 17 | ** See the License for the specific language governing permissions and 18 | ** limitations under the License. 19 | ** 20 | ************************************************************************ 21 | ** 22 | ** Summary: Include files for hosting 23 | ** Module: reb-host.h 24 | ** Author: Carl Sassenrath 25 | ** Notes: 26 | ** 27 | ***********************************************************************/ 28 | 29 | #include "reb-config.h" 30 | 31 | #include "reb-c.h" 32 | #include "reb-ext.h" // includes reb-defs.h 33 | #include "reb-args.h" 34 | #include "reb-device.h" 35 | #include "reb-file.h" 36 | #include "reb-event.h" 37 | #include "reb-evtypes.h" 38 | #include "reb-net.h" 39 | #include "reb-filereq.h" 40 | 41 | #include "reb-gob.h" 42 | #include "reb-lib.h" 43 | -------------------------------------------------------------------------------- /src/include/reb-math.h: -------------------------------------------------------------------------------- 1 | /*********************************************************************** 2 | ** 3 | ** REBOL [R3] Language Interpreter and Run-time Environment 4 | ** 5 | ** Copyright 2012 REBOL Technologies 6 | ** REBOL is a trademark of REBOL Technologies 7 | ** 8 | ** Licensed under the Apache License, Version 2.0 (the "License"); 9 | ** you may not use this file except in compliance with the License. 10 | ** You may obtain a copy of the License at 11 | ** 12 | ** http://www.apache.org/licenses/LICENSE-2.0 13 | ** 14 | ** Unless required by applicable law or agreed to in writing, software 15 | ** distributed under the License is distributed on an "AS IS" BASIS, 16 | ** WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 17 | ** See the License for the specific language governing permissions and 18 | ** limitations under the License. 19 | ** 20 | ************************************************************************ 21 | ** 22 | ** Summary: Math related definitions 23 | ** Module: reb-math.h 24 | ** Author: Carl Sassenrath 25 | ** Notes: 26 | ** 27 | ***********************************************************************/ 28 | 29 | // Decimal number formatting specifications: 30 | typedef struct Reb_Deci_Spec { 31 | REBDEC dec; // number to form 32 | REBINT len; // # of digits requested 33 | REBCHR *out; // result: string of digits (no point or sign) 34 | REBINT point; // result: position of decimal point 35 | REBINT sign; // result: sign of number 36 | } REBDCS; 37 | -------------------------------------------------------------------------------- /src/include/reb-net.h: -------------------------------------------------------------------------------- 1 | /*********************************************************************** 2 | ** 3 | ** REBOL [R3] Language Interpreter and Run-time Environment 4 | ** 5 | ** Copyright 2012 REBOL Technologies 6 | ** REBOL is a trademark of REBOL Technologies 7 | ** 8 | ** Licensed under the Apache License, Version 2.0 (the "License"); 9 | ** you may not use this file except in compliance with the License. 10 | ** You may obtain a copy of the License at 11 | ** 12 | ** http://www.apache.org/licenses/LICENSE-2.0 13 | ** 14 | ** Unless required by applicable law or agreed to in writing, software 15 | ** distributed under the License is distributed on an "AS IS" BASIS, 16 | ** WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 17 | ** See the License for the specific language governing permissions and 18 | ** limitations under the License. 19 | ** 20 | ************************************************************************ 21 | ** 22 | ** Summary: Network device definitions 23 | ** Module: reb-net.h 24 | ** Author: Carl Sassenrath 25 | ** Notes: 26 | ** 27 | ***********************************************************************/ 28 | 29 | // REBOL Socket types: 30 | enum socket_types { 31 | RST_UDP, // TCP or UDP 32 | RST_LISTEN = 8, // LISTEN 33 | RST_REVERSE, // DNS reverse 34 | }; 35 | 36 | // REBOL Socket Modes (state flags) 37 | enum { 38 | RSM_OPEN = 0, // socket is allocated 39 | RSM_ATTEMPT, // attempting connection 40 | RSM_CONNECT, // connection is open 41 | RSM_BIND, // socket is bound to port 42 | RSM_LISTEN, // socket is listening (TCP) 43 | RSM_SEND, // sending 44 | RSM_RECEIVE, // receiving 45 | RSM_ACCEPT, // an inbound connection 46 | }; 47 | 48 | #define IPA(a,b,c,d) (a<<24 | b<<16 | c<<8 | d) 49 | -------------------------------------------------------------------------------- /src/include/reb-series.h: -------------------------------------------------------------------------------- 1 | /*********************************************************************** 2 | ** 3 | ** REBOL [R3] Language Interpreter and Run-time Environment 4 | ** 5 | ** Copyright 2012 REBOL Technologies 6 | ** REBOL is a trademark of REBOL Technologies 7 | ** 8 | ** Licensed under the Apache License, Version 2.0 (the "License"); 9 | ** you may not use this file except in compliance with the License. 10 | ** You may obtain a copy of the License at 11 | ** 12 | ** http://www.apache.org/licenses/LICENSE-2.0 13 | ** 14 | ** Unless required by applicable law or agreed to in writing, software 15 | ** distributed under the License is distributed on an "AS IS" BASIS, 16 | ** WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 17 | ** See the License for the specific language governing permissions and 18 | ** limitations under the License. 19 | ** 20 | ************************************************************************ 21 | ** 22 | ** Summary: REBOL series structure 23 | ** Module: reb-series.h 24 | ** Author: Carl Sassenrath 25 | ** Notes: 26 | ** WARNING: struct size may change -- do not malloc() 27 | ** 28 | ***********************************************************************/ 29 | 30 | typedef struct rebol_series { 31 | REBYTE *data; 32 | REBCNT tail; 33 | REBCNT rest; 34 | REBINT info; 35 | REBCNT size; // Temp - size of image w/h 36 | // OPTIONAL Extensions 37 | } REBSER; 38 | 39 | #define SERIES_TAIL(s) ((s)->tail) 40 | #define SERIES_DATA(s) ((s)->data) 41 | 42 | #define BLK_HEAD(s) ((REBVAL *)((s)->data)) 43 | #define STR_HEAD(s) ((REBYTE *)((s)->data)) 44 | 45 | #define IMG_SIZE(s) ((s)->size) 46 | #define IMG_WIDE(s) ((s)->size & 0xffff) 47 | #define IMG_HIGH(s) ((s)->size >> 16) 48 | #define IMG_DATA(s) ((REBYTE *)((s)->data)) 49 | -------------------------------------------------------------------------------- /src/include/reb-value.h: -------------------------------------------------------------------------------- 1 | /*********************************************************************** 2 | ** 3 | ** REBOL [R3] Language Interpreter and Run-time Environment 4 | ** 5 | ** Copyright 2012 REBOL Technologies 6 | ** REBOL is a trademark of REBOL Technologies 7 | ** 8 | ** Licensed under the Apache License, Version 2.0 (the "License"); 9 | ** you may not use this file except in compliance with the License. 10 | ** You may obtain a copy of the License at 11 | ** 12 | ** http://www.apache.org/licenses/LICENSE-2.0 13 | ** 14 | ** Unless required by applicable law or agreed to in writing, software 15 | ** distributed under the License is distributed on an "AS IS" BASIS, 16 | ** WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 17 | ** See the License for the specific language governing permissions and 18 | ** limitations under the License. 19 | ** 20 | ************************************************************************ 21 | ** 22 | ** Summary: REBOL Values for External Usage 23 | ** Module: reb-value.h 24 | ** Author: Carl Sassenrath 25 | ** Notes: 26 | ** Important: Compile with 4 byte alignment on structures. 27 | ** 28 | ***********************************************************************/ 29 | 30 | struct rebol_value; 31 | typedef struct rebol_value REBVAL; 32 | 33 | typedef struct rebol_tuple { 34 | REBYTE tuple[12]; 35 | } REBTUP; 36 | 37 | typedef struct rebol_series_index 38 | { 39 | REBSER *series; 40 | REBCNT index; 41 | } REBSRI; 42 | 43 | typedef struct rebol_word { 44 | REBCNT sym; // Index of the word's symbol 45 | REBINT index; // Index of the word in the frame 46 | union { 47 | REBSER *frame; // Frame in which the word is defined 48 | REBCNT typeset;// Typeset number 49 | } c; 50 | } REBWRD; 51 | 52 | struct rebol_value { 53 | union REBOL_Val_Data { 54 | REBI64 integer; 55 | REBINT int32; 56 | REBDEC decimal; 57 | REBPAR pair; 58 | REBTUP tuple; 59 | REBGOB *gob; 60 | REBWRD word; 61 | REBSRI series; 62 | } data; 63 | REBINT flags; 64 | }; 65 | 66 | #define VAL_TYPE(v) ((REBYTE)((v)->flags)) // get only the type, not flags 67 | 68 | #define VAL_INT32(v) (REBINT)((v)->data.integer) 69 | #define VAL_INT64(v) ((v)->data.integer) 70 | #define VAL_DECIMAL(v) ((v)->data.decimal) 71 | #define VAL_LOGIC(v) ((v)->data.int32) 72 | #define VAL_TUPLE(v) ((v)->data.tuple.tuple+1) 73 | #define VAL_TUPLE_LEN(v) ((v)->data.tuple.tuple[0]) 74 | #define VAL_PAIR(v) ((v)->data.pair) 75 | #define VAL_WORD(v) ((v)->data.word.index) 76 | #define VAL_WORD_SYM(v) ((v)->data.word.sym) 77 | 78 | #define VAL_SERIES(v) ((v)->data.series.series) 79 | #define VAL_STRING(v) STR_HEAD(VAL_SERIES(v)) 80 | 81 | #define VAL_IMAGE_SIZE(v) (IMG_SIZE(VAL_SERIES(v))) 82 | #define VAL_IMAGE_WIDE(v) (IMG_WIDE(VAL_SERIES(v))) 83 | #define VAL_IMAGE_HIGH(v) (IMG_HIGH(VAL_SERIES(v))) 84 | #define VAL_IMAGE_DATA(v) (IMG_DATA(VAL_SERIES(v))) 85 | 86 | -------------------------------------------------------------------------------- /src/include/sys-dec-to-char.h: -------------------------------------------------------------------------------- 1 | /*********************************************************************** 2 | ** 3 | ** REBOL [R3] Language Interpreter and Run-time Environment 4 | ** 5 | ** REBOL is a trademark of REBOL Technologies 6 | ** 7 | ** Copyright 2012 Saphirion AG 8 | ** 9 | ** Licensed under the Apache License, Version 2.0 (the "License"); 10 | ** you may not use this file except in compliance with the License. 11 | ** You may obtain a copy of the License at 12 | ** 13 | ** http://www.apache.org/licenses/LICENSE-2.0 14 | ** 15 | ** Unless required by applicable law or agreed to in writing, software 16 | ** distributed under the License is distributed on an "AS IS" BASIS, 17 | ** WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 18 | ** See the License for the specific language governing permissions and 19 | ** limitations under the License. 20 | ** 21 | ************************************************************************ 22 | ** 23 | ** Summary: Decimal conversion 24 | ** Author: Ladislav Mecir 25 | ** Notes: 26 | ** 27 | ************************************************************************ 28 | ** 29 | ** NOTE to PROGRAMMERS: 30 | ** 31 | ** 1. Keep code clear and simple. 32 | ** 2. Document unusual code, reasoning, or gotchas. 33 | ** 3. Use same style for code, vars, indent(4), comments, etc. 34 | ** 4. Keep in mind Linux, OS X, BSD, big/little endian CPUs. 35 | ** 5. Test everything, then test it again. 36 | ** 37 | ***********************************************************************/ 38 | 39 | char *dtoa(double dd, int mode, int ndigits, int *decpt, int *sign, char **rve); 40 | double STRTOD(const char *s00, char **se); 41 | -------------------------------------------------------------------------------- /src/include/sys-deci-funcs.h: -------------------------------------------------------------------------------- 1 | /*********************************************************************** 2 | ** 3 | ** REBOL [R3] Language Interpreter and Run-time Environment 4 | ** 5 | ** Copyright 2012 REBOL Technologies 6 | ** REBOL is a trademark of REBOL Technologies 7 | ** 8 | ** Licensed under the Apache License, Version 2.0 (the "License"); 9 | ** you may not use this file except in compliance with the License. 10 | ** You may obtain a copy of the License at 11 | ** 12 | ** http://www.apache.org/licenses/LICENSE-2.0 13 | ** 14 | ** Unless required by applicable law or agreed to in writing, software 15 | ** distributed under the License is distributed on an "AS IS" BASIS, 16 | ** WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 17 | ** See the License for the specific language governing permissions and 18 | ** limitations under the License. 19 | ** 20 | ************************************************************************ 21 | ** 22 | ** Summary: Deci Datatype Functions 23 | ** Module: sys-deci-funcs.h 24 | ** Notes: 25 | ** 26 | ***********************************************************************/ 27 | 28 | /* unary operators - logic */ 29 | REBFLG deci_is_zero (const deci a); 30 | 31 | /* unary operators - deci */ 32 | deci deci_abs (deci a); 33 | deci deci_negate (deci a); 34 | 35 | /* binary operators - logic */ 36 | REBFLG deci_is_equal (deci a, deci b); 37 | REBFLG deci_is_lesser_or_equal (deci a, deci b); 38 | REBFLG deci_is_same (deci a, deci b); 39 | 40 | /* binary operators - deci */ 41 | deci deci_add (deci a, deci b); 42 | deci deci_subtract (deci a, deci b); 43 | deci deci_multiply (const deci a, const deci b); 44 | deci deci_divide (deci a, deci b); 45 | deci deci_mod (deci a, deci b); 46 | 47 | /* conversion to deci */ 48 | deci int_to_deci (REBI64 a); 49 | deci decimal_to_deci (REBDEC a); 50 | deci string_to_deci (REBYTE *s, REBYTE **endptr); 51 | deci binary_to_deci(REBYTE *s); 52 | 53 | /* conversion to other datatypes */ 54 | REBI64 deci_to_int (const deci a); 55 | REBDEC deci_to_decimal (const deci a); 56 | REBINT deci_to_string(REBYTE *string, const deci a, const REBYTE symbol, const REBYTE point); 57 | REBYTE *deci_to_binary(REBYTE binary[12], const deci a); 58 | 59 | /* math functions */ 60 | deci deci_ldexp (deci a, REBINT e); 61 | deci deci_truncate (deci a, deci b); 62 | deci deci_away (deci a, deci b); 63 | deci deci_floor (deci a, deci b); 64 | deci deci_ceil (deci a, deci b); 65 | deci deci_half_even (deci a, deci b); 66 | deci deci_half_away (deci a, deci b); 67 | deci deci_half_truncate (deci a, deci b); 68 | deci deci_half_ceil (deci a, deci b); 69 | deci deci_half_floor (deci a, deci b); 70 | deci deci_sign (deci a); 71 | -------------------------------------------------------------------------------- /src/include/sys-deci.h: -------------------------------------------------------------------------------- 1 | /*********************************************************************** 2 | ** 3 | ** REBOL [R3] Language Interpreter and Run-time Environment 4 | ** 5 | ** Copyright 2012 REBOL Technologies 6 | ** REBOL is a trademark of REBOL Technologies 7 | ** 8 | ** Licensed under the Apache License, Version 2.0 (the "License"); 9 | ** you may not use this file except in compliance with the License. 10 | ** You may obtain a copy of the License at 11 | ** 12 | ** http://www.apache.org/licenses/LICENSE-2.0 13 | ** 14 | ** Unless required by applicable law or agreed to in writing, software 15 | ** distributed under the License is distributed on an "AS IS" BASIS, 16 | ** WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 17 | ** See the License for the specific language governing permissions and 18 | ** limitations under the License. 19 | ** 20 | ************************************************************************ 21 | ** 22 | ** Summary: Deci Datatype 23 | ** Module: sys-deci.h 24 | ** Notes: 25 | ** 26 | ***********************************************************************/ 27 | 28 | typedef struct deci { 29 | unsigned m0:32; /* significand, lowest part */ 30 | unsigned m1:32; /* significand, continuation */ 31 | unsigned m2:23; /* significand, highest part */ 32 | unsigned s:1; /* sign, 0 means nonnegative, 1 means nonpositive */ 33 | int e:8; /* exponent */ 34 | } deci; 35 | 36 | -------------------------------------------------------------------------------- /src/include/sys-globals.h: -------------------------------------------------------------------------------- 1 | /*********************************************************************** 2 | ** 3 | ** REBOL [R3] Language Interpreter and Run-time Environment 4 | ** 5 | ** Copyright 2012 REBOL Technologies 6 | ** REBOL is a trademark of REBOL Technologies 7 | ** 8 | ** Licensed under the Apache License, Version 2.0 (the "License"); 9 | ** you may not use this file except in compliance with the License. 10 | ** You may obtain a copy of the License at 11 | ** 12 | ** http://www.apache.org/licenses/LICENSE-2.0 13 | ** 14 | ** Unless required by applicable law or agreed to in writing, software 15 | ** distributed under the License is distributed on an "AS IS" BASIS, 16 | ** WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 17 | ** See the License for the specific language governing permissions and 18 | ** limitations under the License. 19 | ** 20 | ************************************************************************ 21 | ** 22 | ** Summary: Program and Thread Globals 23 | ** Module: sys-globals.h 24 | ** Author: Carl Sassenrath 25 | ** Notes: 26 | ** 27 | ***********************************************************************/ 28 | 29 | //-- Bootstrap variables: 30 | PVAR REBINT PG_Boot_Phase; // To know how far in the boot we are. 31 | PVAR REBINT PG_Boot_Level; // User specified startup level 32 | PVAR REBYTE **PG_Boot_Strs; // Special strings in boot.r (RS_ constants) 33 | 34 | //-- Various statistics about memory, etc. 35 | PVAR REB_STATS *PG_Reb_Stats; 36 | PVAR REBU64 PG_Mem_Usage; // Overall memory used 37 | PVAR REBU64 PG_Mem_Limit; // Memory limit set by SECURE 38 | 39 | //-- Symbol Table: 40 | PVAR REBSER *PG_Word_Names; // Holds all word strings. Never removed. 41 | PVAR WORD_TABLE PG_Word_Table; // Symbol values accessed by hash 42 | 43 | //-- Main contexts: 44 | PVAR ROOT_CTX *Root_Context; // System root variables 45 | PVAR REBSER *Lib_Context; 46 | PVAR REBSER *Sys_Context; 47 | 48 | //-- Various char tables: 49 | PVAR REBYTE *White_Chars; 50 | PVAR REBUNI *Upper_Cases; 51 | PVAR REBUNI *Lower_Cases; 52 | 53 | // Other: 54 | PVAR REBYTE *PG_Pool_Map; // Memory pool size map (created on boot) 55 | PVAR REBSER *PG_Root_Words; // Root object word table (reused by threads) 56 | 57 | PVAR REBI64 PG_Boot_Time; // Counter when boot started 58 | PVAR REBINT Current_Year; 59 | PVAR REB_OPTS *Reb_Opts; 60 | 61 | PVAR jmp_buf *Halt_State; // Pointer to saved CPU state for HALT/QUIT handlers 62 | 63 | // This signal word should be thread-local, but it will not work 64 | // when implemented that way. Needs research!!!! 65 | PVAR REBCNT Eval_Signals; // Signal flags 66 | 67 | 68 | 69 | /*********************************************************************** 70 | ** 71 | ** Thread Globals - Local to each thread 72 | ** 73 | ***********************************************************************/ 74 | 75 | TVAR TASK_CTX *Task_Context; // Main per-task variables 76 | TVAR REBSER *Task_Series; // Series that holds Task_Context 77 | 78 | //-- Memory and GC: 79 | TVAR REBPOL *Mem_Pools; // Memory pool array 80 | TVAR REBCNT GC_Disabled; // GC disabled counter for critical sections. 81 | TVAR REBINT GC_Ballast; // Bytes allocated to force automatic GC 82 | TVAR REBOOL GC_Active; // TRUE when recycle is enabled (set by RECYCLE func) 83 | TVAR REBSER *GC_Protect; // A stack of protected series (removed by pop) 84 | TVAR REBSER *GC_Series; // An array of protected series (removed by address) 85 | TVAR REBSER **GC_Infants; // A small list of last N series created (nursery) 86 | TVAR REBINT GC_Last_Infant; // Index to last infant above (circular) 87 | TVAR REBFLG GC_Stay_Dirty; // Do not free memory, fill it with 0xBB 88 | TVAR REBSER **Prior_Expand; // Track prior series expansions (acceleration) 89 | 90 | TVAR REBUPT Stack_Limit; // Limit address for CPU stack. 91 | 92 | //-- Evaluation stack: 93 | TVAR REBSER *DS_Series; 94 | TVAR REBVAL *DS_Base; // Data stack base 95 | TVAR REBINT DSP; // Data stack pointer 96 | TVAR REBINT DSF; // Data stack frame (function base) 97 | 98 | TVAR jmp_buf *Saved_State; // Pointer to saved CPU state for error handlers. 99 | 100 | //-- Evaluation variables: 101 | TVAR REBI64 Eval_Cycles; // Total evaluation counter (upward) 102 | TVAR REBI64 Eval_Limit; // Evaluation limit (set by secure) 103 | TVAR REBINT Eval_Count; // Evaluation counter (downward) 104 | TVAR REBINT Eval_Dose; // Evaluation counter reset value 105 | TVAR REBCNT Eval_Sigmask; // Masking out signal flags 106 | 107 | TVAR REBCNT Trace_Flags; // Trace flag 108 | TVAR REBINT Trace_Level; // Trace depth desired 109 | TVAR REBINT Trace_Depth; // Tracks trace indentation 110 | TVAR REBCNT Trace_Limit; // Backtrace buffering limit 111 | TVAR REBSER *Trace_Buffer; // Holds backtrace lines 112 | 113 | TVAR REBI64 Eval_Natives; 114 | TVAR REBI64 Eval_Functions; 115 | 116 | //-- Other per thread globals: 117 | TVAR REBSER *Bind_Table; // Used to quickly bind words to contexts 118 | -------------------------------------------------------------------------------- /src/include/sys-mem.h: -------------------------------------------------------------------------------- 1 | /*********************************************************************** 2 | ** 3 | ** REBOL [R3] Language Interpreter and Run-time Environment 4 | ** 5 | ** Copyright 2012 REBOL Technologies 6 | ** REBOL is a trademark of REBOL Technologies 7 | ** 8 | ** Licensed under the Apache License, Version 2.0 (the "License"); 9 | ** you may not use this file except in compliance with the License. 10 | ** You may obtain a copy of the License at 11 | ** 12 | ** http://www.apache.org/licenses/LICENSE-2.0 13 | ** 14 | ** Unless required by applicable law or agreed to in writing, software 15 | ** distributed under the License is distributed on an "AS IS" BASIS, 16 | ** WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 17 | ** See the License for the specific language governing permissions and 18 | ** limitations under the License. 19 | ** 20 | ************************************************************************ 21 | ** 22 | ** Summary: Memory allocation 23 | ** Module: sys-mem.h 24 | ** Author: Carl Sassenrath 25 | ** Notes: 26 | ** 27 | ***********************************************************************/ 28 | 29 | #ifdef DBG_CHECK_MEM 30 | #define CHECK_MEMORY(n) if (n > MEM_CARE) Check_Memory() 31 | #else 32 | #define CHECK_MEMORY(n) 33 | #endif 34 | 35 | typedef void *REBNOD; // Just used for linking free nodes 36 | 37 | /*********************************************************************** 38 | ** 39 | */ typedef struct rebol_mem_segment 40 | /* 41 | ** Linked list of used memory segments. 42 | ** 43 | ** Size: 8 bytes 44 | ** 45 | ***********************************************************************/ 46 | { 47 | struct rebol_mem_segment *next; 48 | REBCNT size; 49 | } REBSEG; 50 | 51 | 52 | /*********************************************************************** 53 | ** 54 | */ typedef struct rebol_mem_spec 55 | /* 56 | ** Specifies initial pool sizes 57 | ** 58 | ***********************************************************************/ 59 | { 60 | REBCNT wide; // size of allocation unit 61 | REBCNT units; // units per segment allocation 62 | } REBPOOLSPEC; 63 | 64 | 65 | /*********************************************************************** 66 | ** 67 | */ typedef struct rebol_mem_pool 68 | /* 69 | ** Pools manage fixed sized blocks of memory. 70 | ** 71 | ***********************************************************************/ 72 | { 73 | REBCNT wide; // size of allocation unit 74 | REBCNT units; // units per segment allocation 75 | REBCNT free; // number of units remaining 76 | REBSEG *segs; // first memory segment 77 | REBNOD *first; // first free node in pool 78 | REBCNT has; // total number of units 79 | // UL total; // total bytes for all segs 80 | // char *name; // identifying string 81 | // UL extra; // reserved 82 | } REBPOL; 83 | 84 | 85 | /*********************************************************************** 86 | ** 87 | */ enum Mem_Pool_Specs 88 | /* 89 | ***********************************************************************/ 90 | { 91 | MEM_TINY_POOL = 1, 92 | MEM_SMALL_POOLS = MEM_TINY_POOL + 16, 93 | MEM_MID_POOLS = MEM_SMALL_POOLS + 4, 94 | MEM_BIG_POOLS = MEM_MID_POOLS + 4, // larger pools 95 | SERIES_POOL = MEM_BIG_POOLS, 96 | GOB_POOL, 97 | SYSTEM_POOL, 98 | MAX_POOLS 99 | }; 100 | 101 | #define DEF_POOL(size, count) {size, count} 102 | #define MOD_POOL(size, count) {size * MEM_MIN_SIZE, count} 103 | 104 | #define MEM_MIN_SIZE sizeof(REBVAL) 105 | #define MEM_BIG_SIZE 1024 106 | 107 | #define MEM_BALLAST 3000000 108 | 109 | // Disable GC - Only necessary if DO_NEXT with non-referenced series. 110 | #define DISABLE_GC GC_Disabled++ 111 | #define ENABLE_GC GC_Disabled-- 112 | //Was: if (--GC_Disabled <= 0 && GC_Pending) Recycle() 113 | 114 | /***************************************************************************** 115 | ** 116 | ** MUNGWALL 117 | ** Define MUNGWALL to enable "MungWall"-style sentinels for REBNODEs 118 | ** 119 | *****************************************************************************/ 120 | 121 | #ifdef MUNGWALL 122 | #define MUNG_PATTERN1 "Don't overwrite!" 123 | #define MUNG_PATTERN2 "Magic protection" 124 | #define MUNG_SIZE 16 125 | #define MUNG_CHECK(a,b,c) Mung_Check((a),(REBYTE *)(b),(c)) 126 | #ifdef TO_WIN32 127 | void mywrite(int a, char *b, int c) {int i;for(i=0;i 33 | 34 | #define GET_ERROR WSAGetLastError() 35 | #define IOCTL ioctlsocket 36 | #define CLOSE_SOCKET closesocket 37 | 38 | #define NE_ISCONN WSAEISCONN 39 | #define NE_WOULDBLOCK WSAEWOULDBLOCK 40 | #define NE_INPROGRESS WSAEINPROGRESS 41 | #define NE_ALREADY WSAEALREADY 42 | #define NE_NOTCONN WSAENOTCONN 43 | #define NE_INVALID WSAEINVAL 44 | 45 | //----- BSD - The network standard the rest of the world uses 46 | #else 47 | 48 | #ifdef TO_AMIGA 49 | typedef char __BYTE; 50 | typedef unsigned char __UBYTE; 51 | typedef char * __STRPTR; 52 | typedef long __LONG; 53 | #endif 54 | 55 | #include 56 | #include 57 | #include 58 | #include 59 | #include 60 | 61 | #define GET_ERROR errno 62 | #define IOCTL ioctl 63 | #define CLOSE_SOCKET close 64 | #define SOCKET unsigned int 65 | 66 | #define NE_ISCONN EISCONN 67 | #define NE_WOULDBLOCK EAGAIN // see include/asm/errno.h 68 | #define NE_INPROGRESS EINPROGRESS 69 | #define NE_ALREADY EALREADY 70 | #define NE_NOTCONN ENOTCONN 71 | #define NE_INVALID EINVAL 72 | 73 | // Null Win32 functions: 74 | #define WSADATA int 75 | 76 | // FreeBSD mystery define: 77 | #ifndef u_int32_t 78 | #define u_int32_t long 79 | #endif 80 | 81 | #ifndef HOSTENT 82 | typedef struct hostent HOSTENT; 83 | #endif 84 | 85 | #ifndef MAXGETHOSTSTRUCT 86 | #define MAXGETHOSTSTRUCT ((sizeof(struct hostent)+15) & ~15) 87 | #endif 88 | 89 | #endif // BSD 90 | 91 | typedef struct sockaddr_in SOCKAI; // Internet extensions 92 | 93 | #define BAD_SOCKET (~0) 94 | #define MAX_TRANSFER 32000 // Max send/recv buffer size 95 | #define MAX_HOST_NAME 256 // Max length of host name 96 | -------------------------------------------------------------------------------- /src/include/sys-panics.h: -------------------------------------------------------------------------------- 1 | /*********************************************************************** 2 | ** 3 | ** REBOL [R3] Language Interpreter and Run-time Environment 4 | ** 5 | ** Copyright 2012 REBOL Technologies 6 | ** REBOL is a trademark of REBOL Technologies 7 | ** 8 | ** Licensed under the Apache License, Version 2.0 (the "License"); 9 | ** you may not use this file except in compliance with the License. 10 | ** You may obtain a copy of the License at 11 | ** 12 | ** http://www.apache.org/licenses/LICENSE-2.0 13 | ** 14 | ** Unless required by applicable law or agreed to in writing, software 15 | ** distributed under the License is distributed on an "AS IS" BASIS, 16 | ** WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 17 | ** See the License for the specific language governing permissions and 18 | ** limitations under the License. 19 | ** 20 | ************************************************************************ 21 | ** 22 | ** Summary: REBOL Panic Values 23 | ** Module: sys-panics.h 24 | ** Author: Carl Sassenrath 25 | ** Notes: 26 | ** 27 | ***********************************************************************/ 28 | 29 | enum reb_panics { 30 | 31 | // Boot Errors (very limited environment avaliable) 32 | RP_BOOT_DATA = 1000, // no boot.r text found 33 | RP_REBVAL_ALIGNMENT, // not aligned perfectly in memory 34 | RP_BAD_SIZE, // expected size did not match 35 | RP_NO_BUFFER, // buffer not yet allocated 36 | RP_BAD_BOOT_STRING, // boot strings area is invalid 37 | RP_BAD_BOOT_TYPE_BLOCK, // boot block is wrong size 38 | RP_BAD_END_TYPE_WORD, // the end word is not correct 39 | RP_ACTION_OVERFLOW, // more actions than we should have 40 | RE_NATIVE_BOOT, // bad boot.r native ordering 41 | RP_EARLY_ERROR, // error before error handling 42 | RP_BAD_END_CANON_WORD, // END was not found 43 | RP_BAD_TRUE_CANON_WORD, // TRUE was not found 44 | 45 | // Internal Errors (other things that could go wrong) 46 | RP_INTERNAL = 1100, 47 | RP_BAD_EVALTYPE, // invalid datatype for evaluation 48 | RP_CORRUPT_MEMORY, // Check_Memory() found a problem 49 | RP_HASH_OVERFLOW, // Hash ran out of space 50 | RP_NO_PRINT_PTR, // print is missing string pointer 51 | 52 | // Assertion Errors (very rare, not worth using strings) 53 | // NOTE: THESE ARE OPTIONAL. Many are only checked in debug builds. 54 | RP_ASSERTS = 1200, 55 | RP_BAD_SERIES, // zero width series requested 56 | RP_OVER_SERIES, // series overflow happened 57 | RP_BIND_TABLE_SIZE, // word table does not match bind table 58 | RP_BAD_SET_INDEX, // set word has no index 59 | RP_BAD_SET_CONTEXT, // set word has no frame 60 | RP_UNEXPECTED_END, // in GC, block ended before length reached 61 | RP_MISSING_END, // block did not have an END marker 62 | RP_NULL_MARK_SERIES, // in GC, mark series pointer is null 63 | RP_NULL_SERIES, // in GC, a series is null 64 | RP_HOLD_SERIES_MALIGN, // GC_Protect tail was wrong on UNSAVE 65 | RP_THROW_IN_GC, // tried to GC a THROW error value 66 | RP_FREE_NODE_SIZE, // node size is not what it should be 67 | RP_NO_OBJECT_FRAME, // object frame is missing 68 | RP_BAD_OBJ_FRAME, // object frame is invalid 69 | RP_BAD_OBJ_INDEX, // object index past tail 70 | RP_BAD_IMPORT_WORD, // the word index of context is invalid 71 | RP_BAD_TYPE_ACTION, // datatype out of range in action dispatch 72 | RP_BAD_PORT_ACTION, // datatype out of range for ports 73 | RP_NO_ACTION, // Action Value_Dispatch empty for this type 74 | RP_GC_STUCK, // GC_Disable did not get decremented 75 | RP_GC_OF_BLOCK, // Block has been GC'd 76 | RP_TOS_DRIFT, // TOS drifts during Do_Block 77 | RP_MAX_SCHEMES, // Too many native schemes 78 | RP_BIND_BOUNDS, // Bind is out of bounds for the frame 79 | RP_SERIES_OVERFLOW, // Tail has gone past end of series 80 | 81 | // Datatype Errors (300 + N --indicates location) 82 | RP_DATATYPE = 1300, 83 | 84 | // Documented Errors (keep in-sync with error strings in boot.r!) 85 | RP_STR_BASE = 1400, 86 | RP_NO_MEMORY, // not enough memory: %d bytes 87 | RP_BAD_WIDTH, // invalid series width: %d %d %d 88 | RP_ERROR_CATCH, // error already caught 89 | RP_STACK_OVERFLOW, // data stack overflow 90 | RP_IO_ERROR, // problem with IO 91 | RP_MAX_WORDS, // too many words 92 | RP_WORD_LIST, // word list (cache) already in use 93 | RP_LOCKED_SERIES, // locked series expansion 94 | RP_ERROR_RECYCLED, // the error object was gc'd! 95 | RP_NO_CATCH, // top level uncaught error 96 | RP_NO_SAVED_STATE, // saved state frame is missing 97 | RP_MAX_EVENTS, // event queue overflow 98 | RP_NA, // not available 99 | 100 | // Unspecified (just count them) 101 | RP_MISC, 102 | }; 103 | 104 | #define RP_ RP_ASSERTS 105 | 106 | -------------------------------------------------------------------------------- /src/include/sys-stack.h: -------------------------------------------------------------------------------- 1 | /*********************************************************************** 2 | ** 3 | ** REBOL [R3] Language Interpreter and Run-time Environment 4 | ** 5 | ** Copyright 2012 REBOL Technologies 6 | ** REBOL is a trademark of REBOL Technologies 7 | ** 8 | ** Licensed under the Apache License, Version 2.0 (the "License"); 9 | ** you may not use this file except in compliance with the License. 10 | ** You may obtain a copy of the License at 11 | ** 12 | ** http://www.apache.org/licenses/LICENSE-2.0 13 | ** 14 | ** Unless required by applicable law or agreed to in writing, software 15 | ** distributed under the License is distributed on an "AS IS" BASIS, 16 | ** WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 17 | ** See the License for the specific language governing permissions and 18 | ** limitations under the License. 19 | ** 20 | ************************************************************************ 21 | ** 22 | ** Summary: REBOL Stack Definitions 23 | ** Module: sys-stack.h 24 | ** Author: Carl Sassenrath 25 | ** Notes: 26 | ** 27 | ** DSP: index to the top of stack (active value) 28 | ** DSF: index to the base of stack frame (return value) 29 | ** 30 | ** Stack frame format: 31 | ** 32 | ** +---------------+ 33 | ** DSF->0:| Return Value | normally becomes TOS after func return 34 | ** +---------------+ 35 | ** 1:| Prior Frame | old DSF, block, and block index 36 | ** +---------------+ 37 | ** 2:| Func Word | for backtrace info 38 | ** +---------------+ 39 | ** 3:| Func Value | in case value is moved or modified 40 | ** +---------------+ 41 | ** 4:| Arg 1 | args begin here 42 | ** +---------------+ 43 | ** | Arg 2 | 44 | ** +---------------+ 45 | ** 46 | ***********************************************************************/ 47 | 48 | // Special stack controls (used by init and GC): 49 | #define DS_RESET (DSP=DSF=0) 50 | #define DS_TERMINATE (SERIES_TAIL(DS_Series) = DSP+1); 51 | 52 | // Access value at given stack location: 53 | #define DS_VALUE(d) (&DS_Base[d]) 54 | 55 | // Stack pointer based actions: 56 | #define DS_POP (&DS_Base[DSP--]) 57 | #define DS_TOP (&DS_Base[DSP]) 58 | #define DS_NEXT (&DS_Base[DSP+1]) 59 | #define DS_SKIP (DSP++) 60 | #define DS_DROP (DSP--) 61 | #define DS_GET(d) (&DS_Base[d]) 62 | #define DS_PUSH(v) (DS_Base[++DSP]=*(v)) // atomic 63 | #define DS_PUSH_UNSET SET_UNSET(&DS_Base[++DSP]) // atomic 64 | #define DS_PUSH_NONE SET_NONE(&DS_Base[++DSP]) // atomic 65 | #define DS_PUSH_TRUE VAL_SET(&DS_Base[++DSP], REB_LOGIC), \ 66 | VAL_LOGIC(&DS_Base[DSP]) = TRUE // not atomic 67 | #define DS_PUSH_INTEGER(n) VAL_SET(&DS_Base[++DSP], REB_INTEGER), \ 68 | VAL_INT64(&DS_Base[DSP]) = n // not atomic 69 | #define DS_PUSH_DECIMAL(n) VAL_SET(&DS_Base[++DSP], REB_DECIMAL), \ 70 | VAL_DECIMAL(&DS_Base[DSP]) = n // not atomic 71 | 72 | // References from DSF (stack frame base, RETURN value index): 73 | #define DSF_SIZE 3 // from DSF to ARGS-1 74 | #define DSF_BIAS (DSF_SIZE+1) // from RETURN to DSP 75 | #define DSF_RETURN(d) (&DS_Base[d]) // return value 76 | #define DSF_BACK(d) (&DS_Base[(d)+1]) // block, index, prior DSF (VAL_BACK) 77 | #define DSF_WORD(d) (&DS_Base[(d)+2]) // func word backtrace 78 | #define DSF_FUNC(d) (&DS_Base[(d)+3]) // function value saved 79 | #define DSF_ARGS(d,n) (&DS_Base[(d)+DSF_SIZE+(n)]) 80 | #define PRIOR_DSF(d) VAL_BACK(DSF_BACK(d)) 81 | 82 | // Reference from ds that points to current return value: 83 | #define D_RET (ds) 84 | #define D_ARG(n) (ds+(DSF_SIZE+n)) 85 | #define D_REF(n) (!IS_NONE(D_ARG(n))) 86 | 87 | // Reference from current DSF index: 88 | #define DS_ARG_BASE (DSF+DSF_SIZE) 89 | #define DS_ARG(n) DSF_ARGS(DSF, n) 90 | #define DS_REF(n) (!IS_NONE(DS_ARG(n))) 91 | #define DS_ARGC (DSP-DS_ARG_BASE) 92 | 93 | // RETURN operations: 94 | #define DS_RETURN (&DS_Base[DSF]) 95 | #define DS_RET_VALUE(v) (*DS_RETURN=*(v)) 96 | #define DS_RET_INT(n) VAL_SET(DS_RETURN, REB_INTEGER), \ 97 | VAL_INT64(DS_RETURN) = n // not atomic 98 | 99 | // Helpers: 100 | #define DS_RELOAD(d) (d = DS_RETURN) 101 | #define SET_BACK(v,b,i,f) VAL_SET((v), REB_BLOCK), VAL_SERIES(v)=(b), \ 102 | VAL_INDEX(v)=i, VAL_BACK(v)=f 103 | 104 | enum { 105 | R_RET = 0, 106 | R_TOS, 107 | R_TOS1, 108 | R_NONE, 109 | R_UNSET, 110 | R_TRUE, 111 | R_FALSE, 112 | R_ARG1, 113 | R_ARG2, 114 | R_ARG3 115 | }; 116 | -------------------------------------------------------------------------------- /src/include/sys-state.h: -------------------------------------------------------------------------------- 1 | /*********************************************************************** 2 | ** 3 | ** REBOL [R3] Language Interpreter and Run-time Environment 4 | ** 5 | ** Copyright 2012 REBOL Technologies 6 | ** REBOL is a trademark of REBOL Technologies 7 | ** 8 | ** Licensed under the Apache License, Version 2.0 (the "License"); 9 | ** you may not use this file except in compliance with the License. 10 | ** You may obtain a copy of the License at 11 | ** 12 | ** http://www.apache.org/licenses/LICENSE-2.0 13 | ** 14 | ** Unless required by applicable law or agreed to in writing, software 15 | ** distributed under the License is distributed on an "AS IS" BASIS, 16 | ** WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 17 | ** See the License for the specific language governing permissions and 18 | ** limitations under the License. 19 | ** 20 | ************************************************************************ 21 | ** 22 | ** Summary: CPU State 23 | ** Module: sys-state.h 24 | ** Author: Carl Sassenrath 25 | ** Notes: 26 | ** 27 | ***********************************************************************/ 28 | 29 | // Create this on your local stack frame or globally: 30 | typedef struct { // State variables to save 31 | jmp_buf *last_jmp_buf; 32 | REBINT dsp; 33 | REBINT dsf; 34 | REBINT hold_tail; // Tail for GC_Protect 35 | REBSER *error; 36 | jmp_buf cpu_state; 37 | } REBOL_STATE; 38 | 39 | // Save current state info into a structure: 40 | // g is Saved_State or Halt_State. 41 | #define PUSH_STATE(s, g) do {\ 42 | (s).last_jmp_buf = g;\ 43 | (s).dsp = DSP;\ 44 | (s).dsf = DSF;\ 45 | (s).hold_tail = GC_Protect->tail;\ 46 | (s).error = 0;\ 47 | } while(0) 48 | 49 | #define POP_STATE(s, g) do {\ 50 | g = (s).last_jmp_buf;\ 51 | DSP = (s).dsp;\ 52 | DSF = (s).dsf;\ 53 | GC_Protect->tail = (s).hold_tail;\ 54 | } while (0) 55 | 56 | // Do not restore prior state: 57 | #define DROP_STATE(s, g) g = (s).last_state 58 | 59 | // Set the pointer for the prior state: 60 | #define SET_STATE(s, g) g = &(s).cpu_state 61 | 62 | // Store all CPU registers into the structure: 63 | #define SET_JUMP(s) setjmp((s).cpu_state) 64 | -------------------------------------------------------------------------------- /src/mezz/base-constants.r: -------------------------------------------------------------------------------- 1 | REBOL [ 2 | System: "REBOL [R3] Language Interpreter and Run-time Environment" 3 | Title: "REBOL 3 Boot Base: Constants and Equates" 4 | Rights: { 5 | Copyright 2012 REBOL Technologies 6 | REBOL is a trademark of REBOL Technologies 7 | } 8 | License: { 9 | Licensed under the Apache License, Version 2.0 10 | See: http://www.apache.org/licenses/LICENSE-2.0 11 | } 12 | Note: { 13 | This code is evaluated just after actions, natives, sysobj, and other lower 14 | levels definitions. This file intializes a minimal working environment 15 | that is used for the rest of the boot. 16 | } 17 | ] 18 | 19 | ; NOTE: The system is not fully booted at this point, so only simple 20 | ; expressions are allowed. Anything else will crash the boot. 21 | 22 | ;-- Standard constants: 23 | on: true 24 | off: false 25 | yes: true 26 | no: false 27 | zero: 0 28 | 29 | ;-- Special values: 30 | REBOL: system 31 | sys: system/contexts/sys 32 | lib: system/contexts/lib 33 | 34 | ;-- Char constants: 35 | null: #"^(NULL)" 36 | space: #" " 37 | sp: space 38 | backspace: #"^(BACK)" 39 | bs: backspace 40 | tab: #"^-" 41 | newline: #"^/" 42 | newpage: #"^l" 43 | slash: #"/" 44 | backslash: #"\" 45 | escape: #"^(ESC)" 46 | cr: #"^M" 47 | lf: newline 48 | crlf: "^M^J" 49 | 50 | ;-- Function synonyms: 51 | q: :quit 52 | !: :not 53 | min: :minimum 54 | max: :maximum 55 | abs: :absolute 56 | empty?: :tail? 57 | ---: :comment 58 | bind?: :bound? 59 | 60 | rebol.com: http://www.rebol.com 61 | -------------------------------------------------------------------------------- /src/mezz/base-debug.r: -------------------------------------------------------------------------------- 1 | REBOL [ 2 | System: "REBOL [R3] Language Interpreter and Run-time Environment" 3 | Title: "REBOL 3 Boot Base: Debug Functions" 4 | Rights: { 5 | Copyright 2012 REBOL Technologies 6 | REBOL is a trademark of REBOL Technologies 7 | } 8 | License: { 9 | Licensed under the Apache License, Version 2.0 10 | See: http://www.apache.org/licenses/LICENSE-2.0 11 | } 12 | Note: { 13 | This code is evaluated just after actions, natives, sysobj, and other lower 14 | levels definitions. This file intializes a minimal working environment 15 | that is used for the rest of the boot. 16 | } 17 | ] 18 | 19 | probe: func [ 20 | {Debug print a molded value and returns that same value.} 21 | value [any-type!] 22 | ][ 23 | print mold :value 24 | :value 25 | ] 26 | 27 | ??: func [ 28 | {Debug print a word, path, or block of such, followed by its molded value.} 29 | 'name "Word, path, and block to obtain values." 30 | /local out 31 | ][ 32 | case [ 33 | any [ 34 | word? :name 35 | path? :name 36 | ][ 37 | print ajoin [name ": " mold name: get :name] 38 | ] 39 | block? :name [ 40 | out: make string! 50 41 | foreach word name [ 42 | either any [ 43 | word? :word 44 | path? :word 45 | ][ 46 | repend out [word ": " mold get word " "] 47 | ][ 48 | repend out [mold word " "] 49 | ] 50 | ] 51 | print out 52 | ] 53 | true [probe :name] 54 | ] 55 | :name 56 | ] 57 | 58 | boot-print: func [ 59 | "Prints during boot when not quiet." 60 | data 61 | ][ 62 | unless system/options/quiet [print :data] 63 | ] 64 | 65 | loud-print: func [ 66 | "Prints during boot when verbose." 67 | data 68 | ][ 69 | if system/options/flags/verbose [print :data] 70 | ] 71 | -------------------------------------------------------------------------------- /src/mezz/base-defs.r: -------------------------------------------------------------------------------- 1 | REBOL [ 2 | System: "REBOL [R3] Language Interpreter and Run-time Environment" 3 | Title: "REBOL 3 Boot Base: Other Definitions" 4 | Rights: { 5 | Copyright 2012 REBOL Technologies 6 | REBOL is a trademark of REBOL Technologies 7 | } 8 | License: { 9 | Licensed under the Apache License, Version 2.0 10 | See: http://www.apache.org/licenses/LICENSE-2.0 11 | } 12 | Note: { 13 | This code is evaluated just after actions, natives, sysobj, and other lower 14 | levels definitions. This file intializes a minimal working environment 15 | that is used for the rest of the boot. 16 | } 17 | ] 18 | 19 | ;-- Create the reflector functions (e.g. spec-of, body-of, ...) 20 | 21 | ; Must be defined in A108 (no forward refs) 22 | spec-of: 23 | body-of: 24 | words-of: 25 | values-of: 26 | types-of: 27 | title-of: 28 | none 29 | 30 | use [word title] [ 31 | foreach name system/catalog/reflectors [ 32 | word: make word! ajoin [name "-of"] 33 | word: bind/new word 'reflect 34 | title: ajoin ["Returns a copy of the " name " of a " switch/default name [ 35 | spec ["function or module"] 36 | values ["object or module"] 37 | types title ["function"] ; title should include module Title too... 38 | ] ["function, object, or module"]] ; body, words 39 | set word func 40 | reduce [title 'value] 41 | compose [reflect :value (to lit-word! name)] 42 | ] 43 | ] 44 | 45 | decode-url: none ; set in sys init 46 | 47 | ;-- Setup Codecs ------------------------------------------------------------- 48 | 49 | foreach [codec handler] system/codecs [ 50 | if handle? handler [ 51 | ; Change boot handle into object: 52 | codec: set codec make object! [ 53 | entry: handler 54 | title: form reduce ["Internal codec for" codec "media type"] 55 | name: codec 56 | type: 'image! 57 | suffixes: select [ 58 | text [%.txt] 59 | markup [%.html %.htm %.xml %.xsl %.wml %.sgml %.asp %.php %.cgi] 60 | bmp [%.bmp] 61 | gif [%.gif] 62 | jpeg [%.jpg %.jpeg] 63 | png [%.png] 64 | ] codec 65 | ] 66 | ; Media-types block format: [.abc .def type ...] 67 | append append system/options/file-types codec/suffixes codec/name 68 | ] 69 | ] 70 | 71 | ; Special import case for extensions: 72 | append system/options/file-types switch/default fourth system/version [ 73 | 3 [[%.rx %.dll extension]] ; Windows 74 | 2 [[%.rx %.dylib %.so extension]] ; OS X 75 | 4 7 [[%.rx %.so extension]] ; Other Posix 76 | ] [[%.rx extension]] 77 | 78 | internal!: make typeset! [ 79 | end! unset! frame! handle! 80 | ] 81 | 82 | immediate!: make typeset! [ 83 | ; Does not include internal datatypes 84 | none! logic! scalar! date! any-word! datatype! typeset! event! 85 | ] 86 | 87 | system/options/result-types: make typeset! [ 88 | immediate! series! bitset! image! object! map! gob! 89 | ] 90 | 91 | ;-- Create "To-Datatype" conversion functions early in bootstrap: 92 | 93 | any-block?: func [ 94 | "Return TRUE if value is any type of block." 95 | value [any-type!] 96 | ][find any-block! type? :value] 97 | 98 | any-string?: func [ 99 | "Return TRUE if value is any type of string." 100 | value [any-type!] 101 | ][find any-string! type? :value] 102 | 103 | any-function?: func [ 104 | "Return TRUE if value is any type of function." 105 | value [any-type!] 106 | ][find any-function! type? :value] 107 | 108 | any-word?: func [ 109 | "Return TRUE if value is any type of word." 110 | value [any-type!] 111 | ][find any-word! type? :value] 112 | 113 | any-path?: func [ 114 | "Return TRUE if value is any type of path." 115 | value [any-type!] 116 | ][find any-path! type? :value] 117 | 118 | any-object?: func [ 119 | "Return TRUE if value is any type of object." 120 | value [any-type!] 121 | ][find any-object! type? :value] 122 | 123 | number?: func [ 124 | "Return TRUE if value is a number (integer or decimal)." 125 | value [any-type!] 126 | ][find number! type? :value] 127 | 128 | series?: func [ 129 | "Return TRUE if value is any type of series." 130 | value [any-type!] 131 | ][find series! type? :value] 132 | 133 | scalar?: func [ 134 | "Return TRUE if value is any type of scalar." 135 | value [any-type!] 136 | ][find scalar! type? :value] 137 | 138 | true?: func [ 139 | "Returns true if an expression can be used as true." 140 | val ; Note: No [any-type!] - we want unset! to fail. 141 | ] [not not :val] 142 | 143 | quote: func [ 144 | "Returns the value passed to it without evaluation." 145 | :value [any-type!] 146 | ] [ 147 | :value 148 | ] 149 | -------------------------------------------------------------------------------- /src/mezz/base-funcs.r: -------------------------------------------------------------------------------- 1 | REBOL [ 2 | System: "REBOL [R3] Language Interpreter and Run-time Environment" 3 | Title: "REBOL 3 Boot Base: Function Constructors" 4 | Rights: { 5 | Copyright 2012 REBOL Technologies 6 | REBOL is a trademark of REBOL Technologies 7 | } 8 | License: { 9 | Licensed under the Apache License, Version 2.0 10 | See: http://www.apache.org/licenses/LICENSE-2.0 11 | } 12 | Note: { 13 | This code is evaluated just after actions, natives, sysobj, and other lower 14 | levels definitions. This file intializes a minimal working environment 15 | that is used for the rest of the boot. 16 | } 17 | ] 18 | 19 | func: make function! [[ 20 | ; !!! This is a special minimal FUNC for more efficient boot. Gets replaced later in boot. 21 | {Non-copying function constructor (optimized for boot).} 22 | spec [block!] {Help string (opt) followed by arg words (and opt type and string)} 23 | body [block!] {The body block of the function} 24 | ][ 25 | make function! reduce [spec body] 26 | ]] 27 | 28 | function: funct: func [ 29 | {Defines a function with all set-words as locals.} 30 | spec [block!] {Help string (opt) followed by arg words (and opt type and string)} 31 | body [block!] {The body block of the function} 32 | /with {Define or use a persistent object (self)} 33 | object [object! block! map!] {The object or spec} 34 | /extern words [block!] {These words are not local} 35 | ][ 36 | ; Copy the spec and add /local to the end if not found 37 | unless find spec: copy/deep spec /local [append spec [ 38 | /local ; In a block so the generated source gets the newlines 39 | ]] 40 | ; Make a full copy of the body, to allow reuse of the original 41 | body: copy/deep body 42 | ; Collect all set-words in the body as words to be used as locals, and add 43 | ; them to the spec. Don't include the words already in the spec or object. 44 | insert find/tail spec /local collect-words/deep/set/ignore body either with [ 45 | ; Make our own local object if a premade one is not provided 46 | unless object? object [object: make object! object] 47 | bind body object ; Bind any object words found in the body 48 | ; Ignore the words in the spec and those in the object. The spec needs 49 | ; to be copied since the object words shouldn't be added to the locals. 50 | append append append copy spec 'self words-of object words ; ignore 'self too 51 | ][ 52 | ; Don't include the words in the spec, or any extern words. 53 | either extern [append copy spec words] [spec] 54 | ] 55 | make function! reduce [spec body] 56 | ] 57 | 58 | does: func [ 59 | {A shortcut to define a function that has no arguments or locals.} 60 | body [block!] {The body block of the function} 61 | ][ 62 | make function! copy/deep reduce [[] body] 63 | ] 64 | 65 | use: func [ 66 | {Defines words local to a block.} 67 | vars [block! word!] {Local word(s) to the block} 68 | body [block!] {Block to evaluate} 69 | ][ ; !!Needs the R3 equivalent of the [throw] function attribute in the created closure! 70 | apply make closure! reduce [to block! vars copy/deep body] [] 71 | ] 72 | 73 | object: func [ 74 | {Defines a unique object.} 75 | blk [block!] {Object words and values (modified)} 76 | ][ 77 | make object! append blk none 78 | ] 79 | 80 | module: func [ 81 | "Creates a new module." 82 | spec [block!] "The header block of the module (modified)" 83 | body [block!] "The body block of the module (modified)" 84 | /mixin "Mix in words from other modules" 85 | words [object!] "Words collected into an object" 86 | ][ 87 | make module! unbind/deep reduce pick [[spec body] [spec body words]] not mixin 88 | ] 89 | 90 | cause-error: func [ 91 | "Causes an immediate error throw with the provided information." 92 | err-type [word!] 93 | err-id [word!] 94 | args 95 | ][ 96 | ; Make sure it's a block: 97 | args: compose [(:args)] 98 | ; Filter out functional values: 99 | forall args [ 100 | if any-function? first args [ 101 | change/only args spec-of first args 102 | ] 103 | ] 104 | ; Build and throw the error: 105 | do make error! [ 106 | type: err-type 107 | id: err-id 108 | arg1: first args 109 | arg2: second args 110 | arg3: third args 111 | ] 112 | ] 113 | 114 | default: func [ 115 | "Set a word to a default value if it hasn't been set yet." 116 | 'word [word! set-word! lit-word!] "The word (use :var for word! values)" 117 | value "The value" ; unset! not allowed on purpose 118 | ][ 119 | unless all [value? word not none? get word] [set word :value] :value 120 | ] 121 | 122 | secure: func ['d] [boot-print "SECURE is disabled"] 123 | 124 | -------------------------------------------------------------------------------- /src/mezz/base-series.r: -------------------------------------------------------------------------------- 1 | REBOL [ 2 | System: "REBOL [R3] Language Interpreter and Run-time Environment" 3 | Title: "REBOL 3 Boot Base: Series Functions" 4 | Rights: { 5 | Copyright 2012 REBOL Technologies 6 | REBOL is a trademark of REBOL Technologies 7 | } 8 | License: { 9 | Licensed under the Apache License, Version 2.0 10 | See: http://www.apache.org/licenses/LICENSE-2.0 11 | } 12 | Note: { 13 | This code is evaluated just after actions, natives, sysobj, and other lower 14 | levels definitions. This file intializes a minimal working environment 15 | that is used for the rest of the boot. 16 | } 17 | ] 18 | 19 | repend: func [ 20 | "Appends a reduced value to a series and returns the series head." 21 | series [series! port! map! gob! object! bitset!] {Series at point to insert (modified)} 22 | value {The value to insert} 23 | /part {Limits to a given length or position} 24 | length [number! series! pair!] 25 | /only {Inserts a series as a series} 26 | /dup {Duplicates the insert a specified number of times} 27 | count [number! pair!] 28 | ][ 29 | apply :append [series reduce :value part length only dup count] 30 | ] 31 | 32 | join: func [ 33 | "Concatenates values." 34 | value "Base value" 35 | rest "Value or block of values" 36 | ][ 37 | value: either series? :value [copy value] [form :value] 38 | repend value :rest 39 | ] 40 | 41 | reform: func [ 42 | "Forms a reduced block and returns a string." 43 | value "Value to reduce and form" 44 | ;/with "separator" 45 | ][ 46 | form reduce :value 47 | ] 48 | -------------------------------------------------------------------------------- /src/mezz/boot-files.r: -------------------------------------------------------------------------------- 1 | REBOL [ 2 | System: "REBOL [R3] Language Interpreter and Run-time Environment" 3 | Title: "REBOL 3 Boot: System Contexts" 4 | Rights: { 5 | Copyright 2012 REBOL Technologies 6 | REBOL is a trademark of REBOL Technologies 7 | } 8 | License: { 9 | Licensed under the Apache License, Version 2.0 10 | See: http://www.apache.org/licenses/LICENSE-2.0 11 | } 12 | Note: "Used by tools/make-boot.r" 13 | ] 14 | 15 | ;-- base: low-level boot in lib context: 16 | [ 17 | %base-constants.r 18 | %base-funcs.r 19 | %base-series.r 20 | %base-files.r 21 | %base-debug.r 22 | %base-defs.r 23 | ] 24 | 25 | ;-- sys: low-level sys context: 26 | [ 27 | %sys-base.r 28 | %sys-ports.r 29 | %sys-codec.r ; export to lib! 30 | %sys-load.r 31 | %sys-start.r 32 | ] 33 | 34 | ;-- lib: mid-level lib context: 35 | [ 36 | %mezz-types.r 37 | %mezz-func.r 38 | %mezz-debug.r 39 | %mezz-control.r 40 | %mezz-save.r 41 | %mezz-series.r 42 | %mezz-files.r 43 | %mezz-shell.r 44 | %mezz-math.r 45 | %mezz-help.r ; move dump-obj! 46 | %mezz-banner.r 47 | %mezz-colors.r 48 | %mezz-tail.r 49 | ] 50 | 51 | ;-- protocols: 52 | [ 53 | %prot-http.r 54 | ] 55 | -------------------------------------------------------------------------------- /src/mezz/dial-draw.r: -------------------------------------------------------------------------------- 1 | REBOL [ 2 | System: "REBOL [R3] Language Interpreter and Run-time Environment" 3 | Title: "REBOL Internal Dialect: Draw Commands (SVG)" 4 | Rights: { 5 | Copyright 2012 REBOL Technologies 6 | REBOL is a trademark of REBOL Technologies 7 | } 8 | License: { 9 | Licensed under the Apache License, Version 2.0 10 | See: http://www.apache.org/licenses/LICENSE-2.0 11 | } 12 | Note: "Modification requires recompiling affected source files." 13 | ] 14 | 15 | system/dialects/draw: context [ 16 | 17 | type-spec: [block!] 18 | 19 | ;-- DRAW Commands: 20 | 21 | anti-alias: [logic!] 22 | arc: [;shared with SHAPE command 23 | pair! pair! decimal! decimal! word! 24 | decimal! word! 25 | ] 26 | arrow: [tuple! pair!] 27 | box: [pair! pair! decimal!] 28 | circle: [pair! decimal! decimal!] 29 | clip: [pair! pair! logic!] 30 | curve: [* pair!] ;shared with SHAPE command 31 | effect: [pair! pair! block!] 32 | ellipse: [pair! pair!] 33 | fill-pen: [tuple! image! logic!] 34 | fill-rule: [word!] 35 | gamma: [decimal!] 36 | grad-pen: [word! word! pair! logic! decimal! decimal! decimal! decimal! decimal! block!] 37 | invert-matrix: [] 38 | image: [image! tuple! word! word! integer! integer! integer! integer! * pair!] 39 | image-filter: [word! word! decimal!] 40 | line: [* pair!] ;shared with SHAPE command 41 | line-cap: [word!] 42 | line-join: [word!] 43 | line-pattern: [logic! tuple! * decimal!] 44 | line-width: [decimal! word!] 45 | matrix: [block!] 46 | pen: [tuple! image! logic!] 47 | polygon: [* pair!] 48 | push: [block!] 49 | reset-matrix: [] 50 | rotate: [decimal!] 51 | scale: [decimal! decimal!] 52 | shape: [block!] 53 | skew: [decimal!] 54 | spline: [integer! word! * pair!] 55 | text: [word! pair! pair! block!] 56 | transform: [decimal! pair! decimal! decimal! pair!] 57 | translate: [pair!] 58 | triangle: [pair! pair! pair! tuple! tuple! tuple! decimal!] 59 | 60 | ;-- SHAPE Commands 61 | ;arc is shared 62 | close: [] 63 | curv: [* pair!] 64 | ;curve is shared 65 | hline: [decimal!] 66 | ;line is shared 67 | move: [* pair!] 68 | qcurv: [pair!] 69 | qcurve: [* pair!] 70 | vline: [decimal!] 71 | 72 | ;-- DRAW Options: 73 | 74 | ; FILL-PEN 75 | radial: 76 | conic: 77 | diamond: 78 | linear: 79 | diagonal: 80 | cubic: 81 | 82 | ; FILL-RULE 83 | non-zero: 84 | even-odd: 85 | 86 | ; IMAGE 87 | border: 88 | 89 | ; IMAGE-FILTER 90 | nearest: 91 | bilinear: 92 | bicubic: 93 | gaussian: 94 | resample: 95 | 96 | ; LINE-CAP 97 | butt: 98 | square: 99 | rounded: 100 | 101 | ; LINE-JOIN 102 | miter: 103 | miter-bevel: 104 | round: 105 | bevel: 106 | 107 | ;LINE-WIDTH 108 | fixed: 109 | 110 | ; SPLINE & ARC & TEXT 111 | closed: 112 | 113 | ; GRADIENT 114 | normal: 115 | repeat: 116 | reflect: 117 | 118 | ;SHAPE ARC 119 | large: 120 | sweep: 121 | 122 | ;TEXT 123 | vectorial: 124 | none 125 | ] 126 | -------------------------------------------------------------------------------- /src/mezz/dial-effect.r: -------------------------------------------------------------------------------- 1 | REBOL [ 2 | System: "REBOL [R3] Language Interpreter and Run-time Environment" 3 | Title: "REBOL Internal Dialect: Graphic Effects" 4 | Rights: { 5 | Copyright 2012 REBOL Technologies 6 | REBOL is a trademark of REBOL Technologies 7 | } 8 | License: { 9 | Licensed under the Apache License, Version 2.0 10 | See: http://www.apache.org/licenses/LICENSE-2.0 11 | } 12 | Note: "Modification requires recompiling affected source files." 13 | ] 14 | 15 | system/dialects/effect: context [ 16 | 17 | type-spec: [] 18 | 19 | add: [image! image!] 20 | alphamul: [image! integer!] 21 | aspect: [image! word! word! decimal!] 22 | blur: [image!] 23 | colorify: [image! tuple! integer!] 24 | colorize: [image! tuple!] 25 | convolve: [image! block! decimal! integer! logic!] 26 | contrast: [image! integer!] 27 | crop: [image! pair! pair!] 28 | difference: [image! image! tuple!] 29 | emboss: [image!] 30 | extend: [image! pair! pair!] 31 | fit: [image! word! word! decimal!] 32 | flip: [image! pair!] 33 | gradcol: [image! pair! tuple! tuple!] 34 | gradient: [image! pair! tuple! tuple!] 35 | gradmul: [image! pair! tuple! tuple!] 36 | grayscale: [image!] 37 | hsv: [image! tuple!] 38 | invert: [image!] 39 | key: [image! tuple!] 40 | luma: [image! integer!] 41 | mix: [image! image!] 42 | multiply: [image! image! tuple! integer!] 43 | reflect: [image! pair!] 44 | rotate: [image! integer!] 45 | shadow: [image! pair! pair! tuple! decimal! word!] 46 | sharpen: [image!] 47 | tile: [image! pair!] 48 | tile-view: [image!] 49 | tint: [image! integer!] 50 | 51 | ;not yet 52 | comment { 53 | clip: [] 54 | } 55 | ;-- EFFECTS Options: 56 | 57 | ;SHADOW option 58 | only: 59 | 60 | ;FIT options 61 | nearest: 62 | bilinear: 63 | bicubic: 64 | gaussian: 65 | resample: none 66 | ] 67 | -------------------------------------------------------------------------------- /src/mezz/dial-text.r: -------------------------------------------------------------------------------- 1 | REBOL [ 2 | System: "REBOL [R3] Language Interpreter and Run-time Environment" 3 | Title: "REBOL Internal Dialect: Rich Text" 4 | Rights: { 5 | Copyright 2012 REBOL Technologies 6 | REBOL is a trademark of REBOL Technologies 7 | } 8 | License: { 9 | Licensed under the Apache License, Version 2.0 10 | See: http://www.apache.org/licenses/LICENSE-2.0 11 | } 12 | Note: "Modification requires recompiling affected source files." 13 | ] 14 | 15 | system/dialects/text: context [ 16 | 17 | type-spec: [string! tuple!] 18 | 19 | bold: [logic!] 20 | italic: [logic!] 21 | underline: [logic!] 22 | font: [object!] 23 | para: [object!] 24 | size: [integer!] 25 | shadow: [pair! tuple! integer!] 26 | scroll: [pair!] 27 | drop: [integer!] 28 | anti-alias: [logic!] 29 | newline: [] 30 | caret: [object!] 31 | center: [] 32 | left: [] 33 | right: [] 34 | 35 | ; Aliases 36 | b: 37 | i: 38 | u: 39 | nl: 40 | none 41 | 42 | ] 43 | -------------------------------------------------------------------------------- /src/mezz/mezz-banner.r: -------------------------------------------------------------------------------- 1 | REBOL [ 2 | System: "REBOL [R3] Language Interpreter and Run-time Environment" 3 | Title: "REBOL 3 Mezzanine: Startup Banner" 4 | Rights: { 5 | Copyright 2012 REBOL Technologies 6 | REBOL is a trademark of REBOL Technologies 7 | } 8 | License: { 9 | Licensed under the Apache License, Version 2.0 10 | See: http://www.apache.org/licenses/LICENSE-2.0 11 | } 12 | ] 13 | 14 | make-banner: func [ 15 | "Build startup banner." 16 | fmt /local str star spc a b s 17 | ][ 18 | if string? fmt [return fmt] ; aleady built 19 | str: make string! 200 20 | star: append/dup make string! 74 #"*" 74 21 | spc: format ["**" 70 "**"] "" 22 | parse fmt [ 23 | some [ 24 | [ 25 | set a string! (s: format ["** " 68 "**"] a) 26 | | '= set a [string! | word! | set-word!] [ 27 | b: 28 | path! (b: get b/1) 29 | | word! (b: get b/1) 30 | | block! (b: reform b/1) 31 | | string! (b: b/1) 32 | ] 33 | (s: format ["** " 11 55 "**"] reduce [a b]) 34 | | '* (s: star) 35 | | '- (s: spc) 36 | ] 37 | (append append str s newline) 38 | ] 39 | ] 40 | str 41 | ] 42 | 43 | sys/boot-banner: make-banner [ 44 | * 45 | - 46 | "REBOL 3.0 [Alpha Test]" 47 | - 48 | = Copyright: [system/build/year "REBOL Technologies"] 49 | = "" "All rights reserved." 50 | = Website: "www.REBOL.com" 51 | - 52 | = Version: system/version 53 | = Platform: system/platform 54 | = Build: system/build 55 | = Warning: "For testing purposes only. Use at your own risk." 56 | - 57 | = Language: system/locale/language* 58 | = Locale: system/locale/locale* 59 | = Home: [to-local-file system/options/home] 60 | - 61 | * 62 | ] 63 | 64 | sys/boot-help: 65 | {Important notes: 66 | 67 | * Sandbox and security are not available. 68 | * Direct access to TCP HTTP required (no proxies). 69 | * Default web browser must be available. 70 | 71 | Special functions: 72 | 73 | Chat - open DevBase developer forum/BBS 74 | Docs - open DocBase document wiki (web) 75 | Bugs - open CureCode bug database (web) 76 | Demo - run demo launcher (from rebol.com) 77 | Help - show built-in help information 78 | Upgrade - check for newer releases 79 | Changes - what's new about this version (web) 80 | } 81 | 82 | ;print make-banner boot-banner halt 83 | ;print boot-help 84 | -------------------------------------------------------------------------------- /src/mezz/mezz-colors.r: -------------------------------------------------------------------------------- 1 | REBOL [ 2 | System: "REBOL [R3] Language Interpreter and Run-time Environment" 3 | Title: "REBOL View: Standard Colors" 4 | Rights: { 5 | Copyright 2012 REBOL Technologies 6 | REBOL is a trademark of REBOL Technologies 7 | } 8 | License: { 9 | Licensed under the Apache License, Version 2.0 10 | See: http://www.apache.org/licenses/LICENSE-2.0 11 | } 12 | ] 13 | 14 | black: 0.0.0 15 | coal: 64.64.64 16 | gray: 128.128.128 17 | pewter: 170.170.170 18 | silver: 192.192.192 19 | snow: 240.240.240 20 | white: 255.255.255 21 | 22 | blue: 0.0.255 23 | green: 0.255.0 24 | red: 255.0.0 25 | 26 | cyan: 0.255.255 27 | magenta: 255.0.255 28 | yellow: 255.255.0 29 | 30 | yello: 255.240.120 ; selection yellow 31 | navy: 0.0.128 32 | leaf: 0.128.0 33 | teal: 0.128.128 34 | maroon: 128.0.0 35 | olive: 128.128.0 36 | purple: 128.0.128 37 | 38 | orange: 255.150.10 39 | oldrab: 72.72.16 40 | brown: 139.69.19 41 | coffee: 76.26.0 42 | sienna: 160.82.45 43 | crimson: 220.20.60 44 | violet: 72.0.90 45 | brick: 178.34.34 46 | pink: 255.164.200 47 | gold: 255.205.40 48 | tan: 222.184.135 49 | beige: 255.228.196 50 | ivory: 255.255.240 51 | linen: 250.240.230 52 | khaki: 179.179.126 53 | rebolor: 142.128.110 54 | wheat: 245.222.129 55 | aqua: 40.100.130 56 | forest: 0.48.0 57 | water: 80.108.142 58 | papaya: 255.80.37 59 | sky: 164.200.255 60 | mint: 100.136.116 61 | 62 | reblue: 38.58.108 63 | base-color: 200.200.200 64 | -------------------------------------------------------------------------------- /src/mezz/mezz-control.r: -------------------------------------------------------------------------------- 1 | REBOL [ 2 | System: "REBOL [R3] Language Interpreter and Run-time Environment" 3 | Title: "REBOL 3 Mezzanine: Control" 4 | Rights: { 5 | Copyright 2012 REBOL Technologies 6 | REBOL is a trademark of REBOL Technologies 7 | } 8 | License: { 9 | Licensed under the Apache License, Version 2.0 10 | See: http://www.apache.org/licenses/LICENSE-2.0 11 | } 12 | ] 13 | 14 | launch: func [ 15 | {Runs a script as a separate process; return immediately.} 16 | script [file! string! none!] "The name of the script" 17 | /args arg [string! block! none!] "Arguments to the script" 18 | /wait "Wait for the process to terminate" 19 | /local exe 20 | ][ 21 | if file? script [script: to-local-file clean-path script] 22 | exe: to-local-file system/options/boot 23 | 24 | ; Quote everything, just in case it has spaces: 25 | args: to-string reduce [{"} exe {" "} script {" }] 26 | if arg [append args arg] 27 | either wait [call/wait args] [call args] 28 | ] 29 | 30 | wrap: func [ 31 | "Evaluates a block, wrapping all set-words as locals." 32 | body [block!] "Block to evaluate" 33 | ][ 34 | do bind/copy/set body make object! 0 35 | ] 36 | -------------------------------------------------------------------------------- /src/mezz/mezz-debug.r: -------------------------------------------------------------------------------- 1 | REBOL [ 2 | System: "REBOL [R3] Language Interpreter and Run-time Environment" 3 | Title: "REBOL 3 Mezzanine: Debug" 4 | Rights: { 5 | Copyright 2012 REBOL Technologies 6 | REBOL is a trademark of REBOL Technologies 7 | } 8 | License: { 9 | Licensed under the Apache License, Version 2.0 10 | See: http://www.apache.org/licenses/LICENSE-2.0 11 | } 12 | ] 13 | 14 | dt: delta-time: function [ 15 | {Delta-time - returns the time it takes to evaluate the block.} 16 | block [block!] 17 | ][ 18 | start: stats/timer 19 | do block 20 | stats/timer - start 21 | ] 22 | 23 | dp: delta-profile: func [ 24 | {Delta-profile of running a specific block.} 25 | block [block!] 26 | /local start end 27 | ][ 28 | start: values-of stats/profile 29 | do block 30 | end: values-of stats/profile 31 | foreach num start [ 32 | change end end/1 - num 33 | end: next end 34 | ] 35 | start: make system/standard/stats [] 36 | set start head end 37 | start 38 | ] 39 | 40 | speed?: function [ 41 | "Returns approximate speed benchmarks [eval cpu memory file-io]." 42 | /no-io "Skip the I/O test" 43 | /times "Show time for each test" 44 | ][ 45 | result: copy [] 46 | foreach block [ 47 | [ 48 | loop 100'000 [ 49 | ; measure more than just loop func 50 | ; typical load: 1 set, 2 data, 1 op, 4 trivial funcs 51 | x: 1 * index? back next "x" 52 | x: 1 * index? back next "x" 53 | x: 1 * index? back next "x" 54 | x: 1 * index? back next "x" 55 | ] 56 | calc: [100'000 / secs / 100] ; arbitrary calc 57 | ][ 58 | tmp: make binary! 500'000 59 | insert/dup tmp "abcdefghij" 50000 60 | loop 10 [ 61 | random tmp 62 | decompress compress tmp 63 | ] 64 | calc: [(length? tmp) * 10 / secs / 1900] 65 | ][ 66 | repeat n 40 [ 67 | change/dup tmp to-char n 500'000 68 | ] 69 | calc: [(length? tmp) * 40 / secs / 1024 / 1024] 70 | ][ 71 | unless no-io [ 72 | write file: %tmp-junk.txt "" ; force security request before timer 73 | tmp: make string! 32000 * 5 74 | insert/dup tmp "test^/" 32000 75 | loop 100 [ 76 | write file tmp 77 | read file 78 | ] 79 | delete file 80 | calc: [(length? tmp) * 100 * 2 / secs / 1024 / 1024] 81 | ] 82 | ] 83 | ][ 84 | secs: now/precise 85 | calc: 0 86 | recycle 87 | do block 88 | secs: to decimal! difference now/precise secs 89 | append result to integer! do calc 90 | if times [append result secs] 91 | ] 92 | result 93 | ] 94 | -------------------------------------------------------------------------------- /src/mezz/mezz-func.r: -------------------------------------------------------------------------------- 1 | REBOL [ 2 | System: "REBOL [R3] Language Interpreter and Run-time Environment" 3 | Title: "REBOL 3 Mezzanine: Function Helpers" 4 | Rights: { 5 | Copyright 2012 REBOL Technologies 6 | REBOL is a trademark of REBOL Technologies 7 | } 8 | License: { 9 | Licensed under the Apache License, Version 2.0 10 | See: http://www.apache.org/licenses/LICENSE-2.0 11 | } 12 | ] 13 | 14 | clos: func [ 15 | {Defines a closure function.} 16 | spec [block!] {Help string (opt) followed by arg words (and opt type and string)} 17 | body [block!] {The body block of the function} 18 | ][ 19 | make closure! copy/deep reduce [spec body] 20 | ] 21 | 22 | closure: func [ 23 | {Defines a closure function with all set-words as locals.} 24 | spec [block!] {Help string (opt) followed by arg words (and opt type and string)} 25 | body [block!] {The body block of the function} 26 | /with {Define or use a persistent object (self)} 27 | object [object! block! map!] {The object or spec} 28 | /extern words [block!] {These words are not local} 29 | ][ 30 | ; Copy the spec and add /local to the end if not found 31 | unless find spec: copy/deep spec /local [append spec [ 32 | /local ; In a block so the generated source gets the newlines 33 | ]] 34 | ; Make a full copy of the body, to allow reuse of the original 35 | body: copy/deep body 36 | ; Collect all set-words in the body as words to be used as locals, and add 37 | ; them to the spec. Don't include the words already in the spec or object. 38 | insert find/tail spec /local collect-words/deep/set/ignore body either with [ 39 | ; Make our own local object if a premade one is not provided 40 | unless object? object [object: make object! object] 41 | bind body object ; Bind any object words found in the body 42 | ; Ignore the words in the spec and those in the object. The spec needs 43 | ; to be copied since the object words shouldn't be added to the locals. 44 | append append append copy spec 'self words-of object words ; ignore 'self too 45 | ][ 46 | ; Don't include the words in the spec, or any extern words. 47 | either extern [append copy spec words] [spec] 48 | ] 49 | make closure! reduce [spec body] 50 | ] 51 | 52 | has: func [ 53 | {A shortcut to define a function that has local variables but no arguments.} 54 | vars [block!] {List of words that are local to the function} 55 | body [block!] {The body block of the function} 56 | ][ 57 | make function! reduce [head insert copy/deep vars /local copy/deep body] 58 | ] 59 | 60 | context: func [ 61 | {Defines a unique object.} 62 | blk [block!] {Object words and values (modified)} 63 | ][ 64 | make object! blk 65 | ] 66 | 67 | map: func [ 68 | {Make a map value (hashed associative block).} 69 | val 70 | ][ 71 | make map! :val 72 | ] 73 | 74 | task: func [ 75 | {Creates a task.} 76 | spec [block!] {Name or spec block} 77 | body [block!] {The body block of the task} 78 | ][ 79 | make task! copy/deep reduce [spec body] 80 | ] 81 | -------------------------------------------------------------------------------- /src/mezz/mezz-math.r: -------------------------------------------------------------------------------- 1 | REBOL [ 2 | System: "REBOL [R3] Language Interpreter and Run-time Environment" 3 | Title: "REBOL 3 Mezzanine: Math" 4 | Rights: { 5 | Copyright 2012 REBOL Technologies 6 | REBOL is a trademark of REBOL Technologies 7 | } 8 | License: { 9 | Licensed under the Apache License, Version 2.0 10 | See: http://www.apache.org/licenses/LICENSE-2.0 11 | } 12 | ] 13 | 14 | mod: func [ 15 | "Compute a nonnegative remainder of A divided by B." 16 | ; In fact the function tries to find the remainder, 17 | ; that is "almost non-negative" 18 | ; Example: 0.15 - 0.05 - 0.1 // 0.1 is negative, 19 | ; but it is "almost" zero, i.e. "almost non-negative" 20 | [catch] 21 | a [number! money! time!] 22 | b [number! money! time!] "Must be nonzero." 23 | /local r 24 | ] [ 25 | ; Compute the smallest non-negative remainder 26 | all [negative? r: a // b r: r + b] 27 | ; Use abs a for comparisons 28 | a: abs a 29 | ; If r is "almost" b (i.e. negligible compared to b), the 30 | ; result will be r - b. Otherwise the result will be r 31 | either all [a + r = (a + b) positive? r + r - b] [r - b] [r] 32 | ] 33 | 34 | modulo: func [ 35 | {Wrapper for MOD that handles errors like REMAINDER. Negligible values (compared to A and B) are rounded to zero.} 36 | ;[catch] 37 | a [number! money! time!] 38 | b [number! money! time!] "Absolute value will be used" 39 | /local r 40 | ] [ 41 | ; Coerce B to a type compatible with A 42 | any [number? a b: make a b] 43 | ; Get the "accurate" MOD value 44 | r: mod a abs b 45 | ; If the MOD result is "near zero", w.r.t. A and B, 46 | ; return 0--the "expected" result, in human terms. 47 | ; Otherwise, return the result we got from MOD. 48 | either any [a - r = a r + b = b] [make r 0] [r] 49 | ] 50 | 51 | sign?: func [ 52 | "Returns sign of number as 1, 0, or -1 (to use as multiplier)." 53 | number [number! money! time!] 54 | ][ 55 | case [ 56 | positive? number [1] 57 | negative? number [-1] 58 | true [0] 59 | ] 60 | ] 61 | 62 | minimum-of: func [ 63 | {Finds the smallest value in a series} 64 | series [series!] {Series to search} 65 | /skip {Treat the series as records of fixed size} 66 | size [integer!] 67 | /local spot 68 | ][ 69 | size: any [size 1] 70 | if 1 > size [cause-error 'script 'out-of-range size] 71 | spot: series 72 | forskip series size [ 73 | if lesser? first series first spot [spot: series] 74 | ] 75 | spot 76 | ] 77 | 78 | maximum-of: func [ 79 | {Finds the largest value in a series} 80 | series [series!] {Series to search} 81 | /skip {Treat the series as records of fixed size} 82 | size [integer!] 83 | /local spot 84 | ][ 85 | size: any [size 1] 86 | if 1 > size [cause-error 'script 'out-of-range size] 87 | spot: series 88 | forskip series size [ 89 | if greater? first series first spot [spot: series] 90 | ] 91 | spot 92 | ] 93 | -------------------------------------------------------------------------------- /src/mezz/mezz-save.r: -------------------------------------------------------------------------------- 1 | REBOL [ 2 | System: "REBOL [R3] Language Interpreter and Run-time Environment" 3 | Title: "REBOL 3 Mezzanine: Save" 4 | Rights: { 5 | Copyright 2012 REBOL Technologies 6 | REBOL is a trademark of REBOL Technologies 7 | } 8 | License: { 9 | Licensed under the Apache License, Version 2.0 10 | See: http://www.apache.org/licenses/LICENSE-2.0 11 | } 12 | Issues: { 13 | Is MOLD Missing a terminating newline? -CS 14 | Add MOLD/options -CS 15 | } 16 | ] 17 | 18 | mold64: function [ 19 | "Temporary function to mold binary base 64." ; fix the need for this! -CS 20 | data 21 | ][ 22 | base: system/options/binary-base 23 | system/options/binary-base: 64 24 | data: mold :data 25 | system/options/binary-base: :base 26 | data 27 | ] 28 | 29 | save: function [ 30 | {Saves a value, block, or other data to a file, URL, binary, or string.} 31 | where [file! url! binary! string! none!] {Where to save (suffix determines encoding)} 32 | value {Value(s) to save} 33 | /header {Provide a REBOL header block (or output non-code datatypes)} 34 | header-data [block! object! logic!] {Header block, object, or TRUE (header is in value)} 35 | /all {Save in serialized format} 36 | /length {Save the length of the script content in the header} 37 | /compress {Save in a compressed format or not} 38 | method [logic! word!] "true = compressed, false = not, 'script = encoded string" 39 | ][ 40 | ;-- Special datatypes use codecs directly (e.g. PNG image file): 41 | if lib/all [ 42 | not header ; User wants to save value as script, not data file 43 | any [file? where url? where] 44 | type: file-type? where 45 | ][ ; We have a codec: 46 | return write where encode type :value ; will check for valid type 47 | ] 48 | 49 | ;-- Compressed scripts and script lengths require a header: 50 | if any [length method] [ 51 | header: true 52 | header-data: any [header-data []] 53 | ] 54 | 55 | ;-- Handle the header object: 56 | if header-data [ 57 | ; TRUE indicates the header is the first value in the block: 58 | if header-data = true [ 59 | header-data: any [ 60 | lib/all [ 61 | block? :value 62 | first+ value ; the header (do not use TAKE) 63 | ] 64 | [] ; empty header 65 | ] 66 | ] 67 | 68 | ; Make it an object if it's not already (ok to ignore overhead): 69 | header-data: either object? :header-data [ 70 | trim :header-data ; clean out the words set to none 71 | ][ 72 | construct :header-data ; standard/header intentionally not used 73 | ] 74 | 75 | if compress [ ; Make the header option match 76 | case [ 77 | not method [remove find select header-data 'options 'compress] 78 | not block? select header-data 'options [ 79 | repend header-data ['options copy [compress]] 80 | ] 81 | not find header-data/options 'compress [ 82 | append header-data/options 'compress 83 | ] 84 | ] 85 | ] 86 | 87 | if length [ 88 | append header-data [length: #[true]] ; any true? value will work 89 | ] 90 | 91 | unless compress: true? find select header-data 'options 'compress [method: none] 92 | length: true? select header-data 'length 93 | header-data: body-of header-data 94 | ] 95 | 96 | ; (Maybe /all should be the default? See CureCode.) 97 | data: either all [mold/all/only :value] [mold/only :value] 98 | append data newline ; mold does not append a newline? Nope. 99 | 100 | case/all [ 101 | ; Checksum uncompressed data, if requested 102 | tmp: find header-data 'checksum [change next tmp checksum/secure data: to-binary data] 103 | ; Compress the data if necessary 104 | compress [data: lib/compress data] 105 | ; File content is encoded as base-64: 106 | method = 'script [data: mold64 data] 107 | not binary? data [data: to-binary data] 108 | length [change find/tail header-data 'length length? data] 109 | header-data [insert data ajoin ['REBOL #" " mold header-data newline]] 110 | ] 111 | case [ 112 | file? where [write where data] ; WRITE converts to UTF-8, saves overhead 113 | url? where [write where data] ; But some schemes don't support it 114 | none? where [data] ; just return the UTF-8 binary 115 | 'else [insert tail where data] ; string! or binary!, insert data 116 | ] 117 | ] 118 | 119 | #test [ 120 | data: [1 1.2 10:20 "test" user@example.com [sub block]] 121 | probe to string! save none [] 122 | probe to string! save none data 123 | probe to string! save/header none data [title: "my code"] 124 | probe to string! save/compress none [] true 125 | probe to string! save/compress none data true 126 | probe to string! save/compress none data 'script 127 | probe to string! save/header/compress none data [title: "my code"] true 128 | probe to string! save/header/compress none data [title: "my code"] 'script 129 | probe to string! save/header none data [title: "my code" options: [compress]] 130 | probe to string! save/header/compress none data [title: "my code" options: [compress]] none 131 | probe to string! save/header none data [title: "my code" checksum: true] 132 | halt 133 | ; more needed 134 | ] 135 | -------------------------------------------------------------------------------- /src/mezz/mezz-shell.r: -------------------------------------------------------------------------------- 1 | REBOL [ 2 | System: "REBOL [R3] Language Interpreter and Run-time Environment" 3 | Title: "REBOL 3 Mezzanine: Shell-like Command Functions" 4 | Rights: { 5 | Copyright 2012 REBOL Technologies 6 | REBOL is a trademark of REBOL Technologies 7 | } 8 | License: { 9 | Licensed under the Apache License, Version 2.0 10 | See: http://www.apache.org/licenses/LICENSE-2.0 11 | } 12 | ] 13 | 14 | ls: :list-dir 15 | pwd: :what-dir 16 | rm: :delete 17 | mkdir: :make-dir 18 | 19 | cd: func [ 20 | "Change directory (shell shortcut function)." 21 | 'path [file! word! path! unset! string!] "Accepts %file, :variables and just words (as dirs)" 22 | ][ 23 | switch type?/word :path [ 24 | unset! [print what-dir] 25 | file! [change-dir path] 26 | string! [change-dir to-rebol-file path] 27 | word! path! [change-dir to-file path] 28 | ] 29 | ] 30 | 31 | more: func [ 32 | "Print file (shell shortcut function)." 33 | 'file [file! word! path! string!] "Accepts %file and also just words (as file names)" 34 | ][ 35 | print deline to-string read switch type?/word :file [ 36 | file! [file] 37 | string! [to-rebol-file file] 38 | word! path! [to-file file] 39 | ] 40 | ] 41 | -------------------------------------------------------------------------------- /src/mezz/mezz-tail.r: -------------------------------------------------------------------------------- 1 | REBOL [ 2 | System: "REBOL [R3] Language Interpreter and Run-time Environment" 3 | Title: "REBOL 3 Mezzanine: End of Mezz" 4 | Rights: { 5 | Copyright 2012 REBOL Technologies 6 | REBOL is a trademark of REBOL Technologies 7 | } 8 | License: { 9 | Licensed under the Apache License, Version 2.0 10 | See: http://www.apache.org/licenses/LICENSE-2.0 11 | } 12 | ] 13 | 14 | funco: :func ; save it for expert usage 15 | 16 | ; Final FUNC definition: 17 | func: funco [ 18 | {Defines a user function with given spec and body.} 19 | spec [block!] {Help string (opt) followed by arg words (and opt type and string)} 20 | body [block!] {The body block of the function} 21 | ][ 22 | make function! copy/deep reduce [spec body] ; (now it deep copies) 23 | ] 24 | 25 | ; Quick test runner (temporary): 26 | t: does [do %test.r] 27 | -------------------------------------------------------------------------------- /src/mezz/mezz-types.r: -------------------------------------------------------------------------------- 1 | REBOL [ 2 | System: "REBOL [R3] Language Interpreter and Run-time Environment" 3 | Title: "REBOL 3 Mezzanine: To-Type Helpers" 4 | Rights: { 5 | Copyright 2012 REBOL Technologies 6 | REBOL is a trademark of REBOL Technologies 7 | } 8 | License: { 9 | Licensed under the Apache License, Version 2.0 10 | See: http://www.apache.org/licenses/LICENSE-2.0 11 | } 12 | ] 13 | 14 | ; These must be listed now, because there is no longer a global context for mezz functions: 15 | ; Are we sure we really want all these?? -Carl A108 16 | to-logic: to-integer: to-decimal: to-percent: to-money: to-char: to-pair: 17 | to-tuple: to-time: to-date: to-binary: to-string: to-file: to-email: to-url: to-tag: 18 | to-bitset: to-image: to-vector: to-block: to-paren: 19 | to-path: to-set-path: to-get-path: to-lit-path: to-map: to-datatype: to-typeset: 20 | to-word: to-set-word: to-get-word: to-lit-word: to-refinement: to-issue: 21 | to-command: to-closure: to-function: to-object: to-module: to-error: to-port: to-gob: 22 | to-event: 23 | none 24 | 25 | ; Auto-build the functions for the above TO-* words. 26 | use [word] [ 27 | foreach type system/catalog/datatypes [ 28 | ; The list above determines what will be made here: 29 | if in lib word: make word! head remove back tail ajoin ["to-" type] [ 30 | ; Add doc line only if this build has autodocs: 31 | set in lib :word func either string? first spec-of :make [ 32 | reduce [reform ["Converts to" form type "value."] 'value] 33 | ][ 34 | [value] 35 | ] compose [to (type) :value] 36 | ] 37 | ] 38 | ] 39 | -------------------------------------------------------------------------------- /src/mezz/sys-codec.r: -------------------------------------------------------------------------------- 1 | REBOL [ 2 | System: "REBOL [R3] Language Interpreter and Run-time Environment" 3 | Title: "REBOL 3 Boot Sys: Encoder and Decoder" 4 | Rights: { 5 | Copyright 2012 REBOL Technologies 6 | REBOL is a trademark of REBOL Technologies 7 | } 8 | License: { 9 | Licensed under the Apache License, Version 2.0 10 | See: http://www.apache.org/licenses/LICENSE-2.0 11 | } 12 | Context: sys 13 | Note: { 14 | The boot binding of this module is SYS then LIB deep. 15 | Any non-local words not found in those contexts WILL BE 16 | UNBOUND and will error out at runtime! 17 | } 18 | ] 19 | 20 | decode: function [ 21 | {Decodes a series of bytes into the related datatype (e.g. image!).} 22 | type [word!] {Media type (jpeg, png, etc.)} 23 | data [binary!] {The data to decode} 24 | ][ 25 | unless all [ 26 | cod: select system/codecs type 27 | data: do-codec cod/entry 'decode data 28 | ][ 29 | cause-error 'access 'no-codec type 30 | ] 31 | data 32 | ] 33 | 34 | encode: function [ 35 | {Encodes a datatype (e.g. image!) into a series of bytes.} 36 | type [word!] {Media type (jpeg, png, etc.)} 37 | data [image! binary! string!] {The data to encode} 38 | /options opts [block!] {Special encoding options} 39 | ][ 40 | unless all [ 41 | cod: select system/codecs type 42 | data: do-codec cod/entry 'encode data 43 | ][ 44 | cause-error 'access 'no-codec type 45 | ] 46 | data 47 | ] 48 | 49 | encoding?: function [ 50 | "Returns the media codec name for given binary data. (identify)" 51 | data [binary!] 52 | ][ 53 | foreach [name codec] system/codecs [ 54 | if do-codec codec/entry 'identify data [ 55 | return name 56 | ] 57 | ] 58 | none 59 | ] 60 | 61 | export [decode encode encoding?] 62 | -------------------------------------------------------------------------------- /src/os/posix/dev-event.c: -------------------------------------------------------------------------------- 1 | /*********************************************************************** 2 | ** 3 | ** REBOL [R3] Language Interpreter and Run-time Environment 4 | ** 5 | ** Copyright 2012 REBOL Technologies 6 | ** REBOL is a trademark of REBOL Technologies 7 | ** 8 | ** Licensed under the Apache License, Version 2.0 (the "License"); 9 | ** you may not use this file except in compliance with the License. 10 | ** You may obtain a copy of the License at 11 | ** 12 | ** http://www.apache.org/licenses/LICENSE-2.0 13 | ** 14 | ** Unless required by applicable law or agreed to in writing, software 15 | ** distributed under the License is distributed on an "AS IS" BASIS, 16 | ** WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 17 | ** See the License for the specific language governing permissions and 18 | ** limitations under the License. 19 | ** 20 | ************************************************************************ 21 | ** 22 | ** Title: Device: Event handler for Win32 23 | ** Author: Carl Sassenrath 24 | ** Purpose: 25 | ** Processes events to pass to REBOL. Note that events are 26 | ** used for more than just windowing. 27 | ** 28 | ************************************************************************ 29 | ** 30 | ** NOTE to PROGRAMMERS: 31 | ** 32 | ** 1. Keep code clear and simple. 33 | ** 2. Document unusual code, reasoning, or gotchas. 34 | ** 3. Use same style for code, vars, indent(4), comments, etc. 35 | ** 4. Keep in mind Linux, OS X, BSD, big/little endian CPUs. 36 | ** 5. Test everything, then test it again. 37 | ** 38 | ***********************************************************************/ 39 | 40 | #include 41 | #include 42 | #include 43 | #include 44 | 45 | #include "reb-host.h" 46 | #include "host-lib.h" 47 | 48 | void Done_Device(int handle, int error); 49 | 50 | /*********************************************************************** 51 | ** 52 | */ DEVICE_CMD Init_Events(REBREQ *dr) 53 | /* 54 | ** Initialize the event device. 55 | ** 56 | ** Create a hidden window to handle special events, 57 | ** such as timers and async DNS. 58 | ** 59 | ***********************************************************************/ 60 | { 61 | REBDEV *dev = (REBDEV*)dr; // just to keep compiler happy 62 | SET_FLAG(dev->flags, RDF_INIT); 63 | return DR_DONE; 64 | } 65 | 66 | 67 | /*********************************************************************** 68 | ** 69 | */ DEVICE_CMD Poll_Events(REBREQ *req) 70 | /* 71 | ** Poll for events and process them. 72 | ** Returns 1 if event found, else 0. 73 | ** 74 | ** MS Notes: 75 | ** 76 | ** "The PeekMessage function normally does not remove WM_PAINT 77 | ** messages from the queue. WM_PAINT messages remain in the queue 78 | ** until they are processed." 79 | ** 80 | ***********************************************************************/ 81 | { 82 | int flag = DR_DONE; 83 | return flag; // different meaning compared to most commands 84 | } 85 | 86 | 87 | /*********************************************************************** 88 | ** 89 | */ DEVICE_CMD Query_Events(REBREQ *req) 90 | /* 91 | ** Wait for an event, or a timeout (in milliseconds) specified by 92 | ** req->length. The latter is used by WAIT as the main timing 93 | ** method. 94 | ** 95 | ***********************************************************************/ 96 | { 97 | struct timeval tv; 98 | int result; 99 | 100 | tv.tv_sec = 0; 101 | tv.tv_usec = req->length * 1000; 102 | //printf("usec %d\n", tv.tv_usec); 103 | 104 | result = select(0, 0, 0, 0, &tv); 105 | if (result < 0) { 106 | // !!! set error code 107 | printf("ERROR!!!!\n"); 108 | return DR_ERROR; 109 | } 110 | 111 | return DR_DONE; 112 | } 113 | 114 | 115 | /*********************************************************************** 116 | ** 117 | */ DEVICE_CMD Connect_Events(REBREQ *req) 118 | /* 119 | ** Simply keeps the request pending for polling purposes. 120 | ** Use Abort_Device to remove it. 121 | ** 122 | ***********************************************************************/ 123 | { 124 | return DR_PEND; // keep pending 125 | } 126 | 127 | 128 | /*********************************************************************** 129 | ** 130 | ** Command Dispatch Table (RDC_ enum order) 131 | ** 132 | ***********************************************************************/ 133 | 134 | static DEVICE_CMD_FUNC Dev_Cmds[RDC_MAX] = { 135 | Init_Events, // init device driver resources 136 | 0, // RDC_QUIT, // cleanup device driver resources 137 | 0, // RDC_OPEN, // open device unit (port) 138 | 0, // RDC_CLOSE, // close device unit 139 | 0, // RDC_READ, // read from unit 140 | 0, // RDC_WRITE, // write to unit 141 | Poll_Events, 142 | Connect_Events, 143 | Query_Events, 144 | }; 145 | 146 | DEFINE_DEV(Dev_Event, "OS Events", 1, Dev_Cmds, RDC_MAX, 0); 147 | -------------------------------------------------------------------------------- /src/os/win32/rpic-test.c: -------------------------------------------------------------------------------- 1 | /*********************************************************************** 2 | ** 3 | ** REBOL [R3] Language Interpreter and Run-time Environment 4 | ** 5 | ** Copyright 2012 REBOL Technologies 6 | ** REBOL is a trademark of REBOL Technologies 7 | ** 8 | ** Licensed under the Apache License, Version 2.0 (the "License"); 9 | ** you may not use this file except in compliance with the License. 10 | ** You may obtain a copy of the License at 11 | ** 12 | ** http://www.apache.org/licenses/LICENSE-2.0 13 | ** 14 | ** Unless required by applicable law or agreed to in writing, software 15 | ** distributed under the License is distributed on an "AS IS" BASIS, 16 | ** WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 17 | ** See the License for the specific language governing permissions and 18 | ** limitations under the License. 19 | ** 20 | ************************************************************************ 21 | ** 22 | ** rpic-test.c - Test for REBOL Plug-In Component 23 | ** 24 | ***********************************************************************/ 25 | 26 | //#include 27 | 28 | #define ODD_INT_64 29 | 30 | #include "reb-c.h" 31 | #include "reb-plugin.h" 32 | #include "plugin-types.h" 33 | 34 | #define REBSER void 35 | #include "rpi-lib.h" 36 | 37 | const char *init_block = 38 | "REBOL [\n" 39 | "Title: {Example plugin}\n" 40 | "Name: example\n" 41 | "Type: plugin\n" 42 | "Exports: [map-words cmd1 cmd2 cmd2i cmd2d cmdw cmds cmdb cmdbl]\n" 43 | "]\n" 44 | "map-words: command [words [block!]]\n" 45 | "cmd1: command [a]\n" 46 | "cmd2: command [a b]\n" 47 | "cmd2i: command [a [integer!] b [integer!]]\n" 48 | "cmd2d: command [a [decimal!] b [decimal!]]\n" 49 | "cmdw: command [w]\n" 50 | "cmds: command [str [string!] index [integer!]]\n" 51 | "cmdb: command [blk [block!] index [integer!]]\n" 52 | "cmdbl: command [blk [block!]]\n" 53 | ; 54 | 55 | RPIEXT const char *RPI_Init(int opts, RPILIB *lib) { 56 | RPI = lib; 57 | if (lib->version == RPI_VERSION) return init_block; 58 | return 0; 59 | } 60 | 61 | RPIEXT int RPI_Quit(int opts) { 62 | return 0; 63 | } 64 | 65 | u32 *word_ids = 0; 66 | 67 | RPIEXT int RPI_Call(int cmd, RPIFRM *frm) { 68 | switch (cmd) { 69 | case 0: 70 | word_ids = RPI_MAP_WORDS(RPA_SERIES(frm,1)); 71 | return RPR_TRUE; 72 | case 1: 73 | RPA_INT64(frm,1) = -RPA_INT64(frm,1); 74 | break; 75 | case 2: 76 | case 3: 77 | RPA_INT64(frm,1) = RPA_INT64(frm, 1) + RPA_INT64(frm, 2); 78 | break; 79 | case 4: 80 | RPA_DEC64(frm,1) = RPA_DEC64(frm, 1) + RPA_DEC64(frm, 2); 81 | break; 82 | case 5: 83 | RPA_INT64(frm,1) = RPI_FIND_WORD(word_ids, RPA_WORD(frm,1)); 84 | RPA_TYPE(frm,1) = RPT_INTEGER; 85 | break; 86 | case 6: 87 | RPA_INT64(frm,1) = RPI_GET_CHAR(RPA_SERIES(frm,1), (u32)RPA_INT64(frm,2)-1); 88 | RPA_TYPE(frm,1) = RPT_INTEGER; 89 | break; 90 | case 7: 91 | RPA_TYPE(frm,1) = RPI_GET_VALUE(RPA_SERIES(frm,1), (u32)RPA_INT64(frm,2)-1, &RPA_ARG(frm, 1)); 92 | break; 93 | case 8: 94 | RPA_INT64(frm,1) = RPI_SERIES_INFO(RPA_SERIES(frm,1), RPI_INFO_TAIL); 95 | RPA_TYPE(frm,1) = RPT_INTEGER; 96 | break; 97 | } 98 | return RPR_VALUE; 99 | } 100 | -------------------------------------------------------------------------------- /src/tools/file-base.r: -------------------------------------------------------------------------------- 1 | REBOL [ 2 | System: "REBOL [R3] Language Interpreter and Run-time Environment" 3 | Title: "Source File Database" 4 | Rights: { 5 | Copyright 2012 REBOL Technologies 6 | REBOL is a trademark of REBOL Technologies 7 | } 8 | License: { 9 | Licensed under the Apache License, Version 2.0 10 | See: http://www.apache.org/licenses/LICENSE-2.0 11 | } 12 | Author: "Carl Sassenrath" 13 | Purpose: { 14 | Lists of files used for creating makefiles. 15 | } 16 | ] 17 | 18 | core: [ 19 | a-constants.c 20 | a-globals.c 21 | a-lib.c 22 | b-boot.c 23 | b-init.c 24 | c-do.c 25 | c-error.c 26 | c-frame.c 27 | c-function.c 28 | c-port.c 29 | c-task.c 30 | c-word.c 31 | d-crash.c 32 | d-dump.c 33 | d-print.c 34 | f-blocks.c 35 | f-deci.c 36 | f-dtoa.c 37 | f-enbase.c 38 | f-extension.c 39 | f-math.c 40 | f-modify.c 41 | f-qsort.c 42 | f-random.c 43 | f-round.c 44 | f-series.c 45 | f-stubs.c 46 | l-scan.c 47 | l-types.c 48 | m-gc.c 49 | m-pools.c 50 | m-series.c 51 | n-control.c 52 | n-data.c 53 | n-io.c 54 | n-loop.c 55 | n-math.c 56 | n-sets.c 57 | n-strings.c 58 | n-system.c 59 | p-clipboard.c 60 | p-console.c 61 | p-dir.c 62 | p-dns.c 63 | p-event.c 64 | p-file.c 65 | p-net.c 66 | s-cases.c 67 | s-crc.c 68 | s-file.c 69 | s-find.c 70 | s-make.c 71 | s-mold.c 72 | s-ops.c 73 | s-trim.c 74 | s-unicode.c 75 | t-bitset.c 76 | t-block.c 77 | t-char.c 78 | t-datatype.c 79 | t-date.c 80 | t-decimal.c 81 | t-event.c 82 | t-function.c 83 | t-gob.c 84 | t-image.c 85 | t-integer.c 86 | t-logic.c 87 | t-map.c 88 | t-money.c 89 | t-none.c 90 | t-object.c 91 | t-pair.c 92 | t-port.c 93 | t-string.c 94 | t-time.c 95 | t-tuple.c 96 | t-typeset.c 97 | t-utype.c 98 | t-vector.c 99 | t-word.c 100 | u-bmp.c 101 | u-compress.c 102 | u-dialect.c 103 | u-gif.c 104 | u-jpg.c 105 | u-md5.c 106 | u-parse.c 107 | u-png.c 108 | u-sha1.c 109 | u-zlib.c 110 | ] 111 | 112 | made: [ 113 | make-boot.r core/b-boot.c 114 | make-headers.r include/tmp-funcs.h 115 | make-host-ext.r include/host-ext-graphics.h 116 | make-host-init.r include/host-init.h 117 | make-os-ext.r include/host-lib.h 118 | make-reb-lib.r include/reb-lib.h 119 | ] 120 | 121 | os: [ 122 | host-main.c 123 | host-args.c 124 | host-device.c 125 | host-stdio.c 126 | dev-net.c 127 | dev-dns.c 128 | ] 129 | 130 | os-win32: [ 131 | host-lib.c 132 | dev-stdio.c 133 | dev-file.c 134 | dev-event.c 135 | dev-clipboard.c 136 | ] 137 | 138 | os-win32g: [ 139 | host-graphics.c 140 | host-event.c 141 | host-window.c 142 | host-draw.c 143 | host-text.c 144 | ] 145 | 146 | os-posix: [ 147 | host-lib.c 148 | host-readline.c 149 | dev-stdio.c 150 | dev-event.c 151 | dev-file.c 152 | ] 153 | 154 | boot-files: [ 155 | version.r 156 | graphics.r 157 | draw.r 158 | shape.r 159 | text.r 160 | ] 161 | 162 | mezz-files: [ 163 | ; prot-http.r 164 | ; view-colors.r 165 | view-funcs.r 166 | ] 167 | 168 | agg-files: [ 169 | agg_arc.cpp 170 | agg_arrowhead.cpp 171 | agg_bezier_arc.cpp 172 | agg_bspline.cpp 173 | agg_curves.cpp 174 | agg_image_filters.cpp 175 | agg_line_aa_basics.cpp 176 | agg_path_storage.cpp 177 | agg_rasterizer_scanline_aa.cpp 178 | agg_rounded_rect.cpp 179 | agg_sqrt_tables.cpp 180 | agg_trans_affine.cpp 181 | agg_trans_single_path.cpp 182 | agg_vcgen_bspline.cpp 183 | agg_vcgen_contour.cpp 184 | agg_vcgen_dash.cpp 185 | agg_vcgen_markers_term.cpp 186 | agg_vcgen_smooth_poly1.cpp 187 | agg_vcgen_stroke.cpp 188 | agg_vpgen_segmentator.cpp 189 | agg_compo.cpp 190 | agg_graphics.cpp 191 | ; agg_font_freetype.cpp 192 | agg_font_win32_tt.cpp 193 | agg_truetype_text.cpp 194 | ; agg_effects.cpp 195 | compositor.cpp 196 | graphics.cpp 197 | rich_text.cpp 198 | ] 199 | 200 | tools: [ 201 | make-host-init.r 202 | make-host-ext.r 203 | form-header.r 204 | ] 205 | 206 | -------------------------------------------------------------------------------- /src/tools/form-header.r: -------------------------------------------------------------------------------- 1 | REBOL [ 2 | System: "REBOL [R3] Language Interpreter and Run-time Environment" 3 | Title: "Standard source code header" 4 | Rights: { 5 | Copyright 2012 REBOL Technologies 6 | REBOL is a trademark of REBOL Technologies 7 | } 8 | License: { 9 | Licensed under the Apache License, Version 2.0 10 | See: http://www.apache.org/licenses/LICENSE-2.0 11 | } 12 | Author: "Carl Sassenrath" 13 | ] 14 | 15 | bv: load %../boot/version.r 16 | 17 | form-header: func [title [string!] file [file!] /gen by] [ 18 | print ["..." title] 19 | by: either gen [ 20 | rejoin [{** AUTO-GENERATED FILE - Do not modify. (From: } by {)^/**^/}] 21 | ][""] 22 | 23 | rejoin [ 24 | {/*********************************************************************** 25 | ** 26 | ** REBOL [R3] Language Interpreter and Run-time Environment 27 | ** Copyright 2012 REBOL Technologies 28 | ** REBOL is a trademark of REBOL Technologies 29 | ** Licensed under the Apache License, Version 2.0 30 | ** This is a code-generated file. 31 | ** 32 | ************************************************************************ 33 | ** 34 | ** Title: } title { 35 | ** Build: A} bv/3 { 36 | ** Date: } now/date { 37 | ** File: } file { 38 | ** 39 | } by 40 | {***********************************************************************/ 41 | 42 | } 43 | ] 44 | ] 45 | -------------------------------------------------------------------------------- /src/tools/make-host-ext.r: -------------------------------------------------------------------------------- 1 | REBOL [ 2 | System: "REBOL [R3] Language Interpreter and Run-time Environment" 3 | Title: "Build REBOL 3.0 boot extension module" 4 | Rights: { 5 | Copyright 2012 REBOL Technologies 6 | REBOL is a trademark of REBOL Technologies 7 | } 8 | License: { 9 | Licensed under the Apache License, Version 2.0 10 | See: http://www.apache.org/licenses/LICENSE-2.0 11 | } 12 | Author: "Carl Sassenrath" 13 | Needs: 2.100.100 14 | Purpose: { 15 | Collects host-kit extension modules and writes them out 16 | to a .h file in a compilable data format. 17 | } 18 | ] 19 | 20 | print "--- Make Host Boot Extension ---" 21 | 22 | secure none 23 | do %form-header.r 24 | 25 | ;-- Conversion to C strings, depending on compiler --------------------------- 26 | 27 | to-cstr: either system/version/4 = 3 [ 28 | ; Windows format: 29 | func [str /local out] [ 30 | out: make string! 4 * (length? str) 31 | out: insert out tab 32 | forall str [ 33 | out: insert out reduce [to-integer first str ", "] 34 | if zero? ((index? str) // 10) [out: insert out "^/^-"] 35 | ] 36 | ;remove/part out either (pick out -1) = #" " [-2][-4] 37 | head out 38 | ] 39 | ][ 40 | ; Other formats (Linux, OpenBSD, etc.): 41 | func [str /local out data] [ 42 | out: make string! 4 * (length? str) 43 | forall str [ 44 | data: copy/part str 16 45 | str: skip str 15 46 | data: enbase/base data 16 47 | forall data [ 48 | insert data "\x" 49 | data: skip data 3 50 | ] 51 | data: tail data 52 | insert data {"^/} 53 | append out {"} 54 | append out head data 55 | ] 56 | head out 57 | ] 58 | ] 59 | 60 | ;-- Collect Sources ---------------------------------------------------------- 61 | 62 | collect-files: func [ 63 | "Collect contents of several source files and return combined with header." 64 | files [block!] 65 | /local source data header 66 | ][ 67 | source: make block! 1000 68 | 69 | foreach file files [ 70 | data: load/all file 71 | remove-each [a b] data [issue? a] ; commented sections 72 | unless block? header: find data 'rebol [ 73 | print ["Missing header in:" file] halt 74 | ] 75 | unless empty? source [data: next next data] ; first one includes header 76 | append source data 77 | ] 78 | 79 | source 80 | ] 81 | 82 | ;-- Emit Functions ----------------------------------------------------------- 83 | 84 | out: make string! 10000 85 | emit: func [d] [repend out d] 86 | 87 | emit-cmt: func [text] [ 88 | emit [ 89 | {/*********************************************************************** 90 | ** 91 | ** } text { 92 | ** 93 | ***********************************************************************/ 94 | 95 | }] 96 | ] 97 | 98 | form-name: func [word] [ 99 | uppercase replace/all replace/all to-string word #"-" #"_" #"?" #"Q" 100 | ] 101 | 102 | emit-file: func [ 103 | "Emit command enum and source script code." 104 | file [file!] 105 | source [block!] 106 | /local title name data exports words src prefix 107 | ][ 108 | source: collect-files source 109 | 110 | title: select source/2 to-set-word 'title 111 | name: form select source/2 to-set-word 'name 112 | replace/all name "-" "_" 113 | prefix: uppercase copy name 114 | 115 | clear out 116 | emit form-header/gen title second split-path file %make-host-ext.r 117 | 118 | emit ["enum " name "_commands {^/"] 119 | 120 | ; Gather exported words if exports field is a block: 121 | words: make block! 100 122 | src: source 123 | while [src: find src set-word!] [ 124 | if find [command func function funct] src/2 [ 125 | append words to-word src/1 126 | ] 127 | src: next src 128 | ] 129 | 130 | if block? exports: select second source to-set-word 'exports [ 131 | insert exports words 132 | ] 133 | 134 | foreach word words [emit [tab "CMD_" prefix #"_" replace/all form-name word "'" "_LIT" ",^/"]] 135 | emit "};^/^/" 136 | 137 | if src: select source to-set-word 'words [ 138 | emit ["enum " name "_words {^/"] 139 | emit [tab "W_" prefix "_0,^/"] 140 | foreach word src [emit [tab "W_" prefix #"_" form-name word ",^/"]] 141 | emit "};^/^/" 142 | ] 143 | 144 | emit "#ifdef INCLUDE_EXT_DATA^/" 145 | data: append trim/head mold/only/flat source newline 146 | append data to-char 0 ; null terminator may be required 147 | emit ["const unsigned char RX_" name "[] = {^/" to-cstr data "^/};^/^/"] 148 | emit "#endif^/" 149 | 150 | write rejoin [%../include/ file %.h] out 151 | 152 | ; clear out 153 | ; emit form-header/gen join title " - Module Initialization" second split-path file %make-host-ext.r 154 | ; write rejoin [%../os/ file %.c] out 155 | ] 156 | 157 | ;-- Create Files ------------------------------------------------------------- 158 | 159 | emit-file %host-ext-graphics [ 160 | %../boot/graphics.r 161 | %../mezz/view-funcs.r 162 | ] 163 | 164 | emit-file %host-ext-draw [ 165 | %../boot/draw.r 166 | ] 167 | 168 | emit-file %host-ext-shape [ 169 | %../boot/shape.r 170 | ] 171 | 172 | emit-file %host-ext-text [ 173 | %../boot/text.r 174 | ] 175 | 176 | print " " 177 | -------------------------------------------------------------------------------- /src/tools/make-os-ext.r: -------------------------------------------------------------------------------- 1 | REBOL [ 2 | System: "REBOL [R3] Language Interpreter and Run-time Environment" 3 | Title: "Generate OS host API headers" 4 | Rights: { 5 | Copyright 2012 REBOL Technologies 6 | REBOL is a trademark of REBOL Technologies 7 | } 8 | License: { 9 | Licensed under the Apache License, Version 2.0 10 | See: http://www.apache.org/licenses/LICENSE-2.0 11 | } 12 | Author: "Carl Sassenrath" 13 | Needs: 2.100.100 14 | ] 15 | 16 | verbose: false 17 | 18 | version: load %../boot/version.r 19 | 20 | lib-version: version/3 21 | print ["--- Make OS Ext Lib --- Version:" lib-version] 22 | 23 | ; Set platform TARGET 24 | do %systems.r 25 | target: config-system/os-dir 26 | 27 | do %form-header.r 28 | 29 | change-dir append %../os/ target 30 | 31 | files: [ 32 | %host-lib.c 33 | %../host-device.c 34 | ] 35 | 36 | ; If it is graphics enabled: 37 | if all [ 38 | not find any [system/options/args []] "no-gfx" 39 | find [3] system/version/4 40 | ][ 41 | append files [%host-window.c] 42 | ] 43 | 44 | cnt: 0 45 | 46 | xlib: make string! 20000 47 | rlib: make string! 1000 48 | mlib: make string! 1000 49 | dlib: make string! 1000 50 | xsum: make string! 1000 51 | 52 | emit: func [d] [append repend xlib d newline] 53 | remit: func [d] [append repend rlib d newline] 54 | demit: func [d] [append repend dlib d newline] 55 | memit: func [d /nol] [ 56 | repend mlib d 57 | if not nol [append mlib newline] 58 | ] 59 | 60 | count: func [s c /local n] [ 61 | if find ["()" "(void)"] s [return "()"] 62 | out: copy "(a" 63 | n: 1 64 | while [s: find/tail s c][ 65 | repend out [#"," #"a" + n] 66 | n: n + 1 67 | ] 68 | append out ")" 69 | ] 70 | 71 | pads: func [start col] [ 72 | col: col - offset? start tail start 73 | head insert/dup clear "" #" " col 74 | ] 75 | 76 | func-header: [ 77 | [ 78 | thru "/***" 10 100 "*" newline 79 | thru "*/" 80 | copy spec to newline 81 | (if all [ 82 | spec 83 | trim spec 84 | not find spec "static" 85 | fn: find spec "OS_" 86 | find spec #"(" 87 | ][ 88 | emit ["extern " spec "; // " the-file] 89 | append xsum spec 90 | p1: copy/part spec fn 91 | p3: find fn #"(" 92 | p2: copy/part fn p3 93 | p2u: uppercase copy p2 94 | p2l: lowercase copy p2 95 | demit [tab p2 ","] 96 | remit [tab p1 "(*" p2l ")" p3 ";"] 97 | args: count p3 #"," 98 | m: tail mlib 99 | memit/nol ["#define " p2u args] 100 | memit [pads m 35 " Host_Lib->" p2l args] 101 | cnt: cnt + 1 102 | ] 103 | ) 104 | newline 105 | [ 106 | "/*" ; must be in func header section, not file banner 107 | any [ 108 | thru "**" 109 | [#" " | #"^-"] 110 | copy line thru newline 111 | ] 112 | thru "*/" 113 | | 114 | none 115 | ] 116 | ] 117 | ] 118 | 119 | process: func [file] [ 120 | if verbose [?? file] 121 | data: read the-file: file 122 | data: to-string data ; R3 123 | parse/all data [ 124 | any func-header 125 | ] 126 | ] 127 | 128 | ;process %mem_string.c halt 129 | 130 | remit { 131 | typedef struct REBOL_Host_Lib ^{ 132 | int size; 133 | unsigned int ver_sum; 134 | REBDEV **devices;} 135 | 136 | memit { 137 | extern REBOL_HOST_LIB *Host_Lib; 138 | } 139 | 140 | foreach file files [ 141 | print ["scanning" file] 142 | if all [ 143 | %.c = suffix? file 144 | ][process file] 145 | ] 146 | 147 | remit "} REBOL_HOST_LIB;" 148 | 149 | out: reduce [ 150 | form-header/gen "Host Access Library" %host-lib.h %make-os-ext.r 151 | { 152 | #define HOST_LIB_VER } lib-version { 153 | #define HOST_LIB_SUM } checksum/tcp to-binary xsum { 154 | #define HOST_LIB_SIZE } cnt { 155 | 156 | extern REBDEV *Devices[]; 157 | } 158 | rlib 159 | { 160 | //** Included by HOST ********************************************* 161 | 162 | #ifndef REB_DEF 163 | 164 | } 165 | xlib 166 | { 167 | #ifdef OS_LIB_TABLE 168 | 169 | REBOL_HOST_LIB *Host_Lib; 170 | 171 | REBOL_HOST_LIB Host_Lib_Init = ^{ // Host library function vector table. 172 | HOST_LIB_SIZE, 173 | (HOST_LIB_VER << 16) + HOST_LIB_SUM, 174 | (REBDEV**)&Devices, 175 | } 176 | dlib 177 | {^}; 178 | 179 | #endif //OS_LIB_TABLE 180 | 181 | #else //REB_DEF 182 | 183 | //** Included by REBOL ******************************************** 184 | } 185 | mlib 186 | { 187 | #endif //REB_DEF 188 | } 189 | ] 190 | 191 | ;print out ;halt 192 | ;print ['checksum checksum/tcp xsum] 193 | write %../../include/host-lib.h out 194 | ;ask "Done" 195 | print " " 196 | -------------------------------------------------------------------------------- /src/tools/systems.r: -------------------------------------------------------------------------------- 1 | REBOL [ 2 | System: "REBOL [R3] Language Interpreter and Run-time Environment" 3 | Title: "System build targets" 4 | Rights: { 5 | Copyright 2012 REBOL Technologies 6 | REBOL is a trademark of REBOL Technologies 7 | } 8 | License: { 9 | Licensed under the Apache License, Version 2.0 10 | See: http://www.apache.org/licenses/LICENSE-2.0 11 | } 12 | Author: "Carl Sassenrath" 13 | Purpose: { 14 | These are the target system definitions used to build REBOL 15 | with a variety of compilers and libraries. I prefer to keep it 16 | simple like this rather than using a complex configuration tool 17 | that could make it difficult to support REBOL on older platforms. 18 | } 19 | ] 20 | 21 | systems: [ 22 | [plat os-name os-base build-flags] 23 | [0.1.03 "amiga" posix [HID NPS +SC CMT COP -SP -LM]] 24 | [0.2.04 "osx" posix [+OS NCM -LM]] ; no shared lib possible 25 | [0.2.05 "osxi" posix [ARC +O1 NPS PIC NCM HID STX -LM]] 26 | [0.2.40 "osx_x64" posix [+O1 NPS PIC NCM HID STX -LM]] 27 | [0.3.01 "win32" win32 [+O2 UNI W32 CON S4M EXE DIR -LM]] 28 | ; platform 0.3.40 is reserved for win32-x64 29 | [0.4.02 "linux" posix [+O2 LDL ST1 -LM]] ; libc 2.3 30 | [0.4.03 "linux" posix [+O2 HID LDL ST1 -LM]] ; libc 2.5 31 | [0.4.04 "linux" posix [+O2 HID LDL ST1 M32 -LM]] ; libc 2.11 32 | [0.4.10 "linux_ppc" posix [+O1 HID LDL ST1 -LM]] 33 | [0.4.20 "linux_arm" posix [+O2 HID LDL ST1 -LM]] 34 | [0.4.21 "linux_arm" posix [+O2 HID LDL ST1 -LM PIE]] ; bionic (Android) 35 | [0.4.30 "linux_mips" posix [+O2 HID LDL ST1 -LM]] 36 | [0.4.40 "linux_x64" posix [+O2 HID LDL ST1 -LM]] 37 | [0.5.75 "haiku" posix [+O2 ST1 NWK]] 38 | [0.7.02 "freebsd" posix [+O1 ST1 -LM]] 39 | [0.7.40 "freebsd_x64" posix [+O1 ST1 -LM]] 40 | [0.9.04 "openbsd" posix [+O1 ST1 -LM]] 41 | [0.13.01 "android_arm" android [HID F64 LDL LLOG -LM CST]] 42 | ] 43 | 44 | compile-flags: [ 45 | +OS: "-Os" ; size optimize 46 | +O1: "-O1" ; full optimize 47 | +O2: "-O2" ; full optimize 48 | UNI: "-DUNICODE" ; win32 wants it 49 | CST: "-DCUSTOM_STARTUP" ; include custom startup script at host boot 50 | HID: "-fvisibility=hidden" ; all syms are hidden 51 | F64: "-D_FILE_OFFSET_BITS=64" ; allow larger files 52 | NPS: "-Wno-pointer-sign" ; OSX fix 53 | NSP: "-fno-stack-protector" ; avoid insert of functions names 54 | PIC: "-fPIC" ; position independent (used for libs) 55 | PIE: "-fPIE" ; position independent (executables) 56 | DYN: "-dynamic" ; optimize for dll?? 57 | NCM: "-fno-common" ; lib cannot have common vars 58 | PAK: "-fpack-struct" ; pack structures 59 | ARC: "-arch i386" ; x86 32 bit architecture (OSX) 60 | M32: "-m32" ; use 32-bit memory model 61 | ] 62 | 63 | linker-flags: [ 64 | MAP: "-Wl,-M" ; output a map 65 | STA: "--strip-all" 66 | LDL: "-ldl" ; link with dynamic lib lib 67 | LLOG: "-llog" ; on Android, link with liblog.so 68 | ARC: "-arch i386" ; x86 32 bit architecture (OSX) 69 | M32: "-m32" ; use 32-bit memory model (Linux x64) 70 | W32: "-lwsock32 -lcomdlg32" 71 | WIN: "-mwindows" ; build as Windows GUI binary 72 | CON: "-mconsole" ; build as Windows Console binary 73 | S4M: "-Wl,--stack=4194300" 74 | -LM: "-lm" ; HaikuOS has math in libroot, for instance 75 | NWK: "-lnetwork" ; Needed by HaikuOS 76 | ] 77 | 78 | other-flags: [ 79 | +SC: "" ; has smart console 80 | -SP: "" ; non standard paths 81 | COP: "" ; use COPY as cp program 82 | DIR: "" ; use DIR as ls program 83 | ST1: "-s" ; strip flags... 84 | STX: "-x" 85 | ST2: "-S -x -X" 86 | CMT: "-R.comment" 87 | EXE: "" ; use %.exe as binary file suffix 88 | ] 89 | 90 | config-system: func [ 91 | "Return build configuration information" 92 | /fields "record variables" 93 | /define "the TO_TARGET define name" 94 | /os-dir "the %osname/ directory" 95 | /platform v [tuple!] 96 | ][ 97 | if fields [return first systems] 98 | v: any [v to tuple! reduce [0 system/version/4 system/version/5]] 99 | foreach rec next systems [ 100 | if rec/1 = v [ 101 | if os-dir [return dirize to-file rec/3] 102 | if define [return to-word uppercase join "TO_" rec/2] 103 | return rec 104 | ] 105 | ] 106 | none 107 | ] 108 | --------------------------------------------------------------------------------