Skip to content

Commit

Permalink
REPL preliminary release
Browse files Browse the repository at this point in the history
FEAT: added Red interpreter
FEAT: added temporary tokenizer
FEAT: added %console.red script
FEAT: added DO and LOAD natives
FEAT: added actions jump table and runtime registration support
FEAT: added natives jump table and runtime registration support
FEAT: now actions, natives and functions store a pointer to their compiled version in their value slot.
FEAT: added "load-in" internal constructor
FEAT: added `dump-symbols` debugging function for dumping global context content

FIX: several context! internal bugs
FIX: string/rs-head was not taking account of string offset
FIX: fixed volative UTF-8 symbols buffer issues by duplicating them on creation

Current limitations:
------------------

Tokenizer: temporary implementation, will be upgraded soon.
    - Latin-1 only input (no Unicode support)
    - supports: integer!, block!, word!, lit-word!, get-word!, set-word!, string!, paren!
    - no support for negative integers
    - no paths support

Interpreter:
    - able to evaluate all predefined actions, natives and functions.
    - intrinsic natives not supported (includes:
	if unless either any all while until loop repeat
	foreach forall break halt func function does has
	exit return switch case routine
    )
    - refinements not supported
    - path notation not supported
    - simple infix notation supported
    - chained infix partially supported (mix of math ops and comparison not working)

Console:
    - Windows only
    - relies on command.com for features like editing and history
    - Latin-1 only, no Unicode support (limitation of the tokenizer)
  • Loading branch information
dockimbel committed Dec 27, 2012
1 parent 136250c commit 744bcb0
Show file tree
Hide file tree
Showing 25 changed files with 1,042 additions and 74 deletions.
95 changes: 57 additions & 38 deletions red/boot.red
Original file line number Diff line number Diff line change
Expand Up @@ -392,75 +392,76 @@ if: make native! [[
cond [any-type!]
true-blk [block!]
]
none
#get-definition NAT_IF
]

unless: make native! [[
cond [any-type!]
true-blk [block!]
]
none
#get-definition NAT_UNLESS
]

either: make native! [[
cond [any-type!]
true-blk [block!]
false-blk [block!]
]
none
#get-definition NAT_EITHER
]

any: make native! [[
conds [block!]
]
none
#get-definition NAT_ANY
]

all: make native! [[
conds [block!]
]
none
#get-definition NAT_ALL
]

while: make native! [[
cond [block!]
body [block!]
]
none
#get-definition NAT_WHILE
]

until: make native! [[
body [block!]
]
none
#get-definition NAT_UNTIL
]

loop: make native! [[
body [block!]
]
none
#get-definition NAT_LOOP
]

repeat: make native! [[
'word [word!]
value [integer! series!]
body [block!]
]
none
#get-definition NAT_REPEAT
]

foreach: make native! [[
'word [word!]
series [series!]
body [block!]
]
#get-definition NAT_FOREACH
]

forall: make native! [[
'word [word!]
body [block!]
]
none
#get-definition NAT_FORALL
]

;break: make native! [
Expand All @@ -472,35 +473,38 @@ func: make native! [[
spec [block!]
body [block!]
]
none
#get-definition NAT_FUNC
]

function: make native! [[
spec [block!]
body [block!]
]
none
#get-definition NAT_FUNCTION
]

does: make native! [[
body [block!]
]
none
#get-definition NAT_DOES
]

has: make native! [[
vars [block!]
body [block!]
]
none
#get-definition NAT_HAS
]

exit: make native! [[] none]
exit: make native! [
[]
#get-definition NAT_EXIT
]

return: make native! [[
value [any-type!]
]
none
#get-definition NAT_RETURN
]

switch: make native! [[
Expand All @@ -509,22 +513,28 @@ switch: make native! [[
/default
case [block!]
]
none
#get-definition NAT_SWITCH
]

case: make native! [[
cases [block!]
/all
]
none
#get-definition NAT_CASE
]

do: make native! [[
value [any-type!]
]
#get-definition NAT_DO
]

get: make native! [[
word [word!]
/any
return: [any-type!]
]
none
#get-definition NAT_GET
]

set: make native! [[
Expand All @@ -533,93 +543,102 @@ set: make native! [[
/any
return: [any-type!]
]
none
#get-definition NAT_SET
]

print: make native! [[
value [any-type!]
]
none
#get-definition NAT_PRINT
]

prin: make native! [[
value [any-type!]
]
none
#get-definition NAT_PRIN
]

equal?: make native! [[
value1 [any-type!]
value2 [any-type!]
]
none
#get-definition NAT_EQUAL?
]

not-equal?: make native! [[
value1 [any-type!]
value2 [any-type!]
]
none
#get-definition NAT_NOT_EQUAL?
]

strict-equal?: make native! [[
value1 [any-type!]
value2 [any-type!]
]
none
#get-definition NAT_STRICT_EQUAL?
]

same?: make native! [[
lesser?: make native! [[
value1 [any-type!]
value2 [any-type!]
]
none
#get-definition NAT_LESSER?
]

lesser?: make native! [[
greater?: make native! [[
value1 [any-type!]
value2 [any-type!]
]
none
#get-definition NAT_GREATER?
]

greater?: make native! [[
lesser-or-equal?: make native! [[
value1 [any-type!]
value2 [any-type!]
]
none
#get-definition NAT_LESSER_OR_EQUAL?
]

lesser-or-equal?: make native! [[
greater-or-equal?: make native! [[
value1 [any-type!]
value2 [any-type!]
]
none
#get-definition NAT_GREATER_OR_EQUAL?
]

greater-or-equal?: make native! [[
same?: make native! [[
value1 [any-type!]
value2 [any-type!]
]
none
#get-definition NAT_SAME?
]

not: make native! [[
value [any-type!]
]
none
#get-definition NAT_NOT
]

halt: make native! [
[]
none
#get-definition NAT_HALT
]

type?: make native! [[
value [any-type!]
/word
]
none
#get-definition NAT_TYPE?
]

load: make native! [[
source [file! url! string! binary! block!]
/header
/all
/type [word! none!]
]
#get-definition NAT_LOAD
]

;------------------------------------------
Expand Down
6 changes: 4 additions & 2 deletions red/compiler.r
Original file line number Diff line number Diff line change
Expand Up @@ -994,9 +994,11 @@ red: context [

emit-open-frame 'set ;-- function value creation
emit-push-word name
emit compose [
_function/push (spec-blk) (body-blk)
emit reduce [
'_function/push spec-blk body-blk
'as 'integer! to get-word! decorate-func/strict name
]
insert-lf -5
emit 'word/set
insert-lf -1
emit-close-frame
Expand Down
4 changes: 2 additions & 2 deletions red/lexer.r
Original file line number Diff line number Diff line change
Expand Up @@ -45,8 +45,8 @@ lexer: context [
]

UTF8-4: reduce [
#{F0} charset [#"^(90)" - #"^(BF)"] 2 UTF8-tail
'| charset [#"^(F1)" - #"^(F3)"] 3 UTF8-tail
#{F0} charset [#"^(90)" - #"^(BF)"] 2 UTF8-tail
'| charset [#"^(F1)" - #"^(F3)"] 3 UTF8-tail
'| #{F4} charset [#"^(80)" - #"^(8F)"] 2 UTF8-tail
]

Expand Down
Loading

0 comments on commit 744bcb0

Please sign in to comment.