diff --git a/examples/random.cal b/examples/random.cal new file mode 100644 index 0000000..856c690 --- /dev/null +++ b/examples/random.cal @@ -0,0 +1,11 @@ +include "cores/select.cal" +include "std/io.cal" +include "std/random.cal" + +let cell i +0 i ! + +while i @ 10 < do + rand printdec new_line + i @ 1 + i ! +end diff --git a/examples/time.cal b/examples/time.cal new file mode 100644 index 0000000..d37cc31 --- /dev/null +++ b/examples/time.cal @@ -0,0 +1,6 @@ +include "cores/select.cal" +include "std/io.cal" + +requires Time + +get_epoch_time printdec new_line diff --git a/micro_callisto.yaml b/micro_callisto.yaml new file mode 100644 index 0000000..c610a11 --- /dev/null +++ b/micro_callisto.yaml @@ -0,0 +1,39 @@ +filetype: callisto + +detect: + filename: "\\.(cal)$" + +rules: + - statement: "\\b(func|end|begin|asm|include|inline|if|then|elseif|else|while|do)\\b" + - statement: "\\b(let|feature|implements|requires|struct|version|return|const)\\b" + - type: "\\b(addr|void|u8|i8|u16|i16|u32|i32|u64|i64|size|usize|cell|array)\\b" + - identifier: "\\$\\{?[0-9A-Za-z._!@#$*?-]+\\}?" + - identifier: "\\$\\{?[0-9A-Za-z._!@#$*?-]+\\}?" + - identifier: "\\*\\{?[0-9A-Za-z._!@#$*?-]+\\}?" + - identifier: "\\!\\{?[0-9A-Za-z._!@#$*?-]+\\}?" + + - constant.string: + start: "\"" + end: "\"" + skip: "\\\\." + rules: + - constant.specialChar: "\\\\([\"'abfnrtv\\\\]|[0-3]?[0-7]{1,2}|x[0-9A-Fa-f]{1,2}|u[0-9A-Fa-f]{4}|U[0-9A-Fa-f]{8})" + + - constant.string: + start: "'" + end: "'" + skip: "\\\\." + rules: + - constant.specialChar: "\\\\([\"'abfnrtv\\\\]|[0-3]?[0-7]{1,2}|x[0-9A-Fa-f]{1,2}|u[0-9A-Fa-f]{4}|U[0-9A-Fa-f]{8})" + + - constant.number: "\\b([0-9.]*)\\b" + - constant.number: "\\b(0b[0-1.]*)\\b" + - constant.number: "\\b(0x[0-9A-Fa-f.]*)\\b" + - constant.number: "\\b(0o[0-7.]*)\\b" + - constant.bool: "\\b(true|false)\\b" + + - comment: + start: "#" + end: "$" + rules: + - todo: "(TODO|XXX|FIXME):?" diff --git a/source/backends/linux86.d b/source/backends/linux86.d index 7d37906..4faa00e 100644 --- a/source/backends/linux86.d +++ b/source/backends/linux86.d @@ -92,7 +92,7 @@ class BackendLinux86 : CompilerBackend { NewConst("Array.sizeof", 8 * 3); } - void NewConst(string name, long value, ErrorInfo error = ErrorInfo.init) { + override void NewConst(string name, long value, ErrorInfo error = ErrorInfo.init) { consts[name] = Constant(new IntegerNode(error, value)); } @@ -167,7 +167,7 @@ class BackendLinux86 : CompilerBackend { output ~= "section .bss\n"; foreach (name, var ; globals) { - output ~= format("__global_%s: resb %d\n", name, var.Size()); + output ~= format("__global_%s: resb %d\n", name.Sanitise(), var.Size()); } foreach (i, ref array ; arrays) { @@ -522,6 +522,10 @@ class BackendLinux86 : CompilerBackend { } override void CompileConst(ConstNode node) { + if (node.name in consts) { + Error(node.error, "Constant '%s' already defined", node.name); + } + NewConst(node.name, node.value); } } diff --git a/source/backends/rm86.d b/source/backends/rm86.d index 80cb45c..8f4206c 100644 --- a/source/backends/rm86.d +++ b/source/backends/rm86.d @@ -87,7 +87,7 @@ class BackendRM86 : CompilerBackend { NewConst("Array.sizeof", 2 * 3); } - void NewConst(string name, long value, ErrorInfo error = ErrorInfo.init) { + override void NewConst(string name, long value, ErrorInfo error = ErrorInfo.init) { consts[name] = Constant(new IntegerNode(error, value)); } @@ -485,6 +485,10 @@ class BackendRM86 : CompilerBackend { } override void CompileConst(ConstNode node) { + if (node.name in consts) { + Error(node.error, "Constant '%s' already defined", node.name); + } + NewConst(node.name, node.value); } } diff --git a/source/backends/y16.d b/source/backends/y16.d index 9764ece..30b6926 100644 --- a/source/backends/y16.d +++ b/source/backends/y16.d @@ -81,7 +81,7 @@ class BackendY16 : CompilerBackend { NewConst("Array.elements", 4); } - void NewConst(string name, long value, ErrorInfo error = ErrorInfo.init) { + override void NewConst(string name, long value, ErrorInfo error = ErrorInfo.init) { consts[name] = Constant(new IntegerNode(error, value)); } @@ -324,6 +324,10 @@ class BackendY16 : CompilerBackend { } override void CompileConst(ConstNode node) { + if (node.name in consts) { + Error(node.error, "Constant '%s' already defined", node.name); + } + NewConst(node.name, node.value); } } diff --git a/source/compiler.d b/source/compiler.d index ed028fd..d133970 100644 --- a/source/compiler.d +++ b/source/compiler.d @@ -19,6 +19,7 @@ class CompilerBackend { abstract string[] GetVersions(); abstract string[] FinalCommands(); + abstract void NewConst(string name, long value, ErrorInfo error); abstract void Init(); abstract void End(); diff --git a/std b/std index 70302bb..b43465c 160000 --- a/std +++ b/std @@ -1 +1 @@ -Subproject commit 70302bbc679278752b3bc88ee6fcf37b94390d10 +Subproject commit b43465cb1b4cd656df54dd5bc47e99049eca5ec4