diff --git a/next/main.adept b/next/main.adept deleted file mode 100644 index a2f65f89..00000000 --- a/next/main.adept +++ /dev/null @@ -1,31 +0,0 @@ - -pragma compiler_version '2.8' - -import basics -import "src/Context.adept" -import "src/Lexer.adept" - -func main(argc int, argv **ubyte) int { - context adept\Context(argc, argv) - - exhaustive switch context.intent { - case ::FAILED_TO_PARSE_ARGS - return 1 - case ::HELP - context.output.send(adept\Icon()) - context.output.send(adept\Text(embed "src/msg/help.txt", none())) - return 0 - case ::COMPILE - tokenlist List - - unless adept\lex(&context, context.filename.get()).take(&tokenlist) { - return context.exit_code - } - - each adept\Token in tokenlist { - print(adept\getAssociatedInfo(it.id).name) - } - } - - return 0 -} diff --git a/next/src/Context.adept b/next/src/Context.adept deleted file mode 100644 index 2980d0f4..00000000 --- a/next/src/Context.adept +++ /dev/null @@ -1,62 +0,0 @@ - -import Array -import array_util -import String -import del - -import "Output.adept" - -enum adept\ContextIntent (FAILED_TO_PARSE_ARGS, HELP, COMPILE) -enum adept\ContextOutputMode (TERMINAL, CAPTURED) - -struct adept\Context ( - intent adept\ContextIntent, - output *adept\Output, - filename Optional, - exit_code int, -) { - constructor(argc int, argv **ubyte){ - args List = Array(argv at 1, argc - 1).asList().map(func &StringView(*ubyte)) - - this.setOutputMode(::TERMINAL) - - each arg String in args { - if arg == "-h" || arg == "--help" { - this.intent = ::HELP - return - } else if this.filename.isNone() && !arg.startsWith("-") { - this.filename = some(arg.clone()).commit() - } else { - this.output.send(adept\Error("Unknown option `" + arg + "`", none())) - this.intent = ::FAILED_TO_PARSE_ARGS - return - } - } - - if this.filename.isNone() { - if adept\fs\exists("next.adept") { - this.filename.assign("next.adept") - } else { - this.intent = ::HELP - return - } - } - - this.intent = ::COMPILE - } - - func setOutputMode(mode adept\ContextOutputMode){ - if this.output, del(this.output) - - exhaustive switch mode { - case ::TERMINAL - this.output = new adept\TerminalOutput() - case ::CAPTURED - this.output = new adept\CapturedOutput() - } - } - - func __defer__ { - del(this.output) - } -} diff --git a/next/src/Lexer.adept b/next/src/Lexer.adept deleted file mode 100644 index 9f187ffd..00000000 --- a/next/src/Lexer.adept +++ /dev/null @@ -1,684 +0,0 @@ - -import String -import string_util -import cstring -import List -import "sys/ctype.adept" - -import "Context.adept" -import "Token.adept" -import "fs.adept" -import "string.adept" -import "util.adept" -import "datatypes.adept" -import "TokenKeyword.adept" -import "Version.adept" - -func adept\lex(context *adept\Context, filename String) < List> Optional { - lexer adept\lex\Lexer(context) - return lexer.lex(filename) -} - -func adept\lex(context *adept\Context, buffer String, filename String) < List> Optional { - return adept\lex\Lexer(context).lexBuffer(buffer, filename) -} - -struct adept\lex\Lexer ( - context *adept\Context, - filename String, - buffer String, - object_index usize, - tokenlist List, - version adept\Version, - i usize, -) { - constructor(context *adept\Context){ - this.context = context - } - - func lex(filename String) < List> Optional { - contents String - - unless adept\fs\readTextContents(filename, &contents, ::WITH_NEWLINE_ENDING) { - this.context.output.send( - adept\Error( - sprintf("The file `%S` doesn't exist or can't be accessed", filename), - none() - ) - ) - this.context.exit_code = 1 - return none() - } - - return this.lexBuffer(contents, filename.commit()) - } - - func figureOutVersion() successful { - this.version = ::TWO - return true - } - - func lexBuffer(buffer String, filename String) < List> Optional { - estimate usize = buffer.length / 3 - - this.i = 0 - this.object_index = 0 - this.buffer = buffer.commit() - this.tokenlist.clear() - this.tokenlist.reserve(estimate) - this.filename = filename.commit() - - unless this.figureOutVersion() { - this.context.output.send( - adept\Error( - sprintf(embed "msg/no_version_specified.txt", this.context.filename.get()), - none() - ) - ) - - this.context.exit_code = 1 - return none() - } - - ok successful - - exhaustive switch this.version { - case ::TWO - ok = this.lexBufferAdept2() - case ::THREE - this.context.output.send( - adept\Error( - "Only Adept 2.x code can be lexed right now", - some(adept\Source( - 0, - 0, - this.object_index - )) - ) - ) - ok = false - } - - if ok { - return somePOD(this.tokenlist.donate()) - } else { - this.context.exit_code = 1 - return none() - } - } - - func lexBufferAdept2 successful { - while this.i < this.buffer.length { - c ubyte = this.char() - - switch c { - case ' 'ub, fallthrough - case '\t'ub - this.i += 1 - case '('ub - this.simpleToken(::OPEN) - case ')'ub - this.simpleToken(::CLOSE) - case '{'ub - this.simpleToken(::BEGIN) - case '}'ub - this.simpleToken(::END) - case '['ub - this.simpleToken(::BRACKET_OPEN) - case ']'ub - this.simpleToken(::BRACKET_CLOSE) - case ','ub - this.simpleToken(::NEXT) - case ';'ub - this.simpleToken(::TERMINATE_JOIN) - case '?'ub - this.simpleToken(::MAYBE) - case '\n'ub - this.simpleToken(::NEWLINE) - case '-'ub - if isdigit(this.char(1)) { - unless this.number(), return false - } else { - this.cases({ - adept\lex\Case('='ub, ::SUBTRACT_ASSIGN), - adept\lex\Case('-'ub, ::DECREMENT), - }, ::SUBTRACT) - } - case '/'ub - unless this.slash(), return false - case '<'ub - this.options({ - adept\lex\Option("<<<=", ::BIT_LGC_LSHIFT_ASSIGN), - adept\lex\Option("<<<", ::BIT_LGC_LSHIFT), - adept\lex\Option("<<", ::BIT_LSHIFT), - adept\lex\Option("<=", ::LESSTHANEQ), - adept\lex\Option("<", ::LESSTHAN), - }) - case '>'ub - this.options({ - adept\lex\Option(">>>=", ::BIT_LGC_RSHIFT_ASSIGN), - adept\lex\Option(">>>", ::BIT_LGC_RSHIFT), - adept\lex\Option(">>=", ::BIT_RSHIFT_ASSIGN), - adept\lex\Option(">>", :: BIT_RSHIFT), - adept\lex\Option(">=", ::GREATERTHANEQ), - adept\lex\Option(">", ::GREATERTHAN), - }) - case '='ub - this.cases({ - adept\lex\Case('='ub, ::EQUALS), - adept\lex\Case('>'ub, ::STRONG_ARROW), - }, ::ASSIGN) - case '!'ub - this.cases({ - adept\lex\Case('='ub, ::NOTEQUALS), - adept\lex\Case('!'ub, ::TOGGLE), - }, ::NOT) - case ':'ub - this.cases({ - adept\lex\Case(':'ub, ::ASSOCIATE), - }, ::COLON) - case '+'ub - this.cases({ - adept\lex\Case('='ub, ::ADD_ASSIGN), - adept\lex\Case('+'ub, ::INCREMENT), - }, ::ADD) - case '*'ub - this.cases({ - adept\lex\Case('='ub, ::MULTIPLY_ASSIGN), - }, ::MULTIPLY) - case '%'ub - this.cases({ - adept\lex\Case('='ub, ::MODULUS_ASSIGN), - }, ::MODULUS) - case '^'ub - this.cases({ - adept\lex\Case('='ub, ::BIT_XOR_ASSIGN), - }, ::BIT_XOR) - case '~'ub - this.cases({ - adept\lex\Case('>'ub, ::GIVES), - }, ::BIT_COMPLEMENT) - case '&'ub - this.cases({ - adept\lex\Case('&'ub, ::UBERAND), - adept\lex\Case('='ub, ::BIT_AND_ASSIGN), - }, ::AMPERSAND) - case '|'ub - this.cases({ - adept\lex\Case('|'ub, ::UBEROR), - adept\lex\Case('='ub, ::BIT_OR_ASSIGN), - }, ::BIT_OR) - case '.'ub - this.stacking('.'ub, {adept\TokenID::MEMBER, ::RANGE, ::ELLIPSIS}) - case '"'ub - unless this.string(), return false - case '\''ub - unless this.cstring(), return false - case '#'ub - this.running(::META) - case '$'ub - this.running(::POLYMORPH) - default - if isalpha(c) || c == '_'ub || c == '\\'ub { - this.running(::WORD) - continue - } - - if isdigit(c) { - unless this.number(), return false - continue - } - - this.context.output.send( - adept\Error( - sprintf("Unexpected character '%c' while lexing (char code %d)", this.char(), this.char()), - some(adept\Source(this.i, 1, this.object_index)) - ) - ) - return false - } - } - - return true - } - - func add(id adept\TokenID, extra ptr, source adept\Source) { - this.tokenlist.add(adept\Token(id, extra as *adept\TokenExtra, source)) - } - - func simpleToken(token_id adept\TokenID) { - this.add(token_id, null, adept\Source(this.object_index, this.i, 1)) - this.i += 1 - } - - func cases(possibilities Array, default_token_id adept\TokenID) { - c ubyte = this.char(1) - - each adept\lex\Case in possibilities { - if it.extension == c { - this.add(it.token_id, null, adept\Source(this.object_index, this.i, 2)) - this.i += 2 - return - } - } - - this.add(default_token_id, null, adept\Source(this.object_index, this.i, 1)) - this.i += 1 - } - - func rest(offset usize = 0) StringView { - return this.buffer.range(this.i + offset, this.buffer.length) - } - - func options(options Array) { - rest StringView = this.rest() - - each adept\lex\Option in options { - if rest.startsWith(it.sequence) { - this.add(it.token_id, null, adept\Source(this.object_index, this.i, it.sequence.length)) - this.i += it.sequence.length - return - } - } - } - - func stacking(c ubyte, mappings Array) { - stride usize = 1 - - while stride < mappings.length && this.char(stride) == c { - stride += 1 - } - - this.add(mappings[stride - 1], null, adept\Source(this.i, stride, this.object_index)) - this.i += stride - } - - func string successful { - rest StringView = this.rest(1) - unescaped, escaped String - - unless adept\lex\escapableUntil(rest, '"'ub, '\\'ub, &unescaped) { - this.errorUnterminatedString() - return false - } - - unless this.stringUnescapeOrFail(unescaped, &escaped) { - return false - } - - this.add( - ::STRING, - new String(escaped.commit()) as *adept\TokenExtra, - adept\Source( - this.i, - unescaped.length + 2, - this.object_index - ) - ) - - this.i += unescaped.length + 2 - return true - } - - func cstring successful { - rest StringView = this.rest(1) - unescaped, escaped String - - unless adept\lex\escapableUntil(rest, '\''ub, '\\'ub, &unescaped) { - this.errorUnterminatedString() - return false - } - - unless this.stringUnescapeOrFail(unescaped, &escaped) { - return false - } - - // Handle special case of character literals differently - if(escaped.length == 1){ - rest = this.rest(unescaped.length + 2) - - if rest.startsWith("ub") { - // Actually a 'ubyte' character literal - this.add(::UBYTE, adept\toHeap(escaped[0] as ulong), adept\Source(this.i, unescaped.length + 4, this.object_index)) - this.i += unescaped.length + 4 - return true - } elif rest.startsWith("sb") { - // Actually a 'byte' character literal - this.add(::BYTE, adept\toHeap(escaped[0] as long), adept\Source(this.i, unescaped.length + 4, this.object_index)) - this.i += unescaped.length + 4 - return true - } - } - - this.add(::CSTRING, new String(escaped.commit()), adept\Source(this.i, unescaped.length + 2, this.object_index)) - this.i += unescaped.length + 2 - return true - } - - func char(offset usize = 0) ubyte = this.i + offset < this.buffer.length ? this.buffer[this.i + offset] : '\0'ub - - func number successful { - define buf_size = 96 - - is_hex, did_exp bool = false - can_dot bool = true - start_i usize = this.i - - if this.char() == '-'ub { - // Negative number - this.i++ - } else { - beginning StringView = this.buffer.range(this.i, this.buffer.length) - - if beginning.startsWith("0x") || beginning.startsWith("0X") { - is_hex = true - can_dot = false - this.i += 2 - } - } - - while true { - c ubyte = this.char() - - if isdigit(c) || c == '_'ub { - this.i++ - } elif c == '.'ub && can_dot { - can_dot = false - this.i++ - } elif is_hex && ((c >= 'A'ub && c <= 'F'ub) || (c >= 'a'ub && c <= 'f'ub)) { - this.i++ - } elif !did_exp && (c == 'e'ub || c == 'E'ub) { - this.i++ - did_exp = true - can_dot = false - c = this.char() - - if c == '+'ub || c == '-'ub { - this.i++ - } - } else { - break - } - } - - number String = this.buffer.range(start_i, this.i).replace('_'ub, "", ::OR_VIEW) - - token_id adept\TokenID - data ptr - stride usize = this.i - start_i - - // Respect integer/float suffixes - switch this.char() { - case 'u'ub - switch this.char(1) { - case 'b'ub - token_id = ::UBYTE - data = adept\toHeap(toUlong(number, is_hex) as adept\unsigned) - stride += 2 - case 's'ub - token_id = ::USHORT - data = adept\toHeap(toUlong(number, is_hex) as adept\unsigned) - stride += 2 - case 'i'ub - token_id = ::UINT - data = adept\toHeap(toUlong(number, is_hex) as adept\unsigned) - stride += 2 - case 'l'ub - token_id = ::ULONG - data = adept\toHeap(toUlong(number, is_hex) as adept\unsigned) - stride += 2 - case 'z'ub - token_id = ::USIZE - data = adept\toHeap(toUlong(number, is_hex) as adept\unsigned) - stride += 2 - default - this.context.output.send( - adept\Error( - "Expected valid number suffix after 'u' base suffix", - some( - adept\Source(this.i + stride + 1, 1, this.object_index) - ) - ) - ) - return false - } - case 's'ub - switch this.char(1) { - case 'b'ub - token_id = ::BYTE - data = adept\toHeap(toLong(number, is_hex) as adept\signed) - stride += 2 - case 's'ub - token_id = ::SHORT - data = adept\toHeap(toLong(number, is_hex) as adept\signed) - stride += 2 - case 'i'ub - token_id = ::INT - data = adept\toHeap(toLong(number, is_hex) as adept\signed) - stride += 2 - case 'l'ub - token_id = ::LONG - data = adept\toHeap(toLong(number, is_hex) as adept\signed) - stride += 2 - default - token_id = ::SHORT - data = adept\toHeap(toLong(number, is_hex) as adept\signed) - stride += 1 - } - case 'b'ub - token_id = ::BYTE - data = adept\toHeap(toLong(number, is_hex) as adept\signed) - stride += 1 - case 'i'ub - token_id = ::INT - data = adept\toHeap(toLong(number, is_hex) as adept\signed) - stride += 1 - case 'l'ub - token_id = ::LONG - data = adept\toHeap(toLong(number, is_hex) as adept\signed) - stride += 1 - case 'f'ub - token_id = ::FLOAT - data = adept\toHeap(toDouble(number) as adept\floating) - stride += 1 - case 'd'ub - token_id = ::DOUBLE - data = adept\toHeap(toDouble(number) as adept\floating) - stride += 1 - default - if (!is_hex && !can_dot) || did_exp { - // Default to normal generic floating-point - token_id = ::GENERIC_FLOAT - data = adept\toHeap(toDouble(number) as adept\floating) - } elif adept\mustBeUnsigned64(number, is_hex) { - // Numbers that cannot be expressed using int64 will be promoted to uint64 - token_id = ::ULONG - data = adept\toHeap(toUlong(number, is_hex) as adept\unsigned) - } else { - // Otherwise, default to normal generic integer - token_id = ::GENERIC_INT - data = adept\toHeap(toLong(number, is_hex)) - } - } - - // Add number token - this.add(token_id, data, adept\Source(start_i, stride, this.object_index)) - return true - } - - func running(intent adept\TokenID) { - // Contains additional logic for intents: - // - adept\TokenID::WORD - // - adept\TokenID::POLYMORPH - - flag_length usize = intent == ::WORD ? 0 : 1 - start_i usize = this.i - - this.i += flag_length - - while this.i < this.buffer.length { - c ubyte = this.char() - - if c == '_'ub || isalnum(c) { - this.i++ - continue - } - - if intent == ::WORD { - if c == '\\'ub || (c == ':'ub && (isalnum(this.char(1)) || c == '_'ub)) { - this.i++ - continue - } - } - - if intent == ::POLYMORPH && this.i == start_i { - if c == '~'ub { - this.i++ - continue - } - - if c == '#'ub { - intent = ::POLYCOUNT - start_i++ - this.i++ - flag_length++ - continue - } - } - - break - } - - // Create string to hold identifier - identifier String = this.buffer.range(start_i, this.i) - - if intent == ::WORD { - keyword_token_id adept\TokenID = adept\getTokenForKeyword(identifier) - - // Handle word tokens that should be keywords - if keyword_token_id != ::NONE { - this.add(keyword_token_id, null, adept\Source(start_i, identifier.length, this.object_index)) - return - } elif identifier == "elif" { - this.add(::ELSE, null, adept\Source(start_i, 2, this.object_index)) - this.add(::IF, null, adept\Source(start_i + 2, 2, this.object_index)) - return - } - - // Otherwise not a keyword... - // Legacy alternative syntax ':' instead of '\\' as a namespace character - identifier = identifier.replace(':'ub, "\\", ::OR_VIEW) - } - - // Create token - this.add( - intent, - new String(identifier.commit()), - adept\Source(start_i, identifier.length + flag_length, this.object_index) - ) - } - - func slash successful { - switch(this.char(1)){ - case '/'ub - this.i += 1 - while this.char() != '\n'ub { - this.i += 1 - } - case '*'ub - start_i usize = this.i - 1 - this.i += 1 - - while true { - unless this.i + 1 < this.buffer.length { - source adept\Source = adept\Source(start_i, 2, this.object_index) - this.context.output.send(adept\Error("Unterminated multi-line comment", some(source))) - return false - } - - if this.buffer.range(this.i, 2).startsWith("*/") { - this.i += 2 - break - } - - this.i += 1 - } - default - this.cases({ - adept\lex\Case('='ub, ::DIVIDE_ASSIGN), - }, ::DIVIDE) - } - - return true - } - - func stringUnescapeOrFail(string String, out result *String) successful { - error Optional = adept\string\unescape(string, result) - - if error.has { - this.errorUnknownEscapeSequence(error.ref()) - return false - } - - return true - } - - func errorUnterminatedString { - this.context.output.send( - adept\Error( - "Unterminated string literal", - some(adept\Source(this.i, 1, this.object_index)) - ) - ) - } - - func errorUnknownEscapeSequence(error *adept\string\UnescapeError) { - position usize = this.i + 1 + error.relative_position - invalid_escape_char ubyte = this.buffer[position + 1] - - this.context.output.send( - adept\Error( - sprintf("Unknown escape sequence '\\%c\'", invalid_escape_char), - some(adept\Source(position, 2, this.object_index)) - ) - ) - } -} - -record adept\lex\Case (extension ubyte, token_id adept\TokenID) -record adept\lex\Option (sequence String, token_id adept\TokenID) - -func adept\lex\escapableUntil(rest StringView, terminator, escape_prefix ubyte, out output *StringView) successful { - beginning *ubyte = rest.array - end *ubyte = beginning - eof *ubyte = beginning at rest.length - - while end < eof { - if *end == terminator { - *output = rest.range(0, (end - beginning) as usize) - return true - } else if *end == escape_prefix { - end = end at 2 - } else { - end = end at 1 - } - } - - *output = "" - return false -} - -func adept\lex\getLocation(buffer String, index usize, out line, column *usize) { - newlines int = 0 - last_newline *ubyte = null - - for i usize = 0; i != index; i++ { - if buffer[i] == '\n'ub { - last_newline = buffer at i - newlines++ - } - } - - *line = 1 + newlines - *column = last_newline ? cast usize (buffer at index - last_newline) : index + 1 -} diff --git a/next/src/Message.adept b/next/src/Message.adept deleted file mode 100644 index 3bc9c72b..00000000 --- a/next/src/Message.adept +++ /dev/null @@ -1,39 +0,0 @@ - -import String -import Optional - -import "configuration.adept" -import "Source.adept" - -enum adept\MessageKind (NONE, ERROR, WARNING, INFO, ICON) - -record adept\Message (kind adept\MessageKind, content String, source Optional) { - func make { - this.content.make() - } - - func equals(other *adept\Message) bool { - return this.kind == other.kind && - this.content == other.content && - this.source.equals(&other.source) - } -} - -func adept\Text(content String, source Optional) adept\Message - = adept\Message(::NONE, content, source) - -func adept\Error(content String, source Optional) adept\Message - = adept\Message(::ERROR, content, source) - -func adept\Warning(content String, source Optional) adept\Message - = adept\Message(::WARNING, content, source) - -func adept\Info(content String, source Optional) adept\Message - = adept\Message(::INFO, content, source) - -func adept\Icon() adept\Message - = adept\Message( - ::ICON, - sprintf("The Adept Compiler v%S - (c) 2016-2024 Isaac Shelton", adept\VERSION_STRING), - none() - ) diff --git a/next/src/Output.adept b/next/src/Output.adept deleted file mode 100644 index 57d241d7..00000000 --- a/next/src/Output.adept +++ /dev/null @@ -1,58 +0,0 @@ - -import terminal -import "color.adept" -import "Message.adept" - -class adept\Output () { - constructor {} - - virtual func send(_message adept\Message) {} - virtual func getTimeline() * List = null -} - -class adept\TerminalOutput extends adept\Output () { - constructor {} - - override func send(message adept\Message){ - exhaustive switch message.kind { - case ::NONE - print(message.content) - case ::ERROR - color\red() - place("[error] ") - color\reset() - print(message.content) - case ::WARNING - color\yellow() - place("[warning] ") - color\reset() - print(message.content) - case ::INFO - color\blue() - place("[info] ") - color\reset() - print(message.content) - case ::ICON - color\use(::LIGHT_BLUE) - printf(" /▔▔\\\n"); - printf(" / \\\n"); - printf(" / \\\n"); - printf(" / /\\ \\ %S\n", message.content); - printf(" / /\\__ \\\n"); - printf("/___/ \\___\\\n\n"); - color\reset() - } - } -} - -class adept\CapturedOutput extends adept\Output (timeline List) { - constructor {} - - override func send(message adept\Message){ - this.timeline.add(message).make() - } - - override func getTimeline() * List { - return &this.timeline - } -} diff --git a/next/src/Source.adept b/next/src/Source.adept deleted file mode 100644 index 1c95213a..00000000 --- a/next/src/Source.adept +++ /dev/null @@ -1,8 +0,0 @@ - -import Optional - -record adept\Source (object_index, index, stride usize) - -func __equals__(a, b adept\Source) bool { - return memcmp(&a, &b, sizeof(a)) == 0 -} diff --git a/next/src/Token.adept b/next/src/Token.adept deleted file mode 100644 index 62fad0db..00000000 --- a/next/src/Token.adept +++ /dev/null @@ -1,41 +0,0 @@ - -import del -import "TokenID.adept" - -record adept\Token (id adept\TokenID, extra *adept\TokenExtra, source adept\Source) { - func __defer__ { - exhaustive switch adept\getAssociatedInfo(this.id).extra_kind { - case ::ID_ONLY, // (nothing) - case ::SIGNED, delete this.extra - case ::UNSIGNED, delete this.extra - case ::FLOATING, delete this.extra - case ::STRING, del(this.extra as *String) - } - } -} - -union adept\TokenExtra (string String, signed long, unsigned ulong, floating double) - -func adept\TokenExtra(string String) *adept\TokenExtra { - result *String = new String - *result = string.toOwned() - return result as *adept\TokenExtra -} - -func adept\TokenExtra(signed long) *adept\TokenExtra { - result *long = new undef long - *result = signed - return result as *adept\TokenExtra -} - -func adept\TokenExtra(unsigned ulong) *adept\TokenExtra { - result *ulong = new undef ulong - *result = unsigned - return result as *adept\TokenExtra -} - -func adept\TokenExtra(floating double) *adept\TokenExtra { - result *double = new undef double - *result = floating - return result as *adept\TokenExtra -} diff --git a/next/src/TokenID.adept b/next/src/TokenID.adept deleted file mode 100644 index 44de396b..00000000 --- a/next/src/TokenID.adept +++ /dev/null @@ -1,325 +0,0 @@ - -namespace adept - -import List -import String - -enum TokenExtraKind (ID_ONLY, STRING, SIGNED, UNSIGNED, FLOATING) -enum TokenCategory (NONE, WORD, KEYWORD, OPERATOR, LITERAL, POLYMORPH, PREPROCESSOR) - -alias string = String -alias signed = long -alias unsigned = ulong -alias floating = double - -enum TokenID ( - NONE, - WORD, - STRING, - CSTRING, - ADD, - SUBTRACT, - MULTIPLY, - DIVIDE, - ASSIGN, - EQUALS, - NOTEQUALS, - LESSTHAN, - GREATERTHAN, - LESSTHANEQ, - GREATERTHANEQ, - NOT, - OPEN, - CLOSE, - BEGIN, - END, - NEWLINE, - BYTE, - UBYTE, - SHORT, - USHORT, - INT, - UINT, - LONG, - ULONG, - USIZE, - FLOAT, - DOUBLE, - MEMBER, - AMPERSAND, - NEXT, - BRACKET_OPEN, - BRACKET_CLOSE, - MODULUS, - GENERIC_INT, - GENERIC_FLOAT, - ADD_ASSIGN, - SUBTRACT_ASSIGN, - MULTIPLY_ASSIGN, - DIVIDE_ASSIGN, - MODULUS_ASSIGN, - BIT_AND_ASSIGN, - BIT_OR_ASSIGN, - BIT_XOR_ASSIGN, - BIT_LSHIFT_ASSIGN, - BIT_RSHIFT_ASSIGN, - BIT_LGC_LSHIFT_ASSIGN, - BIT_LGC_RSHIFT_ASSIGN, - ELLIPSIS, - UBERAND, - UBEROR, - TERMINATE_JOIN, - COLON, - BIT_OR, - BIT_XOR, - BIT_LSHIFT, - BIT_RSHIFT, - BIT_COMPLEMENT, - BIT_LGC_LSHIFT, - BIT_LGC_RSHIFT, - ASSOCIATE, - META, - POLYMORPH, - MAYBE, - INCREMENT, - DECREMENT, - TOGGLE, - STRONG_ARROW, - RANGE, - GIVES, - POLYCOUNT, - POD_KEYWORD, - ALIAS, - ALIGNOF, - AND, - AS, - AT, - BREAK, - CASE, - CAST, - CLASS, - CONST, - CONSTRUCTOR, - CONTINUE, - DEF, - DEFAULT, - DEFER, - DEFINE, - DELETE, - EACH, - ELSE, - EMBED, - ENUM, - EXHAUSTIVE, - EXTENDS, - EXTERNAL, - FALLTHROUGH, - FALSE, - FOR, - FOREIGN, - FUNC, - FUNCPTR, - GLOBAL, - IF, - IMPLICIT, - IMPORT, - IN, - INOUT, - LLVM_ASM, - NAMESPACE, - NEW, - NULL, - OR, - OUT, - OVERRIDE, - PACKED, - PRAGMA, - PRIVATE, - PUBLIC, - RECORD, - REPEAT, - RETURN, - SIZEOF, - STATIC, - STDCALL, - STRUCT, - SWITCH, - THREAD_LOCAL, - TRUE, - TYPEINFO, - TYPENAMEOF, - UNDEF, - UNION, - UNLESS, - UNTIL, - USING, - VA_ARG, - VA_COPY, - VA_END, - VA_START, - VERBATIM, - VIRTUAL, - WHILE, - NUM_ITEMS -) - -struct TokenAssociatedInfo ( - name StringView, - category adept\TokenCategory, - extra_kind adept\TokenExtraKind, -) - -func getAssociatedInfo(token_id adept\TokenID) *adept\TokenAssociatedInfo { - exhaustive switch token_id { - case ::NONE, return static adept\TokenAssociatedInfo("none", ::NONE, ::ID_ONLY) - case ::WORD, return static adept\TokenAssociatedInfo("word", ::WORD, ::STRING) - case ::STRING, return static adept\TokenAssociatedInfo("string", ::LITERAL, ::STRING) - case ::CSTRING, return static adept\TokenAssociatedInfo("cstring", ::LITERAL, ::STRING) - case ::ADD, return static adept\TokenAssociatedInfo("add", ::OPERATOR, ::ID_ONLY) - case ::SUBTRACT, return static adept\TokenAssociatedInfo("subtract", ::OPERATOR, ::ID_ONLY) - case ::MULTIPLY, return static adept\TokenAssociatedInfo("multiply", ::OPERATOR, ::ID_ONLY) - case ::DIVIDE, return static adept\TokenAssociatedInfo("divide", ::OPERATOR, ::ID_ONLY) - case ::ASSIGN, return static adept\TokenAssociatedInfo("assign", ::OPERATOR, ::ID_ONLY) - case ::EQUALS, return static adept\TokenAssociatedInfo("equals", ::OPERATOR, ::ID_ONLY) - case ::NOTEQUALS, return static adept\TokenAssociatedInfo("not equals", ::OPERATOR, ::ID_ONLY) - case ::LESSTHAN, return static adept\TokenAssociatedInfo("less than", ::OPERATOR, ::ID_ONLY) - case ::GREATERTHAN, return static adept\TokenAssociatedInfo("greater than", ::OPERATOR, ::ID_ONLY) - case ::LESSTHANEQ, return static adept\TokenAssociatedInfo("less than or equal", ::OPERATOR, ::ID_ONLY) - case ::GREATERTHANEQ, return static adept\TokenAssociatedInfo("greater than or equal", ::OPERATOR, ::ID_ONLY) - case ::NOT, return static adept\TokenAssociatedInfo("not", ::OPERATOR, ::ID_ONLY) - case ::OPEN, return static adept\TokenAssociatedInfo("open", ::OPERATOR, ::ID_ONLY) - case ::CLOSE, return static adept\TokenAssociatedInfo("close", ::OPERATOR, ::ID_ONLY) - case ::BEGIN, return static adept\TokenAssociatedInfo("begin", ::OPERATOR, ::ID_ONLY) - case ::END, return static adept\TokenAssociatedInfo("end", ::OPERATOR, ::ID_ONLY) - case ::NEWLINE, return static adept\TokenAssociatedInfo("newline", ::OPERATOR, ::ID_ONLY) - case ::BYTE, return static adept\TokenAssociatedInfo("byte", ::LITERAL, ::SIGNED) - case ::UBYTE, return static adept\TokenAssociatedInfo("ubyte", ::LITERAL, ::UNSIGNED) - case ::SHORT, return static adept\TokenAssociatedInfo("short", ::LITERAL, ::SIGNED) - case ::USHORT, return static adept\TokenAssociatedInfo("ushort", ::LITERAL, ::UNSIGNED) - case ::INT, return static adept\TokenAssociatedInfo("int", ::LITERAL, ::SIGNED) - case ::UINT, return static adept\TokenAssociatedInfo("uint", ::LITERAL, ::UNSIGNED) - case ::LONG, return static adept\TokenAssociatedInfo("long", ::LITERAL, ::SIGNED) - case ::ULONG, return static adept\TokenAssociatedInfo("ulong", ::LITERAL, ::UNSIGNED) - case ::USIZE, return static adept\TokenAssociatedInfo("usize", ::LITERAL, ::UNSIGNED) - case ::FLOAT, return static adept\TokenAssociatedInfo("float", ::LITERAL, ::FLOATING) - case ::DOUBLE, return static adept\TokenAssociatedInfo("double", ::LITERAL, ::FLOATING) - case ::MEMBER, return static adept\TokenAssociatedInfo("member", ::OPERATOR, ::ID_ONLY) - case ::AMPERSAND, return static adept\TokenAssociatedInfo("address", ::OPERATOR, ::ID_ONLY) - case ::NEXT, return static adept\TokenAssociatedInfo("next", ::OPERATOR, ::ID_ONLY) - case ::BRACKET_OPEN, return static adept\TokenAssociatedInfo("bracket open", ::OPERATOR, ::ID_ONLY) - case ::BRACKET_CLOSE, return static adept\TokenAssociatedInfo("bracket close", ::OPERATOR, ::ID_ONLY) - case ::MODULUS, return static adept\TokenAssociatedInfo("modulus", ::OPERATOR, ::ID_ONLY) - case ::GENERIC_INT, return static adept\TokenAssociatedInfo("integer literal", ::LITERAL, ::SIGNED) - case ::GENERIC_FLOAT, return static adept\TokenAssociatedInfo("floating point literal", ::LITERAL, ::FLOATING) - case ::ADD_ASSIGN, return static adept\TokenAssociatedInfo("add assign", ::OPERATOR, ::ID_ONLY) - case ::SUBTRACT_ASSIGN, return static adept\TokenAssociatedInfo("subtract assign", ::OPERATOR, ::ID_ONLY) - case ::MULTIPLY_ASSIGN, return static adept\TokenAssociatedInfo("multiply assign", ::OPERATOR, ::ID_ONLY) - case ::DIVIDE_ASSIGN, return static adept\TokenAssociatedInfo("divide assign", ::OPERATOR, ::ID_ONLY) - case ::MODULUS_ASSIGN, return static adept\TokenAssociatedInfo("modulus assign", ::OPERATOR, ::ID_ONLY) - case ::BIT_AND_ASSIGN, return static adept\TokenAssociatedInfo("bitwise and assign", ::OPERATOR, ::ID_ONLY) - case ::BIT_OR_ASSIGN, return static adept\TokenAssociatedInfo("bitwise or assign", ::OPERATOR, ::ID_ONLY) - case ::BIT_XOR_ASSIGN, return static adept\TokenAssociatedInfo("bitwise xor assign", ::OPERATOR, ::ID_ONLY) - case ::BIT_LSHIFT_ASSIGN, return static adept\TokenAssociatedInfo("bitwise left shift assign", ::OPERATOR, ::ID_ONLY) - case ::BIT_RSHIFT_ASSIGN, return static adept\TokenAssociatedInfo("bitwise right shift assign", ::OPERATOR, ::ID_ONLY) - case ::BIT_LGC_LSHIFT_ASSIGN, return static adept\TokenAssociatedInfo("bitwise logical left shift assign", ::OPERATOR, ::ID_ONLY) - case ::BIT_LGC_RSHIFT_ASSIGN, return static adept\TokenAssociatedInfo("bitwise logical right shift assign", ::OPERATOR, ::ID_ONLY) - case ::ELLIPSIS, return static adept\TokenAssociatedInfo("ellipsis", ::OPERATOR, ::ID_ONLY) - case ::UBERAND, return static adept\TokenAssociatedInfo("uber and", ::OPERATOR, ::ID_ONLY) - case ::UBEROR, return static adept\TokenAssociatedInfo("uber or", ::OPERATOR, ::ID_ONLY) - case ::TERMINATE_JOIN, return static adept\TokenAssociatedInfo("terminate join", ::OPERATOR, ::ID_ONLY) - case ::COLON, return static adept\TokenAssociatedInfo("colon", ::OPERATOR, ::ID_ONLY) - case ::BIT_OR, return static adept\TokenAssociatedInfo("bitwise or", ::OPERATOR, ::ID_ONLY) - case ::BIT_XOR, return static adept\TokenAssociatedInfo("bitwise xor", ::OPERATOR, ::ID_ONLY) - case ::BIT_LSHIFT, return static adept\TokenAssociatedInfo("bitwise left shift", ::OPERATOR, ::ID_ONLY) - case ::BIT_RSHIFT, return static adept\TokenAssociatedInfo("bitwise right shift", ::OPERATOR, ::ID_ONLY) - case ::BIT_COMPLEMENT, return static adept\TokenAssociatedInfo("bitwise complement", ::OPERATOR, ::ID_ONLY) - case ::BIT_LGC_LSHIFT, return static adept\TokenAssociatedInfo("bitwise logical left shift", ::OPERATOR, ::ID_ONLY) - case ::BIT_LGC_RSHIFT, return static adept\TokenAssociatedInfo("bitwise logical right shift", ::OPERATOR, ::ID_ONLY) - case ::ASSOCIATE, return static adept\TokenAssociatedInfo("associate", ::OPERATOR, ::ID_ONLY) - case ::META, return static adept\TokenAssociatedInfo("meta", ::PREPROCESSOR, ::STRING) - case ::POLYMORPH, return static adept\TokenAssociatedInfo("polymorph", ::POLYMORPH, ::STRING) - case ::MAYBE, return static adept\TokenAssociatedInfo("maybe", ::OPERATOR, ::ID_ONLY) - case ::INCREMENT, return static adept\TokenAssociatedInfo("increment", ::OPERATOR, ::ID_ONLY) - case ::DECREMENT, return static adept\TokenAssociatedInfo("decrement", ::OPERATOR, ::ID_ONLY) - case ::TOGGLE, return static adept\TokenAssociatedInfo("toggle", ::OPERATOR, ::ID_ONLY) - case ::STRONG_ARROW, return static adept\TokenAssociatedInfo("strong arrow", ::OPERATOR, ::ID_ONLY) - case ::RANGE, return static adept\TokenAssociatedInfo("range", ::OPERATOR, ::ID_ONLY) - case ::GIVES, return static adept\TokenAssociatedInfo("gives", ::OPERATOR, ::ID_ONLY) - case ::POLYCOUNT, return static adept\TokenAssociatedInfo("polycount", ::LITERAL, ::STRING) - case ::POD_KEYWORD, return static adept\TokenAssociatedInfo("POD keyword", ::KEYWORD, ::ID_ONLY) - case ::ALIAS, return static adept\TokenAssociatedInfo("alias keyword", ::KEYWORD, ::ID_ONLY) - case ::ALIGNOF, return static adept\TokenAssociatedInfo("alignof keyword", ::KEYWORD, ::ID_ONLY) - case ::AND, return static adept\TokenAssociatedInfo("and keyword", ::KEYWORD, ::ID_ONLY) - case ::AS, return static adept\TokenAssociatedInfo("as keyword", ::KEYWORD, ::ID_ONLY) - case ::AT, return static adept\TokenAssociatedInfo("at keyword", ::KEYWORD, ::ID_ONLY) - case ::BREAK, return static adept\TokenAssociatedInfo("break keyword", ::KEYWORD, ::ID_ONLY) - case ::CASE, return static adept\TokenAssociatedInfo("case keyword", ::KEYWORD, ::ID_ONLY) - case ::CAST, return static adept\TokenAssociatedInfo("cast keyword", ::KEYWORD, ::ID_ONLY) - case ::CLASS, return static adept\TokenAssociatedInfo("class keyword", ::KEYWORD, ::ID_ONLY) - case ::CONST, return static adept\TokenAssociatedInfo("const keyword", ::KEYWORD, ::ID_ONLY) - case ::CONSTRUCTOR, return static adept\TokenAssociatedInfo("constructor keyword", ::KEYWORD, ::ID_ONLY) - case ::CONTINUE, return static adept\TokenAssociatedInfo("continue keyword", ::KEYWORD, ::ID_ONLY) - case ::DEF, return static adept\TokenAssociatedInfo("def keyword", ::KEYWORD, ::ID_ONLY) - case ::DEFAULT, return static adept\TokenAssociatedInfo("default keyword", ::KEYWORD, ::ID_ONLY) - case ::DEFER, return static adept\TokenAssociatedInfo("defer keyword", ::KEYWORD, ::ID_ONLY) - case ::DEFINE, return static adept\TokenAssociatedInfo("define keyword", ::KEYWORD, ::ID_ONLY) - case ::DELETE, return static adept\TokenAssociatedInfo("delete keyword", ::KEYWORD, ::ID_ONLY) - case ::EACH, return static adept\TokenAssociatedInfo("each keyword", ::KEYWORD, ::ID_ONLY) - case ::ELSE, return static adept\TokenAssociatedInfo("else keyword", ::KEYWORD, ::ID_ONLY) - case ::EMBED, return static adept\TokenAssociatedInfo("embed keyword", ::KEYWORD, ::ID_ONLY) - case ::ENUM, return static adept\TokenAssociatedInfo("enum keyword", ::KEYWORD, ::ID_ONLY) - case ::EXHAUSTIVE, return static adept\TokenAssociatedInfo("exhaustive keyword", ::KEYWORD, ::ID_ONLY) - case ::EXTENDS, return static adept\TokenAssociatedInfo("extends keyword", ::KEYWORD, ::ID_ONLY) - case ::EXTERNAL, return static adept\TokenAssociatedInfo("external keyword", ::KEYWORD, ::ID_ONLY) - case ::FALLTHROUGH, return static adept\TokenAssociatedInfo("fallthrough keyword", ::KEYWORD, ::ID_ONLY) - case ::FALSE, return static adept\TokenAssociatedInfo("false keyword", ::KEYWORD, ::ID_ONLY) - case ::FOR, return static adept\TokenAssociatedInfo("for keyword", ::KEYWORD, ::ID_ONLY) - case ::FOREIGN, return static adept\TokenAssociatedInfo("foreign keyword", ::KEYWORD, ::ID_ONLY) - case ::FUNC, return static adept\TokenAssociatedInfo("func keyword", ::KEYWORD, ::ID_ONLY) - case ::FUNCPTR, return static adept\TokenAssociatedInfo("funcptr keyword", ::KEYWORD, ::ID_ONLY) - case ::GLOBAL, return static adept\TokenAssociatedInfo("global keyword", ::KEYWORD, ::ID_ONLY) - case ::IF, return static adept\TokenAssociatedInfo("if keyword", ::KEYWORD, ::ID_ONLY) - case ::IMPLICIT, return static adept\TokenAssociatedInfo("implicit keyword", ::KEYWORD, ::ID_ONLY) - case ::IMPORT, return static adept\TokenAssociatedInfo("import keyword", ::KEYWORD, ::ID_ONLY) - case ::IN, return static adept\TokenAssociatedInfo("in keyword", ::KEYWORD, ::ID_ONLY) - case ::INOUT, return static adept\TokenAssociatedInfo("inout keyword", ::KEYWORD, ::ID_ONLY) - case ::LLVM_ASM, return static adept\TokenAssociatedInfo("llvm_asm keyword", ::KEYWORD, ::ID_ONLY) - case ::NAMESPACE, return static adept\TokenAssociatedInfo("namespace keyword", ::KEYWORD, ::ID_ONLY) - case ::NEW, return static adept\TokenAssociatedInfo("new keyword", ::KEYWORD, ::ID_ONLY) - case ::NULL, return static adept\TokenAssociatedInfo("null keyword", ::KEYWORD, ::ID_ONLY) - case ::OR, return static adept\TokenAssociatedInfo("or keyword", ::KEYWORD, ::ID_ONLY) - case ::OUT, return static adept\TokenAssociatedInfo("out keyword", ::KEYWORD, ::ID_ONLY) - case ::OVERRIDE, return static adept\TokenAssociatedInfo("override keyword", ::KEYWORD, ::ID_ONLY) - case ::PACKED, return static adept\TokenAssociatedInfo("packed keyword", ::KEYWORD, ::ID_ONLY) - case ::PRAGMA, return static adept\TokenAssociatedInfo("pragma keyword", ::KEYWORD, ::ID_ONLY) - case ::PRIVATE, return static adept\TokenAssociatedInfo("private keyword", ::KEYWORD, ::ID_ONLY) - case ::PUBLIC, return static adept\TokenAssociatedInfo("public keyword", ::KEYWORD, ::ID_ONLY) - case ::RECORD, return static adept\TokenAssociatedInfo("record keyword", ::KEYWORD, ::ID_ONLY) - case ::REPEAT, return static adept\TokenAssociatedInfo("repeat keyword", ::KEYWORD, ::ID_ONLY) - case ::RETURN, return static adept\TokenAssociatedInfo("return keyword", ::KEYWORD, ::ID_ONLY) - case ::SIZEOF, return static adept\TokenAssociatedInfo("sizeof keyword", ::KEYWORD, ::ID_ONLY) - case ::STATIC, return static adept\TokenAssociatedInfo("static keyword", ::KEYWORD, ::ID_ONLY) - case ::STDCALL, return static adept\TokenAssociatedInfo("stdcall keyword", ::KEYWORD, ::ID_ONLY) - case ::STRUCT, return static adept\TokenAssociatedInfo("struct keyword", ::KEYWORD, ::ID_ONLY) - case ::SWITCH, return static adept\TokenAssociatedInfo("switch keyword", ::KEYWORD, ::ID_ONLY) - case ::THREAD_LOCAL, return static adept\TokenAssociatedInfo("thread_local keyword", ::KEYWORD, ::ID_ONLY) - case ::TRUE, return static adept\TokenAssociatedInfo("true keyword", ::KEYWORD, ::ID_ONLY) - case ::TYPEINFO, return static adept\TokenAssociatedInfo("typeinfo keyword", ::KEYWORD, ::ID_ONLY) - case ::TYPENAMEOF, return static adept\TokenAssociatedInfo("typenameof keyword", ::KEYWORD, ::ID_ONLY) - case ::UNDEF, return static adept\TokenAssociatedInfo("undef keyword", ::KEYWORD, ::ID_ONLY) - case ::UNION, return static adept\TokenAssociatedInfo("union keyword", ::KEYWORD, ::ID_ONLY) - case ::UNLESS, return static adept\TokenAssociatedInfo("unless keyword", ::KEYWORD, ::ID_ONLY) - case ::UNTIL, return static adept\TokenAssociatedInfo("until keyword", ::KEYWORD, ::ID_ONLY) - case ::USING, return static adept\TokenAssociatedInfo("using keyword", ::KEYWORD, ::ID_ONLY) - case ::VA_ARG, return static adept\TokenAssociatedInfo("va_arg keyword", ::KEYWORD, ::ID_ONLY) - case ::VA_COPY, return static adept\TokenAssociatedInfo("va_copy keyword", ::KEYWORD, ::ID_ONLY) - case ::VA_END, return static adept\TokenAssociatedInfo("va_end keyword", ::KEYWORD, ::ID_ONLY) - case ::VA_START, return static adept\TokenAssociatedInfo("va_start keyword", ::KEYWORD, ::ID_ONLY) - case ::VERBATIM, return static adept\TokenAssociatedInfo("verbatim keyword", ::KEYWORD, ::ID_ONLY) - case ::VIRTUAL, return static adept\TokenAssociatedInfo("virtual keyword", ::KEYWORD, ::ID_ONLY) - case ::WHILE, return static adept\TokenAssociatedInfo("while keyword", ::KEYWORD, ::ID_ONLY) - case ::NUM_ITEMS return null // invalid state - } - - return null // unreachable -} diff --git a/next/src/TokenKeyword.adept b/next/src/TokenKeyword.adept deleted file mode 100644 index ab8e9951..00000000 --- a/next/src/TokenKeyword.adept +++ /dev/null @@ -1,47 +0,0 @@ - -import "TokenID.adept" - -namespace adept { - func getTokenForKeyword(identifier String) adept\TokenID { - info *adept\TokenKeyword = adept\keywords.search(identifier) - return info ? info.token_id : adept\TokenID::NONE - } - - keywords List = adept\getKeywords() - - func getKeywords() List { - list List - keyword_suffix StringView = " keyword" - - repeat static adept\TokenID::NUM_ITEMS as usize { - token_id adept\TokenID = idx as adept\TokenID - info *adept\TokenAssociatedInfo = adept\getAssociatedInfo(token_id) - - if info.category == ::KEYWORD && info.name.endsWith(keyword_suffix) { - identifier StringView = info.name.range(0, info.name.length - keyword_suffix.length) - list.add( - adept\TokenKeyword( - identifier, - token_id - ) - ) - } - } - - qsort(list.items, list.length, sizeof adept\TokenKeyword, func &adept\compareKeywords as ptr as func(ptr, ptr) int) - - return list.commit() - } - - record TokenKeyword (identifier StringView, token_id adept\TokenID) - - func compareKeywords(a *adept\TokenKeyword, b *adept\TokenKeyword) int { - return a.identifier.compare(b.identifier) - } -} - -func search(this * List, identifier String) *adept\TokenKeyword { - key adept\TokenKeyword = adept\TokenKeyword(identifier, ::NONE) - compare_fn func(ptr, ptr) int = func &adept\compareKeywords(*adept\TokenKeyword, *adept\TokenKeyword) as ptr as func(ptr, ptr) int - return bsearch(&key, this.items, this.length, sizeof(key), compare_fn) -} diff --git a/next/src/Version.adept b/next/src/Version.adept deleted file mode 100644 index 48b1fb5a..00000000 --- a/next/src/Version.adept +++ /dev/null @@ -1,4 +0,0 @@ - -namespace adept - -enum Version (TWO, THREE) diff --git a/next/src/color.adept b/next/src/color.adept deleted file mode 100644 index 938440ee..00000000 --- a/next/src/color.adept +++ /dev/null @@ -1,38 +0,0 @@ - -import 'sys/cstdio.adept' - -enum color\Color (RESET, RED, YELLOW, WHITE, BLUE, LIGHT_BLUE) - -func color\use(color color\Color){ - exhaustive switch color { - case ::RESET - fputs('\e[0m', stdout) - fflush(stdout) - case ::RED - fputs('\e[31;1m', stdout) - case ::YELLOW - fputs('\e[33;1m', stdout) - case ::WHITE - fputs('\e[37;1m', stdout) - case ::BLUE - fputs('\e[34;1m', stdout) - case ::LIGHT_BLUE - fputs('\e[38;5;31m', stdout) - } -} - -func color\red(){ - color\use(::RED) -} - -func color\blue(){ - color\use(::BLUE) -} - -func color\yellow(){ - color\use(::YELLOW) -} - -func color\reset(){ - color\use(::RESET) -} diff --git a/next/src/configuration.adept b/next/src/configuration.adept deleted file mode 100644 index c49ba648..00000000 --- a/next/src/configuration.adept +++ /dev/null @@ -1,5 +0,0 @@ - -#default adept\version_string "3.0" -#default adept\emscripten __wasm__ - -define adept\VERSION_STRING = #get adept\version_string diff --git a/next/src/datatypes.adept b/next/src/datatypes.adept deleted file mode 100644 index 19f664ad..00000000 --- a/next/src/datatypes.adept +++ /dev/null @@ -1,15 +0,0 @@ - -import String -import cstring - -func adept\mustBeUnsigned64(string String, is_hex bool) bool { - // NOTE: Doesn't care whether 'string' is valid integer representation - - if is_hex { - // Base 16 - return string.length != 16 ? string.length > 16 : strncmp(string.array, '7FFFFFFFFFFFFFFF', 16) > 0 - } else { - // Base 10 - return string.length != 19 ? string.length > 19 : strncmp(string.array, '9223372036854775807', 19) > 0 - } -} diff --git a/next/src/fs.adept b/next/src/fs.adept deleted file mode 100644 index 0fb918c7..00000000 --- a/next/src/fs.adept +++ /dev/null @@ -1,57 +0,0 @@ - -import Unique -import 'sys/cstdio.adept' -import "configuration.adept" - -enum adept\fs\ReadOptions (NONE, WITH_NEWLINE_ENDING) - -func adept\fs\readTextContents(text_filename String, out output *String, options adept\fs\ReadOptions = ::NONE) successful { - filename Unique = Unique(text_filename.cstr()) - - buffer *ubyte = undef - buffer_size usize = undef - - #if adept\emscripten - buffer = node_fs_readFileSync(filename.ref(), options == ::WITH_NEWLINE_ENDING) - if buffer == null, return false - - buffer_size = strlen(buffer) - #else - file *FILE = fopen(filename.ref(), 'r') - if file == null, return false - - fseek(file, 0, SEEK_END) - buffer_size = ftell(file) - fseek(file, 0, SEEK_SET) - - buffer = malloc(buffer_size + 2) - buffer_size = fread(buffer, 1, buffer_size, file) - fclose(file) - #end - - if options == ::WITH_NEWLINE_ENDING { - buffer[buffer_size] = '\n'ub // Append newline to flush everything - buffer[buffer_size + 1] = '\0'ub // Terminate the string for good measure - buffer_size += 1 - } - - *output = StringView(buffer, buffer_size) - return true -} - -func adept\fs\exists(file String) bool { - filename Unique = Unique(file.cstr()) - - #if adept\emscripten - return node_fs_existsSync(filename.ref()) != 0 - #else - f *FILE = fopen(filename.ref(), 'r') - - if f { - fclose(f) - return true - } - - return false - #end -} diff --git a/next/src/msg/help.txt b/next/src/msg/help.txt deleted file mode 100644 index 6c850790..00000000 --- a/next/src/msg/help.txt +++ /dev/null @@ -1,5 +0,0 @@ -Usage: adept [options] [filename] - -Options: - -h, --help Display this message - -e Execute result \ No newline at end of file diff --git a/next/src/msg/no_version_specified.txt b/next/src/msg/no_version_specified.txt deleted file mode 100644 index 2c7d3bb9..00000000 --- a/next/src/msg/no_version_specified.txt +++ /dev/null @@ -1,3 +0,0 @@ -No compiler version specified for `%S`! - To use Adept 3.x, your file must start with `pragma compiler_version '3.0'` - To use Adept 2.x, specify the `-2` flag \ No newline at end of file diff --git a/next/src/string.adept b/next/src/string.adept deleted file mode 100644 index d4788a17..00000000 --- a/next/src/string.adept +++ /dev/null @@ -1,79 +0,0 @@ - -import String - -func adept\string\escape(string String, escaped_quote ubyte, surround bool) String { - result String - - if escaped_quote && surround { - result.append(escaped_quote) - } - - each ubyte in string { - unless it <= 0x1F || it == '\\'ub || (it == escaped_quote && escaped_quote) { - // Put regular character - result.append(it) - continue - } - - // Escape special character - result.append('\\') - - switch it { - case '\0'ub, result.append('0'ub) - case '\t'ub, result.append('t'ub) - case '\n'ub, result.append('n'ub) - case '\r'ub, result.append('r'ub) - case '\b'ub, result.append('b'ub) - case '\\'ub, result.append('\\'ub) - case '\e'ub, result.append('e'ub) - default - if(it == escaped_quote){ - // Escape quote character - result.append(escaped_quote) - } else { - // Unrecognized special character, don't escape - result.append(it) - } - } - } - - if escaped_quote && surround { - result.append(escaped_quote) - } - - return result.commit() -} - -record adept\string\UnescapeError (relative_position usize) - -func adept\string\unescape(string String, out output *String) Optional { - output.clear() - output.reserve(string.length) - - get usize = 0 - - while get != string.length { - if string[get] != '\\'ub || get + 1 == string.length { - output.append(string[get++]) - continue - } - - switch(string[get + 1]){ - case 'n'ub, output.append('\n'ub) - case 'r'ub, output.append('\r'ub) - case 't'ub, output.append('\t'ub) - case 'b'ub, output.append('\b'ub) - case '0'ub, output.append('\0'ub) - case '"'ub, output.append('"'ub) - case 'e'ub, output.append('\e'ub) - case '\''ub, output.append('\''ub) - case '\\'ub, output.append('\\'ub) - default - return some(adept\string\UnescapeError(get)) - } - - get += 2 - } - - return none() -} diff --git a/next/src/util.adept b/next/src/util.adept deleted file mode 100644 index 6717e922..00000000 --- a/next/src/util.adept +++ /dev/null @@ -1,6 +0,0 @@ - -func adept\toHeap(value $T) *$T { - on_heap *$T = new $T - *on_heap = value - return on_heap -}