-
Notifications
You must be signed in to change notification settings - Fork 6
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #49 from GlowingScrewdriver/enhancements
Explicit return generation and error handling
- Loading branch information
Showing
45 changed files
with
268 additions
and
23 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
Error in statement: ['set', 'arr', ['alloc', 3]] | ||
CodegenError: Bad alloc expression: ['alloc', 3] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
(c-lisp | ||
(define ((main void)) | ||
(declare arr (ptr float)) | ||
(set arr (alloc 3)))) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
Error in statement: ['while', [True], ['call', 'print', 4]] | ||
CodegenError: Bad expression: [True] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
(c-lisp | ||
(define ((main int)) | ||
(while (#t) | ||
(call print 4)))) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
Error in statement: ['declare', 'a'] | ||
CodegenError: Bad declare statement: ['declare', 'a'] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
(c-lisp | ||
(define ((main void)) | ||
(declare a) | ||
(call print a))) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
Error in statement: ['ret', ['not', True, False]] | ||
CodegenError: `not` takes only 1 operands: ['not', True, False] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
(c-lisp | ||
(define ((main bool)) | ||
(ret (not #t #f)))) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
Error in statement: ['ret', ['add', 3, 4, 5]] | ||
CodegenError: `add` takes only 2 operands: ['add', 3, 4, 5] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
(c-lisp | ||
(define ((main int)) | ||
(ret (add 3 4 5)))) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
CodegenError: Bad function prototype: ['main', 'int'] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
(c-lisp | ||
(define (main int) | ||
(ret 0))) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
Error in statement: ['for', [['lt', 'i', 10], ['set', ['add', 'i', 1]], ['call', 'print', 'i']]] | ||
CodegenError: Bad for statement: ['for', [['lt', 'i', 10], ['set', ['add', 'i', 1]], ['call', 'print', 'i']]] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
(c-lisp | ||
(define ((main void)) | ||
(declare i int) | ||
(set i 0) | ||
(for ((lt i 10) (set (add i 1)) | ||
(call print i))))) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
Error in statement: ['if', True, ['call', 'print', 5], ['call', 'print', 4], ['call', 'print', 3]] | ||
CodegenError: Bad if statement: ['if', True, ['call', 'print', 5], ['call', 'print', 4], ['call', 'print', 3]] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
(c-lisp | ||
(define ((print int) (n int))) | ||
|
||
(define ((main void)) | ||
(if #t | ||
(call print 5) | ||
(call print 4) | ||
(call print 3)))) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
Error in statement: ['load', 'argv', 'a'] | ||
CodegenError: Bad load expression: ['load', 'argv', 'a'] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
(c-lisp | ||
(define ((main void) (argc int) (argv (ptr (ptr int)))) | ||
(declare a (ptr int)) | ||
(load argv a))) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
CodegenError: Input not a C-Lisp program |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
(brilisp | ||
(define ((main int)) | ||
(ret 0))) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
CodegenError: Not a function: ['declare', 'a', 'int'] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
(c-lisp | ||
(declare a int) | ||
(set a 5) | ||
(return a)) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
Error in statement: ['call', 'print', ['ptradd', 'arr', 4, 3]] | ||
CodegenError: Bad ptradd expression: ['ptradd', 'arr', 4, 3] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
(c-lisp | ||
(define ((main int)) | ||
(declare arr (ptr int)) | ||
(set arr (alloc int 20)) | ||
(call print (ptradd arr 4 3)))) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
Error in statement: ['declare', 'var', 'bool'] | ||
CodegenError: Re-declaration of variable var |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
(c-lisp | ||
(define ((main void)) | ||
(declare var int) | ||
|
||
(if #t | ||
((declare var float) | ||
(set var 0.5))) | ||
|
||
(declare var bool))) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
Error in statement: ['ret', 0, 1] | ||
CodegenError: Return statement can contain only 1 optional return value: ['ret', 0, 1] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
(c-lisp | ||
(define ((main int)) | ||
(ret 0 1))) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
Error in statement: ['call', 'print', 'val'] | ||
CodegenError: Undeclared symbol: val |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
(c-lisp | ||
(define ((print int) (n int))) | ||
|
||
(define ((main void)) | ||
(declare i int) | ||
|
||
(for ((set i 0) | ||
(lt i 100) | ||
(set i (add i 1))) | ||
(declare val int) | ||
(if (eq | ||
i | ||
(mul (div i 7) 7)) | ||
(set val i))) | ||
(call print val))) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
Error in statement: ['set', ['declare', 'var', 'int'], 4] | ||
CodegenError: Bad set expression: ['set', ['declare', 'var', 'int'], 4] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
(c-lisp | ||
(define ((main int)) | ||
(set (declare var int) 4))) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
Error in statement: ['store', 'a', 5, 6, 7] | ||
CodegenError: Bad store expression: ['store', 'a', 5, 6, 7] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
(c-lisp | ||
(define ((main void)) | ||
(declare a (ptr int)) | ||
(set a (alloc int 3)) | ||
(store a 5 6 7))) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
command = "guile ../../../utils/sexp-json.scm < {filename} | python ../../../c-lisp.py 2>&1 | sed -e '/^[ (Traceback)]/d'" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
Error in statement: ['call', 'print', 4] | ||
CodegenError: Call to undeclared function: print |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
(c-lisp | ||
(define ((main int)) | ||
(call print 4))) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
Error in statement: ['set', 'var', 5] | ||
CodegenError: Undeclared symbol: var |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
(c-lisp | ||
(define ((main int)) | ||
(set var 5) | ||
(ret var))) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
Error in statement: ['while', ['call', 'print', 5]] | ||
CodegenError: Bad while statement: ['while', ['call', 'print', 5]] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
(c-lisp | ||
(define ((main int)) | ||
(while | ||
(call print 5)))) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
12 | ||
-2 | ||
-1 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
(c-lisp | ||
(define ((print int) (n int))) | ||
|
||
(define ((cons void) (arr (ptr int)) (n int)) | ||
(declare i int) | ||
(for ((set i 0) | ||
(lt i n) | ||
(set i (add i 1))) | ||
(store | ||
(ptradd arr i) | ||
(mul i 3)))) | ||
|
||
(define ((find int) (arr (ptr int)) (key int) (n int)) | ||
(declare i int) | ||
(for ((set i 0) | ||
(lt i n) | ||
(set i (add i 1))) | ||
(if (eq key | ||
(load (ptradd arr i))) | ||
(ret i)))) | ||
|
||
(define ((verify int) (arr (ptr int)) (key int) (idx int) (len int)) | ||
(declare val int) | ||
(if (lt idx len) | ||
((set val (load (ptradd arr idx))) | ||
(if (eq val key) | ||
(ret val) | ||
(ret -1))) | ||
(ret -2))) | ||
|
||
(define ((main void)) | ||
(declare input (ptr int)) | ||
(declare i int) | ||
|
||
(set input (alloc int 10)) | ||
(call cons input 10) | ||
|
||
(declare 12-idx int) | ||
(declare 13-idx int) | ||
|
||
(set 12-idx (call find input 12 10)) | ||
(set 13-idx (call find input 13 10)) | ||
|
||
(call print (call verify input 12 12-idx 10)) | ||
(call print (call verify input 13 13-idx 10)) | ||
(call print (call verify input 12 2 10)) | ||
(ret))) |
Oops, something went wrong.