From b6967eba48c6289a72a5c664e2878780297eaa2c Mon Sep 17 00:00:00 2001 From: Koichi Nakamura Date: Sun, 3 Jan 2021 08:17:41 +0900 Subject: [PATCH] Add add-error and exception --- bootstrap.fs | 35 +++++++++++++++++++++++++++++++++++ 1 file changed, 35 insertions(+) diff --git a/bootstrap.fs b/bootstrap.fs index 6ff2054..b92a25b 100644 --- a/bootstrap.fs +++ b/bootstrap.fs @@ -1160,3 +1160,38 @@ char 0 char B - constant string-overflow-error \ -18 type then ; immediate + +( === Error Code and Messages === ) + +\ Single linked list of error code and messages. +\ Thre structure of each entry: +\ | link | code | len | message ... | +variable error-list +0 error-list ! + +: add-error ( n c-addr u -- ) + error-list here + over @ , \ fill link + swap ! \ update error-list + rot , \ fill error-code + dup , \ fill length + cmove, \ fill message + align +; + +decimal + +s" -1" >number drop constant aborted-error + +aborted-error s" Aborted" add-error +string-overflow-error s" Too long string literal" add-error + +variable next-user-error +s" -256" >number drop next-user-error ! + +\ Create new user defined error and returns error code. +: exception ( c-addr u -- n ) + next-user-error @ -rot add-error + next-user-error @ + 1 next-user-error -! +;