From 516c789320c3abdf9f921dcf943b78bc9bcb9bc2 Mon Sep 17 00:00:00 2001 From: crc Date: Fri, 28 Dec 2018 04:28:39 +0000 Subject: [PATCH] autopsy: now recognize new instructions FossilOrigin-Name: 653e2682eda0902a0e086430a40d2d9331c59bd3e22cd38b8c564ceb305224c5 --- example/Autopsy.forth | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/example/Autopsy.forth b/example/Autopsy.forth index dfee1ef..3eab1c8 100644 --- a/example/Autopsy.forth +++ b/example/Autopsy.forth @@ -202,6 +202,9 @@ Now for the instructions. Taking a cue from the C implementation, I have a separ :i:sh from-stack from-stack swap shift to-stack ; :i:zr dup n:zero? [ drop i:re ] if ; :i:en ; +:i:ie #1 to-stack ; +:i:iq from-stack #0 eq? [ #0 dup to-stack to-stack ] if ; +:i:ii from-stack #0 eq? [ from-stack c:put ] if ; ~~~ With the instructions defined, populate the jump table. The order is crucial as the opcode number will be the index into this table. @@ -211,14 +214,14 @@ With the instructions defined, populate the jump table. The order is crucial as &i:no , &i:li , &i:du , &i:dr , &i:sw , &i:pu , &i:po , &i:ju , &i:ca , &i:cc , &i:re , &i:eq , &i:ne , &i:lt , &i:gt , &i:fe , &i:st , &i:ad , &i:su , &i:mu , &i:di , - &i:an , &i:or , &i:xo , &i:sh , &i:zr , &i:re , + &i:an , &i:or , &i:xo , &i:sh , &i:zr , &i:en , &i:ie , &i:iq , &i:ii , ~~~ With the populated table of instructions, implementing a `process-single-opcode` is easy. This will check the instruction to make sure it's valid, then call the corresponding handler in the instruction table. If not valid, this will report an error. ~~~ :process-single-opcode (n-) - dup #0 #26 n:between? + dup #0 #29 n:between? [ &Instructions + fetch call ] [ 'Invalid_Instruction:_%n_! s:format s:put nl ] choose ; ~~~